Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::structure::tracks::TrackProcessor Class Referencefinal

A TrackProcessor is a standalone processor that is used as the first step when processing a track in the DSP graph. More...

#include <src/structure/tracks/track_processor.h>

Inheritance diagram for zrythm::structure::tracks::TrackProcessor:
Collaboration diagram for zrythm::structure::tracks::TrackProcessor:

Public Types

enum class  ActiveMidiEventProviders : uint8_t {
  Timeline = 1 << 0 , ClipLauncher = 1 << 1 , PianoRoll = 1 << 2 , Recording = 1 << 3 ,
  Custom = 1 << 4
}
enum class  ActiveAudioProviders : uint8_t { Timeline = 1 << 0 , ClipLauncher = 1 << 1 , Recording = 1 << 2 , Custom = 1 << 3 }
using StereoPortPair = std::pair<std::span<float>, std::span<float>>
using ConstStereoPortPair
using FillEventsCallback
 Function called during processing to fill events.
using HandleRecordingCallback
 Callback to record the given audio or MIDI data.
using AppendMidiInputsToOutputsFunc
 Custom logic to use when appending the MIDI input events to the output events.
using TransformMidiInputsFunc = std::function<void (dsp::MidiEventVector &)>
 Function to transform the given MIDI inputs.
using EnabledProvider = std::function<bool ()>
 Function that returns if the track for this processor is enabled.
using TrackNameProvider = std::function<utils::Utf8String ()>
using MidiEventProviderProcessFunc

Public Member Functions

 TrackProcessor (const dsp::TempoMap &tempo_map, PortType signal_type, TrackNameProvider track_name_provider, EnabledProvider enabled_provider, bool generates_midi_events, bool has_midi_cc, bool is_audio_track, ProcessorBaseDependencies dependencies, std::optional< FillEventsCallback > fill_events_cb=std::nullopt, std::optional< TransformMidiInputsFunc > transform_midi_inputs_func=std::nullopt, std::optional< AppendMidiInputsToOutputsFunc > append_midi_inputs_to_outputs_func=std::nullopt, QObject *parent=nullptr)
 Creates a new track processor for the given track.
void set_handle_recording_callback (HandleRecordingCallback handle_rec_cb)
bool is_audio () const
constexpr bool is_midi () const
utils::Utf8String get_full_designation_for_port (const dsp::Port &port) const
void custom_process_block (EngineProcessTimeInfo time_nfo, const dsp::ITransport &transport) noexcept override
 Process the TrackProcessor.
void custom_prepare_for_processing (const dsp::graph::GraphNode *node, units::sample_rate_t sample_rate, nframes_t max_block_length) override
void custom_release_resources () override
dsp::AudioPortget_stereo_in_port () const
dsp::AudioPortget_stereo_out_port () const
dsp::ProcessorParameterget_mono_param () const
dsp::ProcessorParameterget_input_gain_param () const
dsp::ProcessorParameterget_output_gain_param () const
dsp::ProcessorParameterget_monitor_audio_param () const
dsp::ProcessorParameterget_midi_cc_param (midi_byte_t channel, midi_byte_t control_no)
dsp::MidiPortget_midi_in_port () const
 MIDI in Port.
dsp::MidiPortget_midi_out_port () const
 MIDI out port, if MIDI.
dsp::MidiPortget_piano_roll_port () const
 MIDI input for receiving MIDI signals from the piano roll (i.e., MIDI notes inside regions) or other sources.
auto & timeline_audio_data_provider ()
auto & timeline_midi_data_provider ()
auto & clip_playback_data_provider ()
void set_midi_providers_active (ActiveMidiEventProviders event_providers, bool active)
 Used to enable or disable MIDI event providers.
void set_audio_providers_active (ActiveAudioProviders audio_providers, bool active)
 Used to enable or disable audio providers.
void set_custom_midi_event_provider (MidiEventProviderProcessFunc process_func)
 Replaces the "Custom" MIDI event provider.
void fill_midi_events (const EngineProcessTimeInfo &time_nfo, const dsp::ITransport &transport, dsp::MidiEventVector &midi_events)
 Wrapper for MIDI/instrument/chord tracks to fill in MidiEvents from the timeline data.
