mirror of
https://github.com/janishutz/midi-micro-bit_sound-converter.git
synced 2025-11-25 05:44:24 +00:00
Add pause support to midi conversion
This commit is contained in:
@@ -26,18 +26,16 @@ class MidiManagement:
|
|||||||
tracknumber += 1
|
tracknumber += 1
|
||||||
output_list = []
|
output_list = []
|
||||||
|
|
||||||
tracked_notes = []
|
|
||||||
bpm = 0
|
bpm = 0
|
||||||
timing = 20000
|
timing = 20000
|
||||||
|
|
||||||
# Track messages
|
# Track messages
|
||||||
for msg in mid.tracks[tracknumber]:
|
for msg in mid.tracks[tracknumber]:
|
||||||
if msg.type == "note_on":
|
if msg.type == "note_on":
|
||||||
try:
|
# We only need to handle pauses here
|
||||||
tracked_notes.append(self.get_note_as_micro_bit_string(msg))
|
t = math.floor(msg.time / timing)
|
||||||
|
if t > 0:
|
||||||
except:
|
output_list.append('R:' + str(t))
|
||||||
pass
|
|
||||||
elif msg.type == "note_off":
|
elif msg.type == "note_off":
|
||||||
# End tracked note at time offset for midi msg (that is relative to start)
|
# End tracked note at time offset for midi msg (that is relative to start)
|
||||||
note = ''
|
note = ''
|
||||||
@@ -46,19 +44,8 @@ class MidiManagement:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Find note in tracked notes, ignore if not in there
|
t = math.floor(msg.time / timing)
|
||||||
index = -1
|
output_list.append(note + ':' + str(t))
|
||||||
for n in range(len(tracked_notes)):
|
|
||||||
if tracked_notes[n] == note:
|
|
||||||
index = n
|
|
||||||
break;
|
|
||||||
|
|
||||||
# Get duration
|
|
||||||
if index >= 0:
|
|
||||||
tracked_notes.remove(note)
|
|
||||||
t = math.floor(msg.time / timing)
|
|
||||||
|
|
||||||
output_list.append(note + ':' + str(t))
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
midi_msg = str(msg)
|
midi_msg = str(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user