fix newly-appearing crash-at-close caused by muddled thinking in pbd/pthread_utils
[ardour.git] / gtk2_ardour / editor.cc
index acbb792db50aab15c9310c6d3bdd5898643df9ae..300e317a388729da26950c32cb4c40630e7e9512 100644 (file)
@@ -44,6 +44,7 @@
 #include "pbd/memento_command.h"
 #include "pbd/unknown_type.h"
 #include "pbd/unwind.h"
+#include "pbd/stacktrace.h"
 
 #include <glibmm/miscutils.h>
 #include <gtkmm/image.h>
 
 #include "i18n.h"
 
-#ifdef WITH_CMT
-#include "imageframe_socket_handler.h"
-#endif
-
 using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
@@ -245,6 +242,7 @@ Editor::Editor ()
        , range_mark_label (_("Range Markers"))
        , transport_mark_label (_("Loop/Punch Ranges"))
        , cd_mark_label (_("CD Markers"))
+       , videotl_label (_("Video Timeline"))
        , edit_packer (4, 4, true)
 
          /* the values here don't matter: layout widgets
@@ -263,10 +261,6 @@ Editor::Editor ()
 
        , _toolbar_viewport (*manage (new Gtk::Adjustment (0, 0, 1e10)), *manage (new Gtk::Adjustment (0, 0, 1e10)))
 
-#ifdef WITH_CMT
-       , image_socket_listener(0)
-#endif
-
          /* nudge */
 
        , nudge_clock (new AudioClock (X_("nudge"), false, X_("nudge"), true, false, true))
@@ -383,67 +377,75 @@ Editor::Editor ()
        set_zoom_focus (ZoomFocusLeft);
        zoom_range_clock->ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
 
-       bbt_label.set_name ("EditorTimeButton");
+       bbt_label.set_name ("EditorRulerLabel");
        bbt_label.set_size_request (-1, (int)timebar_height);
        bbt_label.set_alignment (1.0, 0.5);
        bbt_label.set_padding (5,0);
        bbt_label.hide ();
        bbt_label.set_no_show_all();
-       minsec_label.set_name ("EditorTimeButton");
+       minsec_label.set_name ("EditorRulerLabel");
        minsec_label.set_size_request (-1, (int)timebar_height);
        minsec_label.set_alignment (1.0, 0.5);
        minsec_label.set_padding (5,0);
        minsec_label.hide ();
        minsec_label.set_no_show_all();
-       timecode_label.set_name ("EditorTimeButton");
+       timecode_label.set_name ("EditorRulerLabel");
        timecode_label.set_size_request (-1, (int)timebar_height);
        timecode_label.set_alignment (1.0, 0.5);
        timecode_label.set_padding (5,0);
        timecode_label.hide ();
        timecode_label.set_no_show_all();
-       samples_label.set_name ("EditorTimeButton");
+       samples_label.set_name ("EditorRulerLabel");
        samples_label.set_size_request (-1, (int)timebar_height);
        samples_label.set_alignment (1.0, 0.5);
        samples_label.set_padding (5,0);
        samples_label.hide ();
        samples_label.set_no_show_all();
 
-       tempo_label.set_name ("EditorTimeButton");
+       tempo_label.set_name ("EditorRulerLabel");
        tempo_label.set_size_request (-1, (int)timebar_height);
        tempo_label.set_alignment (1.0, 0.5);
        tempo_label.set_padding (5,0);
        tempo_label.hide();
        tempo_label.set_no_show_all();
 
-       meter_label.set_name ("EditorTimeButton");
+       meter_label.set_name ("EditorRulerLabel");
        meter_label.set_size_request (-1, (int)timebar_height);
        meter_label.set_alignment (1.0, 0.5);
        meter_label.set_padding (5,0);
        meter_label.hide();
        meter_label.set_no_show_all();
 
-       mark_label.set_name ("EditorTimeButton");
+       mark_label.set_name ("EditorRulerLabel");
        mark_label.set_size_request (-1, (int)timebar_height);
        mark_label.set_alignment (1.0, 0.5);
        mark_label.set_padding (5,0);
        mark_label.hide();
        mark_label.set_no_show_all();
 
-       cd_mark_label.set_name ("EditorTimeButton");
+       cd_mark_label.set_name ("EditorRulerLabel");
        cd_mark_label.set_size_request (-1, (int)timebar_height);
        cd_mark_label.set_alignment (1.0, 0.5);
        cd_mark_label.set_padding (5,0);
        cd_mark_label.hide();
        cd_mark_label.set_no_show_all();
 
