|
1 | 1 | importprocessing.sound.*; |
2 | 2 |
|
3 | 3 | SinOsc sines[]; |
| 4 | +int initialised; |
| 5 | +float frequency; |
4 | 6 |
|
5 | 7 | voidsetup(){ |
6 | 8 | size(640, 360); |
@@ -29,28 +31,39 @@ void setup(){ |
29 | 31 | println("Playing back different sine waves on the "+MultiChannel.availableChannels() +" different channels"); |
30 | 32 |
|
31 | 33 | sines =newSinOsc[MultiChannel.availableChannels()]; |
| 34 | + initialised =0; |
| 35 | + frequency =100; |
32 | 36 |
|
| 37 | +textSize(128); |
| 38 | +fill(0); |
| 39 | +textAlign(CENTER); |
| 40 | +} |
| 41 | + |
| 42 | +voiddraw(){ |
33 | 43 | // loop through all channels and start one sine wave on each |
34 | | -float frequency =100; |
35 | | -for (int i =0; i < sines.length; i++){ |
36 | | -MultiChannel.activeChannel(i); |
37 | | -// create and start the sine oscillator. |
38 | | - sines[i] =newSinOsc(this); |
39 | | - sines[i].freq(frequency); |
40 | | - sines[i].play(); |
| 44 | +if (initialised < sines.length){ |
41 | 45 | // add a nice theatrical break |
42 | 46 | delay(1000); |
43 | 47 |
|
| 48 | +background(255); |
| 49 | +text((initialised +1) +" of "+ sines.length, width/2, height/2); |
| 50 | + |
| 51 | +MultiChannel.activeChannel(initialised); |
| 52 | +// create and start the sine oscillator. |
| 53 | + sines[initialised] =newSinOsc(this); |
| 54 | + sines[initialised].freq(frequency); |
| 55 | + sines[initialised].play(); |
| 56 | + |
44 | 57 | // increase frequency on the next channel by one semitone |
45 | 58 | frequency = frequency *1.05946; |
| 59 | + initialised = initialised +1; |
| 60 | +return; |
46 | 61 | } |
47 | | -} |
48 | 62 |
|
49 | | -voiddraw(){ |
50 | 63 | // as long as the oscillators are not stopped they will 'stick' |
51 | 64 | // to the channel that they were originally added to, and we can |
52 | 65 | // change their parameters freely |
53 | | -floatfrequency =map(mouseX, 0, width, 80.0, 1000.0); |
| 66 | + frequency =map(mouseX, 0, width, 80.0, 1000.0); |
54 | 67 |
|
55 | 68 | for (SinOsc sin : sines){ |
56 | 69 | sin.freq(frequency); |
|
0 commit comments