Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
AudioClip Class Referencefinal

Audio clips for the pool. More...

#include <src/engine/session/clip.h>

Inheritance diagram for AudioClip:
Collaboration diagram for AudioClip:

Public Types

using BitDepth = zrythm::utils::audio::BitDepth
 
using AudioFile = zrythm::utils::audio::AudioFile
 

Public Member Functions

 AudioClip (const fs::path &full_path, sample_rate_t project_sample_rate, bpm_t current_bpm)
 Creates an audio clip from a file.
 
 AudioClip (const utils::audio::AudioBuffer &buf, utils::audio::BitDepth bit_depth, sample_rate_t project_sample_rate, bpm_t current_bpm, const utils::Utf8String &name)
 Creates an audio clip by copying the given buffer.
 
 AudioClip (const float *arr, unsigned_frame_t nframes, channels_t channels, zrythm::utils::audio::BitDepth bit_depth, sample_rate_t project_sample_rate, bpm_t current_bpm, const utils::Utf8String &name)
 Creates an audio clip by copying the given interleaved float array.
 
 AudioClip (channels_t channels, unsigned_frame_t nframes, sample_rate_t project_sample_rate, bpm_t current_bpm, const utils::Utf8String &name)
 Create an audio clip while recording.
 
void init_loaded (const fs::path &full_path)
 Inits after loading a Project.
 
std::unique_ptr< AudioClipedit_in_ext_program ()
 Shows a dialog with info on how to edit a file, with an option to open an app launcher.
 
void write_to_file (const fs::path &filepath, bool parts)
 Writes the given audio clip data to a file.
 
auto get_bit_depth () const
 
auto get_name () const
 
auto get_file_hash () const
 
auto get_bpm () const
 
const auto & get_samples () const
 
auto get_last_write_to_file () const
 
auto get_use_flac () const
 
void set_name (const utils::Utf8String &name)
 
void set_file_hash (utils::hash::HashT hash)
 
void expand_with_frames (const utils::audio::AudioBuffer &frames)
 Expands (appends to the end) the frames in the clip by the given frames.
 
void replace_frames (const utils::audio::AudioBuffer &src_frames, unsigned_frame_t start_frame)
 Replaces the clip's frames starting from start_frame with frames.
 
void replace_frames_from_interleaved (const float *frames, unsigned_frame_t start_frame, unsigned_frame_t num_frames_per_channel, channels_t channels)
 Replaces the clip's frames starting from start_frame with frames.
 
void clear_frames ()
 Unloads the clip's frames from memory.
 
auto get_num_channels () const
 
auto get_num_frames () const
 
void finalize_buffered_write ()
 Finalizes buffered write to a file (when parts is true in write_to_file()).
 
bool verify_recorded_file (const fs::path &filepath, sample_rate_t project_sample_rate, bpm_t current_bpm) const
 Used during tests to verify that the recorded file is valid.
 
bool enough_time_elapsed_since_last_write () const
 Returns whether enough time has elapsed since the last write to file.
 
- Public Member Functions inherited from zrythm::utils::UuidIdentifiableObject< AudioClip >
 UuidIdentifiableObject (const Uuid &id)
 
 UuidIdentifiableObject (const UuidIdentifiableObject &other)=default
 
 UuidIdentifiableObject (UuidIdentifiableObject &&other)=default
 
UuidIdentifiableObjectoperator= (const UuidIdentifiableObject &other)=default
 
UuidIdentifiableObjectoperator= (UuidIdentifiableObject &&other)=default
 
auto get_uuid () const
 

Static Public Member Functions

static bool should_use_flac (zrythm::utils::audio::BitDepth bd)
 

Friends

void init_from (AudioClip &obj, const AudioClip &other, utils::ObjectCloneType clone_type)
 
void to_json (nlohmann::json &j, const AudioClip &clip)
 
void from_json (const nlohmann::json &j, AudioClip &clip)
 

Detailed Description

Audio clips for the pool.

These should be loaded in the project's sample rate.

Definition at line 22 of file clip.h.

Member Typedef Documentation

◆ AudioFile

Definition at line 28 of file clip.h.

◆ BitDepth

using AudioClip::BitDepth = zrythm::utils::audio::BitDepth

Definition at line 27 of file clip.h.

Constructor & Destructor Documentation

◆ AudioClip() [1/4]

AudioClip::AudioClip ( const fs::path & full_path,
sample_rate_t project_sample_rate,
bpm_t current_bpm )

Creates an audio clip from a file.

The basename of the file will be used as the name of the clip.

Parameters
current_bpmCurrent BPM from TempoTrack. bpm_ will be set to this. FIXME: should this be optional? does "current" BPM make sense?
Exceptions
ZrythmExceptionon error.

◆ AudioClip() [2/4]

AudioClip::AudioClip ( const utils::audio::AudioBuffer & buf,
utils::audio::BitDepth bit_depth,
sample_rate_t project_sample_rate,
bpm_t current_bpm,
const utils::Utf8String & name )

Creates an audio clip by copying the given buffer.

Parameters
bufBuffer to copy.
nameA name for this clip.

◆ AudioClip() [3/4]

AudioClip::AudioClip ( const float * arr,
unsigned_frame_t nframes,
channels_t channels,
zrythm::utils::audio::BitDepth bit_depth,
sample_rate_t project_sample_rate,
bpm_t current_bpm,
const utils::Utf8String & name )
inline

