/[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 1660 by schoenebeck, Sun Feb 3 00:19:55 2008 UTC revision 1898 by persson, Sun May 10 09:35:56 2009 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2008 Andreas Persson   * Copyright (C) 2006-2009 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 24  Line 24 
24  #include <gtkmm/spinbutton.h>  #include <gtkmm/spinbutton.h>
25  #include <gtkmm/dialog.h>  #include <gtkmm/dialog.h>
26  #include <math.h>  #include <math.h>
27    #include <sstream>
28    
29  #include "global.h"  #include "global.h"
30    
# Line 57  gig::Region* SortedRegions::next() { Line 58  gig::Region* SortedRegions::next() {
58    
59    
60    
61  RegionChooser::RegionChooser()  RegionChooser::RegionChooser() :
62        m_VirtKeybModeChoice(_("Virtual Keyboard Mode")),
63        currentActiveKey(-1)
64  {  {
65      Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();      Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
66    
# Line 79  RegionChooser::RegionChooser() Line 82  RegionChooser::RegionChooser()
82      cursor_is_resize = false;      cursor_is_resize = false;
83      h1 = REGION_BLOCK_HEIGHT;      h1 = REGION_BLOCK_HEIGHT;
84    
85        // properties of the virtual keyboard
86        {
87            const char* choices[] = { _("normal"), _("chord"), NULL };
88            static const virt_keyboard_mode_t values[] = {
89                VIRT_KEYBOARD_MODE_NORMAL,
90                VIRT_KEYBOARD_MODE_CHORD
91            };
92            m_VirtKeybModeChoice.set_choices(choices, values);
93            m_VirtKeybModeChoice.set_value(VIRT_KEYBOARD_MODE_NORMAL);
94        }
95        m_VirtKeybVelocityLabelDescr.set_text(_("Note-On Velocity:"));
96        m_VirtKeybVelocityLabel.set_text("-");
97        m_VirtKeybOffVelocityLabelDescr.set_text(_("Note-Off Velocity:"));
98        m_VirtKeybOffVelocityLabel.set_text("-");
99        m_VirtKeybPropsBox.pack_start(m_VirtKeybModeChoice.label, Gtk::PACK_SHRINK);
100        m_VirtKeybPropsBox.pack_start(m_VirtKeybModeChoice.widget, Gtk::PACK_SHRINK);
101        m_VirtKeybPropsBox.pack_start(m_VirtKeybVelocityLabelDescr, Gtk::PACK_SHRINK);
102        m_VirtKeybPropsBox.pack_start(m_VirtKeybVelocityLabel, Gtk::PACK_SHRINK);
103        m_VirtKeybPropsBox.pack_start(m_VirtKeybOffVelocityLabelDescr, Gtk::PACK_SHRINK);
104        m_VirtKeybPropsBox.pack_start(m_VirtKeybOffVelocityLabel, Gtk::PACK_SHRINK);
105        m_VirtKeybPropsBox.set_spacing(10);
106        m_VirtKeybPropsBox.show();
107    
108      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
109      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
110                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
# Line 137  RegionChooser::~RegionChooser() Line 163  RegionChooser::~RegionChooser()
163  {  {
164  }  }
165    
166    template<class T> inline std::string ToString(T o) {
167        std::stringstream ss;
168        ss << o;
169        return ss.str();
170    }
171    
172  void RegionChooser::on_note_on_event(int key, int velocity) {  void RegionChooser::on_note_on_event(int key, int velocity) {
173      draw_region(key, key+1, activeKeyColor);      draw_region(key, key+1, activeKeyColor);
174        m_VirtKeybVelocityLabel.set_text(ToString(velocity));
175  }  }
176    
177  void RegionChooser::on_note_off_event(int key, int velocity) {  void RegionChooser::on_note_off_event(int key, int velocity) {
178      if (is_black_key(key))      if (is_black_key(key)) {
179          draw_region(key, key+1, black);          draw_region(key, key+1, black);
180      else      } else {
181          draw_region(key, key+1, white);          draw_region(key, key+1, key >= 21 && key <= 108 ? white : grey1);
182        }
183        m_VirtKeybOffVelocityLabel.set_text(ToString(velocity));
184  }  }
185    
186  void RegionChooser::on_realize()  void RegionChooser::on_realize()
# Line 301  void RegionChooser::set_instrument(gig:: Line 336  void RegionChooser::set_instrument(gig::
336      region = regions.first();      region = regions.first();
337      queue_draw();      queue_draw();
338      region_selected();      region_selected();
339        dimensionManager.set_region(region);
340  }  }
341    
342  bool RegionChooser::on_button_release_event(GdkEventButton* event)  bool RegionChooser::on_button_release_event(GdkEventButton* event)
343  {  {
344      const int k = int(event->x / (get_width() - 1) * 128.0);      const int k = int(event->x / (get_width() - 1) * 128.0);
345    
346        // handle-note off on virtual keyboard
347      if (event->type == GDK_BUTTON_RELEASE) {      if (event->type == GDK_BUTTON_RELEASE) {
348          if (event->y >= REGION_BLOCK_HEIGHT) {          int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 :
349              int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 :                         int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1;
350                             int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1;          if (velocity <= 0) velocity = 1;
351              keyboard_key_released_signal.emit(k, velocity);          switch (m_VirtKeybModeChoice.get_value()) {
352                case VIRT_KEYBOARD_MODE_CHORD:
353                    if (event->y >= REGION_BLOCK_HEIGHT)
354                        keyboard_key_released_signal.emit(k, velocity);
355                    break;
356                case VIRT_KEYBOARD_MODE_NORMAL:
357                default:
358                    if (currentActiveKey >= 0 && currentActiveKey <= 127) {
359                        keyboard_key_released_signal.emit(currentActiveKey, velocity);
360                        currentActiveKey = -1;
361                    }
362                    break;
363          }          }
364      }      }
365    
# Line 380  bool RegionChooser::on_button_press_even Line 428  bool RegionChooser::on_button_press_even
428          if (event->y >= REGION_BLOCK_HEIGHT) {          if (event->y >= REGION_BLOCK_HEIGHT) {
429              int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 :              int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 :
430                             int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1;                             int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1;
431                currentActiveKey = k;
432              keyboard_key_hit_signal.emit(k, velocity);              keyboard_key_hit_signal.emit(k, velocity);
433          }          }
434      }      }
# Line 391  bool RegionChooser::on_button_press_even Line 440  bool RegionChooser::on_button_press_even
440              region = r;              region = r;
441              queue_draw();              queue_draw();
442              region_selected();              region_selected();
443                dimensionManager.set_region(region);
444              popup_menu_inside_region->popup(event->button, event->time);              popup_menu_inside_region->popup(event->button, event->time);
445          } else {          } else {
446              new_region_pos = k;              new_region_pos = k;
# Line 410  bool RegionChooser::on_button_press_even Line 460  bool RegionChooser::on_button_press_even
460                  region = r;                  region = r;
461                  queue_draw();                  queue_draw();
462                  region_selected();                  region_selected();
463                    dimensionManager.set_region(region);
464    
465                  get_window()->pointer_grab(false,                  get_window()->pointer_grab(false,
466                                             Gdk::BUTTON_RELEASE_MASK |                                             Gdk::BUTTON_RELEASE_MASK |
# Line 620  bool RegionChooser::on_motion_notify_eve Line 671  bool RegionChooser::on_motion_notify_eve
671      Gdk::ModifierType state = Gdk::ModifierType(0);      Gdk::ModifierType state = Gdk::ModifierType(0);
672      window->get_pointer(x, y, state);      window->get_pointer(x, y, state);
673    
674        // handle virtual MIDI keyboard
675        if (m_VirtKeybModeChoice.get_value() != VIRT_KEYBOARD_MODE_CHORD &&
676            currentActiveKey > 0 &&
677            event->y >= REGION_BLOCK_HEIGHT &&
678            event->y < REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT)
679        {
680            const int k = int(event->x / (get_width() - 1) * 128.0);
681            if (k != currentActiveKey) {
682                int velocity =
683                    (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 :
684                    int(float(event->y - REGION_BLOCK_HEIGHT) /
685                        float(KEYBOARD_HEIGHT) * 128.0f) + 1;
686                if (velocity <= 0) velocity = 1;
687                keyboard_key_released_signal.emit(currentActiveKey, velocity);
688                currentActiveKey = k;
689                keyboard_key_hit_signal.emit(k, velocity);
690            }
691        }
692    
693      if (resize.active) {      if (resize.active) {
694          motion_resize_region(x, y);          motion_resize_region(x, y);
695      } else if (move.active) {      } else if (move.active) {
# Line 702  sigc::signal<void>& RegionChooser::signa Line 772  sigc::signal<void>& RegionChooser::signa
772  void RegionChooser::show_region_properties()  void RegionChooser::show_region_properties()
773  {  {
774      if (!region) return;      if (!region) return;
775      Gtk::Dialog dialog("Region Properties", true /*modal*/);      Gtk::Dialog dialog(_("Region Properties"), true /*modal*/);
776      // add "Keygroup" checkbox      // add "Keygroup" checkbox
777      Gtk::CheckButton checkBoxKeygroup("Member of a Keygroup (Exclusive Group)");      Gtk::CheckButton checkBoxKeygroup(_("Member of a Keygroup (Exclusive Group)"));
778      checkBoxKeygroup.set_active(region->KeyGroup);      checkBoxKeygroup.set_active(region->KeyGroup);
779      dialog.get_vbox()->pack_start(checkBoxKeygroup);      dialog.get_vbox()->pack_start(checkBoxKeygroup);
780      checkBoxKeygroup.show();      checkBoxKeygroup.show();
# Line 736  void RegionChooser::add_region() Line 806  void RegionChooser::add_region()
806    
807      queue_draw();      queue_draw();
808      region_selected();      region_selected();
809        dimensionManager.set_region(region);
810      instrument_changed();      instrument_changed();
811  }  }
812    
# Line 749  void RegionChooser::delete_region() Line 820  void RegionChooser::delete_region()
820      region = 0;      region = 0;
821      queue_draw();      queue_draw();
822      region_selected();      region_selected();
823        dimensionManager.set_region(region);
824      instrument_changed();      instrument_changed();
825  }  }
826    

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

  ViewVC Help
Powered by ViewVC