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
This commit is contained in:
parent
d7db3f757f
commit
4d1542d1e5
|
@ -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); }
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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); }
|
||||
};
|
||||
|
||||
|
|
|
@ -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, ¬e);
|
||||
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), ¬e);
|
||||
ev_diamond->move(x, y);
|
||||
ev_diamond->show();
|
||||
ev_diamond->property_fill_color_rgba() = fill;
|
||||
|
|
|
@ -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__ */
|
||||
|
|
Loading…
Reference in New Issue