Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
Mema::SerializableMessage Class Referenceabstract

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 SerializableMessageinitFromMemoryBlock (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).
 

Detailed Description

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.

See also
InterprocessConnectionImpl — client-side TCP wrapper used by Mema.Mo and Mema.Re.
InterprocessConnectionServerImpl — server-side TCP wrapper used by MemaProcessor.
MemaProcessor::handleMessage() — dispatches received messages on the JUCE message thread.

Definition at line 75 of file MemaMessages.h.

Member Enumeration Documentation

◆ SerializableMessageType

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.

Constructor & Destructor Documentation

◆ SerializableMessage()

Mema::SerializableMessage::SerializableMessage ( )
default

◆ ~SerializableMessage()

virtual Mema::SerializableMessage::~SerializableMessage ( )
virtualdefault

Member Function Documentation

◆ createSerializedContent()

virtual juce::MemoryBlock Mema::SerializableMessage::createSerializedContent ( size_t &  contentSize) const
protectedpure virtual

Subclass hook — produces the type-specific payload bytes (everything after the type discriminator).

Parameters
contentSizeSet by the implementation to the byte count of the returned block.
Returns
A 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().

◆ freeMessageData()

static void Mema::SerializableMessage::freeMessageData ( SerializableMessage message)
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.

Parameters
messageThe 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().

◆ getId()

int Mema::SerializableMessage::getId ( ) const
inline

Returns the connection-id tag, or -1 if not set.

Definition at line 99 of file MemaMessages.h.

References m_userId.

◆ getSerializedMessage()

juce::MemoryBlock Mema::SerializableMessage::getSerializedMessage ( ) const
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.

Returns
A heap-allocated MemoryBlock containing the complete framed message.

Definition at line 112 of file MemaMessages.h.

References createSerializedContent(), and m_type.

◆ getType()

const SerializableMessageType Mema::SerializableMessage::getType ( ) const
inline

Returns the concrete message type discriminator.

Definition at line 104 of file MemaMessages.h.

References m_type.

Referenced by freeMessageData().

◆ hasUserId()

bool Mema::SerializableMessage::hasUserId ( ) const
inline

Returns true when a non-default connection-id has been assigned.

Definition at line 101 of file MemaMessages.h.

References m_userId.

◆ initFromMemoryBlock()

static SerializableMessage * Mema::SerializableMessage::initFromMemoryBlock ( const juce::MemoryBlock &  blob)
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.

Parameters
blobThe raw frame received from InterprocessConnection::messageReceived().
Returns
Heap-allocated concrete message, or 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().

◆ ReadUint16()

std::uint16_t Mema::SerializableMessage::ReadUint16 ( const char *  buffer)
inlineprotected

Reads a big-endian uint16 from buffer.

Parameters
bufferPointer to at least 2 bytes of raw data.
Returns
The decoded value.

Definition at line 240 of file MemaMessages.h.

◆ ReadUint32()

std::uint32_t Mema::SerializableMessage::ReadUint32 ( const char *  buffer)
inlineprotected

Reads a big-endian uint32 from buffer.

Parameters
bufferPointer to at least 4 bytes of raw data.
Returns
The decoded value.

Definition at line 232 of file MemaMessages.h.

◆ setId()

void Mema::SerializableMessage::setId ( int  id)
inline

Tags the message with a connection-id used for echo-suppression on the server.

Parameters
idThe connection ID of the originating TCP client (-1 = no origin).

Definition at line 97 of file MemaMessages.h.

References m_userId.

Member Data Documentation

◆ m_type

◆ m_userId

int Mema::SerializableMessage::m_userId = -1
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().


The documentation for this class was generated from the following file: