+void
+Editor::set_loop_range (nframes64_t start, nframes64_t end, string cmd)
+{
+ if (!session) return;
+
+ begin_reversible_command (cmd);
+
+ Location* tll;
+
+ if ((tll = transport_loop_location()) == 0) {
+ Location* loc = new Location (start, end, _("Loop"), Location::IsAutoLoop);
+ XMLNode &before = session->locations()->get_state();
+ session->locations()->add (loc, true);
+ session->set_auto_loop_location (loc);
+ XMLNode &after = session->locations()->get_state();
+ session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
+ } else {
+ XMLNode &before = tll->get_state();
+ tll->set_hidden (false, this);
+ tll->set (start, end);
+ XMLNode &after = tll->get_state();
+ session->add_command (new MementoCommand<Location>(*tll, &before, &after));
+ }
+
+ commit_reversible_command ();
+}
+
+void
+Editor::set_punch_range (nframes64_t start, nframes64_t end, string cmd)
+{
+ if (!session) return;
+
+ begin_reversible_command (cmd);
+
+ Location* tpl;
+
+ if ((tpl = transport_punch_location()) == 0) {
+ Location* loc = new Location (start, end, _("Loop"), Location::IsAutoPunch);
+ XMLNode &before = session->locations()->get_state();
+ session->locations()->add (loc, true);
+ session->set_auto_loop_location (loc);
+ XMLNode &after = session->locations()->get_state();
+ session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
+ }
+ else {
+ XMLNode &before = tpl->get_state();
+ tpl->set_hidden (false, this);
+ tpl->set (start, end);
+ XMLNode &after = tpl->get_state();
+ session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
+ }
+
+ commit_reversible_command ();
+}
+
+void
+Editor::get_regions_at (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
+{
+ const TrackSelection* tracks;
+
+ if (ts.empty()) {
+ tracks = &track_views;
+ } else {
+ tracks = &ts;
+ }
+
+ for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
+
+ AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
+
+ if (atv) {
+ boost::shared_ptr<Diskstream> ds;
+ boost::shared_ptr<Playlist> pl;
+
+ if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
+
+ Playlist::RegionList* regions = pl->regions_at ((nframes64_t) floor ( (double)where * ds->speed()));
+
+ for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
+
+ RegionView* rv = atv->audio_view()->find_view (*i);
+
+ if (rv) {
+ rs.add (rv);
+ }
+ }
+
+ delete regions;
+ }
+ }
+ }
+}
+
+void
+Editor::get_regions_after (RegionSelection& rs, nframes64_t where, const TrackSelection& ts) const
+{
+ const TrackSelection* tracks;
+
+ if (ts.empty()) {
+ tracks = &track_views;
+ } else {
+ tracks = &ts;
+ }
+
+ for (TrackSelection::const_iterator t = tracks->begin(); t != tracks->end(); ++t) {
+
+ AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*t);
+
+ if (atv) {
+ boost::shared_ptr<Diskstream> ds;
+ boost::shared_ptr<Playlist> pl;
+
+ if ((ds = atv->get_diskstream()) && ((pl = ds->playlist()))) {
+
+ Playlist::RegionList* regions = pl->regions_touched ((nframes64_t) floor ( (double)where * ds->speed()), max_frames);
+
+ for (Playlist::RegionList::iterator i = regions->begin(); i != regions->end(); ++i) {
+
+ RegionView* rv = atv->audio_view()->find_view (*i);
+
+ if (rv) {
+ rs.push_back (rv);
+ }
+ }
+
+ delete regions;
+ }
+ }
+ }
+}
+
+void
+Editor::get_regions_for_action (RegionSelection& rs, bool allow_entered)
+{
+ if (selection->regions.empty()) {
+
+ if (selection->tracks.empty()) {
+
+ /* no regions or tracks selected
+ */
+
+ if (entered_regionview && mouse_mode == Editing::MouseObject) {
+
+ /* entered regionview is valid and we're in object mode -
+ just use entered regionview
+ */
+
+ rs.add (entered_regionview);
+ }
+
+ return;
+
+ } else {
+
+ /* no regions selected, so get all regions at the edit point across
+ all selected tracks.
+ */
+
+ nframes64_t where = get_preferred_edit_position();
+ get_regions_at (rs, where, selection->tracks);
+
+ /* if the entered regionview wasn't selected and neither was its track
+ then add it.
+ */
+
+ if (entered_regionview != 0 &&
+ !selection->selected (entered_regionview) &&
+ !selection->selected (&entered_regionview->get_time_axis_view())) {
+ rs.add (entered_regionview);
+ }
+ }
+
+ } else {
+
+ /* just use the selected regions */
+
+ rs = selection->regions;
+
+ /* if the entered regionview wasn't selected and we allow this sort of thing,
+ then add it.
+ */
+
+ if (allow_entered && entered_regionview && !selection->selected (entered_regionview)) {
+ rs.add (entered_regionview);
+ }
+
+ }
+}
+
+void
+Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<RegionView*>& regions)
+{
+
+ for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
+
+ RouteTimeAxisView* tatv;
+
+ if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
+
+ boost::shared_ptr<Playlist> pl;
+ vector<boost::shared_ptr<Region> > results;
+ RegionView* marv;
+ boost::shared_ptr<Diskstream> ds;
+
+ if ((ds = tatv->get_diskstream()) == 0) {
+ /* bus */
+ continue;
+ }
+
+ if ((pl = (ds->playlist())) != 0) {
+ pl->get_region_list_equivalent_regions (region, results);
+ }
+
+ for (vector<boost::shared_ptr<Region> >::iterator ir = results.begin(); ir != results.end(); ++ir) {
+ if ((marv = tatv->view()->find_view (*ir)) != 0) {
+ regions.push_back (marv);
+ }
+ }
+
+ }
+ }
+}
+
+void
+Editor::show_rhythm_ferret ()
+{
+ if (rhythm_ferret == 0) {
+ rhythm_ferret = new RhythmFerret(*this);
+ }
+
+ rhythm_ferret->set_session (session);
+ rhythm_ferret->show ();
+ rhythm_ferret->present ();
+}
+
+void
+Editor::show_bundle_manager ()
+{
+ if (_bundle_manager == 0) {
+ _bundle_manager = new BundleManager (*session);
+ }
+
+ _bundle_manager->show ();
+}
+
+void
+Editor::show_global_port_matrix (ARDOUR::DataType t)
+{
+ if (_global_port_matrix[t] == 0) {
+ _global_port_matrix[t] = new GlobalPortMatrixWindow (*session, t);
+ }
+
+ _global_port_matrix[t]->show ();
+}
+
+void
+Editor::first_idle ()
+{
+ MessageDialog* dialog = 0;
+
+ if (track_views.size() > 1) {
+ dialog = new MessageDialog (*this,
+ _("Please wait while Ardour loads visual data"),
+ true,
+ Gtk::MESSAGE_INFO,
+ Gtk::BUTTONS_NONE);
+ dialog->present ();
+ ARDOUR_UI::instance()->flush_pending ();
+ }
+
+ for (TrackViewList::iterator t = track_views.begin(); t != track_views.end(); ++t) {
+ (*t)->first_idle();
+ }
+
+ // first idle adds route children (automation tracks), so we need to redisplay here
+ redisplay_route_list();
+
+ delete dialog;
+
+ _have_idled = true;
+}
+
+void
+Editor::start_resize_line_ops ()
+{
+#if 0
+ old_resize_line_y = -1;
+ resize_line_y = -1;
+ need_resize_line = true;
+#endif
+}
+
+void
+Editor::end_resize_line_ops ()
+{
+#if 0
+ need_resize_line = false;
+
+ if (old_resize_line_y >= 0) {
+ Gdk::Rectangle r (0, old_resize_line_y, (int) canvas_width, 3);
+ Glib::RefPtr<Gdk::Window> win = get_window();
+ cerr << "Final invalidation at " << old_resize_line_y << endl;
+ win->invalidate_rect (r, false);
+ }
+#endif
+}
+
+void
+Editor::queue_draw_resize_line (int at)
+{
+#if 0
+ Glib::RefPtr<Gdk::Window> win = get_window();
+
+ resize_line_y = at;
+
+ if (win && canvas_width) {
+
+ int controls_width = controls_layout.get_width();
+ int xroot, discard;
+
+ controls_layout.get_window()->get_origin (xroot, discard);
+
+ if (old_resize_line_y >= 0) {
+
+ /* redraw where it used to be */
+
+
+ Gdk::Rectangle r (0, old_resize_line_y - 1, controls_width + (int) canvas_width, 3);
+ win->invalidate_rect (r, true);
+ cerr << "invalidate " << xroot << "," << old_resize_line_y - 1 << ' '
+ << controls_width + canvas_width << " x 3\n";
+ }
+
+ /* draw where it is */
+
+ Gdk::Rectangle r (0, at - 1, controls_width + (int) canvas_width, 3);
+ win->invalidate_rect (r, true);
+ }
+#endif
+}
+
+bool
+Editor::on_expose_event (GdkEventExpose* ev)
+{
+ /* cerr << "+++ editor expose "
+ << ev->area.x << ',' << ev->area.y
+ << ' '
+ << ev->area.width << " x " << ev->area.height
+ << " need reize ? " << need_resize_line
+ << endl;
+ */
+ bool ret = Window::on_expose_event (ev);
+
+#if 0
+ if (need_resize_line) {
+
+ int xroot, yroot, discard;
+ int controls_width;
+
+ /* Our root coordinates for drawing the line will be the left edge
+ of the track controls, and the upper left edge of our own window.
+ */
+
+ get_window()->get_origin (discard, yroot);
+ controls_layout.get_window()->get_origin (xroot, discard);
+ controls_width = controls_layout.get_width();
+
+ GdkRectangle lr;
+ GdkRectangle intersection;
+
+ lr.x = 0;
+ lr.y = resize_line_y;
+ lr.width = controls_width + (int) canvas_width;
+ lr.height = 3;
+
+ if (gdk_rectangle_intersect (&lr, &ev->area, &intersection)) {
+
+ Glib::RefPtr<Gtk::Style> style (get_style());
+ Glib::RefPtr<Gdk::GC> black_gc (style->get_black_gc ());
+ Glib::RefPtr<Gdk::GC> gc = wrap (black_gc->gobj_copy(), false);
+
+ /* draw on root window */
+
+ GdkWindow* win = gdk_get_default_root_window();
+
+ gc->set_subwindow (Gdk::INCLUDE_INFERIORS);
+ gc->set_line_attributes (3, Gdk::LINE_SOLID,
+ Gdk::CAP_NOT_LAST,
+ Gdk::JOIN_MITER);
+
+ gdk_draw_line (win, gc->gobj(),
+ 0,
+ resize_line_y,
+ (int) canvas_width + controls_width,
+ resize_line_y);
+#if 0
+ cerr << "drew line @ " << xroot << ", " << yroot + resize_line_y
+ << " to " << xroot + (int) canvas_width + controls_width
+ << ", " << yroot + resize_line_y
+ << endl;
+#endif
+ old_resize_line_y = resize_line_y;
+ cerr << "NEXT EXPOSE SHOULD BE AT " << old_resize_line_y << endl;
+ } else {
+ cerr << "no intersect with "
+ << lr.x << ',' << lr.y
+ << ' '
+ << lr.width << " x " << lr.height
+ << endl;
+ }
+ }
+
+ //cerr << "--- editor expose\n";
+#endif
+
+ return ret;
+}
+
+static gboolean
+_idle_resizer (gpointer arg)
+{
+ return ((Editor*)arg)->idle_resize ();
+}
+
+void
+Editor::add_to_idle_resize (TimeAxisView* view, uint32_t h)
+{
+ if (resize_idle_id < 0) {
+ resize_idle_id = g_idle_add (_idle_resizer, this);
+ }
+
+ resize_idle_target = h;
+
+ pending_resizes.push_back (view);
+
+ if (selection->selected (view) && !selection->tracks.empty()) {
+ pending_resizes.insert (pending_resizes.end(), selection->tracks.begin(), selection->tracks.end());
+ }
+}
+
+bool
+Editor::idle_resize ()
+{
+ for (vector<TimeAxisView*>::iterator i = pending_resizes.begin(); i != pending_resizes.end(); ++i) {
+ (*i)->idle_resize (resize_idle_target);
+ }
+ pending_resizes.clear();
+ flush_canvas ();
+ resize_idle_id = -1;
+ return false;
+}