Skip to content

Commit 7845a1b

Browse files
committed
synthio: Add filter boolean property to Note objects
1 parent 33fb771 commit 7845a1b

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

shared-bindings/synthio/Note.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static const mp_arg_t note_properties[] = {
4444
{ MP_QSTR_bend_mode, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = (mp_obj_t)MP_ROM_PTR(&bend_mode_VIBRATO_obj) } },
4545
{ MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } },
4646
{ MP_QSTR_envelope, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } },
47+
{ MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(1) } },
4748
{ MP_QSTR_ring_frequency, MP_ARG_OBJ, {.u_obj = NULL } },
4849
{ MP_QSTR_ring_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } },
4950
};
@@ -102,6 +103,24 @@ MP_PROPERTY_GETSET(synthio_note_frequency_obj,
102103
(mp_obj_t)&synthio_note_get_frequency_obj,
103104
(mp_obj_t)&synthio_note_set_frequency_obj);
104105

106+
//| filter: bool
107+
//| """True if the note should be processed via the synthesizer's FIR filter."""
108+
STATIC mp_obj_t synthio_note_get_filter(mp_obj_t self_in) {
109+
synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
110+
return mp_obj_new_bool(common_hal_synthio_note_get_filter(self));
111+
}
112+
MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_filter_obj, synthio_note_get_filter);
113+
114+
STATIC mp_obj_t synthio_note_set_filter(mp_obj_t self_in, mp_obj_t arg) {
115+
synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
116+
common_hal_synthio_note_set_filter(self, mp_obj_is_true(arg));
117+
return mp_const_none;
118+
}
119+
MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_filter_obj, synthio_note_set_filter);
120+
MP_PROPERTY_GETSET(synthio_note_filter_obj,
121+
(mp_obj_t)&synthio_note_get_filter_obj,
122+
(mp_obj_t)&synthio_note_set_filter_obj);
123+
105124
//| panning: float
106125
//| """Defines the channel(s) in which the note appears.
107126
//|
@@ -317,6 +336,7 @@ static void note_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
317336

318337
STATIC const mp_rom_map_elem_t synthio_note_locals_dict_table[] = {
319338
{ MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&synthio_note_frequency_obj) },
339+
{ MP_ROM_QSTR(MP_QSTR_filter), MP_ROM_PTR(&synthio_note_filter_obj) },
320340
{ MP_ROM_QSTR(MP_QSTR_panning), MP_ROM_PTR(&synthio_note_panning_obj) },
321341
{ MP_ROM_QSTR(MP_QSTR_waveform), MP_ROM_PTR(&synthio_note_waveform_obj) },
322342
{ MP_ROM_QSTR(MP_QSTR_envelope), MP_ROM_PTR(&synthio_note_envelope_obj) },

shared-bindings/synthio/Note.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ typedef enum synthio_bend_mode_e synthio_bend_mode_t;
99
mp_float_t common_hal_synthio_note_get_frequency(synthio_note_obj_t *self);
1010
void common_hal_synthio_note_set_frequency(synthio_note_obj_t *self, mp_float_t value);
1111

12+
bool common_hal_synthio_note_get_filter(synthio_note_obj_t *self);
13+
void common_hal_synthio_note_set_filter(synthio_note_obj_t *self, bool value);
14+
1215
mp_float_t common_hal_synthio_note_get_ring_frequency(synthio_note_obj_t *self);
1316
void common_hal_synthio_note_set_ring_frequency(synthio_note_obj_t *self, mp_float_t value);
1417

shared-module/synthio/Note.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ void common_hal_synthio_note_set_frequency(synthio_note_obj_t *self, mp_float_t
4444
self->frequency_scaled = synthio_frequency_convert_float_to_scaled(val);
4545
}
4646

47+
bool common_hal_synthio_note_get_filter(synthio_note_obj_t *self) {
48+
return self->filter;
49+
}
50+
51+
void common_hal_synthio_note_set_filter(synthio_note_obj_t *self, bool value_in) {
52+
self->filter = value_in;
53+
}
54+
4755
mp_float_t common_hal_synthio_note_get_ring_frequency(synthio_note_obj_t *self) {
4856
return self->ring_frequency;
4957
}

shared-module/synthio/Note.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct synthio_note_obj {
4242
int32_t ring_frequency_scaled;
4343
int32_t amplitude_scaled;
4444
int32_t left_panning_scaled, right_panning_scaled;
45+
bool filter;
4546
synthio_bend_mode_t bend_mode;
4647
synthio_lfo_descr_t tremolo_descr, bend_descr;
4748
synthio_lfo_state_t tremolo_state, bend_state;

0 commit comments

Comments
 (0)