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,
65 const dsp::TempoMap &tempo_map) noexcept override;
66
68 {
69 return u8"Sample Processor";
70 }
71
72 nframes_t get_single_playback_latency () const override { return 0; }
73
78
82 void queue_sample_from_file (const char * path);
83
87 void queue_file (const FileDescriptor &file);
88
92 void queue_chord_preset (const ChordPreset &chord_pset);
93
98
99private:
100 static constexpr auto kFaderKey = "fader"sv;
101 friend void to_json (nlohmann::json &j, const SampleProcessor &sp)
102 {
103 j[kFaderKey] = sp.fader_;
104 }
105 friend void from_json (const nlohmann::json &j, SampleProcessor &sp)
106 {
107 // TODO
108 // j.at (kFaderKey).get_to (sp.fader_);
109 }
110
111 void init_common ();
112
113 void queue_file_or_chord_preset (
114 const FileDescriptor * file,
115 const ChordPreset * chord_pset);
116
117public:
119 std::vector<SamplePlayback> current_samples_;
120
122 std::unique_ptr<structure::tracks::Tracklist> tracklist_;
123
125 std::unique_ptr<zrythm::plugins::PluginConfiguration> instrument_setting_;
126
127 std::unique_ptr<dsp::MidiEvents> midi_events_;
128
130 std::unique_ptr<dsp::Fader> fader_;
131
133 // Position playhead_;
134
141 // Position file_end_pos_;
142
144 bool roll_ = false;
145
147 engine::device_io::AudioEngine * audio_engine_ = nullptr;
148
151 moodycamel::LightweightSemaphore rebuilding_sem_{ 1 };
152};
153
154}
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:54
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, const dsp::TempoMap &tempo_map) 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.