-
Notifications
You must be signed in to change notification settings - Fork 16
/
SpecialMidiMap.py
94 lines (79 loc) · 3.16 KB
/
SpecialMidiMap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#Embedded file name: /Users/versonator/Jenkins/live/output/mac_64_static/Release/midi-remote-scripts/Launchpad_Pro/SpecialMidiMap.py
from __future__ import absolute_import
from _Framework.MidiMap import MidiMap
from _Framework.ButtonMatrixElement import ButtonMatrixElement
from _Framework.Resource import PrioritizedResource
from _Framework.Dependency import depends
from .ConfigurableButtonElement import ConfigurableButtonElement
from .MultiButtonElement import MultiButtonElement
from .SliderElement import SliderElement
from .consts import USER_MODE_CHANNELS
#USER_LAYOUT_START_CHANNEL = 5 #seems unused
#NUM_USER_LAYOUT_CHANNELS = 3 #seems unused
@depends(skin=None)
def make_button(name, channel, number, midi_message_type, skin = None, default_states = None, **k):
return ConfigurableButtonElement(True, midi_message_type, channel, number, name=name, skin=skin, default_states=default_states, **k)
@depends(skin=None)
def make_multi_button(name, channel, number, midi_message_type, skin = None, default_states = None, **k):
"""
Creates a special button element that is actually multiple buttons;
one for the default channel (1) and one for each of the channels
used in user layouts. This allows the created buttons
to work correctly in all of the user layouts.
"""
is_momentary = True
return MultiButtonElement(
USER_MODE_CHANNELS,
is_momentary,
midi_message_type,
channel,
number,
name=name,
skin=skin,
default_states=default_states,
**k
)
@depends(skin=None)
def make_slider(name, channel, number, midi_message_type, skin = None):
slider = SliderElement(midi_message_type, channel, number, name=name, skin=skin)
return slider
class SpecialMidiMap(MidiMap):#midi map is just a 'dict' (or map)
def add_button(self, name, channel, number, midi_message_type, default_states = None, element_factory = make_button, **k):
assert(name not in self.keys())
self[name] = element_factory(
name,
channel,
number,
midi_message_type,
default_states=default_states,
**k
)
def add_matrix(self, name, element_factory, channel, numbers, midi_message_type):
assert(name not in self.keys())
def one_dimensional_name(base_name, x, _y):
return '%s_%d' % (base_name, x)
def two_dimensional_name(base_name, x, y):
return '%s_%d_%d' % (base_name, x, y)
name_factory = two_dimensional_name if len(numbers) > 1 else one_dimensional_name
elements = []
id_dict = {}
for row, identifiers in enumerate(numbers):
element_row = []
for column, identifier in enumerate(identifiers):
element_row.append(element_factory(name_factory(name, column, row), channel, identifier, midi_message_type))
id_dict[identifier] = (column, row)
elements.append(element_row)
self['%s_Raw' % name] = elements
self['%s_Ids' % name] = id_dict
self[name] = ButtonMatrixElement(rows=elements, name=name)
def add_modifier_button(self, name, channel, number, midi_message_type, default_states = None, element_factory = make_button):
assert(name not in self.keys())
self.add_button(
name,
channel,
number,
midi_message_type,
default_states=default_states,
element_factory=element_factory,
resource_type=PrioritizedResource
)