new_grid: Rewrite of Snap and Grid. (squashed commit)
[ardour.git] / gtk2_ardour / editor.h
index 98b96b65b7f26d2d1f7224d573bef191213f84c7..1d20fe5958b60b1eb81184a039d8ee307a2cc4dd 100644 (file)
@@ -128,6 +128,7 @@ class RulerDialog;
 class Selection;
 class SoundFileOmega;
 class StreamView;
+class GridLines;
 class TempoLines;
 class TimeAxisView;
 class TimeInfoBox;
@@ -161,19 +162,15 @@ public:
        double trackviews_height () const;
 
        void cycle_snap_mode ();
-       void next_snap_choice ();
-       void next_snap_choice_music_only ();
-       void next_snap_choice_music_and_time ();
-       void prev_snap_choice ();
-       void prev_snap_choice_music_only ();
-       void prev_snap_choice_music_and_time ();
-       void set_snap_to (Editing::SnapType);
+       void next_grid_choice ();
+       void prev_grid_choice ();
+       void set_grid_to (Editing::GridType);
        void set_snap_mode (Editing::SnapMode);
-       void set_snap_threshold (double pixel_distance) {snap_threshold = pixel_distance;}
 
        Editing::SnapMode  snap_mode () const;
-       Editing::SnapType  snap_type () const;
-       bool  snap_musical () const;
+       Editing::GridType  grid_type () const;
+       bool  grid_musical () const;
+       bool  grid_nonmusical () const;
 
        void undo (uint32_t n = 1);
        void redo (uint32_t n = 1);
@@ -274,8 +271,7 @@ public:
 
        /* tempo */
 
-       void set_show_measures (bool yn);
-       bool show_measures () const { return _show_measures; }
+       void update_grid ();
 
        /* analysis window */
 
@@ -362,10 +358,9 @@ public:
        void toggle_zero_line_visibility ();
        void set_summary ();
        void set_group_tabs ();
-       void toggle_measure_visibility ();
 
        /* returns the left-most and right-most time that the gui should allow the user to scroll to */
-       std::pair <samplepos_t,samplepos_t> session_gui_extents( bool use_extra = true ) const; 
+       std::pair <samplepos_t,samplepos_t> session_gui_extents (bool use_extra = true) const;
 
        /* fades */
 
@@ -459,18 +454,17 @@ public:
 
        void snap_to (ARDOUR::MusicSample& first,
                      ARDOUR::RoundMode   direction = ARDOUR::RoundNearest,
+                     ARDOUR::SnapPref    pref = ARDOUR::SnapToAny,
                      bool                for_mark  = false,
-                     bool                ensure_snap = false);
+                     bool                ensure_snap = false);
 
        void snap_to_with_modifier (ARDOUR::MusicSample& first,
                                    GdkEvent const *    ev,
                                    ARDOUR::RoundMode   direction = ARDOUR::RoundNearest,
+                                   ARDOUR::SnapPref    pref = ARDOUR::SnapToAny,
                                    bool                for_mark  = false);
 
-       void snap_to (ARDOUR::MusicSample& first,
-                     ARDOUR::MusicSample& last,
-                     ARDOUR::RoundMode   direction = ARDOUR::RoundNearest,
-                     bool                for_mark  = false);
+       void set_snapped_cursor_position (samplepos_t pos);
 
        void begin_selection_op_history ();
        void begin_reversible_selection_op (std::string cmd_name);
@@ -533,6 +527,7 @@ public:
        ArdourCanvas::ScrollGroup* get_hscroll_group () const { return h_scroll_group; }
        ArdourCanvas::ScrollGroup* get_hvscroll_group () const { return hv_scroll_group; }
        ArdourCanvas::ScrollGroup* get_cursor_scroll_group () const { return cursor_scroll_group; }
+       ArdourCanvas::Container* get_drag_motion_group () const { return _drag_motion_group; }
 
        ArdourCanvas::GtkCanvasViewport* get_track_canvas () const;
 
@@ -612,9 +607,9 @@ private:
        void on_samples_per_pixel_changed ();
 
        Editing::MouseMode mouse_mode;
-       Editing::SnapType  pre_internal_snap_type;
+       Editing::GridType  pre_internal_grid_type;
        Editing::SnapMode  pre_internal_snap_mode;
-       Editing::SnapType  internal_snap_type;
+       Editing::GridType  internal_grid_type;
        Editing::SnapMode  internal_snap_mode;
        Editing::MouseMode effective_mouse_mode () const;
 
@@ -658,7 +653,7 @@ private:
        gint really_remove_marker (ARDOUR::Location* loc);
        void goto_nth_marker (int nth);
        void trigger_script (int nth);
-       void trigger_script_by_name ( const std::string script_name );
+       void trigger_script_by_name (const std::string script_name);
        void toggle_marker_lines ();
        void set_marker_line_visibility (bool);
 
@@ -814,7 +809,6 @@ private:
        size_t push_canvas_cursor (Gdk::Cursor*);
        void pop_canvas_cursor ();
 
-       Gdk::Cursor* which_grabber_cursor () const;
        Gdk::Cursor* which_track_cursor () const;
        Gdk::Cursor* which_mode_cursor () const;
        Gdk::Cursor* which_trim_cursor (bool left_side) const;
@@ -1032,6 +1026,8 @@ private:
 
        friend class EditorCursor;
 
+       EditorCursor* snapped_cursor;
+
        EditorCursor* playhead_cursor;
        samplepos_t playhead_cursor_sample () const;
 
