craffel / pretty-midi

Utility functions for handling MIDI data in a nice/intuitive way.
MIT License
856 stars 151 forks source link

Method to crop PrettyMIDI object. #246

Closed b-boechat closed 2 months ago

b-boechat commented 2 months ago

Feature request: a method that crops a PrettyMIDI object. The user provides a start time and end time.

This can be trivially implemented using PrettyMIDI.adjust_times. However, the documentation for adjust_times isn't clear that events outside the provided time ranges are removed. I was halfway to manually implementing it myself by modifying events (and adjusting ticks) when I saw that the tutorial alludes to the cropping capabilities of adjust_times, which can then be understood by reading the method's source code.

One possibility would be to add this information to the docs. But I think pm.crop(start_time, end_time) is more clear (and searchable) than pm.adjust_times([start_time, end_time], [start_time, end_time]).

I would happily contribute the (trivial) code if this is deemed a useful addition.

craffel commented 2 months ago

Sure, sounds good! Thanks.