@@ -40,11 +40,15 @@ static const mp_arg_t note_properties[] = {
40
40
{ MP_QSTR_amplitude , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (1 ) } },
41
41
{ MP_QSTR_bend , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (0 ) } },
42
42
{ 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 ) } },
43
45
{ MP_QSTR_envelope , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_NONE } },
44
46
{ MP_QSTR_filter , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_NONE } },
45
47
{ MP_QSTR_ring_frequency , MP_ARG_OBJ , {.u_obj = MP_ROM_INT (0 ) } },
46
48
{ MP_QSTR_ring_bend , MP_ARG_OBJ , {.u_obj = MP_ROM_INT (0 ) } },
47
49
{ 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 ) } },
48
52
};
49
53
//| class Note:
50
54
//| def __init__(
@@ -53,13 +57,17 @@ static const mp_arg_t note_properties[] = {
53
57
//| frequency: float,
54
58
//| panning: BlockInput = 0.0,
55
59
//| waveform: Optional[ReadableBuffer] = None,
60
+ //| waveform_loop_start: int = 0,
61
+ //| waveform_loop_end: int = waveform_max_length,
56
62
//| envelope: Optional[Envelope] = None,
57
63
//| amplitude: BlockInput = 0.0,
58
64
//| bend: BlockInput = 0.0,
59
65
//| filter: Optional[Biquad] = None,
60
66
//| ring_frequency: float = 0.0,
61
67
//| ring_bend: float = 0.0,
62
68
//| ring_waveform: Optional[ReadableBuffer] = 0.0,
69
+ //| ring_waveform_loop_start: int = 0,
70
+ //| ring_waveform_loop_end: int = waveform_max_length,
63
71
//| ) -> None:
64
72
//| """Construct a Note object, with a frequency in Hz, and optional panning, waveform, envelope, tremolo (volume change) and bend (frequency change).
65
73
//|
@@ -210,6 +218,53 @@ MP_PROPERTY_GETSET(synthio_note_waveform_obj,
210
218
(mp_obj_t )& synthio_note_get_waveform_obj ,
211
219
(mp_obj_t )& synthio_note_set_waveform_obj );
212
220
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
+
213
268
214
269
//| envelope: Envelope
215
270
//| """The envelope of this note"""
@@ -296,6 +351,53 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_obj,
296
351
(mp_obj_t )& synthio_note_get_ring_waveform_obj ,
297
352
(mp_obj_t )& synthio_note_set_ring_waveform_obj );
298
353
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
+
299
401
300
402
301
403
static 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[] = {
308
410
{ MP_ROM_QSTR (MP_QSTR_filter ), MP_ROM_PTR (& synthio_note_filter_obj ) },
309
411
{ MP_ROM_QSTR (MP_QSTR_panning ), MP_ROM_PTR (& synthio_note_panning_obj ) },
310
412
{ 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 ) },
311
415
{ MP_ROM_QSTR (MP_QSTR_envelope ), MP_ROM_PTR (& synthio_note_envelope_obj ) },
312
416
{ MP_ROM_QSTR (MP_QSTR_amplitude ), MP_ROM_PTR (& synthio_note_amplitude_obj ) },
313
417
{ MP_ROM_QSTR (MP_QSTR_bend ), MP_ROM_PTR (& synthio_note_bend_obj ) },
314
418
{ MP_ROM_QSTR (MP_QSTR_ring_frequency ), MP_ROM_PTR (& synthio_note_ring_frequency_obj ) },
315
419
{ MP_ROM_QSTR (MP_QSTR_ring_bend ), MP_ROM_PTR (& synthio_note_ring_bend_obj ) },
316
420
{ 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 ) },
317
423
};
318
424
STATIC MP_DEFINE_CONST_DICT (synthio_note_locals_dict , synthio_note_locals_dict_table );
319
425
0 commit comments