23 Q_PROPERTY (
int pitch READ pitch WRITE setPitch NOTIFY pitchChanged)
25 int velocity READ velocity WRITE setVelocity NOTIFY velocityChanged)
30 MidiNote (
const dsp::TempoMap &tempo_map, QObject * parent =
nullptr);
31 Q_DISABLE_COPY_MOVE (MidiNote)
32 ~MidiNote ()
override;
36 enum class Notation : std::uint8_t
46 int pitch ()
const {
return static_cast<int> (pitch_); }
47 void setPitch (
int ipitch)
49 ipitch = std::clamp (ipitch, 0, 127);
50 const auto pitch =
static_cast<midi_byte_t> (ipitch);
54 Q_EMIT pitchChanged (ipitch);
62 setPitch (
static_cast<int> (pitch_) + delta);
64 Q_SIGNAL
void pitchChanged (
int ipitch);
65 Q_INVOKABLE QString pitchAsRichText ()
const
70 int velocity ()
const {
return static_cast<int> (velocity_); }
71 void setVelocity (
int ivelocity)
73 ivelocity = std::clamp (ivelocity, 0, 127);
74 const auto velocity =
static_cast<midi_byte_t> (ivelocity);
75 if (velocity_ != velocity)
78 Q_EMIT velocityChanged (ivelocity);
81 Q_SIGNAL
void velocityChanged (
int ivelocity);
97 template <RangeOfM
idiNotePo
inters Range>
100 auto it = std::ranges::min_element (range, [] (
const auto &a,
const auto &b) {
101 return a->position ()->ticks () < b->position ()->ticks ();
103 return (it != range.end ()) ? *it :
nullptr;
109 template <RangeOfM
idiNotePo
inters Range>
114 const auto range_to_test = range | std::views::reverse;
115 auto it = std::ranges::max_element (
116 range_to_test, [] (
const auto &a,
const auto &b) {
117 return a->bounds ()->get_end_position_samples (
false)
118 < b->bounds ()->get_end_position_samples (
false);
120 return (it != range_to_test.end ()) ? *it :
nullptr;
126 template <RangeOfM
idiNotePo
inters Range>
128 -> std::optional<std::pair<midi_byte_t, midi_byte_t>>
130 auto [min_it, max_it] =
131 std::ranges::minmax_element (range, [] (
const auto &a,
const auto &b) {
132 return a->pitch () < b->pitch ();
134 if (min_it == range.end () || max_it == range.end ())
136 return std::make_pair ((*min_it)->pitch (), (*max_it)->pitch ());
139 friend void init_from (
144 static constexpr auto kVelocityKey =
"velocity"sv;
145 static constexpr auto kPitchKey =
"pitch"sv;
146 friend void to_json (nlohmann::json &j,
const MidiNote ¬e)
149 j[kVelocityKey] = note.velocity_;
150 j[kPitchKey] = note.pitch_;
152 friend void from_json (
const nlohmann::json &j, MidiNote ¬e)
155 j.at (kVelocityKey).get_to (note.velocity_);
156 j.at (kPitchKey).get_to (note.pitch_);
161 std::uint8_t velocity_{ DEFAULT_VELOCITY };
164 std::uint8_t pitch_{ 60 };
166 BOOST_DESCRIBE_CLASS (MidiNote, (
ArrangerObject), (), (), (velocity_, pitch_))