Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
clip.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2023 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __AUDIO_CLIP_H__
11#define __AUDIO_CLIP_H__
12
13#include <stdbool.h>
14
15#include "utils/audio.h"
16#include "utils/types.h"
17#include "utils/yaml.h"
18
25#define AUDIO_CLIP_SCHEMA_VERSION 1
26
32typedef struct AudioClip
33{
34 int schema_version;
35
37 char * name;
38
41
44
49
52
58
64
70
74
77
80 char * file_hash;
81
88
97 gint64 last_write;
98} AudioClip;
99
100static const cyaml_schema_field_t audio_clip_fields_schema[] = {
101 YAML_FIELD_INT (AudioClip, schema_version),
102 YAML_FIELD_STRING_PTR (AudioClip, name),
103 YAML_FIELD_STRING_PTR_OPTIONAL (AudioClip, file_hash),
104 YAML_FIELD_FLOAT (AudioClip, bpm),
105 YAML_FIELD_ENUM (AudioClip, bit_depth, bit_depth_strings),
106 YAML_FIELD_INT (AudioClip, use_flac),
107 YAML_FIELD_INT (AudioClip, samplerate),
108 YAML_FIELD_INT (AudioClip, pool_id),
109
110 CYAML_FIELD_END
111};
112
113static const cyaml_schema_value_t audio_clip_schema = {
114 YAML_VALUE_PTR_NULLABLE (AudioClip, audio_clip_fields_schema),
115};
116
117static inline bool
118audio_clip_use_flac (BitDepth bd)
119{
120 return false;
121 /* FLAC seems to fail writing sometimes so disable for now */
122#if 0
123 return bd < BIT_DEPTH_32;
124#endif
125}
126
130COLD NONNULL bool
131audio_clip_init_loaded (AudioClip * self, GError ** error);
132
138NONNULL_ARGS (1)
139AudioClip * audio_clip_new_from_file (const char * full_path, GError ** error);
140
148AudioClip *
150 const float * arr,
151 const unsigned_frame_t nframes,
152 const channels_t channels,
153 BitDepth bit_depth,
154 const char * name);
155
166AudioClip *
168 const channels_t channels,
169 const unsigned_frame_t nframes,
170 const char * name);
171
180NONNULL void
181audio_clip_update_channel_caches (AudioClip * self, size_t start_from);
182
197NONNULL AudioClip *
199
208WARN_UNUSED_RESULT NONNULL bool
210 AudioClip * self,
211 const char * filepath,
212 bool parts,
213 GError ** error);
214
225WARN_UNUSED_RESULT NONNULL bool
227 AudioClip * self,
228 bool parts,
229 bool is_backup,
230 GError ** error);
231
241NONNULL char *
243 const char * name,
244 bool use_flac,
245 bool is_backup);
246
252NONNULL char *
253audio_clip_get_path_in_pool (AudioClip * self, bool is_backup);
254
262NONNULL bool
263audio_clip_is_in_use (AudioClip * self, bool check_undo_stack);
264
274NONNULL void
276
277NONNULL AudioClip *
278audio_clip_clone (AudioClip * src);
279
283NONNULL void
285
290#endif
Audio utils.
NONNULL_ARGS(1) int undo_manager_undo(UndoManager *self
Undo last action.
AudioClip * audio_clip_new_from_file(const char *full_path, GError **error)
Creates an audio clip from a file.
NONNULL void audio_clip_remove_and_free(AudioClip *self, bool backup)
To be called by audio_pool_remove_clip().
NONNULL char * audio_clip_get_path_in_pool_from_name(const char *name, bool use_flac, bool is_backup)
Gets the path of a clip matching name from the pool.
AudioClip * audio_clip_new_recording(const channels_t channels, const unsigned_frame_t nframes, const char *name)
Create an audio clip while recording.
NONNULL void audio_clip_update_channel_caches(AudioClip *self, size_t start_from)
Updates the channel caches.
NONNULL void audio_clip_free(AudioClip *self)
Frees the audio clip.
WARN_UNUSED_RESULT NONNULL bool audio_clip_write_to_file(AudioClip *self, const char *filepath, bool parts, GError **error)
Writes the given audio clip data to a file.
NONNULL AudioClip * audio_clip_edit_in_ext_program(AudioClip *self, GError **error)
Shows a dialog with info on how to edit a file, with an option to open an app launcher.
WARN_UNUSED_RESULT NONNULL bool audio_clip_write_to_pool(AudioClip *self, bool parts, bool is_backup, GError **error)
Writes the clip to the pool as a wav file.
NONNULL char * audio_clip_get_path_in_pool(AudioClip *self, bool is_backup)
Gets the path of the given clip from the pool.
AudioClip * audio_clip_new_from_float_array(const float *arr, const unsigned_frame_t nframes, const channels_t channels, BitDepth bit_depth, const char *name)
Creates an audio clip by copying the given float array.
COLD NONNULL bool audio_clip_init_loaded(AudioClip *self, GError **error)
Inits after loading a Project.
NONNULL bool audio_clip_is_in_use(AudioClip *self, bool check_undo_stack)
Returns whether the clip is used inside the project.
uint_fast64_t unsigned_frame_t
Unsigned type for frame index.
Definition types.h:60
BitDepth
Bit depth.
Definition audio.h:29
float bpm_t
The BPM type.
Definition types.h:50
float sample_t
The sample type.
Definition types.h:47
#define YAML_VALUE_PTR_NULLABLE(cc, fields_schema)
Schema to be used as a pointer that can be NULL.
Definition yaml.h:209
unsigned int channels_t
Number of channels.
Definition types.h:44
Audio clips for the pool.
Definition clip.h:33
sample_t * frames
The audio frames, interleaved.
Definition clip.h:40
char * name
Name of the clip.
Definition clip.h:37
char * file_hash
File hash, used for checking if a clip is already written to the pool.
Definition clip.h:80
sample_t * ch_frames[16]
Per-channel frames for convenience.
Definition clip.h:48
int pool_id
ID in the audio pool.
Definition clip.h:76
unsigned_frame_t num_frames
Number of frames per channel.
Definition clip.h:43
unsigned_frame_t frames_written
Frames already written to the file, per channel.
Definition clip.h:87
BitDepth bit_depth
Bit depth of the clip when the clip was imported into the project.
Definition clip.h:69
bool use_flac
Whether the clip should use FLAC when being serialized.
Definition clip.h:73
gint64 last_write
Time the last write took place.
Definition clip.h:97
bpm_t bpm
BPM of the clip, or BPM of the project when the clip was first loaded.
Definition clip.h:57
int samplerate
Samplerate of the clip, or samplerate when the clip was imported into the project.
Definition clip.h:63
channels_t channels
Number of channels.
Definition clip.h:51
Custom types.
YAML utils.