summaryrefslogtreecommitdiff
path: root/gtk2_ardour
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-07-27 15:42:14 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-07-27 15:42:14 +0000
commit32b2ddd24a81dae469fd4b936dc20c5514b1f78a (patch)
treebb91bc925c839bbaeb6a454376f08250e1b1530f /gtk2_ardour
parentece5093234e4c185cf536d2b4e5edfeb90622409 (diff)
catch the step edit region if it goes away and prepare to use a new one; step edit insert position starts at the edit point, not the start of the edited region
git-svn-id: svn://localhost/ardour2/branches/3.0@7515 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r--gtk2_ardour/midi_time_axis.cc55
-rw-r--r--gtk2_ardour/midi_time_axis.h3
2 files changed, 46 insertions, 12 deletions
diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc
index 7651cff30e..b1d886a04b 100644
--- a/gtk2_ardour/midi_time_axis.cc
+++ b/gtk2_ardour/midi_time_axis.cc
@@ -165,6 +165,12 @@ MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session* sess,
/* ask for notifications of any new RegionViews */
_view->RegionViewAdded.connect (sigc::mem_fun(*this, &MidiTimeAxisView::region_view_added));
_view->attach ();
+
+ midi_track()->PlaylistChanged.connect (*this, invalidator (*this),
+ boost::bind (&MidiTimeAxisView::playlist_changed, this),
+ gui_context());
+ playlist_changed ();
+
}
HBox* midi_controls_hbox = manage(new HBox());
@@ -229,6 +235,31 @@ MidiTimeAxisView::~MidiTimeAxisView ()
delete controller_menu;
}
+void
+MidiTimeAxisView::playlist_changed ()
+{
+ step_edit_region_connection.disconnect ();
+ midi_track()->playlist()->RegionRemoved.connect (step_edit_region_connection, invalidator (*this),
+ ui_bind (&MidiTimeAxisView::region_removed, this, _1),
+ gui_context());
+}
+
+void
+MidiTimeAxisView::region_removed (boost::weak_ptr<Region> wr)
+{
+ boost::shared_ptr<Region> r (wr.lock());
+
+ if (!r) {
+ return;
+ }
+
+ if (step_edit_region == r) {
+ step_edit_region.reset();
+ // force a recompute of the insert position
+ step_edit_beat_pos = -1.0;
+ }
+}
+
void MidiTimeAxisView::model_changed()
{
std::list<std::string> device_modes = MIDI::Name::MidiPatchManager::instance()
@@ -876,7 +907,7 @@ void
MidiTimeAxisView::start_step_editing ()
{
step_edit_insert_position = _editor.get_preferred_edit_position ();
- step_edit_beat_pos = 0;
+ step_edit_beat_pos = -1.0;
step_edit_region = playlist()->top_region_at (step_edit_insert_position);
if (step_edit_region) {
@@ -925,18 +956,18 @@ MidiTimeAxisView::check_step_edit ()
step_edit_region = add_region (step_edit_insert_position);
RegionView* rv = view()->find_view (step_edit_region);
-
- if (rv) {
- step_edit_region_view = dynamic_cast<MidiRegionView*>(rv);
- } else {
- fatal << X_("programming error: no view found for new MIDI region") << endmsg;
- /*NOTREACHED*/
- }
- cerr << "New step edit region is called " << step_edit_region->name()
- << " view @ " << step_edit_region_view << endl;
+ step_edit_region_view = dynamic_cast<MidiRegionView*>(rv);
}
- if (step_edit_region_view) {
+ if (step_edit_region && step_edit_region_view) {
+
+ if (step_edit_beat_pos < 0.0) {
+ framecnt_t frames_from_start = _editor.get_preferred_edit_position() - step_edit_region->position();
+ if (frames_from_start < 0) {
+ continue;
+ }
+ step_edit_beat_pos = step_edit_region_view->frames_to_beats (frames_from_start);
+ }
bool success;
Evoral::MusicalTime beats = _editor.get_grid_type_as_beats (success, step_edit_insert_position);
@@ -944,7 +975,7 @@ MidiTimeAxisView::check_step_edit ()
if (!success) {
continue;
}
-
+
step_edit_region_view->step_add_note (buf[0] & 0xf, buf[1], buf[2], step_edit_beat_pos, beats);
step_edit_beat_pos += beats;
}
diff --git a/gtk2_ardour/midi_time_axis.h b/gtk2_ardour/midi_time_axis.h
index b118b9ab63..0ed44b96c0 100644
--- a/gtk2_ardour/midi_time_axis.h
+++ b/gtk2_ardour/midi_time_axis.h
@@ -136,6 +136,9 @@ class MidiTimeAxisView : public RouteTimeAxisView
Evoral::MusicalTime step_edit_beat_pos;
boost::shared_ptr<ARDOUR::Region> step_edit_region;
MidiRegionView* step_edit_region_view;
+ void region_removed (boost::weak_ptr<ARDOUR::Region>);
+ void playlist_changed ();
+ PBD::ScopedConnection step_edit_region_connection;
Gtk::Menu* build_def_channel_menu();
void set_default_channel (int);