void fill_audio_events (const EngineProcessTimeInfo &time_nfo, const dsp::ITransport &transport, StereoPortPair stereo_ports)
 Wrapper for audio tracks to fill in StereoPorts from the timeline data.
Public Member Functions inherited from zrythm::dsp::ProcessorBase
 ProcessorBase (ProcessorBaseDependencies dependencies, utils::Utf8String name={ u8"ProcessorBase" })
void set_name (const utils::Utf8String &name)
 Set a custom name to be used in the DSP graph.
void add_input_port (const dsp::PortUuidReference &uuid)
void add_output_port (const dsp::PortUuidReference &uuid)
void add_parameter (const dsp::ProcessorParameterUuidReference &uuid)
auto & get_input_ports () const
auto & get_output_ports () const
auto & get_parameters () const
utils::Utf8String get_node_name () const final
 Returns a human friendly name of the node.
void process_block (EngineProcessTimeInfo time_nfo, const dsp::ITransport &transport) noexcept final
 Calls custom_process_block() internally after processing all the parameters.
void prepare_for_processing (const graph::GraphNode *node, units::sample_rate_t sample_rate, nframes_t max_block_length) final
 Called to allocate resources required for processing.
void release_resources () final
 Called to release resources allocated by prepare_for_processing().
Public Member Functions inherited from zrythm::dsp::graph::IProcessable
virtual nframes_t get_single_playback_latency () const
 Returns the latency of only the given processable, without adding the previous/next latencies.

Friends

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

Additional Inherited Members

Protected Member Functions inherited from zrythm::dsp::ProcessorBase
auto dependencies () const

Detailed Description

A TrackProcessor is a standalone processor that is used as the first step when processing a track in the DSP graph.

See also
Channel and ChannelTrack.

Definition at line 25 of file track_processor.h.

Member Typedef Documentation

◆ AppendMidiInputsToOutputsFunc

Initial value:
std::function<void (
dsp::MidiEventVector &out_events,
const dsp::MidiEventVector &in_events,
const EngineProcessTimeInfo &time_nfo)>
A lock-free thread-safe vector of MidiEvents.
Definition midi_event.h:78
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition types.h:133

Custom logic to use when appending the MIDI input events to the output events.

If not explicitly set, this will simply copy the events over.

Mainly used by ChordTrack to transform input MIDI notes into multiple output notes that match the chord.

Definition at line 85 of file track_processor.h.

◆ ConstStereoPortPair

using zrythm::structure::tracks::TrackProcessor::ConstStereoPortPair
Initial value:
std::pair<std::span<const float>, std::span<const float>>

Definition at line 49 of file track_processor.h.

◆ EnabledProvider

Function that returns if the track for this processor is enabled.

Used to conditionally skip processing if disabled.

Definition at line 102 of file track_processor.h.

◆ FillEventsCallback

Initial value:
std::function<void (
const dsp::ITransport &transport,
const EngineProcessTimeInfo &time_nfo,
dsp::MidiEventVector * midi_events,
std::optional<StereoPortPair> stereo_ports)>
Interface for transport.
Definition itransport.h:17

Function called during processing to fill events.

For regions, a helper method is provided for filling events from a single region. Implementations of this are supposed to call that for all their regions (including muted/disabled/etc.).

Definition at line 59 of file track_processor.h.

◆ HandleRecordingCallback

Initial value:
std::function<void (
const EngineProcessTimeInfo &time_nfo,
const dsp::MidiEventVector * midi_events,
std::optional<ConstStereoPortPair> stereo_ports)>

Callback to record the given audio or MIDI data.

Parameters
midi_eventsMIDI events that should be recorded, if any.
stereo_portsAudio data that should be recorded, if any.

Definition at line 71 of file track_processor.h.

◆ MidiEventProviderProcessFunc

using zrythm::structure::tracks::TrackProcessor::MidiEventProviderProcessFunc
Initial value:
std::function<void (
const EngineProcessTimeInfo &time_nfo,
dsp::MidiEventVector &output_buffer)>

Definition at line 106 of file track_processor.h.

◆ StereoPortPair

using zrythm::structure::tracks::TrackProcessor::StereoPortPair = std::pair<std::span<float>, std::span<float>>

