Zrythm v2.0.0-DEV
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 QObject,
19 public Port,
20 public PortConnectionsCacheMixin<MidiPort>,
22{
23 Q_OBJECT
24 QML_ELEMENT
25 QML_UNCREATABLE ("")
26
27public:
28 MidiPort (utils::Utf8String label, PortFlow flow);
29
30 [[gnu::hot]] void process_block (
31 EngineProcessTimeInfo time_nfo,
32 const dsp::ITransport &transport) noexcept override;
33
34 void
35 prepare_for_processing (sample_rate_t sample_rate, nframes_t max_block_length)
36 override;
37
38 void release_resources () override;
39
40 void clear_buffer (std::size_t offset, std::size_t nframes) override;
41
42 friend void init_from (
43 MidiPort &obj,
44 const MidiPort &other,
45 utils::ObjectCloneType clone_type);
46
47private:
48 friend void to_json (nlohmann::json &j, const MidiPort &p)
49 {
50 to_json (j, static_cast<const Port &> (p));
51 }
52 friend void from_json (const nlohmann::json &j, MidiPort &p)
53 {
54 from_json (j, static_cast<Port &> (p));
55 }
56
57public:
62
73 std::unique_ptr<RingBuffer<dsp::MidiEvent>> midi_ring_;
74
75 BOOST_DESCRIBE_CLASS (MidiPort, (Port), (), (), ())
76};
77
78} // namespace zrythm::dsp
Interface for transport.
Definition itransport.h:17
Container for passing midi events through ports.
Definition midi_event.h:440
MIDI port specifics.
Definition midi_port.h:22
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:73
void release_resources() override
Called to release resources allocated by prepare_for_processing().
void prepare_for_processing(sample_rate_t sample_rate, nframes_t max_block_length) override
Called to allocate resources required 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:61
A base class for ports used for connecting processors in the DSP graph.
Definition port.h:30
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:38
uint32_t sample_rate_t
Sample rate.
Definition types.h:61
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:136