Vital
Loading...
Searching...
No Matches
SynthComputerKeyboard Class Reference

Provides a computer-keyboard-based MIDI input mechanism for the Vital standalone application. More...

#include <synth_computer_keyboard.h>

Inheritance diagram for SynthComputerKeyboard:
vital::StringLayout

Public Member Functions

 SynthComputerKeyboard ()=delete
 Deleted default constructor to ensure that a SoundEngine and MidiKeyboardState are provided.
 
 SynthComputerKeyboard (vital::SoundEngine *synth, MidiKeyboardState *keyboard_state)
 Constructs a SynthComputerKeyboard tied to a given Vital SoundEngine and MidiKeyboardState.
 
 ~SynthComputerKeyboard ()
 Destructor. Cleans up any resources.
 
void changeKeyboardOffset (int new_offset)
 Changes the base offset of the computer keyboard notes.
 
bool keyPressed (const KeyPress &key, Component *origin) override
 Called when a key is pressed.
 
bool keyStateChanged (bool isKeyDown, Component *origin) override
 Called when a key state changes (pressed or released).
 
- Public Member Functions inherited from vital::StringLayout
 StringLayout ()
 Constructs a StringLayout with no keys and an empty layout.
 
std::wstring getLayout ()
 Retrieves the current keyboard layout (a wstring of character-to-note mappings).
 
void setLayout (const std::wstring &layout)
 Sets the current keyboard layout.
 
wchar_t getUpKey ()
 Gets the character assigned to increase the octave.
 
void setUpKey (wchar_t up_key)
 Sets the character assigned to increase the octave.
 
wchar_t getDownKey ()
 Gets the character assigned to decrease the octave.
 
void setDownKey (wchar_t down_key)
 Sets the character assigned to decrease the octave.
 

Static Public Attributes

static constexpr int kKeyboardMidiChannel = 1
 The MIDI channel used for the computer keyboard input.
 

Additional Inherited Members

- Protected Attributes inherited from vital::StringLayout
std::wstring layout_
 The mapping of keys to notes.
 
int up_key_
 The key code (wchar_t) for octave up.
 
int down_key_
 The key code (wchar_t) for octave down.
 

Detailed Description

Provides a computer-keyboard-based MIDI input mechanism for the Vital standalone application.

SynthComputerKeyboard maps certain keys on a computer keyboard to MIDI note on/off events, allowing users to play notes without a hardware MIDI controller. It also supports shifting the keyboard layout up and down octaves via dedicated keys.

This class implements JUCE's KeyListener interface to receive and respond to keyboard events.

Constructor & Destructor Documentation

◆ SynthComputerKeyboard() [1/2]

SynthComputerKeyboard::SynthComputerKeyboard ( )
delete

Deleted default constructor to ensure that a SoundEngine and MidiKeyboardState are provided.

◆ SynthComputerKeyboard() [2/2]

SynthComputerKeyboard::SynthComputerKeyboard ( vital::SoundEngine * synth,
MidiKeyboardState * keyboard_state )

Constructs a SynthComputerKeyboard tied to a given Vital SoundEngine and MidiKeyboardState.

Parameters
synthA pointer to the Vital::SoundEngine, used to handle corrections in time and audio state.
keyboard_stateA pointer to a MidiKeyboardState that tracks the active note on/off states.

◆ ~SynthComputerKeyboard()

SynthComputerKeyboard::~SynthComputerKeyboard ( )

Destructor. Cleans up any resources.

Member Function Documentation

◆ changeKeyboardOffset()

void SynthComputerKeyboard::changeKeyboardOffset ( int new_offset)

Changes the base offset of the computer keyboard notes.

For example, shifting the keyboard up or down one octave changes which MIDI notes the keys trigger.

Parameters
new_offsetThe new keyboard offset in semitones (MIDI note numbers).

◆ keyPressed()

bool SynthComputerKeyboard::keyPressed ( const KeyPress & key,
Component * origin )
override

Called when a key is pressed.

Parameters
keyThe KeyPress representing the pressed key.
originThe Component that originated the event.
Returns
True if the event was handled; false otherwise.

◆ keyStateChanged()

bool SynthComputerKeyboard::keyStateChanged ( bool isKeyDown,
Component * origin )
override

Called when a key state changes (pressed or released).

This function detects when keys mapped to notes are pressed or released, and sends note-on or note-off messages to the synthesizer accordingly.

Parameters
isKeyDownTrue if a key is currently pressed; false if released.
originThe Component that originated the event.
Returns
True if the event was handled; false otherwise.

Member Data Documentation

◆ kKeyboardMidiChannel

int SynthComputerKeyboard::kKeyboardMidiChannel = 1
staticconstexpr

The MIDI channel used for the computer keyboard input.


The documentation for this class was generated from the following files: