Last active
July 1, 2018 06:11
-
-
Save mxmilkiib/71e9db96337711c3fad8d4d02881ce02 to your computer and use it in GitHub Desktop.
mididings script - scene_1 maps nanokontrol2 s/m/r button leds to the first three rows in seq64. subscenes of scene_2 are for channel strip effects.
This file contains hidden or 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
#!/usr/bin/env python | |
# m_ctrl.py - mididings things | |
# scene_1 maps s/m/r buttons to seq64 pattern grid | |
# scene_2 to map control to a channel strip | |
# http://dsacre.github.io/mididings/doc/genindex.html | |
from mididings import * | |
# for sending LED scene changes | |
from mididings.event import CtrlEvent | |
# for sending out CtrlEvent in a function and scene support | |
from mididings.engine import output_event, scenes, current_subscene, switch_scene | |
# for livedings | |
from mididings.extra.osc import OSCInterface | |
# for generating the list of nano button CCs | |
from itertools import chain | |
# for easier to grok error messages | |
#import colored_traceback | |
# colored_traceback.add_hook() | |
hook( | |
OSCInterface(port=56700, notify_ports=[56701]) | |
) | |
config( | |
# backend='jack-rt', | |
backend='jack', | |
client_name='nanokontrol2-ctrl', | |
in_ports=[('nanokontrol2', 'system:midi_capture_6')], | |
out_ports=[ | |
('nanoctrl', 'system:midi_playback_6', 'midi-monitor:input'), | |
'seq64ctrl', | |
'strip_1', | |
'strip_2', | |
'strip_3', | |
'strip_4', | |
'strip_5', | |
'strip_6', | |
'strip_7', | |
'strip_8'], | |
initial_scene=1 | |
) | |
# generate a list of nanocontrol2 solo/mute/record button CCs | |
nanokontrol2_seq64_map = chain(range(32, 39), range(48, 55), range(64, 71)) | |
nanokontrol2_seq64_map = list(nanokontrol2_seq64_map) | |
# create dictionary and map nanokontrol2 button grid cc numbers | |
midi_toggles_on = {} | |
for x in nanokontrol2_seq64_map: | |
midi_toggles_on[x] = False | |
# state for strip subscenes - not used yet | |
# create dictionary and map nanokontrol2 s/m/r button cc numbers for channel strip mapping | |
# strip_toggles_on = {} | |
# for y in range(1,8): | |
# strip_toggles_on[y] = {} | |
# for x in nanokontrol2_seq64_map: | |
# strip_toggles_on[y][x] = False | |
def toggle_nanokontrol2(event): | |
""" flip the state of process solo/mute/record button LEDs """ | |
if event.ctrl in nanokontrol2_seq64_map and event.value != 0: | |
if event.type is CTRL and midi_toggles_on[event.ctrl] is False: | |
event.value = 127 | |
midi_toggles_on[event.ctrl] = True | |
elif event.type is CTRL and midi_toggles_on[event.ctrl] is True: | |
event.value = 0 | |
midi_toggles_on[event.ctrl] = False | |
else: | |
return | |
return event | |
def clear_nanokontrol2(dummy): | |
""" set all nano s/m/r button LEDs to off """ | |
return [ | |
CtrlEvent('nanoctrl', 1, x, 0) | |
for x in nanokontrol2_seq64_map | |
] | |
def recall_nanokontrol2_seq64(): | |
""" restore previous scene_1 LED states """ | |
for x in nanokontrol2_seq64_map: | |
if midi_toggles_on[x] is True: | |
output_event(CtrlEvent('nanoctrl', 1, x, 127)) | |
return | |
current_strip = 1 | |
def set_current_strip(): | |
""" set global current_strip state for returning to channel strip mode""" | |
global current_strip | |
current_strip = current_subscene() | |
print(current_strip) | |
def goto_current_strip(ev): | |
switch_scene(2, subscene=current_strip) | |
# control patch runs in parallel with the current scene patches | |
control = CtrlFilter(43, 44) >> CtrlValueFilter(127) >> [CtrlFilter(43) >> SceneSwitch(1) >> ~CtrlFilter(43), | |
CtrlFilter(44) >> Process(goto_current_strip) >> ~CtrlFilter(44)] | |
# manages track left/right button CCs to switch channel strip subscenes | |
control_strip = CtrlFilter(58, 59) >> CtrlValueFilter(127) >> [CtrlFilter(58) >> SubSceneSwitch(offset=-1, wrap=True) >> ~CtrlFilter(58), | |
CtrlFilter(59) >> SubSceneSwitch(offset=1) >> ~CtrlFilter(59)] | |
pre = ~CtrlFilter(43, 44) >> Print('input', portnames='in') | |
scene_pattern_grid = [Init(Ctrl('nanoctrl', 1, 44, 0)), | |
Init(Ctrl('nanoctrl', 1, 43, 127)), | |
Init(Call(recall_nanokontrol2_seq64)), | |
Exit(Ctrl('nanoctrl', 1, 43, 0)), | |
Exit(Process(clear_nanokontrol2)), | |
Filter(CTRL) >> Process(toggle_nanokontrol2) >> [Port('nanoctrl'), Channel(16) >> Port('seq64ctrl')]] | |
scene_strip_1 = [Port('nanokontrol2') >> Port('strip_1'), | |
Init(Ctrl('nanoctrl', 1, 44, 127)), | |
Init(Call(set_current_strip)), | |
Init(Ctrl('nanoctrl', 1, 32, 127)), | |
Exit(Ctrl('nanoctrl', 1, 32, 0)), | |
control_strip] | |
scene_strip_2 = [Port('nanokontrol2') >> Port('strip_2'), | |
Init(Ctrl('nanoctrl', 1, 44, 127)), | |
Init(Ctrl('nanoctrl', 1, 33, 127)), | |
Init(Call(set_current_strip)), | |
Exit(Ctrl('nanoctrl', 1, 33, 0)), | |
control_strip] | |
scene_strip_3 = [Port('nanokontrol2') >> Port('strip_3'), | |
Init(Ctrl('nanoctrl', 1, 44, 127)), | |
Init(Ctrl('nanoctrl', 1, 34, 127)), | |
Init(Call(set_current_strip)), | |
Exit(Ctrl('nanoctrl', 1, 34, 0)), | |
control_strip] | |
scene_strip_4 = [Port('nanokontrol2') >> Port('strip_4'), | |
Init(Ctrl('nanoctrl', 1, 44, 127)), | |
Init(Ctrl('nanoctrl', 1, 35, 127)), | |
Init(Call(set_current_strip)), | |
Exit(Ctrl('nanoctrl', 1, 35, 0)), | |
control_strip] | |
scene_strip_5 = [Port('nanokontrol2') >> Port('strip_5'), | |
Init(Ctrl('nanoctrl', 1, 44, 127)), | |
Init(Ctrl('nanoctrl', 1, 36, 127)), | |
Init(Call(set_current_strip)), | |
Exit(Ctrl('nanoctrl', 1, 36, 0)), | |
control_strip] | |
scene_strip_6 = [Port('nanokontrol2') >> Port('strip_6'), | |
Init(Ctrl('nanoctrl', 1, 44, 127)), | |
Init(Ctrl('nanoctrl', 1, 37, 127)), | |
Init(Call(set_current_strip)), | |
Exit(Ctrl('nanoctrl', 1, 37, 0)), | |
control_strip] | |
scene_strip_7 = [Port('nanokontrol2') >> Port('strip_7'), | |
Init(Ctrl('nanoctrl', 1, 44, 127)), | |
Init(Ctrl('nanoctrl', 1, 38, 127)), | |
Init(Call(set_current_strip)), | |
Exit(Ctrl('nanoctrl', 1, 38, 0)), | |
control_strip] | |
scene_strip_8 = [Port('nanokontrol2') >> Port('strip_8'), | |
Init(Ctrl('nanoctrl', 1, 44, 127)), | |
Init(Ctrl('nanoctrl', 1, 39, 127)), | |
Init(Call(set_current_strip)), | |
Exit(Ctrl('nanoctrl', 1, 39, 0)), | |
control_strip] | |
scenes = { | |
1: Scene("pattern_grid", scene_pattern_grid), | |
2: SceneGroup("strip", [ | |
Scene("strip_1", scene_strip_1), | |
Scene("strip_2", scene_strip_2), | |
Scene("strip_3", scene_strip_3), | |
Scene("strip_4", scene_strip_4), | |
Scene("strip_5", scene_strip_5), | |
Scene("strip_6", scene_strip_6), | |
Scene("strip_7", scene_strip_7), | |
Scene("strip_8", scene_strip_8), | |
]) | |
} | |
post = Print('output', portnames='out') | |
dummy = "so Process() works" | |
clear_nanokontrol2(dummy) | |
run( | |
control=control, | |
pre=pre, | |
post=post, | |
scenes=scenes | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment