Permalink
Browse files

added PStaticTimelineSine

  • Loading branch information...
1 parent c3c7304 commit ccb8e0207649eb2c3b38ed644ab9481c4a8bbfe1 Daniel Jones committed May 1, 2012
Showing with 22 additions and 2 deletions.
  1. +1 −0 isobar/pattern/chance.py
  2. +2 −0 isobar/pattern/operator.py
  3. +19 −2 isobar/pattern/static.py
View
@@ -252,6 +252,7 @@ def next(self):
if self.pos >= 1:
self.pos -= 1
return self.pattern.next()
+ return None
class PFlipFlop(Pattern):
""" PFlipFlop: flip a binary bit with some probability.
@@ -91,7 +91,9 @@ def next(self):
args = [ Pattern.value(value) for value in self.args ]
kwargs = dict((key, Pattern.value(value)) for key, value in self.kwargs.items())
value = self.input.next()
+ print "applying sin to %f" % value
rv = self.operator(value, *args, **kwargs)
+ print "output is %f" % rv
return rv
class PMapEnumerated(PMap):
View
@@ -1,6 +1,7 @@
from isobar.pattern.core import *
import inspect
+import math
class PStaticViaOSC (Pattern):
initialised = False
@@ -32,6 +33,10 @@ def __init__(self):
pass
def next(self):
+ beats = self.get_beats()
+ return round(beats, 5)
+
+ def get_beats(self):
#------------------------------------------------------------------------
# determine the Timeline object we are embedded within and return
# its current number of beats.
@@ -48,8 +53,7 @@ def next(self):
# round to 5 DP to prevent rounding errors which may give us
# a value of N.9999999....
#------------------------------------------------------------------------
- return round(instance.beats, 5)
-
+ return instance.beats
return 0
class PStaticGlobal(Pattern):
@@ -89,3 +93,16 @@ def recv(self, msg, source = None):
key = msg[2]
value = msg[3]
PStaticGlobal.set(key, value)
+
+class PStaticTimelineSine(PStaticTimeline):
+ def __init__(self, period):
+ self.period = period
+
+ def next(self):
+ period = Pattern.value(self.period)
+ # self.phase += math.pi * 2.0 / period
+
+ beats = self.get_beats()
+ rv = math.sin(2 * math.pi * beats / self.period)
+ return rv
+

0 comments on commit ccb8e02

Please sign in to comment.