Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
fader.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __AUDIO_FADER_H__
11#define __AUDIO_FADER_H__
12
13#include "dsp/port.h"
14#include "utils/types.h"
15#include "utils/yaml.h"
16
17typedef struct StereoPorts StereoPorts;
18typedef struct Port Port;
19typedef struct Channel Channel;
20typedef struct AudioEngine AudioEngine;
21typedef struct ControlRoom ControlRoom;
22typedef struct SampleProcessor SampleProcessor;
23typedef struct PortIdentifier PortIdentifier;
24
31#define FADER_SCHEMA_VERSION 2
32
33#define MONITOR_FADER (CONTROL_ROOM->monitor_fader)
34
35#define FADER_MAGIC 32548791
36#define IS_FADER(f) (f->magic == FADER_MAGIC)
37#define IS_FADER_AND_NONNULL(f) (f && f->magic == FADER_MAGIC)
38
40#define FADER_DEFAULT_FADE_FRAMES_SHORT 1024
41#define FADER_DEFAULT_FADE_FRAMES \
42 (ZRYTHM_TESTING ? FADER_DEFAULT_FADE_FRAMES_SHORT : 8192)
43
44#define FADER_FADE_FRAMES_FOR_TYPE(f) \
45 ((f)->type == FADER_TYPE_MONITOR \
46 ? FADER_DEFAULT_FADE_FRAMES \
47 : FADER_DEFAULT_FADE_FRAMES_SHORT)
48
49#define fader_is_in_active_project(self) \
50 ((self->track != NULL \
51 && track_is_in_active_project (self->track)) \
52 || \
53 (self->sample_processor != NULL \
54 && \
55 sample_processor_is_in_active_project ( \
56 self->sample_processor)) \
57 || \
58 (self->control_room != NULL \
59 && \
60 control_room_is_in_active_project ( \
61 self->control_room)))
62
66typedef enum FaderType
67{
68 FADER_TYPE_NONE,
69
72
75
78
79 /* MIDI fader for Channel's. */
80 FADER_TYPE_MIDI_CHANNEL,
81
84} FaderType;
85
86static const cyaml_strval_t fader_type_strings[] = {
87 {"none", FADER_TYPE_NONE },
88 { "monitor", FADER_TYPE_MONITOR },
89 { "sample processor", FADER_TYPE_SAMPLE_PROCESSOR},
90 { "audio channel", FADER_TYPE_AUDIO_CHANNEL },
91 { "midi channel", FADER_TYPE_MIDI_CHANNEL },
92 { "generic", FADER_TYPE_GENERIC },
93};
94
103
104static const cyaml_strval_t midi_fader_mode_strings[] = {
105 {"vel_multiplier", MIDI_FADER_MODE_VEL_MULTIPLIER},
106 { "cc_volume", MIDI_FADER_MODE_CC_VOLUME },
107};
108
117typedef struct Fader
118{
119 int schema_version;
120
124 float volume;
125
127 float phase;
128
131
140
146
150
156
159
162
165
168
173
178
183
188
195 float r_port_db;
196
197 FaderType type;
198
201
204
207
210
213
214 int magic;
215
216 bool is_project;
217
218 /* TODO Caches to be set when recalculating the
219 * graph. */
220 bool implied_soloed;
221 bool soloed;
222
225
230
237
240} Fader;
241
242static const cyaml_schema_field_t fader_fields_schema[] = {
243 YAML_FIELD_INT (Fader, schema_version),
244 YAML_FIELD_ENUM (Fader, type, fader_type_strings),
245 YAML_FIELD_FLOAT (Fader, volume),
246 YAML_FIELD_MAPPING_PTR (Fader, amp, port_fields_schema),
247 YAML_FIELD_FLOAT (Fader, phase),
248 YAML_FIELD_MAPPING_PTR (Fader, balance, port_fields_schema),
249 YAML_FIELD_MAPPING_PTR (Fader, mute, port_fields_schema),
250 YAML_FIELD_MAPPING_PTR (Fader, solo, port_fields_schema),
251 YAML_FIELD_MAPPING_PTR (Fader, listen, port_fields_schema),
252 YAML_FIELD_MAPPING_PTR (Fader, mono_compat_enabled, port_fields_schema),
253 YAML_FIELD_MAPPING_PTR (Fader, swap_phase, port_fields_schema),
254 YAML_FIELD_MAPPING_PTR_OPTIONAL (Fader, midi_in, port_fields_schema),
255 YAML_FIELD_MAPPING_PTR_OPTIONAL (Fader, midi_out, port_fields_schema),
256 YAML_FIELD_MAPPING_PTR_OPTIONAL (Fader, stereo_in, stereo_ports_fields_schema),
257 YAML_FIELD_MAPPING_PTR_OPTIONAL (Fader, stereo_out, stereo_ports_fields_schema),
258 YAML_FIELD_ENUM (Fader, midi_mode, midi_fader_mode_strings),
259 YAML_FIELD_INT (Fader, passthrough),
260
261 CYAML_FIELD_END
262};
263
264static const cyaml_schema_value_t fader_schema = {
265 YAML_VALUE_PTR (Fader, fader_fields_schema),
266};
267
271COLD NONNULL_ARGS (1) void fader_init_loaded (
272 Fader * self,
273 Track * track,
274 ControlRoom * control_room,
275 SampleProcessor * sample_processor);
276
285COLD Fader *
287 FaderType type,
288 bool passthrough,
289 Track * track,
290 ControlRoom * control_room,
291 SampleProcessor * sample_processor);
292
293Fader *
294fader_find_from_port_identifier (const PortIdentifier * id);
295
296Port *
297fader_create_swap_phase_port (Fader * self, bool passthrough);
298
303NONNULL void
304fader_append_ports (const Fader * self, GPtrArray * ports);
305
309void
310fader_set_amp (void * self, float amp);
311
318void
320 Fader * self,
321 float amp_from,
322 float amp_to,
323 bool skip_if_equal);
324
329void
330fader_add_amp (void * self, float amp);
331
332NONNULL void
333fader_set_midi_mode (
334 Fader * self,
335 MidiFaderMode mode,
336 bool with_action,
337 bool fire_events);
338
343void
344fader_set_muted (Fader * self, bool mute, bool fire_events);
345
349NONNULL PURE bool
350fader_get_muted (const Fader * const self);
351
355HOT NONNULL PURE bool
356fader_get_soloed (const Fader * const self);
357
364bool
366
370#define fader_get_listened(self) (control_port_is_toggled (self->listen))
371
376void
377fader_set_listened (Fader * self, bool listen, bool fire_events);
378
383void
384fader_set_soloed (Fader * self, bool solo, bool fire_events);
385
390NONNULL PURE float
391fader_get_amp (void * self);
392
396bool
398
402void
403fader_set_mono_compat_enabled (Fader * self, bool enabled, bool fire_events);
404
408bool
410
414void
415fader_set_swap_phase (Fader * self, bool enabled, bool fire_events);
416
417float
418fader_get_fader_val (void * self);
419
420float
421fader_get_default_fader_val (void * self);
422
423void
424fader_db_string_getter (void * obj, char * buf);
425
426Channel *
427fader_get_channel (Fader * self);
428
429NONNULL Track *
430fader_get_track (Fader * self);
431
432void
433fader_update_volume_and_fader_val (Fader * self);
434
438HOT NONNULL void
440
445void
446fader_set_fader_val (Fader * self, float fader_val);
447
451void
453
459void
461
465NONNULL HOT void
466fader_process (Fader * self, const EngineProcessTimeInfo * const time_nfo);
467
468#if 0
472void
473fader_update_track_pos (
474 Fader * self,
475 int pos);
476#endif
477
478Fader *
479fader_clone (const Fader * src);
480
484void
486
491#endif
Ports that transfer audio/midi/other signals to one another.
NONNULL_ARGS(1) int undo_manager_undo(UndoManager *self
Undo last action.
HOT NONNULL void fader_clear_buffers(Fader *self)
Clears all buffers.
COLD Fader * fader_new(FaderType type, bool passthrough, Track *track, ControlRoom *control_room, SampleProcessor *sample_processor)
Creates a new fader.
NONNULL PURE bool fader_get_muted(const Fader *const self)
Returns if the fader is muted.
FaderType
Fader type.
Definition fader.h:67
void fader_set_listened(Fader *self, bool listen, bool fire_events)
Sets fader listen and optionally adds the action to the undo stack.
void fader_free(Fader *self)
Frees the fader members.
bool fader_get_swap_phase(Fader *self)
Gets whether mono compatibility is enabled.
bool fader_get_mono_compat_enabled(Fader *self)
Gets whether mono compatibility is enabled.
void fader_set_soloed(Fader *self, bool solo, bool fire_events)
Sets track soloed and optionally adds the action to the undo stack.
void fader_set_muted(Fader *self, bool mute, bool fire_events)
Sets track muted and optionally adds the action to the undo stack.
void fader_copy_values(Fader *src, Fader *dest)
Copy the fader values from source to dest.
NONNULL HOT void fader_process(Fader *self, const EngineProcessTimeInfo *const time_nfo)
Process the Fader.
HOT NONNULL PURE bool fader_get_soloed(const Fader *const self)
Returns if the track is soloed.
void fader_set_mono_compat_enabled(Fader *self, bool enabled, bool fire_events)
Sets whether mono compatibility is enabled.
NONNULL void fader_append_ports(const Fader *self, GPtrArray *ports)
Appends the ports owned by fader to the given array.
void fader_add_amp(void *self, float amp)
Adds (or subtracts if negative) to the amplitude of the fader (clamped at 0.0 to 2....
NONNULL PURE float fader_get_amp(void *self)
Gets the fader amplitude (not db) FIXME is void * necessary? do it in the caller.
void fader_set_swap_phase(Fader *self, bool enabled, bool fire_events)
Sets whether mono compatibility is enabled.
MidiFaderMode
Definition fader.h:96
void fader_disconnect_all(Fader *self)
Disconnects all ports connected to the fader.
void fader_set_amp_with_action(Fader *self, float amp_from, float amp_to, bool skip_if_equal)
Sets the amp value with an undoable action.
bool fader_get_implied_soloed(Fader *self)
Returns whether the fader is not soloed on its own but its direct out (or its direct out's direct out...
void fader_set_fader_val(Fader *self, float fader_val)
Sets the fader levels from a normalized value 0.0-1.0 (such as in widgets).
void fader_set_amp(void *self, float amp)
Sets the amplitude of the fader.
@ FADER_TYPE_SAMPLE_PROCESSOR
Audio fader for the sample processor.
Definition fader.h:74
@ FADER_TYPE_GENERIC
For generic uses.
Definition fader.h:83
@ FADER_TYPE_AUDIO_CHANNEL
Audio fader for Channel's.
Definition fader.h:77
@ FADER_TYPE_MONITOR
Audio fader for the monitor.
Definition fader.h:71
@ MIDI_FADER_MODE_VEL_MULTIPLIER
Multiply velocity of all MIDI note ons.
Definition fader.h:98
@ MIDI_FADER_MODE_CC_VOLUME
Send CC volume event on change TODO.
Definition fader.h:101
#define YAML_FIELD_MAPPING_PTR(owner, member, schema)
Mapping pointer to a struct.
Definition yaml.h:37
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
Definition yaml.h:202
#define YAML_FIELD_MAPPING_PTR_OPTIONAL(owner, member, schema)
Mapping pointer to a struct.
Definition yaml.h:43
The audio engine.
Definition engine.h:364
A Channel is part of a Track (excluding Tracks that don't have Channels) and contains information rel...
Definition channel.h:61
The control room allows to specify how Listen will work on each Channel and to set overall volume aft...
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition types.h:138
A Fader is a processor that is used for volume controls and pan.
Definition fader.h:118
Port * balance
A control Port that controls the balance (0.0 ~ 1.0) 0.5 is center.
Definition fader.h:149
StereoPorts * stereo_out
L & R audio output ports, if audio.
Definition fader.h:177
Port * listen
Listened or not.
Definition fader.h:161
Port * swap_phase
Swap phase toggle.
Definition fader.h:167
ControlRoom * control_room
Pointer to owner control room, if any.
Definition fader.h:209
bool was_effectively_muted
Cache.
Definition fader.h:239
float fader_val
0.0 ~ 1.0 for widgets.
Definition fader.h:130
Port * midi_in
MIDI in port, if MIDI.
Definition fader.h:182
int fading_out
Whether currently fading out.
Definition fader.h:236
Port * mute
Control port for muting the (channel) fader.
Definition fader.h:155
Track * track
Pointer to owner track, if any.
Definition fader.h:206
bool passthrough
Whether this is a passthrough fader (like a prefader).
Definition fader.h:203
float volume
Volume in dBFS.
Definition fader.h:124
int fade_out_samples
Number of samples left to fade out.
Definition fader.h:229
StereoPorts * stereo_in
L & R audio input ports, if audio.
Definition fader.h:172
float phase
Used by the phase knob (0.0 ~ 360.0).
Definition fader.h:127
Port * amp
A control port that controls the volume in amplitude (0.0 ~ 1.5)
Definition fader.h:145
float l_port_db
Current dBFS after processing each output port.
Definition fader.h:194
int fade_in_samples
Number of samples left to fade in.
Definition fader.h:224
Port * solo
Soloed or not.
Definition fader.h:158
Port * mono_compat_enabled
Whether mono compatibility switch is enabled.
Definition fader.h:164
Port * midi_out
MIDI out port, if MIDI.
Definition fader.h:187
float last_cc_volume
Value of amp during last processing.
Definition fader.h:139
SampleProcessor * sample_processor
Pointer to owner sample processor, if any.
Definition fader.h:212
MidiFaderMode midi_mode
MIDI fader mode.
Definition fader.h:200
Struct used to identify Ports in the project.
Must ONLY be created via port_new()
Definition port.h:138
A processor to be used in the routing graph for playing samples independent of the timeline.
L & R port, for convenience.
Definition port.h:522
Track to be inserted into the Project's Tracklist.
Definition track.h:186
Custom types.
YAML utils.