Skip to content

Commit

Permalink
Added support for passing program to play(). Added constants for de…
Browse files Browse the repository at this point in the history
…fault

programs
  • Loading branch information
Caleb Smith committed Mar 18, 2013
1 parent d3911dc commit 233c42b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions sebastian/midi/player.py
@@ -1,24 +1,27 @@
## The goal of this module is to eventually be to MIDI players what ## The goal of this module is to eventually be to MIDI players what
## 'webbrowser' is to Web browsers. ## 'webbrowser' is to Web browsers.
##
## Personally, I only need it to work on OS X so patches accepted for other
## operating systems.


import sys import sys
import tempfile import tempfile
import subprocess import subprocess


from sebastian.midi import write_midi from sebastian.midi import write_midi


OPEN = 'open'
TIMIDITY = 'timidity'


def play(tracks):
def play(tracks, program=''):
f = tempfile.NamedTemporaryFile(suffix=".mid", delete=False) f = tempfile.NamedTemporaryFile(suffix=".mid", delete=False)
s = write_midi.SMF(tracks) s = write_midi.SMF(tracks)
s.write(f) s.write(f)
f.close() f.close()
if sys.platform == "darwin": if not program:
subprocess.call(["open", f.name]) if sys.platform == "darwin":
elif sys.platform == "linux2": program = OPEN
subprocess.call(["timidity", f.name]) elif sys.platform == "linux2":
program = TIMIDITY
if program:
subprocess.call([program, f.name])
else: else:
print "Only OS X supported at the moment. Patches accepted!" print 'A suitable program for your platform is unknown'

0 comments on commit 233c42b

Please sign in to comment.