1 /*
2 * Copyright (C) 2020-2021 Alexandros Theodotou <alex at zrythm dot org>
3 *
4 * This file is part of Zrythm
5 *
6 * Zrythm is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Zrythm is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 /**
21 * \file
22 *
23 * Plugin identifier.
24 */
25
26 #ifndef __PLUGINS_PLUGIN_IDENTIFIER_H__
27 #define __PLUGINS_PLUGIN_IDENTIFIER_H__
28
29 #include "zrythm-config.h"
30
31 #include <stdbool.h>
32
33 #include "utils/yaml.h"
34
35 /**
36 * @addtogroup plugins
37 *
38 * @{
39 */
40
41 #define PLUGIN_IDENTIFIER_SCHEMA_VERSION 1
42
43 typedef enum PluginSlotType
44 {
45 PLUGIN_SLOT_INVALID,
46 PLUGIN_SLOT_INSERT,
47 PLUGIN_SLOT_MIDI_FX,
48 PLUGIN_SLOT_INSTRUMENT,
49
50 /** Plugin is part of a modulator. */
51 PLUGIN_SLOT_MODULATOR,
52 } PluginSlotType;
53
54 static const cyaml_strval_t
55 plugin_slot_type_strings[] =
56 {
57 { "Invalid", PLUGIN_SLOT_INVALID },
58 { "Insert", PLUGIN_SLOT_INSERT },
59 { "MIDI FX", PLUGIN_SLOT_MIDI_FX },
60 { "Instrument", PLUGIN_SLOT_INSTRUMENT },
61 { "Modulator", PLUGIN_SLOT_MODULATOR },
62 };
63
64 static inline const char *
plugin_slot_type_to_string(PluginSlotType type)65 plugin_slot_type_to_string (
66 PluginSlotType type)
67 {
68 return plugin_slot_type_strings[type].str;
69 }
70
71 /**
72 * Plugin identifier.
73 */
74 typedef struct PluginIdentifier
75 {
76 int schema_version;
77
78 PluginSlotType slot_type;
79
80 /** Track name hash. */
81 unsigned int track_name_hash;
82
83 /**
84 * The slot this plugin is in in the channel, or
85 * the index if this is part of a modulator.
86 *
87 * If PluginIdentifier.slot_type is an instrument,
88 * this must be set to -1.
89 */
90 int slot;
91 } PluginIdentifier;
92
93 static const cyaml_schema_field_t
94 plugin_identifier_fields_schema[] =
95 {
96 YAML_FIELD_INT (
97 PluginIdentifier, schema_version),
98 YAML_FIELD_ENUM (
99 PluginIdentifier, slot_type,
100 plugin_slot_type_strings),
101 YAML_FIELD_UINT (
102 PluginIdentifier, track_name_hash),
103 YAML_FIELD_INT (
104 PluginIdentifier, slot),
105
106 CYAML_FIELD_END
107 };
108
109 static const cyaml_schema_value_t
110 plugin_identifier_schema = {
111 CYAML_VALUE_MAPPING (CYAML_FLAG_POINTER,
112 PluginIdentifier,
113 plugin_identifier_fields_schema),
114 };
115
116 void
117 plugin_identifier_init (
118 PluginIdentifier * self);
119
120 static inline int
plugin_identifier_is_equal(const PluginIdentifier * a,const PluginIdentifier * b)121 plugin_identifier_is_equal (
122 const PluginIdentifier * a,
123 const PluginIdentifier * b)
124 {
125 return
126 a->slot_type == b->slot_type &&
127 a->track_name_hash == b->track_name_hash &&
128 a->slot == b->slot;
129 }
130
131 void
132 plugin_identifier_copy (
133 PluginIdentifier * dest,
134 const PluginIdentifier * src);
135
136 NONNULL
137 bool
138 plugin_identifier_validate (
139 const PluginIdentifier * self);
140
141 /**
142 * Verifies that @ref slot_type and @ref slot is
143 * a valid combination.
144 */
145 bool
146 plugin_identifier_validate_slot_type_slot_combo (
147 PluginSlotType slot_type,
148 int slot);
149
150 static inline void
plugin_identifier_print(PluginIdentifier * self,char * str)151 plugin_identifier_print (
152 PluginIdentifier * self,
153 char * str)
154 {
155 sprintf (
156 str,
157 "slot_type: %d, track_name hash: %u, slot: %d",
158 self->slot_type, self->track_name_hash,
159 self->slot);
160 }
161
162 /**
163 * @}
164 */
165
166 #endif
167