aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrissess <grissess@nexusg.org>2015-12-19 12:28:26 -0500
committerGrissess <grissess@nexusg.org>2015-12-19 12:28:26 -0500
commitbd176a81f66f7f4c4884a5ddf7e7bb5c5ef97591 (patch)
treea7cc79f7b69ea7e9ce0b4ef01060acca34a0722e
parentac8c88f49e196fe98b0230bb0cb8a8fbbd53380c (diff)
Getting things clean again
-rw-r--r--broadcast.py37
-rw-r--r--voice.py33
2 files changed, 40 insertions, 30 deletions
diff --git a/broadcast.py b/broadcast.py
index 3b163b1..b597268 100644
--- a/broadcast.py
+++ b/broadcast.py
@@ -320,8 +320,7 @@ for fname in args:
for route in routeset.routes:
print route
-<<<<<<< HEAD
-class NSThread(threading.Thread):
+ class NSThread(threading.Thread):
def drop_missed(self):
nsq, cl = self._Thread__args
cnt = 0
@@ -331,9 +330,6 @@ class NSThread(threading.Thread):
if options.verbose:
print self, 'dropped', cnt, 'notes due to miss'
self._Thread__args = (nsq, cl)
-=======
- class NSThread(threading.Thread):
->>>>>>> 7c9661d892f6145d123d91924b720d9d87b69502
def wait_for(self, t):
if t <= 0:
return
@@ -351,8 +347,37 @@ class NSThread(threading.Thread):
if options.verbose:
print (time.time() - BASETIME), cl, ': PLAY', pitch, dur, vel
self.wait_for(dur - ((time.time() - BASETIME) - factor*ttime))
+=======
+ class NSThread(threading.Thread):
+ def drop_missed(self):
+ nsq, cl = self._Thread__args
+ cnt = 0
+ while nsq and float(nsq[0].get('time'))*factor < time.time() - BASETIME:
+ nsq.pop(0)
+ cnt += 1
+>>>>>>> Stashed changes
if options.verbose:
- print '% 6.5f'%(time.time() - BASETIME,), cl, ': DONE'
+ print self, 'dropped', cnt, 'notes due to miss'
+ self._Thread__args = (nsq, cl)
+ def wait_for(self, t):
+ if t <= 0:
+ return
+ time.sleep(t)
+ def run(self):
+ nsq, cl = self._Thread__args
+ for note in nsq:
+ ttime = float(note.get('time'))
+ pitch = int(note.get('pitch')) + options.transpose
+ vel = int(note.get('vel'))
+ dur = factor*float(note.get('dur'))
+ while time.time() - BASETIME < factor*ttime:
+ self.wait_for(factor*ttime - (time.time() - BASETIME))
+ s.sendto(str(Packet(CMD.PLAY, int(dur), int((dur*1000000)%1000000), int(440.0 * 2**((pitch-69)/12.0)), int(vel*2 * options.volume/255.0))), cl)
+ if options.verbose:
+ print (time.time() - BASETIME), cl, ': PLAY', pitch, dur, vel
+ self.wait_for(dur - ((time.time() - BASETIME) - factor*ttime))
+ if options.verbose:
+ print '% 6.5f'%(time.time() - BASETIME,), cl, ': DONE'
threads = []
for ns in notestreams:
diff --git a/voice.py b/voice.py
index f440a68..b31aa84 100644
--- a/voice.py
+++ b/voice.py
@@ -36,6 +36,7 @@ most abstracted:
import math
import pyaudio
import struct
+import time
def norm_theta(theta):
return theta % (2*math.pi)
@@ -49,30 +50,6 @@ def theta2lin(theta):
def lin2theta(lin):
return lin * 2*math.pi
-class ParamInfo(object):
- PT_ANY = 0x0000
- PT_CONST = 0x0001
- PT_SPECIAL = 0x0002
- PT_INT = 0x0100
- PT_FLOAT = 0x0200
- PT_STR = 0x0400
- PT_THETA = 0x0102
- PT_TIME_SEC = 0x0202
- PT_SAMPLES = 0x0302
- PT_REALTIME = 0x0402
- def __init__(self, name, tp=PT_ANY):
- self.name = name
- self.tp = tp
-
-class GenInfo(object):
- def __init__(self, name, *params):
- self.name = name
- self.params = list(params)
-
-class Generator(object):
- class __metaclass__(type):
- def __init__(self
-
class Voice(object):
@classmethod
def register_gen(cls, name, params):
@@ -114,3 +91,11 @@ class VSumMixer(Voice):
self.voices = list(voices)
def __call__(self, theta):
return norm_amp(sum([i(theta) for i in self.voices]))
+
+class VLFOMixer(Voice):
+ def __init__(self, lfo, *voices):
+ self.lfo = lfo
+ self.voices = list(voices)
+ def __call__(self, theta):
+ i = int(len(self.voices) * self.lfo * (time.time() % (1.0 / self.lfo)))
+ return self.voices[i](theta)