Skip to content

Commit

Permalink
fix: fix ignore_missing_instruments option not working properly
Browse files Browse the repository at this point in the history
The `get_note_end_time` function would try to get the note's sound data to estimate its length, but it would fail in case the sound file was missing, since it doesn't get added to the sounds dict returned by `load_instruments` at all (unlike when it's not assigned, when it's just set to `None`).

Fixes #3
  • Loading branch information
Bentroen committed Jul 25, 2022
1 parent 45d4caa commit 817ee6d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions nbswave/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ def get_length(self, notes: Sequence[nbs.Note]) -> float:
"""

def get_note_end_time(note: nbs.Note) -> float:
sound = self._instruments[note.instrument]
note_pitch = audio.key_to_pitch(note.key)

note_start = note.tick / self._song.header.tempo * 1000
note_length = len(sound) / note_pitch
note_end = note_start + note_length

return note_end
sound = self._instruments.get(note.instrument)

if sound is None: # Sound either missing or not assigned
return note_start
else:
note_pitch = audio.key_to_pitch(note.key)
note_length = len(sound) / note_pitch
note_end = note_start + note_length
return note_end

return max(get_note_end_time(note) for note in notes)

Expand Down

0 comments on commit 817ee6d

Please sign in to comment.