Last active
March 11, 2020 19:20
-
-
Save hsitz/d169f84f60acd1cdaa59cd0650d87471 to your computer and use it in GitHub Desktop.
mozaic translation of accordion buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OnLoad | |
log { code version 0.1 } | |
counter = 0 | |
chordtype=0 | |
FillArray chordnote, -1, 10 | |
FillArray note_is_on, NO, 100 | |
DIM=1 | |
MAJ=2 | |
MIN=3 | |
SEVENTH=4 | |
@End | |
@OnMidiNote | |
chordnote[counter] = MIDIByte2 | |
if counter = 2 | |
chordtype=0 | |
interval1 = chordnote[1] - chordnote[0] | |
interval2 = chordnote[2] - chordnote[1] | |
// I think logic below works, but | |
// could be fleshed out with redundancies | |
// to make things clearer | |
if (interval1 % 3 = 0) and (interval2 % 4 = 0) | |
chordtype=MIN | |
elseif (interval1 % 3 = 0) | |
chordtype=DIM | |
elseif (interval2 % 6 = 0) | |
chordtype=SEVENTH | |
else | |
chordtype=MAJ | |
endif | |
endif | |
// we know if we've got a 7th or dim7 chord when | |
// counter=2, but we want to wait until counter=3 for those | |
if (chordtype=min) or (chordtype=maj) or (counter = 3) | |
// We have all the notes of the chord, | |
// whether it's 3 notes or 4 notes | |
call @ProcessChord | |
// reset, we won't know type of | |
//next chord until we get next chord's chordnote[2] | |
chordtype=0 | |
counter = 0 | |
else | |
inc counter // we don't have a full chord yet | |
endif | |
@END | |
@ProcessChord | |
if chordtype = MIN // root and 3rd | |
note1=chordnote[0]+12 | |
note2=chordnote[1]+12 | |
elseif chordtype = MAJ | |
note1 = chordnote[0]+4 | |
note2 = chordnote[0]+7 | |
elseif chordtype = SEVENTH // root, 3rd | |
note1 = chordnote[0] | |
note2 = chordnote[1] | |
elseif chordtype = DIM // | |
note1 = chordnote[0] | |
note2 = 0 | |
else | |
log { we're not supposed to get here } | |
endif | |
call @SendNoteCommands | |
@END | |
@SendNoteCommands | |
log {- } | |
log {---- entering @SendNoteCommands with chordtype }, chordtype | |
log {entering-note-1: command: }, MIDICommand, { note1: }, note1, { note is on?: }, note_is_on[note1] | |
log {entering-note-2: command: }, MIDICommand, { note2: }, note2, { note_is_on?: }, note_is_on[note2] | |
if MIDICommand = 144 // turn midi notes on | |
// if not already on | |
if note_is_on[note1] = NO | |
SendMIDIOut MIDIByte1, note1, MIDIByte3 | |
note_is_on[note1] = YES | |
log {turned note1 ( }, note1, {) ON.} | |
endif | |
if (note2 > 0) and (note_is_on[note2] = NO) | |
SendMIDIOut MIDIByte1, note2, MIDIByte3 | |
note_is_on[note2]=YES | |
log {turned note2 ( }, note2, {) ON.} | |
endif | |
else // Send Note Off command only if no chord is using note | |
if note_is_on[note1] = YES | |
SendMIDIOut MIDIByte1, note1, MIDIByte3 | |
note_is_on[note1] = NO | |
log {turned note1 ( }, note1, {) OFF.} | |
endif | |
if (note2 > 0) and (note_is_on[note2] = YES) | |
SendMIDIOut MIDIByte1, note2, MIDIByte3 | |
note_is_on[note2] = NO | |
log {turned note2 ( }, note2, {) OFF.} | |
endif | |
endif | |
log {exiting--note-1: }, note1, { note is on?: }, note_is_on[note1] | |
log {exiting-note-2: }, note2, { note_is_on?: }, note_is_on[note2] | |
@END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment