3030#include "py/objproperty.h"
3131#include "py/runtime.h"
3232#include "shared-bindings/util.h"
33+ #include "shared-bindings/synthio/__init__.h"
3334#include "shared-bindings/synthio/Note.h"
3435#include "shared-module/synthio/Note.h"
3536
@@ -38,8 +39,9 @@ static const mp_arg_t note_properties[] = {
3839 { MP_QSTR_amplitude , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (1 ) } },
3940 { MP_QSTR_tremolo_rate , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = NULL } },
4041 { 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 ) } },
4345 { MP_QSTR_waveform , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_NONE } },
4446 { MP_QSTR_envelope , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_NONE } },
4547};
@@ -53,17 +55,16 @@ static const mp_arg_t note_properties[] = {
5355//| envelope: Optional[Envelope] = None,
5456//| tremolo_depth: float = 0.0,
5557//| tremolo_rate: float = 0.0,
56- //| vibrato_depth : float = 0.0,
57- //| vibrato_rate : float = 0.0,
58+ //| bend_depth : float = 0.0,
59+ //| bend_rate : float = 0.0,
5860//| ) -> None:
59- //| """Construct a Note object, with a frequency in Hz, and optional amplitude (volume), waveform, envelope, tremolo (volume change) and vibrato (frequency change).
61+ //| """Construct a Note object, with a frequency in Hz, and optional amplitude (volume), waveform, envelope, tremolo (volume change) and bend (frequency change).
6062//|
6163//| If waveform or envelope are `None` the synthesizer object's default waveform or envelope are used.
6264//|
6365//| If the same Note object is played on multiple Synthesizer objects, the result is undefined.
6466//| """
6567STATIC 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 };
6768 mp_arg_val_t args [MP_ARRAY_SIZE (note_properties )];
6869 mp_arg_parse_all_kw_array (n_args , n_kw , all_args , MP_ARRAY_SIZE (note_properties ), note_properties , args );
6970
@@ -158,46 +159,67 @@ MP_PROPERTY_GETSET(synthio_note_tremolo_rate_obj,
158159 (mp_obj_t )& synthio_note_get_tremolo_rate_obj ,
159160 (mp_obj_t )& synthio_note_set_tremolo_rate_obj );
160161
161- //| vibrato_depth: float
162- //| """The vibrato depth of the note, from 0 to 1
163162//|
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,
163+ //| bend_mode: BendMode
164+ //| """The type of bend operation"""
165+ STATIC mp_obj_t synthio_note_get_bend_mode (mp_obj_t self_in ) {
166+ synthio_note_obj_t * self = MP_OBJ_TO_PTR (self_in );
167+ return cp_enum_find (& synthio_bend_mode_type , common_hal_synthio_note_get_bend_mode (self ));
168+ }
169+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_note_get_bend_mode_obj , synthio_note_get_bend_mode );
170+
171+ STATIC mp_obj_t synthio_note_set_bend_mode (mp_obj_t self_in , mp_obj_t arg ) {
172+ synthio_note_obj_t * self = MP_OBJ_TO_PTR (self_in );
173+ common_hal_synthio_note_set_bend_mode (self , cp_enum_value (& synthio_bend_mode_type , arg , MP_QSTR_bend_mode ));
174+ return mp_const_none ;
175+ }
176+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_note_set_bend_mode_obj , synthio_note_set_bend_mode );
177+ MP_PROPERTY_GETSET (synthio_note_bend_mode_obj ,
178+ (mp_obj_t )& synthio_note_get_bend_mode_obj ,
179+ (mp_obj_t )& synthio_note_set_bend_mode_obj );
180+
181+ //
182+ //|
183+ //| bend_depth: float
184+ //| """The bend depth of the note, from -1 to +1
185+ //|
186+ //| A depth of 0 disables bend. A depth of 1 corresponds to a bend of 1
187+ //| octave. A depth of (1/12) = 0.833 corresponds to a bend of 1 semitone,
166188//| and a depth of .00833 corresponds to one musical cent.
167189//| """
168- STATIC mp_obj_t synthio_note_get_vibrato_depth (mp_obj_t self_in ) {
190+ STATIC mp_obj_t synthio_note_get_bend_depth (mp_obj_t self_in ) {
169191 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 ));
192+ return mp_obj_new_float (common_hal_synthio_note_get_bend_depth (self ));
171193}
172- MP_DEFINE_CONST_FUN_OBJ_1 (synthio_note_get_vibrato_depth_obj , synthio_note_get_vibrato_depth );
194+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_note_get_bend_depth_obj , synthio_note_get_bend_depth );
173195
174- STATIC mp_obj_t synthio_note_set_vibrato_depth (mp_obj_t self_in , mp_obj_t arg ) {
196+ STATIC mp_obj_t synthio_note_set_bend_depth (mp_obj_t self_in , mp_obj_t arg ) {
175197 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 ));
198+ common_hal_synthio_note_set_bend_depth (self , mp_obj_get_float (arg ));
177199 return mp_const_none ;
178200}
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 );
201+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_note_set_bend_depth_obj , synthio_note_set_bend_depth );
202+ MP_PROPERTY_GETSET (synthio_note_bend_depth_obj ,
203+ (mp_obj_t )& synthio_note_get_bend_depth_obj ,
204+ (mp_obj_t )& synthio_note_set_bend_depth_obj );
183205
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 ) {
206+ //| bend_rate : float
207+ //| """The bend rate of the note, in Hz."""
208+ STATIC mp_obj_t synthio_note_get_bend_rate (mp_obj_t self_in ) {
187209 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 ));
210+ return mp_obj_new_float (common_hal_synthio_note_get_bend_rate (self ));
189211}
190- MP_DEFINE_CONST_FUN_OBJ_1 (synthio_note_get_vibrato_rate_obj , synthio_note_get_vibrato_rate );
212+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_note_get_bend_rate_obj , synthio_note_get_bend_rate );
191213
192- STATIC mp_obj_t synthio_note_set_vibrato_rate (mp_obj_t self_in , mp_obj_t arg ) {
214+ STATIC mp_obj_t synthio_note_set_bend_rate (mp_obj_t self_in , mp_obj_t arg ) {
193215 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 ));
216+ common_hal_synthio_note_set_bend_rate (self , mp_obj_get_float (arg ));
195217 return mp_const_none ;
196218}
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 );
219+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_note_set_bend_rate_obj , synthio_note_set_bend_rate );
220+ MP_PROPERTY_GETSET (synthio_note_bend_rate_obj ,
221+ (mp_obj_t )& synthio_note_get_bend_rate_obj ,
222+ (mp_obj_t )& synthio_note_set_bend_rate_obj );
201223
202224//| waveform: Optional[ReadableBuffer]
203225//| """The waveform of this note. Setting the waveform to a buffer of a different size resets the note's phase."""
@@ -249,8 +271,9 @@ STATIC const mp_rom_map_elem_t synthio_note_locals_dict_table[] = {
249271 { MP_ROM_QSTR (MP_QSTR_envelope ), MP_ROM_PTR (& synthio_note_envelope_obj ) },
250272 { MP_ROM_QSTR (MP_QSTR_tremolo_depth ), MP_ROM_PTR (& synthio_note_tremolo_depth_obj ) },
251273 { 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 ) },
274+ { MP_ROM_QSTR (MP_QSTR_bend_depth ), MP_ROM_PTR (& synthio_note_bend_depth_obj ) },
275+ { MP_ROM_QSTR (MP_QSTR_bend_rate ), MP_ROM_PTR (& synthio_note_bend_rate_obj ) },
276+ { MP_ROM_QSTR (MP_QSTR_bend_mode ), MP_ROM_PTR (& synthio_note_bend_mode_obj ) },
254277};
255278STATIC MP_DEFINE_CONST_DICT (synthio_note_locals_dict , synthio_note_locals_dict_table );
256279
0 commit comments