'{$STAMP BS2sx} '******************************************************* '** COWE (Controller, One With Everything) Controller '** test/demo code, by Perry R. Cook, 2003 '** Use anything you like in here '******************************************************* tempnib var nib tempbyte var byte tempword var word tilts var byte(2) lasttilts var byte(2) pots var byte(4) lastpots var byte(4) slider var byte breath var byte butts var byte keys var byte fsrpos var byte fsrforce var byte gosub initpins ' ALWAYS DO THIS VERY FIRST!!! channel = 0 ' bogusloop: ' gosub pributts ' debug ? butts ' goto bogusloop if in3 = 1 then testsort realsort: debug "1=ModalTrig {ATouch: 2=accel 3=FSR 4=Slider 5=Blow}", cr gosub pributts if butts=1 then modalbuttloop if butts=2 then shakerloop if butts=3 then fsrshake if butts=4 then slidershake if butts=5 then whistleblow goto realsort testsort: debug "1=butt 2=key 3=pot 4=fsr 5=tilt 6=breath", cr gosub pributts if butts=0 then testsort if butts=1 then testbutts if butts=2 then testkeys if butts=3 then testpots if butts=4 then testfsr if butts=5 then testtilt if butts=6 then testbreath goto testsort MODALNOTES data 60, 62, 64, 65, 67, 69, 71, 72 modalbuttloop: gosub getslider mbyte3 = slider gosub MIDIPots gosub pributts if butts>0 then buttNoteSortE if lastnote = 0 then buttNoteOuttahereE mbyte2 = lastnote gosub midioff lastnote = 0 goto buttNoteOuttahereE buttNoteSortE: '''''''' debug ? temp read MODALNOTES + butts-1, mbyte2 mbyte2 = mbyte2-12 if mbyte2 = lastnote then buttNoteOuttahereE if lastnote = 0 then buttnoteAlreadyOffE tempbyte = mbyte2 mbyte2 = lastnote gosub midioff mbyte2 = tempbyte buttnoteAlreadyOffE: ''''' debug ? mbyte2 gosub midion lastnote = mbyte2 buttNoteOuttahereE goto modalbuttloop '************* CONTROLLER MAP ********************' '** Order: pot0, 1, 2, 3, 4, fsr, jack, acc0,acc1 CONTMAP1 data 2, 1, 4, 11, 44, 11, 2, 2, 2 shakerloop: gosub gettilts tempword = lasttilts(0) - tilts(0) if tilts(0) < lasttilts(0) then nomidac0 tempword = tilts(0) - lasttilts(0) nomidac0: tempbyte = tempword * 2 '''' debug DEC tempword, " " tempword = lasttilts(1) - tilts(1) if tilts(1) < lasttilts(1) then nomidac1 tempword = tilts(1) - lasttilts(1) nomidac1: tempword = tempword * 2 if tempbyte > tempword then donemdacdel tempbyte = tempword donemdacdel: tempword = tempbyte '''' debug DEC tempword, " " if tempword < 4 then skipmdacupdate read CONTMAP1+7, mbyte2 gosub checklimit mbyte3 = tempword gosub midicont lasttilts(0) = tilts(0) lasttilts(1) = tilts(1) skipmdacupdate: '''' debug DEC tempword, cr pause 10 gosub shakpatch gosub MIDIPots goto shakerloop: fsrshake: gosub getfsr if fsrforce < 20 then fsrnoforce1 mbyte2 = fsrpos gosub miditouch '''' debug ? mbyte2 fsrnoforce1 gosub shakpatch gosub MIDIPots goto fsrshake slidershake: gosub getslider if slider = mbyte2 then skipslideshake mbyte2 = slider gosub miditouch '''' debug ? mbyte2 skipslideshake: gosub shakpatch gosub MIDIPots goto slidershake shakpatch: gosub pributts if butts = 0 then noshakpatch mbyte3 = 64 mbyte2 = butts-1 mbyte2 = mbyte2 + (8*in3) + (8*in4) gosub midion debug ? mbyte2 noshakpatch: return whistleblow: gosub getbreath mbyte2 = breath gosub miditouch gosub midipots goto whistleblow: checklimit: if tempword < 127 then limitok tempword = 127 limitok return MIDIPots: gosub getpots for tempnib = 0 to 3 tempword = pots(tempnib) - lastpots(tempnib) if pots(tempnib) > lastpots(tempnib) then skipnegpotsJ tempword = lastpots(tempnib) - pots(tempnib) skipnegpotsJ: if tempword < 1 then skipcontupdateJ read CONTMAP1+tempnib+1, mbyte2 mbyte3 = pots(tempnib) gosub midicont lastpots(tempnib) = pots(tempnib) skipcontupdateJ: next return testbutts: gosub midioff gosub getbutts debug "butts=", DEC butts, " ", DEC in3, " ", DEC in4, cr mbyte3 = 15 + ((butts & %11100000)>>1) mbyte2 = 84 - (butts & %00011111) - (12*in3) - (24*in4) gosub midion goto testbutts testkeys: gosub midioff gosub getbutts gosub getkeys mbyte3 = 64 mbyte2 = keys gosub midion debug "keys=", DEC keys, cr goto testkeys testpots: gosub midioff gosub getpots gosub getslider mbyte2 = pots(0) mbyte3 = pots(1) gosub midion pause slider + 10 gosub midioff gosub getpots mbyte2 = pots(2) mbyte3 = pots(3) gosub midion pause slider+10 debug "slidr=", DEC slider, " pots=" debug DEC pots(0), " ", DEC pots(1), " ", DEC pots(2), " ", DEC pots(3), cr goto testpots testfsr: gosub midioff gosub getfsr if fsrforce > 20 then testfsrenough debug "NoPress", cr goto testfsr testfsrenough: debug "fsr=", DEC fsrforce, " ", DEC fsrpos, cr mbyte2 = fsrpos mbyte3 = fsrforce gosub midion goto testfsr testtilt: gosub midioff gosub gettilts mbyte2 = tilts(0) mbyte3 = tilts(1) gosub midion debug "tilts=", DEC tilts(0), " ", DEC tilts(1), cr goto testtilt testbreath: gosub midioff gosub getbreath mbyte2 = breath mbyte3 = 64 gosub midion debug "breath=", DEC breath, cr goto testbreath '***********************************************************' ' GOOFY BOEHM FINGERING SYSTEM ON BUTTONS switchnotes data data 0, 2, 1, 3, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 7 data 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9 data 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11 data 12, 14, 13, 15, 16, 16, 16, 17, 18, 18, 18, 18, 18, 18, 18, 19 data 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 12 data 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 27 data 0, 2, 1, 3, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 7 data 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9 data 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11 data 12, 14, 13, 15, 16, 16, 16, 17, 18, 18, 18, 18, 18, 18, 18, 19 data 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 12 data 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40 data 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40 data 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40 data 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40 data 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40 getbutts: '''RETURN BINARY BUTTON PATTERN butts = 0 tempbyte = 1 for tempnib = 0 to 7 outC = tempnib butts = butts + (tempbyte * in5) tempbyte = tempbyte * 2 next return pributts: ''' PRIORITY ENCODE HIGHEST SET BIT (+1) butts = 0 for tempnib = 0 to 7 outC = tempnib ' debug DEC in5, " " if in5 = 0 then nobuttpri butts = tempnib + 1 nobuttpri: next ' debug cr ' pause 100 return getkeys: ' CALL GETBUTTS FIRST read switchnotes+butts,keys keys = 84 +- keys - (12*in3) - (24*in4) return '*********************************************************** ' MAXIM 1271 A/D STUFF CSpin con 11 ' clockpin con 12 ' synchronous clock pin to control MAXIM 1270 chip inputpin con 14 ' for reading data from MAXIM 1270 chip outputpin con 13 ' for sending the controlbyte to the MAX1270 chip msb con 1 ' mode for shiftout functions: msb behindclock con 2 ' mode for shiftin: msb post clock '*********************************************************** ' GET BREATH PRESS. control byte = 1 addr 10 01 0000 addr = 010 ADBreathcont con %101010010000 getbreath: shiftout outputpin, clockpin, msb, [ADBreathcont \ 12] shiftin inputpin, clockpin, behindclock, [tempword \ 12] breath = tempword >> 5 return '*********************************************************** ' GET FSR control byte = 1 addr 10 01 0000 addr=001 ADFSRcont con %100110010000 getfsr: output 1 high 1 output 2 low 2 shiftout outputpin, clockpin, msb, [ADFSRcont \ 12] shiftin inputpin, clockpin, behindclock, [tempword \ 12] fsrforce = 127 - (tempword >> 5) input 1 high 2 shiftout outputpin, clockpin, msb, [ADFSRcont \ 12] shiftin inputpin, clockpin, behindclock, [tempword \ 12] fsrpos = tempword >> 5 return '*********************************************************** ' GET POTS control byte = 1 addr 10 01 0000 addr = 100-111 ADPOTcont0 con %110010010000 ADPOTcont1 con %110110010000 ADPOTcont2 con %111010010000 ADPOTcont3 con %111110010000 getpots: shiftout outputpin, clockpin, msb, [ADPOTcont0 \ 12] shiftin inputpin, clockpin, behindclock, [tempword \ 12] pots(0) = tempword >> 5 shiftout outputpin, clockpin, msb, [ADPOTcont1 \ 12] shiftin inputpin, clockpin, behindclock, [tempword \ 12] pots(1) = tempword >> 5 shiftout outputpin, clockpin, msb, [ADPOTcont2 \ 12] shiftin inputpin, clockpin, behindclock, [tempword \ 12] pots(2) = tempword >> 5 shiftout outputpin, clockpin, msb, [ADPOTcont3 \ 12] shiftin inputpin, clockpin, behindclock, [tempword \ 12] pots(3) = tempword >> 5 return '*********************************************************** ' GET SLIDER control byte = 1 addr 10 01 0000 addr = 011 ADSLIDcont con %101110010000 getslider: shiftout outputpin, clockpin, msb, [ADSLIDcont \ 12] shiftin inputpin, clockpin, behindclock, [tempword \ 12] slider = tempword >> 5 return '*********************************************************** ' ADXL202 TILT (acceleration) SENSORS on Pins 6 and 7 ' ALL CONSTANTS HERE ARE HACKED TO THESE SPECIFIC COMPONENTS gettilts: pulsin 6,1,tempword if tempword > 350 then oklotiltx tempword = 350 oklotiltx: if tempword < 847 then okhitiltx tempword = 847 okhitiltx: tilts(0) = (tempword - 350) >> 2 pulsin 7,1,tempword if tempword > 230 then oklotilty tempword = 230 oklotilty: if tempword < 730 then okhitilty tempword = 730 okhitilty: tilts(1) = (tempword - 230) >> 2 return '*********************************************************** ' SETUP INPUT AND OUTPUT PINS initpins: input 1 output 2 input 3 input 4 input 5 input 6 input 7 output 8 output 9 output 10 output 11 output 12 output 13 input 14 output 15 high 15 return '******************************************************************** '***** USEFUL MIDI FUNCTIONS channel var nib mbyte2 var byte mbyte3 var byte lastnote var byte noteOn con 144 channel0 con 0 noteOff con 128 controlr con 176 atouch con 208 bender con 224 prgchang con 192 MIDIPIN con 15 MIDITIME con 60 '**** 12 for BS2, 60 for BS2SX *' '*** Standard Note On *' midion: serout MIDIPIN, MIDITIME, 0, [noteOn + channel, mbyte2, mbyte3] ' debug "NoteOn ", dec mbyte2, " ", dec mbyte3, cr return '*** Standard Note Off, uses real NoteOff status byte *' midioff: serout MIDIPIN, MIDITIME, 0, [noteOff + channel, mbyte2, 64] ' debug "NoteOff ", dec mbyte2, cr return '*** Monophonic aftertouch *' miditouch: serout MIDIPIN, MIDITIME, 0, [atouch + channel, mbyte2] ' debug "ATouch ", dec mbyte2, cr return '*** Send Bank Select first,then Program Number *' midiprog: serout MIDIPIN, MIDITIME, 0, [controlr + channel, 0, 0] serout MIDIPIN, MIDITIME, 0, [prgchang + channel, mbyte2] return '*** Standard Pitch Bend *' midibend: serout MIDIPIN, MIDITIME, 0, [bender + channel, 127, mbyte3] ' debug "Bender ", dec mbyte3, cr return '*** Control Change Message *' midicont: serout MIDIPIN, MIDITIME, 0, [controlr + channel, mbyte2, mbyte3] ' debug "Controller ", dec mbyte2, " ", dec mbyte3, cr return