Skip to content

Commit dbc2aca

Browse files
committed
midi2abc fix by Seymour
Fix from a while back to enable import of midi-files using Python 3.
1 parent 7d5a45d commit dbc2aca

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

easy_abc.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -887,11 +887,10 @@ def abc_to_svg(abc_code, cache_dir, settings, target_file_name=None, with_annota
887887
stderr_value = os.linesep.join([x for x in stderr_value.splitlines()
888888
if not x.startswith('abcm2ps-') and not x.startswith('File ') and not x.startswith('Output written on ')])
889889
stderr_value = stderr_value.strip()
890-
if not os.path.exists(svg_file_first) or 'svg: ' in stderr_value:
891-
return ([], stderr_value)
892-
else:
890+
if os.path.exists(svg_file_first):
893891
return (GetSvgFileList(svg_file_first), stderr_value)
894-
892+
else:
893+
return ([], stderr_value)
895894

896895

897896
def AbcToAbc(abc_code, cache_dir, params, abc2abc_path=None):

fluidsynth.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ def b(s):
3232

3333
if platform.system() == 'Windows':
3434
script_path = os.path.dirname(os.path.abspath(__file__))
35+
import struct
36+
bytesPerPointer = struct.calcsize("P")
3537
fluidsynth_lib_path = script_path + '\\bin\\fluidsynth'
38+
if (bytesPerPointer == 4):
39+
fluidsynth_lib_path += '\\X86'
40+
3641
envpath = os.environ.get('PATH', '')
3742
os.environ['PATH'] = fluidsynth_lib_path + ';' + envpath
38-
lib = 'libfluidsynth-2.dll'
43+
lib = fluidsynth_lib_path + '\\libfluidsynth-2.dll'
3944
else:
4045
lib = 'libfluidsynth.so.2'
4146

midi/MidiFileParser.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def parseMThdChunk(self):
4242

4343
header_chunk_type = raw_in.nextSlice(4)
4444
header_chunk_zise = raw_in.readBew(4)
45-
4645
# check if it is a proper midi file
4746
if header_chunk_type != b'MThd':
4847
raise TypeError("It is not a valid midi file!")
@@ -189,4 +188,4 @@ def parseMTrkChunks(self):
189188
midi_in = MidiFileParser(RawInstreamFile(test_file), MidiToText())
190189
midi_in.parseMThdChunk()
191190
midi_in.parseMTrkChunks()
192-
191+

midi2abc.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
from simple_abc_parser import get_best_key_for_midi_notes, get_accidentals_for_key
3131
from io import StringIO
3232

33-
PY3 = sys.version_info.major > 2
34-
if PY3:
35-
def unicode(s):
36-
return s
37-
3833
num_quarter_notes_per_bar = 3
3934
bars_per_line = 4
4035

@@ -176,7 +171,7 @@ def note_to_string(note, duration, default_len, key_accidentals, cur_accidentals
176171
accidental_string = {-1: '_', -2: '__',
177172
0: '=', 1: '^', 2: '^^'}[accidental_num]
178173

179-
octave = (note - middle_C) / 12
174+
octave = (note - middle_C) // 12
180175

181176
# handle the border cases of Cb and B# to make sure that we use the right octave
182177
if octave_note == 11 and accidental_num == -1:
@@ -359,7 +354,7 @@ def midi_to_abc(filename=None, notes=None, key=None, metre=Fraction(3, 4), defau
359354

360355
# output broken rythm symbol if set
361356
if broken_rythm_symbol:
362-
output.write(unicode(broken_rythm_symbol))
357+
output.write(str(broken_rythm_symbol))
363358

364359
# if a bow was previously started end it here
365360
if bow_started and not bow_started_here:

0 commit comments

Comments
 (0)