use new method in MidiPatchManager to use MIDNAM data when setting a MidiTimeAxisView
[ardour.git] / gtk2_ardour / editor_ops.cc
index aa5c7dfa3e1aee79fe40b352cc9de51d7b127388..195d4d16436b6bbb41aa9e926eafbe0dcbd9abfc 100644 (file)
@@ -1,21 +1,32 @@
 /*
-    Copyright (C) 2000-2004 Paul Davis
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
+ * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
+ * Copyright (C) 2005-2009 Sampo Savolainen <v2@iki.fi>
+ * Copyright (C) 2005-2018 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
+ * Copyright (C) 2006-2015 David Robillard <d@drobilla.net>
+ * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2007-2017 Tim Mayberry <mojofunk@gmail.com>
+ * Copyright (C) 2013-2016 Colin Fletcher <colin.m.fletcher@googlemail.com>
+ * Copyright (C) 2013-2017 John Emmas <john@creativepost.co.uk>
+ * Copyright (C) 2013-2017 Nick Mainsbridge <mainsbridge@gmail.com>
+ * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2014-2019 Ben Loftis <ben@harrisonconsoles.com>
+ * Copyright (C) 2015 AndrĂ© Nusser <andre.nusser@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 /* Note: public Editor methods are documented in public_editor.h */
 
@@ -61,6 +72,7 @@
 #include "ardour/selection.h"
 #include "ardour/session.h"
 #include "ardour/session_playlists.h"
+#include "ardour/source.h"
 #include "ardour/strip_silence.h"
 #include "ardour/transient_detector.h"
 #include "ardour/transport_master_manager.h"
@@ -70,6 +82,7 @@
 #include "canvas/canvas.h"
 
 #include "actions.h"
+#include "ardour_message.h"
 #include "ardour_ui.h"
 #include "audio_region_view.h"
 #include "audio_streamview.h"
@@ -83,6 +96,7 @@
 #include "editor_cursors.h"
 #include "editor_drag.h"
 #include "editor_regions.h"
+#include "editor_sources.h"
 #include "editor_routes.h"
 #include "gui_thread.h"
 #include "insert_remove_time_dialog.h"
@@ -141,6 +155,7 @@ Editor::undo (uint32_t n)
        if (_drags->active ()) {
                _drags->abort ();
        }
