Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catching parsing errors for midi_cc_file.json #366

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions tulip/shared/py/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,28 +543,36 @@ def setup_midi_codes():
BUTTON_IDS = data['buttons']
#print('MIDI CC mappings read from', midi_cc_file)
except OSError: # Anticipating midi_cc_file not found.
#print('MIDI CC mappings file', midi_cc_file, 'not found.')
pass
except TypeError: # data is not a dict
pass
except KeyError: # data doesn't have one of the required things in it
pass

def setup_global_midi_cc_bindings():
"""Set up the global midi control code bindings, once the code arrays are set."""
global GLOBAL_MIDI_CC_BINDINGS
# My default connection of MIDI CCs to sequencer/arpeggiator
# to the Oxygen49 transport keys.
TEMPO_KNOB = KNOB_IDS[7] # Rightmost knob
ARP_ON_BTN = BUTTON_IDS[9] # C27, transport button
ARP_HOLD_BTN = BUTTON_IDS[10]
ARP_MODE_BTN = BUTTON_IDS[11]
ARP_RANGE_BTN = BUTTON_IDS[12]

GLOBAL_MIDI_CC_BINDINGS = {
TEMPO_KNOB: tempo_update,
# Some buttons send 0 on release, ignore that.
ARP_ON_BTN: lambda x: arp_on() if x else None,
ARP_HOLD_BTN: lambda x: arp_hold() if x else None,
ARP_MODE_BTN: lambda x: arp_mode_next() if x else None,
ARP_RANGE_BTN: lambda x: arp_rng_next() if x else None,
}
try:
TEMPO_KNOB = KNOB_IDS[7] # Rightmost knob
ARP_ON_BTN = BUTTON_IDS[9] # C27, transport button
ARP_HOLD_BTN = BUTTON_IDS[10]
ARP_MODE_BTN = BUTTON_IDS[11]
ARP_RANGE_BTN = BUTTON_IDS[12]

GLOBAL_MIDI_CC_BINDINGS = {
TEMPO_KNOB: tempo_update,
# Some buttons send 0 on release, ignore that.
ARP_ON_BTN: lambda x: arp_on() if x else None,
ARP_HOLD_BTN: lambda x: arp_hold() if x else None,
ARP_MODE_BTN: lambda x: arp_mode_next() if x else None,
ARP_RANGE_BTN: lambda x: arp_rng_next() if x else None,
}

except IndexError: # custom midi cc file did not specify buttons or knobs that go this high
print("Warning: we need at least 13 buttons and 8 knobs defined to automatically assign MIDI cc mappings")
GLOBAL_MIDI_CC_BINDINGS = {}


WARNED_MISSING_CHANNELS = set()
Expand Down
Loading