#!/usr/bin/env python from __future__ import print_function import sys, random, libmapper as mpr src = mpr.Device("py.testmapfromstr.src") outsig = src.add_signal(mpr.Direction.OUTGOING, "outsig", 1, mpr.Type.INT32) dest = mpr.Device("py.testmapfromstr.dst") insig = dest.add_signal( mpr.Direction.INCOMING, "insig", 1, mpr.Type.FLOAT, None, None, None, None, lambda s, e, i, v, t: print('signal', s['name'], 'got value', v, 'at time', t.get_double()), mpr.Signal.Event.UPDATE) while not src.ready or not dest.ready: src.poll(10) dest.poll(10) map = mpr.Map("%y=(%x+100)*2", insig, outsig) map.push() while not map.ready: src.poll(10) dest.poll(10) for i in range(100): outsig.set_value(i) dest.poll(10) src.poll(0)
print(device) print(event_name(event)) def map_h(type, map, event): try: print(event.name, 'map:') for s in map.signals(mpr.Location.SOURCE): print(" src: ", s.device()['name'], ':', s['name']) for s in map.signals(mpr.Location.DESTINATION): print(" dst: ", s.device()['name'], ':', s['name']) except: print('exception') print(map) print(event_name(event)) src = mpr.Device("py.testcallbacks.src") src.graph().add_callback(device_h, mpr.Type.DEVICE) src.graph().add_callback(map_h, mpr.Type.MAP) outsig = src.add_signal(mpr.Direction.OUTGOING, "outsig", 1, mpr.Type.FLOAT, None, 0, 1000) dst = mpr.Device("py.testcallbacks.dst") dst.graph().add_callback(map_h, mpr.Type.MAP) insig = dst.add_signal(mpr.Direction.INCOMING, "insig", 1, mpr.Type.FLOAT, None, 0, 1, None, sig_h) while not src.ready or not dst.ready: src.poll() dst.poll(10) map = mpr.Map(outsig, insig) map['expr'] = "y=linear(x,0,100,0,3)" map.push()
#!/usr/bin/env python from __future__ import print_function import sys, libmapper as mpr def h(sig, event, id, val, time): try: print('--> source received', val) except: print('exception') print(sig, val) src = mpr.Device("py.testreverse.src") outsig = src.add_signal(mpr.Direction.OUTGOING, "outsig", 1, mpr.Type.FLOAT, None, 0, 1000) outsig.set_callback(h) dest = mpr.Device("py.testreverse.dst") insig = dest.add_signal(mpr.Direction.INCOMING, "insig", 1, mpr.Type.FLOAT, None, 0, 1) while not src.ready or not dest.ready: src.poll(10) dest.poll(10) map = mpr.Map(insig, outsig).push() while not map.ready: src.poll(10)
phrase += str( outsig.instance(outsig.instance_id( i, mpr.Status.ACTIVE)).get_value()[0]) phrase += ' ] ' phrase += 'active /insig: [' count = insig.num_instances(mpr.Status.ACTIVE) for i in range(count): phrase += ' ' phrase += str( insig.instance(insig.instance_id( i, mpr.Status.ACTIVE)).get_value()[0]) phrase += ' ]' print(phrase) src = mpr.Device("py.testinstance.src") outsig = src.add_signal(mpr.Direction.OUTGOING, "outsig", 1, mpr.Type.INT32, None, 0, 100, 5) outsig.reserve_instances(5) outsig.set_property(mpr.Property.EPHEMERAL, True) dest = mpr.Device("py.testinstance.dst") # reserve 0 instances to start so we can use custom indexes insig = dest.add_signal(mpr.Direction.INCOMING, "insig", 1, mpr.Type.INT32, None, 0, 1, 0, h, mpr.Signal.Event.ALL) insig.reserve_instances([100, 200, 300]) insig.set_property(mpr.Property.STEALING, mpr.Stealing.OLDEST) insig.set_property(mpr.Property.EPHEMERAL, True) while not src.ready or not dest.ready: src.poll()
except: print('Error importing libmapper module.') sys.exit(1) s = Server().boot() s.start() duty = SigTo(value=0.5, time=0.01, init=0.5, add=-0.5) freq = SigTo(value=200, time=0.01, init=200) amp = SigTo(value=0.5, time=0.01, init=0.0) p = Phasor(freq=freq, add=Clip(duty, min=-0.5, max=0.5)) sig = DCBlock(Sig(value=Round(p), mul=[amp, amp])).out() try: dev = mpr.Device("pyo_pwm_example") dev.add_signal(mpr.Direction.INCOMING, "frequency", 1, mpr.Type.FLOAT, "Hz", 0, 1000, None, lambda s, e, i, v, t: freq.setValue(v)) dev.add_signal(mpr.Direction.INCOMING, "amplitude", 1, mpr.Type.FLOAT, "normalized", 0, 1, None, lambda s, e, i, v, t: amp.setValue(v)) dev.add_signal(mpr.Direction.INCOMING, "duty", 1, mpr.Type.FLOAT, "normalized", 0, 1, None, lambda s, e, i, v, t: duty.setValue(v)) while True: dev.poll(5) finally: s.stop() del dev
import libmapper as mpr except: try: # Try the "bindings/python" directory, relative to the location of this # program, which is where it should be if the module has not been installed. sys.path.append( os.path.join( os.path.join(os.getcwd(), os.path.dirname(sys.argv[0])), '../bindings/python')) import libmapper as mpr except: print('Error importing libmapper module.') sys.exit(1) numsliders = 3 dev = mpr.Device("pysideGUI") sigs = [] for i in range(numsliders): sigs.append( dev.add_signal(mpr.Direction.OUTGOING, 'slider%i' % i, 1, mpr.Type.FLOAT, None, 0, 1)) class gui(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.setGeometry(300, 300, 300, 300) self.setFixedSize(300, 300) self.setWindowTitle('libmapper device gui example') blurb = QLabel( 'These sliders will be dynamically labeled with the name of destination signals to which they are connected.',
#!/usr/bin/env python from __future__ import print_function import sys, random, libmapper as mpr def h(sig, event, id, val, time): print(' handler got', sig['name'], '=', val, 'at time', time.get_double()) src = mpr.Device("py.testvector.src") outsig = src.add_signal(mpr.Direction.OUTGOING, "outsig", 10, mpr.Type.INT32, None, 0, 1) dest = mpr.Device("py.testvector.dst") insig = dest.add_signal(mpr.Direction.INCOMING, "insig", 10, mpr.Type.FLOAT, None, 0, 1, None, h) while not src.ready or not dest.ready: src.poll(10) dest.poll(10) map = mpr.Map(outsig, insig) map.push() while not map.ready: src.poll(10) dest.poll(10) for i in range(100): outsig.set_value(
#!/usr/bin/env python import tkinter import sys import libmapper as mpr def on_gui_change(x): sig_out.set_value(int(x)) def on_change(sig, event, id, value, timetag): w.set(int(value)) dev = mpr.Device("tkgui") sig_in = dev.add_signal(mpr.Direction.INCOMING, "input", 1, mpr.Type.INT32, None, 0, 100, None, on_change) sig_out = dev.add_signal(mpr.Direction.OUTGOING, "output", 1, mpr.Type.INT32, None, 0, 100) ui = tkinter.Tk() ui.title("libmapper Python GUI demo") name = tkinter.StringVar() name.set("Waiting for device name...") name_known = False label = tkinter.Label(ui, textvariable=name) label.pack()
sig = d.add_signal(mpr.Direction.INCOMING, "insig", 4, mpr.Type.INT32, None, None, None, None, h) print('signal properties:', sig.properties) sig = d.add_signal(mpr.Direction.OUTGOING, "outsig", 4, mpr.Type.FLOAT) print('signal properties:', sig.properties) # # try adding a signal with the same name # sig = d.add_signal(mpr.Direction.INCOMING, "outsig", 4, mpr.Type.FLOAT) print('setup done!') #check libmapper version #print('using libmapper version', mpr.version) dev1 = mpr.Device("py.test1") setup(dev1) dev2 = mpr.Device("py.test2") setup(dev2) def object_name(type): if type is mpr.Type.DEVICE: return 'DEVICE' elif type is mpr.Type.SIGNAL: return 'SIGNAL' elif type is mpr.Type.MAP: return 'MAP' def graph_cb(type, object, event):
#!/usr/bin/env python from __future__ import print_function import sys, random, libmapper as mpr def h(sig, event, id, val, time): print(' handler got', sig['name'], '=', val, 'at', time) srcs = [mpr.Device("py.testconvergent.src"), mpr.Device("py.testconvergent.src"), mpr.Device("py.testconvergent.src")] outsigs = [srcs[0].add_signal(mpr.Direction.OUTGOING, "outsig", 1, mpr.Type.INT32), srcs[1].add_signal(mpr.Direction.OUTGOING, "outsig", 1, mpr.Type.INT32), srcs[2].add_signal(mpr.Direction.OUTGOING, "outsig", 1, mpr.Type.INT32)] dest = mpr.Device("py.testconvergent.dst") insig = dest.add_signal(mpr.Direction.INCOMING, "insig", 1, mpr.Type.FLOAT, None, None, None, None, h) while not srcs[0].ready or not srcs[1].ready or not srcs[2].ready or not dest.ready: srcs[2].poll(10) srcs[0].poll(10) srcs[1].poll(10) dest.poll(10) map = mpr.Map(outsigs, insig) if not map: print('error: map not created') else: map['expr'] = "y=x$0+_x$1+_x$2" map.push()