Skip to content

Commit

Permalink
[ci] Small refactors, fix winmm backend
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Aug 25, 2024
1 parent 3d241f6 commit b381443
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions include/libremidi/backends/alsa_raw/midi_in.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<timestamp_info>(to_ns, 0));
m_processing.on_bytes(
{bytes, bytes + err}, m_processing.timestamp<timestamp_info>(to_ns, 0));
}
return err;
}
Expand All @@ -169,7 +170,8 @@ class midi_in_impl
const auto to_ns = [ts] {
return static_cast<int64_t>(ts.tv_sec) * 1'000'000'000 + static_cast<int64_t>(ts.tv_nsec);
};
decoder_.on_bytes({bytes, bytes + err}, decoder_.timestamp<timestamp_info>(to_ns, 0));
m_processing.on_bytes(
{bytes, bytes + err}, m_processing.timestamp<timestamp_info>(to_ns, 0));
}
return err;
}
Expand All @@ -189,7 +191,7 @@ class midi_in_impl

snd_rawmidi_t* midiport_{};
std::vector<pollfd> 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
Expand Down
3 changes: 1 addition & 2 deletions include/libremidi/backends/winmm/midi_in.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ class midi_in_winmm final
const auto* sysex = reinterpret_cast<MIDIHDR*>(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)
{
Expand Down
8 changes: 8 additions & 0 deletions include/libremidi/detail/midi_stream_decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ namespace midi1
struct input_state_machine : input_state_machine_base<input_configuration>
{
using input_state_machine_base::input_state_machine_base;

void reset()
{
message.bytes.clear();
message.timestamp = {};
state = main;
}

bool has_finished_sysex(std::span<const uint8_t> bytes) const noexcept
{
return (((bytes.front() == 0xF0) || (state == in_sysex)) && (bytes.back() == 0xF7));
Expand Down

0 comments on commit b381443

Please sign in to comment.