Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
plugin_slot.h
1// SPDX-FileCopyrightText: © 2020-2021, 2023-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "utils/format.h"
7#include "utils/serialization.h"
8#include "utils/uuid_identifiable_object.h"
9
10namespace zrythm::plugins
11{
12
13enum class PluginSlotType
14{
15 Invalid,
16 MidiFx,
17 Instrument,
18 Insert,
19
21 Modulator,
22};
23
24class PluginSlot
25{
26public:
27 using SlotNo = std::uint_fast8_t;
28
29 friend auto operator<=> (const PluginSlot &lhs, const PluginSlot &rhs)
30 {
31 if (lhs.type_ != rhs.type_)
32 return lhs.type_ <=> rhs.type_;
33
34 return lhs.slot_ <=> rhs.slot_;
35 }
36
37 // Needed for testing
38 friend bool operator== (const PluginSlot &lhs, const PluginSlot &rhs)
39 {
40 return (lhs <=> rhs) == 0;
41 }
42
43public:
44 PluginSlot () = default;
45
49 explicit PluginSlot (PluginSlotType type, SlotNo slot)
50 : type_ (type), slot_ (slot)
51 {
52 }
53
57 explicit PluginSlot (PluginSlotType type) : type_ (type) { }
58
59 bool has_slot_index () const { return slot_.has_value (); }
60
61 auto get_slot_with_index () const
62 {
63 if (!has_slot_index ())
64 {
65 throw std::invalid_argument ("Slot has no index");
66 }
67 return std::make_pair (type_, slot_.value ());
68 }
69 auto get_slot_type_only () const
70 {
71 if (slot_.has_value ())
72 {
73 throw std::invalid_argument ("Slot has index");
74 }
75 return type_;
76 }
77
78 PluginSlot get_slot_after_n (PluginSlot::SlotNo n) const
79 {
80 if (!slot_.has_value ())
81 {
82 throw std::invalid_argument ("Slot has no index");
83 }
84 return PluginSlot (type_, slot_.value () + n);
85 }
86
87 size_t get_hash () const;
88
89 bool is_modulator () const { return type_ == PluginSlotType::Modulator; }
90
95 {
96 if (type_ == PluginSlotType::Invalid)
97 return false;
98
99 return (type_ == PluginSlotType::Instrument && !slot_.has_value ())
100 || (type_ != PluginSlotType::Instrument && slot_.has_value ());
101 }
102
103 NLOHMANN_DEFINE_TYPE_INTRUSIVE (PluginSlot, type_, slot_)
104
105private:
106 PluginSlotType type_{ PluginSlotType::Invalid };
107 std::optional<SlotNo> slot_;
108};
109
110inline auto
111format_as (const zrythm::plugins::PluginSlot &slot)
112{
113 if (slot.has_slot_index ())
114 {
115 auto ret = slot.get_slot_with_index ();
116 return fmt::format ("{}::{}", ENUM_NAME (ret.first), ret.second);
117 }
118 return fmt::format ("{}", ENUM_NAME (slot.get_slot_type_only ()));
119}
120
121}; // namespace zrythm::dsp
PluginSlot(PluginSlotType type)
Construct a new Plugin Slot object for an instrument.
Definition plugin_slot.h:57
bool validate_slot_type_slot_combo() const
Verifies that slot_type and slot is a valid combination.
Definition plugin_slot.h:94
PluginSlot(PluginSlotType type, SlotNo slot)
Construct a new Plugin Slot object for a non-instrument.
Definition plugin_slot.h:49