Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
AbstractAudioVisualizer.cpp
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
20
21#include <Image_utils.h>
22
23namespace Mema
24{
25
26
27//==============================================================================
29 : juce::Component()
30{
31 m_changesPending = false;
32
34}
35
39
41{
42 juce::Component::paint(g);
43}
44
49
50void AbstractAudioVisualizer::mouseDown(const juce::MouseEvent& event)
51{
52 juce::Component::mouseDown(event);
53}
54
56{
57 startTimerHz(frequency);
58}
59
64
66{
67 m_usesValuesInDB = useValuesInDB;
68}
69
71{
72 return m_usesValuesInDB;
73}
74
75//std::unique_ptr<XmlElement> AbstractAudioVisualizer::createStateXml()
76//{
77// XmlElement visualizerElement(String(AbstractAudioVisualizer::VisuTypeToString(getType())));
78//
79// auto mappingStateXml = std::make_unique<XmlElement>(AppConfiguration::getTagName(AppConfiguration::TagID::VISUMAP));
80// for (auto mapping : m_channelMapping)
81// {
82// XmlElement* mappingElement = mappingStateXml->createNewChildElement("M" + String(static_cast<int>(mapping.first)));
83// if (mappingElement)
84// {
85// mappingElement->setAttribute("name", AudioVisualizerConfigBase::getMappingString(mapping.first));
86// mappingElement->addTextElement(String(mapping.second));
87// }
88// }
89//
90// auto usesValuesInDBStateXml = std::make_unique<XmlElement>(AppConfiguration::getTagName(AppConfiguration::TagID::VISUUSEDB));
91// usesValuesInDBStateXml->addTextElement(m_usesValuesInDB ? "true" : "false");
92//
93// visualizerElement.addChildElement(usesValuesInDBStateXml.release());
94// visualizerElement.addChildElement(mappingStateXml.release());
95//
96// return std::make_unique<XmlElement>(visualizerElement);
97//}
98//
99//bool AbstractAudioVisualizer::setStateXml(XmlElement* stateXml)
100//{
101// if (!stateXml)
102// return false;
103//
104// if (stateXml->getTagName() != String(AbstractAudioVisualizer::VisuTypeToString(getType())))
105// return false;
106//
107// for (auto stateXmlElement : stateXml->getChildIterator())
108// {
109// if (stateXmlElement->getTagName() == AppConfiguration::getTagName(AppConfiguration::TagID::VISUMAP))
110// {
111// for (auto mappingElement : stateXmlElement->getChildIterator())
112// {
113// if (m_channelMapping.count(static_cast<AudioVisualizerConfigBase::MappingKey>(mappingElement->getTagName().getTrailingIntValue())) > 0)
114// m_channelMapping.at(static_cast<AudioVisualizerConfigBase::MappingKey>(mappingElement->getTagName().getTrailingIntValue())) = mappingElement->getAllSubText().getIntValue();
115// }
116// }
117// else if (stateXmlElement->getTagName() == AppConfiguration::getTagName(AppConfiguration::TagID::VISUUSEDB))
118// {
119// auto valueString = stateXmlElement->getAllSubText();
120// m_usesValuesInDB = (stateXmlElement->getAllSubText() == "true") ? true : false;
121// }
122// }
123//
124// processChangedChannelMapping();
125//
126// return true;
127//}
128
130{
131 m_changesPending = true;
132}
133
135{
136 if (m_changesPending)
137 {
138 m_changesPending = false;
139 repaint();
140 }
141}
142
143}
void paint(Graphics &) override
Paints the visualiser background.
virtual void processChanges()
Called on the message thread to update cached data before repainting.
void notifyChanges()
Marks that new data is available and triggers a repaint on the next timer tick.
void setRefreshFrequency(int frequency)
Sets the display refresh rate in Hz.
void setUsesValuesInDB(bool useValuesInDB)
void mouseDown(const MouseEvent &event) override
Handles mouse-down events (e.g. right-click context menu).
void timerCallback() override
Timer callback that calls processChanges() and triggers a repaint if data changed.
void resized() override
Lays out child components.
Definition Mema.cpp:27