merge with master
[ardour.git] / gtk2_ardour / editor.cc
index 96edd51af6fd284ba3574195ff77117633e528a5..57ae65e9a5a410fcd850cf51bcc2ee24535f6f0a 100644 (file)
 
 #include "i18n.h"
 
-#ifdef WITH_CMT
-#include "imageframe_socket_handler.h"
-#endif
-
 using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
@@ -269,10 +265,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))
@@ -377,6 +369,7 @@ Editor::Editor ()
        location_loop_color = ARDOUR_UI::config()->get_canvasvar_LocationLoop();
        location_punch_color = ARDOUR_UI::config()->get_canvasvar_LocationPunch();
 
+       zoom_focus = ZoomFocusLeft;
        _edit_point = EditAtMouse;
        _internal_editing = false;
        current_canvas_cursor = 0;
@@ -385,8 +378,6 @@ Editor::Editor ()
 
        _scroll_callbacks = 0;
 
-       zoom_focus = ZoomFocusLeft;
-       set_zoom_focus (ZoomFocusLeft);
        zoom_range_clock->ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
 
        bbt_label.set_name ("EditorRulerLabel");
@@ -644,6 +635,7 @@ Editor::Editor ()
 
        setup_toolbar ();
 
+       set_zoom_focus (zoom_focus);
        _snap_type = SnapToBeat;
        set_snap_to (_snap_type);
        _snap_mode = SnapOff;
@@ -706,7 +698,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 */
 
@@ -767,18 +759,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;
@@ -932,7 +912,7 @@ Editor::zoom_adjustment_changed ()
                return;
        }
 
-       double fpu = zoom_range_clock->current_duration() / _visible_canvas_width;
+       framecnt_t fpu = llrintf (zoom_range_clock->current_duration() / _visible_canvas_width);
        bool clamped = clamp_samples_per_pixel (fpu);
        
        if (clamped) {
@@ -1143,7 +1123,7 @@ Editor::map_position_change (framepos_t frame)
 void
 Editor::center_screen (framepos_t frame)
 {
-       double const page = _visible_canvas_width * samples_per_pixel;
+       framecnt_t const page = _visible_canvas_width * samples_per_pixel;
 
        /* if we're off the page, then scroll.
         */
@@ -1280,7 +1260,8 @@ Editor::set_session (Session *t)
 
        /* These signals can all be emitted by a non-GUI thread. Therefore the
           handlers for them must not attempt to directly interact with the GUI,
-          but use Gtkmm2ext::UI::instance()->call_slot();
+          but use PBD::Signal<T>::connect() which accepts an event loop
+          ("context") where the handler will be asked to run.
        */
 
        _session->StepEditStatusChange.connect (_session_connections, invalidator (*this), boost::bind (&Editor::step_edit_status_change, this, _1), gui_context());
@@ -1932,6 +1913,9 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
        edit_items.push_back (MenuElem (_("Bounce Range to Region List"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, false)));
        edit_items.push_back (MenuElem (_("Bounce Range to Region List With Processing"), sigc::bind (sigc::mem_fun(*this, &Editor::bounce_range_selection), false, true)));
        edit_items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_selection)));
+       if (ARDOUR_UI::instance()->video_timeline->get_duration() > 0) {
+               edit_items.push_back (MenuElem (_("Export Video Range..."), sigc::bind (sigc::mem_fun(*this, &Editor::export_video), true)));
+       }
 }
 
 
@@ -2283,7 +2267,9 @@ Editor::set_state (const XMLNode& node, int /*version*/)
        }
 
        if ((prop = node.property ("zoom"))) {
-               reset_zoom (PBD::atof (prop->value()));
+               /* older versions of ardour used floating point samples_per_pixel */
+               double f = PBD::atof (prop->value());
+               reset_zoom (llrintf (f));
        } else {
                reset_zoom (samples_per_pixel);
        }
@@ -2505,7 +2491,8 @@ Editor::get_state ()
        maybe_add_mixer_strip_width (*node);
 
        node->add_property ("zoom-focus", enum_2_string (zoom_focus));
-       snprintf (buf, sizeof(buf), "%f", samples_per_pixel);
+
+       snprintf (buf, sizeof(buf), "%" PRId64, samples_per_pixel);
        node->add_property ("zoom", buf);
        node->add_property ("snap-to", enum_2_string (_snap_type));
        node->add_property ("snap-mode", enum_2_string (_snap_mode));
