diff --git a/include/libremidi/backends/alsa_raw/midi_in.hpp b/include/libremidi/backends/alsa_raw/midi_in.hpp index d5f5a65..fda1b36 100644 --- a/include/libremidi/backends/alsa_raw/midi_in.hpp +++ b/include/libremidi/backends/alsa_raw/midi_in.hpp @@ -144,7 +144,8 @@ class midi_in_impl while ((err = snd.rawmidi.read(this->midiport_, bytes, nbytes)) > 0) { const auto to_ns = [this] { return absolute_timestamp(); }; - decoder_.on_bytes({bytes, bytes + err}, decoder_.timestamp(to_ns, 0)); + m_processing.on_bytes( + {bytes, bytes + err}, m_processing.timestamp(to_ns, 0)); } return err; } @@ -169,7 +170,8 @@ class midi_in_impl const auto to_ns = [ts] { return static_cast(ts.tv_sec) * 1'000'000'000 + static_cast(ts.tv_nsec); }; - decoder_.on_bytes({bytes, bytes + err}, decoder_.timestamp(to_ns, 0)); + m_processing.on_bytes( + {bytes, bytes + err}, m_processing.timestamp(to_ns, 0)); } return err; } @@ -189,7 +191,7 @@ class midi_in_impl snd_rawmidi_t* midiport_{}; std::vector fds_; - midi1::input_state_machine decoder_{this->configuration}; + midi1::input_state_machine m_processing{this->configuration}; }; class midi_in_alsa_raw_threaded : public midi_in_impl diff --git a/include/libremidi/backends/winmm/midi_in.hpp b/include/libremidi/backends/winmm/midi_in.hpp index e482218..f04d57e 100644 --- a/include/libremidi/backends/winmm/midi_in.hpp +++ b/include/libremidi/backends/winmm/midi_in.hpp @@ -240,8 +240,7 @@ class midi_in_winmm final const auto* sysex = reinterpret_cast(midiMessage); if(inputStatus == MIM_LONGERROR) { - self.m_processing.message.bytes.clear(); - self.m_processing.state = self.m_processing.main; + self.m_processing.reset(); } else if (!self.configuration.ignore_sysex) { diff --git a/include/libremidi/detail/midi_stream_decoder.hpp b/include/libremidi/detail/midi_stream_decoder.hpp index 1772729..b69fc6b 100644 --- a/include/libremidi/detail/midi_stream_decoder.hpp +++ b/include/libremidi/detail/midi_stream_decoder.hpp @@ -102,6 +102,14 @@ namespace midi1 struct input_state_machine : input_state_machine_base { using input_state_machine_base::input_state_machine_base; + + void reset() + { + message.bytes.clear(); + message.timestamp = {}; + state = main; + } + bool has_finished_sysex(std::span bytes) const noexcept { return (((bytes.front() == 0xF0) || (state == in_sysex)) && (bytes.back() == 0xF7));