Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
TwoDFieldMultisliderComponent.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
23#include <TwoDFieldBase.h>
24#include "../MemaProcessorEditor/AbstractAudioVisualizer.h"
25
29namespace JUCEAppBasics
30{
31 class FixedFontTextEditor;
32}
33
34namespace Mema
35{
36
37
39class TwoDFieldMultisliderComponent : public JUCEAppBasics::TwoDFieldBase, public juce::Component
40{
41public:
43 {
45 TwoDMultisliderValue(float rX, float rY) { relXPos = rX; relYPos = rY; };
46
47 float relXPos = 0.0f;
48 float relYPos = 0.0f;
49 };
50
53 {
55 TwoDMultisliderSourcePosition(ChannelLayer l, TwoDMultisliderValue v, float s, bool iS, bool iO) { layer = l; value = v; sharpness = s; isSliding = iS; isOn = iO; };
56
57 ChannelLayer layer = ChannelLayer::Positioned;
58 TwoDMultisliderValue value = { 0.0f, 0.0f };
59 float sharpness = 0.4f;
60 bool isSliding = false;
61 bool isOn = true;
62 };
63
64public:
67
68 bool setChannelConfiguration(const juce::AudioChannelSet& channelLayout) override;
69
70 void setIOCount(const std::pair<int, int>& ioCount);
71
72 void setControlsSize(int ctrlsSize);
73
74 //==============================================================================
75 void paint (Graphics&) override;
76 void resized() override;
77 void lookAndFeelChanged() override;
78 std::unique_ptr<juce::ComponentTraverser> createKeyboardFocusTraverser() override;
79
80 //==============================================================================
81 void mouseDown(const juce::MouseEvent& e) override;
82 void mouseUp(const MouseEvent& e) override;
83 void mouseDrag(const MouseEvent& e) override;
84
85 //==============================================================================
86 void setInputToOutputStates(const std::map<std::uint16_t, std::map<std::uint16_t, bool>>& inputToOutputStates);
87 void setInputToOutputLevels(const std::map<std::uint16_t, std::map<std::uint16_t, float>>& inputToOutputLevels);
88
89 //==============================================================================
90 void setInputPosition(std::uint16_t channel, const TwoDMultisliderValue& value, const float& panningSharpness, const ChannelLayer& layer, juce::NotificationType notification = juce::dontSendNotification);
91 void setInputPositionValue(std::uint16_t channel, const TwoDMultisliderValue& value, juce::NotificationType notification = juce::dontSendNotification);
92 void setInputPositionSharpness(std::uint16_t channel, const float& sharpness, juce::NotificationType notification = juce::dontSendNotification);
93 void setInputPositionLayer(std::uint16_t channel, const ChannelLayer& layer, juce::NotificationType notification = juce::dontSendNotification);
94 void selectInput(std::uint16_t channel, bool selectOn, juce::NotificationType notification = juce::dontSendNotification);
95
97
98 //==============================================================================
99 std::function<void(std::uint16_t channel, const TwoDMultisliderValue& value, const float& sharpness, std::optional<ChannelLayer> layer)> onInputPositionChanged;
100 std::function<void(std::uint16_t channel)> onInputSelected;
101 std::function<void(const std::map<std::uint16_t, std::map<std::uint16_t, bool>>&)> onInputToOutputStatesChanged;
102 std::function<void(const std::map<std::uint16_t, std::map<std::uint16_t, float>>&)> onInputToOutputValuesChanged;
103
104private:
105 //==============================================================================
106 void paintCircularLevelIndication(juce::Graphics& g, const juce::Rectangle<float>& circleArea, const std::map<int, juce::Point<float>>& channelLevelMaxPoints, const juce::Array<juce::AudioChannelSet::ChannelType>& channelsToPaint);
107 void paintSliderKnob(juce::Graphics& g, const juce::Rectangle<float>& sliderArea, const float& relXPos, const float& relYPos, const int& silderNumber, bool isSliderOn, bool isSliderSliding);
108
109 //==============================================================================
110 void rebuildDirectionslessChannelSliders();
111 void configureDirectionlessSliderToRelativeCtrl(const juce::AudioChannelSet::ChannelType& channelType, JUCEAppBasics::ToggleStateSlider& slider);
112
113 //==============================================================================
114 std::map<juce::AudioChannelSet::ChannelType, std::unique_ptr<JUCEAppBasics::ToggleStateSlider>> m_directionslessChannelSliders;
115 std::map<juce::AudioChannelSet::ChannelType, std::unique_ptr<juce::Label>> m_directionslessChannelLabels;
116 std::map<juce::AudioChannelSet::ChannelType, double> m_directionlessSliderRelRef;
117
118 std::map<std::uint16_t, std::map<juce::AudioChannelSet::ChannelType, std::pair<bool, float>>> m_inputToOutputVals;
119
120 std::map<std::uint16_t, TwoDMultisliderSourcePosition> m_inputPositions;
121 std::vector<std::uint16_t> m_inputPositionStackingOrder;
122 std::uint16_t m_currentlySelectedInput = 0;
123
124 std::unique_ptr<juce::Label> m_sharpnessLabel;
125 std::unique_ptr<JUCEAppBasics::FixedFontTextEditor> m_sharpnessEdit;
126
127 int m_currentOutputCount = 0;
128
129 //==============================================================================
130 int m_thumbWidth = 0;
131 float m_trackWidth = 0.0f;
132 int m_ctrlsSize = 0;
133
134 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TwoDFieldMultisliderComponent)
135};
136
137}
std::function< void(std::uint16_t channel, const TwoDMultisliderValue &value, const float &sharpness, std::optional< ChannelLayer > layer)> onInputPositionChanged
void setInputPositionValue(std::uint16_t channel, const TwoDMultisliderValue &value, juce::NotificationType notification=juce::dontSendNotification)
void mouseDown(const juce::MouseEvent &e) override
void setInputPositionLayer(std::uint16_t channel, const ChannelLayer &layer, juce::NotificationType notification=juce::dontSendNotification)
void setInputPositionSharpness(std::uint16_t channel, const float &sharpness, juce::NotificationType notification=juce::dontSendNotification)
void setInputToOutputStates(const std::map< std::uint16_t, std::map< std::uint16_t, bool > > &inputToOutputStates)
void selectInput(std::uint16_t channel, bool selectOn, juce::NotificationType notification=juce::dontSendNotification)
std::function< void(std::uint16_t channel)> onInputSelected
void setInputPosition(std::uint16_t channel, const TwoDMultisliderValue &value, const float &panningSharpness, const ChannelLayer &layer, juce::NotificationType notification=juce::dontSendNotification)
std::function< void(const std::map< std::uint16_t, std::map< std::uint16_t, float > > &)> onInputToOutputValuesChanged
std::function< void(const std::map< std::uint16_t, std::map< std::uint16_t, bool > > &)> onInputToOutputStatesChanged
void setIOCount(const std::pair< int, int > &ioCount)
void setInputToOutputLevels(const std::map< std::uint16_t, std::map< std::uint16_t, float > > &inputToOutputLevels)
std::unique_ptr< juce::ComponentTraverser > createKeyboardFocusTraverser() override
bool setChannelConfiguration(const juce::AudioChannelSet &channelLayout) override
Definition Mema.cpp:27
Position data for a single source handle in the 2-D field.
ChannelLayer layer
Height layer index (0 = ground, 1 = elevated).
TwoDMultisliderSourcePosition(ChannelLayer l, TwoDMultisliderValue v, float s, bool iS, bool iO)