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 (
40 const dsp::TempoMapWrapper &tempo_map_wrapper,
41 QObject * parent = nullptr);
42 Q_DISABLE_COPY_MOVE (MidiControlEvent)
43 ~MidiControlEvent () override;
44
45 dsp::ContentPosition * position () const override
46 {
47 return qobject_cast<dsp::ContentPosition *> (ArrangerObject::position ());
48 }
49
50 static constexpr int kMaxChannel = 15;
51 static constexpr int kMaxController = 127;
52 static constexpr int kMaxValue7Bit = 127;
53 static constexpr int kMaxValuePitchBend = 16383;
54
55 EventType controlType () const;
56 void setControlType (EventType type);
57 Q_SIGNAL void controlTypeChanged (EventType);
58
59 int channel () const { return static_cast<int> (channel_); }
60 void setChannel (int ch);
61 Q_SIGNAL void channelChanged (int);
62
63 int controller () const { return static_cast<int> (controller_); }
64 void setController (int ctrl);
65 Q_SIGNAL void controllerChanged (int);
66
67 int value () const { return static_cast<int> (value_); }
68 void setValue (int val);
69 Q_SIGNAL void valueChanged (int);
70
71 EventType controlEventType () const { return type_; }
72 std::uint8_t midiChannel () const { return channel_; }
73 std::uint8_t midiController () const { return controller_; }
74 std::uint16_t midiValue () const { return value_; }
75
76private:
77 int maxValueForType () const;
78
79 friend void init_from (
80 MidiControlEvent &obj,
81 const MidiControlEvent &other,
82 utils::ObjectCloneType clone_type);
83
84 static constexpr auto kTypeKey = "type"sv;
85 static constexpr auto kChannelKey = "channel"sv;
86 static constexpr auto kControllerKey = "controller"sv;
87 static constexpr auto kValueKey = "value"sv;
88 friend void to_json (nlohmann::json &j, const MidiControlEvent &ev);
89 friend void from_json (const nlohmann::json &j, MidiControlEvent &ev);
90
91 EventType type_{ EventType::ControlChange };
92 std::uint8_t channel_{ 0 };
93 std::uint8_t controller_{ 0 };
94 std::uint16_t value_{ 0 };
95
96 BOOST_DESCRIBE_CLASS (
97 MidiControlEvent,
99 (),
100 (),
101 (type_, channel_, controller_, value_))
102};
103
104}
A Position whose ticks are content-space (clip-local) ticks.
Definition position.h:118
ArrangerObject(Type type, const dsp::TempoMapWrapper &tempo_map_wrapper, ArrangerObjectFeatures features, QObject *parent=nullptr) noexcept
Construct a new ArrangerObject.