Ver Fonte

Getting things clean again

Grissess há 10 anos atrás
pai
commit
bd176a81f6
2 ficheiros alterados com 40 adições e 30 exclusões
  1. 31 6
      broadcast.py
  2. 9 24
      voice.py

+ 31 - 6
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:

+ 9 - 24
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)