Exemple #1
0
  def x_offset(self):
    return(self.x_of_time(self.time_offset))
  # convenience functions
  def time_of_x(self, x):
    return(float(x) / self._pixels_per_second)
  def x_of_time(self, time):
    return(float(time) * self._pixels_per_second)
  def height_of_track(self, track):
    min_height = 4 * self.pitch_height
    pitches_height = len(track.pitches) * self.pitch_height
    controllers_height = len(track.controllers) * self.controller_height
    return(max(min_height, pitches_height + controllers_height))
  @property
  def track_spacing(self):
    return(6.0)
serializable.add(ViewScale)

# represent a document, which collects the elements of a persistent workspace
class Document(Model):
  def __init__(self, tracks=None, devices=None, transport=None,
                     view_scale=None, units=None, patch_bay=None):
    Model.__init__(self)
    # the file path to save to
    self.path = None
    # transport
    if (transport is None):
      transport = Transport()
    self.transport = transport
    # time scale
    if (view_scale is None):
      view_scale = ViewScale()
Exemple #2
0
  def name(self):
    if (len(self._name) > 0):
      return(self._name)
    return(self.short_device_name)
  @name.setter
  def name(self, name):
    if (name != self._name):
      self._name = name
      self.on_change()
  # adapter serialization
  def serialize(self):
    return({ 
      'device_name': self._device_name,
      'device_flags': self._device_flags
    })
serializable.add(DeviceAdapter)

# make a class to manage a list of adapters
class DeviceAdapterList(observable.List):
  def __init__(self, adapters=()):
    # map devices by name
    self._name_map = dict()
    observable.List.__init__(self, adapters)
    # make a client connection to jack
    self._client = jackpatch.Client('jackdaw-devices')
    # scan for devices on a regular basis
    self.startTimer(1000)
  # get an adapter for the device with the given name
  def adapter_named(self, name):
    if (name not in self._name_map):
      self.append(DeviceAdapter(device_name=name))
Exemple #3
0
            self._path_loading = False
            self._path_loaded = (self._progress >= 100)
            return
        # ask for another progress report
        self._sampler.call('GET CHANNEL INFO %d' % self._channel.channel_id,
                           self._on_progress)

    def _on_progress(self, result):
        if ((result) and ('INSTRUMENT_STATUS' in result)):
            self._progress = int(result['INSTRUMENT_STATUS'])

    def serialize(self):
        return ({'name': self.name, 'path': self.path})


serializable.add(Instrument)


class InstrumentList(observable.List):
    def __init__(self, instruments=()):
        observable.List.__init__(self, instruments)

    # adapter list serialization
    def serialize(self):
        return ({'instruments': list(self)})


serializable.add(InstrumentList)


# make a unit that represents a list of sampler instruments
Exemple #4
0
        self._client.connect(source, sink)
  # track serialization
  def serialize(self):
    return({ 
      'name': self.name,
      'blocks': list(self),
      'solo': self.solo,
      'mute': self.mute,
      'arm': self.arm,
      'pitch_names': self.pitch_names,
      'bend_range': self.bend_range,
      'controller_names': self.controller_names,
      'controller_outputs': self.controller_outputs,
      'transport': self.transport
    })
serializable.add(Track)

# represent a controller's output on a track
class ControllerTrackOutput(unit.Source, Model):
  def __init__(self, number, value=0.0, client=None):
    self._client = None
    self._number = number
    self._value = 0.0
    Model.__init__(self)
    unit.Source.__init__(self)
    self._source_type = 'midi'
    self.client = client
    self.value = value
  @property
  def client(self):
    return(self._client)
Exemple #5
0
      self._progress_timer = None
      self._path_loading = False
      self._path_loaded = (self._progress >= 100)
      return
    # ask for another progress report
    self._sampler.call('GET CHANNEL INFO %d' % self._channel.channel_id, 
      self._on_progress)
  def _on_progress(self, result):
    if ((result) and ('INSTRUMENT_STATUS' in result)):
      self._progress = int(result['INSTRUMENT_STATUS'])
  def serialize(self):
    return({ 
      'name': self.name,
      'path': self.path
    })
serializable.add(Instrument)

