Skip to content

Commit

Permalink
renamed nb contractions to num
Browse files Browse the repository at this point in the history
  • Loading branch information
Natooz committed Nov 22, 2023
1 parent 5986bc2 commit 2f2acd5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions miditoolkit/midi/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,16 @@ def remove_invalid_notes(self, verbose: bool = True) -> None:

def remove_notes_with_no_duration(self) -> None:
"""Removes (inplace) notes whose end time is before or at their start time."""
for i in range(self.nb_notes - 1, -1, -1):
for i in range(self.num_notes - 1, -1, -1):
if self.notes[i].start >= self.notes[i].end:
del self.notes[i]

@property
def nb_notes(self) -> int:
def num_notes(self) -> int:
return len(self.notes)

def __repr__(self):
return f"Instrument(program={self.program}, is_drum={self.is_drum}, name={self.name}) - {self.nb_notes} notes"
return f"Instrument(program={self.program}, is_drum={self.is_drum}, name={self.name}) - {self.num_notes} notes"

def __eq__(self, other):
# Here we check all tracks attributes except the name.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ def test_remove_notes_with_no_duration(midi_path, tmp_path):
# Load the MIDI file and removes the notes with durations <= 0
midi = MidiFile(midi_path)
midi.instruments[0].remove_notes_with_no_duration()
nb_notes_before = midi.instruments[0].nb_notes
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].nb_notes == nb_notes_before
midi.instruments[0].num_notes == num_notes_before
), "The notes with duration <=0 were not removed by test_remove_notes_with_no_duration"

0 comments on commit 2f2acd5

Please sign in to comment.