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) 2024-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
25#include <ServiceTopologyManager.h>
26
27
28class MemaMoComponent;
31class AboutComponent;
32
60class MainComponent : public juce::Component,
61 public juce::Timer,
62 public MemaMoAppConfiguration::Dumper,
63 public MemaMoAppConfiguration::Watcher
64{
65public:
73
106
107public:
109 ~MainComponent() override;
110
113
114 //==============================================================================
116 void resized() override;
118 void paint(juce::Graphics& g) override;
120 void lookAndFeelChanged() override;
121
123 void timerCallback() override;
124
126 bool keyPressed(const juce::KeyPress& key) override;
127
128 //==============================================================================
130 void performConfigurationDump() override;
132 void onConfigUpdated() override;
133
134 //==============================================================================
136 bool isFullscreenEnabled();
137
138 //==============================================================================
139 std::function<void(int, bool)> onPaletteStyleChange;
140
141 //==============================================================================
142 std::function<void(bool)> onSetFullscreenWindow;
143
144private:
153 class InterprocessConnectionImpl : public juce::InterprocessConnection
154 {
155 public:
156 InterprocessConnectionImpl() : juce::InterprocessConnection() {};
157 virtual ~InterprocessConnectionImpl() { disconnect(); };
158
160 void connectionMade() override { if (onConnectionMade) onConnectionMade(); };
161
163 void connectionLost() override { if (onConnectionLost) onConnectionLost(); };
164
166 void messageReceived(const MemoryBlock& message) override { if (onMessageReceived) onMessageReceived(message); };
167
169 bool ConnectToSocket(const juce::String& hostName, int portNumber) {
170 m_hostName = hostName;
171 m_portNumber = portNumber;
172 return juce::InterprocessConnection::connectToSocket(hostName, portNumber, 3000);
173 };
174
176 bool RetryConnectToSocket() {
177 disconnect();
178 return connectToSocket(m_hostName, m_portNumber, 3000);
179 };
180
181 std::function<void()> onConnectionMade;
182 std::function<void()> onConnectionLost;
183 std::function<void(const MemoryBlock&)> onMessageReceived;
184
185 private:
186 juce::String m_hostName;
187 int m_portNumber = 0;
188 };
189
190 //==============================================================================
191 void handleSettingsMenuResult(int selectedId);
192 void handleSettingsLookAndFeelMenuResult(int selectedId);
193 void handleSettingsOutputVisuTypeMenuResult(int selectedId);
194 void handleSettingsMeteringColourMenuResult(int selectedId);
195 void handleSettingsFullscreenModeToggleResult();
196
197 void setMeteringColour(const juce::Colour& meteringColour);
198 void applyMeteringColour();
199
200 void toggleFullscreenMode();
201
202 std::optional<int> getNumVisibleChannels();
203
204 void setStatus(const Status& s);
205 const Status getStatus();
206
207 void connectToMema();
208
209 //==============================================================================
210 JUCEAppBasics::SessionMasterAwareService m_selectedService;
211 std::unique_ptr<InterprocessConnectionImpl> m_networkConnection;
212
213 std::unique_ptr<MemaMoComponent> m_monitorComponent;
214 std::unique_ptr<MemaClientDiscoverComponent> m_discoverComponent;
215 std::unique_ptr<MemaClientConnectingComponent> m_connectingComponent;
216
217 std::unique_ptr<juce::DrawableButton> m_settingsButton;
218 std::map<int, std::pair<std::string, int>> m_settingsItems;
219 int m_settingsHostLookAndFeelId = -1;
220
221 std::unique_ptr<juce::DrawableButton> m_disconnectButton;
222
223 std::unique_ptr<juce::DrawableButton> m_aboutButton;
224 std::unique_ptr<AboutComponent> m_aboutComponent;
225
226 Status m_currentStatus = Status::Discovering;
227
228 juce::Colour m_meteringColour = juce::Colours::forestgreen;
229
230 std::unique_ptr<MemaMoAppConfiguration> m_config;
231
233};
234
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.
MemaMoSettingsOption
Identifiers for all user-configurable settings exposed via the settings popup menu.
@ OutputVisuType_LRS
3-channel Left/Right/Surround 2-D field.
@ OutputVisuType_5point0
5.0 surround 2-D field.
@ OutputVisuType_LCRS
4-channel LCRS 2-D field.
@ OutputVisuType_Waveform
Scrolling waveform plot.
@ OutputVisuType_Spectrum
FFT frequency-spectrum display.
@ OutputVisuType_Meterbridge
Level-bar meterbridge (default).
@ OutputVisuType_7point1
7.1 surround 2-D field.
@ OutputVisuType_Quadrophonic
Classic 4-channel quadrophonic 2-D field.
@ OutputVisuType_7point0
7.0 surround 2-D field.
@ MeteringColour_Pink
Pink metering bars.
@ MeteringColour_Blue
Blue metering bars.
@ MeteringColour_Green
Green metering bars (default).
@ OutputVisuType_5point1point2
5.1.2 with two height channels.
@ OutputVisuType_9point1point6
9.1.6 ATMOS full-3D layout.
@ MeteringColour_Red
Red metering bars.
@ MeteringColour_Laser
High-visibility laser-green metering bars.
@ OutputVisuType_7point1point4
7.1.4 Dolby Atmos layout.
@ OutputVisuType_5point1
5.1 surround 2-D field.
@ LookAndFeel_Light
Force light look-and-feel.
@ LookAndFeel_FollowHost
Match the host OS appearance.
@ LookAndFeel_Dark
Force dark look-and-feel.
@ 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 network status.
std::function< void(bool)> onSetFullscreenWindow
Called to request a fullscreen/windowed transition from the application shell.
~MainComponent() override
Central monitoring panel of the Mema.Mo application.