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 7.9KB

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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. from libs.simpleosc import *
  2. import wx
  3. class OSCSlider(wx.Panel):
  4. ''' A GUI slider '''
  5. def __init__(self, parent, label, min_value=0, max_value=1, default_value=0, align=True):
  6. ''' Constructor '''
  7. wx.Panel.__init__(self, parent)
  8. sizer=wx.BoxSizer(wx.HORIZONTAL)
  9. label=wx.StaticText(self, label=label, size=(100,15) if align else None)
  10. sizer.Add(label, 0, wx.RIGHT, 10)
  11. self.slider=wx.Slider(self, value=default_value*100, minValue=min_value*100, maxValue=max_value*100)
  12. sizer.Add(self.slider, 1, wx.EXPAND)
  13. self.SetSizerAndFit(sizer)
  14. self.Bind=self.slider.Bind
  15. self.GetValue=self.slider.GetValue
  16. class CommsPanel(wx.Panel):
  17. """ OSC comms """
  18. def __init__(self, parent):
  19. wx.Panel.__init__(self, parent)
  20. sizer = wx.BoxSizer(wx.HORIZONTAL)
  21. label = wx.StaticText(self, label="Sync:")
  22. font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  23. sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT|wx.EXPAND, 5)
  24. self.master = wx.ToggleButton(self, 1, "Master/Minion")
  25. sizer.Add(self.master, 0, wx.ALL, 3)
  26. self.ip=wx.TextCtrl(self, value="127.0.0.1")
  27. sizer.Add(self.ip, 0, wx.ALL, 3)
  28. self.port=wx.TextCtrl(self, value="9000")
  29. sizer.Add(self.port, 0, wx.ALL, 3)
  30. self.SetSizerAndFit(sizer)
  31. class InputPanel(wx.Panel):
  32. ''' Handle the ADC input settings '''
  33. def __init__(self, parent):
  34. ''' Constructor '''
  35. wx.Panel.__init__(self, parent)
  36. sizer = wx.BoxSizer(wx.HORIZONTAL)
  37. label = wx.StaticText(self, label="Line in:")
  38. font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  39. sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5)
  40. self.gain = OSCSlider(self, "Gain", default_value=.5, align=False)
  41. sizer.Add(self.gain, 1, wx.ALL, 5)
  42. self.thru = OSCSlider(self, "Thru", default_value=.5, align=False)
  43. sizer.Add(self.thru, 1, wx.ALL, 5)
  44. self.mute = wx.ToggleButton(self, 1, "Mute")
  45. #self.mute.SetValue(1)
  46. sizer.Add(self.mute, 0)
  47. self.SetSizerAndFit(sizer)
  48. self.gain.Bind(wx.EVT_SCROLL, self.update)
  49. self.thru.Bind(wx.EVT_SCROLL, self.update)
  50. self.mute.Bind(wx.EVT_TOGGLEBUTTON, self.update)
  51. self.update()
  52. def update(self, evt=None):
  53. """ Send OSC messages """
  54. gain=self.gain.slider.GetValue()/100.
  55. thru=self.thru.slider.GetValue()/100.
  56. if self.mute.GetValue(): gain, thru = 0.,0.
  57. try:
  58. sendOSCMsg("/input", [gain, thru])
  59. except OSCClientError:
  60. pass
  61. class DelayPanel(wx.Panel):
  62. ''' Handle the ADC input settings '''
  63. def __init__(self, parent):
  64. ''' Constructor '''
  65. wx.Panel.__init__(self, parent)
  66. sizer = wx.BoxSizer(wx.VERTICAL)
  67. label = wx.StaticText(self, label="Delay lines:")
  68. font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  69. sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5)
  70. self.delayTime=OSCSlider(self, "Delay time (s)", default_value=1, max_value=10)
  71. sizer.Add(self.delayTime, 0, wx.EXPAND|wx.ALL, 5)
  72. self.feedback=OSCSlider(self, "Feedback", default_value=.99)
  73. sizer.Add(self.feedback, 0, wx.EXPAND|wx.ALL, 5)
  74. self.metronome=wx.ToggleButton(self, 0, "Metronome")
  75. sizer.Add(self.metronome, 0, wx.EXPAND|wx.ALL, 5)
  76. self.SetSizerAndFit(sizer)
  77. self.delayTime.Bind(wx.EVT_SCROLL, self.update)
  78. self.feedback.Bind(wx.EVT_SCROLL, self.update)
  79. self.update(None)
  80. def update(self, evt):
  81. """ Send OSC messages """
  82. a=self.delayTime.slider.GetValue()/100.
  83. b=self.feedback.slider.GetValue()/100.
  84. try:
  85. sendOSCMsg("/delay", [a, b])
  86. except OSCClientError:
  87. pass
  88. class Channel(wx.Panel):
  89. """ A single channel """
  90. def __init__(self, parent, index):
  91. self.index=index
  92. wx.Panel.__init__(self, parent)
  93. sizer = wx.BoxSizer(wx.VERTICAL)
  94. label = wx.StaticText(self, label="CH%d" % self.index)
  95. font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  96. sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5)
  97. self.gain = OSCSlider(self, "Gain", default_value=1, max_value=1.3, align=False)
  98. sizer.Add(self.gain, 0, wx.ALL|wx.EXPAND, 3)
  99. self.record = wx.ToggleButton(self, 1, "Arm")
  100. sizer.Add(self.record, 0, wx.ALL|wx.EXPAND if index==0 else wx.ALL|wx.EXPAND, 3)
  101. self.mute = wx.ToggleButton(self, 1, "Mute")
  102. sizer.Add(self.mute, 0, wx.ALL|wx.EXPAND, 3)
  103. self.clear = wx.Button(self, 1, "Clear")
  104. sizer.Add(self.clear, 0, wx.ALL|wx.EXPAND, 3)
  105. self.SetSizerAndFit(sizer)
  106. self.gain.Bind(wx.EVT_SCROLL, self.update)
  107. self.mute.Bind(wx.EVT_TOGGLEBUTTON, self.update)
  108. self.update()
  109. def update(self, evt=None):
  110. print "Channel %d: send gain, pan, mute" % self.index
  111. gain=self.gain.GetValue()/100.
  112. if self.mute.GetValue(): gain=0.0;
  113. try:
  114. sendOSCMsg("/channel", [self.index, gain])
  115. except OSCClientError:
  116. pass
  117. class Mixer(wx.Panel):
  118. ''' All the channels '''
  119. def __init__(self, parent):
  120. ''' Constructor '''
  121. wx.Panel.__init__(self, parent)
  122. sizer = wx.BoxSizer(wx.HORIZONTAL)
  123. self.channels=[]
  124. for i in range(4):
  125. c=Channel(self, index=i)
  126. c.record.Bind(wx.EVT_TOGGLEBUTTON, self.switch_record)
  127. c.record.index=i
  128. c.clear.Bind(wx.EVT_BUTTON, self.clear_channel)
  129. c.clear.index=i
  130. self.channels.append(c)
  131. sizer.Add(c, 1, wx.EXPAND)
  132. self.SetSizerAndFit(sizer)
  133. def switch_record(self, evt):
  134. """ Send OSC message to switch recording channel """
  135. index = evt.GetEventObject().index
  136. value = evt.GetEventObject().GetValue()
  137. for i, c in enumerate(self.channels):
  138. c.record.SetValue(0)
  139. self.channels[index].record.SetValue(value)
  140. if value:
  141. print "Record on channel %d" % index
  142. else:
  143. print "Stop recording on all channels"
  144. def clear_channel(self, evt):
  145. """ Send OSC message to clear a channel """
  146. index = evt.GetEventObject().index
  147. print "Clear channel %d" % index
  148. class MainGUI(wx.Frame):
  149. """ A simple GUI to talk to Chuck """
  150. def __init__(self):
  151. """ Constructor """
  152. # Build the interface
  153. self.app = wx.App(False)
  154. self.build()
  155. self.app.MainLoop()
  156. def build(self):
  157. """ Builds the various pieces of the GUI """
  158. wx.Frame.__init__(self, None, title="DELAY LORD")
  159. self.Bind(wx.EVT_CLOSE, self.quit)
  160. # The main sizer
  161. self.mainsizer = wx.BoxSizer(wx.VERTICAL)
  162. self.commsPanel = CommsPanel(self)
  163. self.mainsizer.Add(self.commsPanel, 0, wx.EXPAND|wx.ALL, 5)
  164. line=wx.StaticLine(self); self.mainsizer.Add(line, 0, wx.EXPAND|wx.ALL, 1)
  165. self.inputPanel = InputPanel(self)
  166. self.mainsizer.Add(self.inputPanel, 0, wx.EXPAND|wx.ALL, 5)
  167. line=wx.StaticLine(self); self.mainsizer.Add(line, 0, wx.EXPAND|wx.ALL, 1)
  168. self.delayPanel = DelayPanel(self)
  169. self.mainsizer.Add(self.delayPanel, 0, wx.EXPAND|wx.ALL, 5)
  170. line=wx.StaticLine(self); self.mainsizer.Add(line, 0, wx.EXPAND|wx.ALL, 1)
  171. self.mixer = Mixer(self)
  172. self.mainsizer.Add(self.mixer, 1, wx.EXPAND|wx.ALL, 5)
  173. # Put things together
  174. self.SetSizerAndFit(self.mainsizer)
  175. self.Show()
  176. def populate_left_panel(self):
  177. """ Populate the left panel """
  178. # Status boxes
  179. def quit(self, *args):
  180. """ Close down gracefully, and then destroy the window """
  181. self.Destroy()
  182. if __name__ == "__main__":
  183. initOSCClient(ip="127.0.0.1", port=9000)
  184. g=MainGUI()
  185. closeOSC()