Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
midi_port.h
1// SPDX-FileCopyrightText: © 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/midi_event.h"
7#include "dsp/port.h"
8#include "utils/icloneable.h"
9#include "utils/ring_buffer.h"
10
11namespace zrythm::dsp
12{
13
17class MidiPort final
18 : public Port,
19 public PortConnectionsCacheMixin<MidiPort>,
21{
22 Q_OBJECT
23 QML_ELEMENT
24 QML_UNCREATABLE ("")
25
26public:
27 MidiPort (utils::Utf8String label, PortFlow flow);
28
29 [[gnu::hot]] void process_block (
31 const dsp::ITransport &transport,
32 const dsp::TempoMap &tempo_map) noexcept override;
33
35 const graph::GraphNode * node,
36 units::sample_rate_t sample_rate,
37 units::sample_u32_t max_block_length) override;
38
39 void release_resources () override;
40
41 void clear_buffer (std::size_t offset, std::size_t nframes) override;
42
43 friend void init_from (
44 MidiPort &obj,
45 const MidiPort &other,
46 utils::ObjectCloneType clone_type);
47
48private:
49 friend void to_json (nlohmann::json &j, const MidiPort &p)
50 {
51 to_json (j, static_cast<const Port &> (p));
52 }
53 friend void from_json (const nlohmann::json &j, MidiPort &p)
54 {
55 from_json (j, static_cast<Port &> (p));
56 }
57
58public:
63
74 std::unique_ptr<RingBuffer<dsp::MidiEvent>> midi_ring_;
75
76 BOOST_DESCRIBE_CLASS (MidiPort, (Port), (), (), ())
77};
78
79} // namespace zrythm::dsp
Interface for transport.
Definition itransport.h:16
Container for passing midi events through ports.
Definition midi_event.h:455
MIDI port specifics.
Definition midi_port.h:21
std::unique_ptr< RingBuffer< dsp::MidiEvent > > midi_ring_
Ring buffer for saving MIDI events to be used in the UI instead of directly accessing the events.
Definition midi_port.h:74
void release_resources() override
Called to release resources allocated by prepare_for_processing().
void clear_buffer(std::size_t offset, std::size_t nframes) override
Clears the port buffer.
dsp::MidiEvents midi_events_
Contains raw MIDI data (MIDI ports only).
Definition midi_port.h:62
void prepare_for_processing(const graph::GraphNode *node, units::sample_rate_t sample_rate, units::sample_u32_t max_block_length) override
Called to allocate resources required for processing.
A base class for ports used for connecting processors in the DSP graph.
Definition port.h:34
Represents a node in a DSP graph.
Definition graph_node.h:173
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