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