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

Main UI shell for the Mema application — composes the processor editor, toolbar, load bars, and settings menu. More...

#include <MemaUIComponent.h>

+ Inheritance diagram for Mema::MemaUIComponent:
+ Collaboration diagram for Mema::MemaUIComponent:

Public Types

enum  MemaSettingsOption {
  LookAndFeel_First = 1 ,
  LookAndFeel_Automatic = LookAndFeel_First ,
  LookAndFeel_Dark ,
  LookAndFeel_Light ,
  LookAndFeel_Last = LookAndFeel_Light ,
  MeteringColour_First ,
  MeteringColour_Green = MeteringColour_First ,
  MeteringColour_Red ,
  MeteringColour_Blue ,
  MeteringColour_Pink ,
  MeteringColour_Laser ,
  MeteringColour_Last = MeteringColour_Laser ,
  LoadConfig ,
  SaveConfig
}
 Identifiers for all user-configurable settings exposed via the settings popup menu. More...
 

Public Member Functions

 MemaUIComponent ()
 Constructs the UI component and wires up child components.
 
 ~MemaUIComponent () override
 
void setStandaloneWindow (bool standalone)
 Switches between popup mode (embedded in the system tray/menubar popover) and standalone window mode.
 
bool isStandaloneWindow ()
 Returns true when the component is currently shown in standalone window mode.
 
void setEditorComponent (juce::Component *editorComponent)
 Attaches the MemaProcessorEditor to be displayed in the central content area.
 
void handleEditorSizeChangeRequest (const juce::Rectangle< int > &requestedSize)
 Responds to a resize request from the embedded editor.
 
void updateCpuUsageBar (int loadPercent)
 Updates the CPU-load progress bar to reflect the current audio processing load.
 
void updateNetworkUsage (const std::map< int, std::pair< double, bool > > &netLoads)
 Updates the network-health bar with per-connection traffic metrics.
 
void updateSessionServiceTopology (const JUCEAppBasics::SessionServiceTopology &serviceDiscoveryTopologyString)
 Updates the service-topology display (if any) with freshly discovered Mema instances.
 
void darkModeSettingChanged () override
 Responds to an OS dark-mode toggle.
 
void paint (Graphics &) override
 Paints the component background using the current look-and-feel background colour.
 
void resized () override
 Lays out all child components.
 
void lookAndFeelChanged () override
 Propagates a look-and-feel change to all child buttons and bars.
 
std::unique_ptr< juce::XmlElement > createStateXml () override
 Serialises the UI state (standalone mode, palette style, metering colour) to XML.
 
bool setStateXml (juce::XmlElement *stateXml) override
 Restores UI state from a <UICONFIG> XmlElement.
 

Public Attributes

std::function< void(bool)> onToggleStandaloneWindow
 Called when the user toggles standalone/popup mode.
 
std::function< void()> onAudioSetupMenuClicked
 Called when the audio-setup button is clicked.
 
std::function< void()> onLookAndFeelChanged
 Called after a look-and-feel change is applied.
 
std::function< void()> onDeleted
 Called when this component is destroyed.
 
std::function< void()> onSettingsChanged
 Called when any setting changes.
 
std::function< void(const JUCEAppBasics::CustomLookAndFeel::PaletteStyle &)> onPaletteStyleChange
 Called when palette style changes.
 
std::function< void()> onLoadConfig
 Called when the user selects Load Config.
 
std::function< void()> onSaveConfig
 Called when the user selects Save Config.
 

Detailed Description

Main UI shell for the Mema application — composes the processor editor, toolbar, load bars, and settings menu.

MemaUIComponent is the outermost visible component shown to the user, both in menubar/tray popup mode and in standalone window mode. It:

  • Hosts the MemaProcessorEditor (set via setEditorComponent()) in its central area.
  • Provides a toolbar row with buttons: standalone-window toggle, settings gear, audio setup, about, and power/quit.
  • Displays a CPU load bar (m_sysLoadBar) and a network health bar (m_netHealthBar) that are updated from the Mema singleton's timer callback via updateCpuUsageBar() and updateNetworkUsage().
  • Exposes a settings popup menu (gear icon) for look-and-feel, metering colour, load/save config.
  • Persists its own state (standalone mode, palette, metering colour) via XmlConfigurableElement within the main MemaAppConfiguration XML under <UICONFIG>.
  • Reacts to OS dark-mode changes via juce::DarkModeSettingListener when "Automatic" palette is selected.

Callback wiring

The Mema singleton connects lambdas to all std::function members during construction, allowing MemaUIComponent to trigger application-level actions (window resize, audio setup, config load/save) without a direct back-reference to Mema.

