forked from jtauber/sebastian
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for passing
program
to play(). Added constants for de…
…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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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' |