Jump To …

dmc.py

#!/usr/bin/env python

remember that some event loop (joystick or keyboard) is required to play the CSD file, since dmc uses perf.Play() not cs.Perform().

platforms: windows jack jack with autoconnect to system ins and outs jack_manual jack without autoconnect, use connect or patchbay in qjackctl

import sys, os
from optparse import OptionParser

If this script is called 'dmc.py' it will choose itself as the dmc module, so replace sys.path[0], the script directory, with the script parent directory where dmc/ is located.

sys.path[0] = os.path.dirname(sys.path[0])

usage = 'usage: %prog [options]'
parser = OptionParser(usage=usage)

parser.add_option('-p', '--platform', metavar='PLATFORM', help='set platform',
    default='windows')
parser.add_option('-b', '--buffer_size', metavar='SAMPLES', 
    type='int', help='set buffer size', default=512)
parser.add_option('-j', '--js', action='store_true', 
    help='enable joystick')
parser.add_option('--print_js', action='store_true', 
    help='print joystick actions')
parser.add_option('--js_loop_delay', metavar='SECONDS', 
    type='float', help='joystick loop polling delay', default=0.001)
parser.add_option('--js_ax_threshold', metavar='SECONDS', 
    type='float', help='joystick minimum axis change to trigger event', 
    default=0.0001)
parser.add_option('--js_hathit_threshold', metavar='NUMBER', 
    type='float', help='joystick hathit debounce threshold', 
    default=0.1/0.0001)
parser.add_option('--js_auto_hathit_threshold', metavar='NUMBER', type='float', 
    help='automatically calculate joystick hathit debounce threshold', 
    default=0.1/0.0001)

parser.add_option('--js_number', help='set joystick number', 
    metavar='NUMBER', type='int', default='0')
parser.add_option('-c', '--csd_file', help='set csd file', metavar='CSD',
    default='dmc/csd/pyces.csd')

(options, args) = parser.parse_args()
print('options', options)

def print_event(t, e):
  print(t,e)  

Csound

from dmc.cs import Cs
cs = Cs()
cs.platform = options.platform
cs.buffer_size = options.buffer_size
cs.init()
cs.run()

Instrument

from dmc.cond import Cond
cond = Cond()
cond.cs = cs
cond.init()

Joystick

if options.js:
  print('Configuring joystick %d' % (options.js_number))
  from dmc.js import Js
  js = Js()
  if options.js_number:
    js.js_number = options.js_number
  if options.js_loop_delay:
    js.loop_delay = options.js_loop_delay
  if options.js_ax_threshold:
    js.ax_threshold = options.js_ax_threshold
  if options.js_hathit_threshold:
    js.hathit_threshold = options.js_hathit_threshold
  if options.js_auto_hathit_threshold:
    js.auto_hathit_threshold()
  js.add_event_listener('init', print_event)
  js.add_event_listener('axis', cond.js_event_callback)
  js.add_event_listener('button', cond.js_event_callback)
  js.add_event_listener('hat', cond.js_event_callback)
  js.init()

  if (options.print_js):
    from dmc.print_js import PrintJs
    pjs = PrintJs()
    js.add_event_listener('axis', pjs.on_js_event)
    js.add_event_listener('hat', pjs.on_js_event)
    js.add_event_listener('button', pjs.on_js_event)

  cond.js = js
  js.run()