-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Piano. Improve semantics, better separation of concerns
- Loading branch information
1 parent
c5360e4
commit 312c324
Showing
3 changed files
with
64 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
#pragma once | ||
#include "midi_audio_stream.hpp" | ||
#include <SFML/Graphics.hpp> | ||
#include <array> | ||
#include <fluidsynth.h> | ||
#include <vector> | ||
|
||
class Piano : public sf::Drawable { | ||
public: | ||
Piano(std::array<float, 4>& pressed_note_colors); | ||
void setKeyPressed(size_t midi_note_number, bool isPressed); | ||
Piano(sf::RenderWindow& window, std::array<float, 4>& pressed_note_colors); | ||
void keyOn(int midi_note_number, int velocity); | ||
void keyOff(int midi_note_number); | ||
void keyToggle(int midi_note_number); | ||
void clearAllKeys(); | ||
std::vector<size_t> getPressedNotes(); | ||
void processEvent(sf::Event& event, sf::RenderWindow& window, fluid_synth_t* synth); | ||
fluid_synth_t* getSynth(); | ||
void processEvent(sf::Event& event); | ||
float key_aspect_ratio = 4.f; | ||
|
||
private: | ||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; | ||
void mouseEvent(sf::Event& event, sf::RenderWindow& window, fluid_synth_t* synth); | ||
void keyboardEvent(sf::Event& event, sf::RenderWindow& window, fluid_synth_t* synth); | ||
void mouseEvent(sf::Event& event); | ||
void keyboardEvent(sf::Event& event); | ||
std::array<bool, 88> keys = {}; | ||
mutable std::array<sf::RectangleShape, 88> key_sprites; | ||
sf::RenderWindow& window; | ||
MidiAudioStream mas{}; | ||
fluid_synth_t* synth = nullptr; | ||
std::array<float, 4>& note_colors; | ||
}; |