2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
# mdefine.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
|
|
|
|
|
|
|
This class is used to parse lines of MDEFINE and stores
|
|
|
|
the sequences for later recall.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2009-05-17 22:34:44 +00:00
|
|
|
import MMA.midiC
|
|
|
|
|
2006-11-10 08:07:56 +00:00
|
|
|
import gbl
|
|
|
|
from MMA.common import *
|
2009-05-17 22:34:44 +00:00
|
|
|
|
2011-07-26 22:49:39 +00:00
|
|
|
def mdefine(ln):
|
|
|
|
""" Set a midi seq pattern. """
|
|
|
|
|
|
|
|
if not ln:
|
|
|
|
error("MDefine needs arguments")
|
|
|
|
|
|
|
|
name = ln[0]
|
|
|
|
if name.startswith('_'):
|
|
|
|
error("Names with a leading underscore are reserved")
|
|
|
|
|
|
|
|
if name.upper() == 'Z':
|
|
|
|
error("The name 'Z' is reserved")
|
|
|
|
|
|
|
|
mdef.set(name, ' '.join(ln[1:]))
|
|
|
|
|
|
|
|
|
|
|
|
def trackMdefine(name, ln):
|
|
|
|
""" Set a midi seq pattern. Ignore track name."""
|
|
|
|
|
|
|
|
mdefine(ln)
|
|
|
|
|
2009-05-17 22:34:44 +00:00
|
|
|
|
2006-11-10 08:07:56 +00:00
|
|
|
class Mdefine:
|
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.defs = {}
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
def get(self, name):
|
2011-07-26 22:49:39 +00:00
|
|
|
""" Return a predefined MIDI pattern."""
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
try:
|
|
|
|
return self.defs[name]
|
|
|
|
except:
|
|
|
|
error("The MDEFINE pattern %s has not been defined" % name)
|
2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
def set(self, name, ln):
|
|
|
|
""" Parse a MDEFINE line.
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
The line must be in the form:
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
NAME <beat> <ctrl> <dat> [; ...]
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
"""
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
name = name.upper()
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
ln=ln.rstrip('; ') # dump trailing ';' and whitespace
|
|
|
|
ln = ln.split(';')
|
|
|
|
evs = []
|
|
|
|
for l in ln:
|
|
|
|
l=l.split()
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
if len(l) == 1:
|
|
|
|
evs.extend( self.get(l[0].upper() ))
|
|
|
|
continue
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
if len(l) != 3:
|
|
|
|
error("MDEFINE sequence must have 3 values: Beat, Ctrl, Datum")
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
off=stof(l[0], "Value for offset must be integer/float")
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
c=MMA.midiC.ctrlToValue(l[1])
|
|
|
|
if c < 0:
|
|
|
|
c=stoi(l[1])
|
|
|
|
if c < 0 or c > 0x7f:
|
|
|
|
error("Controller values must be 0x00 to 0x7f")
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
d=stoi(l[2])
|
|
|
|
if d < 0 or d > 0x7f:
|
|
|
|
error("MIDI Control Datum value must be 0x00 to 0x7f")
|
2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
evs.append( [off, chr(c) + chr(d)])
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
self.defs[name]=evs
|
2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
mdef = Mdefine()
|
|
|
|
|