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

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