Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
clap_plugin_param.h
1// SPDX-FileCopyrightText: © 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3/*
4 * This file incorporates work covered by the following copyright and
5 * permission notice:
6 *
7 * ---
8 *
9 * SPDX-FileCopyrightText: Copyright (c) 2021 Alexandre BIQUE
10 * SPDX-License-Identifier: MIT
11 *
12 * Copyright (c) 2021 Alexandre BIQUE
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining a copy
15 * of this software and associated documentation files (the "Software"), to deal
16 * in the Software without restriction, including without limitation the rights
17 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 * copies of the Software, and to permit persons to whom the Software is
19 * furnished to do so, subject to the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be included in
22 * all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 *
32 * ---
33 *
34 */
35
36#pragma once
37
38#include <ostream>
39#include <unordered_map>
40
41#include <QObject>
42
43#include <clap/clap.h>
44
45namespace zrythm::plugins
46{
47class ClapHost;
48
49class ClapPluginParam : public QObject
50{
51 Q_OBJECT
52
53public:
54 ClapPluginParam (
55 const clap_param_info &info,
56 double value,
57 QObject * parent = nullptr);
58
59 double value () const { return _value; }
60 void setValue (double v);
61
62 double modulation () const { return _modulation; }
63 void setModulation (double v);
64
65 double modulatedValue () const
66 {
67 return std::min (
68 _info.max_value, std::max (_info.min_value, _value + _modulation));
69 }
70
71 bool isValueValid (const double v) const;
72
73 void printShortInfo (std::ostream &os) const;
74 void printInfo (std::ostream &os) const;
75
76 void setInfo (const clap_param_info &info) noexcept { _info = info; }
77 bool isInfoEqualTo (const clap_param_info &info) const;
78 bool isInfoCriticallyDifferentTo (const clap_param_info &info) const;
79 clap_param_info &info () noexcept { return _info; }
80 const clap_param_info &info () const noexcept { return _info; }
81
82 bool isBeingAdjusted () const noexcept { return _isBeingAdjusted; }
83 void setIsAdjusting (bool isAdjusting)
84 {
85 if (isAdjusting && !_isBeingAdjusted)
86 beginAdjust ();
87 else if (!isAdjusting && _isBeingAdjusted)
88 endAdjust ();
89 }
90 void beginAdjust ()
91 {
92 Q_ASSERT (!_isBeingAdjusted);
93 _isBeingAdjusted = true;
94 Q_EMIT isBeingAdjustedChanged ();
95 }
96 void endAdjust ()
97 {
98 Q_ASSERT (_isBeingAdjusted);
99 _isBeingAdjusted = false;
100 Q_EMIT isBeingAdjustedChanged ();
101 }
102
103Q_SIGNALS:
104 void isBeingAdjustedChanged ();
105 void infoChanged ();
106 void valueChanged ();
107 void modulatedValueChanged ();
108
109private:
110 bool _isBeingAdjusted = false;
111 clap_param_info _info;
112 double _value = 0;
113 double _modulation = 0;
114 std::unordered_map<int64_t, std::string> _enumEntries;
115};
116}