Mercurial > hg > movesynth
comparison 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 |
comparison
equal
deleted
inserted
replaced
49:0eeda0223db3 | 50:f4c6999ecfe9 |
---|---|
1 | |
2 | |
3 void setup(){ | |
4 markovStuff(); | |
5 for (int i = 0; i < 16; i++) | |
6 VPA[i] = new VPArray(); // creates the virtual playing array for Heresy AI. | |
7 for (int i = 0; i < noteOnArray.length; i++) | |
8 noteOnArray[i] = false; // makes sure there are initial random inputs from openFrameworks | |
9 | |
10 oscP5return = new OscP5(this,12346); | |
11 | |
12 frameRate(tempo); | |
13 img = createGraphics(imageWidth,imageHeight,P2D); | |
14 size(800,imageHeight,P2D); | |
15 arial = createFont("Arial",32); | |
16 textFont(arial,15); | |
17 | |
18 // initialize the tracks | |
19 | |
20 tracks[0] = new Track("Chord track", true, grid * beatsPerBar, 8, true, true); | |
21 tracks[1] = new Track("Drums", true, grid * beatsPerBar, 8, false, true); | |
22 tracks[2] = new Track("Bass", true, grid * beatsPerBar, 8, false, true); | |
23 tracks[3] = new Track("Pizz Strings", true, grid * beatsPerBar, 8, false, true); | |
24 tracks[4] = new Track("Synth", true, grid * beatsPerBar, 8, false, true); | |
25 tracks[5] = new Track("Voice", true, grid * beatsPerBar, 8, false, true); | |
26 tracks[6] = new Track("Voice", true, grid * beatsPerBar, 8, false, true); | |
27 chordsTemp = new Track("Chord track", true, loopLength, 8, true, false); | |
28 trSelected = 1; | |
29 backgroundColour(); | |
30 drawLines(); | |
31 drawBarLines(); | |
32 imgNoteFan = createGraphics(fanWidth,imageHeight,P2D); | |
33 lastTrack = trSelected; | |
34 clickTrackOn = true; | |
35 // loadSequences(); | |
36 // tracks[2].sequence[15][16] = new NoteEvent (14, 2, bar,beat,fraction,pulse); | |
37 // tracks[2].sequence[15][grid * beatsPerBar -20] = new NoteEvent (14, 2, bar,beat,fraction,pulse, true); | |
38 | |
39 // tracks[3].sequence[13][16] = new NoteEvent (13, 3, bar,beat,fraction,pulse); | |
40 // tracks[3].sequence[13][20] = new NoteEvent (13, 3, bar,beat,fraction,pulse, true); | |
41 // tracks[3].sequence[12][16] = new NoteEvent (12, 3, bar,beat,fraction,pulse); | |
42 // tracks[3].sequence[12][20] = new NoteEvent (12, 3, bar,beat,fraction,pulse, true); | |
43 // tracks[3].sequence[11][16] = new NoteEvent (11, 3, bar,beat,fraction,pulse); | |
44 // tracks[3].sequence[11][20] = new NoteEvent (11, 3, bar,beat,fraction,pulse, true); | |
45 // tracks[3].sequence[10][16] = new NoteEvent (10, 3, bar,beat,fraction,pulse); | |
46 // tracks[3].sequence[10][20] = new NoteEvent (10, 3, bar,beat,fraction,pulse, true); | |
47 } | |
48 | |
49 | |
50 //------------------------------------------------------------------------------------------------------------------------------- | |
51 | |
52 void draw(){ | |
53 /* if (currentPulse % (grid * beatsPerBar) == grid * beatsPerBar -1){ | |
54 int tempTrackSelected = trSelected; | |
55 for (int j = 0; j < 16; j++){ | |
56 trSelected = j; | |
57 if (tracks[j] != null){ | |
58 for (int i = 0; i < 16; i++){ | |
59 noteOnArray[i] = false; | |
60 finishNote(i); | |
61 displayNoteOnArray[i] = false; | |
62 for (int z = 24; z < 109; z++) | |
63 outputToMax(z, 0, j); | |
64 } | |
65 tracks[j] = new Track(tracks[j].name, true, tracks[j].loopLength, tracks[j].quantize, false, false); | |
66 imgNotes = null; | |
67 } | |
68 } | |
69 trSelected = tempTrackSelected; | |
70 } | |
71 */ | |
72 // tracks[0] = new Track("Chord track", true, grid * beatsPerBar, 8, true, true); | |
73 // tracks[1] = new Track("Drums", true, grid * beatsPerBar, 8, false, true); | |
74 // tracks[2] = new Track("Bass", true, grid * beatsPerBar, 8, false, true); | |
75 // tracks[3] = new Track("Pizz Strings", true, grid * beatsPerBar, 8, false, true); | |
76 // tracks[4] = new Track("Synth", true, grid * beatsPerBar, 8, false, true); | |
77 // tracks[5] = new Track("Voice", true, grid * beatsPerBar, 8, false, true); | |
78 // } | |
79 workOutPosition(); // calculates current bar, beat and pulse position | |
80 //println(bar + " " + beat + " " + fraction + " " + pulse); | |
81 // if (chordAI && bar > 1) | |
82 // chordCalc(); | |
83 if (eraseOn) | |
84 eraseNotes(); | |
85 calcColours(); // calcs chord colours for background and grid | |
86 heresyChange = false; | |
87 heresyChordChanged = false; | |
88 if (trackStorer != trSelected){ // resets display when changing tracks | |
89 for (int i = 0; i < 16; i++) | |
90 if (noteOnArray[i] = true){ | |
91 noteOnArray[i] = false; | |
92 displayNoteOnArray[i] = false; | |
93 } | |
94 trackStorer = trSelected; | |
95 imgNotes = null; | |
96 } | |
97 if (imgNotes == null) | |
98 imgNotes = createGraphics(tracks[trSelected].loopLength,imageHeight,P2D); | |
99 background(0); | |
100 image (img,width-x2-playArea,0); | |
101 drawTempImageGrid(); | |
102 createNoteFan(); | |
103 drawNotes(); | |
104 fill (0); | |
105 noStroke(); | |
106 rect (width-playArea,0,playArea,height); | |
107 image (imgNoteFan, width-playArea+3,0); | |
108 pulseFrame(x); // Draws a pulsing white line at the left edge of the edit area | |
109 if (haveQuestion) writeQuestion(); // for input request messages | |
110 x++; // counter for grid movement | |
111 x2++; // counter for note image movement | |
112 if (x2 == width - playArea + grid * beatsPerBar) | |
113 x2 = width - playArea; | |
114 if (x == width - playArea + tracks[trSelected].loopLength) | |
115 x = width - playArea; | |
116 | |
117 | |
118 /* if (clickTrackOn){ // click track | |
119 if (fraction == 1){ | |
120 if (pulse == 1){ | |
121 String noteOut = ("37 80 1"); | |
122 link.output(noteOut); | |
123 } | |
124 if (pulse == 2){ | |
125 String noteOut = ("37 0 1" ); | |
126 link.output(noteOut); | |
127 } | |
128 } | |
129 } | |
130 */ | |
131 checkForMutes(); | |
132 checkCycled(); | |
133 playTrackEvents(); | |
134 | |
135 fill(255,255,255); | |
136 textSize(15); | |
137 text(bar + " " + beat + " " + fraction + " " + pulse, 10,20); // draws current time position to screen | |
138 | |
139 fill(200,0,0); | |
140 textSize(15); | |
141 // this section draws current track and track info to screen | |
142 if (tracks[trSelected].ducking) | |
143 text(tracks[trSelected].name + " ducking", 100,20); | |
144 else | |
145 text(tracks[trSelected].name, 100,20); | |
146 if (tracks[trSelected].muteIn > bar) | |
147 if (!tracks[trSelected].mute) | |
148 text("mute in " + (tracks[trSelected].muteIn - bar), 200,20); | |
149 else | |
150 text("unmute in " + (tracks[trSelected].muteIn - bar), 200,20); | |
151 | |
152 if (haveQuestion){ // asks input questions | |
153 writeQuestion(); | |
154 } | |
155 // println(currentPulse + " "); | |
156 | |
157 | |
158 currentPulse++; // advances the sequencer to next pulse | |
159 } | |
160 | |
161 | |
162 //------------------------------------------------------------------------------------------------------------------------------- | |
163 | |
164 void eraseNotes(){ // erases notes in current track if selected | |
165 if (trSelected != 0){ | |
166 for (int i = 0; i < 16; i++){ | |
167 if (tracks[trSelected].sequence[i][(currentPulse%(tracks[trSelected].loopLength))] != null){ | |
168 tracks[trSelected].sequence[i][(currentPulse%(tracks[trSelected].loopLength))] = null; | |
169 } | |
170 } | |
171 } | |
172 if (trSelected == 0){ | |
173 for (int i = 0; i < 16; i++){ | |
174 if (chordsTemp.sequence[i][(currentPulse%(tracks[trSelected].loopLength))] != null){ | |
175 chordsTemp.sequence[i][(currentPulse%(tracks[trSelected].loopLength))] = null; | |
176 } | |
177 } | |
178 } | |
179 } | |
180 | |
181 | |
182 //------------------------------------------------------------------------------------------------------------------------------- | |
183 | |
184 void workOutPosition(){ // works out current position | |
185 if (currentPulse%(grid*beatsPerBar) == 0) | |
186 ++bar; | |
187 if (currentPulse%grid == 0) | |
188 ++beat; | |
189 if (beat > beatsPerBar) | |
190 beat = 1; | |
191 if (currentPulse%(grid/fractions) == 0) | |
192 ++fraction; | |
193 if (fraction > fractions) | |
194 fraction = 1; | |
195 ++pulse; | |
196 if (pulse > (grid/fractions)) | |
197 pulse = 1; | |
198 } | |
199 | |
200 | |
201 //------------------------------------------------------------------------------------------------------------------------------- | |
202 | |
203 public void finishNote(int noteArrayPosition){ // writes note offs into the sequencers | |
204 if (trSelected != 0) | |
205 tracks[trSelected].sequence[noteArrayPosition][(currentPulse%(tracks[trSelected].loopLength))] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse, true); | |
206 if (trSelected == 0) | |
207 chordsTemp.sequence[noteArrayPosition][(currentPulse%(chordsTemp.loopLength))] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse, true); | |
208 displayNoteOnArray[noteArrayPosition] = false; | |
209 } | |
210 | |
211 public void finishNote(int noteArrayPosition, int channel){ // writes note offs into the sequencers | |
212 if (trSelected != 0) | |
213 tracks[trSelected].sequence[noteArrayPosition][(currentPulse%(tracks[trSelected].loopLength))] = new NoteEvent (noteArrayPosition, channel, bar,beat,fraction,pulse, true); | |
214 if (trSelected == 0) | |
215 chordsTemp.sequence[noteArrayPosition][(currentPulse%(chordsTemp.loopLength))] = new NoteEvent (noteArrayPosition, channel, bar,beat,fraction,pulse, true); | |
216 displayNoteOnArray[noteArrayPosition] = false; | |
217 } | |
218 | |
219 | |
220 //----------------------------------------------------------------------------------------------------------------------------- | |
221 | |
222 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 | |
223 tracks[lastTrack].sequence[noteArrayPosition][(currentPulse%(tracks[lastTrack].loopLength))] = new NoteEvent (noteArrayPosition, lastTrack+1, bar,beat,fraction,pulse, true); | |
224 } | |
225 | |
226 | |
227 //------------------------------------------------------------------------------------------------------------------------------- | |
228 | |
229 public void writeNote(int noteArrayPosition, int veloc){ // writes note ons into the sequencers | |
230 if (trSelected != 0){ | |
231 int quantizeOffset = getQuantizeOffset(); | |
232 if (quantizeOffset >= 0){ | |
233 tracks[trSelected].sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse); | |
234 } | |
235 if (quantizeOffset < 0){ | |
236 tracks[trSelected].sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse); | |
237 | |
238 VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNoteOn = true; | |
239 if (trSelected !=1 && trSelected !=5) | |
240 VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 3); | |
241 else | |
242 VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 1); | |
243 VPA[trSelected].VPArrayNotes[noteArrayPosition].VPNoteVelocity = veloc; | |
244 sendNote(VPA[trSelected].VPArrayNotes[noteArrayPosition], trSelected); | |
245 displayNoteOnArray[noteArrayPosition] = true; | |
246 | |
247 } | |
248 } | |
249 if (trSelected == 0){ | |
250 int quantizeOffset = getQuantizeOffset(); | |
251 if (quantizeOffset >= 0){ | |
252 chordsTemp.sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse); | |
253 } | |
254 if (quantizeOffset < 0){ | |
255 chordsTemp.sequence[noteArrayPosition][(currentPulse+quantizeOffset)%(tracks[trSelected].loopLength)] = new NoteEvent (noteArrayPosition, trSelected+1, bar,beat,fraction,pulse); | |
256 | |
257 if (noteArrayPosition > 3) | |
258 currentChord = 15 - noteArrayPosition; | |
259 displayNoteOnArray[noteArrayPosition] = true; | |
260 } | |
261 } | |
262 } | |
263 | |
264 public void writeNote(int noteArrayPosition, int veloc, int channel){ // writes note ons into the sequencers | |
265 VPA[channel].VPArrayNotes[noteArrayPosition].VPNoteOn = true; | |
266 VPA[channel].VPArrayNotes[noteArrayPosition].VPNotePitch = heresyPitch(noteArrayPosition, 1); | |
267 VPA[channel].VPArrayNotes[noteArrayPosition].VPNoteVelocity = veloc; | |
268 sendNote(VPA[channel].VPArrayNotes[noteArrayPosition], channel); | |
269 } | |
270 | |
271 | |
272 | |
273 | |
274 //------------------------------------------------------------------------------------------------------------------------------- | |
275 | |
276 public int getQuantizeOffset(){ // tells write note method the quantize offset. | |
277 int quantizeInPulses = pulsesPerBar/(tracks[trSelected].quantize); | |
278 int quantizeOffset = currentPulse % quantizeInPulses; | |
279 if (quantizeOffset > quantizeInPulses/2.0){ | |
280 return ((quantizeOffset - quantizeInPulses) * -1) ; | |
281 } | |
282 else{ | |
283 return quantizeOffset * -1; | |
284 } | |
285 } | |
286 | |
287 | |
288 |