Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

OSC note output, and PStaticSeq/PDecisionPoint for mode-switching dec…

…isions based on global statics
  • Loading branch information...
commit 2aa7f074a9409625c300ad32740e95fbb5bd31ac 1 parent ccb8e02
Daniel Jones authored
View
10 isobar/io/midi.py
@@ -17,11 +17,10 @@ def __init__(self, target = MIDIIN_DEFAULT):
for n in range(pypm.CountDevices()):
info = pypm.GetDeviceInfo(n)
name = info[1]
- print "[%d] %s %s" % (n, name, info)
+ # print "[%d] %s %s" % (n, name, info)
isInput = info[2]
if name == target and isInput == 1:
self.midi = pypm.Input(n)
- print "xx found target input: %s" % target
if self.midi is None:
raise Exception, "Could not find MIDI source: %s" % target
@@ -70,7 +69,7 @@ def __destroy__(self):
class MidiOut:
- def __init__(self):
+ def __init__(self, target = MIDIOUT_DEFAULT):
pypm.Initialize()
self.midi = None
self.debug = False
@@ -79,10 +78,13 @@ def __init__(self):
info = pypm.GetDeviceInfo(n)
name = info[1]
isOutput = info[3]
- if name == MIDIOUT_DEFAULT and isOutput == 1:
+ if name == target and isOutput == 1:
self.midi = pypm.Output(n, 1)
print "Found MIDI output (%s)" % name
+ if self.midi is None:
+ raise Exception, "Could not find MIDI source: %s" % target
+
def tick(self, ticklen):
pass
View
38 isobar/io/osc.py
@@ -1,6 +1,40 @@
+import pypm
import random
import time
-class OscOut:
- def __init__(self):
+from OSC import *
+
+from isobar.note import *
+
+MIDIIN_DEFAULT = "IAC Driver A"
+MIDIOUT_DEFAULT = "IAC Driver A"
+
+class OSCOut:
+ def __init__(self, host = "localhost", port = 7000):
+ self.osc = OSCClient()
+ self.osc.connect((host, port))
+ self.debug = False
+
+ def tick(self, ticklen):
pass
+
+ def noteOn(self, note = 60, velocity = 64, channel = 0):
+ if self.debug:
+ print "channel %d, noteOn: %d" % (channel, note)
+ msg = OSCMessage("/note", [ channel, note, velocity ])
+ self.osc.send(msg)
+
+ def noteOff(self, note = 60, channel = 0):
+ if self.debug:
+ print "channel %d, noteOff: %d" % (channel, note)
+ msg = OSCMessage("/note", [ channel, note, 0 ])
+ self.osc.send(msg)
+
+ def allNotesOff(self, channel = 0):
+ if self.debug:
+ print "channel %d, allNotesOff"
+ for n in range(128):
+ self.noteOff(n, channel)
+
+ def __destroy__(self):
+ self.osc.close()
View
29 isobar/pattern/core.py
@@ -5,6 +5,7 @@
import sys
import copy
import random
+import inspect
import itertools
import isobar
@@ -167,6 +168,19 @@ def reset(self):
def append(self, other):
return PConcat([ self, other ])
+ @property
+ def timeline(self):
+ """ returns the timeline that i am embedded in, if any """
+ stack = inspect.stack()
+ for frame in stack:
+ frameobj = frame[0]
+ args, _, _, value_dict = inspect.getargvalues(frameobj)
+ if len(args) and args[0] == 'self':
+ instance = value_dict.get('self', None)
+ classname = instance.__class__.__name__
+ if classname == "Timeline":
+ return instance
+
@staticmethod
def fromgenotype(genotype):
""" create a new object based on this genotype """
@@ -275,8 +289,19 @@ class PDict(Pattern):
""" PDict: Dict of patterns
Thanks to Dan Stowell <http://www.mcld.co.uk/>
"""
- def __init__(self, dict = {}):
- self.dict = dict
+ def __init__(self, value = {}):
+
+ from isobar.pattern.sequence import *
+
+ if type(value) == dict:
+ self.dict = value
+ elif type(value) == list:
+ keys = value[0].keys()
+ print "transforming a list of dicts into a dict of PSeqs"
+ self.dict = {}
+ for key in keys:
+ print " - %s" % key
+ self.dict[key] = PSeq([ item[key] for item in value ], 1)
def __getitem__(self, key):
return self.dict[key]
View
1  isobar/pattern/fade.py
@@ -113,6 +113,7 @@ def __init__(self, *args, **kwargs):
random.shuffle(self.ordering)
def fade_in(self):
+ print "fading between %d and %d" % (self.rate_min, self.rate_max)
fade_count = random.randint(self.rate_min, self.rate_max)
if fade_count < 1: fade_count = 1
print "fading in %d times" % fade_count
View
23 isobar/pattern/sequence.py
@@ -611,3 +611,26 @@ def next(self):
rv = sequence[self.pos]
self.pos += 1
return rv
+
+class PDecisionPoint(Pattern):
+ def __init__(self, fn):
+ self.fn = fn
+ self.pattern = self.fn()
+
+ def next(self):
+ print "next"
+ try:
+ print "enxt from pat"
+ return self.pattern.next()
+ except StopIteration:
+ print "STOPITERATION"
+ sys.stderr.write("HI?!")
+ self.pattern = self.fn()
+ # ?!?!!
+ # if not self.pattern:
+ # causes this to break horribly in the PStaticSeq case
+ # -- seems to try to evaluate self.pattern as a list
+ if self.pattern is None:
+ return None
+ return self.next()
+
View
30 isobar/pattern/static.py
@@ -41,6 +41,7 @@ def get_beats(self):
# determine the Timeline object we are embedded within and return
# its current number of beats.
#------------------------------------------------------------------------
+ """
stack = inspect.stack()
for frame in stack:
frameobj = frame[0]
@@ -54,6 +55,11 @@ def get_beats(self):
# a value of N.9999999....
#------------------------------------------------------------------------
return instance.beats
+ """
+ timeline = self.timeline
+ if timeline:
+ return timeline.beats
+
return 0
class PStaticGlobal(Pattern):
@@ -63,7 +69,8 @@ class PStaticGlobal(Pattern):
def __init__(self, name, value = None):
self.name = name
- PStaticGlobal.set(name, value)
+ if value is not None:
+ PStaticGlobal.set(name, value)
def next(self):
name = Pattern.value(self.name)
@@ -71,6 +78,7 @@ def next(self):
@classmethod
def set(self, key, value):
+ print "setting %s to %s" % (key, value)
PStaticGlobal.dict[key] = value
@classmethod
@@ -106,3 +114,23 @@ def next(self):
rv = math.sin(2 * math.pi * beats / self.period)
return rv
+
+class PStaticSeq(Pattern):
+ def __init__(self, sequence, duration):
+ self.sequence = sequence
+ self.duration = duration
+ self.start = None
+
+ def next(self):
+ timeline = self.timeline
+ if self.start is None:
+ self.start = round(timeline.beats, 5)
+
+ now = round(timeline.beats, 5)
+ if now - self.start >= self.duration:
+ self.sequence.pop(0)
+ self.start = now
+ if len(self.sequence) == 0:
+ raise StopIteration
+ return self.sequence[0]
+
Please sign in to comment.
Something went wrong with that request. Please try again.