2006-11-10 08:07:56 +00:00
|
|
|
# midiM.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 module contains the MIDI number (un)packing routines.
|
|
|
|
|
|
|
|
These are necessary to create the MSB/LSB stuff that
|
|
|
|
MIDI expects.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def intToWord(x):
|
2011-07-26 22:49:39 +00:00
|
|
|
""" Convert INT to a 2 byte MSB LSB value. Used in MIDI headers. """
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
return chr(x>>8 & 0xff) + chr(x & 0xff)
|
2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
def intTo3Byte(x):
|
2007-04-29 06:47:40 +00:00
|
|
|
""" Convert INT to a 3 byte MSB...LSB value. """
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
return intToLong(x)[1:]
|
2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
def intToLong(x):
|
2007-04-29 06:47:40 +00:00
|
|
|
""" Convert INT to a 4 byte MSB...LSB value. """
|
2006-11-10 08:07:56 +00:00
|
|
|
|
2007-04-29 06:47:40 +00:00
|
|
|
return intToWord(x>>16) + intToWord(x)
|
2006-11-10 08:07:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def intToVarNumber(x):
|
2007-04-29 06:47:40 +00:00
|
|
|
""" Convert INT to a variable length MIDI value. """
|
|
|
|
|
|
|
|
lst = chr(x & 0x7f)
|
|
|
|
while 1:
|
|
|
|
x = x >> 7
|
|
|
|
if x:
|
|
|
|
lst = chr((x & 0x7f) | 0x80) + lst
|
|
|
|
else:
|
|
|
|
return lst
|
2006-11-10 08:07:56 +00:00
|
|
|
|