Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
sample_processor.h
1// SPDX-FileCopyrightText: © 2019-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/fader.h"
7#include "dsp/graph.h"
8#include "dsp/midi_event.h"
10#include "structure/tracks/tracklist.h"
11#include "utils/types.h"
12
13#include <moodycamel/lightweightsemaphore.h>
14
15class FileDescriptor;
16class ChordPreset;
17
18namespace zrythm::engine::device_io
19{
20class AudioEngine;
21};
22
23#define SAMPLE_PROCESSOR (AUDIO_ENGINE->sample_processor_)
24
25namespace zrythm::engine::session
26{
33class SampleProcessor final : public QObject, public dsp::graph::IProcessable
34{
35 Q_OBJECT
36public:
37 using PluginConfiguration = zrythm::plugins::PluginConfiguration;
38
39public:
40 SampleProcessor () = default;
41 SampleProcessor (engine::device_io::AudioEngine * engine);
42 Z_DISABLE_COPY_MOVE (SampleProcessor)
43 ~SampleProcessor () override;
44
45 friend void init_from (
46 SampleProcessor &obj,
47 const SampleProcessor &other,
48 utils::ObjectCloneType clone_type);
49
50 void init_loaded (engine::device_io::AudioEngine * engine);
51
58
63 EngineProcessTimeInfo time_nfo,
64 const dsp::ITransport &transport) noexcept override;
65
67 {
68 return u8"Sample Processor";
69 }
70
71 nframes_t get_single_playback_latency () const override { return 0; }
72
77
81 void queue_sample_from_file (const char * path);
82
86 void queue_file (const FileDescriptor &file);
87
91 void queue_chord_preset (const ChordPreset &chord_pset);
92
97
98private:
99 static constexpr auto kFaderKey = "fader"sv;
100 friend void to_json (nlohmann::json &j, const SampleProcessor &sp)
101 {
102 j[kFaderKey] = sp.fader_;
103 }
104 friend void from_json (const nlohmann::json &j, SampleProcessor &sp)
105 {
106 // TODO
107 // j.at (kFaderKey).get_to (sp.fader_);
108 }
109
110 void init_common ();
111
112 void queue_file_or_chord_preset (
113 const FileDescriptor * file,
114 const ChordPreset * chord_pset);
115
116public:
118 std::vector<SamplePlayback> current_samples_;
119
121 std::unique_ptr<structure::tracks::Tracklist> tracklist_;
122
124 std::unique_ptr<zrythm::plugins::PluginConfiguration> instrument_setting_;
125
126 std::unique_ptr<dsp::MidiEvents> midi_events_;
127
129 std::unique_ptr<dsp::Fader> fader_;
130
132 // Position playhead_;
133
140 // Position file_end_pos_;
141
143 bool roll_ = false;
144
146 engine::device_io::AudioEngine * audio_engine_ = nullptr;
147
150 moodycamel::LightweightSemaphore rebuilding_sem_{ 1 };
151};
152
153}
A preset of chord descriptors.
Descriptor of a file.
Interface for transport.
Definition itransport.h:17
Interface for objects that can be processed in the DSP graph.
Definition graph_node.h:53
A processor to be used in the routing graph for playing samples independent of the timeline.
utils::Utf8String get_node_name() const override
Returns a human friendly name of the node.
void stop_file_playback()
Stops playback of files (auditioning).
void load_instrument_if_empty()
Loads the instrument from the settings.
void queue_file(const FileDescriptor &file)
Adds a file (audio or MIDI) to the queue.
void remove_sample_playback(SamplePlayback &sp)
Removes a SamplePlayback from the array.
moodycamel::LightweightSemaphore rebuilding_sem_
Semaphore to be locked while rebuilding the sample processor tracklist and graph.
std::unique_ptr< dsp::Fader > fader_
Fader connected to the main output.
nframes_t get_single_playback_latency() const override
Returns the latency of only the given processable, without adding the previous/next latencies.
std::unique_ptr< structure::tracks::Tracklist > tracklist_
Tracklist for file auditioning.
engine::device_io::AudioEngine * audio_engine_
Pointer to owner audio engine, if any.
void queue_sample_from_file(const char *path)
Adds a sample to play to the queue from a file path.
void queue_chord_preset(const ChordPreset &chord_pset)
Adds a chord preset to the queue.
std::vector< SamplePlayback > current_samples_
An array of samples currently being played.
void process_block(EngineProcessTimeInfo time_nfo, const dsp::ITransport &transport) noexcept override
Process the samples for the given number of frames.
std::unique_ptr< zrythm::plugins::PluginConfiguration > instrument_setting_
Instrument for MIDI auditioning.
bool roll_
Playhead for the tracklist (used when auditioning files).
Configuration for instantiating a plugin descriptor.
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:38
uint32_t nframes_t
Frame count.
Definition types.h:58
A framework from playing back samples independent of the timeline, such as metronomes and samples fro...
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition types.h:133
A sample playback handle to be used by the engine.