Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to clip input files for questionable files #176

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pretty_midi/pretty_midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class PrettyMIDI(object):
List of :class:`pretty_midi.Lyric` objects.
"""

def __init__(self, midi_file=None, resolution=220, initial_tempo=120.):
def __init__(self, midi_file=None, resolution=220,
initial_tempo=120., clip=False):
"""Initialize either by populating it with MIDI data from a file or
from scratch with no data.

Expand All @@ -57,10 +58,10 @@ def __init__(self, midi_file=None, resolution=220, initial_tempo=120.):
# Load in the MIDI data using the midi module
if isinstance(midi_file, six.string_types):
# If a string was given, pass it as the string filename
midi_data = mido.MidiFile(filename=midi_file)
midi_data = mido.MidiFile(filename=midi_file, clip=clip)
else:
# Otherwise, try passing it in as a file pointer
midi_data = mido.MidiFile(file=midi_file)
midi_data = mido.MidiFile(file=midi_file, clip=clip)

# Convert tick values in midi_data to absolute, a useful thing.
for track in midi_data.tracks:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
license='MIT',
install_requires=[
'numpy >= 1.7.0',
'mido >= 1.1.16',
'mido >= 1.2.8',
'six',
]
)