Sampler in ChucK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 12KB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. import wx
  2. # TODO: standardize methods for adding/removing arrays of widgets
  3. def sendOSCSafe(channel, data):
  4. try:
  5. sendOSCMsg(channel, data)
  6. except OSCClientError:
  7. print "OSC comms error"
  8. class OSCSlider(wx.Panel):
  9. """ A GUI slider """
  10. def __init__(self, parent, label, min_value=0, max_value=1, default_value=0, align=True, rescale=100.):
  11. """ Constructor """
  12. self.rescale = rescale
  13. wx.Panel.__init__(self, parent)
  14. sizer = wx.BoxSizer(wx.HORIZONTAL)
  15. label = wx.StaticText(self, label=label,
  16. size=(100, 15) if align else None)
  17. sizer.Add(label, 0, wx.RIGHT, 10)
  18. self.slider = wx.Slider(self, value=default_value * self.rescale,
  19. minValue=min_value * self.rescale, maxValue=max_value * self.rescale)
  20. sizer.Add(self.slider, 1, wx.EXPAND)
  21. self.SetSizerAndFit(sizer)
  22. self.Bind = self.slider.Bind
  23. def GetValue(self):
  24. """ Make sure that we rescale """
  25. return self.slider.GetValue() / self.rescale
  26. class CommsPanel(wx.Panel):
  27. """ OSC comms """
  28. def __init__(self, parent):
  29. wx.Panel.__init__(self, parent)
  30. sizer = wx.BoxSizer(wx.HORIZONTAL)
  31. label = wx.StaticText(self, label="Sync:")
  32. font = label.GetFont()
  33. font.SetWeight(wx.BOLD)
  34. label.SetFont(font)
  35. sizer.Add(label, 0, wx.TOP | wx.BOTTOM | wx.RIGHT | wx.EXPAND, 5)
  36. choices = ["Master", "Minion"]
  37. self.master = wx.ComboBox(self, choices=choices, style=wx.CB_READONLY, size=(25, 25))
  38. sizer.Add(self.master, 1, wx.ALL, 3)
  39. self.master.SetValue(choices[0])
  40. self.ip = wx.TextCtrl(self, value="127.0.0.1")
  41. sizer.Add(self.ip, 0, wx.ALL, 3)
  42. self.port = wx.TextCtrl(self, value="9000")
  43. sizer.Add(self.port, 0, wx.ALL, 3)
  44. self.SetSizerAndFit(sizer)
  45. class InputPanel(wx.Panel):
  46. """ Handle the ADC input settings """
  47. def __init__(self, parent):
  48. """ Constructor """
  49. wx.Panel.__init__(self, parent)
  50. sizer = wx.BoxSizer(wx.HORIZONTAL)
  51. label = wx.StaticText(self, label="Input:")
  52. font = label.GetFont()
  53. font.SetWeight(wx.BOLD)
  54. label.SetFont(font)
  55. sizer.Add(label, 0, wx.TOP | wx.BOTTOM | wx.RIGHT, 5)
  56. self.gain = OSCSlider(self, "Gain", default_value=.5, align=False)
  57. sizer.Add(self.gain, 1, wx.ALL, 5)
  58. self.thru = OSCSlider(self, "Thru", default_value=.5, align=False)
  59. sizer.Add(self.thru, 1, wx.ALL, 5)
  60. self.mute = wx.ToggleButton(self, 0, "Mute")
  61. # self.mute.SetValue(1)
  62. sizer.Add(self.mute, 0)
  63. self.SetSizerAndFit(sizer)
  64. self.gain.Bind(wx.EVT_SCROLL, self.update)
  65. self.thru.Bind(wx.EVT_SCROLL, self.update)
  66. self.mute.Bind(wx.EVT_TOGGLEBUTTON, self.update)
  67. self.update()
  68. def update(self, evt=None):
  69. """ Send OSC messages """
  70. gain = self.gain.slider.GetValue()
  71. thru = self.thru.slider.GetValue()
  72. if self.mute.GetValue():
  73. gain, thru = 0., 0.
  74. sendOSCSafe("/input", [gain, thru])
  75. class DelayPanel(wx.Panel):
  76. """ Handle the ADC input settings """
  77. def __init__(self, parent):
  78. """ Constructor """
  79. wx.Panel.__init__(self, parent)
  80. sizer = wx.BoxSizer(wx.HORIZONTAL)
  81. label = wx.StaticText(self, label="Loop:")
  82. font = label.GetFont()
  83. font.SetWeight(wx.BOLD)
  84. label.SetFont(font)
  85. sizer.Add(label, 0, wx.TOP | wx.BOTTOM | wx.RIGHT, 5)
  86. self.delayTime = OSCSlider(self, "Time", default_value=1, max_value=10, align=False)
  87. sizer.Add(self.delayTime, 1, wx.ALL, 5)
  88. self.feedback = OSCSlider(self, "Hold", default_value=.99, align=False)
  89. sizer.Add(self.feedback, 1, wx.ALL, 5)
  90. self.metronome = wx.ToggleButton(self, 0, "Metronome")
  91. sizer.Add(self.metronome, 0)
  92. self.SetSizerAndFit(sizer)
  93. self.delayTime.Bind(wx.EVT_SCROLL, self.update)
  94. self.feedback.Bind(wx.EVT_SCROLL, self.update)
  95. self.metronome.Bind(wx.EVT_TOGGLEBUTTON, self.switchMetronome)
  96. self.update(None)
  97. def update(self, evt):
  98. """ Send OSC messages """
  99. a = self.delayTime.slider.GetValue()
  100. b = self.feedback.slider.GetValue()
  101. sendOSCSafe("/delay", [a, b])
  102. def switchMetronome(self, evt):
  103. """ Send OSC messages """
  104. sendOSCSafe("/metronome", [int(self.metronome.GetValue())])
  105. class ButtonArray(wx.Panel):
  106. """ Handle the ADC input settings """
  107. def __init__(self, parent, index):
  108. wx.Panel.__init__(self, parent)
  109. w = 40
  110. sizer = wx.BoxSizer(wx.HORIZONTAL)
  111. self.record = wx.ToggleButton(self, 0, "Arm", size=(w, 25))
  112. sizer.Add(self.record, 1, wx.ALL, 0)
  113. self.mute = wx.ToggleButton(self, 0, "Mute", size=(w, 25))
  114. sizer.Add(self.mute, 1, wx.ALL, 0)
  115. self.clear = wx.Button(self, 0, "Clear", size=(w, 25))
  116. sizer.Add(self.clear, 1, wx.ALL, 0)
  117. self.buttons = (self.record, self.mute, self.clear)
  118. self.SetSizerAndFit(sizer)
  119. class Channel(wx.Panel):
  120. """ A single channel """
  121. def __init__(self, parent, index):
  122. self.index = index
  123. wx.Panel.__init__(self, parent)
  124. sizer = wx.BoxSizer(wx.VERTICAL)
  125. # label = wx.StaticText(self, label="CH%d" % self.index)
  126. # font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  127. # sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5)
  128. self.gain = OSCSlider(self, "Gain", default_value=1, max_value=1.3, align=False)
  129. sizer.Add(self.gain, 0, wx.ALL | wx.EXPAND, 3)
  130. self.pan = OSCSlider(self, "Pan", default_value=0, min_value=-1, max_value=1, align=False)
  131. sizer.Add(self.pan, 0, wx.ALL | wx.EXPAND, 3)
  132. self.fxsend = OSCSlider(self, "Dry/Wet", default_value=0, min_value=0, max_value=1, align=False)
  133. sizer.Add(self.fxsend, 0, wx.ALL | wx.EXPAND, 3)
  134. self.buttons = ButtonArray(self, index)
  135. self.record, self.mute, self.clear = self.buttons.buttons
  136. sizer.Add(self.buttons, 0, wx.ALL | wx.EXPAND, 3)
  137. choices = ["1 bar", "2 bars", "4 bars", "Dephase", "1/2 rate"]
  138. self.speed = wx.ComboBox(self, choices=choices, style=wx.CB_READONLY, size=(25, 25))
  139. self.speed.SetValue("1 bar")
  140. sizer.Add(self.speed, 0, wx.ALL | wx.EXPAND, 3)
  141. self.SetSizerAndFit(sizer)
  142. self.gain.Bind(wx.EVT_SCROLL, self.update)
  143. self.pan.Bind(wx.EVT_SCROLL, self.update)
  144. self.fxsend.Bind(wx.EVT_SCROLL, self.update)
  145. self.mute.Bind(wx.EVT_TOGGLEBUTTON, self.update)
  146. self.update()
  147. def update(self, evt=None):
  148. gain = self.gain.GetValue()
  149. pan = self.pan.GetValue()
  150. fxsend = self.fxsend.GetValue()
  151. if self.mute.GetValue():
  152. gain = 0.0
  153. sendOSCSafe("/channel", [self.index, gain, pan, fxsend])
  154. class Mixer(wx.Panel):
  155. """ All the channels """
  156. def __init__(self, parent):
  157. """ Constructor """
  158. wx.Panel.__init__(self, parent)
  159. sizer = wx.BoxSizer(wx.HORIZONTAL)
  160. self.channels = []
  161. for i in range(4):
  162. c = Channel(self, index=i)
  163. c.record.Bind(wx.EVT_TOGGLEBUTTON, self.switch_record)
  164. c.record.index = i
  165. c.clear.Bind(wx.EVT_BUTTON, self.clear_channel)
  166. c.clear.index = i
  167. self.channels.append(c)
  168. sizer.Add(c, 1, wx.EXPAND)
  169. self.SetSizerAndFit(sizer)
  170. def switch_record(self, evt):
  171. """ Send OSC message to switch recording channel """
  172. index = evt.GetEventObject().index
  173. value = evt.GetEventObject().GetValue()
  174. for i, c in enumerate(self.channels):
  175. c.record.SetValue(0)
  176. self.channels[index].record.SetValue(value)
  177. sendOSCSafe("/arm", [index if value else -1])
  178. def clear_channel(self, evt):
  179. """ Send OSC message to clear a channel """
  180. index = evt.GetEventObject().index
  181. sendOSCSafe("/clear", [index])
  182. class FXPanel(wx.Panel):
  183. """ Effects chain """
  184. def __init__(self, parent):
  185. """ Constructor """
  186. wx.Panel.__init__(self, parent)
  187. sizer = wx.BoxSizer(wx.HORIZONTAL)
  188. label = wx.StaticText(self, label="FX:")
  189. font = label.GetFont()
  190. font.SetWeight(wx.BOLD)
  191. label.SetFont(font)
  192. sizer.Add(label, 0, wx.EXPAND | wx.TOP | wx.BOTTOM | wx.RIGHT, 5)
  193. # choices=["Low pass filter", "High pass filter", "Reverb"]
  194. # self.fxtype= wx.ComboBox(self, choices=choices, style=wx.CB_READONLY, size=(25,25))
  195. # sizer.Add(self.fxtype, 1, wx.ALL|wx.EXPAND, 5)
  196. # self.fxtype.SetValue(choices[0])
  197. self.lpf = OSCSlider(self, "Lo-pass", default_value=.5, align=False)
  198. sizer.Add(self.lpf, 2, wx.EXPAND | wx.ALL, 5)
  199. self.lpf.Bind(wx.EVT_SCROLL, self.update)
  200. self.hpf = OSCSlider(self, "Hi-pass", min_value=0.1, default_value=.5, align=False)
  201. sizer.Add(self.hpf, 2, wx.EXPAND | wx.ALL, 5)
  202. self.hpf.Bind(wx.EVT_SCROLL, self.update)
  203. self.reverb = OSCSlider(self, "Reverb", default_value=.5, align=False)
  204. sizer.Add(self.reverb, 2, wx.EXPAND | wx.ALL, 5)
  205. self.reverb.Bind(wx.EVT_SCROLL, self.update)
  206. self.SetSizerAndFit(sizer)
  207. self.update(None)
  208. def update(self, evt):
  209. a = self.lpf.slider.GetValue()
  210. a2 = self.hpf.slider.GetValue()
  211. b = self.reverb.slider.GetValue()
  212. sendOSCSafe("/fx", [a, a2, b])
  213. class OutputPanel(wx.Panel):
  214. """ Handle the ADC input settings """
  215. def __init__(self, parent):
  216. """ Constructor """
  217. wx.Panel.__init__(self, parent)
  218. sizer = wx.BoxSizer(wx.HORIZONTAL)
  219. label = wx.StaticText(self, label="Output:")
  220. font = label.GetFont()
  221. font.SetWeight(wx.BOLD)
  222. label.SetFont(font)
  223. sizer.Add(label, 0, wx.TOP | wx.BOTTOM | wx.RIGHT, 5)
  224. self.level = OSCSlider(self, "Level", default_value=.8, align=False)
  225. sizer.Add(self.level, 2, wx.EXPAND | wx.ALL, 5)
  226. self.level.Bind(wx.EVT_SCROLL, self.update)
  227. # self.gauge = wx.Gauge(self, size=(40,10))
  228. # sizer.Add(self.gauge, 1, wx.EXPAND|wx.ALL, 5)
  229. self.SetSizerAndFit(sizer)
  230. def update(self, evt):
  231. a = self.level.slider.GetValue()
  232. sendOSCSafe("/master", [a])
  233. class MainGUI(wx.Frame):
  234. """ A simple GUI to talk to Chuck """
  235. def __init__(self):
  236. """ Constructor """
  237. # Build the interface
  238. self.app = wx.App(False)
  239. self.build()
  240. def run(self):
  241. self.app.MainLoop()
  242. def build(self):
  243. """ Builds the various pieces of the GUI """
  244. wx.Frame.__init__(self, None, title="DELAY LORD")
  245. self.Bind(wx.EVT_CLOSE, self.quit)
  246. # The main sizer
  247. self.mainsizer = wx.BoxSizer(wx.VERTICAL)
  248. self.components = []
  249. components = (CommsPanel, InputPanel, DelayPanel, Mixer, FXPanel, OutputPanel)
  250. for index, ctype in enumerate(components):
  251. if index>0: self.mainsizer.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
  252. c = ctype(self)
  253. self.components.append(c)
  254. self.mainsizer.Add(self.c, 0, wx.EXPAND | wx.ALL, 5)
  255. self.SetSizerAndFit(self.mainsizer)
  256. self.Show()
  257. def populate_left_panel(self):
  258. """ Populate the left panel """
  259. # Status boxes
  260. def quit(self, *args):
  261. """ Close down gracefully, and then destroy the window """
  262. self.Destroy()
  263. if __name__ == "__main__":
  264. initOSCClient(ip="127.0.0.1", port=9000)
  265. g = MainGUI()
  266. # initOSCServer(ip="127.0.0.1", port=6649, mode=0)
  267. # setOSCHandler("/vu", g.update_vu)
  268. g.run()
  269. closeOSC()