/usr/bin/mididings is in mididings 0~20120419~ds0-5.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #! /usr/bin/python
# -*- coding: utf-8 -*-
#
# mididings
#
# Copyright (C) 2008-2012 Dominic Sacré <dominic.sacre@gmx.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
import sys
import os
import optparse
import mididings
import mididings.extra
import mididings.setup
class Dings(object):
def __init__(self, options):
if options.backend:
self.config(backend=options.backend)
if options.client_name:
self.config(client_name=options.client_name)
if options.start_delay:
self.config(start_delay=options.start_delay)
if options.in_ports or options.in_connections:
in_ports = self.make_port_definitions(options.in_connections, options.in_ports)
self.config(in_ports=in_ports)
if options.out_ports or options.out_connections:
out_ports = self.make_port_definitions(options.out_connections, options.out_ports)
self.config(out_ports=out_ports)
self.dings_dict = mididings.__dict__.copy()
self.dings_dict.update(mididings.extra.__dict__)
def config(self, **kwargs):
mididings.setup._config_impl(override=True, **kwargs)
def make_port_definitions(self, connections, nports):
if connections is None:
return nports
elif nports < len(connections):
connections = connections[:nports]
elif nports > len(connections):
connections += [None] * (nports - len(connections))
return [(None, c) for c in connections]
def run_file(self, filename):
# add filename's directory to sys.path to allow import from the same directory
d = os.path.dirname(filename)
if not d:
d = '.'
sys.path.insert(0, d)
# just a kludge to make AutoRestart() work
sys.modules['__mididings_main__'] = type('MididingsMain', (), {'__file__': os.path.abspath(filename)})
if sys.version_info >= (3,):
exec(compile(open(filename).read(), filename, 'exec'), self.dings_dict)
else:
execfile(filename, self.dings_dict)
# avoid memory leaks
self.dings_dict.clear()
def run_patch(self, patch):
mididings.run(eval(patch, self.dings_dict))
if __name__ == '__main__':
usage = "Usage: mididings [options] \"patch\"\n" \
" mididings [options] -f filename.py"
epilog = "The -I and -O options may be specified multiple times, once for each port.\n\n" \
"The -f option executes a regular mididings Python script. Command line arguments " \
"override config settings in that file."
version = "mididings %s" % mididings.__version__
parser = optparse.OptionParser(usage=usage, epilog=epilog, version=version)
parser.add_option('-b', dest='backend', help="name of backend to use")
parser.add_option('-c', dest='client_name', help="ALSA or JACK client name")
parser.add_option('-i', dest='in_ports', type=int, help="number of input ports")
parser.add_option('-o', dest='out_ports', type=int, help="number of output ports")
parser.add_option('-I', dest='in_connections', type=str, action='append', help='input port connection (regular expression)')
parser.add_option('-O', dest='out_connections', type=str, action='append', help='output port connection (regular expression)')
parser.add_option('-d', dest='start_delay', type=float, help="delay (in seconds) before starting MIDI processing")
parser.add_option('-f', dest='filename', help="file name of script to run")
options, args = parser.parse_args(sys.argv[1:])
if len(args) == 0 and not options.filename:
parser.error("no patch and no filename specified")
elif len(args) > 1:
parser.error("more than one patch specified")
app = Dings(options)
if options.filename:
app.run_file(options.filename)
else:
app.run_patch(args[0])
|