import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import ddf.minim.ugens.*; Minim minim; AudioOutput mainOut; Summer warbleBus; EnvelopeFollower envFollow; float waveSize = 100; void setup() { size( 800, 400 ); colorMode(HSB, 360, 1, 1); minim = new Minim(this); mainOut = minim.getLineOut(); // we'll feed all our kicks into here warbleBus = new Summer(); // to the output, please warbleBus.patch( mainOut ); // SIDECHAIN! // and those will be followed by this envFollow = new EnvelopeFollower( 0.001f, 0.1f, 512 ); // follow the kicks! warbleBus.patch( envFollow ); // pause time when adding a bunch of notes at once mainOut.pauseNotes(); // we set the tempo of the output so that the time and duration arguments // of playNote now are expressed in beats mainOut.setTempo( 120.f ); for(int i = 0; i < 8; i++) { DrumLoop1( i * 8 ); } mainOut.setNoteOffset( 8 * 8 ); Kick( 4.f ); Kick( 4.5f ); Kick( 5.f ); Kick( 5.5f ); Kick( 6.0f ); Kick( 6.75f ); Hiss( 7.0f ); Kick( 7.5f ); mainOut.setNoteOffset( 0.f ); Whine( 0.f, 16.f, "F3" ); Whine( 0.f, 16.f, "Db4" ); Whine( 0.f, 16.f, "Ab4" ); Whine( 16.0f, 16.f, "G3" ); Whine( 16.0f, 16.f, "D4" ); Whine( 16.0f, 16.f, "B4" ); Whine( 32.f, 16.f, "F#3" ); Whine( 32.f, 16.f, "D#4" ); Whine( 32.f, 16.f, "B4" ); Whine( 48.f, 32.f, "F3" ); Whine( 48.f, 32.f, "Eb4" ); Whine( 48.f, 32.f, "C5" ); BassLick( 0.0f, "Db2" ); BassLick( 16.0f, "B1" ); BassLick( 32.f, "A1" ); BassLick( 54.f, "G1" ); mainOut.setNoteOffset( 8 * 9 ); Bass( 0.f, "G2" ); Bass( 0.125f, "F3" ); Bass( 0.25f, "Eb4" ); Bass( 0.375f, "C5" ); Bass( 0.5f, "A5" ); Bass( 0.625f, "C5" ); Bass( 0.75f, "Eb4" ); Bass( 0.875f, "F3" ); Bass( 1.f, "G2" ); mainOut.resumeNotes(); } //////////////////////////////////////////////////////////////// // // INSTRUMENT HELPERS // void DrumLoop1( float startAt ) { mainOut.setNoteOffset( startAt ); Kick( 0.f ); Snare( 1.f ); Kick( 2.5f ); Snare( 3.f ); Snare( 4.75f ); Kick( 5.f ); Kick( 5.5f ); Snare( 6.f ); Kick( 7.f ); } void BassLick( float startAt, String noteName ) { mainOut.setNoteOffset( startAt ); float note = Frequency.ofPitch( noteName ).asHz(); Bass( 0.75f, note ); Bass( 1.00f, note ); Bass( 1.50f, note ); Bass( 2.00f, note ); Bass( 3.75f, note ); Bass( 4.00f, note ); Bass( 4.50f, note ); Bass( 5.00f, note ); Bass( 7.0f, note ); Bass( 7.25f, note * 2 ); Bass( 7.5f, note ); } void Kick( float time ) { mainOut.playNote( time, 0.5f, new KickInstrument( warbleBus ) ); } void Snare( float time ) { mainOut.playNote( time, 0.1f, new SnareInstrument() ); } void Whine( float time, float dur, String note ) { WhineInstrument whiner = new WhineInstrument( Frequency.ofPitch(note).asHz() ); mainOut.playNote( time, dur, whiner ); } void Bass( float time, String noteName ) { mainOut.playNote( time, 1.0f, new BassInstrument( Frequency.ofPitch(noteName).asHz() ) ); } void Bass( float time, float freq ) { mainOut.playNote( time, 0.2, new BassInstrument( freq ) ); } void Hiss( float time ) { mainOut.playNote( time, 9.0, new SnareInstrument( 2200.f, 0.f ) ); } ////////////////////////////////////////////////// // // DRAWING DOWN HERE // float hueForSample( float sample ) { return map( abs(sample), 0, 1, 120, 450 ); } // draw is run many times void draw() { // erase the window to black background( 0 ); // draw using a white stroke stroke( 255 ); // draw the waveforms for( int i = 0; i < mainOut.bufferSize() - 1; i++ ) { // find the x position of each buffer value float x1 = map( i, 0, mainOut.bufferSize(), 0, width ); float x2 = map( i+1, 0, mainOut.bufferSize(), 0, width ); // draw a line from one buffer position to the next for both channels stroke( hueForSample(mainOut.left.get(i)), 1, 1 ); line( x1, height/2 - waveSize + mainOut.left.get(i)*waveSize, x2, height/2 - waveSize + mainOut.left.get(i+1)*waveSize); stroke( hueForSample(mainOut.right.get(i)), 1, 1 ); line( x1, height/2 + waveSize + mainOut.right.get(i)*waveSize, x2, height/2 + waveSize + mainOut.right.get(i+1)*waveSize); } } // stop is run when the user presses stop void stop() { // close the AudioOutput mainOut.close(); // stop the minim object minim.stop(); super.stop(); }