-
Notifications
You must be signed in to change notification settings - Fork 19
/
mixer.py
99 lines (84 loc) · 2.76 KB
/
mixer.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
import enum
import logging
import mido
from gridgets import Gridget, Surface
from palette import palette
from persistence import persistent_attrs, persistent_attrs_init
class Page(enum.Enum):
VOLUME = 1
CHORUS = 2
REVERB = 3
@persistent_attrs(volume=16*[96], chorus=16*[0], reverb=16*[0])
class Mixer(object):
def __init__(self, griode):
self.griode = griode
persistent_attrs_init(self)
# FIXME don't duplicate the CC mappings
for cc, array in [
(7, self.volume),
(91, self.chorus),
(93, self.reverb),
]:
for channel, value in enumerate(array):
m = mido.Message("control_change", control=cc, value=value)
self.griode.devicechains[channel].send(m)
class Faders(Gridget):
def __init__(self, grid):
self.grid = grid
self.surface = Surface(grid.surface)
self.page = Page.VOLUME
self.first_channel = 0
self.draw()
@property
def mixer(self):
return self.grid.griode.mixer
@property
def array(self):
if self.page == Page.VOLUME:
return self.mixer.volume
if self.page == Page.CHORUS:
return self.mixer.chorus
if self.page == Page.REVERB:
return self.mixer.reverb
@property
def cc(self):
if self.page == Page.VOLUME:
return 7
if self.page == Page.CHORUS:
return 91
if self.page == Page.REVERB:
return 93
def draw(self):
for led in self.surface:
if isinstance(led, tuple):
row, column = led
channel = self.first_channel + column - 1
value = self.array[channel]
n_leds = (value+16)//16
color = palette.BLACK
if row <= n_leds:
color = palette.CHANNEL[channel]
self.surface[led] = color
def pad_pressed(self, row, column, velocity):
if velocity == 0:
return
channel = self.first_channel + column - 1
value = 127*(row-1)//7
self.array[channel] = value
logging.info("Setting {} for channel {} to {}"
.format(self.page, channel, value))
message = mido.Message(
"control_change", channel=channel,
control=self.cc, value=value)
self.grid.griode.synth.send(message)
self.draw()
def button_pressed(self, button):
if button == "LEFT":
self.first_channel = 0
if button == "RIGHT":
self.first_channel = 8
if button == "UP":
self.page = Page(self.page.value-1)
if button == "DOWN":
self.page = Page(self.page.value+1)
self.draw()