* fixed velocity text event handling
authorHans Baier <hansfbaier@googlemail.com>
Wed, 24 Dec 2008 10:52:19 +0000 (10:52 +0000)
committerHans Baier <hansfbaier@googlemail.com>
Wed, 24 Dec 2008 10:52:19 +0000 (10:52 +0000)
* fixed track note colors
* fixed color on ChannelMode

git-svn-id: svn://localhost/ardour2/branches/3.0@4345 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/canvas-flag.cc
gtk2_ardour/canvas-note-event.cc
gtk2_ardour/interactive-item.h

index bd82b2d3f309e26e020ac5c2709b7faf6d7db30f..f0361c5bf900a36325e12e42962af01ae03940f3 100644 (file)
@@ -24,7 +24,7 @@ CanvasFlag::set_text(string& a_text)
 {
        delete_allocated_objects();
        
-       _text = new InteractiveText(*this, 0.0, 0.0, Glib::ustring(a_text));
+       _text = new InteractiveText(*this, this, 0.0, 0.0, Glib::ustring(a_text));
        _text->property_justification() = Gtk::JUSTIFY_CENTER;
        _text->property_fill_color_rgba() = _outline_color_rgba;
        double flagwidth  = _text->property_text_width()  + 10.0;
@@ -34,7 +34,7 @@ CanvasFlag::set_text(string& a_text)
        _text->show();
        _line = new SimpleLine(*this, 0.0, 0.0, 0.0, _height);
        _line->property_color_rgba() = _outline_color_rgba;
-       _rect = new InteractiveRect(*this, 0.0, 0.0, flagwidth, flagheight);
+       _rect = new InteractiveRect(*this, this, 0.0, 0.0, flagwidth, flagheight);
        _rect->property_outline_color_rgba() = _outline_color_rgba;
        _rect->property_fill_color_rgba() = _fill_color_rgba;
        _text->raise_to_top();  
index e5ff6abf4679505598a67b989de7a2cd4e75ed84..d89e68786da5af582805d1ea535ae1df599d70a9 100644 (file)
@@ -32,10 +32,10 @@ namespace Canvas {
 
 /// dividing the hue circle in 16 parts, hand adjusted for equal look, courtesy Thorsten Wilms
 const uint32_t CanvasNoteEvent::midi_channel_colors[16] = {
-         0xd32d2d00,  0xd36b2d00,  0xd3972d00,  0xd3d12d00,  
-         0xa0d32d00,  0x7dd32d00,  0x2dd45e00,  0x2dd3c400,  
-         0x2da5d300,  0x2d6fd300,  0x432dd300,  0x662dd300,  
-         0x832dd300,  0xa92dd300,  0xd32dbf00,  0xd32d6700 
+         0xd32d2dff,  0xd36b2dff,  0xd3972dff,  0xd3d12dff,  
+         0xa0d32dff,  0x7dd32dff,  0x2dd45eff,  0x2dd3c4ff,  
+         0x2da5d3ff,  0x2d6fd3ff,  0x432dd3ff,  0x662dd3ff,  
+         0x832dd3ff,  0xa92dd3ff,  0xd32dbfff,  0xd32d67ff
        };
 
 CanvasNoteEvent::CanvasNoteEvent(MidiRegionView& region, Item* item,
@@ -75,7 +75,7 @@ void
 CanvasNoteEvent::show_velocity()
 {
        hide_velocity();
-       _text = new InteractiveText(*(_item->property_parent()));
+       _text = new InteractiveText(*(_item->property_parent()), this);
        _text->property_x() = (x1() + x2()) /2;
        _text->property_y() = (y1() + y2()) /2;
        ostringstream velo(ios::ate);
@@ -176,6 +176,8 @@ CanvasNoteEvent::selected(bool selected)
        _selected = selected;
 }
 
+#define SCALE_USHORT_TO_UINT8_T(x) ((x) / 257)
+
 uint32_t 
 CanvasNoteEvent::base_color()
 {
@@ -183,15 +185,22 @@ CanvasNoteEvent::base_color()
        
        ColorMode mode = _region.color_mode();
        
+       const uint8_t minimal_opaqueness = 15;
+       
        switch (mode) {
        case TrackColor:
                {
                        Gdk::Color color = _region.midi_stream_view()->get_region_color();
-                       return RGBA_TO_UINT(color.get_red(), color.get_green(), color.get_blue(), 0xff);
+                       return RGBA_TO_UINT(
+                                       SCALE_USHORT_TO_UINT8_T(color.get_red()), 
+                                       SCALE_USHORT_TO_UINT8_T(color.get_green()), 
+                                       SCALE_USHORT_TO_UINT8_T(color.get_blue()), 
+                                       minimal_opaqueness + _note->velocity());
                }
                
        case ChannelColors:
-               return CanvasNoteEvent::midi_channel_colors[_note->channel()];
+               return UINT_RGBA_CHANGE_A(CanvasNoteEvent::midi_channel_colors[_note->channel()], 
+                                                 minimal_opaqueness + _note->velocity());
                
        default:
                return meter_style_fill_color(_note->velocity());
@@ -210,8 +219,6 @@ CanvasNoteEvent::on_event(GdkEvent* ev)
        double event_x, event_y, dx, dy;
        bool select_mod;
        uint8_t d_velocity = 10;
-
-       cerr << "CanvasNoteEvent::on_event(GdkEvent* ev)" << endl;
        
        if (_region.get_time_axis_view().editor.current_mouse_mode() != Editing::MouseNote)
                return false;
index 145a592511b65e2b0673cc905f8d5a831910b868..13d224fc728787d871ce1e1adebfc72ffbd2cfdc 100644 (file)
@@ -41,48 +41,51 @@ public:
  */
 class InteractiveText : public Text, public InteractiveItem {
 public:
-       InteractiveText(Group& parent, double x, double y, const Glib::ustring& text) 
+       InteractiveText(Group& parent, InteractiveItem* parent_item, double x, double y, const Glib::ustring& text) 
                : Text(parent, x, y, text) 
-       {
-               _parent = dynamic_cast<InteractiveItem*>(&parent);
-       }
+               , _parent_item(parent_item)
+       {}
        
-       InteractiveText(Group& parent)
-               : Text(parent) 
-       {
-               _parent = dynamic_cast<InteractiveItem*>(&parent);              
-       }
+       InteractiveText(Group& parent, InteractiveItem* parent_item)
+               : Text(parent)
+               , _parent_item(parent_item)
+       {}
        
        bool on_event(GdkEvent* ev) {
-               if(_parent) {
-                       return _parent->on_event(ev);
+               std::cerr << "InteractiveRect::on_event(GdkEvent* ev)" << std::endl;
+               if(_parent_item) {
+                       std::cerr << " parent not null" << std::endl;
+                       return _parent_item->on_event(ev);
                } else {
                        return false;
                }
        }
-
+       
 protected:
-       InteractiveItem* _parent;
+       InteractiveItem* _parent_item;
 };
 
 class InteractiveRect: public SimpleRect, public InteractiveItem
 {
 public:
-       InteractiveRect(Group& parent, double x1, double y1, double x2, double y2) 
-               : SimpleRect(parent, x1, y1, x2, y2) {
-               _parent = dynamic_cast<InteractiveItem*>(&parent);
-       }
+       InteractiveRect(Group& parent, InteractiveItem* parent_item, double x1, double y1, double x2, double y2) 
+               : SimpleRect(parent, x1, y1, x2, y2) 
+               , _parent_item(parent_item)
+               {}
        
        bool on_event(GdkEvent* ev) {
-               if(_parent) {
-                       return _parent->on_event(ev);
+               std::cerr << "InteractiveRect::on_event(GdkEvent* ev)" << std::endl;
+               if(_parent_item) {
+                       std::cerr << " parent not null" << std::endl;
+                       return _parent_item->on_event(ev);
                } else {
                        return false;
                }
        }
 
+
 protected:
-       InteractiveItem* _parent;
+       InteractiveItem* _parent_item;
 };
 
 } /* namespace Canvas */