1 |
/* -*- c++ -*- |
2 |
* Copyright (C) 2006-2011 Andreas Persson |
3 |
* |
4 |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
6 |
* published by the Free Software Foundation; either version 2, or (at |
7 |
* your option) any later version. |
8 |
* |
9 |
* This program is distributed in the hope that it will be useful, but |
10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 |
* General Public License for more details. |
13 |
* |
14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with program; see the file COPYING. If not, write to the Free |
16 |
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
17 |
* 02110-1301 USA. |
18 |
*/ |
19 |
|
20 |
#ifndef GIGEDIT_REGIONCHOOSER_H |
21 |
#define GIGEDIT_REGIONCHOOSER_H |
22 |
|
23 |
#include <vector> |
24 |
|
25 |
#include <gtkmm/drawingarea.h> |
26 |
#include <gtkmm/uimanager.h> |
27 |
#include <gdkmm/window.h> |
28 |
#include <gtkmm/menu.h> |
29 |
|
30 |
#include "dimensionmanager.h" |
31 |
#include "paramedit.h" |
32 |
#include "compat.h" |
33 |
|
34 |
#include <gig.h> |
35 |
|
36 |
enum virt_keyboard_mode_t { |
37 |
VIRT_KEYBOARD_MODE_NORMAL, |
38 |
VIRT_KEYBOARD_MODE_CHORD |
39 |
}; |
40 |
|
41 |
class SortedRegions { |
42 |
private: |
43 |
std::vector<gig::Region*> regions; |
44 |
std::vector<gig::Region*>::iterator region_iterator; |
45 |
|
46 |
public: |
47 |
void update(gig::Instrument* instrument); |
48 |
gig::Region* first(); |
49 |
gig::Region* next(); |
50 |
bool operator() (gig::Region* x, gig::Region* y) { |
51 |
return x->KeyRange.low < y->KeyRange.low; |
52 |
} |
53 |
}; |
54 |
|
55 |
class RegionChooser : public Gtk::DrawingArea |
56 |
{ |
57 |
public: |
58 |
RegionChooser(); |
59 |
virtual ~RegionChooser(); |
60 |
|
61 |
void set_instrument(gig::Instrument* instrument); |
62 |
|
63 |
sigc::signal<void>& signal_region_selected(); |
64 |
sigc::signal<void>& signal_instrument_changed(); |
65 |
|
66 |
sigc::signal<void, gig::Instrument*>& signal_instrument_struct_to_be_changed(); |
67 |
sigc::signal<void, gig::Instrument*>& signal_instrument_struct_changed(); |
68 |
|
69 |
sigc::signal<void, gig::Region*>& signal_region_to_be_changed(); |
70 |
sigc::signal<void, gig::Region*>& signal_region_changed_signal(); |
71 |
|
72 |
sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_hit(); |
73 |
sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_released(); |
74 |
|
75 |
gig::Region* get_region() { return region; } |
76 |
|
77 |
void on_note_on_event(int key, int velocity); |
78 |
void on_note_off_event(int key, int velocity); |
79 |
|
80 |
Gtk::HBox m_VirtKeybPropsBox; |
81 |
|
82 |
protected: |
83 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
84 |
virtual bool on_expose_event(GdkEventExpose* e); |
85 |
#else |
86 |
virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr); |
87 |
#endif |
88 |
virtual bool on_button_press_event(GdkEventButton* event); |
89 |
virtual bool on_button_release_event(GdkEventButton* event); |
90 |
virtual bool on_motion_notify_event(GdkEventMotion* event); |
91 |
|
92 |
gig::Region* get_region(int key); |
93 |
|
94 |
Gdk::RGBA activeKeyColor, red, grey1, white, black; |
95 |
|
96 |
sigc::signal<void> region_selected; |
97 |
sigc::signal<void> instrument_changed; |
98 |
|
99 |
sigc::signal<void, gig::Instrument*> instrument_struct_to_be_changed_signal; |
100 |
sigc::signal<void, gig::Instrument*> instrument_struct_changed_signal; |
101 |
|
102 |
sigc::signal<void, gig::Region*> region_to_be_changed_signal; |
103 |
sigc::signal<void, gig::Region*> region_changed_signal; |
104 |
|
105 |
sigc::signal<void, int/*key*/, int/*velocity*/> keyboard_key_hit_signal; |
106 |
sigc::signal<void, int/*key*/, int/*velocity*/> keyboard_key_released_signal; |
107 |
|
108 |
gig::Instrument* instrument; |
109 |
gig::Region* region; |
110 |
SortedRegions regions; |
111 |
|
112 |
bool is_black_key(int key); |
113 |
void draw_keyboard(const Cairo::RefPtr<Cairo::Context>& cr, |
114 |
int clip_low, int clip_high); |
115 |
void draw_regions(const Cairo::RefPtr<Cairo::Context>& cr, |
116 |
int clip_low, int clip_high); |
117 |
void draw_key(const Cairo::RefPtr<Cairo::Context>& cr, int key); |
118 |
void draw_digit(const Cairo::RefPtr<Cairo::Context>& cr, int key); |
119 |
void motion_resize_region(int x, int y); |
120 |
void motion_move_region(int x, int y); |
121 |
void update_after_resize(); |
122 |
void update_after_move(int pos); |
123 |
void invalidate_key(int key); |
124 |
|
125 |
// returns the leftmost pixel of a key |
126 |
int key_to_x(double k, int w) const { |
127 |
return int(k * w / 128.0 + 0.5); |
128 |
} |
129 |
|
130 |
// returns the key given a pixel |
131 |
int x_to_key(double x, int w) const { |
132 |
return int(x / w * 128.0); |
133 |
} |
134 |
|
135 |
// returns the key given a pixel. If the pixel is the border |
136 |
// between two keys, the key to the r�ght is always returned. |
137 |
int x_to_key_right(double x, int w) const { |
138 |
return int(ceil((x + 0.5) / w * 128.0)) - 1; |
139 |
} |
140 |
|
141 |
// information needed during a resize |
142 |
struct { |
143 |
bool active; |
144 |
enum { |
145 |
undecided, |
146 |
moving_high_limit, |
147 |
moving_low_limit |
148 |
} mode; |
149 |
int pos; |
150 |
int min; |
151 |
int max; |
152 |
gig::Region* region; |
153 |
gig::Region* prev_region; |
154 |
} resize; |
155 |
|
156 |
// information needed during a region move |
157 |
struct { |
158 |
bool active; |
159 |
int offset; |
160 |
} move; |
161 |
|
162 |
bool cursor_is_resize; |
163 |
bool is_in_resize_zone(double x, double y); |
164 |
|
165 |
int h1; |
166 |
|
167 |
Gtk::Menu* popup_menu_inside_region; |
168 |
Gtk::Menu* popup_menu_outside_region; |
169 |
void show_region_properties(); |
170 |
void add_region(); |
171 |
void delete_region(); |
172 |
void manage_dimensions(); |
173 |
void on_dimension_manager_changed(); |
174 |
int new_region_pos; |
175 |
|
176 |
Glib::RefPtr<Gtk::ActionGroup> actionGroup; |
177 |
Glib::RefPtr<Gtk::UIManager> uiManager; |
178 |
|
179 |
// properties of the virtual keyboard |
180 |
ChoiceEntry<virt_keyboard_mode_t> m_VirtKeybModeChoice; |
181 |
Gtk::Label m_VirtKeybVelocityLabelDescr; |
182 |
Gtk::Label m_VirtKeybVelocityLabel; |
183 |
Gtk::Label m_VirtKeybOffVelocityLabelDescr; |
184 |
Gtk::Label m_VirtKeybOffVelocityLabel; |
185 |
int currentActiveKey; |
186 |
bool key_pressed[128]; |
187 |
|
188 |
DimensionManager dimensionManager; |
189 |
}; |
190 |
|
191 |
#endif |