|
30 | 30 | #include "py/objproperty.h"
|
31 | 31 | #include "py/runtime.h"
|
32 | 32 | #include "shared-bindings/util.h"
|
| 33 | +#include "shared-bindings/synthio/__init__.h" |
33 | 34 | #include "shared-bindings/synthio/Note.h"
|
34 | 35 | #include "shared-module/synthio/Note.h"
|
35 | 36 |
|
36 | 37 | static const mp_arg_t note_properties[] = {
|
37 | 38 | { MP_QSTR_frequency, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = NULL } },
|
38 |
| - { MP_QSTR_amplitude, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(1) } }, |
| 39 | + { MP_QSTR_panning, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, |
39 | 40 | { MP_QSTR_tremolo_rate, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } },
|
40 | 41 | { MP_QSTR_tremolo_depth, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } },
|
41 |
| - { MP_QSTR_vibrato_rate, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } }, |
42 |
| - { MP_QSTR_vibrato_depth, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } }, |
| 42 | + { MP_QSTR_bend_rate, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } }, |
| 43 | + { MP_QSTR_bend_depth, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } }, |
| 44 | + { MP_QSTR_bend_mode, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = (mp_obj_t)MP_ROM_PTR(&bend_mode_VIBRATO_obj) } }, |
43 | 45 | { MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } },
|
44 | 46 | { 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) } }, |
| 48 | + { MP_QSTR_ring_frequency, MP_ARG_OBJ, {.u_obj = NULL } }, |
| 49 | + { MP_QSTR_ring_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, |
45 | 50 | };
|
46 | 51 | //| class Note:
|
47 | 52 | //| def __init__(
|
48 | 53 | //| self,
|
49 | 54 | //| *,
|
50 | 55 | //| frequency: float,
|
51 |
| -//| amplitude: float = 1.0, |
| 56 | +//| panning: float = 0.0, |
52 | 57 | //| waveform: Optional[ReadableBuffer] = None,
|
53 | 58 | //| envelope: Optional[Envelope] = None,
|
54 | 59 | //| tremolo_depth: float = 0.0,
|
55 | 60 | //| tremolo_rate: float = 0.0,
|
56 |
| -//| vibrato_depth: float = 0.0, |
57 |
| -//| vibrato_rate: float = 0.0, |
| 61 | +//| bend_depth: float = 0.0, |
| 62 | +//| bend_rate: float = 0.0, |
| 63 | +//| bend_mode: "BendMode" = BendMode.VIBRATO, |
58 | 64 | //| ) -> None:
|
59 |
| -//| """Construct a Note object, with a frequency in Hz, and optional amplitude (volume), waveform, envelope, tremolo (volume change) and vibrato (frequency change). |
| 65 | +//| """Construct a Note object, with a frequency in Hz, and optional panning, waveform, envelope, tremolo (volume change) and bend (frequency change). |
60 | 66 | //|
|
61 | 67 | //| If waveform or envelope are `None` the synthesizer object's default waveform or envelope are used.
|
62 | 68 | //|
|
63 | 69 | //| If the same Note object is played on multiple Synthesizer objects, the result is undefined.
|
64 | 70 | //| """
|
65 | 71 | STATIC mp_obj_t synthio_note_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
66 |
| - enum { ARG_frequency, ARG_amplitude, ARG_waveform, ARG_envelope, ARG_tremolo_rate, ARG_tremolo_depth, ARG_vibrato_rate, ARG_vibrato_depth }; |
67 | 72 | mp_arg_val_t args[MP_ARRAY_SIZE(note_properties)];
|
68 | 73 | mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(note_properties), note_properties, args);
|
69 | 74 |
|
@@ -98,23 +103,46 @@ MP_PROPERTY_GETSET(synthio_note_frequency_obj,
|
98 | 103 | (mp_obj_t)&synthio_note_get_frequency_obj,
|
99 | 104 | (mp_obj_t)&synthio_note_set_frequency_obj);
|
100 | 105 |
|
101 |
| -//| amplitude: float |
102 |
| -//| """The base amplitude of the note, from 0 to 1""" |
103 |
| -STATIC mp_obj_t synthio_note_get_amplitude(mp_obj_t self_in) { |
| 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) { |
104 | 109 | synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
105 |
| - return mp_obj_new_float(common_hal_synthio_note_get_amplitude(self)); |
| 110 | + return mp_obj_new_bool(common_hal_synthio_note_get_filter(self)); |
106 | 111 | }
|
107 |
| -MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_amplitude_obj, synthio_note_get_amplitude); |
| 112 | +MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_filter_obj, synthio_note_get_filter); |
108 | 113 |
|
109 |
| -STATIC mp_obj_t synthio_note_set_amplitude(mp_obj_t self_in, mp_obj_t arg) { |
| 114 | +STATIC mp_obj_t synthio_note_set_filter(mp_obj_t self_in, mp_obj_t arg) { |
110 | 115 | synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
111 |
| - common_hal_synthio_note_set_amplitude(self, mp_obj_get_float(arg)); |
| 116 | + common_hal_synthio_note_set_filter(self, mp_obj_is_true(arg)); |
112 | 117 | return mp_const_none;
|
113 | 118 | }
|
114 |
| -MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_amplitude_obj, synthio_note_set_amplitude); |
115 |
| -MP_PROPERTY_GETSET(synthio_note_amplitude_obj, |
116 |
| - (mp_obj_t)&synthio_note_get_amplitude_obj, |
117 |
| - (mp_obj_t)&synthio_note_set_amplitude_obj); |
| 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 | + |
| 124 | +//| panning: float |
| 125 | +//| """Defines the channel(s) in which the note appears. |
| 126 | +//| |
| 127 | +//| -1 is left channel only, 0 is both channels, and 1 is right channel. |
| 128 | +//| For fractional values, the note plays at full amplitude in one channel |
| 129 | +//| and partial amplitude in the other channel. For instance -.5 plays at full |
| 130 | +//| amplitude in the left channel and 1/2 amplitude in the right channel.""" |
| 131 | +STATIC mp_obj_t synthio_note_get_panning(mp_obj_t self_in) { |
| 132 | + synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 133 | + return mp_obj_new_float(common_hal_synthio_note_get_panning(self)); |
| 134 | +} |
| 135 | +MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_panning_obj, synthio_note_get_panning); |
| 136 | + |
| 137 | +STATIC mp_obj_t synthio_note_set_panning(mp_obj_t self_in, mp_obj_t arg) { |
| 138 | + synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 139 | + common_hal_synthio_note_set_panning(self, mp_obj_get_float(arg)); |
| 140 | + return mp_const_none; |
| 141 | +} |
| 142 | +MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_panning_obj, synthio_note_set_panning); |
| 143 | +MP_PROPERTY_GETSET(synthio_note_panning_obj, |
| 144 | + (mp_obj_t)&synthio_note_get_panning_obj, |
| 145 | + (mp_obj_t)&synthio_note_set_panning_obj); |
118 | 146 |
|
119 | 147 |
|
120 | 148 | //| tremolo_depth: float
|
@@ -158,46 +186,67 @@ MP_PROPERTY_GETSET(synthio_note_tremolo_rate_obj,
|
158 | 186 | (mp_obj_t)&synthio_note_get_tremolo_rate_obj,
|
159 | 187 | (mp_obj_t)&synthio_note_set_tremolo_rate_obj);
|
160 | 188 |
|
161 |
| -//| vibrato_depth: float |
162 |
| -//| """The vibrato depth of the note, from 0 to 1 |
163 | 189 | //|
|
164 |
| -//| A depth of 0 disables vibrato. A depth of 1 corresponds to a vibrato of ±1 |
165 |
| -//| octave. A depth of (1/12) = 0.833 corresponds to a vibrato of ±1 semitone, |
| 190 | +//| bend_mode: BendMode |
| 191 | +//| """The type of bend operation""" |
| 192 | +STATIC mp_obj_t synthio_note_get_bend_mode(mp_obj_t self_in) { |
| 193 | + synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 194 | + return cp_enum_find(&synthio_bend_mode_type, common_hal_synthio_note_get_bend_mode(self)); |
| 195 | +} |
| 196 | +MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_bend_mode_obj, synthio_note_get_bend_mode); |
| 197 | + |
| 198 | +STATIC mp_obj_t synthio_note_set_bend_mode(mp_obj_t self_in, mp_obj_t arg) { |
| 199 | + synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 200 | + common_hal_synthio_note_set_bend_mode(self, cp_enum_value(&synthio_bend_mode_type, arg, MP_QSTR_bend_mode)); |
| 201 | + return mp_const_none; |
| 202 | +} |
| 203 | +MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_bend_mode_obj, synthio_note_set_bend_mode); |
| 204 | +MP_PROPERTY_GETSET(synthio_note_bend_mode_obj, |
| 205 | + (mp_obj_t)&synthio_note_get_bend_mode_obj, |
| 206 | + (mp_obj_t)&synthio_note_set_bend_mode_obj); |
| 207 | + |
| 208 | +// |
| 209 | +//| |
| 210 | +//| bend_depth: float |
| 211 | +//| """The bend depth of the note, from -1 to +1 |
| 212 | +//| |
| 213 | +//| A depth of 0 disables bend. A depth of 1 corresponds to a bend of 1 |
| 214 | +//| octave. A depth of (1/12) = 0.833 corresponds to a bend of 1 semitone, |
166 | 215 | //| and a depth of .00833 corresponds to one musical cent.
|
167 | 216 | //| """
|
168 |
| -STATIC mp_obj_t synthio_note_get_vibrato_depth(mp_obj_t self_in) { |
| 217 | +STATIC mp_obj_t synthio_note_get_bend_depth(mp_obj_t self_in) { |
169 | 218 | synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
170 |
| - return mp_obj_new_float(common_hal_synthio_note_get_vibrato_depth(self)); |
| 219 | + return mp_obj_new_float(common_hal_synthio_note_get_bend_depth(self)); |
171 | 220 | }
|
172 |
| -MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_vibrato_depth_obj, synthio_note_get_vibrato_depth); |
| 221 | +MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_bend_depth_obj, synthio_note_get_bend_depth); |
173 | 222 |
|
174 |
| -STATIC mp_obj_t synthio_note_set_vibrato_depth(mp_obj_t self_in, mp_obj_t arg) { |
| 223 | +STATIC mp_obj_t synthio_note_set_bend_depth(mp_obj_t self_in, mp_obj_t arg) { |
175 | 224 | synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
176 |
| - common_hal_synthio_note_set_vibrato_depth(self, mp_obj_get_float(arg)); |
| 225 | + common_hal_synthio_note_set_bend_depth(self, mp_obj_get_float(arg)); |
177 | 226 | return mp_const_none;
|
178 | 227 | }
|
179 |
| -MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_vibrato_depth_obj, synthio_note_set_vibrato_depth); |
180 |
| -MP_PROPERTY_GETSET(synthio_note_vibrato_depth_obj, |
181 |
| - (mp_obj_t)&synthio_note_get_vibrato_depth_obj, |
182 |
| - (mp_obj_t)&synthio_note_set_vibrato_depth_obj); |
183 |
| - |
184 |
| -//| vibrato_rate: float |
185 |
| -//| """The vibrato rate of the note, in Hz.""" |
186 |
| -STATIC mp_obj_t synthio_note_get_vibrato_rate(mp_obj_t self_in) { |
| 228 | +MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_bend_depth_obj, synthio_note_set_bend_depth); |
| 229 | +MP_PROPERTY_GETSET(synthio_note_bend_depth_obj, |
| 230 | + (mp_obj_t)&synthio_note_get_bend_depth_obj, |
| 231 | + (mp_obj_t)&synthio_note_set_bend_depth_obj); |
| 232 | + |
| 233 | +//| bend_rate: float |
| 234 | +//| """The bend rate of the note, in Hz.""" |
| 235 | +STATIC mp_obj_t synthio_note_get_bend_rate(mp_obj_t self_in) { |
187 | 236 | synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
188 |
| - return mp_obj_new_float(common_hal_synthio_note_get_vibrato_rate(self)); |
| 237 | + return mp_obj_new_float(common_hal_synthio_note_get_bend_rate(self)); |
189 | 238 | }
|
190 |
| -MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_vibrato_rate_obj, synthio_note_get_vibrato_rate); |
| 239 | +MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_bend_rate_obj, synthio_note_get_bend_rate); |
191 | 240 |
|
192 |
| -STATIC mp_obj_t synthio_note_set_vibrato_rate(mp_obj_t self_in, mp_obj_t arg) { |
| 241 | +STATIC mp_obj_t synthio_note_set_bend_rate(mp_obj_t self_in, mp_obj_t arg) { |
193 | 242 | synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
194 |
| - common_hal_synthio_note_set_vibrato_rate(self, mp_obj_get_float(arg)); |
| 243 | + common_hal_synthio_note_set_bend_rate(self, mp_obj_get_float(arg)); |
195 | 244 | return mp_const_none;
|
196 | 245 | }
|
197 |
| -MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_vibrato_rate_obj, synthio_note_set_vibrato_rate); |
198 |
| -MP_PROPERTY_GETSET(synthio_note_vibrato_rate_obj, |
199 |
| - (mp_obj_t)&synthio_note_get_vibrato_rate_obj, |
200 |
| - (mp_obj_t)&synthio_note_set_vibrato_rate_obj); |
| 246 | +MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_bend_rate_obj, synthio_note_set_bend_rate); |
| 247 | +MP_PROPERTY_GETSET(synthio_note_bend_rate_obj, |
| 248 | + (mp_obj_t)&synthio_note_get_bend_rate_obj, |
| 249 | + (mp_obj_t)&synthio_note_set_bend_rate_obj); |
201 | 250 |
|
202 | 251 | //| waveform: Optional[ReadableBuffer]
|
203 | 252 | //| """The waveform of this note. Setting the waveform to a buffer of a different size resets the note's phase."""
|
@@ -237,20 +286,67 @@ MP_PROPERTY_GETSET(synthio_note_envelope_obj,
|
237 | 286 | (mp_obj_t)&synthio_note_get_envelope_obj,
|
238 | 287 | (mp_obj_t)&synthio_note_set_envelope_obj);
|
239 | 288 |
|
| 289 | +//| ring_frequency: float |
| 290 | +//| """The ring frequency of the note, in Hz. Zero disables. |
| 291 | +//| |
| 292 | +//| For ring to take effect, both ``ring_frequency`` and ``ring_waveform`` must be set.""" |
| 293 | +STATIC mp_obj_t synthio_note_get_ring_frequency(mp_obj_t self_in) { |
| 294 | + synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 295 | + return mp_obj_new_float(common_hal_synthio_note_get_ring_frequency(self)); |
| 296 | +} |
| 297 | +MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_ring_frequency_obj, synthio_note_get_ring_frequency); |
| 298 | + |
| 299 | +STATIC mp_obj_t synthio_note_set_ring_frequency(mp_obj_t self_in, mp_obj_t arg) { |
| 300 | + synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 301 | + common_hal_synthio_note_set_ring_frequency(self, mp_obj_get_float(arg)); |
| 302 | + return mp_const_none; |
| 303 | +} |
| 304 | +MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_ring_frequency_obj, synthio_note_set_ring_frequency); |
| 305 | +MP_PROPERTY_GETSET(synthio_note_ring_frequency_obj, |
| 306 | + (mp_obj_t)&synthio_note_get_ring_frequency_obj, |
| 307 | + (mp_obj_t)&synthio_note_set_ring_frequency_obj); |
| 308 | + |
| 309 | +//| ring_waveform: Optional[ReadableBuffer] |
| 310 | +//| """The ring waveform of this note. Setting the ring_waveform to a buffer of a different size resets the note's phase. |
| 311 | +//| |
| 312 | +//| For ring to take effect, both ``ring_frequency`` and ``ring_waveform`` must be set.""" |
| 313 | +//| |
| 314 | +STATIC mp_obj_t synthio_note_get_ring_waveform(mp_obj_t self_in) { |
| 315 | + synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 316 | + return common_hal_synthio_note_get_ring_waveform_obj(self); |
| 317 | +} |
| 318 | +MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_ring_waveform_obj, synthio_note_get_ring_waveform); |
| 319 | + |
| 320 | +STATIC mp_obj_t synthio_note_set_ring_waveform(mp_obj_t self_in, mp_obj_t arg) { |
| 321 | + synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 322 | + common_hal_synthio_note_set_ring_waveform(self, arg); |
| 323 | + return mp_const_none; |
| 324 | +} |
| 325 | +MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_ring_waveform_obj, synthio_note_set_ring_waveform); |
| 326 | +MP_PROPERTY_GETSET(synthio_note_ring_waveform_obj, |
| 327 | + (mp_obj_t)&synthio_note_get_ring_waveform_obj, |
| 328 | + (mp_obj_t)&synthio_note_set_ring_waveform_obj); |
| 329 | + |
| 330 | + |
| 331 | + |
240 | 332 | static void note_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
241 | 333 | (void)kind;
|
242 | 334 | properties_print_helper(print, self_in, note_properties, MP_ARRAY_SIZE(note_properties));
|
243 | 335 | }
|
244 | 336 |
|
245 | 337 | STATIC const mp_rom_map_elem_t synthio_note_locals_dict_table[] = {
|
246 | 338 | { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&synthio_note_frequency_obj) },
|
247 |
| - { MP_ROM_QSTR(MP_QSTR_amplitude), MP_ROM_PTR(&synthio_note_amplitude_obj) }, |
| 339 | + { MP_ROM_QSTR(MP_QSTR_filter), MP_ROM_PTR(&synthio_note_filter_obj) }, |
| 340 | + { MP_ROM_QSTR(MP_QSTR_panning), MP_ROM_PTR(&synthio_note_panning_obj) }, |
248 | 341 | { MP_ROM_QSTR(MP_QSTR_waveform), MP_ROM_PTR(&synthio_note_waveform_obj) },
|
249 | 342 | { MP_ROM_QSTR(MP_QSTR_envelope), MP_ROM_PTR(&synthio_note_envelope_obj) },
|
250 | 343 | { MP_ROM_QSTR(MP_QSTR_tremolo_depth), MP_ROM_PTR(&synthio_note_tremolo_depth_obj) },
|
251 | 344 | { MP_ROM_QSTR(MP_QSTR_tremolo_rate), MP_ROM_PTR(&synthio_note_tremolo_rate_obj) },
|
252 |
| - { MP_ROM_QSTR(MP_QSTR_vibrato_depth), MP_ROM_PTR(&synthio_note_vibrato_depth_obj) }, |
253 |
| - { MP_ROM_QSTR(MP_QSTR_vibrato_rate), MP_ROM_PTR(&synthio_note_vibrato_rate_obj) }, |
| 345 | + { MP_ROM_QSTR(MP_QSTR_bend_depth), MP_ROM_PTR(&synthio_note_bend_depth_obj) }, |
| 346 | + { MP_ROM_QSTR(MP_QSTR_bend_rate), MP_ROM_PTR(&synthio_note_bend_rate_obj) }, |
| 347 | + { MP_ROM_QSTR(MP_QSTR_bend_mode), MP_ROM_PTR(&synthio_note_bend_mode_obj) }, |
| 348 | + { MP_ROM_QSTR(MP_QSTR_ring_frequency), MP_ROM_PTR(&synthio_note_ring_frequency_obj) }, |
| 349 | + { MP_ROM_QSTR(MP_QSTR_ring_waveform), MP_ROM_PTR(&synthio_note_ring_waveform_obj) }, |
254 | 350 | };
|
255 | 351 | STATIC MP_DEFINE_CONST_DICT(synthio_note_locals_dict, synthio_note_locals_dict_table);
|
256 | 352 |
|
|
0 commit comments