DSP processor instance for your module. */
| 27 | |
| 28 | /** DSP processor instance for your module. */ |
| 29 | struct Module { |
| 30 | struct Internal; |
| 31 | Internal* internal; |
| 32 | |
| 33 | /** Not owned. */ |
| 34 | plugin::Model* model = NULL; |
| 35 | |
| 36 | /** Unique ID for referring to the module in the engine. |
| 37 | Between 0 and 2^53-1 since the number is serialized with JSON. |
| 38 | Assigned when added to the engine. |
| 39 | */ |
| 40 | int64_t id = -1; |
| 41 | |
| 42 | /** Arrays of components. |
| 43 | Initialized using config(). |
| 44 | |
| 45 | It is recommended to call getParam(), getInput(), etc. instead of accessing these directly. |
| 46 | */ |
| 47 | std::vector<Param> params; |
| 48 | std::vector<Input> inputs; |
| 49 | std::vector<Output> outputs; |
| 50 | std::vector<Light> lights; |
| 51 | |
| 52 | /** Arrays of component metadata. |
| 53 | Initialized using configParam(), configInput(), configOutput(), and configLight(). |
| 54 | LightInfos are initialized to null unless configLight() is called. |
| 55 | |
| 56 | It is recommended to call getParamQuantity(), getInputInfo(), etc. instead of accessing these directly. |
| 57 | */ |
| 58 | std::vector<ParamQuantity*> paramQuantities; |
| 59 | std::vector<PortInfo*> inputInfos; |
| 60 | std::vector<PortInfo*> outputInfos; |
| 61 | std::vector<LightInfo*> lightInfos; |
| 62 | |
| 63 | /** Represents a message-passing channel for an adjacent module. */ |
| 64 | struct Expander { |
| 65 | /** ID of the expander module, or -1 if nonexistent. */ |
| 66 | int64_t moduleId = -1; |
| 67 | /** Pointer to the expander Module, or NULL if nonexistent. */ |
| 68 | Module* module = NULL; |
| 69 | /** Double buffer for receiving messages from the expander module. |
| 70 | If you intend to receive messages from an expander, allocate both message buffers with identical blocks of memory (arrays, structs, etc). |
| 71 | Remember to free the buffer in the Module destructor. |
| 72 | Example: |
| 73 | |
| 74 | rightExpander.producerMessage = new MyExpanderMessage; |
| 75 | rightExpander.consumerMessage = new MyExpanderMessage; |
| 76 | |
| 77 | You must check the expander module's `model` before attempting to write its message buffer. |
| 78 | Once the module is checked, you can reinterpret_cast its producerMessage at no performance cost. |
| 79 | |
| 80 | Producer messages are intended to be write-only. |
| 81 | Consumer messages are intended to be read-only. |
| 82 | |
| 83 | Once you write a message, set messageFlipRequested to true to request that the messages are flipped at the end of the timestep. |
| 84 | This means that message-passing has 1-sample latency. |
| 85 | |
| 86 | You may choose for your Module to instead write to its own message buffer for consumption by other modules, i.e. the expander "pulls" rather than this module "pushing". |