Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
MainComponent.h
Go to the documentation of this file.
1/* Copyright (c) 2025, Christian Ahrens
2 *
3 * This file is part of Mema <https://github.com/ChristianAhrens/Mema>
4 *
5 * This tool is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 3.0 as published
7 * by the Free Software Foundation.
8 *
9 * This tool is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this tool; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#pragma once
20
21#include <JuceHeader.h>
22
24
26
27#include <ServiceTopologyManager.h>
28
29
30class MemaReComponent;
33class AboutComponent;
34
64class MainComponent : public juce::Component,
65 public juce::Timer,
66 public MemaReAppConfiguration::Dumper,
67 public MemaReAppConfiguration::Watcher
68{
69public:
71 enum Status
72 {
76 };
77
115
116public:
118 ~MainComponent() override;
119
122
123 //==============================================================================
125 void resized() override;
127 void paint(juce::Graphics& g) override;
129 void lookAndFeelChanged() override;
130
132 void timerCallback() override;
133
135 bool keyPressed(const juce::KeyPress& key) override;
136
137 //==============================================================================
141 void onConfigUpdated() override;
142
143 //==============================================================================
146
147 //==============================================================================
148 std::function<void(int, bool)> onPaletteStyleChange;
149
150 //==============================================================================
151 std::function<void(bool)> onSetFullscreenWindow;
152
153private:
162 class InterprocessConnectionImpl : public juce::InterprocessConnection
163 {
164 public:
165 InterprocessConnectionImpl() : juce::InterprocessConnection() {};
166 virtual ~InterprocessConnectionImpl() { disconnect(); };
167
169 void connectionMade() override { if (onConnectionMade) onConnectionMade(); };
170
172 void connectionLost() override { if (onConnectionLost) onConnectionLost(); };
173
175 void messageReceived(const MemoryBlock& message) override { if (onMessageReceived) onMessageReceived(message); };
176
178 bool ConnectToSocket(const juce::String& hostName, int portNumber) {
179 m_hostName = hostName;
180 m_portNumber = portNumber;
181 return juce::InterprocessConnection::connectToSocket(hostName, portNumber, 3000);
182 };
183
185 bool RetryConnectToSocket() {
186 disconnect();
187 return connectToSocket(m_hostName, m_portNumber, 3000);
188 };
189
190 std::function<void()> onConnectionMade;
191 std::function<void()> onConnectionLost;
192 std::function<void(const MemoryBlock&)> onMessageReceived;
193
194 private:
195 juce::String m_hostName;
196 int m_portNumber = 0;
197 };
198
199 //==============================================================================
200 void handleSettingsMenuResult(int selectedId);
201 void handleSettingsLookAndFeelMenuResult(int selectedId);
202 void handleSettingsControlFormatMenuResult(int selectedId);
203 void handleSettingsControlColourMenuResult(int selectedId);
204 void handleSettingsControlsSizeMenuResult(int selectedId);
205 void handleSettingsFullscreenModeToggleResult();
206 void showExternalControlSettings();
207
208 void setControlColour(const juce::Colour& meteringColour);
209 void applyControlColour();
210
212
213 void toggleFullscreenMode();
214
215 void setStatus(const Status& s);
216 const Status getStatus();
217
218 void connectToMema();
219
220 //==============================================================================
221 JUCEAppBasics::SessionMasterAwareService m_selectedService;
222 std::unique_ptr<InterprocessConnectionImpl> m_networkConnection;
223
224 std::unique_ptr<MemaReComponent> m_remoteComponent;
225 std::unique_ptr<MemaClientDiscoverComponent> m_discoverComponent;
226 std::unique_ptr<MemaClientConnectingComponent> m_connectingComponent;
227
228 std::unique_ptr<juce::DrawableButton> m_settingsButton;
229 std::map<int, std::pair<std::string, int>> m_settingsItems;
230 int m_settingsHostLookAndFeelId = -1;
231
232 std::unique_ptr<juce::DrawableButton> m_disconnectButton;
233
234 std::unique_ptr<juce::DrawableButton> m_aboutButton;
235 std::unique_ptr<AboutComponent> m_aboutComponent;
236
237 std::unique_ptr<juce::AlertWindow> m_messageBox;
238
239 Status m_currentStatus = Status::Discovering;
240
241 juce::Colour m_controlColour = juce::Colours::forestgreen;
242
243 std::unique_ptr<MemaReAppConfiguration> m_config;
244
246};
247
Top-level application component for Mema.Mo (MenubarMatrixMonitor).
void paint(juce::Graphics &g) override
Paints the background and any status overlay.
void performConfigurationDump() override
Serialises the current configuration to the XML file on disk.
std::function< void(int, bool)> onPaletteStyleChange
Called when the user changes the look-and-feel or metering colour.
void resized() override
Lays out the active child component to fill the window.
MemaReSettingsOption
Identifiers for all user-configurable settings exposed via the settings popup menu.
@ ControlsSize_M
Medium control elements.
@ ControlsSize_S
Small control elements.
@ ControlFormat_PanningType_5point0
2-D spatial panning — 5.0 surround.
@ LookAndFeel_Light
Force light look-and-feel.
@ ControlFormat_PanningType_7point1point4
2-D spatial panning — 7.1.4 Dolby Atmos.
@ ControlFormat_PanningType_9point1point6
2-D spatial panning — 9.1.6 ATMOS full-3D.
@ ControlColour_Blue
Blue accent colour.
@ LookAndFeel_FollowHost
Match the host OS appearance.
@ ControlFormat_PanningType_7point0
2-D spatial panning — 7.0 surround.
@ ControlColour_Laser
High-visibility laser-green accent colour.
@ ExternalControl
Opens the ADM-OSC external-control settings dialog.
@ LookAndFeel_Dark
Force dark look-and-feel.
@ ControlColour_Pink
Pink accent colour.
@ ControlFormat_PanningType_LCRS
2-D spatial panning — LCRS 4-channel.
@ ControlFormat_PanningType_LRS
2-D spatial panning — LRS 3-channel.
@ ControlFormat_PanningType_Quadrophonic
2-D spatial panning — classic 4-channel quad.
@ ControlsSize_L
Large control elements (good for touch screens).
@ ControlColour_Red
Red accent colour.
@ ControlColour_Green
Green accent colour (default).
@ ControlFormat_RawChannels
Faderbank crosspoint control (raw input × output).
@ ControlFormat_PanningType_5point1point2
2-D spatial panning — 5.1.2 with height.
@ ControlFormat_PluginParameterControl
Plugin-parameter control panel.
@ ControlFormat_PanningType_7point1
2-D spatial panning — 7.1 surround.
@ ControlFormat_PanningType_5point1
2-D spatial panning — 5.1 surround.
@ FullscreenWindowMode
Toggle between popup and fullscreen window mode.
Status
Connection/application phase driven by the TCP session lifecycle.
@ Connecting
TCP handshake in progress.
@ Monitoring
Connected and actively receiving audio data.
@ Discovering
Searching for Mema instances via multicast.
void lookAndFeelChanged() override
Propagates a look-and-feel change to all owned child components.
bool keyPressed(const juce::KeyPress &key) override
Handles keyboard shortcuts (e.g. Escape to disconnect).
void applySettingsOption(const MemaMoSettingsOption &option)
Applies a settings menu selection, updating look-and-feel, visualisation type, or colour.
void onConfigUpdated() override
Reacts to external configuration changes.
bool isFullscreenEnabled()
Returns whether the window is currently displayed in fullscreen mode.
void timerCallback() override
Periodic callback used to retry TCP connections and poll status.
std::function< void(bool)> onSetFullscreenWindow
Called to request a fullscreen/windowed transition from the application shell.
~MainComponent() override
Central remote-control panel of the Mema.Re application.
ControlsSize
Size category for rendered control elements.