[ardour-dev] Patch

Tim Mayberry timbyr at pacific.net.au
Tue Feb 10 20:00:08 PST 2004


This patch has a few small fixes and introduces a 
new magnetic snap mode.
-------------- next part --------------
--- ardour-orig/gtk_ardour/ardour_ui.rc	2004-02-10 14:40:46.000000000 +1000
+++ ardour/gtk_ardour/ardour_ui.rc	2004-02-11 11:07:14.000000000 +1000
@@ -1452,6 +1452,9 @@
 widget "*EditModeSelector" style "cyan_on_teal_entry"
 widget "*EditModeSelector.GtkButton" style "basic_blue_gray_button"
 widget "*EditModeSelector.GtkArrow" style "basic_blue_gray_button"
+widget "*SnapTypeSelector" style "cyan_on_teal_entry"
+widget "*SnapTypeSelector.GtkButton" style "basic_blue_gray_button"
+widget "*SnapTypeSelector.GtkArrow" style "basic_blue_gray_button"
 widget "*SnapModeSelector" style "cyan_on_teal_entry"
 widget "*SnapModeSelector.GtkButton" style "basic_blue_gray_button"
 widget "*SnapModeSelector.GtkArrow" style "basic_blue_gray_button"
-------------- next part --------------
--- ardour-orig/gtk_ardour/editing.h	2004-02-03 13:46:18.000000000 +1000
+++ ardour/gtk_ardour/editing.h	2004-02-11 11:07:14.000000000 +1000
@@ -26,6 +26,11 @@
 		SnapToRegionBoundary
 	};
 
+	enum SnapMode {
+		SnapNormal,
+		SnapMagnetic
+	};
+
 	enum XFadeType {
 		Pre,
 		Post,
-------------- next part --------------
--- ardour-orig/gtk_ardour/editor.cc	2004-02-10 14:40:47.000000000 +1000
+++ ardour/gtk_ardour/editor.cc	2004-02-11 11:07:14.000000000 +1000
@@ -110,7 +110,7 @@
 	0
 };
 