Definition at line 48 of file track_processor.h.

◆ TrackNameProvider

using zrythm::structure::tracks::TrackProcessor::TrackNameProvider = std::function<utils::Utf8String ()>

Definition at line 104 of file track_processor.h.

◆ TransformMidiInputsFunc

Function to transform the given MIDI inputs.

This is used to, for example, change the channel of all events.

Definition at line 95 of file track_processor.h.

Member Enumeration Documentation

◆ ActiveAudioProviders

enum class zrythm::structure::tracks::TrackProcessor::ActiveAudioProviders : uint8_t
strong

Definition at line 119 of file track_processor.h.

◆ ActiveMidiEventProviders

enum class zrythm::structure::tracks::TrackProcessor::ActiveMidiEventProviders : uint8_t
strong

Definition at line 110 of file track_processor.h.

Constructor & Destructor Documentation

◆ TrackProcessor()

zrythm::structure::tracks::TrackProcessor::TrackProcessor ( const dsp::TempoMap & tempo_map,
PortType signal_type,
TrackNameProvider track_name_provider,
EnabledProvider enabled_provider,
bool generates_midi_events,
bool has_midi_cc,
bool is_audio_track,
ProcessorBaseDependencies dependencies,
std::optional< FillEventsCallback > fill_events_cb = std::nullopt,
std::optional< TransformMidiInputsFunc > transform_midi_inputs_func = std::nullopt,
std::optional< AppendMidiInputsToOutputsFunc > append_midi_inputs_to_outputs_func = std::nullopt,
QObject * parent = nullptr )

Creates a new track processor for the given track.

Parameters
generates_midi_eventsWhether this processor requires a "piano roll" port to generate MIDI events into (midi, instrument and chord tracks should set this to true).

Member Function Documentation

◆ clip_playback_data_provider()

auto & zrythm::structure::tracks::TrackProcessor::clip_playback_data_provider ( )
inline

Definition at line 279 of file track_processor.h.

◆ custom_prepare_for_processing()

void zrythm::structure::tracks::TrackProcessor::custom_prepare_for_processing ( const dsp::graph::GraphNode * node,
units::sample_rate_t sample_rate,
nframes_t max_block_length )
overridevirtual

Reimplemented from zrythm::dsp::ProcessorBase.

◆ custom_process_block()

void zrythm::structure::tracks::TrackProcessor::custom_process_block ( EngineProcessTimeInfo time_nfo,
const dsp::ITransport & transport )
overridevirtualnoexcept

Process the TrackProcessor.

This function performs the following:

  • produce output audio/MIDI into stereo out or midi out, based on any audio/MIDI regions, if has piano roll or is audio track
  • produce additional output MIDI events based on any MIDI CC automation regions, if applicable
  • change MIDI CC control port values based on any MIDI input, if recording — at this point the output is ready —
  • handle recording (create events in regions and automation, including MIDI CC automation, based on the MIDI CC control ports)

Reimplemented from zrythm::dsp::ProcessorBase.

◆ custom_release_resources()

void zrythm::structure::tracks::TrackProcessor::custom_release_resources ( )
overridevirtual

Reimplemented from zrythm::dsp::ProcessorBase.

◆ fill_audio_events()

void zrythm::structure::tracks::TrackProcessor::fill_audio_events ( const EngineProcessTimeInfo & time_nfo,
const dsp::ITransport & transport,
StereoPortPair stereo_ports )

Wrapper for audio tracks to fill in StereoPorts from the timeline data.

Note
The engine splits the cycle so transport loop related logic is not needed.
Parameters
stereo_portsStereoPorts to fill.

◆ fill_midi_events()

void zrythm::structure::tracks::TrackProcessor::fill_midi_events ( const EngineProcessTimeInfo & time_nfo,
const dsp::ITransport & transport,
dsp::MidiEventVector & midi_events )

Wrapper for MIDI/instrument/chord tracks to fill in MidiEvents from the timeline data.

Note
The engine splits the cycle so transport loop related logic is not needed.
Parameters
midi_eventsMidiEvents to fill.

◆ get_input_gain_param()

dsp::ProcessorParameter & zrythm::structure::tracks::TrackProcessor::get_input_gain_param ( ) const
inline

