Skip to content

Commit db2d35e

Browse files
committed
Changed scope of some variables in Processing.pde
1 parent 22c6c5b commit db2d35e

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

Processing/Processing.pde

+16-17
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,27 @@ static final byte BEACON_KEY = 42;
2323
// Serial baud rate. Should match desktop program.
2424
static final int BAUD_RATE = 115200;
2525

26-
Minim minim;
27-
AudioInput in;
28-
SelectInput si;
29-
BeatDetect beat;
30-
FFT fft;
31-
Serial serial_port;
32-
PluginHandler plugin;
26+
Minim minim; // Needs global for stop() and setup()
27+
AudioInput in; // Needs global for stop() and setup()
28+
Serial serial_port; // Needs global for draw() and setup()
29+
PluginHandler plugin; // Needs global for draw() and setup()
3330

3431
void setup()
3532
{
3633
// Set up minim / audio input
3734
minim = new Minim(this);
38-
autodetectInput();
35+
in = autodetectInput();
3936

4037
// Set up BeatDetect
41-
beat = new BeatDetect(in.bufferSize(), in.sampleRate());
38+
BeatDetect beat = new BeatDetect(in.bufferSize(), in.sampleRate());
4239
new BeatListener(beat, in);
4340

4441
// Set up FFT
45-
fft = new FFT(in.bufferSize(), in.sampleRate());
42+
FFT fft = new FFT(in.bufferSize(), in.sampleRate());
4643
new FFTListener(fft, in);
4744

4845
// Set up Serial
49-
autodetectSerial();
46+
serial_port = autodetectSerial();
5047

5148
// Set frame rate of draw()
5249
frameRate(FRAME_RATE);
@@ -64,9 +61,9 @@ void setup()
6461
}
6562

6663
// Trys to find and set the Soundflower (2ch) input
67-
void autodetectInput()
64+
AudioInput autodetectInput()
6865
{
69-
si = new SelectInput(Minim.STEREO, BUFFER_SIZE);
66+
SelectInput si = new SelectInput(Minim.STEREO, BUFFER_SIZE);
7067
Mixer.Info[] m = si.getInputs();
7168

7269
// First we will set a default index, in case we don't find it.
@@ -78,11 +75,11 @@ void autodetectInput()
7875
current_input = i;
7976

8077
// Now we set the input. If soundflower was found it should be set.
81-
in = si.setInput(si.getInputs()[current_input]);
78+
return si.setInput(si.getInputs()[current_input]);
8279
}
8380

8481
// Finds the correct serial device to connect to
85-
void autodetectSerial()
82+
Serial autodetectSerial()
8683
{
8784
// Run through each Serial device
8885
for(int i = 0; i < Serial.list().length; i++)
@@ -103,9 +100,11 @@ void autodetectSerial()
103100
delay(BEACON_PERIOD+1);
104101
// If the device sends us a matching byte, we found it
105102
if (serial_port.read() == BEACON_KEY)
106-
return;
103+
return serial_port;
107104
}
108105
}
106+
// If we've gotten this far, there are no more devices left
107+
return null;
109108
}
110109

111110
void draw()
@@ -135,4 +134,4 @@ public void stop() {
135134

136135
boolean displayable() {
137136
return VISIBLE;
138-
}
137+
}

0 commit comments

Comments
 (0)