// Michael Olsen, 10/26/2015 // CCRMA ID: mjolsen // Composition code for homework #4 // duration info 180 => int bpm; 60::second/bpm => dur qNote; qNote/2 => dur eNote; // busses Gain dryGain; Gain wetGain => JCRev rev => Gain masterGain => dac; dryGain => masterGain; // sent bus levels and initial reverb mix amount 1.0 => dryGain.gain; 1.0 => wetGain.gain; 1.25 => masterGain.gain; 0.25 => rev.mix; // function that plays a signal vibraphone note function void playVibeNote(int mFreq, float sPos, float vGain, float vFreq, float bVol, float dGain, float mGain, float nGain) { ModalBar bar => Gain mainBarGain; mainBarGain => Gain dryBarGain => dryGain; mainBarGain => Gain wetBarGain => wetGain; 1.0 => mainBarGain.gain; 0.5 => wetBarGain.gain; 0.5 => dryBarGain.gain; Std.mtof(mFreq) => bar.freq; 1 => bar.preset; // hard coded to vibraphone 0.75 => bar.stickHardness; // always leave at 0.75 (sweet spot) sPos => bar.strikePosition; // set between 0.375 and 0.625 vGain => bar.vibratoGain; vFreq => bar.vibratoFreq; bVol => bar.volume; dGain => bar.directGain; // fluctuate between 0 and 0.25 mGain => bar.masterGain; // play note nGain => bar.noteOn; // fluctuate between 0.25 and 1 to control note intensity and duration // advance time 5::second => now; } // function that plays an individual shaker sound function void playShakeSound(int preset, float velocity) { Shakers s => Gain mainShakerGain; mainShakerGain => Gain dryShakerGain => dryGain; mainShakerGain => Gain wetShakerGain => wetGain; 1.0 => mainShakerGain.gain; 0.05 => wetShakerGain.gain; 0.95 => dryShakerGain.gain; // set shaker type preset => s.which; // play note velocity => s.noteOn; 1::second => now; } // arrays of midi note values for relevant vibraphone phrases [43, 50, 55, 46, 51, 58] @=> int vibeNotes1[]; [43, 50, 55, 53, 58, 51, 46] @=> int vibeNotes2a[]; [48, 55, 62, 55, 44, 51, 58] @=> int vibeNotes2b[]; [48, 55, 62, 63, 58, 51, 48, 55, 60, 58, 51, 46] @=> int vibeNotes3[]; // function to play vibraphone melody pattern function void playVibePhrase1() { for (0 => int i; i < vibeNotes1.cap(); i++ ) { Math.random2f(0.0,0.5) => float dGainVP1; Math.random2f(0.25,1.0) => float nGainVP1; spork ~playVibeNote(vibeNotes1[i],0.5,0,0,0.875,dGainVP1,0.875,nGainVP1); eNote => now; } } // function to play vibraphone melody pattern function void playVibePhrase2a() { for (0 => int i; i < vibeNotes2a.cap(); i++ ) { Math.random2f(0.0,0.5) => float dGainVP2a; Math.random2f(0.25,1.0) => float nGainVP2a; spork ~playVibeNote(vibeNotes2a[i],0.5,0,0,0.875,dGainVP2a,0.875,nGainVP2a); eNote => now; } } // function to play vibraphone melody pattern function void playVibePhrase2b() { for (0 => int i; i < vibeNotes2b.cap(); i++ ) { Math.random2f(0.0,0.5) => float dGainVP2b; Math.random2f(0.25,1.0) => float nGainVP2b; spork ~playVibeNote(vibeNotes2b[i],0.5,0,0,0.875,dGainVP2b,0.875,nGainVP2b); eNote => now; } } // function to play vibraphone melody pattern function void playVibePhrase3() { for (0 => int i; i < vibeNotes3.cap(); i++ ) { Math.random2f(0.0,0.5) => float dGainVP1; Math.random2f(0.25,0.75) => float nGainVP1; spork ~playVibeNote(vibeNotes3[i],0.5,0,0,0.875,dGainVP1,0.875,nGainVP1); eNote => now; } } // function to play shaker pattern function void playShakerPhrase1() { spork ~playShakeSound(6,2); eNote => now; spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(6,2); eNote/2 => now; spork ~playShakeSound(6,0.5); eNote/2 => now; spork ~playShakeSound(21,2); me.yield(); spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(6,1); eNote => now; } // function to play shaker pattern function void playShakerPhrase2a() { spork ~playShakeSound(6,2); eNote => now; spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(6,1); eNote/2 => now; spork ~playShakeSound(6,0.5); eNote/2 => now; spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(21,2); me.yield(); spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(6,1); eNote/2 => now; spork ~playShakeSound(6,0.5); eNote/2 => now; spork ~playShakeSound(6,1); eNote => now; } // function to play shaker pattern function void playShakerPhrase2b() { spork ~playShakeSound(6,2); eNote => now; spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(21,1.5); me.yield(); spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(6,3); eNote => now; spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(21,1.5); me.yield(); spork ~playShakeSound(6,1); eNote/2 => now; spork ~playShakeSound(6,0.5); eNote/2 => now; } // function to play shaker pattern function void playShakerPhrase3() { spork ~playShakeSound(6,2); eNote => now; spork ~playShakeSound(6,1); eNote/2 => now; spork ~playShakeSound(6,0.5); eNote/2 => now; spork ~playShakeSound(6,2); eNote/2 => now; spork ~playShakeSound(6,0.5); eNote/2 => now; spork ~playShakeSound(21,2); me.yield(); spork ~playShakeSound(6,1); eNote => now; spork ~playShakeSound(6,1); eNote/2 => now; spork ~playShakeSound(6,0.5); eNote/2 => now; spork ~playShakeSound(6,1); eNote => now; } // function to bring in vibraphone melody from initial sound of // just metallic block. The tonal feature of the instrument is slowly // faded on function void playVibeIntro() { 1.0 => float dGainI; 0.125 => float nGainI; 0.0 => float bVolI; for (0 => int i; i < vibeNotes1.cap(); i++ ) { spork ~playVibeNote(vibeNotes1[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.75/26 +=> nGainI; eNote => now; } for (0 => int i; i < vibeNotes2a.cap(); i++ ) { spork ~playVibeNote(vibeNotes2a[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.75/26 +=> nGainI; eNote => now; } for (0 => int i; i < vibeNotes1.cap(); i++ ) { spork ~playVibeNote(vibeNotes1[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.75/26 +=> nGainI; eNote => now; } for (0 => int i; i < vibeNotes2b.cap(); i++ ) { spork ~playVibeNote(vibeNotes2b[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.75/26 +=> nGainI; eNote => now; } for (0 => int i; i < vibeNotes1.cap(); i++ ) { spork ~playVibeNote(vibeNotes1[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes2a.cap(); i++ ) { spork ~playVibeNote(vibeNotes2a[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes1.cap(); i++ ) { spork ~playVibeNote(vibeNotes1[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes2b.cap(); i++ ) { spork ~playVibeNote(vibeNotes2b[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes1.cap(); i++ ) { spork ~playVibeNote(vibeNotes1[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.875/52 +=>bVolI; 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes2a.cap(); i++ ) { spork ~playVibeNote(vibeNotes2a[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.875/52 +=>bVolI; 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes1.cap(); i++ ) { spork ~playVibeNote(vibeNotes1[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.875/52 +=>bVolI; 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes2b.cap(); i++ ) { spork ~playVibeNote(vibeNotes2b[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.875/52 +=>bVolI; 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes1.cap(); i++ ) { spork ~playVibeNote(vibeNotes1[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.875/52 +=>bVolI; 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes2a.cap(); i++ ) { spork ~playVibeNote(vibeNotes2a[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.875/52 +=>bVolI; 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes1.cap(); i++ ) { spork ~playVibeNote(vibeNotes1[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.875/52 +=>bVolI; 0.5/78 -=> dGainI; eNote => now; } for (0 => int i; i < vibeNotes2b.cap(); i++ ) { spork ~playVibeNote(vibeNotes2b[i],0.5,0,0,bVolI,dGainI,0.875,nGainI); 0.875/52 +=>bVolI; 0.5/78 -=> dGainI; eNote => now; } } // function to play 2nd melody and then reduce vibraphone to metallic block sound // and then fade out to nothing function void playVibeOutro() { 0.5 => float dGainO; 0.875 => float mGainO; spork ~playShakeSound(21,2); me.yield(); spork ~playShakeSound(6,1); me.yield(); for (0 => int i; i < vibeNotes3.cap(); i++ ) { Math.random2f(0.25,1.0) => float nGainO; spork ~playVibeNote(vibeNotes3[i],0.5,0,0,0.875,dGainO,0.875,nGainO); 0.5/48 +=> dGainO; eNote => now; } 0.3 => rev.mix; for (0 => int i; i < vibeNotes3.cap(); i++ ) { Math.random2f(0.25,1.0) => float nGainO; spork ~playVibeNote(vibeNotes3[i],0.5,0,0,0.875,dGainO,0.875,nGainO); 0.5/48 +=> dGainO; eNote => now; } 0.35 => rev.mix; for (0 => int i; i < vibeNotes3.cap(); i++ ) { Math.random2f(0.25,1.0) => float nGainO; spork ~playVibeNote(vibeNotes3[i],0.5,0,0,0.875,dGainO,0.875,nGainO); 0.5/48 +=> dGainO; eNote => now; } 0.4 => rev.mix; for (0 => int i; i < vibeNotes3.cap(); i++ ) { Math.random2f(0.25,1.0) => float nGainO; spork ~playVibeNote(vibeNotes3[i],0.5,0,0,0.875,dGainO,0.875,nGainO); 0.5/48 +=> dGainO; eNote => now; } 0.45 => rev.mix; for (0 => int i; i < vibeNotes3.cap(); i++ ) { Math.random2f(0.25,1.0) => float nGainO; spork ~playVibeNote(vibeNotes3[i],0.5,0,0,mGainO,dGainO,mGainO,mGainO); 0.875/48 -=> mGainO; eNote => now; } for (0 => int i; i < vibeNotes3.cap(); i++ ) { Math.random2f(0.25,1.0) => float nGainO; spork ~playVibeNote(vibeNotes3[i],0.5,0,0,mGainO,dGainO,mGainO,mGainO); 0.875/48 -=> mGainO; eNote => now; } for (0 => int i; i < vibeNotes3.cap(); i++ ) { Math.random2f(0.25,1.0) => float nGainO; spork ~playVibeNote(vibeNotes3[i],0.5,0,0,mGainO,dGainO,mGainO,mGainO); 0.875/48 -=> mGainO; eNote => now; } for (0 => int i; i < vibeNotes3.cap(); i++ ) { Math.random2f(0.25,1.0) => float nGainO; spork ~playVibeNote(vibeNotes3[i],0.5,0,0,mGainO,dGainO,mGainO,mGainO); 0.875/48 -=> mGainO; eNote => now; } spork ~playVibeNote(vibeNotes3[0],0.5,0,0,0,dGainO,0,0); 4*qNote => now; } // write to a file dac => WvOut2 out => blackhole; me.sourceDir() + "/OLSEN_COMP4.wav" => string _capture; _capture => out.wavFilename; // start playing intro spork ~playVibeIntro(); 104*eNote => now; // wait duration of intro // start playing main vibes + shaker sequence for (0 => int j; j < 4; j++) { spork ~playVibePhrase1(); me.yield(); spork ~playShakerPhrase1(); 6*eNote => now; spork ~playVibePhrase2a(); me.yield(); spork ~playShakerPhrase2a(); 7*eNote => now; spork ~playVibePhrase1(); me.yield(); spork ~playShakerPhrase1(); 6*eNote => now; spork ~playVibePhrase2b(); me.yield(); spork ~playShakerPhrase2b(); 7*eNote => now; } // play alternate vibe + shaker sequence for (0 => int j; j < 4; j++) { spork ~playVibePhrase3(); me.yield(); spork ~playShakerPhrase3(); 6*eNote => now; spork ~playShakerPhrase1(); 6*eNote => now; } // play outro spork ~playVibeOutro(); // wait duration of outro plus some extra time // to allow tail of reverb to decay 96*eNote + 9*qNote => now; out.closeFile();