-static const gchar *snap_mode_strings[] = {
+static const gchar *snap_type_strings[] = {
 	N_("None"),
 	N_("Beats/32"),
 	N_("Beats/16"),
@@ -128,6 +128,12 @@
 	0
 };
 
+static const gchar *snap_mode_strings[] = {
+	N_("Normal"),
+	N_("Magnetic"),
+	0
+};
+
 static const gchar *zoom_focus_strings[] = {
 	N_("Left"),
 	N_("Right"),
@@ -261,7 +267,8 @@
 	  global_automation_button (_("automation")),
 
 	  edit_mode_label (_("Edit Mode")),
-	  snap_mode_label (_("Snap To")),
+	  snap_type_label (_("Snap To")),
+	  snap_mode_label(_("Snap Mode")),
 	  zoom_focus_label (_("Zoom Focus")),
 
 // 	  zoom_adjustment (11, 0, 32, 1, 4),
@@ -308,6 +315,8 @@
 	region_list_display_drag_region = 0;
 
 	snap_type = SnapToFrame;
+	snap_mode = SnapNormal;
+	snap_threshold = 5.0;
 	bbt_beat_subdivision = 4;
 	canvas_width = 0;
 	canvas_height = 0;
@@ -1843,6 +1852,12 @@
 }
 
 void
+Editor::set_snap_mode (SnapMode mode)
+{
+	snap_mode = mode;
+}
+
+void
 Editor::set_selection_from_location ()
 {
 	if (clicked_trackview == 0) {
@@ -1961,6 +1976,10 @@
 		set_snap_to ((SnapType) atoi (prop->value()));
 	}
 
+	if ((prop = node.property ("snap-mode"))) {
+		set_snap_mode ((SnapMode) atoi (prop->value()));
+	}
+
 	if ((prop = node.property ("show-waveforms"))) {
 		set_show_waveforms (prop->value() == "yes");
 	}
@@ -2026,7 +2045,9 @@
 	node->add_property ("zoom", buf);
 	snprintf (buf, sizeof(buf), "%d", (int) snap_type);
 	node->add_property ("snap-to", buf);
-	
+	snprintf (buf, sizeof(buf), "%d", (int) snap_mode);
+	node->add_property ("snap-mode", buf);
+
 	node->add_property ("show-waveforms", _show_waveforms ? "yes" : "no");
 	node->add_property ("show-measures", _show_measures ? "yes" : "no");
 	node->add_property ("follow-playhead", _show_measures ? "yes" : "no");
@@ -2056,8 +2077,10 @@
 void
 Editor::snap_to (jack_nframes_t& start, int direction, bool for_mark)
 {
-	Location* before;
-	Location* after;
+	Location* before = 0;
+	Location* after = 0;
+
+	jack_nframes_t presnap = start;
 
 	switch (snap_type) {
 	case SnapToFrame:
@@ -2148,6 +2171,28 @@
 		}
 		break;
 	}
+
+	switch (snap_mode) {
+	case SnapNormal:
+		return;			
+		
+	case SnapMagnetic:
+		
+		if (presnap > start) {
+			if (presnap > (start + unit_to_frame(snap_threshold))) {
+				start = presnap;
+			}
+			
+		} else if (presnap < start) {
+			if (presnap < (start - unit_to_frame(snap_threshold))) {
+				start = presnap;
+			}
+		}
+		
+	default:
+		return;
+		
+	}
 }
 
 void
@@ -2249,20 +2294,40 @@
 
 	edit_mode_selector.get_popwin()->unmap_event.connect (slot (*this, &Editor::edit_mode_selection_done));
 
-	/* Snap mode */
+	/* Snap Type */
+
+	snap_type_label.set_name ("ToolBarLabel");
+
+	snap_type_selector.set_name ("SnapTypeSelector");
+	snap_type_selector.get_entry()->set_name ("SnapTypeSelector");
+	snap_type_selector.get_popwin()->set_name ("SnapTypeSelector");
+
+	snap_type_box.set_spacing (3);
+	snap_type_box.set_border_width (3);
+
+	/* XXX another disgusting hack because of the way combo boxes size themselves */
+
+	Gtkmmext::set_usize_to_display_given_text (*snap_type_selector.get_entry(), "Region bounds", 2, 10);
+	snap_type_selector.set_popdown_strings (internationalize (snap_type_strings));
+	snap_type_selector.set_value_in_list (true, false);
+
+	snap_type_box.pack_start (snap_type_label, false, false);
+	snap_type_box.pack_start (snap_type_selector, false, false);
+
+	snap_type_selector.get_popwin()->unmap_event.connect (slot (*this, &Editor::snap_type_selection_done));
+
+	/* Snap mode, not snap type */
 
 	snap_mode_label.set_name ("ToolBarLabel");
 
 	snap_mode_selector.set_name ("SnapModeSelector");
 	snap_mode_selector.get_entry()->set_name ("SnapModeSelector");
 	snap_mode_selector.get_popwin()->set_name ("SnapModeSelector");
-
+	
 	snap_mode_box.set_spacing (3);
 	snap_mode_box.set_border_width (3);
 
-	/* XXX another disgusting hack because of the way combo boxes size themselves */
-
-	Gtkmmext::set_usize_to_display_given_text (*snap_mode_selector.get_entry(), "Region bounds", 2, 10);
+	Gtkmmext::set_usize_to_display_given_text (*snap_mode_selector.get_entry(), "SngpMode", 2, 10);
 	snap_mode_selector.set_popdown_strings (internationalize (snap_mode_strings));
 	snap_mode_selector.set_value_in_list (true, false);
 
@@ -2326,6 +2391,7 @@
 	hbox->pack_start (toolbar_selection_clock_table, false, false);
 	hbox->pack_start (zoom_indicator_vbox, false, false); 
 	hbox->pack_start (zoom_focus_box, false, false);
+	hbox->pack_start (snap_type_box, false, false);
 	hbox->pack_start (snap_mode_box, false, false);
 	hbox->pack_start (edit_mode_box, false, false);
 
@@ -2850,13 +2916,13 @@
 }	
 
 gint
