Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/City/CsSched.py
diff options
context:
space:
mode:
Diffstat (limited to 'City/CsSched.py')
-rwxr-xr-xCity/CsSched.py64
1 files changed, 45 insertions, 19 deletions
diff --git a/City/CsSched.py b/City/CsSched.py
index d3288dc..c86e3dd 100755
--- a/City/CsSched.py
+++ b/City/CsSched.py
@@ -16,7 +16,8 @@
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import csnd, heapq
+import csnd
+from heapq import heappush, heappop
from CsHelpers import *
class Csound:
@@ -28,12 +29,25 @@ class Csound:
def __repr__(self):
return "Precompiled Csound object"
-
-class Sched:
- def __init__(self):
- self.queue = []
+class Sched( object ):
+ queue = []
+ time = 0
+ def __init__(self, kr=172.265625, tempo=60):
+ self.kr = kr
+ self.tempo = 60
+ def _increment(self):
+ "return the time increment value"
+ return (1.0 / self.kr) * (60.0 / self.tempo)
+ def poll(self, inc):
+ "increments the time value, and evaluates items scheduled in the past"
+ self.time += (1.0 / self.kr) * (self.tempo / 60.0) #increment the time. The question is... should I let Csound store the time. No GIL that way. hmmm.
+ for i in self.queue:
+ if self.time >= i[0]:
+ obj = heappop(self.queue)
+ (obj[1] (*obj[2]))
+ else: break
def schedEvent(self, time, func, *args):
- heapq.heappush(self.queue, (time, func, args))
+ heappush(self.queue, (time, func, args))
def getTime(self):
if self:
return self.queue[0][0]
@@ -51,13 +65,24 @@ class Sched:
return self.queue[0][2]
def __len__(self):
return len(self.queue)
- def __repr__(self):
- return str(self.queue)
-
+ def __add__(self, integer):
+ "returns now + time value"
+ return self.now() + integer
+ def __rshift__(self, beat):
+ "returns the next nth beat time"
+ return ceil(self.now()) + beat
+ def __div__(self, barlength):
+ "where barlength is the number of beats in a bar, returns a tuple of the current time represented in the form (bar no. , beat no)"
+ return divmod(self.now(), barlength)
+ def now(self):
+ return self.time
+ def reset(self, reset=0):
+ self.time = reset
+
class CsoundChan:
- "a container for Csound channel data"
+ "an empty container for Csound channel data"
#type is either Audio, Control, or String
- #Dirction = INput or Output
+ #Direction = INput or Output
#subType = interger, linear or exponential
#default = default value
#minval = suggested minimum
@@ -98,7 +123,6 @@ def channels(csound):
return result
-
class CsoundPerformer:
def pollScheduler(self, schedObj):
st = schedObj.getTime()
@@ -107,10 +131,11 @@ class CsoundPerformer:
if t >= st:
obj = heapq.heappop(schedObj.queue)
(obj[1] (*obj[2]))
- def __init__(self, schedObj, orcObj, *cs):
+ def __init__(self, metro, orcObj, *cs):
"SchedObj is a Csound timer instance, orcObJ is a CsOrcConstructor Object"
- self.Timer = csnd.CsoundTimer()
- self.schedObj = schedObj
+ #self.Timer = csnd.CsoundTimer()
+ self.metro = metro
+ #self.schedObj = schedObj
self.orcObj = orcObj
if len(cs) == 0:
cs = Csound()
@@ -118,9 +143,9 @@ class CsoundPerformer:
else: self.csound = cs[0]
self.csound.setOrchestra(orcObj.exportOrc())
self.csound.setScore(orcObj.sco)
- self.time = 0
+
if platform == "Sugar":
- self.csound.setCommand("csound -b256 -B2048 -odac --expression-opt --sched=1 -d -m0 /tmp/tmp.orc /tmp/tmp.sco")
+ self.csound.setCommand("csound -b256 -B2048 -+rtaudio=alsa -odac --expression-opt --sched=1 -d -m0 /tmp/tmp.orc /tmp/tmp.sco")
else:
self.csound.setCommand("csound -b256 -B2048 -odac --expression-opt -d -m0 /tmp/tmp.orc /tmp/tmp.sco")
self.csound.exportForPerformance()
@@ -128,9 +153,10 @@ class CsoundPerformer:
self.Channels = channels(self.csound)
self.perf = csnd.CsoundPerformanceThread(self.csound)
self.perf.Play()
- self.perf.SetProcessCallback(self.pollScheduler, schedObj)
+ self.perf.SetProcessCallback(self.metro.poll, 0)
def perfTime(self):
- return self.Timer.GetRealTime()
+ return self.metro.now()
+ #return self.Timer.GetRealTime()
def Stop(self):
self.perf.Stop()
#self.perf.Join()