1 import Actions, OSC, Events, Views, curses
3 class Mixer(Views.View):
5 def __init__(self, context, label, x, y, dx, dy, channels, oscserver, remote):
6 Views.View.__init__(self, context, label, x, y, dx, dy)
7 self._context = context
8 self._server = oscserver
10 self._server.registerHandler(self._remote, self._oscEvent)
11 self._server.command(self._remote,'/mixer/get_channel_count')
12 self._channelNames = channels
15 self._muteState = None
17 def updateView(self, bindings):
24 if not self._channels : return
25 for i in range(self._channels):
26 self.win().addstr(i+1,2,self._channelNames[i][:8])
27 self._redrawValue(i+1)
30 def _redrawValue(self, channel):
31 if self._muteState[channel-1] == self.MUTED:
32 self.win().addstr(channel,11,'Muted',curses.A_BOLD)
33 elif self._volume[channel-1] is not None:
34 self.win().addstr(channel,11, '%5.1f dB' % self._volume[channel-1])
41 def _oscEvent(self, path, data):
42 if path == '/mixer/channel/gain':
44 if self._muteState[data[0]-1] != self.MUTED:
45 self._volume[data[0]-1] = data[1]
46 if self._muteState[data[0]-1] == self.PENDING:
47 self._muteState[data[0]-1] = self.MUTED
48 self._set(data[0],-90.0)
49 self._redrawValue(data[0])
50 return [ Events.ControlEvent(self._context, data[0], data[1]) ]
51 elif path == '/mixer/channel_count':
53 self._channels = int(data[0])
54 self._volume = [ None ] * self._channels
56 if self._muteState is not None:
57 premutes = self._muteState
58 self._muteState = [ self.ACTIVE ] * self._channels
60 for i in range(len(self._muteState)):
62 self._muteState[i] = premutes[i]
63 while len(self._channelNames) < self._channels:
64 self._channelNames.append("Channel %d" % (len(self._channelNames)+1))
66 for i in range(self._channels):
71 def mute(self, channel):
72 if self._channels is None:
73 if self._muteState is None:
75 while(len(self._muteState) < channel) : self._muteState.append( self.ACTIVE )
76 self._muteState[channel-1] = self.PENDING
78 if self._muteState[channel-1] == self.ACTIVE:
79 self._muteState[channel-1] = self.PENDING
82 def unmute(self, channel):
83 if self._muteState[channel-1] != self.ACTIVE:
84 if self._muteState[channel-1] == self.MUTED:
85 self._set(channel, self._volume[channel-1])
86 self._muteState[channel-1] = self.ACTIVE
88 def muteToggle(self, channel):
89 if self._muteState[channel-1] == self.ACTIVE:
94 def muteToggleAll(self):
95 if [ x for x in self._muteState if x is not self.MUTED ]:
96 for i in range(self._channels):
99 for i in range(self._channels):
102 def get(self, channel):
103 if self._muteState is None or self._muteState[channel-1] == self.ACTIVE:
106 def _get(self, channel):
107 self._server.command(self._remote,'/mixer/channel/get_gain', channel)
109 def set(self, channel, value):
110 if self._muteState is None or self._muteState[channel-1] == self.ACTIVE:
111 self._set(channel, value)
113 def _set(self, channel, value):
114 self._server.command(self._remote,'/mixer/channel/set_gain', channel, value)
116 def cycleVolume(self, channel, volumes):
117 if self._muteState is None or self._muteState[channel-1] != self.ACTIVE:
119 elif self._volume[channel-1] is not None:
120 for i in range(len(volumes)):
121 if not volumes[i]-0.01 < self._volume[channel-1]:
122 self._set(channel,volumes[i])
124 self._set(channel, volumes[0])
126 class ParamGetter(object):
128 def __init__(self, mixer, channel):
130 self._channel = channel
133 self._mixer.get(self._channel)
135 class ParamSetter(object):
137 def __init__(self, mixer, channel):
139 self._channel = channel
141 def __call__(self, value):
142 self._mixer.set(self._channel, value)
144 def assignController(self, controller, title, channel, min=-12.0, max=6.0):
145 controller.assign(title,
146 self.ParamSetter(self, channel),
147 self.ParamGetter(self, channel),
148 Events.Event(self._context, channel),
153 class AssignController(Actions.Action):
155 def __init__(self, name, mixer, controller, title, channel, min=-12.0, max=6.0):
156 Actions.Action.__init__(self, name)
158 self._controller = controller
160 self._channel = channel
164 def __call__(self, binding):
165 self._mixer.assignController(self._controller,
172 class MuteChannel(Actions.Action):
174 def __init__(self, name, mixer, channel):
175 Actions.Action.__init__(self, name)
177 self._channel = channel
179 def __call__(self, binding):
180 self._mixer.mute(self._channel)
183 class UnmuteChannel(Actions.Action):
185 def __init__(self, name, mixer, channel):
186 Actions.Action.__init__(self, name, mixer, channel)
187 Actions.Action.__init__(self, name)
189 self._channel = channel
191 def __call__(self, binding):
192 self._mixer.unmute(self._channel)
195 class ToggleMuteChannel(Actions.Action):
197 def __init__(self, name, mixer, channel):
198 Actions.Action.__init__(self, name)
200 self._channel = channel
202 def __call__(self, binding):
203 self._mixer.muteToggle(self._channel)
205 class ToggleMuteAll(Actions.Action):
207 def __init__(self, name, mixer):
208 Actions.Action.__init__(self, name)
211 def __call__(self, binding):
212 self._mixer.muteToggleAll()
214 class CycleVolume(Actions.Action):
216 def __init__(self, name, mixer, channel, volumes):
217 Actions.Action.__init__(self, name)
219 self._channel = channel
220 self._volumes = volumes
222 def __call__(self, binding):
223 self._mixer.cycleVolume(self._channel, self._volumes)
225 def register( viewmanager,
232 mixer = Mixer(context, label, x, y, dx, dy, channels, oscserver, remote)
233 viewmanager.registerView( mixer )