Umsci
Upmix Spatial Control Interface — OCA/OCP.1 spatial audio utility
Loading...
Searching...
No Matches
UmsciZeroconfDiscoverComboComponent.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
20
21
23{
24 m_comboBox = std::make_unique<juce::ComboBox>("ZeroconfServices");
25 m_comboBox->setTextWhenNothingSelected("Searching for OCA/OCP.1 devices...");
26 m_comboBox->setSelectedId(0, juce::dontSendNotification);
27 m_comboBox->setEnabled(false);
28 addAndMakeVisible(m_comboBox.get());
29
30 m_comboBox->onChange = [this]() {
31 auto idx = m_comboBox->getSelectedId() - 2; // id 1 = "searching" placeholder; services start at 2
32 if (idx >= 0 && idx < static_cast<int>(m_services.size()) && onServiceSelected)
33 onServiceSelected(m_services[static_cast<size_t>(idx)]);
34 };
35
36 m_searcher = std::make_unique<ZeroconfSearcher::ZeroconfSearcher>("OCA", "_oca._tcp");
37 m_searcher->AddListener(this);
38 m_searcher->StartSearching();
39}
40
42{
43 if (m_searcher)
44 m_searcher->StopSearching();
45}
46
48{
49 m_comboBox->setBounds(getLocalBounds());
50}
51
53{
54 if (auto* parent = getParentComponent())
55 setSize(juce::roundToInt(parent->getWidth() * 0.8f), getHeight());
56}
57
59{
60 juce::MessageManager::callAsync([this]() { updateComboBox(); });
61}
62
63void UmsciZeroconfDiscoverComboComponent::updateComboBox()
64{
65 if (!m_searcher)
66 return;
67
68 m_services = m_searcher->GetServices();
69
70 m_comboBox->clear(juce::dontSendNotification);
71
72 if (m_services.empty())
73 {
74 m_comboBox->setTextWhenNothingSelected("Searching for OCA/OCP.1 devices...");
75 m_comboBox->setSelectedId(0, juce::dontSendNotification);
76 m_comboBox->setEnabled(false);
77 return;
78 }
79
80 m_comboBox->setEnabled(true);
81 m_comboBox->setTextWhenNothingSelected(juce::String(m_services.size()) + " OCA/OCP.1 devices available...");
82 for (int i = 0; i < static_cast<int>(m_services.size()); ++i)
83 {
84 auto& s = m_services[static_cast<size_t>(i)];
85 auto displayName = juce::String(s.name).upToFirstOccurrenceOf("._oca._tcp", false, true);
86 auto label = displayName + " (" + juce::String(s.ip) + ":" + juce::String(s.port) + ")";
87 m_comboBox->addItem(label, i + 2);
88 }
89 m_comboBox->setSelectedId(0, juce::dontSendNotification);
90}
std::function< void(const ZeroconfSearcher::ZeroconfSearcher::ServiceInfo &)> onServiceSelected
Fired when the user selects a device from the combo box. The ServiceInfo contains the resolved hostna...
void parentSizeChanged() override
Resizes the component to 80 % of the parent's width whenever the parent (AlertWindow) is resized,...
void handleServicesChanged(std::string serviceName) override
ZeroconfSearcherListener callback — called when devices appear or disappear.