-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes remove_invalid_notes (renamed remove_notes_with_no_duration) + …
…minor improvements (#42) * fixes remove_invalid_notes (renamed remove_notes_with_no_duration) + minor improvements * Update miditoolkit/midi/containers.py Co-authored-by: Aarni Koskela <[email protected]> * fixing warnings call/import * renamed nb contractions to num * num_instruments property for MidiFile --------- Co-authored-by: Aarni Koskela <[email protected]>
- Loading branch information
Showing
4 changed files
with
66 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from operator import attrgetter | ||
|
||
import pytest | ||
|
||
from miditoolkit import MidiFile, Note | ||
from tests.utils import MIDI_PATHS | ||
|
||
|
||
@pytest.mark.parametrize("midi_path", MIDI_PATHS[:5], ids=attrgetter("name")) | ||
def test_remove_notes_with_no_duration(midi_path, tmp_path): | ||
"""Test that a MIDI loaded and saved unchanged is indeed the save as before.""" | ||
# Load the MIDI file and removes the notes with durations <= 0 | ||
midi = MidiFile(midi_path) | ||
midi.instruments[0].remove_notes_with_no_duration() | ||
num_notes_before = midi.instruments[0].num_notes | ||
|
||
# Adding notes with durations <= 0, then reapply the method | ||
midi.instruments[0].notes.append(Note(50, 50, 100, 100)) | ||
midi.instruments[0].notes.append(Note(50, 50, 101, 100)) | ||
midi.instruments[0].remove_notes_with_no_duration() | ||
|
||
assert ( | ||
midi.instruments[0].num_notes == num_notes_before | ||
), "The notes with duration <=0 were not removed by test_remove_notes_with_no_duration" |