# Goal: Store the state of midi presses from the APC 40 and send back messages to light pads. # This is to match the behavior of Drambo's clip launcher (which we can't get direct info from) # Setup: Drambo launcher should be set to stop clip on "swipe down", to disable stopping clips clicking an enabled one. # This script supports 5 patterns. An empty 6th one should also be created and mapped to the Clip Stop buttons. # # Logic: # - If row pad 1-5 are hit, we need to light that row and not anything else (ch1 82-86) # - If clearpad 1-8 are hit, we need to unlight that column (note 52, ch 1-8 # - If clearpad 9 (all) is hit, we need to unlight everything (ch 1 note 81) if load # lit pad array dimensions # actual array is I0-39. Matches bottom left to top right note values. # K0-2 are M aliases. Also KC # KF is a free variable alias K4 WIDTH alias K5 HEIGHT alias K6 OFF ASS WIDTH = $8 ASS HEIGHT = $5 #Color of off pads, all the same ASS OFF = $112 #Color of on pads, each one different ASS J0 = $41 $33 $22 $17 $9 $6 $57 $4 $41 $33 $22 $17 $9 $6 $57 $4 $41 $33 $22 $17 $9 $6 $57 $4 $41 $33 $22 $17 $9 $6 $57 $4 $41 $33 $22 $17 $9 $6 $57 $4 END ASS K0 = M0 ASS K1 = M1 ASS K2 = M2 ASS KC = MC BLOCK # detect note on and off messages on ch 1 channel IF K0 == 90 IF K1 != $52 #We handle this clearpad later IF K1 < $40 IF IK1 == 0 #If pad is off and we are turning it on... only we actually turn on after the note off ASS IK1 = 1 SND 90 K1 JK1 #Send our color ASS KF = 0 MAT KE = K1 % 8 #get remainder WHILE KF < $5 MAT KD = 8 * KF MAT KD = KD + KE IF KD != K1 ASS IKD = 0 SND 90 KD OFF #Send our color END MAT KF = KF + 1 end ELSE #Light the pad we are turning off until we let go #ASS IK1 = 0 SND 90 K1 JK1 #Send our color END ELSE IF K1 > $81 IF K1 < $87 #This sends all the pads in the row, light up the current row and turn off others ASS KF = 0 WHILE KF < $5 ASS KE = 0 WHILE KE < 8 MAT KD = KF * 8 MAT KD = KD + KE MAT KC = $86 - K1 IF KF == KC MAT KB = KD + 4 ASS IKD = 1 SND 90 KD JKD ELSE ASS IKD = 0 SND 90 KD OFF END MAT KE = KE + 1 END MAT KF = KF + 1 END END ELSE IF K1 == $81 #Send our all clear ASS KF = 0 WHILE KF < $40 ASS IKF = 0 SND 90 KF OFF MAT KF = KF + 1 END END END END END ELSE IF K0 == 80 #NOTE: We don't worry about setting the array here, its all done at note-on #We have to send the state again after a note off because the apc itself turns its pads off IF K1 < $40 #IF IK1 == 1 SND 90 K1 JK1 #Send our color #ELSE # SND 90 K1 OFF #END END END END IF K0 > 8F IF K0 < 99 IF K1 == $52 #Clearpads 1-8 ASS KF = 0 WHILE KF < $5 MAT KD = 8 * KF MAT KD = KD + KC ASS IKD = 0 SND 90 KD OFF #Send our color MAT KF = KF + 1 END END END END