Skip to content

Commit

Permalink
Merge pull request #40 from PRamoneda/Pedro/big_refactor
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
PRamoneda authored May 28, 2021
2 parents 9f772b9 + 5031294 commit 511af06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 6 additions & 6 deletions pianoplayer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def annotate_PIG(hand, is_right=True):
for n in hand.noteseq:
onset_time = "{:.4f}".format(n.time)
offset_time = "{:.4f}".format(n.time + n.duration)
spelled_pitch = n.name
spelled_pitch = n.pitch
onset_velocity = str(None)
offset_velocity = str(None)
channel = '0' if is_right else '1'
finger_number = n.fingering if is_right else -n.fingering
cost = n.cost
ans.append((onset_time, offset_time, spelled_pitch, onset_velocity, offset_velocity, channel,
finger_number, cost))
finger_number, cost, n.noteID))
return ans


Expand Down Expand Up @@ -195,14 +195,14 @@ def annotate(args):
pig_notes.extend(annotate_PIG(rh))

if not args.right_only:
pig_notes.extend(annotate_PIG(lh))
pig_notes.extend(annotate_PIG(lh, is_right=False))

with open(args.outputfile, 'wt') as out_file:
tsv_writer = csv.writer(out_file, delimiter='\t')
for idx, (onset_time, offset_time, spelled_pitch, onset_velocity, offset_velocity, channel,
finger_number, cost) in enumerate(sorted(pig_notes)):
finger_number, cost, id_n) in enumerate(sorted(pig_notes, key=lambda tup: (float(tup[0]), int(tup[5]), int(tup[2])))):
tsv_writer.writerow([idx, onset_time, offset_time, spelled_pitch, onset_velocity, offset_velocity,
channel, finger_number, cost])
channel, finger_number, cost, id_n])
else:
ext = os.path.splitext(args.filename)[1]
if ext in ['mid', 'midi']:
Expand Down Expand Up @@ -258,4 +258,4 @@ def annotate(args):


if __name__ == '__main__':
run_annotate('../scores/test_chords.xml', outputfile="test_chords_annotated.txt", musescore=True, right_only=True, n_measures=800, depth=9)
run_annotate('../scores/test_chord.xml', outputfile="test_chord_annotate.xml", right_only=True, musescore=True, n_measures=800, depth=0)
13 changes: 8 additions & 5 deletions pianoplayer/scorereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ def reader(sf, beam=0):
print('Reading beam', beam, 'with', len(strm), 'objects in stream.')

chordID = 0

noteID = 0
for n in strm.getElementsByClass("GeneralNote"):

if n.duration.quarterLength==0: continue

if hasattr(n, 'tie'): # address bug https://github.com/marcomusy/pianoplayer/issues/29
Expand All @@ -72,7 +73,7 @@ def reader(sf, beam=0):
# print "doppia nota", n.name
continue
an = INote()
an.noteID += 1
an.noteID = noteID
an.note21 = n
an.isChord= False
an.name = n.name
Expand All @@ -92,6 +93,7 @@ def reader(sf, beam=0):

an.fingering = get_finger_music21(n)
noteseq.append(an)
noteID += 1

elif n.isChord:

Expand All @@ -101,7 +103,7 @@ def reader(sf, beam=0):
for j, cn in enumerate(n.pitches):
an = INote()
an.chordID = chordID
an.noteID += 1
an.noteID = noteID
an.isChord = True
an.pitch = cn.midi
an.note21 = cn
Expand All @@ -111,7 +113,7 @@ def reader(sf, beam=0):
an.octave = cn.octave
an.measure = n.measureNumber
an.x = keypos(cn)
an.time = n.offset-sfasam*j
an.time = n.offset-sfasam*(len(n.pitches)-j-1)
an.duration= n.duration.quarterLength+sfasam*(an.NinChord-1)
if hasattr(cn, 'pitch'):
pc = cn.pitch.pitchClass
Expand All @@ -122,10 +124,11 @@ def reader(sf, beam=0):
else:
an.isBlack = False
an.fingering = get_finger_music21(n, j)
noteID += 1
noteseq.append(an)
chordID += 1

if len(noteseq)<2:
if len(noteseq) < 2:
print("Beam is empty.")
return []
return noteseq
Expand Down

0 comments on commit 511af06

Please sign in to comment.