Beispiel #1
0
def new_map(args):
    srckeys, dstkey, props = args
    srcs = [find_sig(k) for k in srckeys]
    dst = find_sig(dstkey)
    if not (all(srcs) and dst):
        print(srckeys, ' and ', dstkey, ' not found on network!')
        return

    map = mpr.Map(srcs, dst)
    if not map:
        print('error: failed to create map', srckeys, "->", dstkey)
        return
    else:
        print('created map: ', srckeys, ' -> ', dstkey)
    if props and type(props) is dict:
        set_map_properties(props, map)
    else:
        map.push()
Beispiel #2
0
#!/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)
Beispiel #3
0
        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)
    dest.poll(10)

for i in range(100):
    print('updating destination to', i, '-->')
    insig.set_value(i)
    if i == 50:
        outsig[mpr.Property.DIRECTION] = mpr.Direction.INCOMING
    src.poll(10)
    dest.poll(10)
Beispiel #4
0
        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()

while not map.ready:
    src.poll(100)
    dst.poll(100)

for i in range(100):
    outsig.set_value(i)
    src.poll(10)
    dst.poll(10)

map.release()

for i in range(100):
Beispiel #5
0
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()
    dest.poll(10)

map = mpr.Map(outsig, insig).set_property(mpr.Property.EXPRESSION,
                                          "y=x").push()

while not map.ready:
    src.poll(10)
    dest.poll(10)

for i in range(100):
    r = random.randint(0, 5)
    id = random.randint(0, 5)
    if r == 0:
        print('--> retiring sender instance', id)
        outsig.instance(id).release()
    else:
        print('--> sender instance', id, 'updated to', id)
        outsig.instance(id).set_value(id)
    print_instance_ids()
Beispiel #6
0
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()
    dest.poll(10)

map = mpr.Map(outsig, insig).push()

while not map.ready:
    src.poll(10)
    dest.poll(10)

for i in range(100):
    r = random.randint(0, 5)
    id = random.randint(0, 5)
    if r == 0:
        print('--> retiring sender instance', id)
        outsig.instance(id).release()
    else:
        print('--> sender instance', id, 'updated to', id)
        outsig.instance(id).set_value(id)
    print_instance_ids()