3131#include "py/binary.h"
3232#include "py/objproperty.h"
3333#include "py/runtime.h"
34+ #include "py/enum.h"
3435#include "shared-bindings/util.h"
3536#include "shared-bindings/synthio/Biquad.h"
3637#include "shared-bindings/synthio/Synthesizer.h"
@@ -256,7 +257,9 @@ MP_PROPERTY_GETTER(synthio_synthesizer_sample_rate_obj,
256257 (mp_obj_t )& synthio_synthesizer_get_sample_rate_obj );
257258
258259//| pressed: NoteSequence
259- //| """A sequence of the currently pressed notes (read-only property)"""
260+ //| """A sequence of the currently pressed notes (read-only property).
261+ //|
262+ //| This does not include notes in the release phase of the envelope."""
260263//|
261264STATIC mp_obj_t synthio_synthesizer_obj_get_pressed (mp_obj_t self_in ) {
262265 synthio_synthesizer_obj_t * self = MP_OBJ_TO_PTR (self_in );
@@ -268,6 +271,23 @@ MP_DEFINE_CONST_FUN_OBJ_1(synthio_synthesizer_get_pressed_obj, synthio_synthesiz
268271MP_PROPERTY_GETTER (synthio_synthesizer_pressed_obj ,
269272 (mp_obj_t )& synthio_synthesizer_get_pressed_obj );
270273
274+ //| def note_info(self, note: Note) -> Tuple[Optional[EnvelopeState], float]:
275+ //| """Get info about a note's current envelope state
276+ //|
277+ //| If the note is currently playing (including in the release phase), the returned value gives the current envelope state and the current envelope value.
278+ //|
279+ //| If the note is not playing on this synthesizer, returns the tuple ``(None, 0.0)``."""
280+ STATIC mp_obj_t synthio_synthesizer_obj_note_info (mp_obj_t self_in , mp_obj_t note ) {
281+ synthio_synthesizer_obj_t * self = MP_OBJ_TO_PTR (self_in );
282+ check_for_deinit (self );
283+ mp_float_t vol = MICROPY_FLOAT_CONST (0.0 );
284+ envelope_state_e state = common_hal_synthio_synthesizer_note_info (self , note , & vol );
285+ return MP_OBJ_NEW_TUPLE (
286+ cp_enum_find (& synthio_note_state_type , state ),
287+ mp_obj_new_float (vol ));
288+ }
289+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_synthesizer_note_info_obj , synthio_synthesizer_obj_note_info );
290+
271291//| blocks: List[BlockInput]
272292//| """A list of blocks to advance whether or not they are associated with a playing note.
273293//|
@@ -417,6 +437,7 @@ STATIC const mp_rom_map_elem_t synthio_synthesizer_locals_dict_table[] = {
417437 { MP_ROM_QSTR (MP_QSTR_sample_rate ), MP_ROM_PTR (& synthio_synthesizer_sample_rate_obj ) },
418438 { MP_ROM_QSTR (MP_QSTR_max_polyphony ), MP_ROM_INT (CIRCUITPY_SYNTHIO_MAX_CHANNELS ) },
419439 { MP_ROM_QSTR (MP_QSTR_pressed ), MP_ROM_PTR (& synthio_synthesizer_pressed_obj ) },
440+ { MP_ROM_QSTR (MP_QSTR_note_info ), MP_ROM_PTR (& synthio_synthesizer_note_info_obj ) },
420441 { MP_ROM_QSTR (MP_QSTR_blocks ), MP_ROM_PTR (& synthio_synthesizer_blocks_obj ) },
421442};
422443STATIC MP_DEFINE_CONST_DICT (synthio_synthesizer_locals_dict , synthio_synthesizer_locals_dict_table );
0 commit comments