Skip to content

CLAP preset discovery and crash fixes

Latest

Choose a tag to compare

@midilab midilab released this 24 Nov 12:32
· 1 commit to main since this release
1bb7e49

CLAP preset discovery, editor crash fixes, host sync and loop fixes

Summary

  • New: CLAP preset discovery and clap.preset-load, so a host browser lists the
    factory and user preset banks as file locations without needing a plugin instance.
  • Fixed: the editor-lifetime crash (leaked MenuPage kept receiving parameter
    changes after the window closed and called into the freed editor).
  • Fixed: Host sync under LV2/Ardour ("plays one note"), DAW loop playback stopping
    the sequence, and the Play/Stop button staying red with no clock.
  • Improved: audio-thread safety — overdrive model loading, program changes, state
    saves and sync-mode host notifications no longer do non-realtime work in process().
  • Changed: a fresh instance starts with an empty pattern; incoming MIDI notes play
    through the engine in every sync mode, including while the sequencer runs.

Addresses the transport/playback and editor-crash reports from issue #58. Includes
PR #92 (menu-page lifetime) and PR #93 (CLAP presets).

New feature: CLAP preset discovery and preset-load

  • src/ClapPresetDiscovery.cpp (new) implements a CLAP preset-discovery factory
    through clapJuceExtensionCustomFactory. Each preset bank folder is declared as a
    file location (factory bank = factory content, other folders = user content), one
    sound pack per bank. Metadata comes from each preset .json; the factory folder is
    seeded on first use if missing, so indexing before any instance has run still finds
    the factory sounds. It reads files only, never an instance's loaded bank.
  • JC303 now implements clap_juce_audio_processor_capabilities with
    supportsPresetLoad() / presetLoadFromLocation(). Loading a bank file makes it the
    current program (so the LCD shows its name); a file outside the banks applies the
    sound only. A preset picked in the window reports preset-load loaded to the host;
    a host-initiated load does not report again.
  • Presets gained path-only helpers for discovery: presetBankDirectory(),
    seedFactoryPresetsIfMissing() and readPresetFile().
  • Editor: the timer detects a bank switch caused by a host load and refreshes the
    preset list under the window.
  • Build: CLAP_SUPPORTS_CUSTOM_FACTORY 1, a shared JC303_CLAP_ID define, the new
    source file, and a public link to clap_juce_extensions for the processor
    capabilities.

Fixes

Editor lifetime / crashes (PR #92)

  • JC303Editor owns MenuPage through std::unique_ptr and deletes it with the
    editor. Destroying the page is what unregisters its parameter listeners; previously
    the leak outlived the freed editor and the next host parameter event segfaulted in
    process().
  • MenuPage::parameterChanged no longer edits components from the audio thread. Off
    the message thread it raises an atomic flag; the editor's 30 ms timer applies the
    change via handleParameterChanges(). On the message thread it still applies
    immediately.
  • Async tuning-popup actions capture a SafePointer instead of this, and
    resized() guards against the page already being reset during teardown.

Host sync and loop playback (issue #58)

  • Host position fallback: Host sync now uses ppqPosition when present, falls back
    to timeInSamples × BPM when it is not (JUCE's LV2 wrapper never sets ppq), and
    free-runs the sequencer at the host tempo when neither exists. A ppq that has not
    moved for two buffers is treated as unusable, so a host stuck at position 0 can no
    longer replay step 0 forever. This fixes the LV2/Ardour "one note" symptom.
  • Loop wraps: the old “stop at the left locator = loop wrap” heuristic is gone. A
    host stop now gets a 250 ms grace window before the sequencer stops, so hosts that
    implement looping as stop + restart survive the wrap; held notes are released
    immediately. A genuine stop ends the sequencer after the grace period.
  • Play/Stop UX: in Host or MIDI Clock sync, a user Play/Space press stays off until
    the external clock is live (getClockAlive()), instead of turning red and playing
    nothing. A tooltip explains the external-transport behaviour.
  • Tempo bookkeeping: the host BPM is kept separately and no longer overwrites the
    internal tempo, so switching back to Internal keeps the Seq Tempo value. MIDI-clock
    bookkeeping resets when entering that mode, and startup track length comes from the
    seqLength parameter instead of a hard-coded 16.

Audio-thread safety and realtime hygiene

  • Overdrive model changes now queue the file I/O/JSON parse to
    handleAsyncUpdate(); the model swap itself stays at the existing silent fade gap.
    User model JSON is validated on the message thread before queueing, and the deferred
    swap is wrapped in try/catch with a built-in-model fallback.
  • The seqSyncMode parameter notification for an incoming MIDI Start is queued to the
    message thread instead of notifying the host from process().
  • setCurrentProgram defers its ValueTree/host work when called from a host audio
    callback (e.g. a VST3 program change), while keeping getCurrentProgram() immediate.
  • State save/restore, tuning and the mod-knob assignments now share a lock, covering
    the direct parameters.state writes and tuningState.
  • The output MidiBuffer is a pre-sized member instead of a per-block construction;
    releaseResources clears the pending queue after stopping.
  • Defensive guards: samples-per-tick floored at 1, non-finite/absurd ppq falls back to
    the internal clock, zero-channel/zero-sample blocks return early, and pattern getters
    take the existing data lock.

MIDI input and startup pattern

  • Incoming MIDI notes are forwarded to the engine in every sync mode, whether or
    not the sequencer is running. The engine is monophonic: a key takes the voice and the
    next sequence step takes it back.
  • A fresh instance starts with an empty pattern (every step a rest) instead of all
    C1 notes, so a new track is silent until notes are entered.

Smaller UI fixes

  • Knob frame indices are clamped, protecting against a zero-width slider range.
  • SeqKeyboard::showNote keeps re-asserting the held key but skips the redundant
    repaint when the note is unchanged.
  • Null-check the menu page in the editor timer and current-item callback.
  • Correct a dangling reference in preset_test (juce::Array::operator[] returns by
    value).

Behaviour changes to note in the release notes

  • Fresh instances now start silent (empty pattern). Existing projects are unaffected
    because their pattern is restored from state.
  • Incoming MIDI notes always play, including during sequencer playback.
  • In Host/MIDI Clock sync, the Play button no longer arms a silent transport; start the
    host (or send MIDI clock) first.
  • After a real host stop, the sequencer stops and the Play LED clears after up to
    250 ms (the loop-wrap grace).
  • If a host provides no usable transport position, Host sync free-runs at the host
    tempo; it keeps time but is not phase-locked to the transport.