commit bee6a3c0ae9d03cba86121c798571fb317353ab6
Author: Mark Knoop <mark@markknoop.com>
Date:   Thu Jan 5 17:09:01 2023 +0000

    Change logic to fix partially glued regions

diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc
index 00a7da8b78..1ed261d357 100644
--- a/gtk2_ardour/editor_ops.cc
+++ b/gtk2_ardour/editor_ops.cc
@@ -6550,6 +6550,12 @@ Editor::toggle_region_lock_style ()
 	for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
 		(*i)->region()->clear_changes ();
 		Temporal::TimeDomain const td = ((*i)->region()->position_time_domain() == Temporal::AudioTime && !cmi->get_inconsistent()) ? Temporal::BeatTime : Temporal::AudioTime;
+		cerr << "==================================================================" << endl;
+		if (td == Temporal::AudioTime) {
+			cerr << "Editor::toggle_region_lock_style : Region time domain set to Audio Time" << endl;
+		} else {
+			cerr << "Editor::toggle_region_lock_style : Region time domain set to Beat Time" << endl;
+		}
 		(*i)->region()->set_position_time_domain (td);
 		_session->add_command (new StatefulDiffCommand ((*i)->region()));
 	}
diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc
index 62afa7cc5e..8b3a138260 100644
--- a/libs/ardour/region.cc
+++ b/libs/ardour/region.cc
@@ -583,17 +583,28 @@ Region::special_set_position (timepos_t const & pos)
 void
 Region::set_position_time_domain (Temporal::TimeDomain td)
 {
-	if (_length.val().time_domain() != td) {
+	cerr << "  Region::set_position_time_domain" << endl;
 
+	if (position().time_domain() != td) {
+
+		if (td == Temporal::AudioTime) {
+			cerr << "  Region::set_position_time_domain : Region time domain set to Audio Time" << endl;
+		} else {
+			cerr << "  Region::set_position_time_domain : Region time domain set to Beat Time" << endl;
+		}
 		/* _length is a property so we cannot directly call
 		 * ::set_time_domain() on it. Create a temporary timecnt_t,
 		 * change it's time domain, and then assign to _length
 		 */
 
+		cerr << "  Region::set_position_time_domain : old length = " << _length.val().str() << endl;
+
 		timecnt_t t (_length.val());
 		t.set_time_domain (td);
 		_length = t;
 
+		cerr << "  Region::set_position_time_domain : new length = " << _length.val().str() << endl;
+
 		send_change (Properties::time_domain);
 	}
 }
diff --git a/libs/temporal/timeline.cc b/libs/temporal/timeline.cc
index 2c2798e2e1..357373530e 100644
--- a/libs/temporal/timeline.cc
+++ b/libs/temporal/timeline.cc
@@ -155,13 +155,27 @@ timecnt_t::end (TimeDomain return_domain) const
 void
 timecnt_t::set_time_domain (TimeDomain td)
 {
+	std::cerr << "    timecnt_t::set_time_domain" << std::endl;
+
 	if (time_domain() == td) {
-		return;
+		std::cerr << "    timecnt_t::set_time_domain : time domain already set!" << std::endl;
+		//return;
+	}
+
+	if (td == Temporal::AudioTime) {
+		std::cerr << "    timecnt_t::set_time_domain : time domain set to Audio Time" << std::endl;
+	} else {
+		std::cerr << "    timecnt_t::set_time_domain : time domain set to Beat Time" << std::endl;
 	}
 
+	std::cerr << "    timecnt_t::set_time_domain : old position = " << _position.str() << std::endl;
+
 	_position.set_time_domain (td);
 
-	if (_distance.flagged()) {
+	std::cerr << "    timecnt_t::set_time_domain : new position = " << _position.str() << std::endl;
+
+	//if (_distance.flagged()) {
+	if (td == Temporal::AudioTime) {
 		/* beats -> superclock */
 		_distance = int62_t (false, TempoMap::use()->superclock_at (Beats::ticks (magnitude())));
 	} else {
