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, stops = [ 0.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, stops = [ 0.0 ]):
156 Actions.Action.__init__(self, name)
158 self._controller = controller
160 self._channel = channel
165 def __call__(self, binding):
166 self._mixer.assignController(self._controller,
174 class MuteChannel(Actions.Action):
176 def __init__(self, name, mixer, channel):
177 Actions.Action.__init__(self, name)
179 self._channel = channel
181 def __call__(self, binding):
182 self._mixer.mute(self._channel)
185 class UnmuteChannel(Actions.Action):
187 def __init__(self, name, mixer, channel):
188 Actions.Action.__init__(self, name, mixer, channel)
189 Actions.Action.__init__(self, name)
191 self._channel = channel
193 def __call__(self, binding):
194 self._mixer.unmute(self._channel)
197 class ToggleMuteChannel(Actions.Action):
199 def __init__(self, name, mixer, channel):
200 Actions.Action.__init__(self, name)
202 self._channel = channel
204 def __call__(self, binding):
205 self._mixer.muteToggle(self._channel)
207 class ToggleMuteAll(Actions.Action):
209 def __init__(self, name, mixer):
210 Actions.Action.__init__(self, name)
213 def __call__(self, binding):
214 self._mixer.muteToggleAll()
216 class CycleVolume(Actions.Action):
218 def __init__(self, name, mixer, channel, volumes):
219 Actions.Action.__init__(self, name)
221 self._channel = channel
222 self._volumes = volumes
224 def __call__(self, binding):
225 self._mixer.cycleVolume(self._channel, self._volumes)
227 def register( viewmanager,
234 mixer = Mixer(context, label, x, y, dx, dy, channels, oscserver, remote)
235 viewmanager.registerView( mixer )