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"
9#include "structure/tracks/tracklist.h"
10#include "utils/types.h"
11
12#include <moodycamel/lightweightsemaphore.h>
13
14class FileDescriptor;
15class ChordPreset;
16
17namespace zrythm::engine::device_io
18{
19class AudioEngine;
20};
21
22#define SAMPLE_PROCESSOR (AUDIO_ENGINE->sample_processor_)
23
24namespace zrythm::engine::session
25{
32class SampleProcessor final : public QObject, public dsp::graph::IProcessable
33{
34 Q_OBJECT
35public:
36 using PluginConfiguration = zrythm::plugins::PluginConfiguration;
37
38public:
39 SampleProcessor () = default;
40 SampleProcessor (engine::device_io::AudioEngine * engine);
41 Q_DISABLE_COPY_MOVE (SampleProcessor)
42 ~SampleProcessor () override;
43
44 friend void init_from (
45 SampleProcessor &obj,
46 const SampleProcessor &other,
47 utils::ObjectCloneType clone_type);
48
49 void init_loaded (engine::device_io::AudioEngine * engine);
50
57
63 const dsp::ITransport &transport,
64 const dsp::TempoMap &tempo_map) noexcept override;
65
67 {
68 return u8"Sample Processor";
69 }
70
74 void queue_sample_from_file (const char * path);
75
79 void queue_file (const FileDescriptor &file);
80
84 void queue_chord_preset (const ChordPreset &chord_pset);
85
90
91private:
92 static constexpr auto kFaderKey = "fader"sv;
93 friend void to_json (nlohmann::json &j, const SampleProcessor &sp)
94 {
95 j[kFaderKey] = sp.fader_;
96 }
97 friend void from_json (const nlohmann::json &j, SampleProcessor &sp)
98 {
99 // TODO
100 // j.at (kFaderKey).get_to (sp.fader_);
101 }
102
103 void init_common ();
104
105 void queue_file_or_chord_preset (
106 const FileDescriptor * file,
107 const ChordPreset * chord_pset);
108
109public:
111 std::unique_ptr<structure::tracks::Tracklist> tracklist_;
112
114 std::unique_ptr<zrythm::plugins::PluginConfiguration> instrument_setting_;
115
116 std::unique_ptr<dsp::MidiEvents> midi_events_;
117
119 std::unique_ptr<dsp::Fader> fader_;
120
122 // Position playhead_;
123
130 // Position file_end_pos_;
131
133 bool roll_ = false;
134
136 engine::device_io::AudioEngine * audio_engine_ = nullptr;
137
140 moodycamel::LightweightSemaphore rebuilding_sem_{ 1 };
141};
142
143}
A preset of chord descriptors.
Interface for transport.
Definition itransport.h:16
Interface for objects that can be processed in the DSP graph.
Definition graph_node.h:86
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 process_block(dsp::graph::EngineProcessTimeInfo time_nfo, const dsp::ITransport &transport, const dsp::TempoMap &tempo_map) noexcept override
Process the samples for the given number of frames.
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.
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::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:37
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition graph_node.h:51