2013-01-16 13:37:48 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2010-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2013-01-16 13:37:48 -05:00
|
|
|
|
2019-10-25 12:01:08 -04:00
|
|
|
#ifndef _PIANO_KEYBOARD_H_
|
|
|
|
#define _PIANO_KEYBOARD_H_
|
2010-08-02 17:52:21 -04:00
|
|
|
|
2019-10-24 13:43:46 -04:00
|
|
|
#include <map>
|
|
|
|
#include <gtkmm/drawingarea.h>
|
2010-08-02 17:52:21 -04:00
|
|
|
|
2019-10-20 23:41:34 -04:00
|
|
|
#define NNOTES (128)
|
2010-08-02 17:52:21 -04:00
|
|
|
|
2019-10-25 12:01:08 -04:00
|
|
|
class APianoKeyboard : public Gtk::DrawingArea
|
2019-10-24 13:43:46 -04:00
|
|
|
{
|
|
|
|
public:
|
2019-10-25 12:01:08 -04:00
|
|
|
APianoKeyboard ();
|
|
|
|
~APianoKeyboard ();
|
2010-08-02 17:52:21 -04:00
|
|
|
|
2019-12-16 09:02:39 -05:00
|
|
|
sigc::signal<void, int, int> NoteOn;
|
|
|
|
sigc::signal<void, int> NoteOff;
|
|
|
|
sigc::signal<void> Rest;
|
|
|
|
sigc::signal<void,bool> SustainChanged;
|
|
|
|
sigc::signal<void, int, bool> PitchBend;
|
|
|
|
sigc::signal<void, bool> SwitchOctave;
|
2010-08-02 17:52:21 -04:00
|
|
|
|
2019-10-24 13:43:46 -04:00
|
|
|
enum Layout {
|
|
|
|
QWERTY,
|
|
|
|
QWERTZ,
|
|
|
|
AZERTY,
|
2019-10-26 17:49:57 -04:00
|
|
|
DVORAK,
|
|
|
|
S_QWERTY,
|
|
|
|
S_QWERTZ
|
2019-10-24 13:43:46 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void sustain_press ();
|
|
|
|
void sustain_release ();
|
2019-10-25 12:05:28 -04:00
|
|
|
|
2019-10-24 13:43:46 -04:00
|
|
|
void set_note_on (int note);
|
|
|
|
void set_note_off (int note);
|
2019-12-26 06:17:20 -05:00
|
|
|
void reset ();
|
2019-10-25 12:05:28 -04:00
|
|
|
|
2019-10-24 13:43:46 -04:00
|
|
|
void set_grand_piano_highlight (bool enabled);
|
2019-10-25 15:23:27 -04:00
|
|
|
void set_annotate_layout (bool enabled);
|
|
|
|
void set_annotate_octave (bool enabled);
|
2019-10-25 12:05:28 -04:00
|
|
|
|
2019-10-24 13:43:46 -04:00
|
|
|
void set_monophonic (bool monophonic);
|
|
|
|
void set_octave (int octave);
|
|
|
|
void set_octave_range (int octave_range);
|
|
|
|
void set_keyboard_layout (Layout layout);
|
|
|
|
void set_velocities (int min_vel, int max_vel, int key_vel);
|
|
|
|
|
|
|
|
protected:
|
2019-10-25 08:35:38 -04:00
|
|
|
bool on_key_press_event (GdkEventKey*);
|
|
|
|
bool on_key_release_event (GdkEventKey*);
|
2019-10-24 13:43:46 -04:00
|
|
|
bool on_button_press_event (GdkEventButton*);
|
|
|
|
bool on_button_release_event (GdkEventButton*);
|
|
|
|
bool on_motion_notify_event (GdkEventMotion*);
|
|
|
|
bool on_expose_event (GdkEventExpose*);
|
2010-08-02 17:52:21 -04:00
|
|
|
|
2019-10-24 13:43:46 -04:00
|
|
|
void on_size_request (Gtk::Requisition*);
|
|
|
|
void on_size_allocate (Gtk::Allocation&);
|
2019-04-13 11:48:27 -04:00
|
|
|
|
2019-10-24 13:43:46 -04:00
|
|
|
private:
|
2019-10-25 12:05:28 -04:00
|
|
|
void annotate_layout (cairo_t* cr, int note) const;
|
|
|
|
void annotate_note (cairo_t* cr, int note) const;
|
|
|
|
void draw_note (cairo_t* cr, int note) const;
|
|
|
|
|
2019-10-24 13:43:46 -04:00
|
|
|
void queue_note_draw (int note);
|
2019-10-25 12:05:28 -04:00
|
|
|
|
2019-12-16 09:02:39 -05:00
|
|
|
bool handle_fixed_keys (GdkEventKey*);
|
|
|
|
|
2019-10-25 12:05:28 -04:00
|
|
|
void press_key (int key, int vel);
|
|
|
|
void release_key (int key);
|
2019-10-24 13:43:46 -04:00
|
|
|
void stop_sustained_notes ();
|
2019-10-25 12:05:28 -04:00
|
|
|
void stop_unsustained_notes ();
|
|
|
|
|
|
|
|
int key_binding (const char* key) const;
|
2019-10-24 13:43:46 -04:00
|
|
|
void bind_key (const char* key, int note);
|
|
|
|
void clear_notes ();
|
2010-08-02 17:52:21 -04:00
|
|
|
|
2019-10-24 13:43:46 -04:00
|
|
|
void bind_keys_qwerty ();
|
|
|
|
void bind_keys_qwertz ();
|
|
|
|
void bind_keys_azerty ();
|
|
|
|
void bind_keys_dvorak ();
|
|
|
|
|
2019-10-26 17:49:57 -04:00
|
|
|
void bind_keys_basic_qwerty ();
|
|
|
|
void bind_keys_basic_qwertz ();
|
|
|
|
|
2019-10-24 13:43:46 -04:00
|
|
|
int get_note_for_xy (int x, int y) const;
|
|
|
|
int get_velocity_for_note_at_y (int note, int y) const;
|
|
|
|
|
2019-10-25 08:35:38 -04:00
|
|
|
int is_black (int key) const;
|
2019-10-24 13:43:46 -04:00
|
|
|
double black_key_left_shift (int key) const;
|
|
|
|
|
|
|
|
void recompute_dimensions ();
|
|
|
|
|
|
|
|
struct PKNote {
|
|
|
|
PKNote ()
|
2019-10-25 08:35:38 -04:00
|
|
|
: pressed (false)
|
|
|
|
, sustained (false)
|
|
|
|
, white (false)
|
|
|
|
, x (0)
|
|
|
|
, w (0)
|
|
|
|
, h (0)
|
2019-10-24 13:43:46 -04:00
|
|
|
{}
|
|
|
|
|
2019-10-25 08:35:38 -04:00
|
|
|
bool pressed; /* true if key is in pressed down state. */
|
|
|
|
bool sustained; /* true if note is sustained. */
|
|
|
|
bool white; /* true if key is white; 0 otherwise. */
|
|
|
|
int x; /* Distance between the left edge of the key and the left edge of the widget, in pixels. */
|
|
|
|
int w; /* Width of the key, in pixels. */
|
|
|
|
int h; /* Height of the key, in pixels. */
|
2019-10-24 13:43:46 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
bool _sustain_new_notes;
|
|
|
|
bool _highlight_grand_piano_range;
|
2019-10-25 15:23:27 -04:00
|
|
|
bool _annotate_layout;
|
|
|
|
bool _annotate_octave;
|
2019-10-24 13:43:46 -04:00
|
|
|
int _octave;
|
|
|
|
int _octave_range;
|
|
|
|
int _note_being_pressed_using_mouse;
|
|
|
|
int _min_note;
|
|
|
|
int _max_note;
|
|
|
|
int _last_key;
|
|
|
|
bool _monophonic;
|
|
|
|
int _min_velocity;
|
|
|
|
int _max_velocity;
|
|
|
|
int _key_velocity;
|
|
|
|
|
|
|
|
PKNote _notes[NNOTES];
|
|
|
|
|
2019-10-25 08:35:38 -04:00
|
|
|
std::map<std::string, int> _key_bindings; /**< Table used to translate from PC keyboard character to MIDI note number. */
|
2019-10-24 13:43:46 -04:00
|
|
|
std::map<int, std::string> _note_bindings; /**< Table to translate from MIDI note number to PC keyboard character. */
|
2019-10-27 08:54:47 -04:00
|
|
|
std::map<std::string, int> _note_stack;
|
2019-10-25 12:05:28 -04:00
|
|
|
|
|
|
|
/* these are only valid during expose/draw */
|
|
|
|
PangoFontDescription* _font_cue;
|
|
|
|
PangoFontDescription* _font_octave;
|
2019-10-24 13:43:46 -04:00
|
|
|
};
|
2019-10-25 12:01:08 -04:00
|
|
|
|
|
|
|
#endif
|