andrew@50: void sendNote(VPNote note, int channel){ // send note function gathers info to output to max andrew@50: outputToMax(note.VPNotePitch, note.VPNoteVelocity, channel); andrew@50: } andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: void outputToMax(int note, int velocity, int channel){ // calculates the necessary note on and note offs depending on ducking and muting and sends them to max andrew@50: String noteOut = ""; andrew@50: if (!tracks[channel].mute){ andrew@50: if (tracks[channel].ducking){ andrew@50: if (velocity != 0){ andrew@50: noteOut = ("" + note + " " + velocity + " " + (channel+8)); andrew@50: } andrew@50: if (velocity == 0 && !tracks[channel].cycled){ andrew@50: noteOut = ("" + note + " " + velocity + " " + (channel+8)); andrew@50: OscMessage message = new OscMessage("/pitch_vel_chan"); andrew@50: message.add(noteOut); andrew@50: oscP5return.send(message, ableton); andrew@50: link.output(noteOut); andrew@50: noteOut = ("" + note + " " + velocity + " " + channel); andrew@50: } andrew@50: if (velocity == 0 && tracks[channel].cycled){ andrew@50: noteOut = ("" + note + " " + velocity + " " + (channel+8)); andrew@50: } andrew@50: } andrew@50: if (!tracks[channel].ducking){ andrew@50: if (velocity != 0){ andrew@50: noteOut = ("" + note + " " + velocity + " " + channel); andrew@50: } andrew@50: if (velocity == 0 && !tracks[channel].cycled){ andrew@50: noteOut = ("" + note + " " + velocity + " " + (channel+8)); andrew@50: OscMessage message = new OscMessage("/pitch_vel_chan"); andrew@50: message.add(noteOut); andrew@50: oscP5return.send(message, ableton); andrew@50: link.output(noteOut); andrew@50: noteOut = ("" + note + " " + velocity + " " + channel); andrew@50: } andrew@50: if (velocity == 0 && tracks[channel].cycled){ andrew@50: noteOut = ("" + note + " " + velocity + " " + channel); andrew@50: } andrew@50: } andrew@50: link.output(noteOut); andrew@50: OscMessage message = new OscMessage("/pitch_vel_chan"); andrew@50: message.add(noteOut); andrew@50: oscP5return.send(message, ableton); andrew@50: andrew@50: } andrew@50: if (tracks[channel].mute){ andrew@50: if (velocity == 0 && !tracks[channel].cycled){ andrew@50: noteOut = ("" + note + " " + velocity + " " + (channel+8)); andrew@50: link.output(noteOut); andrew@50: OscMessage message = new OscMessage("/pitch_vel_chan"); andrew@50: message.add(noteOut); andrew@50: oscP5return.send(message, ableton); andrew@50: noteOut = ("" + note + " " + velocity + " " + channel); andrew@50: OscMessage message2 = new OscMessage("/pitch_vel_chan"); andrew@50: message2.add(noteOut); andrew@50: oscP5return.send(message, ableton); andrew@50: link.output(noteOut); andrew@50: } andrew@50: } andrew@50: } andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: void mouseDragged(){ // not used andrew@50: } andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: void mouseReleased(){ // not used andrew@50: } andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: void mousePressed(){ // not used andrew@50: } andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: void keyPressed() { // takes keyboard input andrew@50: if (key == 'c' || key == 'C') { andrew@50: chordSelecter = !chordSelecter; andrew@50: if (!chordSelecter) andrew@50: trSelected = lastTrack; andrew@50: else{ andrew@50: lastTrack = trSelected; andrew@50: trSelected = 0; andrew@50: andrew@50: } andrew@50: } andrew@50: andrew@50: if (key == ' ') { andrew@50: if (trSelected != 0){ andrew@50: for (int i = 0; i < 16; i++){ andrew@50: noteOnArray[i] = false; andrew@50: finishNote(i); andrew@50: displayNoteOnArray[i] = false; andrew@50: } andrew@50: andrew@50: if (trSelected != 0){ andrew@50: for (int i = 24; i < 109; i++) andrew@50: outputToMax(i, 0, trSelected); andrew@50: } andrew@50: tracks[trSelected] = new Track(tracks[trSelected].name, true, tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false); andrew@50: imgNotes = null; andrew@50: } andrew@50: andrew@50: if (trSelected == 0){ andrew@50: for (int i = 0; i < 16; i++){ andrew@50: noteOnArray[i] = false; andrew@50: finishNote(i); andrew@50: displayNoteOnArray[i] = false; andrew@50: } andrew@50: heresyMinor = false; andrew@50: heresy7th = false; andrew@50: heresy9th = false; andrew@50: heresy11th = false; andrew@50: heresy13th = false; andrew@50: chordsTemp = new Track(tracks[trSelected].name, true, tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false); andrew@50: imgNotes = null; andrew@50: } andrew@50: } andrew@50: andrew@50: if (key == 'p' || key == 'P') { andrew@50: for (int i = 0; i < 16; i++){ andrew@50: for (int ii = 24; ii < 109; ii++) andrew@50: outputToMax(ii, 0, trSelected); andrew@50: noteOnArray[i] = false; andrew@50: displayNoteOnArray[i] = false; andrew@50: } andrew@50: } andrew@50: andrew@50: if (key == 'd' || key == 'D') { andrew@50: if (trSelected != 0 && trSelected != 1){ andrew@50: tracks[trSelected].ducking = !tracks[trSelected].ducking; andrew@50: tracks[trSelected].cycled = false; andrew@50: tracks[trSelected].cycledPosition = currentPulse%tracks[trSelected].loopLength; andrew@50: } andrew@50: } andrew@50: andrew@50: if (key == 'w' || key == 'W') { andrew@50: andrew@50: trSelected = 0; andrew@50: andrew@50: for (int i = 0; i < 16; i++){ andrew@50: noteOnArray[i] = false; andrew@50: finishNoteCutOff(i); andrew@50: displayNoteOnArray[i] = false; andrew@50: } andrew@50: heresyMinor = false; andrew@50: heresy7th = false; andrew@50: heresy9th = false; andrew@50: heresy11th = false; andrew@50: heresy13th = false; andrew@50: andrew@50: tracks[trSelected] = new Track(tracks[trSelected].name, true, tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false); andrew@50: chordsTemp = new Track(tracks[trSelected].name, true, tracks[trSelected].loopLength, tracks[trSelected].quantize, false, false); andrew@50: imgNotes = null; andrew@50: } andrew@50: andrew@50: if (key == 'q' || key == 'Q'){ andrew@50: quantizeValueIn = true; andrew@50: sendToScreen(tracks[trSelected].name + " quantize?"); andrew@50: } andrew@50: andrew@50: if (key == 'x' || key == 'X'){ andrew@50: clickTrackOn = !clickTrackOn; andrew@50: } andrew@50: andrew@50: if (key == 'e' || key == 'E'){ andrew@50: eraseOn = !eraseOn; andrew@50: if (!eraseOn) imgNotes = null; andrew@50: } andrew@50: andrew@50: if (key == 'r' || key == 'R'){ andrew@50: imgNotes = null; andrew@50: } andrew@50: andrew@50: if (key == 'l' || key == 'L'){ andrew@50: loopLengthValueIn = true; andrew@50: sendToScreen(tracks[trSelected].name + " loop length?"); andrew@50: } andrew@50: andrew@50: if (key == 'm' || key == 'M'){ andrew@50: if (trSelected != 0){ andrew@50: muteValueIn = true; andrew@50: if (!tracks[trSelected].mute) andrew@50: sendToScreen(tracks[trSelected].name + " mute in?"); andrew@50: if (tracks[trSelected].mute) andrew@50: sendToScreen(tracks[trSelected].name + " unmute in?"); andrew@50: } andrew@50: } andrew@50: andrew@50: andrew@50: if (key == '1') numberKey(1); andrew@50: if (key == '2') numberKey(2); andrew@50: if (key == '3') numberKey(3); andrew@50: if (key == '4') numberKey(4); andrew@50: if (key == '5') numberKey(5); andrew@50: if (key == '6') numberKey(6); andrew@50: if (key == '7') numberKey(7); andrew@50: if (key == '8') numberKey(8); andrew@50: if (key == '9') numberKey(9); andrew@50: if (key == '0') numberKey(0); andrew@50: andrew@50: if (key == CODED) { andrew@50: if (keyCode == UP && trSelected < Track.currentNumberOfTracks-1) andrew@50: trSelected++; andrew@50: if (keyCode == DOWN && trSelected > 1) { andrew@50: trSelected--; andrew@50: } andrew@50: } andrew@50: andrew@50: if (key == 's' || key == 'S'){ andrew@50: for (int i = 0; i < 16; i++){ andrew@50: for (int ii = 0; ii < tracks[0].loopLength; ii++){ andrew@50: if (chordsTemp.sequence[i][ii] != null) andrew@50: tracks[0].sequence[i][ii] = chordsTemp.sequence[i][ii]; andrew@50: } andrew@50: } andrew@50: } andrew@50: andrew@50: andrew@50: } andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: void numberKey(int input){ // if a number is enterd, this method works out what to do with it andrew@50: if (quantizeValueIn == true) andrew@50: if (input == 1 || input == 2 || input == 4 || input == 8 || input == 0){ andrew@50: tracks[trSelected].quantize = input; andrew@50: quantizeValueIn = false; andrew@50: aniOut = true; andrew@50: } andrew@50: andrew@50: if (loopLengthValueIn == true){ andrew@50: if (input >= 1 && input <= 8 ){ andrew@50: Track tempTrack = new Track(tracks[trSelected].name, tracks[trSelected].polyphonic, (input * loopLength / 2), tracks[trSelected].quantize, false, false); andrew@50: NoteEvent tempNote; andrew@50: andrew@50: for (int i = 0; i < 16; i++){ andrew@50: if (tempTrack.loopLength >= tracks[trSelected].loopLength){ andrew@50: for (int ii = 0; ii < tracks[trSelected].loopLength; ii++){ andrew@50: tempTrack.sequence[i][ii] = tracks[trSelected].sequence[i][ii]; andrew@50: } andrew@50: }else{ andrew@50: for (int ii = 0; ii < tempTrack.loopLength; ii++){ andrew@50: tempTrack.sequence[i][ii] = tracks[trSelected].sequence[i][ii]; andrew@50: } andrew@50: } andrew@50: } andrew@50: tracks[trSelected] = tempTrack; andrew@50: for (int i = 0; i < 16; i++) andrew@50: if (noteOnArray[i] = true){ andrew@50: noteOnArray[i] = false; andrew@50: finishNoteCutOff(i); andrew@50: displayNoteOnArray[i] = false; andrew@50: } andrew@50: andrew@50: andrew@50: loopLengthValueIn = false; andrew@50: aniOut = true; andrew@50: if (trSelected ==0){ andrew@50: Track tempTrack2 = new Track(chordsTemp.name, chordsTemp.polyphonic, (input * loopLength / 2), chordsTemp.quantize, false, false); andrew@50: NoteEvent tempNote2; andrew@50: andrew@50: for (int i = 0; i < 16; i++){ andrew@50: if (tempTrack2.loopLength >= chordsTemp.loopLength){ andrew@50: for (int ii = 0; ii < chordsTemp.loopLength; ii++){ andrew@50: tempTrack2.sequence[i][ii] = chordsTemp.sequence[i][ii]; andrew@50: } andrew@50: }else{ andrew@50: for (int ii = 0; ii < tempTrack2.loopLength; ii++){ andrew@50: tempTrack2.sequence[i][ii] = chordsTemp.sequence[i][ii]; andrew@50: } andrew@50: } andrew@50: } andrew@50: chordsTemp = tempTrack2; andrew@50: } andrew@50: imgNotes = null; andrew@50: } andrew@50: } andrew@50: andrew@50: if (muteValueIn == true){ andrew@50: tracks[trSelected].muteIn = bar + input; andrew@50: muteValueIn = false; andrew@50: tracks[trSelected].muteDone = false; andrew@50: aniOut = true; andrew@50: } andrew@50: andrew@50: andrew@50: } andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: void sendToScreen(String name){ // prepares a question for asking the user and turns the question on andrew@50: andrew@50: screenQuestion = name; andrew@50: screenAni = 0; andrew@50: haveQuestion = true; andrew@50: andrew@50: } andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: void checkCycled(){ // checks whether after ducking or muting all note offs are played. andrew@50: for (int i = 1; i < Track.currentNumberOfTracks; i++) andrew@50: if (tracks[i].cycled == false) andrew@50: if (tracks[i].cycledPosition-1 == currentPulse%tracks[trSelected].loopLength) andrew@50: tracks[i].cycled = true; andrew@50: andrew@50: } andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: andrew@50: void checkForMutes(){ // looks for mute / unmuted changes in tracks andrew@50: for (int i = 1; i < Track.currentNumberOfTracks; i++) andrew@50: if (tracks[i].muteIn == bar && !tracks[i].muteDone){ andrew@50: tracks[i].mute = !tracks[i].mute; andrew@50: tracks[i].muteDone = true; andrew@50: tracks[trSelected].cycled = false; andrew@50: tracks[trSelected].cycledPosition = currentPulse%tracks[trSelected].loopLength; andrew@50: } andrew@50: } andrew@50: andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: void writeQuestion(){ // animates screen questions andrew@50: andrew@50: if (screenAni < 10 && !aniOut){ andrew@50: screenAni++; andrew@50: } andrew@50: andrew@50: if (screenAni > 0 && aniOut){ andrew@50: screenAni--; andrew@50: } andrew@50: andrew@50: if (screenAni == 0){ andrew@50: haveQuestion = false; andrew@50: aniOut = false; andrew@50: } andrew@50: andrew@50: fill(255,0,0, screenAni*12); andrew@50: textSize((11-screenAni)*40); andrew@50: text(screenQuestion, (screenAni*50)-200,(100-screenAni*10)+150); andrew@50: andrew@50: andrew@50: } andrew@50: andrew@50: andrew@50: //------------------------------------------------------------------------------------------------------------------------------- andrew@50: andrew@50: void oscEvent(OscMessage theOscMessage) { // recieves osc messages from openFrameworks andrew@50: println("osc message : " + theOscMessage); andrew@50: if(theOscMessage.checkAddrPattern("/test")==true) { andrew@50: println("i1 : " + theOscMessage.get(1).intValue() + " i2 : " + theOscMessage.get(2).intValue() + " i3 : " + theOscMessage.get(3).intValue() + " i4 : " + theOscMessage.get(4).intValue()); andrew@50: clickTrack = false; andrew@50: String stringValue = theOscMessage.get(0).stringValue(); andrew@50: int firstValue = theOscMessage.get(1).intValue(); andrew@50: int secondValue = theOscMessage.get(2).intValue(); andrew@50: int thirdValue = theOscMessage.get(3).intValue(); //velocity andrew@50: int fourthValue = theOscMessage.get(4).intValue(); //channel andrew@50: if (secondValue == 1){ andrew@50: noteOnArray[firstValue] = true; andrew@50: writeNote(firstValue, thirdValue, fourthValue); andrew@50: } andrew@50: else{ andrew@50: noteOnArray[firstValue] = false; andrew@50: writeNote(firstValue, 0, fourthValue); andrew@50: } andrew@50: } andrew@50: if(theOscMessage.checkAddrPattern("/chord")==true) { andrew@50: chordCalc(); andrew@50: // writeNote(15, 80, 6); andrew@50: writeNote(14, 80, 6); andrew@50: writeNote(13, 80, 6); andrew@50: writeNote(12, 80, 6); andrew@50: writeNote(11, 80, 6); andrew@50: writeNote(10, 80, 6); andrew@50: writeNote(9, 80, 6); andrew@50: } andrew@50: } andrew@50: andrew@50: andrew@50: