'-------------------------------------------------------------------------- '-------------------------------------------------------------------------- ' Knee(Audio)Pads v1.0 ' by Elie Zananiri ' ez@prisonerjohn.com ' ' November 2004 '-------------------------------------------------------------------------- '-------------------------------------------------------------------------- ' initialize variables and constants noOfDrums CON 6 'to use in array initializations iLimit CON noOfDrums-1 'to use in for loops isOn CON 0 isOff CON 1 i VAR NIB midiOut CON 0 midiBaud CON 60 outPause CON 0 bendPot CON 15 bend VAR WORD oldBend VAR WORD velPot CON 14 vel VAR WORD vel = 120 maxLen CON 7 'max length of a note played longLen CON 0 drum0 VAR IN5 drum1 VAR IN6 drum2 VAR IN7 drum3 VAR IN8 drum4 VAR IN9 drum5 VAR IN10 INPUT 5 INPUT 6 INPUT 7 INPUT 8 INPUT 9 INPUT 10 notes VAR BYTE(noOfDrums) notes(0) = 40 notes(1) = 51 notes(2) = 64 notes(3) = 49 notes(4) = 36 notes(5) = 42 noteLen VAR BYTE(noOfDrums) noteGo VAR BIT(noOfDrums) 'boolean: has the pad been hit? FOR i=0 TO iLimit noteGo(i) = isOff NEXT notePlay VAR BIT(noOfDrums) 'boolean: is the note currently playing? FOR i=0 TO iLimit notePlay(i) = isOff NEXT '-------------------------------------------------------------------------- ' check which notes have been activated and call all subroutines to ' generate the MIDI signal mainLoop: IF (drum0 = isOn AND notePlay(0) = isOff) THEN noteGo(0) = isOn IF (drum1 = isOn AND notePlay(1) = isOff) THEN noteGo(1) = isOn IF (drum2 = isOn AND notePlay(2) = isOff) THEN noteGo(2) = isOn IF (drum3 = isOn AND notePlay(3) = isOff) THEN noteGo(3) = isOn IF (drum4 = isOn AND notePlay(4) = isOff) THEN noteGo(4) = isOn IF (drum5 = isOn AND notePlay(5) = isOff) THEN noteGo(5) = isOn GOSUB playNotes GOSUB decrementTime 'GOSUB getVel GOSUB getBend GOSUB killNotes GOTO mainLoop '-------------------------------------------------------------------------- ' turn on the notes that have been activated and send out the MIDI signal playNotes: FOR i=0 TO iLimit IF (noteGo(i) = isOn) THEN DEBUG CR, "note ", DEC i," on" noteLen(i) = maxLen IF (i = 4 OR i = 5) THEN noteLen(i) = noteLen(i)+longLen SEROUT midiOut, midiBaud, outPause, [$90, notes(i), vel] noteGo(i) = isOff notePlay(i) = isOn ENDIF NEXT RETURN '-------------------------------------------------------------------------- ' adjust the current playing time of each note decrementTime: FOR i=0 TO iLimit IF (noteLen(i) > 0 AND notePlay(i) = isOn) THEN noteLen(i) = noteLen(i) - 1 ENDIF NEXT RETURN '-------------------------------------------------------------------------- ' get the velocity and send it out through the MIDI channel getVel: HIGH velPot PAUSE 1 RCTIME velPot, 1, vel vel = vel//127 'DEBUG ? vel 'SEROUT midiOut, midiBaud, outPause, [$90, theNote, vel] RETURN '-------------------------------------------------------------------------- ' get the pitch bend and send it out through the MIDI channel getBend: oldBend = bend HIGH bendPot PAUSE 1 RCTIME bendPot, 1, bend bend = bend//127 IF (ABS(oldBend-bend) >= 5) THEN DEBUG CR, "pitch bend" SEROUT midiOut, midiBaud, outPause, [$E0, 127-bend, bend] ENDIF RETURN '-------------------------------------------------------------------------- ' turn off the notes that have been on for the max length of time and send ' out the corresponding MIDI signal killNotes: FOR i=0 TO iLimit IF (noteLen(i) = 0 AND notePlay(i) = isOn) THEN DEBUG CR, "note ", DEC i, " off" notePlay(i) = isOff SEROUT midiOut, midiBaud, outPause, [$90, notes(i), 0] ENDIF NEXT RETURN