1 /*
2  * Copyright (C) 2018-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  * Port schema.
24  */
25 
26 #ifndef __SCHEMAS_AUDIO_PORTS_H__
27 #define __SCHEMAS_AUDIO_PORTS_H__
28 
29 #include "zrythm-config.h"
30 
31 typedef enum PortInternalType_v1
32 {
33   INTERNAL_NONE_v1,
34   INTERNAL_LV2_PORT_v1,
35   INTERNAL_JACK_PORT_v1,
36   INTERNAL_PA_PORT_v1,
37   INTERNAL_ALSA_SEQ_PORT_v1,
38 } PortInternalType_v1;
39 
40 static const cyaml_strval_t
41 port_internal_type_strings_v1[] =
42 {
43   { "LV2 port",       INTERNAL_LV2_PORT_v1    },
44   { "JACK port",      INTERNAL_JACK_PORT_v1   },
45 };
46 
47 typedef struct Port_v1
48 {
49   int                 schema_version;
50   PortIdentifier_v1      id;
51   int                 exposed_to_backend;
52   float *             buf;
53   void *        midi_events;
54   struct Port_v1 **      srcs;
55   struct Port_v1 **      dests;
56   PortIdentifier_v1 *    src_ids;
57   PortIdentifier_v1 *    dest_ids;
58   float *             multipliers;
59   float *             src_multipliers;
60   int *               dest_locked;
61   int *               src_locked;
62   int *               dest_enabled;
63   int *               src_enabled;
64   int                 num_srcs;
65   int                 num_dests;
66   size_t              srcs_size;
67   size_t              dests_size;
68   PortInternalType_v1    internal_type;
69   float               minf;
70   float               maxf;
71   float               zerof;
72   float               deff;
73   int                vst_param_id;
74   int                carla_param_id;
75   void *              data;
76   void *  mme_connections[40];
77   int                 num_mme_connections;
78   ZixSem              mme_connections_sem;
79   gint64              last_midi_dequeue;
80   void *      rtmidi_ins[128];
81   int                 num_rtmidi_ins;
82   void *      rtmidi_outs[128];
83   int                 num_rtmidi_outs;
84   void *    rtaudio_ins[128];
85   int                num_rtaudio_ins;
86   void *   scale_points;
87   int                num_scale_points;
88   float               control;
89   float               unsnapped_control;
90   bool                value_changed_from_reading;
91   gint64              last_change;
92   void *            tmp_plugin;
93   void *   sample_processor;
94   int                 initialized;
95   float               base_value;
96   long                capture_latency;
97   long                playback_latency;
98   int                 deleting;
99   bool                write_ring_buffers;
100   volatile int        has_midi_events;
101   gint64              last_midi_event_time;
102   ZixRing *           audio_ring;
103   ZixRing *           midi_ring;
104   float               peak;
105   gint64              peak_timestamp;
106   midi_byte_t         last_midi_status;
107   const void * lilv_port;
108   LV2_URID        value_type;
109   void *      evbuf;
110   void * widget;
111   size_t          min_buf_size;
112   int             lilv_port_index;
113   bool            received_ui_event;
114   float           last_sent_control;
115   bool            automating;
116   bool            old_api;
117   void *   at;
118   void *           ext_port;
119   bool                is_project;
120   int                 magic;
121 } Port_v1;
122 
123 static const cyaml_schema_field_t
124 port_fields_schema__v1[] =
125 {
126   YAML_FIELD_INT (
127     Port_v1, schema_version),
128   YAML_FIELD_MAPPING_EMBEDDED (
129     Port_v1, id,
130     port_identifier_fields_schema_v1),
131   YAML_FIELD_INT (
132     Port_v1, exposed_to_backend),
133   CYAML_FIELD_SEQUENCE_COUNT (
134     "dest_ids",
135     CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL,
136     Port_v1, dest_ids, num_dests,
137     &port_identifier_schema_default_v1,
138     0, CYAML_UNLIMITED),
139   CYAML_FIELD_SEQUENCE_COUNT (
140     "src_ids",
141     CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL,
142     Port_v1, src_ids, num_srcs,
143     &port_identifier_schema_default_v1,
144     0, CYAML_UNLIMITED),
145   CYAML_FIELD_SEQUENCE_COUNT (
146     "multipliers",
147     CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL,
148     Port_v1, multipliers, num_dests,
149     &float_schema, 0, CYAML_UNLIMITED),
150   CYAML_FIELD_SEQUENCE_COUNT (
151     "src_multipliers",
152     CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL,
153     Port_v1, src_multipliers, num_srcs,
154     &float_schema, 0, CYAML_UNLIMITED),
155   CYAML_FIELD_SEQUENCE_COUNT (
156     "dest_locked",
157     CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL,
158     Port_v1, dest_locked, num_dests,
159     &int_schema, 0, CYAML_UNLIMITED),
160   CYAML_FIELD_SEQUENCE_COUNT (
161     "src_locked",
162     CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL,
163     Port_v1, src_locked, num_srcs,
164     &int_schema, 0, CYAML_UNLIMITED),
165   CYAML_FIELD_SEQUENCE_COUNT (
166     "dest_enabled",
167     CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL,
168     Port_v1, dest_enabled, num_dests,
169     &int_schema, 0, CYAML_UNLIMITED),
170   CYAML_FIELD_SEQUENCE_COUNT (
171     "src_enabled",
172     CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL,
173     Port_v1, src_enabled, num_srcs,
174     &int_schema, 0, CYAML_UNLIMITED),
175   CYAML_FIELD_ENUM (
176     "internal_type", CYAML_FLAG_DEFAULT,
177     Port_v1, internal_type, port_internal_type_strings_v1,
178     CYAML_ARRAY_LEN (port_internal_type_strings_v1)),
179   YAML_FIELD_FLOAT (
180     Port_v1, control),
181   YAML_FIELD_FLOAT (
182     Port_v1, minf),
183   YAML_FIELD_FLOAT (
184     Port_v1, maxf),
185   YAML_FIELD_FLOAT (
186     Port_v1, zerof),
187   YAML_FIELD_FLOAT (
188     Port_v1, deff),
189   YAML_FIELD_INT (
190     Port_v1, vst_param_id),
191   YAML_FIELD_INT (
192     Port_v1, carla_param_id),
193 
194   CYAML_FIELD_END
195 };
196 
197 static const cyaml_schema_value_t
198 port_schema_v1 =
199 {
200   YAML_VALUE_PTR_NULLABLE (
201     Port_v1, port_fields_schema_v1),
202 };
203 
204 /**
205  * L & R port, for convenience.
206  *
207  * Must ONLY be created via stereo_ports_new()
208  */
209 typedef struct StereoPorts_v1
210 {
211   int             schema_version;
212   Port_v1       * l;
213   Port_v1       * r;
214 } StereoPorts_v1;
215 
216 static const cyaml_schema_field_t
217   stereo_ports_fields_schema_v1[] =
218 {
219   YAML_FIELD_INT (
220     StereoPorts_v1, schema_version),
221   YAML_FIELD_MAPPING_PTR (
222     StereoPorts_v1, l,
223     port_fields_schema_v1),
224   YAML_FIELD_MAPPING_PTR (
225     StereoPorts_v1, r,
226     port_fields_schema_v1),
227 
228   CYAML_FIELD_END
229 };
230 
231 static const cyaml_schema_value_t
232   stereo_ports_schema_v1 = {
233   YAML_VALUE_PTR (
234     StereoPorts_v1, stereo_ports_fields_schema_v1),
235 };
236 
237 #endif
238