/* ZynAddSubFX - a software synthesizer NotePool.h - Pool of Synthesizer Engines And Note Instances Copyright (C) 2016 Mark McCurry This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ #pragma once #include #include #include "../globals.h" //Expected upper bound of synths given that max polyphony is hit #define EXPECTED_USAGE 3 namespace zyncarla { struct LegatoParams; class NotePool { public: typedef uint8_t note_t; //Currently this wastes a ton of bits due ot the legatoMirror flag struct NoteDescriptor { //acceptable overlap after 2 minutes //run time at 48kHz 8 samples per buffer //19 bit minimum uint32_t age; uint8_t note; uint8_t sendto; //max of 16 kit elms and 3 kit items per uint8_t size; uint8_t status; bool legatoMirror; bool operator==(NoteDescriptor); //status checks bool playing(void) const; bool off(void) const; bool sustained(void) const; bool released(void) const; //status transitions void setStatus(uint8_t s); void doSustain(void); bool canSustain(void) const; void makeUnsustainable(void); }; //To be pedantic this wastes 2 or 6 bytes per descriptor //depending on 32bit/64bit alignment rules struct SynthDescriptor { SynthNote *note; uint8_t type; uint8_t kit; }; //Pool of notes NoteDescriptor ndesc[POLYPHONY]; SynthDescriptor sdesc[POLYPHONY*EXPECTED_USAGE]; bool needs_cleaning; //Iterators struct activeNotesIter { SynthDescriptor *begin() {return _b;}; SynthDescriptor *end() {return _e;}; SynthDescriptor *_b; SynthDescriptor *_e; }; struct activeDescIter { activeDescIter(NotePool &_np):np(_np) { int off=0; for(int i=0; i