Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
MemaUIComponent.h
Go to the documentation of this file.
1/* Copyright (c) 2024, 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 <CustomLookAndFeel.h>
26#include <ServiceTopologyManager.h>
27
28class LoadBar;
29class NetworkHealthBar;
30class EmptySpace;
31class AboutComponent;
32
33namespace Mema
34{
35
62class MemaUIComponent : public juce::Component,
63 public juce::DarkModeSettingListener,
64 public JUCEAppBasics::AppConfigurationBase::XmlConfigurableElement
65{
66public:
90
91public:
94 ~MemaUIComponent() override;
95
105 bool isStandaloneWindow();
106
113 void setEditorComponent(juce::Component* editorComponent);
114
122 void handleEditorSizeChangeRequest(const juce::Rectangle<int>& requestedSize);
123
138 void updateNetworkUsage(const std::map<int, std::pair<double, bool>>& netLoads);
145 void updateSessionServiceTopology(const JUCEAppBasics::SessionServiceTopology& serviceDiscoveryTopologyString);
146
147 //==============================================================================
153 void darkModeSettingChanged() override;
154
155 //========================================================================*
157 void paint(Graphics&) override;
163 void resized() override;
164
165 //========================================================================*
167 void lookAndFeelChanged() override;
168
169 //==========================================================================
174 std::unique_ptr<juce::XmlElement> createStateXml() override;
180 bool setStateXml(juce::XmlElement* stateXml) override;
181
182 //========================================================================*
183 std::function<void(bool)> onToggleStandaloneWindow;
184 std::function<void()> onAudioSetupMenuClicked;
185 std::function<void()> onLookAndFeelChanged;
186 std::function<void()> onDeleted;
187 std::function<void()> onSettingsChanged;
188 std::function<void(const JUCEAppBasics::CustomLookAndFeel::PaletteStyle&)> onPaletteStyleChange;
189 std::function<void()> onLoadConfig;
190 std::function<void()> onSaveConfig;
191
192private:
193 //========================================================================*
195 void handleSettingsMenuResult(int selectedId);
197 void handleSettingsLookAndFeelMenuResult(int selectedId);
199 void handleSettingsMeteringColourMenuResult(int selectedId);
200
201 //========================================================================*
203 void setMeteringColour(const juce::Colour& meteringColour);
205 void applyMeteringColour();
206
208 void applyPaletteStyle(const JUCEAppBasics::CustomLookAndFeel::PaletteStyle& paletteStyle);
209
210 //========================================================================*
211 std::unique_ptr<juce::DrawableButton> m_toggleStandaloneWindowButton;
212 std::unique_ptr<juce::DrawableButton> m_appSettingsButton;
213 std::unique_ptr<juce::DrawableButton> m_audioSetupButton;
214 std::unique_ptr<juce::DrawableButton> m_aboutButton;
215 std::unique_ptr<juce::DrawableButton> m_powerButton;
216 std::unique_ptr<EmptySpace> m_emptySpace;
217 std::unique_ptr<LoadBar> m_sysLoadBar;
218 std::unique_ptr<LoadBar> m_netHealthBar;
219
220 juce::Component* m_editorComponent = nullptr;
221
222 std::unique_ptr<AboutComponent> m_aboutComponent;
223
224 std::map<int, std::pair<std::string, int>> m_settingsItems;
225
226 bool m_followLocalStyle = true;
227
228 bool m_isStandaloneWindow = false;
229
230 juce::Colour m_meteringColour = juce::Colours::forestgreen;
231
232 static constexpr int sc_buttonSize = 26;
233 static constexpr int sc_loadNetWidth = 70;
234
236};
237
238};
Main UI shell for the Mema application — composes the processor editor, toolbar, load bars,...
std::function< void()> onDeleted
Called when this component is destroyed.
std::function< void(const JUCEAppBasics::CustomLookAndFeel::PaletteStyle &)> onPaletteStyleChange
Called when palette style changes.
std::function< void()> onSettingsChanged
Called when any setting changes.
std::function< void()> onLoadConfig
Called when the user selects Load Config.
std::function< void(bool)> onToggleStandaloneWindow
Called when the user toggles standalone/popup mode.
MemaSettingsOption
Identifiers for all user-configurable settings exposed via the settings popup menu.
@ SaveConfig
Save configuration to file.
@ MeteringColour_Blue
Blue metering bars.
@ MeteringColour_Pink
Pink metering bars.
@ LookAndFeel_Dark
Force dark look-and-feel.
@ LookAndFeel_Automatic
Match the host OS appearance.
@ LoadConfig
Load configuration from file.
@ MeteringColour_Red
Red metering bars.
@ MeteringColour_Green
Green metering bars (default).
@ LookAndFeel_Light
Force light look-and-feel.
@ MeteringColour_Laser
High-visibility laser-green metering bars.
void setStandaloneWindow(bool standalone)
Switches between popup mode (embedded in the system tray/menubar popover) and standalone window mode.
void updateSessionServiceTopology(const JUCEAppBasics::SessionServiceTopology &serviceDiscoveryTopologyString)
Updates the service-topology display (if any) with freshly discovered Mema instances.
void paint(Graphics &) override
Paints the component background using the current look-and-feel background colour.
void setEditorComponent(juce::Component *editorComponent)
Attaches the MemaProcessorEditor to be displayed in the central content area.
std::function< void()> onLookAndFeelChanged
Called after a look-and-feel change is applied.
std::function< void()> onAudioSetupMenuClicked
Called when the audio-setup button is clicked.
bool setStateXml(juce::XmlElement *stateXml) override
Restores UI state from a <UICONFIG> XmlElement.
void updateCpuUsageBar(int loadPercent)
Updates the CPU-load progress bar to reflect the current audio processing load.
std::unique_ptr< juce::XmlElement > createStateXml() override
Serialises the UI state (standalone mode, palette style, metering colour) to XML.
bool isStandaloneWindow()
Returns true when the component is currently shown in standalone window mode.
void resized() override
Lays out all child components.
std::function< void()> onSaveConfig
Called when the user selects Save Config.
void darkModeSettingChanged() override
Responds to an OS dark-mode toggle.
void updateNetworkUsage(const std::map< int, std::pair< double, bool > > &netLoads)
Updates the network-health bar with per-connection traffic metrics.
void handleEditorSizeChangeRequest(const juce::Rectangle< int > &requestedSize)
Responds to a resize request from the embedded editor.
MemaUIComponent()
Constructs the UI component and wires up child components.
void lookAndFeelChanged() override
Propagates a look-and-feel change to all child buttons and bars.
Definition Mema.cpp:27