Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
midi_panic_processor.h
1// SPDX-FileCopyrightText: © 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <atomic>
7
8#include "dsp/midi_port.h"
9#include "dsp/processor_base.h"
10
11namespace zrythm::dsp
12{
13
17class MidiPanicProcessor final : public QObject, public dsp::ProcessorBase
18{
19 Q_OBJECT
20
21public:
22 MidiPanicProcessor (
23 ProcessorBaseDependencies dependencies,
24 QObject * parent = nullptr)
25 : QObject (parent), dsp::ProcessorBase (dependencies, u8"MIDI Panic")
26 {
27 add_output_port (dependencies.port_registry_.create_object<dsp::MidiPort> (
28 u8"Panic MIDI out", dsp::PortFlow::Output));
29 }
30
36 void request_panic () { panic_.store (true); }
37
38 // ============================================================================
39 // ProcessorBase Interface
40 // ============================================================================
41
43 EngineProcessTimeInfo time_nfo,
44 const dsp::ITransport &transport,
45 const dsp::TempoMap &tempo_map) noexcept override
46 {
47 const auto panic = panic_.exchange (false);
48 if (!panic)
49 return;
50
51 // queue panic event
52 midi_out_->midi_events_.queued_events_.panic_without_lock (
53 time_nfo.local_offset_);
54 }
55
56 void custom_prepare_for_processing (
57 const graph::GraphNode * node,
58 units::sample_rate_t sample_rate,
59 nframes_t max_block_length) override
60 {
61 midi_out_ = get_output_ports ().front ().get_object_as<dsp::MidiPort> ();
62 }
63
64 void custom_release_resources () override { midi_out_ = nullptr; }
65
66 // ============================================================================
67
68private:
69 std::atomic_bool panic_;
70
71 // Processing caches
72 dsp::MidiPort * midi_out_{};
73};
74} // namespace zrythm::dsp
Interface for transport.
Definition itransport.h:17
void custom_process_block(EngineProcessTimeInfo time_nfo, const dsp::ITransport &transport, const dsp::TempoMap &tempo_map) noexcept override
Custom processor logic after processing all owned parameters.
void request_panic()
Request panic messages to be sent.
MIDI port specifics.
Definition midi_port.h:22
A base class for processors in the DSP graph.
Represents a node in a DSP graph.
Definition graph_node.h:131
uint32_t nframes_t
Frame count.
Definition types.h:58
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition types.h:133