13
0

Virtual-keyboard: "Tab" to sustain (still undocumented)

This commit is contained in:
Robin Gareus 2019-11-02 23:52:29 +01:00
parent 7b25a89944
commit db08810164
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 35 additions and 13 deletions

View File

@ -211,8 +211,6 @@ APianoKeyboard::press_key (int key, int vel)
assert (key >= 0);
assert (key < NNOTES);
_maybe_stop_sustained_notes = false;
/* This is for keyboard autorepeat protection. */
if (_notes[key].pressed) {
return;
@ -247,8 +245,6 @@ APianoKeyboard::release_key (int key)
assert (key >= 0);
assert (key < NNOTES);
_maybe_stop_sustained_notes = false;
if (!_notes[key].pressed) {
return;
}
@ -284,8 +280,10 @@ APianoKeyboard::stop_sustained_notes ()
{
for (int i = 0; i < NNOTES; ++i) {
if (_notes[i].sustained) {
_notes[i].pressed = false;
_notes[i].sustained = false;
if (_notes[i].pressed) {
continue;
}
NoteOff (i); /* EMIT SIGNAL */
queue_note_draw (i);
}
@ -322,6 +320,7 @@ APianoKeyboard::bind_keys_qwerty ()
clear_notes ();
bind_key ("space", 128);
bind_key ("Tab", 129);
/* Lower keyboard row - "zxcvbnm". */
bind_key ("z", 12); /* C0 */
@ -375,6 +374,7 @@ APianoKeyboard::bind_keys_azerty ()
clear_notes ();
bind_key ("space", 128);
bind_key ("Tab", 129);
/* Lower keyboard row - "wxcvbn,". */
bind_key ("w", 12); /* C0 */
@ -418,6 +418,7 @@ APianoKeyboard::bind_keys_dvorak ()
clear_notes ();
bind_key ("space", 128);
bind_key ("Tab", 129);
/* Lower keyboard row - ";qjkxbm". */
bind_key ("semicolon", 12); /* C0 */
@ -471,6 +472,7 @@ APianoKeyboard::bind_keys_basic_qwerty ()
clear_notes ();
bind_key ("space", 128);
bind_key ("Tab", 129);
/* simple - middle rows only */
bind_key ("a", 12); /* C0 */
@ -500,6 +502,7 @@ APianoKeyboard::bind_keys_basic_qwertz ()
clear_notes ();
bind_key ("space", 128);
bind_key ("Tab", 129);
/* simple - middle rows only */
bind_key ("a", 12); /* C0 */
@ -552,6 +555,10 @@ APianoKeyboard::on_key_press_event (GdkEventKey* event)
/* Rest is used on release */
return false;
}
if (note == 129) {
toggle_sustain ();
return true;
}
note += _octave * 12;
@ -856,7 +863,6 @@ APianoKeyboard::APianoKeyboard ()
using namespace Gdk;
add_events (KEY_PRESS_MASK | KEY_RELEASE_MASK | BUTTON_PRESS_MASK | BUTTON_RELEASE_MASK | POINTER_MOTION_MASK | POINTER_MOTION_HINT_MASK);
_maybe_stop_sustained_notes = false;
_sustain_new_notes = false;
_highlight_grand_piano_range = true;
_annotate_layout = false;
@ -920,22 +926,34 @@ APianoKeyboard::set_velocities (int min_vel, int max_vel, int key_vel)
}
}
void
APianoKeyboard::toggle_sustain ()
{
if (_sustain_new_notes) {
sustain_release ();
} else {
sustain_press ();
}
}
void
APianoKeyboard::sustain_press ()
{
if (!_sustain_new_notes) {
_sustain_new_notes = true;
_maybe_stop_sustained_notes = true;
if (_sustain_new_notes) {
return;
}
_sustain_new_notes = true;
SustainChanged (true); /* EMIT SIGNAL */
}
void
APianoKeyboard::sustain_release ()
{
if (_maybe_stop_sustained_notes) {
stop_sustained_notes ();
stop_sustained_notes ();
if (_sustain_new_notes) {
_sustain_new_notes = false;
SustainChanged (false); /* EMIT SIGNAL */
}
_sustain_new_notes = false;
}
void

View File

@ -34,6 +34,7 @@ public:
sigc::signal<void, int, int> NoteOn;
sigc::signal<void, int> NoteOff;
sigc::signal<void> Rest;
sigc::signal<void,bool> SustainChanged;
enum Layout {
QWERTY,
@ -78,6 +79,7 @@ private:
void queue_note_draw (int note);
void toggle_sustain ();
void press_key (int key, int vel);
void release_key (int key);
void stop_sustained_notes ();
@ -121,7 +123,6 @@ private:
int h; /* Height of the key, in pixels. */
};
bool _maybe_stop_sustained_notes;
bool _sustain_new_notes;
bool _highlight_grand_piano_range;
bool _annotate_layout;

View File

@ -378,6 +378,9 @@ VirtualKeyboardWindow::on_key_press_event (GdkEventKey* ev)
_piano.grab_focus ();
/* handle up/down */
// XXX consider to handle these in APianoKeyboard::on_key_press_event
// and use signals. -- also subscribe SustainChanged, indicate sustain.
// TODO: pitch-bend shortcuts
if (ev->type == GDK_KEY_PRESS) {
if (ev->keyval == GDK_KEY_Left) {
_piano_octave_key.set_value (_piano_octave_key.get_value_as_int () - 1);