Jump To …

ins1.py

import random

turnoff_ins = 10101
def turnoff (ins, instance):
  sco = 'i%d 0 0.0001 %d.%d' % (turnoff_ins, ins, instance)
  return sco

class Ins1_1:
  def __init__(self, amp, min_freq, max_freq):
    self.amp = amp
    self.min_freq = min_freq
    self.max_freq = max_freq
    self.instr = 1
    self.zeroes = 2 + 3
  def on(self, instance, ctrl):
    amp = self.amp
    pan = random.random()
    freq = random.uniform(self.min_freq, self.max_freq)
    sco = 'i%d.%d 0 -1 %f %f %f' % (self.instr, instance, amp, pan, freq)
    return sco
  def off(self, instance):
    return turnoff(self.instr, instance)
 
class Ins11_1:
  def __init__(self, amp, min_freq, max_freq, fn):
    self.amp = amp
    self.min_freq = min_freq
    self.max_freq = max_freq
    self.fn = fn
    self.instr = 11
    self.zeroes = 2 + 4
  def on(self, instance, ctrl):
    amp = self.amp
    pan = random.random()
    freq = random.uniform(self.min_freq, self.max_freq)
    fn = self.fn
    sco = 'i%d.%d 0 -1 %f %f %f %d' % (self.instr, instance, amp, pan, freq, fn)
    return sco
  def off(self, instance):
    return turnoff(self.instr, instance)
 
class Ins21_1:
  def __init__(self, amp, min_freq, max_freq):
    self.amp = amp
    self.min_freq = min_freq
    self.max_freq = max_freq
    self.instr = 21
    self.zeroes = 2 + 4
  def on(self, instance, ctrl):
    amp = self.amp
    pan = random.random()
    freq1 = random.uniform(self.min_freq, self.max_freq)
    freq2 = freq1 + random.uniform(0, freq1/10)
    sco = 'i%d.%d 0 -1 %f %f %f %f' % (self.instr, instance, amp, pan, freq1, freq2)
    return sco
  def off(self, instance):
    return turnoff(self.instr, instance)

class Ins21_2:
  def __init__(self, amp, min_freq1, max_freq1, min_freq2, max_freq2):
    self.amp = amp
    self.min_freq1 = min_freq1
    self.max_freq1 = max_freq1
    self.min_freq2 = min_freq2
    self.max_freq2 = max_freq2
    self.instr = 21
    self.zeroes = 2 + 4
  def on(self, instance, ctrl):
    amp = self.amp
    pan = random.random()
    freq1 = random.randint(self.min_freq1, self.max_freq1)
    freq2 = random.randint(self.min_freq2, self.max_freq2)
    sco = 'i%d.%d 0 -1 %f %f %f %f' % (self.instr, instance, amp, pan, 
        freq1, freq2)
    return sco
  def off(self, instance):
    return turnoff(self.instr, instance)


class Ins31_1:
  def __init__(self, amp, min_freq1, max_freq1, min_freq2, max_freq2, hp):
    self.amp = amp
    self.min_freq1 = min_freq1
    self.max_freq1 = max_freq1
    self.min_freq2 = min_freq2
    self.max_freq2 = max_freq2
    self.hp = hp
    self.instr = 31
    self.zeroes = 2 + 5
  def on(self, instance, ctrl):
    amp = self.amp
    pan = random.random()
    freq1 = random.uniform(self.min_freq1, self.max_freq1)
    freq2 = random.uniform(self.min_freq2, self.max_freq2)
    hp = self.hp
    sco = 'i%d.%d 0 -1 %f %f %f %f %f' % (self.instr, instance, amp, pan, 
        freq1, freq2, hp)
    return sco
  def off(self, instance):
    return turnoff(self.instr, instance)


class Ins41_1:
  def __init__(self, amp):
    self.amp = amp
    self.instr = 41
    self.zeroes = 2 + 3
  def on(self, instance, ctrl):
    amp = self.amp
    pan = random.random()
    betamod = random.random()
    sco = 'i%d.%d 0 -1 %f %f %f' % (self.instr, instance, amp, pan, betamod)
    return sco
  def off(self, instance):
    return turnoff(self.instr, instance)
 
 
class Ins51_1:
  def __init__(self, amp, fco_min, fco_max, res_min, res_max):
    self.amp = amp
    self.fco_min = fco_min
    self.fco_max = fco_max
    self.res_min = res_min
    self.res_max = res_max
    self.instr = 51
    self.zeroes = 2 + 4
  def on(self, instance, ctrl):
    amp = self.amp
    pan = random.random()
    fco = random.randint(self.fco_min, self.fco_max)
    res = random.randint(self.res_min, self.res_max)
    sco = 'i%d.%d 0 -1 %f %f %f %f' % (self.instr, instance, amp, pan, fco, res)
    return sco
  def off(self, instance):
    return turnoff(self.instr, instance)

class Ins61_1:
  def __init__(self, amp, min_freq, max_freq, fn):
    self.amp = amp
    self.min_freq = min_freq
    self.max_freq = max_freq
    self.fn = fn
    self.instr = 61
    self.zeroes = 2 + 4
  def on(self, instance, ctrl):
    amp = self.amp
    pan = random.random()
    freq = random.uniform(self.min_freq, self.max_freq)
    fn = self.fn
    sco = 'i%d.%d 0 -1 %f %f %f %d' % (self.instr, instance, amp, pan, freq, fn)
    return sco
  def off(self, instance):
    return turnoff(self.instr, instance)

class Ins71_1:
  def __init__(self, amp, fco_min, fco_max, res_min, res_max, num,
      start_max, dur_max):
    self.amp = amp
    self.fco_min = fco_min
    self.fco_max = fco_max
    self.res_min = res_min
    self.res_max = res_max
    self.start_max = start_max
    self.dur_max = dur_max
    self.num = num
    self.instr = 71
    self.zeroes = 2 + 4
  def on(self, instance, ctrl):
    amp = self.amp
    num = self.num
    sco = ''
    first = True
    for i in range(num):
      pan = random.random()
      fco = random.randint(self.fco_min, self.fco_max)
      res = random.randint(self.res_min, self.res_max)
      if first:
        start = 0
        first = False
      start = abs(random.uniform(0,ctrl['js'].ax[2]*self.start_max))
      dur = abs(random.uniform(0,ctrl['js'].ax[3]*self.dur_max))
      sco += 'i%d.%d %f %f %f %f %f %f\n' % (self.instr, instance, start, dur, 
          amp, pan, fco, res)
    return sco
  def off(self, instance):
    sco = ''
    return sco