Sampler in ChucK
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

244 linhas
8.1KB

  1. from libs.simpleosc import *
  2. import wx
  3. def sendOSCSave(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. self.master = wx.ToggleButton(self, 1, "Master/Minion")
  30. sizer.Add(self.master, 0, wx.ALL, 3)
  31. self.ip=wx.TextCtrl(self, value="127.0.0.1")
  32. sizer.Add(self.ip, 0, wx.ALL, 3)
  33. self.port=wx.TextCtrl(self, value="9000")
  34. sizer.Add(self.port, 0, wx.ALL, 3)
  35. self.SetSizerAndFit(sizer)
  36. class InputPanel(wx.Panel):
  37. ''' Handle the ADC input settings '''
  38. def __init__(self, parent):
  39. ''' Constructor '''
  40. wx.Panel.__init__(self, parent)
  41. sizer = wx.BoxSizer(wx.HORIZONTAL)
  42. label = wx.StaticText(self, label="Line in:")
  43. font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  44. sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5)
  45. self.gain = OSCSlider(self, "Gain", default_value=.5, align=False)
  46. sizer.Add(self.gain, 1, wx.ALL, 5)
  47. self.thru = OSCSlider(self, "Thru", default_value=.5, align=False)
  48. sizer.Add(self.thru, 1, wx.ALL, 5)
  49. self.mute = wx.ToggleButton(self, 1, "Mute")
  50. #self.mute.SetValue(1)
  51. sizer.Add(self.mute, 0)
  52. self.SetSizerAndFit(sizer)
  53. self.gain.Bind(wx.EVT_SCROLL, self.update)
  54. self.thru.Bind(wx.EVT_SCROLL, self.update)
  55. self.mute.Bind(wx.EVT_TOGGLEBUTTON, self.update)
  56. self.update()
  57. def update(self, evt=None):
  58. """ Send OSC messages """
  59. gain=self.gain.slider.GetValue()/100.
  60. thru=self.thru.slider.GetValue()/100.
  61. if self.mute.GetValue(): gain, thru = 0.,0.
  62. sendOSCMsg("/input", [gain, thru])
  63. class DelayPanel(wx.Panel):
  64. ''' Handle the ADC input settings '''
  65. def __init__(self, parent):
  66. ''' Constructor '''
  67. wx.Panel.__init__(self, parent)
  68. sizer = wx.BoxSizer(wx.VERTICAL)
  69. label = wx.StaticText(self, label="Delay lines:")
  70. font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  71. sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5)
  72. self.delayTime=OSCSlider(self, "Delay time (s)", default_value=1, max_value=10)
  73. sizer.Add(self.delayTime, 0, wx.EXPAND|wx.ALL, 5)
  74. self.feedback=OSCSlider(self, "Feedback", default_value=.99)
  75. sizer.Add(self.feedback, 0, wx.EXPAND|wx.ALL, 5)
  76. self.metronome=wx.ToggleButton(self, 0, "Metronome")
  77. sizer.Add(self.metronome, 0, wx.EXPAND|wx.ALL, 5)
  78. self.SetSizerAndFit(sizer)
  79. self.delayTime.Bind(wx.EVT_SCROLL, self.update)
  80. self.feedback.Bind(wx.EVT_SCROLL, self.update)
  81. self.metronome.Bind(wx.EVT_TOGGLEBUTTON, self.switchMetronome)
  82. self.update(None)
  83. def update(self, evt):
  84. """ Send OSC messages """
  85. a=self.delayTime.slider.GetValue()/100.
  86. b=self.feedback.slider.GetValue()/100.
  87. sendOSCMsg("/delay", [a, b])
  88. def switchMetronome(self, evt):
  89. """ Send OSC messages """
  90. sendOSCMsg("/metronome", [int(self.metronome.GetValue())])
  91. class Channel(wx.Panel):
  92. """ A single channel """
  93. def __init__(self, parent, index):
  94. self.index=index
  95. wx.Panel.__init__(self, parent)
  96. sizer = wx.BoxSizer(wx.VERTICAL)
  97. label = wx.StaticText(self, label="CH%d" % self.index)
  98. font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  99. sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5)
  100. self.gain = OSCSlider(self, "Gain", default_value=1, max_value=1.3, align=False)
  101. sizer.Add(self.gain, 0, wx.ALL|wx.EXPAND, 3)
  102. self.pan = OSCSlider(self, "Pan", default_value=0, min_value=-1, max_value=1, align=False)
  103. sizer.Add(self.pan, 0, wx.ALL|wx.EXPAND, 3)
  104. self.record = wx.ToggleButton(self, 1, "Arm")
  105. sizer.Add(self.record, 0, wx.ALL|wx.EXPAND if index==0 else wx.ALL|wx.EXPAND, 3)
  106. self.mute = wx.ToggleButton(self, 1, "Mute")
  107. sizer.Add(self.mute, 0, wx.ALL|wx.EXPAND, 3)
  108. self.clear = wx.Button(self, 1, "Clear")
  109. sizer.Add(self.clear, 0, wx.ALL|wx.EXPAND, 3)
  110. self.SetSizerAndFit(sizer)
  111. self.gain.Bind(wx.EVT_SCROLL, self.update)
  112. self.pan.Bind(wx.EVT_SCROLL, self.update)
  113. self.mute.Bind(wx.EVT_TOGGLEBUTTON, self.update)
  114. self.update()
  115. def update(self, evt=None):
  116. gain=self.gain.GetValue()/100.
  117. pan=self.pan.GetValue()/100.
  118. if self.mute.GetValue(): gain=0.0;
  119. sendOSCMsg("/channel", [self.index, gain, pan])
  120. class Mixer(wx.Panel):
  121. ''' All the channels '''
  122. def __init__(self, parent):
  123. ''' Constructor '''
  124. wx.Panel.__init__(self, parent)
  125. sizer = wx.BoxSizer(wx.HORIZONTAL)
  126. self.channels=[]
  127. for i in range(4):
  128. c=Channel(self, index=i)
  129. c.record.Bind(wx.EVT_TOGGLEBUTTON, self.switch_record)
  130. c.record.index=i
  131. c.clear.Bind(wx.EVT_BUTTON, self.clear_channel)
  132. c.clear.index=i
  133. self.channels.append(c)
  134. sizer.Add(c, 1, wx.EXPAND)
  135. self.SetSizerAndFit(sizer)
  136. def switch_record(self, evt):
  137. """ Send OSC message to switch recording channel """
  138. index = evt.GetEventObject().index
  139. value = evt.GetEventObject().GetValue()
  140. for i, c in enumerate(self.channels):
  141. c.record.SetValue(0)
  142. self.channels[index].record.SetValue(value)
  143. sendOSCMsg("/arm", [index if value else -1])
  144. def clear_channel(self, evt):
  145. """ Send OSC message to clear a channel """
  146. index = evt.GetEventObject().index
  147. sendOSCMsg("/clear", [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()