Umsci
Upmix Spatial Control Interface — OCA/OCP.1 spatial audio utility
Loading...
Searching...
No Matches
OscController.cpp
Go to the documentation of this file.
1/* Copyright (c) 2026, Christian Ahrens
2 *
3 * This file is part of Umsci <https://github.com/ChristianAhrens/Umsci>
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#include "OscController.h"
20
21
23{
26
27 m_oscReceiver.addListener(this);
28}
29
31{
32 m_oscReceiver.removeListener(this);
33 m_oscReceiver.disconnect();
34}
35
37{
38 if (m_port == port)
39 return;
40
41 m_oscReceiver.disconnect();
42 m_port = port;
43
44 if (port > 0)
45 m_oscReceiver.connect(port);
46}
47
49 const juce::String& address)
50{
51 m_addresses[static_cast<int>(param)] = address;
52}
53
55{
56 return m_addresses[static_cast<int>(param)];
57}
58
59void OscController::oscMessageReceived(const juce::OSCMessage& message)
60{
61 auto address = message.getAddressPattern().toString();
62 if (message.isEmpty() || !message[0].isFloat32())
63 return;
64
65 auto rawValue = message[0].getFloat32();
66
68 {
69 if (m_addresses[i] == address)
70 {
71 auto param = static_cast<UmsciExternalControlComponent::UpmixMidiParam>(i);
72 auto [minVal, maxVal] = UmsciExternalControlComponent::s_paramRanges[i];
73 auto domainValue = juce::jlimit(minVal, maxVal, rawValue);
74
76 onParamValueChanged(param, domainValue);
77 break;
78 }
79 }
80}
juce::String getAddress(UmsciExternalControlComponent::UpmixMidiParam param) const
std::function< void(UmsciExternalControlComponent::UpmixMidiParam, float)> onParamValueChanged
void openPort(int port)
~OscController() override
void setAddress(UmsciExternalControlComponent::UpmixMidiParam param, const juce::String &address)
static const juce::String s_oscDefaultAddresses[UpmixMidiParam_COUNT]
Default OSC address for each parameter, indexed by UpmixMidiParam.
static const std::array< std::pair< float, float >, UpmixMidiParam_COUNT > s_paramRanges
Natural parameter ranges for normalised MIDI→domain mapping. Indexed by UpmixMidiParam.
UpmixMidiParam
Identifies each controllable upmix transform parameter.