/[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 2844 - (hide annotations) (download) (as text)
Sun Sep 20 08:49:40 2015 UTC (8 years, 7 months ago) by persson
File MIME type: text/x-c++hdr
File size: 6042 byte(s)
* allow building with gtkmm 2 and G/GDK/GTK_DISABLE_DEPRECATED

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

  ViewVC Help
Powered by ViewVC