VocalEasel/mma/MMA/patBass.py

137 lines
3.4 KiB
Python
Raw Permalink Normal View History

2006-11-10 08:07:56 +00:00
2007-04-29 06:47:40 +00:00
# patBass.py
2006-11-10 08:07:56 +00:00
"""
2007-04-29 06:47:40 +00:00
This module is an integeral part of the program
2006-11-10 08:07:56 +00:00
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
"""
2007-04-29 06:47:40 +00:00
2006-11-10 08:07:56 +00:00
2009-05-17 22:34:44 +00:00
import MMA.notelen
import MMA.harmony
2006-11-10 08:07:56 +00:00
import gbl
from MMA.common import *
from MMA.pat import PC
class Bass(PC):
2007-04-29 06:47:40 +00:00
""" Pattern class for a bass track. """
2011-07-26 22:49:39 +00:00
2007-04-29 06:47:40 +00:00
vtype = 'BASS'
2011-07-26 22:49:39 +00:00
2007-04-29 06:47:40 +00:00
def getPgroup(self, ev):
""" Get group for bass pattern.
Fields - start, length, note, volume
"""
if len(ev) != 4:
error("There must be n groups of 4 in a pattern definition, "
"not <%s>" % ' '.join(ev) )
a = struct()
a.offset = self.setBarOffset(ev[0])
2009-05-17 22:34:44 +00:00
a.duration = MMA.notelen.getNoteLen( ev[1] )
2007-04-29 06:47:40 +00:00
offset = ev[2]
n=offset[0]
if n in "1234567":
a.noteoffset = int(n)-1
else:
error("Note offset in Bass must be '1'...'7', not '%s'" % n )
n = offset[1:2]
if n == "#":
a.accidental = 1
ptr = 2
elif n == 'b' or n == 'b' or n == '&':
a.accidental = -1
ptr = 2
else:
a.accidental = 0
ptr = 1
a.addoctave = 0
for n in ev[2][ptr:]:
if n == '+':
a.addoctave += 12
elif n == '-':
a.addoctave -= 12
else:
error("Only '- + # b &' are permitted after a noteoffset, not '%s'" % n)
a.vol = stoi(ev[3], "Note volume in Bass definition not int")
return a
def restart(self):
self.ssvoice = -1
def trackBar(self, pattern, ctable):
""" Do the bass bar.
Called from self.bar()
"""
sc = self.seq
unify = self.unify[sc]
for p in pattern:
ct = self.getChordInPos(p.offset, ctable)
if ct.bassZ:
continue
note = ct.chord.scaleList[p.noteoffset] + p.addoctave + p.accidental
if not self.harmonyOnly[sc]:
self.sendNote(
p.offset,
self.getDur(p.duration),
self.adjustNote(note),
self.adjustVolume(p.vol, p.offset))
if self.harmony[sc]:
2009-05-17 22:34:44 +00:00
h = MMA.harmony.harmonize(self.harmony[sc], note, ct.chord.noteList)
2011-07-26 22:49:39 +00:00
strumOffset = self.getStrum(sc)
2007-04-29 06:47:40 +00:00
for n in h:
self.sendNote(
2011-07-26 22:49:39 +00:00
p.offset + strumOffset,
2007-04-29 06:47:40 +00:00
self.getDur(p.duration),
self.adjustNote(n),
self.adjustVolume(p.vol * self.harmonyVolume[sc], -1))
2011-07-26 22:49:39 +00:00
strumOffset += self.getStrum(sc)
2007-04-29 06:47:40 +00:00
2006-11-10 08:07:56 +00:00