4#include "sound_engine.h"
7 MidiKeyboardState* keyboard_state) {
9 keyboard_state_ = keyboard_state;
21 for (
int i = 0; i <
layout_.length(); ++i) {
22 int note = computer_keyboard_offset_ + i;
24 keys_pressed_.erase(
layout_[i]);
39 bool consumed =
false;
41 for (
int i = 0; i <
layout_.length(); ++i) {
42 int note = computer_keyboard_offset_ + i;
43 ModifierKeys modifiers = ModifierKeys::getCurrentModifiersRealtime();
46 if (KeyPress::isKeyCurrentlyDown(
layout_[i]) &&
47 !keys_pressed_.count(
layout_[i]) && isKeyDown && !modifiers.isCommandDown()) {
48 keys_pressed_.insert(
layout_[i]);
52 else if (!KeyPress::isKeyCurrentlyDown(
layout_[i]) && keys_pressed_.count(
layout_[i])) {
53 keys_pressed_.erase(
layout_[i]);
60 if (KeyPress::isKeyCurrentlyDown(
down_key_)) {
71 if (KeyPress::isKeyCurrentlyDown(
up_key_)) {
72 if (!keys_pressed_.count(
up_key_)) {
82 if (KeyPress::isKeyCurrentlyDown(KeyPress::spaceKey)) {
83 if (!keys_pressed_.count(
' ')) {
84 keys_pressed_.insert(
' ');
90 keys_pressed_.erase(
' ');
bool keyStateChanged(bool isKeyDown, Component *origin) override
Called when a key state changes (pressed or released).
Definition synth_computer_keyboard.cpp:38
bool keyPressed(const KeyPress &key, Component *origin) override
Called when a key is pressed.
Definition synth_computer_keyboard.cpp:32
void changeKeyboardOffset(int new_offset)
Changes the base offset of the computer keyboard notes.
Definition synth_computer_keyboard.cpp:19
static constexpr int kKeyboardMidiChannel
The MIDI channel used for the computer keyboard input.
Definition synth_computer_keyboard.h:26
~SynthComputerKeyboard()
Destructor. Cleans up any resources.
Definition synth_computer_keyboard.cpp:16
SynthComputerKeyboard()=delete
Deleted default constructor to ensure that a SoundEngine and MidiKeyboardState are provided.
Core class responsible for handling note events, oversampling, and the main effects chain.
Definition sound_engine.h:33
void correctToTime(double seconds) override
Synchronizes all time-based modules to a given time, e.g. for timeline-based automation.
Definition sound_engine.cpp:314
int up_key_
The key code (wchar_t) for octave up.
Definition synth_types.h:185
std::wstring layout_
The mapping of keys to notes.
Definition synth_types.h:184
int down_key_
The key code (wchar_t) for octave down.
Definition synth_types.h:186
force_inline int iclamp(int value, int min_val, int max_val)
Clamps an integer between [min_val, max_val].
Definition utils.h:250
constexpr wchar_t kDefaultKeyboardOctaveUp
Default key for octave-up action in the computer keyboard layout.
Definition synth_constants.h:76
constexpr int kNotesPerOctave
Number of semitones per octave.
Definition common.h:51
const std::wstring kDefaultKeyboard
The default keyboard layout (QWERTY-based) mapping keys to notes.
Definition synth_constants.h:82
constexpr int kDefaultKeyboardOffset
Default starting octave offset for the computer keyboard layout.
Definition synth_constants.h:73
constexpr int kMidiSize
MIDI note count (0-127).
Definition common.h:44
constexpr wchar_t kDefaultKeyboardOctaveDown
Default key for octave-down action in the computer keyboard layout.
Definition synth_constants.h:79