2 Copyright (C) 2001-2007 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <gtkmm2ext/gtk_ui.h>
28 #include <sigc++/signal.h>
30 #include <ardour/playlist.h>
31 #include <ardour/tempo.h>
32 #include <ardour/midi_region.h>
33 #include <ardour/midi_source.h>
34 #include <ardour/midi_diskstream.h>
35 #include <ardour/midi_events.h>
36 #include <ardour/midi_model.h>
38 #include "streamview.h"
39 #include "midi_region_view.h"
40 #include "midi_streamview.h"
41 #include "midi_time_axis.h"
42 #include "simpleline.h"
43 #include "canvas-hit.h"
44 #include "public_editor.h"
45 #include "ghostregion.h"
46 #include "midi_time_axis.h"
47 #include "automation_time_axis.h"
48 #include "automation_region_view.h"
50 #include "midi_util.h"
51 #include "gui_thread.h"
57 using namespace ARDOUR;
59 using namespace Editing;
60 using namespace ArdourCanvas;
62 MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color& basic_color)
63 : RegionView (parent, tv, r, spu, basic_color)
64 , _default_note_length(0.0)
66 , _note_group(new ArdourCanvas::Group(*parent))
67 , _delta_command(NULL)
71 group->lower_to_bottom();
72 _note_group->raise_to_top();
74 frame->property_fill_color_rgba() = 0xff000033;
77 MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
78 : RegionView (parent, tv, r, spu, basic_color, visibility)
79 , _default_note_length(0.0)
81 , _note_group(new ArdourCanvas::Group(*parent))
82 , _delta_command(NULL)
86 _note_group->raise_to_top();
90 MidiRegionView::init (Gdk::Color& basic_color, bool wfd)
93 midi_region()->midi_source(0)->load_model();
95 const Meter& m = trackview.session().tempo_map().meter_at(_region->position());
96 const Tempo& t = trackview.session().tempo_map().tempo_at(_region->position());
97 _default_note_length = m.frames_per_bar(t, trackview.session().frame_rate())
100 _model = midi_region()->midi_source(0)->model();
101 _enable_display = false;
103 RegionView::init(basic_color, false);
105 compute_colors (basic_color);
107 reset_width_dependent_items ((double) _region->length() / samples_per_unit);
109 set_y_position_and_height (0, trackview.height);
112 region_resized (BoundsChanged);
115 _region->StateChanged.connect (mem_fun(*this, &MidiRegionView::region_changed));
119 _enable_display = true;
125 _model->ContentsChanged.connect(sigc::mem_fun(this, &MidiRegionView::redisplay_model));
128 midi_region()->midi_source(0)->Switched.connect(sigc::mem_fun(this, &MidiRegionView::switch_source));
130 group->signal_event().connect (mem_fun (this, &MidiRegionView::canvas_event), false);
135 MidiRegionView::canvas_event(GdkEvent* ev)
137 static bool delete_mod = false;
138 static Editing::MidiEditMode original_mode;
140 static double drag_start_x, drag_start_y;
141 static double last_x, last_y;
142 double event_x, event_y;
143 nframes_t event_frame = 0;
145 static ArdourCanvas::SimpleRect* drag_rect = NULL;
147 if (trackview.editor.current_mouse_mode() != MouseNote)
154 if (ev->key.keyval == GDK_Delete && !delete_mod) {
156 original_mode = trackview.editor.current_midi_edit_mode();
157 trackview.editor.set_midi_edit_mode(MidiEditErase);
158 start_delta_command();
159 _mouse_state = EraseTouchDragging;
161 } else if (ev->key.keyval == GDK_Shift_L || ev->key.keyval == GDK_Control_L) {
162 _mouse_state = SelectTouchDragging;
167 case GDK_KEY_RELEASE:
168 if (ev->key.keyval == GDK_Delete) {
169 if (_mouse_state == EraseTouchDragging) {
174 trackview.editor.set_midi_edit_mode(original_mode);
178 } else if (ev->key.keyval == GDK_Shift_L || ev->key.keyval == GDK_Control_L) {
184 case GDK_BUTTON_PRESS:
185 if (_mouse_state != SelectTouchDragging && _mouse_state != EraseTouchDragging)
186 _mouse_state = Pressed;
187 _pressed_button = ev->button.button;
190 case GDK_ENTER_NOTIFY:
191 /* FIXME: do this on switch to note tool, too, if the pointer is already in */
192 Keyboard::magic_widget_grab_focus();
196 case GDK_MOTION_NOTIFY:
197 event_x = ev->motion.x;
198 event_y = ev->motion.y;
199 group->w2i(event_x, event_y);
201 event_frame = trackview.editor.pixel_to_frame(event_x);
202 trackview.editor.snap_to(event_frame);
204 switch (_mouse_state) {
205 case Pressed: // Drag start
208 if (_pressed_button == 1 && trackview.editor.current_midi_edit_mode() == MidiEditSelect) {
209 group->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
210 Gdk::Cursor(Gdk::FLEUR), ev->motion.time);
213 drag_start_x = event_x;
214 drag_start_y = event_y;
216 drag_rect = new ArdourCanvas::SimpleRect(*group);
217 drag_rect->property_x1() = event_x;
218 drag_rect->property_y1() = event_y;
219 drag_rect->property_x2() = event_x;
220 drag_rect->property_y2() = event_y;
221 drag_rect->property_outline_what() = 0xFF;
222 drag_rect->property_outline_color_rgba()
223 = ARDOUR_UI::config()->canvasvar_MidiSelectRectOutline.get();
224 drag_rect->property_fill_color_rgba()
225 = ARDOUR_UI::config()->canvasvar_MidiSelectRectFill.get();
227 _mouse_state = SelectRectDragging;
230 // Add note drag start
231 } else if (trackview.editor.current_midi_edit_mode() == MidiEditPencil) {
232 group->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
233 Gdk::Cursor(Gdk::FLEUR), ev->motion.time);
236 drag_start_x = event_x;
237 drag_start_y = event_y;
239 drag_rect = new ArdourCanvas::SimpleRect(*group);
240 drag_rect->property_x1() = trackview.editor.frame_to_pixel(event_frame);
242 drag_rect->property_y1() = midi_stream_view()->note_to_y(midi_stream_view()->y_to_note(event_y));
243 drag_rect->property_x2() = event_x;
244 drag_rect->property_y2() = drag_rect->property_y1() + floor(midi_stream_view()->note_height());
245 drag_rect->property_outline_what() = 0xFF;
246 drag_rect->property_outline_color_rgba() = 0xFFFFFF99;
248 drag_rect->property_fill_color_rgba() = 0xFFFFFF66;
250 _mouse_state = AddDragging;
256 case SelectRectDragging: // Select drag motion
257 case AddDragging: // Add note drag motion
258 if (ev->motion.is_hint) {
261 GdkModifierType state;
262 gdk_window_get_pointer(ev->motion.window, &t_x, &t_y, &state);
267 if (_mouse_state == AddDragging)
268 event_x = trackview.editor.frame_to_pixel(event_frame);
271 if (event_x > drag_start_x)
272 drag_rect->property_x2() = event_x;
274 drag_rect->property_x1() = event_x;
276 if (drag_rect && _mouse_state == SelectRectDragging) {
277 if (event_y > drag_start_y)
278 drag_rect->property_y2() = event_y;
280 drag_rect->property_y1() = event_y;
282 update_drag_selection(drag_start_x, event_x, drag_start_y, event_y);
288 case EraseTouchDragging:
289 case SelectTouchDragging:
297 case GDK_BUTTON_RELEASE:
298 event_x = ev->motion.x;
299 event_y = ev->motion.y;
300 group->w2i(event_x, event_y);
301 group->ungrab(ev->button.time);
302 event_frame = trackview.editor.pixel_to_frame(event_x);
304 switch (_mouse_state) {
305 case Pressed: // Clicked
306 switch (trackview.editor.current_midi_edit_mode()) {
311 trackview.editor.snap_to(event_frame, -1);
312 event_x = trackview.editor.frame_to_pixel(event_frame);
313 create_note_at(event_x, event_y, _default_note_length);
319 case SelectRectDragging: // Select drag done
324 case AddDragging: // Add drag done
326 if (drag_rect->property_x2() > drag_rect->property_x1() + 2) {
327 create_note_at(drag_rect->property_x1(), drag_rect->property_y1(),
328 trackview.editor.pixel_to_frame(
329 drag_rect->property_x2() - drag_rect->property_x1()));
347 /** Add a note to the model, and the view, at a canvas (click) coordinate */
349 MidiRegionView::create_note_at(double x, double y, double dur)
351 MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
352 MidiStreamView* const view = mtv->midi_view();
354 double note = midi_stream_view()->y_to_note(y);
357 assert(note <= 127.0);
359 const nframes_t stamp = trackview.editor.pixel_to_frame (x);
361 //assert(stamp <= _region->length());
363 //const Meter& m = trackview.session().tempo_map().meter_at(stamp);
364 //const Tempo& t = trackview.session().tempo_map().tempo_at(stamp);
365 //double dur = m.frames_per_bar(t, trackview.session().frame_rate()) / m.beats_per_bar();
367 // Add a 1 beat long note (for now)
368 const boost::shared_ptr<Note> new_note(new Note(0, stamp, dur, (uint8_t)note, 0x40));
370 view->update_bounds(new_note->note());
372 MidiModel::DeltaCommand* cmd = _model->new_delta_command("add note");
374 _model->apply_command(cmd);
376 //add_note(new_note);
381 MidiRegionView::clear_events()
386 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
387 if ((gr = dynamic_cast<MidiGhostRegion*>(*g)) != 0) {
392 for (std::vector<CanvasMidiEvent*>::iterator i = _events.begin(); i != _events.end(); ++i)
400 MidiRegionView::display_model(boost::shared_ptr<MidiModel> model)
410 MidiRegionView::redisplay_model()
412 // Don't redisplay the model if we're currently recording and displaying that
423 for (size_t i=0; i < _model->n_notes(); ++i)
424 add_note(_model->note_at(i));
428 /*for (Automatable::Controls::const_iterator i = _model->controls().begin();
429 i != _model->controls().end(); ++i) {
433 boost::shared_ptr<AutomationTimeAxisView> at
434 = midi_view()->automation_child(i->second->parameter());
438 Gdk::Color col = midi_stream_view()->get_region_color();
440 boost::shared_ptr<AutomationRegionView> arv;
443 Glib::Mutex::Lock list_lock (i->second->list()->lock());
445 arv = boost::shared_ptr<AutomationRegionView>(
446 new AutomationRegionView(at->canvas_display,
447 *at.get(), _region, i->second->list(),
448 midi_stream_view()->get_samples_per_unit(), col));
451 arv->set_duration(_region->length(), this);
452 arv->init(col, true);
454 _automation_children.insert(std::make_pair(i->second->parameter(), arv));
457 _model->read_unlock();
460 cerr << "MidiRegionView::redisplay_model called without a model" << endmsg;
465 MidiRegionView::~MidiRegionView ()
467 in_destructor = true;
469 RegionViewGoingAway (this); /* EMIT_SIGNAL */
477 delete _delta_command;
482 MidiRegionView::region_resized (Change what_changed)
484 RegionView::region_resized(what_changed);
486 if (what_changed & ARDOUR::PositionChanged) {
491 } else if (what_changed & Change (StartChanged)) {
493 //cerr << "MIDI RV START CHANGED" << endl;
495 } else if (what_changed & Change (LengthChanged)) {
497 //cerr << "MIDI RV LENGTH CHANGED" << endl;
503 MidiRegionView::reset_width_dependent_items (double pixel_width)
505 RegionView::reset_width_dependent_items(pixel_width);
506 assert(_pixel_width == pixel_width);
513 MidiRegionView::set_y_position_and_height (double y, double h)
515 RegionView::set_y_position_and_height(y, h - 1);
517 if (_enable_display) {
521 for (std::vector<CanvasMidiEvent*>::const_iterator i = _events.begin(); i != _events.end(); ++i) {
522 CanvasNote* note = dynamic_cast<CanvasNote*>(*i);
523 if (note && note->note()) {
524 if (note->note()->note() < midi_stream_view()->lowest_note() ||
525 note->note()->note() > midi_stream_view()->highest_note()) {
526 if (canvas_item_visible(note)) {
531 const double y1 = midi_stream_view()->note_to_y(note->note()->note());
532 const double y2 = y1 + floor(midi_stream_view()->note_height());
534 if (!canvas_item_visible(note)) {
538 note->property_y1() = y1;
539 note->property_y2() = y2;
544 _model->read_unlock();
548 name_text->raise_to_top();
553 MidiRegionView::add_ghost (TimeAxisView& tv)
555 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
559 double unit_position = _region->position () / samples_per_unit;
560 MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*>(&tv);
561 MidiGhostRegion* ghost;
563 if (mtv && mtv->midi_view()) {
564 /* if ghost is inserted into midi track, use a dedicated midi ghost canvas group.
565 this is because it's nice to have midi notes on top of the note lines and
566 audio waveforms under it.
568 ghost = new MidiGhostRegion (*mtv->midi_view(), trackview, unit_position);
571 ghost = new MidiGhostRegion (tv, trackview, unit_position);
574 ghost->set_height ();
575 ghost->set_duration (_region->length() / samples_per_unit);
576 ghosts.push_back (ghost);
578 for (std::vector<CanvasMidiEvent*>::iterator i = _events.begin(); i != _events.end(); ++i) {
579 if ((note = dynamic_cast<CanvasNote*>(*i)) != 0) {
580 ghost->add_note(note);
584 ghost->GoingAway.connect (mem_fun(*this, &MidiRegionView::remove_ghost));
590 /** Begin tracking note state for successive calls to add_event
593 MidiRegionView::begin_write()
595 assert(!_active_notes);
596 _active_notes = new CanvasNote*[128];
597 for (unsigned i=0; i < 128; ++i)
598 _active_notes[i] = NULL;
602 /** Destroy note state for add_event
605 MidiRegionView::end_write()
607 delete[] _active_notes;
608 _active_notes = NULL;
612 /** Resolve an active MIDI note (while recording).
615 MidiRegionView::resolve_note(uint8_t note, double end_time)
617 if (midi_view()->note_mode() != Sustained)
620 if (_active_notes && _active_notes[note]) {
621 _active_notes[note]->property_x2() = trackview.editor.frame_to_pixel((nframes_t)end_time);
622 _active_notes[note]->property_outline_what() = (guint32) 0xF; // all edges
623 _active_notes[note] = NULL;
628 /** Extend active notes to rightmost edge of region (if length is changed)
631 MidiRegionView::extend_active_notes()
636 for (unsigned i=0; i < 128; ++i)
637 if (_active_notes[i])
638 _active_notes[i]->property_x2() = trackview.editor.frame_to_pixel(_region->length());
642 /** Add a MIDI note to the view (with duration).
644 * If in sustained mode, notes with duration 0 will be considered active
645 * notes, and resolve_note should be called when the corresponding note off
646 * event arrives, to properly display the note.
649 MidiRegionView::add_note(const boost::shared_ptr<Note> note)
651 assert(note->time() >= 0);
652 //assert(note->time() < _region->length());
653 assert(midi_view()->note_mode() == Sustained || midi_view()->note_mode() == Percussive);
655 ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
657 if (midi_view()->note_mode() == Sustained) {
659 //cerr << "MRV::add_note sustained " << note->note() << " @ " << note->time()
660 // << " .. " << note->end_time() << endl;
662 const double y1 = midi_stream_view()->note_to_y(note->note());
664 CanvasNote* ev_rect = new CanvasNote(*this, *group, note);
665 ev_rect->property_x1() = trackview.editor.frame_to_pixel((nframes_t)note->time());
666 ev_rect->property_y1() = y1;
667 if (note->duration() > 0)
668 ev_rect->property_x2() = trackview.editor.frame_to_pixel((nframes_t)(note->end_time()));
670 ev_rect->property_x2() = trackview.editor.frame_to_pixel(_region->length());
671 ev_rect->property_y2() = y1 + floor(midi_stream_view()->note_height());
673 ev_rect->property_fill_color_rgba() = note_fill_color(note->velocity());
674 ev_rect->property_outline_color_rgba() = note_outline_color(note->velocity());
676 if (note->duration() == 0) {
677 _active_notes[note->note()] = ev_rect;
678 /* outline all but right edge */
679 ev_rect->property_outline_what() = (guint32) (0x1 & 0x4 & 0x8);
681 /* outline all edges */
682 ev_rect->property_outline_what() = (guint32) 0xF;
686 _events.push_back(ev_rect);
690 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
691 if ((gr = dynamic_cast<MidiGhostRegion*>(*g)) != 0) {
692 gr->add_note(ev_rect);
696 } else if (midi_view()->note_mode() == Percussive) {
698 //cerr << "MRV::add_note percussive " << note->note() << " @ " << note->time()
699 // << " .. " << note->end_time() << endl;
701 const double diamond_size = midi_stream_view()->note_height() / 2.0;
702 const double x = trackview.editor.frame_to_pixel((nframes_t)note->time());
703 const double y = midi_stream_view()->note_to_y(note->note()) + ((diamond_size-2) / 4.0);
705 CanvasHit* ev_diamond = new CanvasHit(*this, *group, diamond_size);
706 ev_diamond->move(x, y);
708 ev_diamond->property_fill_color_rgba() = note_fill_color(note->velocity());
709 ev_diamond->property_outline_color_rgba() = note_outline_color(note->velocity());
710 _events.push_back(ev_diamond);
716 MidiRegionView::delete_selection()
718 assert(_delta_command);
720 for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i)
721 if ((*i)->selected())
722 _delta_command->remove((*i)->note());
728 MidiRegionView::clear_selection_except(ArdourCanvas::CanvasMidiEvent* ev)
730 for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i)
731 if ((*i)->selected() && (*i) != ev)
732 (*i)->selected(false);
738 MidiRegionView::unique_select(ArdourCanvas::CanvasMidiEvent* ev)
740 for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i)
742 (*i)->selected(false);
745 _selection.insert(ev);
747 if ( ! ev->selected())
752 MidiRegionView::note_selected(ArdourCanvas::CanvasMidiEvent* ev, bool add)
755 clear_selection_except(ev);
757 _selection.insert(ev);
759 if ( ! ev->selected())
765 MidiRegionView::note_deselected(ArdourCanvas::CanvasMidiEvent* ev, bool add)
768 clear_selection_except(ev);
770 _selection.erase(ev);
778 MidiRegionView::update_drag_selection(double x1, double x2, double y1, double y2)
780 const double last_y = std::min(y1, y2);
781 const double y = std::max(y1, y2);
783 // FIXME: so, so, so much slower than this should be
786 for (std::vector<CanvasMidiEvent*>::iterator i = _events.begin(); i != _events.end(); ++i) {
787 if ((*i)->x1() >= x1 && (*i)->x1() <= x2 && (*i)->y1() >= last_y && (*i)->y1() <= y) {
788 (*i)->selected(true);
789 _selection.insert(*i);
791 (*i)->selected(false);
792 _selection.erase(*i);
796 for (std::vector<CanvasMidiEvent*>::iterator i = _events.begin(); i != _events.end(); ++i) {
797 if ((*i)->x2() <= x1 && (*i)->x2() >= x2 && (*i)->y1() >= last_y && (*i)->y1() <= y) {
798 (*i)->selected(true);
799 _selection.insert(*i);
801 (*i)->selected(false);
802 _selection.erase(*i);
810 MidiRegionView::move_selection(double dx, double dy)
812 for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i)
813 (*i)->item()->move(dx, dy);
818 MidiRegionView::note_dropped(CanvasMidiEvent* ev, double dt, uint8_t dnote)
820 // TODO: This would be faster/nicer with a MoveCommand that doesn't need to copy...
821 if (_selection.find(ev) != _selection.end()) {
822 start_delta_command();
824 for (Selection::iterator i = _selection.begin(); i != _selection.end() ; ) {
825 Selection::iterator next = i;
828 command_remove_note(*i);
829 const boost::shared_ptr<Note> copy(new Note(*(*i)->note().get()));
831 copy->set_time((*i)->note()->time() + dt);
832 copy->set_note((*i)->note()->note() + dnote);
834 command_add_note(copy);
844 MidiRegionView::begin_resizing(CanvasNote::NoteEnd note_end)
846 _resize_data.clear();
848 for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
849 CanvasNote *note = dynamic_cast<CanvasNote *> (*i);
851 // only insert CanvasNotes into the map
853 NoteResizeData *resize_data = new NoteResizeData();
854 resize_data->canvas_note = note;
856 SimpleRect *resize_rect = new SimpleRect(*group, note->x1(), note->y1(), note->x2(), note->y2());
858 uint fill_color = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_MidiNoteSelectedOutline.get(), 128);
859 fill_color = UINT_INTERPOLATE(fill_color, 0xFFFFFF40, 0.5);
861 resize_rect->property_fill_color_rgba() =
863 note_fill_color(note->note()->velocity()),
867 resize_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MidiNoteSelectedOutline.get();
868 resize_data->resize_rect = resize_rect;
870 if(note_end == CanvasNote::NOTE_ON) {
871 resize_data->current_x = note->x1();
873 resize_data->current_x = note->x2();
876 _resize_data.push_back(resize_data);
882 MidiRegionView::snap_to(double x)
884 PublicEditor &editor = trackview.editor;
886 nframes_t frame = editor.pixel_to_frame(x);
887 editor.snap_to(frame);
888 return (double) editor.frame_to_pixel(frame);
892 MidiRegionView::update_resizing(CanvasNote::NoteEnd note_end, double dx, bool relative)
896 for (std::vector<NoteResizeData *>::iterator i = _resize_data.begin(); i != _resize_data.end(); ++i) {
897 SimpleRect *resize_rect = (*i)->resize_rect;
898 CanvasNote *canvas_note = (*i)->canvas_note;
901 (*i)->current_x = (*i)->current_x + dx;
903 (*i)->current_x = dx;
906 double current_x = (*i)->current_x;
908 if(note_end == CanvasNote::NOTE_ON) {
909 resize_rect->property_x1() = snap_to(current_x);
910 resize_rect->property_x2() = canvas_note->x2();
912 resize_rect->property_x2() = snap_to(current_x);
913 resize_rect->property_x1() = canvas_note->x1();
919 MidiRegionView::commit_resizing(CanvasNote::NoteEnd note_end, double event_x, bool relative)
921 start_delta_command();
923 for (std::vector<NoteResizeData *>::iterator i = _resize_data.begin(); i != _resize_data.end(); ++i) {
924 CanvasNote *canvas_note = (*i)->canvas_note;
925 SimpleRect *resize_rect = (*i)->resize_rect;
926 double current_x = (*i)->current_x;
933 nframes_t current_frame = trackview.editor.pixel_to_frame(current_x);
934 trackview.editor.snap_to(current_frame);
936 const boost::shared_ptr<Note> copy(new Note(*(canvas_note->note().get())));
938 // resize beginning of note
939 if (note_end == CanvasNote::NOTE_ON && current_frame < copy->end_time()) {
940 command_remove_note(canvas_note);
941 copy->on_event().time() = current_frame;
942 command_add_note(copy);
944 // resize end of note
945 if (note_end == CanvasNote::NOTE_OFF && current_frame > copy->time()) {
946 command_remove_note(canvas_note);
947 copy->off_event().time() = current_frame;
948 command_add_note(copy);
955 _resize_data.clear();
961 MidiRegionView::note_entered(ArdourCanvas::CanvasMidiEvent* ev)
963 if (ev->note() && _mouse_state == EraseTouchDragging) {
964 start_delta_command();
966 _delta_command->remove(ev->note());
967 } else if (_mouse_state == SelectTouchDragging) {
968 note_selected(ev, true);
974 MidiRegionView::switch_source(boost::shared_ptr<Source> src)
976 boost::shared_ptr<MidiSource> msrc = boost::dynamic_pointer_cast<MidiSource>(src);
978 display_model(msrc->model());
982 MidiRegionView::set_frame_color()
985 if (_selected && should_show_selection) {
986 frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get();
988 frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MidiFrameBase.get();