7#include "gui/dsp/port.h"
8#include "utils/icloneable.h"
10using WrappedObjectWithChangeSignal =
struct _WrappedObjectWithChangeSignal;
18#define MIDI_MAPPINGS (PROJECT->midi_mappings_)
23class MidiMapping final :
public QObject,
public ICloneable<MidiMapping>
31 MidiMapping (QObject * parent =
nullptr);
37 void set_enabled (
bool enabled) {
enabled_.store (enabled); }
39 void apply (std::array<midi_byte_t, 3> buf);
42 static constexpr auto kKeyKey =
"key"sv;
43 static constexpr auto kDevicePortKey =
"devicePort"sv;
44 static constexpr auto kDestIdKey =
"destId"sv;
45 static constexpr auto kEnabledKey =
"enabled"sv;
46 friend void to_json (nlohmann::json &j,
const MidiMapping &mapping)
49 { kKeyKey, mapping.
key_ },
52 { kEnabledKey, mapping.
enabled_.load () },
55 friend void from_json (
const nlohmann::json &j, MidiMapping &mapping)
57 j.at (kKeyKey).get_to (mapping.
key_);
59 j.at (kDestIdKey).get_to (mapping.
dest_id_);
60 mapping.
enabled_.store (j.at (kEnabledKey).get<
bool> ());
65 std::array<midi_byte_t, 3>
key_ = {};
71 std::optional<PortIdentifier::PortUuid>
dest_id_;
102 std::array<midi_byte_t, 3> buf,
117 std::array<midi_byte_t, 3> buf,
123 buf, dev_port, dest_port,
static_cast<int> (mappings_.size ()),
128 bind_track (std::array<midi_byte_t, 3> buf,
Port &dest_port,
bool fire_events)
131 buf,
nullptr, dest_port,
static_cast<int> (mappings_.size ()),
135 int get_mapping_index (
const MidiMapping &mapping)
const;
169 static constexpr auto kMappingsKey =
"mappings"sv;
170 friend void to_json (nlohmann::json &j,
const MidiMappings &mappings)
172 j[kMappingsKey] = mappings.mappings_;
174 friend void from_json (
const nlohmann::json &j, MidiMappings &mappings);
177 std::vector<std::unique_ptr<MidiMapping>> mappings_;
A lock-free thread-safe vector of MidiEvents.
A mapping from a MIDI CC value to a destination ControlPort.
std::optional< PortIdentifier::PortUuid > dest_id_
Destination.
std::unique_ptr< ExtPort > device_port_
The device that this connection will be mapped for.
std::array< midi_byte_t, 3 > key_
Raw MIDI signal.
Port * dest_
Destination pointer, for convenience.
void init_after_cloning(const MidiMapping &other, ObjectCloneType clone_type) override
Initializes the cloned object.
std::atomic< bool > enabled_
Whether this binding is enabled.
All MIDI mappings in Zrythm.
void apply(const midi_byte_t *buf)
Applies the given buffer to the matching ports.
void apply_from_cc_events(MidiEventVector &events)
Applies the events to the appropriate mapping.
void unbind(int idx, bool fire_events)
Unbinds the given binding.
int get_for_port(const Port &dest_port, std::vector< MidiMapping * > *arr) const
Get MIDI mappings for the given port.
void bind_at(std::array< midi_byte_t, 3 > buf, ExtPort *device_port, Port &dest_port, int idx, bool fire_events)
Binds the CC represented by the given raw buffer (must be size 3) to the given Port.
void init_after_cloning(const MidiMappings &other, ObjectCloneType clone_type) override
Initializes the cloned object.
The Port class represents a port in the audio processing graph.
Struct used to identify Ports in the project.
void clone_unique_ptr_container(Container &dest, const Container &src, ObjectCloneType clone_type=ObjectCloneType::Snapshot)
Clones the elements of a container of std::unique_ptr into the destination container.
uint8_t midi_byte_t
MIDI byte.