-Editor::snap_mode_selection_done (GdkEventAny *ev)
+Editor::snap_type_selection_done (GdkEventAny *ev)
 {
 	if (session == 0) {
 		return FALSE;
 	}
 
-	string choice = snap_mode_selector.get_entry()->get_text();
+	string choice = snap_type_selector.get_entry()->get_text();
 	SnapType snaptype = SnapToFrame;
 	
 	if (choice == _("Beats/3")) {
@@ -2895,6 +2961,25 @@
 }	
 
 gint
+Editor::snap_mode_selection_done (GdkEventAny *ev)
+{
+	if(session == 0) return FALSE;
+
+	string choice = snap_mode_selector.get_entry()->get_text();
+	SnapMode mode = SnapNormal;
+
+	if (choice == _("Normal")) {
+		mode = SnapNormal;
+	} else if (choice == _("Magnetic")) {
+		mode = SnapMagnetic;
+	}
+
+	set_snap_mode (mode);
+
+	return FALSE;
+}
+
+gint
 Editor::zoom_focus_selection_done (GdkEventAny *ev)
 {
 	if (session == 0) {
-------------- next part --------------
--- ardour-orig/gtk_ardour/editor.h	2004-02-10 14:40:47.000000000 +1000
+++ ardour/gtk_ardour/editor.h	2004-02-11 11:07:14.000000000 +1000
@@ -113,6 +113,8 @@
 	ARDOUR::Session* current_session() const { return session; }
 
 	void set_snap_to (Editing::SnapType);
+	void set_snap_mode (Editing::SnapMode);
+	void set_snap_threshold (double pixel_distance) {snap_threshold = pixel_distance;}
 
 	void undo (unsigned int n = 1);
 	void redo (unsigned int n = 1);
@@ -923,6 +925,8 @@
 	void extend_selection_to_start_of_region (bool previous);
 
 	Editing::SnapType snap_type;
+	Editing::SnapMode snap_mode;
+	double snap_threshold;
 
 	void soundfile_chosen_for_insert (string selection, bool split_channels);
 	void soundfile_chosen_for_embed (string selection, bool split_channels);
@@ -1210,6 +1214,12 @@
 
 	gint edit_mode_selection_done (GdkEventAny*);
 
+	Gtk::Combo               snap_type_selector;
+	Gtk::Label               snap_type_label;
+	Gtk::VBox                snap_type_box;
+
+	gint snap_type_selection_done (GdkEventAny*);
+
 	Gtk::Combo               snap_mode_selector;
 	Gtk::Label               snap_mode_label;
 	Gtk::VBox                snap_mode_box;
-------------- next part --------------
--- ardour-orig/gtk_ardour/editor_mouse.cc	2004-02-10 14:40:47.000000000 +1000
+++ ardour/gtk_ardour/editor_mouse.cc	2004-02-11 11:14:49.000000000 +1000
@@ -184,7 +184,7 @@
 		for (AudioRegionSelection::iterator i = selection->audio_regions.begin(); i != selection->audio_regions.end(); ++i) {
 			(*i)->set_should_show_selection (false);
 		}
-		for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
+		for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
 			if ((*i)->selected()) {
 				(*i)->show_selection (selection->time);
 			}
@@ -255,23 +255,23 @@
 		break;
 
 	case MouseZoom:
-		if (next) set_mouse_mode (MouseTimeFX);
+		if (next) set_mouse_mode (MouseGain);
 		else set_mouse_mode (MouseRange);
 		break;
-
-	case MouseTimeFX:
-		if (next) set_mouse_mode (MouseGain);
+	
+	case MouseGain:
+		if (next) set_mouse_mode (MouseTimeFX);
 		else set_mouse_mode (MouseZoom);
 		break;
-
-	case MouseGain:
+	
+	case MouseTimeFX:
 		if (next) set_mouse_mode (MouseScrub);
-		else set_mouse_mode (MouseTimeFX);
+		else set_mouse_mode (MouseGain);
 		break;
 
 	case MouseScrub:
 		if (next) set_mouse_mode (MouseObject);
-		else set_mouse_mode (MouseGain);
+		else set_mouse_mode (MouseTimeFX);
 		break;
 	}
 }
@@ -415,10 +415,15 @@
 				break;
 
 			case SelectionItem:
-				if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
+				if (Keyboard::modifier_state_contains 
+				    (event->button.state, Keyboard::ModifierMask(Keyboard::Alt))) {
+					// contains and not equals because I can't use alt as a modifier alone.
+					start_selection_grab (item, event);
+				} else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
 					/* grab selection for moving */
 					start_selection_op (item, event, SelectionMove);
 				}
+					   					   
 				break;
 
 			default:
@@ -472,15 +477,6 @@
 					start_line_grab_from_line (item, event);
 					return TRUE;
 					break;
-					
-				case SelectionItem:
-					if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
-						/* grab selection for moving (for now) */
-						start_selection_op (item, event, SelectionMove);
-					} else {
-						start_selection_grab (item, event);
-					}
-					break;
 
 				case StreamItem:
 					/* start rubberband region select */
-------------- next part --------------
--- ardour-orig/gtk_ardour/public_editor.h	2004-02-11 12:36:11.000000000 +1000
+++ ardour/gtk_ardour/public_editor.h	2004-02-11 11:07:14.000000000 +1000
@@ -44,6 +44,8 @@
 	virtual void             connect_to_session (ARDOUR::Session*) = 0;
 	virtual ARDOUR::Session* current_session() const = 0;
 	virtual void set_snap_to (Editing::SnapType) = 0;
+	virtual void set_snap_mode (Editing::SnapMode) = 0;
+	virtual void set_snap_threshold (double) = 0;
 	virtual void undo (unsigned int n = 1) = 0;
 	virtual void redo (unsigned int n = 1) = 0;
 	virtual void set_mouse_mode (Editing::MouseMode) = 0;


More information about the Ardour-Dev mailing list