+       paste_count = 0;
 
        if (_session) {
                _session->undo (n);
@@ -165,6 +180,7 @@ Editor::redo (uint32_t n)
        if (_drags->active ()) {
                _drags->abort ();
        }
+       paste_count = 0;
 
        if (_session) {
        _session->redo (n);
@@ -1787,7 +1803,13 @@ Editor::temporal_zoom (samplecnt_t fpp)
        new_page_size = (samplepos_t) floor (_visible_canvas_width * nfpp);
        half_page_size = new_page_size / 2;
 
-       switch (zoom_focus) {
+       Editing::ZoomFocus zf = zoom_focus;
+
+       if (zf == ZoomFocusEdit && _edit_point == EditAtMouse) {
+               zf = ZoomFocusMouse;
+       }
+
+       switch (zf) {
        case ZoomFocusLeft:
                leftmost_after_zoom = current_leftmost;
                break;
@@ -1857,9 +1879,7 @@ Editor::temporal_zoom (samplecnt_t fpp)
        case ZoomFocusEdit:
                /* try to keep the edit point in the same place */
                where = get_preferred_edit_position ();
-
-               if (where > 0) {
-
+               {
                        double l = - ((new_page_size * ((where - current_leftmost)/(double)current_page)) - where);
 
                        if (l < 0) {
@@ -1869,10 +1889,6 @@ Editor::temporal_zoom (samplecnt_t fpp)
                        } else {
                                leftmost_after_zoom = (samplepos_t) l;
                        }
-
-               } else {
-                       /* edit point not defined */
-                       return;
                }
                break;
 
@@ -2541,7 +2557,7 @@ Editor::unhide_ranges ()
 /* INSERT/REPLACE */
 
 void
-Editor::insert_region_list_selection (float times)
+Editor::insert_source_list_selection (float times)
 {
        RouteTimeAxisView *tv = 0;
        boost::shared_ptr<Playlist> playlist;
@@ -2564,7 +2580,7 @@ Editor::insert_region_list_selection (float times)
                return;
        }
 
-       boost::shared_ptr<Region> region = _regions->get_single_selection ();
+       boost::shared_ptr<Region> region = _sources->get_single_selection ();
        if (region == 0) {
                return;
        }
@@ -3976,7 +3992,7 @@ Editor::freeze_route ()
        }
 
        if (!clicked_routeview->track()->bounceable (clicked_routeview->track()->main_outs(), true)) {
-               MessageDialog d (
+               ArdourMessageDialog d (
                        _("This track/bus cannot be frozen because the signal adds or loses channels before reaching the outputs.\n"
                          "This is typically caused by plugins that generate stereo output from mono input or vice versa.")
                        );
@@ -3986,9 +4002,9 @@ Editor::freeze_route ()
        }
 
        if (clicked_routeview->track()->has_external_redirects()) {
-               MessageDialog d (string_compose (_("<b>%1</b>\n\nThis track has at least one send/insert/return as part of its signal flow.\n\n"
-                                                  "Freezing will only process the signal as far as the first send/insert/return."),
-                                                clicked_routeview->track()->name()), true, MESSAGE_INFO, BUTTONS_NONE, true);
+               ArdourMessageDialog d (string_compose (_("<b>%1</b>\n\nThis track has at least one send/insert/return as part of its signal flow.\n\n"
+                                                        "Freezing will only process the signal as far as the first send/insert/return."),
+                                                      clicked_routeview->track()->name()), true, MESSAGE_INFO, BUTTONS_NONE, true);
 
                d.add_button (_("Freeze anyway"), Gtk::RESPONSE_OK);
                d.add_button (_("Don't freeze"), Gtk::RESPONSE_CANCEL);
@@ -4037,7 +4053,7 @@ Editor::bounce_range_selection (bool replace, bool enable_processing)
                        RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
 
                        if (rtv && rtv->track() && replace && enable_processing && !rtv->track()->bounceable (rtv->track()->main_outs(), false)) {
-                               MessageDialog d (
+                               ArdourMessageDialog d (
                                        _("You can't perform this operation because the processing of the signal "
                                          "will cause one or more of the tracks to end up with a region with more channels than this track has inputs.\n\n"
                                          "You can do this without processing, which is a different operation.")
@@ -4478,6 +4494,32 @@ Editor::remove_clicked_region ()
 }
 
 
+void
+Editor::recover_regions (ARDOUR::RegionList regions)
+{
+#ifdef RECOVER_REGIONS_IS_WORKING
+       begin_reversible_command (_("recover regions"));
+
+       for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
+               boost::shared_ptr<ARDOUR::Source> source = (*i)->source();
+
+               RouteList routes = _session->get_routelist();
+               for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) {
+                       boost::shared_ptr<ARDOUR::Track> track = boost::dynamic_pointer_cast<Track>(*it);
+                       if (track) {
+                               //ToDo
+                               if (source->captured_for() == track->) {
+                                       //_session->add_command(new StatefulDiffCommand (playlist));    
+                               }
+                       }
+               }
+       }
+
+       commit_reversible_command ();
+#endif
+}
+
+
 /** Remove the selected regions */
 void
 Editor::remove_selected_regions ()
@@ -6123,7 +6165,9 @@ Editor::toggle_mute ()
                        first = false;
                }
 
-               cl->push_back (stav->stripable()->mute_control());
+               boost::shared_ptr<MuteControl> mc = stav->stripable()->mute_control();
+               cl->push_back (mc);
+               mc->start_touch (_session->audible_sample ());
        }
 
        _session->set_controls (cl, new_state, Controllable::UseGroup);
@@ -7005,10 +7049,10 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
 
        if (positions.size() > 20 && can_ferret) {
                std::string msgstr = string_compose (_("You are about to split\n%1\ninto %2 pieces.\nThis could take a long time."), r->name(), positions.size() + 1);
-               MessageDialog msg (msgstr,
-                                  false,
-                                  Gtk::MESSAGE_INFO,
-                                  Gtk::BUTTONS_OK_CANCEL);
+               ArdourMessageDialog msg (msgstr,
+                                        false,
+                                        Gtk::MESSAGE_INFO,
+                                        Gtk::BUTTONS_OK_CANCEL);
 
                if (can_ferret) {
                        msg.add_button (_("Call for the Ferret!"), RESPONSE_APPLY);
@@ -7018,8 +7062,6 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
                }
 
                msg.set_title (_("Excessive split?"));
-               msg.present ();
-
                int response = msg.run();
                msg.hide ();
 
@@ -7593,19 +7635,17 @@ Editor::_remove_tracks ()
        }
 
        if (special_bus && !Config->get_allow_special_bus_removal()) {
-               MessageDialog msg (_("That would be bad news ...."),
-                                  false,
-                                  Gtk::MESSAGE_INFO,
-                                  Gtk::BUTTONS_OK);
-               msg.set_secondary_text (string_compose (_(
-                                                               "Removing the master or monitor bus is such a bad idea\n\
+               ArdourMessageDialog msg (_("That would be bad news ...."),
+                                        false,
+                                        Gtk::MESSAGE_INFO,
+                                        Gtk::BUTTONS_OK);
+               msg.set_secondary_text (string_compose (_("Removing the master or monitor bus is such a bad idea\n\
 that %1 is not going to allow it.\n\
 \n\
 If you really want to do this sort of thing\n\
 edit your ardour.rc file to set the\n\
 \"allow-special-bus-removal\" option to be \"yes\""), PROGRAM_NAME));
 
-               msg.present ();
                msg.run ();
                return;
        }
@@ -7721,17 +7761,15 @@ void
 Editor::do_insert_time ()
 {
        if (selection->tracks.empty()) {
-               MessageDialog msg (_("You must first select some tracks to Insert Time."),
-                                  true, MESSAGE_INFO, BUTTONS_OK, true);
-               msg.set_position (WIN_POS_MOUSE);
+               ArdourMessageDialog msg (_("You must first select some tracks to Insert Time."),
+                                  true, MESSAGE_INFO, BUTTONS_OK, true);
                msg.run ();
                return;
        }
 
        if (Config->get_edit_mode() == Lock) {
-               MessageDialog msg (_("You cannot insert time in Lock Edit mode."),
-                                  true, MESSAGE_INFO, BUTTONS_OK, true);
-               msg.set_position (WIN_POS_MOUSE);
+               ArdourMessageDialog msg (_("You cannot insert time in Lock Edit mode."),
+                                        true, MESSAGE_INFO, BUTTONS_OK, true);
                msg.run ();
                return;
        }
@@ -7896,17 +7934,15 @@ void
 Editor::do_remove_time ()
 {
        if (selection->tracks.empty()) {
-               MessageDialog msg (_("You must first select some tracks to Remove Time."),
-                                  true, MESSAGE_INFO, BUTTONS_OK, true);
-               msg.set_position (WIN_POS_MOUSE);
+               ArdourMessageDialog msg (_("You must first select some tracks to Remove Time."),
+                                        true, MESSAGE_INFO, BUTTONS_OK, true);
                msg.run ();
                return;
        }
 
        if (Config->get_edit_mode() == Lock) {
-               MessageDialog msg (_("You cannot remove time in Lock Edit mode."),
-                                  true, MESSAGE_INFO, BUTTONS_OK, true);
-               msg.set_position (WIN_POS_MOUSE);
+               ArdourMessageDialog msg (_("You cannot remove time in Lock Edit mode."),
+                                        true, MESSAGE_INFO, BUTTONS_OK, true);
                msg.run ();
                return;
        }
@@ -8135,7 +8171,8 @@ Editor::fit_tracks (TrackViewList & tracks)
        double first_y_pos = DBL_MAX;
 
        if (h < TimeAxisView::preset_height (HeightSmall)) {
-               MessageDialog msg (_("There are too many tracks to fit in the current window"));
+               ArdourMessageDialog msg (_("There are too many tracks to fit in the current window"));
+               msg.run ();
                /* too small to be displayed */
                return;
        }