Rename KeyboardLayout to PianoKeyBindings

This is to prevent polluting the global namespace with a
symbol name that is likely to cause conflicts.
This commit is contained in:
Robin Gareus 2020-04-07 18:38:33 +02:00
parent d4d57c844f
commit 1eb98316a3
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
6 changed files with 31 additions and 31 deletions

View file

@ -20,19 +20,19 @@
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
#include "keyboardlayout.h" #include "piano_key_bindings.h"
KeyboardLayout::KeyboardLayout () PianoKeyBindings::PianoKeyBindings ()
{ {
bind_keys_qwerty (); bind_keys_qwerty ();
} }
KeyboardLayout::~KeyboardLayout () PianoKeyBindings::~PianoKeyBindings ()
{ {
} }
void void
KeyboardLayout::set_layout (Layout layout) PianoKeyBindings::set_layout (Layout layout)
{ {
switch (layout) { switch (layout) {
case QWERTY: case QWERTY:
@ -57,7 +57,7 @@ KeyboardLayout::set_layout (Layout layout)
} }
int int
KeyboardLayout::key_binding (const char* key) const PianoKeyBindings::key_binding (const char* key) const
{ {
std::map<std::string, int>::const_iterator kv; std::map<std::string, int>::const_iterator kv;
if (key && (kv = _key_bindings.find (key)) != _key_bindings.end ()) { if (key && (kv = _key_bindings.find (key)) != _key_bindings.end ()) {
@ -67,7 +67,7 @@ KeyboardLayout::key_binding (const char* key) const
} }
const char* const char*
KeyboardLayout::note_binding (int note) const PianoKeyBindings::note_binding (int note) const
{ {
std::map<int, std::string>::const_iterator kv = _note_bindings.find (note); std::map<int, std::string>::const_iterator kv = _note_bindings.find (note);
if (kv == _note_bindings.end ()) { if (kv == _note_bindings.end ()) {
@ -76,8 +76,8 @@ KeyboardLayout::note_binding (int note) const
return kv->second.c_str(); return kv->second.c_str();
} }
KeyboardLayout::Layout PianoKeyBindings::Layout
KeyboardLayout::layout (std::string const& l) PianoKeyBindings::layout (std::string const& l)
{ {
if (l == "QWERTY") { if (l == "QWERTY") {
return QWERTY; return QWERTY;
@ -99,7 +99,7 @@ KeyboardLayout::layout (std::string const& l)
} }
const char* const char*
KeyboardLayout::get_keycode (GdkEventKey* event) PianoKeyBindings::get_keycode (GdkEventKey* event)
{ {
/* We're not using event->keyval, because we need keyval with level set to 0. /* We're not using event->keyval, because we need keyval with level set to 0.
E.g. if user holds Shift and presses '7', we want to get a '7', not '&'. */ E.g. if user holds Shift and presses '7', we want to get a '7', not '&'. */
@ -122,21 +122,21 @@ KeyboardLayout::get_keycode (GdkEventKey* event)
} }
void void
KeyboardLayout::bind_key (const char* key, int note) PianoKeyBindings::bind_key (const char* key, int note)
{ {
_key_bindings[key] = note; _key_bindings[key] = note;
_note_bindings[note] = key; _note_bindings[note] = key;
} }
void void
KeyboardLayout::clear_notes () PianoKeyBindings::clear_notes ()
{ {
_key_bindings.clear (); _key_bindings.clear ();
_note_bindings.clear (); _note_bindings.clear ();
} }
void void
KeyboardLayout::bind_keys_qwerty () PianoKeyBindings::bind_keys_qwerty ()
{ {
clear_notes (); clear_notes ();
@ -187,7 +187,7 @@ KeyboardLayout::bind_keys_qwerty ()
} }
void void
KeyboardLayout::bind_keys_qwertz () PianoKeyBindings::bind_keys_qwertz ()
{ {
bind_keys_qwerty (); bind_keys_qwerty ();
@ -197,7 +197,7 @@ KeyboardLayout::bind_keys_qwertz ()
} }
void void
KeyboardLayout::bind_keys_azerty () PianoKeyBindings::bind_keys_azerty ()
{ {
clear_notes (); clear_notes ();
@ -241,7 +241,7 @@ KeyboardLayout::bind_keys_azerty ()
} }
void void
KeyboardLayout::bind_keys_dvorak () PianoKeyBindings::bind_keys_dvorak ()
{ {
clear_notes (); clear_notes ();
@ -295,7 +295,7 @@ KeyboardLayout::bind_keys_dvorak ()
} }
void void
KeyboardLayout::bind_keys_basic_qwerty () PianoKeyBindings::bind_keys_basic_qwerty ()
{ {
clear_notes (); clear_notes ();
@ -325,7 +325,7 @@ KeyboardLayout::bind_keys_basic_qwerty ()
} }
void void
KeyboardLayout::bind_keys_basic_qwertz () PianoKeyBindings::bind_keys_basic_qwertz ()
{ {
clear_notes (); clear_notes ();

View file

@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef _KEYBOARD_LAYOUT_H_ #ifndef _PIANO_KEY_BINDINGS_H_
#define _KEYBOARD_LAYOUT_H_ #define _PIANO_KEY_BINDINGS_H_
#include <map> #include <map>
#include <string> #include <string>
@ -29,11 +29,11 @@
* Class for mapping PC keyboard keys to note pitches. Used by the * Class for mapping PC keyboard keys to note pitches. Used by the
* Virtual MIDI Keyboard. * Virtual MIDI Keyboard.
*/ */
class KeyboardLayout class PianoKeyBindings
{ {
public: public:
KeyboardLayout (); PianoKeyBindings ();
~KeyboardLayout (); ~PianoKeyBindings ();
enum Layout { enum Layout {
QWERTY, QWERTY,

View file

@ -357,7 +357,7 @@ APianoKeyboard::on_key_press_event (GdkEventKey* event)
return true; return true;
} }
char const* key = KeyboardLayout::get_keycode (event); char const* key = PianoKeyBindings::get_keycode (event);
int note = _keyboard_layout.key_binding (key); int note = _keyboard_layout.key_binding (key);
if (note < -1) { if (note < -1) {
@ -408,7 +408,7 @@ APianoKeyboard::on_key_release_event (GdkEventKey* event)
return true; return true;
} }
char const* key = KeyboardLayout::get_keycode (event); char const* key = PianoKeyBindings::get_keycode (event);
if (!key) { if (!key) {
return false; return false;
@ -893,7 +893,7 @@ APianoKeyboard::set_octave_range (int octave_range)
} }
void void
APianoKeyboard::set_keyboard_layout (KeyboardLayout::Layout layout) APianoKeyboard::set_keyboard_layout (PianoKeyBindings::Layout layout)
{ {
_keyboard_layout.set_layout (layout); _keyboard_layout.set_layout (layout);
queue_draw (); queue_draw ();

View file

@ -23,7 +23,7 @@
#include <map> #include <map>
#include <gtkmm/drawingarea.h> #include <gtkmm/drawingarea.h>
#include "keyboardlayout.h" #include "piano_key_bindings.h"
#define NNOTES (128) #define NNOTES (128)
@ -54,7 +54,7 @@ public:
void set_monophonic (bool monophonic); void set_monophonic (bool monophonic);
void set_octave (int octave); void set_octave (int octave);
void set_octave_range (int octave_range); void set_octave_range (int octave_range);
void set_keyboard_layout (KeyboardLayout::Layout layout); void set_keyboard_layout (PianoKeyBindings::Layout layout);
void set_velocities (int min_vel, int max_vel, int key_vel); void set_velocities (int min_vel, int max_vel, int key_vel);
protected: protected:
@ -125,7 +125,7 @@ private:
PKNote _notes[NNOTES]; PKNote _notes[NNOTES];
KeyboardLayout _keyboard_layout; PianoKeyBindings _keyboard_layout;
std::map<std::string, int> _note_stack; std::map<std::string, int> _note_stack;
/* these are only valid during expose/draw */ /* these are only valid during expose/draw */

View file

@ -365,7 +365,7 @@ VirtualKeyboardWindow::on_key_release_event (GdkEventKey* ev)
void void
VirtualKeyboardWindow::select_keyboard_layout (std::string const& l) VirtualKeyboardWindow::select_keyboard_layout (std::string const& l)
{ {
_piano.set_keyboard_layout (KeyboardLayout::layout (l)); _piano.set_keyboard_layout (PianoKeyBindings::layout (l));
_piano.grab_focus (); _piano.grab_focus ();
} }

View file

@ -125,8 +125,6 @@ gtk2_ardour_sources = [
'ghostregion.cc', 'ghostregion.cc',
'global_port_matrix.cc', 'global_port_matrix.cc',
'group_tabs.cc', 'group_tabs.cc',
'keyboardlayout.cc',
'pianokeyboard.cc',
'gui_object.cc', 'gui_object.cc',
'idleometer.cc', 'idleometer.cc',
'insert_remove_time_dialog.cc', 'insert_remove_time_dialog.cc',
@ -193,6 +191,8 @@ gtk2_ardour_sources = [
'panner_ui.cc', 'panner_ui.cc',
'patch_change.cc', 'patch_change.cc',
'patch_change_widget.cc', 'patch_change_widget.cc',
'pianokeyboard.cc',
'piano_key_bindings.cc',
'piano_roll_header.cc', 'piano_roll_header.cc',
'pingback.cc', 'pingback.cc',
'playlist_selector.cc', 'playlist_selector.cc',