/[svn]/gigedit/trunk/src/gigedit/regionchooser.h
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/regionchooser.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3068 - (show annotations) (download) (as text)
Mon Jan 2 22:13:01 2017 UTC (7 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6118 byte(s)
- Preparations for Xcode project update.

1 /* -*- c++ -*-
2 * Copyright (C) 2006-2017 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/box.h>
26 #include <gtkmm/drawingarea.h>
27 #include <gtkmm/uimanager.h>
28 #include <gdkmm/window.h>
29 #include <gtkmm/menu.h>
30
31 #include "dimensionmanager.h"
32 #include "paramedit.h"
33 #include "compat.h"
34
35 #ifdef LIBGIG_HEADER_FILE
36 # include LIBGIG_HEADER_FILE(gig.h)
37 #else
38 # include <gig.h>
39 #endif
40
41 enum virt_keyboard_mode_t {
42 VIRT_KEYBOARD_MODE_NORMAL,
43 VIRT_KEYBOARD_MODE_CHORD
44 };
45
46 class SortedRegions {
47 private:
48 std::vector<gig::Region*> regions;
49 std::vector<gig::Region*>::iterator region_iterator;
50
51 public:
52 void update(gig::Instrument* instrument);
53 gig::Region* first();
54 gig::Region* next();
55 bool operator() (gig::Region* x, gig::Region* y) const {
56 return x->KeyRange.low < y->KeyRange.low;
57 }
58 };
59
60 class RegionChooser : public Gtk::DrawingArea
61 {
62 public:
63 RegionChooser();
64 virtual ~RegionChooser();
65
66 void set_instrument(gig::Instrument* instrument);
67
68 sigc::signal<void>& signal_region_selected();
69 sigc::signal<void>& signal_instrument_changed();
70
71 sigc::signal<void, gig::Instrument*>& signal_instrument_struct_to_be_changed();
72 sigc::signal<void, gig::Instrument*>& signal_instrument_struct_changed();
73
74 sigc::signal<void, gig::Region*>& signal_region_to_be_changed();
75 sigc::signal<void, gig::Region*>& signal_region_changed_signal();
76
77 sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_hit();
78 sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_released();
79
80 gig::Region* get_region() { return region; }
81 void set_region(gig::Region* region);
82
83 void on_note_on_event(int key, int velocity);
84 void on_note_off_event(int key, int velocity);
85
86 Gtk::HBox m_VirtKeybPropsBox;
87
88 protected:
89 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
90 virtual bool on_expose_event(GdkEventExpose* e);
91 #else
92 virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
93 #endif
94 virtual bool on_button_press_event(GdkEventButton* event);
95 virtual bool on_button_release_event(GdkEventButton* event);
96 virtual bool on_motion_notify_event(GdkEventMotion* event);
97
98 gig::Region* get_region(int key);
99
100 Gdk::RGBA activeKeyColor, red, grey1, white, black;
101
102 sigc::signal<void> region_selected;
103 sigc::signal<void> instrument_changed;
104
105 sigc::signal<void, gig::Instrument*> instrument_struct_to_be_changed_signal;
106 sigc::signal<void, gig::Instrument*> instrument_struct_changed_signal;
107
108 sigc::signal<void, gig::Region*> region_to_be_changed_signal;
109 sigc::signal<void, gig::Region*> region_changed_signal;
110
111 sigc::signal<void, int/*key*/, int/*velocity*/> keyboard_key_hit_signal;
112 sigc::signal<void, int/*key*/, int/*velocity*/> keyboard_key_released_signal;
113
114 gig::Instrument* instrument;
115 gig::Region* region;
116 SortedRegions regions;
117
118 bool is_black_key(int key);
119 void draw_keyboard(const Cairo::RefPtr<Cairo::Context>& cr,
120 int clip_low, int clip_high);
121 void draw_regions(const Cairo::RefPtr<Cairo::Context>& cr,
122 int clip_low, int clip_high);
123 void draw_key(const Cairo::RefPtr<Cairo::Context>& cr, int key);
124 void draw_digit(const Cairo::RefPtr<Cairo::Context>& cr, int key);
125 void motion_resize_region(int x, int y);
126 void motion_move_region(int x, int y);
127 void update_after_resize();
128 void update_after_move(int pos);
129 void invalidate_key(int key);
130
131 // returns the leftmost pixel of a key
132 int key_to_x(double k, int w) const {
133 return int(k * w / 128.0 + 0.5);
134 }
135
136 // returns the key given a pixel
137 int x_to_key(double x, int w) const {
138 return int(x / w * 128.0);
139 }
140
141 // returns the key given a pixel. If the pixel is the border
142 // between two keys, the key to the r�ght is always returned.
143 int x_to_key_right(double x, int w) const {
144 return int(ceil((x + 0.5) / w * 128.0)) - 1;
145 }
146
147 // information needed during a resize
148 struct {
149 bool active;
150 enum {
151 undecided,
152 moving_high_limit,
153 moving_low_limit
154 } mode;
155 int pos;
156 int min;
157 int max;
158 gig::Region* region;
159 gig::Region* prev_region;
160 } resize;
161
162 // information needed during a region move
163 struct {
164 bool active;
165 int offset;
166 } move;
167
168 bool cursor_is_resize;
169 bool is_in_resize_zone(double x, double y);
170
171 int h1;
172
173 Gtk::Menu* popup_menu_inside_region;
174 Gtk::Menu* popup_menu_outside_region;
175 void show_region_properties();
176 void add_region();
177 void delete_region();
178 void manage_dimensions();
179 void on_dimension_manager_changed();
180 int new_region_pos;
181
182 Glib::RefPtr<Gtk::ActionGroup> actionGroup;
183 Glib::RefPtr<Gtk::UIManager> uiManager;
184
185 // properties of the virtual keyboard
186 ChoiceEntry<virt_keyboard_mode_t> m_VirtKeybModeChoice;
187 Gtk::Label m_VirtKeybVelocityLabelDescr;
188 Gtk::Label m_VirtKeybVelocityLabel;
189 Gtk::Label m_VirtKeybOffVelocityLabelDescr;
190 Gtk::Label m_VirtKeybOffVelocityLabel;
191 int currentActiveKey;
192 bool key_pressed[128];
193
194 DimensionManager dimensionManager;
195 };
196
197 #endif

  ViewVC Help
Powered by ViewVC