Jump To …

cs.py

import csnd

class Cs:
  def __init__(self):
    self.event_types = []
    self.event_listeners = {}
    for event_type in self.event_types:
      self.event_listeners[event_type] = [] 
    self.csd_file = 'dmc/csd/dmc.csd'
    self.platform = 'windows'
    self.buffer_size = 512
    self.test = 200

  def event(self, event_type, e):
    for l in self.event_listeners[event_type]:
      l(event_type, e)

  def add_event_listener(self, event_type, listener):
    self.event_listeners[event_type].append(listener)
    return len(self.event_listeners[event_type]) - 1

  def init(self):
    self.cs = csnd.Csound()

figure out arguments

    self.cs_args = csnd.CsoundArgVList()
    cs_args = []

capture is disabled right now '-iadc:system:capture_',

    if self.platform == 'jack':
      cs_args = ['-d', '-g', '--sched', 
          '-iadc:system:capture_', 
          '-odac:system:playback_', '-+rtaudio=jack', '-W', '-R']
    elif self.platform == 'jack_manual':
      cs_args = ['-d', '-g', '--sched', 
          '-odac', '-+rtaudio=jack', '-W', '-R']
    elif self.platform == 'windows':
      cs_args = ['-d', '-g', '-odac']
    elif self.platform == 'none':
      cs_args = []
    cs_args.append('-B ' + str(self.buffer_size))
    for a in cs_args:
      self.cs_args.Append(a)
    self.cs_args.Append(self.csd_file)

When using this, remember that perf.Play() will only keep the score playing while the perf object exists, so the client will have to run a loop. cs.Perform() will play a whole score.

  def run(self):
    self.cs = csnd.Csound()
    self.cs.SetMessageLevel(231)
    self.cs.Compile(self.cs_args.argc(), self.cs_args.argv())
    self.perf = csnd.CsoundPerformanceThread(self.cs)
    self.perf.Play()

  def score(self, s):    
    self.perf.InputMessage(s)

  def set_process_callback(self, process_callback):
    self.perf.SetProcessCallback(process_callback, self.cs)

  def stop(self):
    self.perf.Stop()
    self.perf.Join()
    self.cs.cleanup()