@@ -1064,7 +1060,9 @@ private:
        ARDOUR::samplepos_t find_next_region_boundary (ARDOUR::samplepos_t, int32_t dir, const TrackViewList&);
 
        std::vector<ARDOUR::samplepos_t> region_boundary_cache;
+       void mark_region_boundary_cache_dirty () { _region_boundary_cache_dirty = true; }
        void build_region_boundary_cache ();
+       bool    _region_boundary_cache_dirty;
 
        Gtk::HBox           toplevel_hpacker;
 
@@ -1519,19 +1517,16 @@ private:
        void set_loop_start_from_edit_point ();
        void set_loop_end_from_edit_point ();
 
-       void keyboard_selection_begin ( Editing::EditIgnoreOption = Editing::EDIT_IGNORE_NONE );
+       void keyboard_selection_begin (Editing::EditIgnoreOption = Editing::EDIT_IGNORE_NONE);
        void keyboard_selection_finish (bool add, Editing::EditIgnoreOption = Editing::EDIT_IGNORE_NONE);
        bool have_pending_keyboard_selection;
        samplepos_t pending_keyboard_selection_start;
 
        void move_range_selection_start_or_end_to_region_boundary (bool, bool);
 
-       Editing::SnapType _snap_type;
+       Editing::GridType _grid_type;
        Editing::SnapMode _snap_mode;
 
-       /// Snap threshold in pixels
-       double snap_threshold;
-
        bool ignore_gui_changes;
 
        DragManager* _drags;
@@ -1667,7 +1662,6 @@ private:
 
        /* display control */
 
-       bool _show_measures;
        /// true if the editor should follow the playhead, otherwise false
        bool _follow_playhead;
        /// true if we scroll the tracks rather than the playhead
@@ -1675,17 +1669,17 @@ private:
        /// true if we are in fullscreen mode
        bool _maximised;
 
-       TempoLines* tempo_lines;
+       std::vector<ArdourCanvas::Ruler::Mark> grid_marks;
+       GridLines* grid_lines;
 
        ArdourCanvas::Container* global_rect_group;
        ArdourCanvas::Container* time_line_group;
 
-       void hide_measures ();
-       void draw_measures (std::vector<ARDOUR::TempoMap::BBTPoint>&);
+       void hide_grid_lines ();
+       void maybe_draw_grid_lines ();
 
        void new_tempo_section ();
 
-
        void remove_tempo_marker (ArdourCanvas::Item*);
        void remove_meter_marker (ArdourCanvas::Item*);
        gint real_remove_tempo_marker (ARDOUR::TempoSection*);
@@ -1760,7 +1754,8 @@ private:
 
        void tempo_map_changed (const PBD::PropertyChange&);
        void tempometric_position_changed (const PBD::PropertyChange&);
-       void redisplay_tempo (bool immediate_redraw);
+
+       void redisplay_grid (bool immediate_redraw);
 
        uint32_t bbt_beat_subdivision;
 
@@ -1820,22 +1815,25 @@ private:
        void set_edit_mode (ARDOUR::EditMode);
        void cycle_edit_mode ();
 
-       ArdourWidgets::ArdourDropdown snap_type_selector;
-       void build_snap_type_menu ();
+       ArdourWidgets::ArdourDropdown grid_type_selector;
+       void build_grid_type_menu ();
+
+       ArdourWidgets::ArdourButton snap_mode_button;
+       bool snap_mode_button_clicked (GdkEventButton *);
 
-       ArdourWidgets::ArdourDropdown snap_mode_selector;
-       void build_snap_mode_menu ();
        Gtk::HBox snap_box;
 
-       std::vector<std::string> snap_type_strings;
+       Gtk::HBox _box;
+
+       std::vector<std::string> grid_type_strings;
        std::vector<std::string> snap_mode_strings;
 
-       void snap_type_selection_done (Editing::SnapType);
+       void grid_type_selection_done (Editing::GridType);
        void snap_mode_selection_done (Editing::SnapMode);
        void snap_mode_chosen (Editing::SnapMode);
-       void snap_type_chosen (Editing::SnapType);
+       void grid_type_chosen (Editing::GridType);
 
-       Glib::RefPtr<Gtk::RadioAction> snap_type_action (Editing::SnapType);
+       Glib::RefPtr<Gtk::RadioAction> grid_type_action (Editing::GridType);
        Glib::RefPtr<Gtk::RadioAction> snap_mode_action (Editing::SnapMode);
 
        //zoom focus meu stuff
@@ -2186,14 +2184,18 @@ private:
        void select_next_stripable (bool routes_only = true);
        void select_prev_stripable (bool routes_only = true);
 
+       samplepos_t snap_to_grid (      std::vector<ArdourCanvas::Ruler::Mark>  marks, 
+                                    samplepos_t                             presnap,
+                                    ARDOUR::RoundMode                       direction = ARDOUR::RoundNearest);
+
        void snap_to_internal (ARDOUR::MusicSample& first,
                               ARDOUR::RoundMode   direction = ARDOUR::RoundNearest,
+                              ARDOUR::SnapPref    gpref = ARDOUR::SnapToAny,
                               bool                for_mark  = false,
-                              bool                ensure_snap = false);
+                              bool                ensure_snap = false);
 
-       void timecode_snap_to_internal (ARDOUR::MusicSample& first,
-                                       ARDOUR::RoundMode   direction = ARDOUR::RoundNearest,
-                                       bool                for_mark  = false);
+       samplepos_t marker_snap_to_internal (samplepos_t        presnap,
+                                              ARDOUR::RoundMode   direction = ARDOUR::RoundNearest);
 
        RhythmFerret* rhythm_ferret;