Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions include/libremidi/backends/keyboard/midi_in.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <libremidi/backends/keyboard/config.hpp>
#include <libremidi/detail/midi_in.hpp>

#include <algorithm>
#include <chrono>
#include <unordered_map>

Expand Down Expand Up @@ -54,7 +55,10 @@ class midi_in_kbd final

if (it->second >= kevent::NOTE_0 && it->second < (kevent::NOTE_0 + 128))
{
int note = it->second - kevent::NOTE_0 + 12 * m_current_octave;
const int note = it->second - kevent::NOTE_0 + 12 * m_current_octave;
if (note > 127)
return;

this->configuration.on_message(
libremidi::channel_events::note_on(0, note, m_current_velocity));
m_current_notes_scancodes[scancode] = note;
Expand All @@ -65,7 +69,7 @@ class midi_in_kbd final
}
else if (it->second >= kevent::OCT_0 && it->second < (kevent::OCT_0 + 128))
{
m_current_octave = it->second - kevent::OCT_0;
m_current_octave = std::min(it->second - kevent::OCT_0, max_octave);
}
else
{
Expand All @@ -78,10 +82,10 @@ class midi_in_kbd final
m_current_velocity = std::clamp(m_current_velocity + 10, 0, 127);
break;
case kevent::OCTAVE_MINUS:
m_current_octave = std::clamp(m_current_octave - 1, 0, 127);
m_current_octave = std::clamp(m_current_octave - 1, 0, max_octave);
break;
case kevent::OCTAVE_PLUS:
m_current_octave = std::clamp(m_current_octave + 1, 0, 127);
m_current_octave = std::clamp(m_current_octave + 1, 0, max_octave);
break;
}
}
Expand All @@ -106,6 +110,7 @@ class midi_in_kbd final
}
}

static constexpr int max_octave = 9;
int m_current_octave{3};
int m_current_velocity{80};
std::unordered_map<int, int> m_current_notes_scancodes;
Expand Down
Loading