Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
plugin_group.h
1// SPDX-FileCopyrightText: © 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <utility>
7
8#include "dsp/fader.h"
9#include "plugins/plugin_all.h"
10#include "utils/qt.h"
11
12#include <QAbstractListModel>
13#include <QtQmlIntegration/qqmlintegration.h>
14
15#include <nlohmann/json_fwd.hpp>
16
17namespace zrythm::plugins
18{
45class PluginGroup : public QAbstractListModel
46{
47 Q_OBJECT
48 Q_PROPERTY (QString name READ name WRITE setName NOTIFY nameChanged)
49 QML_ELEMENT
50 QML_UNCREATABLE ("")
51
52public:
53 enum class ProcessingTypeHint : std::uint8_t
54 {
62
69
74 };
75 Q_ENUM (ProcessingTypeHint)
76
77 enum class DeviceGroupType : std::uint8_t
78 {
79 Audio,
80 MIDI,
81 Instrument,
82 CV,
83 };
84 Q_ENUM (DeviceGroupType)
85
86 PluginGroup (
87 utils::IObjectRegistry &registry,
88 DeviceGroupType type,
89 ProcessingTypeHint processing_type,
90 QObject * parent = nullptr);
91 Q_DISABLE_COPY_MOVE (PluginGroup)
92 ~PluginGroup () override;
93
94 // ============================================================================
95 // QML Interface
96 // ============================================================================
97
98 QString name () const { return name_; }
99 void setName (const QString &name);
100 Q_SIGNAL void nameChanged (const QString &name);
101
102 enum DeviceGroupListModelRoles
103 {
104 DeviceGroupPtrRole = Qt::UserRole + 1,
105 };
106 Q_ENUM (DeviceGroupListModelRoles)
107
108 QHash<int, QByteArray> roleNames () const override;
109 int rowCount (const QModelIndex &parent = QModelIndex ()) const override;
110 QVariant
111 data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
112 // ============================================================================
113
114 // Note: plugin add/remove API does not concern itself with automation tracks
115 // or graph rebuilding.
116 // When plugins are added or removed,
117 // automation tracks should be generated/moved accordingly and the DSP graph
118 // should be regenerated.
119
120 void insert_plugin (plugins::PluginUuidReference plugin_ref, int index = -1);
121 void append_plugin (plugins::PluginUuidReference plugin_ref)
122 {
123 insert_plugin (std::move (plugin_ref), -1);
124 }
125 plugins::PluginUuidReference
126 remove_plugin (const plugins::Plugin::Uuid &plugin_id);
127
128 QVariant element_at_idx (size_t idx) const;
129
130 void get_plugins (
131 std::vector<plugins::PluginUuidReference> &plugins,
132 bool recursive = true) const;
133
134private:
135 static constexpr auto kDeviceGroupsKey = "deviceGroups"sv;
136 static constexpr auto kFaderKey = "fader"sv;
137 friend void to_json (nlohmann::json &j, const PluginGroup &l);
138 friend void from_json (const nlohmann::json &j, PluginGroup &l);
139
140private:
141 utils::IObjectRegistry &registry_;
142 const ProcessingTypeHint processing_type_;
143 const DeviceGroupType type_;
144 utils::QObjectUniquePtr<dsp::Fader> fader_;
145 QString name_;
146
147 struct DeviceGroupImpl;
148 std::unique_ptr<DeviceGroupImpl> pimpl_;
149};
150}
@ Serial
Process each element in sequence, connecting the output to the next element's input,...
@ Custom
Processing is completely up to the user of this class.
@ Parallel
Process all elements separately and sum their outputs to the fader.
Abstract interface for a UUID-keyed object registry.