@@ -40,11 +40,15 @@ static const mp_arg_t note_properties[] = {
4040 { MP_QSTR_amplitude , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (1 ) } },
4141 { MP_QSTR_bend , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (0 ) } },
4242 { MP_QSTR_waveform , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_NONE } },
43+ { MP_QSTR_waveform_loop_start , MP_ARG_OBJ , {.u_obj = MP_ROM_INT (0 ) } },
44+ { MP_QSTR_waveform_loop_end , MP_ARG_OBJ , {.u_obj = MP_ROM_INT (SYNTHIO_WAVEFORM_SIZE ) } },
4345 { MP_QSTR_envelope , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_NONE } },
4446 { MP_QSTR_filter , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_NONE } },
4547 { MP_QSTR_ring_frequency , MP_ARG_OBJ , {.u_obj = MP_ROM_INT (0 ) } },
4648 { MP_QSTR_ring_bend , MP_ARG_OBJ , {.u_obj = MP_ROM_INT (0 ) } },
4749 { MP_QSTR_ring_waveform , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_NONE } },
50+ { MP_QSTR_ring_waveform_loop_start , MP_ARG_OBJ , {.u_obj = MP_ROM_INT (0 ) } },
51+ { MP_QSTR_ring_waveform_loop_end , MP_ARG_OBJ , {.u_obj = MP_ROM_INT (SYNTHIO_WAVEFORM_SIZE ) } },
4852};
4953//| class Note:
5054//| def __init__(
@@ -53,13 +57,17 @@ static const mp_arg_t note_properties[] = {
5357//| frequency: float,
5458//| panning: BlockInput = 0.0,
5559//| waveform: Optional[ReadableBuffer] = None,
60+ //| waveform_loop_start: int = 0,
61+ //| waveform_loop_end: int = waveform_max_length,
5662//| envelope: Optional[Envelope] = None,
5763//| amplitude: BlockInput = 0.0,
5864//| bend: BlockInput = 0.0,
5965//| filter: Optional[Biquad] = None,
6066//| ring_frequency: float = 0.0,
6167//| ring_bend: float = 0.0,
6268//| ring_waveform: Optional[ReadableBuffer] = 0.0,
69+ //| ring_waveform_loop_start: int = 0,
70+ //| ring_waveform_loop_end: int = waveform_max_length,
6371//| ) -> None:
6472//| """Construct a Note object, with a frequency in Hz, and optional panning, waveform, envelope, tremolo (volume change) and bend (frequency change).
6573//|
@@ -210,6 +218,53 @@ MP_PROPERTY_GETSET(synthio_note_waveform_obj,
210218 (mp_obj_t )& synthio_note_get_waveform_obj ,
211219 (mp_obj_t )& synthio_note_set_waveform_obj );
212220
221+ //| waveform_loop_start: int
222+ //| """The sample index of where to begin looping waveform data.
223+ //|
224+ //| Values outside the range ``0`` to ``waveform_max_length-1`` (inclusive) are rejected with a `ValueError`.
225+ //|
226+ //| Values greater than or equal to the actual waveform length are treated as 0."""
227+ STATIC mp_obj_t synthio_note_get_waveform_loop_start (mp_obj_t self_in ) {
228+ synthio_note_obj_t * self = MP_OBJ_TO_PTR (self_in );
229+ return mp_obj_new_int (common_hal_synthio_note_get_waveform_loop_start (self ));
230+ }
231+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_note_get_waveform_loop_start_obj , synthio_note_get_waveform_loop_start );
232+
233+ STATIC mp_obj_t synthio_note_set_waveform_loop_start (mp_obj_t self_in , mp_obj_t arg ) {
234+ synthio_note_obj_t * self = MP_OBJ_TO_PTR (self_in );
235+ common_hal_synthio_note_set_waveform_loop_start (self , mp_obj_get_int (arg ));
236+ return mp_const_none ;
237+ }
238+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_note_set_waveform_loop_start_obj , synthio_note_set_waveform_loop_start );
239+ MP_PROPERTY_GETSET (synthio_note_waveform_loop_start_obj ,
240+ (mp_obj_t )& synthio_note_get_waveform_loop_start_obj ,
241+ (mp_obj_t )& synthio_note_set_waveform_loop_start_obj );
242+
243+ //| waveform_loop_end: int
244+ //| """The sample index of where to end looping waveform data.
245+ //|
246+ //| Values outside the range ``1`` to ``waveform_max_length`` (inclusive) are rejected with a `ValueError`.
247+ //|
248+ //| If the value is greater than the actual waveform length, or less than or equal to the loop start, the loop will occur at the end of the waveform.
249+ //|
250+ //| Use the `synthio.waveform_max_length` constant to set the loop point at the end of the wave form, no matter its length."""
251+ //|
252+ STATIC mp_obj_t synthio_note_get_waveform_loop_end (mp_obj_t self_in ) {
253+ synthio_note_obj_t * self = MP_OBJ_TO_PTR (self_in );
254+ return mp_obj_new_int (common_hal_synthio_note_get_waveform_loop_end (self ));
255+ }
256+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_note_get_waveform_loop_end_obj , synthio_note_get_waveform_loop_end );
257+
258+ STATIC mp_obj_t synthio_note_set_waveform_loop_end (mp_obj_t self_in , mp_obj_t arg ) {
259+ synthio_note_obj_t * self = MP_OBJ_TO_PTR (self_in );
260+ common_hal_synthio_note_set_waveform_loop_end (self , mp_obj_get_int (arg ));
261+ return mp_const_none ;
262+ }
263+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_note_set_waveform_loop_end_obj , synthio_note_set_waveform_loop_end );
264+ MP_PROPERTY_GETSET (synthio_note_waveform_loop_end_obj ,
265+ (mp_obj_t )& synthio_note_get_waveform_loop_end_obj ,
266+ (mp_obj_t )& synthio_note_set_waveform_loop_end_obj );
267+
213268
214269//| envelope: Envelope
215270//| """The envelope of this note"""
@@ -296,6 +351,53 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_obj,
296351 (mp_obj_t )& synthio_note_get_ring_waveform_obj ,
297352 (mp_obj_t )& synthio_note_set_ring_waveform_obj );
298353
354+ //| ring_waveform_loop_start: int
355+ //| """The sample index of where to begin looping waveform data.
356+ //|
357+ //| Values outside the range ``0`` to ``waveform_max_length-1`` (inclusive) are rejected with a `ValueError`.
358+ //|
359+ //| Values greater than or equal to the actual waveform length are treated as 0."""
360+ STATIC mp_obj_t synthio_note_get_ring_waveform_loop_start (mp_obj_t self_in ) {
361+ synthio_note_obj_t * self = MP_OBJ_TO_PTR (self_in );
362+ return mp_obj_new_int (common_hal_synthio_note_get_ring_waveform_loop_start (self ));
363+ }
364+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_note_get_ring_waveform_loop_start_obj , synthio_note_get_ring_waveform_loop_start );
365+
366+ STATIC mp_obj_t synthio_note_set_ring_waveform_loop_start (mp_obj_t self_in , mp_obj_t arg ) {
367+ synthio_note_obj_t * self = MP_OBJ_TO_PTR (self_in );
368+ common_hal_synthio_note_set_ring_waveform_loop_start (self , mp_obj_get_int (arg ));
369+ return mp_const_none ;
370+ }
371+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_note_set_ring_waveform_loop_start_obj , synthio_note_set_ring_waveform_loop_start );
372+ MP_PROPERTY_GETSET (synthio_note_ring_waveform_loop_start_obj ,
373+ (mp_obj_t )& synthio_note_get_ring_waveform_loop_start_obj ,
374+ (mp_obj_t )& synthio_note_set_ring_waveform_loop_start_obj );
375+
376+ //| ring_waveform_loop_end: int
377+ //| """The sample index of where to end looping waveform data.
378+ //|
379+ //| Values outside the range ``1`` to ``waveform_max_length`` (inclusive) are rejected with a `ValueError`.
380+ //|
381+ //| If the value is greater than the actual waveform length, or less than or equal to the loop start, the loop will occur at the end of the waveform.
382+ //|
383+ //| Use the `synthio.waveform_max_length` constant to set the loop point at the end of the wave form, no matter its length."""
384+ //|
385+ STATIC mp_obj_t synthio_note_get_ring_waveform_loop_end (mp_obj_t self_in ) {
386+ synthio_note_obj_t * self = MP_OBJ_TO_PTR (self_in );
387+ return mp_obj_new_int (common_hal_synthio_note_get_ring_waveform_loop_end (self ));
388+ }
389+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_note_get_ring_waveform_loop_end_obj , synthio_note_get_ring_waveform_loop_end );
390+
391+ STATIC mp_obj_t synthio_note_set_ring_waveform_loop_end (mp_obj_t self_in , mp_obj_t arg ) {
392+ synthio_note_obj_t * self = MP_OBJ_TO_PTR (self_in );
393+ common_hal_synthio_note_set_ring_waveform_loop_end (self , mp_obj_get_int (arg ));
394+ return mp_const_none ;
395+ }
396+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_note_set_ring_waveform_loop_end_obj , synthio_note_set_ring_waveform_loop_end );
397+ MP_PROPERTY_GETSET (synthio_note_ring_waveform_loop_end_obj ,
398+ (mp_obj_t )& synthio_note_get_ring_waveform_loop_end_obj ,
399+ (mp_obj_t )& synthio_note_set_ring_waveform_loop_end_obj );
400+
299401
300402
301403static void note_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
@@ -308,12 +410,16 @@ STATIC const mp_rom_map_elem_t synthio_note_locals_dict_table[] = {
308410 { MP_ROM_QSTR (MP_QSTR_filter ), MP_ROM_PTR (& synthio_note_filter_obj ) },
309411 { MP_ROM_QSTR (MP_QSTR_panning ), MP_ROM_PTR (& synthio_note_panning_obj ) },
310412 { MP_ROM_QSTR (MP_QSTR_waveform ), MP_ROM_PTR (& synthio_note_waveform_obj ) },
413+ { MP_ROM_QSTR (MP_QSTR_waveform_loop_start ), MP_ROM_PTR (& synthio_note_waveform_loop_start_obj ) },
414+ { MP_ROM_QSTR (MP_QSTR_waveform_loop_end ), MP_ROM_PTR (& synthio_note_waveform_loop_end_obj ) },
311415 { MP_ROM_QSTR (MP_QSTR_envelope ), MP_ROM_PTR (& synthio_note_envelope_obj ) },
312416 { MP_ROM_QSTR (MP_QSTR_amplitude ), MP_ROM_PTR (& synthio_note_amplitude_obj ) },
313417 { MP_ROM_QSTR (MP_QSTR_bend ), MP_ROM_PTR (& synthio_note_bend_obj ) },
314418 { MP_ROM_QSTR (MP_QSTR_ring_frequency ), MP_ROM_PTR (& synthio_note_ring_frequency_obj ) },
315419 { MP_ROM_QSTR (MP_QSTR_ring_bend ), MP_ROM_PTR (& synthio_note_ring_bend_obj ) },
316420 { MP_ROM_QSTR (MP_QSTR_ring_waveform ), MP_ROM_PTR (& synthio_note_ring_waveform_obj ) },
421+ { MP_ROM_QSTR (MP_QSTR_ring_waveform_loop_start ), MP_ROM_PTR (& synthio_note_ring_waveform_loop_start_obj ) },
422+ { MP_ROM_QSTR (MP_QSTR_ring_waveform_loop_end ), MP_ROM_PTR (& synthio_note_ring_waveform_loop_end_obj ) },
317423};
318424STATIC MP_DEFINE_CONST_DICT (synthio_note_locals_dict , synthio_note_locals_dict_table );
319425
0 commit comments