Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
midi_control_event.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <cstdint>
7
8#include "structure/arrangement/arranger_object.h"
9
10#include <nlohmann/json_fwd.hpp>
11
12namespace zrythm::structure::arrangement
13{
14
15class MidiControlEvent final : public ArrangerObject
16{
17 Q_OBJECT
18 Q_PROPERTY (
19 EventType controlType READ controlType WRITE setControlType NOTIFY
20 controlTypeChanged)
21 Q_PROPERTY (int channel READ channel WRITE setChannel NOTIFY channelChanged)
22 Q_PROPERTY (
23 int controller READ controller WRITE setController NOTIFY controllerChanged)
24 Q_PROPERTY (int value READ value WRITE setValue NOTIFY valueChanged)
25 QML_ELEMENT
26 QML_UNCREATABLE ("")
27
28public:
29 enum class EventType : std::uint8_t
30 {
31 ControlChange,
32 PitchBend,
33 ChannelPressure,
34 PolyKeyPressure,
35 ProgramChange,
36 };
37 Q_ENUM (EventType)
38
39 MidiControlEvent (const dsp::TempoMap &tempo_map, QObject * parent = nullptr);
40 Q_DISABLE_COPY_MOVE (MidiControlEvent)
41 ~MidiControlEvent () override;
42
43 static constexpr int kMaxChannel = 15;
44 static constexpr int kMaxController = 127;
45 static constexpr int kMaxValue7Bit = 127;
46 static constexpr int kMaxValuePitchBend = 16383;
47
48 EventType controlType () const;
49 void setControlType (EventType type);
50 Q_SIGNAL void controlTypeChanged (EventType);
51
52 int channel () const { return static_cast<int> (channel_); }
53 void setChannel (int ch);
54 Q_SIGNAL void channelChanged (int);
55
56 int controller () const { return static_cast<int> (controller_); }
57 void setController (int ctrl);
58 Q_SIGNAL void controllerChanged (int);
59
60 int value () const { return static_cast<int> (value_); }
61 void setValue (int val);
62 Q_SIGNAL void valueChanged (int);
63
64 EventType controlEventType () const { return type_; }
65 std::uint8_t midiChannel () const { return channel_; }
66 std::uint8_t midiController () const { return controller_; }
67 std::uint16_t midiValue () const { return value_; }
68
69private:
70 int maxValueForType () const;
71
72 friend void init_from (
73 MidiControlEvent &obj,
74 const MidiControlEvent &other,
75 utils::ObjectCloneType clone_type);
76
77 static constexpr auto kTypeKey = "type"sv;
78 static constexpr auto kChannelKey = "channel"sv;
79 static constexpr auto kControllerKey = "controller"sv;
80 static constexpr auto kValueKey = "value"sv;
81 friend void to_json (nlohmann::json &j, const MidiControlEvent &ev);
82 friend void from_json (const nlohmann::json &j, MidiControlEvent &ev);
83
84 EventType type_{ EventType::ControlChange };
85 std::uint8_t channel_{ 0 };
86 std::uint8_t controller_{ 0 };
87 std::uint16_t value_{ 0 };
88
89 BOOST_DESCRIBE_CLASS (
90 MidiControlEvent,
92 (),
93 (),
94 (type_, channel_, controller_, value_))
95};
96
97}
ArrangerObject(Type type, const dsp::TempoMap &tempo_map, ArrangerObjectFeatures features, QObject *parent=nullptr) noexcept
Construct a new ArrangerObject.