Ok here is my first code attempt at midi. The note and octave are read into the adc from a 16 channel sequencer that sequences a set of pots for each channel that select note and octave. The note lenght is a pot to let you say how long a note will be. I will have to tie this to the sequencer step in some way. Not done yet.
The code just reads the adc's and then first looks a the octave and then goes sub to the octave to selectthe note. It then sends out a serial command to turn the note on at a a certain velocity, wait for the note lenght, turn the note off and set velocity to zero. Do it goes home and looks for the next note. Question is did I setup the HSEROUT data correctly?
There are ten octaves. I truncated them in the post because they just repeat and the post was too long.
The code just reads the adc's and then first looks a the octave and then goes sub to the octave to selectthe note. It then sends out a serial command to turn the note on at a a certain velocity, wait for the note lenght, turn the note off and set velocity to zero. Do it goes home and looks for the next note. Question is did I setup the HSEROUT data correctly?
There are ten octaves. I truncated them in the post because they just repeat and the post was too long.
Code:
#picaxe 28x2
let dirsB = %11111111
let adcsetup = 0
symbol NOTE= w0 ;[C=0-50,c#=75-125, D=150-200, D#=225-275, E=300-350, F=375-425, F#=450-
symbol OCTAVE= w1 ;10 Ocatves[Oct0=0-50,Oct1=75-125, Oct2=150-200, Oct3=225-275, Oct4=300-
symbol NOTE_OCTAVE= b5 ;final selected midi note
symbol NOTE_ON= b6 ;midi note on channel 1 0x80
symbol NOTE_OFF= b7 ;midi note off channel 1 0x90
symbol NOTE_VELOCITY= b8 ;midi note velocity (0-127)
symbol NOTE_LENGTH= w5 ;note lenght
LET NOTE_ON= 128 ;all midi command in decimal
LET NOTE_OFF= 144
LET NOTE_VELOCITY= 64
HSERSETUP B31250_8,%10000 ;setup serial port to send at 31250 at 8 mhz
Main:
readadc10 a.0, NOTE ;read NOTE POT
readadc10 a.1, OCTAVE ;read OCTAVE POT
readadc10 a.2, NOTE_LENGTH ;read Note length pot (might change to reading CS change)
;OCTAVE SELECTION
IF OCTAVE=>0 and OCTAVE<50 Then goto OCTAVE_zero ;select the correct OCTAVE
IF OCTAVE>75 and OCTAVE<125 Then goto OCTAVE_one
IF OCTAVE>150 and OCTAVE<200 Then goto OCTAVE_two
IF OCTAVE>225 and OCTAVE<275 Then goto OCTAVE_three
IF OCTAVE>300 and OCTAVE<350 Then goto OCTAVE_four
IF OCTAVE>375 and OCTAVE<425 Then goto OCTAVE_five
IF OCTAVE>450 and OCTAVE<500 Then goto OCTAVE_six
IF OCTAVE>525 and OCTAVE<575 Then goto OCTAVE_seven
IF OCTAVE>600 and OCTAVE<650 Then goto OCTAVE_eight
IF OCTAVE>675 and OCTAVE<725 Then goto OCTAVE_nine
IF OCTAVE>750 and OCTAVE<800 Then goto OCTAVE_ten
;NOTE SELECTION IN OCTAVE
OCTAVE_zero:
IF NOTE=>0 and note <50 Then LET NOTE_OCTAVE=0 :ENDIF
IF NOTE=>75 and note <125 Then LET NOTE_OCTAVE=1 :ENDIF
IF NOTE=>150 and note <200 Then LET NOTE_OCTAVE=2 :ENDIF
IF NOTE=>225 and note <275 Then LET NOTE_OCTAVE=3 :ENDIF
IF NOTE=>300 and note <350 Then LET NOTE_OCTAVE=4 :ENDIF
IF NOTE=>375 and note <425 Then LET NOTE_OCTAVE=5 :ENDIF
IF NOTE=>450 and note <500 Then LET NOTE_OCTAVE=6 :ENDIF
IF NOTE=>525 and note <575 Then LET NOTE_OCTAVE=7 :ENDIF
IF NOTE=>600 and note <650 Then LET NOTE_OCTAVE=8 :ENDIF
IF NOTE=>675 and note <725 Then LET NOTE_OCTAVE=9 :ENDIF
IF NOTE=>750 and note <800 Then LET NOTE_OCTAVE=10:ENDIF
IF NOTE=>825 and note<875 Then LET NOTE_OCTAVE=11:ENDIF
HSEROUT 0,(NOTE_ON,NOTE_OCTAVE,NOTE_VELOCITY) ;send not on, note value, note velocity
Pause NOTE_LENGTH ;wait till next note
HSEROUT 0,(NOTE_OFF,NOTE_OCTAVE,0) ;turn off note set velocity to 0
GOTO MAIN ;go home and look for next note
OCTAVE_one:
IF NOTE=>0 and note <50 Then LET NOTE_OCTAVE=12 :ENDIF
IF NOTE=>75 and note <125 Then LET NOTE_OCTAVE=13 :ENDIF
IF NOTE=>150 and note <200 Then LET NOTE_OCTAVE=14 :ENDIF
IF NOTE=>225 and note <275 Then LET NOTE_OCTAVE=15 :ENDIF
IF NOTE=>300 and note <350 Then LET NOTE_OCTAVE=16 :ENDIF
IF NOTE=>375 and note <425 Then LET NOTE_OCTAVE=17 :ENDIF
IF NOTE=>450 and note <500 Then LET NOTE_OCTAVE=18 :ENDIF
IF NOTE=>525 and note <575 Then LET NOTE_OCTAVE=19 :ENDIF
IF NOTE=>600 and note <650 Then LET NOTE_OCTAVE=20 :ENDIF
IF NOTE=>675 and note <725 Then LET NOTE_OCTAVE=21 :ENDIF
IF NOTE=>750 and note <800 Then LET NOTE_OCTAVE=22:ENDIF
IF NOTE=>825 and note<875 Then LET NOTE_OCTAVE=23:ENDIF
HSEROUT 0,(NOTE_ON,NOTE_OCTAVE,NOTE_VELOCITY) ;send not on, note value, note velocity
Pause NOTE_LENGTH ;wait till next note
HSEROUT 0,(NOTE_OFF,NOTE_OCTAVE,0) ;turn off note set velocity to 0
GOTO MAIN
;go home and look for next note
OCTAVE_two:
IF NOTE=>0 and NOTE <50 Then LET NOTE_OCTAVE=24 :ENDIF
IF NOTE=>75 and note <125 Then LET NOTE_OCTAVE=25 :ENDIF
IF NOTE=>150 and note <200 Then LET NOTE_OCTAVE=26 :ENDIF
IF NOTE=>225 and note <275 Then LET NOTE_OCTAVE=27 :ENDIF
IF NOTE=>300 and note <350 Then LET NOTE_OCTAVE=28 :ENDIF
IF NOTE=>375 and note <425 Then LET NOTE_OCTAVE=29 :ENDIF
IF NOTE=>450 and note <500 Then LET NOTE_OCTAVE=30 :ENDIF
IF NOTE=>525 and note <575 Then LET NOTE_OCTAVE=31 :ENDIF
IF NOTE=>600 and note <650 Then LET NOTE_OCTAVE=32 :ENDIF
IF NOTE=>675 and note <725 Then LET NOTE_OCTAVE=33 :ENDIF
IF NOTE=>750 and note <800 Then LET NOTE_OCTAVE=34:ENDIF
IF NOTE=>825 and note<875 Then LET NOTE_OCTAVE=35:ENDIF
HSEROUT 0,(NOTE_ON,NOTE_OCTAVE,NOTE_VELOCITY) ;send not on, note value, note velocity
Pause NOTE_LENGTH ;wait till next note
HSEROUT 0,(NOTE_OFF,NOTE_OCTAVE,0) ;turn off note set velocity to 0
GOTO MAIN
;go home and look for next note
OCTAVE_three:
IF NOTE=>0 and NOTE <50 Then LET NOTE_OCTAVE=36 :ENDIF
IF NOTE=>75 and note <125 Then LET NOTE_OCTAVE=37 :ENDIF
IF NOTE=>150 and note <200 Then LET NOTE_OCTAVE=38 :ENDIF
IF NOTE=>225 and note <275 Then LET NOTE_OCTAVE=39 :ENDIF
IF NOTE=>300 and note <350 Then LET NOTE_OCTAVE=40 :ENDIF
IF NOTE=>375 and note <425 Then LET NOTE_OCTAVE=41 :ENDIF
IF NOTE=>450 and note <500 Then LET NOTE_OCTAVE=42 :ENDIF
IF NOTE=>525 and note <575 Then LET NOTE_OCTAVE=43 :ENDIF
IF NOTE=>600 and note <650 Then LET NOTE_OCTAVE=44 :ENDIF
IF NOTE=>675 and note <725 Then LET NOTE_OCTAVE=45 :ENDIF
IF NOTE=>750 and note <800 Then LET NOTE_OCTAVE=46:ENDIF
IF NOTE=>825 and note<875 Then LET NOTE_OCTAVE=47:ENDIF
HSEROUT 0,(NOTE_ON,NOTE_OCTAVE,NOTE_VELOCITY) ;send not on, note value, note velocity
Pause NOTE_LENGTH ;wait till next note
HSEROUT 0,(NOTE_OFF,NOTE_OCTAVE,0) ;turn off note set velocity to 0
GOTO MAIN
;go home and look for next note
OCTAVE_four:
IF NOTE=>0 and NOTE <50 Then LET NOTE_OCTAVE=48 :ENDIF
IF NOTE=>75 and note <125 Then LET NOTE_OCTAVE=49 :ENDIF
IF NOTE=>150 and note <200 Then LET NOTE_OCTAVE=50 :ENDIF
IF NOTE=>225 and note <275 Then LET NOTE_OCTAVE=51 :ENDIF
IF NOTE=>300 and note <350 Then LET NOTE_OCTAVE=52 :ENDIF
IF NOTE=>375 and note <425 Then LET NOTE_OCTAVE=53 :ENDIF
IF NOTE=>450 and note <500 Then LET NOTE_OCTAVE=54 :ENDIF
IF NOTE=>525 and note <575 Then LET NOTE_OCTAVE=55 :ENDIF
IF NOTE=>600 and note <650 Then LET NOTE_OCTAVE=56 :ENDIF
IF NOTE=>675 and note <725 Then LET NOTE_OCTAVE=57 :ENDIF
IF NOTE=>750 and note <800 Then LET NOTE_OCTAVE=58:ENDIF
IF NOTE=>825 and note<875 Then LET NOTE_OCTAVE=59:ENDIF
HSEROUT 0,(NOTE_ON,NOTE_OCTAVE,NOTE_VELOCITY) ;send not on, note value, note velocity
Pause NOTE_LENGTH ;wait till next note
HSEROUT 0,(NOTE_OFF,NOTE_OCTAVE,0) ;turn off note set velocity to 0
GOTO MAIN
;go home and look for next note
;go home and look for next note