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 == FaderType::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 && track_is_in_active_project (self->track)) || (self->sample_processor != NULL && sample_processor_is_in_active_project (self->sample_processor)) || (self->control_room != NULL && control_room_is_in_active_project (self->control_room)))
51
55enum class FaderType
56{
57 FADER_TYPE_NONE,
58
61
64
67
68 /* MIDI fader for Channel's. */
69 FADER_TYPE_MIDI_CHANNEL,
70
73};
74
83
90typedef struct Fader
91{
92 int schema_version;
93
97 float volume;
98
100 float phase;
101
104
113
119
123
129
132
135
138
141
146
151
156
161
168 float r_port_db;
169
170 FaderType type;
171
174
177
180
183
186
187 int magic;
188
189 bool is_project;
190
191 /* TODO Caches to be set when recalculating the
192 * graph. */
193 bool implied_soloed;
194 bool soloed;
195
198
203
210
213} Fader;
214
218COLD NONNULL_ARGS (1) void fader_init_loaded (
219 Fader * self,
220 Track * track,
221 ControlRoom * control_room,
222 SampleProcessor * sample_processor);
223
232COLD Fader *
234 FaderType type,
235 bool passthrough,
236 Track * track,
237 ControlRoom * control_room,
238 SampleProcessor * sample_processor);
239
240Fader *
241fader_find_from_port_identifier (const PortIdentifier * id);
242
243Port *
244fader_create_swap_phase_port (Fader * self, bool passthrough);
245
250NONNULL void
251fader_append_ports (const Fader * self, GPtrArray * ports);
252
256void
257fader_set_amp (void * self, float amp);
258
265void
267 Fader * self,
268 float amp_from,
269 float amp_to,
270 bool skip_if_equal);
271
276void
277fader_add_amp (void * self, float amp);
278
279NONNULL void
280fader_set_midi_mode (
281 Fader * self,
282 MidiFaderMode mode,
283 bool with_action,
284 bool fire_events);
285
290void
291fader_set_muted (Fader * self, bool mute, bool fire_events);
292
296NONNULL bool
297fader_get_muted (const Fader * const self);
298
302HOT NONNULL bool
303fader_get_soloed (const Fader * const self);
304
311bool
313
317#define fader_get_listened(self) (control_port_is_toggled (self->listen))
318
323void
324fader_set_listened (Fader * self, bool listen, bool fire_events);
325
330void
331fader_set_soloed (Fader * self, bool solo, bool fire_events);
332
337NONNULL float
338fader_get_amp (void * self);
339
343bool
345
349void
350fader_set_mono_compat_enabled (Fader * self, bool enabled, bool fire_events);
351
355bool
357
361void
362fader_set_swap_phase (Fader * self, bool enabled, bool fire_events);
363
364float
365fader_get_fader_val (void * self);
366
367float
368fader_get_default_fader_val (void * self);
369
370void
371fader_db_string_getter (void * obj, char * buf);
372
373Channel *
374fader_get_channel (Fader * self);
375
376NONNULL Track *
377fader_get_track (Fader * self);
378
379void
380fader_update_volume_and_fader_val (Fader * self);
381
385HOT NONNULL void
387
392void
393fader_set_fader_val (Fader * self, float fader_val);
394
398void
400
406void
408
412NONNULL HOT void
413fader_process (Fader * self, const EngineProcessTimeInfo * const time_nfo);
414
415#if 0
419void
420fader_update_track_pos (
421 Fader * self,
422 int pos);
423#endif
424
425Fader *
426fader_clone (const Fader * src);
427
431void
433
438#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.
FaderType
Fader type.
Definition fader.h:56
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.
NONNULL bool fader_get_muted(const Fader *const self)
Returns if the fader is muted.
HOT NONNULL bool fader_get_soloed(const Fader *const self)
Returns if the track is soloed.
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 float fader_get_amp(void *self)
Gets the fader amplitude (not db) FIXME is void * necessary? do it in the caller.
NONNULL HOT void fader_process(Fader *self, const EngineProcessTimeInfo *const time_nfo)
Process the Fader.
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....
void fader_set_swap_phase(Fader *self, bool enabled, bool fire_events)
Sets whether mono compatibility is enabled.
MidiFaderMode
Definition fader.h:76
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_GENERIC
For generic uses.
@ FADER_TYPE_AUDIO_CHANNEL
Audio fader for Channel's.
@ FADER_TYPE_SAMPLE_PROCESSOR
Audio fader for the sample processor.
@ FADER_TYPE_MONITOR
Audio fader for the monitor.
@ MIDI_FADER_MODE_CC_VOLUME
Send CC volume event on change TODO.
@ MIDI_FADER_MODE_VEL_MULTIPLIER
Multiply velocity of all MIDI note ons.
The audio engine.
Definition engine.h:353
A Channel is part of a Track (excluding Tracks that don't have Channels) and contains information rel...
Definition channel.h:57
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:142
A Fader is a processor that is used for volume controls and pan.
Definition fader.h:91
Port * balance
A control Port that controls the balance (0.0 ~ 1.0) 0.5 is center.
Definition fader.h:122
StereoPorts * stereo_out
L & R audio output ports, if audio.
Definition fader.h:150
Port * listen
Listened or not.
Definition fader.h:134
Port * swap_phase
Swap phase toggle.
Definition fader.h:140
ControlRoom * control_room
Pointer to owner control room, if any.
Definition fader.h:182
bool was_effectively_muted
Cache.
Definition fader.h:212
float fader_val
0.0 ~ 1.0 for widgets.
Definition fader.h:103
Port * midi_in
MIDI in port, if MIDI.
Definition fader.h:155
int fading_out
Whether currently fading out.
Definition fader.h:209
Port * mute
Control port for muting the (channel) fader.
Definition fader.h:128
Track * track
Pointer to owner track, if any.
Definition fader.h:179
bool passthrough
Whether this is a passthrough fader (like a prefader).
Definition fader.h:176
float volume
Volume in dBFS.
Definition fader.h:97
int fade_out_samples
Number of samples left to fade out.
Definition fader.h:202
StereoPorts * stereo_in
L & R audio input ports, if audio.
Definition fader.h:145
float phase
Used by the phase knob (0.0 ~ 360.0).
Definition fader.h:100
Port * amp
A control port that controls the volume in amplitude (0.0 ~ 1.5)
Definition fader.h:118
float l_port_db
Current dBFS after processing each output port.
Definition fader.h:167
int fade_in_samples
Number of samples left to fade in.
Definition fader.h:197
Port * solo
Soloed or not.
Definition fader.h:131
Port * mono_compat_enabled
Whether mono compatibility switch is enabled.
Definition fader.h:137
Port * midi_out
MIDI out port, if MIDI.
Definition fader.h:160
float last_cc_volume
Value of amp during last processing.
Definition fader.h:112
SampleProcessor * sample_processor
Pointer to owner sample processor, if any.
Definition fader.h:185
MidiFaderMode midi_mode
MIDI fader mode.
Definition fader.h:173
Struct used to identify Ports in the project.
Must ONLY be created via port_new()
Definition port.h:136
A processor to be used in the routing graph for playing samples independent of the timeline.
L & R port, for convenience.
Definition port.h:501
Track to be inserted into the Project's Tracklist.
Definition track.h:177
Custom types.
YAML utils.