Skip to content

Commit d2130d8

Browse files
committed
codal_port/modmusic: Remove support for None as a tune rest.
It was broken ever since background music was introduced. Fixes issue #139. Signed-off-by: Damien George <[email protected]>
1 parent 4e9c550 commit d2130d8

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/codal_port/modmusic.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,17 @@ void microbit_music_tick(void) {
118118
} else {
119119
note = ((mp_obj_t *)music_data->async_note)[music_data->async_notes_index];
120120
}
121-
if (note == mp_const_none) {
122-
// a rest (is this even used anymore?)
123-
music_output_amplitude(MUSIC_OUTPUT_AMPLITUDE_OFF);
124-
music_data->async_wait_ticks = 60000 / music_data->bpm;
125-
music_data->async_state = ASYNC_MUSIC_STATE_NEXT_NOTE;
126-
} else {
127-
// a note
128-
mp_uint_t note_len;
129-
const char *note_str = mp_obj_str_get_data(note, &note_len);
130-
uint32_t delay_on = start_note(note_str, note_len);
131-
music_data->async_wait_ticks = mp_hal_ticks_ms() + delay_on;
132-
music_data->async_notes_index += 1;
133-
music_data->async_state = ASYNC_MUSIC_STATE_ARTICULATE;
121+
if (!mp_obj_is_str_or_bytes(note)) {
122+
mp_printf(&mp_plat_print, "TypeError: expecting a str for note\n");
123+
music_data->async_state = ASYNC_MUSIC_STATE_IDLE;
124+
return;
134125
}
126+
mp_uint_t note_len;
127+
const char *note_str = mp_obj_str_get_data(note, &note_len);
128+
uint32_t delay_on = start_note(note_str, note_len);
129+
music_data->async_wait_ticks = mp_hal_ticks_ms() + delay_on;
130+
music_data->async_notes_index += 1;
131+
music_data->async_state = ASYNC_MUSIC_STATE_ARTICULATE;
135132
}
136133
}
137134

0 commit comments

Comments
 (0)