// demo of how to script a change after a duration has elapsed // see below for a sectionI followed by a sectionII //////////////////////////////////////////////////////////////// // play a cycle of pitches 4 => int nPitches; // array to hold midi pitches (key numbers) int keyn[nPitches]; [ 60, 62, 64, 66 ] @=> keyn; //////////////////////////////////////////////////////////////// // against a cycle of a different length varying instrument parameters 3 => int nInsts; // arrays to hold loudnesses, pitch register transposition, channel, instrument type float loud[nInsts]; float tran[nInsts]; int chan[nInsts]; StkInstrument inst[nInsts]; // loudness contour [ 0.2, 0.2, 0.2 ] @=> loud; // pitch register contour [ 1.0, 1.0, 1.0 ] @=> tran; // e.g., 2.0 for octave higher, 4.0 for two octaves, etc. // channel contour [ 0, 0, 1 ] @=> chan; // strike position contour [ 0.0, 0.1, 1.0 ] @=> float vent[]; // per-instrument amount, 0.0 – 1.0 // StkInstrument physical models to choose from // BandedWG BlowBotl BlowHole Bowed Brass Clarinet // Flute StifKarp ModalBar Saxofony // instantiate 3 instruments and set their output channels Clarinet x @=> inst[0] => dac.chan(chan[0]); Saxofony y @=> inst[1] => dac.chan(chan[1]); Clarinet z @=> inst[2] => dac.chan(chan[2]); for (0=>int i; i dur duration; // set a common note duration 10.0 => dac.gain; // bump up the output level 1000::ms => dur ioi; // starting inter-onset interval (inverse of tempo) 50::ms => dur minIoi; // accelerate to this smallest ioi 0 => int p; // which pitch is next 0 => int i; // which instrument is next //////////////////////////////////////////////////////////////// // sectionI // when to change 10::second + now => time endOfSectionI; while( now < endOfSectionI ) { <<< p, i >>>; // print pitch index, instrument index Std.mtof( keyn[p] ) * tran[i] => inst[i].freq; // assign pitch as freq loud[i] => inst[i].noteOn; // start note duration => now; // wait 0.1 => inst[i].noteOff; // stop note p++; i++; // increment note and instrument (p % nPitches) => p; // cycle pitch through full array (i % nInsts) => i; // cycle instrument through full array // advance time by interval and calculate the next time interval ioi => now; ioi * 0.8 => ioi; // accelerate if (ioi < minIoi) minIoi => ioi;// can't go faster than minIoi } //////////////////////////////////////////////////////////////// // sectionII 5::second + now => time endOfSectionII; [ 66, 67, 68, 69 ] @=> keyn; [ 2.0, 1.0, 1.0 ] @=> tran; [ 1, 0, 2 ] @=> chan; while( now < endOfSectionII ) { <<< p, i >>>; // print pitch index, instrument index Std.mtof( keyn[p] ) * tran[i] => inst[i].freq; // assign pitch as freq loud[i] => inst[i].noteOn; // start note duration => now; // wait 0.1 => inst[i].noteOff; // stop note p++; i++; // increment note and instrument (p % nPitches) => p; // cycle pitch through full array (i % nInsts) => i; // cycle instrument through full array // advance time by interval and calculate the next time interval ioi => now; ioi * 0.8 => ioi; // accelerate if (ioi < minIoi) minIoi => ioi;// can't go faster than minIoi } 10::second + now => time endOfSectionIII; [ 50, 54, 56, 58 ] @=> keyn; [ 1.0, 1.0, 2.0 ] @=> tran; [ 2, 0, 1] @=> chan; while( now < endOfSectionIII ) { <<< p, i >>>; // print pitch index, instrument index Std.mtof( keyn[p] ) * tran[i] => inst[i].freq; // assign pitch as freq loud[i] => inst[i].noteOn; // start note duration => now; // wait 0.1 => inst[i].noteOff; // stop note p++; i++; // increment note and instrument (p % nPitches) => p; // cycle pitch through full array (i % nInsts) => i; // cycle instrument through full array // advance time by interval and calculate the next time interval ioi => now; ioi * 0.8 => ioi; // accelerate if (ioi < minIoi) minIoi => ioi;// can't go faster than minIoi } 10::second + now => time endOfSectionIV; [ 50, 60, 68, 55] @=> keyn; [ 1.0, 1.0, 1.0 ] @=> tran; while( now < endOfSectionIV ) { <<< p, i >>>; // print pitch index, instrument index Std.mtof( keyn[p] ) * tran[i] => inst[i].freq; // assign pitch as freq loud[i] => inst[i].noteOn; // start note duration => now; // wait 0.1 => inst[i].noteOff; // stop note p++; i++; // increment note and instrument (p % nPitches) => p; // cycle pitch through full array (i % nInsts) => i; // cycle instrument through full array // advance time by interval and calculate the next time interval ioi => now; ioi * 0.8 => ioi; // accelerate if (ioi < minIoi) minIoi => ioi;// can't go faster than minIoi }