Skip to content

Commit b044c4c

Browse files
authored
Merge pull request #10309 from rhammell/add-mixervoice-end-method
Add end() method to MixerVoice to allow samples to finish playing bef…
2 parents 07ec0c6 + fd2500d commit b044c4c

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

shared-bindings/audiomixer/MixerVoice.c

+14
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ static mp_obj_t audiomixer_mixervoice_obj_stop(size_t n_args, const mp_obj_t *po
8181
}
8282
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_stop_obj, 1, audiomixer_mixervoice_obj_stop);
8383

84+
//| def end(self) -> None:
85+
//| """ Sets looping to False if sample is playing. This allows the looped
86+
//| sample to complete its current playback and end further looping """
87+
//| ...
88+
//|
89+
static mp_obj_t audiomixer_mixervoice_obj_end(mp_obj_t self_in) {
90+
audiomixer_mixervoice_obj_t *self = MP_OBJ_TO_PTR(self_in);
91+
common_hal_audiomixer_mixervoice_end(self);
92+
return mp_const_none;
93+
}
94+
MP_DEFINE_CONST_FUN_OBJ_1(audiomixer_mixervoice_end_obj, audiomixer_mixervoice_obj_end);
95+
96+
8497
//| level: synthio.BlockInput
8598
//| """The volume level of a voice, as a floating point number between 0 and 1. If your board
8699
//| does not support synthio, this property will only accept a float value.
@@ -140,6 +153,7 @@ static const mp_rom_map_elem_t audiomixer_mixervoice_locals_dict_table[] = {
140153
// Methods
141154
{ MP_ROM_QSTR(MP_QSTR_play), MP_ROM_PTR(&audiomixer_mixervoice_play_obj) },
142155
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&audiomixer_mixervoice_stop_obj) },
156+
{ MP_ROM_QSTR(MP_QSTR_end), MP_ROM_PTR(&audiomixer_mixervoice_end_obj) },
143157

144158
// Properties
145159
{ MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiomixer_mixervoice_playing_obj) },

shared-bindings/audiomixer/MixerVoice.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void common_hal_audiomixer_mixervoice_construct(audiomixer_mixervoice_obj_t *sel
1515
void common_hal_audiomixer_mixervoice_set_parent(audiomixer_mixervoice_obj_t *self, audiomixer_mixer_obj_t *parent);
1616
void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t *self, mp_obj_t sample, bool loop);
1717
void common_hal_audiomixer_mixervoice_stop(audiomixer_mixervoice_obj_t *self);
18+
void common_hal_audiomixer_mixervoice_end(audiomixer_mixervoice_obj_t *self);
1819
mp_obj_t common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t *self);
1920
void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *self, mp_obj_t gain);
2021

shared-module/audiomixer/MixerVoice.c

+6
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,9 @@ bool common_hal_audiomixer_mixervoice_get_playing(audiomixer_mixervoice_obj_t *s
6767
void common_hal_audiomixer_mixervoice_stop(audiomixer_mixervoice_obj_t *self) {
6868
self->sample = NULL;
6969
}
70+
71+
void common_hal_audiomixer_mixervoice_end(audiomixer_mixervoice_obj_t *self) {
72+
if (self->sample != NULL) {
73+
self->loop = false;
74+
}
75+
}

0 commit comments

Comments
 (0)