Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "vstcomponenthandler.h"
23 :
24 : using namespace muse::vst;
25 : using namespace muse::async;
26 :
27 0 : IMPLEMENT_FUNKNOWN_METHODS(VstAdvancedHandler, Steinberg::Vst::IComponentHandler2, Steinberg::Vst::IComponentHandler2::iid)
28 :
29 0 : IMPLEMENT_REFCOUNT(VstComponentHandler)
30 :
31 0 : ::Steinberg::tresult PLUGIN_API VstComponentHandler::queryInterface(const ::Steinberg::TUID _iid, void** obj)
32 : {
33 0 : QUERY_INTERFACE(_iid, obj, ::Steinberg::FUnknown::iid, IComponentHandler)
34 0 : QUERY_INTERFACE(_iid, obj, IComponentHandler::iid, IComponentHandler)
35 :
36 0 : if (::Steinberg::FUnknownPrivate::iidEqual(_iid, IAdvancedComponentHandler::iid)) {
37 0 : return m_advancedHandler->queryInterface(_iid, obj);
38 : }
39 0 : *obj = nullptr;
40 0 : return ::Steinberg::kNoInterface;
41 : }
42 :
43 0 : VstComponentHandler::VstComponentHandler()
44 0 : : m_advancedHandler(new VstAdvancedHandler(m_paramsChangedNotify))
45 : {
46 0 : }
47 :
48 0 : Channel<PluginParamId, PluginParamValue> VstComponentHandler::pluginParamChanged() const
49 : {
50 0 : return m_paramChanged;
51 : }
52 :
53 0 : Notification VstComponentHandler::pluginParamsChanged() const
54 : {
55 0 : return m_paramsChangedNotify;
56 : }
57 :
58 0 : void VstComponentHandler::setSuppressNotify(bool suppress)
59 : {
60 0 : m_advancedHandler->setSuppressNotify(suppress);
61 0 : }
62 :
63 0 : Steinberg::tresult VstComponentHandler::beginEdit(Steinberg::Vst::ParamID /*id*/)
64 : {
65 0 : return Steinberg::kResultOk;
66 : }
67 :
68 0 : Steinberg::tresult VstComponentHandler::performEdit(Steinberg::Vst::ParamID id, Steinberg::Vst::ParamValue valueNormalized)
69 : {
70 0 : if (!m_advancedHandler->suppressNotify()) {
71 0 : m_paramChanged.send(id, valueNormalized);
72 : }
73 :
74 0 : return Steinberg::kResultOk;
75 : }
76 :
77 0 : Steinberg::tresult VstComponentHandler::endEdit(Steinberg::Vst::ParamID /*id*/)
78 : {
79 0 : if (!m_advancedHandler->suppressNotify()) {
80 0 : m_paramsChangedNotify.notify();
81 : }
82 :
83 0 : return Steinberg::kResultOk;
84 : }
85 :
86 0 : Steinberg::tresult VstComponentHandler::restartComponent(Steinberg::int32 /*flags*/)
87 : {
88 0 : return Steinberg::kResultOk;
89 : }
90 :
91 0 : VstAdvancedHandler::VstAdvancedHandler(async::Notification notifier)
92 0 : : m_paramsChanged(notifier)
93 : {
94 0 : }
95 :
96 0 : void VstAdvancedHandler::setSuppressNotify(bool suppress)
97 : {
98 0 : m_suppressNotify.store(suppress, std::memory_order_relaxed);
99 0 : }
100 :
101 0 : bool VstAdvancedHandler::suppressNotify() const
102 : {
103 0 : return m_suppressNotify.load(std::memory_order_relaxed);
104 : }
105 :
106 0 : Steinberg::tresult VstAdvancedHandler::setDirty(Steinberg::TBool /*state*/)
107 : {
108 0 : if (!suppressNotify()) {
109 0 : m_paramsChanged.notify();
110 : }
111 :
112 0 : return Steinberg::kResultOk;
113 : }
114 :
115 0 : Steinberg::tresult VstAdvancedHandler::requestOpenEditor(Steinberg::FIDString /*name*/)
116 : {
117 0 : return Steinberg::kResultOk;
118 : }
119 :
120 0 : Steinberg::tresult VstAdvancedHandler::startGroupEdit()
121 : {
122 0 : return Steinberg::kResultOk;
123 : }
124 :
125 0 : Steinberg::tresult VstAdvancedHandler::finishGroupEdit()
126 : {
127 0 : if (!suppressNotify()) {
128 0 : m_paramsChanged.notify();
129 : }
130 :
131 0 : return Steinberg::kResultOk;
132 : }
|