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.

178 lines
5.7KB

  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, show_value=True, align=True):
  6. ''' Constructor '''
  7. self.show_value=show_value
  8. wx.Panel.__init__(self, parent)
  9. sizer=wx.BoxSizer(wx.HORIZONTAL)
  10. label=wx.StaticText(self, label=label, size=(100,15) if align else None)
  11. sizer.Add(label, 0, wx.RIGHT, 10)
  12. self.slider=wx.Slider(self, value=default_value*100, minValue=min_value*100, maxValue=max_value*100)
  13. sizer.Add(self.slider, 1, wx.EXPAND)
  14. if show_value:
  15. self.indicator=wx.StaticText(self, label="--", size=(50,15))
  16. sizer.Add(self.indicator, 0, wx.LEFT, 10)
  17. self.SetSizerAndFit(sizer)
  18. self.slider.Bind(wx.EVT_SCROLL, self.update)
  19. self.update(None)
  20. def update(self, evt):
  21. value=self.slider.GetValue()/100.
  22. if self.show_value: self.indicator.SetLabel("%s" % value)
  23. class InputPanel(wx.Panel):
  24. ''' Handle the ADC input settings '''
  25. def __init__(self, parent):
  26. ''' Constructor '''
  27. wx.Panel.__init__(self, parent)
  28. sizer = wx.BoxSizer(wx.HORIZONTAL)
  29. label = wx.StaticText(self, label="Line In:")
  30. font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  31. sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5)
  32. self.gain = OSCSlider(self, "Gain", default_value=.5, show_value=False, align=False)
  33. sizer.Add(self.gain, 1, wx.ALL, 5)
  34. self.thru = OSCSlider(self, "Thru", default_value=.5, show_value=False, align=False)
  35. sizer.Add(self.thru, 1, wx.ALL, 5)
  36. self.button = wx.Button(self, 1, "Kill input")
  37. sizer.Add(self.button, 0)
  38. self.SetSizerAndFit(sizer)
  39. self.gain.slider.Bind(wx.EVT_SCROLL, self.update)
  40. self.thru.slider.Bind(wx.EVT_SCROLL, self.update)
  41. self.update(None)
  42. def update(self, evt):
  43. """ Send OSC messages """
  44. a=self.gain.slider.GetValue()/100.
  45. b=self.thru.slider.GetValue()/100.
  46. try:
  47. sendOSCMsg("/input", [a, b])
  48. except OSCClientError:
  49. pass
  50. class DelayPanel(wx.Panel):
  51. ''' Handle the ADC input settings '''
  52. def __init__(self, parent):
  53. ''' Constructor '''
  54. wx.Panel.__init__(self, parent)
  55. sizer = wx.BoxSizer(wx.VERTICAL)
  56. label = wx.StaticText(self, label="Delay line:")
  57. font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  58. sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5)
  59. self.delayTime=OSCSlider(self, "Delay time (s)", default_value=5, max_value=10)
  60. sizer.Add(self.delayTime, 0, wx.EXPAND|wx.ALL, 5)
  61. self.feedback=OSCSlider(self, "Feedback", default_value=.95)
  62. sizer.Add(self.feedback, 0, wx.EXPAND|wx.ALL, 5)
  63. self.SetSizerAndFit(sizer)
  64. self.delayTime.slider.Bind(wx.EVT_SCROLL, self.update)
  65. self.feedback.slider.Bind(wx.EVT_SCROLL, self.update)
  66. self.update(None)
  67. def update(self, evt):
  68. """ Send OSC messages """
  69. a=self.delayTime.slider.GetValue()/100.
  70. b=self.feedback.slider.GetValue()/100.
  71. try:
  72. sendOSCMsg("/delay", [a, b])
  73. except OSCClientError:
  74. pass
  75. class Channel(wx.Panel):
  76. """ A single channel """
  77. def __init__(self, parent, index):
  78. self.index=index
  79. wx.Panel.__init__(self, parent)
  80. sizer = wx.BoxSizer(wx.VERTICAL)
  81. self.SetBackgroundColour((255,0,0))
  82. label = wx.StaticText(self, label="CH%d" % self.index)
  83. font = label.GetFont(); font.SetWeight(wx.BOLD); label.SetFont(font)
  84. sizer.Add(label, 0, wx.TOP|wx.BOTTOM|wx.RIGHT, 5)
  85. self.SetSizerAndFit(sizer)
  86. class ChannelPanel(wx.Panel):
  87. ''' All the channels '''
  88. def __init__(self, parent):
  89. ''' Constructor '''
  90. wx.Panel.__init__(self, parent)
  91. sizer = wx.BoxSizer(wx.HORIZONTAL)
  92. self.channels=[]
  93. for i in range(4):
  94. c=Channel(self, index=i)
  95. #self.feedback.slider.Bind(wx.EVT_SCROLL, self.update)
  96. self.channels.append(c)
  97. sizer.Add(c, 1, wx.EXPAND)
  98. self.SetSizerAndFit(sizer)
  99. self.update(None)
  100. def update(self, evt):
  101. """ Send OSC messages """
  102. pass
  103. class MainGUI(wx.Frame):
  104. """ A simple GUI to talk to Chuck """
  105. def __init__(self):
  106. """ Constructor """
  107. # Build the interface
  108. self.app = wx.App(False)
  109. self.build()
  110. self.app.MainLoop()
  111. def build(self):
  112. """ Builds the various pieces of the GUI """
  113. wx.Frame.__init__(self, None, title="DELAY LORD")
  114. self.Bind(wx.EVT_CLOSE, self.quit)
  115. # The main sizer
  116. self.mainsizer = wx.BoxSizer(wx.VERTICAL)
  117. self.inputPanel = InputPanel(self)
  118. self.mainsizer.Add(self.inputPanel, 0, wx.EXPAND|wx.ALL, 5)
  119. line=wx.StaticLine(self); self.mainsizer.Add(line, 0, wx.EXPAND|wx.ALL, 5)
  120. self.delayPanel = DelayPanel(self)
  121. self.mainsizer.Add(self.delayPanel, 0, wx.EXPAND|wx.ALL, 5)
  122. line=wx.StaticLine(self); self.mainsizer.Add(line, 0, wx.EXPAND|wx.ALL, 5)
  123. self.channelPanel = ChannelPanel(self)
  124. self.mainsizer.Add(self.channelPanel, 1, wx.EXPAND|wx.ALL, 5)
  125. # Put things together
  126. self.SetSizerAndFit(self.mainsizer)
  127. self.Show()
  128. self.SetSize((400,500))
  129. def populate_left_panel(self):
  130. """ Populate the left panel """
  131. # Status boxes
  132. def quit(self, *args):
  133. """ Close down gracefully, and then destroy the window """
  134. self.Destroy()
  135. if __name__ == "__main__":
  136. initOSCClient(ip="127.0.0.1", port=9000)
  137. g=MainGUI()
  138. closeOSC()