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
I'm working with midi files that have pretty long first silences, and I want to get rid of them. I think this is quite a necessary requirement, but I can't find the pre-written tools to support it. That's why I wanted to write a function to do this. The simple idea is to subtract the start time of all the notes of all tracks by an interval equal to the start time of the first note (the earliest).
Here is the source code to implement that idea. I would like to ask if something is wrong with my method or my understanding of how to use muspy.Music.
importmuspyasmpmin=mp.read_midi('midi-file-path.mid', backend='mido')
deftrim_silence(music: mp.Music):
music=music.deepcopy()
# Collect notesnotes= []
fortrackinmusic.tracks:
notes.extend(track.notes)
# Raise an error if no notes is foundifnotnotes:
raiseRuntimeError("No notes found.")
# Sort the notesnotes.sort(key=lambdan: n.time)
start_time=notes[0].time# Ship the start time to zeroforitinrange(len(music.tracks)):
forinoteinrange(len(music.tracks[it].notes)):
music.tracks[it].notes[inote].time-=start_timereturnmusic
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
-
I'm working with midi files that have pretty long first silences, and I want to get rid of them. I think this is quite a necessary requirement, but I can't find the pre-written tools to support it. That's why I wanted to write a function to do this. The simple idea is to subtract the start time of all the notes of all tracks by an interval equal to the start time of the first note (the earliest).
Here is the source code to implement that idea. I would like to ask if something is wrong with my method or my understanding of how to use
muspy.Music
.Beta Was this translation helpful? Give feedback.
All reactions