-       range_mark_label.set_name ("EditorTimeButton");
+       videotl_bar_height = 4;
+       videotl_label.set_name ("EditorRulerLabel");
+       videotl_label.set_size_request (-1, (int)timebar_height * videotl_bar_height);
+       videotl_label.set_alignment (1.0, 0.5);
+       videotl_label.set_padding (5,0);
+       videotl_label.hide();
+       videotl_label.set_no_show_all();
+
+       range_mark_label.set_name ("EditorRulerLabel");
        range_mark_label.set_size_request (-1, (int)timebar_height);
        range_mark_label.set_alignment (1.0, 0.5);
        range_mark_label.set_padding (5,0);
        range_mark_label.hide();
        range_mark_label.set_no_show_all();
 
-       transport_mark_label.set_name ("EditorTimeButton");
+       transport_mark_label.set_name ("EditorRulerLabel");
        transport_mark_label.set_size_request (-1, (int)timebar_height);
        transport_mark_label.set_alignment (1.0, 0.5);
        transport_mark_label.set_padding (5,0);
@@ -695,7 +697,7 @@ Editor::Editor ()
        signal_configure_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
        signal_delete_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::exit_on_main_window_close));
 
-       Gtkmm2ext::Keyboard::the_keyboard().ShiftReleased.connect (sigc::mem_fun (*this, &Editor::shift_key_released));
+       Gtkmm2ext::Keyboard::the_keyboard().ZoomVerticalModifierReleased.connect (sigc::mem_fun (*this, &Editor::zoom_vertical_modifier_released));
        
        /* allow external control surfaces/protocols to do various things */
 
@@ -756,18 +758,6 @@ Editor::Editor ()
 
 Editor::~Editor()
 {
-#ifdef WITH_CMT
-       if(image_socket_listener) {
-               if(image_socket_listener->is_connected())
-               {
-                       image_socket_listener->close_connection() ;
-               }
-
-               delete image_socket_listener ;
-               image_socket_listener = 0 ;
-       }
-#endif
-
         delete button_bindings;
        delete _routes;
        delete _route_groups;
@@ -1369,7 +1359,7 @@ Editor::fill_xfade_menu (Menu_Helpers::MenuList& items, bool start)
        
        items.push_back (
                ImageMenuElem (
-                       _("ConstantPower"),
+                       _("Constant power"),
                        *(*images)[FadeConstantPower],
                        sigc::bind (sigc::mem_fun (*this, emf), FadeConstantPower)
                        ));
@@ -1506,7 +1496,7 @@ Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* i
                                
                        items.push_back (
                                ImageMenuElem (
-                                       _("Constant Power"),
+                                       _("Constant power"),
                                        *_fade_in_images[FadeConstantPower],
                                        sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_in_shape), FadeConstantPower)
                                        ));
@@ -1568,7 +1558,7 @@ Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* i
 
                        items.push_back (
                                ImageMenuElem (
-                                       _("Constant Power"),
+                                       _("Constant power"),
                                        *_fade_out_images[FadeConstantPower],
                                        sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_out_shape), FadeConstantPower)
                                        ));
@@ -2139,9 +2129,16 @@ Editor::set_snap_to (SnapType st)
 void
 Editor::set_snap_mode (SnapMode mode)
 {
-       _snap_mode = mode;
        string str = snap_mode_strings[(int)mode];
 
+       if (_internal_editing) {
+               internal_snap_mode = mode;
+       } else {
+               pre_internal_snap_mode = mode;
+       }
+
+       _snap_mode = mode;
+
        if (str != snap_mode_selector.get_active_text ()) {
                snap_mode_selector.set_active_text (str);
        }
@@ -2289,6 +2286,7 @@ Editor::set_state (const XMLNode& node, int /*version*/)
                pre_internal_snap_type = (SnapType) string_2_enum (prop->value(), pre_internal_snap_type);
        }
 
+
        if ((prop = node.property ("pre-internal-snap-mode"))) {
                pre_internal_snap_mode = (SnapMode) string_2_enum (prop->value(), pre_internal_snap_mode);
        }