See also
Mema the singleton that owns this component and wires up its callbacks.
MemaProcessorEditor the embedded audio visualisation and routing control component.

Definition at line 62 of file MemaUIComponent.h.

Member Enumeration Documentation

◆ MemaSettingsOption

Identifiers for all user-configurable settings exposed via the settings popup menu.

Values are grouped into three ranges: look-and-feel (1–3), metering colour (4–8), and action items (load/save config). The settings menu is built dynamically from m_settingsItems which maps each value to a localised display string and a submenu ID.

Enumerator
LookAndFeel_First 
LookAndFeel_Automatic 

Match the host OS appearance.

LookAndFeel_Dark 

Force dark look-and-feel.

LookAndFeel_Light 

Force light look-and-feel.

LookAndFeel_Last 
MeteringColour_First 
MeteringColour_Green 

Green metering bars (default).

MeteringColour_Red 

Red metering bars.

MeteringColour_Blue 

Blue metering bars.

MeteringColour_Pink 

Pink metering bars.

MeteringColour_Laser 

High-visibility laser-green metering bars.

MeteringColour_Last 
LoadConfig 

Load configuration from file.

SaveConfig 

Save configuration to file.

Definition at line 73 of file MemaUIComponent.h.

Constructor & Destructor Documentation

◆ MemaUIComponent()

◆ ~MemaUIComponent()

Mema::MemaUIComponent::~MemaUIComponent ( )
override

Definition at line 252 of file MemaUIComponent.cpp.

References onDeleted.

Member Function Documentation

◆ createStateXml()

std::unique_ptr< XmlElement > Mema::MemaUIComponent::createStateXml ( )
override

Serialises the UI state (standalone mode, palette style, metering colour) to XML.

Returns
A new <UICONFIG> XmlElement for inclusion in the main application configuration.

Definition at line 433 of file MemaUIComponent.cpp.

References Mema::MemaAppConfiguration::getAttributeName(), Mema::MemaAppConfiguration::getTagName(), LookAndFeel_First, Mema::MemaAppConfiguration::METERINGCOLOR, Mema::MemaAppConfiguration::PALETTESTYLE, and Mema::MemaAppConfiguration::UICONFIG.

◆ darkModeSettingChanged()

void Mema::MemaUIComponent::darkModeSettingChanged ( )
override

Responds to an OS dark-mode toggle.

Only acts when m_followLocalStyle is true (i.e. "Automatic" look-and-feel is selected). Reads the current OS setting and calls applyPaletteStyle() with the matching palette.

Definition at line 380 of file MemaUIComponent.cpp.

References LookAndFeel_First, and lookAndFeelChanged().

Referenced by MemaUIComponent(), and setStateXml().

◆ handleEditorSizeChangeRequest()

void Mema::MemaUIComponent::handleEditorSizeChangeRequest ( const juce::Rectangle< int > &  requestedSize)

Responds to a resize request from the embedded editor.

Called by Mema::onEditorSizeChangeRequested when the editor (or a loaded plugin) wants to be displayed at a specific size. In standalone mode this resizes the window; in popup mode it adjusts the popup panel size if the host allows it.

Parameters
requestedSizeThe new desired bounds for the editor area.

Definition at line 298 of file MemaUIComponent.cpp.

References LookAndFeel_First.

◆ isStandaloneWindow()

bool Mema::MemaUIComponent::isStandaloneWindow ( )

Returns true when the component is currently shown in standalone window mode.

Definition at line 283 of file MemaUIComponent.cpp.

Referenced by lookAndFeelChanged().

◆ lookAndFeelChanged()

void Mema::MemaUIComponent::lookAndFeelChanged ( )
override

Propagates a look-and-feel change to all child buttons and bars.

Definition at line 405 of file MemaUIComponent.cpp.

References isStandaloneWindow(), LookAndFeel_First, and onLookAndFeelChanged.

Referenced by darkModeSettingChanged(), and setStandaloneWindow().

◆ paint()

void Mema::MemaUIComponent::paint ( Graphics g)
override

Paints the component background using the current look-and-feel background colour.

Definition at line 333 of file MemaUIComponent.cpp.

References LookAndFeel_First.

◆ resized()

void Mema::MemaUIComponent::resized ( )
override

Lays out all child components.

Arranges the toolbar buttons and load bars in a fixed-height top strip, and scales the embedded editor to fill the remaining area below it.

Definition at line 338 of file MemaUIComponent.cpp.

References LookAndFeel_First.

◆ setEditorComponent()

void Mema::MemaUIComponent::setEditorComponent ( juce::Component *  editorComponent)

