Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
InputPositionMapper.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
24namespace Mema
25{
26
27
30{
31public:
32 //==============================================================================
34 virtual ~InputPositionMapper() = default;
35
36 void setOutputIncludePositions(const juce::Array<juce::AudioChannelSet::ChannelType>& outputIncludePositions)
37 {
38 if (m_outputIncludePositions != outputIncludePositions)
39 m_outputIncludePositions = outputIncludePositions;
40 };
41 void setOutputIgnorePositions(const juce::Array<juce::AudioChannelSet::ChannelType>& outputIgnorePositions)
42 {
43 if (m_outputIgnorePositions != outputIgnorePositions)
44 m_outputIgnorePositions = outputIgnorePositions;
45 };
46
47 void mapInputPosition(std::uint16_t channel, const juce::Point<float>& inputPosition, float sharpness)
48 {
50 if (onInputPositionMapped && getAngleForChannelType) // no need to do any processing if the mandatory access hooks are not set
51 {
52 std::map<juce::AudioChannelSet::ChannelType, juce::Point<float>> outputsMaxPoints;
53 std::map<juce::AudioChannelSet::ChannelType, float> channelToOutputsDists;
54
55 for (auto const& channelType : m_outputIncludePositions)
56 {
57 auto angleRad = juce::degreesToRadians(getAngleForChannelType(channelType));
58 auto xLength = sinf(angleRad);
59 auto yLength = cosf(angleRad);
60 outputsMaxPoints[channelType] = juce::Point<float>(xLength, -yLength);
61
62 // this is the actual primitive sourceposition-to-output level calculation algorithm
63 auto outputMaxPoint = outputsMaxPoints[channelType];
64 auto distance = outputMaxPoint.getDistanceFrom(inputPosition);
65 auto base = 0.5f * distance;
66 auto exp = jmap(sharpness, 1.0f, 5.0f);
67 channelToOutputsDists[channelType] = powf(base, exp);
68
69 //DBG(juce::String(__FUNCTION__) << " incl. " << juce::AudioChannelSet::getAbbreviatedChannelTypeName(channelType) << ": " << channelToOutputsDists[channelType]);
70 }
71 for (auto const& channelType : m_outputIgnorePositions)
72 {
73 channelToOutputsDists[channelType] = 0.0f;
74
75 //DBG(juce::String(__FUNCTION__) << " excl. " << juce::AudioChannelSet::getAbbreviatedChannelTypeName(channelType) << ": " << channelToOutputsDists[channelType]);
76 }
77
78 onInputPositionMapped(channel, channelToOutputsDists);
79 }
80 }
81
82 std::function<void(std::uint16_t, const std::map<juce::AudioChannelSet::ChannelType, float>&)> onInputPositionMapped;
83 std::function<float(const juce::AudioChannelSet::ChannelType&)> getAngleForChannelType;
84
85protected:
86 //==============================================================================
87
88private:
89 //==============================================================================
90
91 //==============================================================================
92 juce::Array<juce::AudioChannelSet::ChannelType> m_outputIncludePositions;
93 juce::Array<juce::AudioChannelSet::ChannelType> m_outputIgnorePositions;
94};
95
96
97};
void mapInputPosition(std::uint16_t channel, const juce::Point< float > &inputPosition, float sharpness)
void setOutputIgnorePositions(const juce::Array< juce::AudioChannelSet::ChannelType > &outputIgnorePositions)
std::function< void(std::uint16_t, const std::map< juce::AudioChannelSet::ChannelType, float > &)> onInputPositionMapped
void setOutputIncludePositions(const juce::Array< juce::AudioChannelSet::ChannelType > &outputIncludePositions)
std::function< float(const juce::AudioChannelSet::ChannelType &)> getAngleForChannelType
virtual ~InputPositionMapper()=default
Definition Mema.cpp:27