You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue #293 addressed some weird behavior in time values of notes of MIDI files.
This time values generally come in two units seconds and ticks. MIDI files are represented as PerformedPart objects or note_array objects. In both objects individual note onset, duraiton, or offset times can be changed in either time unit, but these changes do not necessarily reflect changes in the other unit or in the other object after conversion. The script below illustrates this behavior.
Best practice for manual timing changes is:
for manipulations of the performedpart: change both 'sound_off' and 'note_off', for consistency delete all ticks information (also for onset times use 'note_on', not the value in ticks)
for manipulations of the note_array: change both values in seconds, 'onset_sec' / 'duration_sec', tick times are discarded
import partitura as pt
import numpy as np
performedPart = pt.load_performance_midi(pt.EXAMPLE_MIDI)[0]
# when creating a note array,
# and the SOUND_OFF property is available,
# it's used for duration_sec -> no change due to NOTE_OFF
print("changes in 'note_off' don't show up in note array, if there is a 'sound_off'")
print("original 'note_off': ",performedPart.notes[0]['note_off'])
print("same note in note array ",performedPart.note_array()[0])
performedPart.notes[0]['note_off'] += 1.0
print("changed 'note_off': ",performedPart.notes[0]['note_off'])
print("note in note array ",performedPart.note_array()[0])
print("dtypes of note array 'onset_sec', 'duration_sec','onset_tick','duration_tick'")
print("-----------------------------")
# when creating a note array,
# and the NOTE_OFF_TICK property is UNavailable,
# NOTE_OFF is used for duration_sec -> change due to NOTE_OFF
for n in performedPart.notes:
n.pop('note_on_tick', None)
n.pop('note_off_tick', None)
print("delete the NOTE_OFF_TICK and the the tick values are inferred from 'note_off' and not 'sound_off'.")
print("the 4th value in note array ('duration_ticks') is higher than before, and inconsistent with the other duration")
print("same note in note array ",performedPart.note_array()[0])
print("dtypes of note array 'onset_sec', 'duration_sec','onset_tick','duration_tick'")
# for manipulations of the performedpart: change both 'sound_off' and 'note_off', for consistency delete all ticks information
print("-----------------------------")
# when creating a performedpart from note_array,
# only the times in seconds are used...
print("when creating the a performedpart from note_array, times in seconds are used")
na_to_change = np.copy(performedPart.note_array())
print("original note in note array ",na_to_change[0])
print("original 'note_off' in performedpart ", pt.performance.PerformedPart.from_note_array(na_to_change).notes[0]["note_off"])
print("change 'duration_tick'")
na_to_change[0]["duration_tick"] = 17
print("changed note in note array ", na_to_change[0])
print("UNCHANGED 'note_off' in performedpart ", pt.performance.PerformedPart.from_note_array(na_to_change).notes[0]["note_off"])
print("change 'duration_sec'")
na_to_change[0]["duration_sec"] = 100.
print("changed note in note array ", na_to_change[0])
print("CHANGED 'note_off' in performedpart ", pt.performance.PerformedPart.from_note_array(na_to_change).notes[0]["note_off"])
# for manipulations of the note_array: change both values in seconds, 'onset_sec' / 'duration_sec', tick times are discarded
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Issue #293 addressed some weird behavior in time values of notes of MIDI files.
This time values generally come in two units
seconds
andticks
. MIDI files are represented asPerformedPart
objects ornote_array
objects. In both objects individual note onset, duraiton, or offset times can be changed in either time unit, but these changes do not necessarily reflect changes in the other unit or in the other object after conversion. The script below illustrates this behavior.Best practice for manual timing changes is:
Beta Was this translation helpful? Give feedback.
All reactions