Don't invalidate AU preset on load
authorRobin Gareus <robin@gareus.org>
Sun, 2 Dec 2018 01:04:21 +0000 (02:04 +0100)
committerRobin Gareus <robin@gareus.org>
Sun, 2 Dec 2018 01:04:21 +0000 (02:04 +0100)
This works around async parameter-changed signal emission when loading
an AU preset. A simple timeout is used to delay making the preset
as modified.

libs/ardour/ardour/audio_unit.h
libs/ardour/audio_unit.cc

index 55faf4a08e462092ea3da649e29f7481c663470a..454a7d1ce0ac11cf3b2468d9fe58441da945908a 100644 (file)
@@ -228,8 +228,9 @@ class LIBARDOUR_API AUPlugin : public ARDOUR::Plugin
        void discover_factory_presets ();
 
        samplepos_t transport_sample;
-       float      transport_speed;
-       float      last_transport_speed;
+       float       transport_speed;
+       float       last_transport_speed;
+       pframes_t   preset_holdoff;
 
        static void _parameter_change_listener (void* /*arg*/, void* /*src*/, const AudioUnitEvent* event, UInt64 host_time, Float32 new_value);
        void parameter_change_listener (void* /*arg*/, void* /*src*/, const AudioUnitEvent* event, UInt64 host_time, Float32 new_value);
index 812d004e6a0673dc7f72a40fadc5a342c6d10ea3..559961b0b28c415c75369eabdf9ffa03342aff5a 100644 (file)
@@ -452,6 +452,7 @@ AUPlugin::AUPlugin (AudioEngine& engine, Session& session, boost::shared_ptr<CAC
        , transport_sample (0)
        , transport_speed (0)
        , last_transport_speed (0.0)
+       , preset_holdoff (0)
 {
        if (!preset_search_path_initialized) {
                Glib::ustring p = Glib::get_home_dir();
@@ -493,6 +494,7 @@ AUPlugin::AUPlugin (const AUPlugin& other)
        , transport_sample (0)
        , transport_speed (0)
        , last_transport_speed (0.0)
+       , preset_holdoff (0)
 
 {
        init ();
@@ -1651,6 +1653,10 @@ AUPlugin::connect_and_run (BufferSet& bufs,
        AudioTimeStamp ts;
        OSErr err;
 
+       if (preset_holdoff > 0) {
+               preset_holdoff -= std::min (nframes, preset_holdoff);
+       }
+
        if (requires_fixed_size_buffers() && (nframes != _last_nframes)) {
                unit->GlobalReset();
                _last_nframes = nframes;
@@ -2215,6 +2221,9 @@ AUPlugin::load_preset (PresetRecord r)
                        AUParameterListenerNotify (NULL, NULL, &changedUnit);
                }
        }
+       if (ret) {
+               preset_holdoff = std::max (_session.get_block_size() * 2.0, _session.sample_rate() * .2);
+       }
 
        return ret && Plugin::load_preset (r);
 }
@@ -3500,7 +3509,11 @@ AUPlugin::parameter_change_listener (void* /*arg*/, void* src, const AudioUnitEv
                 /* whenever we change a parameter, we request that we are NOT notified of the change, so anytime we arrive here, it
                    means that something else (i.e. the plugin GUI) made the change.
                 */
-                Plugin::parameter_changed_externally (i->second, new_value);
+                if (preset_holdoff > 0) {
+                       ParameterChangedExternally (i->second, new_value);
+                } else {
+                        Plugin::parameter_changed_externally (i->second, new_value);
+               }
                 break;
         default:
                 break;