[Csnd] Flexx Csound interface
Date | 2018-09-23 13:43 |
From | Richard |
Subject | [Csnd] Flexx Csound interface |
Last time I mentioned Flexx, a pure Python solution to create
GUI's in the browser. Here is a complete example with 4 sliders controlling ADSR of a csd.
""" Flexx Csound interface zappfinger, 23SEP2018 """ import sys sys.path.insert(0, '/Users/richard/py35env/lib/python3.5/site-packages') from csoundSession import CsoundSession from flexx import flx, ui, event class ThemedForm(flx.Widget): # lives in JS def init(self): flx.Label(text='Att:') self.slider1 = flx.Slider(min=0.01, max=2, value=.5, flex=0) flx.Label(text='Dec:') self.slider2 = flx.Slider(min=0, max=6, value=0, flex=0) flx.Label(text='Sus:') self.slider3 = flx.Slider(min=1, max=10, value=5, flex=0) flx.Label(text='Rel:') self.slider4 = flx.Slider(min=0, max=6, value=0, flex=1) @flx.reaction def _update(self, *events): att, dec, sus, rel = self.slider1.value, self.slider2.value, self.slider3.value, self.slider4.value self.root.cses.update(att, dec, sus, rel) class CsSession(flx.PyComponent): # Lives in Python cs = CsoundSession("/Users/richard/PycharmProjects/OSCall/csds/Mono_Synth.csd") @flx.action def update(self, *events): self.cs.setControlChannel('att', events[0]) self.cs.setControlChannel('dec', events[1]) self.cs.setControlChannel('sus', events[2]) self.cs.setControlChannel('rel', events[3]) self.cs.setControlChannel('pitchglide', 1.5) class MyApp(flx.PyComponent): cses = flx.ComponentProp() def init(self): self._mutate_cses(CsSession()) self.ui = ThemedForm() if __name__ == '__main__': app = flx.App(MyApp) app.serve('') #m = flx.launch(MyApp, 'chrome-app') flx.run() |