@@ -3127,12 +3125,12 @@ Editor::convert_drop_to_paths (
                */
 
                string txt = data.get_text();
-               const char* p;
+               char* p;
                const char* q;
 
-               p = (const char *) malloc (txt.length() + 1);
-               txt.copy (const_cast<char *> (p), txt.length(), 0);
-               const_cast<char*>(p)[txt.length()] = '\0';
+               p = (char *) malloc (txt.length() + 1);
+               txt.copy (p, txt.length(), 0);
+               p[txt.length()] = '\0';
 
                while (p)
                {
@@ -3312,8 +3310,6 @@ Editor::duplicate_range (bool with_dialog)
                win.add_button (_("Duplicate"), RESPONSE_ACCEPT);
                win.set_default_response (RESPONSE_ACCEPT);
 
-               win.set_position (WIN_POS_MOUSE);
-
                spinner.grab_focus ();
 
                switch (win.run ()) {
@@ -4015,7 +4011,7 @@ Editor::restore_editing_space ()
 
 /**
  *  Make new playlists for a given track and also any others that belong
- *  to the same active route group with the `edit' property.
+ *  to the same active route group with the `select' property.
  *  @param v Track.
  */
 
@@ -4031,7 +4027,7 @@ Editor::new_playlists (TimeAxisView* v)
 
 /**
  *  Use a copy of the current playlist for a given track and also any others that belong
- *  to the same active route group with the `edit' property.
+ *  to the same active route group with the `select' property.
  *  @param v Track.
  */
 
@@ -4046,7 +4042,7 @@ Editor::copy_playlists (TimeAxisView* v)
 }
 
 /** Clear the current playlist for a given track and also any others that belong
- *  to the same active route group with the `edit' property.
+ *  to the same active route group with the `select' property.
  *  @param v Track.
  */
 
@@ -4271,6 +4267,19 @@ Editor::set_frames_per_unit (double fpu)
        instant_save ();
 }
 
+void
+Editor::queue_visual_videotimeline_update ()
+{
+       /* TODO:
+        * pending_visual_change.add (VisualChange::VideoTimeline);
+        * or maybe even more specific: which videotimeline-image
+        * currently it calls update_video_timeline() to update
+        * _all outdated_ images on the video-timeline.
+        * see 'exposeimg()' in video_image_frame.cc
+        */
+       ensure_visual_change_idle_handler ();
+}
+
 void
 Editor::ensure_visual_change_idle_handler ()
 {
@@ -4320,9 +4329,15 @@ Editor::idle_visual_changer ()
                                         current_bbt_points_begin, current_bbt_points_end);
                update_tempo_based_rulers (current_bbt_points_begin, current_bbt_points_end);
        }
+
+       if (p & VisualChange::ZoomLevel) {
+               update_video_timeline();
+       }
+
        if (p & VisualChange::TimeOrigin) {
                set_horizontal_position (pending_visual_change.time_origin / frames_per_unit);
        }
+
        if (p & VisualChange::YOrigin) {
                vertical_adjustment.set_value (pending_visual_change.y_origin);
        }
@@ -4333,6 +4348,10 @@ Editor::idle_visual_changer ()
                redisplay_tempo (true);
        }
 
+       if (!(p & VisualChange::ZoomLevel)) {
+               update_video_timeline();
+       }
+
        _summary->set_overlays_dirty ();
 
        pending_visual_change.being_handled = false;
@@ -4530,7 +4549,7 @@ Editor::get_regions_after (RegionSelection& rs, framepos_t where, const TrackVie
                                        RegionView* rv = rtv->view()->find_view (*i);
 
                                        if (rv) {
-                                               rs.push_back (rv);
+                                               rs.add (rv);
                                        }
                                }
                        }
@@ -4538,32 +4557,16 @@ Editor::get_regions_after (RegionSelection& rs, framepos_t where, const TrackVie
        }
 }
 
