forked from geokala/music_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm210run
More file actions
executable file
·68 lines (58 loc) · 2.12 KB
/
Copy pathm210run
File metadata and controls
executable file
·68 lines (58 loc) · 2.12 KB
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
#! /usr/bin/env python
# The line above tells some systems (e.g. Linux/Apple shells) what program to
# use to execute this script.
# Import the libraries we need
import os
import sys
from music21 import (
clef,
environment,
metadata,
meter,
note,
stream,
)
# Tell music21 what to use to play midi and display score
environment.set('midiPath', '/usr/bin/timidity')
environment.set('musicxmlPath', '/usr/bin/musescore')
# Only run this if the script is executed directly, not imported
if __name__ == '__main__':
# Complain if there were no arguments passed by the user
if len(sys.argv) < 3:
# First, print a helpful message
print('add a "score" argument to see the score.')
print('add a "text" argument to see the python objects.')
print('add a "midi" argument to hear it.')
print('e.g. To hear the tune: {command} midi'.format(
command=sys.argv[0],
))
# Now exit without doing anything
sys.exit()
src_path = sys.argv[1]
with open(src_path) as src_handle:
src = src_handle.read()
code = compile(
src,
os.path.basename(src_path),
'exec',
)
exec(code)
remaining_args = sys.argv[2:]
# See if the user put the word 'midi' in the arguments
if 'midi' in remaining_args:
# The stream.Score (tune) object knows how to play itself using the
# environment set midi player and will do so when its show method is
# called with a 'midi' argument.
tune.show('midi')
# See if the user put the word 'text' in the arguments
if 'text' in remaining_args:
# The stream.Score (tune) object knows how to display itself as python
# objects in text, and will do so when its show method is called with
# a 'text' argument.
tune.show('text')
# See if the user put the word 'score' in the arguments
if 'score' in remaining_args:
# The stream.Score (tune) object knows how to display itself as
# musical score, and will do so by default when its show method is
# called with no arguments.
tune.show()