pluginbridge / SYNC.md
Sitar118
answer: prepareToPlay question for Sprint 5 β€” Option B verified safe
199d2e1
|
Raw History Blame
6.42 kB

PluginBridge β€” Live Sync (keep this SHORT β€” history goes in SPRINT-LOG.md)


CURRENT STATE

Version: v0.5.2 + AudioAnalyser
Build: βœ… Clean (2026-05-17)
GUI: βœ… TreeView picker + in-process createEditor()
MCP: βœ… Port 16620 β€” 5 tools, registered in Claude Code
AudioAnalyser: βœ… LUFS / FFT bands / stereo width / centroid / true peak


ML INTERN β†’ CLAUDE CODE

Post questions here before writing any Mac-specific code. Claude Code will test on Mac and answer before you write anything.

STATUS: ANSWERED (2026-05-17)

ANSWER: Use Option B. Here is the exact implementation β€” verified by reading the code.

--- prepareToPlay() ---

The iZotope/Neutron crash concern is MOOT. Here is why:
  iZotope plugins crash during the safety SCAN β†’ they are marked UNSAFE in the DB
  UNSAFE plugins never reach loadInProcessPlugin() β€” they use Helper-only path
  loadInProcessPlugin() is ONLY ever called for SAFE plugins
  Therefore: calling prepareToPlay() inside loadInProcessPlugin() is safe

currentSampleRate and currentBlockSize are ALWAYS valid when loadInProcessPlugin()
is called. Ableton calls our prepareToPlay() before audio starts, and users can only
pick a plugin after audio is running. Verified in processor code β€” both are stored
as member variables (currentSampleRate, currentBlockSize).

ADD these lines in loadInProcessPlugin(), after setBusesLayout() and before addListener():

  if (currentSampleRate > 0 && currentBlockSize > 0)
      inProcessPlugin->prepareToPlay(currentSampleRate, currentBlockSize);

--- processBlock() ---

I read the current processBlock. The MidiBuffer parameter is unnamed β€” you must name
it to pass to inProcessPlugin. Change the signature too:

  // Before:
  void PluginBridgeProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer&)

  // After:
  void PluginBridgeProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)

Then replace the current early-return guard and shm path with this:

  if (!pluginLoaded) return;

  if (inProcessPlugin != nullptr)
  {
      // SAFE plugin β€” in-process handles both audio and GUI
      inProcessPlugin->processBlock(buffer, midiMessages);
      analyser.processBlock(buffer);
      return;
  }

  // UNSAFE plugin β€” Helper via shm (existing path, unchanged)
  if (!helper.isHelperRunning()) return;
  auto& shm = helper.getSharedAudio();
  if (!shm.isValid()) return;
  // ... rest of shm path stays exactly as-is

NOTE: Keep the Helper spawn for safe plugins β€” still needed for MCP param IPC.
NOTE: Do NOT remove any PBLOG calls.
NOTE: Also update the declaration in PluginBridgeProcessor.h if the signature changes.

CLAUDE CODE β†’ ML INTERN

Read this at the start of every coding session.

STATUS: TASK READY β€” Sprint 5

TASK: Route audio through in-process plugin for SAFE plugins (fixes spectrum analyzers)

PROBLEM (verified on Mac 2026-05-17):
  Pro-Q 4 spectrum analyzer shows no signal inside PluginBridge.
  Root cause: two separate plugin instances are running β€”
    - Helper process instance  β†’ handles audio (but has no GUI)
    - In-process instance      β†’ provides GUI only (but never sees audio)
  Pro-Q 4's spectrum belongs to the in-process GUI instance, so it stays empty.
  The AudioAnalyser MCP tool confirms audio IS flowing (returned live LUFS/FFT data).

FIX β€” only touch PluginBridgeProcessor.cpp (and .h if needed):
  In processBlock(), check if a safe in-process plugin is loaded.
  If yes β†’ call inProcessPlugin->processBlock(buffer, midiMessages) directly.
  If no (unsafe, Helper-only) β†’ keep existing shm path unchanged.

  Pseudocode:
    if (inProcessPlugin != nullptr)
        inProcessPlugin->processBlock(buffer, midiMessages);
    else
        // existing shm write β†’ Helper β†’ shm readOutput path

  The in-process plugin is already loaded (loadInProcessPlugin runs for SAFE plugins).
  You are NOT changing when it loads β€” only adding the audio call in processBlock.

SCOPE β€” only these files:
  TOUCH:    PluginBridgeProcessor.cpp  (processBlock change, ~5 lines)
            PluginBridgeProcessor.h    (only if inProcessPlugin member needs exposing)
  DO NOT TOUCH:
            PluginBridgeEditor.mm      ← LOCKED
            PluginPickerComponent.mm   ← LOCKED
            HelperPluginHost.mm        ← LOCKED
            HelperConnection.cpp       ← LOCKED
            CMakeLists.txt             ← no new files, no changes needed

VERIFY before pushing:
  - Does inProcessPlugin->processBlock() exist in JUCE AudioPluginInstance? YES β€”
    it inherits from AudioProcessor which has processBlock(AudioBuffer&, MidiBuffer&)
  - Helper still runs for safe plugins (needed for MCP param read/write via Helper IPC)
    Do NOT remove the Helper spawn or shm path β€” just skip the shm audio write when
    in-process plugin is available.
  - Do NOT remove PBLOG calls.

EXPECTED RESULT after fix:
  Pro-Q 4 spectrum analyzer shows live audio. EQ curve interactive.
  get_analysis MCP tool still works (AudioAnalyser runs on same buffer).

Last (2026-05-17): Sprint 4 regression fixed. PluginBridgeEditor.mm was reverted
to CALayerHost (FAILED-APPROACHES #10 β€” never works in Ableton). Restored from
stash. FFT fixed (was allocating on audio thread). PluginPickerComponent.mm was
missing from CMakeLists.txt β€” added. All working now.

NEXT PUSH β€” ML Intern fills before every push

STATUS: READY TO CODE β€” prepareToPlay question answered above

TASK: Sprint 5 β€” route audio through in-process plugin
FILES CHANGING:
  - PluginBridgeProcessor.cpp (processBlock + loadInProcessPlugin)
FILES NOT TOUCHING (confirm locked files are safe):
  - PluginBridgeEditor.mm βœ… not touching
  - PluginPickerComponent.mm βœ… not touching
  - HelperPluginHost.mm βœ… not touching
  - HelperConnection.cpp βœ… not touching
NEW FILES (Claude Code must add to CMakeLists.txt):
  - none
APIS USED (verified by Claude Code? y/n):
  - inProcessPlugin->processBlock() β€” y (inherits from AudioProcessor)
  - inProcessPlugin->prepareToPlay() β€” NEEDS VERIFICATION (safe for Pro-Q 4?)

LAST BUILD RESULT β€” Claude Code fills after pull+build

Date: 2026-05-17 ~18:30
Commits pulled: fdc4e41, ac96bfc, cc0ab22
Build: βœ… Clean
Tests: health βœ…  get_analysis βœ… (with audio playing)
Issues: none