Repository navigation
Expand file tree
/
Copy pathau_loadprogram_backfill.patch
More file actions
86 lines (78 loc) · 3.79 KB
/
Copy pathau_loadprogram_backfill.patch
File metadata and controls
86 lines (78 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
diff --git a/distrho/src/DistrhoPluginAU.cpp b/distrho/src/DistrhoPluginAU.cpp
index 4290dd61..c9ced513 100644
--- a/distrho/src/DistrhoPluginAU.cpp
+++ b/distrho/src/DistrhoPluginAU.cpp
@@ -30,6 +30,7 @@
#include <AudioToolbox/AudioUnitUtilities.h>
#include <map>
+#include <memory>
#include <vector>
#ifndef DISTRHO_PLUGIN_BRAND_ID
@@ -2649,6 +2650,18 @@ private:
reinterpret_cast<const void**>(&data)),);
DISTRHO_SAFE_ASSERT_RETURN(CFGetTypeID(data) == CFDictionaryGetTypeID(),);
+ #if DISTRHO_PLUGIN_WANT_STRICT_PARAMETER_RESTORE
+ // Tracks which parameters this call actually assigned a value to,
+ // whether via a loaded program or an explicit "params" entry, so that
+ // anything left untouched can be backfilled with its coded default
+ // below instead of silently keeping whatever value the plugin
+ // instance happened to have before this call.
+ // std::vector<bool> is NOT usable here since its bit-packed
+ // specialization can't hand back a real bool* for loadProgram()'s
+ // out-parameter.
+ const std::unique_ptr<bool[]> paramsSet(new bool[fParameterCount]());
+ #endif
+
#if DISTRHO_PLUGIN_WANT_PROGRAMS
CFNumberRef programRef = nullptr;
if (CFDictionaryGetValueIfPresent(data, CFSTR("program"), reinterpret_cast<const void**>(&programRef))
@@ -2662,7 +2675,11 @@ private:
if (program >= 0)
{
fLastFactoryProgram = program;
+ #if DISTRHO_PLUGIN_WANT_STRICT_PARAMETER_RESTORE
+ fPlugin.loadProgram(fLastFactoryProgram, paramsSet.get());
+ #else
fPlugin.loadProgram(fLastFactoryProgram);
+ #endif
notifyPropertyListeners('DPFo', kAudioUnitScope_Global, 0);
}
@@ -2783,6 +2800,9 @@ private:
fLastParameterValues[j] = value;
fPlugin.setParameterValue(j, value);
+ #if DISTRHO_PLUGIN_WANT_STRICT_PARAMETER_RESTORE
+ paramsSet[j] = true;
+ #endif
notifyPropertyListeners('DPFp', kAudioUnitScope_Global, j);
if (fBypassParameterIndex == j)
@@ -2794,6 +2814,32 @@ private:
std::free(symbol);
}
+
+ #if DISTRHO_PLUGIN_WANT_STRICT_PARAMETER_RESTORE
+ // Anything not explicitly touched above -- whether because it was
+ // never mentioned by the incoming preset at all, because a "params"
+ // entry was malformed or named an unknown symbol, or (when
+ // DISTRHO_PLUGIN_WANT_PROGRAMS is also enabled) because the requested
+ // program did not assign it -- is reset to its coded default here,
+ // rather than being left at whatever value this plugin instance had
+ // before this call. Each parameter is still only ever assigned once
+ // per call: this loop is disjoint from both the program-load and the
+ // explicit "params" assignments above.
+ for (uint32_t j=0; j<fParameterCount; ++j)
+ {
+ if (paramsSet[j] || fPlugin.isParameterOutputOrTrigger(j))
+ continue;
+
+ const float value = fPlugin.getParameterRanges(j).def;
+
+ fLastParameterValues[j] = value;
+ fPlugin.setParameterValue(j, value);
+ notifyPropertyListeners('DPFp', kAudioUnitScope_Global, j);
+
+ if (fBypassParameterIndex == j)
+ notifyPropertyListeners(kAudioUnitProperty_BypassEffect, kAudioUnitScope_Global, 0);
+ }
+ #endif
}
// ----------------------------------------------------------------------------------------------------------------