summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-08-01 21:59:07 +0000
committerDavid Robillard <d@drobilla.net>2007-08-01 21:59:07 +0000
commit4d1542d1e59737fb3f6464ebb5638ca64cb985e8 (patch)
tree1a72d1deecab5ce7a443c7324122b8251a991f71
parentd7db3f757fde92126ef9886370ce604992b7e974 (diff)
Note deleting.
Press delete on a single note to delete it. Hold delete and mouse over a number of notes to delete them all in a single operation. git-svn-id: svn://localhost/ardour2/trunk@2214 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--gtk2_ardour/canvas-hit.h10
-rw-r--r--gtk2_ardour/canvas-midi-event.cc25
-rw-r--r--gtk2_ardour/canvas-midi-event.h14
-rw-r--r--gtk2_ardour/canvas-note.h12
-rw-r--r--gtk2_ardour/midi_region_view.cc16
-rw-r--r--gtk2_ardour/midi_region_view.h40
6 files changed, 101 insertions, 16 deletions
diff --git a/gtk2_ardour/canvas-hit.h b/gtk2_ardour/canvas-hit.h
index 2760e62c79..e3dcc452de 100644
--- a/gtk2_ardour/canvas-hit.h
+++ b/gtk2_ardour/canvas-hit.h
@@ -29,8 +29,14 @@ namespace Canvas {
class CanvasHit : public Diamond, public CanvasMidiEvent {
public:
- CanvasHit(MidiRegionView& region, Group& group, double size)
- : Diamond(group, size), CanvasMidiEvent(region, this) {}
+ CanvasHit(MidiRegionView& region, Group& group, double size, const ARDOUR::MidiModel::Note* note=NULL)
+ : Diamond(group, size), CanvasMidiEvent(region, this, note) {}
+
+ virtual void selected(bool yn) {
+ // Temporary hack, no reversal for now
+ if (yn)
+ property_outline_color_rgba() = 0xFF000099;
+ }
bool on_event(GdkEvent* ev) { return CanvasMidiEvent::on_event(ev); }
};
diff --git a/gtk2_ardour/canvas-midi-event.cc b/gtk2_ardour/canvas-midi-event.cc
index dafe94872c..90b7ff09df 100644
--- a/gtk2_ardour/canvas-midi-event.cc
+++ b/gtk2_ardour/canvas-midi-event.cc
@@ -25,15 +25,17 @@
#include "keyboard.h"
using namespace std;
+using ARDOUR::MidiModel;
namespace Gnome {
namespace Canvas {
-CanvasMidiEvent::CanvasMidiEvent(MidiRegionView& region, Item* item)
+CanvasMidiEvent::CanvasMidiEvent(MidiRegionView& region, Item* item, const ARDOUR::MidiModel::Note* note)
: _region(region)
, _item(item)
, _state(None)
+ , _note(note)
{
}
@@ -48,10 +50,27 @@ CanvasMidiEvent::on_event(GdkEvent* ev)
return false;
switch (ev->type) {
+ case GDK_KEY_PRESS:
+ if (_note && ev->key.keyval == GDK_Delete) {
+ _region.start_remove_command();
+ _region.command_remove_note(this);
+ }
+ break;
+
+ case GDK_KEY_RELEASE:
+ if (ev->key.keyval == GDK_Delete) {
+ _region.apply_command();
+ }
+ break;
+
case GDK_ENTER_NOTIFY:
cerr << "ENTERED: " << ev->crossing.state << endl;
Keyboard::magic_widget_grab_focus();
_item->grab_focus();
+ _region.note_entered(this);
+ //if (delete_down)
+ // cerr << "DELETE ENTER\n" << endl;
+
/*if ( (ev->crossing.state & GDK_BUTTON2_MASK) ) {
}*/
@@ -63,10 +82,6 @@ CanvasMidiEvent::on_event(GdkEvent* ev)
//_region.get_time_axis_view().editor.reset_focus();
_region.get_canvas_group()->grab_focus();
break;
-
- case GDK_KEY_PRESS:
- cerr << "EVENT KEY PRESS\n"; // doesn't work :/
- break;
case GDK_BUTTON_PRESS:
_state = Pressed;
diff --git a/gtk2_ardour/canvas-midi-event.h b/gtk2_ardour/canvas-midi-event.h
index bd98e82efd..def2203f5c 100644
--- a/gtk2_ardour/canvas-midi-event.h
+++ b/gtk2_ardour/canvas-midi-event.h
@@ -21,6 +21,7 @@
#define __gtk_ardour_canvas_midi_event_h__
#include "simplerect.h"
+#include <ardour/midi_model.h>
class Editor;
class MidiRegionView;
@@ -40,17 +41,22 @@ namespace Canvas {
*/
class CanvasMidiEvent {
public:
- CanvasMidiEvent(MidiRegionView& region, Item* item);
+ CanvasMidiEvent(MidiRegionView& region, Item* item, const ARDOUR::MidiModel::Note* note = NULL);
virtual ~CanvasMidiEvent() {}
virtual bool on_event(GdkEvent* ev);
+ virtual void selected(bool yn) = 0;
+
+ const ARDOUR::MidiModel::Note* note() { return _note; }
+
private:
enum State { None, Pressed, Dragging };
- MidiRegionView& _region;
- Item* const _item;
- State _state;
+ MidiRegionView& _region;
+ Item* const _item;
+ State _state;
+ const ARDOUR::MidiModel::Note* _note;
};
} // namespace Gnome
diff --git a/gtk2_ardour/canvas-note.h b/gtk2_ardour/canvas-note.h
index 2d64095187..f49157e0cf 100644
--- a/gtk2_ardour/canvas-note.h
+++ b/gtk2_ardour/canvas-note.h
@@ -29,11 +29,17 @@ namespace Canvas {
class CanvasNote : public SimpleRect, public CanvasMidiEvent {
public:
- CanvasNote(MidiRegionView& region, Group& group)
- : SimpleRect(group), CanvasMidiEvent(region, this)
+ CanvasNote(MidiRegionView& region, Group& group, const ARDOUR::MidiModel::Note* note=NULL)
+ : SimpleRect(group), CanvasMidiEvent(region, this, note)
{
}
-
+
+ virtual void selected(bool yn) {
+ // Temporary hack, no reversal for now
+ if (yn)
+ property_outline_color_rgba() = 0xFF000099;
+ }
+
bool on_event(GdkEvent* ev) { return CanvasMidiEvent::on_event(ev); }
};
diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc
index d1156bb9c5..61d3ce770d 100644
--- a/gtk2_ardour/midi_region_view.cc
+++ b/gtk2_ardour/midi_region_view.cc
@@ -61,6 +61,7 @@ MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &
Gdk::Color& basic_color)
: RegionView (parent, tv, r, spu, basic_color)
, _active_notes(0)
+ , _command_mode(None)
{
}
@@ -68,6 +69,7 @@ MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &
Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
: RegionView (parent, tv, r, spu, basic_color, visibility)
, _active_notes(0)
+ , _command_mode(None)
{
}
@@ -122,6 +124,16 @@ MidiRegionView::canvas_event(GdkEvent* ev)
return false;
switch (ev->type) {
+ case GDK_KEY_PRESS:
+ if (ev->key.keyval == GDK_Delete)
+ start_remove_command();
+ break;
+
+ case GDK_KEY_RELEASE:
+ if (_command_mode == Remove && ev->key.keyval == GDK_Delete)
+ apply_command();
+ break;
+
case GDK_BUTTON_PRESS:
//group->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, ev->button.time);
_state = Pressed;
@@ -506,7 +518,7 @@ MidiRegionView::add_note (const MidiModel::Note& note)
const double y1 = trackview.height - (pixel_range * (note.note() - view->lowest_note() + 1))
- footer_height - 3.0;
- ArdourCanvas::SimpleRect * ev_rect = new CanvasNote(*this, *group);
+ ArdourCanvas::SimpleRect * ev_rect = new CanvasNote(*this, *group, &note);
ev_rect->property_x1() = trackview.editor.frame_to_pixel((nframes_t)note.time());
ev_rect->property_y1() = y1;
ev_rect->property_x2() = trackview.editor.frame_to_pixel((nframes_t)(note.end_time()));
@@ -524,7 +536,7 @@ MidiRegionView::add_note (const MidiModel::Note& note)
const double y = trackview.height - (pixel_range * (note.note() - view->lowest_note() + 1))
- footer_height - 3.0;
- CanvasHit* ev_diamond = new CanvasHit(*this, *group, std::min(pixel_range, 5.0));
+ CanvasHit* ev_diamond = new CanvasHit(*this, *group, std::min(pixel_range, 5.0), &note);
ev_diamond->move(x, y);
ev_diamond->show();
ev_diamond->property_fill_color_rgba() = fill;
diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h
index 9207ca6b21..9324838abe 100644
--- a/gtk2_ardour/midi_region_view.h
+++ b/gtk2_ardour/midi_region_view.h
@@ -34,6 +34,7 @@
#include "enums.h"
#include "canvas.h"
#include "canvas-note.h"
+#include "canvas-midi-event.h"
namespace ARDOUR {
class MidiRegion;
@@ -76,6 +77,40 @@ class MidiRegionView : public RegionView
void display_model(boost::shared_ptr<ARDOUR::MidiModel> model);
+ inline void start_remove_command() {
+ _command_mode = Remove;
+ if (!_delta_command)
+ _delta_command = _model->new_delta_command();
+ }
+
+ void command_remove_note(ArdourCanvas::CanvasMidiEvent* ev) {
+ if (_delta_command && ev->note()) {
+ _delta_command->remove(*ev->note());
+ ev->selected(true);
+ }
+ }
+
+ void note_entered(ArdourCanvas::CanvasMidiEvent* ev) {
+ if (_command_mode == Remove && _delta_command && ev->note())
+ _delta_command->remove(*ev->note());
+ }
+
+ //ARDOUR::MidiModel::DeltaCommand* delta_command() { return _delta_command; }
+
+ void abort_command() {
+ delete _delta_command;
+ _delta_command = NULL;
+ _command_mode = None;
+ }
+
+ void apply_command() {
+ if (_delta_command) {
+ _model->apply_command(_delta_command);
+ _delta_command = NULL;
+ }
+ _command_mode = None;
+ }
+
protected:
/* this constructor allows derived types
@@ -108,6 +143,11 @@ class MidiRegionView : public RegionView
boost::shared_ptr<ARDOUR::MidiModel> _model;
std::vector<ArdourCanvas::Item*> _events;
ArdourCanvas::CanvasNote** _active_notes;
+ ARDOUR::MidiModel::DeltaCommand* _delta_command;
+
+ enum CommandMode { None, Remove };
+ CommandMode _command_mode;
+
};
#endif /* __gtk_ardour_midi_region_view_h__ */