abcplay.py my_collection.abc:3:7:8 another_collection.abc
+An example of using timidity options would be slowing down a tune
+while you are learning::
+
+ abcplay.py --timidity '--adjust-tempo 50' my_collection.abc:3
+
SIGINT (usually ^C) will kill the current tune and proceed the next
one. Two SIGINTs in less than one second will kill the abcplay.py
-process.
+process. This should be familiar to users of mpg123_ or ogg123_.
.. _abc2midi: http://abc.sourceforge.net/abcMIDI/
.. _timidity: http://timidity.sourceforge.net/
+.. _mpg123: http://www.mpg123.org/
+.. _ogg123: http://www.vorbis.com
"""
+import shlex
from subprocess import Popen
from tempfile import mkstemp
from time import time
REFNUM_SEP = ':'
class ABCPlayer (object):
- def __init__(self):
+ def __init__(self, abc2midi_options=None, timidity_options=None):
f,self._tempfile = mkstemp(prefix='abcplay-', suffix='.midi')
+ self._abc2midi = ['abc2midi']
+ if abc2midi_options:
+ self._abc2midi.extend(abc2midi_options)
+ self._timidity = ['timidity']
+ if timidity_options:
+ self._timidity.extend(timidity_options)
self._last_interrupt = 0
self._p = None
def _convert_to_midi(self, filename, refnum):
self._p = Popen(
- ['abc2midi', filename, str(refnum), '-o', self._tempfile])
+ self._abc2midi + [filename, str(refnum), '-o', self._tempfile])
self._p.wait()
self._p = None
def _play_midi(self):
- self._p = Popen(['timidity', self._tempfile])
+ self._p = Popen(self._timidity + [self._tempfile])
self._p.wait()
self._p = None
import sys
import optparse
- usage = '%prog file[:refnum[:refnum:...]] ...'
+ usage = '%prog [options] file[:refnum[:refnum:...]] ...'
epilog = __doc__
p = optparse.OptionParser(usage=usage, epilog=epilog)
p.format_epilog = lambda formatter: epilog+'\n'
+ p.add_option('-a', '--abc2midi', dest='abc2midi',
+ help='Extra options to pass to abc2midi.')
+ p.add_option('-t', '--timidity', dest='timidity',
+ help='Extra options to pass to timidity.')
options,args = p.parse_args()
del p
- p = ABCPlayer()
+ abc2midi = options.abc2midi
+ if abc2midi:
+ abc2midi = shlex.split(abc2midi)
+ timidity = options.timidity
+ if timidity:
+ timidity = shlex.split(timidity)
+
+ p = ABCPlayer(abc2midi, timidity)
try:
p.play_files(args)
finally: