22 Q_PROPERTY (
int pitch READ pitch WRITE setPitch NOTIFY pitchChanged)
24 int velocity READ velocity WRITE setVelocity NOTIFY velocityChanged)
29 MidiNote (
const dsp::TempoMap &tempo_map, QObject * parent =
nullptr);
30 Z_DISABLE_COPY_MOVE (MidiNote)
31 ~MidiNote ()
override;
35 enum class Notation : std::uint8_t
45 int pitch ()
const {
return static_cast<int> (pitch_); }
46 void setPitch (
int ipitch)
48 ipitch = std::clamp (ipitch, 0, 127);
49 const auto pitch =
static_cast<midi_byte_t> (ipitch);
53 Q_EMIT pitchChanged (ipitch);
61 setPitch (
static_cast<int> (pitch_) + delta);
63 Q_SIGNAL
void pitchChanged (
int ipitch);
64 Q_INVOKABLE QString pitchAsRichText ()
const
69 int velocity ()
const {
return static_cast<int> (velocity_); }
70 void setVelocity (
int ivelocity)
72 ivelocity = std::clamp (ivelocity, 0, 127);
73 const auto velocity =
static_cast<midi_byte_t> (ivelocity);
74 if (velocity_ != velocity)
77 Q_EMIT velocityChanged (ivelocity);
80 Q_SIGNAL
void velocityChanged (
int ivelocity);
96 template <RangeOfM
idiNotePo
inters Range>
99 auto it = std::ranges::min_element (range, [] (
const auto &a,
const auto &b) {
100 return a->position ()->ticks () < b->position ()->ticks ();
102 return (it != range.end ()) ? *it :
nullptr;
108 template <RangeOfM
idiNotePo
inters Range>
113 const auto range_to_test = range | std::views::reverse;
114 auto it = std::ranges::max_element (
115 range_to_test, [] (
const auto &a,
const auto &b) {
116 return a->bounds ()->get_end_position_samples (
false)
117 < b->bounds ()->get_end_position_samples (
false);
119 return (it != range_to_test.end ()) ? *it :
nullptr;
125 template <RangeOfM
idiNotePo
inters Range>
127 -> std::optional<std::pair<midi_byte_t, midi_byte_t>>
129 auto [min_it, max_it] =
130 std::ranges::minmax_element (range, [] (
const auto &a,
const auto &b) {
131 return a->pitch () < b->pitch ();
133 if (min_it == range.end () || max_it == range.end ())
135 return std::make_pair ((*min_it)->pitch (), (*max_it)->pitch ());
138 friend void init_from (
143 static constexpr auto kVelocityKey =
"velocity"sv;
144 static constexpr auto kPitchKey =
"pitch"sv;
145 friend void to_json (nlohmann::json &j,
const MidiNote ¬e)
148 j[kVelocityKey] = note.velocity_;
149 j[kPitchKey] = note.pitch_;
151 friend void from_json (
const nlohmann::json &j, MidiNote ¬e)
154 j.at (kVelocityKey).get_to (note.velocity_);
155 j.at (kPitchKey).get_to (note.pitch_);
160 std::uint8_t velocity_{ DEFAULT_VELOCITY };
163 std::uint8_t pitch_{ 60 };
165 BOOST_DESCRIBE_CLASS (MidiNote, (
ArrangerObject), (), (), (velocity_, pitch_))