From 26134d5c7b78b7e3eb9a50bf9cf1679f8de29c4b Mon Sep 17 00:00:00 2001
From: ergen <rhetr@users.noreply.github.com>
Date: Thu, 23 Jul 2026 00:58:57 -0400
Subject: [PATCH] set allow patch changes

---
 gtk2_ardour/rc_option_editor.cc               | 32 +++++++++++++++++++
 gtk2_ardour/rc_option_editor.h                |  1 +
 .../ardour/ardour/rc_configuration_vars.inc.h |  1 +
 libs/ardour/triggerbox.cc                     |  2 +-
 4 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/gtk2_ardour/rc_option_editor.cc b/gtk2_ardour/rc_option_editor.cc
index 2c9bae1186..7d6ff68012 100644
--- a/gtk2_ardour/rc_option_editor.cc
+++ b/gtk2_ardour/rc_option_editor.cc
@@ -3690,6 +3690,16 @@ These settings will only take effect after %1 is restarted.\n\
 	add_option (_("Editor/Modifiers"), new KeyboardOptions);
 	add_option (_("Editor/Modifiers"), new OptionEditorBlank ());
 
+	/* Cue Page *****************************************************************/
+
+	add_option (_("Cue"), new OptionEditorHeading (_("Default Clip Properties")));
+	add_option (_("Cue"),
+			new BoolOption (
+				"allow-patch-changes",
+				_("Send MIDI patches on clip trigger"),
+				sigc::mem_fun (*_rc_config, &RCConfiguration::get_allow_patch_changes),
+				sigc::mem_fun (*this, &RCOptionEditor::set_allow_patch_changes)
+				));
 
 	/* MIDI *********************************************************************/
 
@@ -5579,3 +5589,25 @@ RCOptionEditor::set_default_upper_midi_note (std::string str)
 
 	return UIConfiguration::instance().set_default_upper_midi_note (note);
 }
+
+bool
+RCOptionEditor::set_allow_patch_changes (bool enabled)
+{
+	std::shared_ptr<RouteList const> rl = _session->get_routes();
+	for (auto const& route : *rl) {
+		std::shared_ptr<TriggerBox> box = route->triggerbox();
+		if (!box) {
+			// ignore routes with no triggerbox
+			continue;
+		}
+		for (int32_t n = 0; n < TriggerBox::default_triggers_per_box; ++n) {
+			TriggerPtr trigger = box->trigger(n);
+			if (std::shared_ptr<Region> () == trigger->the_region()) {
+				// only modify empty triggers
+				trigger->set_allow_patch_changes(enabled);
+			}
+		}
+	}
+
+	return _rc_config->set_allow_patch_changes (enabled);
+}
diff --git a/gtk2_ardour/rc_option_editor.h b/gtk2_ardour/rc_option_editor.h
index b617c784b9..12732e05b6 100644
--- a/gtk2_ardour/rc_option_editor.h
+++ b/gtk2_ardour/rc_option_editor.h
@@ -76,6 +76,7 @@ private:
 	bool set_default_lower_midi_note (std::string);
 	std::string get_default_upper_midi_note ();
 	bool set_default_upper_midi_note (std::string);
+	bool set_allow_patch_changes(bool);
 
 	/* plugin actions */
 	void plugin_scan_refresh ();
diff --git a/libs/ardour/ardour/rc_configuration_vars.inc.h b/libs/ardour/ardour/rc_configuration_vars.inc.h
index 87afd076b2..dcfa3ca88b 100644
--- a/libs/ardour/ardour/rc_configuration_vars.inc.h
+++ b/libs/ardour/ardour/rc_configuration_vars.inc.h
@@ -221,6 +221,7 @@ CONFIG_VARIABLE_SPECIAL (std::string, default_session_parent_dir, "default-sessi
 #endif
 CONFIG_VARIABLE (std::string, clip_library_dir, "clip-library-dir", "@default@") /* writable folder */
 CONFIG_VARIABLE (std::string, sample_lib_path, "sample-lib-path", "") /* custom paths */
+CONFIG_VARIABLE (bool, allow_patch_changes, "allow-patch-changes", true)
 CONFIG_VARIABLE (bool, allow_special_bus_removal, "allow-special-bus-removal", false)
 CONFIG_VARIABLE (int32_t, processor_usage, "processor-usage", -1)
 CONFIG_VARIABLE (int32_t, cpu_dma_latency, "cpu-dma-latency", -1) /* >=0 to enable */
diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc
index 6eef6cad12..baa83eae17 100644
--- a/libs/ardour/triggerbox.cc
+++ b/libs/ardour/triggerbox.cc
@@ -232,7 +232,7 @@ Trigger::Trigger (uint32_t n, TriggerBox& b)
 	, _velocity_effect (Properties::velocity_effect, 0.)
 	, _stretchable (Properties::stretchable, true)
 	, _cue_isolated (Properties::cue_isolated, false)
-	, _allow_patch_changes (Properties::allow_patch_changes, true)
+	, _allow_patch_changes (Properties::allow_patch_changes, Config->get_allow_patch_changes())
 	, _stretch_mode (Properties::stretch_mode, Trigger::Crisp)
 	, _name (Properties::name, "")
 	, _color (Properties::color, 0xBEBEBEFF)
-- 
2.43.0

