feat: added initial midi support
This commit is contained in:
parent
a1963d3787
commit
759bfe4c39
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.json
|
|
@ -1,10 +1,18 @@
|
|||
import json, sys, rpp
|
||||
from rich import print
|
||||
|
||||
def getSecondsFromPPQ(tempo, ppq, offset):
|
||||
microseconds_per_tick = (60000 / tempo * 1000) / ppq
|
||||
seconds_per_tick = microseconds_per_tick / 1000000
|
||||
seconds = offset * seconds_per_tick
|
||||
return seconds
|
||||
|
||||
try:
|
||||
with open(sys.argv[1], "rb") as f:
|
||||
data = f.read().decode("utf-8")
|
||||
r = rpp.loads(data)
|
||||
|
||||
tempo = float(next(r.iterfind(".//TEMPO"))[1])
|
||||
trackList = {}
|
||||
|
||||
for item in r.iterfind(".//TRACK"):
|
||||
|
@ -15,7 +23,21 @@ try:
|
|||
for pos in item.iterfind(".//POSITION"):
|
||||
itemType = item.find(".//SOURCE").attrib
|
||||
itemPos = float(pos[1])
|
||||
if (itemType not in ["MIDI"]):
|
||||
if (itemType[0] == "MIDI"):
|
||||
ppq = 960
|
||||
tick_offset = 0
|
||||
|
||||
for midiData in item.find(".//SOURCE").children:
|
||||
if midiData[0] == 'HASDATA':
|
||||
ppq = int(midiData[2])
|
||||
|
||||
if midiData[0] in ['e', 'E']:
|
||||
if midiData[2].startswith('9') and midiData[4] != '00':
|
||||
trackList[trackName].append(getSecondsFromPPQ(tempo, ppq, int(midiData[1]) + tick_offset) + itemPos)
|
||||
tick_offset += int(midiData[1])
|
||||
|
||||
else:
|
||||
print(itemType)
|
||||
trackList[trackName].append(itemPos)
|
||||
|
||||
if (len(sys.argv) > 2):
|
||||
|
|
Loading…
Reference in New Issue
Block a user