Creates an audio clip by copying the given interleaved float array.

Parameters
arrInterleaved array.
nframesNumber of frames per channel.
channelsNumber of channels.
nameA name for this clip.

Definition at line 69 of file clip.h.

◆ AudioClip() [4/4]

AudioClip::AudioClip ( channels_t channels,
unsigned_frame_t nframes,
sample_rate_t project_sample_rate,
bpm_t current_bpm,
const utils::Utf8String & name )

Create an audio clip while recording.

The frames will keep getting reallocated until the recording is finished.

Parameters
nframesNumber of frames to allocate. This should be the current cycle's frames when called during recording.

Member Function Documentation

◆ clear_frames()

void AudioClip::clear_frames ( )
inline

Unloads the clip's frames from memory.

Definition at line 200 of file clip.h.

◆ edit_in_ext_program()

std::unique_ptr< AudioClip > AudioClip::edit_in_ext_program ( )

Shows a dialog with info on how to edit a file, with an option to open an app launcher.

When the user closes the dialog, the clip is assumed to have been edited.

The given audio clip will be free'd.

Note
This must not be used on pool clips.
Returns
A new instance of AudioClip if successful, nullptr, if not.
Exceptions
ZrythmExceptionon error.

◆ enough_time_elapsed_since_last_write()

bool AudioClip::enough_time_elapsed_since_last_write ( ) const

Returns whether enough time has elapsed since the last write to file.

This is used so that writing to file is done in chunks.

◆ expand_with_frames()

void AudioClip::expand_with_frames ( const utils::audio::AudioBuffer & frames)

Expands (appends to the end) the frames in the clip by the given frames.

Parameters
framesNon-interleaved frames.

◆ get_bit_depth()

auto AudioClip::get_bit_depth ( ) const
inline

Definition at line 150 of file clip.h.

◆ get_bpm()

auto AudioClip::get_bpm ( ) const
inline

Definition at line 153 of file clip.h.

◆ get_file_hash()

auto AudioClip::get_file_hash ( ) const
inline

Definition at line 152 of file clip.h.

◆ get_last_write_to_file()

auto AudioClip::get_last_write_to_file ( ) const
inline

Definition at line 155 of file clip.h.

◆ get_name()

auto AudioClip::get_name ( ) const
inline

Definition at line 151 of file clip.h.

◆ get_num_channels()

auto AudioClip::get_num_channels ( ) const
inline

Definition at line 205 of file clip.h.

◆ get_num_frames()

auto AudioClip::get_num_frames ( ) const
inline

Definition at line 206 of file clip.h.

◆ get_samples()

const auto & AudioClip::get_samples ( ) const
inline

Definition at line 154 of file clip.h.

◆ get_use_flac()

auto AudioClip::get_use_flac ( ) const
inline

Definition at line 156 of file clip.h.

◆ init_loaded()

void AudioClip::init_loaded ( const fs::path & full_path)

Inits after loading a Project.

Parameters
full_pathFull path to the corresponding audio file in the pool.
Exceptions
ZrythmExceptionon error.

◆ replace_frames()

void AudioClip::replace_frames ( const utils::audio::AudioBuffer & src_frames,
unsigned_frame_t start_frame )

Replaces the clip's frames starting from start_frame with frames.

Warning
Not realtime safe.
Parameters
src_framesFrames to copy.
start_frameFrame to start copying to (src_frames are always copied from the start).

◆ replace_frames_from_interleaved()

void AudioClip::replace_frames_from_interleaved ( const float * frames,
unsigned_frame_t start_frame,
unsigned_frame_t num_frames_per_channel,
channels_t channels )

Replaces the clip's frames starting from start_frame with frames.

Warning
Not realtime safe.
Parameters
framesFrames, interleaved.
start_frameFrame to start copying to (src_frames are always copied from the start).

◆ set_file_hash()

void AudioClip::set_file_hash ( utils::hash::HashT hash)
inline

Definition at line 159 of file clip.h.

◆ set_name()

void AudioClip::set_name ( const utils::Utf8String & name)
inline

Definition at line 158 of file clip.h.

◆ should_use_flac()

static bool AudioClip::should_use_flac ( zrythm::utils::audio::BitDepth bd)
inlinestatic

Definition at line 103 of file clip.h.

◆ verify_recorded_file()

bool AudioClip::verify_recorded_file ( const fs::path & filepath,
sample_rate_t project_sample_rate,
bpm_t current_bpm ) const

Used during tests to verify that the recorded file is valid.

Parameters
current_bpmCurrent BPM from TempoTrack, used when creating a temporary clip from the filepath.

◆ write_to_file()

void AudioClip::write_to_file ( const fs::path & filepath,
bool parts )

Writes the given audio clip data to a file.

Parameters
partsIf true, only write new data.
See also
AudioClip.frames_written.
Exceptions
ZrythmExceptionon error.

Friends And Related Symbol Documentation

◆ from_json

void from_json ( const nlohmann::json & j,
AudioClip & clip )
friend

Definition at line 248 of file clip.h.

◆ to_json

void to_json ( nlohmann::json & j,
const AudioClip & clip )
friend

Definition at line 238 of file clip.h.


The documentation for this class was generated from the following file: