16class PianoRollTrackMixin :
public QObject
20 bool drumMode READ drumMode WRITE setDrumMode NOTIFY drumModeChanged)
22 bool passthroughMidiInput READ passthroughMidiInput WRITE
23 setPassthroughMidiInput NOTIFY passthroughMidiInputChanged)
25 std::uint8_t midiChannel READ midiChannel WRITE setMidiChannel NOTIFY
30 PianoRollTrackMixin (QObject * parent =
nullptr);
31 Z_DISABLE_COPY_MOVE (PianoRollTrackMixin)
32 ~PianoRollTrackMixin ()
override =
default;
38 std::uint8_t midiChannel ()
const {
return midi_ch_; }
39 void setMidiChannel (std::uint8_t midi_ch)
41 midi_ch = std::clamp (
42 midi_ch,
static_cast<std::uint8_t
> (1),
static_cast<std::uint8_t
> (16));
43 if (midi_ch_ == midi_ch)
47 Q_EMIT midiChannelChanged (midi_ch);
49 Q_SIGNAL
void midiChannelChanged (std::uint8_t midi_ch);
51 bool passthroughMidiInput ()
const {
return passthrough_midi_input_; }
52 void setPassthroughMidiInput (
bool passthrough)
54 if (passthrough_midi_input_ == passthrough)
57 passthrough_midi_input_ = passthrough;
58 Q_EMIT passthroughMidiInputChanged (passthrough);
60 Q_SIGNAL
void passthroughMidiInputChanged (
bool passthrough);
62 bool drumMode ()
const {
return drum_mode_; }
63 void setDrumMode (
bool drum_mode)
65 if (drum_mode_ == drum_mode)
68 drum_mode_ = drum_mode;
69 Q_EMIT drumModeChanged (drum_mode);
71 Q_SIGNAL
void drumModeChanged (
bool drum_mode);
75 bool allow_only_specific_midi_channels ()
const
77 return midi_channels_.has_value ();
79 auto &midi_channels_to_allow ()
const {
return midi_channels_.value (); }
87 if (!passthrough_midi_input_)
94 static constexpr auto kDrumModeKey =
"drumMode"sv;
95 static constexpr auto kMidiChKey =
"midiCh"sv;
96 static constexpr auto kPassthroughMidiInputKey =
"passthroughMidiInput"sv;
97 static constexpr auto kMidiChannelsKey =
"midiChannels"sv;
98 friend void to_json (nlohmann::json &j,
const PianoRollTrackMixin &track)
100 j[kDrumModeKey] = track.drum_mode_;
101 j[kMidiChKey] = track.midi_ch_;
102 j[kPassthroughMidiInputKey] = track.passthrough_midi_input_.load ();
103 j[kMidiChannelsKey] = track.midi_channels_;
105 friend void from_json (
const nlohmann::json &j, PianoRollTrackMixin &track)
107 j.at (kDrumModeKey).get_to (track.drum_mode_);
108 j.at (kMidiChKey).get_to (track.midi_ch_);
109 bool passthrough_midi_input{};
110 j.at (kPassthroughMidiInputKey).get_to (passthrough_midi_input);
111 track.passthrough_midi_input_.store (passthrough_midi_input);
112 if (j.contains (kMidiChannelsKey))
114 j.at (kMidiChannelsKey).get_to (track.midi_channels_);
118 friend void init_from (
119 PianoRollTrackMixin &obj,
120 const PianoRollTrackMixin &other,
127 bool drum_mode_ =
false;
139 std::atomic_bool passthrough_midi_input_ =
false;
146 std::optional<std::array<bool, 16>> midi_channels_;