Skip to content

Commit 817ee6d

Browse files
committed
fix: fix ignore_missing_instruments option not working properly
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
1 parent 45d4caa commit 817ee6d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

nbswave/main.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,17 @@ def get_length(self, notes: Sequence[nbs.Note]) -> float:
115115
"""
116116

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

121119
note_start = note.tick / self._song.header.tempo * 1000
122-
note_length = len(sound) / note_pitch
123-
note_end = note_start + note_length
124-
125-
return note_end
120+
sound = self._instruments.get(note.instrument)
121+
122+
if sound is None: # Sound either missing or not assigned
123+
return note_start
124+
else:
125+
note_pitch = audio.key_to_pitch(note.key)
126+
note_length = len(sound) / note_pitch
127+
note_end = note_start + note_length
128+
return note_end
126129

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

0 commit comments

Comments
 (0)