-/** Start with regions that are selected.  Then add equivalent regions
- *  on tracks in the same active edit-enabled route group as any of
- *  the regions that we started with.
- */
-
-RegionSelection
-Editor::get_regions_from_selection ()
-{
-       return get_equivalent_regions (selection->regions, ARDOUR::Properties::select.property_id);
-}
-
 /** Get regions using the following method:
  *
- *  Make an initial region list using the selected regions, unless
+ *  Make a region list using the selected regions, unless
  *  the edit point is `mouse' and the mouse is over an unselected
- *  region.  In this case, start with just that region.
+ *  region.  In this case, use just that region.
  *
- *  Then, add equivalent regions in active edit groups to the region list.
- *
- *  Then, search the list of selected tracks to find any selected tracks which
- *  do not contain regions already in the region list. If there are no selected
- *  tracks and 'No Selection = All Tracks' is active, search all tracks rather
- *  than just the selected.
- *
- *  Add any regions that are under the edit point on these tracks to get the
- *  returned region list.
+ *  If the edit point is not 'mouse', and there are no regions selected,
+ *  search the list of selected tracks and return regions that are under
+ *  the edit point on these tracks. If there are no selected tracks and
+ *  'No Selection = All Tracks' is active, search all tracks,
  *
  *  The rationale here is that the mouse edit point is special in that
  *  its position describes both a time and a track; the other edit
@@ -4585,48 +4588,25 @@ Editor::get_regions_from_selection_and_edit_point ()
                regions = selection->regions;
        }
 
-       TrackViewList tracks;
 
-       if (_edit_point != EditAtMouse) {
-               tracks = selection->tracks;
-       }
+       if (regions.empty() && _edit_point != EditAtMouse) {
+               TrackViewList tracks = selection->tracks;
 
-       /* Add any other regions that are in the same
-          edit-activated route group as one of our regions.
-        */
-       regions = get_equivalent_regions (regions, ARDOUR::Properties::select.property_id);
-       framepos_t const where = get_preferred_edit_position ();
-
-       if (_route_groups->all_group_active_button().get_active() && tracks.empty()) {
-               /* tracks is empty (no track selected), and 'No Selection = All Tracks'
-                * is enabled, so consider all tracks
-                */
-               tracks = track_views; 
-       }
-
-       if (!tracks.empty()) {
-               /* now search the selected tracks for tracks which don't
-                  already contain regions to be acted upon, and get regions at
-                  the edit point on those tracks too.
-                */
-               TrackViewList tracks_without_relevant_regions;
-
-               for (TrackViewList::iterator t = tracks.begin (); t != tracks.end (); ++t) {
-                       if (!regions.involves (**t)) {
-                               /* there are no equivalent regions on this track */
-                               tracks_without_relevant_regions.push_back (*t);
-                       }
+               if (_route_groups->all_group_active_button().get_active() && tracks.empty()) {
+                       /* tracks is empty (no track selected), and 'No Selection = All Tracks'
+                        * is enabled, so consider all tracks
+                        */
+                       tracks = track_views; 
                }
 
-               if (!tracks_without_relevant_regions.empty()) {
-                       /* there are some selected tracks with neither selected
-                        * regions or their equivalents: act upon all regions in
-                        * those tracks
-                        */
-                       get_regions_at (regions, where, tracks_without_relevant_regions);
+               if (!tracks.empty()) {
+                       /* no region selected or entered, but some selected tracks:
+                        * act on all regions on the selected tracks at the edit point
+                        *
+                       framepos_t const where = get_preferred_edit_position ();
+                       get_regions_at(regions, where, tracks);
                }
        }
-
        return regions;
 }
 
@@ -4644,7 +4624,7 @@ Editor::get_regions_from_selection_and_entered ()
                regions.add (entered_regionview);
        }
 
-       return get_equivalent_regions (regions, ARDOUR::Properties::select.property_id);
+       return regions;
 }
 
 void
@@ -4856,7 +4836,7 @@ Editor::add_routes (RouteList& routes)
        for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
                boost::shared_ptr<Route> route = (*x);
 
-               if (route->is_hidden() || route->is_monitor()) {
+               if (route->is_auditioner() || route->is_monitor()) {
                        continue;
                }
 
@@ -5406,7 +5386,6 @@ Editor::change_region_layering_order (bool from_context_menu)
 
        if (layering_order_editor == 0) {
                layering_order_editor = new RegionLayeringOrderEditor (*this);
-               layering_order_editor->set_position (WIN_POS_MOUSE);
        }
 
        layering_order_editor->set_context (clicked_routeview->name(), _session, clicked_routeview, pl, position);
@@ -5520,7 +5499,7 @@ Editor::popup_control_point_context_menu (ArdourCanvas::Item* item, GdkEvent* ev
 }
 
 void
-Editor::shift_key_released ()
+Editor::zoom_vertical_modifier_released()
 {
        _stepping_axis_view = 0;
 }