@@ -3147,12 +3134,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)
                {
@@ -3332,8 +3319,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 ()) {
@@ -3725,8 +3710,14 @@ Editor::set_show_measures (bool yn)
                        if (tempo_lines) {
                                tempo_lines->show();
                        }
-                       (void) redraw_measures ();
-               }
+
+                       ARDOUR::TempoMap::BBTPointList::const_iterator begin;
+                       ARDOUR::TempoMap::BBTPointList::const_iterator end;
+                       
+                       compute_current_bbt_points (leftmost_frame, leftmost_frame + current_page_samples(), begin, end);
+                       draw_measures (begin, end);
+               } 
+
                instant_save ();
        }
 }
@@ -4131,16 +4122,16 @@ Editor::reset_y_origin (double y)
 }
 
 void
-Editor::reset_zoom (double fpp)
+Editor::reset_zoom (framecnt_t spp)
 {
-       clamp_samples_per_pixel (fpp);
+       clamp_samples_per_pixel (spp);
 
-       if (fpp == samples_per_pixel) {
+       if (spp == samples_per_pixel) {
                return;
        }
 
        pending_visual_change.add (VisualChange::ZoomLevel);
-       pending_visual_change.samples_per_pixel = fpp;
+       pending_visual_change.samples_per_pixel = spp;
        ensure_visual_change_idle_handler ();
 }
 
@@ -4251,17 +4242,18 @@ Editor::use_visual_state (VisualState& vs)
  *  @param fpu New frames per unit; should already have been clamped so that it is sensible.
  */
 void
-Editor::set_samples_per_pixel (double fpp)
+Editor::set_samples_per_pixel (framecnt_t spp)
 {
+       clamp_samples_per_pixel (spp);
+       samples_per_pixel = spp;
+
        if (tempo_lines) {
                tempo_lines->tempo_map_changed();
        }
 
-       samples_per_pixel = fpp;
-
        /* convert fpu to frame count */
 
-       framepos_t frames = (framepos_t) floor (samples_per_pixel * _visible_canvas_width);
+       framepos_t frames = samples_per_pixel * _visible_canvas_width;
 
        if (samples_per_pixel != zoom_range_clock->current_duration()) {
                zoom_range_clock->set (frames);
@@ -4277,7 +4269,16 @@ Editor::set_samples_per_pixel (double fpp)
 
        ZoomChanged (); /* EMIT_SIGNAL */
 
-       //reset_scrolling_region ();
+       ArdourCanvas::GtkCanvasViewport* c;
+
+       c = get_time_bars_canvas();
+       if (c) {
+               c->canvas()->zoomed ();
+       }
+       c = get_track_canvas();
+       if (c) {
+               c->canvas()->zoomed ();
+       }
 
        if (playhead_cursor) {
                playhead_cursor->set_position (playhead_cursor->current_frame ());
@@ -4340,6 +4341,7 @@ Editor::idle_visual_changer ()
 
        double const last_time_origin = horizontal_position ();
 
+
        if (p & VisualChange::ZoomLevel) {
                set_samples_per_pixel (pending_visual_change.samples_per_pixel);
 
@@ -4353,9 +4355,7 @@ Editor::idle_visual_changer ()
                compute_bbt_ruler_scale (pending_visual_change.time_origin, pending_visual_change.time_origin + current_page_samples(),
                                         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();
        }
 
@@ -4404,7 +4404,7 @@ Editor::get_preferred_edit_position (bool ignore_playhead, bool from_context_men
        EditPoint ep = _edit_point;
 
        if (from_context_menu && (ep == EditAtMouse)) {
-               return  window_event_frame (&context_click_event, 0, 0);
+               return  canvas_event_frame (&context_click_event, 0, 0);
        }
 
        if (entered_marker) {
@@ -4891,8 +4891,10 @@ Editor::add_routes (RouteList& routes)
                rtv->view()->RegionViewRemoved.connect (sigc::mem_fun (*this, &Editor::region_view_removed));
        }
 
-       _routes->routes_added (new_views);
-       _summary->routes_added (new_views);
+       if (new_views.size() > 0) {
+               _routes->routes_added (new_views);
+               _summary->routes_added (new_views);
+       }
 
        if (show_editor_mixer_when_tracks_arrive) {
                show_editor_mixer (true);
@@ -5410,7 +5412,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);
@@ -5524,7 +5525,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;
 }