-
Notifications
You must be signed in to change notification settings - Fork 10
/
NoteRepeatComponent.py
97 lines (79 loc) · 3.18 KB
/
NoteRepeatComponent.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
#Embedded file name: /Users/versonator/Jenkins/live/output/mac_64_static/Release/midi-remote-scripts/Push/NoteRepeatComponent.py
from _Framework.ModesComponent import ModesComponent
from _Framework import Task
from _Framework.CompoundComponent import CompoundComponent
from _Framework.SubjectSlot import subject_slot
from .ActionWithOptionsComponent import OptionsComponent
t = 3.0 / 2.0
NOTE_REPEAT_FREQUENCIES = [32 * t,
32,
16 * t,
16,
8 * t,
8,
4 * t,
4]
del t
class DummyNoteRepeat(object):
repeat_rate = 1.0
enabled = False
class NoteRepeatComponent(CompoundComponent):
"""
Component for setting up the note repeat
"""
def __init__(self, *a, **k):
super(NoteRepeatComponent, self).__init__(*a, **k)
self._aftertouch = None
self._last_record_quantization = None
self._note_repeat = None
self._options = self.register_component(OptionsComponent())
self._options.selected_color = 'NoteRepeat.RateSelected'
self._options.unselected_color = 'NoteRepeat.RateUnselected'
self._options.option_names = map(str, range(8))
self._options.selected_option = 5
self._on_selected_option_changed.subject = self._options
self.set_note_repeat(None)
def on_enabled_changed(self):
if self.is_enabled():
self._enable_note_repeat()
else:
self._disable_note_repeat()
def update(self):
super(NoteRepeatComponent, self).update()
self._update_aftertouch()
def _update_aftertouch(self):
if self._aftertouch:
self._aftertouch.reset()
def set_aftertouch_control(self, control):
self._aftertouch = control
self._update_aftertouch()
def set_select_buttons(self, buttons):
self._options.select_buttons.set_control_element(buttons)
def set_note_repeat(self, note_repeat):
note_repeat = note_repeat or DummyNoteRepeat()
if self._note_repeat != None:
self._note_repeat.enabled = False
self._note_repeat = note_repeat
self._update_note_repeat(enabled=self.is_enabled())
def set_pad_parameters(self, element):
if element:
element.reset()
def _enable_note_repeat(self):
self._last_record_quantization = self.song().midi_recording_quantization
self._set_recording_quantization(False)
self._update_note_repeat(enabled=True)
def _disable_note_repeat(self):
if not self.song().midi_recording_quantization and self._last_record_quantization:
self._set_recording_quantization(self._last_record_quantization)
self._update_note_repeat(enabled=False)
def _set_recording_quantization(self, value):
def doit():
self.song().midi_recording_quantization = value
self._tasks.parent_task.add(Task.run(doit))
@subject_slot('selected_option')
def _on_selected_option_changed(self, option):
frequency = NOTE_REPEAT_FREQUENCIES[option]
self._note_repeat.repeat_rate = 1.0 / frequency * 4.0
def _update_note_repeat(self, enabled = False):
self._on_selected_option_changed(self._options.selected_option)
self._note_repeat.enabled = self.is_enabled()