Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
velocity.h
1// SPDX-FileCopyrightText: © 2019-2022, 2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#ifndef __AUDIO_VELOCITY_H__
5#define __AUDIO_VELOCITY_H__
6
7#include "gui/dsp/arranger_object.h"
8#include "gui/dsp/region_owned_object.h"
9#include "utils/icloneable.h"
10
11class MidiNote;
12class MidiRegion;
13
19
23constexpr uint8_t VELOCITY_DEFAULT = 90;
24
28class Velocity final : public QObject, public ICloneable<Velocity>
29{
30 Q_OBJECT
31 QML_ELEMENT
32 Q_PROPERTY (int value READ getValue WRITE setValue NOTIFY valueChanged)
33public:
34 using VelocityValueT = midi_byte_t;
35 Velocity (QObject * parent = nullptr);
36
37 // ========================================================================
38 // QML Interface
39 // ========================================================================
40
41 int getValue () const { return static_cast<int> (vel_); }
42
43 void setValue (int ival)
44 {
45 const auto vel = static_cast<VelocityValueT> (ival);
46 if (vel_ != vel)
47 {
48 vel_ = vel;
49 Q_EMIT valueChanged ();
50 }
51 }
52 Q_SIGNAL void valueChanged ();
53
54 // ========================================================================
55
61 void set_val (int val);
62
66 // MidiNote * get_midi_note () const;
67
68#if 0
69 static const char * setting_enum_to_str (size_t index);
70
71 static size_t setting_str_to_enum (const char * str);
72#endif
73
74 void init_after_cloning (const Velocity &other, ObjectCloneType clone_type)
75 override;
76
77private:
78 static constexpr std::string_view kVelocityKey = "value";
79 friend void to_json (nlohmann::json &j, const Velocity &velocity)
80 {
81 j[kVelocityKey] = velocity.vel_;
82 }
83 friend void from_json (const nlohmann::json &j, Velocity &velocity)
84 {
85 j.at (kVelocityKey).get_to (velocity.vel_);
86 }
87
88public:
90 // MidiNote * midi_note_ = nullptr;
91
93 VelocityValueT vel_ = 0;
94
96 VelocityValueT vel_at_start_ = 0;
97};
98
99inline bool
100operator== (const Velocity &lhs, const Velocity &rhs)
101{
102 return lhs.vel_ == rhs.vel_;
103}
104
108
109#endif
A MIDI note inside a Region shown in the piano roll.
Definition midi_note.h:31
A Region containing MIDI events.
Definition midi_region.h:43
The MidiNote velocity.
Definition velocity.h:29
void init_after_cloning(const Velocity &other, ObjectCloneType clone_type) override
Returns the owner MidiNote.
VelocityValueT vel_
Pointer back to the MIDI note (this is also the QObject parent).
Definition velocity.h:93
void set_val(int val)
Sets the velocity to the given value.
VelocityValueT vel_at_start_
Velocity at drag begin - used for ramp actions only.
Definition velocity.h:96
constexpr uint8_t VELOCITY_DEFAULT
Default velocity.
Definition velocity.h:23
ObjectCloneType
Definition icloneable.h:25
uint8_t midi_byte_t
MIDI byte.
Definition types.h:59