Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
CrosspointsControlComponent.cpp
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
20
21
22namespace Mema
23{
24
25//==============================================================================
28{
29 m_matrixGrid.rowGap.pixels = s_nodeGap;
30 m_matrixGrid.columnGap.pixels = s_nodeGap;
31}
32
36
38{
39 m_matrixGrid.performLayout(getLocalBounds());
40}
41
43{
44 // (Our component is opaque, so we must completely fill the background with a solid colour)
45 g.fillAll(getLookAndFeel().findColour(ResizableWindow::backgroundColourId));
46}
47
48void CrosspointsControlComponent::setCrosspointEnabledValue(std::uint16_t input, std::uint16_t output, bool enabledState, int /*userId*/)
49{
50 m_crosspointEnabledValues[input][output] = enabledState;
51 if (1 == m_crosspointComponent.count(input) && 1 == m_crosspointComponent.at(input).count(output) && m_crosspointComponent.at(input).at(output))
52 m_crosspointComponent.at(input).at(output)->setChecked(enabledState);
53
54 repaint();
55}
56
57void CrosspointsControlComponent::setCrosspointFactorValue(std::uint16_t input, std::uint16_t output, float factor, int /*userId*/)
58{
59 m_crosspointFactorValues[input][output] = factor;
60 if (1 == m_crosspointComponent.count(input) && 1 == m_crosspointComponent.at(input).count(output) && m_crosspointComponent.at(input).at(output))
61 m_crosspointComponent.at(input).at(output)->setFactor(factor);
62
63 repaint();
64}
65
66void CrosspointsControlComponent::setIOCount(std::uint16_t inputCount, std::uint16_t outputCount)
67{
68 auto newIOCount = std::make_pair(int(inputCount), int(outputCount));
69 if (m_ioCount != newIOCount)
70 {
71 m_ioCount = newIOCount;
72 DBG(__FUNCTION__ << " " << newIOCount.first << " " << newIOCount.second);
73
74 std::function<void(std::uint16_t, std::uint16_t)> initCrosspoint = [=](std::uint16_t input, std::uint16_t output) {
75 DBG(__FUNCTION__ << " " << int(input) << " " << int(output));
76 m_crosspointEnabledValues[input][output] = false;
77 m_crosspointFactorValues[input][output] = 1.0f;
78 m_crosspointComponent[input][output] = std::make_unique<CrosspointComponent>(std::make_pair(input, output));
79 m_crosspointComponent[input][output]->onCheckedChanged = [=](bool checkedState, CrosspointComponent* sender) {
80 if (nullptr != sender && CrosspointComponent::CrosspointIdent(-1, -1) != sender->getIdent())
81 crosspointEnabledChange(std::uint16_t(sender->getIdent().first), std::uint16_t(sender->getIdent().second), checkedState, this);
82 };
83 m_crosspointComponent[input][output]->onFactorChanged = [=](float factor, CrosspointComponent* sender) {
84 if (nullptr != sender && CrosspointComponent::CrosspointIdent(-1, -1) != sender->getIdent())
85 crosspointFactorChange(std::uint16_t(sender->getIdent().first), std::uint16_t(sender->getIdent().second), factor, this);
86 };
87 addAndMakeVisible(m_crosspointComponent[input][output].get());
88
89 for (int j = m_matrixGrid.templateColumns.size(); j < input; j++)
90 m_matrixGrid.templateColumns.add(juce::Grid::TrackInfo(juce::Grid::Px(s_nodeSize)));
91
92 for (int j = m_matrixGrid.templateRows.size(); j < output; j++)
93 m_matrixGrid.templateRows.add(juce::Grid::TrackInfo(juce::Grid::Px(s_nodeSize)));
94 };
95
96 m_matrixGrid.items.clear();
97 m_matrixGrid.templateColumns.clear();
98 m_matrixGrid.templateRows.clear();
99 m_crosspointComponent.clear();
100
101 for (std::uint16_t i = 1; i <= inputCount; i++)
102 {
103 if (1 != m_crosspointComponent.count(i))
104 {
105 for (std::uint16_t o = 1; o <= outputCount; o++)
106 initCrosspoint(i, o);
107 }
108 else
109 {
110 if (1 != m_crosspointComponent.at(i).count(outputCount))
111 {
112 for (std::uint16_t o = 1; o <= outputCount; o++)
113 {
114 if (1 != m_crosspointComponent.at(i).count(o))
115 initCrosspoint(i, o);
116 }
117 }
118 }
119 }
120
121 for (std::uint16_t o = 1; o <= outputCount; o++)
122 {
123 for (std::uint16_t i = 1; i <= inputCount; i++)
124 {
125 if (m_crosspointComponent.at(i).at(o))
126 m_matrixGrid.items.add(juce::GridItem(m_crosspointComponent.at(i).at(o).get()));
127 else
128 jassertfalse;
129 }
130 }
131
134
135 resized();
136 }
137}
138
140{
141 if (m_crosspointComponent.size() > 0 && m_crosspointComponent.count(1) != 0 && m_crosspointComponent.at(1).size() > 0)
142 return { int(m_crosspointComponent.size() * (s_nodeGap + s_nodeSize)), int(m_crosspointComponent.at(1).size() * (s_nodeGap + s_nodeSize)) };
143 else
144 return {};
145}
146
147}
void setCrosspointEnabledValue(std::uint16_t input, std::uint16_t output, bool enabledState, int userId=-1) override
void setCrosspointFactorValue(std::uint16_t input, std::uint16_t output, float factor, int userId=-1) override
void setIOCount(std::uint16_t inputCount, std::uint16_t outputCount) override
void crosspointEnabledChange(std::uint16_t input, std::uint16_t output, bool enabledState, MemaCrosspointCommander *sender)
void crosspointFactorChange(std::uint16_t input, std::uint16_t output, float factor, MemaCrosspointCommander *sender)
Definition Mema.cpp:27