class InstrumentList(observable.List):
  def __init__(self, instruments=()):
    observable.List.__init__(self, instruments)
  # adapter list serialization
  def serialize(self):
    return({ 
      'instruments': list(self)
    })
serializable.add(InstrumentList)

# make a unit that represents a list of sampler instruments
class InstrumentListUnit(unit.Unit):
  def __init__(self, instruments, *args, **kwargs):
    unit.Unit.__init__(self, *args, **kwargs)
Exemple #6
0
import jackpatch

import observable
import serializable
import unit

class SystemPlaybackUnit(unit.Sink, unit.Unit):
  def __init__(self, *args, **kwargs):
    unit.Unit.__init__(self, *args, **kwargs)
    unit.Sink.__init__(self)
    self._sink_type = 'stereo'
    self._client = jackpatch.Client('jackdaw-playback')
    ports = self._client.get_ports(name_pattern='system:.*', 
                                   flags=jackpatch.JackPortIsInput)
    self._sink_port = tuple(ports)
serializable.add(SystemPlaybackUnit)
Exemple #7
0
                pitch=self.pitch,
                velocity=self.velocity,
                duration=self.duration))
  def __repr__(self):
    return('Note(time=%0.9g, pitch=%d, velocity=%g, duration=%0.9g)' %
            (self.time, self.pitch, self.velocity, self.duration))
  def serialize(self):
    return({ 
      'time': self.time,
      'pitch': self.pitch,
      'velocity': self.velocity,
      'duration': self.duration,
      'bend': self.bend,
      'aftertouch': self.aftertouch
    })
serializable.add(Note)

# represents a single control-change message with time, controller number, 
#  and controller value
class CCSet(Model):
  def __init__(self, time=None, number=None, value=None):
    Model.__init__(self)
    self._time = time
    self._number = number
    self._value = value
  # the time relative to the beginning of its container when the 
  #  controller setting takes effect (in seconds)
  @property
  def time(self):
    return(self._time)
  @time.setter
Exemple #8
0
import jackpatch

import observable
import serializable
import unit


class SystemPlaybackUnit(unit.Sink, unit.Unit):
    def __init__(self, *args, **kwargs):
        unit.Unit.__init__(self, *args, **kwargs)
        unit.Sink.__init__(self)
        self._sink_type = 'stereo'
        self._client = jackpatch.Client('jackdaw-playback')
        ports = self._client.get_ports(name_pattern='system:.*',
                                       flags=jackpatch.JackPortIsInput)
        self._sink_port = tuple(ports)


serializable.add(SystemPlaybackUnit)
Exemple #9
0
    if (mark is not None):
      self.time = mark.time
  def next_mark(self, *args):
    mark = self.get_next_mark(self.time)
    if (mark is not None):
      self.time = mark.time
  # transport serialization
  def serialize(self):
    return({
      'time': self.time,
      'duration': self.duration,
      'cycling': self.cycling,
      'marks': list(self.marks),
      'protocol': self.protocol
    })
serializable.add(Transport)

# a model to store a marked timepoint on a transport
class Mark(observable.Object):
  def __init__(self, time=0.0):
    observable.Object.__init__(self)
    self._time = time
  @property
  def time(self):
    return(self._time)
  @time.setter
  def time(self, value):
    if (value != self._time):
      self._time = value
      self.on_change()
  # overload the less-than operator for sorting by time
Exemple #10
0
    self.y = rect.y() + (rect.height() / 2)
  # unit serialization
  def serialize(self):
    obj = { 
      'name': self.name,
      'x': self.x,
      'y': self.y
    }
    if (self.width > 0):
      obj['width'] = self.width
    if (self.height > 0):
      obj['height'] = self.height
    if (self.hue is not None):
      obj['hue'] = self.hue
    return(obj)
serializable.add(Unit)

# represent a list of units
class UnitList(ModelList):
  def __init__(self, units=()):
    ModelList.__init__(self, units)
  # track serialization
  def serialize(self):
    return({ 
      'units': list(self)
    })
serializable.add(UnitList)

# make a unit that groups other units so they can be moved together
class GroupUnit(Unit):
  def __init__(self, units=(), *args, **kwargs):