Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for passing `program` to play(). Added constants for de…

…fault

programs
  • Loading branch information...
commit 233c42bde8c6b8159a8e0c46bde378c487ea67fb 1 parent d3911dc
@calebsmith calebsmith authored
Showing with 12 additions and 9 deletions.
  1. +12 −9 sebastian/midi/player.py
View
21 sebastian/midi/player.py
@@ -1,8 +1,5 @@
## The goal of this module is to eventually be to MIDI players what
## '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 tempfile
@@ -10,15 +7,21 @@
from sebastian.midi import write_midi
+OPEN = 'open'
+TIMIDITY = 'timidity'
-def play(tracks):
+
+def play(tracks, program=''):
f = tempfile.NamedTemporaryFile(suffix=".mid", delete=False)
s = write_midi.SMF(tracks)
s.write(f)
f.close()
- if sys.platform == "darwin":
- subprocess.call(["open", f.name])
- elif sys.platform == "linux2":
- subprocess.call(["timidity", f.name])
+ if not program:
+ if sys.platform == "darwin":
+ program = OPEN
+ elif sys.platform == "linux2":
+ program = TIMIDITY
+ if program:
+ subprocess.call([program, f.name])
else:
- print "Only OS X supported at the moment. Patches accepted!"
+ print 'A suitable program for your platform is unknown'
Please sign in to comment.
Something went wrong with that request. Please try again.