1 import Actions, OSC, Events, Views, curses
4 class Metronome(Views.View):
6 def __init__(self, context, label, x, y, dx, dy, dispatcher):
7 Views.View.__init__(self, context, label, x, y, dx, dy)
8 self._dispatcher = dispatcher
10 self._eci('-G:jack,metronome,notransport')
11 self._eci('ai-add null')
12 self._eci('ao-add jack_auto,system')
13 self._eci('cop-add -pn:metronome,120')
14 self._eci('cop-add -ea:1')
15 self._eci('engine-launch')
21 def updateView(self, bindings):
28 def _redraw(self, refresh=1):
29 self.win().addstr(1,2,'%3d bpm' % self._bpm)
31 self.win().addstr(1,10,'Running',curses.A_BOLD)
33 self.win().addstr(1,10,'Off ')
34 self.win().addstr(1,18,'%3.1f' % self._volume)
39 self._running = not self._running
48 if self._tap and self._tap < t and self._tap > t-2:
49 self.setBPM(60.0 / (t - self._tap))
52 def setVolume(self, value):
54 self._eci('cop-select 2')
55 self._eci('copp-select 1')
56 self._eci('copp-set', self._volume)
59 def setBPM(self, value):
60 self._bpm = int(value)
61 self._eci('cop-select 1')
62 self._eci('copp-select 1')
63 self._eci('copp-set', self._bpm)
66 def stepBPM(self, dir, min=30, max=360):
68 bpm = self._bpm/step * step
73 if bpm<min : bpm = min
74 if bpm>max : bpm = max
77 class VolumeSetter(object):
79 def __init__(self, metronome):
80 self._metronome = metronome
82 def __call__(self, value):
83 self._metronome.setVolume(value)
85 class VolumeGetter(object):
87 def __init__(self, metronome):
88 self._metronome = metronome
91 return self._metronome._volume
93 def assignVolumeController(self, controller, title, min, max, steps=[]):
94 controller.assign(title,
95 self.VolumeSetter(self),
96 self.VolumeGetter(self),
100 class BPMSetter(object):
102 def __init__(self, metronome):
103 self._metronome = metronome
105 def __call__(self, value):
106 self._metronome.setBPM(value)
108 class BPMGetter(object):
110 def __init__(self, metronome):
111 self._metronome = metronome
114 return self._metronome._bpm
116 def assignBPMController(self, controller, title, min, max, steps=[]):
117 controller.assign(title,
118 self.BPMSetter(self),
119 self.BPMGetter(self),
124 class Toggle(Actions.Action):
126 def __init__(self, name, m):
127 Actions.Action.__init__(self, name)
130 def __call__(self, binding):
133 class Tap(Actions.Action):
135 def __init__(self, name, m):
136 Actions.Action.__init__(self, name)
139 def __call__(self, binding):
142 class AssignVolumeController(Actions.Action):
144 def __init__(self, name, metronome, controller, title, min, max, steps=[]):
145 Actions.Action.__init__(self, name)
146 self._metronome = metronome
147 self._controller = controller
153 def __call__(self, binding):
154 self._metronome.assignVolumeController(self._controller,
160 class AssignBPMController(Actions.Action):
162 def __init__(self, name, metronome, controller, title, min, max, steps=[]):
163 Actions.Action.__init__(self, name)
164 self._metronome = metronome
165 self._controller = controller
171 def __call__(self, binding):
172 self._metronome.assignBPMController(self._controller,
178 class StepBPM(Actions.Action):
180 def __init__(self, name, m, dir):
181 Actions.Action.__init__(self, name)
185 def __call__(self, binding):
186 self._m.stepBPM(self._dir)
188 def register( viewmanager,
193 metronome = Metronome(context, label, x, y, dx, dy, dispatcher)
194 viewmanager.registerView( metronome )