Skip to content

Commit 7a71416

Browse files
committed
Compatible with wxPython 4
Compatible with wxPython 4 Fixed Python 3 issues
1 parent 8eea51b commit 7a71416

11 files changed

+3396
-1446
lines changed

abc2xml.py

+130-44
Large diffs are not rendered by default.

easy_abc.py

+54-413
Large diffs are not rendered by default.

midi/DataTypeConverters.py

+4-66
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def setNibbles(hiNibble, loNibble):
5353
def readBew(value):
5454
"""
5555
Reads string as big endian word, (asserts len(value) in [1,2,4])
56-
>>> readBew('aáâã')
56+
>>> readBew('a���')
5757
1642193635L
58-
>>> readBew('')
58+
>>> readBew('a�')
5959
25057
6060
"""
6161
return unpack('>%s' % {1:'B', 2:'H', 4:'L'}[len(value)], value)[0]
@@ -88,9 +88,9 @@ def readVar(value):
8888
might be a varlen and it will only use the relevant chars.
8989
use varLen(readVar(value)) to see how many bytes the integer value takes.
9090
asserts len(value) >= 0
91-
>>> readVar('@')
91+
>>> readVar('@')
9292
64
93-
>>> readVar('áâãa')
93+
>>> readVar('���a')
9494
205042145
9595
"""
9696
sum = 0
@@ -142,68 +142,6 @@ def fromBytes(value):
142142
return ''
143143
return pack('%sB' % len(value), *value)
144144

145-
146-
147-
if __name__ == '__main__':
148-
149-
# print to7bits(0, 3)
150-
# print to7bits(127, 3)
151-
# print to7bits(255, 3)
152-
# print to7bits(65536, 3)
153-
154-
# simple test cases
155-
156-
# print 'getHiLoHex', getNibbles(16)
157-
# print 'setHiLoHex', setNibbles(1,0)
158-
#
159-
# print 'readBew', readBew('aáâã')
160-
# print 'writeBew', writeBew(1642193635, 4)
161-
#
162-
# print 'varLen', varLen(1)
163-
#
164-
print 'readVar', readVar('€@')
165-
print 'writeVar', writeVar(8192)
166-
167-
print 'readVar', readVar('áâãa')
168-
print 'writeVar', writeVar(205058401)
169-
#
170-
# vartest = '\x82\xF7\x80\x00'
171-
# print 'toBytes', toBytes(vartest)
172-
# print 'fromBytes', fromBytes([48, 49, 50,])
173-
174-
175-
# instr = '\xFF\xFF\xFF\x00'
176-
# print 'readVar', readVar(instr)
177-
# inst2 = 268435455
178-
# print inst2
179-
# print writeVar(inst2)
180-
# print writeVar(readVar(instr))
181-
182-
s1 = 0x00000000
183-
print '%08X -' % s1, '00', writeVar(s1)
184-
s2 = 0x00000040
185-
print '%08X -' % s2, '40', writeVar(s2)
186-
s3 = 0x0000007F
187-
print '%08X -' % s3, '7F', writeVar(s3)
188-
s4 = 0x00000080
189-
print '%08X -' % s4, '81 00', writeVar(s4)
190-
s5 = 0x00002000
191-
print '%08X -' % s5, 'C0 00', writeVar(s5)
192-
s6 = 0x00003FFF
193-
print '%08X -' % s6, 'FF 7F', writeVar(s6)
194-
s7 = 0x00004000
195-
print '%08X -' % s7, '81 80 00', writeVar(s7)
196-
s8 = 0x00100000
197-
print '%08X -' % s8, 'C0 80 00', writeVar(s8)
198-
s9 = 0x001FFFFF
199-
print '%08X -' % s9, 'FF FF 7F', writeVar(s9)
200-
s10 = 0x00200000
201-
print '%08X -' % s10, '81 80 80 00', writeVar(s10)
202-
s11 = 0x08000000
203-
print '%08X -' % s11, 'C0 80 80 00', writeVar(s11)
204-
s12 = 0x0FFFFFFF
205-
print '%08X -' % s12, 'FF FF FF 7F', writeVar(s12)
206-
207145

208146

209147

midi/EventDispatcher.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from struct import unpack
55

66
# custom
7-
from DataTypeConverters import readBew, readVar, varLen, toBytes
7+
from .DataTypeConverters import readBew, readVar, varLen, toBytes
88

99
# uhh I don't really like this, but there are so many constants to
1010
# import otherwise
11-
from constants import *
11+
from .constants import *
1212

1313

1414
class EventDispatcher:
@@ -132,7 +132,7 @@ def channel_messages(self, hi_nible, channel, data):
132132

133133
else:
134134

135-
raise ValueError, 'Illegal channel message!'
135+
raise ValueError('Illegal channel message!')
136136

137137

138138

midi/MidiFileParser.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
# uhh I don't really like this, but there are so many constants to
77
# import otherwise
8-
from constants import *
8+
from .constants import *
99

10-
from EventDispatcher import EventDispatcher
10+
from .EventDispatcher import EventDispatcher
1111

1212
class MidiFileParser:
1313

@@ -45,7 +45,7 @@ def parseMThdChunk(self):
4545

4646
# check if it is a proper midi file
4747
if header_chunk_type != 'MThd':
48-
raise TypeError, "It is not a valid midi file!"
48+
raise TypeError("It is not a valid midi file!")
4949

5050
# Header values are at fixed locations, so no reason to be clever
5151
self.format = raw_in.readBew(2)

midi/MidiInFile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: ISO-8859-1 -*-
22

3-
from RawInstreamFile import RawInstreamFile
4-
from MidiFileParser import MidiFileParser
3+
from .RawInstreamFile import RawInstreamFile
4+
from .MidiFileParser import MidiFileParser
55

66

77
class MidiInFile:

midi/RawInstreamFile.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
# -*- coding: ISO-8859-1 -*-
22

3+
import sys
4+
PY3 = sys.version_info.major > 2
5+
6+
if PY3:
7+
unichr = chr
8+
xrange = range
9+
def unicode(s):
10+
return s
11+
max_int = sys.maxsize
12+
basestring = str
13+
314
# standard library imports
4-
from types import StringTypes
515
from struct import unpack
616

717
# custom import
8-
from DataTypeConverters import readBew, readVar, varLen
18+
from .DataTypeConverters import readBew, readVar, varLen
919

1020

1121
class RawInstreamFile:
@@ -28,7 +38,7 @@ def __init__(self, infile=''):
2838
copy them into memory.
2939
"""
3040
if infile:
31-
if isinstance(infile, StringTypes):
41+
if isinstance(infile, basestring):
3242
infile = open(infile, 'rb')
3343
self.data = infile.read()
3444
infile.close()
@@ -99,10 +109,10 @@ def readVarLen(self):
99109

100110
test_file = 'test/midifiles/minimal.mid'
101111
fis = RawInstreamFile(test_file)
102-
print fis.nextSlice(len(fis.data))
112+
print(fis.nextSlice(len(fis.data)))
103113

104114
test_file = 'test/midifiles/cubase-minimal.mid'
105115
cubase_minimal = open(test_file, 'rb')
106116
fis2 = RawInstreamFile(cubase_minimal)
107-
print fis2.nextSlice(len(fis2.data))
117+
print(fis2.nextSlice(len(fis2.data)))
108118
cubase_minimal.close()

0 commit comments

Comments
 (0)