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

Diff of /gigedit/trunk/src/gigedit/regionchooser.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1658 by persson, Sat Feb 2 08:52:48 2008 UTC revision 1660 by schoenebeck, Sun Feb 3 00:19:55 2008 UTC
# Line 27  Line 27 
27    
28  #include "global.h"  #include "global.h"
29    
30    #define REGION_BLOCK_HEIGHT             20
31    #define KEYBOARD_HEIGHT                 40
32    
33  void SortedRegions::update(gig::Instrument* instrument) {  void SortedRegions::update(gig::Instrument* instrument) {
34      // Usually, the regions in a gig file are ordered after their key      // Usually, the regions in a gig file are ordered after their key
35      // range, but there are files where they are not. The      // range, but there are files where they are not. The
# Line 74  RegionChooser::RegionChooser() Line 77  RegionChooser::RegionChooser()
77      resize.active = false;      resize.active = false;
78      move.active = false;      move.active = false;
79      cursor_is_resize = false;      cursor_is_resize = false;
80      h1 = 20;      h1 = REGION_BLOCK_HEIGHT;
81    
82      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
83      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
# Line 122  RegionChooser::RegionChooser() Line 125  RegionChooser::RegionChooser()
125              sigc::mem_fun(*this, &RegionChooser::on_dimension_manager_changed)              sigc::mem_fun(*this, &RegionChooser::on_dimension_manager_changed)
126          )          )
127      );      );
128        keyboard_key_hit_signal.connect(
129            sigc::mem_fun(*this, &RegionChooser::on_note_on_event)
130        );
131        keyboard_key_released_signal.connect(
132            sigc::mem_fun(*this, &RegionChooser::on_note_off_event)
133        );
134  }  }
135    
136  RegionChooser::~RegionChooser()  RegionChooser::~RegionChooser()
# Line 154  bool RegionChooser::on_expose_event(GdkE Line 163  bool RegionChooser::on_expose_event(GdkE
163  {  {
164      Glib::RefPtr<Gdk::Window> window = get_window();      Glib::RefPtr<Gdk::Window> window = get_window();
165      window->clear();      window->clear();
166      const int h = 40;      const int h = KEYBOARD_HEIGHT;
167      const int w = get_width() - 1;      const int w = get_width() - 1;
168      const int bh = int(h * 0.55);      const int bh = int(h * 0.55);
169    
# Line 224  bool RegionChooser::on_expose_event(GdkE Line 233  bool RegionChooser::on_expose_event(GdkE
233  void RegionChooser::on_size_request(GtkRequisition* requisition)  void RegionChooser::on_size_request(GtkRequisition* requisition)
234  {  {
235      *requisition = GtkRequisition();      *requisition = GtkRequisition();
236      requisition->height = 40 + 20;      requisition->height = KEYBOARD_HEIGHT + REGION_BLOCK_HEIGHT;
237      requisition->width = 500;      requisition->width = 500;
238  }  }
239    
# Line 234  bool RegionChooser::is_black_key(int key Line 243  bool RegionChooser::is_black_key(int key
243  }  }
244    
245  void RegionChooser::draw_digit(int key) {  void RegionChooser::draw_digit(int key) {
246      const int h = 40;      const int h = KEYBOARD_HEIGHT;
247      const int w = get_width() - 1;      const int w = get_width() - 1;
248      Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(get_pango_context());      Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(get_pango_context());
249      char buf[30];      char buf[30];
# Line 250  void RegionChooser::draw_digit(int key) Line 259  void RegionChooser::draw_digit(int key)
259    
260  void RegionChooser::draw_region(int from, int to, const Gdk::Color& color)  void RegionChooser::draw_region(int from, int to, const Gdk::Color& color)
261  {  {
262      const int h = 40;      const int h = KEYBOARD_HEIGHT;
263      const int w = get_width() - 1;      const int w = get_width() - 1;
264      const int bh = int(h * 0.55);      const int bh = int(h * 0.55);
265    
# Line 296  void RegionChooser::set_instrument(gig:: Line 305  void RegionChooser::set_instrument(gig::
305    
306  bool RegionChooser::on_button_release_event(GdkEventButton* event)  bool RegionChooser::on_button_release_event(GdkEventButton* event)
307  {  {
308        const int k = int(event->x / (get_width() - 1) * 128.0);
309    
310        if (event->type == GDK_BUTTON_RELEASE) {
311            if (event->y >= REGION_BLOCK_HEIGHT) {
312                int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 :
313                               int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1;
314                keyboard_key_released_signal.emit(k, velocity);
315            }
316        }
317    
318      if (resize.active) {      if (resize.active) {
319          get_window()->pointer_ungrab(event->time);          get_window()->pointer_ungrab(event->time);
320          resize.active = false;          resize.active = false;
# Line 355  bool RegionChooser::on_button_press_even Line 374  bool RegionChooser::on_button_press_even
374  {  {
375      if (!instrument) return true;      if (!instrument) return true;
376    
377      int k = int(event->x / (get_width() - 1) * 128.0);      const int k = int(event->x / (get_width() - 1) * 128.0);
378    
379        if (event->type == GDK_BUTTON_PRESS) {
380            if (event->y >= REGION_BLOCK_HEIGHT) {
381                int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 :
382                               int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1;
383                keyboard_key_hit_signal.emit(k, velocity);
384            }
385        }
386    
387        if (event->y >= REGION_BLOCK_HEIGHT) return true;
388      if (event->type == GDK_BUTTON_PRESS && event->button == 3) {      if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
389          gig::Region* r = get_region(k);          gig::Region* r = get_region(k);
390          if (r) {          if (r) {
# Line 751  sigc::signal<void, gig::Region*>& Region Line 779  sigc::signal<void, gig::Region*>& Region
779  sigc::signal<void, gig::Region*>& RegionChooser::signal_region_changed_signal() {  sigc::signal<void, gig::Region*>& RegionChooser::signal_region_changed_signal() {
780      return region_changed_signal;      return region_changed_signal;
781  }  }
782    
783    sigc::signal<void, int/*key*/, int/*velocity*/>& RegionChooser::signal_keyboard_key_hit() {
784        return keyboard_key_hit_signal;
785    }
786    
787    sigc::signal<void, int/*key*/, int/*velocity*/>& RegionChooser::signal_keyboard_key_released() {
788        return keyboard_key_released_signal;
789    }

Legend:
Removed from v.1658  
changed lines
  Added in v.1660

  ViewVC Help
Powered by ViewVC