Definition at line 208 of file track_processor.h.

◆ get_midi_cc_param()

dsp::ProcessorParameter & zrythm::structure::tracks::TrackProcessor::get_midi_cc_param ( midi_byte_t channel,
midi_byte_t control_no )
inline
Parameters
channelChannel (0-15)
control_noControl (0-127)

Definition at line 231 of file track_processor.h.

◆ get_midi_in_port()

dsp::MidiPort & zrythm::structure::tracks::TrackProcessor::get_midi_in_port ( ) const
inline

MIDI in Port.

This port is for receiving MIDI signals from an external MIDI source.

This is also where piano roll, midi in and midi manual press will be routed to and this will be the port used to pass midi to the plugins.

Definition at line 247 of file track_processor.h.

◆ get_midi_out_port()

dsp::MidiPort & zrythm::structure::tracks::TrackProcessor::get_midi_out_port ( ) const
inline

MIDI out port, if MIDI.

Definition at line 256 of file track_processor.h.

◆ get_monitor_audio_param()

dsp::ProcessorParameter & zrythm::structure::tracks::TrackProcessor::get_monitor_audio_param ( ) const
inline

Definition at line 218 of file track_processor.h.

◆ get_mono_param()

dsp::ProcessorParameter & zrythm::structure::tracks::TrackProcessor::get_mono_param ( ) const
inline

Definition at line 203 of file track_processor.h.

◆ get_output_gain_param()

dsp::ProcessorParameter & zrythm::structure::tracks::TrackProcessor::get_output_gain_param ( ) const
inline

Definition at line 213 of file track_processor.h.

◆ get_piano_roll_port()

dsp::MidiPort & zrythm::structure::tracks::TrackProcessor::get_piano_roll_port ( ) const
inline

MIDI input for receiving MIDI signals from the piano roll (i.e., MIDI notes inside regions) or other sources.

This bypasses any MIDI transformations by transform_midi_inputs_func_.

Definition at line 268 of file track_processor.h.

◆ get_stereo_in_port()

dsp::AudioPort & zrythm::structure::tracks::TrackProcessor::get_stereo_in_port ( ) const
inline

Definition at line 192 of file track_processor.h.

◆ get_stereo_out_port()

dsp::AudioPort & zrythm::structure::tracks::TrackProcessor::get_stereo_out_port ( ) const
inline

Definition at line 197 of file track_processor.h.

◆ is_audio()

bool zrythm::structure::tracks::TrackProcessor::is_audio ( ) const
inline

Definition at line 156 of file track_processor.h.

◆ is_midi()

bool zrythm::structure::tracks::TrackProcessor::is_midi ( ) const
inlineconstexpr

Definition at line 158 of file track_processor.h.

◆ set_audio_providers_active()

void zrythm::structure::tracks::TrackProcessor::set_audio_providers_active ( ActiveAudioProviders audio_providers,
bool active )

Used to enable or disable audio providers.

For example, when a clip is launched this should be called once to disable the timeline and once more to enable the clip provider.

Note
Changes will take effect during the next processing cycle.

◆ set_handle_recording_callback()

void zrythm::structure::tracks::TrackProcessor::set_handle_recording_callback ( HandleRecordingCallback handle_rec_cb)
inline

Definition at line 151 of file track_processor.h.

◆ set_midi_providers_active()

void zrythm::structure::tracks::TrackProcessor::set_midi_providers_active ( ActiveMidiEventProviders event_providers,
bool active )

Used to enable or disable MIDI event providers.

For example, when a clip is launched this should be called once to disable the timeline and once more to enable the clip provider.

Note
Changes will take effect during the next processing cycle.

◆ timeline_audio_data_provider()

auto & zrythm::structure::tracks::TrackProcessor::timeline_audio_data_provider ( )
inline

Definition at line 273 of file track_processor.h.

◆ timeline_midi_data_provider()

auto & zrythm::structure::tracks::TrackProcessor::timeline_midi_data_provider ( )
inline

Definition at line 277 of file track_processor.h.

◆ to_json

void to_json ( nlohmann::json & j,
const TrackProcessor & tp )
friend

Definition at line 338 of file track_processor.h.


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