RAM2118 commited on
Commit
33d2e82
·
verified ·
1 Parent(s): 767fa15

add FAILED-APPROACHES.md — log of everything that didn't work and why

Browse files
Files changed (1) hide show
  1. FAILED-APPROACHES.md +182 -0
FAILED-APPROACHES.md ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PluginBridge — Failed Approaches & Architecture Decisions Log
2
+ > Everything we tried that didn't work, why it failed, and what we did instead.
3
+ > Use this to avoid repeating mistakes or to revisit with better solutions later.
4
+
5
+ ---
6
+
7
+ ## 1. Out-of-Process GUI via Floating Window (Sprint 2, v0.2)
8
+
9
+ **What we tried:**
10
+ Host the plugin in a separate Helper process. Show the plugin's GUI as a floating window from the Helper process, overlaying Ableton.
11
+
12
+ **What worked:**
13
+ - Audio routing via shared memory ✅
14
+ - Crash safety (Helper crashes, Ableton survives) ✅
15
+ - GUI showed correctly when Ableton was in WINDOWED mode ✅
16
+
17
+ **What broke:**
18
+ When Ableton was in macOS FULLSCREEN, the plugin GUI opened in a separate Space (different virtual desktop), not over Ableton.
19
+
20
+ **Fixes attempted (all failed in fullscreen):**
21
+
22
+ | Attempt | Code | Result |
23
+ |---|---|---|
24
+ | `NSApplicationActivationPolicyAccessory` | Set in `main.cpp initialise()` | No Dock icon ✅ but broke fullscreen behavior ❌ |
25
+ | `setLevel: 3` (NSFloatingWindowLevel) | In `showAsFloatingPanel()` | Not high enough — fullscreen apps are above level 3 ❌ |
26
+ | `setLevel: 25` (NSStatusWindowLevel) | In `showAsFloatingPanel()` | Still opens in separate Space ❌ |
27
+ | `setCollectionBehavior: canJoinAllSpaces + fullScreenAuxiliary` (257) | Before `setVisible(true)` | Still separate Space ❌ |
28
+ | `setCollectionBehavior` + `stationary` + `ignoresCycle` | Full flags (1<<0 \| 1<<4 \| 1<<6 \| 1<<8) | Still separate Space ❌ |
29
+ | `orderFrontRegardless` | After setting level | Window appears but wrong Space ❌ |
30
+ | `setHidesOnDeactivate: 0` | Combined with above | No effect on Space problem ❌ |
31
+ | `setAlwaysOnTop(true)` (JUCE method) | Reverted to original approach | Was original working code but didn't fix fullscreen either ❌ |
32
+
33
+ **Root cause:**
34
+ macOS fullscreen creates a dedicated compositor Space. Apple prevents other processes from injecting windows into a fullscreen app's Space. No combination of window level, collection behavior, or activation policy reliably works for cross-process window display in fullscreen. This is a macOS platform limitation, not a code bug.
35
+
36
+ **What we did instead:**
37
+ Switched to in-process hosting (v0.3). Plugin GUI is embedded inside PluginBridge's own editor. Ableton manages the window. No separate process window needed.
38
+
39
+ ---
40
+
41
+ ## 2. X Button (Close) Not Working on Helper Window (Sprint 2, v0.2)
42
+
43
+ **What happened:**
44
+ The Helper's floating window had minimize and close (X) buttons visible, but clicking X did nothing.
45
+
46
+ **Root cause:**
47
+ When the Helper ran as `NSApplicationActivationPolicyAccessory`, macOS doesn't deliver close-button clicks to accessory-policy processes the same way. The native title bar's close button was visible but non-functional.
48
+
49
+ **Fix by Claude Code (commit 0632681):**
50
+ Removed `makeAccessoryProcess()`, added `showAsFloatingPanel()` with objc_msgSend level tricks. This fixed the X button but broke the fullscreen behavior (see #1 above).
51
+
52
+ **What we did instead:**
53
+ In v0.3 (in-process hosting), there's no separate window at all. The plugin editor is a child component inside PluginBridge's editor. No close button needed — the DAW manages the window lifecycle.
54
+
55
+ ---
56
+
57
+ ## 3. Plugin Crashes Crashing Ableton (v0.3 initial)
58
+
59
+ **What happened:**
60
+ After moving to in-process hosting, loading Kickstart 2 crashed Ableton (because the plugin crash happens inside Ableton's process).
61
+
62
+ **Root cause:**
63
+ `loadPlugin()` called `createPluginInstance()` directly without first testing if the plugin was safe. Some plugins (Kickstart 2, Ozone 12, Gullfoss) call `abort()` or show `NSAlert` during loading, which kills the host process.
64
+
65
+ **Fix attempted that was missing:**
66
+ The design called for Helper-based test loading BEFORE in-process load, but it was left as a `// TODO` stub.
67
+
68
+ **What we did:**
69
+ Implemented `testPluginSafety()` — spawns `PluginBridgeHelper --test "/path"` before loading. If Helper survives (exit 0) → safe to load in-process. If Helper crashes → add to blocklist → show "Not compatible" → Ableton stays alive.
70
+
71
+ ---
72
+
73
+ ## 4. In-Process Hosting = No Crash Safety for Audio Processing
74
+
75
+ **Current limitation (v0.3):**
76
+ If a plugin passes the test-load but crashes during `processBlock()` later (rare but possible), Ableton will still crash. The Helper test only validates loading, not runtime stability.
77
+
78
+ **Potential future solutions:**
79
+ - Wrap `processBlock()` in a signal handler (fragile, not recommended)
80
+ - Use `setjmp`/`longjmp` around processBlock (undefined behavior with C++)
81
+ - Move back to out-of-process audio routing BUT keep GUI in-process (hybrid approach)
82
+ - Accept the risk — plugins that crash during audio processing are very rare
83
+
84
+ **Status:** Accepted risk. Most crashes happen during loading, not during audio processing.
85
+
86
+ ---
87
+
88
+ ## 5. Plugin Scanning via PluginDirectoryScanner (Early research, never shipped)
89
+
90
+ **What was planned:**
91
+ Use JUCE's `PluginDirectoryScanner` to scan all installed plugins on first run.
92
+
93
+ **Why it was rejected:**
94
+ Some plugins execute code during scanning (show NSAlert dialogs, call abort()). This would crash the scanner — or worse, crash Ableton if scanning happened in-process.
95
+
96
+ **What we did instead:**
97
+ Read `.vst3` and `.component` filenames from disk (no code execution). Only actually load a plugin when the user selects it (after Helper test).
98
+
99
+ ---
100
+
101
+ ## 6. `addDefaultFormats()` — Deleted in JUCE 8
102
+
103
+ **What happened:**
104
+ Early code used `formatManager.addDefaultFormats()` which doesn't exist in JUCE 8.
105
+
106
+ **Fix:**
107
+ Explicitly register formats:
108
+ ```cpp
109
+ formatManager.addFormat(new juce::VST3PluginFormat());
110
+ formatManager.addFormat(new juce::AudioUnitPluginFormat());
111
+ ```
112
+
113
+ ---
114
+
115
+ ## 7. `MSG_NOSIGNAL` — Doesn't Exist on macOS
116
+
117
+ **What happened:**
118
+ Socket code used `MSG_NOSIGNAL` flag which is Linux-only.
119
+
120
+ **Fix:**
121
+ ```cpp
122
+ signal(SIGPIPE, SIG_IGN); // Global
123
+ int nosigpipe = 1;
124
+ setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe)); // Per-socket
125
+ ```
126
+
127
+ ---
128
+
129
+ ## 8. `juce::Thread::setCurrentThreadPriority()` — Removed in JUCE 8
130
+
131
+ **What happened:**
132
+ Audio thread priority setting via JUCE API no longer exists.
133
+
134
+ **Fix:**
135
+ Use native pthread:
136
+ ```cpp
137
+ struct sched_param param;
138
+ param.sched_priority = sched_get_priority_max(SCHED_FIFO);
139
+ pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
140
+ ```
141
+
142
+ ---
143
+
144
+ ## 9. `create_audio_track()` Serialization Error (Ableton LOM, not PluginBridge)
145
+
146
+ **Context:** From the broader AI Music Production system, not PluginBridge-specific.
147
+
148
+ **What happened:**
149
+ `song.create_audio_track()` in Ableton's LOM returns a "not JSON serializable" error.
150
+
151
+ **Reality:**
152
+ The track IS created. The error is in the return value serialization, not the action.
153
+
154
+ **Workaround:**
155
+ Always check `len(song.tracks)` to confirm track was created, ignore the error message.
156
+
157
+ ---
158
+
159
+ ## Architecture Evolution Summary
160
+
161
+ ```
162
+ v0.1 (Sprint 1): Plugin shell + MCP server only (no hosting)
163
+ v0.2 (Sprint 2): Out-of-process hosting via shared memory
164
+ ✅ Crash-safe audio
165
+ ❌ GUI in separate window → fullscreen broken
166
+ v0.3 (Sprint 3): In-process hosting (like SnappySnap)
167
+ ✅ GUI embedded in Ableton's window
168
+ ✅ Helper tests plugin safety before loading
169
+ ❌ No crash safety during audio processBlock (accepted risk)
170
+ ```
171
+
172
+ ---
173
+
174
+ ## Revisit Candidates (Future)
175
+
176
+ | Problem | Possible Future Solution | Difficulty |
177
+ |---|---|---|
178
+ | Fullscreen floating window from separate process | Wait for Apple to provide a supported API, or use private `CGSOrderWindow` API | Hard, fragile |
179
+ | Runtime crash safety (processBlock) | Hybrid: audio in Helper, GUI in-process. Two instances synced via IPC. | Very hard |
180
+ | Blocklist is manual (per-machine) | Share blocklist via cloud / community database | Medium |
181
+ | Test-load adds 2-3 second delay first time | Cache results aggressively, pre-test in background on startup | Medium |
182
+ | Some plugins crash in createEditor() not createInstance() | Test GUI creation in Helper too (spawn with --test-gui flag) | Medium |