Skip to content

Commit ac02a26

Browse files
committed
synthio: avoid exceptions inside get_buffer
.. in case the items in lfos are not actually LFOs
1 parent 78e75f6 commit ac02a26

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

shared-module/synthio/Synthesizer.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ audioio_get_buffer_result_t synthio_synthesizer_get_buffer(synthio_synthesizer_o
7878
mp_obj_t iterable = mp_getiter(self->lfos, &iter_buf);
7979
mp_obj_t item;
8080
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
81-
synthio_block_slot_t slot;
82-
synthio_block_assign_slot(item, &slot, MP_QSTR_arg);
81+
if (!synthio_obj_is_block(item)) {
82+
continue;
83+
}
84+
synthio_block_slot_t slot = { item };
8385
(void)synthio_block_slot_get(&slot);
8486
}
8587
return GET_BUFFER_MORE_DATA;

shared-module/synthio/__init__.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,19 +584,27 @@ int32_t synthio_block_slot_get_scaled(synthio_block_slot_t *lfo_slot, mp_float_t
584584
return (int32_t)MICROPY_FLOAT_C_FUN(round)(MICROPY_FLOAT_C_FUN(ldexp)(value, 15));
585585
}
586586

587-
void synthio_block_assign_slot(mp_obj_t obj, synthio_block_slot_t *slot, qstr arg_name) {
588-
if (mp_proto_get(MP_QSTR_synthio_block, obj)) {
587+
bool synthio_block_assign_slot_maybe(mp_obj_t obj, synthio_block_slot_t *slot) {
588+
if (synthio_obj_is_block(obj)) {
589589
slot->obj = obj;
590-
return;
590+
return true;
591591
}
592592

593593
mp_float_t value = MICROPY_FLOAT_CONST(0.);
594594
if (obj != mp_const_none && !mp_obj_get_float_maybe(obj, &value)) {
595-
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_BlockInput, mp_obj_get_type_qstr(obj));
595+
return false;
596596
}
597597

598598
slot->obj = mp_obj_new_float(value);
599+
return true;
599600
}
601+
602+
void synthio_block_assign_slot(mp_obj_t obj, synthio_block_slot_t *slot, qstr arg_name) {
603+
if (!synthio_block_assign_slot_maybe(obj, slot)) {
604+
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_BlockInput, mp_obj_get_type_qstr(obj));
605+
}
606+
}
607+
600608
bool synthio_obj_is_block(mp_obj_t obj) {
601609
return mp_proto_get(MP_QSTR_synthio_block, obj);
602610
}

shared-module/synthio/block.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ int32_t synthio_block_slot_get_scaled(synthio_block_slot_t *block_slot, mp_float
5656

5757
// Assign an object (which may be a float or a synthio_block_obj_t) to an block slot
5858
void synthio_block_assign_slot(mp_obj_t obj, synthio_block_slot_t *block_slot, qstr arg_name);
59+
bool synthio_block_assign_slot_maybe(mp_obj_t obj, synthio_block_slot_t *block_slot);
5960
bool synthio_obj_is_block(mp_obj_t obj);

0 commit comments

Comments
 (0)