Attaches the MemaProcessorEditor to be displayed in the central content area.

The component pointer is borrowed (not owned); the editor is owned by MemaProcessor. Calling this again with a different pointer replaces the previous editor.

Parameters
editorComponentPointer to the processor editor, or nullptr to clear it.

Definition at line 288 of file MemaUIComponent.cpp.

References LookAndFeel_First.

◆ setStandaloneWindow()

void Mema::MemaUIComponent::setStandaloneWindow ( bool  standalone)

Switches between popup mode (embedded in the system tray/menubar popover) and standalone window mode.

In standalone mode the component fills a normal resizable OS window; in popup mode it is constrained to fit inside the system-provided popup panel. The onToggleStandaloneWindow callback is fired so the Mema singleton can show or hide the dedicated window.

Parameters
standalonetrue to show as a standalone window, false for popup/tray mode.

Definition at line 261 of file MemaUIComponent.cpp.

References LookAndFeel_First, and lookAndFeelChanged().

◆ setStateXml()

bool Mema::MemaUIComponent::setStateXml ( juce::XmlElement *  stateXml)
override

◆ updateCpuUsageBar()

void Mema::MemaUIComponent::updateCpuUsageBar ( int  loadPercent)

Updates the CPU-load progress bar to reflect the current audio processing load.

Called from the Mema singleton's juce::Timer callback (~1 Hz) after querying AudioDeviceManager::getCpuUsage().

Parameters
loadPercentCPU load as a percentage in [0, 100].

Definition at line 309 of file MemaUIComponent.cpp.

References LookAndFeel_First.

◆ updateNetworkUsage()

void Mema::MemaUIComponent::updateNetworkUsage ( const std::map< int, std::pair< double, bool > > &  netLoads)

Updates the network-health bar with per-connection traffic metrics.

Called from the Mema singleton's timer callback after querying MemaProcessor::getNetworkHealth(). Each entry represents one connected TCP client (Mema.Mo or Mema.Re).

Parameters
netLoadsMap of {connectionId → {bytes/s, isConnected}} for each active TCP client.

Definition at line 315 of file MemaUIComponent.cpp.

References LookAndFeel_First.

◆ updateSessionServiceTopology()

void Mema::MemaUIComponent::updateSessionServiceTopology ( const JUCEAppBasics::SessionServiceTopology &  serviceDiscoveryTopologyString)

Updates the service-topology display (if any) with freshly discovered Mema instances.

Called when ServiceTopologyManager detects a change in the multicast announcement list. Currently used to keep internal state; future UI may display a list of discoverable peers.

Parameters
serviceDiscoveryTopologyStringThe full current service topology snapshot.

Definition at line 327 of file MemaUIComponent.cpp.

References LookAndFeel_First.

Member Data Documentation

◆ onAudioSetupMenuClicked

std::function<void()> Mema::MemaUIComponent::onAudioSetupMenuClicked

Called when the audio-setup button is clicked.

Definition at line 184 of file MemaUIComponent.h.

Referenced by MemaUIComponent().

◆ onDeleted

std::function<void()> Mema::MemaUIComponent::onDeleted

Called when this component is destroyed.

Definition at line 186 of file MemaUIComponent.h.

Referenced by ~MemaUIComponent().

◆ onLoadConfig

std::function<void()> Mema::MemaUIComponent::onLoadConfig

Called when the user selects Load Config.

Definition at line 189 of file MemaUIComponent.h.

◆ onLookAndFeelChanged

std::function<void()> Mema::MemaUIComponent::onLookAndFeelChanged

Called after a look-and-feel change is applied.

Definition at line 185 of file MemaUIComponent.h.

Referenced by lookAndFeelChanged().

◆ onPaletteStyleChange

std::function<void(const JUCEAppBasics::CustomLookAndFeel::PaletteStyle&)> Mema::MemaUIComponent::onPaletteStyleChange

Called when palette style changes.

Definition at line 188 of file MemaUIComponent.h.

◆ onSaveConfig

std::function<void()> Mema::MemaUIComponent::onSaveConfig

Called when the user selects Save Config.

Definition at line 190 of file MemaUIComponent.h.

◆ onSettingsChanged

std::function<void()> Mema::MemaUIComponent::onSettingsChanged

Called when any setting changes.

Definition at line 187 of file MemaUIComponent.h.

◆ onToggleStandaloneWindow

std::function<void(bool)> Mema::MemaUIComponent::onToggleStandaloneWindow

Called when the user toggles standalone/popup mode.

Definition at line 183 of file MemaUIComponent.h.

Referenced by MemaUIComponent().


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