-
Notifications
You must be signed in to change notification settings - Fork 1
/
LightHouseMidiReceiver.py
148 lines (128 loc) · 6.7 KB
/
LightHouseMidiReceiver.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Copyright (C) 2015 Manuel Hirschauer (manuel@hirschauer.net)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# For questions regarding this module contact
# Manuel Hirschauer <manuel@hirschauer.net>
"""
LightHouseMidiReceiver handles incoming messages from LightHouse
"""
import Live
""" Constants and configuration """
from consts import *
from util.RangeUtil import RangeUtil
class LightHouseMidiReceiver:
"""
LightHouseMidiReceiver handles incoming messages from LightHouse
"""
def __init__(self, yaas, c_instance):
self.log = yaas.log
self._LightHouseMidiReceiver__c_instance = c_instance
self.yaas = yaas
self._range_util_android = RangeUtil(0, 100)
self._currentClipNumber = 0
def build_midi_map(self, midi_map_handle):
self.log.verbose('(LightHouseMidiReceiver) build_midi_map() called')
Live.MidiMap.forward_midi_note(self.script_handle(), midi_map_handle, CHANNEL_LIGHTHOUSE, 1)
Live.MidiMap.forward_midi_note(self.script_handle(), midi_map_handle, CHANNEL_LIGHTHOUSE, 2)
Live.MidiMap.forward_midi_note(self.script_handle(), midi_map_handle, CHANNEL_LIGHTHOUSE, 3)
Live.MidiMap.forward_midi_note(self.script_handle(), midi_map_handle, CHANNEL_LIGHTHOUSE, 4)
Live.MidiMap.forward_midi_note(self.script_handle(), midi_map_handle, CHANNEL_LIGHTHOUSE, 12)
Live.MidiMap.forward_midi_note(self.script_handle(), midi_map_handle, CHANNEL_LIGHTHOUSE, 13)
Live.MidiMap.forward_midi_note(self.script_handle(), midi_map_handle, CHANNEL_LIGHTHOUSE, 14)
# midi_note_definitions
for k, v in self.yaas.midi_note_definitions_for_lighthouse.iteritems():
#self.log.debug('registered ' + str(k))
Live.MidiMap.forward_midi_note(self.script_handle(), midi_map_handle, CHANNEL_LIGHTHOUSE, k)
return
def receive_midi(self, midi_bytes):
self.log.verbose('(LightHouseMidiReceiver) receive_midi() ' + str(midi_bytes))
assert (midi_bytes != None)
assert isinstance(midi_bytes, tuple)
if (len(midi_bytes) is 3):
message_type = midi_bytes[0]
midi_note = midi_bytes[1]
value = midi_bytes[2]
#print('found message_type ' + str(message_type));
if (message_type == MESSAGE_TYPE_LIGHTHOUSE_MIDI_NOTE_PRESSED):
#print('found pressed');
if (midi_note in self.yaas.midi_note_definitions_for_lighthouse):
self.log.verbose('found action');
self.yaas.handle_parametered_function(self.yaas.midi_note_definitions_for_lighthouse, midi_note, value);
if (midi_note == 1):
if (value == 1):
#print('found start')
track_helper = self.yaas._song_helper.get_track_for_name("Alto Flute")
if (track_helper is not None):
#print('track: ' + track_helper.get_track().name)
#device = track_helper.get_device("Flute")
track_helper.get_track().clip_slots[1].fire()
if (value == 2):
#print('found stop')
track_helper = self.yaas._song_helper.get_track_for_name("Alto Flute")
if (track_helper is not None):
#print('track: ' + track_helper.get_track().name)
#device = track_helper.get_device("Flute")
track_helper.get_track().clip_slots[1].stop()
if (midi_note == 2):
#print('x: ' + str(value))
self.handleKnob(1, value)
if (midi_note == 3):
#print('y: ' + str(value))
self.handleKnob(2, value)
if (midi_note == 4):
#print('z: ' + str(value))
self.handleKnob(3, value)
if (midi_note == 12):
print('x: ' + str(value))
self.add_second_track(value)
if (midi_note == 13):
#print('y: ' + str(value))
self.startClip(value)
#if (midi_note == 14):
# print('y: ' + str(value))
elif (message_type == MESSAGE_TYPE_LIGHTHOUSE_MIDI_NOTE_RELEASED):
#self.log.debug("released");
return
return
def add_second_track(self, value):
track_helper = self.yaas._song_helper.get_track_for_name("DrumBeat")
if (track_helper is not None):
value = value - 70
if (value > 5):
track_helper.get_track().clip_slots[self._currentClipNumber].fire()
if (value < 5):
track_helper.get_track().clip_slots[self._currentClipNumber].stop()
def startClip(self, value):
track_helper = self.yaas._song_helper.get_track_for_name("DrumNorm")
if (track_helper is not None):
value = value - 70
if (value != self._currentClipNumber):
self._currentClipNumber = value
track_helper.get_track().clip_slots[value].fire()
#print('track: ' + track_helper.get_track().name)
def handleKnob(self, type, value):
track_helper = self.yaas._song_helper.get_track_for_name("Alto Flute")
if (track_helper is not None):
device = track_helper.get_device("Flute")
if (device is not None):
#print('found hash device: ' + device.name)
valueX = self._range_util_android.get_value(device.parameters[type], value);
#print('valueX ' + str(valueX))
device.parameters[type].value = valueX
def script_handle(self):
return self._LightHouseMidiReceiver__c_instance.handle()
def song(self):
return self.yaas.song()