From 7845a1b13b21b0e2f0f8b61df48ddccfa7f3b9d8 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 11 May 2023 17:58:09 -0500 Subject: [PATCH] synthio: Add `filter` boolean property to Note objects --- shared-bindings/synthio/Note.c | 20 ++++++++++++++++++++ shared-bindings/synthio/Note.h | 3 +++ shared-module/synthio/Note.c | 8 ++++++++ shared-module/synthio/Note.h | 1 + 4 files changed, 32 insertions(+) diff --git a/shared-bindings/synthio/Note.c b/shared-bindings/synthio/Note.c index dbf0f44495..f058b16d2e 100644 --- a/shared-bindings/synthio/Note.c +++ b/shared-bindings/synthio/Note.c @@ -44,6 +44,7 @@ static const mp_arg_t note_properties[] = { { MP_QSTR_bend_mode, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = (mp_obj_t)MP_ROM_PTR(&bend_mode_VIBRATO_obj) } }, { MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, { MP_QSTR_envelope, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, + { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(1) } }, { MP_QSTR_ring_frequency, MP_ARG_OBJ, {.u_obj = NULL } }, { MP_QSTR_ring_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, }; @@ -102,6 +103,24 @@ MP_PROPERTY_GETSET(synthio_note_frequency_obj, (mp_obj_t)&synthio_note_get_frequency_obj, (mp_obj_t)&synthio_note_set_frequency_obj); +//| filter: bool +//| """True if the note should be processed via the synthesizer's FIR filter.""" +STATIC mp_obj_t synthio_note_get_filter(mp_obj_t self_in) { + synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); + return mp_obj_new_bool(common_hal_synthio_note_get_filter(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_filter_obj, synthio_note_get_filter); + +STATIC mp_obj_t synthio_note_set_filter(mp_obj_t self_in, mp_obj_t arg) { + synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_synthio_note_set_filter(self, mp_obj_is_true(arg)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_filter_obj, synthio_note_set_filter); +MP_PROPERTY_GETSET(synthio_note_filter_obj, + (mp_obj_t)&synthio_note_get_filter_obj, + (mp_obj_t)&synthio_note_set_filter_obj); + //| panning: float //| """Defines the channel(s) in which the note appears. //| @@ -317,6 +336,7 @@ static void note_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ STATIC const mp_rom_map_elem_t synthio_note_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&synthio_note_frequency_obj) }, + { MP_ROM_QSTR(MP_QSTR_filter), MP_ROM_PTR(&synthio_note_filter_obj) }, { MP_ROM_QSTR(MP_QSTR_panning), MP_ROM_PTR(&synthio_note_panning_obj) }, { MP_ROM_QSTR(MP_QSTR_waveform), MP_ROM_PTR(&synthio_note_waveform_obj) }, { MP_ROM_QSTR(MP_QSTR_envelope), MP_ROM_PTR(&synthio_note_envelope_obj) }, diff --git a/shared-bindings/synthio/Note.h b/shared-bindings/synthio/Note.h index e548f9b5a7..b87310576a 100644 --- a/shared-bindings/synthio/Note.h +++ b/shared-bindings/synthio/Note.h @@ -9,6 +9,9 @@ typedef enum synthio_bend_mode_e synthio_bend_mode_t; mp_float_t common_hal_synthio_note_get_frequency(synthio_note_obj_t *self); void common_hal_synthio_note_set_frequency(synthio_note_obj_t *self, mp_float_t value); +bool common_hal_synthio_note_get_filter(synthio_note_obj_t *self); +void common_hal_synthio_note_set_filter(synthio_note_obj_t *self, bool value); + mp_float_t common_hal_synthio_note_get_ring_frequency(synthio_note_obj_t *self); void common_hal_synthio_note_set_ring_frequency(synthio_note_obj_t *self, mp_float_t value); diff --git a/shared-module/synthio/Note.c b/shared-module/synthio/Note.c index 89de8bce16..e6269eaf2e 100644 --- a/shared-module/synthio/Note.c +++ b/shared-module/synthio/Note.c @@ -44,6 +44,14 @@ void common_hal_synthio_note_set_frequency(synthio_note_obj_t *self, mp_float_t self->frequency_scaled = synthio_frequency_convert_float_to_scaled(val); } +bool common_hal_synthio_note_get_filter(synthio_note_obj_t *self) { + return self->filter; +} + +void common_hal_synthio_note_set_filter(synthio_note_obj_t *self, bool value_in) { + self->filter = value_in; +} + mp_float_t common_hal_synthio_note_get_ring_frequency(synthio_note_obj_t *self) { return self->ring_frequency; } diff --git a/shared-module/synthio/Note.h b/shared-module/synthio/Note.h index db3495f8b3..d7b9a6f67f 100644 --- a/shared-module/synthio/Note.h +++ b/shared-module/synthio/Note.h @@ -42,6 +42,7 @@ typedef struct synthio_note_obj { int32_t ring_frequency_scaled; int32_t amplitude_scaled; int32_t left_panning_scaled, right_panning_scaled; + bool filter; synthio_bend_mode_t bend_mode; synthio_lfo_descr_t tremolo_descr, bend_descr; synthio_lfo_state_t tremolo_state, bend_state;