2006-11-10 08:07:56 +00:00
|
|
|
# opts.py
|
|
|
|
|
|
|
|
"""
|
|
|
|
This module is an integeral part of the program
|
|
|
|
MMA - Musical Midi Accompaniment.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
Bob van der Poel <bob@mellowood.ca>
|
2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import getopt
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import MMA.docs
|
|
|
|
import MMA.parse
|
|
|
|
import MMA.chords
|
2009-05-17 22:34:44 +00:00
|
|
|
import MMA.alloc
|
|
|
|
import MMA.volume
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2009-05-17 22:34:44 +00:00
|
|
|
import gbl
|
|
|
|
from MMA.common import *
|
|
|
|
from MMA.macro import macros
|
2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
def opts():
|
2007-04-29 06:47:40 +00:00
|
|
|
""" Option parser. """
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
try:
|
|
|
|
opts, args = getopt.gnu_getopt(sys.argv[1:],
|
2009-05-17 22:34:44 +00:00
|
|
|
"dpsS:ri:wneom:f:M:cgGvD:01PT:", [] )
|
2007-04-29 06:47:40 +00:00
|
|
|
except getopt.GetoptError:
|
|
|
|
usage()
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
for o,a in opts:
|
|
|
|
|
|
|
|
if o == '-d':
|
|
|
|
gbl.debug = gbl.Ldebug = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-o':
|
|
|
|
gbl.showFilenames = gbl.LshowFilenames = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-p':
|
|
|
|
gbl.pshow = gbl.Lpshow = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-s':
|
|
|
|
gbl.seqshow = gbl.Lseqshow = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-S':
|
|
|
|
ln = a.split('=', 1)
|
|
|
|
macros.setvar(ln)
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-r':
|
|
|
|
gbl.showrun = gbl.Lshowrun = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-w':
|
|
|
|
gbl.noWarn = gbl.LnoWarn = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-n':
|
|
|
|
gbl.noOutput = gbl.LnoOutput = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-e':
|
|
|
|
gbl.showExpand = gbl.LshowExpand = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-c':
|
|
|
|
gbl.chshow = gbl.Lchshow = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-f':
|
|
|
|
gbl.outfile = a
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-i':
|
|
|
|
gbl.mmaRC = a
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-g':
|
|
|
|
gbl.makeGrvDefs = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-G':
|
|
|
|
gbl.makeGrvDefs = 2
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-m':
|
|
|
|
try:
|
|
|
|
a=int(a)
|
|
|
|
except:
|
|
|
|
error("Expecting -m arg to be a integer")
|
|
|
|
gbl.maxBars = a
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-v':
|
|
|
|
print "%s" % gbl.version
|
|
|
|
sys.exit(0)
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-M':
|
|
|
|
if a in ['0', '1']:
|
|
|
|
gbl.cmdSMF = a
|
|
|
|
else:
|
|
|
|
error("Only a '0' or '1' is permitted for the -M arg")
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2009-05-17 22:34:44 +00:00
|
|
|
elif o == '-T': # set tracks to generate, mute all others
|
|
|
|
gbl.muteTracks = a.upper().split(',')
|
|
|
|
|
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-D':
|
|
|
|
if a == 'xl':
|
2009-05-17 22:34:44 +00:00
|
|
|
gbl.createDocs = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif a == 'xh':
|
2009-05-17 22:34:44 +00:00
|
|
|
gbl.createDocs = 2
|
|
|
|
|
|
|
|
elif a == 'v':
|
|
|
|
gbl.createDocs = 3
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif a == 'k':
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2009-05-17 22:34:44 +00:00
|
|
|
def pl(msg, lst, adds):
|
2007-04-29 06:47:40 +00:00
|
|
|
print msg,
|
2009-05-17 22:34:44 +00:00
|
|
|
for i in sorted(lst.keys() + adds):
|
2007-04-29 06:47:40 +00:00
|
|
|
print i,
|
|
|
|
print "\n"
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2009-05-17 22:34:44 +00:00
|
|
|
pl("Base track names:", MMA.alloc.trkClasses, [])
|
|
|
|
pl("Commands:", MMA.parse.simpleFuncs,
|
|
|
|
["BEGIN", "END",] )
|
|
|
|
pl("TrackCommands:", MMA.parse.trackFuncs, [])
|
2007-04-29 06:47:40 +00:00
|
|
|
print "Not complete ... subcommands, comments, chords..."
|
|
|
|
sys.exit(0)
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
else:
|
|
|
|
print "Unknown -D option."
|
|
|
|
usage()
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
elif o == '-0':
|
|
|
|
gbl.synctick = 1
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2009-05-17 22:34:44 +00:00
|
|
|
elif o == '-1':
|
|
|
|
gbl.endsync = 1
|
|
|
|
|
|
|
|
elif o == '-P':
|
|
|
|
gbl.playFile = 1
|
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
else:
|
|
|
|
usage() # unreachable??
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2009-05-17 22:34:44 +00:00
|
|
|
# we have processed all the args. Should just have a filename left
|
|
|
|
|
|
|
|
if len(args)>1:
|
|
|
|
usage("Only one input filename is permitted, %s given on command line." % len(args) )
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2009-05-17 22:34:44 +00:00
|
|
|
if gbl.infile:
|
|
|
|
usage("Input filename already assigned ... should not happen.")
|
|
|
|
|
|
|
|
if args:
|
|
|
|
gbl.infile = args[0]
|
2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
def usage(msg=''):
|
2007-04-29 06:47:40 +00:00
|
|
|
""" Usage message. """
|
|
|
|
|
|
|
|
txt=[
|
|
|
|
"MMA - Musical Midi Accompaniment",
|
|
|
|
" Copyright 2003-5, Bob van der Poel. Version %s" % gbl.version ,
|
|
|
|
" Distributed under the terms of the GNU Public License.",
|
|
|
|
" Usage: mma [opts ...] INFILE [opts ...]",
|
|
|
|
"",
|
|
|
|
"Options:",
|
|
|
|
" -c display default Channel assignments",
|
|
|
|
" -d enable lots of Debugging messages",
|
|
|
|
" -Dk print list of MMA keywords",
|
|
|
|
" -Dxl eXtract Latex doc blocks from file",
|
|
|
|
" -Dxh eXtract HTML doc blocks from file",
|
2009-05-17 22:34:44 +00:00
|
|
|
" -Dv extract lots of info about the grooves/seqs in file",
|
2007-04-29 06:47:40 +00:00
|
|
|
" -e show parsed/Expanded lines",
|
|
|
|
" -f <file> set output Filename",
|
|
|
|
" -g update Groove dependency database",
|
|
|
|
" -G create Groove dependency database",
|
|
|
|
" -i <file> specify init (mmarc) file",
|
|
|
|
" -m <x> set Maxbars (default == 500)",
|
|
|
|
" -M <x> set SMF to 0 or 1",
|
|
|
|
" -n No generation of midi output",
|
|
|
|
" -o show complete filenames when Opened",
|
|
|
|
" -p display Patterns as they are defined",
|
|
|
|
" -r display Running progress",
|
|
|
|
" -s display Sequence info during run",
|
|
|
|
" -S <var[=data]> Set macro 'var' to 'data'",
|
2009-05-17 22:34:44 +00:00
|
|
|
" -T <tracks> Limit generation to specified tracks",
|
2007-04-29 06:47:40 +00:00
|
|
|
" -v display Version number",
|
|
|
|
" -w disable Warning messages",
|
2009-05-17 22:34:44 +00:00
|
|
|
" -0 create sync at start of all channel tracks",
|
|
|
|
" -1 create sync at end of all channel tracks" ]
|
2007-04-29 06:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
for a in txt:
|
|
|
|
print a
|
|
|
|
|
|
|
|
if msg:
|
|
|
|
print
|
|
|
|
print msg
|
|
|
|
|
|
|
|
print
|
|
|
|
sys.exit(1)
|
2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
|