Jump To …

cond.py

import datetime
from types import ListType, FunctionType
from ins import ins1
import groups

turnoff_instr = 10101

class Cond:
  def __init__(self):
    self.cs = None
    self.playing = {}
    self.recording_dmc = None
    self.recording_ext = None
    self.callbacks = {}
    self.callbacks['button'] = self.button_callback
    self.callbacks['axis'] = self.axis_callback
    self.callbacks['hat'] = self.hat_callback

PS2 setup

    self.js = None
    self.button_record_dmc = 8
    self.button_output_mode = 9
    self.instrument_triggers = [4, 5, 6, 7]
    self.instrument_trigger_set = set(self.instrument_triggers)
    self.group = 0

0: normal 1: 0dbfs 2: input

    self.output_mode = 0; 

  def init(self):
    pass

keep in mind that we need to keep the playing id if we sustain across a group switch

  def button_callback(self, e):
    if e[0] == self.button_record_dmc:
      if e[1]:
        if self.recording_dmc:
          print 'END DMC RECORDING %s' % (self.recording_dmc)
          self.cs.score('i%d 0 0.001 10200' % (turnoff_instr))
          self.recording_dmc = None
        else:
          filename = '%s_dmc.wav' % (timestamp())
          print 'BEGIN DMC RECORDING %s' % (filename)
          self.cs.score('i10200 0 -1 "%s"' % (filename))
          self.recording_dmc = filename

kind of brittle. If first output mode is changed in CSD or something goes wrong here...

    elif e[0] == self.button_output_mode:
      if e[1]:
        old_output_mode = self.output_mode
        self.output_mode = (self.output_mode + 1) % 3
        print('output_mode', self.output_mode)
        self.cs.score('i%d 0 0.001 %d' % (10102, 10000 + old_output_mode))
        self.cs.score('i%d 0 -1' % (10000 + self.output_mode))

    elif e[0] in self.instrument_trigger_set:
      i = self.instrument_triggers.index(e[0])
      if e[1]:
        if (type(groups.group[self.group]) is ListType):
          print('dict')
          ins = groups.group[self.group][i]
        elif (type(groups.group[self.group]) is FunctionType):
          print('function')
          ins = groups.group[self.group]()[i]
        sco = ins.on(i, {'js': self.js})
        print(sco)
        self.playing[i] = ins
        print ('ON  ' + sco)
        self.cs.score(sco)
      else:
        sco = self.playing[i].off(i)
        print(sco)
        print ('OFF ' + sco)
        self.cs.score(sco)

  def axis_callback(self, e):
    self.cs.cs.SetChannel('ax' + str(e[0]), e[1])

  def hat_callback(self, e):
    if e[0] == 0:
      if e[1] == 0:
        self.group += e[2]
        if self.group > groups.num_groups - 1:
          self.group = 0
        elif self.group < 0:
          self.group = groups.num_groups - 1
      print ('group', self.group) 

  def js_event_callback(self, event_type, e):
    self.callbacks[event_type](e)

def timestamp():
  d = datetime.datetime.now()
  return '%s%02d%02d_%02d%02d%02d' % (str(d.year)[2:], d.month, d.day, d.hour, 
    d.minute, d.second)