Mercurial > hg > movesynth
diff HeresyBigBangDone/application.macosx/source/HeresyBigBangDone.pde @ 50:f4c6999ecfe9 tip
added the files on my computer that aren't aiff s> these shoudl be everything for the big bang fair 2011 - heresy, and tim's file's also here
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sat, 08 Oct 2011 22:12:49 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeresyBigBangDone/application.macosx/source/HeresyBigBangDone.pde Sat Oct 08 22:12:49 2011 +0100 @@ -0,0 +1,288 @@ + + +void setup(){ + markovStuff(); + for (int i = 0; i < 16; i++) + VPA[i] = new VPArray(); // creates the virtual playing array for Heresy AI. + for (int i = 0; i < noteOnArray.length; i++) + noteOnArray[i] = false; // makes sure there are initial random inputs from openFrameworks + + oscP5return = new OscP5(this,12346); + + frameRate(tempo); + img = createGraphics(imageWidth,imageHeight,P2D); + size(800,imageHeight,P2D); + arial = createFont("Arial",32); + textFont(arial,15); + + // initialize the tracks + + tracks[0] = new Track("Chord track", true, grid * beatsPerBar, 8, true, true); + tracks[1] = new Track("Drums", true, grid * beatsPerBar, 8, false, true); + tracks[2] = new Track("Bass", true, grid * beatsPerBar, 8, false, true); + tracks[3] = new Track("Pizz Strings", true, grid * beatsPerBar, 8, false, true); + tracks[4] = new Track("Synth", true, grid * beatsPerBar, 8, false, true); + tracks[5] = new Track("Voice", true, grid * beatsPerBar, 8, false, true); + tracks[6] = new Track("Voice", true, grid * beatsPerBar, 8, false, true); + chordsTemp = new Track("Chord track", true, loopLength, 8, true, false); + trSelected = 1; + backgroundColour(); + drawLines(); + drawBarLines(); + imgNoteFan = createGraphics(fanWidth,imageHeight,P2D); + lastTrack = trSelected; + clickTrackOn = true; + // loadSequences(); + // tracks[2].sequence[15][16] = new NoteEvent (14, 2, bar,beat,fraction,pulse); + // tracks[2].sequence[15][grid * beatsPerBar -20] = new NoteEvent (14, 2, bar,beat,fraction,pulse, true); + + // tracks[3].sequence[13][16] = new NoteEvent (13, 3, bar,beat,fraction,pulse); + // tracks[3].sequence[13][20] = new NoteEvent (13, 3, bar,beat,fraction,pulse, true); + // tracks[3].sequence[12][16] = new NoteEvent (12, 3, bar,beat,fraction,pulse); + // tracks[3].sequence[12][20] = new NoteEvent (12, 3, bar,beat,fraction,pulse, true); + // tracks[3].sequence[11][16] = new NoteEvent (11, 3, bar,beat,fraction,pulse); + // tracks[3].sequence[11][20] = new NoteEvent (11, 3, bar,beat,fraction,pulse, true); + // tracks[3].sequence[10][16] = new NoteEvent (10, 3, bar,beat,fraction,pulse); + // tracks[3].sequence[10][20] = new NoteEvent (10, 3, bar,beat,fraction,pulse, true); +} + + +//------------------------------------------------------------------------------------------------------------------------------- + +void draw(){ + /* if (currentPulse % (grid * beatsPerBar) == grid * beatsPerBar -1){ + int tempTrackSelected = trSelected; + for (int j = 0; j < 16; j++){ + trSelected = j; + if (tracks[j] != null){ + for (int i = 0; i < 16; i++){ + noteOnArray[i] = false; + finishNote(i); + displayNoteOnArray[i] = false; + for (int z = 24; z < 109; z++) + outputToMax(z, 0, j); + } + tracks[j] = new Track(tracks[j].name, true, tracks[j].loopLength, tracks[j].quantize, false, false); + imgNotes = null; + } + } + trSelected = tempTrackSelected; + } + */ + // tracks[0] = new Track("Chord track", true, grid * beatsPerBar, 8, true, true); + // tracks[1] = new Track("Drums", true, grid * beatsPerBar, 8, false, true); + // tracks[2] = new Track("Bass", true, grid * beatsPerBar, 8, false, true); + // tracks[3] = new Track("Pizz Strings", true, grid * beatsPerBar, 8, false, true); + // tracks[4] = new Track("Synth", true, grid * beatsPerBar, 8, false, true); + // tracks[5] = new Track("Voice", true, grid * beatsPerBar, 8, false, true); + // } + workOutPosition(); // calculates current bar, beat and pulse position + //println(bar + " " + beat + " " + fraction + " " + pulse); +// if (chordAI && bar > 1) +// chordCalc(); + if (eraseOn) + eraseNotes(); + calcColours(); // calcs chord colours for background and grid + heresyChange = false; + heresyChordChanged = false; + if (trackStorer != trSelected){ // resets display when changing tracks + for (int i = 0; i < 16; i++) + if (noteOnArray[i] = true){ + noteOnArray[i] = false; + displayNoteOnArray[i] = false; + } + trackStorer = trSelected; + imgNotes = null; + } + if (imgNotes == null) + imgNotes = createGraphics(tracks[trSelected].loopLength,imageHeight,P2D); + background(0); + image (img,width-x2-playArea,0); + drawTempImageGrid(); + createNoteFan(); + drawNotes(); + fill (0); + noStroke(); + rect (width-playArea,0,playArea,height); + image (imgNoteFan, width-playArea+3,0); + pulseFrame(x); // Draws a pulsing white line at the left edge of the edit area + if (haveQuestion) writeQuestion(); // for input request messages + x++; // counter for grid movement + x2++; // counter for note image movement + if (x2 == width - playArea + grid * beatsPerBar) + x2 = width - playArea; + if (x == width - playArea + tracks[trSelected].loopLength) + x = width - playArea; + + + /* if (clickTrackOn){ // click track + if (fraction == 1){ + if (pulse == 1){ + String noteOut = ("37 80 1"); + link.output(noteOut); + } + if (pulse == 2){ + String noteOut = ("37 0 1" ); + link.output(noteOut); + } + } + } + */ + checkForMutes(); + checkCycled(); + playTrackEvents(); + + fill(255,255,255); + textSize(15); + text(bar + " " + beat + " " + fraction + " " + pulse, 10,20); // draws current time position to screen + + fill(200,0,0); + textSize(15); + // this section draws current track and track info to screen + if (tracks[trSelected].ducking) + text(tracks[trSelected].name + " ducking", 100,20); + else + text(tracks[trSelected].name, 100,20); + if (tracks[trSelected].muteIn > bar) + if (!tracks[trSelected].mute) + text("mute in " + (tracks[trSelected].muteIn - bar), 200,20); + else + text("unmute in " + (tracks[trSelected].muteIn - bar), 200,20); + + if (haveQuestion){ // asks input questions + writeQuestion(); + } + // println(currentPulse + " "); + + + currentPulse++; // advances the sequencer to next pulse +} + + +//------------------------------------------------------------------------------------------------------------------------------- + +void eraseNotes(){ // erases notes in current track if selected + if (trSelected != 0){ + for (int i = 0; i < 16; i++){ + if (tracks[trSelected].sequence[i][(currentPulse%(tracks[trSelected].loopLength))] != null){ + tracks[trSelected].sequence[i][(currentPulse%(tracks[trSelected].loopLength))] = null; + } + } + } + if (trSelected == 0){ + for (int i = 0; i < 16; i++){ + if (chordsTemp.sequence[i][(currentPulse%(tracks[trSelected].loopLength))] != null){ + chordsTemp.sequence[i][(currentPulse%(tracks[trSelected].loopLength))] = null; + } + } + } +} + + +//------------------------------------------------------------------------------------------------------------------------------- + +void workOutPosition(){ // works out current position + if (currentPulse%(grid*beatsPerBar) == 0) + ++bar; + if (currentPulse%grid == 0) + ++beat; + if (beat > beatsPerBar) + beat = 1; + if (currentPulse%(grid/fractions) == 0) + ++fraction; + if (fraction > fractions) + fraction = 1; + ++pulse; + if (pulse > (grid/fractions)) + pulse = 1; +} + + +//------------------------------------------------------------------------------------------------------------------------------- + +public void finishNote(int noteArrayPosition){ // writes note offs into the sequencers + if (trSelected != 0) + tracks[trSelected].sequence[noteArrayPosition][(currentPulse%(tracks[trSelected].loopLength))] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse, true); + if (trSelected == 0) + chordsTemp.sequence[noteArrayPosition][(currentPulse%(chordsTemp.loopLength))] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse, true); + displayNoteOnArray[noteArrayPosition] = false; +} + +public void finishNote(int noteArrayPosition, int channel){ // writes note offs into the sequencers + if (trSelected != 0) + tracks[trSelected].sequence[noteArrayPosition][(currentPulse%(tracks[trSelected].loopLength))] = new NoteEvent (noteArrayPosition, channel, bar,beat,fraction,pulse, true); + if (trSelected == 0) + chordsTemp.sequence[noteArrayPosition][(currentPulse%(chordsTemp.loopLength))] = new NoteEvent (noteArrayPosition, channel, bar,beat,fraction,pulse, true); + displayNoteOnArray[noteArrayPosition] = false; +} + + +//----------------------------------------------------------------------------------------------------------------------------- + +public void finishNoteCutOff(int noteArrayPosition){ // writes note offs for unfinished notes in to the last track if track is changed and note ons are active + tracks[lastTrack].sequence[noteArrayPosition][(currentPulse%(tracks[lastTrack].loopLength))] = new NoteEvent (noteArrayPosition, lastTrack+1, bar,beat,fraction,pulse, true); +} + + +//------------------------------------------------------------------------------------------------------------------------------- + +public void writeNote(int noteArrayPosition, int veloc){ // writes note ons into the sequencers + if (trSelected != 0){ + int quantizeOffset = getQuantizeOffset(); + if (quantizeOffset >= 0){ + tracks[trSelected].sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse); + } + if (quantizeOffset < 0){ + tracks[trSelected].sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse); + + VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNoteOn = true; + if (trSelected !=1 && trSelected !=5) + VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 3); + else + VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 1); + VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNoteVelocity = veloc; + sendNote(VPA[trSelected].VPArrayNotes[noteArrayPosition], trSelected); + displayNoteOnArray[noteArrayPosition] = true; + + } + } + if (trSelected == 0){ + int quantizeOffset = getQuantizeOffset(); + if (quantizeOffset >= 0){ + chordsTemp.sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse); + } + if (quantizeOffset < 0){ + chordsTemp.sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse); + + if (noteArrayPosition > 3) + currentChord = 15 - noteArrayPosition; + displayNoteOnArray[noteArrayPosition] = true; + } + } +} + +public void writeNote(int noteArrayPosition, int veloc, int channel){ // writes note ons into the sequencers + VPA[channel].VPArrayNotes[noteArrayPosition].VPNoteOn = true; + VPA[channel].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 1); + VPA[channel].VPArrayNotes[noteArrayPosition].VPNoteVelocity = veloc; + sendNote(VPA[channel].VPArrayNotes[noteArrayPosition], channel); +} + + + + +//------------------------------------------------------------------------------------------------------------------------------- + +public int getQuantizeOffset(){ // tells write note method the quantize offset. + int quantizeInPulses = pulsesPerBar/(tracks[trSelected].quantize); + int quantizeOffset = currentPulse % quantizeInPulses; + if (quantizeOffset > quantizeInPulses/2.0){ + return ((quantizeOffset - quantizeInPulses) * -1) ; + } + else{ + return quantizeOffset * -1; + } +} + + +