6#include "dsp/parameter.h"
7#include "utils/icloneable.h"
8#include "utils/iobject_registry.h"
10#include <nlohmann/json_fwd.hpp>
12#define MIDI_MAPPINGS (PROJECT->midi_mappings_)
14namespace zrythm::engine::session
19class MidiMapping :
public QObject
27 Q_DISABLE_COPY_MOVE (MidiMapping)
30 friend void init_from (
32 const MidiMapping &other,
35 void set_enabled (
bool enabled) {
enabled_.store (enabled); }
37 void apply (std::array<midi_byte_t, 3> buf);
40 static constexpr auto kKeyKey =
"key"sv;
41 static constexpr auto kDeviceIdKey =
"deviceIdentifier"sv;
42 static constexpr auto kDestIdKey =
"destId"sv;
43 static constexpr auto kEnabledKey =
"enabled"sv;
44 friend void to_json (nlohmann::json &j,
const MidiMapping &mapping);
45 friend void from_json (
const nlohmann::json &j, MidiMapping &mapping);
51 std::array<midi_byte_t, 3>
key_ = {};
61 std::optional<dsp::ProcessorParameterUuidReference>
dest_id_;
71class MidiMappings final
85 std::array<midi_byte_t, 3> buf,
86 std::optional<utils::Utf8String> device_id,
87 dsp::ProcessorParameterUuidReference dest_port,
97 void unbind (
int idx,
bool fire_events);
100 std::array<midi_byte_t, 3> buf,
101 std::optional<utils::Utf8String> device_id,
102 dsp::ProcessorParameterUuidReference dest_port,
106 buf, device_id, dest_port,
static_cast<int> (mappings_.size ()),
111 std::array<midi_byte_t, 3> buf,
112 dsp::ProcessorParameterUuidReference dest_port,
116 buf, std::nullopt, dest_port,
static_cast<int> (mappings_.size ()),
120 int get_mapping_index (
const MidiMapping &mapping)
const;
145 std::vector<MidiMapping *> * arr)
const;
147 friend void init_from (
149 const MidiMappings &other,
157 static constexpr auto kMappingsKey =
"mappings"sv;
158 friend void to_json (nlohmann::json &j,
const MidiMappings &mappings);
159 friend void from_json (
const nlohmann::json &j,
MidiMappings &mappings);
162 std::vector<std::unique_ptr<MidiMapping>> mappings_;
A lock-free thread-safe vector of MidiEvents.
Processor parameter that accepts automation and modulation sources and integrates with QML and the DS...
std::optional< dsp::ProcessorParameterUuidReference > dest_id_
Destination.
std::array< midi_byte_t, 3 > key_
Raw MIDI signal.
std::optional< utils::Utf8String > device_id_
The device that this connection will be mapped for.
std::atomic< bool > enabled_
Whether this binding is enabled.
All MIDI mappings in Zrythm.
int get_for_port(const dsp::ProcessorParameter &dest_port, std::vector< MidiMapping * > *arr) const
Get MIDI mappings for the given port.
void unbind(int idx, bool fire_events)
Unbinds the given binding.
void apply_from_cc_events(const dsp::MidiEventVector &events)
Applies the events to the appropriate mapping.
void apply(const midi_byte_t *buf)
Applies the given buffer to the matching ports.
void bind_at(std::array< midi_byte_t, 3 > buf, std::optional< utils::Utf8String > device_id, dsp::ProcessorParameterUuidReference dest_port, int idx, bool fire_events)
Binds the CC represented by the given raw buffer (must be size 3) to the given Port.
Abstract interface for a UUID-keyed object registry.
std::uint8_t midi_byte_t
MIDI byte.