clean up item event handling in MidiRegionViews by removing unnecessary InteractiveItem inheritance, and keep child->parent event handling order consistent as much as possible

git-svn-id: svn://localhost/ardour2/branches/3.0@7186 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-05-28 16:37:04 +00:00
parent 3d6493abc9
commit 3e966771d0
11 changed files with 130 additions and 187 deletions

View file

@ -5,6 +5,26 @@
using namespace Gnome::Canvas;
using namespace std;
CanvasFlag::CanvasFlag (MidiRegionView& region,
Group& parent,
double height,
guint outline_color_rgba,
guint fill_color_rgba,
double x,
double y)
: Group(parent, x, y)
, _text(0)
, _height(height)
, _outline_color_rgba(outline_color_rgba)
, _fill_color_rgba(fill_color_rgba)
, _region(region)
, _line(0)
, _rect(0)
{
/* XXX this connection is needed if ::on_event() is changed to actually do anything */
signal_event().connect (sigc::mem_fun (*this, &CanvasFlag::on_event));
}
void
CanvasFlag::delete_allocated_objects()
{
@ -23,7 +43,7 @@ CanvasFlag::set_text(const string& a_text)
{
delete_allocated_objects();
_text = new InteractiveText(*this, this, 0.0, 0.0, Glib::ustring(a_text));
_text = new Text (*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;
@ -33,10 +53,14 @@ CanvasFlag::set_text(const 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, this, 0.0, 0.0, flagwidth, flagheight);
_rect = new SimpleRect(*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();
/* XXX these two connections are needed if ::on_event() is changed to actually do anything */
//_rect->signal_event().connect (sigc::mem_fun (*this, &CanvasFlag::on_event));
//_text->signal_event().connect (sigc::mem_fun (*this, &CanvasFlag::on_event));
}
CanvasFlag::~CanvasFlag()
@ -47,5 +71,8 @@ CanvasFlag::~CanvasFlag()
bool
CanvasFlag::on_event(GdkEvent* /*ev*/)
{
/* XXX if you change this function to actually do anything, be sure
to fix the connections commented out elsewhere in this file.
*/
return false;
}

View file

@ -4,38 +4,28 @@
#include <string>
#include <libgnomecanvasmm/group.h>
#include <libgnomecanvasmm/widget.h>
#include <libgnomecanvasmm/text.h>
#include "ardour/midi_model.h"
#include "simplerect.h"
#include "simpleline.h"
#include "interactive-item.h"
class MidiRegionView;
namespace Gnome {
namespace Canvas {
class CanvasFlag : public Group, public InteractiveItem
class CanvasFlag : public Group
{
public:
CanvasFlag(
MidiRegionView& region,
Group& parent,
double height,
guint outline_color_rgba = 0xc0c0c0ff,
guint fill_color_rgba = 0x07070707,
double x = 0.0,
double y = 0.0)
: Group(parent, x, y)
, _text(0)
, _height(height)
, _outline_color_rgba(outline_color_rgba)
, _fill_color_rgba(fill_color_rgba)
, _region(region)
, _line(0)
, _rect(0)
{}
CanvasFlag(MidiRegionView& region,
Group& parent,
double height,
guint outline_color_rgba = 0xc0c0c0ff,
guint fill_color_rgba = 0x07070707,
double x = 0.0,
double y = 0.0);
virtual ~CanvasFlag();
@ -44,7 +34,7 @@ public:
void set_text(const std::string& a_text);
protected:
InteractiveText* _text;
Text* _text;
double _height;
guint _outline_color_rgba;
guint _fill_color_rgba;
@ -54,7 +44,7 @@ private:
void delete_allocated_objects();
SimpleLine* _line;
InteractiveRect* _rect;
SimpleRect* _rect;
};

View file

@ -9,14 +9,26 @@ using namespace ARDOUR;
namespace Gnome {
namespace Canvas {
CanvasHit::CanvasHit (MidiRegionView& region,
Group& group,
double size,
const boost::shared_ptr<NoteType> note,
bool with_events)
: Diamond(group, size)
, CanvasNoteEvent(region, this, note)
{
if (with_events) {
signal_event().connect (sigc::mem_fun (*this, &CanvasHit::on_event));
}
}
bool
CanvasHit::on_event(GdkEvent* ev)
{
if (!_region.get_trackview().editor().canvas_note_event (ev, this)) {
return CanvasNoteEvent::on_event (ev);
} else {
return true;
}
if (!CanvasNoteEvent::on_event (ev)) {
return _region.get_trackview().editor().canvas_note_event (ev, this);
}
return true;
}
void

View file

@ -35,11 +35,8 @@ public:
MidiRegionView& region,
Group& group,
double size,
const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>())
: Diamond(group, size), CanvasNoteEvent(region, this, note)
{
}
const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>(),
bool with_events = true);
void show() { Diamond::show(); }
void hide() { Diamond::hide(); }

View file

@ -18,6 +18,9 @@
*/
#include <iostream>
#include "gtkmm2ext/keyboard.h"
#include "canvas-note-event.h"
#include "midi_region_view.h"
#include "public_editor.h"
@ -25,6 +28,7 @@
#include "keyboard.h"
using namespace std;
using namespace Gtkmm2ext;
using ARDOUR::MidiModel;
namespace Gnome {
@ -40,8 +44,7 @@ const uint32_t CanvasNoteEvent::midi_channel_colors[16] = {
0x832dd3ff, 0xa92dd3ff, 0xd32dbfff, 0xd32d67ff
};
CanvasNoteEvent::CanvasNoteEvent(MidiRegionView& region, Item* item,
const boost::shared_ptr<NoteType> note)
CanvasNoteEvent::CanvasNoteEvent(MidiRegionView& region, Item* item, const boost::shared_ptr<NoteType> note)
: _region(region)
, _item(item)
, _text(0)
@ -81,7 +84,7 @@ void
CanvasNoteEvent::show_velocity()
{
if (!_text) {
_text = new InteractiveText(*(_item->property_parent()), this);
_text = new NoEventText (*(_item->property_parent()));
}
_text->property_x() = (x1() + x2()) /2;
_text->property_y() = (y1() + y2()) /2;
@ -218,35 +221,31 @@ CanvasNoteEvent::base_color()
bool
CanvasNoteEvent::on_event(GdkEvent* ev)
{
PublicEditor& editor (_region.get_time_axis_view().editor());
if (!editor.internal_editing()) {
cerr << "CNE: on_event type " << ev->type << endl;
if (!_region.get_time_axis_view().editor().internal_editing()) {
return false;
}
switch (ev->type) {
case GDK_ENTER_NOTIFY:
_region.note_entered(this);
//Keyboard::magic_widget_grab_focus();
break;
case GDK_LEAVE_NOTIFY:
//Keyboard::magic_widget_drop_focus();
_region.note_left (this);
if (!selected()) {
hide_velocity();
}
break;
case GDK_BUTTON_PRESS:
if (ev->button.button == 3) {
show_channel_selector();
cerr << "button press, bton = " << ev->button.button << endl;
if (ev->button.button == 3 && Keyboard::no_modifiers_active (ev->button.state)) {
show_channel_selector();
return true;
}
break;
case GDK_BUTTON_RELEASE:
if (ev->button.button == 3) {
if (ev->button.button == 3 && Keyboard::no_modifiers_active (ev->button.state)) {
return true;
}
break;

View file

@ -28,8 +28,8 @@
#include "rgb_macros.h"
#include "ardour_ui.h"
#include "canvas-noevent-text.h"
#include "ui_config.h"
#include "interactive-item.h"
class Editor;
class MidiRegionView;
@ -51,8 +51,9 @@ namespace Canvas {
*
* A newer, better canvas should remove the need for all the ugly here.
*/
class CanvasNoteEvent : virtual public sigc::trackable, public InteractiveItem {
public:
class CanvasNoteEvent : virtual public sigc::trackable
{
public:
typedef Evoral::Note<ARDOUR::MidiModel::TimeType> NoteType;
CanvasNoteEvent(
@ -129,7 +130,7 @@ protected:
MidiRegionView& _region;
Item* const _item;
InteractiveText* _text;
NoEventText* _text;
Widget* _channel_selector_widget;
State _state;
const boost::shared_ptr<NoteType> _note;

View file

@ -8,14 +8,25 @@ using namespace ARDOUR;
namespace Gnome {
namespace Canvas {
CanvasNote::CanvasNote (MidiRegionView& region,
Group& group,
const boost::shared_ptr<NoteType> note,
bool with_events)
: SimpleRect(group), CanvasNoteEvent(region, this, note)
{
if (with_events) {
signal_event().connect (sigc::mem_fun (*this, &CanvasNote::on_event));
}
}
bool
CanvasNote::on_event(GdkEvent* ev)
{
if (!_region.get_trackview().editor().canvas_note_event (ev, this)) {
return CanvasNoteEvent::on_event (ev);
} else {
return true;
if (!CanvasNoteEvent::on_event (ev)) {
return _region.get_trackview().editor().canvas_note_event (ev, this);
}
return true;
}
void

View file

@ -29,10 +29,16 @@
namespace Gnome {
namespace Canvas {
class CanvasNote : public SimpleRect, public CanvasNoteEvent {
public:
class CanvasNote : public SimpleRect, public CanvasNoteEvent
{
public:
typedef Evoral::Note<Evoral::MusicalTime> NoteType;
CanvasNote (MidiRegionView& region,
Group& group,
const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>(),
bool with_events = true);
double x1() { return property_x1(); }
double y1() { return property_y1(); }
double x2() { return property_x2(); }
@ -46,25 +52,16 @@ public:
bool on_event(GdkEvent* ev);
void move_event(double dx, double dy);
CanvasNote (MidiRegionView& region,
Group& group,
const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>())
: SimpleRect(group), CanvasNoteEvent(region, this, note)
{
}
};
class NoEventCanvasNote : public CanvasNote
{
public:
NoEventCanvasNote (
MidiRegionView& region,
Group& group,
const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>()
)
: CanvasNote (region, group, note) {}
public:
NoEventCanvasNote (MidiRegionView& region,
Group& group,
const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>())
: CanvasNote (region, group, note, false) {}
double point_vfunc(double, double, int, int, GnomeCanvasItem**) {
/* return a huge value to tell the canvas that we're never the item for an event */
return 9999999999999.0;

View file

@ -44,7 +44,6 @@
#include "control_point.h"
#include "canvas_impl.h"
#include "simplerect.h"
#include "interactive-item.h"
#include "editor_drag.h"
#include "midi_time_axis.h"
#include "editor_regions.h"
@ -65,12 +64,6 @@ Editor::track_canvas_scroll (GdkEventScroll* ev)
nframes64_t xdelta;
int direction = ev->direction;
Gnome::Canvas::Item* item = track_canvas->get_item_at(ev->x, ev->y);
InteractiveItem* interactive_item = dynamic_cast<InteractiveItem*>(item);
if (interactive_item) {
return interactive_item->on_event(reinterpret_cast<GdkEvent*>(ev));
}
retry:
switch (direction) {
case GDK_SCROLL_UP:
@ -153,8 +146,7 @@ bool
Editor::track_canvas_scroll_event (GdkEventScroll *event)
{
track_canvas->grab_focus();
track_canvas_scroll (event);
return false;
return track_canvas_scroll (event);
}
bool
@ -961,6 +953,7 @@ Editor::canvas_note_event (GdkEvent *event, ArdourCanvas::Item* item)
return false;
}
cerr << "Forward note event item on to editor\n";
return typed_event (item, event, NoteItem);
}

View file

@ -1,93 +0,0 @@
/*
Copyright (C) 2008 Paul Davis
Author: Dave Robillard
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __ardour_interactive_item_h__
#define __ardour_interactive_item_h__
#include <libgnomecanvasmm/text.h>
#include "simplerect.h"
namespace Gnome {
namespace Canvas {
/** A canvas item that handles events.
* This is required so ardour can custom deliver events to specific items
* (e.g. to delineate scroll events) since Gnome::Canvas::Item::on_event
* is protected.
*/
class InteractiveItem {
public:
virtual ~InteractiveItem() {}
virtual bool on_event(GdkEvent* ev) = 0;
};
/** A canvas text that forwards events to its parent.
*/
class InteractiveText : public Text, public InteractiveItem {
public:
InteractiveText(Group& parent, InteractiveItem* parent_item, double x, double y, const Glib::ustring& text)
: Text(parent, x, y, text)
, _parent_item(parent_item)
{}
InteractiveText(Group& parent, InteractiveItem* parent_item)
: Text(parent)
, _parent_item(parent_item)
{}
bool on_event(GdkEvent* ev) {
if(_parent_item) {
return _parent_item->on_event(ev);
} else {
return false;
}
}
protected:
InteractiveItem* _parent_item;
};
class InteractiveRect: public SimpleRect, public InteractiveItem
{
public:
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_item) {
return _parent_item->on_event(ev);
} else {
return false;
}
}
protected:
InteractiveItem* _parent_item;
};
} /* namespace Canvas */
} /* namespace Gnome */
#endif /* __ardour_interactive_item_h__ */

View file

@ -277,6 +277,7 @@ bool
MidiRegionView::enter_notify (GdkEventCrossing* ev)
{
/* FIXME: do this on switch to note tool, too, if the pointer is already in */
Keyboard::magic_widget_grab_focus();
group->grab_focus();
@ -290,6 +291,7 @@ MidiRegionView::enter_notify (GdkEventCrossing* ev)
bool
MidiRegionView::leave_notify (GdkEventCrossing* ev)
{
_mouse_state = None;
trackview.editor().hide_verbose_canvas_cursor ();
delete _ghost_note;
_ghost_note = 0;
@ -511,16 +513,20 @@ MidiRegionView::motion (GdkEventMotion* ev)
bool
MidiRegionView::scroll (GdkEventScroll* ev)
{
bool fine = Keyboard::modifier_state_equals (ev->state, Keyboard::Level4Modifier);
if (_selection.empty()) {
return false;
}
trackview.editor().hide_verbose_canvas_cursor ();
bool fine = Keyboard::modifier_state_equals (ev->state, Keyboard::SecondaryModifier);
if (ev->direction == GDK_SCROLL_UP) {
change_velocities (true, fine, false);
return true;
} else if (ev->direction == GDK_SCROLL_DOWN) {
change_velocities (false, fine, false);
return true;
}
return false;
return true;
}
bool
@ -566,8 +572,8 @@ MidiRegionView::key_press (GdkEventKey* ev)
} else if (ev->keyval == GDK_Up) {
bool allow_smush = Keyboard::modifier_state_contains (ev->state, Keyboard::SecondaryModifier);
bool fine = Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier);
bool allow_smush = Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier);
bool fine = !Keyboard::modifier_state_contains (ev->state, Keyboard::SecondaryModifier);
if (Keyboard::modifier_state_contains (ev->state, Keyboard::PrimaryModifier)) {
change_velocities (true, fine, allow_smush);
@ -578,8 +584,8 @@ MidiRegionView::key_press (GdkEventKey* ev)
} else if (ev->keyval == GDK_Down) {
bool allow_smush = Keyboard::modifier_state_contains (ev->state, Keyboard::SecondaryModifier);
bool fine = Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier);
bool allow_smush = Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier);
bool fine = !Keyboard::modifier_state_contains (ev->state, Keyboard::SecondaryModifier);
if (Keyboard::modifier_state_contains (ev->state, Keyboard::PrimaryModifier)) {
change_velocities (false, fine, allow_smush);
@ -1306,6 +1312,7 @@ MidiRegionView::update_note (CanvasNote* ev)
{
boost::shared_ptr<NoteType> note = ev->note();
const nframes64_t note_start_frames = beats_to_frames(note->time());
const nframes64_t note_end_frames = beats_to_frames(note->end_time());
@ -2179,6 +2186,8 @@ MidiRegionView::change_note_velocity(CanvasNoteEvent* event, int8_t velocity, bo
new_velocity = velocity;
}
event->show_velocity ();
diff_add_change (event, MidiModel::DiffCommand::Velocity, new_velocity);
}
@ -2485,6 +2494,7 @@ MidiRegionView::change_channel(uint8_t channel)
for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
diff_add_change (*i, MidiModel::DiffCommand::Channel, channel);
}
apply_diff();
}
@ -2493,20 +2503,19 @@ void
MidiRegionView::note_entered(ArdourCanvas::CanvasNoteEvent* ev)
{
if (_mouse_state == SelectTouchDragging) {
note_selected(ev, true);
note_selected (ev, true);
}
show_verbose_canvas_cursor (ev->note ());
}
void
MidiRegionView::note_left (ArdourCanvas::CanvasNoteEvent*)
MidiRegionView::note_left (ArdourCanvas::CanvasNoteEvent* note)
{
PublicEditor& editor (trackview.editor());
editor.hide_verbose_canvas_cursor ();
note->hide_velocity ();
trackview.editor().hide_verbose_canvas_cursor ();
}
void
MidiRegionView::switch_source(boost::shared_ptr<Source> src)
{