# Path: mididings/extra/osc.py
# def SendOSC(target, path, *args):
#     """
#     Send an OSC message.
#     Parameters are the same as for :func:`liblo.send()`.
#     Additionally, instead of a specific value, each data argument may also
#     be a Python function that takes a single :class:`~.MidiEvent` parameter,
#     and returns the value to be sent.
#     """
#     return _Call(_SendOSC(target, path, args))


from mididings import *
from mididings.extra.osc import SendOSC
#
# klick.py - uses SendOSC() to start/stop klick, or change its tempo
#
# klick: http://das.nasophon.de/klick/
#
# CC 13 runs/terminates the klick process (alternatively,
# run "klick -P -o 1234"),
# CC 14 starts/stops the metronome, and CC 15 changes tempo.
#


port = 1234

run(
    Filter(CTRL) >> CtrlSplit({
        # CC 13: run/terminate klick process
        13: CtrlValueSplit(
                64,
                SendOSC(port, '/klick/quit'),
                System('klick -P -o %d' % port)
            ),
        # CC 14: start/stop playing
        14: CtrlValueSplit(
                64,
                SendOSC(port, '/klick/metro/stop'),
                SendOSC(port, '/klick/metro/start'),
            ),
        # CC 15: change tempo

# Path: mididings/extra/osc.py
# def SendOSC(target, path, *args):
#     """
#     Send an OSC message.
#     Parameters are the same as for :func:`liblo.send()`.
#     Additionally, instead of a specific value, each data argument may also
#     be a Python function that takes a single :class:`~.MidiEvent` parameter,
#     and returns the value to be sent.
#     """
#     return _Call(_SendOSC(target, path, args))


# Path: doc/examples/klick.py
from mididings import *
from mididings.extra.osc import SendOSC

#
# klick.py - uses SendOSC() to start/stop klick, or change its tempo
#
# klick: http://das.nasophon.de/klick/
#
# CC 13 runs/terminates the klick process (alternatively,
# run "klick -P -o 1234"),
# CC 14 starts/stops the metronome, and CC 15 changes tempo.
#


port = 1234

run(
    Filter(CTRL) >> CtrlSplit({
        # CC 13: run/terminate klick process
        13: CtrlValueSplit(
                64,
                SendOSC(port, '/klick/quit'),
                System('klick -P -o %d' % port)
            ),
        # CC 14: start/stop playing
        14: CtrlValueSplit(
                64,
                SendOSC(port, '/klick/metro/stop'),
                SendOSC(port, '/klick/metro/start'),
            ),
        # CC 15: change tempo

        15: SendOSC(port, '/klick/simple/set_tempo', lambda ev: 60 + ev.value)