1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:17:35 +00:00

Piano: Use LibDSP::Keyboard for all keyboard-playing logic

The only major functional change is that the Track now needs to know
whether it's active or not, in order to listen to the keyboard (or not).

There are some bugs exposed/created by this, mainly:
* KeysWidget sometimes shows phantom notes. Those do not actually exist
  as far as debugging has revealed and do not play in the synth.
* The keyboard can lock up Piano when rapidly pressing keys. This
  appears to be a HashMap bug; I invested significant time in bugfixing
  but got nowhere.
This commit is contained in:
kleines Filmröllchen 2022-05-14 01:11:23 +02:00 committed by Linus Groh
parent a861d2b728
commit aea8a040b3
11 changed files with 83 additions and 132 deletions

View file

@ -9,6 +9,8 @@
#pragma once
#include "AK/NonnullRefPtr.h"
#include "LibDSP/Keyboard.h"
#include "Music.h"
#include "Track.h"
#include <AK/Array.h>
@ -26,30 +28,32 @@ public:
Track& current_track() { return *m_tracks[m_current_track]; }
Span<const Sample> buffer() const { return m_current_front_buffer; }
int octave() const { return m_octave; }
int octave_base() const { return (m_octave - octave_min) * 12; }
int track_count() { return m_tracks.size(); };
void set_current_track(size_t track_index)
{
VERIFY((int)track_index < track_count());
auto old_track = m_current_track;
m_current_track = track_index;
m_tracks[old_track]->set_active(false);
m_tracks[m_current_track]->set_active(true);
}
NonnullRefPtr<LibDSP::Transport> transport() const { return m_transport; }
NonnullRefPtr<LibDSP::Keyboard> keyboard() const { return m_keyboard; }
// Legacy API, do not add new users.
void time_forward(int amount);
void fill_buffer(Span<Sample>);
void reset();
void set_keyboard_note(int note, Switch note_switch);
void set_keyboard_note(int note, LibDSP::Keyboard::Switch note_switch);
void set_should_loop(bool b) { m_should_loop = b; }
void set_octave(Direction);
void set_octave(int octave);
void add_track();
int next_track_index() const;
private:
Vector<NonnullOwnPtr<Track>> m_tracks;
NonnullRefPtr<LibDSP::Transport> m_transport;
NonnullRefPtr<LibDSP::Keyboard> m_keyboard;
size_t m_current_track { 0 };
Array<Sample, sample_count> m_front_buffer;
@ -57,9 +61,5 @@ private:
Span<Sample> m_current_front_buffer { m_front_buffer.span() };
Span<Sample> m_current_back_buffer { m_back_buffer.span() };
int m_octave { 4 };
NonnullRefPtr<LibDSP::Transport> m_transport;
bool m_should_loop { true };
};