Thanks for the MIDI suggestion.

I got something basic working with music21.

I saved a midi from lilly with 2 parts for staff/tab.   Very basic score
with a handful of notes but I'll test with more typical rhythm notation.

I then cobbled together this code using AI/SO.   I'll need to do more
testing but it's looking exactly what I need,   I can use the octave I hope
to check the correct frequency of the incoming guitar signal.   That was
much easier than parsing the ly fle and manually calculating the time from
rhythm.

from music21 import *

# Load the MIDI file
score = converter.parse('./mid/MidTest.midi',forceSource=True)

notes = []


i = 0;
for a in score:
if a.isStream:
e = repeat.Expander(a)
s2 = e.process()
timing = s2.secondsMap
score[i] = s2
i += 1;

def getMusicProperties(x):
s = '';
t='';
s = str(x.pitch) + ", " + str(x.duration.type) + ", " + str(x
.duration.quarterLength);
s += ", "
if x.tie != None:
t = x.tie.type;
s += t + ", " + str(x.pitch.ps) + ", " + str(x.octave); # + str(x.seconds)
# x.seconds not always there
return s

print("Time Offset")
for el in score[2].recurse().notes:
if (el.isNote):
totalOffset = el.getOffsetInHierarchy(score)
print(totalOffset)


print('pitch, duration_string, duration, tie, midi pitch, octave')
for a in score[2].recurse().notes:

if (a.isNote):
x = a;
s = getMusicProperties(x);
print(s);


print("Done.")

Reply via email to