Zrythm v2.0.0-DEV
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 (
88 plugins::PluginRegistry &plugin_registry,
89 DeviceGroupType type,
90 ProcessingTypeHint processing_type,
91 QObject * parent = nullptr);
92 Z_DISABLE_COPY_MOVE (PluginGroup)
93 ~PluginGroup () override;
94
95 // ============================================================================
96 // QML Interface
97 // ============================================================================
98
99 QString name () const { return name_; }
100 void setName (const QString &name);
101 Q_SIGNAL void nameChanged (const QString &name);
102
103 enum DeviceGroupListModelRoles
104 {
105 DeviceGroupPtrRole = Qt::UserRole + 1,
106 };
107 Q_ENUM (DeviceGroupListModelRoles)
108
109 QHash<int, QByteArray> roleNames () const override;
110 int rowCount (const QModelIndex &parent = QModelIndex ()) const override;
111 QVariant
112 data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
113 // ============================================================================
114
115 // Note: plugin add/remove API does not concern itself with automation tracks
116 // or graph rebuilding.
117 // When plugins are added or removed,
118 // automation tracks should be generated/moved accordingly and the DSP graph
119 // should be regenerated.
120
121 void insert_plugin (plugins::PluginUuidReference plugin_ref, int index = -1);
122 void append_plugin (plugins::PluginUuidReference plugin_ref)
123 {
124 insert_plugin (std::move (plugin_ref), -1);
125 }
126 plugins::PluginUuidReference
127 remove_plugin (const plugins::Plugin::Uuid &plugin_id);
128
129 QVariant element_at_idx (size_t idx) const;
130
136 void get_plugins (std::vector<plugins::PluginPtrVariant> &plugins) const;
137
138private:
139 static constexpr auto kDeviceGroupsKey = "deviceGroups"sv;
140 friend void to_json (nlohmann::json &j, const PluginGroup &l);
141 friend void from_json (const nlohmann::json &j, PluginGroup &l);
142
143private:
145 plugins::PluginRegistry &plugin_registry_;
146 const ProcessingTypeHint processing_type_;
147 const DeviceGroupType type_;
149 QString name_;
150
151 struct DeviceGroupImpl;
152 std::unique_ptr<DeviceGroupImpl> pimpl_;
153};
154}
@ 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.
void get_plugins(std::vector< plugins::PluginPtrVariant > &plugins) const
Returns all plugins in the group (scanning recursively).
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38