Laptop Instrument Programming a Tune
Program Sections Instrument Note names Duration array Tune array Play loop
Instruments The clarinet // Define the instrument Clarinet Benny => dac; //patch the unit generator to the dac // Wet the reed, attach the reed, set the embouchure, etc. 0.3 => Benny.reed; //reed stiffness 0.1 => Benny.noiseGain; 8.0 => Benny.vibratoFreq; 0.4 => Benny.vibratoGain; 0.2 => Benny.pressure;
Note Names Define pitch names based on MIDI designations The note segment, created from the note spreadsheet
Duration Array Set the tempo Define an array of durations 120 => int tempo; // marching tempo Define an array of durations dur duration[20];
Duration Array (2) Set the durations based on the tempo Etc. //quarter note duration * relative note length (1::minute/tempo) * (4./1) => duration[1]; // whole note (1::minute/tempo) * (4./2) => duration[2]; // half note (1::minute/tempo) * (4./4) => duration[4]; // quarter note Etc.
Tune Array Chuck the tune as an array of pairs of integers to the tune array. Start with C major scale with half notes. [[C4,2],[D4,2],[E4,2],[F4,2],[G4,2],[A5,2] [[B5,2],[C5,2]]@=> int Tune[][]; First integer of a pair is the MIDI note number, represented by its name. Second integer of a pair is the index of the note duration in the duration array.
Play Loop Define a loop that plays each note in turn for( 0 => int i; i < Tune.cap(); i++) { Std.mtof(Tune[i][0]) => benny.freq; //convert MIDI note number to frequency 1.0 => benny.noteOn; //attack the note duration[Tune[i][1]] => now; 1.0 => benny.noteOff; }
Play Loop – Try 2 Define a loop that plays each note in turn Include note spacing for( 0 => int i; i < Tune.cap(); i++) { Std.mtof(Tune[i][0]) => benny.freq; //convert MIDI note number to frequency 1.0 => benny.noteOn; //attack the note duration[Tune[i][1]] => now; 1.0 => benny.noteOff; 5::ms => now; //set note spacing }