![]() |
Mema
Memory Matrix — multi-channel audio matrix monitor and router
|
Base class for all messages exchanged between Mema, Mema.Mo, and Mema.Re over TCP. More...
#include <MemaMessages.h>
Inheritance diagram for Mema::SerializableMessage:
Collaboration diagram for Mema::SerializableMessage:Public Types | |
| enum | SerializableMessageType { None = 0 , EnvironmentParameters , AnalyzerParameters , ReinitIOCount , AudioInputBuffer , AudioOutputBuffer , DataTrafficTypeSelection , ControlParameters , PluginParameterInfos , PluginParameterValue } |
Public Member Functions | |
| SerializableMessage ()=default | |
| virtual | ~SerializableMessage ()=default |
| void | setId (int id) |
| Tags the message with a connection-id used for echo-suppression on the server. | |
| int | getId () const |
| Returns the connection-id tag, or -1 if not set. | |
| bool | hasUserId () const |
| Returns true when a non-default connection-id has been assigned. | |
| const SerializableMessageType | getType () const |
| Returns the concrete message type discriminator. | |
| juce::MemoryBlock | getSerializedMessage () const |
Serialises the message to a MemoryBlock ready to send over the socket. | |
Static Public Member Functions | |
| static SerializableMessage * | initFromMemoryBlock (const juce::MemoryBlock &blob) |
Deserialises a raw TCP frame into the correct concrete SerializableMessage subclass. | |
| static void | freeMessageData (SerializableMessage *message) |
Type-correctly destroys a SerializableMessage* returned by initFromMemoryBlock(). | |
Protected Member Functions | |
| virtual juce::MemoryBlock | createSerializedContent (size_t &contentSize) const =0 |
| Subclass hook — produces the type-specific payload bytes (everything after the type discriminator). | |
| std::uint32_t | ReadUint32 (const char *buffer) |
Reads a big-endian uint32 from buffer. | |
| std::uint16_t | ReadUint16 (const char *buffer) |
Reads a big-endian uint16 from buffer. | |
Protected Attributes | |
| SerializableMessageType | m_type = SerializableMessageType::None |
| Type discriminator stored in the first 4 bytes of every serialised frame. | |
| int | m_userId = -1 |
| Optional connection-id tag for echo-suppression (-1 = not set). | |
Base class for all messages exchanged between Mema, Mema.Mo, and Mema.Re over TCP.
All inter-process communication between the Mema server and its clients (Mema.Mo, Mema.Re) uses a simple binary framing protocol built on top of JUCE's InterprocessConnection:
| Offset | Size | Content |
|---|---|---|
| 0 | 4 B | SerializableMessageType enum value (little-endian uint32) |
| 4 | N B | Payload produced by createSerializedContent() |
Sending — call getSerializedMessage() to obtain the complete framed MemoryBlock, then pass it to InterprocessConnection::sendMessage().
Receiving — pass the raw MemoryBlock received from the socket to the static initFromMemoryBlock() factory, which reads the type byte and constructs the correct concrete subclass. The caller owns the returned pointer and must call freeMessageData() to properly destroy it via the correct subclass destructor.
Echo suppression — the optional user-id (m_userId) is set by MemaProcessor when it forwards an inbound ControlParametersMessage back out to all other connected clients. The originating client's connection-id is stored so that the server-side commander wrapper can skip re-sending the update to the client that triggered it.
Definition at line 75 of file MemaMessages.h.
| Enumerator | |
|---|---|
| None | Sentinel / uninitialised type. |
| EnvironmentParameters | Look-and-feel palette sent by Mema to clients on connect. |
| AnalyzerParameters | Audio device sample rate and block size; lets clients initialise their local ProcessorDataAnalyzer. |
| ReinitIOCount | New input/output channel count; clients must rebuild their UI accordingly. |
| AudioInputBuffer | Raw PCM input buffer streamed from Mema to subscribed clients. |
| AudioOutputBuffer | Raw PCM output buffer streamed from Mema to subscribed clients. |
| DataTrafficTypeSelection | Sent by a client to opt in/out of specific message types (bandwidth control). |
| ControlParameters | Full routing-matrix state snapshot; sent by Mema on connect and echoed by Mema.Re on change. |
| PluginParameterInfos | Plugin name and full parameter descriptor list; sent by Mema when a plugin is loaded or changed. |
| PluginParameterValue | Single parameter value update sent from Mema.Re to Mema. |
Definition at line 78 of file MemaMessages.h.
|
default |
|
virtualdefault |
|
protectedpure virtual |
Subclass hook — produces the type-specific payload bytes (everything after the type discriminator).
| contentSize | Set by the implementation to the byte count of the returned block. |
MemoryBlock containing only the payload (no type prefix). Implemented in Mema::AudioBufferMessage, Mema::EnvironmentParametersMessage, Mema::AnalyzerParametersMessage, Mema::ReinitIOCountMessage, Mema::DataTrafficTypeSelectionMessage, Mema::ControlParametersMessage, Mema::PluginParameterInfosMessage, and Mema::PluginParameterValueMessage.
Referenced by getSerializedMessage().
|
inlinestatic |
Type-correctly destroys a SerializableMessage* returned by initFromMemoryBlock().
Because the pointer is typed as the base class, a plain delete would invoke the wrong destructor. This helper casts to the concrete subclass before destruction.
| message | The message to destroy. Safe to call with nullptr. |
Definition at line 168 of file MemaMessages.h.
References AnalyzerParameters, AudioInputBuffer, AudioOutputBuffer, ControlParameters, DataTrafficTypeSelection, getType(), None, PluginParameterInfos, PluginParameterValue, and ReinitIOCount.
Referenced by MainComponent::MainComponent().
|
inline |
Returns the connection-id tag, or -1 if not set.
Definition at line 99 of file MemaMessages.h.
References m_userId.
|
inline |
Serialises the message to a MemoryBlock ready to send over the socket.
Prepends the SerializableMessageType enum value (4 bytes) followed by the payload produced by the subclass createSerializedContent() implementation.
MemoryBlock containing the complete framed message. Definition at line 112 of file MemaMessages.h.
References createSerializedContent(), and m_type.
|
inline |
Returns the concrete message type discriminator.
Definition at line 104 of file MemaMessages.h.
References m_type.
Referenced by freeMessageData().
|
inline |
Returns true when a non-default connection-id has been assigned.
Definition at line 101 of file MemaMessages.h.
References m_userId.
|
inlinestatic |
Deserialises a raw TCP frame into the correct concrete SerializableMessage subclass.
Reads the first 4 bytes as a SerializableMessageType enum and constructs the matching subclass using its MemoryBlock-taking constructor. The caller takes ownership of the returned pointer and must call freeMessageData() to destroy it.
| blob | The raw frame received from InterprocessConnection::messageReceived(). |
nullptr if the type is None or unknown. Definition at line 129 of file MemaMessages.h.
References AnalyzerParameters, AudioInputBuffer, AudioOutputBuffer, ControlParameters, DataTrafficTypeSelection, EnvironmentParameters, None, PluginParameterInfos, PluginParameterValue, and ReinitIOCount.
Referenced by MainComponent::MainComponent(), and Mema::MemaProcessor::MemaProcessor().
|
inlineprotected |
Reads a big-endian uint16 from buffer.
| buffer | Pointer to at least 2 bytes of raw data. |
Definition at line 240 of file MemaMessages.h.
|
inlineprotected |
Reads a big-endian uint32 from buffer.
| buffer | Pointer to at least 4 bytes of raw data. |
Definition at line 232 of file MemaMessages.h.
|
inline |
Tags the message with a connection-id used for echo-suppression on the server.
| id | The connection ID of the originating TCP client (-1 = no origin). |
Definition at line 97 of file MemaMessages.h.
References m_userId.
|
protected |
Type discriminator stored in the first 4 bytes of every serialised frame.
Definition at line 247 of file MemaMessages.h.
Referenced by Mema::AnalyzerParametersMessage::AnalyzerParametersMessage(), Mema::AnalyzerParametersMessage::AnalyzerParametersMessage(), Mema::AudioInputBufferMessage::AudioInputBufferMessage(), Mema::AudioInputBufferMessage::AudioInputBufferMessage(), Mema::AudioOutputBufferMessage::AudioOutputBufferMessage(), Mema::AudioOutputBufferMessage::AudioOutputBufferMessage(), Mema::ControlParametersMessage::ControlParametersMessage(), Mema::ControlParametersMessage::ControlParametersMessage(), Mema::DataTrafficTypeSelectionMessage::DataTrafficTypeSelectionMessage(), Mema::DataTrafficTypeSelectionMessage::DataTrafficTypeSelectionMessage(), Mema::EnvironmentParametersMessage::EnvironmentParametersMessage(), Mema::EnvironmentParametersMessage::EnvironmentParametersMessage(), getSerializedMessage(), getType(), Mema::PluginParameterInfosMessage::PluginParameterInfosMessage(), Mema::PluginParameterInfosMessage::PluginParameterInfosMessage(), Mema::PluginParameterValueMessage::PluginParameterValueMessage(), Mema::PluginParameterValueMessage::PluginParameterValueMessage(), Mema::ReinitIOCountMessage::ReinitIOCountMessage(), and Mema::ReinitIOCountMessage::ReinitIOCountMessage().
|
protected |
Optional connection-id tag for echo-suppression (-1 = not set).
Definition at line 248 of file MemaMessages.h.
Referenced by getId(), hasUserId(), and setId().