From 7039dd1307f0499bacdbab61789174515fcd2fc7 Mon Sep 17 00:00:00 2001 From: Stuart Longland Date: Sat, 15 Jul 2017 15:19:54 +1000 Subject: [PATCH] adsr: Add state helper functions Add helper functions that report back whether the ADSR generator is in a given state. Namely, if it is "waiting" for a trigger, or it is idle. --- adsr.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/adsr.h b/adsr.h index 3d38a30..abb903a 100644 --- a/adsr.h +++ b/adsr.h @@ -135,6 +135,22 @@ static inline uint8_t adsr_is_done(struct adsr_env_gen_t* const adsr) { return (adsr->state == ADSR_STATE_DONE); } +/*! + * Test to see if the ADSR is awaiting a trigger. + */ +static inline uint8_t adsr_is_waiting(struct adsr_env_gen_t* const adsr) { + return ((adsr->next_event == UINT32_MAX) + && ((adsr->state == ADSR_STATE_DELAY_EXPIRE) + || (adsr->state == ADSR_STATE_SUSTAIN_EXPIRE))); +} + +/*! + * Test to see if the ADSR is idle. + */ +static inline uint8_t adsr_is_idle(struct adsr_env_gen_t* const adsr) { + return (adsr->state == ADSR_STATE_IDLE); +} + /*! * Tell the ADSR to move onto the next state. */