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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3364 - (hide annotations) (download) (as text)
Tue Nov 14 18:07:25 2017 UTC (6 years, 6 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6720 byte(s)
* Added experimental support for upcoming GTK(MM)4
  (for now up to GTKMM 3.91.2 while still preserving backward compatibility
  down to GTKMM 2).
* Re-merged r2845 to compile now with and without Gtk "Stock ID" API
  (see also r3158).

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

  ViewVC Help
Powered by ViewVC