diff --git a/.github/workflows/harmony-fast-dsp.yml b/.github/workflows/harmony-fast-dsp.yml new file mode 100644 index 000000000..cf4324086 --- /dev/null +++ b/.github/workflows/harmony-fast-dsp.yml @@ -0,0 +1,39 @@ +name: Harmony native DSP fast verification +on: + pull_request: + types: [opened, reopened, synchronize] + paths: + - 'engine/builtin_fx/Harmony*.h' + - 'tests/harmony*.cpp' + - 'CMakeLists.txt' + - '.github/workflows/harmony-fast-dsp.yml' +permissions: + contents: read +concurrency: + group: harmony-fast-${{ github.event.pull_request.number }} + cancel-in-progress: true +jobs: + harmony-cpp: + name: Native DSP compile and PCM regression (Linux, no JUCE) + runs-on: ubuntu-latest + timeout-minutes: 7 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Build and run synchronous vocal fixture + run: | + g++ -std=c++20 -O2 -Wall -Wextra tests/harmony_pitch_synchronous_test.cpp -o /tmp/arson-harmony-psola + /tmp/arson-harmony-psola + - name: Compile and run complete engine dry, pitch, stereo and graph-independent PCM fixtures + run: | + g++ -std=c++20 -O2 -Wall -Wextra tests/harmony_dsp_test.cpp -o /tmp/arson-harmony-engine + /tmp/arson-harmony-engine + - name: Verify stage separation, mono and exact PCM + run: | + g++ -std=c++20 -O2 -Wall -Wextra tests/harmony_stage_spatial_test.cpp -o /tmp/arson-harmony-spatial + /tmp/arson-harmony-spatial + - name: Compile and exercise native offline listening A/B renderer + run: | + g++ -std=c++20 -O2 -Wall -Wextra tools/harmony_offline_ab.cpp -o /tmp/arson-harmony-ab + /tmp/arson-harmony-ab --self-test diff --git a/.github/workflows/p1-windows.yml b/.github/workflows/p1-windows.yml index d3392ecd3..95c3c9580 100644 --- a/.github/workflows/p1-windows.yml +++ b/.github/workflows/p1-windows.yml @@ -129,7 +129,8 @@ jobs: node scripts/check_console_puzzle.mjs node --check web/approved-native-bridge.js node --check web/approved-native-contract.js - node --test tests/workstream_coordination_contract.test.mjs tests/ci_workflow_efficiency_test.mjs tests/chat_ci_dispatch_contract.test.mjs tests/approved_native_m2_contract.test.cjs tests/native_artifact_packaging_contract_test.mjs tests/windows_installer_contract_test.mjs tests/live_graph_contract_test.mjs + node --test --test-name-pattern="ASIO4ALL|ASIO restart" tests/mixer_io_operator_contract_test.mjs + node --test tests/workstream_coordination_contract.test.mjs tests/ci_workflow_efficiency_test.mjs tests/chat_ci_dispatch_contract.test.mjs tests/approved_native_m2_contract.test.cjs tests/native_artifact_packaging_contract_test.mjs tests/windows_installer_contract_test.mjs tests/live_graph_contract_test.mjs tests/native_caption_wire_geometry_contract.test.cjs python -m unittest discover -s tests -p approved_native_gui_bundle_test.py -v python -m unittest discover -s scripts/tests -p test_factoryfx_release_bundle.py -v - name: Compressor exact-source native CPU A/B (same runner, non-gating timing) @@ -145,6 +146,15 @@ jobs: run: | g++ -std=c++20 -O2 -DNDEBUG -fno-fast-math tests/builtin_channel_compressor_test.cpp -o "$RUNNER_TEMP/native-compressor-core-test" "$RUNNER_TEMP/native-compressor-core-test" + # Catch DSP recovery failures in seconds, before any exact-SHA MSVC + # qualification. Portable core tests intentionally exclude JUCE. + - name: Vocal Throw portable native C++ DSP / beat relock regression + if: ${{ github.event_name == 'pull_request' && startsWith(github.head_ref, 'integration/arson-vocal-throw-') }} + run: | + g++ -std=c++20 -O2 -DNDEBUG -fno-fast-math tests/native_music_tempo_test.cpp -o "$RUNNER_TEMP/native-music-tempo-test" + "$RUNNER_TEMP/native-music-tempo-test" + g++ -std=c++20 -O2 -DNDEBUG -fno-fast-math tests/builtin_vocal_throw_test.cpp -o "$RUNNER_TEMP/native-vocal-throw-test" + "$RUNNER_TEMP/native-vocal-throw-test" windows-build: name: Windows MSVC / realtime CTest needs: quick diff --git a/.github/workflows/ui-smoke.yml b/.github/workflows/ui-smoke.yml index a57b32e9e..f2b5cfe4a 100644 --- a/.github/workflows/ui-smoke.yml +++ b/.github/workflows/ui-smoke.yml @@ -109,6 +109,7 @@ jobs: node --check site/preview-v2/assets/mixer-native-compressor.js node --check site/preview-v2/assets/mixer-native-harmony.js python tests/native_harmony_assembly_test.py + node --check site/preview-v2/assets/mixer-native-vocal-throw.js python tests/native_peq_assembly_test.py python tests/approved_operator_ux_smoke.py python scripts/build_ui_css.py --check @@ -128,6 +129,34 @@ jobs: - name: Block incomplete product release only when preparing product review if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft && startsWith(github.head_ref, 'integration/product-') }} run: node scripts/check_console_puzzle.mjs --release + vocal-throw-preview: + name: Vocal Throw native editor desktop/mobile Chromium FAT + needs: quick + # Run dedicated Vocal Throw visual validation in the reconciled native + # engine branch too; generic /preview/ smoke does not call this fixture. + if: ${{ github.event_name == 'pull_request' && (startsWith(github.head_ref, 'feature/arson-vocal-throw-') || startsWith(github.head_ref, 'integration/arson-vocal-throw-') || github.head_ref == 'integration/asio4all-harmony-d4-compat-20261109') }} + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install Chromium for targeted Vocal Throw UI + run: | + python -m pip install playwright + python -m playwright install --with-deps chromium + - name: Check exact mixer picker, native ACK and editor in desktop/mobile + run: python tests/approved_native_vocal_throw_smoke.py + - name: Keep compact editor screenshot evidence + if: ${{ always() }} + uses: actions/upload-artifact@v4 + with: + name: ArSonMix-Vocal-Throw-Desktop-Mobile-${{ github.run_id }} + path: arsonmix-vocal-throw-*.png + if-no-files-found: ignore + retention-days: 7 + operator-ux-fat: name: Operator UX real Chromium / native-assembled GUI (5 viewports) needs: quick @@ -268,6 +297,8 @@ jobs: run: python tests/approved_native_harmony_smoke.py - name: Cold start first WIRE and original-channel VST3 picker editor run: python tests/approved_native_cold_start_smoke.py + - name: Native desktop titlebar toolbar measured in Chromium at four viewport widths + run: python tests/native_header_toolbar_chromium_smoke.py - name: Native WIRE gain and OUT share accepted PCM identity (real Chromium) run: python tests/approved_native_wire_gain_smoke.py - name: Stage D one runtime CSSOM and actual stylesheet network count @@ -278,6 +309,8 @@ jobs: run: python tests/pages_wire_first_canonical_main_smoke.py - name: Verify V49 direct WIRE, gain wheel, connected status, replug and scoped undo run: python tests/pages_wire_v49_direct_controls_smoke.py + - name: Desktop titlebar WIRE geometry across resize and cancelled pointer capture + run: python tests/desktop_wire_resize_chromium_smoke.py - name: Verify V53 handle-free FX row drag, keyboard and rack reorder run: python tests/pages_fx_rail_v53_smoke.py - name: Qualify public /preview/ floating Channel Editor with zero mixer reflow (five real Chromium viewports) @@ -479,7 +512,7 @@ jobs: done git diff --exit-code -- site/preview-v2/index.html site/preview-v2/assets/mixer-chrome-material.css site/preview-v2/assets/mixer-plugin-browser.css site/preview-v2/assets/mixer-pan-controls.css site/preview-v2/assets/mixer-fader-assembly.css site/preview-v2/assets/mixer-meter-display.css site/preview-v2/assets/mixer-utility-controls.css - name: Verify V28 exact approved /preview/ source and interactive browser parity - if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && (startsWith(github.head_ref, 'css/v28-') || startsWith(github.head_ref, 'integration/product-'))) }} + if: ${{ (github.event_name == 'workflow_dispatch' && inputs.historical_css == true) || (github.event_name == 'pull_request' && (startsWith(github.head_ref, 'css/v28-') || startsWith(github.head_ref, 'integration/product-'))) }} run: python tests/pages_css_architecture_v28_smoke.py - name: Verify embedded Inter font and contextual V7 micro-controls if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && startsWith(github.head_ref, 'integration/product-')) }} diff --git a/CMakeLists.txt b/CMakeLists.txt index eb89c69c9..7d826bbb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,13 +78,22 @@ target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h engine/bu if(MSVC) target_compile_options(ARMixConsole PRIVATE "$<$:/utf-8>") endif() +# Stamp the build source in Copy Audio Report, including Windows field trials. +execute_process(COMMAND git rev-parse --verify HEAD + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE ARMIX_BUILD_SOURCE_SHA OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE ARMIX_BUILD_SOURCE_STATUS ERROR_QUIET) +if(NOT ARMIX_BUILD_SOURCE_STATUS EQUAL 0 OR NOT ARMIX_BUILD_SOURCE_SHA MATCHES "^[0-9a-f]+$") + set(ARMIX_BUILD_SOURCE_SHA "unavailable") +endif() # One JUCE mixer/PCM host on all three desktops. Device backends are OS owned. target_compile_definitions(ARMixConsole PRIVATE JUCE_WEB_BROWSER=1 JUCE_USE_CURL=0 JUCE_PLUGINHOST_VST3=1 JUCE_APPLICATION_NAME_STRING="AR MIX Studio" - JUCE_APPLICATION_VERSION_STRING="0.5.0-p2") + JUCE_APPLICATION_VERSION_STRING="0.5.0-p2" + ARMIX_BUILD_SOURCE_SHA="${ARMIX_BUILD_SOURCE_SHA}") if(WIN32) # Windows retains its proven ASIO-first / WASAPI / static WebView2 distribution. # Never link Windows loader or sound APIs into macOS/Linux builds. @@ -115,9 +124,22 @@ if(BUILD_TESTING) add_executable(ARMixFxStructuralHandoffTests tests/live_fx_structural_handoff_test.cpp) target_compile_features(ARMixFxStructuralHandoffTests PRIVATE cxx_std_20) add_test(NAME R0BStructuralFxAckAndControlThreadRetirement COMMAND ARMixFxStructuralHandoffTests) + add_executable(ARMixHarmonyOfflineAb tools/harmony_offline_ab.cpp) + target_compile_features(ARMixHarmonyOfflineAb PRIVATE cxx_std_20) + add_test(NAME NativeHarmonyOfflineDryAndABRenderHarness COMMAND ARMixHarmonyOfflineAb --self-test) + add_executable(ARMixHarmonyPitchSyncTests tests/harmony_pitch_synchronous_test.cpp) + target_compile_features(ARMixHarmonyPitchSyncTests PRIVATE cxx_std_20) + add_test(NAME NativeHarmonyPitchSynchronousFormantCandidateAndBlockParity COMMAND ARMixHarmonyPitchSyncTests) + add_executable(ARMixHarmonySpatialTests tests/harmony_stage_spatial_test.cpp) + target_compile_features(ARMixHarmonySpatialTests PRIVATE cxx_std_20) + add_test(NAME NativeHarmonyBackingStageSpatialDepthAndMonoPDC COMMAND ARMixHarmonySpatialTests) add_executable(ARMixHarmonyDspTests tests/harmony_dsp_test.cpp) target_compile_features(ARMixHarmonyDspTests PRIVATE cxx_std_20) add_test(NAME NativeHarmonyMultivoicePitchAndRealtimeFinitePCM COMMAND ARMixHarmonyDspTests) + # Non-gating synthetic engine-only CPU profile (not ASIO certification). + add_executable(ARMixHarmonyCpuProfileTests tests/harmony_cpu_profile_test.cpp) + target_compile_features(ARMixHarmonyCpuProfileTests PRIVATE cxx_std_20) + add_test(NAME NativeHarmonySyntheticCallbackCpuProfile COMMAND ARMixHarmonyCpuProfileTests) add_executable(ARMixHarmonyMusicGuideTests tests/harmony_music_key_test.cpp) target_compile_features(ARMixHarmonyMusicGuideTests PRIVATE cxx_std_20) add_test(NAME NativeHarmonyCrossChannelMusicKeyAndManualFallback COMMAND ARMixHarmonyMusicGuideTests) @@ -126,10 +148,18 @@ if(BUILD_TESTING) target_link_libraries(ARMixHarmonyChannelPcmTests PRIVATE juce::juce_audio_processors juce::juce_recommended_config_flags) target_compile_features(ARMixHarmonyChannelPcmTests PRIVATE cxx_std_20) add_test(NAME NativeHarmonyMusicFromOtherChannelIdAndStateMigration COMMAND ARMixHarmonyChannelPcmTests) + # Explicit FX lease + ChannelId PCM regression: continuous Harmony DSP on + # disabled insert/rack, exact dry PDC and state-identical wet reactivation. + juce_add_console_app(ARMixHarmonyBypassPcmTests PRODUCT_NAME "ArSonMix Harmony Clickless Bypass PCM") + target_sources(ARMixHarmonyBypassPcmTests PRIVATE tests/harmony_bypass_reliability_test.cpp) + target_link_libraries(ARMixHarmonyBypassPcmTests PRIVATE + juce::juce_audio_processors juce::juce_recommended_config_flags) + target_compile_features(ARMixHarmonyBypassPcmTests PRIVATE cxx_std_20) + add_test(NAME NativeHarmonyWarmBypassRackSlotAndLatencyParity COMMAND ARMixHarmonyBypassPcmTests) add_test(NAME ApprovedNativeHarmonyEditorAckAndSingleGui COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_harmony_assembly_test.py") add_executable(ARMixMixerRoutingTests tests/mixer_routing_plan_test.cpp) target_compile_features(ARMixMixerRoutingTests PRIVATE cxx_std_20) - add_dependencies(ARMixMixerRoutingTests ARMixHarmonyDspTests ARMixHarmonyMusicGuideTests ARMixHarmonyChannelPcmTests) + add_dependencies(ARMixMixerRoutingTests ARMixHarmonyDspTests ARMixHarmonyMusicGuideTests ARMixHarmonyChannelPcmTests ARMixHarmonyBypassPcmTests ARMixHarmonyCpuProfileTests) add_test(NAME TenStripStaticRoutingAndMaster COMMAND ARMixMixerRoutingTests) # M3D atomic native Session: the accepted Console roster cannot advance # without a successful epoch/revision-gated PCM publication. @@ -272,6 +302,10 @@ if(BUILD_TESTING) add_executable(ARMixStreamWatchdogTests tests/independent_stream_watchdog_test.cpp) target_compile_features(ARMixStreamWatchdogTests PRIVATE cxx_std_20) add_test(NAME IndependentStreamSilenceRecovery COMMAND ARMixStreamWatchdogTests) + add_executable(ARMixAsioRestartGateTests tests/asio_restart_recovery_gate_test.cpp + engine/device/AsioRestartRecoveryGate.h) + target_compile_features(ARMixAsioRestartGateTests PRIVATE cxx_std_20) + add_test(NAME Asio4AllWdmSettleBoundedDriverTransactionsAndDeferredRebind COMMAND ARMixAsioRestartGateTests) add_executable(ARMixRecoveryTests tests/direct_restore_backoff_test.cpp) target_compile_features(ARMixRecoveryTests PRIVATE cxx_std_20) add_test(NAME BoundedDirectDeviceRecovery COMMAND ARMixRecoveryTests) @@ -433,6 +467,30 @@ if(BUILD_TESTING) COMMAND ARMixNativeCompressorLifecycleTests) add_dependencies(ARMixMixerRoutingTests ARMixNativeCompressorLifecycleTests) + add_executable(ARMixNativeVocalThrowTests tests/builtin_vocal_throw_test.cpp + engine/builtin_fx/VocalThrow.h) + target_compile_features(ARMixNativeVocalThrowTests PRIVATE cxx_std_20) + add_test(NAME NativeVocalThrowPhraseCaptureManualAutoAndNoHeap COMMAND ARMixNativeVocalThrowTests) + add_dependencies(ARMixMixerRoutingTests ARMixNativeVocalThrowTests) + # A stopped ASIO callback must not execute old, UI-rejected THROW cues + # on resume. Exercise the real JUCE processor and its SPSC completion. + juce_add_console_app(ARMixVocalThrowCancelTests PRODUCT_NAME + "ArSonMix Vocal Throw Expired Cue Safety Tests") + target_sources(ARMixVocalThrowCancelTests PRIVATE + tests/native_vocal_throw_cancel_test.cpp + engine/builtin_fx/VocalThrowProcessor.h) + target_link_libraries(ARMixVocalThrowCancelTests PRIVATE + juce::juce_audio_processors juce::juce_recommended_config_flags) + target_compile_features(ARMixVocalThrowCancelTests PRIVATE cxx_std_20) + add_test(NAME NativeVocalThrowExpiredCueCancellation COMMAND ARMixVocalThrowCancelTests) + add_dependencies(ARMixMixerRoutingTests ARMixVocalThrowCancelTests) + add_executable(ARMixNativeMusicTempoTests tests/native_music_tempo_test.cpp + engine/core/NativeMusicTempoMonitor.h) + target_compile_features(ARMixNativeMusicTempoTests PRIVATE cxx_std_20) + add_test(NAME NativeMusicTempoSourceOnsetsAndFallback COMMAND ARMixNativeMusicTempoTests) + add_dependencies(ARMixMixerRoutingTests ARMixNativeMusicTempoTests) + + add_executable(ARMixNativeMasterLoudnessTests tests/native_master_loudness_test.cpp engine/dsp/NativeMasterLoudness.h) target_compile_features(ARMixNativeMasterLoudnessTests PRIVATE cxx_std_20) add_test(NAME P1KMeasuredNativeBS1770StereoAnd4xTruePeak COMMAND ARMixNativeMasterLoudnessTests) diff --git a/docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md b/docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md new file mode 100644 index 000000000..6b1d7fe0c --- /dev/null +++ b/docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md @@ -0,0 +1,133 @@ +# ARD — ArSon Harmony FX Backing-Only Spatial Depth Engine (v1.0) +**Date:** 2026-11-09 · **Status:** Proposed architecture with staged implementation checks +**Scope:** Native built-in Harmony on PR #487; companion [PRD](PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md) and [Natural Ensemble](ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md). + +## Evidence-led acoustic model +Human auditory distance relies on **direct/reverberant energy ratio**, overall source level, spectral balance and interaural cues. Increasing reverberant ratio commonly signals greater distance; absolute physical distance cannot be inferred from a simple Space knob. First-arriving direct sound determines much of localization (precedence); a small number of obvious repeats can produce slap/comb effects rather than a coherent room. More high-frequency absorption is a mixing cue, but **air absorption over just a few metres does not justify extreme LPF**. For a live singer, masking and consonant smearing are unacceptable. + +- Bronkhorst & Houtgast, *Nature* 1999, distance versus DRR: https://www.nature.com/articles/17374 +- Zahorik review, distance, intensity, DRR, spectral and interaural cues: https://pmc.ncbi.nlm.nih.gov/articles/PMC4744263/ +- Litovsky et al. review of the precedence effect: https://pmc.ncbi.nlm.nih.gov/articles/PMC4310855/ +- JASA 2025 frontal distance study (DRR or spectral centroid best single cue): https://pubmed.ncbi.nlm.nih.gov/40928551/ +- Sound on Sound depth mixing (level/EQ/diffuse reverb versus clarity): https://www.soundonsound.com/techniques/creating-sense-depth-your-mix +- iZotope mix depth: https://www.izotope.com/community/blog/what-is-mix-depth-how-to-create-front-back-space +- FDN theory / realtime late room: https://artificial-audio.github.io/portfolio/fdn/ + +## Before: audited exact C++ issue +`engine/builtin_fx/HarmonyDsp.h::process` mixes lead with +`(1.f - wet_*0.65f*voicedGain_)` despite the lead being dry; at Wet=.45 / voicedGain=1 this is about -3 dB lead. This is **gain duck**, not proof of phase cancellation. Current `HarmonyEnsembleSpace.h` adds one early opposite-side tap/voice but has **no diffuse late field**. At most it generates scattered echoes and pan; it does not control DRR as an acoustic scene. + +## One-source, one-room block graph +```text +Mono mic PCM + accepted ChannelId / native graph + | + +--> phase-safe analysis / voice targets --> pitch shifters (2-5) + | | + | +--> independent singer onset / timbre / pitch modulation + | | + | +--> short direct backing L/R (Space-dependent attenuation) + | +--> per-singer fixed-tap filtered early reflections + | +--> ONE shared small stereo diffuse late field [FDN] + | (backing send ONLY; fixed delay, stable feedback) + | + +--> exact delayed native L/R lead --> optional explicitly enabled Pitch Tune + | | + +-----------------------------> sum w backing L/R + -> explicit Gain -> existing PCM bus +``` +Only existing `Settings::space`, wet, color and voices. No new scene schema, plugin routing, hidden monitor step, GUI Lab, or second ownership. `Space=0` disables audible room, not the valid PCM path. Diffuse field is never fed with lead. + +## Time/frequency strategy +- **Front:** lead unchanged by wet, stereo and sample latency untouched. Pitch Tune explicitly replaces/corrects when user enables it; never implied by Wet. +- **Direct backup:** keep existing individually phase-offset 5–17 ms arrival, deterministic cent modulation and prepared pan L/C/R. At increasing Space, reduce direct backing gain mildly (candidate 0dB to -4dB) so backing remains intelligible but moves behind. +- **Backstage spectral contour:** one sample-rate-normalized low-pass in each voice with a smooth dry/filtered crossfade, evaluated on backing only. Candidate corner around 3–6 kHz and partial dry retention; do not physically claim air propagation at 3 m. +- **Early field:** use existing per-voice 12–20 ms fixed taps, with mild high-frequency damping and side distribution; no modulation of the delay tap by Space (avoids Doppler/comb chirp). +- **Late field:** one shared bounded 4-branch stereo feedback delay network (FDN), fixed integer delay lines with different non-harmonic lengths and a normalized Hadamard feedback transform. Feedback damping and per-line gain computed in non-RT `prepare(rate)` to target about 0.45–0.7 s decay. Conservative energy normalization, filtered output, no runaway or metallic tonal build-up. First prototype is room **ambience**, not cathedral/hall reverb. +- **Control:** `space` interpolates smoothly across width, direct gain, backing brightness, early/late send and return. `wet` scales backing energy only; disabled or Wet=0 must not leak old tail. All coefficients finite and clamped. No audio-owner reallocation or blocking. + +## Proposed bounded C++ data ownership +- `HarmonyEnsembleSpace.h`: per-voice onset, identity modulation and 4096-sample early reflection rings; optional per-voice damping state. Precompute sample-rate coefficients on CONTROL `prepare(rate)`; callback only adds/multiplies. +- `HarmonyDepthRoom.h`: 4 shared, 8192-sample float delay rings (128 KiB); 4 damping states; 4 feedback gains; 1 monotonic write index. Delays up to 41 ms at 192k remain in bounds. A 4x4 orthonormal Hadamard transformation (scale 0.5) ensures controlled feedback energy. No `new`, FFT, `pow`, `sin`, `log`, device calls or synchronization in `processSample`. +- `HarmonyDsp.h`: keep lead path independent of `wet`; accumulate backing direct and early/late sends by voice, shared stereo room returns only in wet branch. Use existing 5-ms control smoothing and fixed instance state. +- Single publisher and callback: preserve bridge ACK/readback/graph lease, `ChannelHarmonyProcessor`, SPSC packets and `latencySamples()`. Declared PDC remains 1536 samples @48k until evidence warrants an independent P0 latency redesign. + +## Risks, failure behavior and test design +| Risk | Defensive behavior / evidence | +|---|---| +| Room self-oscillation / metallic flutter | Precomputed feedback magnitude <1 and damping, orthogonal matrix; impulse decay < target floor by ~2 seconds; 32/44.1/48/96/192k CTest and extended silence | +| Mono cancellation / comb | Positive-polarity forward dry, no artificial anti-phase width; L+R output energy with 2/3/5 voices >0 and lead parity; evaluate ER frequency response with real voice | +| Space automation chirping | Interpolate gains/filter coefficients, **not** delay lengths; test 0->1->0 at arbitrary 64-sample boundaries, output finite without transient spike | +| Lead duck | Unit check dry equals original delayed PCM at wet=0,45,100 and multiple Space; actual lead equation cannot reference Wet | +| Reverb masks lyrics | Limit room gain, high-pass/LP spectrally soften only wet room; compare consonant intelligibility, DRR as measured against current impl | +| Real singer still robot | Keep depth independent; this architecture doesn't solve formant/grain synthesis; P0 resynthesis follows separate proof | +| Device restart / session | `prepare(rate)` resets room/filters and restarts deterministic state, no stale room tail from previous device; maintain GUI native ACK identity | + +## No shortcut quality declaration +Do not equate "FDN compiled" with “feels like three people metres away.” First require baseline/updated dry and backing stems rendered at level parity, mono/stereo blind A/B for perceived front-back ranking, listening through nearfields/headphones/mono laptop speaker, and actual ASIO 48/96 kHz 64/128/256 buffers with full mixer FX rack and CPU p95/p99/XRUN data. The desired response is **distant but distinct, not washed out**. Exact room dimensions and HRTF positioning are not implemented and must not be shown as facts in GUI. + +## 2026-11-09 implementation checkpoint D0–D1 (unqualified acoustically) + +D0 implemented: `HarmonyDsp::leadPath` no longer references Wet; Pitch Tune still explicitly blends corrected lead. Direct backing attenuation is separate from dry lead. D1 implemented: `EnsembleSpace::shadeBacking` adds a rate-correct gentle LP shading to **backing only**; `BackingDepthRoom` adds a 4-branch fixed-delay, precomputed 0.55 s nominal FDN with frequency damping and non-anti-phase stereo outputs. Space smooths original pan, backing attenuation, early-field gain, late send and return. No new controls/schema or device calls; no extra plugin PDC. + +Added CTest gates for 32/44.1/48/96/192 kHz impulse/tail feedback stability, reset/silence/mono compatibility, backing HF-shading boundedness and explicit pitch-tune lead preservation. This is an acoustically *unqualified* room candidate until real listening A/B and physical ASIO load. + +## 2026-11-09 D2 — backing-stage acoustic depth candidate + +Field feedback: the pitch-synchronous singer is now acceptably natural but backing appears too close to the original singer. Keep original lead and pitch resynthesis unchanged. New `HarmonyStageSpatial.h` introduces a fixed 0.22ms far-ear precedence cue, a **second per-voice early reflection** at 27–38ms (first remains 12–20ms), and stronger direct/reverberant separation. Existing ONE shared backing-only 4x4 FDN remains unchanged. + +With Space `s` in [0,1], direct gain is `1-0.62s`, early send `0.49s`, late return `1.08s`. Positive-polarity stereo image; no exact HRTF or claimed physical metres, no extra audio latency or device, no delay-time modulation, no lead processing changes. An offline-only switch retains old spatial routing to compare against the current pitch engine. The one-knob GUI remains unchanged. + +Test `NativeHarmonyBackingStageSpatialDepthAndMonoPDC` validates 32–192k, monotonic early/direct energy, three/five singer first-arrival and mono energy, 64/257 callback parity, declared 1536-sample PDC and Wet0 lead invariance. Aural user validation and physical ASIO xrun still required. + +## 2026-11-09 P1 spatial refinement: frequency-dependent far-ear cue + +After the stage placement milestone, the fixed 0.22ms far-ear precedence cue used the *same full-band vocal* for near and far ears, so lateral placement could still resemble ordinary pan/doubling rather than a believable backing position. The stage now precomputes one gentle 4.1kHz one-pole for the **contralateral-only** short-delay ring. The near-ear direct path, lead PCM, source pitch-synchronous resynthesis, fixed sample PDC, per-singer reflection timing, shared room, and existing Space control are unchanged. No speculative physical 3D/HRTF distance claims. + +At Space 0 the far-ear blend is zero; at higher Space, far ear combines a proportion of the original with a short delayed, spectrally softened replica. Fixed delay and preprepared coefficient prevent audio-control chirps. This is a small independent cue, not new unbounded spectral processing. Synthetic tests compare 350Hz / 8kHz far-to-near energy at 48/96/192k, preserve full-band Space0 parity, plus existing per-singer reflection/DRR, dry polarity, mono and callback-block parity. Real singer/headphones/mono A/B still gate acceptance. + +### 2026-11-09 center backing separation + +The fixed short far-ear shadow cue now combines with a modest, **center-only backing direct** recess. With three singers the middle backing singer can otherwise overlap the dry center-lead image. At Space 1 its center direct level is 0.83 of its original while its reflected and one-room-send components remain unchanged. The effect tapers with physical stage direction and Space (fully neutral at Space 0), preserves side singer direct energy and never changes dry lead, pitch/formant engine or published PDC. Impulse regressions validate actual center direct/room ratio, no full muting or polarity tricks. Subjective quality is still an ear-test. + + +## 2026-11-09 D3 — conservatively focused musical backing room + +`HarmonyRoomFocus.h` is a shared 170Hz high-pass on the BACKING ROOM SEND +only, and a 12ms attack / 240ms release lead-envelope follower that +modulates only the late room return (max 22% attenuation at Space=1). +Its input is the original latency-aligned dry lead, not a second channel. +During sustained lead, late diffusion is gently eased back; between +phrases the late field blooms again. Direct singers, all first reflections, +lead dry PCM and pitch/formant candidate are unaffected. No FFT, lookahead, +extra delay/PDC, GUI knob, saved schema change or realtime allocation. + +Native regression measures the 75/600Hz frequency discrimination at +32/44.1/48/96/192k, bounded attack/release, Space0 unity and restart +clearing. Offline A/B adds `10_room_focus_off_space_060.wav` and +`11_room_focus_off_backing_only.wav` with the SAME stage and pitch +to isolate the room change. Synthetic tests are not a real singer or +physical ASIO qualification. + + +## 2026-11-09 D4 field fix — harmony wet presence and knob optical spacing + +A recorded owner listening session found pitch quality noticeably human, +but backing was too thin even with 4 voices, 100% Wet and Space 60%. +`HarmonyDsp` previously applied `0.65*Wet/sqrt(voices)`, followed by +the existing Space direct attenuation. The new **control-thread** voice +law `Wet*(0.77+0.38*Wet)/sqrt(voices)` raises wet backing roughly ++3.2 dB at Wet45% and +4.95 dB at Wet100%, without ducking the original +dry lead or moving spatial placements. Wet0 is exactly zero; 2–5 voices +retain sqrt-count normalization. This is not a master limiter, and no +physical hardware headroom or singing quality is implied by the formula. +An offline-only before-process() switch produces the prior presence law +for matched-A/B WAV `12_presence_old_space_060.wav` and +`13_presence_old_backing_only.wav`. Synthetic self-test asserts backing +stem RMS increases in the expected bounded range and dry lead parity. + +The screenshot showed COLOR/SPACE/WET/GAIN overlapping the glowing ring: +the pseudo ring extends 11px below the 68/59px knob but the old label +was separated by only a 1px gap. Add a compact 12px top margin and 11px +line height to the caption; preserve all editor dimensions, dial size, +pointer and parameter meanings. Chromium geometry checks real caption +clearance and value noncollision across existing test viewports. diff --git a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md index 2a205e6fb..9ade422a9 100644 --- a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md +++ b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md @@ -49,3 +49,67 @@ A 1536-sample lookback at 48 kHz is **32 ms DSP delay**, before device input + o - Rubber Band v4 technical docs expose formant options and exact latency API, but licensing, ASIO callback suitability and measured overhead must be independently assessed; do not add by assumption. **Status:** engineering candidate only; PR stays Draft pending exact-HEAD qualification and physical vocal FAT. + +## 2026-11-09 follow-up — pitch CPU and measurable callback budget (post-merge) + +- Roll the shifted window's energy from one candidate lag to the next. Keep the existing dot-product, confidence threshold, quantizer and FX/PDC/GUI contracts. Each adjacent lag changes by one outgoing + one incoming squared sample instead of recomputing 160 squares. Only floating-point rounding may differ. +- Extend deterministic C++ PCM regressions to a multi-harmonic A2 sample with 64/128/257-frame chunks. Existing E2/C6, dry-latency alignment, automation and music-guide tests remain in force. +- Add `NativeHarmonySyntheticCallbackCpuProfile` to CTest. Synthetic engine-only p50/p95/p99/max data covers 48 kHz (64/128/256 samples), 96 kHz (128 samples), with 2/5 voices. Timing is recorded only outside engine->process(), but Windows runner contention makes absolute timing unsuitable for a CI hard gate. +- No quantitative speedup claim without controlled before/after on one machine. No ASIO driver, JUCE graph, real-world multichannel CPU, formant quality or ear monitoring is measured by this synthetic profile. Physical singer FAT remains release blocking. + +## 2026-11-09 P0 bounded realtime engine milestone + +**Release scope**: Stable 48-kHz 1536-sample (32ms) DSP lookback and exact native PDC remain unchanged until recorded singing/listening establishes a safe lower-latency algorithm. No experimental formant shifter or hidden direct monitor path is enabled merely to advertise latency gains. + +- Move pitch autocorrelation off one large sample spike: snapshot a fixed decimated window every ~6.7ms, process at most 32 candidate lags per sample-scheduled slice, finish before the next analysis window. All snapshots and per-instance state are fixed-size, and graph/audio ownership is unchanged. This reduces the worst-case single-sample analysis work even at ASIO 64. +- Keep the sliding lagged energy improvement from previous #485, preserving confidence thresholds, song key readback, five-voice controls and existing tests. +- Recompute voiced gate and ratio smoothing coefficients on `prepare(rate)` only so physical time constants remain the same across 32–192kHz device reopen; 48kHz response stays calibrated to the earlier engine. +- Enforce deterministic output for identical stereo singing PCM across 64/127/256 sample callback partitioning and instrument the maximum completed pitch-lag work per sample. Retain all prior E2–C6, cross-channel Music Key and dry 192k latency tests. +- The synthetic engine-only CPU profile is diagnostic, not a hardware underrun oracle. Next **non-automatable** P0 gate: independent actual Windows ASIO interface, human singing + recorded dry/wet FFT/formant comparison, 48/96k with 64/128/256 periods and 2–5 voices for 30 minutes; callback p95/p99/max, driver XRUNs and measured loopback round trip must be documented. +- Formant-preserving pitch synchronous synthesis (TD-PSOLA / equivalent) remains a separate replaceable shifter milestone: it must be verified against consonants, onset/off pitch, male/female vowels and CPU/latency tradeoffs before becoming audible default. Never claim today's granular shifter preserves formants. + +Project status: P0 **realtime boundedness implementation** awaiting exact-HEAD Windows CTest and singer FAT; not a final professional-quality or latency qualification. + +## 2026-11-09 P1 — stereo phase-resilient Harmony analysis + +Both `HarmonyDsp` vocal analysis/grain source and the cross-ChannelId `MusicKeyDetector` used `0.5*(L+R)`. Valid `L=-R` PCM from an extreme stereo widener or polarity-inverting source disappeared completely from both. The read-only music source remained audible elsewhere but Harmony incorrectly fell back to Manual. + +`StereoPhaseSafeFold.h` now provides a **per-instance, callback-owned, constant-work** fold with precomputed 20ms polarity evidence and 15ms smoothed recovery, strict -0.78 engage / -0.55 release hysteresis, silence release, and stereo analysis-only polarity repair. Ordinary coherent stereo keeps the existing sum. Neither dry stereo, audio routing, FX rack, SPSC schema, 2–5 voices, output device, declared latency nor GUI changes. No heap, locks, timers or per-sample trigonometry. + +PCM regressions: anti-phase singer A3 and nonzero five-voice harmony at 48/96k; anti-phase music C major at 48/96k, silence/Manual fallback; real native other-ChannelId antiphase A-minor guide with read-only source samples, plus preexisting in-phase, rekey, block parity, PDC and state migration. This only prevents destructive analysis cancellation, it is *not* formant preservation or ASIO/ear latency certification. Physical singer FAT remains open. + +## 2026-11-09 P0/P1/P2 tone and CPU milestone — exact speaker-independent tests + +**P0 boundedness**: Preserve exactly the native two-grain shifter's 1536 samples of 48k lookback and its 32-lag-per-slice pitch work. Do not promise latency reduction, physical ASIO stability or true formant preservation without human singing and measured loopback; this commit instead ensures that deterministic pitch ratios and timbral control stay safe across devices. + +**P1 tone parity**: Extract `RateStableColor` (257 precomputed floats/instance). The original 48k one-pole coefficient `0.07 + color*0.77` is retained within float precision; at 32, 44.1, 96, 192k convert that same attenuation to its equivalent physical time. The smoothing envelope remains separate. Lookup/interpolation occurs only once per active processing sample and is shared across all active harmonies plus lead correction. Control-thread `prepare()` alone uses `std::pow`. Tests compare 10ms decay consistency across all five device rates and seven Color settings. + +**P2 realtime hot path**: Five extra `pow(2, semitones/12)` calls per pitch detection hop were replaced with a 49-entry immutable, off-callback prepared interval ratio table and one reference ratio exponent. Precomputed semitone intervals are combined by multiplication, with output clamp retained. Exhaustive deterministic test covers 12 keys, both scales, 71 degrees, five detunes and all five voice intervals (approximately 42,600 ratios). Maximum deviation from the former formula is below `1e-6` absolute in tests. No new state packets, allocations, locks, threads, routed audio, FX slot changes or GUI code. + +**Release gate**: This is source-level algorithmic hardening; the CI synthetic CPU profile is diagnostic only. Additional real voice/female/male formant comparisons and 64/128/256 ASIO buffer loopback/driver XRUN evidence remain mandatory. + +## 2026-11-09 P0 bounded-pitch work and hostile PCM follow-up + +**Actual source-level issue:** 32 candidate lags × 160 dot-product taps were still evaluated in a single callback sample, causing an avoidable periodic CPU spike even when the average synthetic CPU looked acceptable. Reducing the per-sample slice width without shortening cadence would cause silent abandoned pitch windows. This checkpoint changes BOTH: `maxPitchLagsPerSlice=8` and `pitchSliceEvery_=detectEvery_/32`. Total candidate-lag dot products and 48k grain/PCM/PDC are unchanged. Every snapshot finishes with headroom before the next analysis hop on all 32–192k supported sample rates, with separate completed/abandoned window counters for test-only diagnostics. + +**P0 hostile PCM fail-closed:** Native input guards now clip finite >4.0f amplitude before the internal dry/grain histories (the engine already clamps all output to +/-4.0f); NaN and infinity still become silence. `StereoPhaseSafeFold` returns the bounded fold it actually uses for correlation, instead of computing an unbounded sum after clipping evidence. This prevents a host supplying finite near-FLT_MAX PCM from poisoning Music Guide or vocal analysis with infinity. Ordinary valid PCM [-4,+4], channel polarity, dry PDC, Music Track read-only routing and GUI are untouched. + +**Qualification:** 5 sample rates (32/44.1/48/96/192k), 3 callback partitions (64/127/256 frames), deterministic A3 voiced note, complete correlation windows/no abandoned windows and <=8 candidate lags per slice; real 2/5-voice hostile IEEE PCM and direct near-FLT_MAX stereo guide. The existing 48k blockwise PCM parity, low bass/high soprano, 48/192k stereo dry and 1536-sample PDC regression remain active. Hardware ASIO and spectral/formant gate remain unverified; no claim of a completed P0 low-latency/formant engine. + +## 2026-11-09 P0 Harmony native-key and singer telemetry UX + +The field failure had two independent operator problems: (1) stale modeless-editor +control lease on graph/device change was resolved by accepted-graph auto-rebind, +and (2) native pitch `observedNote` was in the authoritative C++ snapshot but +never visible to the operator in Manual Key, which only polled Music mode. +The editor now uses the EXISTING 12Hz console tick for <=2Hz readback in +both modes, showing `TRACKING A3`/ `WAITING VOICE`/ `DSP SYNCING` +from the true PCM-owner `observedNote`, never inferred from the UI key. +Key gestures outline the requested letter immediately but the accepted +key/LCD still changes ONLY after the native DSP ACK and matching readback. +The status reports `KEY C#m - AWAITING DSP ACK` while pending. One +small footer string and a one-pixel indicator; no graph routing, FX +parameter schema, audio callback work or polling timer added. Real Chromium +test additionally checks manual-mode liveness, immediate gesture indicator +and its disappearance after accepted readback. Vocal formant/spatial realism +remains unproven and separate from this GUI feedback milestone. diff --git a/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md b/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md new file mode 100644 index 000000000..aa64cb791 --- /dev/null +++ b/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md @@ -0,0 +1,95 @@ +# ArSon Harmony — Natural Vocal Ensemble DSP Architecture & Evidence +2026-11-09 | source branch PR #487 | Design audit, **NOT** acoustic certification + +## Product acceptance + +A user singing one live monophonic lead must hear **one intelligible lead in front and independently perceived backing singers**, e.g. three voices behind, moderately left, near-center and moderately right. The BACKINGS must vary in timing, intonation, timbre and room position without creating robotic timbre, metallic grain edges, clicks, doubling of consonant transients, excess latency or ASIO XRUN. Key buttons should respond immediately with *pending* feedback, then turn *accepted* only on true native DSP ACK/readback. GUI should display an audio-owned tracking note, not pretend that pressing Key triggers sound or proves PCM processing. + +## Source-code diagnosis (before redesign) + +Current `engine/builtin_fx/HarmonyDsp.h` uses one phase-safe mono analysis/grain source for all harmony voices, two overlapping 16ms grains per shifter, identical initial grain phase for all voices, note-locked fixed diatonic offsets `{+2,+4,-2,+6,-4}` scale degrees, the **same one-pole Color** coefficient for all voices, equal-power stereo pan, and shared smoothing. `Space` only multiplies pan; it supplies no distance, room or early reflections. There are no differentiated vocal-formant paths, per-voice onset microtiming, natural vibrato or voice-leading across chords. The current declared DSP PDC at 48k remains **1536 samples / 32ms**. `Voice count=3` represents three wet harmony voices in addition to dry lead, not three separately modeled people. + +This is functional prototype pitch-shifting, **not** a formant-stable choir model. Improving pan or reverb alone cannot repair consonant smearing, pitch-mark phase discontinuity, or shifted formants. `Color` is *brightness*, not voice-tract formant preservation. + +## Research cross-check (public engineering references) + +- Antares Harmony Engine: independent voice timbre/vibrato/panning, humanize and choir controls; scale, chord and arranged notes; https://www.antarestech.com/products/creative-vocal-effects/harmony-engine +- Antares walkthrough: per-voice pan/throat length, vibrato onset/rate, timing and pitch variation; https://www.antarestech.com/blog/tutorial-introduction-to-harmony-engine +- Eventide H949: intelligent de-glitched splicing, micropitch and randomized delay to reduce lockstep duplication; https://www.eventideaudio.com/plug-ins/h949-harmonizer/ +- Eventide Quadravox: independent diatonic voice intervals and pitch transitions; https://cdn.eventideaudio.com/manuals/h90/1.1.2/content/algorithms/pitch.html +- PSOLA singing paper: pitch marks and 2-period Hann window, formant-aware spectral envelope processing, low-cost resynthesis but pitch-mark error is audible; https://www.mdpi.com/2076-3417/6/11/368 +- AES PSOLA + transient preservation: pitched segmentation needs robust marks and explicit consonant/transient bypass/reinjection; https://aes.org/publications/elibrary-page/?id=15624 +- Real-time phase vocoder spectral envelope: whitening/reconstruction is an alternative but incurs spectral window work and transient tradeoffs; https://www.isca-archive.org/interspeech_2017/lenarczyk17_interspeech.pdf +- Rubber Band documentation: `OptionFormantPreserved` and `OptionPitchHighConsistency` for dynamically varying vocal pitch. LiveShifter documents **>=50ms delay** depending on settings; not a free drop-in replacement for a low-latency live ASIO path; https://breakfastquay.com/rubberband/integration.html and https://breakfastquay.com/rubberband/code-doc/classRubberBand_1_1RubberBandLiveShifter.html. License GPLv2+ or commercial, review distribution terms before any integration: https://breakfastquay.com/rubberband/license.html +- Backing-vocal spatial placement / front-back depth: complementary pan and differences in timbre, early reflections, reverb/delay; natural doubles need independent microtiming; mono-check to avoid comb filtering: https://www.izotope.com/community/blog/tips-for-mixing-vocal-harmonies and https://www.izotope.com/community/blog/what-is-mix-depth-how-to-create-front-back-space and https://www.izotope.com/community/blog/10-tips-for-better-mixes-through-panning + +## Committed engineering decision, staged — no rushed wholesale DSP swap + +**P0: native GUI provenance, truth, response.** Keep one audio-owned ChannelId/InstanceId, native ACK and readback. Preserve editor across device/graph revision using safe auto-rebind. `observedNote` (quantized tracked MIDI note, *not exact raw singing F0*) now drives a small `TRACKING A3` / `WAITING VOICE` indicator on existing console ticks at <=2Hz, including Manual Key. Key gesture outlined as *queued* immediately while the actual LCD highlight is still the last accepted DSP value. No new polling timer, speculative PCM meters, Lab modes, FX permission gates or GUI shell redesign. + +**P0: make pitch/resynthesis natural, then measure.** Retain the proven prototype behind a native A/B flag during experimentation. Candidate quality path: confidence-gated fundamental detection -> robust glottal-epoch / pitch-mark tracking (using existing pitch estimator as an initial predictor; verify each mark by correlation) -> low-cost overlap-add on two-period tapered periods, scheduled at target F0. Preserve spectral envelope via pitch-synchronous segment handling; if audible vowel/formant drift persists at large shifts, benchmark pre/post spectral-envelope or LPC correction off the shared analysis window. Shared normalized/unvoiced consonant and transient path should not create three repeated sibilant attacks. When pitch confidence falls, crossfade safely to neutral or limited fallback rather than random target harmonies. Do not invent claims that TD-PSOLA alone is perfect at large intervals. Maintain the same single native PCM owner, immutable prepared controls, bounded history and predictable callback instruction budget. + +**P1: three distinct backing singers; ensemble spatializer.** Model each voice independently AFTER pitch generation: slight deterministic, slowly evolving detune rather than random-per-sample jitter; own phrase-onset delay / vibrato rate+depth/offset; mild unique spectral contour and intentional register. Keep leading dry vocal prominent. Initial *hypotheses to measure/listen*, not shipped presets: pan L=-0.35 to -0.45, inner=-0.05 to +0.05, R=+0.35 to +0.45; differences in onset 10–25ms; low-amplitude individual 3–8-cent pitch drift (slow and correlated within a phrase), modest sustain-only vibrato ~4–6 Hz, no hard random reset at graph boundaries. Per-voice room-send and early reflection mix with small filtered reflected taps ~20–50ms, not five independent convolution reverbs. Reverberant-to-direct ratio and high-frequency loss convey distance; simply cranking global width does not make a voice sound behind the lead. Pan+room must remain mono-compatible with no unexpected polarity cancellation; avoid phase-widening shortcuts. + +**P2: musical arrangement reliability.** Key+scale alone does NOT tell the current chord; fixed diatonic thirds/fifths can harmonize out of chord when music changes. Source-channel Music Guide must stay an independent read-only reference with confidence hysteresis/fallback; explore chord estimation / optional MIDI note control and smooth voice-leading only AFTER reliable native PCM keys and natural pitch shifting. No silent auto-chord hallucination. `Space` remains a single easy control that intelligently combines width/depth with carefully tuned bounds; power and Wet remain intuitive. + +**Low-latency ownership rule.** The source singer's ASIO monitor must not be slowed by experimental spatialization. Any PDC change needs native graph/host correctness and same-time dry/wet alignment verification. The present 1536-sample lookback is a measured *code delay*, not a benchmark of total ASIO round trip. Incremental tuning cannot be declared 'zero latency'. No locks/malloc/blocking on callback, no unbounded FFT work on sample path, no plugin worker feeding the realtime thread with a blocking rendezvous. + +## Measured acceptance gates before release promotion + +1. Exact Windows native compiled tests at 32/44.1/48/96/192 kHz and callback periods 64/128/256: deterministic output across buffer partitionings; bounded per-sample/per-block costs, no NaN/inf, clipping, lost ACK, stale FX lease or phase-cancelled mono. +2. Native visual/transport tests: tap Key while voice is live -> immediate pending outline/status; only accepted key after audio ACK and matching readback; live pitch tracking readback while Manual; Graph revision, device restart, FX move/recreate, stale ACK rejected; renderer never strands user on REOPEN. +3. Voice quality: licensed/consented male/female/child-free adult recordings, vowels A/E/I/O/U, breath/voiced/unvoiced consonants and held/fast syllables; measure F0 trajectory error, F1/F2/F3 shift, transient repetition, onset jitter, sibilance and phrase coherence against dry and reference algorithms. +4. Spatial A/B with mono fold-down: blind listen for **three distinguishable backup singers behind the lead**, not combed/flanged copies. Check L/C/R placements, loudness-normalized mono/stereo, low/normal/high background levels, output on mono speakers and headphones. +5. Actual ASIO physical FAT at 48/96 kHz, 64/128/256 frames: CPU time distribution p95/p99, deadline margin and XRUNs with 2/3/5 voices and multiple mixer plugins, hot graph/device rebind. These results cannot be inferred from ordinary GitHub Actions. + +**Non-claim:** The present PR does not yet implement or certify natural formants, an acoustic spatial engine, or a shorter engine PDC. Changing those requires measured code, CTest, render comparisons, audio A/B and physical ASIO proof. + +## 2026-11-09 P1 implemented — bounded singer individuation and early room + +New `engine/builtin_fx/HarmonyEnsembleSpace.h` defines five deterministic +backing singer identities, allocated as fixed-size fields and prepared on the +control thread. Each has its own arrival offset (5–17ms), phase and slight +detune (~1–3 cents) with onset-ramped, subtle 4.5–5.35Hz vibrato, and a +mild unique timbre coefficient. Up to five fixed 4096-sample reflection rings +supply one integer-delay, opposite-side quiet early reflection (12–20ms). +The same existing `Space` control now governs moderate pan width and +room amount, without adding another GUI mode or `.smix` schema field. + +No `sin`, `pow`, heap allocation, locks, worker or buffered audio queue +runs inside callback; each singer's LFO uses control-thread sine LUT. All +reflection histories advance when backing voices are inactive so stale FX +cannot reappear. No native graph, VST3, ASIO callback owner, slider/preset, +transport or routing changes. Plugin PDC remains 1536 samples @48k +(32ms). Vocal backing output is intentionally slightly later than the +lead, rather than delaying the lead itself: this is *musical onset and +depth*, NOT an additional reported whole-plugin latency. + +Acceptance includes fixed-tap reflection impulse at 32–192k, isolation +between singers, bounded detune/vibrato and mono-compatible 3-voice +stereo field at 48/96k. Existing PCM block-partitioning, host bypass, +anti-phase dry and realtime CPU diagnostic still apply. This is a P1 +ensemble-spatial realism increment, **not a formant-preserving +resynthesis fix**. The original two-grain pitch shifter can still sound +robotic on real recorded consonants and wide intervals. It requires a +separate pitch-synchronous/formant-aware algorithm and A/B acoustic gate. + +## 2026-11-09 P0 native pitch-synchronous candidate (requires physical singer qualification) + +Audit found the audible 16ms fixed-grain playback still changes vowel phase at unrelated seam boundaries. This commit adds a **causal, bounded pitch-synchronous window candidate** to the same ChannelId `HarmonyDsp`. It uses source-F0 pitch periods and local positive source landmarks to read waveform windows at **unity PCM speed**, while note ratio controls the spacing of synthesis centers; formants are no longer intentionally frequency-scaled by speeding the source playback. The original grain shifter is retained as the fallback for missing landmarks/low correlation/unvoiced phonemes; transitions ramp over 12ms. This is an approximation, not a proven glottal-closure PSOLA or completed formant-safe voice model. + +- One 16,384-sample mono history already owned by Harmony; no new audio route, device, host, PDC, user control or UI. Per-voice candidate stores at most 8 active source windows, fixed-size. Peak searches are bounded to <1 source period and never read future input. +- New original-harmonic source CTest checks up/down ratios, a low male period, high-rate registers and **exact 64/257 callback-partition PCM parity** at 48/96/192k. Existing native lead preservation and phase-safe music tests still apply. +- **Crucial nonclaim:** harmonic synthetic tests do not establish a singer's natural vowel formants or consonant intelligibility. Positive peaks are not reliable epochs for all breathy, growled or multi-pitch vocals. Do not mark PR production-ready until real recorded-vocal spectral F1/F2/F3, fricative/phrase boundaries, loudness-matched blind A/B and worst-case ASIO xrun/latency testing. If an audible regression occurs, fall back to the previous grain implementation before release. + +## 2026-11-09 Native vocal A/B workstation milestone + +The same `HarmonyDsp::Engine` now exposes an **offline reference-only** switch to re-render the previous grain synthesis against the pitch-synchronous candidate; normal live devices always default to the candidate and no new GUI mode/schema/control packet is added. The separate `ARMixHarmonyOfflineAb` C++ CLI takes a licensed/consented **adult** voice excerpt in mono/stereo 16/24-bit PCM or 32-bit float RIFF WAV, 32–192 kHz, <=60 seconds: + +```sh +ARMixHarmonyOfflineAb dry-vocal.wav output-directory +``` + +Outputs `01_lead_reference.wav`, `02_legacy_grain_mix.wav`, `03_new_space_060.wav`, `04_new_backing_only.wav`, `05_new_mono_fold.wav`, `06_new_space_000.wav`, `07_new_space_100.wav`, and `metrics.json`. All cases are reset from identical input and Manual C major / three voices / Wet 45%, Pitch Tune OFF, Gain 0dB. Wet0 lead is compared sample-exact across candidates; backing stem is mathematical difference from that lead and rejects hard-clipped output. The tool runs offline only; no filesystem IO in the audio callback. Compile/run `--self-test` as a quick synthetic source integrity check. + +**Unmet acoustic gates:** actual consented singer recordings and blind A/B, F1/F2/F3/vowel envelope preservation, noisy consonants, source expression, physical Windows ASIO loopback and CPU/xrun timings. Do NOT use the synthetic self-test or unnormalized WAV comparison to claim a professional natural-sounding result. diff --git a/docs/ARSON_VOCAL_THROW_BEAT_GRID_M3_20261109.md b/docs/ARSON_VOCAL_THROW_BEAT_GRID_M3_20261109.md new file mode 100644 index 000000000..6cb0512fb --- /dev/null +++ b/docs/ARSON_VOCAL_THROW_BEAT_GRID_M3_20261109.md @@ -0,0 +1,45 @@ +# ArSon Vocal Throw M3 — native music beat-phase quantized echo + +**Branch:** `feature/arson-vocal-throw-phase-grid-m3-20261109`; builds on draft M2 PR #474 (which builds on M1 PR #469). Product issue #473. **Not a hardware-certified stage release.** + +## What changed + +A stable BPM alone cannot locate the *beat boundary*. M3 shares the existing native ChannelId audio renderer's monotonically increasing callback frame counter with its built-in FX processing, then quantizes **only the newly scheduled echo** when the selected MUSIC ChannelId has a credible beat-phase estimate. + +``` +ONE native ASIO/JUCE ChannelId render (epoch + graph revision) + beginAudioBlock(frames) -> monotonic native sample-frame start + NativeBeatFrameScope (thread-local, callback-only and restored on exit) + pre-FX MUSIC ChannelId -> 10ms nonmutating energy frames + each summary carries its exact observed audio end-frame (within 10ms) + SPSC -> existing control timer -> BPM, onset anchor, phase confidence + CONTROL publishes BPM + sample-frame anchor + epoch/revision to FX + -> atomic version-fenced snapshot (one read attempt per callback) + VOICE FX on SAME callback/thread + -> read versioned tempo + scoped native frame origin + -> if source/epoch/revision invalid: accepted Manual/TAP + -> if BPM stable, beat phase weak: BPM-derived interval, NO grid + -> if BPM and phase credible: snapshot anchor & interval at THROW + -> freeze voice with existing two-tail bounded PCM + -> schedule next echo at FIRST native music grid point >= + intended (phrase end + musical subdivision), with correction + bounded to ONE subdivision and zero change to dry PCM + -> already sounding echo tails retain frozen timing across BPM/graph edits +``` + +### Realtime invariant +No new audio callback, dynamic allocation, model inference, FFT, lock, waiting, JS audio, logging or file I/O from the callback. Channel PCM enters one mixer graph and is never processed twice. The timing scope is a trivially copied thread-local struct, no global audio clock thread. Tempo/phase inference (up to 121 BPM candidates) is CONTROL-only. Packed atomic scalar fields are protected by an even/odd version; the audio callback makes **one** bounded read attempt and immediately falls back on inconsistency. + +### Confidence and fallback +- BPM confidence and beat-phase confidence are independent. A musical onset beat grid is used only if a majority of percussive onset strength agrees on a single pulse lattice. +- Ambiguous rhythmic patterns remain **AUTO BPM · BPM only**, not a speculative grid. A missing source or stale graph becomes **Manual / TAP** without losing the accepted preset. +- A 10ms analysis window means onset time has approximately up to one window of inherent beat-position uncertainty, even though *subsequent scheduling* uses exact callback sample indices. This is not sample-perfect transient detection. +- Phase quantization is measured against **pre-FX** selected music PCM, not against a fully latency-compensated external performance clock. Vendor VST3 latency, off-beat percussion, compressed music, drift, sample-rate changes, ASIO callback reentrancy and sparse backing must still pass field tests. + +### Automated acceptance +- Native DSP unit test verifies an actual frozen phrase's first echo is scheduled on the music frame lattice and remains there after transport disappears, compared with Manual/TAP quarter-note fallback; repeats at 64/128-frame PCM chunks with callback heap forbidden. +- Native graph PCM test stamps the selected music ChannelId from one authoritative callback at variable 64+36 sample chunks, verifies anchored BPM/phase confidence at 72/95/120/160 BPM, one block-clock scope, frame counter continuity after a graph revision, and restoration of callback-only context. +- Desktop/mobile Chromium smoke explicitly distinguishes a native ACKed source's **BPM only** from **BEAT GRID** status. No user-facing opt-in or extra monitor/arm step. + +### Deferred release qualification +Physical ASIO 64/128 frame loops at 44.1/48/96 kHz; on-stage singer/backing leakage, syncopated 4/4 and half/double-time, large FX PDC, dropout/replug, fade/no-click audition, real CPU/xrun vs bypass, and sustained stress still require field evidence. Do not merge while the PR chain and these safety gates remain unresolved. diff --git a/docs/ARSON_VOCAL_THROW_MUSIC_TEMPO_M2_20261108.md b/docs/ARSON_VOCAL_THROW_MUSIC_TEMPO_M2_20261108.md new file mode 100644 index 000000000..088665a93 --- /dev/null +++ b/docs/ARSON_VOCAL_THROW_MUSIC_TEMPO_M2_20261108.md @@ -0,0 +1,45 @@ +# ArSon Vocal Throw M2 — Native Music Channel Tempo Detection + +**Status:** implementation and qualification draft, stacked on Vocal Throw M1 PR #469. M1 green head `4db384851e6f6378cca4fd037b744c98bd1f0ba3`; M2 is PR #474 and tracks issue #473. + +## Signal authority + +``` +Authoritative ChannelId native PCM graph, single JUCE / ASIO callback + MUSIC ChannelId selected explicitly by singer/operator + -> PRE-FX non-mutating read-only music tap + -> 10ms stereo absolute-energy summary, bounded SPSC + -> existing 12Hz JUCE control timer: onset search + BPM confidence + -> accepted tempo precomputed into sample intervals, CONTROL only + -> per-VocalThrow atomic pending interval + -> next dry/vocal PCM callback copies interval BEFORE any THROW + -> new frozen vocal echo gets music interval, old tails keep prior schedule + VOICE ChannelId -> VocalThrow (no added dry PCM delay) -> WIRE/BUS/MAIN +``` + +**AUDIO callback contract:** no memory allocations, FFT, file I/O, logging, locks, networking, JS DSP, or new audio threads. Only the explicitly selected source channel's input stereo samples are summarized; every other channel skips the per-sample music tap. Existing JUCE callback remains the only audio authority. Core audio buffers and retained FX leases remain with the native graph. + +**CONTROL contract:** only an accepted `ChannelId` with input / GROUP / FX_RETURN role and an actually scheduled PCM lane is a permissible tempo source. The native FX editor validates both its own vocal insert instance and source identity, device epoch and graph revision. Monitor/MAIN and the vocal channel itself are not accepted. On a valid structural graph recompile, an existing source ID is rebound with a new analysis generation; if absent or stale, the music clock is disabled, and Vocal Throw falls back to its saved BPM or TAP tempo. + +## Detector + +- A 10ms energy onset, 80ms transient refractory and adaptive floor reject a simple repeated rise from a sustained note. +- Bounded pairwise onset-period candidate scoring (60–180 BPM), with penalty for octave half/double candidates, three consistent estimates and confidence threshold. +- Native readback distinguishes **AUTO BPM locked**, **Listening**, and **Manual/TAP fallback**. A silence period exceeding 3.2s resets lock. +- UI conveys confidence as measured by estimator; this number is not field-certified reliability. + +**Explicit limitations:** Music/onset BPM estimation does not provide sample-perfect beat-phase grid alignment. A recent transient anchor is retained for diagnostics only; it is not used as a globally compensated sample clock. Syncopated and heavily compressed music, live mic bleed, time-signature changes, half/double-time ambiguity and device-specific ASIO timing remain hardware field gates. Tempo selection is ephemeral song-wide, not yet persisted per Show. The fallback path always remains audible on the singer's dry stream. + +## Qualification evidence + +- Prior M1 Windows MSVC/JUCE: 63/63 CTest on exact SHA `4db384851e6f6378cca4fd037b744c98bd1f0ba3`. +- M2 Windows MSVC/JUCE: 64/64 CTest, including `NativeMusicTempoSourceOnsetsAndFallback`, on exact SHA `cce63231da52f69e6789873ecc406adba69aa1cb`. See [Actions run 42498186748](https://github.com/masarray/arsonmix/actions/runs/42498186748). +- Chromium FAT M2 native Vocal Throw picker, music source ACK, BPM readback and stale instance handling passed on same SHA. +- Later hardening: inbound tempo sampled before same-callback THROW and reset on plugin audio reprepare; corresponding regression checks for manual fallback and active tail interval stability. Qualification on the later SHA must be checked independently. +- Deterministic PCM: 72, 95, 120, 160 BPM; non-vocal source, stale revision, source change, dropout, default fallback. The CTest calls the *actual* native publisher to verify a music signal traverses the accepted graph, not only the isolated estimator. + +**Not qualified:** physical ASIO 64/128 frame load at 44.1/48/96 kHz; prolonged simultaneous singer/backing test; live beat-grid sync / stereo echo hearing test; WASAPI secondary stream callback load; long-run xrun/restart and voice-music bleed reliability. Green CI is necessary but not sufficient for release. + +## Next DSP/UX milestone + +Prove stable beat phase with a source-specific latency-compensated anchor; handle half/double-time ambiguity with confidence floor and long-window hysteresis; permit song/Show fallback preference; add footswitch mapping and live capture metrics without callback work. Until then label UI as estimated **AUTO BPM** rather than **sample-accurate beat quantization**. diff --git a/docs/ARSON_VOCAL_THROW_NATIVE_20261108.md b/docs/ARSON_VOCAL_THROW_NATIVE_20261108.md new file mode 100644 index 000000000..e39acc139 --- /dev/null +++ b/docs/ARSON_VOCAL_THROW_NATIVE_20261108.md @@ -0,0 +1,54 @@ +# ArSon Vocal Throw — native phrase-aware live delay + +**Status: functional prototype on a separate feature branch; not a certified live-performance release.** + +This is a first-class native ChannelId insert in ArSonMix's single JUCE PCM render graph, not a second audio callback, browser-generated sound or independent DAW. + +## Implemented + +- **Manual:** rolling ring buffer holds up to 1.5 seconds of the most recent vocal. THROW captures a word or phrase and schedules up to six decaying repeats. Two independent tail voices allow a subsequent phrase to overlap an existing echo instead of cutting it. +- **Auto:** energy envelope, minimum voice duration, silence threshold and cooldown detect the end of a sung phrase without letting the wet echo re-trigger itself. +- **Hybrid (default):** phrase-end automation and manual cue together, with manual-cue suppression of a subsequent auto event for the same phrase. +- **Tempo:** BPM entry (60-200), TAP BPM, quarter/eighth/dotted-eighth/half note subdivisions. Interval timing is in native samples at the actual device rate. +- **Mix:** direct dry input with zero added samples, stereo echo, decay, short fades, smoothed wet edits, and ducking while the singer is active. A bounded active-tap gain normalizer prevents dense repeats/overlapping phrases from amplifying the wet bus simply because taps stack; dry is never attenuated. +- **Real-time:** all rolling/frozen buffers are allocated off-callback; a fixed maximum 24-stereo-frame-per-sample capture copy budget per active tail avoids a single large callback memcpy. Contiguous copy chunks eliminate per-frame modulo, and the ring write cursor rolls over without division. A lock-free SPSC transfers host settings and manual cue to the audio callback. Callback never allocates/logs/locks. +- **Identity & persistence:** stable native catalog ID; ChannelId, device epoch, graph revision, and insert instance fencing. DSP completed ACK and later readback precede accepted display. Schema-versioned 48-byte AVTH settings blob validated during Show restore; audio capture and tails are not persisted. +- **UX:** a compact FX editor inside the exact approved /preview/ mixer; presets in header, uniform power/close, BPM/note/repeat, THROW, TAP and collapsible advanced controls. One shared FX stylesheet. + +## Architecture + +Hardware input → ChannelId mixer strip → upstream EQ/Compressor/VST3 → VocalThrowProcessor → downstream inserts → fader/pan → WIRE/BUS/MAIN → hardware output. + +Core files: engine/builtin_fx/VocalThrow.h (DSP), VocalThrowProcessor.h (JUCE), src/LiveAudioEngine.h (graph install), src/Main.cpp (validated command/readback), src/NativeMixerSessionFxRestore.h (versioned state), scripts/compose_native_peq.py (one picker), web/approved-native-bridge.js (real insert), site/preview-v2/assets/mixer-native-vocal-throw.js (controls only). + +## Tests / qualification + +The ARMixNativeVocalThrowTests CTest covers zero-added-sample dry, tempo divisions, captured stereo echoes after manual cue, auto-end detection and no self-trigger, bad parameter rejection, 8/44.1/48 kHz sample rates and a global allocator guard around realtime processing. Additional deterministic tests cover 8/48/96 kHz two-tail preservation during a second cue, a full two-tail pool reporting cue refusal rather than overwriting a running phrase, suppression of manual/auto double-cues, and peak containment of dense six-tap echoes. Python native picker/compiled-gui tests enforce no extra mixer screen and real-ACK event names. + +Before shipping: exact-SHA Windows MSVC + CTest, actual approved /preview/ Chromium screenshots, ASIO 64/128-frame stress at 44.1/48/96 kHz, live singer audition, device restart, bypass/tail behavior, and Show restore. + +## Explicit limitations + +1. **Automatic BPM analysis from the music/backing bus is not yet implemented.** Auto currently means automatic vocal phrase-end trigger, not auto-estimated music tempo. BPM is entered or TAP-derived. Full beat tracking requires an independent music-bus feed, beat confidence and phase tracking. +2. Voice end detector uses an adjustable energy-envelope heuristic, not linguistic speech recognition or a trained singing model. Breaths, falsetto and microphone bleed can cause false cues. +3. No MIDI footswitch binding, more than two simultaneous phrase layers, stretchable echo phrases, global music BPM transport integration, or direct song-snapshot binding in this milestone. When both frozen-tail slots are busy, further THROW requests are rejected (native ACK reports not applied) rather than cutting an existing musical phrase. +4. Green quick CI is not equivalent to real Windows native compilation or ASIO device certification. Zero reported PDC applies only to the FX DSP's dry path; end-to-end hardware/driver latency and callback CPU load still require ASIO measurements. +5. Existing channel routing and independent secondary audio clock remain authoritative; the FX insert makes no new claims about unresolved WIRE/SOURCE ONLY issues. + +## Field test + +Insert ID armix.builtin.vocal-throw.v1 into real ChannelId vocal strip; confirm graph ACK; sing “atau tidak” then press THROW at 72/95/120/160 BPM; try Auto with varying held notes and short breaths; toggle bypass while dry vocal remains direct; change device/quantum and reject stale instance requests. Compare physical ASIO callback xruns, stereo/feedback, click-free fades and singer subjective quality. + +## 2026-11-08 — performance and musicality hardening audit + +Audit of the first native revision identified these concrete risks: +- Triggering a second phrase reset `playing_` and overwrote the frozen buffer of the first tail; audible repeat discontinuity was possible. +- The original capture copied 24 frames via two per-frame ring modulo operations; this was an avoidable callback hot-path cost. +- Hybrid manual cues could be followed by auto-trigger of the same sung phrase, producing unintended double repeats. +- Wet level changed immediately on edits; close-spaced six-tap feedback-like echoes could produce unnecessarily high wet peaks. + +Hardening: two independent frozen voices, bounded cue admission (explicit rejection if full), bulk contiguous ring capture, write cursor without modulo, continuous smoothing of wet/duck gain, current-phrase manual suppression of auto replay, and peak-aware wet overlap normalization. Silence counters are now saturating for multi-hour sessions. + +**Realtime caveats:** No heap, locks, logging or file operations in `processStereo`, `throwNow`, or parameter application. Worst-case processing still includes two simultaneous 24-frame copy budgets, and an up-to-twelve-tap mix; on low-buffer ASIO that requires measured xrun and callback-duration evidence, not just source inspection. Extra frozen buffer memory is allocated only on channels with this effect. A full two-voice pool intentionally rejects a new cue, so polyphony and cue policies should be evaluated with vocalist/operator tests. + +**Next release gates:** exact-SHA MSVC CTest and native JUCE compile, 64/128-frame ASIO at 44.1/48/96 kHz, overnight stability and lifecycle/device-rate restart, phrase-ending listening sessions including breath/bleed/falsetto, bypass/re-enable and FX graph routing, and latency/xrun baseline comparisons versus bypass. Beat tracking from an isolated backing/music bus (confidence, phase and half/double-time hysteresis) remains a separate architecture milestone, not an already delivered feature. diff --git a/docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md b/docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md new file mode 100644 index 000000000..4b3a00397 --- /dev/null +++ b/docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md @@ -0,0 +1,49 @@ +# PRD — ArSon Harmony FX: Natural Backing Vocal Depth (v1.0) +**Date:** 2026-11-09 · **Status:** Binding product target, not a claim of acoustic quality achieved +**Owner scope:** ArSonMix native built-in Harmony on draft PR #487. Preserve the approved compact Harmony editor, same .smix schema, native PCM ownership, and auto-rebinding DSP/GUI. +**Related:** [Natural Ensemble architecture](ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md) · [Harmony engine audit](ARSON_HARMONY_ENGINE_AUDIT_20261108.md) · [Depth engine ARD](ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md) + +## User outcome / job to be done +One live singer should remain **clearly in front and unmistakably themselves**. Enabling 3 harmony backing singers should sound like **three people standing farther back**—mildly left, inner-center and mildly right in a coherent shared acoustic space. Harmony must not replace, cancel, phase-comb or automatically duck the original singer. When harmony is muted/off/at Wet 0, the same dry vocal must be preserved exactly except declared latency/PDC, explicitly selected pitch correction and global Gain. + +Users currently report a robotic/noise-like stack with little natural back/front separation. This is a P0 sound-quality defect, not solved by more panning or simply adding vibrato or wet reverb. The original 2-grain pitch-shifter is **still unqualified on singer recordings**; adding depth is a separate measurable, staged milestone. + +## Native one-knob user workflow +- The single existing **Space** knob remains the primary distance/width control; no Room Lab, advanced switches, extra dialog, permission gate or mandatory mixer routing. Wet controls backing strength; Color controls timbral brightness; Gain remains explicit output gain. +- At **Space 0**: compact, center-dominant dry backing (little/no backing reflection), lead still forward. +- At **Space 0.6 (factory default)**: audible but unobtrusive backing group a few steps behind, with left/near-center/right separation. Depth comes from lower backing direct level relative to reflected/diffuse sound, smooth upper timbre, modest onset offset and coherent short room, **not arbitrary meters or fake 3D localization**. +- At **Space 1**: noticeably deeper backing; no excessively long tails, discrete echo, metallic ring, mono disappearing vocals or extra lead level loss. Space automation must not sweep variable delay taps. +- **Wet 0 or rack bypass**: backing and its room must not leak into the monitoring output. Switching the rack on/off must follow native state, no GUI-only fake effect. +- **Music / Manual Key**: existing authoritative audio-owner ACK/readback, observed note and auto-rebind remain intact. Changing Space while holding a note must not produce zipper/click. + +## Audio precedence and separation requirements +1. **Lead invariant (P0):** Without user-enabled Pitch Tune, the sample-aligned lead path is independent of Wet/Space and retains channel polarity. Only the explicitly selected output Gain can scale both. Do not reuse a wet/dry crossfade that subtracts lead energy. +2. **Backing-only depth (P1):** all direct attenuation, high-frequency shading, early reflections and late diffusion apply to backing voices only. No additional effect may enter the lead path inadvertently. +3. **Direct-to-reverberant ratio (DRR):** deeper Space decreases backing DRR relative to Space near zero. This is a measurable signal-energy relationship, NOT a fixed literal physical distance. More reflection alone is not a substitute for quieter direct backing; no exaggerated reverb masking lyrics. +4. **Realistic front/back:** differentiated backing timbre without muffling consonants into noise; controlled stereo spread, mild independent phrases and natural pitch resynthesis. Existing 5–17 ms singer onset offsets and 12–20 ms early reflections need additional diffuse room energy to avoid hearing a single metallic/slap echo. +5. **Same room:** three singers share one subtle stereo diffuse field (with per-voice source position), not three unrelated giant reverb boxes. Late field is correlated acoustically but should not collapse to identical phase L=−R. +6. **Mono/speaker sanity:** mono fold of all wet voices stays audible and finite, no polarity inversion of dry signal, no excessive comb-filtering from source duplication. Test direct monitor + host monitored route externally: two simultaneous lead paths can still cause comb filtering outside Harmony, which DSP alone cannot cure. +7. **RT budget / portable:** keep current single JUCE PCM callback, bounded fixed memory and deterministic per-sample work. No fft/heap/mutex/host calls in realtime, no forced new global audio device, no new plugin PDC unless graph PDC tests pass. + +## Objective acceptance gates (all required) +| Gate | Test and evidence | Release requirement | +|---|---|---| +| Lead preservation | Wet=0/45/100, Space=0/60/100, no Pitch Tune, native PCM difference against dry-latency baseline | Sample-exact or <=1e-6 numerical lead-path delta after removing backing; no silent wet lead duck | +| Backstage vs foreground | Record natural male/female adult singing phrases; loudness-matched blind A/B between Space 0 / 0.6 / 1 | Listener reliably ranks backing behind lead and three voices separate; report results, not invented 3m coordinates | +| DRR / spectral balance | Synthetic impulse + vowel, separate backing-only STEM before final sum, calculate direct/reflected RMS in defined windows, compare bands | DRR decreases with Space; no extreme high-frequency loss (sibilant intelligibility); log curve | +| Room behavior | 32–192 kHz transient and silence; inspect 0.3–1.5 s tails and decay | No audible flutter echo, metallic ping, runaway feedback, NaN, noise-on-silence or tail on Wet 0 | +| Mono compatibility | L+R fold-down, L-R, in-phase and anti-phase stereo; 2/3/5 voices, 64/128/256 frames | Lead unchanged, backing energy remains audible with no complete cancellation | +| Realtime | Exact Windows MSVC/CTest plus CPU profile and real ASIO 48/96k × 64/128/256 frames with FX rack open/close and device graph restart | No extra graph latency, XRUNs or callback p95/p99 regressions; report hardware measurements | +| Natural vocal quality (separate P0) | Consented vowel/consonant, breathy, low-bass, female-soprano, slides and vibrato recordings | Formant and intelligibility evidence; cannot call the ensemble natural before this gate | + +## Milestones / explicit nonclaims +**D0:** Update PRD/ARD, isolate and remove wet-dependent lead duck, add mono/dry assertions. +**D1:** Prepared-sample-rate backing spectral shading + source-specific early reflections; one small bounded *backing-only* stereo diffuse late field; Space maps direct and reflected energy, not just width. +**D2:** Calibrate room decay/DRR and blind-listening A/B; profile worst-case Windows ASIO and return the simplest model that passes. +**D3 (separate P0 quality):** formant-preserving voiced/unvoiced resynthesis and expressive musical voice leading. D1 must not be marketed as completion of D3. + +**Release rule:** CI passing proves code correctness; perceived 3-person background distance and human timbre need real recordings/listener evidence. Keep PR Draft until justified. + +## 2026-11-09 D0/D1 working candidate (pending CI and ear-test) + +Updated `HarmonyDsp.h` removes the silent Wet-controlled lead duck, preserves the already selected Pitch Tune semantics and builds an independent backing-only distance chain. The existing Space control now adjusts direct-versus-reflected ratio, gentle high-frequency contour and one shared late stereo ambience field in addition to moderate pan. This addresses the *architecture* behind depth—not a verified acoustic outcome. D2 listener ranking/DRR level matching and D3 formant-aware synthesis remain open; preserve Draft status. diff --git a/docs/releases/v0.5.0-alpha.7.md b/docs/releases/v0.5.0-alpha.7.md new file mode 100644 index 000000000..f881529fa --- /dev/null +++ b/docs/releases/v0.5.0-alpha.7.md @@ -0,0 +1,19 @@ +# ArSonMix v0.5.0-alpha.7 — New Digital Mixer Public Preview + +**November 10, 2026 — Windows x64 first.** This alpha is a substantial feature and reliability upgrade from the published v0.5.0-alpha.5. It remains a public *preview*, not a claim that all audio interfaces and plugin combinations have been certified. The product owner reports real-world use of the current features as suitable for wider public trial. + +## New and improved +- **Real native digital mixer:** approved /preview/ mixer GUI in JUCE/WebView2, one ChannelId PCM routing graph, hardware inputs on mixer channels, source-only workflow, WIRE routing, physical MAIN/BUS path, fader, mute, solo, FX racks and VST3 host. +- **ArSon Player:** native music playback, independent KEY and TEMPO processing, per-song stage controls, folder import and safe missing-media relinking, without pulling filesystem work into realtime audio. +- **Singer FX:** built-in ArSon Harmony with phase-safe processing, improved warm/clickless bypass and bounded musical-key retargeting; ArSon Vocal Throw performance-delay FX with manual/auto tempo, phrase and beat-aware timing; familiar built-in parametric EQ and low-latency compressor. +- **Sessions and hardware:** retained mixer/.smix workflow, first-launch SOURCE NONE support, ASIO4ALL/input reconnect and restart recovery work; output-only FX workspace when no capture device is available. +- **Desktop polish:** native continuous ArSonMiX titlebar, clearer version/copyright and responsive window buttons; WIRE connector layout tracks window resizing; user-facing audio status no longer displays internal development/FAT metadata. +- **Safer Windows updates:** integrated on-exit Smart Auto Updater M3 for verified, installed Inno builds, with bounded staging, user data preservation and repair/rollback guards. It does not force-close an active mixer. Existing alpha.5 users must run this installer once to bootstrap automatic updates. + +## Installation +Download the **Windows x64 Setup** from this prerelease. Close any live performance before manually upgrading. Inno Setup preserves Studio and saved .smix files. Portable packages are for separate manual usage and do not install the auto-update supervisor. The optional first-party VST3 bundles are included only when reported in FACTORYFX_STAGE_REPORT.json; do not assume all sibling plugins ship by default. + +## Boundaries +Actual USB/ASIO interface, sample rate, plugins, WASAPI/OBS copy, exclusive device ownership and no-crackle behaviour depend on hardware; there is no blanket zero-xrun certification. Automatically updating a running audio session is intentionally prohibited. The Windows installer is not asserted to be Authenticode-signed. Linux/macOS assets are published only if separately qualified from this exact source. If a specific setup fails, retain the previous working version and report the interface/driver, rate, buffer and reproduction details. + +**Source integrity and release status:** release source is an exact immutable SHA, independently built and tested by Windows CTest, approved GUI, native packaging, Inno upgrade/uninstall, and SHA256/provenance gates before publication. Publishing is forbidden if those gates fail. diff --git a/engine/builtin_fx/BuiltInFxCatalog.h b/engine/builtin_fx/BuiltInFxCatalog.h index bbc6b83d3..67db030e2 100644 --- a/engine/builtin_fx/BuiltInFxCatalog.h +++ b/engine/builtin_fx/BuiltInFxCatalog.h @@ -11,6 +11,7 @@ namespace armix::builtin_fx { inline constexpr std::string_view channelEqId = "armix.builtin.channel-eq.v1"; inline constexpr std::string_view channelCompressorId = "armix.builtin.channel-compressor.v1"; +inline constexpr std::string_view vocalThrowId = "armix.builtin.vocal-throw.v1"; enum class FilterKind : std::uint8_t { highPass, lowShelf, bell, highShelf, lowPass }; enum class Slope : std::uint8_t { db12 = 12, db24 = 24 }; diff --git a/engine/builtin_fx/ChannelHarmonyProcessor.h b/engine/builtin_fx/ChannelHarmonyProcessor.h index 5573c3c25..7d2e15a7d 100644 --- a/engine/builtin_fx/ChannelHarmonyProcessor.h +++ b/engine/builtin_fx/ChannelHarmonyProcessor.h @@ -141,6 +141,7 @@ class ChannelHarmonyProcessor final : public juce::AudioProcessor, } double acceptedSampleRate() const noexcept {return sampleRate_;} bool isReady() const noexcept{return ready_;} + bool requiresContinuousBypassProcessing() const noexcept override {return true;} void sealForRealtime() noexcept override {published_=true;} bool stateSnapshotQuiescent() const noexcept override { return queued_.empty()&&completion_.empty()&&!pendingId_; diff --git a/engine/builtin_fx/HarmonyDepthRoom.h b/engine/builtin_fx/HarmonyDepthRoom.h new file mode 100644 index 000000000..83854d3f0 --- /dev/null +++ b/engine/builtin_fx/HarmonyDepthRoom.h @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +namespace armix::harmony { +// ONE deterministic backing-only stereo ambience field, not 5 reverbs. +// A 4x4 orthonormal Hadamard feedback stage distributes early line energy. +// Loop gains and pole coefficients are prepared off the realtime callback; +// the total energy gain is strictly < 1 before frequency damping. +class BackingDepthRoom final { +public: + static constexpr std::size_t branches=4; + static constexpr std::size_t capacity=8192; + struct Output {float left=0.f,right=0.f;}; + bool prepare(double rate) noexcept { + if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; + constexpr std::array delayMs{{23.f,29.f,34.f,41.f}}; + for(std::size_t i=0;i(std::lround( + static_cast(delayMs[i])*.001*rate)); + if(delay_[i]<2||delay_[i]>=capacity)return false; + // Nominal room RT60 ~0.55 s at low frequencies, shorter at + // high frequencies through the one-pole damping filter. + feedback_[i]=static_cast(std::pow( + 10.,-3.*static_cast(delay_[i])/(rate*.55))); + if(!std::isfinite(feedback_[i])||feedback_[i]>=1.f)return false; + lines_[i].fill(0.f);damped_[i]=0.f; + } + dampingAlpha_=static_cast( + 1.-std::exp(-2.*3.141592653589793*3200./rate)); + cursor_=0; + return dampingAlpha_>0.f&&dampingAlpha_<1.f; + } + Output process(float inputL,float inputR) noexcept { + std::array d{}; + for(std::size_t i=0;i,branches> lines_{}; + std::array delay_{}; + std::array feedback_{},damped_{}; + float dampingAlpha_=0.f; + std::size_t cursor_=0; +}; +} // namespace armix::harmony diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 56d245e84..e1d60272c 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -5,6 +5,13 @@ #include #include #include +#include "HarmonyStereoFold.h" +#include "HarmonyPreparedTone.h" +#include "HarmonyEnsembleSpace.h" +#include "HarmonyDepthRoom.h" +#include "HarmonyRoomFocus.h" +#include "HarmonyStageSpatial.h" +#include "HarmonyPitchSynchronous.h" // Deterministic, allocation-free vocal harmony DSP. No JUCE or GUI dependency. // Grain shifting is a functioning prototype, not formant-accurate synthesis. @@ -61,6 +68,7 @@ inline float smoothGrainBlend(float phase) noexcept { class Engine final { public: static constexpr int maxVoices=5; + static constexpr int maxPitchLagsPerSlice=8; // fewer burst MACs per sample // Maximum 192 kHz grain is 3072 frames: 2*grain latency + 3*grain // history = 15360, so 16384 frames retain the full rate/ratio budget. // Halves the three large audio rings per instance without RT allocation. @@ -72,6 +80,10 @@ class Engine final { latency_=2*grain_; decimation_=std::max(1,static_cast(std::round(rate/12000.))); detectEvery_=std::max(128,static_cast(rate/150.)); + // 32 fixed time slices per analysis hop, but only 8 lags/slice. + // Even 32k input completes every supported 65-1200 Hz candidate + // before the next frozen PCM window. Distributes RT work on ASIO 64. + pitchSliceEvery_=std::max(1,detectEvery_/32); // Support bass through soprano fundamentals; keep Nyquist/finiteness guards. // Earlier 850 Hz cap failed to track high soprano notes (e.g. C6). lowLag_=std::max(8,static_cast(rate/(decimation_*1200.))); @@ -79,16 +91,39 @@ class Engine final { if(lowLag_>=highLag_||latency_+3*grain_>=static_cast(capacity))return false; left_.fill(0.f);right_.fill(0.f);mono_.fill(0.f);decimated_.fill(0.f); filtered_.fill(0.f);phase_.fill(0.f);ratio_.fill(1.f);targetRatio_.fill(1.f); + // Independent grain clocks avoid five identical backing-singer seams. + // Lead correction keeps its neutral original phase. + for(int v=0;v(v)]=.157f*static_cast(v); // Low-pass before downsampling: raw 12 kHz decimation aliases vocal sibilants // into the periodicity detector and destabilizes the live note readback. decimationLowpass_=0.f; + if(!vocalFold_.prepare(rate)||!toneColor_.prepare(rate)|| + !ensemble_.prepare(rate)||!depthRoom_.prepare(rate)|| + !stage_.prepare(rate)||!roomFocus_.prepare(rate))return false; + pitchIntervals_.prepare(); + pitchSync_.reset(); + pitchSyncBlend_.fill(0.f);pitchSyncFiltered_.fill(0.f); + sourcePeriodSamples_=0.f;sourceConfidence_=0.f;sampleClock_=0; + pitchSyncReferenceEnabled_=true; + stageDepthReferenceEnabled_=true; + roomFocusReferenceEnabled_=true; + presenceReferenceEnabled_=true; + pitchSyncAlpha_=static_cast(1.-std::exp(-1./(rate*.012))); const float cutoff=1800.f; decimationAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*cutoff/rate)); write_=0;downWrite_=0;downSeen_=0;downCounter_=0; - detectCounter_=0;noteHold_=0;currentNote_=-1;candidateNote_=-1; - guideKey_=-1;guideScale_=-1; + detectCounter_=0;pitchSliceCounter_=0;pitchNextLag_=0; + pitchActive_=false;pitchBest_=-1.f;pitchBestLag_=0; + peakPitchLagWork_=0;completedPitchAnalyses_=0;abandonedPitchAnalyses_=0; + noteHold_=0;currentNote_=-1;candidateNote_=-1; + guideKey_=-1;guideScale_=-1;tonalTransitionPending_=false; voiced_=false;voicedGain_=0.f;settings_=Settings{}; - smoothingAlpha_=static_cast(1.-std::exp(-1./(rate*0.005))); // 5 ms continuous control ramp + smoothingAlpha_=static_cast(1.-std::exp(-1./(rate*0.005))); // 5 ms control ramp + // Preserve the established 48k envelope while keeping durations + // constant at 32-192k. Exponents computed off the callback. + voicedGateAlpha_=static_cast(1.-std::pow(1.-0.002,48000./rate)); + ratioAlpha_=static_cast(1.-std::pow(1.-0.00045,48000./rate)); processed_=false;settings_=Settings{}; return setSettings(settings_); } @@ -99,15 +134,28 @@ class Engine final { float gain=1.f; float mixL[maxVoices]{},mixR[maxVoices]{}; }; - static bool prepareSettings(const Settings& next,PreparedSettings& out) noexcept { + // Wet-only musical presence, prepared OFF the audio callback. + // 4-voice full Wet rises ~5 dB while dry lead and stage remain unchanged. + static float normalizedBackingWetAmplitude(float wet,int voices, + bool enhanced=true) noexcept { + if(!std::isfinite(wet)||wet<=0.f||voices<2||voices>maxVoices)return 0.f; + const float w=std::clamp(wet,0.f,1.f); + const float presence=enhanced?(.77f+.38f*w):.65f; + return w*presence/std::sqrt(static_cast(voices)); + } + static bool prepareSettings(const Settings& next,PreparedSettings& out, + bool enhancedPresence=true) noexcept { if(!valid(next))return false; PreparedSettings prepared; prepared.settings=next; prepared.gain=std::pow(10.f,next.gainDb/20.f); constexpr float pi=3.14159265358979323846f; - const float amplitude=next.wet*0.65f/std::sqrt(static_cast(next.voices)); + const float amplitude=normalizedBackingWetAmplitude( + next.wet,next.voices,enhancedPresence); for(int v=0;v(v)/(next.voices-1)-1.f); + // Width is moderate even at the center-friendly default Space. + const float pan=.72f*next.space* + (2.f*static_cast(v)/(next.voices-1)-1.f); const float angle=(pan+1.f)*pi*0.25f; prepared.mixL[v]=amplitude*std::cos(angle); prepared.mixR[v]=amplitude*std::sin(angle); @@ -116,12 +164,14 @@ class Engine final { } bool applyPreparedSettings(const PreparedSettings& next) noexcept { // Caller publishes only prepareSettings()-validated packets. - // A scale/key change must not inherit the previous tonal quantizer - // candidate or remain held on a now-out-of-scale note. + // Discard only the TONAL candidate on a key/source edit. The singer's + // current voiced envelope, source period and active grains continue. + // Next completed pitch windows retune to the new scale, bypassing + // old-key note hysteresis exactly until a new note is confirmed. if(next.settings.key!=settings_.key||next.settings.scale!=settings_.scale|| next.settings.guideMode!=settings_.guideMode|| next.settings.guideChannelId!=settings_.guideChannelId){ - candidateNote_=-1;currentNote_=-1;noteHold_=0;voiced_=false; + candidateNote_=-1;noteHold_=0;tonalTransitionPending_=true; } if(next.settings.guideMode!=settings_.guideMode|| next.settings.guideChannelId!=settings_.guideChannelId){ @@ -129,6 +179,7 @@ class Engine final { } settings_=next.settings; targetWet_=next.settings.wet;targetColor_=next.settings.color; + targetSpace_=next.settings.space; targetGain_=next.gain; targetCorrection_=next.settings.correction?1.f:0.f; for(int v=0;v(v)]=next.mixR[v]; } if(!processed_){ - wet_=targetWet_;color_=targetColor_;gain_=targetGain_; + wet_=targetWet_;color_=targetColor_;space_=targetSpace_; + gain_=targetGain_; correctionMix_=targetCorrection_; mixL_=targetMixL_;mixR_=targetMixR_; } @@ -146,7 +198,8 @@ class Engine final { // FX mailbox invokes applyPreparedSettings(), never this trig/pow path. bool setSettings(const Settings& next) noexcept { PreparedSettings prepared; - return prepareSettings(next,prepared)&&applyPreparedSettings(prepared); + return prepareSettings(next,prepared,presenceReferenceEnabled_)&& + applyPreparedSettings(prepared); } // Called only on the existing audio callback from a separately selected // source channel. Invalid/ambiguous music always restores Manual Key. @@ -156,7 +209,9 @@ class Engine final { const int previousKey=effectiveKey(),previousScale=effectiveScale(); guideKey_=key;guideScale_=scale; if(previousKey!=effectiveKey()||previousScale!=effectiveScale()){ - currentNote_=-1;candidateNote_=-1;noteHold_=0;voiced_=false; + // A guide-key revision is not vocal silence. Preserve the + // continuous sound and retune at the next stable pitch evidence. + candidateNote_=-1;noteHold_=0;tonalTransitionPending_=true; } } int effectiveKey() const noexcept { @@ -167,8 +222,38 @@ class Engine final { } const Settings& settings() const noexcept{return settings_;} int latencySamples() const noexcept{return latency_;} + // Offline A/B harness only: retain the exact legacy granular reference + // without introducing a user-facing mode or changing serialized FX state. + // Production instances always default to the pitch-synchronous candidate. + void setPitchSynchronousCandidateForOfflineReference(bool enabled) noexcept { + pitchSyncReferenceEnabled_=enabled; + } + // Offline A/B only. Default live audio always uses the new stage; no + // ordinary GUI control, device transaction or saved setting is added. + void setStageDepthForOfflineReference(bool enabled) noexcept { + stageDepthReferenceEnabled_=enabled; + } + void setRoomFocusForOfflineReference(bool enabled) noexcept { + roomFocusReferenceEnabled_=enabled; + } + // Offline-only before process(): same native pitch, stage, room and wet, + // but old vs new normalized voice gain, for controlled vocal A/B. + bool setBackingPresenceForOfflineReference(bool enabled) noexcept { + if(processed_)return false; + presenceReferenceEnabled_=enabled; + return setSettings(settings_); + } int observedMidiNote() const noexcept{return currentNote_;} bool voiced() const noexcept{return voiced_;} + int peakPitchLagWork() const noexcept{return peakPitchLagWork_;} + // Audio-owner telemetry; standalone CTest reads after process() returns. + int completedPitchAnalyses() const noexcept{return completedPitchAnalyses_;} + int abandonedPitchAnalyses() const noexcept{return abandonedPitchAnalyses_;} + // Wet changes are NEVER a hidden sidechain duck on the real lead. Only + // explicitly enabled Pitch Tune may substitute corrected lead samples. + static float leadPath(float original,float corrected,float correctionMix) noexcept { + return original*(1.f-correctionMix)+corrected*correctionMix; + } void process(float* l,float* r,int frames) noexcept { if(!l||!r||frames<=0||rate_<=0.)return; processed_=true; @@ -178,6 +263,7 @@ class Engine final { const float a=smoothingAlpha_; wet_+=a*(targetWet_-wet_); color_+=a*(targetColor_-color_); + space_+=a*(targetSpace_-space_); gain_+=a*(targetGain_-gain_); correctionMix_+=a*(targetCorrection_-correctionMix_); for(int v=0;v=decimation_){ @@ -196,27 +285,85 @@ class Engine final { downWrite_=(downWrite_+1)%decimated_.size(); ++downSeen_; } - if(++detectCounter_>=detectEvery_){detectCounter_=0;detectPitch();} + if(++detectCounter_>=detectEvery_){ + detectCounter_=0;beginPitchAnalysis(); + } + // Correlation search is spread across the existing sample + // callback: never evaluate all 175+ candidate lags at once. + // Every 64-sample ASIO period sees a bounded number of slices. + if(pitchActive_ && ++pitchSliceCounter_>=pitchSliceEvery_){ + pitchSliceCounter_=0;continuePitchAnalysis(); + } const float dryL=tap(left_,static_cast(latency_)); const float dryR=tap(right_,static_cast(latency_)); - voicedGain_+=((voiced_?1.f:0.f)-voicedGain_)*0.002f; + voicedGain_+=((voiced_?1.f:0.f)-voicedGain_)*voicedGateAlpha_; + // Compute the device-rate-correct filter coefficient once per + // active sample, not once for each of up to six shifters. + const float filterCoef=voicedGain_>0.00001f? + toneColor_.coefficient(color_):0.f; float lead=0.f; if(correctionMix_>0.00001f&&voicedGain_>0.00001f) - lead=shifted(maxVoices,color_); + lead=shifted(maxVoices,filterCoef); const float leadBlend=correctionMix_*voicedGain_; - float outL=(dryL*(1.f-leadBlend)+lead*leadBlend)*(1.f-wet_*0.65f*voicedGain_); - float outR=(dryR*(1.f-leadBlend)+lead*leadBlend)*(1.f-wet_*0.65f*voicedGain_); - if(voicedGain_>0.00001f){ - for(int v=0;v(v); - if(std::abs(mixL_[ix])+std::abs(mixR_[ix])<1.e-5f)continue; - const float y=shifted(v,color_)*voicedGain_; - outL+=y*mixL_[ix];outR+=y*mixR_[ix]; + float outL=leadPath(dryL,lead,leadBlend); + float outR=leadPath(dryR,lead,leadBlend); + // Direct sound and reflections from backing singers only. + // Preserve the exact previous spatial gains in offline reference. + const auto stageGain=BackingStageSpatial::gains(space_); + const float backingDirect=stageDepthReferenceEnabled_? + stageGain.direct:1.f-.38f*space_; + const float earlyReturn=stageDepthReferenceEnabled_? + stageGain.early:.28f*space_; + float roomSendL=0.f,roomSendR=0.f; + for(int v=0;v(v); + const bool audible=voicedGain_>0.00001f&& + std::abs(mixL_[ix])+std::abs(mixR_[ix])>=1.e-5f; + float voice=0.f; + if(audible){ + voice=shifted(v,ensemble_.timbreCoefficient(v,filterCoef), + ensemble_.arrivalSamples(v), + ensemble_.pitchRatio(v))*voicedGain_; + } + voice=ensemble_.shadeBacking(v,voice,space_); + const float reflection=ensemble_.exchangeReflection(v,voice); + const float second=ensemble_.secondReflection(v); + const float directL=voice*mixL_[ix],directR=voice*mixR_[ix]; + const auto placed=stage_.place(v,voice,reflection,second, + mixL_[ix],mixR_[ix],space_); + if(stageDepthReferenceEnabled_){ + outL+=placed.directL*backingDirect+placed.earlyL*earlyReturn; + outR+=placed.directR*backingDirect+placed.earlyR*earlyReturn; + roomSendL+=placed.roomL;roomSendR+=placed.roomR; + }else{ + outL+=directL*backingDirect+ + reflection*mixR_[ix]*earlyReturn; + outR+=directR*backingDirect+ + reflection*mixL_[ix]*earlyReturn; + roomSendL+=directL;roomSendR+=directR; } } + // One shared backing-only diffuse field. Both its input and + // audible return ramp with Space. Wet=0 gates its old tail on + // a smooth <=5 ms envelope while the room ring still decays. + // Room-only low-cut and musical tail bloom; lead remains untouched. + const float sendL=roomSendL*space_,sendR=roomSendR*space_; + const auto cleaned=roomFocus_.filterSend(sendL,sendR); + const auto room=depthRoom_.process( + roomFocusReferenceEnabled_?cleaned.left:sendL, + roomFocusReferenceEnabled_?cleaned.right:sendR); + const float roomGate=std::min(1.f,wet_*4.f); + const float lateReturn=(stageDepthReferenceEnabled_? + stageGain.late:.85f*space_)*roomGate; + const float focus=roomFocus_.returnGain(dryL,dryR,space_); + const float roomReturn=lateReturn*(roomFocusReferenceEnabled_?focus:1.f); + outL+=room.left*roomReturn;outR+=room.right*roomReturn; l[i]=std::clamp(outL*gain_,-4.f,4.f); r[i]=std::clamp(outR*gain_,-4.f,4.f); + ensemble_.advance(voiced_); + stage_.advance(); write_=(write_+1)%capacity; + ++sampleClock_; } } private: @@ -228,59 +375,109 @@ class Engine final { const auto a1=(a0+capacity-1)%capacity; return a[a0]*(1.f-f)+a[a1]*f; } - float shifted(int voice,float color) noexcept { + float shifted(int voice,float filterCoef,float arrival=0.f, + float fineRatio=1.f) noexcept { float& currentRatio=ratio_[static_cast(voice)]; - currentRatio+=(targetRatio_[static_cast(voice)]-currentRatio)*0.00045f; + currentRatio+=(targetRatio_[static_cast(voice)]-currentRatio)*ratioAlpha_; + const float effectiveRatio=std::clamp(currentRatio*fineRatio,.49f,2.01f); const float p=phase_[static_cast(voice)]; const float pB=p<0.5f?p+0.5f:p-0.5f; - const float delayA=2.f*grain_+(1.f-currentRatio)*p*grain_; - const float delayB=2.f*grain_+(1.f-currentRatio)*pB*grain_; + const float delayA=2.f*grain_+arrival+(1.f-effectiveRatio)*p*grain_; + const float delayB=2.f*grain_+arrival+(1.f-effectiveRatio)*pB*grain_; // Cubic smoothstep over the complementary two-grain windows. // Unlike the triangular seam, both endpoints have zero slope: // reduced grain-edge modulation without sin/cos in audio callback. const float w=smoothGrainBlend(p); float y=w*tap(mono_,delayA)+(1.f-w)*tap(mono_,delayB); - const float coef=0.07f+color*0.77f; - float& f=filtered_[static_cast(voice)]; - f+=coef*(y-f);y=f; - phase_[static_cast(voice)]+=1.f/static_cast(grain_); - if(phase_[static_cast(voice)]>=1.f) - phase_[static_cast(voice)]-=1.f; + const auto ix=static_cast(voice); + float& f=filtered_[ix]; + f+=filterCoef*(y-f); + // Voiced, periodic sources can use causal pitch-synchronous + // overlap-add. The exact source period is measured, not inferred + // from the harmony target. Uncertain/nonperiodic sounds retain the + // previous validated granular shifter with a bounded 12ms crossfade. + const bool confident=pitchSyncReferenceEnabled_&&voiced_&&sourceConfidence_>.82f&& + sourcePeriodSamples_>=8.f; + PitchSynchronousVoice::Output sync{}; + if(confident) + sync=pitchSync_.process(voice,sampleClock_,write_,mono_, + sourcePeriodSamples_,effectiveRatio, + static_cast(latency_)+arrival); + float& colorState=pitchSyncFiltered_[ix]; + colorState+=filterCoef*(sync.sample-colorState); + float& blend=pitchSyncBlend_[ix]; + blend+=pitchSyncAlpha_*((confident&&sync.ready?1.f:0.f)-blend); + y=f*(1.f-blend)+colorState*blend; + phase_[ix]+=1.f/static_cast(grain_); + if(phase_[ix]>=1.f)phase_[ix]-=1.f; return y; } - void detectPitch() noexcept { + // Prepare one immutable, bounded pitch-analysis window every analysis hop. + // The subsequent 8-lag correlation slices cannot race PCM history writes: + // they only read the frozen fixed-size pitchWindow_. + void beginPitchAnalysis() noexcept { + if(pitchActive_)++abandonedPitchAnalyses_; + pitchActive_=false; if(downSeen_(highLag_+170))return; constexpr int span=160; - // Gather a contiguous fixed-size pitch window ONCE per analysis hop. - // Previously every candidate/lag re-indexed circular history in the - // inner O(lags * span) loop: unpredictable CPU peaks on tiny ASIO buffers. - std::array samples{}; auto ix=(downWrite_+decimated_.size()-1)%decimated_.size(); for(int j=0;j(j)]=decimated_[ix]; + pitchWindow_[static_cast(j)]=decimated_[ix]; ix=ix==0?decimated_.size()-1:ix-1; } - double energy=0.; + pitchEnergy_=0.; for(int j=0;j(j)]; - energy+=x*x; + const double x=pitchWindow_[static_cast(j)]; + pitchEnergy_+=x*x; } - if(energy/static_cast(span)<1.e-6){ - voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; + if(pitchEnergy_/static_cast(span)<1.e-6){ + sourceConfidence_=0.f;voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1; + return; } - float best=-1.f;int bestLag=0; - std::array correlations{}; - for(int lag=lowLag_;lag<=highLag_;++lag){ - double xy=0.,yy=0.; + pitchCorrelations_.fill(0.f); + pitchLagEnergy_=0.; + for(int j=0;j(j+lowLag_)]; + pitchLagEnergy_+=y*y; + } + pitchBest_=-1.f;pitchBestLag_=0;pitchNextLag_=lowLag_; + pitchSliceCounter_=0; + pitchActive_=true; + } + void continuePitchAnalysis() noexcept { + if(!pitchActive_)return; + constexpr int span=160; + const int endLag=std::min(highLag_,pitchNextLag_+maxPitchLagsPerSlice-1); + const int work=endLag-pitchNextLag_+1; + peakPitchLagWork_=std::max(peakPitchLagWork_,work); + for(int lag=pitchNextLag_;lag<=endLag;++lag){ + if(lag>lowLag_){ + const double leaving=pitchWindow_[static_cast(lag-1)]; + const double entering=pitchWindow_[static_cast(span+lag-1)]; + pitchLagEnergy_+=entering*entering-leaving*leaving; + } + double xy=0.; for(int j=0;j(j)]; - const double y=samples[static_cast(j+lag)]; - xy+=x*y;yy+=y*y; + const double x=pitchWindow_[static_cast(j)]; + const double y=pitchWindow_[static_cast(j+lag)]; + xy+=x*y; } - const float correlation=static_cast(xy/std::sqrt(energy*yy+1.e-14)); - correlations[static_cast(lag)]=correlation; - if(correlation>best){best=correlation;bestLag=lag;} + const float correlation=static_cast( + xy/std::sqrt(pitchEnergy_*std::max(0.,pitchLagEnergy_)+1.e-14)); + pitchCorrelations_[static_cast(lag)]=correlation; + if(correlation>pitchBest_){pitchBest_=correlation;pitchBestLag_=lag;} + } + pitchNextLag_=endLag+1; + if(pitchNextLag_>highLag_){ + pitchActive_=false; + ++completedPitchAnalyses_; + finishPitchAnalysis(); } + } + void finishPitchAnalysis() noexcept { + const auto& correlations=pitchCorrelations_; + float best=pitchBest_; + int bestLag=pitchBestLag_; // Prefer shortest strong period rather than an octave-multiple peak. if(best>0.77f){ for(int lag=lowLag_;lag<=highLag_;++lag){ @@ -290,7 +487,7 @@ class Engine final { } } if(bestLag==0||best<=0.77f){ - voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; + sourceConfidence_=0.f;voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; } // Three-point peak interpolation reduces integer-lag tuning steps, // especially at the high end of the supported singing range. @@ -306,12 +503,13 @@ class Engine final { const float hz=static_cast(rate_)/(decimation_*lag); const float midi=69.f+12.f*std::log2(hz/440.f); if(!std::isfinite(midi)||midi<31.f||midi>96.f){ - voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; + sourceConfidence_=0.f;voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; } const int activeKey=effectiveKey(),activeScale=effectiveScale(); int degree=nearestDegree(midi,activeKey,activeScale); int note=noteAt(degree,activeKey,activeScale); - if(!pitchChangeHasMargin(currentNote_,note,midi)){ + if(!tonalTransitionPending_ && + !pitchChangeHasMargin(currentNote_,note,midi)){ note=currentNote_; degree=nearestDegree(static_cast(note),activeKey,activeScale); } @@ -322,30 +520,67 @@ class Engine final { // Two consistent windows for both phrase onset and melodic transitions; // do not generate provisional harmony on a single noisy transient. if(noteHold_<2)return; - currentNote_=note;voiced_=true; + currentNote_=note;voiced_=true;tonalTransitionPending_=false; + const float newPeriod=static_cast(rate_/hz); + if(sourcePeriodSamples_>0.f&& + std::abs(newPeriod-sourcePeriodSamples_)>.25f*sourcePeriodSamples_){ + pitchSync_.reset();pitchSyncBlend_.fill(0.f); + pitchSyncFiltered_.fill(0.f); + } + sourcePeriodSamples_=newPeriod; + sourceConfidence_=std::clamp(best,0.f,1.f); // Fifth harmony voice is a lower sixth in key; keep each voice // independent and normalize its level against the total count. + // One fractional-pitch exponent per analysis hop; each harmony + // interval is an integer number of semitones in the chosen scale. + // Five previous pow() calls move to the CONTROL prepared LUT. + const float baseRatio=std::pow(2.f,(note-midi)/12.f); constexpr std::array intervals{{2,4,-2,6,-4}}; for(int v=0;v(v)], activeKey,activeScale); targetRatio_[static_cast(v)]=std::clamp( - std::pow(2.f,(target-midi)/12.f),0.50f,2.0f); + baseRatio*pitchIntervals_.ratio(target-note),0.50f,2.0f); } - targetRatio_[maxVoices]=std::clamp(std::pow(2.f,(note-midi)/12.f),0.75f,1.34f); + targetRatio_[maxVoices]=std::clamp(baseRatio,0.75f,1.34f); } double rate_=0.; int grain_=0,latency_=0,decimation_=4,detectEvery_=320; int lowLag_=12,highLag_=144;std::size_t write_=0,downWrite_=0,downSeen_=0; int downCounter_=0,detectCounter_=0; + int pitchSliceEvery_=1,pitchSliceCounter_=0,pitchNextLag_=0; + int pitchBestLag_=0,peakPitchLagWork_=0; + int completedPitchAnalyses_=0,abandonedPitchAnalyses_=0; + bool pitchActive_=false; + float pitchBest_=-1.f; + double pitchEnergy_=0.,pitchLagEnergy_=0.; + // Fixed PCM snapshots; no allocation or variable work on the callback. + std::array pitchWindow_{}; + std::array pitchCorrelations_{}; int currentNote_=-1,candidateNote_=-1,noteHold_=0; int guideKey_=-1,guideScale_=-1; + bool tonalTransitionPending_=false; // retune note, never mute voiced singer bool voiced_=false;float voicedGain_=0.f; bool processed_=false; - float smoothingAlpha_=1.f; + float smoothingAlpha_=1.f,voicedGateAlpha_=0.002f,ratioAlpha_=0.00045f; float wet_=0.f,targetWet_=0.f,color_=0.f,targetColor_=0.f; + float sourcePeriodSamples_=0.f,sourceConfidence_=0.f,pitchSyncAlpha_=0.f; + std::uint64_t sampleClock_=0; + bool pitchSyncReferenceEnabled_=true,stageDepthReferenceEnabled_=true; + bool roomFocusReferenceEnabled_=true; + bool presenceReferenceEnabled_=true; + std::array pitchSyncBlend_{},pitchSyncFiltered_{}; + float space_=0.f,targetSpace_=0.f; float gain_=1.f,targetGain_=1.f,correctionMix_=0.f,targetCorrection_=0.f; std::array mixL_{},mixR_{},targetMixL_{},targetMixR_{}; float decimationLowpass_=0.f,decimationAlpha_=0.f; + StereoPhaseSafeFold vocalFold_{}; + RateStableColor toneColor_{}; + PreparedPitchIntervals pitchIntervals_{}; + EnsembleSpace ensemble_{}; + BackingDepthRoom depthRoom_{}; + BackingStageSpatial stage_{}; + BackingRoomFocus roomFocus_{}; + PitchSynchronousVoice pitchSync_{}; Settings settings_{}; std::array left_{},right_{},mono_{}; std::array decimated_{}; diff --git a/engine/builtin_fx/HarmonyEnsembleSpace.h b/engine/builtin_fx/HarmonyEnsembleSpace.h new file mode 100644 index 000000000..ad91b2cb8 --- /dev/null +++ b/engine/builtin_fx/HarmonyEnsembleSpace.h @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +// Deterministic, bounded, single-audio-owner backing-singer individualization. +// Prepared on non-realtime thread. No random generator, heap, mutex, worker +// or transcendental functions in the PCM callback. +namespace armix::harmony { +class EnsembleSpace final { +public: + static constexpr int voices=5; + static constexpr std::size_t reflectionCapacity=8192; + static constexpr std::size_t sineCount=1024; + bool prepare(double rate) noexcept { + if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; + constexpr float tau=6.2831853071795864769f; + constexpr std::array arrivalMs{{5.f,9.f,12.f,15.f,17.f}}; + constexpr std::array reflectionMs{{12.f,15.f,17.f,19.f,20.f}}; + constexpr std::array secondMs{{27.f,31.f,34.f,36.f,38.f}}; + constexpr std::array cents{{-2.8f,1.4f,3.2f,-1.7f,2.3f}}; + constexpr std::array vibratoHz{{4.7f,5.2f,4.9f,5.35f,4.55f}}; + constexpr std::array vibratoCents{{2.4f,3.0f,2.8f,2.6f,3.3f}}; + constexpr std::array timbre{{.93f,.86f,.96f,.89f,.83f}}; + for(std::size_t i=0;i(i)/sineCount); + for(int v=0;v(v); + offset_[ix]=static_cast(rate*arrivalMs[ix]*.001); + reflectionDelay_[ix]=static_cast(std::lround(rate*reflectionMs[ix]*.001)); + secondDelay_[ix]=static_cast(std::lround(rate*secondMs[ix]*.001)); + if(reflectionDelay_[ix]<2|| + reflectionDelay_[ix]>=static_cast(reflectionCapacity)|| + secondDelay_[ix]<=reflectionDelay_[ix]|| + secondDelay_[ix]>=static_cast(reflectionCapacity))return false; + ratio_[ix]=std::pow(2.f,cents[ix]/1200.f); + vibratoRatio_[ix]=vibratoCents[ix]*(.69314718056f/1200.f); + increment_[ix]=vibratoHz[ix]/static_cast(rate); + phase_[ix]=static_cast(ix)*.197f; + tone_[ix]=timbre[ix]; + reflections_[ix].fill(0.f); + } + // A sample-rate-stable, shallow air/room HF shading of backing + // singers only. Bypassed exactly when Space=0; lead is untouched. + shadingAlpha_=static_cast( + 1.-std::exp(-2.*3.141592653589793*4400./rate)); + distanceLowpass_.fill(0.f); + ageStart_=static_cast(rate*.065); + ageRamp_=static_cast(1./(rate*.165)); + age_=0;cursor_=0; + return true; + } + float shadeBacking(int v,float sample,float space) noexcept { + const auto i=static_cast(v); + distanceLowpass_[i]+=shadingAlpha_*(sample-distanceLowpass_[i]); + const float blend=.52f*std::clamp(space,0.f,1.f); + return sample*(1.f-blend)+distanceLowpass_[i]*blend; + } + float arrivalSamples(int v) const noexcept { + return offset_[static_cast(v)]; + } + int reflectionSamples(int v) const noexcept { + return reflectionDelay_[static_cast(v)]; + } + float timbreCoefficient(int v,float colorCoefficient) const noexcept { + return colorCoefficient*tone_[static_cast(v)]; + } + // All 5 LFOs have independent, deterministic phase and frequency. + // Sustain vibrato appears gradually; no per-block reset or random jitter. + float pitchRatio(int v) noexcept { + const auto i=static_cast(v); + const float position=phase_[i]*static_cast(sineCount); + const auto index=static_cast(position); + const auto following=(index+1)&(sineCount-1); + const float fraction=position-static_cast(index); + const float wave=sine_[index]+(sine_[following]-sine_[index])*fraction; + phase_[i]+=increment_[i]; + if(phase_[i]>=1.f)phase_[i]-=1.f; + const float mature=std::clamp((age_-ageStart_)*ageRamp_,0.f,1.f); + return ratio_[i]*(1.f+wave*vibratoRatio_[i]*mature); + } + // Exactly one filtered early reflection from each independent singer. + // Fixed integer tap delay: changing Space can never sweep a delay line + // or create a pitch chirp. 4096 samples covers 20ms even at 192k. + float exchangeReflection(int v,float sample) noexcept { + const auto i=static_cast(v); + reflections_[i][cursor_]=sample; + const auto delayed=(cursor_+reflectionCapacity- + static_cast(reflectionDelay_[i]))&(reflectionCapacity-1); + return reflections_[i][delayed]; + } + // A distinct later early-reflection arrival from the very same bounded + // singer ring. Call after exchangeReflection() writes the current sample. + float secondReflection(int singer) const noexcept { + const auto i=static_cast(singer); + const auto at=(cursor_+reflectionCapacity- + static_cast(secondDelay_[i]))&(reflectionCapacity-1); + return reflections_[i][at]; + } + int secondReflectionSamples(int singer) const noexcept { + return secondDelay_[static_cast(singer)]; + } + void advance(bool voiced) noexcept { + cursor_=(cursor_+1)&(reflectionCapacity-1); + if(!voiced)age_=0; + else if(age_<100000000)++age_; + } +private: + std::array sine_{}; + std::array,voices> reflections_{}; + std::array offset_{},ratio_{},vibratoRatio_{}; + std::array increment_{},phase_{},tone_{},distanceLowpass_{}; + float shadingAlpha_=0.f; + std::array reflectionDelay_{},secondDelay_{}; + std::size_t cursor_=0; + int age_=0,ageStart_=0; + float ageRamp_=0.f; +}; +} // namespace armix::harmony diff --git a/engine/builtin_fx/HarmonyMusicKey.h b/engine/builtin_fx/HarmonyMusicKey.h index 3743cb79f..b6aeefa36 100644 --- a/engine/builtin_fx/HarmonyMusicKey.h +++ b/engine/builtin_fx/HarmonyMusicKey.h @@ -4,12 +4,22 @@ #include #include #include +#include "HarmonyStereoFold.h" // Audio-thread-only, bounded chroma guide from a DIFFERENT ChannelId's real // pre-fader PCM. Not a chord recognizer and never an audible sidechain. // Conservative confidence/hold; uncertain music falls back to Manual Key. // No FFT allocation, locks, async worker, trig or heap in process(). namespace armix::harmony { +// Do not indefinitely pin an obsolete key when a new candidate is stable but +// moderately confident. Strong evidence can retarget after 0.8s; weaker yet +// valid evidence needs 2.0s of consecutive agreement. A candidate that +// oscillates resets its hold in evaluate(), so this never forces ambiguity. +constexpr bool acceptMusicKeyCandidate(bool currentValid,bool sameKey, + float confidence,int stableWindows) noexcept { + if(stableWindows<8)return false; + return !currentValid||sameKey||confidence>0.10f||stableWindows>=20; +} struct MusicKeyEstimate final { int key=-1,scale=-1; // -1 means no reliable tonal evidence float confidence=0.f; @@ -18,9 +28,16 @@ struct MusicKeyEstimate final { class MusicKeyDetector final { public: static constexpr int bins=36; // C3..B5, 3 octaves of music harmonics + // A 100ms chroma boundary must never score 24 tonal candidates in ONE + // ASIO sample. Spread two scores per decimated sample (<2.1ms total). + static constexpr int maxKeyScoresPerDecimatedSample=2; + static constexpr int maxRotorNormalizationsPerDecimatedSample=3; + int peakKeyScoresPerSample() const noexcept {return peakKeyScores_;} + int peakRotorNormalizationsPerSample() const noexcept {return peakNormalizations_;} bool prepare(double rate) noexcept { if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; decimation_=std::max(1,static_cast(std::round(rate/6000.))); + if(!stereoFold_.prepare(rate))return false; const double fs=rate/decimation_; sampleAlpha_=static_cast(1.-std::exp(-1./(fs*.18))); lowpassAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*1500./rate)); @@ -35,9 +52,13 @@ class MusicKeyDetector final { reset();return true; } void reset() noexcept { + stereoFold_.reset(); inC_.fill(0.f);inS_.fill(0.f); oscC_.fill(1.f);oscS_.fill(0.f);hist_.fill(0.f); - downCount_=0;periodCount_=0;normalizeCount_=0; + downCount_=0;periodCount_=0;normalizeCount_=0;normalizeIndex_=bins; + scoringActive_=false;scoringIndex_=0;scoringBest_=-2.f; + scoringSecond_=-2.f;scoringRoot_=-1;scoringScale_=-1; + scoringHist_.fill(0.f);peakKeyScores_=0;peakNormalizations_=0; framesSeen_=0;candidate_=-1;candidateScale_=-1;candidateHold_=0; silentFrames_=0;uncertainFrames_=0;windowEnergy_=0.;filtered_=0.f; current_={}; @@ -47,7 +68,7 @@ class MusicKeyDetector final { for(int n=0;n=4096){ - normalizeCount_=0; - for(int k=0;k0.5f&&std::isfinite(size)){ - oscC_[k]/=size;oscS_[k]/=size; - }else {oscC_[k]=1.f;oscS_[k]=0.f;} - } + normalizeCount_=0;normalizeIndex_=0; } + int normalized=0; + while(normalizeIndex_0.5f&&std::isfinite(size)){ + oscC_[k]/=size;oscS_[k]/=size; + }else {oscC_[k]=1.f;oscS_[k]=0.f;} + ++normalized; + } + peakNormalizations_=std::max(peakNormalizations_,normalized); if(++periodCount_>=period_){ periodCount_=0; evaluate(static_cast(std::sqrt(windowEnergy_/period_))); windowEnergy_=0.; } + // Score order matches the historical major-then-minor, root 0..11 + // loop. The scoring input is a frozen chroma snapshot, so the + // answer is independent of host callback partition boundaries. + continueScoring(); } } MusicKeyEstimate estimate() const noexcept{return current_;} @@ -98,6 +130,7 @@ class MusicKeyDetector final { return dot/std::sqrt(cc*pp+1.e-12f); } void evaluate(float rms) noexcept { + scoringActive_=false; if(!std::isfinite(rms)||rms<0.002f) { if(++silentFrames_>=10) { current_={};hist_.fill(0.f); @@ -120,18 +153,31 @@ class MusicKeyDetector final { hist_[k]=hist_[k]*0.91f+0.09f*(chroma[k]/sum); if(framesSeen_<1000)++framesSeen_; if(framesSeen_<12)return; // at least ~1.2 seconds of music - float best=-2.f,second=-2.f; - int bestRoot=-1,bestScale=-1; - for(int scale=0;scale<2;++scale) - for(int root=0;root<12;++root) { - const float score=correlation(hist_,scale?minorProfile:majorProfile,root); - if(score>best){ - second=best;best=score;bestRoot=root;bestScale=scale; - } else second=std::max(second,score); - } - // This is a KEY estimate, not chord detection. Relative minors and - // sparse/sustained notes often remain ambiguous: keep manual fallback. - const float confidence=std::clamp(best-second,0.f,1.f); + scoringHist_=hist_; // fixed-size snapshot; zero allocation + scoringIndex_=0;scoringBest_=-2.f;scoringSecond_=-2.f; + scoringRoot_=-1;scoringScale_=-1;scoringActive_=true; + } + void continueScoring() noexcept { + if(!scoringActive_)return; + int scored=0; + while(scoringIndex_<24 && scoredscoringBest_){ + scoringSecond_=scoringBest_;scoringBest_=score; + scoringRoot_=root;scoringScale_=scale; + } else scoringSecond_=std::max(scoringSecond_,score); + ++scoringIndex_;++scored; + } + peakKeyScores_=std::max(peakKeyScores_,scored); + if(scoringIndex_<24)return; + scoringActive_=false; + const float best=scoringBest_; + const int bestRoot=scoringRoot_,bestScale=scoringScale_; + // This is KEY estimation, not chord detection. A complete, frozen + // evaluation commits atomically only after all 24 candidate scores. + const float confidence=std::clamp(best-scoringSecond_,0.f,1.f); if(best<0.48f||confidence<0.045f) { candidate_=-1;candidateScale_=-1;candidateHold_=0; // A new ambiguous musical section cannot retain the previous @@ -142,17 +188,24 @@ class MusicKeyDetector final { uncertainFrames_=0; if(bestRoot!=candidate_||bestScale!=candidateScale_){ candidate_=bestRoot;candidateScale_=bestScale;candidateHold_=1; - }else if(candidateHold_<12)++candidateHold_; - if(candidateHold_>=8 && (!current_.valid() || - (current_.key==bestRoot&¤t_.scale==bestScale) || confidence>0.10f)) + }else if(candidateHold_<20)++candidateHold_; + if(acceptMusicKeyCandidate(current_.valid(), + current_.key==bestRoot&¤t_.scale==bestScale, + confidence,candidateHold_)) current_={bestRoot,bestScale,confidence}; } int decimation_=0,downCount_=0,period_=0,periodCount_=0,normalizeCount_=0; + int normalizeIndex_=bins,scoringIndex_=0; + int scoringRoot_=-1,scoringScale_=-1,peakKeyScores_=0,peakNormalizations_=0; + float scoringBest_=-2.f,scoringSecond_=-2.f; + bool scoringActive_=false; + std::array scoringHist_{}; int framesSeen_=0,silentFrames_=0,uncertainFrames_=0; int candidate_=-1,candidateScale_=-1,candidateHold_=0; float sampleAlpha_=0.f,lowpassAlpha_=0.f,filtered_=0.f; double windowEnergy_=0.; MusicKeyEstimate current_{}; + StereoPhaseSafeFold stereoFold_{}; std::array rotorC_{},rotorS_{},weight_{}; std::array oscC_{},oscS_{},inC_{},inS_{}; std::array hist_{}; diff --git a/engine/builtin_fx/HarmonyPitchSynchronous.h b/engine/builtin_fx/HarmonyPitchSynchronous.h new file mode 100644 index 000000000..9395ea1ca --- /dev/null +++ b/engine/builtin_fx/HarmonyPitchSynchronous.h @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include +#include + +namespace armix::harmony { +// Experimental causal pitch-synchronous source-window candidate. +// Vowel waveforms are read at unity sample speed; pitch changes arise by +// re-spacing aligned source windows, rather than resampling their formants. +// Positive waveform peaks are approximate epochs, NOT proven glottal closures. +// This must pass actual singer A/B before acoustic release qualification. +// All state is fixed; no allocation, locks, FFT or IO in process(). +template +class PitchSynchronousVoice final { + static_assert(Capacity >= 4096 && (Capacity & (Capacity-1)) == 0); + static_assert(Voices > 0 && Voices <= 8); +public: + struct Output { float sample=0.f; bool ready=false; }; + void reset() noexcept { states_={}; } + void resetVoice(int v) noexcept { + if(v>=0&&v(v)]={}; + } + // time/writeIndex refer to the input sample just written to the ring. + // fixedDelay retains the host's published latency; a singer-specific + // arrival delay can be added without moving the original dry PCM. + Output process(int v,std::uint64_t time,std::size_t writeIndex, + const std::array& input, + float sourcePeriod,float ratio,float fixedDelay) noexcept { + if(v<0||v>=Voices||!std::isfinite(sourcePeriod)|| + !std::isfinite(ratio)||!std::isfinite(fixedDelay)|| + sourcePeriod<8.f||sourcePeriod>3200.f|| + ratio<.49f||ratio>2.01f||fixedDelay(v)]; + const double period=static_cast(sourcePeriod); + const double spacing=period/static_cast(ratio); + const double width=std::max(period,spacing); + if(!state.initialized) { + state.initialized=true; + state.nextCenter=static_cast(time)+width; + } + // Advance at most two grains per sample, even on hostile period jumps. + // Normal supported periods place >=4 samples between target marks. + for(int scheduled=0;scheduled<2 && + static_cast(time)+.0001>=state.nextCenter-width;++scheduled) { + const double desired=state.nextCenter-static_cast(fixedDelay); + const auto peak=findPositiveEpoch(input,time,writeIndex,desired,period); + if(peak>=0) { + auto& grain=state.grains[state.nextSlot]; + grain={state.nextCenter,static_cast(peak),width,true}; + state.nextSlot=(state.nextSlot+1)%state.grains.size(); + } + state.nextCenter+=spacing; + } + if(state.nextCenter+width(time)) + state.nextCenter=static_cast(time)+width; + float sum=0.f,weight=0.f; + for(auto& grain:state.grains) { + if(!grain.active)continue; + const double offset=static_cast(time)-grain.center; + const double u=offset/grain.width; + if(u>=1.){grain.active=false;continue;} + if(u<=-1.)continue; + // Raised compact zero-slope window, avoiding per-sample trig. + const float w=static_cast((1.-u*u)*(1.-u*u)); + const float sample=readAt(input,time,writeIndex,grain.source+offset); + sum+=sample*w;weight+=w; + } + if(weight<.05f)return {}; + return {sum/weight,true}; + } +private: + struct Grain {double center=0.,source=0.,width=1.;bool active=false;}; + struct State { + std::array grains{}; + double nextCenter=0.; + std::size_t nextSlot=0; + bool initialized=false; + }; + // Bound the peak search to <1 source cycle, never scanning beyond the + // already received microphone input. Unreliable speech uses fallback. + static std::int64_t findPositiveEpoch(const std::array& input, + std::uint64_t time,std::size_t writeIndex, + double desired,double period) noexcept { + const auto half=static_cast(std::ceil(period*.46)); + const auto center=static_cast(std::llround(desired)); + const auto oldest=static_cast( + time>=Capacity-3?time-(Capacity-3):0); + const auto newest=static_cast(time>1?time-1:0); + const auto start=std::max(oldest,center-half); + const auto end=std::min(newest,center+half); + if(end( + static_cast(time)-t); + const float value=input[(writeIndex+Capacity-age)&(Capacity-1)]; + if(value>best){best=value;peak=t;} + } + return peak; + } + static float readAt(const std::array& input, + std::uint64_t time,std::size_t writeIndex,double position) noexcept { + if(time<2||position<0.||position>static_cast(time-1)|| + position( + time>=Capacity-3?time-(Capacity-3):0))return 0.f; + const double age=static_cast(time)-position; + const auto whole=static_cast(age); + const float fractional=static_cast( + age-static_cast(whole)); + const auto index=(writeIndex+Capacity-whole)&(Capacity-1); + return input[index]*(1.f-fractional)+ + input[(index+Capacity-1)&(Capacity-1)]*fractional; + } + std::array states_{}; +}; +} // namespace armix::harmony diff --git a/engine/builtin_fx/HarmonyPreparedTone.h b/engine/builtin_fx/HarmonyPreparedTone.h new file mode 100644 index 000000000..ee1d78cd0 --- /dev/null +++ b/engine/builtin_fx/HarmonyPreparedTone.h @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +// Control-thread prepared Harmony timbre filter and equal-temperament +// interval ratios. No transcendental function or allocation on AUDIO. +namespace armix::harmony { +class RateStableColor final { +public: + static constexpr std::size_t segments=256; + // 48k is the previously approved Color response; all other rates + // preserve the same one-pole physical-time attenuation. + bool prepare(double rate) noexcept { + if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; + for(std::size_t i=0;i<=segments;++i){ + const double color=static_cast(i)/segments; + const double previous=.07+.77*color; + coefficients_[i]=static_cast( + 1.-std::pow(1.-previous,48000./rate)); + } + return true; + } + float coefficient(float color) const noexcept { + const float position=std::clamp(color,0.f,1.f)*segments; + const auto index=static_cast(position); + const auto next=std::min(index+1,segments); + const float fraction=position-static_cast(index); + const float current=coefficients_[index]; + return current+(coefficients_[next]-current)*fraction; + } +private: + std::array coefficients_{}; +}; +class PreparedPitchIntervals final { +public: + static constexpr int maximumSemitones=24; + void prepare() noexcept { + for(int delta=-maximumSemitones;delta<=maximumSemitones;++delta) + ratios_[static_cast(delta+maximumSemitones)]= + std::pow(2.f,static_cast(delta)/12.f); + } + // Caller guarantees scale-degree intervals remain inside +/-24. + // Clamping makes an unexpected new music scale safe rather than OOB. + float ratio(int semitones) const noexcept { + const int index=std::clamp(semitones,-maximumSemitones,maximumSemitones); + return ratios_[static_cast(index+maximumSemitones)]; + } +private: + std::array ratios_{}; +}; +} // namespace armix::harmony diff --git a/engine/builtin_fx/HarmonyRoomFocus.h b/engine/builtin_fx/HarmonyRoomFocus.h new file mode 100644 index 000000000..90bb9e3fe --- /dev/null +++ b/engine/builtin_fx/HarmonyRoomFocus.h @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +namespace armix::harmony { +// Backing-ROOM ONLY, no lead/direct FX; prepared off realtime. +class BackingRoomFocus final { +public: + struct Stereo {float left=0.f,right=0.f;}; + bool prepare(double rate) noexcept { + if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; + constexpr double pi=3.14159265358979323846; + hp_=static_cast(1.-std::exp(-2.*pi*170./rate)); + attack_=static_cast(1.-std::exp(-1./(rate*.012))); + release_=static_cast(1.-std::exp(-1./(rate*.240))); + lowL_=lowR_=env_=0.f; + return hp_>0.f&&hp_<1.f&&attack_>0.f&&release_>0.f; + } + Stereo filterSend(float l,float r) noexcept { + lowL_+=hp_*(l-lowL_);lowR_+=hp_*(r-lowR_); + if(std::abs(lowL_)<1.e-12f)lowL_=0.f; + if(std::abs(lowR_)<1.e-12f)lowR_=0.f; + return {l-lowL_,r-lowR_}; + } + float returnGain(float dryL,float dryR,float space) noexcept { + const float level=std::min(4.f,std::max(std::abs(dryL),std::abs(dryR))); + env_+=(level>env_?attack_:release_)*(level-env_); + if(env_<1.e-10f)env_=0.f; + return 1.f-.22f*std::clamp(space,0.f,1.f)*(env_/(env_+.10f)); + } + float leadEnvelope()const noexcept{return env_;} +private: + float hp_=0.f,attack_=0.f,release_=0.f,lowL_=0.f,lowR_=0.f,env_=0.f; +}; +} // namespace armix::harmony diff --git a/engine/builtin_fx/HarmonyStageSpatial.h b/engine/builtin_fx/HarmonyStageSpatial.h new file mode 100644 index 000000000..d032d40ab --- /dev/null +++ b/engine/builtin_fx/HarmonyStageSpatial.h @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include +namespace armix::harmony { +// A fixed-clock backing-only virtual stage, not individualized HRTF rendering. +// Per-voice far-ear precedence timing and two physically separated early taps +// supplement the existing ONE shared room. No modulated delay or polarity flips. +class BackingStageSpatial final { +public: + static constexpr int voices=5; + static constexpr std::size_t earCapacity=128; + struct Gains {float direct=1.f,early=0.f,late=0.f;}; + struct Output {float directL=0, directR=0, earlyL=0, earlyR=0, roomL=0, roomR=0;}; + static Gains gains(float space) noexcept { + const float s=std::clamp(space,0.f,1.f); + return {1.f-.62f*s,.49f*s,1.08f*s}; + } + bool prepare(double rate) noexcept { + if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; + const auto delay=static_cast(std::lround(rate*.00022)); + if(delay<2||delay>=earCapacity)return false; + farEarDelay_=delay; + // Head-shadow proxy: the contralateral signal is gently softened + // before a fixed precedence delay. Prepared once per device rate. + // Not a measured HRTF and never applied to the original dry lead. + farEarLowpassAlpha_=static_cast( + 1.-std::exp(-2.*3.141592653589793*4100./rate)); + if(!(farEarLowpassAlpha_>0.f&&farEarLowpassAlpha_<1.f))return false; + farEarLowpassState_.fill(0.f); + for(auto& ring:farEarHistory_)ring.fill(0.f); + cursor_=0; + return true; + } + Output place(int singer,float source,float firstReflection, + float secondReflection,float mixL,float mixR, + float space) noexcept { + // Engine calls with validated singer indices [0,4]. + const auto i=static_cast(singer); + auto& ring=farEarHistory_[i]; + float& filtered=farEarLowpassState_[i]; + filtered+=farEarLowpassAlpha_*(source-filtered); + // Store filtered signal for the far ear only. The near ear keeps the + // original pitch-synchronous PCM unchanged. Reuse the old fixed ring: + // no extra audio buffer, allocation or reported latency. + ring[cursor_]=filtered; + const float delayed=ring[(cursor_+earCapacity-farEarDelay_)&(earCapacity-1)]; + const float sum=std::abs(mixL)+std::abs(mixR); + const float direction=sum>1.e-9f?(mixR-mixL)/sum:0.f; + // Only the quieter, contralateral ear carries the tiny fixed lag. + // Space crossfades the level, NOT the delay (no Doppler sweep). + const float cross=.68f*std::clamp(space,0.f,1.f)* + std::clamp(2.15f*std::abs(direction),0.f,1.f); + const float far=source*(1.f-cross)+delayed*cross; + const float left=(direction>0.f?far:source)*mixL; + const float right=(direction<0.f?far:source)*mixR; + // Center backing voice otherwise coincides with the center lead. + // Recess its *direct* component slightly but retain early and + // shared-room sends: a modest DRR cue, not a volume duck on lead. + // At Space 0 the original direct output is bit-for-bit unchanged. + const float centerAmount=1.f-std::clamp( + 1.7f*std::abs(direction),0.f,1.f); + const float centerRecess=1.f-.17f* + std::clamp(space,0.f,1.f)*centerAmount; + // Early sound spreads in both directions with positive polarity: + // first reflection is contralateral, second modestly ipsilateral. + const float earlyLeft=.68f*firstReflection*mixR+ + .32f*secondReflection*(.67f*mixL+.33f*mixR); + const float earlyRight=.68f*firstReflection*mixL+ + .32f*secondReflection*(.33f*mixL+.67f*mixR); + return {left*centerRecess,right*centerRecess, + earlyLeft,earlyRight,left,right}; + } + void advance() noexcept {cursor_=(cursor_+1)&(earCapacity-1);} + std::size_t farEarDelaySamples()const noexcept{return farEarDelay_;} +private: + std::array,voices> farEarHistory_{}; + std::array farEarLowpassState_{}; + float farEarLowpassAlpha_=0.f; + std::size_t cursor_=0,farEarDelay_=0; +}; +} // namespace armix::harmony diff --git a/engine/builtin_fx/HarmonyStereoFold.h b/engine/builtin_fx/HarmonyStereoFold.h new file mode 100644 index 000000000..8d6f4f854 --- /dev/null +++ b/engine/builtin_fx/HarmonyStereoFold.h @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include + +// Callback-owned analysis ONLY, not an audible stereo output mixer. +// Recover music/vocal guide PCM when opposite-polarity stereo cancels L+R. +// Normal correlated stereo remains the exact legacy sum; near-opposition +// needs two-threshold hysteresis and a smoothed phase-aware sign fold. +// Constant-work, fixed-state, lock/heap-free, zero added sample latency. +namespace armix::harmony { +class StereoPhaseSafeFold final { +public: + bool prepare(double rate) noexcept { + if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; + evidenceAlpha_=static_cast(1.-std::exp(-1./(rate*.020))); + blendAlpha_=static_cast(1.-std::exp(-1./(rate*.015))); + reset(); + return true; + } + void reset() noexcept { + energyL_=0.f;energyR_=0.f;cross_=0.f;amount_=0.f; + antiCorrelated_=false; + } + float process(float left,float right) noexcept { + // Both callers sanitize nonfinite source PCM. Limit only correlation + // evidence amplitude, never change a valid dry stereo source. + const float l=std::clamp(left,-4.f,4.f); + const float r=std::clamp(right,-4.f,4.f); + energyL_+=evidenceAlpha_*(l*l-energyL_); + energyR_+=evidenceAlpha_*(r*r-energyR_); + cross_+=evidenceAlpha_*(l*r-cross_); + const float power=.5f*(energyL_+energyR_); + if(power<1.e-8f)antiCorrelated_=false; + else if(antiCorrelated_){ + if(cross_>-.55f*power)antiCorrelated_=false; + }else if(cross_<-.78f*power)antiCorrelated_=true; + amount_+=blendAlpha_*((antiCorrelated_?1.f:0.f)-amount_); + // amount=0 -> original 0.5*(L+R) for ordinary audio. + // amount=1 -> recovered 0.5*(L-R). + // Use bounded evidence samples for the return as well: finite + // but huge external float PCM would otherwise overflow L+R before + // pitch/Music Guide filtering. + return .5f*(l+r)-amount_*r; + } + float rescueAmount() const noexcept{return amount_;} +private: + float evidenceAlpha_=0.f,blendAlpha_=0.f; + float energyL_=0.f,energyR_=0.f,cross_=0.f,amount_=0.f; + bool antiCorrelated_=false; +}; +} // namespace armix::harmony diff --git a/engine/builtin_fx/VocalThrow.h b/engine/builtin_fx/VocalThrow.h new file mode 100644 index 000000000..aa3cfbd1b --- /dev/null +++ b/engine/builtin_fx/VocalThrow.h @@ -0,0 +1,370 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include +#include +#include + +// ArSon Vocal Throw. One audio-thread owner; preparation allocates on CONTROL. +// The microphone's dry PCM is never buffered or delayed. A rolling history +// freezes the last word/phrase for tempo-spaced stereo echoes. All samples and +// triggers run on the existing native ChannelId PCM callback, never WebView. +namespace armix::builtin_fx { +struct VocalThrowSettings final { + int mode=2; // 0 manual, 1 automatic, 2 hybrid + float bpm=120.f; // explicit/host or tap BPM (not claimed auto-detected) + int division=0; // 0 quarter, 1 eighth, 2 dotted eighth, 3 half + int repeats=3; + float captureMs=460.f; + float silenceMs=220.f; + float thresholdDb=-35.f; + float wet=.42f; + float decay=.55f; // successive repeat amplitude multiplier + float ducking=.7f; // suppress echo while lead vocalist is active +}; +class VocalThrow final { +public: + static constexpr int addedLatencySamples=0; + static constexpr int maxRepeats=6; + static constexpr float maxCaptureMs=1500.f; + struct PreparedEdit { + VocalThrowSettings settings{}; + double sampleRate=0.; + std::uint32_t intervalSamples=0, captureSamples=0, silenceSamples=0; + float gateLinear=0.f; + bool valid=false; + }; + static bool validSettings(const VocalThrowSettings& s) noexcept { + return s.mode>=0&&s.mode<=2&&s.division>=0&&s.division<=3&& + s.repeats>=1&&s.repeats<=maxRepeats&& + std::isfinite(s.bpm)&&s.bpm>=60.f&&s.bpm<=200.f&& + std::isfinite(s.captureMs)&&s.captureMs>=80.f&&s.captureMs<=maxCaptureMs&& + std::isfinite(s.silenceMs)&&s.silenceMs>=80.f&&s.silenceMs<=900.f&& + std::isfinite(s.thresholdDb)&&s.thresholdDb>=-65.f&&s.thresholdDb<=-15.f&& + std::isfinite(s.wet)&&s.wet>=0.f&&s.wet<=1.f&& + std::isfinite(s.decay)&&s.decay>=.15f&&s.decay<=.9f&& + std::isfinite(s.ducking)&&s.ducking>=0.f&&s.ducking<=1.f; + } + static bool prepareEdit(const VocalThrowSettings& s,double sampleRate,PreparedEdit& out) noexcept { + if(!validSettings(s)||!std::isfinite(sampleRate)|| + sampleRate<8000.||sampleRate>192000.)return false; + constexpr std::array beats{{1.,.5,.75,2.}}; + PreparedEdit next{}; + next.settings=s;next.sampleRate=sampleRate; + next.intervalSamples=std::max(1u,static_cast( + std::llround(60.*sampleRate*beats[static_cast(s.division)]/s.bpm))); + next.captureSamples=std::max(1u,static_cast( + std::llround(sampleRate*s.captureMs/1000.))); + next.silenceSamples=std::max(1u,static_cast( + std::llround(sampleRate*s.silenceMs/1000.))); + next.gateLinear=static_cast(std::pow(10.,s.thresholdDb/20.)); + next.valid=next.gateLinear>0.f; + out=next;return true; + } + // CONTROL thread only, before publishing the insert. Maximum memory is + // bounded by the selected device rate and independent of song duration. + bool prepare(double rate) { + PreparedEdit packet{}; + if(!prepareEdit(VocalThrowSettings{},rate,packet))return false; + const auto historyFrames=static_cast(std::ceil(rate*2.5))+4; + const auto freezeFrames=static_cast(std::ceil(rate*maxCaptureMs/1000.))+4; + if(historyFrames>500000||freezeFrames>300000)return false; + historyL_.assign(historyFrames,0.f); + historyR_.assign(historyFrames,0.f); + // Two independent tails: new phrases never overwrite an active echo. + for(auto& voice:voices_) { + voice.freezeL.assign(freezeFrames,0.f); + voice.freezeR.assign(freezeFrames,0.f); + } + rate_=rate;ready_=true;settings_=packet;reset(); + return true; + } + // CONTROL, before publication. No vector resizing during state restore. + bool resetUnpublished(const VocalThrowSettings& settings) noexcept { + PreparedEdit next{}; + if(!ready_||!prepareEdit(settings,rate_,next))return false; + settings_=next;reset();return true; + } + // AUDIO: trivially copied, completely validated, no heap/locks. + bool applyPrepared(const PreparedEdit& edit) noexcept { + if(!ready_||!edit.valid||edit.sampleRate!=rate_|| + !validSettings(edit.settings)||edit.intervalSamples==0|| + edit.captureSamples==0||edit.captureSamples>voices_[0].freezeL.size()|| + edit.silenceSamples==0)return false; + settings_=edit;return true; + } + // AUDIO: incoming transport interval is already computed on CONTROL. + // A zero interval explicitly falls back to accepted song/TAP BPM. Each + // frozen tail keeps its interval when a backing track changes tempo. + void setMusicIntervalSamples(std::uint32_t samples) noexcept { + musicIntervalSamples_=samples; + gridValid_=false; // BPM-only mode never claims a measured beat grid. + } + // AUDIO: the JUCE insert reads the one accepted ChannelId block clock + // and control-prepared music onset anchor. Onsets are observed in 10ms + // windows, so beat-phase is approximate (not sample-perfect detection). + // The local->graph sample mapping is taken before every FX processing + // block; it works even when the insert was added after playback began. + void setMusicBeatGrid(std::uint32_t intervalSamples, + std::uint64_t anchorFrame, + std::uint64_t blockStartFrame, + bool locked) noexcept { + musicIntervalSamples_=locked?intervalSamples:0; + gridValid_=locked&&intervalSamples>0; + gridAnchorFrame_=anchorFrame; + gridBlockStartFrame_=blockStartFrame; + gridLocalStartFrame_=clock_; + } + // AUDIO: triggers the most recent word/phrase, preferring the latest + // vocal end if the singer stopped within the last 700 ms. + bool throwNow() noexcept { + if(!ready_||recorded_==0||lastSoundEnd_==0||clock_(rate_*.7); + if(clock_-lastSoundEnd_>recent)return false; // reject stale/silent cues + const bool ended=quiet_>0; + // Auto already threw this finished phrase. A late manual click must + // not produce a second identical echo in Hybrid mode. + if(ended && lastSoundEnd_==autoTriggeredPhraseEnd_)return false; + const bool accepted=freezeAt(ended?lastSoundEnd_:clock_); + if(accepted)manualInCurrentPhrase_=true; + return accepted; + } + void processStereo(float* left,float* right,std::size_t frames) noexcept { + if(!ready_||!left||!right)return; + const bool mono=left==right; + const std::uint32_t maxQuiet=static_cast(rate_); + const std::uint32_t phraseGap=static_cast(rate_*.06); + const std::uint32_t minVoice=static_cast(rate_*.08); + for(std::size_t i=0;ienvelope_?envAttack_:envRelease_; + envelope_=coeff*envelope_+(1.f-coeff)*peak; + if(envelope_<1.0e-20f)envelope_=0.f; + const bool singing=envelope_>=settings_.gateLinear; + if(singing) { + if(quiet_>phraseGap) { + voiced_=0; + manualInCurrentPhrase_=false; // genuinely new sung phrase + autoTriggeredPhraseEnd_=0; + } + quiet_=0; + voiced_=std::min(voiced_+1,maxQuiet); + lastSoundEnd_=clock_; + if(voiced_>=minVoice)armed_=true; + } else { + if(quiet_=settings_.silenceSamples) { + if(settings_.settings.mode!=0 && !manualInCurrentPhrase_ + && clock_>=nextAutoEligible_) { + if(freezeAt(lastSoundEnd_)) { + autoTriggeredPhraseEnd_=lastSoundEnd_; + nextAutoEligible_=clock_+ + static_cast(rate_*.4); + } + } + armed_=false; + } + } + float echoL=0.f,echoR=0.f,activeTapGain=0.f; + for(auto& voice:voices_) { + if(voice.copying)copyFrozenChunk(voice); + if(!voice.playing)continue; + // Fixed six-tap limit, constant time; voice owns its capture + // and scheduling packet even when BPM changes mid-tail. + for(int tap=0;tap(tap); + const std::uint64_t start=voice.repeatStarts[slot]; + if(clock_<=start)continue; + const std::uint64_t offset=clock_-start-1; + if(offset>=voice.freezeCount)continue; + float ramp=1.f; + if(voice.edgeSamples>0) { + ramp=std::min(ramp,static_cast(offset)/ + static_cast(voice.edgeSamples)); + ramp=std::min(ramp,static_cast(voice.freezeCount-offset-1)/ + static_cast(voice.edgeSamples)); + } + const auto p=static_cast(offset); + const float gain=voice.repeatGains[slot]*std::max(0.f,ramp); + echoL+=voice.freezeL[p]*gain;echoR+=voice.freezeR[p]*gain; + activeTapGain+=gain; + } + const auto end=voice.repeatStarts[ + static_cast(voice.active.settings.repeats-1)] + +voice.freezeCount; + if(clock_>end)voice.playing=false; + } + // Slew wet level and ducking independently to avoid zipper + // noise on rapid GUI edits and the next vocal entrance. + const float duckTarget=singing?1.f-settings_.settings.ducking:1.f; + duck_=duck_*duckCoeff_+duckTarget*(1.f-duckCoeff_); + wetSmoothed_=wetSmoothed_*duckCoeff_+ + settings_.settings.wet*(1.f-duckCoeff_); + // Concert-safe overlap headroom: many closely spaced taps, + // including two phrases, must not multiply the wet peak by 6x. + // No attenuation for ordinary nonoverlapping delays. + const float echoGain=(wetSmoothed_*duck_)/ + std::max(1.f,activeTapGain*wetSmoothed_); + left[i]=dryL+echoL*echoGain; + if(!mono)right[i]=dryR+echoR*echoGain; + } + } + // AUDIO only: discard historical vocalist PCM and pending echo tails + // when the FX finishes bypassing or is re-enabled. Do not clear vector + // storage here: 192kHz history could cost ~480,000 writes in one ASIO + // callback. recorded_=0 fences stale samples until truly overwritten. + // Retain the accepted settings, sample clock and completed cue counter. + void invalidateCaptureHistory() noexcept { + recorded_=0; + lastSoundEnd_=nextAutoEligible_=autoTriggeredPhraseEnd_=0; + voiced_=quiet_=0; + armed_=manualInCurrentPhrase_=false; + envelope_=0.f; + for(auto& voice:voices_) { + voice.copying=false;voice.playing=false; + voice.freezeCount=0;voice.copyIndex=0; + } + } + [[nodiscard]] bool ready() const noexcept{return ready_;} + [[nodiscard]] VocalThrowSettings settingsForTests() const noexcept{return settings_.settings;} + [[nodiscard]] bool echoActive() const noexcept{ + for(const auto& voice:voices_)if(voice.playing)return true; + return false; + } + [[nodiscard]] unsigned throwCount() const noexcept{return throwCount_;} + [[nodiscard]] double sampleRate() const noexcept{return rate_;} +private: + struct TailVoice final { + std::vector freezeL,freezeR; + std::array repeatStarts{}; + std::array repeatGains{}; + PreparedEdit active{}; + std::uint64_t copyEnd=0,freezeCount=0; + std::size_t copyIndex=0,sourceIndex=0; + std::uint32_t edgeSamples=0; + std::uint64_t gridAnchorFrame=0,gridCueFrame=0,gridCueLocal=0; + bool gridValid=false; + bool copying=false,playing=false; + }; + bool freezeAt(std::uint64_t end) noexcept { + if(end==0||end>clock_||historyL_.empty())return false; + // Bounded polyphony: do not cut or overwrite an existing phrase. + // A full pool rejects a cue (and reports this via native ACK). + TailVoice* slot=nullptr; + for(auto& voice:voices_) { + if(!voice.playing&&!voice.copying){slot=&voice;break;} + } + if(!slot)return false; + const auto available=std::min(end,recorded_); + const auto count=std::min(available,settings_.captureSamples); + if(count(rate_*.025))return false; + slot->copyEnd=end; + slot->freezeCount=count; + slot->copyIndex=0; + slot->sourceIndex=static_cast((end-count)%historyL_.size()); + slot->edgeSamples=static_cast(rate_*.004); + slot->active=settings_; + if(musicIntervalSamples_) + slot->active.intervalSamples=musicIntervalSamples_; + // Freeze the same accepted beat grid as the captured phrase. + // Later tempo changes, stale epochs or an unplugged MUSIC WIRE do + // not re-time an already accepted echo tail. + slot->gridValid=gridValid_; + slot->gridAnchorFrame=gridAnchorFrame_; + slot->gridCueFrame=gridBlockStartFrame_+ + (gridValid_?clock_-gridLocalStartFrame_:0); + slot->gridCueLocal=clock_; + slot->copying=true; + ++throwCount_; + return true; + } + void copyFrozenChunk(TailVoice& voice) noexcept { + // A fixed 24-frame budget each sample. Contiguous bulk copying + // replaces per-frame division/modulo in the former implementation. + const std::size_t left=static_cast(voice.freezeCount)-voice.copyIndex; + const std::size_t n=std::min({24,left, + historyL_.size()-voice.sourceIndex}); + std::copy_n(historyL_.data()+voice.sourceIndex,n, + voice.freezeL.data()+voice.copyIndex); + std::copy_n(historyR_.data()+voice.sourceIndex,n, + voice.freezeR.data()+voice.copyIndex); + voice.copyIndex+=n; + voice.sourceIndex+=n; + if(voice.sourceIndex==historyL_.size())voice.sourceIndex=0; + if(voice.copyIndex!=voice.freezeCount)return; + voice.copying=false; + std::uint64_t first=std::max( + clock_,voice.copyEnd+voice.active.intervalSamples); + if(voice.gridValid && voice.active.intervalSamples && + first>=voice.gridCueLocal) { + const auto interval=voice.active.intervalSamples; + const auto globalFirst=voice.gridCueFrame+ + (first-voice.gridCueLocal); + // Quantize only the echo onset, never the singer's dry PCM. + // Use unsigned arithmetic and bound grid correction to one + // subdivision, protecting against a stale/future anchor. + if(globalFirst>=voice.gridAnchorFrame) { + const auto remainder= + (globalFirst-voice.gridAnchorFrame)%interval; + if(remainder)first+=interval-remainder; + } else if(voice.gridAnchorFrame-globalFirst<=interval) { + first+=voice.gridAnchorFrame-globalFirst; + } + } + float amplitude=1.f; + for(int tap=0;tap(tap); + voice.repeatStarts[slot]=first+ + static_cast(tap)*voice.active.intervalSamples; + voice.repeatGains[slot]=amplitude; + amplitude*=voice.active.settings.decay; + } + voice.playing=true; + } + void reset() noexcept { + clock_=lastSoundEnd_=nextAutoEligible_=autoTriggeredPhraseEnd_=0; + recorded_=writeIndex_=0; + voiced_=quiet_=0; + armed_=manualInCurrentPhrase_=false; + envelope_=0.f;duck_=1.f;throwCount_=0; + wetSmoothed_=settings_.settings.wet; + if(rate_>0) { + envAttack_=static_cast(std::exp(-1./(rate_*.004))); + envRelease_=static_cast(std::exp(-1./(rate_*.018))); + duckCoeff_=static_cast(std::exp(-1./(rate_*.008))); + } + for(auto& voice:voices_) { + voice.copyEnd=voice.freezeCount=0; + voice.copyIndex=voice.sourceIndex=0; + voice.edgeSamples=0; + voice.copying=voice.playing=false; + voice.gridValid=false; + voice.gridAnchorFrame=voice.gridCueFrame=voice.gridCueLocal=0; + voice.repeatStarts.fill(0);voice.repeatGains.fill(0.f); + } + std::fill(historyL_.begin(),historyL_.end(),0.f); + std::fill(historyR_.begin(),historyR_.end(),0.f); + } + PreparedEdit settings_{}; + std::vector historyL_,historyR_; + std::array voices_{}; + std::uint64_t clock_=0,lastSoundEnd_=0,nextAutoEligible_=0,autoTriggeredPhraseEnd_=0; + std::size_t recorded_=0,writeIndex_=0; + std::uint32_t voiced_=0,quiet_=0; + float envelope_=0.f,envAttack_=0.f,envRelease_=0.f,duckCoeff_=0.f; + float duck_=1.f,wetSmoothed_=.42f; + double rate_=0.; + std::uint32_t musicIntervalSamples_=0; + std::uint64_t gridAnchorFrame_=0,gridBlockStartFrame_=0,gridLocalStartFrame_=0; + bool gridValid_=false; + unsigned throwCount_=0; + bool armed_=false,manualInCurrentPhrase_=false,ready_=false; +}; +} // namespace armix::builtin_fx diff --git a/engine/builtin_fx/VocalThrowProcessor.h b/engine/builtin_fx/VocalThrowProcessor.h new file mode 100644 index 000000000..793d628cd --- /dev/null +++ b/engine/builtin_fx/VocalThrowProcessor.h @@ -0,0 +1,275 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "VocalThrow.h" +#include "FxSpsc.h" +#include "../core/RealtimeNativeFxControl.h" +#include "../core/NativeBeatFrameContext.h" +#include +#include +#include +#include + +// JUCE adapter for the existing ChannelId FX rack. All setting/throw requests +// are bound to an exact accepted graph instance by ConsoleWindow before they +// enter the control->audio SPSC. Audio never posts a WebView event. +namespace armix::builtin_fx { +class VocalThrowProcessor final : public juce::AudioProcessor, + public armix::mixer::RealtimeNativeFxControl { +public: + static constexpr const char* catalogIdentity="armix.builtin.vocal-throw.v1"; + enum class CommandKind : std::uint8_t { settings, trigger }; + struct Completion { + std::uint64_t requestId=0; + VocalThrowSettings settings{}; + CommandKind kind=CommandKind::settings; + bool applied=false; + bool bypassed=false; + }; + VocalThrowProcessor() + : juce::AudioProcessor(BusesProperties() + .withInput("Input",juce::AudioChannelSet::stereo(),true) + .withOutput("Output",juce::AudioChannelSet::stereo(),true)) { + setLatencySamples(VocalThrow::addedLatencySamples); + } + const juce::String getName() const override {return "ArSon Vocal Throw";} + bool acceptsMidi() const override{return false;} + bool producesMidi() const override{return false;} + bool isMidiEffect() const override{return false;} + double getTailLengthSeconds() const override{return 16.;} + int getNumPrograms() override{return 1;} + int getCurrentProgram() override{return 0;} + void setCurrentProgram(int) override{} + const juce::String getProgramName(int) override{return "Current";} + void changeProgramName(int,const juce::String&) override{} + bool hasEditor() const override{return false;} + juce::AudioProcessorEditor* createEditor() override{return nullptr;} + bool isBusesLayoutSupported(const BusesLayout& layout) const override { + return layout.getMainInputChannelSet()==juce::AudioChannelSet::stereo()&& + layout.getMainOutputChannelSet()==juce::AudioChannelSet::stereo(); + } + void prepareToPlay(double sampleRate,int) override { + // CONTROL/device thread, only after the prior audio callback stops. + // The DSP may already have APPLIED an edit whose completion is still + // waiting in the AUDIO->CONTROL SPSC. Rebuilding from accepted_ + // would silently undo that change on a buffer/device/rate restart. + // Preserve the actual last DSP target, just like Compressor does. + // Cold Show restore (not yet prepared) takes accepted_ instead. + const auto latest=core_.ready()?core_.settingsForTests():accepted_; + // Each device epoch gets a new frame clock. A previously accepted + // auto BPM interval is invalid if the hardware sample rate changed. + lastTempoBpm_=0.f;lastTempoDivision_=-1; + bypassed_=false;captureInvalidated_=false; + musicInterval_.store(0,std::memory_order_release); + ready_=core_.prepare(sampleRate)&&core_.resetUnpublished(latest); + if(ready_)rate_=sampleRate; + } + void releaseResources() override{ + ready_=false;musicInterval_.store(0,std::memory_order_release); + } + void processBlock(juce::AudioBuffer& pcm,juce::MidiBuffer&) override { + juce::ScopedNoDenormals noDenormals; + if(!ready_||pcm.getNumChannels()<2||pcm.getNumSamples()<=0)return; + // consumeRealtimeEdits() snapshots the accepted tempo BEFORE any + // manual cue in the same block; bypassed inserts use the same path. + consumeRealtimeEdits(); + core_.processStereo(pcm.getWritePointer(0),pcm.getWritePointer(1), + static_cast(pcm.getNumSamples())); + observedThrows_.store(core_.throwCount(),std::memory_order_relaxed); + observedTail_.store(core_.echoActive(),std::memory_order_relaxed); + } + void processBlock(juce::AudioBuffer&,juce::MidiBuffer&) override{} + void onRealtimeBypass(bool requested,bool fully) noexcept override { + // Called by the single native render owner before any FX edits or + // PCM in this block. Preserve a playing tail through fade-out; clear + // only after full bypass, or on any re-enable (including quick flips). + const bool clear=(requested&&fully&&!captureInvalidated_) || + (!requested&&bypassed_); + if(clear&&ready_) { + core_.invalidateCaptureHistory(); + observedTail_.store(false,std::memory_order_relaxed); + } + if(requested&&fully)captureInvalidated_=true; + if(!requested)captureInvalidated_=false; + bypassed_=requested; + } + void consumeRealtimeEdits() noexcept override { + if(!ready_)return; + // One bounded attempt, never spin in ASIO. The native PCM callback + // is the ONLY owner of a valid block sample clock. A stale epoch, + // graph revision, or torn control publication falls back to TAP. + const auto block=armix::mixer::NativeBeatFrameScope::current(); + const auto v0=gridVersion_.load(std::memory_order_acquire); + bool valid=block.valid && (v0&1U)==0U; + std::uint64_t anchor=0; + std::uint32_t interval=0; + if(valid) { + const auto epoch=gridEpoch_.load(std::memory_order_relaxed); + const auto revision=gridRevision_.load(std::memory_order_relaxed); + anchor=gridAnchor_.load(std::memory_order_relaxed); + interval=musicInterval_.load(std::memory_order_relaxed); + const auto v1=gridVersion_.load(std::memory_order_acquire); + valid=v0==v1 && block.epoch==epoch && + block.revision==revision && interval>0; + } + // Low-confidence music can provide a real BPM while its beat + // position is ambiguous. Keep that useful interval, but do NOT + // claim grid quantization. If the whole transport is stale/torn, + // fall all the way back to accepted Manual/TAP. + if(valid&&anchor>0&&anchor<=block.startFrame) + core_.setMusicBeatGrid(interval,anchor,block.startFrame,true); + else + core_.setMusicIntervalSamples(valid?interval:0); + Edit e{}; + if(!done_.canPush()||!commands_.pop(e))return; + // CONTROL can reject an expired UI request while ASIO is stopped. + // A delayed callback must NEVER play its old vocal cue on resume. + // One acquire load and one fixed-size completion; no RT clock/heap. + // Multiple UI requests may time out while ASIO is suspended. + // A single last-cancelled ID is NOT sufficient: later timeouts + // would reactivate earlier queued cues. 32 cancellation slots + // cover the 32-entry command FIFO with fixed bounded RT reads. + bool expired=false; + for(const auto& cancelled:cancelledIds_) + expired=expired || + cancelled.load(std::memory_order_acquire)==e.id; + const bool blockedTrigger=e.kind==CommandKind::trigger && bypassed_; + // Settings are remembered while OFF; performance cues are not + // scheduled into a stopped capture clock or revived on rack ON. + const bool applied=!expired&&!blockedTrigger && + (e.kind==CommandKind::settings? + core_.applyPrepared(e.prepared):core_.throwNow()); + (void)done_.push({e.id,e.prepared.settings,e.kind,applied, + blockedTrigger}); + } + // CONTROL-thread song/auto BPM, deliberately independent of accepted + // serialized preset BPM. No queue ACK storm or GUI state overwrite. + void publishMusicBpm(float bpm) noexcept { + if(!ready_||!std::isfinite(bpm)||bpm<60.f||bpm>200.f) { + if(lastTempoBpm_!=0.f) { + lastTempoBpm_=0.f;lastTempoDivision_=-1; + musicInterval_.store(0,std::memory_order_release); + } + return; + } + // The 12Hz message timer may deliver the same accepted tempo many + // times. Never recompute power/division or publish redundant atomics. + if(lastTempoBpm_==bpm && lastTempoDivision_==accepted_.division) + return; + auto settings=accepted_;settings.bpm=bpm; + VocalThrow::PreparedEdit packet{}; + const auto valid=VocalThrow::prepareEdit(settings,rate_,packet); + lastTempoBpm_=valid?bpm:0.f; + lastTempoDivision_=valid?accepted_.division:-1; + musicInterval_.store(valid?packet.intervalSamples:0, + std::memory_order_release); + } + // CONTROL ONLY: one source-derived BPM+phase packet is fenced by the + // accepted native PCM epoch/revision. The sample-grid anchor comes from + // onset timestamped INSIDE the same audio callback (10ms granularity). + // Writer is the existing serialized JUCE timer, not a second thread. + void publishMusicGrid(float bpm,std::uint64_t anchorFrame, + std::uint64_t epoch, + std::uint64_t revision) noexcept { + gridVersion_.fetch_add(1,std::memory_order_acq_rel); // odd, unstable + publishMusicBpm(bpm); + gridAnchor_.store(bpm>=60.f&&bpm<=200.f?anchorFrame:0, + std::memory_order_relaxed); + gridEpoch_.store(epoch,std::memory_order_relaxed); + gridRevision_.store(revision,std::memory_order_relaxed); + gridVersion_.fetch_add(1,std::memory_order_release); // even, ready + } + bool queueSettings(const VocalThrowSettings& settings,std::uint64_t id) noexcept { + if(!ready_||id==0)return false; + Edit e{};e.id=id;e.kind=CommandKind::settings; + if(!VocalThrow::prepareEdit(settings,rate_,e.prepared))return false; + return commands_.push(e); + } + bool queueTrigger(std::uint64_t id) noexcept { + if(!ready_||id==0)return false; + Edit e{};e.id=id;e.kind=CommandKind::trigger; + return commands_.push(e); + } + void cancelQueuedRequest(std::uint64_t id) noexcept { + if(id)cancelledIds_[cancelWrite_++ % cancelledIds_.size()].store( + id,std::memory_order_release); // CONTROL single writer + } + bool pollCompletion(Completion& out) noexcept { + if(!done_.pop(out))return false; + if(out.applied&&out.kind==CommandKind::settings)accepted_=out.settings; + return true; + } + VocalThrowSettings acceptedSettings() const noexcept{return accepted_;} + double acceptedSampleRate() const noexcept{return rate_;} + unsigned observedThrowCount() const noexcept { + return observedThrows_.load(std::memory_order_relaxed); + } + bool observedTailActive() const noexcept { + return observedTail_.load(std::memory_order_relaxed); + } + bool isReady() const noexcept{return ready_;} + void sealForRealtime() noexcept override{published_=true;} + bool stateSnapshotQuiescent() const noexcept override{ + return commands_.empty()&&done_.empty(); + } + void getStateInformation(juce::MemoryBlock& out) override { + juce::MemoryOutputStream writer(out,false); + writer.writeInt(0x41565448); // AVTH + writer.writeInt(1); + writer.writeInt(accepted_.mode); + writer.writeFloat(accepted_.bpm); + writer.writeInt(accepted_.division); + writer.writeInt(accepted_.repeats); + writer.writeFloat(accepted_.captureMs); + writer.writeFloat(accepted_.silenceMs); + writer.writeFloat(accepted_.thresholdDb); + writer.writeFloat(accepted_.wet); + writer.writeFloat(accepted_.decay); + writer.writeFloat(accepted_.ducking); + } + bool restoreUnpublishedState(const void* data,int bytes) { + if(published_||!data||bytes!=48||!commands_.empty()||!done_.empty()) + return false; + juce::MemoryInputStream reader(data,static_cast(bytes),false); + if(reader.readInt()!=0x41565448||reader.readInt()!=1)return false; + VocalThrowSettings s{}; + s.mode=reader.readInt(); + s.bpm=reader.readFloat(); + s.division=reader.readInt(); + s.repeats=reader.readInt(); + s.captureMs=reader.readFloat(); + s.silenceMs=reader.readFloat(); + s.thresholdDb=reader.readFloat(); + s.wet=reader.readFloat(); + s.decay=reader.readFloat(); + s.ducking=reader.readFloat(); + if(!reader.isExhausted()||!VocalThrow::validSettings(s))return false; + if(ready_&&!core_.resetUnpublished(s))return false; + accepted_=s;return true; + } + void setStateInformation(const void* data,int bytes) override{ + (void)restoreUnpublishedState(data,bytes); + } +private: + struct Edit { + std::uint64_t id=0; + CommandKind kind=CommandKind::settings; + VocalThrow::PreparedEdit prepared{}; + }; + VocalThrow core_{}; + FxSpsc commands_{}; + FxSpsc done_{}; + VocalThrowSettings accepted_{}; + std::atomic observedThrows_{0}; + std::atomic musicInterval_{0}; + std::atomic gridVersion_{0},gridAnchor_{0}; + std::atomic gridEpoch_{0},gridRevision_{0}; + std::array,32> cancelledIds_{}; + std::uint32_t cancelWrite_=0; // CONTROL only + bool bypassed_=false,captureInvalidated_=false; // AUDIO only + std::atomic observedTail_{false}; + double rate_=0.; + float lastTempoBpm_=0.f; // CONTROL only + int lastTempoDivision_=-1; // CONTROL only + bool ready_=false,published_=false; +}; +} // namespace armix::builtin_fx diff --git a/engine/core/DynamicNativeSessionPublisher.h b/engine/core/DynamicNativeSessionPublisher.h index f867130fa..18ef3d10c 100644 --- a/engine/core/DynamicNativeSessionPublisher.h +++ b/engine/core/DynamicNativeSessionPublisher.h @@ -2,6 +2,8 @@ #pragma once #include "DynamicPreparedMixerBlock.h" #include "DynamicConsoleRoutingView.h" +#include "NativeMusicTempoMonitor.h" +#include "NativeBeatFrameContext.h" #include "RealtimeRoutePublisher.h" #include "RealtimeRenderPermit.h" #include @@ -124,8 +126,23 @@ class DynamicNativeSessionPublisher final { const auto status=publisher_.publish(std::move(next), expectedRevision,activeDeviceEpoch); switch(status) { - case Publisher::Result::applied: + case Publisher::Result::applied: { + const auto source=musicTempo_.selectedSource(); + if(source.value) { + const auto* published=publisher_.controlPrepared( + proposedDeviceEpoch,expectedRevision+1); + const auto* channel=published? + published->routing.find(source):nullptr; + const bool retained=published&&channel&& + (channel->role==ChannelRole::input|| + channel->role==ChannelRole::group|| + channel->role==ChannelRole::fxReturn)&& + published->graph.channelScheduled(source); + musicTempo_.onGraphCommitted(proposedDeviceEpoch, + expectedRevision,expectedRevision+1,retained); + } report.revision=expectedRevision+1;return report; + } case Publisher::Result::staleDevice: report.fault=Fault::staleDevice;break; case Publisher::Result::staleRevision: @@ -187,11 +204,20 @@ class DynamicNativeSessionPublisher final { if(!exclusive) { clearOutputs();return false; } + // One sample domain for all ChannelIds and their FX racks. This + // fixed-time callback-local scope also fences bypassed/stale inserts; + // no second transport thread, allocation or callback is introduced. + const auto startFrame=musicTempo_.beginAudioBlock(deviceEpoch,frames); + NativeBeatFrameScope frameScope{deviceEpoch,snap->graphRevision,startFrame}; // Prepared FX takes precedence over the legacy external callback. // NEVER invoke both: that would double-compress or double-reverb. // Snapshot ownership pins the M4 instance throughout this callback; // only control-thread retirement releases the shared owner. const auto dispatch=[&](ChannelId id,float* l,float* r,int n) noexcept { + // Analysis source is the installed ChannelId MUSIC PCM, before + // its VST rack; never microphone/echo/main unless explicitly + // selected and role-checked on CONTROL. No analysis on AUDIO. + musicTempo_.capture(id,l,r,n,snap->deviceEpoch,snap->graphRevision); const auto& acceptedFx=snap->prepared->fx; if(acceptedFx.render) acceptedFx.render(acceptedFx.context,id,l,r,n); @@ -204,6 +230,25 @@ class DynamicNativeSessionPublisher final { return ok; } + // CONTROL ONLY: choose an actual active backing input/GROUP/FX return. + // Preserve the one authoritative PCM graph and reject stale selectors. + bool setMusicTempoSource(std::uint64_t epoch,std::uint64_t revision, + ChannelId source,double sampleRate) noexcept { + const auto* p=publisher_.controlPrepared(epoch,revision); + if(!p)return false; + if(source.value) { + const auto* ch=p->routing.find(source); + if(!ch || (ch->role!=ChannelRole::input && + ch->role!=ChannelRole::group && + ch->role!=ChannelRole::fxReturn) || + !p->graph.channelScheduled(source))return false; + } + return musicTempo_.select(source,epoch,revision,sampleRate); + } + NativeMusicTempoMonitor::State pollMusicTempo(std::uint64_t epoch, + std::uint64_t revision) noexcept { + return musicTempo_.poll(epoch,revision); + } // CONTROL ONLY; pointer is valid until the next structural commit. // The caller must COPY needed fields before yielding the writer thread. // Future WebView event serializes this only after native ACK, never draft. @@ -290,6 +335,7 @@ class DynamicNativeSessionPublisher final { } private: Publisher publisher_; + NativeMusicTempoMonitor musicTempo_{}; std::atomic_flag rendering_=ATOMIC_FLAG_INIT; }; } // namespace armix::mixer diff --git a/engine/core/LiveChannelFxGraph.h b/engine/core/LiveChannelFxGraph.h index 769bc927a..ed374c3e8 100644 --- a/engine/core/LiveChannelFxGraph.h +++ b/engine/core/LiveChannelFxGraph.h @@ -33,6 +33,7 @@ class LiveChannelFxGraph final { struct FxInstance final : juce::AudioProcessorListener { std::unique_ptr processor; RealtimeNativeFxControl* nativeControl=nullptr; // bound once OFF realtime + bool continuousBypassProcessing=false; // prepared once; no dynamic cast in RT juce::MidiBuffer midi; const juce::String catalogId; const juce::String name; @@ -61,7 +62,11 @@ class LiveChannelFxGraph final { bypassFade.prepare(false,processor?processor->getSampleRate():48000.0,0); if(processor){ nativeControl=dynamic_cast(processor.get()); - if(nativeControl)nativeControl->sealForRealtime(); + if(nativeControl){ + continuousBypassProcessing= + nativeControl->requiresContinuousBypassProcessing(); + nativeControl->sealForRealtime(); + } processor->addListener(this); } } @@ -116,14 +121,19 @@ class LiveChannelFxGraph final { } // G5C: atomic request from control; fade and scratch RT-owned. // Master rack bypass affects the WET/DRY envelope, never the remembered insert preference. - bypassFade.request(rackBypassed || bypassRequested.load(std::memory_order_relaxed)); + const bool requestedBypass=rackBypassed || + bypassRequested.load(std::memory_order_relaxed); + bypassFade.request(requestedBypass); if(samples<=0 || static_cast(samples)>dryLeft.size()) { juce::FloatVectorOperations::clear(left,std::max(0,samples)); juce::FloatVectorOperations::clear(right,std::max(0,samples)); processing.clear(std::memory_order_release); return; } - // Drain at most one native EQ control edit even while bypassed. + if(nativeControl) + nativeControl->onRealtimeBypass(requestedBypass, + bypassFade.fullyBypassed()); + // Drain at most one native FX control edit even while bypassed. // Fully bypassed plugins otherwise never call processBlock, which // would strand pending GUI commands until users turned them ON. if(nativeControl && bypassFade.fullyBypassed()) @@ -135,11 +145,16 @@ class LiveChannelFxGraph final { dryLeft[static_cast(i)]=l; dryRight[static_cast(i)]=r; } - if(bypassFade.fullyBypassed()||latencyChanged.load(std::memory_order_acquire)) { + const bool fullyBypassed=bypassFade.fullyBypassed(); + if((fullyBypassed&&!continuousBypassProcessing)|| + latencyChanged.load(std::memory_order_acquire)) { juce::FloatVectorOperations::copy(left,dryLeft.data(),samples); juce::FloatVectorOperations::copy(right,dryRight.data(),samples); processing.clear(std::memory_order_release);return; } + // Harmony alone remains timeline-warm while fully bypassed. + // The host consumes real PCM, but publishes the exact PDC dry path: + // no stale pitch history or room tail can leak on reactivation. const bool fading=bypassFade.transitioning(); try { float* planar[]{left,right}; @@ -152,7 +167,10 @@ class LiveChannelFxGraph final { juce::FloatVectorOperations::clear(left,samples); juce::FloatVectorOperations::clear(right,samples); } - if(fading)for(int i=0;i(i)]*mix.dry; right[i]=right[i]*mix.wet+dryRight[static_cast(i)]*mix.dry; diff --git a/engine/core/NativeBeatFrameContext.h b/engine/core/NativeBeatFrameContext.h new file mode 100644 index 000000000..c77f79b08 --- /dev/null +++ b/engine/core/NativeBeatFrameContext.h @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include + +// A tiny callback-local sample-clock context, NOT a transport or second +// callback. The native ChannelId publisher owns the authoritative frame +// counter. JUCE's built-in VocalThrow reads the same context only while +// it is rendering as an insert on that callback thread. No heap or locks. +namespace armix::mixer { +struct NativeBeatFrameContext final { + std::uint64_t epoch=0,revision=0,startFrame=0; + bool valid=false; +}; +inline thread_local NativeBeatFrameContext currentNativeBeatFrame{}; + +class NativeBeatFrameScope final { +public: + explicit NativeBeatFrameScope(std::uint64_t epoch,std::uint64_t revision, + std::uint64_t startFrame) noexcept + : previous_(currentNativeBeatFrame) { + currentNativeBeatFrame={epoch,revision,startFrame,epoch!=0&&revision!=0}; + } + ~NativeBeatFrameScope() noexcept {currentNativeBeatFrame=previous_;} + NativeBeatFrameScope(const NativeBeatFrameScope&)=delete; + NativeBeatFrameScope& operator=(const NativeBeatFrameScope&)=delete; + static NativeBeatFrameContext current() noexcept { + return currentNativeBeatFrame; + } +private: + NativeBeatFrameContext previous_{}; +}; +} // namespace armix::mixer diff --git a/engine/core/NativeMusicTempoMonitor.h b/engine/core/NativeMusicTempoMonitor.h new file mode 100644 index 000000000..90c8a73ad --- /dev/null +++ b/engine/core/NativeMusicTempoMonitor.h @@ -0,0 +1,436 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "../builtin_fx/FxSpsc.h" +#include "DynamicChannelRoster.h" +#include +#include +#include +#include +#include +#include +#include + +// ArSon M2: source-specific music tempo observation inside the ONE installed +// ChannelId renderer. AUDIO only summarizes its explicitly selected music +// channel into 10ms energy frames and pushes a bounded SPSC. CONTROL owns all +// onset, pulse-correlation and tempo work. This is NOT a second audio engine. +namespace armix::mixer { +class MusicTempoEstimator final { +public: + struct Result final { + float bpm=0.f,confidence=0.f,phaseConfidence=0.f; + bool phaseLocked=false; + std::uint64_t beatAnchorTick=0,observationTick=0; + // Both are authoritative native callback sample-frame positions. + // Onset is quantized by the 10ms summary window; not sample-perfect + // transient detection or DAW-wide delay compensation. + std::uint64_t beatAnchorFrame=0,observationFrame=0; + bool locked=false; + // Last CONTROL-only scan's actual tempo-bin comparisons. Enables + // deterministic worst-case budget regression without wall-clock + // timing or instrumentation on the ASIO callback. + std::uint32_t scoringComparisons=0; + }; + void reset() noexcept { + previous_=floor_=0.f;count_=write_=0; + lastHit_=lastScan_=lastTick_=0; + stableCount_=0;candidateBpm_=0;result_={}; + } + void ingest(float energy,std::uint64_t tick, + std::uint64_t endingFrame=0) noexcept { + if(!std::isfinite(energy)||energy<0.f)energy=0.f; + if(lastTick_ && (tick<=lastTick_ || tick-lastTick_>4))reset(); + lastTick_=tick; + floor_+=.005f*(energy-floor_); + const float rise=energy-previous_; + // Attack transient only; sustained pads/bleed cannot retrigger + // every 10ms. 80ms refractory rejects the same drum's ringing. + if(tick>=lastHit_+8 && energy>.003f && + rise>std::max(.005f,floor_*.45f)) { + hits_[write_]={tick,std::min(1.f,rise),endingFrame}; + write_=(write_+1)%hits_.size(); + count_=std::min(count_+1,hits_.size()); + lastHit_=tick; + } + previous_=energy; + if(endingFrame)result_.observationFrame=endingFrame; + if(result_.locked && tick>lastHit_+320) { + result_.locked=false;result_.confidence=0.f; + result_.phaseLocked=false;result_.phaseConfidence=0.f; + candidateBpm_=stableCount_=0; + } + if(tick>=lastScan_+50) { + lastScan_=tick; + evaluate(); + } + } + Result result() const noexcept {return result_;} +private: + struct Hit { + std::uint64_t tick=0; + float strength=0.f; + std::uint64_t frame=0; + }; + std::array hits_{}; + std::size_t count_=0,write_=0; + std::uint64_t lastHit_=0,lastScan_=0,lastTick_=0; + float previous_=0.f,floor_=0.f; + int stableCount_=0,candidateBpm_=0; + Result result_{}; + + void evaluate() noexcept { + if(count_<7 || lastTick_<300 || lastTick_>lastHit_+320)return; + const auto at=[&](std::size_t i) noexcept ->const Hit& { + return hits_[(write_+hits_.size()-count_+i)%hits_.size()]; + }; + if(at(count_-1).tick-at(0).tick<300)return; + int bestBpm=0; + float bestScore=0.f; + // CONTROL-owned fixed stack scratch; no heap or unbounded history. + // Retain the incumbent candidate's score so a transient half/double + // time accent cannot steal an already convincing song clock. + std::array candidates{}; + // CONTROL ONLY, exact-score-preserving sparse candidate search. + // The former 121-BPM outer loop re-traversed the complete onset + // history for every candidate, adding unpredictable GUI timer work. + // Each onset pair can support only nearby BPM bins (<=3 periods). + // Enumerate each pair ONCE, derive the mathematically eligible BPM + // neighborhood, then use the original round/error/weight formula. + // Memory is the same 121-float fixed stack array; no heap, worker, + // allocations, callback scheduling or changed confidence threshold. + constexpr int minBpm=60,maxBpm=180; + constexpr float maxPairTicks=(6000.f/minBpm)*3.08f; + std::uint32_t compared=0; + for(std::size_t j=1;j1100)continue; + for(std::size_t i=j;i-->0;) { + const auto& earlier=at(i); + const float dt=static_cast(later.tick-earlier.tick); + if(dt>maxPairTicks)break; + const float strength=std::sqrt(earlier.strength*later.strength); + for(int cycles=1;cycles<=3;++cycles) { + const float targetBpm=6000.f*cycles/dt; + // The original tolerance is max(1.4 ticks, 2.2% of + // a multi-beat period). Within 60–180 BPM, its largest + // possible candidate separation is <10 BPM. +/-12 + // therefore cannot discard an original valid score. + const int near=static_cast(std::lround(targetBpm)); + const int lo=std::max(minBpm,near-12); + const int hi=std::min(maxBpm,near+12); + for(int bpm=lo;bpm<=hi;++bpm) { + ++compared; + const float period=6000.f/static_cast(bpm); + if(dt>period*3.08f)continue; + if(static_cast(std::lround(dt/period))!=cycles)continue; + const float tolerance=std::max(1.4f,.022f*period*cycles); + const float error=std::abs(dt-period*cycles); + if(error>=tolerance)continue; + candidates[static_cast(bpm-minBpm)]+= + strength*(1.f-error/tolerance)/ + (cycles==1?1.f:cycles==2?1.6f:2.25f); + } + } + } + } + result_.scoringComparisons=compared; + // Preserve deterministic ascending-BPM tie-breaking and the old + // half/double-time decision semantics exactly. + for(int bpm=minBpm;bpm<=maxBpm;++bpm) { + const float score=candidates[static_cast(bpm-minBpm)]; + if(score>bestScore){bestScore=score;bestBpm=bpm;} + } + if(bestBpm==0 || bestScore<2.0f)return; + if(result_.locked) { + const int previous=static_cast(std::lround(result_.bpm)); + const bool octave=std::abs(2*previous-bestBpm)<=3 || + std::abs(previous-2*bestBpm)<=3; + if(octave && previous>=60 && previous<=180 && + candidates[static_cast(previous-60)]>= + bestScore*.70f) { + // A wrong half/double-time incumbent can otherwise become + // PERMANENT: an exact 120 BPM pulse also supports 60 BPM + // through two-beat intervals. Detect strong, consecutive + // DIRECT onsets on the proposed new pulse, not just scored + // multiples of an older rhythm. Retain the incumbent when + // direct cadence is ambiguous (syncopated/off-beat music). + float strongest=0.f; + for(std::size_t i=0;i(candidate); + const float tolerance=std::max(1.5f,period*.045f); + const Hit* lastStrong=nullptr; + int matches=0; + for(std::size_t i=0;i600||hit.strength(hit.tick-lastStrong->tick) + -period)<=tolerance) + ++matches; + lastStrong=&hit; + } + return matches; + }; + const auto incumbentScore= + candidates[static_cast(previous-60)]; + const bool clearNewPulse= + bestScore>incumbentScore*1.005f && + directStrongMatches(bestBpm)>=6 && + directStrongMatches(bestBpm)>= + directStrongMatches(previous)+4; + if(!clearNewPulse) + bestBpm=previous; + } + } + if(std::abs(bestBpm-candidateBpm_)<=2)++stableCount_; + else {candidateBpm_=bestBpm;stableCount_=1;} + // A proven lock resists transient alternate half/double-time peaks. + if(result_.locked && std::abs(bestBpm-result_.bpm)>5.f && + stableCount_<6)return; + if(stableCount_<3)return; + // Octave hysteresis can deliberately select a weaker incumbent. + // Confidence MUST describe that selected BPM, not an alternate + // double/half-time peak that we explicitly rejected. + const float acceptedScore= + candidates[static_cast(bestBpm-60)]; + // Only the same LIVE 11-second onset window contributes to the + // candidate score. The ring may still contain many old weak hat + // attacks from a previous passage. Dividing by all 128 archival + // hits permanently depresses confidence even after a convincing + // quarter-note pulse returns (observed Windows CTest regression). + // Keep numerator and denominator on the identical time horizon. + std::size_t recentCount=0; + for(std::size_t i=0;i(std::max(7,recentCount))*.9f,0.f,1.f); + if(confidence<.28f) { + // A busy but low-confidence groove is NOT a stable beat. The + // previous code kept locked=true (and old beat-phase) while + // overwriting BPM, which could shift the next singer echo on an + // untrusted grid. Fail closed to accepted Manual/TAP, then demand + // three fresh good estimates before reacquiring Auto. + result_.confidence=confidence; + result_.locked=false; + result_.phaseLocked=false; + result_.phaseConfidence=0.f; + result_.beatAnchorFrame=0; + result_.beatAnchorTick=0; + stableCount_=candidateBpm_=0; + return; + } + result_.bpm=static_cast(bestBpm); + result_.confidence=confidence; + // CONTROL: phase is a separate decision from the BPM estimate. + // Search the bounded onset set for the strongest coherent pulse + // lattice, not simply the most recent loud snare / clap. + const float period=6000.f/result_.bpm; + const float tolerance=std::max(1.6f,period*.075f); + const auto matches=[&](std::uint64_t a,std::uint64_t b) noexcept { + const float elapsed=static_cast(a>b?a-b:b-a); + const float cycles=std::round(elapsed/period); + const float difference=std::abs(elapsed-cycles*period); + return std::max(0.f,1.f-difference/tolerance); + }; + float total=0.f; + for(std::size_t i=0;i0.f)for(std::size_t candidate=0;candidate1100)continue; + float coherence=0.f; + for(std::size_t i=0;ileading+.0001f || + (std::abs(coherence-leading)<=.0001f && + center.tick>anchor)) { + leading=coherence; + anchor=center.tick; + anchorFrame=center.frame; + } + } + // Competing off-beat cohorts mean the quarter-note phase is not + // established, even when interval BPM itself is reliable. + float competing=0.f; + if(anchor)for(std::size_t candidate=0;candidate1100 || + matches(center.tick,anchor)>.15f)continue; + float coherence=0.f; + for(std::size_t i=0;i0.f? + std::clamp(leading/total,0.f,1.f):0.f; + result_.phaseLocked=anchorFrame>0 && + result_.phaseConfidence>=.52f && + competing192000.))return false; + source_.store(id.value,std::memory_order_relaxed); + epoch_.store(epoch,std::memory_order_relaxed); + revision_.store(revision,std::memory_order_relaxed); + window_.store(id.value? + static_cast(std::lround(sampleRate*.01)):0, + std::memory_order_relaxed); + config_.fetch_add(1,std::memory_order_release); + return true; + } + // CONTROL: harmless structural WIRE/FX commits should preserve a valid + // music source. If the selected channel disappears, fall back to manual + // immediately rather than capturing stale processor/graph PCM. + ChannelId selectedSource() const noexcept { + return ChannelId{source_.load(std::memory_order_relaxed)}; + } + void onGraphCommitted(std::uint64_t epoch,std::uint64_t previousRevision, + std::uint64_t revision,bool retained) noexcept { + if(!selectedSource().value)return; + if(!retained || epoch_.load(std::memory_order_relaxed)!=epoch || + revision_.load(std::memory_order_relaxed)!=previousRevision) { + (void)select(ChannelId{},epoch,revision,0); + return; + } + revision_.store(revision,std::memory_order_relaxed); + config_.fetch_add(1,std::memory_order_release); + } + // AUDIO ONLY: the accepted publisher calls this ONCE per successfully + // admitted render block before traversing its ChannelId lanes. Revisions + // do not reset this clock; a physical epoch change always does. + std::uint64_t beginAudioBlock(std::uint64_t epoch,int frames) noexcept { + if(audioEpoch_!=epoch) { + audioEpoch_=epoch; + audioFrameClock_=0; + } + const auto start=audioFrameClock_; + if(frames>0)audioFrameClock_+=static_cast(frames); + blockStartFrame_=start; + return start; + } + // AUDIO: invoked once for every scheduled source channel by the existing + // renderer's pre-FX dispatch. Only the selected ID costs per-sample work. + void capture(ChannelId id,const float* left,const float* right,int frames, + std::uint64_t epoch,std::uint64_t revision) noexcept { + const auto generation=config_.load(std::memory_order_acquire); + if(audioGeneration_!=generation) { + audioGeneration_=generation; + bucketSamples_=0;energySum_=0.f;audioTick_=0; + } + if(!id.value||id.value!=source_.load(std::memory_order_relaxed)|| + epoch!=epoch_.load(std::memory_order_relaxed)|| + revision!=revision_.load(std::memory_order_relaxed)|| + !left||!right||frames<=0)return; + const auto window=window_.load(std::memory_order_relaxed); + if(window==0)return; + for(int i=0;i(i)+1}; + if(!frames_.push(f)) + dropped_.fetch_add(1,std::memory_order_relaxed); + bucketSamples_=0;energySum_=0.f; + } + } + } + // CONTROL: limited work per timer tick, never called from ASIO callback. + State poll(std::uint64_t liveEpoch,std::uint64_t liveRevision, + std::uint64_t nowMs=0) noexcept { + // CONTROL only. The former tick-only timeout could hold the last + // beat/grid indefinitely when an ASIO callback stopped completely: + // no new 10ms frames meant the estimator clock could not expire. + // Monotonic wall time is never read from the realtime callback. + if(nowMs==0) + nowMs=static_cast( + std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()).count()); + const auto generation=config_.load(std::memory_order_acquire); + if(controlGeneration_!=generation) { + controlGeneration_=generation;estimator_.reset(); + lastReceivedControlMs_=0; + } + Frame f{}; + bool sawCurrentFrame=false; + for(int i=0;i<512 && frames_.pop(f);++i) + if(f.generation==generation) { + estimator_.ingest(f.energy,f.tick,f.frameEnd); + sawCurrentFrame=true; + } + if(sawCurrentFrame)lastReceivedControlMs_=nowMs; + else if(lastReceivedControlMs_ && nowMs>=lastReceivedControlMs_ && + nowMs-lastReceivedControlMs_>3500) { + // Keep the selected ChannelId, but never publish an obsolete + // BPM/phase lock after the audio stream freezes or is suspended. + // On resumed PCM the same source reacquires from fresh onsets. + estimator_.reset(); + lastReceivedControlMs_=0; + } + State out{}; + out.source.value=source_.load(std::memory_order_relaxed); + out.epoch=epoch_.load(std::memory_order_relaxed); + out.revision=revision_.load(std::memory_order_relaxed); + out.dropped=dropped_.load(std::memory_order_relaxed); + out.active=out.source.value && out.epoch==liveEpoch && + out.revision==liveRevision; + if(out.active)out.tempo=estimator_.result(); + return out; + } +private: + struct Frame { + std::uint32_t generation=0; + std::uint64_t tick=0; + float energy=0.f; + std::uint64_t frameEnd=0; + }; + armix::builtin_fx::FxSpsc frames_{}; + MusicTempoEstimator estimator_{}; // CONTROL owner only + std::atomic source_{0},epoch_{0},revision_{0}; + std::atomic config_{0},window_{0},dropped_{0}; + // The following fields are AUDIO-thread exclusive. + std::uint32_t audioGeneration_=0,bucketSamples_=0; + float energySum_=0.f; + std::uint64_t audioTick_=0; + std::uint64_t audioEpoch_=0,audioFrameClock_=0,blockStartFrame_=0; + std::uint32_t controlGeneration_=0; // CONTROL only + std::uint64_t lastReceivedControlMs_=0; // CONTROL-only callback stall watchdog +}; +} // namespace armix::mixer diff --git a/engine/core/RealtimeNativeFxControl.h b/engine/core/RealtimeNativeFxControl.h index b15eab95d..77bac2c21 100644 --- a/engine/core/RealtimeNativeFxControl.h +++ b/engine/core/RealtimeNativeFxControl.h @@ -9,6 +9,16 @@ namespace armix::mixer { struct RealtimeNativeFxControl { virtual ~RealtimeNativeFxControl() = default; virtual void consumeRealtimeEdits() noexcept = 0; + // CONTROL-queried once when the native FX lease is prepared. Temporal DSP + // that cannot resume from stale input (Harmony pitch/history/room) must + // continue processing the actual PCM while its output is bypassed. + // Ordinary EQ/compressor/vendor FX retain the CPU-saving bypass fast path. + virtual bool requiresContinuousBypassProcessing() const noexcept {return false;} + // AUDIO callback only. A native performer cue can be dangerous when + // the rack is OFF: while fully bypassed its capture clock stops. + // Default no-op preserves Compressor/EQ/Harmony and vendor FX behavior. + virtual void onRealtimeBypass(bool /*requested*/,bool /*fully*/) noexcept {} + // CONTROL-only lifecycle: after FxInstance accepts this processor, a // vendor-state restore must not mutate published audio-owned filters. virtual void sealForRealtime() noexcept {} diff --git a/engine/device/AsioRestartRecoveryGate.h b/engine/device/AsioRestartRecoveryGate.h new file mode 100644 index 000000000..6d0fb9685 --- /dev/null +++ b/engine/device/AsioRestartRecoveryGate.h @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include + +namespace armix::device { +// CONTROL-thread scheduler for an ASIO4ALL driver whose WDM pin inventory +// may be transient during a control-panel restart. It never opens a device, +// touches a vendor plugin, or enters the realtime PCM callback. +// Only actual driver reopen/correction calls consume the bounded budget; +// readback and native graph publication remain eligible after it is spent. +class AsioRestartRecoveryGate final { +public: + static constexpr unsigned maxDriverTransactions=3; + static constexpr std::uint64_t settleMs=350; + + void observeEpoch(std::uint64_t epoch,std::uint64_t nowMs) noexcept { + if(epoch==0 || epoch==epoch_)return; + epoch_=epoch; + driverTransactions_=0; + bindFailures_=0; + nextMs_=add(nowMs,settleMs); + } + // A restart caused by *our own* verified reopen/correction is not a new + // opportunity for an unlimited series of expensive vendor calls. + void carryInternalEpoch(std::uint64_t epoch) noexcept { + if(epoch!=0)epoch_=epoch; + } + bool due(std::uint64_t nowMs) const noexcept { + return epoch_!=0 && nowMs>=nextMs_; + } + bool mayChangeDriver() const noexcept { + return driverTransactions_30000?30000:pause); + } + void recovered() noexcept { + driverTransactions_=0; + bindFailures_=0; + nextMs_=0; + } + unsigned driverTransactions() const noexcept {return driverTransactions_;} + std::uint64_t trackedEpoch() const noexcept {return epoch_;} +private: + static std::uint64_t add(std::uint64_t a,std::uint64_t b) noexcept { + return a>std::numeric_limits::max()-b? + std::numeric_limits::max():a+b; + } + void defer(std::uint64_t nowMs,std::uint64_t millis) noexcept { + const auto deadline=add(nowMs,millis); + if(deadline>nextMs_)nextMs_=deadline; + } + std::uint64_t epoch_=0,nextMs_=0; + unsigned driverTransactions_=0,bindFailures_=0; +}; +} // namespace armix::device diff --git a/engine/device/DirectRouteFence.h b/engine/device/DirectRouteFence.h index 8647f3e6d..02fbca3a0 100644 --- a/engine/device/DirectRouteFence.h +++ b/engine/device/DirectRouteFence.h @@ -92,8 +92,10 @@ class DirectRouteFence final std::string_view inputMask, std::string_view outputMask) noexcept { - if (type.empty() || device.empty() || !validMask(inputMask) - || !validMask(outputMask)) return 0; + // Zero capture pins are permitted ONLY for the input side of an + // output-only session. The playback mask must identify real pins. + if (type.empty() || device.empty() || !validMask(inputMask,true) + || !validMask(outputMask,false)) return 0; std::uint64_t hash=14695981039346656037ull; append(hash, type); append(hash, device); @@ -102,9 +104,10 @@ class DirectRouteFence final return hash ? hash : 1; // reserve zero for never-approved } private: - static bool validMask(std::string_view mask) noexcept + static bool validMask(std::string_view mask,bool allowZero) noexcept { - if (mask.empty() || mask.front() == '0') return false; + if (mask.empty() || (mask.front() == '0' && + !(allowZero && mask.size() == 1))) return false; for (const unsigned char c : mask) if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'))) return false; diff --git a/engine/device/JuceActivePortSnapshot.h b/engine/device/JuceActivePortSnapshot.h index 359ea9d96..feb8c1745 100644 --- a/engine/device/JuceActivePortSnapshot.h +++ b/engine/device/JuceActivePortSnapshot.h @@ -26,8 +26,8 @@ struct JuceActivePortSnapshot final { std::uint64_t epoch=0; juce::String deviceName, typeName; - // Accept a frozen copy of masks so unit tests can exercise sparse - // numbering without requiring an ASIO device. This executes off RT. + // Accept a frozen copy of masks to exercise sparse numbering and real + // output-only devices with zero capture pins. No fake input is created. static bool fromMasks(std::uint64_t epoch, const juce::BigInteger& inputMask, const juce::BigInteger& outputMask, @@ -46,7 +46,6 @@ struct JuceActivePortSnapshot final { if(p>=limit || out>=limit){error=Fault::tooManyOutputs;return false;} outputIndices[out++]=p; } - if(in==0){error=Fault::emptyInput;return false;} if(out==0){error=Fault::emptyOutput;return false;} JuceActivePortSnapshot candidate; LiveInputPortRegistry::Fault inputFault{}; diff --git a/engine/player/PlayerLibraryPolicy.h b/engine/player/PlayerLibraryPolicy.h new file mode 100644 index 000000000..8a4570655 --- /dev/null +++ b/engine/player/PlayerLibraryPolicy.h @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +namespace armix::player { +// FILE/WORKER only. No audio callback, network, plugin or device access. +// Folder import is a bounded, naturally ordered, user-directed action. +struct PlayerLibraryPolicy final { + static constexpr std::size_t maxSongs=2000; + static constexpr std::size_t maxEntriesInspected=20000; + static bool supported(const juce::File& file) { + return file.hasFileExtension("wav;mp3;flac;aif;aiff;ogg"); + } + static bool sameSongName(const juce::File& saved,const juce::File& chosen) { + return supported(chosen) && chosen.existsAsFile() && + saved.getFileNameWithoutExtension().isNotEmpty() && + saved.getFileNameWithoutExtension().equalsIgnoreCase( + chosen.getFileNameWithoutExtension()); + } + struct Scan { + std::vector files; + bool truncated=false; + }; + static Scan scanFolder(const juce::File& folder) { + Scan result; + if(!folder.isDirectory())return result; + // Iterates lazily and stops at finite bounds, including deep folders. + // Executed by the import worker, never by the WebView message loop. + juce::DirectoryIterator files(folder,true,"*",juce::File::findFiles); + std::size_t inspected=0; + while(files.next()) { + if(++inspected>maxEntriesInspected) { + result.truncated=true;break; + } + const auto file=files.getFile(); + if(!supported(file))continue; + if(result.files.size()>=maxSongs) { + result.truncated=true;break; + } + result.files.push_back(file); + } + std::sort(result.files.begin(),result.files.end(), + [](const juce::File& a,const juce::File& b) { + const int c=a.getFileName().compareNatural(b.getFileName(),false); + if(c!=0)return c<0; + return a.getFullPathName().compareIgnoreCase( + b.getFullPathName())<0; + }); + result.files.erase(std::unique(result.files.begin(),result.files.end()), + result.files.end()); + return result; + } +}; +} // namespace armix::player diff --git a/integration/ApprovedNativeRuntimeSnapshot.h b/integration/ApprovedNativeRuntimeSnapshot.h index f5065a557..2b3207ea9 100644 --- a/integration/ApprovedNativeRuntimeSnapshot.h +++ b/integration/ApprovedNativeRuntimeSnapshot.h @@ -71,7 +71,7 @@ inline bool publishVerifiedFirstSoundState(juce::var& snapshot, static_cast(routeEpoch)>0 && static_cast(revision)>0 && juce::String(static_cast(routeEpoch))==epoch.toString() && - inputs.isArray() && !inputs.getArray()->isEmpty() && + inputs.isArray() && outputs.isArray() && outputs.getArray()->size()>=2 && nativeV8Number(device.getProperty("sampleRate",{}),rate) && nativeV8Number(device.getProperty("bufferFrames",{}),frames) && @@ -267,7 +267,7 @@ inline bool projectInstalledNativeChannelIdGraph( const auto frames=device.getProperty("bufferFrames",{}); double actualRate=0.,actualFrames=0.; if (!outputMask.isArray() || !inputMask.isArray() || - outputMask.getArray()->size()<2 || inputMask.getArray()->isEmpty() || + outputMask.getArray()->size()<2 || !nativeV8Number(rate,actualRate) || !nativeV8Number(frames,actualFrames) || actualRate<8000. || actualRate>384000. || diff --git a/scripts/build_approved_native_gui.py b/scripts/build_approved_native_gui.py index 0c7d1bcdb..5dac25f24 100644 --- a/scripts/build_approved_native_gui.py +++ b/scripts/build_approved_native_gui.py @@ -58,6 +58,12 @@ def accepted_pages_html() -> str: # HTML at native build time. Every anchor must occur exactly once: no silent # breakage if Pages GUI source evolves. No extra layout or simulated PCM. NATIVE_EVENT_HOOKS = ( + # The mixer shell must remain visible even with zero audio endpoints or + # before the first accepted roster. Native control intents are still + # fenced by the bridge's authoritative ACK/readback; no mock PCM runs. + ("Mixer · Reference Session", "Mixer · Native Session"), + ("Interactive visual reference. Changes are local to this mockup.", "Preparing native mixer…"), + ("SIMULATED METERS · NO REAL AUDIO", "NATIVE AUDIO"), # The published /preview/ HTML and its V28 checkpoint are immutable. # Change ONLY the compiled native WebView's operator fader travel law. # The DSP gain remains exact dB -> 10^(dB/20), and the mapping is @@ -228,10 +234,10 @@ def accepted_pages_html() -> str: " setNativeCatalog(rows){\n" " pluginCatalog=rows.filter(x=>x&&typeof x.id==='string'&&typeof x.name==='string').map(x=>({\n" " id:x.id,name:x.name,vendor:x.vendor||'Unknown',category:x.category||'Utility',\n" - " format:'VST3',status:'ready',latencySamples:null,\n" + " format:x.format==='Native'?'Native':'VST3',status:'ready',latencySamples:null,\n" " favorite:!!x.favorite,hidden:false}));\n" " const label=document.querySelector('.plugin-disclaimer');\n" - " if(label)label.textContent='NATIVE JUCE VST3 · only verified scanned catalog entries are insertable';\n" + " if(label)label.textContent='Native EQ/Compressor/Harmony ready · external VST3 require verified scan';\n" " renderPluginCatalog();renderFastPicker();return pluginCatalog.length;\n" " },\n" " closeNativePicker(){setFastPicker(false);},\n" diff --git a/scripts/compose_native_peq.py b/scripts/compose_native_peq.py index a44984f58..4962371d1 100644 --- a/scripts/compose_native_peq.py +++ b/scripts/compose_native_peq.py @@ -6,6 +6,7 @@ SCRIPT='' COMP_SCRIPT='' HARMONY_SCRIPT='' +THROW_SCRIPT='' PICKER_HEAD="function renderFastPicker(){" PICKER_FN="""function insertChosenNativeEq(){ const t=tracks.concat(master).find(x=>x.id===activeFxTarget?.channelId); @@ -73,6 +74,25 @@ say('ArSon Harmony · browser preview ONLY · no DSP'); return true; } +function insertChosenNativeThrow(){ + const t=tracks.concat(master).find(x=>x.id===activeFxTarget?.channelId); + const slot=Number(activeFxTarget?.slot); + if(!t||!Number.isInteger(slot)||slot<0||slot>=8){ + say('Vocal Throw · choose an empty FX insert');return false; + } + if(window.__JUCE__?.backend?.emitEvent){ + const host=window.ArSonMixNativeVocalThrow; + if(!host?.insert){say('Native Vocal Throw host unavailable');return false;} + host.insert(activeFxTarget);return true; + } + if(t.fx[slot]!=='None'){ + say('FX slot already occupied · choose an empty insert');return false; + } + t.fx[slot]='ArSon Vocal Throw';t.slotBypass[slot]=false; + t.fxInsertIds[slot]={id:'visual-throw-'+t.id+'-'+slot,name:'ArSon Vocal Throw'}; + refreshStrip(t);setFastPicker(false); + say('Vocal Throw · browser preview ONLY · no audio DSP');return true; +} function renderFastPicker(){""" PICKER_RENDER="plugEl('fastResults').innerHTML=list.length?list.map(p=>" PICKER_RENDER_NEW="""const eqBuiltin=!q||['parametric eq','peq','channel eq','built-in fx'].some(n=>n.includes(q))? @@ -81,7 +101,9 @@ '':''; const harmonyBuiltin=!q||['arson harmony','harmony','vocal harmony','built-in fx'].some(n=>n.includes(q))? '':''; - const builtin=(eqBuiltin||compBuiltin||harmonyBuiltin?'
BUILT-IN FX
':'')+eqBuiltin+compBuiltin+harmonyBuiltin; + const throwBuiltin=!q||['vocal throw','throw','delay','echo','phrase','concert','built-in fx'].some(n=>n.includes(q))? + '':''; + const builtin=(eqBuiltin||compBuiltin||harmonyBuiltin||throwBuiltin?'
BUILT-IN FX
':'')+eqBuiltin+compBuiltin+harmonyBuiltin+throwBuiltin; plugEl('fastResults').innerHTML=builtin+'
VST3 PLUGINS
'+(list.length?list.map(p=>""" PICKER_END=""").join(''):'
No matching effects
';""" PICKER_END_NEW=""").join(''):'
No matching effects
');""" @@ -89,9 +111,10 @@ PICKER_CLICK_NEW=""" if(e.target.closest('[data-fast-native-harmony]')){insertChosenNativeHarmony();return;} if(e.target.closest('[data-fast-native-eq]')){insertChosenNativeEq();return;} if(e.target.closest('[data-fast-native-comp]')){insertChosenNativeCompressor();return;} + if(e.target.closest('[data-fast-native-throw]')){insertChosenNativeThrow();return;} const btn=e.target.closest('[data-fast-id]');if(btn)insertCatalogPlugin(btn.dataset.fastId);""" PICKER_ENTER="if(b){e.preventDefault();insertCatalogPlugin(b.dataset.fastId);}" -PICKER_ENTER_NEW="if(b){e.preventDefault();if(b.hasAttribute('data-fast-native-harmony'))insertChosenNativeHarmony();else if(b.hasAttribute('data-fast-native-eq'))insertChosenNativeEq();else if(b.hasAttribute('data-fast-native-comp'))insertChosenNativeCompressor();else insertCatalogPlugin(b.dataset.fastId);}" +PICKER_ENTER_NEW="if(b){e.preventDefault();if(b.hasAttribute('data-fast-native-harmony'))insertChosenNativeHarmony();else if(b.hasAttribute('data-fast-native-throw'))insertChosenNativeThrow();else if(b.hasAttribute('data-fast-native-eq'))insertChosenNativeEq();else if(b.hasAttribute('data-fast-native-comp'))insertChosenNativeCompressor();else insertCatalogPlugin(b.dataset.fastId);}" OPEN=" if(a==='openPlugin'){openFastPicker(t,Number(btn.dataset.slot),btn);return;}" OPEN_NEW=""" if(a==='openPlugin'){ const index=Number(btn.dataset.slot); @@ -104,6 +127,9 @@ if(t.fx[index]==='ArSon Harmony'){ window.ArSonMixNativeHarmony?.open(t,index);return; } + if(t.fx[index]==='ArSon Vocal Throw'){ + window.ArSonMixNativeVocalThrow?.open(t,index);return; + } openFastPicker(t,index,btn);return; }""" def apply_native_peq(html: str)->str: @@ -114,11 +140,11 @@ def apply_native_peq(html: str)->str: (PICKER_ENTER,PICKER_ENTER_NEW), (OPEN,OPEN_NEW)) if html.count('')!=1 or html.count('')!=1 or \ - SCRIPT in html or COMP_SCRIPT in html or 'insertChosenNativeEq' in html: + SCRIPT in html or COMP_SCRIPT in html or HARMONY_SCRIPT in html or THROW_SCRIPT in html or 'insertChosenNativeEq' in html: raise ValueError("Parametric EQ requires one pristine approved compiled GUI") for before,after in anchors: if html.count(before)!=1: raise ValueError('Ambiguous approved picker/editor anchor: '+before[:90]) html=html.replace(before,after,1) - html=html.replace('',SCRIPT+'\n'+COMP_SCRIPT+'\n'+HARMONY_SCRIPT+'\n',1) + html=html.replace('',SCRIPT+'\n'+COMP_SCRIPT+'\n'+HARMONY_SCRIPT+'\n'+THROW_SCRIPT+'\n',1) return html diff --git a/site/preview-v2/assets/arson-player.js b/site/preview-v2/assets/arson-player.js index 1b7d349e7..79be6dc43 100644 --- a/site/preview-v2/assets/arson-player.js +++ b/site/preview-v2/assets/arson-player.js @@ -32,6 +32,8 @@ toggle.addEventListener("click",()=>open(root.hidden)); $("playerClose").addEventListener("click",()=>open(false)); $("playerAdd").addEventListener("click",()=>send("playerAdd")); + $("playerAddFolder").addEventListener("click",()=>send("playerAddFolder")); + $("playerRelink").addEventListener("click",()=>send("playerRelink")); $("playerPlay").addEventListener("click",()=>{ send(model.transport?.state==="PLAYING"?"playerPause":"playerPlay"); }); @@ -144,11 +146,17 @@ "Music playing · output muted", ERROR:"Unable to decode this file" }[state]||""); - const indicator=(t.processingChangePending && !model.error && !t.error && + const indicator=model.libraryBusy && !model.error? + "Adding songs from folder…": + (t.processingChangePending && !model.error && !t.error && state!=="EMPTY" && state!=="ERROR") - ?"Preparing music KEY/TEMPO in decoder…":detail; + ?"Preparing music KEY/TEMPO in decoder…":detail; showFeedback(indicator,Boolean(model.error||t.error)); $("playerChooseOutput").hidden=!native || !Boolean(model.chooseOutput); + const missing=model.tracks.find(x=>x.id===model.selected)?.missing; + $("playerRelink").hidden=!native || !missing; + $("playerAddFolder").disabled=Boolean(model.libraryBusy); + $("playerAdd").disabled=Boolean(model.libraryBusy); $("playerCount").textContent=model.tracks.length+" songs"; renderTracks(); } diff --git a/site/preview-v2/assets/arson-vocal-hardware-encoder.svg b/site/preview-v2/assets/arson-vocal-hardware-encoder.svg new file mode 100644 index 000000000..2cb7d175f --- /dev/null +++ b/site/preview-v2/assets/arson-vocal-hardware-encoder.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/site/preview-v2/assets/arson-vocal-hardware-push.svg b/site/preview-v2/assets/arson-vocal-hardware-push.svg new file mode 100644 index 000000000..1b9970a96 --- /dev/null +++ b/site/preview-v2/assets/arson-vocal-hardware-push.svg @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/site/preview-v2/assets/arson-vocal-hardware-rotor.svg b/site/preview-v2/assets/arson-vocal-hardware-rotor.svg new file mode 100644 index 000000000..e8c72a55e --- /dev/null +++ b/site/preview-v2/assets/arson-vocal-hardware-rotor.svg @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/site/preview-v2/assets/arson-vocal-hardware-toggle.svg b/site/preview-v2/assets/arson-vocal-hardware-toggle.svg new file mode 100644 index 000000000..d3aad9aa7 --- /dev/null +++ b/site/preview-v2/assets/arson-vocal-hardware-toggle.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/site/preview-v2/assets/arson-vocal-throw-performance.svg b/site/preview-v2/assets/arson-vocal-throw-performance.svg new file mode 100644 index 000000000..38305d831 --- /dev/null +++ b/site/preview-v2/assets/arson-vocal-throw-performance.svg @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/site/preview-v2/assets/mixer-chrome-material.css b/site/preview-v2/assets/mixer-chrome-material.css index 4e6cddea4..2f4e22f54 100644 --- a/site/preview-v2/assets/mixer-chrome-material.css +++ b/site/preview-v2/assets/mixer-chrome-material.css @@ -1489,3 +1489,70 @@ html :where(.app, .app *),html :where(.app, .app *)::before,html :where(.app, .a .routing-wire-overlay path{filter:none!important;pointer-events:none} + +/* Desktop JUCE titlebar: one real OS window caption, no doubled WebView header. + The public interactive browser reference keeps its own top identity bar. */ +html.armix-native-desktop .app > .window-title{display:none!important} +.window-title .logo{display:inline-flex!important;align-items:center;gap:0;letter-spacing:.015em} +.window-title .logo .armix-brand-ar{color:#48d5f3} +.window-title .logo .armix-brand-son{color:#eff8fa} +.window-title .logo .armix-brand-mix{color:#ffad59} +/* Compact consistent operator toolbar spacing, preserving existing BTN-180 skin. */ +.app .command-bar{ + min-height:34px!important;align-items:center!important;column-gap:5px!important; + padding-left:9px!important;padding-right:9px!important; +} +.app .command-bar>.sep{margin-left:2px!important;margin-right:2px!important} +.app .command-bar .toolbar-label{font-size:9px!important;letter-spacing:.06em} +@media(max-width:1220px){ + .app .command-bar{column-gap:3px!important;padding-left:5px!important;padding-right:5px!important} +} + +/* Native desktop toolbar V2 — functional hardware keys stay 29px high. + Separate command groups visually; keep the bank and More fully usable. + The public /preview/ layout and historical fixture are untouched. */ +html.armix-native-desktop .app .command-bar{ + height:43px!important;min-height:43px!important;max-height:43px!important; + flex:0 0 43px!important; + align-items:center!important;column-gap:8px!important; + padding-inline:12px!important; + background:linear-gradient(180deg,#1b3340 0%,#172d39 100%)!important; + border-top:1px solid #5f7b864c!important; + border-bottom:1px solid #081922!important; +} +html.armix-native-desktop .app .command-bar>.armix-toolbar-divider, +html.armix-native-desktop .app .command-bar>.sep{ + display:block!important;flex:0 0 1px!important;width:1px!important; + height:21px!important;padding:0!important; + margin:0 4px!important;align-self:center!important;pointer-events:none!important; + background:linear-gradient(180deg,transparent,#7799a27d 30%,#7799a27d 70%,transparent)!important; + border:0!important; +} +html.armix-native-desktop .app .command-bar>.tool:not(.bank-arrow), +html.armix-native-desktop .app .command-bar>.more-tools>summary.tool{ + padding-inline:10px!important; +} +html.armix-native-desktop .app .command-bar>.mixer-file-tool{ + gap:6px!important; +} +html.armix-native-desktop .app .command-bar>.mixer-file-tool img{ + display:block;width:16px;height:16px;flex:none; +} +html.armix-native-desktop .app .command-bar>.toolbar-label{ + font-size:9px!important;letter-spacing:.09em!important; +} +@media(max-width:1360px){ + html.armix-native-desktop .app .command-bar{ + column-gap:5px!important;padding-inline:7px!important; + } + html.armix-native-desktop .app .command-bar>.armix-toolbar-divider{display:none!important} + html.armix-native-desktop .app .command-bar>.tool:not(.bank-arrow), + html.armix-native-desktop .app .command-bar>.more-tools>summary.tool{ + padding-inline:7px!important; + } +} +@media(max-width:1150px){ + html.armix-native-desktop .app .command-bar{ + column-gap:4px!important;padding-inline:5px!important; + } +} diff --git a/site/preview-v2/assets/mixer-contextual-buttons.css b/site/preview-v2/assets/mixer-contextual-buttons.css index 84f8b2ef8..d26016500 100644 --- a/site/preview-v2/assets/mixer-contextual-buttons.css +++ b/site/preview-v2/assets/mixer-contextual-buttons.css @@ -197,22 +197,24 @@ } /* Single authoritative modal Close + built-in FX Power chrome. + The semantic .armix-builtin-fx-power / -close classes are mandatory on + every built-in editor, while legacy EQ/Compressor names remain compatible. All cards: same 24px hit box, same icon, same pressed-red interaction. Green ON, muted red insert bypass, amber rack bypass, grey unavailable. FX state is assigned exclusively from accepted DSP graph readback. */ -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close){display:inline-flex!important;align-items:center!important;justify-content:center!important;position:relative!important;box-sizing:border-box!important;flex:0 0 24px!important;width:24px!important;min-width:24px!important;max-width:24px!important;height:24px!important;min-height:24px!important;max-height:24px!important;padding:0!important;margin:0!important;font-size:0!important;line-height:1!important;color:#e0edf2!important;cursor:pointer!important;border:1px solid #607d8c!important;border-radius:4px!important;background:linear-gradient(#3e5866,#293e4b)!important;box-shadow:inset 0 1px #ffffff22,0 1px 2px #06131f75!important;transform:none!important;text-shadow:none!important;transition:background-color .10s,border-color .10s,color .10s!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close) svg{display:none!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close)::before{content:none!important;display:none!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close)::after,:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close):active::after{content:""!important;display:block!important;position:relative!important;flex:0 0 12px!important;inset:auto!important;width:12px!important;height:12px!important;opacity:1!important;border:0!important;border-radius:0!important;transform:none!important;box-shadow:none!important;pointer-events:none!important;background:linear-gradient(45deg,transparent 43%,currentColor 43% 57%,transparent 57%),linear-gradient(-45deg,transparent 43%,currentColor 43% 57%,transparent 57%)!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close):hover:not(:disabled){color:#fff!important;border-color:#b27078!important;background:linear-gradient(#64424f,#4d343f)!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close):active:not(:disabled){color:#fff!important;border-color:#ee8b93!important;background:linear-gradient(#cc4753,#982a36)!important;box-shadow:inset 0 2px 4px #4c0c1790,0 0 0 1px #ef698069!important;transition:none!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close):focus-visible{outline:2px solid #a2dce9!important;outline-offset:2px!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power){display:inline-flex!important;align-items:center!important;justify-content:center!important;box-sizing:border-box!important;flex:0 0 26px!important;width:26px!important;height:24px!important;opacity:1!important;padding:0!important;border:1px solid #4b6572!important;border-radius:4px!important;background:linear-gradient(#384b56,#243846)!important;box-shadow:inset 0 1px #ffffff20!important;font-size:18px!important;transition:none!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power)[data-fx-state="on"]{color:#76f0b9!important;border-color:#428969!important;background:linear-gradient(#335c51,#204539)!important;text-shadow:0 0 5px #7df0b85c!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power)[data-fx-state="off"]{color:#e99b9f!important;border-color:#83525a!important;background:linear-gradient(#533b42,#3a3039)!important;text-shadow:none!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power)[data-fx-state="rack-off"]{color:#f0c483!important;border-color:#846948!important;background:linear-gradient(#544737,#41382d)!important;text-shadow:none!important;cursor:not-allowed!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power)[data-fx-state="unknown"]{color:#8498a4!important;border-color:#4b5d66!important;background:linear-gradient(#3a4751,#2b3941)!important;text-shadow:none!important;cursor:not-allowed!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power):focus-visible{outline:2px solid #9cdbe7!important;outline-offset:2px!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close){display:inline-flex!important;align-items:center!important;justify-content:center!important;position:relative!important;box-sizing:border-box!important;flex:0 0 24px!important;width:24px!important;min-width:24px!important;max-width:24px!important;height:24px!important;min-height:24px!important;max-height:24px!important;padding:0!important;margin:0!important;font-size:0!important;line-height:1!important;color:#e0edf2!important;cursor:pointer!important;border:1px solid #607d8c!important;border-radius:4px!important;background:linear-gradient(#3e5866,#293e4b)!important;box-shadow:inset 0 1px #ffffff22,0 1px 2px #06131f75!important;transform:none!important;text-shadow:none!important;transition:background-color .10s,border-color .10s,color .10s!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close) svg{display:none!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close)::before{content:none!important;display:none!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close)::after,:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close):active::after{content:""!important;display:block!important;position:relative!important;flex:0 0 12px!important;inset:auto!important;width:12px!important;height:12px!important;opacity:1!important;border:0!important;border-radius:0!important;transform:none!important;box-shadow:none!important;pointer-events:none!important;background:linear-gradient(45deg,transparent 43%,currentColor 43% 57%,transparent 57%),linear-gradient(-45deg,transparent 43%,currentColor 43% 57%,transparent 57%)!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close):hover:not(:disabled){color:#fff!important;border-color:#b27078!important;background:linear-gradient(#64424f,#4d343f)!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close):active:not(:disabled){color:#fff!important;border-color:#ee8b93!important;background:linear-gradient(#cc4753,#982a36)!important;box-shadow:inset 0 2px 4px #4c0c1790,0 0 0 1px #ef698069!important;transition:none!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close):focus-visible{outline:2px solid #a2dce9!important;outline-offset:2px!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power){display:inline-flex!important;align-items:center!important;justify-content:center!important;box-sizing:border-box!important;flex:0 0 26px!important;width:26px!important;height:24px!important;opacity:1!important;padding:0!important;border:1px solid #4b6572!important;border-radius:4px!important;background:linear-gradient(#384b56,#243846)!important;box-shadow:inset 0 1px #ffffff20!important;font-size:18px!important;transition:none!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power)[data-fx-state="on"]{color:#76f0b9!important;border-color:#428969!important;background:linear-gradient(#335c51,#204539)!important;text-shadow:0 0 5px #7df0b85c!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power)[data-fx-state="off"]{color:#e99b9f!important;border-color:#83525a!important;background:linear-gradient(#533b42,#3a3039)!important;text-shadow:none!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power)[data-fx-state="rack-off"]{color:#f0c483!important;border-color:#846948!important;background:linear-gradient(#544737,#41382d)!important;text-shadow:none!important;cursor:not-allowed!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power)[data-fx-state="unknown"]{color:#8498a4!important;border-color:#4b5d66!important;background:linear-gradient(#3a4751,#2b3941)!important;text-shadow:none!important;cursor:not-allowed!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power):focus-visible{outline:2px solid #9cdbe7!important;outline-offset:2px!important} /* ArSon Player: compact stage-first drawer inside the ONE approved mixer GUI. */ #playerToggle{min-width:86px;letter-spacing:.01em} @@ -262,7 +264,7 @@ body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power):focus-visible{outline:2px #arsonPlayer .ap-listhead{display:flex;align-items:center;gap:8px; padding:10px 13px;border-top:1px solid #273a43;border-bottom:1px solid #273a43} #arsonPlayer .ap-listhead strong{font-size:12px;font-weight:550} -#arsonPlayer #playerAdd{margin-left:auto;border:1px solid #41616a; +#arsonPlayer #playerAdd{margin-left:0;white-space:nowrap;border:1px solid #41616a; border-radius:6px;padding:6px 10px;background:#223f47;color:#bfe9e6} #arsonPlayer #playerSearch{width:calc(100% - 26px);margin:9px 13px; padding:8px 10px;border-radius:7px;background:#0f1b22; @@ -322,3 +324,18 @@ body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power):focus-visible{outline:2px #arsonPlayer #playerTempoValue{width:36px} #arsonPlayer .ap-reset{padding:5px} } + +/* M3 smart library controls: lightweight, keyboard-accessible icon and + one contextual Locate file action. No additional cards or UI modes. */ +#arsonPlayer #playerAddFolder{margin-left:auto;display:inline-flex; + align-items:center;justify-content:center;width:29px;height:29px; + flex:0 0 29px;border:1px solid #45616a;border-radius:6px; + background:#223941;color:#a7d4d2} +#arsonPlayer #playerAddFolder:hover{background:#2c5058} +#arsonPlayer #playerRelink{border:1px solid #41616a; + border-radius:6px;padding:5px 8px;background:#223f47; + color:#bfe9e6;white-space:nowrap;font-size:11px} +#arsonPlayer #playerRelink:hover{background:#2b5761} +#arsonPlayer #playerRelink[hidden]{display:none!important} +#arsonPlayer #playerAdd:disabled, +#arsonPlayer #playerAddFolder:disabled{opacity:.5;cursor:wait} diff --git a/site/preview-v2/assets/mixer-contextual-buttons.js b/site/preview-v2/assets/mixer-contextual-buttons.js index 54a05ea26..2c09fb3be 100644 --- a/site/preview-v2/assets/mixer-contextual-buttons.js +++ b/site/preview-v2/assets/mixer-contextual-buttons.js @@ -58,8 +58,8 @@
TEMPO100%
-
Add music to begin
-
Setlist0 songs
+
Add music to begin
+
Setlist0 songs
Click to prepare · Double-click to play · Native audio through your mixer
`; @@ -71,3 +71,18 @@ script.src=new URL('arson-player.js',base).href; document.body.appendChild(script); })(); + +/* ArSonMiX owner wordmark; original source HTML/assembler anchor is immutable. */ +(()=>{ + 'use strict'; + const logo=document.querySelector('.app > .window-title .logo'); + if(!logo||logo.textContent!=='ArSonMix'||typeof logo.replaceChildren!=='function')return; + logo.replaceChildren(...[ + ['armix-brand-ar','Ar'],['armix-brand-son','Son'],['armix-brand-mix','MiX'] + ].map(([cls,value])=>{ + const span=document.createElement('span'); + span.className=cls;span.textContent=value; + return span; + })); + logo.setAttribute('aria-label','ArSonMiX'); +})(); diff --git a/site/preview-v2/assets/mixer-fx-rack.css b/site/preview-v2/assets/mixer-fx-rack.css index b5f8376f9..35f92efef 100644 --- a/site/preview-v2/assets/mixer-fx-rack.css +++ b/site/preview-v2/assets/mixer-fx-rack.css @@ -518,7 +518,7 @@ .mx-harm-sliders{ display:grid;grid-template-columns:repeat(2,minmax(105px,1fr)); width:min(100%,390px);align-items:center;justify-items:center; - gap:5px 17px;padding:8px 12px + gap:14px 17px;padding:3px 12px } .mx-harm-slider{ --dial-turn:0deg;display:flex;flex-direction:column;align-items:center; @@ -566,7 +566,12 @@ transform-origin:50% 27px;transform:rotate(var(--dial-turn)); pointer-events:none } -.mx-harm-dial-label{font-size:9px;letter-spacing:.85px;color:#405963;font-weight:600} +/* Outer illuminated ring extends 11px beyond the knob's actual face. + Leave real space below the halo without growing the mixer FX editor. */ +.mx-harm-dial-label{ + margin-top:12px;font-size:9px;line-height:11px; + letter-spacing:.85px;color:#405963;font-weight:600 +} .mx-harm-slider output{ font:500 10px/1.2 Inter,'Segoe UI',sans-serif; font-variant-numeric:tabular-nums;color:#253f49 @@ -710,11 +715,13 @@ .mx-harm-foot>span:first-child{ min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap } +.mx-harm-foot #mxHTracking{flex:0 0 auto;white-space:nowrap;color:#80c6c3} +.mx-harm-note.queued:not(.active){outline:2px solid #69d6b4;outline-offset:1px} @media(max-width:740px){ .mx-harm-body{grid-template-columns:126px minmax(0,1fr) 206px;min-height:224px} .mx-harm-left{padding:14px 9px 10px} .mx-harm-signature strong{font-size:15px} - .mx-harm-sliders{grid-template-columns:repeat(2,minmax(78px,1fr));gap:4px;padding:5px} + .mx-harm-sliders{grid-template-columns:repeat(2,minmax(78px,1fr));gap:10px 4px;padding:2px 5px} .mx-harm-dial-face{width:59px;height:59px} .mx-harm-dial-pointer{height:19px;transform-origin:50% 23px} .mx-harm-slider{height:101px} @@ -748,3 +755,242 @@ @media(prefers-reduced-motion:reduce){ .mx-harm *{transition:none!important;animation:none!important} } + +/* Vocal Throw M4 — aligned studio-hardware faceplate. + One spacing grid, one encoder body, one fixed 260deg rounded level arc. + Close/Power remain the same approved EQ/Compressor shared controls. */ +.mx-vthrow{position:fixed;z-index:15001;top:clamp(7px,7vh,66px);left:clamp(7px,9vw,175px); + width:min(778px,calc(100vw - 14px));max-height:calc(100dvh - 14px);display:flex;flex-direction:column; + box-sizing:border-box;overflow:hidden;border:1px solid #505763;border-radius:9px;color:#d5dce5; + background:linear-gradient(155deg,#323740,#242931 60%,#20252d); + box-shadow:inset 0 1px #ffffff21,inset 0 -1px #090c1199,0 18px 50px #000c; + font:400 11px/1.35 Inter,'Segoe UI',sans-serif} +.mx-vthrow[hidden]{display:none}.mx-vthrow *{box-sizing:border-box} +.mx-vthrow button{font:inherit;cursor:pointer} +.mx-vthrow :is(button,select,input):focus-visible{outline:2px solid #b6e8e3;outline-offset:3px} +.mx-vthrow .vt-face-header{height:42px;flex:0 0 42px;display:flex;align-items:center;gap:8px; + min-width:0;padding:0 11px 0 15px;cursor:move;touch-action:none;user-select:none; + background:linear-gradient(#3d444e,#292f38);border-bottom:1px solid #141922; + box-shadow:inset 0 1px #ffffff29,inset 0 -1px #ffffff09} +.mx-vthrow .brand{display:flex;align-items:baseline;gap:7px;white-space:nowrap;flex:0 0 auto} +.mx-vthrow .brand-mark{font-size:9px;font-weight:660;color:#c885e7;letter-spacing:.12em} +.mx-vthrow .brand-name{font-size:12px;font-weight:580;color:#f0eef4;letter-spacing:.055em} +.mx-vthrow .channel{min-width:0;max-width:136px;flex:1;overflow:hidden;text-overflow:ellipsis; + white-space:nowrap;font-size:9px;color:#aeb1ba} +.mx-vthrow .vt-preset{display:flex;align-items:center;gap:4px;margin-left:auto;min-width:0} +.mx-vthrow .vt-preset select{width:112px;height:25px;min-width:0;max-width:112px;padding:0 7px; + border:1px solid #525c68;border-radius:4px;background:linear-gradient(#2a3039,#1f252e); + color:#dce1e9;font:500 10px Inter,'Segoe UI',sans-serif} +.mx-vthrow option{color:#e8eaf1;background:#272b34} +.mx-vthrow .vt-hardware{min-height:0;overflow:auto;overscroll-behavior:contain;display:grid; + padding:0;scrollbar-width:thin;scrollbar-color:#565563 #22272e} +.mx-vthrow .vt-console{padding:13px 16px 12px;border-bottom:1px solid #515660; + background:linear-gradient(135deg,#31363e,#262b34 65%,#2b2f38); + box-shadow:inset 0 1px #ffffff13} +.mx-vthrow .vt-instrument{display:grid;grid-template-columns:minmax(0,1fr) 212px minmax(0,1fr); + align-items:center;column-gap:12px;min-width:0} +.mx-vthrow .vt-encoder-bank{display:grid;grid-template-columns:repeat(3,minmax(0,1fr)); + justify-items:stretch;align-items:stretch;min-width:0;gap:5px} +.mx-vthrow .vt-encoder{display:grid;grid-template-rows:16px 70px 18px; + justify-items:center;align-items:center;align-content:center;row-gap:3px; + min-width:0;width:100%;padding:2px 0} +.mx-vthrow .vt-encoder-name{height:auto;max-width:100%;line-height:15px;color:#b4beca; + font-size:10px;font-weight:540;letter-spacing:.067em;text-align:center;white-space:nowrap} +.mx-vthrow .vt-encoder-face{position:relative;display:block;flex:0 0 auto;width:70px;height:70px; + padding:0;border:0;border-radius:50%;touch-action:none;cursor:ns-resize; + background:transparent url("arson-vocal-hardware-encoder.svg") center/77% 77% no-repeat; + filter:drop-shadow(0 4px 5px #060a10a8)} +.mx-vthrow .vt-knob-meter{position:absolute;inset:0;width:100%;height:100%;overflow:visible; + fill:none;pointer-events:none} +.mx-vthrow .vt-meter-track,.mx-vthrow .vt-meter-fill{fill:none;stroke-width:3.3; + stroke-linecap:round;stroke-linejoin:round} +.mx-vthrow .vt-meter-track{stroke:#52616c;stroke-opacity:.8} +.mx-vthrow .vt-meter-fill{stroke:#79d4c7;stroke-width:3.8; + stroke-dasharray:100 100;stroke-dashoffset:var(--arc-offset,100); + filter:drop-shadow(0 0 1.3px #6ad8c788)} +.mx-vthrow .vt-encoder-needle{position:absolute;inset:0;transform:rotate(var(--turn,-130deg)); + pointer-events:none} +.mx-vthrow .vt-encoder-needle::after{content:"";position:absolute;left:calc(50% - 1.25px); + top:23%;height:12px;width:2.5px;border-radius:3px;background:#aee9e2; + box-shadow:0 0 3px #73cfce94} +.mx-vthrow .vt-encoder-value{font:500 12px/17px Inter,'Segoe UI',sans-serif; + color:#e1e4eb;font-variant-numeric:tabular-nums;white-space:nowrap;text-align:center} +.mx-vthrow .vt-center{min-width:0;display:flex;align-items:center; + justify-content:center;flex-direction:column;gap:0} +.mx-vthrow .vt-throw-button{position:relative;display:block;width:212px;height:212px;flex:0 0 auto; + border:0;padding:0;border-radius:50%;overflow:visible;touch-action:manipulation;cursor:pointer; + background:transparent url("arson-vocal-throw-performance.svg") center/contain no-repeat; + filter:drop-shadow(0 8px 9px #090d15af);transform:translateZ(0); + transition:filter 150ms ease,transform 100ms ease} +.mx-vthrow .vt-throw-aura{position:absolute;inset:10%;border-radius:50%;pointer-events:none; + box-shadow:inset 0 0 0 1px #b267c821,0 0 0 1px #11141b; + transition:box-shadow 150ms ease} +.mx-vthrow .vt-throw-button:hover:not(:disabled){filter:brightness(1.19) drop-shadow(0 8px 10px #080c13ca)} +.mx-vthrow .vt-throw-button:hover:not(:disabled) .vt-throw-aura{box-shadow:0 0 22px #bc36df3b,inset 0 0 0 1px #c17fdd3a} +.mx-vthrow .vt-throw-button:active:not(:disabled){transform:scale(.958) translateY(2px); + filter:brightness(1.32) drop-shadow(0 1px 2px #000b)} +.mx-vthrow .vt-throw-button[data-tail=true]:not(:disabled) .vt-throw-aura{ + box-shadow:0 0 29px #bb29e73f,inset 0 0 0 1px #e7a7f783} +.mx-vthrow .vt-throw-button:disabled{opacity:.53;filter:grayscale(.72) brightness(.8)} +.mx-vthrow .vt-throw-engraving{margin-top:-3px;color:#bca0cc; + font-size:9px;letter-spacing:.24em;font-weight:560;user-select:none; + transform:translateY(6px);pointer-events:none} +.mx-vthrow .vt-performance{display:grid;grid-template-columns:88px minmax(0,1fr) 302px; + align-items:center;column-gap:15px;margin-top:8px;min-height:110px} +.mx-vthrow .vt-wet-module{padding:0;justify-self:center;width:88px} +.mx-vthrow .vt-wet-module .vt-encoder-face{width:70px;height:70px} +.mx-vthrow .vt-trigger{min-width:0;height:100%;display:flex;align-items:center;justify-content:center} +.mx-vthrow .vt-mode-buttons{width:min(210px,100%);min-height:38px} +.mx-vthrow .vt-mode-buttons,.mx-vthrow .vt-division-buttons{display:flex;align-items:center; + gap:2px;padding:3px;border:1px solid #171c23;border-radius:7px; + background:linear-gradient(#131820,#242a32); + box-shadow:inset 0 2px 4px #060b11b8,0 1px #56606a3d} +.mx-vthrow :is(.vt-mode-buttons,.vt-division-buttons) button{flex:1;min-width:0; + min-height:31px;padding:3px 7px;border:1px solid transparent;border-radius:4px; + background:linear-gradient(#3b424b,#2d343d);box-shadow:inset 0 1px #ffffff15; + color:#b8c0cb;font-size:10.5px;font-weight:560;letter-spacing:.025em} +.mx-vthrow :is(.vt-mode-buttons,.vt-division-buttons) button[aria-pressed=true]{ + color:#f5e4ff;border-color:#784f8b;background:linear-gradient(#6a4c78,#3f344a); + box-shadow:inset 0 1px #efbaff2b,0 0 7px #b66bd327} +.mx-vthrow .vt-virtual-input,.mx-vthrow .vt-screen-reader{position:absolute!important; + width:1px!important;height:1px!important;padding:0!important;border:0!important; + opacity:0!important;overflow:hidden!important;pointer-events:none!important} +.mx-vthrow .vt-clock-tap{display:grid;grid-template-columns:minmax(145px,1fr) 83px; + align-items:center;gap:10px;min-width:0} +.mx-vthrow .vt-tempo{min-width:0;display:flex;flex-direction:column;align-items:center;gap:3px} +.mx-vthrow .vt-clock-screen{position:relative;width:100%;height:79px;min-width:0;display:flex;flex-direction:column; + justify-content:center;align-items:stretch;gap:1px;padding:7px 11px 5px; + border:1px solid #42616a;border-radius:6px;color:#cbf8e9; + background:radial-gradient(ellipse at 50% 15%,#173b40b5,transparent 80%), + linear-gradient(155deg,#071c22,#092831 70%,#061a20); + box-shadow:inset 0 2px 11px #000b,inset 0 0 0 1px #092a32,0 1px #53667233} +.mx-vthrow .vt-lcd-top{display:flex;align-items:center;justify-content:space-between; + font-size:9px;letter-spacing:.15em;color:#77aead} +.mx-vthrow #vtClockLabel{color:#a9dec5;font-size:9px;font-weight:550;letter-spacing:.1em} +.mx-vthrow .vt-lcd-digits{display:flex;align-items:baseline;gap:8px} +.mx-vthrow #vtDisplayBpm{padding:0;margin:0;border:0;background:none;appearance:none; + font:500 44px/1.04 'Segoe UI',Inter,sans-serif; + color:#d8fff2;letter-spacing:-.05em;font-variant-numeric:tabular-nums; + text-shadow:0 0 15px #61b7a533;cursor:text;text-align:left} +.mx-vthrow #vtDisplayBpm:hover{color:#e8fff7} +.mx-vthrow .vt-clock-screen[data-editing=true] #vtDisplayBpm{opacity:0;pointer-events:none} +.mx-vthrow .vt-lcd-digits>span{font-size:10px;color:#7fbeb2;letter-spacing:.07em} +.mx-vthrow .vt-manual-bpm{display:none;position:absolute;left:11px;right:10px; + top:25px;height:49px;align-items:center;z-index:1} +.mx-vthrow .vt-clock-screen[data-editing=true] .vt-manual-bpm{display:flex} +.mx-vthrow .vt-manual-bpm input{width:100%;max-width:148px;height:49px;margin:0; + padding:0;border:0;border-bottom:1px solid #75d5c58f;border-radius:0; + outline:0;background:#0b252d;color:#d8fff2; + font:500 44px/1.04 'Segoe UI',sans-serif;text-align:left; + letter-spacing:-.05em;font-variant-numeric:tabular-nums; + appearance:textfield} +.mx-vthrow .vt-manual-bpm input::-webkit-inner-spin-button, +.mx-vthrow .vt-manual-bpm input::-webkit-outer-spin-button{appearance:none;margin:0} +.mx-vthrow .vt-tap-button{height:79px;display:flex;flex-direction:column; + align-items:center;justify-content:center;gap:1px;color:#c8d0d9; + background:linear-gradient(#414852,#262c35);border:1px solid #4c5661;border-radius:9px; + box-shadow:inset 0 1px #ffffff21,0 3px 6px #0008} +.mx-vthrow .vt-tap-button span{font-size:15px;font-weight:640;letter-spacing:.12em} +.mx-vthrow .vt-tap-button small{font-size:9px;letter-spacing:.12em;color:#a5b0bc} +.mx-vthrow .vt-tap-button:active{background:linear-gradient(#242931,#353b45); + box-shadow:inset 0 2px 5px #000a} +.mx-vthrow .vt-transport{min-width:0;display:grid; + grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:17px; + padding:12px 17px 12px;background:linear-gradient(#232a33,#20252d); + border-top:1px solid #0f141b;border-bottom:1px solid #4b525c} +.mx-vthrow .vt-pulse,.mx-vthrow .vt-music-source{min-width:0; + display:flex;flex-direction:column;align-items:stretch;gap:6px} +.mx-vthrow .vt-small-label{font-size:10px;line-height:14px;font-weight:540;letter-spacing:.09em; + color:#b4bac5;white-space:nowrap} +.mx-vthrow .vt-division-buttons{height:40px} +.mx-vthrow .vt-division-buttons button{height:32px;padding:3px 5px;white-space:nowrap} +.mx-vthrow .vt-repeat-leds{display:flex;align-items:center;gap:5px; + white-space:nowrap;height:14px} +.mx-vthrow .vt-repeat-leds i{display:block;width:16px;height:3px; + border-radius:3px;background:#3d4550} +.mx-vthrow .vt-repeat-leds i[data-on=true]{background:#7bd4c7;box-shadow:0 0 4px #7bd4c755} +.mx-vthrow .vt-repeat-leds[data-playing=true] i[data-on=true]{background:#ade6d4} +.mx-vthrow .vt-music-source select{height:40px;width:100%;min-width:0;padding:0 11px; + border:1px solid #46515e;border-radius:5px;background:linear-gradient(#333a45,#252c36); + color:#e1e7ee;font:500 11px Inter,'Segoe UI',sans-serif} +.mx-vthrow .music-status{height:14px;line-height:14px;overflow:hidden;text-overflow:ellipsis; + white-space:nowrap;font-size:10px;color:#a2cfc6} +.mx-vthrow .vt-status-rail{height:30px;min-width:0;display:flex;align-items:center; + justify-content:space-between;gap:12px;padding:0 16px; + border-top:1px solid #090d13;background:linear-gradient(#272d36,#232831); + font-size:10px;letter-spacing:.02em;color:#a0adb9} +.mx-vthrow .vt-device{flex:0 0 auto;white-space:nowrap} +.mx-vthrow .dot{display:inline-block;width:6px;height:6px;margin-right:6px; + border-radius:50%;background:#6f7781;box-shadow:0 0 0 1px #10141a} +.mx-vthrow .dot.active{background:#79cbb8;box-shadow:0 0 5px #79cbb855} +.mx-vthrow .vt-hint{min-width:0;flex:1;text-align:center;overflow:hidden; + text-overflow:ellipsis;white-space:nowrap} +.mx-vthrow #vtCount{flex:0 0 auto;white-space:nowrap} +.mx-vthrow[data-fx-state=off] :is(.vt-encoder-face,.vt-throw-button), +.mx-vthrow[data-fx-state=rack-off] :is(.vt-encoder-face,.vt-throw-button){ + opacity:.55;filter:grayscale(.55) brightness(.77)} +@media(max-width:740px){ + .mx-vthrow{top:7px;left:7px} + .mx-vthrow .vt-console{padding:10px 12px 12px} + .mx-vthrow .vt-instrument{grid-template-columns:minmax(0,1fr) 184px minmax(0,1fr);gap:8px} + .mx-vthrow .vt-throw-button{width:184px;height:184px} + .mx-vthrow .vt-encoder{grid-template-rows:15px 60px 18px;row-gap:2px} + .mx-vthrow .vt-encoder-face{width:60px;height:60px} + .mx-vthrow .vt-encoder-name{font-size:9px} + .mx-vthrow .vt-encoder-needle::after{height:10px} + .mx-vthrow .vt-performance{grid-template-columns:75px minmax(0,1fr) 284px;column-gap:9px} + .mx-vthrow .vt-wet-module{width:75px} + .mx-vthrow .vt-wet-module .vt-encoder-face{width:60px;height:60px} + .mx-vthrow .vt-transport{gap:14px;padding:11px 12px} +} +@media(max-width:600px){ + .mx-vthrow{width:calc(100vw - 10px);max-height:calc(100dvh - 10px);left:5px;top:5px} + .mx-vthrow .vt-face-header{height:40px;flex-basis:40px;gap:6px;padding:0 9px} + .mx-vthrow .brand{gap:5px}.mx-vthrow .brand-mark{font-size:8px} + .mx-vthrow .brand-name{font-size:10.5px} + .mx-vthrow .channel{max-width:80px;font-size:9px} + .mx-vthrow .vt-preset select{width:83px;max-width:83px;font-size:10px} + .mx-vthrow .vt-console{padding:9px 11px 11px} + .mx-vthrow .vt-instrument{display:flex;flex-direction:column;gap:0} + .mx-vthrow .vt-center{order:0;margin-bottom:2px} + .mx-vthrow #vtEncodersLeft{order:1} + .mx-vthrow #vtEncodersRight{order:2} + .mx-vthrow .vt-throw-button{width:160px;height:160px} + .mx-vthrow .vt-throw-engraving{font-size:9px;margin-top:-4px} + .mx-vthrow .vt-encoder-bank{width:100%;grid-template-columns:repeat(3,minmax(0,1fr));gap:5px} + .mx-vthrow .vt-encoder{grid-template-rows:14px 60px 16px;row-gap:2px;padding:1px 0} + .mx-vthrow .vt-encoder-face{width:60px;height:60px} + .mx-vthrow .vt-encoder-name{font-size:9.5px;line-height:14px} + .mx-vthrow .vt-encoder-value{font-size:11px;line-height:16px} + .mx-vthrow .vt-performance{grid-template-columns:minmax(78px,1fr) minmax(0,2fr); + column-gap:10px;row-gap:4px;min-height:0;margin-top:5px} + .mx-vthrow .vt-wet-module{width:100%;grid-template-rows:14px 60px 16px;row-gap:2px} + .mx-vthrow .vt-wet-module .vt-encoder-face{width:60px;height:60px} + .mx-vthrow .vt-clock-tap{grid-column:1/-1;grid-template-columns:minmax(0,1fr) 86px; + align-items:center;gap:10px;margin-top:2px} + .mx-vthrow .vt-clock-screen{height:83px} + .mx-vthrow #vtDisplayBpm{font-size:47px} + .mx-vthrow .vt-tap-button{height:83px} + .mx-vthrow .vt-mode-buttons{width:min(212px,100%);max-width:100%} + .mx-vthrow .vt-mode-buttons button{font-size:10px;min-height:31px;padding:3px 7px} + .mx-vthrow .vt-transport{grid-template-columns:1fr;gap:8px;padding:9px 11px} + .mx-vthrow .vt-division-buttons{height:38px} + .mx-vthrow .vt-division-buttons button{font-size:10px;height:30px} + .mx-vthrow .vt-music-source select{height:36px} + .mx-vthrow .vt-status-rail{gap:8px;padding:0 10px} +} +@media(max-width:350px){ + .mx-vthrow .channel{display:none} + .mx-vthrow .brand-name{font-size:9.5px} + .mx-vthrow .vt-preset select{width:74px} + .mx-vthrow .vt-mode-buttons button{padding:3px 5px} +} +@media(max-height:590px) and (min-width:601px){ + .mx-vthrow{top:4px;max-height:calc(100dvh - 8px)} + .mx-vthrow .vt-console{padding-top:6px;padding-bottom:7px} + .mx-vthrow .vt-throw-button{height:172px;width:172px} + .mx-vthrow .vt-instrument{grid-template-columns:minmax(0,1fr) 176px minmax(0,1fr)} +} +@media(prefers-reduced-motion:reduce){ + .mx-vthrow .vt-throw-button,.mx-vthrow .vt-throw-aura{transition:none} +} diff --git a/site/preview-v2/assets/mixer-native-compressor.js b/site/preview-v2/assets/mixer-native-compressor.js index 57bd82293..c9599c2ef 100644 --- a/site/preview-v2/assets/mixer-native-compressor.js +++ b/site/preview-v2/assets/mixer-native-compressor.js @@ -61,6 +61,7 @@ power.title="FX STATE UNAVAILABLE";power.dataset.fxState="unknown"; power.disabled=true;power.setAttribute("aria-pressed","false"); power.setAttribute("aria-label","Compressor state unavailable"); close.setAttribute("aria-label","Close Compressor"); +power.classList.add("armix-builtin-fx-power");close.classList.add("armix-builtin-fx-close"); header.append(brand,channel,presetSelect,stateDot,power,close); const controls=dom("div","mx-comp-controls"); const left=dom("div","mx-comp-left"); diff --git a/site/preview-v2/assets/mixer-native-harmony.js b/site/preview-v2/assets/mixer-native-harmony.js index 9800f90d4..c7d4d11f6 100644 --- a/site/preview-v2/assets/mixer-native-harmony.js +++ b/site/preview-v2/assets/mixer-native-harmony.js @@ -60,7 +60,7 @@ root.innerHTML=` MANUAL -
PREVIEW · NO AUDIO
+
PREVIEW · NO AUDIOVOICE WAITING
`; // Cached editor nodes and change-only text: no DOM traversal/paint churn on // native readback ticks while the user sings. @@ -106,7 +106,7 @@ const backend=()=>window.__JUCE__?.backend; const state=()=>window.__ARMIX_NATIVE_M2__?.state?.()?.current; const demos=new Map(); let current=null,settings=fresh(),pending=null,latest=null,seq=0,readbackRequest=""; -let readbackSentAt=0; +let readbackSentAt=0,verified=false,heldPatch=null; let mode="DEMO",readbackLatency=0,observedNote=-1,preset="trio"; let detectedKey=-1,detectedScale=-1,detectedConfidence=0,lastGuideRead=0; let effectiveKey=-1,effectiveScale=-1,sourceSignature="",availableSources=[]; @@ -118,15 +118,75 @@ const sliders=sliderDefs.map(([key])=>({ key,input:root.querySelector('[data-field="'+key+'"]'), output:root.querySelector('[data-out="'+key+'"]') })); -const context=()=>{ +// The native accepted graph is the only authority, including after reopen. +// Track exact insert identity through a slot move; allow a successor at the +// former slot only on the SAME stable ChannelId. Never retarget another strip. +const acceptedLocation=()=>{ const n=state(); if(!current||!native()||!n?.admitted)return null; - const channel=n.graph?.channels?.find(ch=>ch.id===current.channelId); - const insert=channel?.inserts?.[current.slot]; - if(insert?.id!==current.instanceId||insert?.catalogId!==ID)return null; - return {channelId:current.channelId,deviceEpoch:n.device.epoch, - graphRevision:n.graph.revision,slot:current.slot,instanceId:current.instanceId}; + const id=current.channelId||window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(current.track); + const channel=n.graph?.channels?.find(ch=>ch.id===id),inserts=channel?.inserts; + if(!Array.isArray(inserts))return null; + let slot=current.instanceId? + inserts.findIndex(x=>x?.id===current.instanceId&&x.catalogId===ID):-1; + if(slot<0&&inserts[current.slot]?.catalogId===ID&&inserts[current.slot]?.id) + slot=current.slot; + if(slot<0)return null; + const insert=inserts[slot]; + if(!insert?.id||insert.catalogId!==ID)return null; + return {channelId:id,deviceEpoch:n.device.epoch, + graphRevision:n.graph.revision,slot,instanceId:insert.id}; +}; +const context=()=>{ + const c=acceptedLocation(); + if(!c||!current||c.channelId!==current.channelId|| + c.instanceId!==current.instanceId||c.slot!==current.slot|| + c.deviceEpoch!==current.boundEpoch|| + c.graphRevision!==current.boundRevision)return null; + return c; }; +// Carry only actually edited fields; never push stale full plugin presets +// into a freshly created instance after a device/graph transition. +function holdUnfinishedEdit(){ + const desired=latest||pending?.settings; + if(!desired)return; + const diff={}; + for(const key of Object.keys(settings)) + if(desired[key]!==settings[key])diff[key]=desired[key]; + heldPatch={...diff,...(heldPatch||{})}; +} +function reconcileBinding(){ + if(!native()||!current)return false; + const c=acceptedLocation(); + if(!c){ + if(verified||pending||readbackRequest){ + holdUnfinishedEdit();verified=false;pending=null;latest=null; + readbackRequest="";effectiveKey=-1;effectiveScale=-1; + hint("HARMONY RECONNECTING · WAITING FOR ACCEPTED FX");paint(); + } + return false; + } + const changed=current.channelId!==c.channelId|| + current.instanceId!==c.instanceId||current.slot!==c.slot|| + current.boundEpoch!==c.deviceEpoch|| + current.boundRevision!==c.graphRevision; + if(changed){ + holdUnfinishedEdit(); + current.channelId=c.channelId;current.instanceId=c.instanceId; + current.slot=c.slot;current.boundEpoch=c.deviceEpoch; + current.boundRevision=c.graphRevision; + pending=null;latest=null;verified=false; + readbackRequest="";readbackSentAt=0; + effectiveKey=-1;effectiveScale=-1; + detectedKey=-1;detectedScale=-1;detectedConfidence=0; + showText(el("mxHChannel"),current.track.name+" · FX "+(c.slot+1)); + hint("HARMONY CONNECTED · READING DSP"); + refreshGuideSources();paint();snapshot(true); + }else if(!verified&&(!readbackRequest||Date.now()-readbackSentAt>2500)){ + snapshot(true); + } + return true; +} const hint=t=>showText(el("mxHStatus"),t); const valid=s=>s&&Number.isInteger(s.key)&&s.key>=0&&s.key<12&& Number.isInteger(s.scale)&&s.scale>=0&&s.scale<=1&& @@ -176,7 +236,8 @@ function syncPower(){ power.setAttribute("aria-label",power.title); } function paint(){ - const v=latest||pending?.settings||settings; + const v=latest||pending?.settings|| + (heldPatch?{...settings,...heldPatch}:settings); const auto=v.guideMode===1; // Native LCD never guesses from music confidence or pending UI edits. // One atomic native readback is the actual effective DSP key+scale pair. @@ -186,6 +247,13 @@ function paint(){ const reliable=displayKey>=0&&displayKey<12&&displayScale>=0&&displayScale<=1; const inGraph=availableSources.some(ch=>ch.id===v.guideChannelId); const detected=auto&&detectedKey>=0&&detectedScale>=0; + // Gesture feedback is visibly immediate, but the active key still + // reflects ONLY the last native PCM ACK + authoritative readback. + const draft=latest||pending?.settings|| + (heldPatch?{...settings,...heldPatch}:null); + const queuedKey=nativeView&&draft&& + (draft.key!==settings.key||draft.scale!==settings.scale) + ?draft.key:-1; for(const b of guideButtons){ const active=Number(b.dataset.guideMode)===v.guideMode; b.classList.toggle("active",active); @@ -195,8 +263,11 @@ function paint(){ const source=el("mxHGuideSource"); const chosen=inGraph?v.guideChannelId:"0"; if(source.value!==chosen)source.value=chosen; - for(const b of noteButtons)b.classList.toggle("active", - reliable&&Number(b.dataset.key)===displayKey); + for(const b of noteButtons){ + b.classList.toggle("active", + reliable&&Number(b.dataset.key)===displayKey); + b.classList.toggle("queued",Number(b.dataset.key)===queuedKey); + } for(const b of voiceButtons){ const active=Number(b.dataset.voices)===v.voices; b.classList.toggle("active",active); @@ -231,6 +302,12 @@ function paint(){ showText(output,key==="gainDb"?v[key].toFixed(1)+" dB":Math.round(value)+"%"); } syncPower(); + const detectedNote=observedNote>=0 && observedNote<=127? + keys[observedNote%12]+String(Math.floor(observedNote/12)-1):""; + const tracking=nativeView? + !verified?"DSP SYNCING":detectedNote?"TRACKING "+detectedNote:"WAITING VOICE": + "DEMO"; + showText(el("mxHTracking"),tracking); showText(el("mxHLatency"),mode==="NATIVE"?readbackLatency+" samples":"DEMO"); } // One in-flight readback, a bounded retry on the EXISTING 12 Hz console @@ -246,24 +323,31 @@ function snapshot(force=false){ } function send(next){ const c=context(); - if(!c){hint("NATIVE INSTANCE CHANGED · REOPEN FX");return;} + if(!c||!verified){hint("HARMONY RECONNECTING · EDIT HELD");return;} if(pending){latest=next;hint("DSP APPLYING · LATEST EDIT HELD");paint();return;} const id="harm-"+String(Date.now()*1000+(seq++%1000)); pending={id,settings:next,ack:false,context:c,startedAt:Date.now()}; backend().emitEvent("arMixAction",{action:"nativeHarmonySetSettings", requestId:id,...c,settings:next}); - hint("DSP QUEUED · AWAITING AUDIO ACK");paint(); + hint(next.key!==settings.key||next.scale!==settings.scale? + "KEY "+keys[next.key]+(next.scale?"m":"")+" · AWAITING DSP ACK": + "DSP QUEUED · AWAITING AUDIO ACK");paint(); } function edit(patch){ - const next={...(latest||pending?.settings||settings),...patch}; + const next={...(latest||pending?.settings|| + (heldPatch?{...settings,...heldPatch}:settings)),...patch}; if(!valid(next))return; preset="custom"; if(!native()){ settings=next; demos.set(current?.track?.id+":"+current?.slot,{...settings}); hint("BROWSER PREVIEW · VISUAL ONLY · NO AUDIO"); - }else if(mode==="NATIVE")send(next); - else hint("NATIVE HARMONY NOT ACCEPTED"); + }else if(mode==="NATIVE"){ + if(!reconcileBinding()||!verified){ + heldPatch={...(heldPatch||{}),...patch}; + hint("HARMONY RECONNECTING · EDIT SAVED"); + }else send(next); + }else hint("NATIVE HARMONY NOT ACCEPTED"); paint(); } noteButtons.forEach(b=>b.addEventListener("click",()=> @@ -296,7 +380,12 @@ el("mxHPreset").addEventListener("change",e=>{ const next={...(latest||pending?.settings||settings),...change}; if(!native()){settings=next;demos.set(current?.track?.id+":"+current?.slot,{...next}); hint("BROWSER PREVIEW · VISUAL ONLY · NO AUDIO"); - }else if(mode==="NATIVE")send(next); + }else if(mode==="NATIVE"){ + if(!reconcileBinding()||!verified){ + heldPatch={...(heldPatch||{}),...change}; + hint("HARMONY RECONNECTING · PRESET SAVED"); + }else send(next); + } }paint(); }); el("mxHPower").addEventListener("click",()=>{ @@ -331,21 +420,26 @@ window.ArSonMixNativeHarmony=Object.freeze({ id:ID, insert(target){return Boolean(window.__ARMIX_NATIVE_M2__?.insertPlugin?.(ID,target));}, open(track,slot){ - pending=null;latest=null;seq++;observedNote=-1;readbackLatency=0; + pending=null;latest=null;heldPatch=null;verified=false; + seq++;observedNote=-1;readbackLatency=0; readbackRequest="";readbackSentAt=0; detectedKey=-1;detectedScale=-1;detectedConfidence=0;lastGuideRead=0; effectiveKey=-1;effectiveScale=-1;sourceSignature="";availableSources=[]; const n=state(),id=window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(track); const ch=n?.graph?.channels?.find(x=>x.id===id),insert=ch?.inserts?.[slot]; - current={track,slot,channelId:null,instanceId:null}; - if(native()&&n?.admitted&&insert?.catalogId===ID&&insert.id){ - current.channelId=id;current.instanceId=insert.id;mode="NATIVE"; - settings=fresh();hint("NATIVE · READING ACCEPTED DSP");snapshot(); - }else if(!native()){ + current={track,slot,channelId:id,instanceId:null, + boundEpoch:null,boundRevision:null}; + showText(el("mxHChannel"),track.name+" · FX "+(slot+1)); + if(native()){ + mode="NATIVE";settings=fresh(); + hint("HARMONY · LOCATING ACCEPTED DSP"); + if(n?.admitted&&insert?.catalogId===ID&&insert.id) + current.instanceId=insert.id; + reconcileBinding(); + }else{ mode="DEMO";settings={...(demos.get(track.id+":"+slot)||fresh())}; hint("BROWSER PREVIEW · VISUAL ONLY · NO AUDIO"); - }else{mode="UNAVAILABLE";settings=fresh();hint("NATIVE HARMONY SLOT NOT ACCEPTED");} - el("mxHChannel").textContent=track.name+" · FX "+(slot+1); + } root.hidden=false;refreshGuideSources();paint(); }, close(){root.hidden=true;} @@ -380,7 +474,7 @@ backend()?.addEventListener?.("arMixBuiltinHarmonySnapshot",snap=>{ if(pending.ack)hint("DSP APPLIED · WAITING READBACK"); return; } - settings={...snap.settings}; + settings={...snap.settings};verified=true; effectiveKey=snap.effectiveKey;effectiveScale=snap.effectiveScale; detectedKey=Number.isInteger(snap.guideDetectedKey)?snap.guideDetectedKey:-1; detectedScale=Number.isInteger(snap.guideDetectedScale)?snap.guideDetectedScale:-1; @@ -388,18 +482,28 @@ backend()?.addEventListener?.("arMixBuiltinHarmonySnapshot",snap=>{ observedNote=Number.isInteger(snap.observedNote)?snap.observedNote:-1; readbackLatency=Number.isInteger(snap.latencySamples)?snap.latencySamples:0; pending=null; + refreshGuideSources(); if(latest){const next=latest;latest=null;send(next);} - else hint(settings.guideMode===1?"NATIVE · LIVE MUSIC GUIDE":"NATIVE DSP ACCEPTED · "+c.instanceId); - refreshGuideSources();paint(); + else if(heldPatch){ + const patch=heldPatch;heldPatch=null; + const next={...settings,...patch}; + if(next.guideMode===1&& + !availableSources.some(ch=>ch.id===next.guideChannelId)){ + next.guideMode=0;next.guideChannelId="0"; + } + if(valid(next))send(next); + else hint("HARMONY RESTORED · INVALID EDIT DISCARDED"); + }else hint(settings.guideMode===1?"NATIVE · LIVE MUSIC GUIDE":"NATIVE DSP ACCEPTED · "+c.instanceId); + paint(); }); backend()?.addEventListener?.("arMixConsoleSnapshot",()=>{ - if(root.hidden||!native()||!current?.instanceId)return; + if(root.hidden||!native()||!current)return; queueMicrotask(()=>{ - if(!context()){ - pending=null;latest=null;effectiveKey=-1;effectiveScale=-1; - readbackRequest=""; - hint("DEVICE / GRAPH CHANGED · REOPEN ACCEPTED FX");paint();return; + if(!reconcileBinding()){ + hint("HARMONY RECONNECTING · WAITING FOR ACCEPTED FX"); + return; } + if(!verified)return; syncPower(); const now=Date.now(); if(pending){ @@ -413,7 +517,10 @@ backend()?.addEventListener?.("arMixConsoleSnapshot",()=>{ } return; } - if(settings.guideMode===1&&now-lastGuideRead>750){ + // Manual mode also needs real singer activity. The accepted native + // audio-owner observedNote already exists; use this 12Hz console tick + // at <=2Hz readback without allocating a new polling timer. + if(now-lastGuideRead>500){ lastGuideRead=now;snapshot(); } }); diff --git a/site/preview-v2/assets/mixer-native-peq.js b/site/preview-v2/assets/mixer-native-peq.js index e0b2e990e..270ec25b0 100644 --- a/site/preview-v2/assets/mixer-native-peq.js +++ b/site/preview-v2/assets/mixer-native-peq.js @@ -76,7 +76,8 @@ close.innerHTML=' { +"use strict"; +const ID="armix.builtin.vocal-throw.v1"; +const defaults=()=>({mode:2,bpm:120,division:0,repeats:3,captureMs:460, + silenceMs:220,thresholdDb:-35,wet:.42,decay:.55,ducking:.7}); +const presets={ + Concert:defaults(), + Fast:{...defaults(),division:1,repeats:4,captureMs:330,decay:.6}, + Ballad:{...defaults(),bpm:72,captureMs:650,wet:.48}, + Word:{...defaults(),mode:0,captureMs:280,silenceMs:180} +}; +const ranges={bpm:[60,200],repeats:[1,6],captureMs:[80,1500],silenceMs:[80,900], + thresholdDb:[-65,-15],wet:[0,1],decay:[.15,.9],ducking:[0,1]}; +const valid=s=>s&&[0,1,2].includes(s.mode)&&[0,1,2,3].includes(s.division)&& + Object.entries(ranges).every(([k,[min,max]])=> + Number.isFinite(s[k])&&s[k]>=min&&s[k]<=max); +const same=(a,b)=>Object.keys(defaults()).every(k=>a[k]===b[k]); +const clamp=(v,min,max)=>Math.max(min,Math.min(max,v)); +const backend=()=>window.__JUCE__?.backend; +const native=()=>typeof backend()?.emitEvent==="function"; +const snapshot=()=>window.__ARMIX_NATIVE_M2__?.state?.()?.current; + +const panel=document.createElement("section"); +panel.className="mx-vthrow";panel.id="mxNativeVocalThrow";panel.hidden=true; +panel.setAttribute("role","dialog");panel.setAttribute("aria-modal","false"); +panel.setAttribute("aria-label","ArSon Vocal Throw"); +// One universal 260-degree rounded level arc for EVERY hardware encoder. +// The face itself stays stationary; only the pointer and stroke advance. +const rotaryArc=''; +panel.innerHTML=[ + '
ARSONVOCAL THROW
', + '', + '', + '
', + '
', + '
', + '
', + '
MIX42%
', + '
', + '
TEMPOMAN
BPM
', + '
', + '
RHYTHM
1/4 · HYBRID
', + '
TAP
', + '
LIVE0
' +].join(""); +document.body.append(panel); +const $=id=>panel.querySelector("#"+id); +const encoderMeta={ + captureMs:["CAPTURE","ms",5,"vtEncodersLeft"], + silenceMs:["END","ms",10,"vtEncodersLeft"], + thresholdDb:["GATE","dB",1,"vtEncodersLeft"], + decay:["DECAY","%",.01,"vtEncodersRight"], + ducking:["DUCK","%",.01,"vtEncodersRight"], + repeats:["REPEATS","x",1,"vtEncodersRight"] +}; +for(const [key,[title,unit,,bank]] of Object.entries(encoderMeta)){ + const node=document.createElement("div"); + node.className="vt-encoder";node.dataset.key=key; + node.innerHTML=''+title+''+ + ''+ + ''; + node.querySelector("output").dataset.unit=unit; + $(bank).append(node); +} +let current=null,accepted=defaults(),draft=defaults(),pending=null, + readId="",readSent=0,seq=1,taps=[],windowDrag=null; +let tempoPending=null,musicSource="0",musicReadback=null; +const context=()=>{ + const state=snapshot(),id=current&&window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(current.track); + const fx=state?.graph?.channels?.find(ch=>ch.id===id)?.inserts?.[current?.slot]; + if(!state?.admitted||!id||fx?.catalogId!==ID||fx?.id!==current?.instanceId)return null; + return {channelId:id,slot:current.slot,instanceId:fx.id, + deviceEpoch:state.device.epoch,graphRevision:state.graph.revision}; +}; +const hint=text=>{$("vtHint").textContent=text;}; +function refreshMusicChannels(){ + const state=snapshot(),ctx=context(),selector=$("vtMusicSource"); + const selected=tempoPending?.source||musicSource; + const candidates=(state?.graph?.channels||[]).filter(ch=> + ch&&ch.id&&String(ch.id)!==String(ctx?.channelId)&& + ["INPUT","GROUP","FX_RETURN","FXRETURN"].includes( + String(ch.role||"").toUpperCase().replaceAll("-","_"))); + selector.replaceChildren(new Option("Manual / TAP","0")); + for(const ch of candidates)selector.add(new Option( + String(ch.name||ch.id).slice(0,45),String(ch.id))); + if([...selector.options].some(x=>x.value===String(selected))) + selector.value=String(selected); + else selector.value="0"; + selector.disabled=!ctx||!native()||Boolean(tempoPending); +} +function renderMusicStatus(tempo){ + if(tempo)musicReadback=tempo; + const label=$("vtMusicStatus"),clock=$("vtClockLabel"),number=$("vtDisplayBpm"); + const fallback=()=>{number.textContent=String(Math.round(accepted.bpm));clock.textContent="MAN";}; + if(tempoPending){label.textContent="CONNECT";label.title="Validating music channel";clock.textContent="CHECK";return;} + if(musicSource==="0"){label.textContent="TAP";label.title="Manual BPM / TAP";fallback();return;} + if(!musicReadback?.musicSourceActive){label.textContent="NO SIGNAL";label.title="Music source unavailable · manual BPM fallback";fallback();return;} + if(!musicReadback.musicLocked){label.textContent="LISTEN";label.title="Listening for beat · manual BPM fallback";fallback();return;} + const confidence=Math.round(Math.max(0,Math.min(1,Number(musicReadback.musicConfidence)||0))*100); + const beatGrid=musicReadback.musicGridAvailable===true; + const bpm=Math.round(Number(musicReadback.musicBpm)); + label.textContent=beatGrid?bpm+" · GRID":bpm+" · BPM"; + label.title="Auto tempo "+bpm+" BPM · "+confidence+"% confidence · "+(beatGrid?"beat grid":"BPM only"); + clock.textContent=beatGrid?"LOCK":"AUTO"; + number.textContent=String(bpm); +} +function syncPower(){ + const state=snapshot(),id=current&&window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(current.track); + const lane=state?.graph?.channels?.find(ch=>ch.id===id),fx=lane?.inserts?.[current?.slot]; + const value=!context()?"unknown":lane.fxRackBypassed?"rack-off":fx.bypassed?"off":"on"; + panel.dataset.fxState=value; + const btn=$("vtPower");btn.dataset.fxState=value; + btn.disabled=value==="unknown"||value==="rack-off"; + btn.title=value==="on"?"Active · click to bypass":value==="off"?"Bypassed · click to enable": + value==="rack-off"?"FX rack bypassed":"Native FX unavailable"; + btn.setAttribute("aria-pressed",String(value==="on")); + btn.setAttribute("aria-label",btn.title); + $("vtThrow").disabled=value!=="on"||!!pending; + $("vtStatus").textContent=value==="on"? + ($("vtThrow").dataset.tail==="true"?"TAIL":"LIVE"): + value==="off"?"BYPASS":value==="rack-off"?"RACK OFF":"OFFLINE"; +} +function paint(){ + $("vtMode").value=String(draft.mode); + if(panel.querySelector(".vt-clock-screen").dataset.editing!=="true") + $("vtBpm").value=String(draft.bpm); + $("vtDivision").value=String(draft.division);$("vtRepeats").value=String(draft.repeats); + for(const [key,[,unit]] of Object.entries(encoderMeta)){ + const node=panel.querySelector('.vt-encoder[data-key="'+key+'"]'); + const min=ranges[key][0],max=ranges[key][1]; + const pct=(draft[key]-min)/(max-min); + const turn=-130+260*pct; + node.style.setProperty("--turn",turn.toFixed(2)+"deg"); + // pathLength=100 guarantees a linearly advancing, rounded 260-degree arc. + // Never rotate the knob chassis with the pointer. + node.style.setProperty("--arc-offset",(100-pct*100).toFixed(3)); + node.querySelector(".vt-encoder-value").textContent= + (unit==="%"?Math.round(draft[key]*100):Math.round(draft[key]))+unit; + const dial=node.querySelector(".vt-encoder-face"); + dial.setAttribute("aria-valuemin",String(min)); + dial.setAttribute("aria-valuemax",String(max)); + dial.setAttribute("aria-valuenow",String(draft[key])); + dial.setAttribute("aria-valuetext",node.querySelector(".vt-encoder-value").textContent); + } + const wetPct=Math.round(draft.wet*100); + $("vtWetValue").textContent=wetPct+"%"; + $("vtWetDial").style.setProperty("--turn",(-130+260*draft.wet).toFixed(2)+"deg"); + $("vtWetDial").style.setProperty("--arc-offset",(100-draft.wet*100).toFixed(3)); + $("vtWetDial").setAttribute("aria-valuenow",String(wetPct)); + $("vtWetDial").setAttribute("aria-valuetext",wetPct+" percent"); + for(const b of panel.querySelectorAll(".vt-mode-buttons button")) + b.setAttribute("aria-pressed",String(Number(b.dataset.mode)===draft.mode)); + for(const b of panel.querySelectorAll(".vt-division-buttons button")) + b.setAttribute("aria-pressed",String(Number(b.dataset.division)===draft.division)); + $("vtPreset").value=Object.entries(presets).find(([,v])=>same(v,draft))?.[0]||"Custom"; + const rhythmic=["1/4","1/8","DOTTED 1/8","1/2"][accepted.division]; + const modes=["MANUAL","AUTO","HYBRID"]; + $("vtRhythm").textContent=rhythmic+" · "+modes[accepted.mode]; + for(const [index,led] of [...$("vtBeatRail").querySelectorAll("i")].entries()) + led.dataset.on=String(index{ + if(!current||pending)return; + bpmScreen.dataset.editing="true"; + $("vtBpm").value=String(draft.bpm); + $("vtBpm").focus();$("vtBpm").select(); +}); +$("vtBpm").addEventListener("keydown",e=>{ + if(e.key==="Escape"){ + e.preventDefault();e.stopPropagation(); + $("vtBpm").value=String(accepted.bpm); + $("vtBpm").blur(); + }else if(e.key==="Enter"){ + e.preventDefault();$("vtBpm").blur(); + } +}); +$("vtBpm").addEventListener("blur",()=>{bpmScreen.dataset.editing="false";}); +for(const [key,id] of [["mode","vtMode"],["bpm","vtBpm"], + ["division","vtDivision"],["repeats","vtRepeats"]]){ + $(id).addEventListener("change",()=>{ + draft={...draft,[key]:Number($(id).value)};paint();send("nativeThrowSet"); + }); +} +// Physical rotary control: vertical pointer drag, mouse wheel and keyboard. +// Update visual locally during movement; issue exactly ONE accepted native +// settings intent at drag release. No DOM/audio DSP loops are introduced. +function bindRotary(face,key,step){ + const [min,max]=ranges[key]; + const quantize=v=>clamp(Math.round(v/step)*step,min,max); + let gesture=null; + const update=v=>{if(pending)return;draft={...draft,[key]:quantize(v)};paint();}; + face.addEventListener("pointerdown",e=>{ + if(e.button!==0||pending)return; + gesture={id:e.pointerId,y:e.clientY,initial:draft[key],changed:false}; + face.setPointerCapture(e.pointerId);e.preventDefault(); + }); + face.addEventListener("pointermove",e=>{ + if(!gesture||gesture.id!==e.pointerId)return; + const next=quantize(gesture.initial+(gesture.y-e.clientY)*(max-min)/168); + if(next!==draft[key]){gesture.changed=true;update(next);} + e.preventDefault(); + }); + const finish=e=>{ + if(!gesture||e.pointerId!==gesture.id)return; + const changed=gesture.changed;gesture=null; + if(face.hasPointerCapture?.(e.pointerId))face.releasePointerCapture(e.pointerId); + if(changed)send("nativeThrowSet"); + }; + face.addEventListener("pointerup",finish); + face.addEventListener("pointercancel",()=>{gesture=null;paint();}); + face.addEventListener("wheel",e=>{ + if(pending)return; + e.preventDefault();update(draft[key]+(e.deltaY<0?step:-step)); + send("nativeThrowSet"); + },{passive:false}); + face.addEventListener("keydown",e=>{ + const delta={ArrowUp:1,ArrowRight:1,ArrowDown:-1,ArrowLeft:-1,PageUp:5,PageDown:-5}[e.key]; + if(delta===undefined&&e.key!=="Home"&&e.key!=="End")return; + e.preventDefault(); + update(e.key==="Home"?min:e.key==="End"?max:draft[key]+delta*step); + send("nativeThrowSet"); + }); + face.addEventListener("dblclick",()=>{ + if(pending)return; + update(defaults()[key]);send("nativeThrowSet"); + }); +} +for(const [key,[,,step]] of Object.entries(encoderMeta)) + bindRotary(panel.querySelector('.vt-encoder[data-key="'+key+'"] .vt-encoder-face'),key,step); +bindRotary($("vtWetDial"),"wet",.01); +for(const button of panel.querySelectorAll(".vt-mode-buttons button")){ + button.addEventListener("click",()=>{ + $("vtMode").value=button.dataset.mode; + $("vtMode").dispatchEvent(new Event("change",{bubbles:true})); + }); +} +for(const button of panel.querySelectorAll(".vt-division-buttons button")){ + button.addEventListener("click",()=>{ + $("vtDivision").value=button.dataset.division; + $("vtDivision").dispatchEvent(new Event("change",{bubbles:true})); + }); +} +$("vtMusicSource").addEventListener("change",()=>{ + const ctx=context(),source=String($("vtMusicSource").value); + if(!ctx||!native()||tempoPending){refreshMusicChannels();return;} + const requestId="tempo-"+Date.now()+"-"+(++seq); + tempoPending={requestId,source,created:Date.now()}; + backend().emitEvent("arMixAction",{ + action:"nativeThrowTempoSource",requestId,sourceChannelId:source,...ctx}); + renderMusicStatus();refreshMusicChannels(); +}); +$("vtPreset").addEventListener("change",()=>{ + const p=presets[$("vtPreset").value];if(!p)return; + draft={...p};paint();send("nativeThrowSet"); +}); +$("vtThrow").addEventListener("click",()=>send("nativeThrowTrigger")); +$("vtTap").addEventListener("click",()=>{ + const now=performance.now(); + if(taps.length&&now-taps[taps.length-1]>2500)taps=[]; + taps.push(now);if(taps.length>6)taps.shift(); + if(taps.length<3){hint("Tap at least three beats");return;} + const deltas=taps.slice(1).map((time,i)=>time-taps[i]).filter(v=>v>=280&&v<=1200); + if(deltas.length<2){hint("Tap a steady beat");return;} + const ordered=[...deltas].sort((a,b)=>a-b); + const median=ordered[Math.floor(ordered.length/2)]; + draft={...draft,bpm:clamp(Math.round(60000/median),60,200)}; + paint();send("nativeThrowSet"); +}); +$("vtPower").addEventListener("click",()=>{ + if(current&&context())window.__ARMIX_NATIVE_M2__?.consumeAction?.( + current.track,"slotPower",{dataset:{slot:String(current.slot)}}); +}); +$("vtClose").addEventListener("click",()=>{panel.hidden=true;pending=null;tempoPending=null;readId="";}); +window.addEventListener("keydown",e=>{ + if(e.key==="Escape"&&!panel.hidden){panel.hidden=true;pending=null;readId="";} +}); +const head=panel.querySelector("header"); +head.addEventListener("pointerdown",e=>{ + if(e.button||e.target.closest("button,select"))return; + const box=panel.getBoundingClientRect(); + windowDrag={id:e.pointerId,dx:e.clientX-box.left,dy:e.clientY-box.top}; + head.setPointerCapture(e.pointerId);e.preventDefault(); +}); +head.addEventListener("pointermove",e=>{ + if(!windowDrag||e.pointerId!==windowDrag.id)return; + panel.style.left=clamp(e.clientX-windowDrag.dx,0,Math.max(0,innerWidth-panel.offsetWidth))+"px"; + panel.style.top=clamp(e.clientY-windowDrag.dy,0,Math.max(0,innerHeight-panel.offsetHeight))+"px"; +}); +head.addEventListener("pointerup",e=>{windowDrag=null;head.releasePointerCapture?.(e.pointerId);}); +window.ArSonMixNativeVocalThrow=Object.freeze({ + id:ID, + insert(target){return Boolean(window.__ARMIX_NATIVE_M2__?.insertPlugin?.(ID,target));}, + open(track,slot){ + current={track,slot,instanceId:null};pending=null;tempoPending=null;musicSource="0";musicReadback=null;readId=""; + const state=snapshot(),id=window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(track); + const insert=state?.graph?.channels?.find(ch=>ch.id===id)?.inserts?.[slot]; + if(native()&&state?.admitted&&insert?.catalogId===ID&&insert.id){ + current.instanceId=insert.id;draft=defaults();accepted=defaults(); + hint(""); + }else if(!native()){draft=defaults();accepted=defaults(); + hint("Browser preview only · no PCM");} + else hint("Native FX instance unavailable"); + $("vtChannel").textContent=track.name||"CH"; + panel.hidden=false;paint();refreshMusicChannels();requestSnapshot(true); + }, + close(){panel.hidden=true;} +}); +backend()?.addEventListener?.("arMixBuiltinThrowTempoAck",reply=>{ + if(!tempoPending||reply?.requestId!==tempoPending.requestId)return; + if(reply.status==="APPLIED"){ + musicSource=tempoPending.source; + hint(""); + }else hint("Tempo source rejected · "+(reply.errorCode||"STALE")); + tempoPending=null;refreshMusicChannels();renderMusicStatus(); + requestSnapshot(true); +}); +backend()?.addEventListener?.("arMixBuiltinThrowQueue",reply=>{ + if(!pending||reply?.requestId!==pending.requestId)return; + if(reply.status==="REJECTED"){hint("DSP rejected · "+(reply.errorCode||"STALE")); + pending=null;requestSnapshot(true);syncPower();} +}); +backend()?.addEventListener?.("arMixBuiltinThrowAck",reply=>{ + if(!pending||reply?.requestId!==pending.requestId)return; + if(reply.status!=="APPLIED"){hint("DSP rejected · "+(reply.errorCode||"UNKNOWN")); + pending=null;requestSnapshot(true);syncPower();return;} + if(pending.command==="nativeThrowTrigger"){hint(""); + pending=null;requestSnapshot(true);syncPower();} + else{pending.ack=true;requestSnapshot(true);} +}); +backend()?.addEventListener?.("arMixBuiltinThrowSnapshot",reply=>{ + if(panel.hidden||reply?.requestId!==readId)return; + readId="";readSent=0; + const ctx=context(); + if(!ctx||reply.status!=="ACCEPTED"||reply.channelId!==ctx.channelId|| + reply.instanceId!==ctx.instanceId||reply.deviceEpoch!==ctx.deviceEpoch|| + reply.graphRevision!==ctx.graphRevision||!valid(reply.settings)|| + reply.addedLatencySamples!==0){hint("Stale FX graph · reopen editor");return;} + if(reply.musicSourceChannelId!==undefined) { + musicSource=String(reply.musicSourceChannelId||"0"); + refreshMusicChannels();renderMusicStatus(reply); + } + $("vtCount").textContent=String(reply.throwCount||0); + $("vtCount").setAttribute("aria-label",String(reply.throwCount||0)+" completed throws"); + $("vtDot").classList.toggle("active",reply.tailActive===true); + $("vtBeatRail").dataset.playing=String(reply.tailActive===true); + $("vtThrow").dataset.tail=String(reply.tailActive===true); + $("vtStatus").textContent=reply.tailActive?"TAIL":"LIVE"; + if(pending){ + if(!pending.ack||reply.appliedRequestId!==pending.requestId)return; + accepted={...reply.settings};draft={...accepted};pending=null; + hint(""); + }else{accepted={...reply.settings};draft={...accepted};} + paint(); +}); +backend()?.addEventListener?.("arMixConsoleSnapshot",()=>{ + if(panel.hidden)return; + if(native()&&!context()){ + pending=null;tempoPending=null; + hint("FX graph changed · reopen"); + } + refreshMusicChannels();syncPower(); +}); +window.setInterval(()=>{ + if(panel.hidden)return; + if(pending&&Date.now()-pending.created>3500){hint("DSP ACK timeout");pending=null;} + if(tempoPending&&Date.now()-tempoPending.created>3500){ + hint("Tempo source ACK timeout");tempoPending=null;refreshMusicChannels(); + } + if(native())requestSnapshot(); + syncPower(); +},250); +})(); diff --git a/site/preview-v2/index.html b/site/preview-v2/index.html index c2fa7648b..8d6bf0221 100644 --- a/site/preview-v2/index.html +++ b/site/preview-v2/index.html @@ -1284,6 +1284,9 @@ /* One accepted CH→MAIN edge is represented by two local cable fragments. Physical coordinates are measured from actual sockets; never connect strips with a long SVG crossing banks or alter the audio graph. */ +// MAIN mini cables use a separate one-shot dirty flag; ordinary pointer moves +// must not force layout reads on a stable native viewport. +let wireFragmentGeometryDirty=false; function paintMainWireFragment(strip,edge,isMain){ const section=strip?.querySelector('.send-section.wire-section'); if(!section)return; @@ -1292,9 +1295,9 @@ layer?.remove();return; } // Pointer-motion repaint must not synchronously remeasure every channel. - // Structural render, bank, density and resize remount the section; a - // changed accepted edgeId invalidates this tiny projection automatically. - if(layer?.dataset.edgeId===String(edge.id))return; + // A stable edgeId can still move when the host window is resized. + // Refresh the physical anchor only on a geometry event (or edge edit). + if(layer?.dataset.edgeId===String(edge.id)&&!wireFragmentGeometryDirty)return; const jack=section.querySelector(isMain?'.wire-node-in .wire-arrow':'.wire-node-out .wire-pin'); const sectionRect=section.getBoundingClientRect(),pin=jack?.getBoundingClientRect(); if(!pin||!sectionRect.width||!sectionRect.height)return; @@ -1355,6 +1358,7 @@ } function renderWireRouting(){ syncMainWireFragments(); + wireFragmentGeometryDirty=false; if(wireWsOpen&&!wireGesture?.active)renderWireWorkspace(); document.querySelector('.console-body')?.classList.toggle('wire-intent',!!wireIntent); const svg=document.getElementById('wireLayer'),viewport=document.getElementById('viewport'); @@ -2879,10 +2883,68 @@ document.getElementById(e.key==='ArrowRight'?'bankNext':'bankPrev').click(); } }); -let resizeQueued=false; -window.addEventListener('resize',()=>{ - if(resizeQueued)return;resizeQueued=true; - requestAnimationFrame(()=>{resizeQueued=false;render();}); +// Desktop maximise, restore, DPI changes and normal resizing are layout events, +// not mixer/PCM edits. Read the true socket bounds AFTER layout and coalesce +// concurrent ResizeObserver + viewport events into one animation frame. +let wireGeometryFrame=0,wireGeometryDirty=false; +function scheduleWireGeometryReflow(){ + wireGeometryDirty=true; + if(wireGeometryFrame||document.hidden)return; + wireGeometryFrame=requestAnimationFrame(()=>{ + wireGeometryFrame=0; + if(document.hidden)return; + const viewport=document.getElementById('viewport'); + if(!viewport||viewport.clientWidth<=0||viewport.clientHeight<=0)return; + wireGeometryDirty=false; + const root=document.querySelector('.console-body'); + const drawn=Number(root?.style.getPropertyValue('--bank-capacity')); + const required=bankCapacity(); + if(drawn&&required!==drawn){ + // A bank rebuild destroys pointer-capture owners. Retire only in-flight + // UI gestures BEFORE the strips are replaced; the committed WIRE graph, + // route identities and accepted fader level never change on resize. + if(wireGesture){ + const g=wireGesture;wireGesture=null;wireSuppressClick=true; + setWireSnapTarget(null); + root?.classList.remove('wire-dragging'); + root?.querySelectorAll('.is-replug-origin,.is-drag-origin').forEach(el=> + el.classList.remove('is-replug-origin','is-drag-origin')); + const owner=root?.querySelector('.strip[data-id="'+(g.originDestId??g.sourceId)+'"] '+ + (g.originDestId!=null?'.wire-node-in':'.wire-node-out')); + if(owner?.hasPointerCapture?.(g.pointerId))owner.releasePointerCapture?.(g.pointerId); + } + if(faderGesture){ + const g=faderGesture;faderGesture=null; + if(g.box?.hasPointerCapture?.(g.pointerId))g.box.releasePointerCapture?.(g.pointerId); + } + // Kill any RAF that still closes over the pre-resize cable coordinates. + ++wireMotion.token;wireMotion.key=null;wireMotion.offset=0; + render(); // structural bank change only + }else{ + // Stop a still-running cable spring (its animation closes over old pixels). + ++wireMotion.token;wireMotion.key=null;wireMotion.offset=0; + wireFragmentGeometryDirty=true; + renderWireRouting(); // geometry-only; no native graph/strip edits + } + }); +} +// WebView2 can resize its child compositor one event AFTER the parent HWND. +// Observe stable mixer boxes rather than polling or assuming old viewport width. +if(typeof ResizeObserver==='function'){ + const wireGeometryObserver=new ResizeObserver(scheduleWireGeometryReflow); + for(const id of ['viewport','tracks','master']){ + const el=document.getElementById(id); + if(el)wireGeometryObserver.observe(el); + } + wireGeometryObserver.observe(document.querySelector('.console-body')); +} +window.addEventListener('resize',scheduleWireGeometryReflow,{passive:true}); +window.visualViewport?.addEventListener?.('resize',scheduleWireGeometryReflow,{passive:true}); +document.getElementById('viewport')?.addEventListener?.('scroll',scheduleWireGeometryReflow,{passive:true}); +window.addEventListener('focus',scheduleWireGeometryReflow,{passive:true}); +window.addEventListener('pageshow',scheduleWireGeometryReflow,{passive:true}); +document.addEventListener('visibilitychange',()=>{ + if(!document.hidden)scheduleWireGeometryReflow(); }); restorePluginPreferences();init(); })(); diff --git a/src/ArSonWindowChrome.h b/src/ArSonWindowChrome.h new file mode 100644 index 000000000..68ef2cd69 --- /dev/null +++ b/src/ArSonWindowChrome.h @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include + +namespace armix::ui +{ +// Only the main JUCE mixer window uses this caption. No WebView2 command +// round trips for minimise, maximise, close, drag or OS window resizing. +class MixerCaptionButton final : public juce::Button +{ +public: + explicit MixerCaptionButton (int kind) : Button ("ArSonMiX window control"), kind_ (kind) + { + // Exact operator-provided SVG path geometry, in its native 24x24 coordinates. + icon_ = load (kind == juce::DocumentWindow::closeButton + ? "M6.4,19L5,17.6L10.6,12L5,6.4L6.4,5L12,10.6L17.6,5L19,6.4L13.4,12L19,17.6L17.6,19L12,13.4L6.4,19Z" + : kind == juce::DocumentWindow::minimiseButton + ? "M6,21V19H18v2H6Z" + : "M3,21V3H21V21H3Zm2-2H19V5H5V19Zm0,0V5V19Z"); + if (kind == juce::DocumentWindow::maximiseButton) + restoreIcon_ = load ("M8,3H21V16H18V6H8V3ZM3,8H16V21H3V8ZM6,11V18H13V11H6Z"); + setTooltip (kind == juce::DocumentWindow::closeButton ? "Close" : + kind == juce::DocumentWindow::minimiseButton ? "Minimise" : "Maximise / restore"); + setMouseCursor (juce::MouseCursor::PointingHandCursor); + } + + void paintButton (juce::Graphics& g, bool over, bool down) override + { + const bool close = kind_ == juce::DocumentWindow::closeButton; + // Compact 34 px hit area; only the 30x25 interior lights on hover. + // No timers, interpolated animations, allocation or WebView2 messaging. + // A pressed command is immediately visible: teal minimise, blue + // maximise/restore, and intentionally red close. + if (over || down) + { + // Clear chromatic outline on hover; solid pressed state. + // The native JUCE Button repaints only on its mouse-state change. + const bool minimise = kind_ == juce::DocumentWindow::minimiseButton; + const auto accent = close ? juce::Colour (0xffff6874) + : minimise ? juce::Colour (0xff50d4e7) + : juce::Colour (0xff67b9ff); + const auto pressed = close ? juce::Colour (0xffdc3549) + : minimise ? juce::Colour (0xff168fa7) + : juce::Colour (0xff287abd); + const auto face = getLocalBounds().toFloat().reduced (2.0f, 3.0f); + g.setColour (down ? pressed : accent.withAlpha ((juce::uint8) 27)); + g.fillRoundedRectangle (face, 3.0f); + g.setColour (accent); + g.drawRoundedRectangle (face.reduced (0.5f), 3.0f, 1.0f); + } + if (hasKeyboardFocus (true)) + { + g.setColour (juce::Colour (0xff68d9f2)); + g.drawRoundedRectangle (getLocalBounds().toFloat().reduced (1.5f, 2.5f), 3.0f, 1.0f); + } + auto* parent = findParentComponentOfClass(); + auto* image = kind_ == juce::DocumentWindow::maximiseButton && + parent != nullptr && parent->isFullScreen() + ? restoreIcon_.get() : icon_.get(); + if (image != nullptr) + { + const auto b = getLocalBounds().toFloat(); + image->drawWithin (g, { b.getCentreX() - 6.0f, b.getCentreY() - 6.0f, 12.0f, 12.0f }, + juce::RectanglePlacement::centred, isEnabled() ? 1.0f : 0.45f); + } + } + +private: + static std::unique_ptr load (const char* path) + { + juce::String source (""; + if (auto xml = juce::XmlDocument::parse (source)) + return juce::Drawable::createFromSVG (*xml); + return {}; + } + int kind_; + std::unique_ptr icon_, restoreIcon_; +}; + +class MixerCaptionLookAndFeel final : public juce::LookAndFeel_V4 +{ +public: + juce::Button* createDocumentWindowButton (int kind) override + { + return new MixerCaptionButton (kind); + } + + void positionDocumentWindowButtons (juce::DocumentWindow&, int x, int y, int w, int h, + juce::Button* minimise, juce::Button* maximise, + juce::Button* close, bool onLeft) override + { + constexpr int buttonWidth = 34; + if (onLeft) + { + for (auto* button : { close, minimise, maximise }) + if (button != nullptr) { button->setBounds (x, y, buttonWidth, h); x += buttonWidth; } + } + else + { + x += w; + for (auto* button : { close, maximise, minimise }) + if (button != nullptr) { x -= buttonWidth; button->setBounds (x, y, buttonWidth, h); } + } + } + + void drawDocumentWindowTitleBar (juce::DocumentWindow& window, juce::Graphics& g, + int w, int h, int titleX, int titleW, + const juce::Image* icon, bool) override + { + g.fillAll (juce::Colour (0xff112632)); + g.setColour (juce::Colour (0xff365b6b)); + g.drawHorizontalLine (h - 1, 0.0f, static_cast (w)); + int x = juce::jmax (10, titleX + 9); + if (icon != nullptr && icon->isValid()) + { + g.drawImageWithin (*icon, x, (h - 16) / 2, 16, 16, + juce::RectanglePlacement::centred, false); + x += 23; + } + const auto brandFont = juce::Font (juce::FontOptions { 13.0f }); + g.setFont (brandFont); + const auto alpha = window.isActiveWindow() ? 1.0f : 0.72f; + auto paintPart = [&] (const juce::String& word, juce::Colour colour) + { + // Real glyph advances: "ArSonMiX" is one continuous wordmark. + const auto advance = juce::GlyphArrangement::getStringWidthInt (brandFont, word); + g.setColour (colour.withMultipliedAlpha (alpha)); + g.drawText (word, x, 0, advance + 2, h, juce::Justification::centredLeft, false); + x += advance; + }; + paintPart ("Ar", juce::Colour (0xff48d5f3)); + paintPart ("Son", juce::Colour (0xffeff8fa)); + paintPart ("MiX", juce::Colour (0xffffad59)); + x += 15; + const auto remaining = juce::jmax (0, titleX + titleW - x - 9); + if (remaining > 80) + { + // Explicit Unicode code point prevents mojibake in MSVC builds. + const auto subtitle = juce::String ("Open Source Premium Digital Mixer | Version 01.00 | ") + + juce::String::charToString ((juce::juce_wchar) 0x00a9) + " 2026 SonKuPik"; + g.setColour (juce::Colour (0xff96b3bf).withMultipliedAlpha (alpha)); + g.setFont (juce::Font (juce::FontOptions { 10.5f })); + g.drawText (subtitle, x, 0, remaining, h, + juce::Justification::centredLeft, true); + } + } +}; +} // namespace armix::ui diff --git a/src/DiagnosticTone.h b/src/DiagnosticTone.h index fbedcc300..b7647649d 100644 --- a/src/DiagnosticTone.h +++ b/src/DiagnosticTone.h @@ -7,7 +7,7 @@ namespace armix::diagnostics { // Diagnostic routes are temporary, never persisted as the chosen user device. -enum class Route : int { normal = 0, dryThrough = 1, outputOnlyTone = 2, captureOnly = 3 }; +enum class Route : int { normal = 0, dryThrough = 1, outputOnlyTone = 2, captureOnly = 3, mainOutputTone = 4 }; inline constexpr const char* routeName (Route route) noexcept { @@ -17,6 +17,7 @@ inline constexpr const char* routeName (Route route) noexcept case Route::dryThrough: return "DRY_THROUGH"; case Route::outputOnlyTone: return "OUTPUT_ONLY_TONE"; case Route::captureOnly: return "CAPTURE_ONLY"; + case Route::mainOutputTone: return "MAIN_OUTPUT_TONE"; } return "INVALID"; } diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index 77cc2b4c5..7768c6a43 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -14,6 +14,7 @@ #include "../engine/builtin_fx/ChannelEqProcessor.h" #include "../engine/builtin_fx/ChannelCompressorProcessor.h" #include "../engine/builtin_fx/ChannelHarmonyProcessor.h" +#include "../engine/builtin_fx/VocalThrowProcessor.h" #include "DiagnosticTone.h" #include "../engine/device/JuceIndependentClockDevice.h" #include "../engine/device/LiveSecondaryOutputDevice.h" @@ -191,6 +192,20 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // Prefer both input pins on a verified stereo endpoint; saved explicit // channel masks still take precedence. Outputs remain DISARMED. auto error = deviceManager_.initialise (2, 2, savedSettings, !savedRoute); + if(savedAsioPreflight && (error.isNotEmpty() || !deviceManager_.getCurrentAudioDevice() || + deviceManager_.getCurrentAudioDevice()->getActiveOutputChannels().countNumberOfSetBits()<2)) { + auto fallback=*savedSettings; + auto name=fallback.getStringAttribute("audioDeviceName"); + if(name.isEmpty())name=fallback.getStringAttribute("audioOutputDeviceName"); + if(name.startsWithIgnoreCase("ASIO4ALL")) { + const bool captureDisabled=fallback.getStringAttribute("audioDeviceInChans")=="0"; + if(!captureDisabled)fallback.removeAttribute("audioDeviceInChans"); + fallback.removeAttribute("audioDeviceOutChans"); + deviceManager_.closeAudioDevice(); + error=deviceManager_.initialise(2,2,&fallback,false); + } + } + #if defined(_WIN32) if (error.isNotEmpty() && !savedRoute && deviceManager_.singleAsioPreferred()) { @@ -211,6 +226,19 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback + " | Windows Audio fallback unavailable"; } #endif + // On first installation only, an output-only endpoint is a valid + // playback/Player host. Never replace a saved explicit ASIO route. + // Physical output is still muted and DIRECT-fenced until verified. + if(error.isNotEmpty() && !savedRoute) { + const auto outputError=deviceManager_.initialise(0,2,nullptr,true); + const auto* candidate=deviceManager_.getCurrentAudioDevice(); + if(outputError.isEmpty() && candidate && + candidate->getActiveOutputChannels().countNumberOfSetBits()>=2) { + startupFallbackReason_="AUTO_OUTPUT_ONLY_NO_CAPTURE"; + error.clear(); + } else if(outputError.isNotEmpty()) + error+=" | Output-only startup: "+outputError; + } if (error.isNotEmpty()) return error; const auto* active = deviceManager_.getCurrentAudioDevice(); if (active == nullptr) @@ -382,8 +410,10 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // Native AUDIO SETUP is the explicit user authorization boundary. // Suppress any live output while selecting/changing a device, even if JUCE // starts its new callback before the selector window is closed. - void beginManualAudioSetup() noexcept { + void beginManualAudioSetup(bool preserveMonitorIntent=false) noexcept { offeredWasapiBinding_.reset(); + if(!preserveMonitorIntent)resumeMainAfterAsioReset_.store(false,std::memory_order_release); + else if(isMonitorEnabled())resumeMainAfterAsioReset_.store(true,std::memory_order_release); setOutputMuted(true); secondaryOutput_.disarm(); directFence_.suspend(); @@ -391,7 +421,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // device-binding operation, not an implicit CLEAR MIXER command. // The JUCE selector may change the driver before its window closes. } - bool finishManualAudioSetup() { + bool finishManualAudioSetup(bool reuseAsioBinding=true) { if(!approveDirectRoute())return false; using Decision=armix::device::DeviceSessionDecision; switch(armix::device::decideDeviceSession( @@ -402,7 +432,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback case Decision::createFirstSilentMixer: return startUnpatchedProductionSession().isEmpty(); case Decision::retainUnboundMixer: - return rebindRetainedWasapiSession(); + return (reuseAsioBinding && reattachRetainedAsioMixer()) || rebindRetainedWasapiSession(); case Decision::rejectedDevice: return false; } @@ -432,6 +462,108 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback bool recoverSameWasapiMixer() { return hasRetainedUnboundMixer() && rebindRetainedWasapiSession(); } + // The JUCE ASIO device may restart itself after a control panel change. + // Reauthorize only the previously approved driver class and session. + bool sameRetainedAsioDriver() { + auto* device=deviceManager_.getCurrentAudioDevice(); + if(!device || !acceptedMixerBinding_ || !asioPinnedRegistration_.valid() || + device->getTypeName()!="ASIO" || device->getName()!=acceptedMixerBinding_->playback)return false; + const auto registered=armix::device::AsioRegistryIdentityProbe::resolve( + std::wstring(device->getName().toWideCharPointer())); + return registered.registration.ok() && + asioPinnedRegistration_.sameDriverClass(registered.registration.identity); + } + // A vendor ASIO4ALL restart can leave JUCE with NO current device object. + // Only the previously selected, explicitly approved driver name and its + // FULL registered CLSID may be reopened; never choose a default endpoint. + // CONTROL only: registry lookup and JUCE setup are forbidden in callback. + bool selectedRetainedAsioDriverForReopen() { + using Policy=armix::session::MixerDeviceBindingPolicy; + if(deviceManager_.getCurrentAudioDevice() || !acceptedMixerBinding_ || + !Policy::isAsio4All(*acceptedMixerBinding_) || + !asioPinnedRegistration_.valid() || !attached_ || independent_.active() || + deviceManager_.getCurrentAudioDeviceType()!="ASIO")return false; + juce::AudioDeviceManager::AudioDeviceSetup setup; + deviceManager_.getAudioDeviceSetup(setup); + if(setup.outputDeviceName.isEmpty() || + setup.outputDeviceName!=acceptedMixerBinding_->playback || + (!setup.inputDeviceName.isEmpty() && + setup.inputDeviceName!=acceptedMixerBinding_->capture))return false; + const auto registered=armix::device::AsioRegistryIdentityProbe::resolve( + std::wstring(setup.outputDeviceName.toWideCharPointer())); + return registered.registration.ok() && + asioPinnedRegistration_.sameDriverClass(registered.registration.identity); + } + bool authorizeRetainedAsioRestart() { + using Policy=armix::session::MixerDeviceBindingPolicy; + if(!hasRetainedNativeSession() || !acceptedMixerBinding_ || + !Policy::isAsio4All(*acceptedMixerBinding_) || !asioPinnedRegistration_.valid() || + !allOutputsDisarmed() || independent_.active() || !attached_ || handoff_.busy() || + fxMovePhase_.load(std::memory_order_acquire)!=0 || + routeReconfiguring_.load(std::memory_order_acquire) || + diagnosticRoute()!=armix::diagnostics::Route::normal)return false; + auto* device=deviceManager_.getCurrentAudioDevice(); + if(!device || !device->isOpen() || device->getTypeName()!="ASIO" || + device->getName()!=acceptedMixerBinding_->playback)return false; + return approveDirectRoute(&asioPinnedRegistration_); + } + std::optional asioRestartPinCorrection() { + using Policy=armix::session::MixerDeviceBindingPolicy; + auto* device=deviceManager_.getCurrentAudioDevice(); + if(!device || !acceptedMixerBinding_ || !directFence_.permitted())return {}; + const auto& previous=*acceptedMixerBinding_; + const auto live=readMixerBinding(*device); + if(live.backend!=previous.backend || live.capture!=previous.capture || + live.playback!=previous.playback)return {}; + juce::AudioDeviceManager::AudioDeviceSetup setup; + deviceManager_.getAudioDeviceSetup(setup); + const auto correct=[](const juce::String& oldMask,const juce::StringArray& oldNames, + const juce::StringArray& newNames,juce::BigInteger& mask, + bool& useDefault) { + if(oldNames==newNames)return false; + juce::BigInteger before; + before.parseString(oldMask,16); + const auto mapped=Policy::translateNamedPins(before,oldNames,newNames); + if(!mapped || *mapped==mask)return false; + mask=*mapped; + useDefault=false; + return true; + }; + const bool input=correct(previous.inputMask,previous.inputNames,live.inputNames, + setup.inputChannels,setup.useDefaultInputChannels); + const bool returning=Policy::addReturningCapturePins( + dryRoutingLab_.waitingAsioInputs(),live.inputNames,setup.inputChannels); + const bool output=correct(previous.outputMask,previous.outputNames,live.outputNames, + setup.outputChannels,setup.useDefaultOutputChannels); + if(!input && !output && !returning)return {}; + setup.useDefaultInputChannels=false; + setup.useDefaultOutputChannels=false; + return setup; + } + bool reattachRetainedAsioMixer() { + using Policy=armix::session::MixerDeviceBindingPolicy; + if(!acceptedMixerBinding_ || !Policy::isAsio4All(*acceptedMixerBinding_) || + !hasRetainedNativeSession() || !allOutputsDisarmed() || + !directFence_.permitted() || handoff_.busy())return false; + armix::session::MixerSessionDocument document; + if(!dryRoutingLab_.describeRetainedAsioSession(document))return false; + document.binding=*acceptedMixerBinding_; + MixerBindingInspection inspected; + constexpr auto mode=Policy::Mode::verifiedAsioRestart; + if(inspectNativeMixerSessionBinding(document,inspected,mode).isNotEmpty() || + inspected.live.rate!=document.binding.rate || + Policy::apply(document,inspected.live,inspected.outputs,inspected.callbackInputs,mode).isNotEmpty() || + !dryRoutingLab_.rebindRetainedAsioSession(std::move(document),inspected.pins, + inspected.live.frames))return false; + acceptedMixerBinding_=std::move(inspected.live); + return true; + } + bool takeAsioResetMonitorIntent() noexcept { + return resumeMainAfterAsioReset_.exchange(false,std::memory_order_acq_rel); + } + void cancelAsioResetMonitorIntent() noexcept { + resumeMainAfterAsioReset_.store(false,std::memory_order_release); + } bool hasRetainedNativeSession() const noexcept { return dryRoutingLab_.hasRetainedNativeSession(); } @@ -568,9 +700,35 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // user setup is restored on exit; temporary routes must not be persisted. juce::String setDiagnosticRoute (armix::diagnostics::Route wanted) { - if (dryRoutingLab_.hasAuthoredMixerContent()) - return "An authored mixer cannot enter endpoint isolation until a safe session rebind is available"; using Route = armix::diagnostics::Route; + const auto currentRoute=diagnosticRoute_.load(std::memory_order_acquire); + if(wanted==Route::mainOutputTone) { + if(currentRoute==wanted)return {}; + if(currentRoute!=Route::normal || independent_.active()) + return "Return to NORMAL on the DIRECT device before testing MAIN."; + if(const auto error=liveOutputArmFault(false);error.isNotEmpty())return error; + if(secondaryOutput_.armed()) + return "Stop STREAM before testing the physical MAIN output."; + const auto pair=dryRoutingLab_.acceptedMainCallbackPair(); + if(pair[0]<0 || pair[1]<0 || pair[0]==pair[1]) + return "No verified MAIN output pair."; + mainTestEpoch_.store(dryRoutingLab_.epoch(),std::memory_order_relaxed); + mainTestPair_.store(static_cast(pair[0]) | + (static_cast(pair[1])<<16),std::memory_order_relaxed); + mainTestWasArmed_=isMonitorEnabled(); + mainTestPeak_.store(0.f,std::memory_order_relaxed); + diagnosticRoute_.store(wanted,std::memory_order_release); + setMonitorEnabled(true); // the operator explicitly requested this isolated tone + return {}; + } + if(currentRoute==Route::mainOutputTone) { + // A diagnostic ARM does not authorize microphone audio on exit. + if(!mainTestWasArmed_)setOutputMuted(true); + diagnosticRoute_.store(Route::normal,std::memory_order_release); + if(wanted==Route::normal)return {}; + } + if (dryRoutingLab_.hasAuthoredMixerContent()) + return "Use MAIN OUTPUT TONE to test the output without reopening the authored mixer."; if (handoff_.busy()) return "Finish the pending FX graph transition first"; if (independent_.active()) return "Disable independent clock mode before endpoint isolation tests"; if (wanted == diagnosticRoute_.load (std::memory_order_acquire) && @@ -1132,6 +1290,13 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback formats_,device->getCurrentSampleRate(), juce::jmax(32,device->getCurrentBufferSizeSamples())); if(error.isEmpty() && dryRoutingLab_.epoch()==epoch) { + // The real SOURCE NONE graph is editable before any hardware IN + // patch; one ChannelId publisher remains the PCM authority. + if(!dryRoutingLab_.admitChannelIdFromAcceptedM4( + graphOwned_->count, + juce::jmax(32,device->getCurrentBufferSizeSamples()), + allOutputsDisarmed(),currentOriginalCh1Lease(),true)) + return "Prepared silent mixer could not admit native ChannelId graph"; acceptedMixerBinding_=readMixerBinding(*device); acceptedWasapiBinding_=std::move(profile); } @@ -1573,6 +1738,11 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback return {}; } + // Cold-start restore ONLY: the installed native SOURCE NONE starter has + // never been edited, so the durable saved Show can safely take ownership. + bool hasPristineStartupMixer() const noexcept { + return dryRoutingLab_.canReplacePristineStartupMixer(); + } // A single explicit user Play gesture prepares the previously verified // MAIN and creates its owned virtual MUSIC channel if absent. No manual // PATCH, MONITOR or ARM control is part of the ordinary user workflow. @@ -1923,6 +2093,65 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback } } + // ArSon Vocal Throw: single native PCM graph, same insert leases, bypass, + // ChannelId topology and dry monitoring as EQ/Compressor. + LiveDryRoutingLab::NativeBusResult installNativeBuiltInVocalThrow( + std::uint64_t ep,std::uint64_t pcmRevision, + std::uint64_t rosterRevision,armix::mixer::ChannelId id) { + LiveDryRoutingLab::NativeBusResult fail{}; + fail.error="NATIVE_THROW_HOST_UNAVAILABLE"; + auto* device=deviceManager_.getCurrentAudioDevice(); + if(independent_.active()||!attached_||!device|| + !directFence_.permitted()||secondaryOutput_.armed()|| + handoff_.busy()||fxMovePhase_.load(std::memory_order_acquire)!=0|| + routeReconfiguring_.load(std::memory_order_acquire)|| + diagnosticRoute_.load(std::memory_order_acquire)!= + armix::diagnostics::Route::normal)return fail; + if(ep!=dryRoutingLab_.epoch()){ + fail.error="NATIVE_THROW_DEVICE_CHANGED";return fail; + } + const auto rate=device->getCurrentSampleRate(); + const int frames=juce::jmax(32,device->getCurrentBufferSizeSamples()); + if(!(rate>=8000.&&rate<=192000.)|| + frames>LiveDryRoutingLab::Block::hardFrameLimit) { + fail.error="NATIVE_THROW_UNSUPPORTED_AUDIO_FORMAT";return fail; + } + try { + auto processor=std::make_unique(); + processor->prepareToPlay(rate,frames); + if(!processor->isReady()){ + fail.error="NATIVE_THROW_PREPARE_REJECTED";return fail; + } + auto lease=std::make_shared< + armix::mixer::LiveChannelFxGraph::FxInstance>( + std::move(processor), + juce::String(armix::builtin_fx::VocalThrowProcessor::catalogIdentity), + "ArSon Vocal Throw",LiveDryRoutingLab::Block::hardFrameLimit); + return dryRoutingLab_.attachNativeInsert(ep,pcmRevision, + rosterRevision,id, + armix::builtin_fx::VocalThrowProcessor::catalogIdentity, + std::move(lease),true); + } catch(...) { + fail.error="NATIVE_THROW_PREPARE_EXCEPTION";return fail; + } + } + + bool selectNativeMusicTempoSource(std::uint64_t epoch,std::uint64_t revision, + armix::mixer::ChannelId musicChannel) noexcept { + auto* device=deviceManager_.getCurrentAudioDevice(); + if(!device||independent_.active()||!attached_||!directFence_.permitted()) + return false; + return dryRoutingLab_.selectMusicTempoSource(epoch,revision, + musicChannel,device->getCurrentSampleRate()); + } + armix::mixer::NativeMusicTempoMonitor::State pollNativeMusicTempo() noexcept { + return dryRoutingLab_.pollMusicTempo(); + } + template + void forEachNativeProcessor(Callback&& visit) const { + dryRoutingLab_.forEachNativeProcessor(std::forward(visit)); + } + // User-owned VST3 on a true dynamic ChannelId. Instantiation/scan/layout // work is CONTROL only; the callback receives an immutable fx lease. LiveDryRoutingLab::NativeBusResult installNativeVst3( @@ -2175,6 +2404,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback : deviceManager_.getCurrentAudioDevice(); auto* capture = dual ? independent_.captureDevice() : d; o->setProperty ("dryRoutingLab",dryRoutingLab_.status(capture)); + o->setProperty("waitingAsioInputs",dryRoutingLab_.waitingAsioInputCount()); // NORMAL mode is never silently served by the legacy CH1 fallback. // This state is for operator feedback; it does not authorize output. o->setProperty ("productionRoutingState", @@ -2346,6 +2576,10 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback o->setProperty ("peak", outputPeak_.load()); o->setProperty ("peakLeft", outputPeakL_.load()); o->setProperty ("peakRight", outputPeakR_.load()); + o->setProperty ("driverBufferPeakLeft",driverBufferPeakL_.load(std::memory_order_relaxed)); + o->setProperty ("driverBufferPeakRight",driverBufferPeakR_.load(std::memory_order_relaxed)); + o->setProperty ("driverBufferProvenance","JUCE_CALLBACK_OUTPUT_POST_GATE"); + o->setProperty ("mainTestLastPeak",mainTestPeak_.load(std::memory_order_relaxed)); const auto loudness = masterLoudness_.read(); const bool measuredDirect = !dual && loudness.supported; o->setProperty ("masterAnalysisProvenance", @@ -2446,7 +2680,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const auto rate=device->getCurrentSampleRate(); const auto frames=device->getCurrentBufferSizeSamples(); if(inputs!=setup.inputChannels || outputs!=setup.outputChannels || - inputs.isZero() || outputs.countNumberOfSetBits()<2 || + outputs.countNumberOfSetBits()<2 || !std::isfinite(rate) || rate<8000.0 || rate!=setup.sampleRate || frames<16 || frames>LiveDryRoutingLab::Block::hardFrameLimit || frames!=setup.bufferSize)return {}; @@ -2502,8 +2736,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const armix::device::AsioRegistrationPolicy::Identity* expectedAsio = nullptr) { auto* device=deviceManager_.getCurrentAudioDevice(); - if (device == nullptr || device->getActiveInputChannels().isZero() - || device->getActiveOutputChannels().isZero()) + if (device == nullptr || device->getActiveOutputChannels().isZero()) return false; // JUCE BigInteger has no fixed 64-bit channel limit: preserve all // channel bits when locking an explicitly approved ASIO/WASAPI route. @@ -2513,6 +2746,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const auto inputMask=device->getActiveInputChannels().toString (16); const auto outputMask=device->getActiveOutputChannels().toString (16); armix::device::AsioRegistrationPolicy::Identity candidate; + if (backend != "ASIO" && expectedAsio != nullptr)return false; if (backend == "ASIO") { const auto selected = armix::device::AsioRegistryIdentityProbe::resolve ( @@ -2545,8 +2779,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback bool resumeVerifiedDirectRoute() { auto* device=deviceManager_.getCurrentAudioDevice(); - if (device == nullptr || device->getActiveInputChannels().isZero() - || device->getActiveOutputChannels().isZero()) + if (device == nullptr || device->getActiveOutputChannels().isZero()) return false; const auto backend=device->getTypeName(); const auto name=device->getName(); @@ -2603,11 +2836,15 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback LiveDryRoutingLab dryRoutingLab_; std::atomic diagnosticRoute_ {armix::diagnostics::Route::normal}; std::atomic routeReconfiguring_ {false}; + std::atomic mainTestEpoch_{0}; + std::atomic mainTestPair_{0}; + bool mainTestWasArmed_=false; // control thread only std::optional savedLiveSetup_; // Indexed atomic bypass flags: instant RT-safe toggles, no graph detachment. // Temporary publication silence never changes operator MONITOR or MAIN MUTE. // The DIRECT device fence and physical-output verification remain separate. std::atomic topologyPublicationMute_ { false }; + std::atomic resumeMainAfterAsioReset_{false}; std::atomic monitor_ { false }, channelMute_ { false }, masterMute_ { false }, masterMono_ { false }, dryTest_ { false }; std::atomic masterGain_ { 1.f }, channelGain_ { 1.f }, channelPan_ { 0.f }; std::atomic inputPeak_ { 0.f }, postFxPeak_ { 0.f }, outputPeak_ { 0.f }; @@ -2615,6 +2852,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback std::atomic captureObservationBlocks_ {0}; // per native device epoch, even UNPATCHED armix::rt::CaptureBoundaryEvidence captureBoundary_; // callback-only PCM continuity std::atomic outputPeakL_ { 0.f }, outputPeakR_ { 0.f }; + std::atomic driverBufferPeakL_{0.f},driverBufferPeakR_{0.f},mainTestPeak_{0.f}; std::atomic callbackInputs_ { 0 }, callbackOutputs_ { 0 }; std::atomic callbackCount_ { 0 }; // Audio-thread-only timestamp and cheap atomically published counters. @@ -2657,10 +2895,13 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const juce::AudioDeviceManager::AudioDeviceSetup& expected) { const auto* active = deviceManager_.getCurrentAudioDevice(); + // A previously verified OUTPUT-ONLY mixer must be recoverable with + // the same zero-capture identity. Only the physical stereo output is + // compulsory; resumeVerifiedDirectRoute() separately rechecks exact + // backend/device/input/output masks before PCM can be armed. if (active == nullptr || deviceManager_.getCurrentAudioDeviceType() != "Windows Audio" || - active->getActiveInputChannels().isZero() || - active->getActiveOutputChannels().isZero()) return false; + active->getActiveOutputChannels().countNumberOfSetBits()<2) return false; juce::AudioDeviceManager::AudioDeviceSetup current; deviceManager_.getAudioDeviceSetup (current); return current.inputDeviceName == expected.inputDeviceName @@ -2690,6 +2931,11 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback void audioDeviceAboutToStart (juce::AudioIODevice* d) override { + // Some ASIO implementations announce a new callback before STOP. + // Remember the existing MAIN intent before muting this epoch; only + // the verified same-driver CONTROL rebind may resume it. No RT work. + if(monitor_.load(std::memory_order_acquire)) + resumeMainAfterAsioReset_.store(true,std::memory_order_release); setOutputMuted(true); secondaryOutput_.invalidateSource(); // source clock may have changed dryRoutingLab_.prepareDevice(d); // exact active mask, before callback @@ -2739,11 +2985,13 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback inputPeak_.store (0.f); postFxPeak_.store (0.f); outputPeak_.store (0.f); + publishDriverBufferPeaks(0.f,0.f); } void audioDeviceStopped() override { - setOutputMuted(true); + if(monitor_.exchange(false,std::memory_order_acq_rel)) + resumeMainAfterAsioReset_.store(true,std::memory_order_release); secondaryOutput_.invalidateSource(); // explicit reconnect required after device stop masterLoudness_.prepare (0.0); // clear validity across device epoch dryRoutingLab_.deviceStopped(); @@ -2756,6 +3004,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback captureBoundary_.reset(); // no stale pin peaks after disconnect inputPeak_.store (0.f); outputPeak_.store (0.f); + publishDriverBufferPeaks(0.f,0.f); } // ONE original CH1 rack processor for M4 compatibility and the native @@ -2846,6 +3095,11 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback return fx; } + void publishDriverBufferPeaks(float left,float right) noexcept { + driverBufferPeakL_.store(left,std::memory_order_relaxed); + driverBufferPeakR_.store(right,std::memory_order_relaxed); + } + void audioDeviceIOCallbackWithContext ( const float* const* inputs, int inputChannels, float* const* outputs, int outputChannels, int samples, const juce::AudioIODeviceCallbackContext&) override @@ -2855,7 +3109,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // while the user is changing devices. Atomic gate only: no name hash, // allocations, OS calls or device restart on the realtime callback. // An independent WASAPI bridge has its own verified endpoint guard. - const auto activeDiagnosticRoute = diagnosticRoute_.load (std::memory_order_relaxed); + const auto activeDiagnosticRoute = diagnosticRoute_.load (std::memory_order_acquire); // DRY_THROUGH still routes a live microphone to the hardware output: // it MUST use the same DIRECT authorization fence as NORMAL. Only // genuinely isolated OUTPUT_ONLY_TONE / CAPTURE_ONLY tests may bypass @@ -2867,6 +3121,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback { for (int c=0; c (samples), std::memory_order_relaxed); return; @@ -2911,6 +3166,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback outputPeak_.store(0.f, std::memory_order_relaxed); outputPeakL_.store(0.f, std::memory_order_relaxed); outputPeakR_.store(0.f, std::memory_order_relaxed); + publishDriverBufferPeaks(0.f,0.f); handoff_.endCycle(cycle); // ACK prepared FX graph even in silence return; } @@ -3036,7 +3292,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback peak=juce::jmax(peak,std::abs(out[i])); } if(c==0)movedPeakL=peak; - else movedPeakR=peak; + else if(c==1)movedPeakR=peak; } if(routedFxMove==1 && cycle.graph) { cycle.graph->orderPacked.store( @@ -3083,6 +3339,9 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback for(int channel=0;channel outputPair{{0,1}}; + if(route==armix::diagnostics::Route::mainOutputTone) { + const auto packed=mainTestPair_.load(std::memory_order_relaxed); + outputPair={{static_cast(packed&0xffffu),static_cast(packed>>16)}}; + if(!dryRoutingLab_.ready() || + mainTestEpoch_.load(std::memory_order_relaxed)!=dryRoutingLab_.epoch()) + outputPair={{-1,-1}}; + } + const auto testPair=armix::mixer::NativeOutputPairTap::select(outputs,outputChannels,outputPair); const bool captureTest = route == armix::diagnostics::Route::captureOnly; - if (toneTest && outputChannels > 0) + if (toneTest && testPair[0]) testOutputFrames_.fetch_add (static_cast (samples), std::memory_order_relaxed); if (captureTest && inputChannels > 0) testCaptureFrames_.fetch_add (static_cast (samples), std::memory_order_relaxed); @@ -3131,7 +3400,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback { auto* left = scratch_.getWritePointer (0); auto* right = scratch_.getWritePointer (1); - const bool audible = enabled && !masterMute_.load (std::memory_order_relaxed); + const bool audible = testPair[0] && enabled && !masterMute_.load (std::memory_order_relaxed); for (int i = 0; i < frames; ++i) left[i] = right[i] = diagnosticTone_.next (audible); } @@ -3165,6 +3434,10 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const float* left = scratch_.getReadPointer (0); const float* right = scratch_.getReadPointer (1); float* dst = outputs[c] + offset; + if(toneTest && (!testPair[0] || (c!=outputPair[0] && c!=outputPair[1]))) { + juce::FloatVectorOperations::clear(dst,frames); + continue; + } const float fromL = mono ? monoL : (c == 0 ? matrix.ll : matrix.rl); const float fromR = mono ? monoR : (c == 0 ? matrix.lr : matrix.rr); float channelPeak = 0.f; @@ -3184,8 +3457,8 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback channelPeak = juce::jmax (channelPeak, std::abs (value)); } outPeak = juce::jmax (outPeak, channelPeak); - if (c == 0) outPeakL = juce::jmax (outPeakL, channelPeak); - if (c == 1) outPeakR = juce::jmax (outPeakR, channelPeak); + if (c == outputPair[0]) outPeakL = juce::jmax (outPeakL, channelPeak); + if (c == outputPair[1]) outPeakR = juce::jmax (outPeakR, channelPeak); } } if (!independent_.active()) @@ -3198,6 +3471,10 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback } inputPeak_.store (juce::jmin (1.f, inPeak), std::memory_order_relaxed); postFxPeak_.store (juce::jmin (1.f, postFxPeak), std::memory_order_relaxed); + publishDriverBufferPeaks(outPeakL,outPeakR); + if(route==armix::diagnostics::Route::mainOutputTone) + mainTestPeak_.store(juce::jmax(mainTestPeak_.load(std::memory_order_relaxed),outPeak), + std::memory_order_relaxed); outputPeak_.store (juce::jmin (1.f, outPeak), std::memory_order_relaxed); outputPeakL_.store (juce::jmin (1.f, outPeakL), std::memory_order_relaxed); outputPeakR_.store (juce::jmin (1.f, outPeakR), std::memory_order_relaxed); diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index f404be1a4..3bf0cdb0b 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -5,6 +5,7 @@ #include "../engine/core/MasterOutputMonoPolicy.h" #include "../engine/core/LiveChannelFxGraph.h" #include "../engine/core/DynamicChannelFxLeaseBank.h" +#include "../engine/core/NativeMusicTempoMonitor.h" #include "../engine/device/DeviceSessionTransitionPolicy.h" #include "../engine/core/NativeFxRackTransaction.h" #include "../engine/core/UnifiedLegacyProductionAdmission.h" @@ -94,7 +95,7 @@ class LiveDryRoutingLab final { device,generation,snapshot,reason))return; const int inputs=snapshot.inputs.enabledCount; const int outputs=snapshot.outputCount; - if(inputs<=0 || outputs<2) return; // stereo monitoring LAB only + if(inputs<0 || outputs<2) return; // output-only is a real SILENT native session for(int i=0;isetProperty("channels",juce::var(channels)); const FxSelections none{}; - // Same publisher/graph as a real user APPLY, but no authorization. - // Never briefly advertise a synthetic route as LIVE. + // Keep M4's historical unpatched/fail-silent behavior. Startup + // explicitly promotes this same genuine SOURCE NONE graph to PCM. return apply(juce::var(request.release()),directPermitted, independentClock,loadedFx,none,formats, sampleRate,deviceFrames,false); @@ -220,7 +221,7 @@ class LiveDryRoutingLab final { if(topologyFault_.load(std::memory_order_acquire)) return "Device callback channel layout changed; reopen AUDIO SETUP before applying"; const int countNow=portCount_.load(std::memory_order_acquire); - if(countNow<=0 || countNow>armix::device::LiveInputPortRegistry::limit) + if(countNow<0 || countNow>armix::device::LiveInputPortRegistry::limit) return "Invalid active device input channel mask"; std::array physicalPorts{}; for(int i=0;i0)!=externalCh1.populated() || - !hasExplicitRoute()||!ready() || + (!hasExplicitRoute()&&!silentStarter)||!ready() || topologyFault_.load(std::memory_order_acquire)) return false; const auto generation=epoch(),m4Revision=revision(); const auto* old=publisher_.controlPrepared(generation,m4Revision); if(!old || deviceFrames<=0) return false; + const auto& route=silentStarter?sourceTemplate_:acceptedRoute_; + // This admission never upgrades a draft with unverified capture. + if(silentStarter) { + const auto* rows=route.getProperty("channels",juce::var()).getArray(); + if(!rows || rows->size()!=count)return false; + for(const auto& row:*rows) + if(row.getProperty("mode",{}).toString()!="NONE")return false; + } armix::mixer::NativeDryRouteCommand decoded; juce::String problem; if(!armix::mixer::NativeDryRouteCommand::decode( - acceptedRoute_,decoded,problem))return false; + route,decoded,problem))return false; // A native IN is a callback ordinal, not the numerical physical // port label. Preserve original order including sparse ASIO pins. const int inputs=portCount_.load(std::memory_order_acquire); - if(inputs<=0||inputs>armix::device::LiveInputPortRegistry::limit) + if(inputs<0||inputs>armix::device::LiveInputPortRegistry::limit) return false; std::array ports{}; for(int i=0;i + void forEachNativeProcessor(Callback&& visit) const { + if(!channelIdPhysicalPcmActive()||!nativeAccepted_.fxOwners)return; + for(const auto& ch:nativeAccepted_.graph.roster.channels()) { + const auto count=nativeAccepted_.fxOwners->insertCount(ch.id); + for(std::size_t slot=0;slotownerForControl(ch.id,slot); + if(owner && *owner && (*owner)->processor) + visit(ch.id,(*owner)->processor.get()); + } + } + } bool nativeChannelIsOriginalCh1(armix::mixer::ChannelId target) const noexcept { return nativeAccepted_.fxOwners && nativeAccepted_.fxOwners->externalChannel()==target && @@ -1828,6 +1866,7 @@ class LiveDryRoutingLab final { nativeAccepted_.graph.request=std::move(request); nativeAccepted_.fxOwners=std::move(owner); nativeAccepted_.pcmRevision=published.revision; + std::erase_if(waitingAsioInputs_,[id](const auto& pin){return pin.id==id;}); nativeStructureLive_=true; nativeMeterEpoch_.store(0,std::memory_order_release); reply.accepted=true;reply.error=""; @@ -1914,6 +1953,7 @@ class LiveDryRoutingLab final { nativeAccepted_.graph.request=std::move(request); nativeAccepted_.fxOwners=std::move(owner); nativeAccepted_.pcmRevision=published.revision; + std::erase_if(waitingAsioInputs_,[channel](const auto& pin){return pin.id==channel;}); nativeStructureLive_=true; // M4 source roster no longer authoritative nativeMeterEpoch_.store(0,std::memory_order_release); reply.accepted=true;reply.error=""; @@ -2212,6 +2252,7 @@ class LiveDryRoutingLab final { draft.legacyIds=nativeAccepted_.graph.ids; draft.outputs=nativeAccepted_.hardware; draft.request=nativeAccepted_.graph.request; + draft.waitingAsioInputs=waitingAsioInputs_; std::vector staged; std::set hashes; juce::int64 total=0; @@ -2252,6 +2293,34 @@ class LiveDryRoutingLab final { } catch(...) {return "Native graph/VST3 state capture failed";} } + bool describeRetainedAsioSession(armix::session::MixerSessionDocument& document) const { + if(!hasRetainedNativeSession() || + !nativeAccepted_.matches(nativePublisher_,nativeAccepted_.deviceEpoch, + nativeAccepted_.pcmRevision))return false; + document.roster=nativeAccepted_.graph.roster; + document.request=nativeAccepted_.graph.request; + document.legacyIds=nativeAccepted_.graph.ids; + document.outputs=nativeAccepted_.hardware; + document.waitingAsioInputs=waitingAsioInputs_; + return true; + } + + bool rebindRetainedAsioSession(armix::session::MixerSessionDocument document, + const armix::device::JuceActivePortSnapshot& pins,int deviceFrames) { + const auto next=nativeGraphRevisionForRestore(); + const auto previous=document.request.maxFrames; + // Existing processors can still use their prepared quantum. Larger + // device blocks are split by the same render path used before reset. + document.request.maxFrames=armix::device::retainedMixerQuantum(previous, + deviceFrames,Block::hardFrameLimit,false,true); + if(!next || !document.request.maxFrames || !hasRetainedNativeSession())return false; + auto bank=std::make_shared(); + if(armix::mixer::DynamicChannelFxLeaseBank::rebindSameFormat( + pins.epoch,next,*nativeAccepted_.fxOwners,*bank)!= + armix::mixer::DynamicChannelFxLeaseBank::Fault::none)return false; + return restoreNativeMixerSession(std::move(document),std::move(bank),pins,true).isEmpty(); + } + // Match CONTROL's live device readback to the masks registered for the // actual callback epoch. Neither a saved document nor an M4 graph // attests which physical pins the current callback can address. @@ -2310,6 +2379,7 @@ class LiveDryRoutingLab final { nativeAccepted_.graph.roster=std::move(document.roster); nativeAccepted_.graph.request=std::move(document.request); nativeAccepted_.graph.ids=document.legacyIds; + waitingAsioInputs_=std::move(document.waitingAsioInputs); nativeAccepted_.graph.revision=nativeAccepted_.graph.roster.revision(); nativeAccepted_.hardware=document.outputs; nativeAccepted_.fxOwners=std::move(bank); @@ -2507,6 +2577,20 @@ class LiveDryRoutingLab final { return channelIdPhysicalPcmActive() && nativeStructureLive_ ?nativeAccepted_.pcmRevision:revision(); } + // The first accepted SOURCE NONE ChannelId graph is a disposable + // bootstrap topology, not an authored Show. A persisted .smix may replace + // it once on cold start; any accepted FX, control, WIRE, BUS or source + // mutation immediately makes that replacement unsafe. + // CONTROL THREAD ONLY: hasAuthoredMixerContent traverses roster/FX. + bool canReplacePristineStartupMixer() const noexcept { + return channelIdPhysicalPcmActive() && sourceTemplate_.isObject() && + !acceptedRoute_.isObject() && !nativeStructureLive_ && + !nativeControlDirty_ && nativeAccepted_.fxOwners && + nativeAccepted_.graph.request.sources.empty() && + !hasAuthoredMixerContent(); + } + std::span waitingAsioInputs() const noexcept {return waitingAsioInputs_;} + int waitingAsioInputCount() const noexcept {return static_cast(waitingAsioInputs_.size());} bool hasVerifiedNativeSources() const noexcept { return channelIdPhysicalPcmActive() && !nativeAccepted_.graph.request.sources.empty(); } @@ -2523,6 +2607,7 @@ class LiveDryRoutingLab final { nativeControlDirty_=false; nativePublisher_.unpublish(); // CONTROL-only; audio lease retires safely nativeAccepted_=armix::mixer::UnifiedLegacyAccepted{}; + waitingAsioInputs_.clear(); userPatched_.store(false,std::memory_order_release); enabled_.store(false,std::memory_order_release); publishedEpoch_.store(0,std::memory_order_release); @@ -2551,6 +2636,9 @@ class LiveDryRoutingLab final { // CONTROL ONLY: hardware loss makes ready() false but does not erase // authored values, FX identity, GROUP/FX_RETURN buses or accepted WIREs. // Never downgrade this dynamic document to the fixed 10CH/4AUX schema. + std::uint64_t retainedNativeEpoch() const noexcept { + return hasRetainedNativeSession()?nativeAccepted_.deviceEpoch:0; + } bool hasRetainedNativeSession() const noexcept { return !channelIdPhysicalPcmActive() && nativeAccepted_.fxOwners && hasAuthoredMixerContent(); } @@ -2647,6 +2735,17 @@ class LiveDryRoutingLab final { } std::uint64_t revision() const noexcept {return publisher_.lastRevision();} // control only + // Control thread only. The test uses the exact pair the current mixer + // owns, including non-contiguous physical pins mapped to compact indices. + std::array acceptedMainCallbackPair() const noexcept { + if(!ready())return {{-1,-1}}; + if(channelIdPhysicalPcmActive()) + return {{nativeAccepted_.hardware.mainL,nativeAccepted_.hardware.mainR}}; + if(const auto* graph=publisher_.controlPrepared(epoch(),revision())) + return {{graph->mainOutputLeft(),graph->mainOutputRight()}}; + return {{-1,-1}}; + } + // JUCE render callback, with a verified single-clock device. Routing // publishes at the BLOCK boundary. Missing/stale ports output SILENCE. // A failed run never falls through to an unrelated microphone/plugin path. @@ -3079,6 +3178,7 @@ class LiveDryRoutingLab final { return juce::var(out.release()); } private: + std::vector waitingAsioInputs_; // Four 9-bit callback indices (0 means absent) and the prepared quantum. // One atomic read gives AUDIO a coherent destination/quantum contract. std::atomic nativeHardware_{0}; diff --git a/src/Main.cpp b/src/Main.cpp index 9f25c832e..2a2b7f01f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -11,12 +11,14 @@ #include "LiveAudioEngine.h" #include "NativeSessionToken.h" #include "ArSonMixStartupSplash.h" +#include "ArSonWindowChrome.h" #include "VstOrbitController.h" #include "../engine/core/OrbitDistanceMapping.h" #include "../engine/core/DearVrPolarPolicy.h" #include "DiagnosticsRecorder.h" #include "../engine/device/DirectRestoreBackoff.h" #include "../engine/device/AudioSetupRecoveryPolicy.h" +#include "../engine/device/AsioRestartRecoveryGate.h" #include "../engine/device/PeriodCapabilityEvidence.h" #include "../engine/diagnostics/CrackleEvidenceWindow.h" #if defined(_WIN32) @@ -44,7 +46,9 @@ #include #include #include "../engine/player/PlayerSetlistPolicy.h" +#include "../engine/player/PlayerLibraryPolicy.h" #include +#include namespace { @@ -217,7 +221,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr { public: explicit ConsoleWindow (std::function onStartupStage) - : DocumentWindow ("AR MIX Studio — Native VST3 FX Host", + : DocumentWindow ("ArSonMiX — Native Mixer", juce::Colour (0xff101921), allButtons), catalog_ (settingsDirectory()), diagnostics_ (settingsDirectory().getChildFile ("diagnostics")), @@ -280,9 +284,17 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr restorePlayerLibrary(); // portable, local song paths only; NEVER autoplay on launch catalog_.onChanged = [this] { emitCatalog(); emitScanProgress(); }; catalog_.scanFactoryIfPresent(); // Only the signed-off local manifest; never global VST scans. +#if defined(_WIN32) + // JUCE owns the real window commands; unlike WebView2 JS, these are + // synchronous native controls with JUCE's existing resize constrainer. + setLookAndFeel (&mixerCaption_); + setUsingNativeTitleBar (false); + setTitleBarHeight (31); +#else setUsingNativeTitleBar (true); +#endif setIcon (approvedAppIcon()); - setResizable (true, true); + setResizable (true, false); setResizeLimits (1100, 650, 3840, 2160); setContentNonOwned (&browser_, false); // A fixed 1650x930 initial HWND exceeds the *logical* Windows work @@ -343,11 +355,13 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr } engine_.stop(); browser_.setVisible (false); + setLookAndFeel (nullptr); // before the owned LookAndFeel is destroyed } void closeButtonPressed() override { juce::JUCEApplication::getInstance()->systemRequestedQuit(); } private: + armix::ui::MixerCaptionLookAndFeel mixerCaption_; LiveAudioEngine engine_; VstOrbitController orbit_; // The exact native ChannelId/insert identity retains its VST3 owner @@ -382,6 +396,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr int playerSelected_=-1,playerCurrent_=-1; int playerOutputPendingIndex_=-1; // only after explicit Choose output gesture bool playerAutoNext_=false; + bool playerFolderBusy_=false; // GUI only; background scanner never touches this std::uint64_t lastAutoAdvanceGeneration_=0; juce::String playerError_; juce::File lastPluginFolder_ = juce::File::getSpecialLocation (juce::File::userHomeDirectory); @@ -411,6 +426,15 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr } pendingNativeHarmony_; juce::String lastNativeHarmonyRequest_,lastNativeHarmonyInstance_; juce::String lastNativeHarmonyEpoch_,lastNativeHarmonyRevision_; + struct PendingNativeThrow { + armix::mixer::LiveChannelFxGraph::InstanceLease owner; + juce::String request,channelId,deviceEpoch,revision,instanceId; + juce::uint32 started=0; + bool trigger=false; + } pendingNativeThrow_; + juce::String lastNativeThrowRequest_,lastNativeThrowInstance_; + juce::String lastNativeThrowEpoch_,lastNativeThrowRevision_; + armix::mixer::NativeMusicTempoMonitor::State lastMusicTempo_{}; std::unique_ptr editorWindow_; std::unique_ptr audioSetupWindow_; juce::String startupError_, lastAudioXml_; @@ -1012,8 +1036,10 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr (void) armix::console::projectRetainedNativeChannelIdGraph (accepted, live); // Sole control-thread SessionSnapshot from the installed PCM publisher. armix::console::publishAuthoritativeMixerSession(accepted); - if(auto* obj=accepted.getDynamicObject()) + if(auto* obj=accepted.getDynamicObject()) { obj->setProperty("channelAppearance",channelAppearance_.snapshot(accepted.getProperty("graph",{}))); + obj->setProperty("waitingAsioInputs",live.getProperty("waitingAsioInputs",0)); + } return accepted; } @@ -1062,6 +1088,14 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // ENGINE callback. This code executes on the JUCE message thread, not RT. void handleApprovedNativeControl(const juce::var& request) { + if(audioDeviceApplyActive_) { + auto ack=std::make_unique(); + ack->setProperty("requestId",request.getProperty("requestId",{})); + ack->setProperty("status","REJECTED"); + ack->setProperty("errorCode","AUDIO_DEVICE_APPLY_IN_PROGRESS"); + browser_.emitEventIfBrowserIsVisible("arMixConsoleAck",juce::var(ack.release())); + return; + } const auto beforeLive=engine_.status(); const auto before=approvedNativeSnapshot(beforeLive); const auto route=beforeLive.getProperty("dryRoutingLab",{}); @@ -1094,9 +1128,16 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr armix::builtin_fx::ChannelCompressorProcessor::catalogIdentity; const bool builtInHarmony=catalogId== armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity; - const auto* plugin=(builtInEq||builtInComp||builtInHarmony)?nullptr:catalog_.find(catalogId); + // Built-in DSP is compiled into the native host. Its admit + // path must remain usable even while third-party VST3 metadata + // discovery blocks or scans in the background. External + // plugins still require a fully verified, idle catalog. + const bool builtInThrow=catalogId== + armix::builtin_fx::VocalThrowProcessor::catalogIdentity; + const bool externalCatalog=!builtInEq&&!builtInComp&&!builtInHarmony&&!builtInThrow; + const auto* plugin=externalCatalog?catalog_.find(catalogId):nullptr; std::uint64_t ep=0,rev=0,roster=0,target=0; - if((!builtInEq&&!builtInComp&&!builtInHarmony&&!plugin)||catalog_.busy()||nativeShowBusy_|| + if((externalCatalog&&(!plugin||catalog_.busy()))||nativeShowBusy_|| studioBackupBusy_||engine_.isGraphSwitchPending()) { nativeError="NATIVE_VST3_CATALOG_OR_HOST_BUSY"; } else if(!armix::console::approvedNativeId( @@ -1118,6 +1159,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr builtInHarmony? engine_.installNativeBuiltInHarmony( ep,rev,roster,armix::mixer::ChannelId{target}): + builtInThrow? + engine_.installNativeBuiltInVocalThrow( + ep,rev,roster,armix::mixer::ChannelId{target}): engine_.installNativeVst3( ep,rev,roster,armix::mixer::ChannelId{target}, plugin->path,plugin->uid,plugin->key()); @@ -1274,7 +1318,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr o->setProperty("open",device!=nullptr&&device->isOpen()); o->setProperty("authorized",engine_.directRouteAuthorized()); o->setProperty("outputMuted",engine_.isOutputMuted()); - o->setProperty("deviceGeneration",engine_.status().getProperty("deviceGeneration",0)); + const auto live=engine_.status(); + o->setProperty("deviceGeneration",live.getProperty("deviceGeneration",0)); + o->setProperty("mainOutputs",live.getProperty("dryRoutingLab",{}).getProperty("mainOutputs",{})); juce::Array inputNames,outputNames,inputPins,outputPins,rates,buffers; if(device!=nullptr&&device->isOpen()) { const auto inputs=device->getInputChannelNames(); @@ -1305,6 +1351,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // One-shot on a verified setup or startup, including the first input // patch. A later device epoch or a user MUTE cancels the pending arm. std::uint64_t autoMainEpoch_=0; + bool autoMainRequiresInput_=true; std::optional autoMainCheckedRevision_; void serviceAutomaticMain() { if(autoMainEpoch_==0)return; @@ -1318,24 +1365,73 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const auto revision=engine_.outputArmRevision(); if(autoMainCheckedRevision_==revision)return; if(engine_.isGraphSwitchPending()||!engine_.hasBoundMixerRoute())return; + // A transient native graph/FX ACK must not permanently consume + // the only automatic MAIN attempt for this control revision. + // Retry only the cheap CONTROL preflight until it is genuinely safe. + if(engine_.liveOutputArmFault(autoMainRequiresInput_).isNotEmpty())return; autoMainCheckedRevision_=revision; - if(engine_.liveOutputArmFault().isNotEmpty())return; engine_.setMonitorEnabled(true); autoMainEpoch_=0; diagnostics_.record("MAIN_AUTO_ENABLED","Verified device, input and MAIN output"); } - void requestAutomaticMain() { + void requestAutomaticMain(bool requireInput=true) { + autoMainRequiresInput_=requireInput; autoMainEpoch_=engine_.dryRoutingLabEpoch(); autoMainCheckedRevision_.reset(); serviceAutomaticMain(); } + using MixerBindingMode=armix::session::MixerDeviceBindingPolicy::Mode; + bool audioDeviceApplyActive_=false; // JUCE message thread, including nested driver dispatch + + juce::String openSelectedAudioDevice(const juce::String& backend, + const juce::AudioDeviceManager::AudioDeviceSetup& setup,bool resetDefaults=false) { + auto& manager=engine_.devices(); + if(manager.getCurrentAudioDeviceType()==backend && !resetDefaults) { + if(auto* device=manager.getCurrentAudioDevice();device && !device->isOpen()) + manager.closeAudioDevice(); + return manager.setAudioDeviceSetup(setup,true); + } + + // JUCE's setCurrentAudioDeviceType opens its remembered/default + // device first and sleeps on the message thread. Initialise the + // exact named backend and requested masks in one open instead. + auto xml=manager.createStateXml(); + if(!xml)xml=std::make_unique("DEVICESETUP"); + xml->setAttribute("deviceType",backend); + xml->removeAttribute("audioDeviceName"); + xml->setAttribute("audioInputDeviceName",setup.inputDeviceName); + xml->setAttribute("audioOutputDeviceName",setup.outputDeviceName); + xml->setAttribute("audioDeviceRate",setup.sampleRate); + xml->setAttribute("audioDeviceBufferSize",setup.bufferSize); + const auto setMask=[&](const char* key,bool useDefault,const juce::BigInteger& mask) { + if(useDefault)xml->removeAttribute(key); + else xml->setAttribute(key,mask.toString(2)); + }; + setMask("audioDeviceInChans",setup.useDefaultInputChannels,setup.inputChannels); + setMask("audioDeviceOutChans",setup.useDefaultOutputChannels,setup.outputChannels); + diagnostics_.record("CUSTOM_AUDIO_PHASE","CLOSE_PREVIOUS | "+manager.getCurrentAudioDeviceType()); + manager.closeAudioDevice(); + diagnostics_.record("CUSTOM_AUDIO_PHASE","OPEN_SELECTED | "+backend); + return manager.initialise(2,2,xml.get(),false); + } + void applyCustomAudioDevice(const juce::var& args) { - // Synchronous manager operations stay on JUCE's established message - // thread. A vendor driver may block; never pretend JS async fixes it. + // JUCE device lifecycle runs on the message thread, including ASIO's + // modal callbacks. Serialize transactions across nested dispatch. const auto id=args.getProperty("requestId",{}).toString().substring(0,64); + if(audioDeviceApplyActive_) { + auto ack=std::make_unique(); + ack->setProperty("requestId",id); + ack->setProperty("ok",false); + ack->setProperty("state","BUSY"); + ack->setProperty("error","Audio I/O is already applying a device change."); + browser_.emitEventIfBrowserIsVisible("arMixAudioDeviceApplyAck",juce::var(ack.release())); + return; + } + const juce::ScopedValueSetter applying(audioDeviceApplyActive_,true); const auto oldGeneration=engine_.status().getProperty("deviceGeneration",0); auto send=[&](bool ok,const juce::String& state,const juce::String& error, bool canReusePins=false) @@ -1362,7 +1458,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr if(nativeShowBusy_||studioBackupBusy_||mixerSessionWorker_.busy()|| engine_.isGraphSwitchPending()|| static_cast(nativeRoute.getProperty("pending",false))|| - engine_.independentClockActive()||engine_.hasTemporaryDiagnosticDevice()|| + engine_.independentClockActive()|| + engine_.diagnosticRoute()!=armix::diagnostics::Route::normal|| engine_.secondaryArmed()) return send(false,"REJECTED", "Stop STREAM and finish Show/FX/diagnostic/clock transition first"); @@ -1371,9 +1468,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const auto typeName=config.getProperty("backend",{}).toString(); const auto capture=config.getProperty("captureDevice",{}).toString(); const auto playback=config.getProperty("playbackDevice",{}).toString(); - if(typeName.isEmpty()||capture.isEmpty()||playback.isEmpty()|| + if(typeName.isEmpty()||playback.isEmpty()|| typeName.length()>160||capture.length()>250||playback.length()>250) - return send(false,"REJECTED","Choose actual capture and playback devices"); + return send(false,"REJECTED","Choose an actual playback device"); auto& manager=engine_.devices(); juce::AudioIODeviceType* selectedType=nullptr; for(auto* type:manager.getAvailableDeviceTypes()) @@ -1382,8 +1479,15 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // Do not let JS submit arbitrary names or combine unmatched ASIO devices. const auto namesIn=selectedType->getDeviceNames(true); const auto namesOut=selectedType->getDeviceNames(false); - if(!namesIn.contains(capture)||!namesOut.contains(playback)|| - (!selectedType->hasSeparateInputsAndOutputs()&&capture!=playback)) + // A separate-input/output backend can legitimately open a render + // endpoint WITHOUT capture hardware. Empty capture is a deliberate + // operator choice, never an inferred name or a fake input port. + // ASIO/non-separate drivers retain exact duplex device identity; + // they may still expose zero enabled capture *pins*. + const bool separate=selectedType->hasSeparateInputsAndOutputs(); + const bool outputOnly=separate&&capture.isEmpty(); + if((!outputOnly&&!namesIn.contains(capture))||!namesOut.contains(playback)|| + (!separate&&capture!=playback)) return send(false,"REJECTED","Device names or duplex pairing are not reported by JUCE"); auto sample=config.getProperty("sampleRate",{}), period=config.getProperty("bufferSize",{}); if(!(sample.isInt()||sample.isDouble()||sample.isInt64())|| @@ -1405,6 +1509,10 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const bool previousWasOpen=previousDevice!=nullptr&&previousDevice->isOpen(); const bool previousMixerBound=engine_.hasBoundMixerRoute(); const bool previousMonitor=engine_.isMonitorEnabled(); + const auto assignMain=config.getProperty("assignSelectedPlaybackPinsToMain",false); + if(!assignMain.isBool()) + return send(false,"REJECTED","Invalid MAIN playback pin selection"); + const bool explicitMain=static_cast(assignMain); const auto confirm=config.getProperty("confirmRetainedPinMapping",false); if(!confirm.isBool()) return send(false,"REJECTED","Invalid retained mixer mapping confirmation"); @@ -1412,7 +1520,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // The first Apply must open and verify the selected device. // Confirmation binds only that exact, still-open generation; // draft rate, buffer and pin changes use the normal Apply path. - if(!sameEndpoint || !previousWasOpen || rate!=before.sampleRate || + if(explicitMain || !sameEndpoint || !previousWasOpen || rate!=before.sampleRate || block!=before.bufferSize || !engine_.confirmRetainedWasapiPortMapping()) return send(false,"NEEDS_REMAP", @@ -1445,6 +1553,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const auto recovery=armix::device::AudioSetupRecoveryPolicy::select( sameEndpoint,previousWasOpen,typeName=="ASIO", pinInput.isArray()&&pinOutput.isArray()); + if(explicitMain && (!recovery.reuseActivePins || + pinOutput.getArray()->size()!=2)) + return send(false,"REJECTED","Select exactly two inspected playback pins for MAIN."); if(recovery.reuseActivePins) { const auto inCount=juce::jmin(64,previousDevice->getInputChannelNames().size()); const auto outCount=juce::jmin(64,previousDevice->getOutputChannelNames().size()); @@ -1461,14 +1572,18 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr }; juce::BigInteger inMask,outMask; if(!parsePins(pinInput,inCount,inMask)||!parsePins(pinOutput,outCount,outMask)|| - inMask.countNumberOfSetBits()<1||outMask.countNumberOfSetBits()<2) - return send(false,"REJECTED","Choose >=1 verified capture and >=2 playback pins"); + (outputOnly&&!inMask.isZero())||outMask.countNumberOfSetBits()<2) + return send(false,"REJECTED","Select real input pins (or none) and >=2 verified playback pins"); candidate.useDefaultInputChannels=false; candidate.useDefaultOutputChannels=false; candidate.inputChannels=inMask; candidate.outputChannels=outMask; }else { - candidate.useDefaultInputChannels=true; + // The requested 0-IN option must not reopen a microphone merely + // because JUCE defaults to enabling available capture channels. + // Output pin selection still requires actual driver readback. + candidate.useDefaultInputChannels=!outputOnly; + if(outputOnly)candidate.inputChannels.clear(); candidate.useDefaultOutputChannels=true; } auto* active=manager.getCurrentAudioDevice(); @@ -1490,7 +1605,6 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const auto start=monotonicMilliseconds(); autoMainEpoch_=0; engine_.beginManualAudioSetup(); - if(!unchangedDevice)manager.setCurrentAudioDeviceType(typeName,false); // JUCE setAudioDeviceSetup() can return success without reopening when // setup == currentSetup and currentAudioDevice != nullptr, even when // that driver object has stopped. closeAudioDevice() deletes it but @@ -1502,18 +1616,47 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr typeName+" | "+(previousWasOpen?"REFRESH_ASIO_PINS":"CLOSED_DEVICE_RECOVERY")); manager.closeAudioDevice(); } - auto error=manager.getCurrentAudioDeviceType()==typeName - ?manager.setAudioDeviceSetup(candidate,true) - :juce::String("Selected audio backend could not be opened"); + diagnostics_.record("CUSTOM_AUDIO_PHASE","APPLY | "+typeName); + auto error=openSelectedAudioDevice(typeName,candidate); + diagnostics_.record("CUSTOM_AUDIO_PHASE","VERIFY_READBACK | "+typeName); juce::AudioDeviceManager::AudioDeviceSetup actual; manager.getAudioDeviceSetup(actual); auto* opened=manager.getCurrentAudioDevice(); - const bool changedAsioPinLayout=error.isEmpty()&&recovery.verifyAsioPinIdentity&& + bool changedAsioPinLayout=error.isEmpty()&&recovery.verifyAsioPinIdentity&& opened!=nullptr&&opened->isOpen()&& (opened->getInputChannelNames()!=originalInputNames|| opened->getOutputChannelNames()!=originalOutputNames); + const bool refreshedAsio4All=typeName=="ASIO" && playback.startsWithIgnoreCase("ASIO4ALL") && + recovery.reuseActivePins && (changedAsioPinLayout || error.isNotEmpty()); + bool explicitPairStillIdentified=explicitMain; + if(refreshedAsio4All) { + // Never replay an index into a newly enumerated ASIO aggregate. + // Preserve verified selected names if they still exist, including + // VB-Cable capture moved past newly enabled input channels. + using BindingPolicy=armix::session::MixerDeviceBindingPolicy; + const auto freshInputNames=changedAsioPinLayout?opened->getInputChannelNames():juce::StringArray{}; + const auto freshOutputNames=changedAsioPinLayout?opened->getOutputChannelNames():juce::StringArray{}; + const auto capturePins=changedAsioPinLayout?BindingPolicy::translateNamedPins( + candidate.inputChannels,originalInputNames,freshInputNames):std::nullopt; + const auto playbackPins=changedAsioPinLayout?BindingPolicy::translateNamedPins( + candidate.outputChannels,originalOutputNames,freshOutputNames):std::nullopt; + candidate.useDefaultInputChannels=!capturePins && !candidate.inputChannels.isZero(); + candidate.useDefaultOutputChannels=!playbackPins; + if(capturePins)candidate.inputChannels=*capturePins; + if(playbackPins)candidate.outputChannels=*playbackPins; + explicitPairStillIdentified=explicitMain && playbackPins.has_value(); + diagnostics_.record("CUSTOM_AUDIO_PHASE","REFRESH_ASIO4ALL_INVENTORY"); + error=openSelectedAudioDevice(typeName,candidate,true); + manager.getAudioDeviceSetup(actual); + opened=manager.getCurrentAudioDevice(); + changedAsioPinLayout=error.isEmpty() && opened && opened->isOpen() && + ((capturePins && opened->getInputChannelNames()!=freshInputNames) || + (playbackPins && opened->getOutputChannelNames()!=freshOutputNames)); + } + // Never consume the automatic recovery epoch before a mixer bind. + // A transient ASIO4ALL pin inventory can settle on the next tick. if(changedAsioPinLayout) - error="ASIO pin layout changed. Output remains muted; review the NEW capture and playback pins and Apply again"; + error="ASIO pin layout changed. Output remains muted; review the new playback pins."; if(error.isEmpty()&&(opened==nullptr||!opened->isOpen()|| manager.getCurrentAudioDeviceType()!=typeName|| actual.inputDeviceName!=capture||actual.outputDeviceName!=playback|| @@ -1523,15 +1666,18 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr (!candidate.useDefaultOutputChannels&&actual.outputChannels!=candidate.outputChannels)|| opened->getActiveInputChannels()!=actual.inputChannels|| opened->getActiveOutputChannels()!=actual.outputChannels|| - opened->getActiveInputChannels().countNumberOfSetBits()<1|| opened->getActiveOutputChannels().countNumberOfSetBits()<2|| std::abs(opened->getCurrentSampleRate()-actual.sampleRate)>1.0|| opened->getCurrentBufferSizeSamples()!=actual.bufferSize)) error="Driver readback mismatch; device setting was not accepted"; - if(error.isEmpty()&&!finishAudioSetupAndRecoverMixer(true)) { + if(error.isEmpty())diagnostics_.record("CUSTOM_AUDIO_PHASE","BIND_MIXER | "+typeName); + const auto bindingMode=explicitPairStillIdentified?MixerBindingMode::verifiedMainPinApply: + MixerBindingMode::verifiedDeviceApply; + if(error.isEmpty()&&!finishAudioSetupAndRecoverMixer(bindingMode)) { if(!previousMixerBound && engine_.directRouteAuthorized() && (engine_.hasRetainedUnboundMixer() || mixerSessionRecoveryPending_)) { - const juce::String needsRemap="Device opened. Mixer retained and muted; its port mapping or FX processing format needs review"; + const auto needsRemap=mixerSessionError_.isNotEmpty()?mixerSessionError_: + juce::String("Device opened, but the mixer could not bind to its playback pins."); diagnostics_.record("CUSTOM_AUDIO_NEEDS_REMAP",needsRemap); send(false,"NEEDS_REMAP",needsRemap,engine_.stageRetainedWasapiPortMapping()); emitApprovedNativeSnapshot(); @@ -1544,6 +1690,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr startupError_.clear(); deviceSettingsDirty_=true; directRestore_.cancel(); + asioRecoveryEpoch_=engine_.dryRoutingLabEpoch(); diagnostics_.record("CUSTOM_AUDIO_APPLY_OK", typeName+" | "+juce::String(static_cast(monotonicMilliseconds()-start))+" ms"); requestAutomaticMain(); @@ -1561,11 +1708,10 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // One rollback, never blind default endpoint fallback, no auto-unmute. // A previously CLOSED device was never a verified rollback target. engine_.beginManualAudioSetup(); - if(recovery.priorKnownOpen&&manager.getCurrentAudioDeviceType()!=previousType&&previousType.isNotEmpty()) - manager.setCurrentAudioDeviceType(previousType,false); + diagnostics_.record("CUSTOM_AUDIO_PHASE","ROLLBACK | "+previousType); const auto restored=recovery.priorKnownOpen&&previousType.isNotEmpty()&& - manager.getCurrentAudioDeviceType()==previousType&& - manager.setAudioDeviceSetup(before,true).isEmpty(); + openSelectedAudioDevice(previousType,before).isEmpty()&& + manager.getCurrentAudioDeviceType()==previousType; juce::AudioDeviceManager::AudioDeviceSetup checked; manager.getAudioDeviceSetup(checked); const bool verified=restored&& @@ -1581,6 +1727,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr (manager.getCurrentAudioDevice()->getInputChannelNames()==originalInputNames&& manager.getCurrentAudioDevice()->getOutputChannelNames()==originalOutputNames))&& finishAudioSetupAndRecoverMixer(); + if(verified)asioRecoveryEpoch_=engine_.dryRoutingLabEpoch(); diagnostics_.record("CUSTOM_AUDIO_APPLY_FAIL",error+" | rollback="+ (verified?"RESTORED":"RECOVERY_REQUIRED")+" | "+ juce::String(static_cast(monotonicMilliseconds()-start))+" ms"); @@ -1597,7 +1744,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // Suspend physical output but retain ALL authored mixer state while // the real JUCE device selector is visible (including no-change close). autoMainEpoch_=0; - engine_.beginManualAudioSetup(); + engine_.beginManualAudioSetup(true); // The native JUCE device list is cached after first construction: // reopening the settings window avoids repeating full widget setup. @@ -1620,7 +1767,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr if (safe == nullptr) return; if (safe->finishAudioSetupAndRecoverMixer()) { - safe->requestAutomaticMain(); + safe->requestAutomaticMain(!safe->engine_.takeAsioResetMonitorIntent()); safe->deviceSettingsDirty_ = true; safe->startupError_.clear(); safe->diagnostics_.record ("DIRECT_ROUTE_APPROVED", @@ -1641,11 +1788,11 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr { safe->playerOutputPendingIndex_=-1; safe->diagnostics_.record ("DIRECT_ROUTE_REJECTED", - "No valid full-duplex device; audio remains gated"); + "No verified stereo playback device; audio remains gated"); safe->emitNotice ( safe->engine_.hasRetainedUnboundMixer() - ? "Mixer and plugin state retained. Device binding changed; output stays muted until a verified full-session rebind." - : "Choose a working capture and render device. Audio remains muted.", true); + ? "Playback unavailable. Mixer and plugin settings are saved." + : "Choose a working stereo output in Audio I/O. Input hardware is optional.", true); safe->emitApprovedNativeSnapshot(); } }); @@ -1780,7 +1927,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr result.preallocateBytes (64 * 1024); result << "ARSONMIX / SMART AUDIO DIAGNOSTIC REPORT v2\n"; result << "Timestamp: " << juce::Time::getCurrentTime().toISO8601 (true) << "\n"; - result << "Build: experimental-P0 clock-instrumentation / native JUCE 8.0.15\n"; + result << "Build: " << juce::JUCEApplication::getInstance()->getApplicationVersion() + << " | Source HEAD: " << ARMIX_BUILD_SOURCE_SHA << "\n"; result << "Platform: " << juce::SystemStats::getOperatingSystemName() << "\n"; result << "CPU: " << juce::SystemStats::getCpuModel() << "\n"; result << "Logical cores: " << juce::SystemStats::getNumCpus() @@ -2131,6 +2279,160 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr "arMixBuiltinHarmonyAck",juce::var(ack.release())); } + // CONTROL ONLY: drain at most 512 ten-ms music summary frames per 12Hz + // host tick. The actual music audio was tapped inside the existing PCM + // graph; BPM/onset analysis never touches the ASIO callback. All live + // vocal inserts consume a precomputed atomic interval, not a WebView BPM. + void serviceNativeMusicTempo() { + lastMusicTempo_=engine_.pollNativeMusicTempo(); + const bool bpmLocked=lastMusicTempo_.active&& + lastMusicTempo_.tempo.locked; + const bool phaseLocked=bpmLocked&& + lastMusicTempo_.tempo.phaseLocked&& + lastMusicTempo_.tempo.beatAnchorFrame>0; + const float bpm=bpmLocked?lastMusicTempo_.tempo.bpm:0.f; + const std::uint64_t anchor=phaseLocked? + lastMusicTempo_.tempo.beatAnchorFrame:0; + const auto epoch=lastMusicTempo_.epoch; + const auto revision=lastMusicTempo_.revision; + engine_.forEachNativeProcessor([bpm,anchor,epoch,revision]( + armix::mixer::ChannelId,juce::AudioProcessor* p) { + if(auto* vocal=dynamic_cast(p)) + vocal->publishMusicGrid(bpm,anchor,epoch,revision); + }); + } + + // Native Vocal Throw settings, manual cue and auto-trigger readback. + // Settings and triggers are not accepted until the AUDIO-owned SPSC + // completion is drained on JUCE's message thread. + void emitNativeThrowSnapshot(const juce::String& request, + const juce::String& channelId,const juce::String& epoch, + const juce::String& revision,const juce::String& instanceId, + armix::builtin_fx::VocalThrowProcessor* processor) { + auto reply=std::make_unique(); + reply->setProperty("requestId",request); + reply->setProperty("channelId",channelId); + reply->setProperty("deviceEpoch",epoch); + reply->setProperty("graphRevision",revision); + reply->setProperty("instanceId",instanceId); + reply->setProperty("schemaVersion",1); + reply->setProperty("status",processor?"ACCEPTED":"REJECTED"); + if(processor) { + auto settings=std::make_unique(); + const auto s=processor->acceptedSettings(); + settings->setProperty("mode",s.mode); + settings->setProperty("bpm",s.bpm); + settings->setProperty("division",s.division); + settings->setProperty("repeats",s.repeats); + settings->setProperty("captureMs",s.captureMs); + settings->setProperty("silenceMs",s.silenceMs); + settings->setProperty("thresholdDb",s.thresholdDb); + settings->setProperty("wet",s.wet); + settings->setProperty("decay",s.decay); + settings->setProperty("ducking",s.ducking); + reply->setProperty("settings",juce::var(settings.release())); + reply->setProperty("sampleRate",processor->acceptedSampleRate()); + // MUSIC tempo belongs to Vocal Throw, not to the unrelated EQ. + // Fence every displayed source/beat to THIS accepted graph. + // A retired device may leave a last control-timer snapshot; it + // must never appear as a locked beat on a newly opened device. + const bool currentMusicGraph=lastMusicTempo_.active&& + epoch==juce::String(std::to_string(lastMusicTempo_.epoch))&& + revision==juce::String(std::to_string(lastMusicTempo_.revision)); + reply->setProperty("musicSourceChannelId", + currentMusicGraph? + juce::String(std::to_string(lastMusicTempo_.source.value)): + juce::String("0")); + reply->setProperty("musicSourceActive",currentMusicGraph); + reply->setProperty("musicLocked",currentMusicGraph&& + lastMusicTempo_.tempo.locked); + reply->setProperty("musicBpm", + currentMusicGraph&&lastMusicTempo_.tempo.locked? + lastMusicTempo_.tempo.bpm:0.f); + reply->setProperty("musicConfidence", + currentMusicGraph?lastMusicTempo_.tempo.confidence:0.f); + reply->setProperty("musicGridAvailable",currentMusicGraph&& + lastMusicTempo_.tempo.locked&& + lastMusicTempo_.tempo.phaseLocked); + reply->setProperty("musicPhaseConfidence", + currentMusicGraph?lastMusicTempo_.tempo.phaseConfidence:0.f); + reply->setProperty("musicBeatAnchorFrame",juce::String( + std::to_string(currentMusicGraph? + lastMusicTempo_.tempo.beatAnchorFrame:0))); + reply->setProperty("musicDroppedFrames",currentMusicGraph? + static_cast(lastMusicTempo_.dropped):0); + + reply->setProperty("throwCount",static_cast(processor->observedThrowCount())); + reply->setProperty("tailActive",processor->observedTailActive()); + reply->setProperty("addedLatencySamples",processor->getLatencySamples()); + if(instanceId==lastNativeThrowInstance_&& + epoch==lastNativeThrowEpoch_&&revision==lastNativeThrowRevision_) + reply->setProperty("appliedRequestId",lastNativeThrowRequest_); + } else reply->setProperty("error","NATIVE_THROW_INSTANCE_OR_REVISION_UNAVAILABLE"); + if(browser_.loaded)browser_.emitEventIfBrowserIsVisible( + "arMixBuiltinThrowSnapshot",juce::var(reply.release())); + } + + void servicePendingNativeThrow() { + if(!pendingNativeThrow_.owner)return; + auto* processor=dynamic_cast( + pendingNativeThrow_.owner->processor.get()); + if(!processor){pendingNativeThrow_={};return;} + const auto request=pendingNativeThrow_.request; + const auto wire=request.startsWith("throw-")? + request.substring(6).toStdString():std::string(); + std::uint64_t requestId=0; + if(!wire.empty()&&wire.size()<=19&& + wire.find_first_not_of("0123456789")==std::string::npos) { + try{requestId=std::stoull(wire);}catch(...){requestId=0;} + } + // Old completions can arrive after a rejected timeout. Drain at + // most the bounded SPSC depth and ONLY ACK our exact request. + armix::builtin_fx::VocalThrowProcessor::Completion completion{},item{}; + bool matched=false; + for(int i=0;i<32 && processor->pollCompletion(item);++i) { + if(requestId && item.requestId==requestId) { + completion=item;matched=true;break; + } + } + if(!matched && + juce::Time::getMillisecondCounter()-pendingNativeThrow_.started<3000u) + return; + if(!matched)processor->cancelQueuedRequest(requestId); + bool applied=matched&&completion.applied&&requestId!=0; + const auto snap=approvedNativeSnapshot(); + const auto device=snap.getProperty("device",{}); + const auto graph=snap.getProperty("graph",{}); + applied=applied&&pendingNativeThrow_.deviceEpoch== + device.getProperty("epoch","").toString()&& + pendingNativeThrow_.revision== + graph.getProperty("revision","").toString(); + if(applied) { + lastNativeThrowRequest_=request; + lastNativeThrowInstance_=pendingNativeThrow_.instanceId; + lastNativeThrowEpoch_=pendingNativeThrow_.deviceEpoch; + lastNativeThrowRevision_=pendingNativeThrow_.revision; + } + auto ack=std::make_unique(); + ack->setProperty("requestId",request); + ack->setProperty("channelId",pendingNativeThrow_.channelId); + ack->setProperty("deviceEpoch",pendingNativeThrow_.deviceEpoch); + ack->setProperty("graphRevision",pendingNativeThrow_.revision); + ack->setProperty("instanceId",pendingNativeThrow_.instanceId); + ack->setProperty("status",applied?"APPLIED":"REJECTED"); + ack->setProperty("command",pendingNativeThrow_.trigger? + "TRIGGER":"SETTINGS"); + ack->setProperty("errorCode",applied?"NONE":!matched? + "DSP_ACK_TIMEOUT_CANCELLED": + (pendingNativeThrow_.trigger&&completion.bypassed)? + "FX_BYPASSED_THROW_DISABLED": + pendingNativeThrow_.trigger? + "NO_CAPTURE_OR_STALE_GRAPH":"DSP_EDIT_NOT_APPLIED_OR_STALE"); + pendingNativeThrow_={}; + if(browser_.loaded)browser_.emitEventIfBrowserIsVisible( + "arMixBuiltinThrowAck",juce::var(ack.release())); + } + // Never confuse durable logical ChannelId state with a physical device // authorization. This message-thread report is status only, not PCM. void emitMixerSessionAck(const juce::String& operation, @@ -2151,7 +2453,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr for(auto& insert:doc.inserts) { if(insert.catalogId==armix::builtin_fx::ChannelEqProcessor::catalogIdentity || insert.catalogId==armix::builtin_fx::ChannelCompressorProcessor::catalogIdentity || - insert.catalogId==armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity) { + insert.catalogId==armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity || + insert.catalogId==armix::builtin_fx::VocalThrowProcessor::catalogIdentity) { if(insert.path.isNotEmpty() || insert.uid!=0) return "Saved built-in FX identity was modified"; continue; @@ -2218,16 +2521,33 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr diagnostics_.record("DYNAMIC_MIXER_VST3_REMAP_REQUIRED",error); return error; } + if(bindingMode==MixerBindingMode::exact && startupOnSavedDevice && + armix::session::MixerDeviceBindingPolicy::isAsio4All(doc.binding)) + bindingMode=MixerBindingMode::verifiedAsioRestart; const bool resume=startupOnSavedDevice && - bindingMode==armix::session::MixerDeviceBindingPolicy::Mode::exact && + (bindingMode==MixerBindingMode::exact || bindingMode==MixerBindingMode::verifiedAsioRestart) && !usedPrevious && !retained && doc.resumeMain.value_or(true); const auto live=engine_.status().getProperty("dryRoutingLab",{}); - if(static_cast(live.getProperty("nativeChannelIdPcmActive",false))) { + const bool nativeAlreadyActive=static_cast( + live.getProperty("nativeChannelIdPcmActive",false)); + // A fresh silent ChannelId starter is now admitted before the saved + // Show is inspected. Only THAT unmodified bootstrap may be replaced + // by cold-start restore or by verified Apply after a failed startup. User-authored FX, + // WIRE, BUS and fader edits must never be overwritten by late scan. + // A verified PREVIOUS checkpoint is also eligible: the separate + // resume policy keeps MAIN muted after recovery from corrupt HEAD. + const bool recoveringAfterDeviceApply=bindingMode!=MixerBindingMode::exact && + mixerSessionRecoveryPending_; + const bool replacePristineStartup=nativeAlreadyActive && !retained && + (startupOnSavedDevice || recoveringAfterDeviceApply) && + engine_.hasPristineStartupMixer(); + if(nativeAlreadyActive && !replacePristineStartup) { mixerSessionStatus_="LIVE_MIXER_UNCHANGED"; - return "Live native mixer already active; refusing to replace it"; + return "Live native mixer already edited; refusing to replace it"; } - error=engine_.restoreNativeMixerSession(std::move(doc),states,false,nullptr,bindingMode); + error=engine_.restoreNativeMixerSession(std::move(doc),states, + replacePristineStartup,nullptr,bindingMode); if(error.isNotEmpty()) { mixerSessionStatus_=error.contains("NEEDS_REMAP") ?"NEEDS_REMAP":"RESTORE_REJECTED"; @@ -2236,7 +2556,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr return error; } mixerSessionRecoveryPending_=false; - if(resume)requestAutomaticMain(); + if(resume)requestAutomaticMain(bindingMode!=MixerBindingMode::verifiedAsioRestart); mixerSessionStatus_=engine_.isMonitorEnabled()?"RESTORED_MONITORING":"RESTORED_MUTED"; mixerSessionError_.clear(); diagnostics_.record("DYNAMIC_MIXER_RESTORED",mixerSessionStatus_); @@ -2448,6 +2768,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr obj->setProperty("selected",playerSelected_); obj->setProperty("current",playerCurrent_); obj->setProperty("autoNext",playerAutoNext_); + obj->setProperty("libraryBusy",playerFolderBusy_); obj->setProperty("error",playerError_); obj->setProperty("chooseOutput", playerError_.containsIgnoreCase("Choose a verified MAIN output") || @@ -2513,6 +2834,115 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr }); }); } + void choosePlayerFolder() { + if(playerFileChooser_ || playerFolderBusy_)return; + playerFileChooser_=std::make_unique( + "Add Music Folder", + juce::File::getSpecialLocation(juce::File::userMusicDirectory), + "*",true); + playerFileChooser_->launchAsync( + juce::FileBrowserComponent::openMode | + juce::FileBrowserComponent::canSelectDirectories, + [safe=juce::Component::SafePointer(this)] + (const juce::FileChooser& picker) { + if(!safe)return; + const auto folder=picker.getResult(); + // FileChooser must not be destroyed inside its callback. + juce::MessageManager::callAsync([safe] { + if(safe)safe->playerFileChooser_.reset(); + }); + if(!folder.isDirectory())return; + safe->playerFolderBusy_=true; + safe->playerError_.clear(); + safe->emitPlayerState(); + // Only filesystem enumeration, bounded in scope and output, + // is performed on the worker. Never block the JUCE message + // loop or ASIO callback while importing a large USB folder. + std::thread([safe,folder] { + auto scan=armix::player::PlayerLibraryPolicy::scanFolder(folder); + juce::MessageManager::callAsync( + [safe,scan=std::move(scan)]() mutable { + if(!safe)return; + safe->playerFolderBusy_=false; + int added=0; + int first=-1; + for(const auto& file:scan.files) { + const auto found=std::find( + safe->playerLibrary_.begin(), + safe->playerLibrary_.end(),file); + if(found!=safe->playerLibrary_.end())continue; + if(safe->playerLibrary_.size()>= + armix::player::PlayerLibraryPolicy::maxSongs)break; + if(first<0) + first=static_cast(safe->playerLibrary_.size()); + safe->playerLibrary_.push_back(file); + safe->playerTrackSettings_.push_back({}); + ++added; + } + if(safe->playerSelected_<0 && first>=0) + safe->playerSelected_=first; + safe->playerError_=scan.truncated? + "Folder scan reached its safe size limit; only some songs were added": + added==0? + "No new supported songs found in this folder": + juce::String{}; + safe->persistPlayerLibrary(); + safe->emitPlayerState(true); + }); + }).detach(); + }); + } + + void choosePlayerRelink() { + if(playerFileChooser_ || playerFolderBusy_)return; + const int index=playerSelected_; + if(index<0 || index>=static_cast(playerLibrary_.size()))return; + const auto old=playerLibrary_[static_cast(index)]; + if(old.existsAsFile())return; // only resolve genuinely missing music + playerFileChooser_=std::make_unique( + "Locate Missing Music — "+old.getFileName(), + old.getParentDirectory().isDirectory()? + old.getParentDirectory(): + juce::File::getSpecialLocation(juce::File::userMusicDirectory), + "*.wav;*.mp3;*.flac;*.aif;*.aiff;*.ogg",true); + playerFileChooser_->launchAsync( + juce::FileBrowserComponent::openMode | + juce::FileBrowserComponent::canSelectFiles, + [safe=juce::Component::SafePointer(this),index,old] + (const juce::FileChooser& picker) { + if(!safe)return; + const auto chosen=picker.getResult(); + juce::MessageManager::callAsync([safe] { + if(safe)safe->playerFileChooser_.reset(); + }); + if(chosen==juce::File{})return; + if(index>=static_cast(safe->playerLibrary_.size()) || + safe->playerLibrary_[static_cast(index)]!=old) { + safe->playerError_="Setlist changed; locate the song again"; + } else if(!armix::player::PlayerLibraryPolicy::sameSongName( + old,chosen)) { + safe->playerError_="Choose the same song filename to avoid relinking the wrong music"; + } else if(std::find(safe->playerLibrary_.begin(), + safe->playerLibrary_.end(),chosen)!= + safe->playerLibrary_.end()) { + safe->playerError_="This music file is already in your setlist"; + } else { + // Preserve same logical song ID, order and per-song + // KEY/TEMPO. Never start a song or switch the output + // as a side effect of locating a file. + if(safe->playerCurrent_==index) { + safe->engine_.playerStop(); + safe->playerCurrent_=-1; + } + safe->playerLibrary_[static_cast(index)]=chosen; + safe->playerOutputPendingIndex_=-1; + safe->playerError_.clear(); + safe->persistPlayerLibrary(); + } + safe->emitPlayerState(true); + }); + } + void playTransportMusic() { const auto phase=engine_.playerStatus().getProperty( "state","EMPTY").toString().toStdString(); @@ -2572,6 +3002,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr void onAction (const juce::var& args) { auto action = args.getProperty ("action", {}).toString(); + if(audioDeviceApplyActive_ && action!="audioDeviceApply")return; const auto value = args.getProperty ("value", {}); const int slot = static_cast (args.getProperty ("slot", -1)); if(action=="playerChooseOutput") { @@ -2588,6 +3019,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr } if(action=="playerSubscribe")return emitPlayerState(true); if(action=="playerAdd")return choosePlayerFiles(); + if(action=="playerAddFolder")return choosePlayerFolder(); + if(action=="playerRelink")return choosePlayerRelink(); if(action=="playerKeyStep" || action=="playerTempoStep" || action=="playerPitchTempoReset") { const auto target=armix::player::SetlistPolicy::pitchTempoTarget( @@ -2652,7 +3085,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr action == "routingNativeFxRackBypass" || action == "routingNativeFxInsertBypass" || action == "routingFxRackBypass" || - action == "nativeEqSetBand" || action == "nativeCompSet")) + action == "nativeEqSetBand" || action == "nativeCompSet" || + action == "nativeThrowSet" || action == "nativeThrowTrigger" || + action == "nativeThrowTempoSource")) { const auto reason=juce::String( "Studio backup in progress. Finish backup before editing saved FX or VST library."); @@ -2989,6 +3424,116 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr return; } + // ArSon Vocal Throw: all UI commands reference one exact installed + // ChannelId + device epoch + graph revision + insert instance. + if(action=="nativeThrowSnapshot"||action=="nativeThrowSet"|| + action=="nativeThrowTrigger"||action=="nativeThrowTempoSource") { + const auto rawChannel=args.getProperty("channelId",{}); + const auto rawEpoch=args.getProperty("deviceEpoch",{}); + const auto rawRevision=args.getProperty("graphRevision",{}); + const auto rawInstance=args.getProperty("instanceId",{}); + const auto request=args.getProperty("requestId",{}).toString(); + const int throwSlot=static_cast(args.getProperty("slot",-1)); + std::uint64_t ch=0,ep=0,rev=0; + const bool valid=armix::console::approvedNativeId(rawChannel,ch)&& + armix::console::approvedNativeId(rawEpoch,ep)&& + armix::console::approvedNativeId(rawRevision,rev)&& + rawInstance.isString()&&rawInstance.toString().isNotEmpty()&& + throwSlot>=0&&throwSlot(throwSlot), + rawInstance.toString()): + armix::mixer::LiveChannelFxGraph::InstanceLease{}; + auto* processor=owner?dynamic_cast( + owner->processor.get()):nullptr; + if(action=="nativeThrowSnapshot") { + emitNativeThrowSnapshot(request,rawChannel.toString(), + rawEpoch.toString(),rawRevision.toString(), + rawInstance.toString(),processor); + return; + } + if(action=="nativeThrowTempoSource") { + // A single shared song clock is selected by stable ChannelId; + // the source cannot be this vocal channel, MAIN or MONITOR. + const auto rawSource=args.getProperty("sourceChannelId",{}); + const auto sourceText=rawSource.toString(); + std::uint64_t source=0; + const bool parsed=sourceText=="0" || + armix::console::approvedNativeId(rawSource,source); + const bool chosen=processor && parsed && (!source||source!=ch) && + !nativeShowBusy_&&!studioBackupBusy_ && + engine_.selectNativeMusicTempoSource( + ep,rev,armix::mixer::ChannelId{source}); + if(chosen)serviceNativeMusicTempo(); + auto reply=std::make_unique(); + reply->setProperty("requestId",request); + reply->setProperty("status",chosen?"APPLIED":"REJECTED"); + reply->setProperty("sourceChannelId",sourceText); + reply->setProperty("errorCode",chosen?"NONE": + "INVALID_OR_STALE_MUSIC_CHANNEL"); + if(browser_.loaded)browser_.emitEventIfBrowserIsVisible( + "arMixBuiltinThrowTempoAck",juce::var(reply.release())); + return; + } + const auto wire=request.startsWith("throw-")? + request.substring(6).toStdString():std::string(); + std::uint64_t numeric=0; + if(!wire.empty()&&wire.size()<=19&& + wire.find_first_not_of("0123456789")==std::string::npos) { + try{numeric=std::stoull(wire);}catch(...){numeric=0;} + } + const bool isSettings=action=="nativeThrowSet"; + const auto values=args.getProperty("settings",{}); + armix::builtin_fx::VocalThrowSettings settings{}; + auto read=[&values](const char* key,float& out) { + const auto value=values.getProperty(key,{}); + if(!value.isInt()&&!value.isDouble())return false; + const auto v=static_cast(value); + if(!std::isfinite(v))return false; + out=static_cast(v); + return std::isfinite(out); + }; + auto integer=[&read](const char* key,int& out) { + float candidate=0.f; + if(!read(key,candidate)||candidate!=std::floor(candidate)|| + candidate<0.f||candidate>1000.f)return false; + out=static_cast(candidate);return true; + }; + const bool settingsValid=!isSettings || (values.isObject()&& + integer("mode",settings.mode)&&read("bpm",settings.bpm)&& + integer("division",settings.division)&&integer("repeats",settings.repeats)&& + read("captureMs",settings.captureMs)&&read("silenceMs",settings.silenceMs)&& + read("thresholdDb",settings.thresholdDb)&&read("wet",settings.wet)&& + read("decay",settings.decay)&&read("ducking",settings.ducking)&& + armix::builtin_fx::VocalThrow::validSettings(settings)); + bool queued=false; + if(processor&&numeric>0&&settingsValid&&!pendingNativeThrow_.owner&& + !nativeShowBusy_&&!studioBackupBusy_&&!engine_.independentClockActive()) { + queued=isSettings?processor->queueSettings(settings,numeric): + processor->queueTrigger(numeric); + if(queued) { + pendingNativeThrow_.owner=owner; + pendingNativeThrow_.request=request; + pendingNativeThrow_.channelId=rawChannel.toString(); + pendingNativeThrow_.deviceEpoch=rawEpoch.toString(); + pendingNativeThrow_.revision=rawRevision.toString(); + pendingNativeThrow_.instanceId=rawInstance.toString(); + pendingNativeThrow_.started=juce::Time::getMillisecondCounter(); + pendingNativeThrow_.trigger=!isSettings; + } + } + auto ack=std::make_unique(); + ack->setProperty("requestId",request); + ack->setProperty("status",queued?"QUEUED":"REJECTED"); + ack->setProperty("errorCode",queued?"NONE": + pendingNativeThrow_.owner?"THROW_CONTROL_BUSY": + "INVALID_OR_STALE_NATIVE_THROW"); + if(browser_.loaded)browser_.emitEventIfBrowserIsVisible( + "arMixBuiltinThrowQueue",juce::var(ack.release())); + return; + } + // Route the approved channel FX picker to the SAME prepared M4 // graph as physical IN/OUT. ID resolves exclusively in the JUCE // catalog; browser paths/names are never trusted as plugin identity. @@ -4412,7 +4957,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr lastDirectRestoreError_.clear(); // One-sided device routes are temporary and must never leak into // normal user configuration or the persisted audio-devices.xml. - if (engine_.hasTemporaryDiagnosticDevice()) + if (engine_.hasTemporaryDiagnosticDevice() || + engine_.diagnosticRoute()==armix::diagnostics::Route::mainOutputTone) { const auto error = engine_.setDiagnosticRoute (armix::diagnostics::Route::normal); if (error.isNotEmpty()) return emitNotice (error, true); @@ -4431,9 +4977,12 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr deviceSettingsDirty_ = true; } using Route = armix::diagnostics::Route; - const auto selected = value.toString(); + auto selected = value.toString(); + if(selected=="TOGGLE_MAIN_OUTPUT_TONE") + selected=engine_.diagnosticRoute()==Route::mainOutputTone?"NORMAL":"MAIN_OUTPUT_TONE"; auto route = Route::normal; if (selected == "OUTPUT_ONLY_TONE") route = Route::outputOnlyTone; + else if (selected == "MAIN_OUTPUT_TONE") route = Route::mainOutputTone; else if (selected == "CAPTURE_ONLY") route = Route::captureOnly; else if (selected == "DRY_THROUGH") route = Route::dryThrough; else if (selected != "NORMAL") return emitNotice ("Unsupported diagnostic mode", true); @@ -4448,8 +4997,11 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr if (route == Route::normal) deviceSettingsDirty_ = true; diagnostics_.record ("AUDIO_TEST_MODE", selected + " | " + juce::JSON::toString (engine_.status(), false)); - emitNotice ("Audio diagnostic: " + selected + - ". Use low headphone volume and MARK CRACKLE on audible faults."); + if(route==Route::mainOutputTone) + emitNotice("MAIN test tone active. Use low speaker volume. Press Test MAIN output again to stop."); + else + emitNotice ("Audio diagnostic: " + selected + + ". Use low headphone volume and MARK CRACKLE on audible faults."); } else if (action == "diagnosticMark") { @@ -4803,6 +5355,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr fault=engine_.liveOutputArmFault(); if (fault.isEmpty()) { autoMainEpoch_=0; + if(!arm)engine_.cancelAsioResetMonitorIntent(); engine_.setMonitorEnabled(arm); diagnostics_.record("OUTPUT_MUTE",arm?"OFF":"ON"); } @@ -4834,19 +5387,22 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr } } - bool finishAudioSetupAndRecoverMixer(bool verifiedDeviceApply=false) { - const bool bound=engine_.finishManualAudioSetup(); + bool finishAudioSetupAndRecoverMixer(MixerBindingMode bindingMode=MixerBindingMode::exact) { + const bool bound=engine_.finishManualAudioSetup(bindingMode!=MixerBindingMode::verifiedMainPinApply); if(!engine_.directRouteAuthorized())return false; const auto lab=engine_.status().getProperty("dryRoutingLab",{}); - if(static_cast(lab.getProperty("nativeChannelIdPcmActive",false)))return true; - if(engine_.hasRetainedNativeSession() || - armix::session::NativeMixerSessionStore(settingsDirectory()).exists()) { - using BindingMode=armix::session::MixerDeviceBindingPolicy::Mode; - const auto error=restoreSavedMixerSession(false,verifiedDeviceApply? - BindingMode::verifiedDeviceApply:BindingMode::exact); + const bool hasCheckpoint=armix::session::NativeMixerSessionStore(settingsDirectory()).exists(); + const bool recoverPristine=bindingMode!=MixerBindingMode::exact && hasCheckpoint && + mixerSessionRecoveryPending_ && engine_.hasPristineStartupMixer(); + if(static_cast(lab.getProperty("nativeChannelIdPcmActive",false)) && + !recoverPristine)return true; + if(engine_.hasRetainedNativeSession() || hasCheckpoint) { + if(bindingMode==MixerBindingMode::exact && engine_.sameRetainedAsioDriver()) + bindingMode=MixerBindingMode::verifiedAsioRestart; + const auto error=restoreSavedMixerSession(false,bindingMode); if(error.isNotEmpty()) { mixerSessionError_=error; - emitNotice("Mixer retained; "+error,true); + emitNotice(error.startsWith("NEEDS_REMAP:")?error.fromFirstOccurrenceOf(": ",false,false):error,true); return false; } return true; @@ -4854,8 +5410,112 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr return bound; } + std::uint64_t asioRecoveryEpoch_=0; // last successfully bound generation + armix::device::AsioRestartRecoveryGate asioRecoveryGate_; + + void serviceAsioMixerRestart() { + const auto epoch=engine_.dryRoutingLabEpoch(); + if(epoch==asioRecoveryEpoch_ || !engine_.hasRetainedNativeSession() || + audioDeviceApplyActive_ || (audioSetupWindow_ && audioSetupWindow_->isVisible()) || + nativeShowBusy_ || studioBackupBusy_ || mixerSessionWorker_.busy() || catalog_.busy() || + engine_.isGraphSwitchPending() || engine_.independentClockActive() || + engine_.diagnosticRoute()!=armix::diagnostics::Route::normal)return; + auto* device=engine_.devices().getCurrentAudioDevice(); + if(device) { + if(device->getTypeName()!="ASIO" || + !device->getName().startsWithIgnoreCase("ASIO4ALL") || + !engine_.sameRetainedAsioDriver())return; + } else if(!engine_.selectedRetainedAsioDriverForReopen()) { + // The device pointer disappeared: never open an unapproved or + // guessed driver name, even if ASIO4ALL happens to be installed. + return; + } + const auto now=monotonicMilliseconds(); + asioRecoveryGate_.observeEpoch(epoch,now); + if(!asioRecoveryGate_.due(now))return; // let ASIO4ALL WDM pin inventory settle + const juce::ScopedValueSetter applying(audioDeviceApplyActive_,true); + if(!device || !device->isOpen() || + device->getActiveOutputChannels().countNumberOfSetBits()<2) { + // A missing, closed or output-less ASIO device requires a vendor call. + // Never reopen it repeatedly on each UI timer tick. + if(!asioRecoveryGate_.mayChangeDriver()) { + asioRecoveryGate_.waitForReadback(now); + return; + } + juce::AudioDeviceManager::AudioDeviceSetup setup; + engine_.devices().getAudioDeviceSetup(setup); + // A deliberate 0-IN session remains 0-IN. Never resurrect a mic. + setup.useDefaultInputChannels=!setup.inputChannels.isZero(); + setup.useDefaultOutputChannels=true; + asioRecoveryGate_.driverTransaction(now); + if(!device)diagnostics_.record("ASIO4ALL_DEVICE_MISSING", + "Reopening previously approved registered ASIO driver; no fallback"); + const auto error=openSelectedAudioDevice("ASIO",setup,true); + asioRecoveryGate_.carryInternalEpoch(engine_.dryRoutingLabEpoch()); + device=engine_.devices().getCurrentAudioDevice(); + if(error.isNotEmpty() || !device || !device->isOpen()) { + diagnostics_.record("ASIO4ALL_REOPEN_FAILED",error); + emitApprovedNativeSnapshot(); + return; + } + } + if(!engine_.authorizeRetainedAsioRestart()) { + // Admission can lag driver restart without any driver call. + // It MUST NOT exhaust the bounded reopen/correction allowance. + asioRecoveryGate_.waitForReadback(now); + diagnostics_.record("ASIO4ALL_BIND_NOT_READY","Waiting for verified callback/readback"); + return; + } + if(const auto corrected=engine_.asioRestartPinCorrection()) { + if(!asioRecoveryGate_.mayChangeDriver()) { + asioRecoveryGate_.waitForReadback(now); + diagnostics_.record("ASIO4ALL_PIN_CORRECTION_DEFERRED", + "Driver transaction budget exhausted for this physical epoch"); + return; + } + const auto inputNames=device->getInputChannelNames(); + const auto outputNames=device->getOutputChannelNames(); + asioRecoveryGate_.driverTransaction(now); + const auto error=openSelectedAudioDevice("ASIO",*corrected); + asioRecoveryGate_.carryInternalEpoch(engine_.dryRoutingLabEpoch()); + auto* reopened=engine_.devices().getCurrentAudioDevice(); + if(error.isNotEmpty() || !reopened || !reopened->isOpen() || + reopened->getInputChannelNames()!=inputNames || + reopened->getOutputChannelNames()!=outputNames || + reopened->getActiveInputChannels()!=corrected->inputChannels || + reopened->getActiveOutputChannels()!=corrected->outputChannels || + !engine_.authorizeRetainedAsioRestart()) { + diagnostics_.record("ASIO4ALL_PIN_CORRECTION_FAILED", + error.isNotEmpty()?error:juce::String("Readback changed during correction")); + emitApprovedNativeSnapshot(); + return; + } + } + const auto error=engine_.reattachRetainedAsioMixer()?juce::String{}: + restoreSavedMixerSession(false,MixerBindingMode::verifiedAsioRestart); + if(error.isNotEmpty()) { + // A native graph/FX lease may become ready after the driver's + // current epoch; retry without reopening hardware at an + // exponentially bounded CONTROL cadence. + asioRecoveryGate_.bindFailed(now); + diagnostics_.record("ASIO4ALL_REATTACH_FAILED",error); + emitApprovedNativeSnapshot(); + return; + } + asioRecoveryEpoch_=engine_.dryRoutingLabEpoch(); + asioRecoveryGate_.carryInternalEpoch(asioRecoveryEpoch_); + asioRecoveryGate_.recovered(); + mixerSessionStatus_="RESTORED_MUTED"; + mixerSessionError_.clear(); + if(engine_.takeAsioResetMonitorIntent())requestAutomaticMain(false); + if(engine_.isMonitorEnabled())mixerSessionStatus_="RESTORED_MONITORING"; + diagnostics_.record("ASIO4ALL_REATTACHED","Verified driver and current MAIN pair"); + emitApprovedNativeSnapshot(); + } + void changeListenerCallback (juce::ChangeBroadcaster*) override { + if(audioDeviceApplyActive_)return; // synchronous transaction owns recovery // Save device state only after a real change, not on every 3-second tick. deviceSettingsDirty_ = true; // The retention gate closes only on an actual epoch/owner change. @@ -4871,6 +5531,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr void timerCallback() override { + if(audioDeviceApplyActive_)return; // a vendor modal loop may re-enter JUCE // Always disabled unless the user explicitly starts a bounded trace. const bool timing = guiPerf_.active; const double tickStart = timing ? juce::Time::getMillisecondCounterHiRes() : 0.0; @@ -4882,9 +5543,11 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr guiPerf_.prevTickMs = tickStart; } ++timerTicks_; + serviceNativeMusicTempo(); servicePendingNativeEq(); servicePendingNativeComp(); servicePendingNativeHarmony(); + servicePendingNativeThrow(); // A hidden JUCE/WebView2 peer may defer first navigation. Expose the // compositor behind the opaque startup splash after the first tick; // the user sees the completed mixer only after the ready handshake. @@ -4933,11 +5596,12 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr mixerSessionRecoveryPending_=true; const auto error=restoreSavedMixerSession(startupError_.isEmpty()); if(error.isNotEmpty()) - emitNotice("Saved mixer retained; "+error,true); + emitNotice(error.startsWith("NEEDS_REMAP:")?error.fromFirstOccurrenceOf(": ",false,false):error,true); else deviceSettingsDirty_=true; }else if(startupError_.isEmpty())requestAutomaticMain(); } + serviceAsioMixerRestart(); // ONE actionable notice per unexpected DIRECT reroute. The audio // callback has already zero-filled output atomically; status, log and // WebView notifications belong only on this JUCE control timer. @@ -4951,7 +5615,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr unexpectedRouteNoticeSent_ = true; diagnostics_.record ("DIRECT_ROUTE_BLOCKED", "A device or backend changed unexpectedly; host output held at zero"); - emitNotice ("Audio device changed unexpectedly. Live output muted; confirm your ASIO/WASAPI device in AUDIO SETUP.", true); + if(!engine_.sameRetainedAsioDriver()) + emitNotice ("Audio device changed unexpectedly. Live output muted; confirm your ASIO/WASAPI device in AUDIO SETUP.", true); } if (!blocked) unexpectedRouteNoticeSent_ = false; // Audio thread publishes only fault flags. A bounded message-thread diff --git a/src/NativeMixerSessionDocument.h b/src/NativeMixerSessionDocument.h index 24cbacda3..68ce4c659 100644 --- a/src/NativeMixerSessionDocument.h +++ b/src/NativeMixerSessionDocument.h @@ -1,5 +1,6 @@ // SPDX-License-Identifier: AGPL-3.0-only #pragma once +#include #include #include "../engine/core/UnifiedLegacyProductionAdmission.h" #include "NativeShowStore.h" @@ -7,7 +8,9 @@ #include #include #include +#include #include +#include #include // The logical session and its hardware binding are deliberately separate. @@ -24,6 +27,12 @@ struct HardwareBinding final { // still decode without inventing an ASIO pin inventory. juce::StringArray inputNames,outputNames; }; +// A disconnected source has a physical identity but no live PCM ordinal. +struct WaitingAsioInput final { + ChannelId id{}; + int left=-1,right=-1; // physical pin indices, for legacy files without labels + juce::String leftName,rightName; +}; struct StoredInsert final { ChannelId channel{}; std::size_t slot=0; @@ -39,6 +48,7 @@ struct MixerSessionDocument final { LegacyChannelIds legacyIds{}; VerifiedNativeOutputs outputs{}; HardwareBinding binding{}; + std::vector waitingAsioInputs; std::vector inserts; std::vector rackBypassed; float masterGain=1.f; @@ -65,54 +75,90 @@ struct MixerDeviceBindingPolicy final { (!a.monitorEnabled || (a.monitorL==b.monitorL && a.monitorR==b.monitorR)); } - enum class Mode { exact, verifiedDeviceApply }; + enum class Mode { exact, verifiedDeviceApply, verifiedMainPinApply, verifiedAsioRestart }; + static bool isAsio4All(const HardwareBinding& binding) { + return binding.backend=="ASIO" && binding.playback.startsWithIgnoreCase("ASIO4ALL"); + } + static std::optional translateNamedPins( + const juce::BigInteger& previous,const juce::StringArray& oldNames, + const juce::StringArray& newNames) { + juce::BigInteger result; + for(int pin=previous.findNextSetBit(0);pin>=0;pin=previous.findNextSetBit(pin+1)) { + const int next=findSamePin(oldNames,newNames,pin); + if(next<0 || next>=64)return {}; + result.setBit(next); + } + return result; + } + static bool addReturningCapturePins(std::span waiting, + const juce::StringArray& names,juce::BigInteger& mask) { + const auto previous=mask; + for(const auto& patch:waiting) { + const int left=uniquePin(names,patch.leftName); + const int right=uniquePin(names,patch.rightName); + if(left<0 || left>=64 || (patch.right>=0 && (right<0 || right>=64 || right==left)))continue; + mask.setBit(left); + if(patch.right>=0)mask.setBit(right); + } + return mask!=previous; + } static VerifiedNativeOutputs proposedOutputs(const MixerSessionDocument& document, const HardwareBinding& live,int count,Mode mode=Mode::exact) { const auto& saved=document.binding; - if(mode==Mode::verifiedDeviceApply && - (saved.backend!=live.backend || saved.playback!=live.playback)) - return count==2?VerifiedNativeOutputs{count,0,1,-1,-1,false}: - VerifiedNativeOutputs{count,-1,-1,-1,-1,false}; - // A matching endpoint name does NOT prove an unchanged physical - // jack inventory. Reject rather than silently rebase MAIN to 1/2 - // if pin labels changed or an unknown ASIO inventory lost pins. - if(mode==Mode::verifiedDeviceApply && - ((!saved.outputNames.isEmpty() && saved.outputNames!=live.outputNames) || - (saved.outputNames.isEmpty() && live.backend=="ASIO" && - saved.outputMask!=live.outputMask))) - return {count,-1,-1,-1,-1,false}; + const VerifiedNativeOutputs unavailable{count,-1,-1,-1,-1,false}; + if(mode==Mode::verifiedMainPinApply || + (mode==Mode::verifiedDeviceApply && + (saved.backend!=live.backend || saved.playback!=live.playback))) + return count==2?VerifiedNativeOutputs{count,0,1,-1,-1,false}:unavailable; + if(mode==Mode::verifiedAsioRestart && + (!isAsio4All(live) || saved.backend!=live.backend || saved.playback!=live.playback)) + return unavailable; auto outputs=document.outputs; outputs.activeOutputChannels=count; - if(saved.outputMask!=live.outputMask) { - const auto oldPins=mask(saved.outputMask); - const auto newPins=mask(live.outputMask); - outputs.mainL=remapPin(oldPins,newPins,outputs.mainL); - outputs.mainR=remapPin(oldPins,newPins,outputs.mainR); + const auto oldPins=mask(saved.outputMask),newPins=mask(live.outputMask); + if(mode!=Mode::exact || saved.outputMask!=live.outputMask) { + const auto remap=[&](int ordinal) { + return remapPin(oldPins,newPins,saved.outputNames,live.outputNames, + ordinal,live.backend=="ASIO"); + }; + outputs.mainL=remap(outputs.mainL); + outputs.mainR=remap(outputs.mainR); if(outputs.monitorEnabled) { - outputs.monitorL=remapPin(oldPins,newPins,outputs.monitorL); - outputs.monitorR=remapPin(oldPins,newPins,outputs.monitorR); + outputs.monitorL=remap(outputs.monitorL); + outputs.monitorR=remap(outputs.monitorR); } } if(!outputs.valid()) { outputs.monitorL=outputs.monitorR=-1; outputs.monitorEnabled=false; } - // Never substitute the first available pair when the saved MAIN - // physical connectors disappear. Audio may only return after the - // operator explicitly patches MAIN to available output pins. + // The same approved ASIO4ALL driver can expose a different speaker + // after a WDM selection. Adopt the sole verified physical pair. + if(!outputs.valid() && (mode==Mode::verifiedDeviceApply || mode==Mode::verifiedAsioRestart) && + isAsio4All(live) && count>=2) { + // ASIO4ALL can expose virtual and physical WDM outputs together. + // A unique, enabled physical stereo pair is safe to recover even + // when its callback ordinals are 3/4 or arrive in reverse order. + // Ambiguous speakers and virtual-only inventories remain muted. + if(const auto pair=uniqueNamedSpeakerPair(newPins,live.outputNames)) + return {count,pair->first,pair->second,-1,-1,false}; + } return outputs; } static juce::String apply(MixerSessionDocument& document, const HardwareBinding& live, const VerifiedNativeOutputs& outputs, int callbackInputs,Mode mode) { - if(!outputs.valid() || callbackInputs<1 || callbackInputs>256 || - live.backend.isEmpty() || live.capture.isEmpty() || + if(callbackInputs<0 || callbackInputs>256 || + live.backend.isEmpty() || + (callbackInputs>0 && live.capture.isEmpty()) || live.playback.isEmpty() || live.inputMask.isEmpty() || live.outputMask.isEmpty() || !std::isfinite(live.rate) || live.rate<8000. || live.rate>384000. || live.frames<16 || live.frames>8192) return "NEEDS_REMAP: live device verification incomplete"; + if(!outputs.valid()) + return "NEEDS_REMAP: saved MAIN pair unavailable on the active playback pins"; const auto oldPins=mask(document.binding.inputMask); const auto newPins=mask(live.inputMask); if(oldPins.countNumberOfSetBits()!=document.request.physicalInputs || @@ -128,42 +174,71 @@ struct MixerDeviceBindingPolicy final { return exact?juce::String{}:juce::String( "NEEDS_REMAP: select the saved audio device and pin layout in Audio I/O"); - // An Apply of the SAME playback endpoint must keep the saved - // physical MAIN connectors. The current mask only changes their - // ordinals; it never authorizes quietly switching MAIN to another - // jack. Compare against the policy-computed remap even when a caller - // supplies a valid but DIFFERENT output pair. - if(saved.backend==live.backend && saved.playback==live.playback) { - const auto mapped=proposedOutputs(document,live, - outputs.activeOutputChannels,Mode::verifiedDeviceApply); + if(mode==Mode::verifiedMainPinApply || mode==Mode::verifiedAsioRestart || + (saved.backend==live.backend && saved.playback==live.playback)) { + const auto mapped=proposedOutputs(document,live,outputs.activeOutputChannels,mode); if(!mapped.valid() || !sameOutputs(mapped,outputs)) - return "NEEDS_REMAP: saved MAIN output pins are no longer selected; explicitly choose MAIN outputs"; + return "NEEDS_REMAP: MAIN does not match the verified playback pair"; } auto& sources=document.request.sources; - if(saved.backend!=live.backend || saved.capture!=live.capture || - !samePinNames(saved.inputNames,live.inputNames,live.backend)) { - // Different capture hardware invalidates PHYSICAL pins only. - // PlayerDeck is a DEVICE-INDEPENDENT source with no ASIO ordinal. - // Preserve it (still muted until physical output is verified). - sources.erase(std::remove_if(sources.begin(),sources.end(), - [](const DynamicSourcePatch& p) { - return p.kind==DynamicSourceKind::physical; - }),sources.end()); - } else if(oldPins!=newPins) { - std::vector mapped; - mapped.reserve(sources.size()); - for(auto source:sources) { + if(isAsio4All(saved) && isAsio4All(live) && saved.playback==live.playback) { + // Binding playback is independent of capture. Keep the user's + // patch by physical identity until the selected input returns. + auto desired=std::move(document.waitingAsioInputs); + desired.reserve(desired.size()+sources.size()); + std::vector virtualSources; + virtualSources.reserve(sources.size()); + for(const auto& source:sources) { + // ASIO capture remap never translates virtual music into pin 0. if(source.kind==DynamicSourceKind::playerDeck) { - mapped.push_back(source); // no physical input pin to remap + virtualSources.push_back(source); continue; } - source.inputL=remapPin(oldPins,newPins,source.inputL); - if(source.stereo)source.inputR=remapPin(oldPins,newPins,source.inputR); - if(source.inputL>=0 && (!source.stereo || source.inputR>=0)) - mapped.push_back(source); + const auto left=physicalAt(oldPins,source.inputL); + const auto right=physicalAt(oldPins,source.inputR); + desired.push_back({source.id,left,right, + saved.inputNames[left],saved.inputNames[right]}); + } + sources=std::move(virtualSources); + document.waitingAsioInputs.clear(); + for(auto& source:desired) { + const auto* channel=document.roster.find(source.id); + if(!channel || channel->role!=ChannelRole::input)continue; + const auto resolve=[&](int previous,const juce::String& label) { + const auto pin=label.isEmpty()?previous:uniquePin(live.inputNames,label); + return callbackAt(newPins,pin); + }; + const auto left=resolve(source.left,source.leftName); + const auto right=resolve(source.right,source.rightName); + const bool stereo=source.right>=0; + if(left>=0 && (!stereo || (right>=0 && left!=right))) + sources.push_back({source.id,left,right,stereo}); + else + document.waitingAsioInputs.push_back(std::move(source)); + } + } else { + document.waitingAsioInputs.clear(); + if(saved.backend!=live.backend || saved.capture!=live.capture) { + sources.erase(std::remove_if(sources.begin(),sources.end(), + [](const DynamicSourcePatch& p) { + return p.kind==DynamicSourceKind::physical; + }),sources.end()); + } else if(oldPins!=newPins || saved.inputNames!=live.inputNames) { + std::vector mapped; + mapped.reserve(sources.size()); + for(auto source:sources) { + if(source.kind==DynamicSourceKind::playerDeck) { + mapped.push_back(source); + continue; + } + source.inputL=remapPin(oldPins,newPins,saved.inputNames,live.inputNames,source.inputL,false); + if(source.stereo) + source.inputR=remapPin(oldPins,newPins,saved.inputNames,live.inputNames,source.inputR,false); + if(source.inputL>=0 && (!source.stereo || source.inputR>=0))mapped.push_back(source); + } + sources=std::move(mapped); } - sources=std::move(mapped); } document.request.physicalInputs=callbackInputs; document.binding=live; @@ -171,26 +246,75 @@ struct MixerDeviceBindingPolicy final { return {}; } private: - static bool samePinNames(const juce::StringArray& saved,const juce::StringArray& live, - const juce::String& backend) { - return saved.isEmpty()?backend!="ASIO":saved==live; - } static juce::BigInteger mask(const juce::String& text) { juce::BigInteger bits; bits.parseString(text,16); return bits; } - static int remapPin(const juce::BigInteger& saved,const juce::BigInteger& current,int ordinal) { + static std::optional> uniqueNamedSpeakerPair( + const juce::BigInteger& pins,const juce::StringArray& names) { + std::optional> chosen; + for(int leftPin=pins.findNextSetBit(0);leftPin>=0; + leftPin=pins.findNextSetBit(leftPin+1)) { + if(leftPin>=names.size() || uniquePin(names,names[leftPin])!=leftPin)continue; + const auto label=names[leftPin].trim().toLowerCase(); + if(!label.endsWith(" 1"))continue; + const auto stem=label.dropLastCharacters(2); + if(stem.isEmpty() || stem.contains("vb-audio") || stem.contains("cable") || + stem.contains("virtual") || stem.contains("loopback") || + stem.contains("monitor") || + !(stem.contains("realtek") || stem.contains("speaker") || + stem.contains("output with sst")))continue; + int rightPin=-1; + for(int pin=pins.findNextSetBit(0);pin>=0;pin=pins.findNextSetBit(pin+1)) { + if(pin=0)return {}; // duplicate right endpoint + rightPin=pin; + } + } + if(rightPin<0 || uniquePin(names,names[rightPin])!=rightPin)continue; + const int left=callbackAt(pins,leftPin),right=callbackAt(pins,rightPin); + if(left<0 || right<0 || left==right || chosen)return {}; + chosen=std::make_pair(left,right); + } + return chosen; + } + static int uniquePin(const juce::StringArray& names,const juce::String& name) { + if(name.isEmpty())return -1; + const auto pin=names.indexOf(name); + return pin>=0 && names.indexOf(name,false,pin+1)<0?pin:-1; + } + static int findSamePin(const juce::StringArray& previous,const juce::StringArray& live,int pin) { + const auto name=previous[pin]; + return uniquePin(previous,name)==pin?uniquePin(live,name):-1; + } + static int physicalAt(const juce::BigInteger& mask,int ordinal) { if(ordinal<0)return -1; - int physical=saved.findNextSetBit(0); - for(int i=0;i=0;++i) - physical=saved.findNextSetBit(physical+1); - if(physical<0 || !current[physical])return -1; + int pin=mask.findNextSetBit(0); + for(int i=0;i=0;++i)pin=mask.findNextSetBit(pin+1); + return pin; + } + static int callbackAt(const juce::BigInteger& mask,int physical) { + if(physical<0 || !mask[physical])return -1; int index=0; - for(int pin=current.findNextSetBit(0);pinsetProperty(k,v); } + static juce::var pinNames(const juce::StringArray& names) { + juce::Array values; + for(const auto& name:names)values.add(name); + return juce::var(values); + } + static bool readPinNames(const juce::var& value,juce::StringArray& names) { + const auto* values=value.getArray(); + if(!values || values->size()>256)return false; + for(const auto& entry:*values) { + juce::String name; + if(!textField(entry,name,256,true))return false; + names.add(name); + } + return true; + } static juce::var ids(const LegacyChannelIds& ids) { auto v=object(); juce::Array in,aux; @@ -270,7 +409,20 @@ class Codec final { set(bind,"outputMask",d.binding.outputMask); set(bind,"rate",d.binding.rate); set(bind,"frames",d.binding.frames); + if(!d.binding.inputNames.isEmpty())set(bind,"inputNames",pinNames(d.binding.inputNames)); + if(!d.binding.outputNames.isEmpty())set(bind,"outputNames",pinNames(d.binding.outputNames)); set(root,"binding",bind); + if(!d.waitingAsioInputs.empty()) { + juce::Array waiting; + for(const auto& pin:d.waitingAsioInputs) { + auto entry=object(); + set(entry,"id",decimal(pin.id.value)); + set(entry,"left",pin.left);set(entry,"right",pin.right); + set(entry,"leftName",pin.leftName);set(entry,"rightName",pin.rightName); + waiting.add(entry); + } + set(root,"waitingAsioInputs",juce::var(waiting)); + } auto output=object(); set(output,"active",d.outputs.activeOutputChannels); set(output,"mainL",d.outputs.mainL);set(output,"mainR",d.outputs.mainR); @@ -363,7 +515,7 @@ class Codec final { doc.savedMs=static_cast(ms); const auto binding=get(root,"binding"); if(!textField(get(binding,"backend"),doc.binding.backend,128)|| - !textField(get(binding,"capture"),doc.binding.capture,256)|| + !textField(get(binding,"capture"),doc.binding.capture,256,true)|| !textField(get(binding,"playback"),doc.binding.playback,256)|| !textField(get(binding,"inputMask"),doc.binding.inputMask,256)|| !textField(get(binding,"outputMask"),doc.binding.outputMask,256)) @@ -373,6 +525,10 @@ class Codec final { doc.binding.rate=n; if(!integral(get(binding,"frames"),doc.binding.frames,16,8192)) return false; + if((binding.getDynamicObject()->hasProperty("inputNames") && + !readPinNames(get(binding,"inputNames"),doc.binding.inputNames)) || + (binding.getDynamicObject()->hasProperty("outputNames") && + !readPinNames(get(binding,"outputNames"),doc.binding.outputNames)))return false; auto outputs=get(root,"outputs"); if(!integral(get(outputs,"active"),doc.outputs.activeOutputChannels,2,256)|| !integral(get(outputs,"mainL"),doc.outputs.mainL,0,255)|| @@ -442,13 +598,19 @@ class Codec final { (doc.legacyIds.monitor.value&&!seek(doc.legacyIds.monitor,ChannelRole::monitor))) return false; auto req=get(root,"request"); - if(!integral(get(req,"physicalInputs"),doc.request.physicalInputs,1,256)|| + if(!integral(get(req,"physicalInputs"),doc.request.physicalInputs,0,256)|| !integral(get(req,"maxFrames"),doc.request.maxFrames,16,8192)|| !strictBool(get(req,"mainMonoAfterFx"),doc.request.mainMonoAfterFx)) return false; const auto sourcesVar=get(req,"sources"); const auto* sources=sourcesVar.getArray(); + // An all-virtual MUSIC session is legitimate even with zero + // connected capture pins. The per-source decoder below still + // rejects EVERY physical ordinal when physicalInputs == 0. if(!sources||sources->size()>channels->size())return false; + if(doc.binding.capture.isEmpty() && + (doc.request.physicalInputs!=0 || doc.binding.inputMask!="0")) + return false; std::set seenSources; for(const auto& src:*sources) { DynamicSourcePatch p; @@ -477,6 +639,22 @@ class Codec final { } doc.request.sources.push_back(p); } + if(root.getDynamicObject()->hasProperty("waitingAsioInputs")) { + const auto waiting=get(root,"waitingAsioInputs"); + const auto* entries=waiting.getArray(); + if(!entries || entries->size()>channels->size() || + !MixerDeviceBindingPolicy::isAsio4All(doc.binding))return false; + for(const auto& entry:*entries) { + WaitingAsioInput pin; + if(!parseDecimal(get(entry,"id"),pin.id.value) || + !seenSources.insert(pin.id.value).second || !seek(pin.id,ChannelRole::input) || + !integral(get(entry,"left"),pin.left,0,255) || + !integral(get(entry,"right"),pin.right,-1,255) || pin.left==pin.right || + !textField(get(entry,"leftName"),pin.leftName,256,true) || + !textField(get(entry,"rightName"),pin.rightName,256,true))return false; + doc.waitingAsioInputs.push_back(std::move(pin)); + } + } const auto fxVar=get(root,"inserts"),racksVar=get(root,"rackBypassed"); const auto* fx=fxVar.getArray(); const auto* racks=racksVar.getArray(); diff --git a/src/NativeMixerSessionFxRestore.h b/src/NativeMixerSessionFxRestore.h index 6fccac16f..c86211b53 100644 --- a/src/NativeMixerSessionFxRestore.h +++ b/src/NativeMixerSessionFxRestore.h @@ -6,6 +6,7 @@ #include "../engine/builtin_fx/ChannelEqProcessor.h" #include "../engine/builtin_fx/ChannelCompressorProcessor.h" #include "../engine/builtin_fx/ChannelHarmonyProcessor.h" +#include "../engine/builtin_fx/VocalThrowProcessor.h" #include #include #include @@ -95,6 +96,16 @@ class NativeMixerSessionFxRestore final { state.bytes.getData(),static_cast(state.bytes.getSize()))) return "Saved native Harmony state rejected; graph unchanged"; processor=std::move(harmony); + } else if(insert.catalogId== + armix::builtin_fx::VocalThrowProcessor::catalogIdentity) { + auto throwFx=std::make_unique(); + throwFx->prepareToPlay(sampleRate,frames); + if(!throwFx->isReady()|| + !throwFx->restoreUnpublishedState( + state.bytes.getData(), + static_cast(state.bytes.getSize()))) + return "Saved native Vocal Throw state rejected; graph unchanged"; + processor=std::move(throwFx); } else { if(!format|| !format->fileMightContainThisPluginType(insert.path)) @@ -116,7 +127,9 @@ class NativeMixerSessionFxRestore final { insert.catalogId!= armix::builtin_fx::ChannelCompressorProcessor::catalogIdentity && insert.catalogId!= - armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity) + armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity && + insert.catalogId!= + armix::builtin_fx::VocalThrowProcessor::catalogIdentity) processor->setStateInformation(state.bytes.getData(), static_cast(state.bytes.getSize())); const int latency=processor->getLatencySamples(); diff --git a/tests/approved_native_cold_start_smoke.py b/tests/approved_native_cold_start_smoke.py index d4053e2c0..91ad872bf 100644 --- a/tests/approved_native_cold_start_smoke.py +++ b/tests/approved_native_cold_start_smoke.py @@ -1,4 +1,4 @@ -"""Real compiled DOM from G0: first drag without OUT priming, first native +"""Real compiled DOM: hide reference G0, first drag without OUT priming, first native FX picker insert on original CH with structural=false, then vendor editor. Backend isolation is emulated; actual latency/sample evidence is CTest. """ @@ -41,6 +41,75 @@ def main(): addEventListener(name,callback){window.__nativeListeners.set(name,callback);}}};""") page.goto((out/'index.html').as_uri()) page.wait_for_function('()=>window.__ARMIX_NATIVE_M2__?.enabled') + # Native Console is ALWAYS visible, even with no callback/device. + # Bridge still rejects unadmitted PCM edits until accepted readback. + assert page.locator('.console-pane').is_visible() + assert not page.evaluate('()=>window.__nativeIntents.length') + # Built-in JUCE DSP must be discoverable before ANY third-party + # VST3 catalog response. The native host never inserts demo FX. + for native_id in ('armix.builtin.channel-eq.v1', + 'armix.builtin.channel-compressor.v1', + 'armix.builtin.arson-harmony.v1'): + assert page.locator('#fastResults [data-fast-id="'+native_id+'"]').count()==1, ( + 'Compiled native FX missing from cold-start picker: '+native_id) + # Output-only playback is a REAL Audio I/O choice, not a hidden + # capture prerequisite. Verify native intent/ACK on the approved + # assembled Windows GUI at every supported viewport. + page.locator('.command-bar [data-native-io]').click() + io_inventory={ + 'types':[{'name':'Windows Audio','separate':True, + 'inputs':['Studio Mic'],'outputs':['Speakers']}], + 'active':{'backend':'Windows Audio','captureDevice':'Studio Mic', + 'playbackDevice':'Speakers','open':True, + 'authorized':True,'deviceGeneration':23, + 'inputNames':['Mic 1'],'outputNames':['L','R'], + 'enabledInputs':[0],'enabledOutputs':[0,1], + 'rate':48000,'buffer':480, + 'rates':[48000],'buffers':[480]}} + emit(page,'arMixAudioDeviceInventory',io_inventory) + capture_select=page.locator('.armix-audio-dialog [data-audio-field="capture"]') + capture_select.select_option(value='') + assert capture_select.input_value()=='' + assert page.locator('.armix-audio-dialog [data-audio-apply]').is_enabled() + page.locator('.armix-audio-dialog [data-audio-apply]').click() + request=page.evaluate("""()=>window.__events.filter(e=> + e.payload?.action==='audioDeviceApply').at(-1)?.payload""") + assert request and request['config']['captureDevice']=='' + assert request['config']['playbackDevice']=='Speakers' + assert request['config']['enabledInputs']==[] + assert request['config']['enabledOutputs']==[] + out_active={**io_inventory['active'],'captureDevice':'', + 'inputNames':[],'enabledInputs':[], + 'outputNames':['WDM L','WDM R','Realtek L','Realtek R']} + emit(page,'arMixAudioDeviceApplyAck',{ + 'requestId':request['requestId'],'ok':True, + 'state':'ACCEPTED_MUTED','active':out_active, + 'outputMuted':True,'mixerBound':True}) + assert page.locator('.armix-audio-shade').is_hidden() + page.locator('.command-bar [data-native-io]').click() + io_inventory['active']=out_active + emit(page,'arMixAudioDeviceInventory',io_inventory) + assert capture_select.input_value()=='' # reopening does not auto-patch a mic + page.locator('.armix-audio-dialog details summary').click() + assign_main=page.locator('[data-audio-main-pins]') + def playback_pin(index): + return page.locator(f'[data-audio-pin="output"][data-pin-index="{index}"]') + playback_pin(0).uncheck() + assert assign_main.is_hidden() + playback_pin(1).uncheck() + playback_pin(2).check() + playback_pin(3).check() + assign_main.click() + repatch=page.evaluate("""()=>window.__events.filter(e=> + e.payload?.action==='audioDeviceApply').at(-1)?.payload""") + assert repatch['config']['assignSelectedPlaybackPinsToMain'] is True + assert repatch['config']['enabledOutputs']==[2,3] + assert repatch['config']['enabledInputs']==[] + emit(page,'arMixAudioDeviceApplyAck',{ + 'requestId':repatch['requestId'],'ok':True, + 'state':'ACCEPTED_MUTED','active':{**out_active,'enabledOutputs':[2,3]}, + 'outputMuted':True,'mixerBound':True}) + assert page.locator('.armix-audio-shade').is_hidden() g0=json.loads((ROOT/'integration/console-v6/fixtures.json').read_text())['g0'] g0['mixerSession']={'authority':'NONE','deviceEpoch':g0['device']['epoch'],'channels':[]} g0['legacyM4']={'active':True,'routeAccepted':False,'routingRevision':'1'} @@ -90,6 +159,9 @@ def show_select(value): emit(page,"arMixNativeSessionAck",{"operation":"OPEN","ok":False,"error":"Invalid mixer JSON"}) assert page.get_by_text("Invalid mixer JSON",exact=True).count()>=1 assert not page.evaluate("()=>window.__events.some(e=>e.payload?.action==='monitor')") + show_click("Test MAIN output") + assert page.evaluate("()=>window.__events.at(-1).payload")=={ + "action":"diagnosticRoute","value":"TOGGLE_MAIN_OUTPUT_TONE"} show_click("Browse Shows") assert page.evaluate("()=>window.__events.at(-1).payload.action")=="routingDryShowList" emit(page,"arMixNativeShowListAck",{"ok":True,"items":[ @@ -124,12 +196,12 @@ def show_select(value): assert page.evaluate("()=>window.__events.at(-1).payload.action")=="routingDryShowList" emit(page,"arMixNativeShowListAck",{"ok":True,"items":[]}) assert not page.evaluate("()=>window.__events.some(e=>e.payload?.action==='monitor')") - if 'collapsed-send' in (page.locator('.console-body').get_attribute('class') or ''): - page.locator('.section-rail [data-section="send"]').click() - # Release before bootstrap SOURCE's later native readback arrives. - drag(page,1,2) + # Failed preflight and an unbound audio device must not blank the + # operator workspace. No unadmitted intent can escape to JUCE. + assert page.locator('.console-pane').is_visible() assert not page.evaluate('()=>window.__nativeIntents.length') state=snapshot() + state['device'].update(enabledInputs=[],inputEndpoints=[]) state['graph']['edges'].pop(1) # genuinely no existing channel send state['graph']['capabilities']['supportedOps'] += ['LOAD_INSERT'] for ident, role, name in [('101','GROUP','Vocal Group'), @@ -142,6 +214,10 @@ def show_select(value): state['legacyM4']={'active':True,'routeAccepted':True,'routingRevision':'77', 'nativeBusStructural':False,'fxInstances':[[] for _ in range(14)]} emit(page,'arMixConsoleSnapshot',state) + page.locator('.console-pane').wait_for(state='visible') + if 'collapsed-send' in (page.locator('.console-body').get_attribute('class') or ''): + page.locator('.section-rail [data-section="send"]').click() + drag(page,1,2) page.wait_for_function('()=>window.__nativeIntents.length===1') route=page.evaluate('()=>window.__nativeIntents[0]') assert route['operation']=='APPLY_WIRE_TRANSACTION' @@ -209,16 +285,16 @@ def show_select(value): channels=copy.deepcopy(retained['graph']['channels'])) emit(page,'arMixConsoleSnapshot',retained) page.wait_for_function('()=>window.__ARMIX_NATIVE_M2__.state().current?.retained') - assert page.locator('.status-bar .warning').inner_text().startswith('NEEDS REMAP') + assert page.locator('.status-bar .warning').inner_text().startswith('PLAYBACK UNAVAILABLE') assert page.locator('[data-native-monitor]').is_disabled() assert add_track.is_disabled() assert page.locator('#tracks .strip').count()==4 - assert 'OUT NEEDS REMAP' in page.locator('#transport').inner_text() + assert 'OUTPUT WAITING FOR DEVICE' in page.locator('#transport').inner_text() page.locator('#tracks .strip[data-id="1"] .wire-node-out').click() emit(page,'arMixConsoleSnapshot',retained) assert page.locator('#tracks .strip[data-id="2"] .wire-gain').is_disabled() strip=page.locator('#tracks .strip[data-id="1"]') - assert strip.locator('select[data-field="input"]').input_value()=='NEEDS REMAP' + assert strip.locator('select[data-field="input"]').input_value()=='Waiting for device' assert strip.locator('.fx-section [data-action="openPlugin"]').first.inner_text()=='Latency VST' before=page.evaluate('()=>window.__events.filter(e=>e.payload?.action==="routingFxEditor").length') strip.locator('.fx-section [data-action="openPlugin"]').first.click() @@ -249,7 +325,8 @@ def show_select(value): 'state':'ACCEPTED_LIVE','active':active,'mixerBound':True,'outputMuted':False}) assert page.locator('.armix-audio-shade').is_hidden() rebound=copy.deepcopy(state) - rebound['device'].update(epoch='93',outputArmed=True) + rebound['device'].update(epoch='93',outputArmed=True, + enabledInputs=g0['device']['enabledInputs'],inputEndpoints=g0['device']['inputEndpoints']) rebound['graph']['revision']='6' rebound['graph']['capabilities']['supportedOps'].append('CREATE_CHANNEL') rebound['mixerSession'].update(deviceEpoch='93',routeRevision='6') diff --git a/tests/approved_native_gui_bundle_test.py b/tests/approved_native_gui_bundle_test.py index 4ad0188bf..b770ba045 100644 --- a/tests/approved_native_gui_bundle_test.py +++ b/tests/approved_native_gui_bundle_test.py @@ -24,6 +24,10 @@ def test_native_is_exact_assembled_public_pages_plus_nonvisual_native_seam(self) self.assertEqual(bundle.public_from_native(native), approved) self.assertNotIn("__ARMIX_NATIVE_M2__", approved) self.assertIn("__ARMIX_NATIVE_M2__", native) + # Never let a missing ASIO driver or delayed native snapshot + # hide the entire mixer. Readback controls remain separately gated. + self.assertNotIn('id="native-mixer-startup"', native) + self.assertNotIn('html:not([data-armix-native-roster]) :is(.console-pane,#trackCount){visibility:hidden}', native) # M3 native-only scope is embedded inside the existing Pages IIFE: # no visual duplication; it must be stripped in public_from_native. self.assertIn("window.__ARMIX_NATIVE_SCOPE__=Object.freeze({", native) diff --git a/tests/approved_native_harmony_smoke.py b/tests/approved_native_harmony_smoke.py index 32aeb3249..3d50d7014 100644 --- a/tests/approved_native_harmony_smoke.py +++ b/tests/approved_native_harmony_smoke.py @@ -25,15 +25,15 @@ def last_action(page,kind): return actions[-1] def readback(page,state,values,key,scale,detected=(-1,-1),applied=None, - request=None): + request=None,instance=INSTANCE,observed=-1): action=request or last_action(page,"nativeHarmonySnapshot") packet={ "requestId":action["requestId"], - "channelId":SOURCE,"instanceId":INSTANCE,"status":"ACCEPTED", + "channelId":SOURCE,"instanceId":instance,"status":"ACCEPTED", "deviceEpoch":state["device"]["epoch"], "graphRevision":state["graph"]["revision"], "schemaVersion":2,"sampleRate":48000,"latencySamples":1536, - "settings":copy.deepcopy(values),"observedNote":-1, + "settings":copy.deepcopy(values),"observedNote":observed, "guideDetectedKey":detected[0],"guideDetectedScale":detected[1], "guideConfidence":0.75 if detected[0]>=0 else 0.0, "effectiveKey":key,"effectiveScale":scale, @@ -104,7 +104,8 @@ def main(): # Native LCD must not fabricate manual/detected effective key # until the exact instance-scoped DSP snapshot arrives. assert page.locator("#mxHKeyReadout").inner_text()=="—" - readback(page,state,DEFAULT,0,0) + readback(page,state,DEFAULT,0,0,observed=57) + assert page.locator("#mxHTracking").inner_text()=="TRACKING A3" assert page.locator("#mxHKeyReadout").inner_text()=="C" assert page.locator("#mxHGuideStatus").inner_text()=="MANUAL" assert page.locator("#mxHSourcePicker").is_hidden() @@ -158,9 +159,14 @@ def main(): assert manual["settings"]["guideMode"]==0 assert manual["settings"]["guideChannelId"]=="0" assert page.locator("#mxHKeyReadout").inner_text()=="Am" + assert "AWAITING DSP ACK" in page.locator("#mxHStatus").inner_text() + assert "queued" in (page.locator( + '.mx-harm-note[data-key="7"]').get_attribute("class") or "") locked={**DEFAULT,"key":7} apply_edit(page,state,locked,7,0) assert page.locator("#mxHKeyReadout").inner_text()=="G" + assert "queued" not in (page.locator( + '.mx-harm-note[data-key="7"]').get_attribute("class") or "") assert page.locator("#mxHGuideStatus").inner_text()=="MANUAL" assert page.locator("#mxHSourcePicker").is_hidden() # G is a literal circle, subtly larger than unselected notes. @@ -296,7 +302,161 @@ def face_metrics(locator): readback(page,state,selected,9,1,detected=(9,1), request=old_poll) assert page.locator("#mxHKeyReadout").inner_text()=="G" + # Manual Key also observes audio-owner tracking on existing + # console ticks. Never infer singing from a UI button state. + # The preceding bypass-readback tests may have left ONE + # outstanding (throttled) snapshot request. Complete it as + # native JUCE would, rather than asserting a second request + # within the in-flight 2500ms readback fence. + latest_snap=last_action(page,"nativeHarmonySnapshot") + readback(page,state,values,7,0,request=latest_snap) + before=len(page.evaluate( + "()=>window.__actions.filter(x=>x.action==='nativeHarmonySnapshot')")) + # Native host produces ~12 console ticks per second, not one + # artificially selected 530ms tick after an arbitrary prior + # music readback. Exercise the real tick cadence for 2s. + # A single tick may legitimately be coalesced or queued. + after=before + for _ in range(24): + emit(page,"arMixConsoleSnapshot",state) + after=len(page.evaluate( + "()=>window.__actions.filter(x=>x.action==='nativeHarmonySnapshot')")) + if after>before:break + page.wait_for_timeout(85) + assert after>before,("no Manual Key native tracking poll", + page.locator("#mxHStatus").inner_text(), + page.locator("#mxHTracking").inner_text()) + monitor=last_action(page,"nativeHarmonySnapshot") + readback(page,state,changed,7,0,request=monitor,observed=60) + assert page.locator("#mxHTracking").inner_text()=="TRACKING C4" + # Reproduce the field screenshot: singer DSP continues playing + # while a native device/graph revision changes under an open + # Harmony editor. It MUST auto-rebind; no user reopen/wizard. + if width==1366: + accepted={**changed,"voices":5} + def push_graph(): + state["mixerSession"]["channels"]=copy.deepcopy( + state["graph"]["channels"]) + emit(page,"arMixConsoleSnapshot",state) + def bump(): + graph=state["graph"] + graph["revision"]=str(int(graph["revision"])+1) + def await_snap(instance,slot): + page.wait_for_function("""arg=>window.__actions.some(x=> + x.action==='nativeHarmonySnapshot' && + x.graphRevision===arg.revision && + x.instanceId===arg.instance && x.slot===arg.slot)""", + arg={"revision":state["graph"]["revision"], + "instance":instance,"slot":slot}) + result=last_action(page,"nativeHarmonySnapshot") + assert result["instanceId"]==instance,result + assert result["slot"]==slot,result + bump();push_graph() + await_snap(INSTANCE,0) + assert "REOPEN" not in page.locator("#mxHStatus").inner_text() + readback(page,state,accepted,7,0) + page.locator('[data-voices="4"]').click() + write=last_action(page,"nativeHarmonySetSettings") + assert write["graphRevision"]==state["graph"]["revision"] + accepted={**accepted,"voices":4} + apply_edit(page,state,accepted,7,0) + + # Recreated *same-channel* FX instance; stale ACKs cannot + # commit controls or paint a previous DSP identity. + successor="harmony-native-recreated" + bump() + state["graph"]["channels"][0]["inserts"][0]["id"]=successor + push_graph() + await_snap(successor,0) + emit(page,"arMixBuiltinHarmonyAck", + {"requestId":write["requestId"],"status":"APPLIED"}) + readback(page,state,DEFAULT,0,0,instance=successor) + assert page.locator("#mxHKeyReadout").inner_text()=="C" + page.locator('[data-key="9"]').click() + new_write=last_action(page,"nativeHarmonySetSettings") + assert new_write["instanceId"]==successor + assert new_write["channelId"]==SOURCE + assert new_write["settings"]["key"]==9 + emit(page,"arMixBuiltinHarmonyQueue", + {"requestId":new_write["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinHarmonyAck", + {"requestId":new_write["requestId"],"status":"APPLIED"}) + accepted={**DEFAULT,"key":9} + readback(page,state,accepted,9,0, + applied=new_write["requestId"],instance=successor) + assert page.locator("#mxHKeyReadout").inner_text()=="A" + + # Exact same insert identity follows an FX reorder, and + # subsequent edits use NEW accepted slot (not old index). + bump() + other={"id":"eq-accepted-other","catalogId": + "armix.builtin.channel-eq.v1","name":"EQ", + "bypassed":False} + harmony=copy.deepcopy(state["graph"]["channels"][0]["inserts"][0]) + state["graph"]["channels"][0]["inserts"]=[other,harmony] + push_graph() + await_snap(successor,1) + readback(page,state,accepted,9,0,instance=successor) + page.locator('[data-voices="5"]').click() + moving=last_action(page,"nativeHarmonySetSettings") + assert moving["slot"]==1 and moving["instanceId"]==successor + emit(page,"arMixBuiltinHarmonyQueue", + {"requestId":moving["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinHarmonyAck", + {"requestId":moving["requestId"],"status":"APPLIED"}) + accepted={**accepted,"voices":5} + readback(page,state,accepted,9,0, + applied=moving["requestId"],instance=successor) + + # A temporarily unpublished FX must NOT accept stale + # gestures. Hold the latest edit and apply only after + # a fresh accepted instance-scoped DSP readback. + bump();state["graph"]["channels"][0]["inserts"]=[other] + push_graph() + page.wait_for_function("""()=>document.querySelector( + '#mxHStatus').textContent.includes('RECONNECTING')""") + before=len(page.evaluate("""()=>window.__actions.filter( + x=>x.action==='nativeHarmonySetSettings')""")) + page.locator('[data-voices="3"]').click() + after=len(page.evaluate("""()=>window.__actions.filter( + x=>x.action==='nativeHarmonySetSettings')""")) + assert before==after,"stale FX received an edit" + bump();state["graph"]["channels"][0]["inserts"]=[other,harmony] + push_graph();await_snap(successor,1) + readback(page,state,accepted,9,0,instance=successor) + resumed=last_action(page,"nativeHarmonySetSettings") + assert resumed["slot"]==1 and resumed["instanceId"]==successor + assert resumed["settings"]["voices"]==3,resumed + emit(page,"arMixBuiltinHarmonyQueue", + {"requestId":resumed["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinHarmonyAck", + {"requestId":resumed["requestId"],"status":"APPLIED"}) + accepted={**accepted,"voices":3} + readback(page,state,accepted,9,0, + applied=resumed["requestId"],instance=successor) + assert page.locator('#mxHStatus').inner_text().startswith("NATIVE") + assert "FX 2" in page.locator("#mxHChannel").inner_text() assert not errors,errors + # The knob's lit pseudo-ring extends 11px past its face. + # Test real layout, not only CSS text, at every viewport. + dial_geometry=page.evaluate("""()=>[...document.querySelectorAll( + '#mxNativeHarmony .mx-harm-slider')].map(s=>{ + const f=s.querySelector('.mx-harm-dial-face').getBoundingClientRect(); + const c=s.querySelector('.mx-harm-dial-label').getBoundingClientRect(); + const o=s.querySelector('output').getBoundingClientRect(); + return {gap:c.top-f.bottom,labelBottom:c.bottom,outputTop:o.top, + faceTop:f.top,outputBottom:o.bottom}; + })""") + assert len(dial_geometry)==4,dial_geometry + for geom in dial_geometry: + assert geom["gap"]>=12.0,("caption overlaps halo",width,geom) + assert geom["outputTop"]>=geom["labelBottom"]-0.5,( + "caption/value collision",width,geom) + # Check spacing between rows as well as each knob. + # The next luminous ring reaches 11px above its face. + for upper,lower in zip(dial_geometry[:2],dial_geometry[2:]): + assert upper["outputBottom"]+2<=lower["faceTop"]-11,( + "next-row halo collides with upper value",width,upper,lower) rect=editor.bounding_box() assert rect and rect["width"]<=width+1,(width,rect) assert rect["x"]>=0 and rect["x"]+rect["width"]<=width+1,rect diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 31f2539ef..3f9061392 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -381,7 +381,10 @@ test("P0 first Add FX discovers real local VST3 lazily without an audio-thread s assert.match(bridge,/discoverFxOnFirstPickerOpen\(\);[\s\S]*?scope\?\.openFastPicker/); assert.match(native,/action == "scanVst3"[\s\S]*?catalog_\.scanDefaults\(\)/); assert.match(catalog,/struct Scanner final : juce::Thread/); - assert.match(bridge,/scope\?\.setNativeCatalog\?\.\(\[\.\.\.nativeCatalog\.values\(\)\]\)/); + // The approved picker publishes real compiled-in FX independently of + // external scanner state; the verified VST3 library follows those entries. + assert.match(bridge,/const presentFxCatalog=\(\)=>scope\?\.setNativeCatalog\?\.\(/); + assert.ok(bridge.includes('[...nativeBuiltins,...nativeCatalog.values()]')); // Neither startup nor audio callback can trigger a surprise system scan. assert.doesNotMatch(bridge.slice(0,bridge.indexOf("function discoverFxOnFirstPickerOpen")), /action:"scanVst3"/); @@ -563,7 +566,8 @@ test("P0 WIRE-to-MAIN and channel OUT use one acknowledged native transaction",( assert.match(native,/engine_\.repatchDryRoutingLabChannel\(channel,/); assert.match(bridge,/scope\?\.closeNativePicker\?\.\(\)/); assert.match(builder,/closeNativePicker\(\)\{setFastPicker\(false\);\}/); - assert.match(builder,/NATIVE JUCE VST3/); + assert.match(builder,/Native EQ\/Compressor\/Harmony ready/); + assert.match(builder,/external VST3 require verified scan/); assert.doesNotMatch(bridge,/AudioContext|AudioWorklet/); }); test("P0 typed mono-stereo, PAN detent, fader geometry & FX failure diagnostics",()=>{ @@ -703,7 +707,7 @@ test("P0 same-VB-Cable feedback is blocked before native MAIN arm",()=>{ assert.match(engine,/MONITOR OFF: VB-Cable capture\/playback self-loop/); assert.match(bridge,/const virtualCableFeedbackPair=/); const native=read("src/Main.cpp"); - assert.match(native,/if\(engine_\.liveOutputArmFault\(\)\.isNotEmpty\(\)\)return;/); + assert.match(native,/if\(engine_\.liveOutputArmFault\(autoMainRequiresInput_\)\.isNotEmpty\(\)\)return;/); assert.match(native,/autoMainEpoch_!=engine_\.dryRoutingLabEpoch\(\)/); }); test("single /preview/ GUI: channel IN, actual OUT and correlated device safety ACK",()=>{ @@ -1238,15 +1242,67 @@ test("P0 native FX rack and per-slot readback update mounted strip without repla assert.equal(paints,2,"an actual VST instance identity change MUST re-project"); }); +test("P0 automatic cold-start Show replaces only pristine SOURCE NONE ChannelId",()=>{ + const main=read('src/Main.cpp'); + const engine=read('src/LiveAudioEngine.h'); + const route=read('src/LiveDryRoutingLab.h'); + assert.match(main,/nativeAlreadyActive && !retained &&/); + assert.match(main,/\(startupOnSavedDevice \|\| recoveringAfterDeviceApply\) &&/); + assert.match(main,/recoveringAfterDeviceApply=bindingMode!=MixerBindingMode::exact &&\s*mixerSessionRecoveryPending_/); + assert.match(main,/!usedPrevious && !retained/); // only normal auto-resume, not recovery admission + assert.match(main,/engine_\.hasPristineStartupMixer\(\)/); + assert.match(main,/restoreNativeMixerSession\(std::move\(doc\),states,\s*replacePristineStartup/); + assert.match(engine,/dryRoutingLab_\.canReplacePristineStartupMixer\(\)/); + assert.match(route,/bool canReplacePristineStartupMixer\(\) const noexcept/); + assert.match(route,/!nativeControlDirty_ && nativeAccepted_\.fxOwners/); +}); + test("P0 startup banner never demands legacy Patch CH1 / Arm wizard",()=>{ const bridge=read("web/approved-native-bridge.js"); assert.match(bridge,/SELECT CHANNEL IN · NATIVE MONITOR AFTER ACK/); - assert.match(bridge,/NO CAPTURE INPUT · OPEN AUDIO I\/O/); + assert.match(bridge,/next.admitted\?"CHOOSE AN INPUT"/); + assert.doesNotMatch(bridge,/FAT PENDING/); + assert.doesNotMatch(bridge,/hardware\.device\.enabledInputs\.length>0/); assert.match(bridge,/NO VERIFIED INPUT ROUTE · OPEN AUDIO I\/O/); assert.doesNotMatch(bridge,/NO AUDIBLE OUTPUT · PATCH INPUT \+ ARM/); assert.match(bridge,/const preparedFirstSound=session\?\.authority==="NONE"/); assert.match(bridge,/const deviceReady=\(\)=>/); }); +test("P0 native built-in FX appear before vendor scan and remain after catalog refresh",()=>{ + const bridge=read("web/approved-native-bridge.js"); + const builder=read("scripts/build_approved_native_gui.py"); + for(const id of ["armix.builtin.channel-eq.v1", + "armix.builtin.channel-compressor.v1", + "armix.builtin.arson-harmony.v1"]) + assert.ok(bridge.includes('id:"'+id+'"')); + assert.ok(bridge.includes('[...nativeBuiltins,...nativeCatalog.values()]')); + assert.ok(bridge.includes('presentFxCatalog(); // compiled native FX')); + assert.ok(builder.includes("x.format==='Native'?'Native':'VST3'")); + assert.ok(!bridge.includes('scope?.setNativeCatalog?.([])')); +}); +test("P0 built-in EQ/Compressor/Harmony load independent of slow external VST3 catalog scan",()=>{ + const cpp=read("src/Main.cpp"); + const gate=cpp.slice(cpp.indexOf('const bool builtInEq=catalogId=='), + cpp.indexOf('const auto result=builtInEq?',cpp.indexOf('const bool builtInEq=catalogId=='))); + assert.ok(gate.includes('const bool externalCatalog=!builtInEq&&!builtInComp&&!builtInHarmony')); + assert.ok(gate.includes('externalCatalog&&(!plugin||catalog_.busy())')); + assert.ok(!gate.includes('||catalog_.busy()||nativeShowBusy_'), + 'third-party metadata discovery must not disable compiled-in FX'); + assert.ok(gate.includes('nativeShowBusy_')&&gate.includes('studioBackupBusy_'), + 'native structural session/backup safety interlocks remain active'); +}); +test("P0 output-only Audio I/O is a real native configuration, never blocked by missing capture",()=>{ + const cpp=read("src/Main.cpp"),bridge=read("web/approved-native-bridge.js"); + assert.match(cpp,/const bool outputOnly=separate&&capture\.isEmpty\(\)/); + assert.match(cpp,/candidate\.useDefaultInputChannels=!outputOnly/); + assert.match(cpp,/if\(outputOnly\)candidate\.inputChannels\.clear\(\)/); + assert.match(cpp,/\(outputOnly&&!inMask\.isZero\(\)\)/); + assert.doesNotMatch(cpp,/opened->getActiveInputChannels\(\)\.countNumberOfSetBits\(\)<1/); + assert.match(bridge,/No hardware input \(Player \/ FX\)/); + assert.match(bridge,/t\?\.separate\?\["",\.\.\.\(t\.inputs\|\|\[\]\)\]/); + assert.doesNotMatch(bridge,/ack\.active\.enabledInputs\.length>0/); + assert.match(bridge,/FX\/WIRE available/); +}); test("P0 FIRST SOUND G0 offers verified input and leaves automatic MAIN to native",()=>{ const vm=require("node:vm"),sent=[],listeners=new Map(),renderedChoices=[]; let win; @@ -1440,8 +1496,8 @@ test("native Windows operator can explicitly patch first physical input, arm and assert.match(js,/if\(ack\.ok===true\)/); assert.match(js,/NATIVE PATCH REJECTED:/); assert.match(js,/NO VERIFIED AUDIO DEVICE/); - assert.match(js,/NATIVE PCM · HARDWARE FAT PENDING/); - assert.match(js,/MAIN MONITOR ON · PCM ADMISSION NOT VERIFIED/); + assert.doesNotMatch(js,/FAT PENDING/); + assert.match(js,/CHECK AUDIO CONNECTION/); assert.match(main,/action=="routingSourceSwitch"/); assert.match(main,/engine_\.liveOutputArmFault\(\)/); assert.match(main,/safe->emitApprovedNativeSnapshot\(\)/); diff --git a/tests/approved_native_v8_projection_test.cpp b/tests/approved_native_v8_projection_test.cpp index dced419c2..576c4386a 100644 --- a/tests/approved_native_v8_projection_test.cpp +++ b/tests/approved_native_v8_projection_test.cpp @@ -637,6 +637,11 @@ static void installedCallbackAdmissionRegression(const juce::var& rawBus) { =="9007199254740993"); assert(std::abs(static_cast(session.getProperty("main",{}) .getProperty("db",0.))-(-13.5))<0.00001); + // The installed graph remains editable with playback and no capture pins. + dev.getDynamicObject()->setProperty("enabledInputs",juce::var(juce::Array{})); + assert(projectInstalledNativeChannelIdGraph(snap,live)); + publishAuthoritativeMixerSession(snap); + assert(snap.getProperty("mixerSession",{}).getProperty("authority","").toString()=="CHANNEL_ID"); // Real restart: lab routing epoch counts STOP+START, unlike M2 // deviceStartCount. This G0-to-native authority switch must advance. auto disconnected=canonicalSnapshot(); @@ -826,7 +831,18 @@ static void firstSoundRouteAdmissionRegression() { auto withoutInput=juce::JSON::parse(juce::JSON::toString(snapshot,false)); withoutInput.getProperty("device",{}).getDynamicObject() ->setProperty("enabledInputs",juce::var(juce::Array{})); - assert(!publishVerifiedFirstSoundState(withoutInput,live)); + assert(publishVerifiedFirstSoundState(withoutInput,live)); + assert(withoutInput.getProperty("legacyM4",{}) + .getProperty("channels",{}).getArray()->isEmpty()); // stale MONO mapping rejected + auto noCaptureRoute=juce::JSON::parse(juce::JSON::toString(live,false)); + auto noCaptureRows=noCaptureRoute.getProperty("dryRoutingLab",{}) + .getProperty("acceptedRoute",{}).getProperty("channels",{}); + auto* unpatched=noCaptureRows[4].getDynamicObject(); + unpatched->setProperty("mode","NONE"); + unpatched->setProperty("left",-1); + assert(publishVerifiedFirstSoundState(withoutInput,noCaptureRoute)); + assert(withoutInput.getProperty("legacyM4",{}) + .getProperty("channels",{}).getArray()->size()==10); } // Control-only fixture: validates exclusive M4 session normalization, diff --git a/tests/approved_native_vocal_throw_smoke.py b/tests/approved_native_vocal_throw_smoke.py new file mode 100644 index 000000000..94dd89676 --- /dev/null +++ b/tests/approved_native_vocal_throw_smoke.py @@ -0,0 +1,373 @@ +"""Real approved /preview/ bundle: ArSon Vocal Throw picker, insert, native ACK. +The JUCE event transport is emulated, NOT the native DSP nor singing quality. +DSP is independently tested in standalone CTest on Windows.""" +import base64 +import copy +import xml.etree.ElementTree as ET +import importlib.util +from pathlib import Path +import tempfile +from playwright.sync_api import sync_playwright +from approved_native_wire_gain_smoke import snapshot, emit, ack, SOURCE, RECEIVER + +ROOT=Path(__file__).resolve().parents[1] +ID="armix.builtin.vocal-throw.v1" +INSTANCE="vocal-throw-test-instance" +DEFAULTS={"mode":2,"bpm":120,"division":0,"repeats":3, + "captureMs":460,"silenceMs":220,"thresholdDb":-35, + "wet":.42,"decay":.55,"ducking":.7} + +def last(page,action): + records=page.evaluate("name=>window.__actions.filter(x=>x.action===name)",action) + assert records, "No "+action+" event" + return records[-1] + +def reply_snapshot(page,state,settings,applied=None,count=0,tail=False,music=None): + act=last(page,"nativeThrowSnapshot") + data={"requestId":act["requestId"],"channelId":SOURCE,"slot":0, + "instanceId":INSTANCE,"status":"ACCEPTED","schemaVersion":1, + "deviceEpoch":state["device"]["epoch"], + "graphRevision":state["graph"]["revision"],"sampleRate":48000, + "addedLatencySamples":0,"throwCount":count,"tailActive":tail, + "musicSourceChannelId":music["source"] if music else "0", + "musicSourceActive":bool(music), + "musicLocked":bool(music), + "musicBpm":music["bpm"] if music else 0, + "musicConfidence":music["confidence"] if music else 0, + "musicGridAvailable":music.get("grid",False) if music else False, + "musicPhaseConfidence":music["confidence"] if music and music.get("grid",False) else 0, + "settings":copy.deepcopy(settings)} + if applied:data["appliedRequestId"]=applied + emit(page,"arMixBuiltinThrowSnapshot",data) + +def main(): + spec=importlib.util.spec_from_file_location( + "bundle",ROOT/"scripts/build_approved_native_gui.py") + bundle=importlib.util.module_from_spec(spec);spec.loader.exec_module(bundle) + # Owner-provided purple illuminated hardware button (tombol_ungu.svg). + # Fail closed on a missing/rasterized asset or an unsafe remote image href. + source_svg=(ROOT/"site/preview-v2/assets/arson-vocal-throw-performance.svg").read_text() + assert 'viewBox="0 0 327 327"' in source_svg + assert '10000, "do not replace premium artwork with a low-detail icon" + assert not any(v.startswith(('http:', 'https:', 'file:')) + for el in root.iter() for k,v in el.attrib.items() if k.endswith('href')) + assert '_Linear6' in source_svg and '_Linear7' in source_svg + with tempfile.TemporaryDirectory(prefix="armix-throw-") as directory,sync_playwright() as pw: + out=Path(directory);bundle.stage(out) + browser=pw.chromium.launch(headless=True) + # Desktop, constrained desktop and portrait operator control panel. + for width,height in [(1366,768),(650,720),(390,844)]: + page=browser.new_page(viewport={"width":width,"height":height}) + errors=[] + page.on("pageerror",lambda e:errors.append(str(e))) + page.add_init_script("""window.__nativeListeners=new Map(); + window.__nativeIntents=[];window.__actions=[]; + window.__JUCE__={backend:{ + emitEvent(name,payload){ + if(name==='arMixConsoleIntent')window.__nativeIntents.push(payload); + if(name==='arMixAction')window.__actions.push(payload);}, + addEventListener(name,callback){ + const old=window.__nativeListeners.get(name); + window.__nativeListeners.set(name,old? + payload=>{old(payload);callback(payload);}:callback);}}};""") + page.goto((out/"index.html").as_uri()) + page.wait_for_function("()=>window.__ARMIX_NATIVE_M2__?.enabled && window.ArSonMixNativeVocalThrow") + state=snapshot() + state["graph"]["capabilities"]["supportedOps"]+=["LOAD_INSERT","REMOVE_INSERT","MOVE_INSERT"] + emit(page,"arMixConsoleSnapshot",state) + if width<=500:page.locator("#bankSelect").select_option("0") + strip=page.locator('#tracks .strip[data-id="1"]') + strip.locator('.fx-pick.empty').first.click() + picker=page.locator("#fastResults [data-fast-native-throw]") + picker.wait_for(state="visible") + assert picker.count()==1,"exactly one Vocal Throw built-in picker option" + picker.click() + intents=page.evaluate("""()=>window.__nativeIntents.filter( + x=>x.operation==='LOAD_INSERT')""") + assert len(intents)==1,intents + assert intents[0]["payload"]["catalogId"]==ID + assert page.locator("#mxNativeVocalThrow").is_hidden(),"no editor before accepted insert" + state["graph"].update(revision="3",rosterRevision="3") + state["graph"]["channels"][0]["fxRackBypassed"]=False + state["graph"]["channels"][0]["inserts"].append({ + "id":INSTANCE,"catalogId":ID,"name":"ArSon Vocal Throw","bypassed":False}) + state["mixerSession"].update(routeRevision="3",rosterRevision="3", + channels=copy.deepcopy(state["graph"]["channels"])) + ack(page,state,intents[0]);emit(page,"arMixConsoleSnapshot",state) + row=strip.locator('.fxslot-row[data-insert-id="'+INSTANCE+'"]') + row.wait_for(state="visible") + page.keyboard.press("Escape") + row.locator('[data-action="openPlugin"]').click() + editor=page.locator("#mxNativeVocalThrow") + editor.wait_for(state="visible") + assert editor.locator("#vtPreset").count()==1 + assert editor.locator("#vtClose.vt-close.armix-floating-close").count()==1 + assert editor.locator("#vtPower.vt-power.armix-builtin-fx-power").count()==1 + assert editor.locator("#vtClose.armix-builtin-fx-close").count()==1 + # The shared chrome class is safe, a Compressor-specific + # selector is not: it must match exactly the Compressor editor. + assert page.locator(".mx-comp-close").count()==1 + assert page.locator(".mx-comp-power").count()==1 + assert page.locator("#mxNativePeq .armix-builtin-fx-power").count()==1 + assert page.locator("#mxNativePeq .armix-builtin-fx-close").count()==1 + assert page.locator("#mxNativeComp .armix-builtin-fx-power").count()==1 + assert page.locator("#mxNativeComp .armix-builtin-fx-close").count()==1 + assert editor.locator("#vtPower").get_attribute("data-fx-state")=="on" + assert editor.locator("#vtPower").get_attribute("aria-pressed")=="true" + # EQ and Compressor have ONE CSS owner for 24px Close and 26px + # Power hit boxes, the same as Vocal Throw (no local overrides). + close_box=editor.locator("#vtClose").bounding_box() + power_box=editor.locator("#vtPower").bounding_box() + assert close_box and power_box + assert abs(close_box["width"]-24)<.1 and abs(close_box["height"]-24)<.1 + assert abs(power_box["width"]-26)<.1 and abs(power_box["height"]-24)<.1 + assert power_box["x"]+power_box["width"]<=close_box["x"]+1 + assert editor.locator("#vtMode").input_value()=="2" + initial=last(page,"nativeThrowSnapshot") + page.wait_for_timeout(300) + assert last(page,"nativeThrowSnapshot")["requestId"]==initial["requestId"],\ + "snapshot polling overwrote outstanding request too early" + reply_snapshot(page,state,DEFAULTS) + assert editor.locator("#vtStatus").inner_text()=="LIVE" + assert editor.locator("#vtCount").inner_text()=="0" + box=editor.bounding_box() + assert box and box["width"]<=778 and box["width"]<=width and \ + box["x"]>=0 and box["x"]+box["width"]<=width+1,(width,box) + assert editor.evaluate("(el)=>el.scrollWidth<=el.clientWidth+1"),\ + "premium FX editor overflows horizontal viewport" + assert editor.locator("#vtDisplayBpm").inner_text()=="120" + assert editor.locator("#vtClockLabel").inner_text()=="MAN" + # BPM is one integrated LCD number, not a detached duplicate. + # Click the LCD to enter editing; Escape restores the accepted + # native setting without issuing a new DSP command. + assert editor.locator("#vtBpm").is_hidden() + editor.locator("#vtDisplayBpm").click() + assert editor.locator("#vtBpm").is_visible() + assert editor.locator("#vtBpm").input_value()=="120" + editor.locator("#vtBpm").fill("133") + editor.locator("#vtBpm").press("Escape") + assert editor.locator("#vtBpm").is_hidden() + assert editor.locator("#vtDisplayBpm").inner_text()=="120" + assert editor.locator("#vtBeatRail i[data-on='true']").count()==3 + assert editor.locator(".vt-encoder-bank .vt-encoder-face").count()==6 + assert editor.locator("#vtWetDial[role='slider']").count()==1 + assert editor.locator(".vt-throw-button").count()==1 + trigger=editor.locator("#vtThrow") + assert trigger.get_attribute("aria-label")=="Throw captured vocal phrase" + assert trigger.inner_text().strip()=="","Singer cue has no noisy visible words" + tb=trigger.bounding_box() + assert tb and tb["width"]>=160 and tb["height"]>=160 + assert editor.locator(".vt-throw-engraving").inner_text()=="THROW" + assert editor.locator("#vtTap").is_visible() + assert editor.locator("#vtMusicStatus").inner_text()=="TAP" + assert "FIRE PHRASE" not in editor.inner_text() + assert "SMART PHRASE / LIVE ENGINE" not in editor.inner_text() + assert "ZERO DRY LATENCY" not in editor.inner_text() + assert editor.locator(".vt-mode-buttons button").count()==3 + assert editor.locator(".vt-division-buttons button").count()==4 + # No browser form hiding of basic parameters: real accessible + # hardware rotary controls are displayed at desktop AND mobile. + assert editor.locator("#vtWetDial").is_visible() + assert editor.locator('.vt-encoder[data-key="captureMs"] button').is_visible() + # Every control, including MIX, has the exact SAME stationary + # knob body, pointer and rounded level arc geometry. + assert editor.locator(".vt-encoder-face").count()==7 + assert editor.locator(".vt-meter-fill").count()==7 + assert editor.locator(".vt-knob-meter").count()==7 + for dial in editor.locator(".vt-encoder-face").all(): + bg=dial.evaluate("(el)=>getComputedStyle(el).backgroundImage") + assert "arson-vocal-hardware-encoder.svg" in bg,bg + assert dial.locator(".vt-meter-fill").get_attribute("pathLength")=="100" + # Inspect the actual rendered SVG control backgrounds. WebView + # file:// disables fetch() for SVG files, not CSS backgrounds. + for selector,name in [("#vtWetDial","encoder"), + ('.vt-encoder-face',"encoder"), + ("#vtThrow","performance")]: + bg=editor.locator(selector).first.evaluate( + "(el)=>getComputedStyle(el).backgroundImage") + assert ("arson-vocal-throw-performance.svg" if name=="performance" + else "arson-vocal-hardware-"+name+".svg") in bg,(selector,bg) + # Bounded physical layout QA, not just a screenshot. The large + # singer switch must be centered, the two encoder banks in + # alignment, and tempo LCD and TAP must be physically adjacent. + throw=editor.locator("#vtThrow").bounding_box() + left=editor.locator("#vtEncodersLeft").bounding_box() + right=editor.locator("#vtEncodersRight").bounding_box() + lcd=editor.locator(".vt-clock-screen").bounding_box() + tap=editor.locator("#vtTap").bounding_box() + assert all([throw,left,right,lcd,tap]) + assert abs((throw["x"]+throw["width"]/2)-(box["x"]+box["width"]/2))<4, \ + ("THROW is off center",width,throw,box) + if width>600: + assert abs(left["y"]-right["y"])<3, ("uneven encoder rows",left,right) + assert left["x"]+left["width"]<=throw["x"]+1 and \ + throw["x"]+throw["width"]<=right["x"]+1, \ + ("encoders invade singer button",left,throw,right) + else: + assert throw["y"]+throw["height"]=145 and lcd["height"]>=70 + # Text must have a real cell, not be squeezed against a knob. + # Three columns in each bank share exact name/rotary/value + # baselines; this caught the original tiny asymmetric 8px text. + for bank in ("#vtEncodersLeft","#vtEncodersRight"): + names=editor.locator(bank+" .vt-encoder-name") + dials=editor.locator(bank+" .vt-encoder-face") + values=editor.locator(bank+" .vt-encoder-value") + assert names.count()==dials.count()==values.count()==3 + labels=[el.bounding_box() for el in names.all()] + knobs=[el.bounding_box() for el in dials.all()] + nums=[el.bounding_box() for el in values.all()] + assert max(x["y"] for x in labels)-min(x["y"] for x in labels)<1 + assert max(x["y"] for x in knobs)-min(x["y"] for x in knobs)<1 + assert max(x["y"] for x in nums)-min(x["y"] for x in nums)<1 + for n,k,v in zip(labels,knobs,nums): + center=lambda b:b["x"]+b["width"]/2 + assert abs(center(n)-center(k))<1.5 and \ + abs(center(v)-center(k))<1.5, \ + ("rotary name/value not centered",width,n,k,v) + assert n["y"]+n["height"]<=k["y"]+1 and \ + k["y"]+k["height"]<=v["y"]+1, \ + ("control text collides with rotary",width,n,k,v) + for name in names.all(): + assert name.evaluate("""el=> + parseFloat(getComputedStyle(el).fontSize)>=9 && + el.scrollWidth<=el.clientWidth+1"""), \ + ("encoder caption is too small or clipped",width, + name.inner_text()) + wet=editor.locator("#vtWetDial").bounding_box() + mode=editor.locator(".vt-mode-buttons").bounding_box() + assert wet and mode + assert abs((wet["y"]+wet["height"]/2)- + (mode["y"]+mode["height"]/2))<11, \ + ("MIX and trigger controls are vertically off-axis",width,wet,mode) + # Every song-source selector has a deliberate text space. + song=editor.locator("#vtMusicSource").bounding_box() + assert song and song["width"]>=180,("MUSIC selector too narrow",width,song) + assert editor.locator("#vtMusicSource").evaluate("""el=> + el.scrollWidth<=el.clientWidth+1""") + if width>600: + rhythm=editor.locator(".vt-pulse .vt-small-label").bounding_box() + music=editor.locator(".vt-music-source .vt-small-label").bounding_box() + assert rhythm and music and abs(rhythm["y"]-music["y"])<1, \ + ("RHYTHM and MUSIC section labels not aligned",width,rhythm,music) + rail=editor.locator(".vt-status-rail").bounding_box() + assert rail and rail["y"]+rail["height"]<=box["y"]+box["height"]+2, \ + ("footer clipped beneath mobile controls",width,rail,box) + # No control may draw past the horizontal plugin bounds. + for control in ["#vtThrow","#vtTap","#vtWetDial", + "#vtClockLabel","#vtDisplayBpm"]: + rect=editor.locator(control).bounding_box() + assert rect and rect["x"]>=box["x"]-1 and \ + rect["x"]+rect["width"]<=box["x"]+box["width"]+1,(control,rect,box) + page.screenshot(path="arsonmix-vocal-throw-"+str(width)+".png") + editor.screenshot(path="arsonmix-vocal-throw-editor-"+str(width)+".png") + if width==1366: + editor.locator('.vt-mode-buttons button[data-mode="0"]').click() + edit=last(page,"nativeThrowSet") + assert edit["settings"]["mode"]==0 and edit["instanceId"]==INSTANCE + assert edit["channelId"]==SOURCE + emit(page,"arMixBuiltinThrowQueue",{"requestId":edit["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinThrowAck",{"requestId":edit["requestId"],"status":"APPLIED"}) + reply_snapshot(page,state,{**DEFAULTS,"mode":0},applied=edit["requestId"]) + assert editor.locator("#vtMode").input_value()=="0" + assert editor.locator('.vt-mode-buttons button[data-mode="0"]').get_attribute("aria-pressed")=="true" + # Rotary wheel edits actually send settings through the native + # request/ACK/readback contract, not a CSS-only animation. + dial=editor.locator("#vtWetDial") + before=dial.evaluate("""el=>({ + offset:parseFloat(getComputedStyle(el.querySelector('.vt-meter-fill')).strokeDashoffset), + transform:getComputedStyle(el.querySelector('.vt-encoder-needle')).transform, + bg:getComputedStyle(el).backgroundImage + })""") + dial.hover() + page.mouse.wheel(0,-120) + after=dial.evaluate("""el=>({ + offset:parseFloat(getComputedStyle(el.querySelector('.vt-meter-fill')).strokeDashoffset), + transform:getComputedStyle(el.querySelector('.vt-encoder-needle')).transform, + bg:getComputedStyle(el).backgroundImage + })""") + assert float(after["offset"]).42 and rotary["settings"]["wet"]<=.44 + emit(page,"arMixBuiltinThrowQueue",{"requestId":rotary["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinThrowAck",{"requestId":rotary["requestId"],"status":"APPLIED"}) + updated={**DEFAULTS,"mode":0,"wet":rotary["settings"]["wet"]} + reply_snapshot(page,state,updated,applied=rotary["requestId"]) + assert "%" in editor.locator("#vtWetValue").inner_text() + editor.locator("#vtThrow").click() + assert editor.locator("#vtThrow").is_disabled(), "no repeated stage cue until native ACK" + cue=last(page,"nativeThrowTrigger") + assert cue["instanceId"]==INSTANCE and cue["channelId"]==SOURCE + assert cue["slot"]==0 + emit(page,"arMixBuiltinThrowQueue",{"requestId":cue["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinThrowAck",{"requestId":cue["requestId"],"status":"APPLIED"}) + reply_snapshot(page,state,{**DEFAULTS,"mode":0,"wet":rotary["settings"]["wet"]},count=1,tail=True) + assert editor.locator("#vtCount").inner_text()=="1" + assert editor.locator("#vtStatus").inner_text()=="TAIL" + assert editor.locator("#vtThrow").get_attribute("data-tail")=="true" + assert not editor.locator("#vtThrow").is_disabled() + # Real native tempo-source command (not a browser-only BPM guess). + source_menu=editor.locator("#vtMusicSource") + assert source_menu.locator('option[value="'+RECEIVER+'"]').count()==1 + source_menu.select_option(RECEIVER) + request=last(page,"nativeThrowTempoSource") + assert request["sourceChannelId"]==RECEIVER and request["channelId"]==SOURCE + assert editor.locator("#vtMusicStatus").inner_text()=="CONNECT" + emit(page,"arMixBuiltinThrowTempoAck",{ + "requestId":request["requestId"],"status":"APPLIED", + "sourceChannelId":RECEIVER}) + reply_snapshot(page,state, + {**DEFAULTS,"mode":0,"wet":rotary["settings"]["wet"]} if width==1366 else DEFAULTS, + count=1 if width==1366 else 0,tail=width==1366, + music={"source":RECEIVER,"bpm":120,"confidence":.85}) + assert editor.locator("#vtMusicStatus").inner_text()=="120 · BPM" + assert editor.locator("#vtClockLabel").inner_text()=="AUTO" + # Snapshot transport is request/response, not unsolicited push. + # Wait for a fresh native read request before testing a second + # DSP status update; a replay of the prior request is ignored. + previous=last(page,"nativeThrowSnapshot")["requestId"] + page.wait_for_function( + """old=>window.__actions.filter(x=>x.action==='nativeThrowSnapshot').at(-1)?.requestId!==old""", + arg=previous,timeout=4000) + # Confidence-approved grid is a separate native fact; the GUI + # must never fabricate it from BPM alone. + reply_snapshot(page,state, + {**DEFAULTS,"mode":0,"wet":rotary["settings"]["wet"]} if width==1366 else DEFAULTS, + count=1 if width==1366 else 0,tail=width==1366, + music={"source":RECEIVER,"bpm":120,"confidence":.85,"grid":True}) + assert editor.locator("#vtMusicStatus").inner_text()=="120 · GRID" + assert editor.locator("#vtClockLabel").inner_text()=="LOCK" + if width==1366: + # The next changed graph invalidates the old editor instance. + state["graph"]["channels"][0]["inserts"][0]["id"]="replaced-instance" + state["graph"].update(revision="4",rosterRevision="4") + state["mixerSession"].update(routeRevision="4",rosterRevision="4", + channels=copy.deepcopy(state["graph"]["channels"])) + emit(page,"arMixConsoleSnapshot",state) + page.wait_for_function("""()=>document.querySelector('#vtThrow')?.disabled""",timeout=2000) + editor.locator("#vtClose").click() + assert editor.is_hidden(),"standard close must dismiss editor" + assert not errors,(width,errors) + page.close() + browser.close() + print("PASS: ArSon Vocal Throw native picker/ACK/manual cue/compact editor in 2 viewports") + +if __name__=="__main__": + main() diff --git a/tests/approved_operator_ux_chromium_fat.py b/tests/approved_operator_ux_chromium_fat.py index af1367045..b7a62a94f 100644 --- a/tests/approved_operator_ux_chromium_fat.py +++ b/tests/approved_operator_ux_chromium_fat.py @@ -77,6 +77,23 @@ def wait_balanced(page): def inspect_page(page, width, height, scale, label): page.goto((Path(label)).as_uri()) + # Preserve the existing visible-channel gate; make hidden ancestor + # geometry inspectable if a cross-feature CSS/layout integration fails. + if not page.locator('#tracks .strip[data-id="1"]').is_visible(): + info=page.evaluate("""() => { + const target=document.querySelector('#tracks .strip[data-id="1"]'); + const ancestors=[]; + for(let n=target;n&&ancestors.length<13;n=n.parentElement){ + const s=getComputedStyle(n),r=n.getBoundingClientRect(); + ancestors.push({tag:n.tagName,id:n.id,classes:String(n.className), + hidden:n.hidden,display:s.display,visibility:s.visibility, + contentVisibility:s.contentVisibility,width:r.width,height:r.height, + minHeight:s.minHeight,position:s.position,overflow:s.overflow}); + } + return {readyState:document.readyState,viewport:[innerWidth,innerHeight], + ancestors,stylesheets:document.styleSheets.length}; + }""") + print("UX_INVISIBLE_ANCESTRY",width,height,json.dumps(info),flush=True) page.wait_for_selector('#tracks .strip[data-id="1"]') page.evaluate("document.fonts.ready") assert page.locator('.mixer-title').count()==0,"redundant LIVE MIXER bar" diff --git a/tests/approved_preview_mobile_navigation_smoke.py b/tests/approved_preview_mobile_navigation_smoke.py index a156320f8..3493a1285 100644 --- a/tests/approved_preview_mobile_navigation_smoke.py +++ b/tests/approved_preview_mobile_navigation_smoke.py @@ -139,6 +139,14 @@ async def verify_phone(browser, width: int, height: int): await page.locator("#playerKeyPlus").click() assert "desktop app" in await page.locator("#playerFeedback").inner_text() assert await page.locator("#playerKeyValue").inner_text() == "0 st" + folder_button=page.locator("#playerAddFolder") + assert await folder_button.is_visible() + folder_bounds=await folder_button.bounding_box() + assert folder_bounds and folder_bounds["x"]>=0 + assert folder_bounds["x"]+folder_bounds["width"]<=width+2 + assert await page.locator("#playerRelink").is_hidden() + await folder_button.click() + assert "desktop app" in await page.locator("#playerFeedback").inner_text() await page.locator("#playerAdd").click() feedback = await page.locator("#playerFeedback").inner_text() assert "desktop app" in feedback, ("public preview must not fake playback", feedback) diff --git a/tests/asio_restart_recovery_gate_test.cpp b/tests/asio_restart_recovery_gate_test.cpp new file mode 100644 index 000000000..07dc41d2e --- /dev/null +++ b/tests/asio_restart_recovery_gate_test.cpp @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#include "../engine/device/AsioRestartRecoveryGate.h" +#ifdef NDEBUG + #undef NDEBUG +#endif +#include +#include +#include + +int main() { + using armix::device::AsioRestartRecoveryGate; + AsioRestartRecoveryGate gate; + assert(!gate.due(999999)); + gate.observeEpoch(21,1000); + assert(!gate.due(1349) && gate.due(1350)); + gate.waitForReadback(1350); // no debit when ASIO panel is still settling + assert(gate.driverTransactions()==0 && !gate.due(2099) && gate.due(2100)); + gate.driverTransaction(2100); + gate.carryInternalEpoch(22); + gate.observeEpoch(22,2150); + assert(gate.trackedEpoch()==22 && gate.driverTransactions()==1); + assert(!gate.due(3299) && gate.due(3300)); + gate.driverTransaction(3300); // pin correction or reopened device + assert(gate.driverTransactions()==2 && !gate.due(7299)); + gate.bindFailed(3350); // never shorten a scheduled driver cool-down + assert(!gate.due(7299) && gate.due(7300)); + gate.driverTransaction(7300); + assert(!gate.mayChangeDriver()); + assert(!gate.due(15299) && gate.due(15300)); + gate.bindFailed(15300); // read-only rebind is still allowed after budget + assert(!gate.due(17699) && gate.due(17700)); + gate.observeEpoch(23,18000); // real external device change reopens budget + assert(gate.driverTransactions()==0 && gate.mayChangeDriver()); + assert(!gate.due(18349) && gate.due(18350)); + gate.recovered(); + assert(gate.driverTransactions()==0); + // avoid overflow across uptime wrap or synthetic test timestamps + gate.observeEpoch(24,std::numeric_limits::max()-10); + assert(!gate.due(std::numeric_limits::max()-1)); + assert(gate.due(std::numeric_limits::max())); +} diff --git a/tests/builtin_vocal_throw_test.cpp b/tests/builtin_vocal_throw_test.cpp new file mode 100644 index 000000000..30f125715 --- /dev/null +++ b/tests/builtin_vocal_throw_test.cpp @@ -0,0 +1,356 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#include "../engine/builtin_fx/VocalThrow.h" +#include +#include +#include +#include +#include +#include +#include +#include +#define check(x) do {if(!(x)){std::fprintf(stderr,"FAIL:%s:%d %s\n",__FILE__,__LINE__,#x);std::abort();}}while(false) +// Catch allocations from inside the audio callback, not from preparation. +static std::atomic noHeap{false}; +void* operator new(std::size_t n) { + if(noHeap.load(std::memory_order_relaxed))std::abort(); + if(void* p=std::malloc(n?n:1))return p; + throw std::bad_alloc(); +} +void* operator new[](std::size_t n) { + if(noHeap.load(std::memory_order_relaxed))std::abort(); + if(void* p=std::malloc(n?n:1))return p; + throw std::bad_alloc(); +} +void operator delete(void* p) noexcept{std::free(p);} +void operator delete[](void* p) noexcept{std::free(p);} +void operator delete(void* p,std::size_t) noexcept{std::free(p);} +void operator delete[](void* p,std::size_t) noexcept{std::free(p);} + +using armix::builtin_fx::VocalThrow; +using armix::builtin_fx::VocalThrowSettings; +static void run(VocalThrow& fx,float l,float r,int frames,float& maxL,float& maxR) { + std::array left{},right{}; + for(int begin=0;begin(n)); + noHeap.store(false,std::memory_order_release); + for(int i=0;i::quiet_NaN(); + check(!VocalThrow::prepareEdit(settings,48000,packet)); + settings=VocalThrowSettings{};settings.mode=3; + check(!VocalThrow::prepareEdit(settings,48000,packet)); + settings=VocalThrowSettings{};settings.repeats=7; + check(!VocalThrow::prepareEdit(settings,48000,packet)); + settings=VocalThrowSettings{};settings.captureMs=1550; + check(!VocalThrow::prepareEdit(settings,48000,packet)); +} +static void manualAndDry(double rate) { + VocalThrow fx;check(fx.prepare(rate)); + auto s=fx.settingsForTests();s.mode=0;s.captureMs=300;s.silenceMs=150; + check(fx.resetUnpublished(s)); + float peakL=0,peakR=0; + // No trigger: the leading vocalist is bit-exact dry, even in an insert. + std::array left{},right{}; + left.fill(.35f);right.fill(-.20f); + noHeap.store(true); + fx.processStereo(left.data(),right.data(),left.size()); + noHeap.store(false); + for(std::size_t n=0;n(rate*.35),peakL,peakR); + run(fx,0,0,static_cast(rate*.06),peakL,peakR); + check(fx.throwCount()==0); + noHeap.store(true); + const bool fired=fx.throwNow(); + noHeap.store(false); + check(fired&&fx.throwCount()==1); + peakL=peakR=0; + run(fx,0,0,static_cast(rate*.10),peakL,peakR); + check(peakL==0&&peakR==0); // beat-scheduled, no immediate echo smear + run(fx,0,0,static_cast(rate*.75),peakL,peakR); + check(peakL>.01f&&peakR>.005f); + // Recorded stereo is preserved (same gain on both channels). + check(peakL>peakR*1.4f); + noHeap.store(true); + const bool staleCue=fx.throwNow(); + noHeap.store(false); + check(!staleCue); // 700ms after last vocal: never report an empty throw +} +static void automaticAndHybrid(double rate) { + VocalThrow fx;check(fx.prepare(rate)); + auto s=fx.settingsForTests(); + s.mode=1;s.captureMs=220;s.silenceMs=120;s.thresholdDb=-30; + check(fx.resetUnpublished(s)); + float l=0,r=0; + run(fx,.5f,.35f,static_cast(rate*.3),l,r); + run(fx,0,0,static_cast(rate*.23),l,r); + check(fx.throwCount()==1); + run(fx,0,0,static_cast(rate*1.0),l,r); + check(fx.throwCount()==1); // no retrigger on the echoed tail + run(fx,.5f,.35f,static_cast(rate*.28),l,r); + run(fx,0,0,static_cast(rate*.23),l,r); + check(fx.throwCount()==2); + +} +static void hybridEditAndNoHeap() { + VocalThrow fx;check(fx.prepare(48000)); + VocalThrowSettings s{};s.mode=2;s.bpm=95;s.division=1;s.repeats=6; + VocalThrow::PreparedEdit edit{};check(VocalThrow::prepareEdit(s,48000,edit)); + check(!fx.applyPrepared(VocalThrow::PreparedEdit{})); + auto stale=edit;stale.sampleRate=44100;check(!fx.applyPrepared(stale)); + noHeap.store(true);const bool ok=fx.applyPrepared(edit);noHeap.store(false); + check(ok); + float l=0,r=0; + run(fx,.4f,.2f,10000,l,r); + noHeap.store(true);const bool fired=fx.throwNow();noHeap.store(false); + check(fired); + run(fx,0,0,200000,l,r); + check(std::isfinite(l)&&std::isfinite(r)); +} +// Two separate frozen phrases must coexist. A new cue must not chop the +// already sounding repeat. All fixtures run as bounded PCM chunks without +// any callback allocations, including at the highest allowed device rate. +static void twoTailsStayLive(double rate) { + VocalThrow reference,overlap; + check(reference.prepare(rate)&&overlap.prepare(rate)); + auto s=reference.settingsForTests(); + s.mode=0;s.bpm=200;s.division=1;s.repeats=3; + s.captureMs=300;s.silenceMs=120; + check(reference.resetUnpublished(s)&&overlap.resetUnpublished(s)); + float l=0.f,r=0.f; + auto both=[&](float input,int frames) { + run(reference,input,input*.5f,frames,l,r); + run(overlap,input,input*.5f,frames,l,r); + }; + both(.5f,static_cast(rate*.20)); + both(0.f,static_cast(rate*.10)); + noHeap.store(true); + const bool firstA=reference.throwNow(),firstB=overlap.throwNow(); + noHeap.store(false); + check(firstA&&firstB); + both(.4f,static_cast(rate*.12)); + both(0.f,static_cast(rate*.03)); + noHeap.store(true); + const bool second=overlap.throwNow(); + const bool saturated=overlap.throwNow(); + noHeap.store(false); + check(second&&!saturated); + check(overlap.throwCount()==2); + // From 0.45 to 0.485 s the second voice is preparing, and its first + // scheduled echo is still in the future. Output must be IDENTICAL to + // the reference's first tail, not abruptly muted by the second cue. + std::array refL{},refR{},mixL{},mixR{}; + float maxReference=0.f,maxOverlap=0.f; + const int compareFrames=static_cast(rate*.035); + for(int done=0;done(std::min(128,compareFrames-done)); + refL.fill(0.f);refR.fill(0.f);mixL.fill(0.f);mixR.fill(0.f); + noHeap.store(true); + reference.processStereo(refL.data(),refR.data(),count); + overlap.processStereo(mixL.data(),mixR.data(),count); + noHeap.store(false); + for(std::size_t i=0;i.001f&&maxOverlap>.001f); + run(overlap,0.f,0.f,static_cast(rate*.8),l,r); + check(overlap.throwCount()==2); +} +static void autoThenManualMustNotDoubleEcho() { + VocalThrow fx;check(fx.prepare(48000)); + auto s=fx.settingsForTests(); + s.mode=2;s.silenceMs=120;s.captureMs=250; + check(fx.resetUnpublished(s)); + float l=0.f,r=0.f; + run(fx,.5f,.25f,14400,l,r); + run(fx,0.f,0.f,12000,l,r); + check(fx.throwCount()==1); + noHeap.store(true); + const bool duplicated=fx.throwNow(); + noHeap.store(false); + check(!duplicated&&fx.throwCount()==1); + // A fresh phrase re-arms the manual path: previous auto trigger must + // not poison legitimate new cues when the singer starts again. + run(fx,.5f,.25f,12000,l,r); + noHeap.store(true); + const bool newPhrase=fx.throwNow(); + noHeap.store(false); + check(newPhrase&&fx.throwCount()==2); +} +static void denseRepeatsStayBounded() { + VocalThrow fx;check(fx.prepare(48000)); + auto settings=fx.settingsForTests(); + settings.mode=0;settings.bpm=200;settings.division=1; + settings.repeats=6;settings.decay=.9f; + settings.captureMs=1200.f;settings.wet=1.f;settings.ducking=0.f; + check(fx.resetUnpublished(settings)); + float maxL=0.f,maxR=0.f; + run(fx,.75f,.6f,48000,maxL,maxR); + noHeap.store(true); + const bool fired=fx.throwNow(); + noHeap.store(false); + check(fired); + maxL=maxR=0.f; + run(fx,0.f,0.f,static_cast(48000*2.5),maxL,maxR); + check(maxL>.20f&&maxR>.10f); + // An exposed six-tap feedback-like burst must not produce >0dBFS + // solely because echo taps overlap (dry path is unchanged). + check(maxL<=.751f&&maxR<=.601f); +} +static void manualOverrideSuppressesAuto() { + VocalThrow fx;check(fx.prepare(48000)); + auto s=fx.settingsForTests(); + s.mode=2;s.silenceMs=160;s.captureMs=250; + check(fx.resetUnpublished(s)); + float l=0.f,r=0.f; + run(fx,.5f,.25f,12000,l,r); // phrase 1 + run(fx,0.f,0.f,2400,l,r); // manual cue before auto silence timeout + noHeap.store(true); + const bool fired=fx.throwNow(); + noHeap.store(false); + check(fired&&fx.throwCount()==1); + run(fx,0.f,0.f,12000,l,r); + check(fx.throwCount()==1); // same phrase must not double-fire + run(fx,.5f,.25f,12000,l,r); // genuinely new phrase + // The 18ms release envelope must fall below the voice gate BEFORE + // the 160ms silence threshold begins. 208ms total is insufficient + // with a sustained 0.5 peak and threshold -35dB. + run(fx,0.f,0.f,9000,l,r); + check(fx.throwCount()==1); // no premature false-positive throw + run(fx,0.f,0.f,5000,l,r); + check(fx.throwCount()==2); // new phrase, after full release + gate +} +// Accepted music BPM affects only new frozen tails, never retimes a tail +// already singing. An unlocked source must use persisted Manual/TAP BPM. +static void musicTempoChangesOnlyFutureTail() { + VocalThrow music,manual; + check(music.prepare(48000)&&manual.prepare(48000)); + auto s=music.settingsForTests(); + s.mode=0;s.bpm=120.f;s.division=0;s.repeats=1; + s.captureMs=120.f;s.wet=1.f;s.ducking=0.f; + check(music.resetUnpublished(s)&&manual.resetUnpublished(s)); + float a=0.f,b=0.f; + run(music,.6f,.4f,12000,a,b); + run(manual,.6f,.4f,12000,a,b); + run(music,0.f,0.f,2880,a,b); + run(manual,0.f,0.f,2880,a,b); + noHeap.store(true); + music.setMusicIntervalSamples(16000); // quarter-note at 180 BPM + const bool firedMusic=music.throwNow(); + const bool firedManual=manual.throwNow(); + // The selected backing bus can disappear immediately after the cue. + // Its already frozen tail must retain the accepted .25s repeat interval. + music.setMusicIntervalSamples(0); + noHeap.store(false); + check(firedMusic&&firedManual); + a=b=0.f; + run(music,0.f,0.f,12960,a,b); // 270 ms after cue + check(a==0.f&&b==0.f); + a=b=0.f; + run(music,0.f,0.f,8160,a,b); // repeat around 290-410 ms + check(a>.01f&&b>.01f); + a=b=0.f; + run(manual,0.f,0.f,17760,a,b); // manual .5s must still be silent + check(a==0.f&&b==0.f); + a=b=0.f; + run(manual,0.f,0.f,7680,a,b); + check(a>.01f&&b>.01f); +} +// M3 beat-phase regression. Vocal PCM remains zero-latency dry, while the +// first frozen echo is snapped to the accepted source beat lattice. Changing +// transport AFTER the cue never changes the frozen tail's scheduled onset. +static void nativeMusicBeatGridQuantization(int quantum) { + VocalThrow gridded,unquantized; + check(gridded.prepare(48000)&&unquantized.prepare(48000)); + auto settings=gridded.settingsForTests(); + settings.mode=0;settings.captureMs=120.f; + settings.repeats=1;settings.bpm=120.f; + settings.division=0;settings.wet=1.f;settings.ducking=0.f; + check(gridded.resetUnpublished(settings)); + check(unquantized.resetUnpublished(settings)); + float l=0.f,r=0.f; + run(gridded,.65f,.35f,12000,l,r); + run(unquantized,.65f,.35f,12000,l,r); + run(gridded,0.f,0.f,3000,l,r); + run(unquantized,0.f,0.f,3000,l,r); + // Both processors have local sample 15000. Music tempo is 180 BPM + // (16000 sample quarter) with an observed beat at graph frame 100. + gridded.setMusicBeatGrid(16000,100,15000,true); + noHeap.store(true,std::memory_order_release); + const auto snapped=gridded.throwNow(); + const auto plain=unquantized.throwNow(); + // Simulate late rejection of source / changed BPM immediately following + // the cue. The old grid snapshot must remain in this tail. + gridded.setMusicBeatGrid(10000,15000,15000,false); + noHeap.store(false,std::memory_order_release); + check(snapped&&plain); + const auto onset=[&](VocalThrow& fx) { + std::array ll{},rr{}; + for(int start=0;start<50000;start+=quantum) { + const int n=std::min(quantum,50000-start); + ll.fill(0.f);rr.fill(0.f); + noHeap.store(true,std::memory_order_release); + fx.processStereo(ll.data(),rr.data(),static_cast(n)); + noHeap.store(false,std::memory_order_release); + for(int k=0;k.0002f)return start+k; + } + } + return -1; + }; + // First native music grid point >= intended onset: frame 32100. + // Cue at graph frame 15000 => first wet sample around offset 17100. + const int quantized=onset(gridded); + const int fallback=onset(unquantized); + check(quantized>=17100&&quantized<17120); + check(fallback>=23980&&fallback<25000); // manual 120 BPM / quarter + check(quantized+5000{\n" + " if(resizeQueued)return;resizeQueued=true;\n" + " requestAnimationFrame(()=>{resizeQueued=false;render();});\n" + "});\n") + html=html[:start]+legacy_resize+html[end:] + # MAIN pin-fragment caching and stale-RAF cancellation were introduced + # after V28; invert only those explicit, uniquely anchored edits here. + # The historical fixture itself must remain immutable. + for changed, prior in ( + ("// MAIN mini cables use a separate one-shot dirty flag; ordinary pointer moves\n// must not force layout reads on a stable native viewport.\nlet wireFragmentGeometryDirty=false;\n", + ""), + (" // A stable edgeId can still move when the host window is resized.\n // Refresh the physical anchor only on a geometry event (or edge edit).\n if(layer?.dataset.edgeId===String(edge.id)&&!wireFragmentGeometryDirty)return;", + " // Structural render, bank, density and resize remount the section; a\n // changed accepted edgeId invalidates this tiny projection automatically.\n if(layer?.dataset.edgeId===String(edge.id))return;"), + ("function renderWireRouting(){\n syncMainWireFragments();\n wireFragmentGeometryDirty=false;", + "function renderWireRouting(){\n syncMainWireFragments();") + ): + assert html.count(changed)==1,"Desktop WIRE checkpoint fragment drift" + html=html.replace(changed,prior,1) chrome=OWNER.read_text(encoding="utf-8") + # Owner V2 adds a native-ONLY toolbar after the original desktop caption. + # Strip that uniquely anchored addition first, preserving the strict V28 + # byte-for-byte historical CSS migration and the old 1600-byte caption gate. + desktop_toolbar_css="\n/* Native desktop toolbar V2 — functional hardware keys stay 29px high." + assert chrome.count(desktop_toolbar_css)==1,"Native toolbar CSS owner missing or duplicated" + toolbar_tail=chrome[chrome.index(desktop_toolbar_css):] + assert 1200 .window-title" in extra_css + assert len(extra_css)<1600,"Desktop caption CSS unexpectedly includes unrelated rules" + chrome=chrome[:chrome.index(desktop_css)] assert meta(html)==d["current"]["html"],"V28 HTML changed after checkpoint" assert meta(chrome)==d["current"]["chrome"],"V28 Chrome CSS changed after checkpoint" moved=d["movedCss"] diff --git a/tests/desktop_wire_resize_chromium_smoke.py b/tests/desktop_wire_resize_chromium_smoke.py new file mode 100644 index 000000000..3f3ccef27 --- /dev/null +++ b/tests/desktop_wire_resize_chromium_smoke.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python3 +"""Physical WIRE endpoint accuracy across Windows-like viewport resize sequences. + +The exact generated /preview/ page is exercised in real Chromium. No mocked +routing or PCM authority, no screenshot-only judgement and no idle polling. +""" +from __future__ import annotations + +import re +import subprocess +import sys +import tempfile +from pathlib import Path + +from playwright.sync_api import sync_playwright +from approved_publication_fixture import published_console + +ROOT = Path(__file__).resolve().parents[1] +NUMBER = re.compile(r"-?\d+(?:\.\d+)?") + + +def center(locator): + b = locator.bounding_box() + assert b and b["width"] > 0 and b["height"] > 0, ("missing socket", b) + return b["x"] + b["width"] / 2, b["y"] + b["height"] / 2 + + +def path_points(locator): + d = locator.get_attribute("d") or "" + numbers = [float(v) for v in NUMBER.findall(d)] + assert len(numbers) >= 4 and d.startswith("M") and (" C" in d or " L" in d), ("no committed WIRE path", d) + return (numbers[0], numbers[1]), (numbers[-2], numbers[-1]) + + +def assert_pinned(page, width): + vp = page.locator("#viewport").bounding_box() + assert vp and vp["width"] > 0, (width, "viewport missing", vp) + src = page.locator('#tracks .strip[data-id="5"] .wire-node-out .wire-pin') + dst = page.locator('#tracks .strip[data-id="3"] .wire-node-in .wire-arrow') + cable = page.locator('#wireLayer path.wire-outgoing-line[data-from="5"][data-to="3"]') + assert cable.count() == 1, (width, "committed WIRE disappeared", cable.count()) + source, dest = path_points(cable) + pin = center(src) + socket = center(dst) + actual = ((pin[0] - vp["x"], pin[1] - vp["y"]), + (socket[0] - vp["x"], socket[1] - vp["y"])) + for label, got, expect in zip(("OUT", "IN"), (source, dest), actual): + assert abs(got[0] - expect[0]) < .6 and abs(got[1] - expect[1]) < .6, ( + width, label, "stale cable endpoint after resize", got, expect) + assert page.locator('#tracks .strip[data-id="3"] .wire-node-in').get_attribute( + "data-wire-arrival") == "true", (width, "accepted WIRE arrival lost") + + # A MAIN fragment is a local SVG drawn in its own send-section coordinate + # system. It must follow the real pin after height changes without + # depending on an edge-ID change. + main = page.locator('#tracks .strip[data-id="5"] .wire-main-fragment path.wire-main-jacket') + if main.count(): + p0, _ = path_points(main) + section = page.locator('#tracks .strip[data-id="5"] .send-section.wire-section') + pin = center(section.locator('.wire-node-out .wire-pin')) + rect = section.bounding_box() + assert abs(p0[0] - (pin[0] - rect["x"])) < .65 and abs( + p0[1] - (pin[1] - rect["y"])) < .65, ( + width, "MAIN mini cable detached from physical pin", p0, pin, rect) + + +def main(): + with tempfile.TemporaryDirectory(prefix="arsonmix-caption-wire-") as td: + dist = Path(td) / "dist" + subprocess.run([sys.executable, str(ROOT / "scripts/build_pages.py"), + "--out", str(dist), "--sha", "caption-wire-resize", + "--branch", "native-caption"], cwd=ROOT, + text=True, capture_output=True, check=True) + public = published_console(dist) + with sync_playwright() as pw: + browser = pw.chromium.launch(headless=True) + page = browser.new_page(viewport={"width": 1680, "height": 900}) + errors = [] + page.on("pageerror", lambda error: errors.append(str(error))) + page.goto(public.as_uri()) + page.locator('#tracks .strip[data-id="5"] .strip-identity-top').click() + body = page.locator(".console-body") + if "collapsed-send" in (body.get_attribute("class") or ""): + page.locator('.section-rail [data-section="send"]').click() + + src = page.locator('#tracks .strip[data-id="5"] .wire-node-out .wire-pin') + dst = page.locator('#tracks .strip[data-id="3"] .wire-node-in .wire-arrow') + x0, y0 = center(src) + x1, y1 = center(dst) + page.mouse.move(x0, y0) + page.mouse.down() + page.mouse.move((x0+x1)/2, y0+52, steps=7) + page.mouse.move(x1, y1, steps=7) + page.mouse.up() + page.mouse.move(x0, y0-65) + page.wait_for_function("""()=>!!document.querySelector( + '#wireLayer path.wire-outgoing-line[data-from="5"][data-to="3"]')""") + # Exercise both within-bank resize and actual bank-capacity change. + for width, height in ((1680, 900), (1366, 900), (1920, 1080), + (1280, 760), (1680, 820)): + page.set_viewport_size({"width": width, "height": height}) + page.wait_for_function("""()=> { + const svg=document.querySelector('#wireLayer'); + const vp=document.querySelector('#viewport'); + return !!svg&&!!vp&&svg.viewBox.baseVal.width===vp.getBoundingClientRect().width; + }""") + assert_pinned(page, width) + + # Start an OUT gesture, then force a bank remount via narrow resize. + # The pointer-capture owner gets detached; the gesture must be + # cancelled fail-closed, not turned into an unintended route. + before = page.locator('#tracks .strip[data-id="2"] .wire-node-in').get_attribute( + "data-wire-arrival") + loose = page.locator('#tracks .strip[data-id="6"] .wire-node-out .wire-pin') + x, y = center(loose) + page.mouse.move(x, y) + page.mouse.down() + page.mouse.move(x+35, y+32, steps=5) + assert "wire-dragging" in (body.get_attribute("class") or ""), ( + "test never activated a cable drag") + prior_capacity = page.evaluate("""()=>Number(document.querySelector('.console-body') + ?.style.getPropertyValue('--bank-capacity'))""") + assert prior_capacity >= 7, ("test needs an expanded bank", prior_capacity) + page.set_viewport_size({"width": 1200, "height": 760}) + page.wait_for_function("""prior => { + const root=document.querySelector('.console-body'); + const next=Number(root?.style.getPropertyValue('--bank-capacity')); + return next>0&&next{ + const begin=engine.indexOf('bool verifyRestoredDirectDevice ('); + const end=engine.indexOf('void detach()',begin); + assert.ok(begin>0&&end>begin); + const restore=engine.slice(begin,end); + assert.ok(restore.includes('active->getActiveOutputChannels().countNumberOfSetBits()<2')); + assert.ok(!restore.includes('active->getActiveInputChannels().isZero()'), + 'zero actual capture pins must not make a valid output-only mixer unrecoverable'); + assert.ok(restore.includes('current.inputDeviceName == expected.inputDeviceName')); + assert.ok(restore.includes('current.outputDeviceName == expected.outputDeviceName')); + assert.match(engine,/resumeVerifiedDirectRoute\(\)/); + assert.match(main,/No verified stereo playback device; audio remains gated/); +}); test('restore retry is bounded and disabled on success, explicit direct and setup paths',()=>{ assert.match(main,/directRestore_\.failed \(snapshot\.generation, now\)/); assert.match(main,/directRestore_\.recovered \(snapshot\.generation\)/); @@ -87,8 +100,10 @@ test('ASIO/WASAPI DIRECT authorizes the exact active input/output channel map',( } assert.ok(engine.includes('EXACT_ACTIVE_INPUT_AND_OUTPUT_CHANNEL_BITMASKS')); assert.ok(fence.includes('UNEXPECTED_DIRECT_BACKEND_DEVICE_OR_CHANNEL_MASK')); - assert.ok(fence.includes('!validMask(inputMask)')); - assert.ok(fence.includes('!validMask(outputMask)')); + // A real output-only playback session has the canonical zero input mask. + // The exact device fingerprint must still reject absent physical outputs. + assert.ok(fence.includes('!validMask(inputMask,true)')); + assert.ok(fence.includes('!validMask(outputMask,false)')); const callback=engine.slice(engine.indexOf('void audioDeviceIOCallbackWithContext')); assert.ok(callback.indexOf('!directFence_.permitted()')>=0); assert.ok(callback.indexOf('!directFence_.permitted()') +#include +#include +#include +#include +#include + +using namespace armix::mixer; +using armix::builtin_fx::ChannelHarmonyProcessor; + +static float singer(int n) noexcept { + const double t=static_cast(n)/48000.; + return static_cast(.16*std::sin(6.283185307179586*220.*t)+ + .045*std::sin(6.283185307179586*440.*t)); +} +static LiveChannelFxGraph::InstanceLease makeHarmony( + double rate=48000.,int quantum=64,float wet=1.f,float space=1.f) { + auto p=std::make_unique(); + p->prepareToPlay(rate,quantum); + const int declaredLatency=2*static_cast(std::round(rate*.016)); + assert(p->isReady() && p->getLatencySamples()==declaredLatency); + armix::harmony::Settings rich; + rich.voices=5;rich.wet=wet;rich.space=space; + assert(p->queueAccepted(rich,9001)); + return std::make_shared( + std::move(p),ChannelHarmonyProcessor::catalogIdentity, + "ArSon Harmony",quantum); +} +int main() { + constexpr ChannelId vocal{7301}; + auto uninterrupted=makeHarmony(), switching=makeHarmony(),legacy=makeHarmony(); + assert(switching->continuousBypassProcessing); + // Isolated offline reference of PRE-FIX host behavior; production never + // disables the warm-processing contract. This must diverge on reentry. + legacy->continuousBypassProcessing=false; + assert(uninterrupted->latencySamples==1536); + assert(switching->latencySamples==uninterrupted->latencySamples); + DynamicChannelFxLeaseBank::Assignment referenceRow,switchingRow,legacyRow; + referenceRow.id=vocal;referenceRow.format=ProcessingFormat::stereo; + referenceRow.inserts.push_back(uninterrupted); + switchingRow.id=vocal;switchingRow.format=ProcessingFormat::stereo; + switchingRow.inserts.push_back(switching); + legacyRow.id=vocal;legacyRow.format=ProcessingFormat::stereo; + legacyRow.inserts.push_back(legacy); + DynamicChannelFxLeaseBank alwaysOn,switched,oldBehavior; + const std::array referenceRows{referenceRow}; + const std::array switchingRows{switchingRow}; + const std::array legacyRows{legacyRow}; + assert(DynamicChannelFxLeaseBank::prepare(1,1,legacyRows,oldBehavior)== + DynamicChannelFxLeaseBank::Fault::none); + assert(DynamicChannelFxLeaseBank::prepare(1,1,referenceRows,alwaysOn)== + DynamicChannelFxLeaseBank::Fault::none); + assert(DynamicChannelFxLeaseBank::prepare(1,1,switchingRows,switched)== + DynamicChannelFxLeaseBank::Fault::none); + bool priorSlot=false,priorRack=false; + float maxWetDifference=0.f,maxDryDifference=0.f; + float maxOldBypassDifference=0.f,maxClickSlopeExcess=0.f; + int samplesCheckedWet=0,samplesCheckedDry=0; + float previousWetL=0.f,previousWetR=0.f; + float previousProbeL=0.f,previousProbeR=0.f,previousDry=0.f; + // Fixed 64-frame hardware-shaped partitions, with slot and rack OFF. + // The last pair is a quick reverse-toggle (no graph or callback restart). + for(int block=0;block<1300;++block) { + const bool slotOff=(block>=320&&block<580)|| + (block>=700&&block<780)|| + (block==1110||block==1112); + const bool rackOff=(block>=850&&block<1000)|| + (block==1111||block==1113); + if(slotOff!=priorSlot) { + assert(switched.setInsertBypass(1,1,vocal,0,switching->instanceId,slotOff)); + assert(oldBehavior.setInsertBypass(1,1,vocal,0,legacy->instanceId,slotOff)); + priorSlot=slotOff; + } + if(rackOff!=priorRack) { + assert(switched.setRackBypass(1,1,vocal,rackOff)); + assert(oldBehavior.setRackBypass(1,1,vocal,rackOff)); + priorRack=rackOff; + } + std::array baseL{},baseR{},probeL{},probeR{},oldL{},oldR{}; + for(int i=0;i<64;++i) { + const int n=block*64+i; + baseL[i]=probeL[i]=oldL[i]=singer(n); + baseR[i]=probeR[i]=oldR[i]=singer(n); + } + alwaysOn(vocal,baseL.data(),baseR.data(),64); + switched(vocal,probeL.data(),probeR.data(),64); + oldBehavior(vocal,oldL.data(),oldR.data(),64); + const bool quietBypass=slotOff||rackOff; + const bool steadyWet=!quietBypass && + (block>=590&&block<700 || block>=790&&block<850 || + block>=1010&&block<1110 || block>=1125); + const bool steadyDry=quietBypass&& + (block>=330&&block<580 || block>=710&&block<780 || + block>=860&&block<1000); + for(int i=0;i<64;++i) { + const int n=block*64+i; + const float delayed=n>=1536?singer(n-1536):0.f; + if(n>=1537){ + // Actual post-bypass sample slope may only exceed either + // continuous wet or exact aligned dry slope by the 8ms ramp + // contribution. No block-edge impulse is allowed. + const float wetSlope=std::max(std::abs(baseL[i]-previousWetL), + std::abs(baseR[i]-previousWetR)); + const float drySlope=std::abs(delayed-previousDry); + const float actualSlope=std::max(std::abs(probeL[i]-previousProbeL), + std::abs(probeR[i]-previousProbeR)); + const float excess=actualSlope-std::max(wetSlope,drySlope); + maxClickSlopeExcess=std::max(maxClickSlopeExcess,excess); + assert(excess<.035f); + } + previousWetL=baseL[i];previousWetR=baseR[i]; + previousProbeL=probeL[i];previousProbeR=probeR[i]; + previousDry=delayed; + assert(std::isfinite(probeL[i])&&std::isfinite(probeR[i])); + assert(std::abs(probeL[i])<=4.f&&std::abs(probeR[i])<=4.f); + if(steadyWet) { + const float d=std::max(std::abs(probeL[i]-baseL[i]), + std::abs(probeR[i]-baseR[i])); + maxWetDifference=std::max(maxWetDifference,d); + assert(d<.00002f); // same exact history as never-bypassed DSP + ++samplesCheckedWet; + if(block>=590&&block<615 || block>=790&&block<815) + maxOldBypassDifference=std::max(maxOldBypassDifference, + std::max(std::abs(oldL[i]-baseL[i]), + std::abs(oldR[i]-baseR[i]))); + } + if(steadyDry) { + const int n=block*64+i-1536; + const float expect=n>=0?singer(n):0.f; + const float d=std::max(std::abs(probeL[i]-expect), + std::abs(probeR[i]-expect)); + maxDryDifference=std::max(maxDryDifference,d); + assert(d<.00002f); // never switch PDC when OFF + ++samplesCheckedDry; + } + } + } + assert(samplesCheckedWet>10000&&samplesCheckedDry>10000); + assert(maxOldBypassDifference>.003f); // old skipped DSP history visibly diverges + assert(!switched.rackBypassed(vocal)); + + // Cross-product regression across WET 0/50/100 and Space 0/60/100. + // Native FxInstance::render() is used at 48/96k and three ASIO periods. + // Includes a singing section, a silence/room-tail section, rack OFF/ON, + // slot OFF/ON, reentry after the singer returns, and exact dry PDC. + // Keep the original always-on/old-behavior A/B probe above, too. + struct Scenario { double rate;int quantum;float wet,space; }; + constexpr std::array cases{{ + {48000.,64,0.f,0.f},{48000.,128,0.f,.6f}, + {48000.,256,0.f,1.f},{48000.,64,.5f,0.f}, + {96000.,128,.5f,.6f},{96000.,256,.5f,1.f}, + {96000.,64,1.f,0.f},{96000.,128,1.f,.6f}, + {96000.,256,1.f,1.f} + }}; + double worstExcess=0.; + int verifiedWet=0,verifiedDry=0; + for(const auto cfg:cases) { + auto a=makeHarmony(cfg.rate,cfg.quantum,cfg.wet,cfg.space); + auto b=makeHarmony(cfg.rate,cfg.quantum,cfg.wet,cfg.space); + assert(a->latencySamples==b->latencySamples); + DynamicChannelFxLeaseBank::Assignment ref,probe; + ref.id=vocal;ref.format=ProcessingFormat::stereo; + ref.inserts.push_back(a); + probe.id=vocal;probe.format=ProcessingFormat::stereo; + probe.inserts.push_back(b); + DynamicChannelFxLeaseBank on,cycle; + const std::array ar{ref},br{probe}; + assert(DynamicChannelFxLeaseBank::prepare(3,1,ar,on)== + DynamicChannelFxLeaseBank::Fault::none); + assert(DynamicChannelFxLeaseBank::prepare(3,1,br,cycle)== + DynamicChannelFxLeaseBank::Fault::none); + const int total=static_cast(cfg.rate*.85); + const int latency=b->latencySamples; + const auto input=[&](int n) noexcept -> float { + if(n<0)return 0.f; + const double time=static_cast(n)/cfg.rate; + double amplitude=1.; + if(time>=.5&&time<.505)amplitude=1.-(time-.5)/.005; + else if(time>=.505&&time<.73)amplitude=0.; + else if(time>=.73&&time<.735)amplitude=(time-.73)/.005; + const double phase=6.283185307179586*220.*time; + return static_cast(amplitude*(.16*std::sin(phase)+ + .045*std::sin(phase*2.))); + }; + bool wasSlotOff=false,wasRackOff=false; + float lastWetL=0.f,lastWetR=0.f,lastOutL=0.f,lastOutR=0.f,lastDry=0.f; + int wetCount=0,dryCount=0; + for(int offset=0;offset(offset)/cfg.rate; + const bool slotOff=at>=.20&&at<.36; + const bool rackOff=at>=.61&&at<.73; + if(slotOff!=wasSlotOff){ + assert(cycle.setInsertBypass(3,1,vocal,0,b->instanceId,slotOff)); + wasSlotOff=slotOff; + } + if(rackOff!=wasRackOff){ + assert(cycle.setRackBypass(3,1,vocal,rackOff)); + wasRackOff=rackOff; + } + std::array rl{},rr{},pl{},pr{}; + for(int i=0;i(n)/cfg.rate; + const bool stableDry=(time>=.212&&time<.36)|| + (time>=.622&&time<.73); + const bool stableWet=(time>=.38&&time<.61)|| + (time>=.75); + const float wetSlope=std::max(std::abs(rl[i]-lastWetL), + std::abs(rr[i]-lastWetR)); + const float drySlope=std::abs(delayed-lastDry); + const float actualSlope=std::max(std::abs(pl[i]-lastOutL), + std::abs(pr[i]-lastOutR)); + if(n>latency){ + worstExcess=std::max(worstExcess,static_cast( + actualSlope-std::max(wetSlope,drySlope))); + assert(actualSlope-std::max(wetSlope,drySlope)<.045f); + } + lastWetL=rl[i];lastWetR=rr[i]; + lastOutL=pl[i];lastOutR=pr[i];lastDry=delayed; + assert(std::isfinite(pl[i])&&std::isfinite(pr[i])); + assert(std::abs(pl[i])<=4.f&&std::abs(pr[i])<=4.f); + if(stableDry){ + assert(std::abs(pl[i]-delayed)<.00003f&& + std::abs(pr[i]-delayed)<.00003f); + ++dryCount; + } + if(stableWet){ + // The exact live DSP state must match a never-bypassed + // lease, not merely have a visually smooth envelope. + assert(std::abs(pl[i]-rl[i])<.00003f&& + std::abs(pr[i]-rr[i])<.00003f); + ++wetCount; + } + } + } + assert(wetCount>0&&dryCount>0); + verifiedWet+=wetCount;verifiedDry+=dryCount; + assert(!cycle.rackBypassed(vocal)); + assert(!b->bypassRequested.load(std::memory_order_acquire)); + } + std::cout<<"Harmony multi-rate wet/space bypass matrix PASS; " + <<"scenarios="< +#include +#include +#include +#include +#include +#include +#include + +namespace { +using Clock=std::chrono::steady_clock; +constexpr int warmup=256; +constexpr int measured=512; +void profile(double rate,int block,int voices,bool musicGuide=false){ + auto engine=std::make_unique(); + if(!engine->prepare(rate)){std::cerr<<"Harmony prepare failed\n";std::exit(2);} + armix::harmony::Settings settings; + settings.voices=voices;settings.wet=0.55f;settings.correction=true; + settings.guideMode=musicGuide?1:0; + settings.guideChannelId=musicGuide?770:0; + armix::harmony::MusicKeyDetector guide; + if(musicGuide&&!guide.prepare(rate)){ + std::cerr<<"Music guide prepare failed\\n";std::exit(2); + } + if(!engine->setSettings(settings)){std::cerr<<"Harmony settings rejected\n";std::exit(2);} + std::array l{},r{},musicL{},musicR{}; + std::array elapsed{}; + double phase=0.; + const double step=6.283185307179586*220./rate; + for(int blockIndex=0;blockIndex(0.16*std::sin(phase)+ + 0.04*std::sin(2.*phase)); + l[static_cast(i)]=x; + r[static_cast(i)]=x; + if(musicGuide){ + // Different ChannelId source; no music PCM mixed into vocal. + // Exclude guide-tone fixture synthesis from timed callback. + const double t=static_cast(blockIndex*block+i)/rate; + musicL[static_cast(i)]= + musicR[static_cast(i)]=static_cast( + .06*(std::sin(6.283185307179586*261.625565*t)+ + std::sin(6.283185307179586*329.627557*t)+ + std::sin(6.283185307179586*391.995436*t))); + } + phase+=step; + if(phase>=6.283185307179586)phase-=6.283185307179586; + } + const auto started=Clock::now(); + if(musicGuide){ + guide.process(musicL.data(),musicR.data(),block); + const auto key=guide.estimate(); + engine->setGuideKey(key.valid()?key.key:-1,key.valid()?key.scale:-1); + } + engine->process(l.data(),r.data(),block); + const auto finished=Clock::now(); + if(blockIndex>=warmup) + elapsed[static_cast(blockIndex-warmup)]= + std::chrono::duration(finished-started).count(); + for(int i=0;i(i)])|| + !std::isfinite(r[static_cast(i)])){ + std::cerr<<"Nonfinite Harmony PCM in profile\n";std::exit(2); + } + } + const double deadlineUs=1.e6*static_cast(block)/rate; + const auto misses=std::count_if(elapsed.begin(),elapsed.end(), + [deadlineUs](double elapsedUs){return elapsedUs>deadlineUs;}); + std::sort(elapsed.begin(),elapsed.end()); + std::cout< #include #include +#include using namespace armix::harmony; static void need(bool value,const char* why){if(!value){std::cerr<applyPreparedSettings(keyPacket),"key edit was rejected"); - need(!rekey->voiced()&&rekey->observedMidiNote()==-1, - "key edit reused a stale note from previous scale"); + need(rekey->voiced()&&rekey->observedMidiNote()==69, + "key edit interrupted a sustained voiced singer"); for(int i=0;i<48000;++i) rkL[i]=rkR[i]=.2f*std::sin(6.28318530718*440*i/48000); for(int i=0;i<48000;i+=128)rekey->process(rkL.data()+i,rkR.data()+i,128); need(rekey->voiced()&&rekey->observedMidiNote()==69, "fresh key did not reacquire stable A4"); + + // A change of guide key and fallback MUST NOT suppress active vocal + // analysis/room/grains. The former setGuideKey() immediately unvoiced a + // singer, making Music mode audibly sputter on uncertain key boundaries. + auto guided=std::make_unique(); + need(guided->prepare(48000),"guided vocal prepare failed"); + Settings guideSettings;guideSettings.key=0;guideSettings.scale=0; + guideSettings.guideMode=1;guideSettings.guideChannelId=6001; + guideSettings.voices=5;guideSettings.wet=1.f; + need(guided->setSettings(guideSettings),"guided settings failed"); + std::vector gL(48000),gR(48000); + const auto feedGuided=[&](int count){ + for(int i=0;i(.20*std::sin( + 6.283185307179586*440.*i/48000.)); + for(int i=0;iprocess(gL.data()+i,gR.data()+i,std::min(64,count-i)); + }; + feedGuided(48000); + need(guided->voiced()&&guided->observedMidiNote()==69, + "guide singer baseline lost stable voice"); + for(int cycle=0;cycle<8;++cycle){ + if(cycle%2==0)guided->setGuideKey(0,1); // C minor excludes sung A + else guided->setGuideKey(-1,-1); // explicit Manual fallback + need(guided->voiced()&&guided->observedMidiNote()>=0, + "guide key event hard-gated sustained vocal"); + feedGuided(4096); + need(guided->voiced()&&guided->observedMidiNote()>=0, + "singer failed to continue across guide key transition"); + if(cycle%2==0) + need(guided->observedMidiNote()!=69, + "old C-major pitch was stuck after C-minor transition"); + else + need(guided->observedMidiNote()==69, + "manual fallback failed to retune singing A"); + } // Fixed-size reduced audio history must survive repeated wraparound at // the highest supported device rate without changing declared PDC. auto wrap=std::make_unique(); @@ -220,5 +257,413 @@ int main(){ std::abs(wr[i]-(impulse?-.25f:0.f))<1.e-5f, "reduced 192 kHz history corrupted a wrapped dry impulse"); } + // Regression for sliding lag-energy normalization: harmonic-rich A2 + // vocals must remain a stable note at small, irregular ASIO block sizes. + for(int block:{64,128,257}){ + auto pitched=std::make_unique(); + need(pitched->prepare(48000.),"harmonic tracking prepare failed"); + constexpr int samples=24000; + std::vector hl(samples),hr(samples); + for(int i=0;i(i)/48000.; + hl[i]=hr[i]=static_cast( + .17*std::sin(6.283185307179586*110.*t)+ + .04*std::sin(6.283185307179586*220.*t)+ + .02*std::sin(6.283185307179586*330.*t)); + } + for(int i=0;iprocess(hl.data()+i,hr.data()+i,std::min(block,samples-i)); + need(pitched->voiced()&&pitched->observedMidiNote()==45, + "rolling pitch energy altered singer-like A2 classification"); + } + // P0: alternate ASIO block sizes must produce identical output PCM. + // Sliced analysis operates per sample, never depends on callback framing. + std::vector referenceL,referenceR; + for(int block:{64,127,256}){ + auto bounded=std::make_unique(); + need(bounded->prepare(48000.),"P0 bounded engine prepare failed"); + Settings rich;rich.voices=5;rich.wet=.7f;rich.correction=true; + need(bounded->setSettings(rich),"P0 quality setup failed"); + constexpr int frames=48000; + std::vector left(frames),right(frames); + for(int i=0;i(.18*std::sin(phase)+.06*std::sin(2*phase)); + right[i]=static_cast(.16*std::sin(phase)+.04*std::sin(3*phase)); + } + for(int i=0;iprocess(left.data()+i,right.data()+i,std::min(block,frames-i)); + need(bounded->peakPitchLagWork()>0&& + bounded->peakPitchLagWork()<=Engine::maxPitchLagsPerSlice, + "P0 pitch analysis overran per-sample lag budget"); + need(bounded->completedPitchAnalyses()>100&& + bounded->abandonedPitchAnalyses()==0, + "P0 slices failed to finish before the next analysis hop"); + need(bounded->voiced()&&bounded->observedMidiNote()==57, + "P0 bounded singer tone detection failed"); + if(referenceL.empty()){ + referenceL=left;referenceR=right; + }else for(int i=0;i(); + need(opposite->prepare(rate),"antiphase singer prepare failed"); + Settings wet;wet.voices=5;wet.wet=.85f;wet.correction=true; + need(opposite->setSettings(wet),"antiphase singer settings failed"); + const int count=static_cast(rate*.65); + std::vector left(static_cast(count)); + std::vector right(static_cast(count)); + for(int i=0;i( + .19*std::sin(6.283185307179586*220.*i/rate)+ + .05*std::sin(6.283185307179586*440.*i/rate)); + left[static_cast(i)]=x; + right[static_cast(i)]=-x; + } + for(int i=0;iprocess(left.data()+i,right.data()+i,std::min(257,count-i)); + need(opposite->voiced()&&opposite->observedMidiNote()==57, + "phase-opposed singer lost stable A3 pitch"); + double harmonized=0.; + for(int i=count/2;i(i)]; + const float r=right[static_cast(i)]; + need(std::isfinite(l)&&std::isfinite(r),"phase-safe PCM not finite"); + const double recovered=.5*(static_cast(l)+r); + harmonized+=recovered*recovered; + } + need(harmonized>0.005,"opposed stereo produced no harmonized audio"); + } + + // P1: the approved 48 kHz Color law must be preserved. At every other + // supported sample rate, equal physical time must imply equal one-pole + // attenuation; no pow/log calls can occur inside the audio callback. + for(double rate:{32000.,44100.,48000.,96000.,192000.}){ + RateStableColor table; + need(table.prepare(rate),"color filter prepare rejected supported rate"); + for(float color:{0.f,.08f,.25f,.5f,.75f,.91f,1.f}){ + const float actual=table.coefficient(color); + const float legacy=.07f+.77f*color; + need(std::isfinite(actual)&&actual>0.f&&actual<1.f, + "rate-adjusted Color coefficient invalid"); + if(rate==48000.) + need(std::abs(actual-legacy)<1.e-6f, + "48 kHz Color legacy response changed"); + // 125 microseconds is six samples at 48k. A 10ms measurement + // would hide every wrong Color coefficient: these filters all + // decay to ~zero well before 10ms. + const double oldDecay=std::pow(1.-static_cast(legacy),6.); + const double newDecay=std::pow(1.-static_cast(actual), + rate*.000125); + need(std::abs(oldDecay-newDecay)<1.e-4, + "Color attenuation changes at identical physical time"); + } + } + // P2: compare every supported key/scale/degree against the old per-voice + // pow(2,(targetMidi-observedMidi)/12) reference before accepting a LUT. + PreparedPitchIntervals intervals; + intervals.prepare(); + for(int key=0;key<12;++key) + for(int scale=0;scale<2;++scale) + for(int degree=-5;degree<=65;++degree){ + const int note=noteAt(degree,key,scale); + constexpr std::array offsets{{2,4,-2,6,-4}}; + for(float detune:{-.45f,-.17f,0.f,.23f,.49f}){ + const float midi=static_cast(note)+detune; + const float base=std::pow(2.f,(note-midi)/12.f); + for(const int offset:offsets){ + const int target=noteAt(degree+offset,key,scale); + need(std::abs(target-note)<=PreparedPitchIntervals::maximumSemitones, + "harmonic interval outside precomputed LUT"); + const float old=std::clamp(std::pow(2.f,(target-midi)/12.f), + 0.5f,2.f); + const float next=std::clamp(base*intervals.ratio(target-note), + 0.5f,2.f); + need(std::abs(old-next)<1.e-6f, + "precomputed harmony interval changed output pitch ratio"); + } + } + } + // P0: rescued phase-opposed ANALYSIS must never modify DRY output. + // The player, direct hardware monitor and graph still own stereo polarity. + for(double rate:{48000.,192000.}){ + auto dry=std::make_unique(); + need(dry->prepare(rate),"dry antiphase sample-rate prepare failed"); + Settings silentRack;silentRack.wet=0.f;silentRack.correction=false; + need(dry->setSettings(silentRack),"dry antiphase packet failed"); + const int latency=dry->latencySamples(); + const int count=latency*3+217; + std::vector original(static_cast(count)); + std::vector left(static_cast(count)); + std::vector right(static_cast(count)); + for(int i=0;i( + .21*std::sin(6.283185307179586*140.*i/rate)+ + .06*std::sin(6.283185307179586*280.*i/rate)); + original[static_cast(i)]=x; + left[static_cast(i)]=x; + right[static_cast(i)]=-x; + } + for(int i=0;iprocess(left.data()+i,right.data()+i,std::min(127,count-i)); + for(int i=0;i(i-latency)]; + need(std::abs(left[static_cast(i)]-expected)<1.e-6f&& + std::abs(right[static_cast(i)]+expected)<1.e-6f, + "P0 polarity rescue corrupted dry stereo or exact PDC"); + } + } + + // P0: all supported device rates and irregular ASIO-shaped periods must + // complete the full frozen correlation search WITHOUT dropped windows. + // This prevents a naive 32->8-lag reduction from silently truncating E2-C6. + for(const double rate:{32000.,44100.,48000.,96000.,192000.}){ + for(int block:{64,127,256}){ + auto sliced=std::make_unique(); + need(sliced->prepare(rate),"P0 multirate slice prepare failed"); + const int samples=static_cast(rate*.30); + std::vector l(static_cast(samples)); + std::vector r(static_cast(samples)); + for(int i=0;i( + .16*std::sin(6.283185307179586*220.*i/rate)+ + .04*std::sin(6.283185307179586*440.*i/rate)); + l[static_cast(i)]=value; + r[static_cast(i)]=value; + } + for(int i=0;iprocess(l.data()+i,r.data()+i,std::min(block,samples-i)); + need(sliced->peakPitchLagWork()<=8&& + sliced->peakPitchLagWork()>0, + "P0 worst-case lag slice exceeded eight"); + need(sliced->completedPitchAnalyses()>=20 && + sliced->abandonedPitchAnalyses()==0, + "P0 correlation hop overwritten on supported device"); + need(sliced->voiced() && sliced->observedMidiNote()==57, + "P0 sliced note lost in a supported rate/block configuration"); + } + } + // P0 defensive PCM: no allocation/crash/NaN from extreme finite, + // infinity or NaN, including during the silence->singer transition. + for(int voiceCount:{2,5}){ + auto overflow=std::make_unique(); + need(overflow->prepare(48000.),"P0 extreme PCM prepare failed"); + Settings full;full.wet=1.f;full.voices=voiceCount;full.correction=true; + need(overflow->setSettings(full),"P0 extreme PCM settings rejected"); + constexpr int frames=8192; + std::vector l(frames),r(frames); + for(int i=0;i::max(): + j==1?-std::numeric_limits::max(): + j==2?std::numeric_limits::infinity(): + j==3?-std::numeric_limits::infinity(): + j==4?std::numeric_limits::quiet_NaN(): + j==5?4.5f:j==6?-4.5f:0.f; + l[static_cast(i)]=raw; + r[static_cast(i)]=-raw; + } + for(int i=0;iprocess(l.data()+i,r.data()+i,std::min(64,frames-i)); + for(int i=0;i(i)]) && + std::isfinite(r[static_cast(i)]) && + std::abs(l[static_cast(i)])<=4.f && + std::abs(r[static_cast(i)])<=4.f, + "P0 extreme PCM yielded invalid or out-of-bounds output"); + } + // Direct analysis-only stereo fold must never produce NaN/inf even if a + // connected host provides a finite float close to FLT_MAX. + StereoPhaseSafeFold guard; + need(guard.prepare(48000.),"P0 stereo analysis fold prepare failed"); + for(int i=0;i<4096;++i){ + const float huge=std::numeric_limits::max(); + const float y=guard.process(huge,huge); + need(std::isfinite(y)&&std::abs(y)<=4.f, + "P0 guide PCM overflowed in stereo analysis fold"); + } + + // P1 natural ensemble: each singer owns a distinct stable arrival time, + // vibrato phase/rate and early-reflection history. No heap or random PCM + // work is introduced, and reflections must not bleed between singers. + for(double rate:{32000.,48000.,96000.,192000.}){ + auto ensemble=std::make_unique(); + need(ensemble->prepare(rate),"ensemble prepare rejected supported rate"); + need(ensemble->arrivalSamples(0)>0.f&& + ensemble->arrivalSamples(2)>ensemble->arrivalSamples(1), + "independent singer onset offsets not prepared"); + need(ensemble->reflectionSamples(4)( + EnsembleSpace::reflectionCapacity), + "highest-rate reflection would read outside fixed history"); + const int delay=ensemble->reflectionSamples(0); + for(int i=0;i<=delay+5;++i){ + for(int v=0;vexchangeReflection(v,input); + const float expected=(i==delay&&v==0)?1.f:0.f; + need(std::abs(out-expected)<1.e-6f, + "ensemble reflection delay or channel isolation broken"); + } + ensemble->advance(true); + } + float minRatio=2.f,maxRatio=0.f; + const int sustain=static_cast(rate*.60); + for(int i=0;ipitchRatio(0); + const float b=ensemble->pitchRatio(1); + need(std::isfinite(a)&&std::isfinite(b)&&a>.996f&&a<1.004f&& + b>.996f&&b<1.004f, + "ensemble vibrato/detune exceeds transparent musical bounds"); + minRatio=std::min(minRatio,a);maxRatio=std::max(maxRatio,a); + ensemble->advance(true); + } + need(maxRatio-minRatio>0.0004f, + "ensemble vocalist lacks independent sustain modulation"); + ensemble->advance(false); + } + // At Space=0 mono input stays mono with no reflected crossfeed. At + // Space=1, three distinct backing singers must form true stereo PCM, + // while the singer's dry path keeps its declared delay and center. + for(double rate:{48000.,96000.}){ + constexpr int samples=48000; + std::vector zeroL(samples),zeroR(samples); + std::vector wideL(samples),wideR(samples); + auto center=std::make_unique(); + auto wide=std::make_unique(); + need(center->prepare(rate)&&wide->prepare(rate), + "ensemble space engine prepare failed"); + Settings narrow; narrow.voices=3;narrow.wet=.6f;narrow.space=0.f; + Settings spread=narrow;spread.space=1.f; + need(center->setSettings(narrow)&&wide->setSettings(spread), + "ensemble controls not accepted"); + for(int i=0;i(.16*std::sin( + 6.283185307179586*220.*i/rate)+.05*std::sin( + 6.283185307179586*440.*i/rate)); + zeroL[static_cast(i)]=zeroR[static_cast(i)]=x; + wideL[static_cast(i)]=wideR[static_cast(i)]=x; + } + for(int i=0;iprocess(zeroL.data()+i,zeroR.data()+i,len); + wide->process(wideL.data()+i,wideR.data()+i,len); + } + double centerDifference=0.,spreadDifference=0.,wideEnergy=0.,foldEnergy=0.; + for(int i=samples/2;i(i)]- + zeroR[static_cast(i)]); + spreadDifference+=std::abs(wideL[static_cast(i)]- + wideR[static_cast(i)]); + const double x=.5*(wideL[static_cast(i)]+ + wideR[static_cast(i)]); + wideEnergy+=wideL[static_cast(i)]* + wideL[static_cast(i)]+ + wideR[static_cast(i)]* + wideR[static_cast(i)]; + foldEnergy+=x*x; + } + need(centerDifference<.0001, + "Space zero leaked phase-widened stereo or unbalanced rooms"); + need(spreadDifference>0.5&&wideEnergy>1.&&foldEnergy>.1, + "ensemble room has no stereo depth or loses mono compatibility"); + } + + // Field feedback: full Wet, 4 voices, Space 60% still sounded thin. + // Presence curve must lift BACKING only, with sqrt voice count normalization + // and exact Wet0 silence; all scalar math is prepared on control thread. + for(int voices=2;voices<=Engine::maxVoices;++voices){ + float previous=0.f; + for(float wet:{0.f,.15f,.45f,.60f,.85f,1.f}){ + const float modern=Engine::normalizedBackingWetAmplitude(wet,voices); + const float legacy=Engine::normalizedBackingWetAmplitude(wet,voices,false); + need(std::isfinite(modern)&&modern>=previous&& + modern<=1.151f/std::sqrt(static_cast(voices)), + "Harmony wet presence nonmonotone or unbounded"); + if(wet==0.f)need(modern==0.f&&legacy==0.f,"Wet0 leaked harmony"); + if(wet==1.f)need(modern>legacy*1.73f&&modernprior*1.73f,"prepared Harmony pan lost presence or normalization"); + } + } + // P0 lead preservation: backing Wet must never change the lead amplitude. + // The *only* intentional lead replacement is Pitch Tune's explicit blend. + for(float dry:{-.9f,-.3f,0.f,.27f,.9f}){ + need(Engine::leadPath(dry,.5f,0.f)==dry, + "wet-independent original lead unexpectedly ducked"); + need(std::abs(Engine::leadPath(dry,.5f,.5f)-(.5f*dry+.25f))<1.e-6f, + "explicit Pitch Tune blend changed"); + } + + // P1 diffuse shared BACKING room: no immediate output, fixed delay at + // all accepted rates, decaying rather than metallic or unstable feedback. + for(double rate:{32000.,44100.,48000.,96000.,192000.}){ + auto room=std::make_unique(); + need(room->prepare(rate),"backing room rejected supported sample rate"); + for(std::size_t v=0;vdelaySamples(v)>0&& + room->delaySamples(v)feedbackGain(v)>0.f&&room->feedbackGain(v)<1.f, + "backing FDN missing bounded delays or stable feedback"); + const int total=static_cast(rate*1.8); + double first=0.,late=0.,last=0.,mono=0.; + for(int i=0;iprocess(i==0?1.f:0.f,i==0?1.f:0.f); + need(std::isfinite(o.left)&&std::isfinite(o.right)&& + std::abs(o.left)<2.f&&std::abs(o.right)<2.f, + "backing room blew up or returned non-finite PCM"); + const double energy=o.left*o.left+o.right*o.right; + if(i(rate*.02)) + need(energy<1.e-18,"diffuse field leaked before its first tap"); + if(i(rate*.11))first+=energy; + else if(i(rate*.35))late+=energy; + if(i>static_cast(rate*1.5))last+=energy; + mono+=(.5*(o.left+o.right))*(.5*(o.left+o.right)); + } + need(first>1.e-5&&late>1.e-9&&last1.e-5,"room anti-phase cancelled in mono"); + need(room->prepare(rate),"device restart failed to reset room"); + for(int i=0;i<512;++i){ + const auto o=room->process(0.f,0.f); + need(o.left==0.f&&o.right==0.f, + "room restart retained stale output from previous session"); + } + } + // P1 stereo depth changes must remain audible in mono, but lead should + // stay transparent regardless of Space and Wet when no Pitch Tune. + for(float depth:{0.f,.5f,1.f}){ + EnsembleSpace singer; + need(singer.prepare(48000.),"backing HF shader prepare failed"); + double inputEnergy=0.,outputEnergy=0.; + for(int i=0;i<3000;++i){ + const float pulse=(i%7)<3?1.f:-1.f; + const float shaded=singer.shadeBacking(0,pulse,depth); + inputEnergy+=pulse*pulse; + outputEnergy+=shaded*shaded; + singer.advance(true); + } + need(outputEnergy>0.&&outputEnergy<=inputEnergy*1.01, + "backing distance contour amplified or removed singer"); + if(depth==0.f)need(std::abs(outputEnergy-inputEnergy)<1.e-6, + "Space zero failed to preserve direct backing"); + } + // Declared 48k wet/dry sample PDC must remain 2*16ms even after slicing. + need(e->latencySamples()==1536,"P0 changed live session PDC without proof"); std::cout<<"Native Harmony DSP: deterministic PCM, 2-5 voices, octave/scale, stereo, silence and 32-192k PASS\n"; } diff --git a/tests/harmony_music_bank_test.cpp b/tests/harmony_music_bank_test.cpp index a8ac2ebdb..ba4adbc72 100644 --- a/tests/harmony_music_bank_test.cpp +++ b/tests/harmony_music_bank_test.cpp @@ -73,17 +73,20 @@ int main(){ assert(live->effectiveKeyCode()==14); // music absent: manual D minor juce::MemoryBlock saved; live->getStateInformation(saved); - ChannelHarmonyProcessor restored; + // Realtime processor owns fixed DSP and reflection rings; production + // allocates FX instances on heap. Two stack-local processors overflow + // the default Windows 1 MiB CTest stack after stage-reflection growth. + auto restored=std::make_unique(); // Production NativeMixerSessionFxRestore prepares first, then restores. // Source must be armed at the actual DSP input, not just in accepted UI. - restored.prepareToPlay(48000.,128); - assert(restored.isReady()); - assert(restored.restoreUnpublishedState(saved.getData(), + restored->prepareToPlay(48000.,128); + assert(restored->isReady()); + assert(restored->restoreUnpublishedState(saved.getData(), static_cast(saved.getSize()))); - assert(restored.acceptedSettings().guideMode==1); - assert(restored.acceptedSettings().guideChannelId==music.value); - assert(restored.musicSourceChannel()==music.value); - assert(restored.observedMusicKey()==-1); // no stale old-device estimate + assert(restored->acceptedSettings().guideMode==1); + assert(restored->acceptedSettings().guideChannelId==music.value); + assert(restored->musicSourceChannel()==music.value); + assert(restored->observedMusicKey()==-1); // no stale old-device estimate // Version-1 state still loads as Manual Key with no source binding. juce::MemoryBlock old; { @@ -97,14 +100,14 @@ int main(){ writer.writeFloat(.5f);writer.writeFloat(0.f); } assert(old.getSize()>0); - ChannelHarmonyProcessor migrated; - migrated.prepareToPlay(48000.,128); - assert(migrated.isReady()); - assert(migrated.restoreUnpublishedState(old.getData(), + auto migrated=std::make_unique(); + migrated->prepareToPlay(48000.,128); + assert(migrated->isReady()); + assert(migrated->restoreUnpublishedState(old.getData(), static_cast(old.getSize()))); - assert(migrated.acceptedSettings().guideMode==0); - assert(migrated.acceptedSettings().guideChannelId==0); - assert(migrated.musicSourceChannel()==0); + assert(migrated->acceptedSettings().guideMode==0); + assert(migrated->acceptedSettings().guideChannelId==0); + assert(migrated->musicSourceChannel()==0); // Music-source retarget must not bleed the old channel's guide into the // new source. After switching to Manual the other-channel PCM must never // change the selected manual key. A third row owns no FX and no audible WIRE. @@ -146,7 +149,11 @@ int main(){ std::sin(6.28318530718*261.625565*t)+ std::sin(6.28318530718*329.627557*t))); } + // Real anti-phase other-channel PCM remains unmodified by the guide. + for(int j=0;j<128;++j)r[j]=-l[j]; + const float originalL=l[17],originalR=r[17]; bank2(musicB,l,r,128); + assert(l[17]==originalL&&r[17]==originalR); } assert(live->observedMusicKey()==9&&live->observedMusicScale()==1); assert(live->effectiveKeyCode()==21); // detected A minor diff --git a/tests/harmony_music_key_test.cpp b/tests/harmony_music_key_test.cpp index 03b65317e..a7a108365 100644 --- a/tests/harmony_music_key_test.cpp +++ b/tests/harmony_music_key_test.cpp @@ -12,7 +12,7 @@ static void need(bool test,const char* reason){ if(!test){std::cerr<& pitches,double seconds){ + const std::vector& pitches,double seconds,int partition=127){ const int size=static_cast(seconds*sampleRate); std::vector left(static_cast(size)); std::vector right(static_cast(size)); @@ -24,10 +24,29 @@ static void sendChord(MusicKeyDetector& detector,double sampleRate, left[static_cast(i)]=static_cast(sample); right[static_cast(i)]=static_cast(sample); } - for(int pos=0;pos 0.10: valid 0.045..0.10 candidates could NEVER take over. + // Exercise the exact policy independently of spectral fixture sensitivity. + need(!acceptMusicKeyCandidate(true,false,.07f,7), + "weak music key changed before required hold"); + need(!acceptMusicKeyCandidate(true,false,.07f,12), + "moderate-confidence music key changed prematurely"); + need(!acceptMusicKeyCandidate(true,false,.07f,19), + "moderate-confidence music key changed before stable hold"); + need(acceptMusicKeyCandidate(true,false,.07f,20), + "stable moderately confident new music key stayed stuck forever"); + need(acceptMusicKeyCandidate(true,false,.12f,8), + "strong new key did not switch after initial stable hold"); + need(acceptMusicKeyCandidate(false,false,.06f,8), + "initial key was not acquired after stable hold"); + need(acceptMusicKeyCandidate(true,true,.06f,8), + "accepted key confidence update incorrectly blocked"); + MusicKeyDetector bad; need(!bad.prepare(8000.)&&!bad.prepare(384000.),"unsafe sample rate accepted"); for(const double rate:{48000.,96000.}){ @@ -37,6 +56,12 @@ int main(){ need(estimate.valid()&&estimate.key==0&&estimate.scale==0, "C-major music track did not produce stable C major"); need(estimate.confidence>=.045f,"C-major confidence lower than acceptance"); + need(c.peakKeyScoresPerSample()>0 && + c.peakKeyScoresPerSample()<=MusicKeyDetector::maxKeyScoresPerDecimatedSample, + "music key correlation burst exceeded bounded audio sample budget"); + need(c.peakRotorNormalizationsPerSample()>0 && + c.peakRotorNormalizationsPerSample()<=MusicKeyDetector::maxRotorNormalizationsPerDecimatedSample, + "music rotor maintenance burst exceeded audio sample budget"); // Source-channel silence invalidates old guidance; Manual is safe. sendChord(c,rate,{0.},1.4); need(!c.estimate().valid(),"silent music source kept stale key"); @@ -46,6 +71,55 @@ int main(){ need(estimate.valid()&&estimate.key==9&&estimate.scale==1, "A-minor music track did not identify natural minor"); am.reset();need(!am.estimate().valid(),"channel retarget retained stale key"); + // Extreme polarity-inverted stereo music still contains C-major PCM. + MusicKeyDetector opposed; + need(opposed.prepare(rate),"opposed music prepare failed"); + const int frames=static_cast(rate*3.5); + std::vector invL(static_cast(frames)); + std::vector invR(static_cast(frames)); + for(int i=0;i(i)/rate; + const float v=static_cast(.09*( + std::sin(6.283185307179586*261.625565*t)+ + std::sin(6.283185307179586*329.627557*t)+ + std::sin(6.283185307179586*391.995436*t))); + invL[static_cast(i)]=v; + invR[static_cast(i)]=-v; + } + for(int i=0;i A minor -> disconnected guide -> C + // major again, with alternate 64/127/256 ASIO-like partitions. This was + // missing from the old one-key-per-detector tests and catches stale-key + // revisions as well as callback-grain dependence. + for(int chunk:{64,127,256}){ + MusicKeyDetector live; + need(live.prepare(48000.),"transition music preparation failed"); + sendChord(live,48000.,{261.625565,329.627557,391.995436},4.5,chunk); + const auto c=live.estimate(); + need(c.valid()&&c.key==0&&c.scale==0, + "C major not acquired in live music transition sequence"); + sendChord(live,48000.,{220.,261.625565,329.627557},5.0,chunk); + const auto a=live.estimate(); + need(a.valid()&&a.key==9&&a.scale==1, + "new A minor key did not replace C major after stable evidence"); + sendChord(live,48000.,{0.},1.4,chunk); + need(!live.estimate().valid(),"stopped guide retained an obsolete key"); + sendChord(live,48000.,{261.625565,329.627557,391.995436},3.5,chunk); + const auto restarted=live.estimate(); + need(restarted.valid()&&restarted.key==0&&restarted.scale==0, + "music restarted on a different key failed to reacquire"); + need(live.peakKeyScoresPerSample()== + MusicKeyDetector::maxKeyScoresPerDecimatedSample, + "tiled tonal evaluation did not exercise its work budget"); } // Manual Key stays unchanged when the music detector has no evidence; // selection is an audio-thread-only, valid other-ChannelId control packet. diff --git a/tests/harmony_pitch_synchronous_test.cpp b/tests/harmony_pitch_synchronous_test.cpp new file mode 100644 index 000000000..97477cda2 --- /dev/null +++ b/tests/harmony_pitch_synchronous_test.cpp @@ -0,0 +1,81 @@ +#include "../engine/builtin_fx/HarmonyPitchSynchronous.h" +#include +#include +#include +#include +#include +#include +using armix::harmony::PitchSynchronousVoice; +using Shifter=PitchSynchronousVoice<16384,6>; +static void need(bool yes,const char* reason){ + if(!yes){std::cerr< render(double rate,double f0,double ratio,int block){ + auto p=Shifter{}; + std::array ring{}; + const int n=static_cast(rate*.65); + std::vector out(static_cast(n)); + for(int pos=0;pos(t)&16383]=static_cast( + .19*std::sin(phase)+.052*std::sin(2*phase+.31)+ + .029*std::sin(3*phase+.17)); + const auto sample=p.process(0,t,static_cast(t)&16383,ring, + static_cast(rate/f0),static_cast(ratio), + static_cast(rate*.032)); + out[static_cast(t)]=sample.sample; + need(std::isfinite(sample.sample)&&std::abs(sample.sample)<2.f, + "synchronous output nonfinite/unbounded"); + } + return out; +} +static double measuredHz(const std::vector& signal,double rate,double wanted){ + const int begin=static_cast(rate*.27); + const int length=static_cast(rate*.23); + const int low=static_cast(rate/(wanted*1.05)); + const int high=static_cast(rate/(wanted*.95)); + double best=-100.;int lag=0; + for(int d=low;d<=high;++d){ + double numerator=0,energy=0; + for(int t=begin;t(t)]* + signal[static_cast(t-d)]; + energy+=signal[static_cast(t)]* + signal[static_cast(t)]; + } + if(numerator/(energy+1.e-20)>best){ + best=numerator/(energy+1.e-20);lag=d; + } + } + need(best>.6&&lag>0,"synchronous source lost periodicity"); + return rate/lag; +} +int main(){ + // Actual source-period pitch shifting, not just a sine-wave finite test. + // Three original harmonics approximate one voiced source; FFT/formant and + // actual adult singer evidence are still necessary before quality claims. + for(const auto& v:std::array,5>{{ + {{48000.,220.,1.5}},{{48000.,220.,.667}}, + {{48000.,82.40689,1.2}},{{96000.,440.,.75}}, + {{192000.,880.,1.4}} + }}){ + const auto a=render(v[0],v[1],v[2],64); + const auto b=render(v[0],v[1],v[2],257); + need(a.size()==b.size(),"different source length"); + for(std::size_t i=0;i silence{}; + need(!bad.process(0,0,0,silence,0.f,1.f,1536.f).ready, + "invalid F0 accepted"); + need(!bad.process(0,100,100,silence,3200.f,1.f,1536.f).ready, + "insufficient host latency accepted"); + std::cout<<"bounded source windows and block parity passed\n"; +} diff --git a/tests/harmony_stage_spatial_test.cpp b/tests/harmony_stage_spatial_test.cpp new file mode 100644 index 000000000..a1935f73e --- /dev/null +++ b/tests/harmony_stage_spatial_test.cpp @@ -0,0 +1,169 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#include "../engine/builtin_fx/HarmonyStageSpatial.h" +#include "../engine/builtin_fx/HarmonyRoomFocus.h" +#include "../engine/builtin_fx/HarmonyEnsembleSpace.h" +#include "../engine/builtin_fx/HarmonyDsp.h" +#include +#include +#include +#include +#include +#include +using namespace armix::harmony; +static void need(bool b,const char* reason) { + if(!b){std::cerr<(); + auto stage=std::make_unique(); + need(e->prepare(rate)&&stage->prepare(rate),"stage prepare failed"); + need(stage->farEarDelaySamples()>=2,"missing far-ear cue"); + need(e->secondReflectionSamples(singer)>e->reflectionSamples(singer), + "secondary reflection not after first"); + const float pan=.72f*space*(2.f*singer/(voices-1)-1.f); + const float angle=(pan+1.f)*3.14159265358979323846f*.25f; + const float ml=std::cos(angle),mr=std::sin(angle); + const auto g=BackingStageSpatial::gains(space); + SceneEnergy x{}; + for(int i=0;i(rate*.16);++i){ + const float input=i==0?.7f:0.f; + const float a=e->exchangeReflection(singer,input); + const float b=e->secondReflection(singer); + const auto p=stage->place(singer,input,a,b,ml,mr,space); + const double dl=p.directL*g.direct,dr=p.directR*g.direct; + const double rl=p.earlyL*g.early,rr=p.earlyR*g.early; + x.direct+=dl*dl+dr*dr;x.early+=rl*rl+rr*rr; + x.mono+=.25*(dl+dr+rl+rr)*(dl+dr+rl+rr); + x.stereo+=(dl+rl-dr-rr)*(dl+rl-dr-rr); + need(std::isfinite(dl)&&std::isfinite(dr)&& + std::isfinite(rl)&&std::isfinite(rr),"nonfinite stage PCM"); + e->advance(true);stage->advance(); + } + need(x.direct>.001&&x.mono>.0001,"backing collapsed in mono"); + if(space==0.f)need(x.early==0.,"Space 0 leaked reflection"); + else need(x.early>1.e-5,"room reflection inaudible"); + return x; +} +static std::vector render(int block,float space,bool wet){ + auto e=std::make_unique(); + need(e->prepare(48000.),"native engine prepare"); + Settings s;s.voices=3;s.wet=wet?.65f:0.f;s.space=space; + need(e->setSettings(s),"engine settings invalid"); + constexpr int n=24000; + std::vector l(n),r(n); + for(int i=0;i(.18*std::sin(p)+.045*std::sin(2*p)); + r[i]=static_cast(.12*std::sin(p)+.07*std::sin(3*p)); + } + for(int i=0;iprocess(l.data()+i,r.data()+i,std::min(block,n-i)); + for(float value:l)need(std::isfinite(value),"render nonfinite"); + need(e->latencySamples()==1536,"native PDC changed"); + return l; +} + +// Separate synthetic frequency-band check for the modest head-shadow cue. +// Compare far/near energy at 350 Hz and 8 kHz while keeping pan and Space +// constant. Not a binaural localization or human HRTF listening test. +static double farNearRatio(double rate,double frequency,float space){ + BackingStageSpatial stage; + need(stage.prepare(rate),"head shadow rate prepare failed"); + const int frames=static_cast(rate*.09); + double nearEnergy=0.,farEnergy=0.; + for(int t=0;t(.4*std::sin( + 6.283185307179586*frequency*t/rate)); + const auto p=stage.place(0,input,0.f,0.f,.28f,.96f,space); + if(t>static_cast(rate*.04)){ + // Compare against direct ear gains to remove normal panning. + nearEnergy+=(p.directR/.96f)*(p.directR/.96f); + farEnergy+=(p.directL/.28f)*(p.directL/.28f); + } + stage.advance(); + } + need(nearEnergy>1.e-5&&farEnergy>0.,"head shadow null output"); + return farEnergy/nearEnergy; +} +// Synthetic room clarity and phrase-envelope proof, not real singer listening. +static double focusEnergy(double rate,double hz){ + BackingRoomFocus f;need(f.prepare(rate),"room focus rate"); + const int n=static_cast(rate*.16);double sum=0.; + for(int i=0;i(.3*std::sin( + 6.283185307179586*hz*i/rate)); + const auto s=f.filterSend(x,x); + need(std::isfinite(s.left)&&std::isfinite(s.right),"room finite"); + if(i>n/2)sum+=s.left*s.left; + } + return sum/(n/2); +} +static void focusTest(double rate){ + BackingRoomFocus f;need(f.prepare(rate),"room init"); + need(focusEnergy(rate,75.)(rate*.35);++i){ + const float g=f.returnGain(.40f,.40f,1.f); + need(g>.78f&&g<=1.f&&std::abs(g-last)<.003f, + "room level jump or overduck");last=g; + } + need(last<.85f,"room activity follower inactive"); + need(f.returnGain(.4f,.4f,0.f)==1.f,"Space0 room not neutral"); + for(int i=0;i(rate*1.5);++i) + last=f.returnGain(0.f,0.f,1.f); + need(last>.995f&&last<=1.f,"room tail did not bloom in gaps"); + need(f.prepare(rate)&&f.leadEnvelope()==0.f,"room restart stale envelope"); + need(f.filterSend(0.f,0.f).left==0.f&& + f.returnGain(0.f,0.f,1.f)==1.f,"room restart stale sample"); +} +int main(){ + for(double rate:{32000.,44100.,48000.,96000.,192000.}){ + focusTest(rate); + double previous=-1.; + for(float space:{.25f,.6f,1.f}){ + const auto left=scene(rate,space,0,3); + const auto relative=left.early/left.direct; + need(relative>previous,"Space no longer lowers direct/reflected energy ratio"); + previous=relative; + need(left.stereo>1.e-5,"left image collapsed to mono"); + const auto center=scene(rate,space,1,3); + const auto right=scene(rate,space,2,3); + need(center.mono>.0001&&right.mono>.0001,"other voices lost in mono"); + } + scene(rate,0.f,0,3); + scene(rate,.8f,4,5); + } + // A center harmony voice competes directly with the lead phantom center. + // Center-only direct recession is modest; its room send remains intact. + for(double rate:{48000.,96000.,192000.}){ + BackingStageSpatial x; + need(x.prepare(rate),"center recession prepare failed"); + auto zero=x.place(1,.5f,0.f,0.f,.5f,.5f,0.f); + x.advance(); + auto deep=x.place(1,.5f,0.f,0.f,.5f,.5f,1.f); + need(std::abs(zero.directL-.25f)<1.e-6f&& + std::abs(zero.roomL-.25f)<1.e-6f, + "Space0 center direct changed"); + need(deep.directLdeep.roomL*.80f, + "center backing direct did not move behind lead"); + need(std::abs(deep.roomL-.25f)<1.e-6f, + "center stage lost shared-room input"); + const double low=farNearRatio(rate,350.,1.f); + const double high=farNearRatio(rate,8000.,1.f); + need(high.08,"far ear over-attenuated or disappeared"); + need(std::abs(farNearRatio(rate,350.,0.f)-1.)<.015, + "Space zero changed neutral stereo signal"); + need(std::abs(farNearRatio(rate,8000.,0.f)-1.)<.015, + "Space zero changed high-frequency signal"); + } + for(float space:{0.f,.6f,1.f}) + need(render(64,space,true)==render(257,space,true), + "callback partition affected spatial audio"); + need(render(64,0.f,false)==render(257,1.f,false), + "Space changed true lead at Wet0"); + std::cout<<"Harmony stage depth, reflections, mono, PDC and parity PASS\n"; +} diff --git a/tests/independent_clock_adapter_contract_test.mjs b/tests/independent_clock_adapter_contract_test.mjs index 8d113a649..705cb1be9 100644 --- a/tests/independent_clock_adapter_contract_test.mjs +++ b/tests/independent_clock_adapter_contract_test.mjs @@ -161,7 +161,7 @@ test('P0 ASIO live direct route fence blocks hotplug substitution before DSP',() assert.match(engine,/directSuppressedFrames_\.fetch_add/); assert.match(engine,/directRouteProtection/); assert.match(host,/engine_\.beginManualAudioSetup\(\)/); - assert.match(host,/engine_\.finishManualAudioSetup\(\)/); + assert.match(host,/engine_\.finishManualAudioSetup\(bindingMode!=MixerBindingMode::verifiedMainPinApply\)/); assert.match(host,/engine_\.directRouteAuthorized\(\)/); }); diff --git a/tests/juce_active_port_snapshot_test.cpp b/tests/juce_active_port_snapshot_test.cpp index b4e76b976..06fd698b7 100644 --- a/tests/juce_active_port_snapshot_test.cpp +++ b/tests/juce_active_port_snapshot_test.cpp @@ -40,10 +40,15 @@ int main(){ out.clear(); assert(!JuceActivePortSnapshot::fromMasks(12,in,out,snap,fault)); assert(fault==JuceActivePortSnapshot::Fault::emptyOutput); - in.clear(); - assert(!JuceActivePortSnapshot::fromMasks(12,in,out,snap,fault)); - assert(fault==JuceActivePortSnapshot::Fault::emptyInput); - assert(snap.inputs.callbackIndex(9)==previous.inputs.callbackIndex(9)); + in.clear();out.setBit(1);out.setBit(7); + assert(JuceActivePortSnapshot::fromMasks(12,in,out,snap,fault)); + assert(snap.inputs.enabledCount==0); + assert(snap.matchesCallback(12,0,2)); + assert(!snap.matchesCallback(12,1,2)); + out.clear(); + assert(!JuceActivePortSnapshot::fromMasks(13,in,out,snap,fault)); + assert(fault==JuceActivePortSnapshot::Fault::emptyOutput); + assert(snap.inputs.callbackIndex(9)==-1); // failed 0-OUT preserves accepted zero-input snapshot assert(!JuceActivePortSnapshot::capture(nullptr,12,snap,fault)); assert(fault==JuceActivePortSnapshot::Fault::nullDevice); } diff --git a/tests/live_graph_contract_test.mjs b/tests/live_graph_contract_test.mjs index 77df0958a..dad4468c4 100644 --- a/tests/live_graph_contract_test.mjs +++ b/tests/live_graph_contract_test.mjs @@ -195,7 +195,7 @@ test('R0B B3 preserves diagnostic isolation without exposing an accepted patch', assert.match(diagnostic,/dryRoutingLab_\.disable\(\)/); assert.match(diagnostic,/startUnpatchedProductionSession\(\)/); assert.match(diagnostic,/resumeVerifiedDirectRoute\(\)/); - const manual=e.slice(e.indexOf('void beginManualAudioSetup()'), + const manual=e.slice(e.indexOf('void beginManualAudioSetup('), e.indexOf('bool independentClockActive()')); assert.match(manual,/setOutputMuted\(true\)/); assert.match(manual,/secondaryOutput_\.disarm\(\)/); diff --git a/tests/mixer_io_operator_contract_test.mjs b/tests/mixer_io_operator_contract_test.mjs index 11176a98e..81bcf28f9 100644 --- a/tests/mixer_io_operator_contract_test.mjs +++ b/tests/mixer_io_operator_contract_test.mjs @@ -202,9 +202,16 @@ test('DEVICE1 existing matrix drives real JUCE manager with gated native readbac for(const flag of ['JUCE_ASIO=1','JUCE_WASAPI=1','JUCE_DIRECTSOUND=1'])assert.ok(cm.includes(flag)); assert.match(native,/manager, 1, 64, 1, 64, false, false, false, false/); // hidden fallback only assert.match(native,/action == "audioDeviceApply"/); - assert.match(native,/setAudioDeviceSetup\(candidate,true\)/); + const open=native.slice(native.indexOf('juce::String openSelectedAudioDevice('), + native.indexOf('void applyCustomAudioDevice(')); + assert.match(native,/openSelectedAudioDevice\(typeName,candidate\)/); + assert.match(native,/openSelectedAudioDevice\(previousType,before\)/); + assert.match(open,/setAudioDeviceSetup\(setup,true\)/); + assert.match(open,/manager\.initialise\(2,2,xml\.get\(\),false\)/); + assert.match(open,/manager\.closeAudioDevice\(\);[\s\S]*manager\.initialise/); + assert.doesNotMatch(open,/manager\.setCurrentAudioDeviceType\(/); assert.match(native,/beginManualAudioSetup\(\)/); - assert.match(native,/finishManualAudioSetup\(\)/); + assert.match(native,/finishManualAudioSetup\(bindingMode!=MixerBindingMode::verifiedMainPinApply\)/); assert.match(native,/RESTORED_MUTED/); assert.match(native,/RECOVERY_REQUIRED/); assert.match(native,/arMixAudioDeviceApplyAck/); @@ -220,10 +227,15 @@ test('DEVICE1 existing matrix drives real JUCE manager with gated native readbac test('explicit device Apply restores the authored mixer after driver readback and can roll back',()=>{ const main=read('src/Main.cpp'); const apply=main.slice(main.indexOf('void applyCustomAudioDevice('),main.indexOf('void showDeviceSetup()')); - assert.match(apply,/if\(error\.isEmpty\(\)&&!finishAudioSetupAndRecoverMixer\(true\)\)/); + assert.match(apply,/if\(error\.isEmpty\(\)&&!finishAudioSetupAndRecoverMixer\(bindingMode\)\)/); assert.match(apply,/if\(!previousMixerBound && engine_\.directRouteAuthorized\(\)/); assert.match(apply,/finishAudioSetupAndRecoverMixer\(\);/); - assert.match(main,/BindingMode::verifiedDeviceApply:BindingMode::exact/); + assert.match(apply,/explicitPairStillIdentified\?MixerBindingMode::verifiedMainPinApply/); + assert.match(apply,/pinOutput.getArray\(\)->size\(\)!=2/); + assert.match(main,/restoreSavedMixerSession\(false,bindingMode\)/); + assert.match(apply,/if\(refreshedAsio4All\) \{[\s\S]*?openSelectedAudioDevice\(typeName,candidate,true\)/); + assert.match(main,/epoch==asioRecoveryEpoch_/); + assert.match(main,/authorizeRetainedAsioRestart\(\)[\s\S]*?restoreSavedMixerSession\(false,MixerBindingMode::verifiedAsioRestart\)/); }); test('SETUP1 honest bus patch has real AUX/MAIN/MONITOR navigation, no fake GROUP DCA',()=>{ @@ -585,3 +597,50 @@ test('hardware input CH1/CH2/CH10 selectable on the mixer itself without an IO m assert.match(css,/\.arChannelQuickInput\{/); assert.doesNotMatch(css,/backdrop-filter|filter:blur/); }); + +// Recovery regression: a transient ASIO4ALL reopen must not consume the +// only opportunity to bind the retained ChannelId PCM graph. +test('ASIO4ALL automatic rebind has bounded retries, succeeds only after verified readback',()=>{ + const src=read('src/Main.cpp'); + const service=src.slice(src.indexOf('void serviceAsioMixerRestart()'),src.indexOf('void changeListenerCallback (')); + assert.match(service,/asioRecoveryGate_\.observeEpoch\(epoch,now\)/); + assert.match(service,/asioRecoveryGate_\.due\(now\)/); + assert.match(service,/asioRecoveryGate_\.mayChangeDriver\(\)/); + assert.match(service,/asioRecoveryGate_\.driverTransaction\(now\)/); + assert.match(service,/asioRecoveryGate_\.carryInternalEpoch\(engine_\.dryRoutingLabEpoch\(\)\)/); + assert.match(service,/asioRecoveryGate_\.bindFailed\(now\)/); + assert.match(service,/audioSetupWindow_->isVisible\(\)/); + assert.match(service,/restoreSavedMixerSession\(false,MixerBindingMode::verifiedAsioRestart\)/); + assert.match(service,/asioRecoveryEpoch_=engine_\.dryRoutingLabEpoch\(\)/); + assert.match(service,/setup\.useDefaultInputChannels=!setup\.inputChannels\.isZero\(\)/); + const apply=src.slice(src.indexOf('void applyCustomAudioDevice('),src.indexOf('void showDeviceSetup()')); + assert.doesNotMatch(apply,/asioRecoveryEpoch_=engine_\.dryRoutingLabEpoch\(\);\s*if\(changedAsioPinLayout\)/); +}); + +test('ASIO4ALL missing JUCE device can reopen only the pinned user-selected driver',()=>{ + const main=read('src/Main.cpp'),engine=read('src/LiveAudioEngine.h'); + const service=main.slice(main.indexOf('void serviceAsioMixerRestart()'), + main.indexOf('void changeListenerCallback (')); + assert.match(service,/else if\(!engine_\.selectedRetainedAsioDriverForReopen\(\)\)/); + assert.match(service,/if\(!device \|\| !device->isOpen\(\)/); + assert.match(service,/ASIO4ALL_DEVICE_MISSING/); + const selected=engine.slice(engine.indexOf('bool selectedRetainedAsioDriverForReopen()'), + engine.indexOf('bool authorizeRetainedAsioRestart()')); + assert.match(selected,/deviceManager_\.getCurrentAudioDevice\(\)/); + assert.match(selected,/deviceManager_\.getCurrentAudioDeviceType\(\)!="ASIO"/); + assert.match(selected,/Policy::isAsio4All\(\*acceptedMixerBinding_\)/); + assert.match(selected,/setup\.outputDeviceName!=acceptedMixerBinding_->playback/); + assert.match(selected,/setup\.inputDeviceName!=acceptedMixerBinding_->capture/); + assert.match(selected,/asioPinnedRegistration_\.sameDriverClass\(registered\.registration\.identity\)/); +}); + +test('ASIO restart cannot strand MAIN off after temporary graph readiness faults',()=>{ + const main=read('src/Main.cpp'),engine=read('src/LiveAudioEngine.h'); + const arm=main.slice(main.indexOf('void serviceAutomaticMain()'),main.indexOf('void requestAutomaticMain(')); + assert.ok(arm.indexOf('liveOutputArmFault(autoMainRequiresInput_)')< + arm.indexOf('autoMainCheckedRevision_=revision;'),'only a verified ARM consumes the revision'); + const begin=engine.slice(engine.indexOf('void audioDeviceAboutToStart ('),engine.indexOf('void audioDeviceStopped()')); + assert.match(begin,/if\(monitor_\.load\(std::memory_order_acquire\)\)/); + assert.match(begin,/resumeMainAfterAsioReset_\.store\(true/); + assert.ok(begin.indexOf('resumeMainAfterAsioReset_.store(true') fs.readFileSync(path.join(root, p), 'utf8'); +const main = read('src/Main.cpp'), chrome = read('src/ArSonWindowChrome.h'); +const page = read('site/preview-v2/index.html'); +const css = read('site/preview-v2/assets/mixer-chrome-material.css'); +const bridge = read('web/approved-native-bridge.js'); +assert.match(main, /setLookAndFeel \(&mixerCaption_\)/); +assert.match(main, /setUsingNativeTitleBar \(false\)/); +assert.match(main, /setTitleBarHeight \(31\)/); +assert.match(main, /setLookAndFeel \(nullptr\)/); +assert.match(chrome, /M6\.4,19L5,17\.6L10\.6,12/); +assert.match(chrome, /M6,21V19H18v2H6Z/); +assert.match(chrome, /M3,21V3H21V21H3Z/); +assert.match(chrome, /constexpr int buttonWidth = 34/); +assert.match(chrome, /12\.0f, 12\.0f/); +assert.match(chrome, /0xffdc3549/); +assert.match(chrome, /0xff168fa7/); +assert.match(chrome, /0xff287abd/); +assert.match(chrome, /drawRoundedRectangle/); +assert.match(chrome, /GlyphArrangement::getStringWidthInt \(brandFont, word\)/); +assert.match(chrome, /paintPart \("Ar", juce::Colour/); +assert.match(chrome, /paintPart \("Son", juce::Colour/); +assert.match(chrome, /paintPart \("MiX", juce::Colour/); +assert.match(chrome, /Open Source Premium Digital Mixer/); +assert.match(chrome, /Version 01\.00/); +assert.match(chrome, /charToString \(\(juce::juce_wchar\) 0x00a9\)/); +assert.match(chrome, /2026 SonKuPik/); +assert.doesNotMatch(chrome, /NATIVE SESSION/); +assert.ok(bridge.includes('classList?.add?.("armix-native-desktop")')); +assert.match(bridge, /const operatorMessage = message =>/); +assert.match(bridge, /const NEEDS_REMAP="Audio connection lost"/); +assert.match(bridge, /MutationObserver\(sanitize\)/); +assert.doesNotMatch(bridge, /FAT PENDING/); +assert.doesNotMatch(bridge, /HARDWARE FAT PENDING/); +assert.match(bridge, /"OUTPUT ENABLED"/); +assert.match(bridge, /status\("Mixer settings updated"\)/); +assert.match(bridge, /element\.textContent=operatorMessage\(message\)/); +assert.match(bridge, /nativeToolbarGroup=name/); +assert.match(bridge, /toolbar\.insertBefore\(divider,element\)/); +assert.match(css, /html\.armix-native-desktop \.app \.command-bar\{\s*height:43px!important/); +assert.match(css, /\.armix-toolbar-divider\{display:none!important\}/); +assert.match(css, /html\.armix-native-desktop \.app > \.window-title\{display:none!important\}/); +assert.match(page, /function scheduleWireGeometryReflow\(\)/); +assert.match(page, /let wireFragmentGeometryDirty=false/); +assert.match(page, /wireMotion\.token;wireMotion\.key=null/); +assert.match(page, /if\(layer\?\.dataset\.edgeId===String\(edge\.id\)&&!wireFragmentGeometryDirty\)return/); +assert.match(page, /new ResizeObserver\(scheduleWireGeometryReflow\)/); +assert.match(page, /if\(drawn&&required!==drawn\)\{/); +assert.match(page, /if\(wireGesture\)\{/); +assert.match(page, /wireGesture=null;wireSuppressClick=true/); +assert.match(page, /if\(faderGesture\)\{/); +assert.match(page, /render\(\); \/\/ structural bank change only/); +assert.match(page, /renderWireRouting\(\); \/\/ geometry-only/); +assert.match(page, /document\.addEventListener\('visibilitychange'/); +assert.doesNotMatch(page, /resizeQueued=false;render\(\)/); +// Reconciled main Player M3 controls must survive the native caption branch. +const playerHtml = read('site/preview-v2/assets/mixer-contextual-buttons.js'); +assert.match(main, /struct PlayerTrackSettings/); +assert.match(main, /action=="playerKeyStep" \|\| action=="playerTempoStep"/); +assert.match(main, /setPlayerPitchTempo\(next\.key,next\.tempo\)/); +assert.match(playerHtml, /id="playerKeyMinus"/); +assert.match(playerHtml, /id="playerTempoPlus"/); +assert.match(playerHtml, /armix-brand-mix/); +console.log('Native titlebar + supplied SVG + WIRE geometry contract PASS'); + +// Runtime scheduler test with fake DOM; no WebView2, no sound engine and no timer. +const vm = require('node:vm'); +// User-visible status copy must never expose internal admission/QA or revision +// codes even if the preview or native error path emits one later. +const messageStart=bridge.indexOf('const operatorMessage = message => {'); +const messageEnd=bridge.indexOf('\n const status = message => {',messageStart); +assert.ok(messageStart>0&&messageEnd>messageStart,'operator copy adapter missing'); +const operatorCopy=vm.runInNewContext( + bridge.slice(messageStart,messageEnd).replace('const operatorMessage','var operatorMessage')+ + '\noperatorMessage;',{}, {filename:'native-operator-copy.js'}); +for(const raw of [ + 'NATIVE PCM · HARDWARE FAT PENDING', + 'NATIVE PCM GRAPH ACCEPTED · FAT PENDING · device 3 · graph 3 · roster 94', + 'NATIVE PENDING_ACCEPTED_SNAPSHOT · awaiting authoritative readback', + 'WIRE not applied · native admission timed out; previous audio preserved', + 'NATIVE: STALE_NATIVE_WIRE_GRAPH · previous controls unchanged', + 'SIMULATED METERS · NO REAL AUDIO', + 'DEVICE_INIT_FAILED', + 'STALE_NATIVE_GRAPH_REVISION', + 'JUCE_CALLBACK_DIAGNOSTIC_FAT_PENDING' +]){ + const shown=operatorCopy(raw); + assert.ok(shown.length>0); + assert.doesNotMatch(shown,/\b(FAT|PCM|ACK|readback|graph|roster|epoch|revision|native|simulated|demo|admission)\b|NATIVE_/i); +} +assert.equal(operatorCopy('Mixer saved as .smix'),'Mixer saved as .smix'); +console.log('Operator-facing footer and toast copy isolation PASS'); +const begin=page.indexOf('// Desktop maximise, restore, DPI changes'); +const end=page.indexOf('restorePluginPreferences();init();',begin); +assert.ok(begin>=0&&end>begin,'geometry scheduler source must exist'); +let drawn=9, required=9, width=800, hidden=false; +let renderCount=0, wireCount=0; +const raf=[], events=new Map(), docEvents=new Map(); +const node={clientWidth:width,clientHeight:600}; +const dom={ + get hidden(){return hidden;}, + getElementById:()=>{node.clientWidth=width;return node;}, + querySelector:()=>({style:{getPropertyValue:()=>String(drawn)}}), + addEventListener:(name,handler)=>docEvents.set(name,handler) +}; +const browser={addEventListener:(name,handler)=>events.set(name,handler)}; +const motion={token:7,key:'stale-edge',offset:3}; +const changed={graph:0,cancelled:0,captureReleased:0}; +class FakeResizeObserver{constructor(handler){this.handler=handler}observe(){}} +const sandbox={ + document:dom,window:browser,ResizeObserver:FakeResizeObserver, + wireGesture:null,faderGesture:null,wireSuppressClick:false, + setWireSnapTarget:()=>changed.cancelled++, + wireMotion:motion,wireFragmentGeometryDirty:false, + requestAnimationFrame:fn=>{raf.push(fn);return raf.length;}, + bankCapacity:()=>required,render:()=>{renderCount++}, + renderWireRouting:()=>{wireCount++;assert.equal(sandbox.wireFragmentGeometryDirty,true);sandbox.wireFragmentGeometryDirty=false;} +}; +vm.runInNewContext(page.slice(begin,end),sandbox,{filename:'wire-reflow-runtime.js'}); +const frame=()=>{assert.equal(raf.length,1);raf.shift()();}; +events.get('resize')();events.get('resize')(); +frame(); +assert.equal(wireCount,1,'two resize events need just one geometry pass'); +assert.equal(motion.token,8,'in-flight wire animation cancels once'); +assert.equal(motion.key,null,'stale wire coordinates are retired'); +assert.equal(renderCount,0,'no full mixer rebuild within a bank'); +required=8;events.get('resize')();frame(); +assert.equal(renderCount,1,'bank boundary requires structural render'); +assert.equal(motion.token,9,'structural resize must also cancel old WIRE motion'); +assert.equal(changed.graph,0,'resize must never commit graph operations'); +// A captured WIRE drag must be retired before a bank's DOM is replaced. +const oldRoot=dom.querySelector; +dom.querySelector=()=>({ + style:{getPropertyValue:()=>String(drawn)}, + classList:{remove:()=>{}}, + querySelectorAll:()=>[{classList:{remove:()=>{}}}], + querySelector:()=>({hasPointerCapture:()=>true,releasePointerCapture:()=>changed.captureReleased++}) +}); +sandbox.wireGesture={pointerId:88,sourceId:5,originDestId:null,active:true}; +required=7;events.get('resize')();frame(); +assert.equal(renderCount,2,'second bank change must still redraw'); +assert.equal(sandbox.wireGesture,null,'detached WIRE drag must be cancelled'); +assert.equal(sandbox.wireSuppressClick,true,'late click must not create a route'); +assert.equal(changed.cancelled,1,'snap outline must be cleared once'); +assert.equal(changed.captureReleased,1,'native pointer capture must be released'); +dom.querySelector=oldRoot; +drawn=7; // simulate the structural render committing its new bank geometry +hidden=true;events.get('resize')(); +assert.equal(raf.length,0,'hidden window must not repaint'); +hidden=false;docEvents.get('visibilitychange')();frame(); +assert.equal(wireCount,2,'restore repaints live pin geometry'); +width=0;events.get('focus')();frame(); +assert.equal(wireCount,2,'zero viewport must not paint stale SVG'); +width=800;events.get('pageshow')();frame(); +assert.equal(wireCount,3,'recovered WebView viewport repaints'); +console.log('Coalesced runtime WIRE resize / restore scheduler PASS'); diff --git a/tests/native_harmony_assembly_test.py b/tests/native_harmony_assembly_test.py index e262f1103..1a00c7e2f 100644 --- a/tests/native_harmony_assembly_test.py +++ b/tests/native_harmony_assembly_test.py @@ -90,6 +90,11 @@ def test_quiet_manual_music_mode_and_selector(self): self.assertIn('edit({guideMode:0,guideChannelId:"0"})',self.ui) self.assertIn('const status=!auto?"MANUAL":!inGraph?"SAFE":detected?"AUTO":"LISTEN";',self.ui) self.assertIn("showText(el(\"mxHKeyReadout\"),",self.ui) + self.assertIn('id="mxHTracking" aria-live="off"',self.ui) + self.assertIn('showText(el("mxHTracking"),tracking)',self.ui) + self.assertIn('if(now-lastGuideRead>500)',self.ui) + self.assertIn('b.classList.toggle("queued"',self.ui) + self.assertIn('.mx-harm-note.queued:not(.active)',self.css) self.assertIn('role="status" aria-live="polite"',self.ui) self.assertIn(".mx-harm-mode button.active",self.css) self.assertIn(".mx-harm-source-picker[hidden]{display:none}",self.css) @@ -154,7 +159,12 @@ def test_reference_inspired_wide_harmony_and_exact_shared_fx_chrome(self): def test_no_fabricated_native_pcm(self): self.assertIn("BROWSER PREVIEW · VISUAL ONLY · NO AUDIO",self.ui) self.assertIn("if(!native())",self.ui) - self.assertIn("if(native()&&n?.admitted",self.ui) + # Accepted ChannelId/instance binding is re-established on the + # current graph, not permanently pinned to the editor's open tick. + self.assertIn("if(!current||!native()||!n?.admitted)return null;",self.ui) + self.assertIn("if(n?.admitted&&insert?.catalogId===ID&&insert.id)",self.ui) + self.assertIn("function reconcileBinding(){",self.ui) + self.assertNotIn("REOPEN ACCEPTED FX",self.ui) self.assertIn("Native Harmony host not ready · audio unchanged",self.html) with self.assertRaises(ValueError): apply_native_peq(self.html) diff --git a/tests/native_header_toolbar_chromium_smoke.py b/tests/native_header_toolbar_chromium_smoke.py new file mode 100644 index 000000000..468fae017 --- /dev/null +++ b/tests/native_header_toolbar_chromium_smoke.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +"""Native-only desktop toolbar: real assembled WebView DOM, no DSP simulation. + +Verify breathing room, semantic group separators, no overlapped controls and +the original file/menu actions at ordinary and minimum Windows widths. +""" +import importlib.util +import tempfile +from pathlib import Path + +from playwright.sync_api import sync_playwright + +ROOT = Path(__file__).resolve().parents[1] + + +def main(): + spec = importlib.util.spec_from_file_location( + "native_bundle", ROOT / "scripts/build_approved_native_gui.py") + bundle = importlib.util.module_from_spec(spec) + spec.loader.exec_module(bundle) + with tempfile.TemporaryDirectory(prefix="arsonmix-toolbar-") as folder, sync_playwright() as pw: + dst = Path(folder) + bundle.stage(dst) + browser = pw.chromium.launch(headless=True) + for width, height in ((1680, 900), (1366, 768), (1200, 740), (1100, 650)): + page = browser.new_page(viewport={"width": width, "height": height}) + errors = [] + page.on("pageerror", lambda err: errors.append(str(err))) + page.add_init_script("""window.__nativeListeners=new Map();window.__events=[]; + window.__JUCE__={backend:{ + emitEvent(name,payload){window.__events.push({name,payload});}, + addEventListener(name,callback){window.__nativeListeners.set(name,callback);} + }};""") + page.goto((dst / "index.html").as_uri()) + page.wait_for_function("""()=>document.documentElement.classList.contains('armix-native-desktop') && + document.querySelectorAll('.command-bar .mixer-file-tool').length===2 && + document.querySelectorAll('.command-bar .armix-toolbar-divider').length===4 && + !!document.getElementById('playerToggle')""") + metrics = page.evaluate("""()=>{ + const bar=document.querySelector('.command-bar'); + const b=bar.getBoundingClientRect(); + const more=document.querySelector('#moreTools').getBoundingClientRect(); + const visible=[...bar.children].filter(el=>{ + const r=el.getBoundingClientRect(),cs=getComputedStyle(el); + return r.width>0 && r.height>0 && cs.display!=='none' && + !el.classList.contains('armix-toolbar-divider') && + !el.classList.contains('sep'); + }).map(el=>({id:el.id||el.textContent.trim().slice(0,12), + left:el.getBoundingClientRect().left, + right:el.getBoundingClientRect().right})); + return {bar:{height:b.height,left:b.left,right:b.right}, + more:{left:more.left,right:more.right}, + visible,dividers:[...bar.querySelectorAll('.armix-toolbar-divider')] + .map(el=>({hidden:getComputedStyle(el).display==='none', + height:el.getBoundingClientRect().height}))}; + }""") + assert metrics["bar"]["height"] == 43, (width, "incorrect native toolbar height", metrics) + assert metrics["more"]["right"] <= width + 1, ( + width, "overflow More menu outside window", metrics) + assert metrics["dividers"][0]["height"] in (0, 21), ( + width, "divider layout changed", metrics) + visible = metrics["visible"] + for a, b in zip(visible, visible[1:]): + # More can be pushed to the far right, never overlaid on controls. + assert a["right"] <= b["left"] + 1, ( + width, "toolbar controls overlap", a, b) + for item in visible: + assert item["left"] >= -1 and item["right"] <= width+1, ( + width, "toolbar control outside viewport", item) + for caption in ("Save", "Open"): + button = page.locator('.command-bar .mixer-file-tool').filter(has_text=caption) + assert button.count() == 1 and button.is_visible(), ( + width, "native file control not usable", caption) + button.click() + assert page.evaluate("()=>window.__events.at(-1).payload.action") == ( + "nativeMixerFile"+caption), (width, "file action disconnected", caption) + more = page.locator("#moreTools>summary") + more.click() + assert page.locator("#moreTools").get_attribute("open") is not None, ( + width, "More menu did not open") + more.click() + assert not errors, (width, "native JavaScript errors", errors) + print("NATIVE_TOOLBAR", width, metrics["bar"], len(visible), flush=True) + page.close() + browser.close() + print("PASS native toolbar: spacing, group borders, actions, four viewports") + + +if __name__ == "__main__": + main() diff --git a/tests/native_mixer_session_store_test.cpp b/tests/native_mixer_session_store_test.cpp index 9692b03ec..0255f8f25 100644 --- a/tests/native_mixer_session_store_test.cpp +++ b/tests/native_mixer_session_store_test.cpp @@ -93,6 +93,61 @@ class FixtureDevice final : public juce::AudioIODevice { double rate=48000.; }; +static void outputOnlyNativeStartup() { + // Real output-only callback: never invent a capture pin, but a silent + // ChannelId session, its FX/WIRE bus and physical zero output are valid. + FixtureDevice playback; + playback.inputMask.clear(); + LiveDryRoutingLab mixer; + juce::AudioPluginFormatManager formats; + mixer.prepareDevice(&playback); + assert(mixer.startUnpatchedSession(true,false,0,formats,48000.,480).isEmpty()); + assert(mixer.ready() && !mixer.hasExplicitRoute()); + // Legacy startup is silent before the one deliberate native migration. + assert(!mixer.admitChannelIdFromAcceptedM4(0,480,true)); + assert(mixer.admitChannelIdFromAcceptedM4(0,480,true,{},true)); + assert(mixer.hasExplicitRoute() && !mixer.hasVerifiedNativeSources()); + assert(mixer.canReplacePristineStartupMixer()); + // Startup automatically restores an existing .smix on precisely the + // same verified device. The saved Show must win over a never-edited + // SOURCE NONE starter, without a second publisher/audio callback. + { + auto saved=makeSession(); + saved.binding={"Windows Audio","","Verified WASAPI fixture","0","3",48000.,480}; + saved.request.physicalInputs=0; + saved.request.sources.clear(); + saved.request.maxFrames=480; + saved.rackBypassed.clear(); + armix::device::JuceActivePortSnapshot pins; + armix::device::JuceActivePortSnapshot::Fault fault; + assert(armix::device::JuceActivePortSnapshot::capture(&playback,mixer.epoch(),pins,fault)); + std::shared_ptr bank; + const auto prepare=NativeMixerSessionFxRestore::prepare(saved,{},formats, + 48000.,480,pins.epoch,mixer.nativeGraphRevisionForRestore(),bank); + assert(prepare.isEmpty() && bank); + assert(mixer.restoreNativeMixerSession(saved,std::move(bank),pins,true,true).isEmpty()); + assert(!mixer.canReplacePristineStartupMixer()); // saved Show is now authored + assert(mixer.hasExplicitRoute() && !mixer.hasVerifiedNativeSources()); + } + const auto native=mixer.nativeBusStatus(); + assert(native.isObject()); + const auto graph=static_cast( + native.getProperty("graphRevision",{}).toString().getLargeIntValue()); + const auto roster=static_cast( + native.getProperty("rosterRevision",{}).toString().getLargeIntValue()); + const auto add=mixer.createNativeInputChannel(mixer.epoch(),graph,roster, + "No Microphone Track",ProcessingFormat::stereo,true); + assert(add.accepted && !mixer.hasVerifiedNativeSources()); + assert(!mixer.canReplacePristineStartupMixer()); // edited graph can never be replaced + std::array left{},right{}; + left.fill(1.f);right.fill(1.f); // must be cleared, not fake audio + float* outputs[]={left.data(),right.data()}; + assert(mixer.process(nullptr,0,outputs,2,480,1.f,true, + nullptr,nullptr,false,nullptr,nullptr,true)); + for(const auto s:left)assert(s==0.f); + for(const auto s:right)assert(s==0.f); +} + static void nativeDeviceRecovery() { FixtureDevice device; auto saved=makeSession(); @@ -252,6 +307,59 @@ static void nativeDeviceRecovery() { assert(current.inserts.size()==1 && current.inserts[0].catalogId==eqId); current.binding=saved.binding; + // Render actual PCM after a sparse ASIO4ALL re-enumeration. Two compact + // callbacks now address physical pins 2 and 3, with MAIN L at ordinal 1. + auto aggregate=current; + aggregate.binding={"ASIO","ASIO4ALL v2","ASIO4ALL v2","3","3",48000.,480, + {"VB-Audio Point 1","VB-Audio Point 2"},{"2nd output with SST 1","2nd output with SST 2"}}; + auto reenumerated=aggregate.binding; + reenumerated.inputMask=reenumerated.outputMask="6"; + reenumerated.inputNames.insert(0,"Other capture"); + reenumerated.outputNames={"Other playback","2nd output with SST 2","2nd output with SST 1"}; + const auto asioPair=MixerDeviceBindingPolicy::proposedOutputs( + aggregate,reenumerated,2,BindingMode::verifiedAsioRestart); + assert(MixerDeviceBindingPolicy::apply(aggregate,reenumerated,asioPair,2, + BindingMode::verifiedAsioRestart).isEmpty()); + mixer.deviceStopped(); + device.inputMask.setBit(2);device.inputMask.clearBit(0); + device.outputMask=device.inputMask; + mixer.prepareDevice(&device); + assert(restore(aggregate,currentStates,true).isEmpty()); + process(true); + assert(outL.back()==0.f && outR.back()==0.f); + process(false); + assert(outL.back()>.02f && outR.back()>outL.back()+.01f); + const auto reattachAsio=[&](const HardwareBinding& previous,const HardwareBinding& live) { + mixer.deviceStopped(); + mixer.prepareDevice(&device); + MixerSessionDocument draft; + assert(mixer.describeRetainedAsioSession(draft)); + draft.binding=previous; + const auto pair=MixerDeviceBindingPolicy::proposedOutputs(draft,live,2, + BindingMode::verifiedAsioRestart); + assert(MixerDeviceBindingPolicy::apply(draft,live,pair, + device.inputMask.countNumberOfSetBits(),BindingMode::verifiedAsioRestart).isEmpty()); + armix::device::JuceActivePortSnapshot pins; + armix::device::JuceActivePortSnapshot::Fault fault; + assert(armix::device::JuceActivePortSnapshot::capture(&device,mixer.epoch(),pins,fault)); + assert(mixer.rebindRetainedAsioSession(std::move(draft),pins,480)); + }; + auto noCapture=reenumerated; + noCapture.inputMask="0"; + device.inputMask.clear(); + reattachAsio(reenumerated,noCapture); + assert(mixer.channelIdPhysicalPcmActive() && mixer.waitingAsioInputCount()==1); + assert(mixer.setNativeInputMix(mixer.epoch(),mixer.controlRevision(),{1},.6f,0.f)); + process(false); + assert(outL.back()==0.f && outR.back()==0.f); + device.inputMask.setRange(1,2,true); + reattachAsio(noCapture,reenumerated); + assert(mixer.waitingAsioInputCount()==0); + process(false); + assert(outL.back()>.02f && outR.back()>outL.back()+.01f); + device.inputMask.clearBit(2);device.inputMask.setBit(0); + device.outputMask=device.inputMask; + // The field failure switched Realtek playback to HDMI while keeping the // same VB-Cable source and a live FX rack. The new epoch has working PCM, // existing WIRE IDs and a repatchable ChannelId graph after one Apply. @@ -396,6 +504,57 @@ static void verifyVirtualPlayerSessionSerialization() { DynamicSourceKind::playerDeck); assert(document.request.sources.front().deckId==1); assert(document.roster.find({17})->sends.front().destination.value==15); + + // Reconciled ASIO4ALL + ArSon Player: physically disconnected inputs + // must NOT erase the mixer-owned virtual MUSIC source or its MAIN wire. + auto virtualOnly=makeSession(); + auto channels=virtualOnly.roster.channels(); + channels.push_back(player); + assert(virtualOnly.roster.restoreExact(virtualOnly.acceptedRevision,channels)); + virtualOnly.request.sources.clear(); + virtualOnly.request.sources.push_back( + {{17},-1,-1,true,DynamicSourceKind::playerDeck,1}); + virtualOnly.request.physicalInputs=0; + virtualOnly.binding.backend="ASIO"; + virtualOnly.binding.capture=virtualOnly.binding.playback="ASIO4ALL v2"; + virtualOnly.binding.inputMask="0"; + virtualOnly.binding.inputNames.clear(); + virtualOnly.binding.outputMask="3"; + virtualOnly.binding.outputNames={"Realtek Speakers 1","Realtek Speakers 2"}; + const auto onlyPlayer=Codec::encode(virtualOnly); + MixerSessionDocument restoredPlayer; + assert(Codec::decode(onlyPlayer,restoredPlayer)); + assert(restoredPlayer.request.physicalInputs==0 && + restoredPlayer.request.sources.size()==1 && + restoredPlayer.request.sources.front().kind== + DynamicSourceKind::playerDeck); + assert(Codec::encode(restoredPlayer)==onlyPlayer); + auto returned=virtualOnly.binding; + returned.inputMask="3"; + returned.inputNames={"VB-Audio Point 1","VB-Audio Point 2"}; + const auto pair=MixerDeviceBindingPolicy::proposedOutputs( + restoredPlayer,returned,2,BindingMode::verifiedAsioRestart); + assert(pair.valid()); + assert(MixerDeviceBindingPolicy::apply(restoredPlayer,returned,pair,2, + BindingMode::verifiedAsioRestart).isEmpty()); + assert(restoredPlayer.request.physicalInputs==2 && + restoredPlayer.request.sources.size()==1 && + restoredPlayer.request.sources.front().kind== + DynamicSourceKind::playerDeck); + assert(restoredPlayer.roster.find({17})->sends.front() + .destination.value==15); + // The reverse transition 2-IN -> 0-IN must also retain the same deck. + const auto absent=virtualOnly.binding; + assert(MixerDeviceBindingPolicy::apply(restoredPlayer,absent,pair,0, + BindingMode::verifiedAsioRestart).isEmpty()); + assert(restoredPlayer.request.sources.size()==1 && + restoredPlayer.request.sources.front().deckId==1); + // Never relax zero-input validation for physical mic ordinals. + auto bad=juce::JSON::parse(onlyPlayer); + auto src=bad.getProperty("request",{}).getProperty("sources",{}); + src.getArray()->getReference(0).getDynamicObject() + ->removeProperty("kind"); + assert(!Codec::decode(juce::JSON::toString(bad,false),restoredPlayer)); } // Actual production callback fixture: a freshly verified mixer needs ZERO @@ -481,6 +640,22 @@ static void verifyProductionPlayerFirstSoundWithSourceOnly() { int main(){ verifyProductionPlayerFirstSoundWithSourceOnly(); verifyVirtualPlayerSessionSerialization(); + // Zero-input is a legitimate saved SOURCE NONE workspace, never a fake mic. + { + auto silent=makeSession(); + silent.binding={"Windows Audio","","Speakers","0","3",48000.,256}; + silent.request.sources.clear();silent.request.physicalInputs=0; + MixerSessionDocument decoded; + assert(Codec::decode(Codec::encode(silent),decoded)); + assert(decoded.request.physicalInputs==0 && decoded.request.sources.empty()); + assert(decoded.roster.revision()==silent.roster.revision()); + assert(MixerDeviceBindingPolicy::apply(decoded,decoded.binding, + decoded.outputs,0,BindingMode::exact).isEmpty()); + auto malformed=juce::JSON::parse(Codec::encode(silent)); + malformed.getProperty("binding",{}).getDynamicObject()->setProperty("inputMask","3"); + assert(!Codec::decode(juce::JSON::toString(malformed,false),decoded)); + } + outputOnlyNativeStartup(); warmVst3Discovery(); nativeDeviceRecovery(); auto d=makeSession(); @@ -548,6 +723,18 @@ int main(){ assert(MixerDeviceBindingPolicy::apply(main34,only12,unauthorized12,2, BindingMode::verifiedDeviceApply).startsWith("NEEDS_REMAP")); assert(Codec::encode(main34)==main34Before); + // Deliberate MAIN assignment through the verified current two-pin mask + // is distinct from a normal Apply that must preserve the original pair. + auto explicitlyRepatched=main34; + const auto explicitPair=MixerDeviceBindingPolicy::proposedOutputs( + main34,only12,2,BindingMode::verifiedMainPinApply); + assert(explicitPair.valid() && explicitPair.mainL==0 && explicitPair.mainR==1); + assert(MixerDeviceBindingPolicy::apply(explicitlyRepatched,only12,explicitPair,2, + BindingMode::verifiedMainPinApply).isEmpty()); + assert(explicitlyRepatched.binding.outputMask=="3"); + assert(explicitlyRepatched.roster.revision()==main34.roster.revision()); + assert(!MixerDeviceBindingPolicy::proposedOutputs(main34,main34.binding,4, + BindingMode::verifiedMainPinApply).valid()); // If outputs 3/4 remain physically selected, ordinal 2/3 -> 0/1 // is a legal SAME-PIN remap, not an automatic route to different jacks. auto only34=main34.binding; @@ -580,7 +767,103 @@ int main(){ BindingMode::exact).isNotEmpty()); assert(MixerDeviceBindingPolicy::apply(reordered,reorderedPins,d.outputs,2, BindingMode::verifiedDeviceApply).isEmpty()); - assert(reordered.request.sources.empty()); + assert(reordered.request.sources.size()==d.request.sources.size()); + assert(reordered.request.sources.front().inputL==1); + assert(reordered.request.sources.front().inputR==-1); + + // ASIO4ALL can reorder the VB-Cable input and the Realtek pair even + // though JUCE still reports the same registered driver name. + auto asio=d; + asio.binding.backend="ASIO"; + asio.request.sources.front().stereo=true; + asio.request.sources.front().inputR=1; + asio.binding.capture=asio.binding.playback="ASIO4ALL v2"; + asio.binding.inputNames={"VB-Audio Point 1","VB-Audio Point 2"}; + asio.binding.outputNames={"2nd output with SST 1","2nd output with SST 2"}; + asio.binding.outputMask="3"; + asio.outputs={2,0,1,-1,-1,false}; + auto shifted=asio.binding; + shifted.inputNames={"New input","VB-Audio Point 1","VB-Audio Point 2"}; + shifted.inputMask="6"; + shifted.outputNames={"New output","2nd output with SST 2","2nd output with SST 1"}; + shifted.outputMask="6"; + const auto shiftedPair=MixerDeviceBindingPolicy::proposedOutputs(asio,shifted,2, + BindingMode::verifiedAsioRestart); + assert(shiftedPair.valid() && shiftedPair.mainL==1 && shiftedPair.mainR==0); + auto shiftedSession=asio; + assert(MixerDeviceBindingPolicy::apply(shiftedSession,shifted,shiftedPair,2, + BindingMode::verifiedAsioRestart).isEmpty()); + assert(shiftedSession.request.sources.front().inputL==0); + assert(shiftedSession.request.sources.front().inputR==1); + assert(shiftedSession.roster.revision()==asio.roster.revision()); + juce::BigInteger oldCapturePins; + oldCapturePins.setRange(0,2,true); + const auto translated=MixerDeviceBindingPolicy::translateNamedPins( + oldCapturePins,asio.binding.inputNames,shifted.inputNames); + assert(translated && translated->toString(16)=="6"); + auto temporarilyUnavailable=shifted; + temporarilyUnavailable.inputMask="0"; + auto waiting=shiftedSession; + assert(MixerDeviceBindingPolicy::apply(waiting,temporarilyUnavailable,shiftedPair,0, + BindingMode::verifiedAsioRestart).isEmpty()); + assert(waiting.request.physicalInputs==0 && waiting.request.sources.empty()); + assert(waiting.waitingAsioInputs.size()==1); + assert(waiting.roster.revision()==asio.roster.revision()); + assert(waiting.inserts.size()==asio.inserts.size()); + MixerSessionDocument reopenedWhileDisconnected; + assert(Codec::decode(Codec::encode(waiting),reopenedWhileDisconnected)); + assert(reopenedWhileDisconnected.binding.outputNames==shifted.outputNames); + assert(reopenedWhileDisconnected.waitingAsioInputs[0].leftName=="VB-Audio Point 1"); + juce::BigInteger returningMask; + assert(!MixerDeviceBindingPolicy::addReturningCapturePins( + reopenedWhileDisconnected.waitingAsioInputs,{"VB-Audio Point 1"},returningMask)); + assert(returningMask.isZero()); // a stereo half cannot open an unrelated capture + assert(MixerDeviceBindingPolicy::addReturningCapturePins( + reopenedWhileDisconnected.waitingAsioInputs,shifted.inputNames,returningMask)); + assert(returningMask.toString(16)=="6"); + + auto nextSpeaker=shifted; + nextSpeaker.outputMask="3"; + nextSpeaker.outputNames={"Realtek HD Audio output with SST 1","Realtek HD Audio output with SST 2"}; + const auto newlyApproved=MixerDeviceBindingPolicy::proposedOutputs( + reopenedWhileDisconnected,nextSpeaker,2,BindingMode::verifiedAsioRestart); + assert(newlyApproved.valid() && newlyApproved.mainL==0 && newlyApproved.mainR==1); + assert(MixerDeviceBindingPolicy::apply(reopenedWhileDisconnected,nextSpeaker,newlyApproved,2, + BindingMode::verifiedAsioRestart).isEmpty()); + assert(reopenedWhileDisconnected.waitingAsioInputs.empty()); + assert(reopenedWhileDisconnected.request.sources.front().inputL==0); + assert(reopenedWhileDisconnected.request.sources.front().inputR==1); + // ASIO4ALL often exposes VB-Cable and Realtek together: the physical + // MAIN pair must be recovered at callback ordinals 2/3, not rejected + // simply because four output pins are active. + auto simultaneous=shifted; + simultaneous.outputMask="f"; + simultaneous.outputNames={"VB-Audio Point 1","VB-Audio Point 2", + "Realtek HD Audio output with SST 1","Realtek HD Audio output with SST 2"}; + const auto recoveredRealtek=MixerDeviceBindingPolicy::proposedOutputs( + asio,simultaneous,4,BindingMode::verifiedAsioRestart); + assert(recoveredRealtek.valid() && recoveredRealtek.activeOutputChannels==4 && + recoveredRealtek.mainL==2 && recoveredRealtek.mainR==3); + auto multiOutputSession=asio; + assert(MixerDeviceBindingPolicy::apply(multiOutputSession,simultaneous, + recoveredRealtek,2,BindingMode::verifiedAsioRestart).isEmpty()); + assert(multiOutputSession.request.sources.size()==1 && + multiOutputSession.request.sources[0].inputL==0); + // Multiple physical speaker pairs are ambiguous and must never + // automatically redirect a live singer to the wrong output. + auto ambiguous=simultaneous; + ambiguous.outputNames={"Realtek Speakers A 1","Realtek Speakers A 2", + "Realtek Speakers B 1","Realtek Speakers B 2"}; + assert(!MixerDeviceBindingPolicy::proposedOutputs( + asio,ambiguous,4,BindingMode::verifiedAsioRestart).valid()); + auto virtualCable=nextSpeaker; + virtualCable.outputNames={"VB-Audio Point 1","VB-Audio Point 2"}; + assert(!MixerDeviceBindingPolicy::proposedOutputs(asio,virtualCable,2, + BindingMode::verifiedDeviceApply).valid()); + auto duplicatePins=shifted; + duplicatePins.outputNames.add("2nd output with SST 1"); + assert(!MixerDeviceBindingPolicy::proposedOutputs(asio,duplicatePins,2, + BindingMode::verifiedAsioRestart).valid()); auto exact=d; assert(MixerDeviceBindingPolicy::apply(exact,d.binding,d.outputs,2,BindingMode::exact) .isEmpty()); diff --git a/tests/native_music_tempo_test.cpp b/tests/native_music_tempo_test.cpp new file mode 100644 index 000000000..76dcd402a --- /dev/null +++ b/tests/native_music_tempo_test.cpp @@ -0,0 +1,332 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#include "../engine/core/NativeMusicTempoMonitor.h" +#include "../engine/core/DynamicNativeSessionPublisher.h" +#include +#include +#include +#include +#include +#include +#include +#define check(x) do {if(!(x)){std::fprintf(stderr,"FAIL:%s:%d %s\n",__FILE__,__LINE__,#x);std::abort();}}while(false) +static std::atomic noHeap{false}; +void* operator new(std::size_t n) { + if(noHeap.load(std::memory_order_relaxed))std::abort(); + if(void* p=std::malloc(n?n:1))return p; + throw std::bad_alloc(); +} +void* operator new[](std::size_t n) { + if(noHeap.load(std::memory_order_relaxed))std::abort(); + if(void* p=std::malloc(n?n:1))return p; + throw std::bad_alloc(); +} +void operator delete(void* p) noexcept {std::free(p);} +void operator delete[](void* p) noexcept {std::free(p);} +void operator delete(void* p,std::size_t) noexcept {std::free(p);} +void operator delete[](void* p,std::size_t) noexcept {std::free(p);} +using armix::mixer::ChannelId; +using armix::mixer::NativeMusicTempoMonitor; +static void renderWindow(NativeMusicTempoMonitor& tap,int index,int period, + float beat=.7f,bool weakOffbeats=false, + std::uint64_t epoch=7,std::uint64_t revision=13, + std::uint64_t controlNowMs=0) { + std::array l{},r{}; + const int pos=index%period; + const float level=pos==0?beat: + weakOffbeats&&pos==period/2?.07f:0.f; + l.fill(level);r.fill(level); + // A 10ms bucket is split across 64+36 ASIO callback frames at 10kHz. + noHeap.store(true,std::memory_order_release); + (void)tap.beginAudioBlock(epoch,64); + tap.capture(ChannelId{301},l.data(),r.data(),64,epoch,revision); + (void)tap.beginAudioBlock(epoch,36); + tap.capture(ChannelId{301},l.data()+64,r.data()+64,36,epoch,revision); + noHeap.store(false,std::memory_order_release); + if(index%8==0)(void)tap.poll(epoch,revision,controlNowMs); // host timer, not RT +} +static void lockTempo(int bpm,bool hats=false) { + NativeMusicTempoMonitor tap; + check(!tap.select(ChannelId{301},7,13,0)); + check(tap.select(ChannelId{301},7,13,10000)); + auto state=tap.poll(7,13); + check(state.active&&state.source.value==301&&!state.tempo.locked); + const int period=static_cast(std::lround(6000.0/bpm)); + for(int n=0;n<1100;++n)renderWindow(tap,n,period,.75f,hats); + state=tap.poll(7,13); + check(state.tempo.locked); + check(std::abs(state.tempo.bpm-bpm)<=3.1f); + check(state.tempo.confidence>=.28f); + // Sparse pair scoring uses only qualifying BPM neighborhoods instead + // of 121 complete rescans. This is a deterministic, hardware-neutral + // CONTROL timer budget, NOT a wall-clock benchmark. + check(state.tempo.scoringComparisons>0); + check(state.tempo.scoringComparisons<120000); + check(state.tempo.phaseLocked && state.tempo.phaseConfidence>=.50f); + check(state.tempo.beatAnchorTick>0); + check(state.tempo.beatAnchorFrame>0); + check(state.tempo.observationFrame>state.tempo.beatAnchorFrame); + check(state.dropped==0); + // One second of no music must NOT produce spurious half/double BPM. + for(int n=1100;n<1200;++n)renderWindow(tap,n,6000); + state=tap.poll(7,13); + check(state.tempo.locked); + // The user must see manual/TAP fallback after >3.2s of silence. + for(int n=1200;n<1580;++n)renderWindow(tap,n,6000); + state=tap.poll(7,13); + check(!state.tempo.locked); +} +// A full backing groove can carry snare/hi-hat accents on the eighth-note +// offbeat. Its BPM may be correct while a quarter-note phase is ambiguous. +static void harmonicAndPhaseAmbiguity() { + NativeMusicTempoMonitor tap; + check(tap.select(ChannelId{301},7,13,10000)); + const auto groove=[&](int index,float offbeat) { + std::array left{},right{}; + const int p=index%50; // quarter note at 120 BPM + const float value=p==0?.78f:p==25?offbeat:0.f; + left.fill(value);right.fill(value); + noHeap.store(true,std::memory_order_release); + (void)tap.beginAudioBlock(7,64); + tap.capture(ChannelId{301},left.data(),right.data(),64,7,13); + (void)tap.beginAudioBlock(7,36); + tap.capture(ChannelId{301},left.data()+64,right.data()+64,36,7,13); + noHeap.store(false,std::memory_order_release); + if(index%8==0)(void)tap.poll(7,13); + }; + for(int i=0;i<1150;++i)groove(i,.035f); + auto baseline=tap.poll(7,13); + check(baseline.tempo.locked && std::abs(baseline.tempo.bpm-120.f)<=3.f); + check(baseline.tempo.phaseLocked); + // For 11s, the equal-strength offbeat pulse could be mistaken for a + // new beat lattice; do not switch to 60 BPM, or claim a phase lock. + for(int i=1150;i<2450;++i)groove(i,.78f); + auto ambiguous=tap.poll(7,13); + check(ambiguous.tempo.locked); + check(ambiguous.tempo.scoringComparisons>0); + check(ambiguous.tempo.scoringComparisons<120000); + check(std::abs(ambiguous.tempo.bpm-120.f)<=3.f); + check(!ambiguous.tempo.phaseLocked); + // The music clears; the true quarter-note lattice should recover. + for(int i=2450;i<3650;++i)groove(i,.035f); + auto recovered=tap.poll(7,13); + if(!recovered.tempo.locked || std::abs(recovered.tempo.bpm-120.f)>3.f) + std::fprintf(stderr, + "MUSIC_OFFBEAT_RECOVERY tick=3650 locked=%d bpm=%.3f confidence=%.3f phase=%d phaseConfidence=%.3f comparisons=%u dropped=%u\n", + static_cast(recovered.tempo.locked),recovered.tempo.bpm, + recovered.tempo.confidence,static_cast(recovered.tempo.phaseLocked), + recovered.tempo.phaseConfidence,recovered.tempo.scoringComparisons, + recovered.dropped); + check(recovered.tempo.locked); + check(recovered.tempo.scoringComparisons>0); + check(recovered.tempo.scoringComparisons<120000); + check(std::abs(recovered.tempo.bpm-120.f)<=3.f); + check(recovered.tempo.phaseLocked); + check(recovered.dropped==0); +} +// A formerly locked backing can switch to densely accented but weak +// percussion. This is enough rhythmic activity to score a candidate, yet +// NOT enough evidence to keep the old beat grid or invent a new one. +static void weakBusyGrooveMustReleaseBeatGrid() { + NativeMusicTempoMonitor tap; + check(tap.select(ChannelId{301},7,13,10000)); + for(int n=0;n<1100;++n)renderWindow(tap,n,50,.78f); + auto locked=tap.poll(7,13); + check(locked.tempo.locked&&locked.tempo.phaseLocked); + for(int n=1100;n<2350;++n)renderWindow(tap,n,8,.10f); + const auto ambiguous=tap.poll(7,13); + check(ambiguous.active); + check(!ambiguous.tempo.locked && !ambiguous.tempo.phaseLocked); + check(ambiguous.tempo.confidence<.28f); + check(ambiguous.dropped==0); + // Once clear music returns the phase can be acquired again. + for(int n=2350;n<3550;++n)renderWindow(tap,n,50,.78f); + const auto recovered=tap.poll(7,13); + if(!recovered.tempo.locked || std::abs(recovered.tempo.bpm-120.f)>3.f) + std::fprintf(stderr, + "MUSIC_WEAK_RECOVERY locked=%d bpm=%.3f confidence=%.3f phase=%d phaseConfidence=%.3f comparisons=%u dropped=%u\n", + static_cast(recovered.tempo.locked),recovered.tempo.bpm, + recovered.tempo.confidence,static_cast(recovered.tempo.phaseLocked), + recovered.tempo.phaseConfidence,recovered.tempo.scoringComparisons, + recovered.dropped); + check(recovered.tempo.locked && + std::abs(recovered.tempo.bpm-120.f)<=3.f); + check(recovered.tempo.phaseLocked); +} +// If the audio callback stops entirely (ASIO suspension/reconfiguration), + // tick-based expiry alone cannot advance: fail closed on CONTROL time. +static void stoppedAudioCallbackMustRevokeOldBeat() { + NativeMusicTempoMonitor tap; + check(tap.select(ChannelId{301},7,13,10000)); + for(int n=0;n<1100;++n) + renderWindow(tap,n,50,.75f,false,7,13,1000+static_cast(n)*10); + auto locked=tap.poll(7,13,12000); + check(locked.active && locked.tempo.locked && locked.tempo.phaseLocked); + // A short interruption must not cause a needless BPM reset. + const auto hold=tap.poll(7,13,14450); + check(hold.active && hold.tempo.locked); + // No render/capture calls at all for >3.5s: stale beat cannot survive. + const auto stale=tap.poll(7,13,15501); + check(stale.active && stale.source.value==301); + check(!stale.tempo.locked && !stale.tempo.phaseLocked); + check(stale.tempo.beatAnchorFrame==0 && stale.tempo.bpm==0.f); + // Resume the very same source; require fresh musical evidence. + for(int n=1100;n<2300;++n) + renderWindow(tap,n,50,.75f,false,7,13, + 15510+static_cast(n-1100)*10); + const auto recovered=tap.poll(7,13,27600); + check(recovered.active && recovered.tempo.locked); + check(recovered.tempo.phaseLocked && std::abs(recovered.tempo.bpm-120.f)<=3.f); +} +static void steadyPadIsNotAClock() { + NativeMusicTempoMonitor tap; + check(tap.select(ChannelId{301},7,13,10000)); + std::array pcm{};pcm.fill(.22f); + for(int index=0;index<1200;++index) { + noHeap.store(true); + (void)tap.beginAudioBlock(7,100); + tap.capture(ChannelId{301},pcm.data(),pcm.data(),100,7,13); + noHeap.store(false); + if(index%8==0)(void)tap.poll(7,13); + } + const auto state=tap.poll(7,13); + check(!state.tempo.locked); + // A sustained pad is not evidence of rhythm. It cannot trigger a + // high-cost candidate scan simply because PCM keeps arriving. + check(state.tempo.scoringComparisons==0); +} +static void failClosed() { + NativeMusicTempoMonitor tap; + check(tap.select(ChannelId{301},7,13,48000)); + std::array pcm{};pcm.fill(.8f); + noHeap.store(true); + for(int i=0;i<240;++i) { + // Wrong channel and wrong graph revision must not populate the FIFO. + tap.capture(ChannelId{302},pcm.data(),pcm.data(),128,7,13); + tap.capture(ChannelId{301},pcm.data(),pcm.data(),128,7,14); + } + noHeap.store(false); + auto stale=tap.poll(7,14); + check(!stale.active&&!stale.tempo.locked); + auto active=tap.poll(7,13); + check(active.active&&!active.tempo.locked); + check(tap.select(ChannelId{},7,13,0)); + check(!tap.poll(7,13).active); +} +static void actualGraphSourcePcm() { + using namespace armix::mixer; + DynamicChannelRoster roster; + ChannelEdit source,main; + source.kind=ChannelEdit::Kind::add;source.position=0; + source.role=ChannelRole::input;source.text="BACKING"; + main.kind=ChannelEdit::Kind::add;main.position=1; + main.role=ChannelRole::main;main.text="MAIN"; + main.format=ProcessingFormat::stereo; + const std::array adds{source,main}; + const auto created=roster.edit(0,adds); + check(created.ok()&&created.createdIds.size()==2); + const auto music=created.createdIds[0],master=created.createdIds[1]; + ChannelEdit output; + output.kind=ChannelEdit::Kind::setPrimaryOutput; + output.id=music;output.target=master; + const std::array links{output}; + check(roster.edit(1,links).ok()); + DynamicGraphRequest request; + request.physicalInputs=1;request.maxFrames=128; + request.sources={{music,0,-1,false}}; + DynamicNativeSessionPublisher graph; + constexpr std::uint64_t epoch=7; + const auto applied=graph.commit(roster,request,0,epoch,epoch,true); + check(applied.ok()&&applied.revision==1); + check(!graph.setMusicTempoSource(epoch,1,master,10000)); // MAIN forbidden + check(!graph.setMusicTempoSource(epoch-1,1,music,10000)); + check(graph.setMusicTempoSource(epoch,1,music,10000)); + std::array input{},outL{},outR{}; + const float* physical[]{input.data()}; + int expectedTick=0; + const auto dryFx=[&](ChannelId,float*,float*,int n) noexcept { + const auto current=NativeBeatFrameScope::current(); + check(current.valid && current.epoch==epoch && + current.revision==1 && n==100); + check(current.startFrame==static_cast(expectedTick)*100); + }; + for(int tick=0;tick<1000;++tick) { + input.fill((tick%50)==0?.65f:0.f); // 120 BPM from real graph + noHeap.store(true,std::memory_order_release); + expectedTick=tick; + const bool rendered=graph.render(epoch,physical,1, + outL.data(),outR.data(),100,false,dryFx); + noHeap.store(false,std::memory_order_release); + check(rendered); + if(tick%8==0)(void)graph.pollMusicTempo(epoch,1); + } + auto state=graph.pollMusicTempo(epoch,1); + check(state.active&&state.source==music); + check(state.tempo.locked&&std::abs(state.tempo.bpm-120.f)<=3.f); + check(state.tempo.phaseLocked&&state.tempo.phaseConfidence>=.50f); + check(state.tempo.beatAnchorFrame>0 && + state.tempo.beatAnchorFrame<=100000); + check(state.tempo.observationFrame>=state.tempo.beatAnchorFrame); + check(!NativeBeatFrameScope::current().valid); // callback scope restored + // The *same* music ChannelId survives a graph revision with no second + // callback or preserved stale PCM pointers. + const auto newer=graph.commit(roster,request,1,epoch,epoch,true); + check(newer.ok()&&newer.revision==2); + state=graph.pollMusicTempo(epoch,2); + check(state.active&&state.source==music); + check(!graph.pollMusicTempo(epoch,1).active); + const auto newGraphFx=[&](ChannelId,float*,float*,int n) noexcept { + const auto block=NativeBeatFrameScope::current(); + check(block.valid && block.epoch==epoch && + block.revision==2 && block.startFrame==100000 && n==100); + }; + noHeap.store(true,std::memory_order_release); + const bool next=graph.render(epoch,physical,1, + outL.data(),outR.data(),100,false,newGraphFx); + noHeap.store(false,std::memory_order_release); + check(next); + check(!NativeBeatFrameScope::current().valid); + graph.unpublish(); + graph.pollRetirement(); +} +static void callbackClockEpochAndNestedScope() { + using armix::mixer::NativeBeatFrameScope; + NativeMusicTempoMonitor tap; + check(!NativeBeatFrameScope::current().valid); + noHeap.store(true,std::memory_order_release); + check(tap.beginAudioBlock(82,64)==0); + check(tap.beginAudioBlock(82,128)==64); + { + NativeBeatFrameScope outer{82,7,192}; + const auto a=NativeBeatFrameScope::current(); + check(a.valid&&a.epoch==82&&a.revision==7&&a.startFrame==192); + { + NativeBeatFrameScope nested{82,8,320}; + const auto b=NativeBeatFrameScope::current(); + check(b.valid&&b.revision==8&&b.startFrame==320); + } + const auto restored=NativeBeatFrameScope::current(); + check(restored.valid&&restored.revision==7&&restored.startFrame==192); + } + check(!NativeBeatFrameScope::current().valid); + check(tap.beginAudioBlock(82,256)==192); + // Physical device restart must establish a NEW sample origin. This + // prevents a beat from the old ASIO epoch appearing on the new device. + check(tap.beginAudioBlock(83,64)==0); + check(tap.beginAudioBlock(83,128)==64); + noHeap.store(false,std::memory_order_release); +} +int main() { + lockTempo(72); + lockTempo(95); + lockTempo(120); + lockTempo(160); + lockTempo(120,true); + harmonicAndPhaseAmbiguity(); + weakBusyGrooveMustReleaseBeatGrid(); + stoppedAudioCallbackMustRevokeOldBeat(); + steadyPadIsNotAClock(); + failClosed(); + callbackClockEpochAndNestedScope(); + actualGraphSourcePcm(); + std::puts("PASS: native music-channel BPM 72/95/120/160, silence holdover, stale graph, no RT heap"); +} diff --git a/tests/native_peq_assembly_test.py b/tests/native_peq_assembly_test.py index 890d798f1..069bd4889 100644 --- a/tests/native_peq_assembly_test.py +++ b/tests/native_peq_assembly_test.py @@ -24,6 +24,9 @@ def test_one_authoritative_mixer(self): self.assertEqual(self.assembled.count('src="assets/mixer-native-peq.js?v=eq-graph1"'),1) self.assertEqual(self.assembled.count('src="assets/mixer-native-compressor.js?v=comp-1"'),1) self.assertEqual(self.assembled.count("function insertChosenNativeCompressor(){"),1) + self.assertEqual(self.assembled.count("function insertChosenNativeThrow(){"),1) + self.assertEqual(self.assembled.count('src="assets/mixer-native-vocal-throw.js?v=throw-1"'),1) + self.assertEqual(self.assembled.count('data-fast-native-throw="1"'),1) def test_native_rack_uses_regular_insert_slot(self): self.assertIn("host.insert(activeFxTarget)",self.assembled) @@ -35,6 +38,7 @@ def test_native_rack_uses_regular_insert_slot(self): self.assertEqual(self.assembled.count('data-fast-native-eq="1"'),1) self.assertEqual(self.assembled.count('data-fast-native-comp="1"'),1) self.assertIn("if(t.fx[index]==='Compressor')",self.assembled) + self.assertIn("if(t.fx[index]==='ArSon Vocal Throw')",self.assembled) def test_single_style_owner(self): # The approved CSS compiler requires exactly 18 component-owner links. @@ -54,6 +58,50 @@ def test_single_style_owner(self): self.assertIn('addedLatencySamples!==0',compressor) self.assertNotIn("new AudioContext",compressor) self.assertIn(".mx-comp[hidden]{display:none}",css) + throw=(ROOT/"site/preview-v2/assets/mixer-native-vocal-throw.js").read_text("utf-8") + self.assertIn("arMixBuiltinThrowAck",throw) + self.assertIn("arMixBuiltinThrowSnapshot",throw) + self.assertIn("nativeThrowTrigger",throw) + self.assertIn('id="vtPreset"',throw) + self.assertIn("armix-floating-close",throw) + self.assertNotIn("new AudioContext",throw) + + def test_native_tempo_readback_belongs_to_vocal_throw_not_eq(self): + # The real C++ dispatcher must populate the exact VocalThrow + # snapshot, not an unrelated EQ response. Browser-only mocks cannot + # catch a payload sent on the wrong native event. + main=(ROOT/"src/Main.cpp").read_text("utf-8") + def body(start,finish): + self.assertEqual(main.count(start),1) + return main.split(start,1)[1].split(finish,1)[0] + eq=body("void emitNativeEqSnapshot(", + "void servicePendingNativeEq()") + vocal=body("void emitNativeThrowSnapshot(", + "void servicePendingNativeThrow()") + fields=("musicSourceChannelId","musicSourceActive", + "musicLocked","musicBpm","musicConfidence", + "musicGridAvailable","musicPhaseConfidence", + "musicBeatAnchorFrame","musicDroppedFrames") + for field in fields: + self.assertIn('reply->setProperty("'+field+'"',vocal, + "missing accepted Vocal Throw BPM field: "+field) + self.assertNotIn('reply->setProperty("'+field+'"',eq, + "cross-FX snapshot pollution: "+field) + # After device restart or graph change the last control snapshot + # is stale. No stale source/phase can be advertised as locked. + self.assertIn("const bool currentMusicGraph=lastMusicTempo_.active",vocal) + self.assertIn("lastMusicTempo_.epoch",vocal) + self.assertIn("lastMusicTempo_.revision",vocal) + self.assertIn("currentMusicGraph&&",vocal) + self.assertIn("musicBpm",vocal) + self.assertIn('juce::String("0")',vocal) + self.assertIn('"arMixBuiltinThrowSnapshot"',vocal) + self.assertNotIn('"arMixBuiltinThrowSnapshot"',eq) + throw_js=(ROOT/"site/preview-v2/assets/mixer-native-vocal-throw.js").read_text("utf-8") + for field in ("musicLocked","musicBpm","musicGridAvailable", + "musicSourceChannelId"): + self.assertIn(field,throw_js) + self.assertNotIn("new AudioContext",throw_js) def test_fail_closed_on_repeat(self): with self.assertRaises(ValueError): diff --git a/tests/native_vocal_throw_cancel_test.cpp b/tests/native_vocal_throw_cancel_test.cpp new file mode 100644 index 000000000..0caf3b745 --- /dev/null +++ b/tests/native_vocal_throw_cancel_test.cpp @@ -0,0 +1,255 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// Actual JUCE SPSC boundary, no ASIO device needed: an old cue must not +// sound when the device resumes after the native UI already rejected it. +#include "../engine/builtin_fx/VocalThrowProcessor.h" +#include +#include +#include +#include +#include +#define check(x) do{if(!(x)){std::fprintf(stderr,"FAIL %s:%d: %s\n",__FILE__,__LINE__,#x);std::abort();}}while(false) +static std::atomic noHeap{false}; +void* operator new(std::size_t n) { + if(noHeap.load(std::memory_order_relaxed))std::abort(); + if(void* p=std::malloc(n?n:1))return p; + throw std::bad_alloc(); +} +void* operator new[](std::size_t n) { + if(noHeap.load(std::memory_order_relaxed))std::abort(); + if(void* p=std::malloc(n?n:1))return p; + throw std::bad_alloc(); +} +void operator delete(void* p) noexcept{std::free(p);} +void operator delete[](void* p) noexcept{std::free(p);} +void operator delete(void* p,std::size_t) noexcept{std::free(p);} +void operator delete[](void* p,std::size_t) noexcept{std::free(p);} +using armix::builtin_fx::VocalThrowProcessor; +static void render(VocalThrowProcessor& p,juce::AudioBuffer& b, + juce::MidiBuffer& m,float amplitude) { + for(int c=0;c<2;++c)for(int i=0;i block(2,128); + juce::MidiBuffer midi; + std::array left{},right{}; + for(int b=0;b(n)]=v; + right[static_cast(n)]=v*.7f; + } + // Audio callback must never allocate, including first post-restart. + noHeap.store(true,std::memory_order_release); + reference.processStereo(left.data(),right.data(),left.size()); + noHeap.store(false,std::memory_order_release); + render(p,block,midi,amplitude); + for(int n=0;n<128;++n) { + const auto l=left[static_cast(n)]; + const auto r=right[static_cast(n)]; + check(std::isfinite(l)&&std::isfinite(r)); + check(std::abs(block.getSample(0,n)-l)<3.e-6f); + check(std::abs(block.getSample(1,n)-r)<3.e-6f); + if(echo && amplitude==0.f) + *echo+=std::abs(l)+std::abs(r); + } + } +} +static void testAudioAppliedStateSurvivesDeviceRestart() { + using armix::builtin_fx::VocalThrow; + for(const double firstRate:{44100.,48000.,96000.}) { + VocalThrowProcessor p; + p.prepareToPlay(firstRate,128); + check(p.isReady()); + p.sealForRealtime(); + auto latest=p.acceptedSettings(); + latest.mode=0; latest.bpm=156.f; latest.division=1; + latest.captureMs=300.f;latest.silenceMs=180.f; + latest.wet=.84f;latest.decay=.67f;latest.ducking=0.f; + latest.repeats=2; + check(p.queueSettings(latest,301)); + juce::AudioBuffer first(2,128);juce::MidiBuffer midi; + render(p,first,midi,0.f); + check(!p.stateSnapshotQuiescent()); + check(p.acceptedSettings().bpm!=latest.bpm); // ACK not yet polled + p.releaseResources(); + const auto secondRate=firstRate==96000.?48000.:96000.; + p.prepareToPlay(secondRate,128); + check(p.isReady()&&p.acceptedSampleRate()==secondRate); + check(p.acceptedSettings().bpm!=latest.bpm); + VocalThrow reference; + check(reference.prepare(secondRate)&&reference.resetUnpublished(latest)); + compareAudio(p,reference,140,.7f); + compareAudio(p,reference,45,0.f); + check(p.queueTrigger(302)); + check(reference.throwNow()); + float echo=0.f; + compareAudio(p,reference,320,0.f,&echo); + check(echo>.1f); // actual post-restart wet PCM, not only settings + VocalThrowProcessor::Completion completion{}; + check(p.pollCompletion(completion)&&completion.requestId==301&&completion.applied); + check(equalSettings(completion.settings,latest)); + check(p.pollCompletion(completion)&&completion.requestId==302&&completion.applied); + check(equalSettings(p.acceptedSettings(),latest)); + // Queued before yet another sample-rate change: packet is stale. + auto other=latest;other.bpm=85.f; + check(p.queueSettings(other,303)); + p.releaseResources(); + const auto thirdRate=secondRate==44100.?48000.:44100.; + p.prepareToPlay(thirdRate,257); + check(p.isReady()&&p.acceptedSampleRate()==thirdRate); + check(reference.prepare(thirdRate)&&reference.resetUnpublished(latest)); + compareAudio(p,reference,12,.7f); + check(p.pollCompletion(completion)&&completion.requestId==303&&!completion.applied); + check(equalSettings(p.acceptedSettings(),latest)); + check(p.stateSnapshotQuiescent()); + // Fresh revision with new coefficients succeeds after restart. + check(p.queueSettings(other,304)); + render(p,first,midi,0.f); + check(p.pollCompletion(completion)&&completion.requestId==304&&completion.applied); + check(equalSettings(p.acceptedSettings(),other)); + } +} +static void testColdShowRestoreAfterStart() { + using armix::builtin_fx::VocalThrow; + auto scene=armix::builtin_fx::VocalThrowSettings{}; + scene.mode=0;scene.bpm=92.f;scene.division=2; + scene.captureMs=670.f;scene.wet=.77f;scene.repeats=4; + juce::MemoryBlock stored; + { + juce::MemoryOutputStream writer(stored,false); + writer.writeInt(0x41565448);writer.writeInt(1); + writer.writeInt(scene.mode);writer.writeFloat(scene.bpm); + writer.writeInt(scene.division);writer.writeInt(scene.repeats); + writer.writeFloat(scene.captureMs);writer.writeFloat(scene.silenceMs); + writer.writeFloat(scene.thresholdDb);writer.writeFloat(scene.wet); + writer.writeFloat(scene.decay);writer.writeFloat(scene.ducking); + } + check(stored.getSize()==48); + VocalThrowProcessor cold; + check(cold.restoreUnpublishedState(stored.getData(), + static_cast(stored.getSize()))); + cold.prepareToPlay(48000.,128); + check(cold.isReady()&&equalSettings(cold.acceptedSettings(),scene)); + VocalThrow reference; + check(reference.prepare(48000.)&&reference.resetUnpublished(scene)); + compareAudio(cold,reference,50,.65f); + cold.releaseResources(); + cold.prepareToPlay(96000.,256); + check(cold.isReady()&&equalSettings(cold.acceptedSettings(),scene)); + check(reference.prepare(96000.)&&reference.resetUnpublished(scene)); + compareAudio(cold,reference,50,.65f); +} + + +static void testBypassNeverReplaysOldVocalCue() { + VocalThrowProcessor p; + p.prepareToPlay(48000.,128); + check(p.isReady()); + p.sealForRealtime(); + juce::AudioBuffer b(2,128); + juce::MidiBuffer midi; + auto settings=p.acceptedSettings(); + settings.mode=0;settings.wet=.9f;settings.ducking=0.f; + check(p.queueSettings(settings,501)); + render(p,b,midi,0.f); + VocalThrowProcessor::Completion done{}; + check(p.pollCompletion(done)&&done.requestId==501&&done.applied); + // Prime real singer history while FX is ON. + for(int n=0;n<115;++n)render(p,b,midi,.7f); + for(int n=0;n<32;++n)render(p,b,midi,0.f); + // A fade-out can still process audio; user cue must be rejected now. + p.onRealtimeBypass(true,false); + check(p.queueTrigger(502)); + render(p,b,midi,0.f); + check(p.pollCompletion(done)&&done.requestId==502&&!done.applied&& + done.bypassed); + // After full OFF the old ring is invalid, without a history-vector wipe + // in the realtime callback. Settings still ACK while the rack is OFF. + p.onRealtimeBypass(true,true); + auto next=settings;next.bpm=160.f; + check(p.queueSettings(next,503)); + p.consumeRealtimeEdits(); // native FX host fully-bypassed path + check(p.pollCompletion(done)&&done.requestId==503&&done.applied); + check(p.acceptedSettings().bpm==160.f); + check(p.queueTrigger(504)); + p.consumeRealtimeEdits(); + check(p.pollCompletion(done)&&done.requestId==504&&!done.applied&& + done.bypassed); + // Re-enable must not make the stale pre-bypass capture eligible again. + p.onRealtimeBypass(false,false); + check(p.queueTrigger(505)); + render(p,b,midi,0.f); + check(p.pollCompletion(done)&&done.requestId==505&&!done.applied&& + !done.bypassed); + check(p.observedThrowCount()==0); + // A FRESH sung phrase has an independent eligible manual cue. + for(int n=0;n<120;++n)render(p,b,midi,.7f); + for(int n=0;n<32;++n)render(p,b,midi,0.f); + check(p.queueTrigger(506)); + render(p,b,midi,0.f); + check(p.pollCompletion(done)&&done.requestId==506&&done.applied); + check(p.observedThrowCount()==1); + check(p.stateSnapshotQuiescent()); +} + +int main(){ + testBypassNeverReplaysOldVocalCue(); + testAudioAppliedStateSurvivesDeviceRestart(); + testColdShowRestoreAfterStart(); + VocalThrowProcessor p; + p.prepareToPlay(48000.,128); + check(p.isReady()); + p.sealForRealtime(); + juce::AudioBuffer b(2,128); + juce::MidiBuffer m; + auto old=p.acceptedSettings(); + auto changed=old;changed.bpm=156.f;changed.wet=.71f; + // Expired settings never mutate the DSP or its accepted settings shadow. + check(p.queueSettings(changed,101)); + p.cancelQueuedRequest(101); + // A second expired UI edit must not make the FIRST one executable + // again when ASIO eventually resumes. + check(p.queueSettings(changed,105)); + p.cancelQueuedRequest(105); + render(p,b,m,0.f); + VocalThrowProcessor::Completion c{}; + check(p.pollCompletion(c)&&c.requestId==101&&!c.applied); + render(p,b,m,0.f); + check(p.pollCompletion(c)&&c.requestId==105&&!c.applied); + check(p.acceptedSettings().bpm==old.bpm); + // A fresh request remains valid even after canceling an older ID. + check(p.queueSettings(changed,102)); + render(p,b,m,0.f); + check(p.pollCompletion(c)&&c.requestId==102&&c.applied); + check(p.acceptedSettings().bpm==156.f); + // Prime a real voiced phrase and then stop it; the trigger is valid. + for(int n=0;n<100;++n)render(p,b,m,.7f); + for(int n=0;n<32;++n)render(p,b,m,0.f); + check(p.queueTrigger(103)); + p.cancelQueuedRequest(103); + render(p,b,m,0.f); + check(p.pollCompletion(c)&&c.requestId==103&&!c.applied); + check(p.observedThrowCount()==0); + check(p.queueTrigger(104)); + render(p,b,m,0.f); + check(p.pollCompletion(c)&&c.requestId==104&&c.applied); + check(p.observedThrowCount()==1); + check(p.stateSnapshotQuiescent()); + std::puts("PASS: expired Vocal Throw cue and settings cannot replay on ASIO resume"); +} diff --git a/tests/player_native_decode_test.cpp b/tests/player_native_decode_test.cpp index 54ea9008b..c93d2cbb3 100644 --- a/tests/player_native_decode_test.cpp +++ b/tests/player_native_decode_test.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only #include "../engine/player/NativePlayerDeck.h" #include "../engine/player/PlayerSetlistPolicy.h" +#include "../engine/player/PlayerLibraryPolicy.h" #ifdef NDEBUG #undef NDEBUG #endif @@ -34,6 +35,36 @@ int main() { assert(Policy::nextTrack(9,9,10)==-1); // STOP after last assert(Policy::nextTrack(-1,2,10)==2); // first song assert(Policy::nextTrack(3,99,10)==4); // invalid queue ignored + // A singer can select a folder containing nested backing tracks. + // Import order is natural, bounded and excludes unrelated files. + const auto folder=juce::File::getSpecialLocation( + juce::File::tempDirectory).getNonexistentChildFile( + "arson-player-library-policy","",false); + assert(folder.createDirectory().wasOk()); + const auto nested=folder.getChildFile("subfolder"); + assert(nested.createDirectory().wasOk()); + assert(folder.getChildFile("10-outro.FLAC").create().wasOk()); + assert(folder.getChildFile("02-verse.mp3").create().wasOk()); + assert(folder.getChildFile("01-intro.wav").create().wasOk()); + assert(folder.getChildFile("garbage.txt").create().wasOk()); + assert(nested.getChildFile("03-chorus.aiff").create().wasOk()); + const auto scanned=armix::player::PlayerLibraryPolicy::scanFolder(folder); + assert(!scanned.truncated && scanned.files.size()==4); + assert(scanned.files[0].getFileName()=="01-intro.wav"); + assert(scanned.files[1].getFileName()=="02-verse.mp3"); + assert(scanned.files[2].getFileName()=="03-chorus.aiff"); + assert(scanned.files[3].getFileName()=="10-outro.FLAC"); + assert(!armix::player::PlayerLibraryPolicy::supported( + folder.getChildFile("garbage.txt"))); + // Missing track relink requires explicit matching filename; never + // silently substitute a different backing song or change its preset. + const auto missing=folder.getChildFile("old").getChildFile("02-verse.mp3"); + assert(!missing.existsAsFile()); + assert(armix::player::PlayerLibraryPolicy::sameSongName( + missing,folder.getChildFile("02-verse.mp3"))); + assert(!armix::player::PlayerLibraryPolicy::sameSongName( + missing,folder.getChildFile("01-intro.wav"))); + assert(folder.deleteRecursively()); const auto file=juce::File::getSpecialLocation(juce::File::tempDirectory) .getNonexistentChildFile("arson-player-decoder-test",".wav",false); juce::WavAudioFormat wave; diff --git a/tools/harmony_offline_ab.cpp b/tools/harmony_offline_ab.cpp new file mode 100644 index 000000000..de612a792 --- /dev/null +++ b/tools/harmony_offline_ab.cpp @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// Offline native Harmony A/B: genuine adult vocal WAVs, no live callback IO. +// Synthesized self-test is only a build and integrity gate, not an ear-test. +#include "../engine/builtin_fx/HarmonyDsp.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using armix::harmony::Engine; +using armix::harmony::Settings; +namespace fs=std::filesystem; +struct Wave {unsigned rate=0;std::vector left,right;}; +static std::uint16_t u16(const unsigned char* p){return std::uint16_t(p[0])|(std::uint16_t(p[1])<<8);} +static std::uint32_t u32(const unsigned char* p){return std::uint32_t(p[0])|(std::uint32_t(p[1])<<8)|(std::uint32_t(p[2])<<16)|(std::uint32_t(p[3])<<24);} +static void put16(std::ostream& out,std::uint16_t v){out.put(char(v&255));out.put(char((v>>8)&255));} +static void put32(std::ostream& out,std::uint32_t v){for(int k=0;k<4;++k)out.put(char((v>>(8*k))&255));} +static Wave readWave(const fs::path& file){ + if(!fs::exists(file)||fs::file_size(file)>220000000)throw std::runtime_error("WAV missing/too large"); + std::ifstream stream(file,std::ios::binary); + if(!stream)throw std::runtime_error("WAV open failed"); + const std::vector bytes((std::istreambuf_iterator(stream)),{}); + if(bytes.size()<44||std::memcmp(bytes.data(),"RIFF",4)!=0|| + std::memcmp(bytes.data()+8,"WAVE",4)!=0) + throw std::runtime_error("expected RIFF/WAVE"); + std::uint16_t fmt=0,ch=0,bits=0,align=0;std::uint32_t hz=0; + std::size_t offset=12,dataStart=0,dataBytes=0; + while(offset+8<=bytes.size()){ + const auto size=static_cast(u32(bytes.data()+offset+4)); + const auto start=offset+8; + if(size>bytes.size()-start)throw std::runtime_error("truncated WAV chunk"); + if(std::memcmp(bytes.data()+offset,"fmt ",4)==0){ + if(size<16)throw std::runtime_error("WAV fmt too short"); + const auto* p=bytes.data()+start; + fmt=u16(p);ch=u16(p+2);hz=u32(p+4);align=u16(p+12);bits=u16(p+14); + }else if(std::memcmp(bytes.data()+offset,"data",4)==0){ + dataStart=start;dataBytes=size; + } + offset=start+size+(size&1); + } + if(hz<32000||hz>192000||(ch!=1&&ch!=2)|| + !((fmt==1&&(bits==16||bits==24))||(fmt==3&&bits==32))|| + align!=ch*(bits/8)||!dataBytes||dataBytes%align) + throw std::runtime_error("use 32-192kHz mono/stereo PCM16/24 or IEEE float32 WAV"); + const auto frames=dataBytes/align; + if(frames>static_cast(hz)*60)throw std::runtime_error("use <=60s original adult-vocal excerpt"); + Wave out;out.rate=hz;out.left.resize(frames);out.right.resize(frames); + const auto* data=bytes.data()+dataStart; + for(std::size_t i=0;ifloat{ + const auto* p=data+i*align+static_cast(c)*(bits/8); + if(fmt==3){ + const auto raw=u32(p);float x=0;std::memcpy(&x,&raw,sizeof(x)); + return std::isfinite(x)?std::clamp(x,-4.f,4.f):0.f; + } + if(bits==16)return static_cast(std::int16_t(u16(p)))/32768.f; + std::int32_t value=std::int32_t(p[0])|(std::int32_t(p[1])<<8)| + (std::int32_t(p[2])<<16); + if(value&0x800000)value|=~0xffffff; + return static_cast(value)/8388608.f; + }; + out.left[i]=sample(0); + out.right[i]=sample(ch==2?1:0); + } + return out; +} +static void writeWave(const fs::path& path,const Wave& wave){ + if(wave.left.size()!=wave.right.size()||wave.left.size()>0x1fffffff) + throw std::runtime_error("WAV output too large"); + std::ofstream out(path,std::ios::binary|std::ios::trunc); + if(!out)throw std::runtime_error("WAV output open failed"); + const std::uint32_t n=static_cast(wave.left.size()*8); + out.write("RIFF",4);put32(out,n+36);out.write("WAVEfmt ",8); + put32(out,16);put16(out,3);put16(out,2);put32(out,wave.rate); + put32(out,wave.rate*8);put16(out,8);put16(out,32); + out.write("data",4);put32(out,n); + for(std::size_t i=0;i(); + if(!e->prepare(input.rate)||!e->setSettings(settings)) + throw std::runtime_error("native Harmony configuration invalid"); + e->setPitchSynchronousCandidateForOfflineReference(synchronous); + e->setStageDepthForOfflineReference(enhancedDepth); + e->setRoomFocusForOfflineReference(focus); + if(!e->setBackingPresenceForOfflineReference(presence)) + throw std::runtime_error("Harmony presence offline reference rejected"); + Wave out=input; + for(std::size_t pos=0;pos(block)) + e->process(out.left.data()+pos,out.right.data()+pos, + static_cast(std::min(static_cast(block),out.left.size()-pos))); + return out; +} +static double rms(const Wave& x){ + if(x.left.empty())return 0.;double acc=0.; + for(std::size_t i=0;i=3.999f||std::abs(modern.right[i])>=3.999f) + throw std::runtime_error("mixed output clipped: lower recording level for valid stem subtraction"); + const Wave backing=subtract(modern,dry); + const Wave previousDepth=process(input,settings,true,127,false); + const Wave previousRoomFocus=process(input,settings,true,127,true,false); + const Wave previousPresence=process(input,settings,true,127,true,true,false); + writeWave(folder/"01_lead_reference.wav",dry); + writeWave(folder/"02_legacy_grain_mix.wav",old); + writeWave(folder/"03_new_space_060.wav",modern); + writeWave(folder/"04_new_backing_only.wav",backing); + writeWave(folder/"05_new_mono_fold.wav",fold(modern)); + writeWave(folder/"08_previous_depth_space_060.wav",previousDepth); + writeWave(folder/"09_previous_backing_only.wav",subtract(previousDepth,dry)); + writeWave(folder/"10_room_focus_off_space_060.wav",previousRoomFocus); + writeWave(folder/"11_room_focus_off_backing_only.wav",subtract(previousRoomFocus,dry)); + writeWave(folder/"12_presence_old_space_060.wav",previousPresence); + writeWave(folder/"13_presence_old_backing_only.wav",subtract(previousPresence,dry)); + settings.space=0.f;writeWave(folder/"06_new_space_000.wav",process(input,settings,true)); + settings.space=1.f;writeWave(folder/"07_new_space_100.wav",process(input,settings,true)); + generateReport(folder,input,dry,old,modern,backing,previousDepth,previousPresence); +} +int main(int argc,char** argv){ + try{ + if(argc==2&&std::string(argv[1])=="--self-test"){ + Wave v;v.rate=48000;v.left.resize(18000);v.right.resize(18000); + for(int i=0;i<18000;++i){ + const double ph=6.283185307179586*220.*i/48000.; + v.left[i]=v.right[i]=static_cast( + .13*std::sin(ph)+.06*std::sin(2*ph)+.03*std::sin(3*ph)); + } + Settings s;s.wet=.45f; + auto before=process(v,s,false); + auto after=process(v,s,true); + if(!(rms(before)>0.01&&rms(after)>0.01))return 2; + s.wet=1.f;s.space=.6f;s.voices=4; + const auto baseline=process(v,s,true,127,true,true,false); + const auto boosted=process(v,s,true,127,true,true,true); + auto drySettings=s;drySettings.wet=0.f; + const auto dry=process(v,drySettings,true); + const double beforeRms=rms(subtract(baseline,dry)); + const double afterRms=rms(subtract(boosted,dry)); + if(!(beforeRms>.0001&&afterRms>beforeRms*1.50&& + afterRms { + const raw=String(message??"").trim(); + if(!raw)return ""; + const internalCode=/\b[A-Z][A-Z0-9]{2,}(?:_[A-Z0-9]+)+\b/.test(raw); + if(internalCode || + /\b(FAT|PCM|ACK|readback|admission|admitted|graph|roster|epoch|revision|M[0-9]|JUCE|callback|worker|fixture|reference|mockup|simulated|demo|legacy|native|authoritative)\b/i.test(raw)){ + if(/\b(device|driver|audio interface)\b|DEVICE_/i.test(raw) && + /\b(disconnect|unavailable|not ready|not open|not found|failed)\b|_(FAILED|ERROR|DISCONNECTED|UNAVAILABLE)/i.test(raw)) + return "Audio device unavailable · Open Audio I/O"; + if(/\b(WIRE|route|routing)\b/i.test(raw)){ + if(/\b(reject|fail|error|timed out|not applied|unavailable)\b/i.test(raw)) + return "Routing not changed · Check the connection and try again"; + if(/\b(pending|await|verif|applying|completing)\w*/i.test(raw)) + return "Updating channel routing…"; + return "Channel routing updated"; + } + if(/\b(VST3|plugin|effect|FX)\b/i.test(raw)){ + if(/\b(reject|fail|error|timed out)\b/i.test(raw)) + return "Effect change failed · Previous settings kept"; + if(/\b(pending|await|verif|loading|applying)\w*/i.test(raw)) + return "Applying effect…"; + return "Effect settings updated"; + } + if(/\b(error|failed|rejected|timed out|invalid|unavailable|not applied)\b|_(FAILED|ERROR|REJECTED|STALE|INVALID|TIMEOUT|MISSING)(?:\b|_)/i.test(raw)) + return "Change not applied · Previous mixer settings kept"; + if(/\b(pending|awaiting|verifying|saving|processing|applying|loading|deleting)\b|_PENDING\b|PENDING_/i.test(raw)) + return "Applying mixer changes…"; + return "Mixer settings updated"; + } + return raw; + }; const status = message => { - lastNativeError = message; + lastNativeError = message; // raw engine state remains inspectable internally + const text = operatorMessage(message); const info = document.getElementById("info"); - if (info && info.textContent !== message) info.textContent = message; + if (info && info.textContent !== text) info.textContent = text; }; + // The original preview's say() may still populate this footer. + // Observe two text nodes only, no polling, audio callback or DOM-wide scans. + if(connected){ + const info=document.getElementById?.("info"); + const warning=document.querySelector?.(".status-bar .warning"); + if(info)info.textContent="Opening mixer…"; + if(warning)warning.textContent="CONNECTING AUDIO…"; + if(typeof MutationObserver==="function"){ + const nodes=[info,warning].filter(Boolean); + const sanitize=()=>{ + for(const node of nodes){ + const clean=operatorMessage(node.textContent); + if(node.textContent!==clean)node.textContent=clean; + } + }; + const observer=new MutationObserver(sanitize); + for(const node of nodes) + observer.observe(node,{childList:true,characterData:true,subtree:true}); + } + const demoFoot=document.querySelector?.(".route-choice-foot"); + if(demoFoot)demoFoot.textContent="Your routing changes take effect after you confirm."; + } const stopDemo = () => { // The public Pages demo remains unchanged. In native, DEMO meters and // reference-only physical operations are never passed off as live audio. @@ -598,7 +657,7 @@ Number.isInteger(p.port) && hardware.device.enabledInputs.includes(p.port)):[]; // BUS is verified engine state, not an available hardware input choice. const INTERNAL_BUS="Internal BUS (read-only)"; - const NEEDS_REMAP="NEEDS REMAP"; + const NEEDS_REMAP="Audio connection lost"; const monoLabel=p=>"Mono · "+p.label+" [IN "+(p.port+1)+"]"; const stereoLabel=(a,b)=>"Stereo · IN "+(a.port+1)+" + "+(b.port+1); const inputChoicesFor=()=>{ @@ -983,6 +1042,18 @@ return true; } let pendingFxInsert=null,fxRequestSerial=0,nativeCatalog=new Map(); + // Native JUCE processors: these are real compiled DSP, not demo effects, + // scanned VST binaries, a JS renderer or placeholder library entries. + const nativeBuiltins=Object.freeze([ + Object.freeze({id:"armix.builtin.channel-eq.v1",name:"Parametric EQ", + vendor:"ArSonMix",category:"EQ",format:"Native",source:"builtin"}), + Object.freeze({id:"armix.builtin.channel-compressor.v1",name:"Compressor", + vendor:"ArSonMix",category:"Dynamics",format:"Native",source:"builtin"}), + Object.freeze({id:"armix.builtin.arson-harmony.v1",name:"ArSon Harmony", + vendor:"ArSonMix",category:"Utility",format:"Native",source:"builtin"}) + ]); + const presentFxCatalog=()=>scope?.setNativeCatalog?.( + [...nativeBuiltins,...nativeCatalog.values()]); let nativeFxDiscoveryRequested=false,nativeFxCatalogScanning=false; // Lazy USER-triggered discovery: the first Add FX opens immediately and // starts real JUCE VST3 scanning on its dedicated non-audio worker. Never @@ -1462,7 +1533,7 @@ hardware.device.epoch!=="0" && hardware.device.sampleRate>0 && hardware.device.bufferFrames>0 && Array.isArray(hardware.device.enabledInputs) && - hardware.device.enabledInputs.length>0 && + // Physical IN is optional; SOURCE NONE and FX/WIRE are native edits. Array.isArray(hardware.device.enabledOutputs) && hardware.device.enabledOutputs.length>=2 && (mixerSession()?.authority==="CHANNEL_ID" @@ -1498,7 +1569,7 @@ scope.master.output=mainOutput; if(!next?.admitted && !next?.retained)scope.render?.(); } - const transport=next?.retained?"MONITOR OFF · OUT NEEDS REMAP": + const transport=next?.retained?"OUTPUT WAITING FOR DEVICE": !deviceOpen?"Audio device not ready": (d.outputArmed?"MONITOR ON":"MONITOR OFF")+" · OUT "+playback+ (virtualOut?" · VIRTUAL / NO SPEAKERS":""); @@ -1509,11 +1580,13 @@ // initiates native source publication; only its correlated ACK may // request a safe first MONITOR. If the driver exposes no physical IN, // guide the operator to the existing Audio I/O panel instead. - const warningText=next?.retained?"NEEDS REMAP · MIXER RETAINED · OUTPUT MUTED": + const warningText=next?.retained?"PLAYBACK UNAVAILABLE · MIXER SAVED": !deviceOpen?"NO VERIFIED AUDIO DEVICE": - d.outputArmed?(next.admitted?"NATIVE PCM · HARDWARE FAT PENDING": - "MAIN MONITOR ON · PCM ADMISSION NOT VERIFIED"): - !d.enabledInputs?.length?"NO CAPTURE INPUT · OPEN AUDIO I/O": + next?.raw?.waitingAsioInputs>0?"INPUT TEMPORARILY UNAVAILABLE · AUTO-RECONNECT": + d.outputArmed?(next.admitted?"OUTPUT ENABLED": + "CHECK AUDIO CONNECTION"): + !d.enabledInputs?.length?(next.admitted?"CHOOSE AN INPUT": + "CHECK AUDIO I/O SETTINGS"): legacy()?.routeAccepted?"NATIVE INPUT ROUTED · MONITOR OFF": deviceReady()?"SELECT CHANNEL IN · NATIVE MONITOR AFTER ACK": "NO VERIFIED INPUT ROUTE · OPEN AUDIO I/O"; @@ -1575,7 +1648,7 @@ "font:12px system-ui,sans-serif;box-shadow:0 9px 28px #0008"; document.body.appendChild(element); } - element.textContent=message;element.hidden=false; + element.textContent=operatorMessage(message);element.hidden=false; window.clearTimeout(toastTimer); toastTimer=window.setTimeout(()=>{element.hidden=true;},3400); } @@ -1626,6 +1699,7 @@
+
@@ -1675,9 +1749,13 @@ devicePanel.querySelector("[data-audio-apply]").onclick=()=>{ if(deviceBusy||!deviceChoice||!deviceInventory?.active)return; const draft=deviceChoice,active=deviceInventory.active; - if(!draft.backend||!draft.capture||!draft.playback)return; + const separate=deviceInventory.types?.find(x=>x.name===draft.backend)?.separate===true; + if(!draft.backend||!draft.playback||(!separate&&!draft.capture))return; sendDeviceApply(); }; + devicePanel.querySelector("[data-audio-main-pins]").onclick=()=>{ + if(!deviceBusy)sendDeviceApply(false,true); + }; devicePanel.querySelector("[data-audio-remap]").onclick=()=>{ if(!deviceBusy && offeredPinRemap!==null) sendDeviceApply(true); @@ -1696,7 +1774,10 @@ if(!el)return; el.replaceChildren(...values.map(value=>{ const option=document.createElement("option"); - option.value=value;option.textContent=value;return option; + option.value=value; + option.textContent=name==="capture"&&value==="" + ?"No hardware input (Player / FX)":value; + return option; })); if(values.includes(current))el.value=current; el.disabled=deviceBusy; @@ -1707,7 +1788,9 @@ if(!deviceChoice){ const backendName=active.backend||types[0]?.name||""; const selected=types.find(x=>x.name===backendName); - const capture=active.captureDevice||selected?.inputs?.[0]||""; + // Preserve an already-open output-only endpoint on repeated dialog opens. + const capture=active.open?String(active.captureDevice||""): + active.captureDevice||selected?.inputs?.[0]||""; deviceChoice={backend:backendName,capture, playback:active.playbackDevice|| (selected?.separate?selected?.outputs?.[0]:capture)||"", @@ -1720,7 +1803,8 @@ if(asio4allHint)asio4allHint.hidden=!( deviceChoice.backend==="ASIO"&&/asio4all/i.test(deviceChoice.capture)); fillAudioSelect("backend",types.map(x=>x.name),deviceChoice.backend); - fillAudioSelect("capture",t?.inputs||[],deviceChoice.capture); + fillAudioSelect("capture", + t?.separate?["",...(t.inputs||[])]:t?.inputs||[],deviceChoice.capture); fillAudioSelect("playback",t?.outputs||[],deviceChoice.playback); const same=active.open&&active.backend===deviceChoice.backend&& active.captureDevice===deviceChoice.capture&& @@ -1762,23 +1846,30 @@ }else pins.textContent="Apply this device first to inspect its real enabled pins."; } const activeText=devicePanel.querySelector("[data-audio-active]"); + const mainPins=Array.isArray(active.mainOutputs)?active.mainOutputs + .map(pin=>active.outputNames?.[pin]).filter(Boolean):[]; if(activeText && !deviceBusy)activeText.textContent=deviceResult||(active.open? - "ACTIVE · "+active.backend+" · "+active.rate+" Hz / "+active.buffer+" samples": + "ACTIVE · "+active.backend+" · "+active.rate+" Hz / "+active.buffer+" samples"+ + (mainPins.length===2?" · MAIN "+mainPins.join(" / "):""): "No verified audio device. Select a supported input and output."); devicePanel.querySelector("[data-audio-apply]").disabled=deviceBusy|| - !deviceChoice.backend||!deviceChoice.capture|| + !deviceChoice.backend||(!t?.separate&&!deviceChoice.capture)|| !deviceChoice.playback; + const assignMain=devicePanel.querySelector("[data-audio-main-pins]"); + assignMain.hidden=!same || deviceChoice.outputPins?.length!==2; + assignMain.disabled=deviceBusy; const remap=devicePanel.querySelector("[data-audio-remap]"); remap.hidden=!same || offeredPinRemap!==active.deviceGeneration; remap.disabled=deviceBusy; remap.title="Reuse existing input and output pin numbers on the selected device. MONITOR stays off."; } - function sendDeviceApply(confirmRetainedPinMapping=false){ + function sendDeviceApply(confirmRetainedPinMapping=false,assignMain=false){ if(!deviceChoice||!deviceInventory?.active)return; const c=deviceChoice,a=deviceInventory.active; const same=a.open&&a.backend===c.backend&& a.captureDevice===c.capture&&a.playbackDevice===c.playback; if(confirmRetainedPinMapping && (!same || offeredPinRemap!==a.deviceGeneration))return; + if(assignMain && (!same || c.outputPins?.length!==2))return; deviceBusy=true; const requestId="approved-io-"+(++deviceRequest); devicePanel.dataset.pendingRequest=requestId; @@ -1792,7 +1883,8 @@ bufferSize:confirmRetainedPinMapping?a.buffer:same?c.buffer:0, enabledInputs:same?c.inputPins:[], enabledOutputs:same?c.outputPins:[], - ...(confirmRetainedPinMapping?{confirmRetainedPinMapping:true}:{})}}); + ...(confirmRetainedPinMapping?{confirmRetainedPinMapping:true}:{}), + ...(assignMain?{assignSelectedPlaybackPinsToMain:true}:{})}}); } if(connected){ backend.addEventListener("arMixAudioDeviceInventory",inventory=>{ @@ -1812,15 +1904,14 @@ const accepted=ack.ok===true&&["ACCEPTED_LIVE","ACCEPTED_MUTED"].includes(ack.state) && ack.active?.open===true && ack.active?.authorized===true && Array.isArray(ack.active.enabledInputs) && - ack.active.enabledInputs.length>0 && Array.isArray(ack.active.enabledOutputs) && ack.active.enabledOutputs.length>=2; const outputReady=ack.outputMuted===false; deviceResult=accepted? (outputReady?"Mixer ready · Output live": - ack.mixerBound?"Mixer ready · Verify channel IN and output":"Audio device ready · choose a channel IN"): + ack.mixerBound?"Mixer ready · FX/WIRE available":"Audio device ready · no hardware input required"): ack.state==="NEEDS_REMAP"? - "NEEDS REMAP · "+ack.error: + String(ack.error||"Playback unavailable").replace(/^NEEDS_REMAP:\s*/,""): "Device rejected · "+(ack.error||"native hardware readback failed"); deviceChoice=null; if(accepted){ @@ -1906,6 +1997,11 @@ // Windows RAM/process paging context from the existing 1 Hz control // timer. No sampling or file I/O happens in the ASIO callback. const healthTitle=item("span","more-tools-caption","AUDIO HEALTH"); + const tone=item("button","tool","Test MAIN output"); + tone.title="Start or stop a quiet tone on the verified MAIN pair without reopening the driver"; + tone.addEventListener("click",()=>{ + backend.emitEvent("arMixAction",{action:"diagnosticRoute",value:"TOGGLE_MAIN_OUTPUT_TONE"}); + }); const mark=item("button","tool","Mark Crackle"); mark.title="Capture 5s before an audible crackle, including Windows memory"; mark.addEventListener("click",()=>{ @@ -2062,7 +2158,7 @@ if(!save)controller?.subscribe(); }); menu.append(caption,setup,muteBtn,hardwareNote, - healthTitle,mark,report,advanced, + healthTitle,tone,mark,report,advanced, showHeading,showSave,showBrowse,showSelect,showUpdate,showRecall,showRecover,showNote); // Single discoverable AUDIO I/O button next to ordinary mixer tools. // The existing More entry remains a shortcut to THIS SAME panel. @@ -2115,6 +2211,21 @@ status(armed?"Hardware MUTE requested":"MAIN monitor verifying hardware route"); }); toolbar.insertBefore(monitor,io); + // Fixed groups, not extra controls. Placement is DOM-only at startup; + // no resize listeners, repaint loops or menu reparenting. + for(const [name,element] of [ + ["files",document.getElementById("pluginsButton")], + ["routing",document.getElementById("wireNavigatorToggle")], + ["channels",addTrack], + ["monitor",monitor] + ]){ + if(!element || element.parentElement!==toolbar)continue; + const divider=document.createElement("span"); + divider.className="armix-toolbar-divider"; + divider.dataset.nativeToolbarGroup=name; + divider.setAttribute("aria-hidden","true"); + toolbar.insertBefore(divider,element); + } } updateHardwarePanel(hardware); } @@ -2149,7 +2260,10 @@ const session=next?.raw?.mixerSession; if(!session || session.deviceEpoch!==next.device.epoch) { flags.acceptedGraphConnected=false; - status("NATIVE SESSION UNAVAILABLE · controls unchanged"); + flags.productionCallbackLive=false; + lastPaintedSignature=""; + delete document.documentElement.dataset.armixNativeRoster; + status("AUDIO CONNECTION CHANGED · OPEN AUDIO I/O"); return; } // Never paint unacknowledged controls; pending slider caps are kept @@ -2160,7 +2274,8 @@ reconcileM4RackReadback(next); if(session.authority==="M4" && m4Verified()) { paintM4Fallback(next); - scope?.syncVerifiedM4Wires?.(session.channels.map(ch=>ch.source),m4TrackIds); + if(scope?.syncVerifiedM4Wires?.(session.channels.map(ch=>ch.source),m4TrackIds)) + document.documentElement.dataset.armixNativeRoster="accepted"; } // A second channel's IN can be selected while the first transaction is // in flight. Always dispatch its latest choice with a FRESH native route @@ -2195,23 +2310,26 @@ pendingFxInsert=null;pendingTrackDelete=null;startupWire=null;activeWireAttempt=null; pendingWireGains.clear();pendingNativeControl.clear();liveFaderVisualTargets.clear(); const signature="retained|"+next.identity+"|"+appearanceRevision; - if(lastPaintedSignature!==signature && projectNativeGraphWithoutFocusLoss(next)) + if(lastPaintedSignature!==signature && projectNativeGraphWithoutFocusLoss(next)){ lastPaintedSignature=signature; + document.documentElement.dataset.armixNativeRoster="accepted"; + } stopDemo(); paintNativeMeters(next); - status("NEEDS REMAP · mixer retained · output muted"); + status("Playback unavailable · waiting for the audio device"); return; } if (!nativeAdmitted) { flags.productionCallbackLive=false;flags.acceptedGraphConnected=false; lastPaintedSignature="";lastNativeTopologySignature=""; + if(!m4Verified())delete document.documentElement.dataset.armixNativeRoster; stopDemo(); status(m4Verified()? "NATIVE M4 · real PCM faders and meters · ChannelId buses not yet admitted": deviceReady()? "NATIVE G0 · verified physical IN ready · select a channel input": hardware?.device?.enabledInputs?.length===0? - "NO CAPTURE PINS · Audio I/O: enable an actual hardware input": + "NATIVE MIXER UNAVAILABLE · verify playback in Audio I/O": "NATIVE G0 NOT READY · open Audio I/O and verify device / native route"); return; } @@ -2231,6 +2349,7 @@ stopDemo();status("NATIVE READBACK INVALID · existing GUI controls unchanged"); return; } + document.documentElement.dataset.armixNativeRoster="accepted"; flags.productionCallbackLive=next.productLive;flags.acceptedGraphConnected=true; syncMonitorButton(next.device); lastPaintedSignature=signature;stopDemo();paintNativeMeters(next); @@ -2256,9 +2375,7 @@ if(actual===p.bypassed)pendingNativeFxPower=null; } if(startupWire)window.queueMicrotask(flushStartupWire); - status((next.productLive?"NATIVE PRODUCT LIVE":"NATIVE PCM GRAPH ACCEPTED · FAT PENDING")+ - " · device "+next.device.epoch+ - " · graph "+next.graph.revision+" · roster "+next.graph.rosterRevision); + status("Mixer settings updated"); } if (connected) { controller = protocol.createController({ @@ -2497,7 +2614,7 @@ typeof actual?.instanceId==="string"&&actual.instanceId.length){ status("CH "+(p.channel+1)+" FX loaded · verified native VST3"); scope?.closeNativePicker?.(); - scope?.setNativeCatalog?.([...nativeCatalog.values()]); + presentFxCatalog(); controller.subscribe(); }else { const reason=ack?.error||"native FX instance missing from accepted PCM"; @@ -2512,12 +2629,12 @@ nativeCatalog=new Map(catalog.items.filter(p=> p&&typeof p.id==="string"&&p.id.length>0&& typeof p.name==="string"&&p.name.length>0).map(p=>[p.id,p])); - scope?.setNativeCatalog?.([...nativeCatalog.values()]); + presentFxCatalog(); if(nativeFxDiscoveryRequested&&!nativeFxCatalogScanning&&nativeCatalog.size===0) - status("No installed VST3 discovered · use Import VST3 in Plugin Manager"); + status("Built-in FX ready · import VST3 to add more effects"); if(hardware?.raw?.legacyM4)paintM4FxInstances(hardware.raw.legacyM4); const count=document.getElementById("pluginCount"); - if(count)count.title="Verified JUCE native VST3 catalog"; + if(count)count.title="Native built-in DSP + verified VST3 catalog"; }); backend.addEventListener("arMixScanProgress",progress=>{ const statusEl=document.getElementById("pluginScanStatus"); @@ -2739,6 +2856,8 @@ window.ArSonMixNativeCompressor?.open(t,slot); } else if(insert.catalogId==='armix.builtin.arson-harmony.v1') { window.ArSonMixNativeHarmony?.open(t,slot); + } else if(insert.catalogId==='armix.builtin.vocal-throw.v1') { + window.ArSonMixNativeVocalThrow?.open(t,slot); } else backend.emitEvent("arMixAction",{action:"routingFxEditor",channelId:id,slot, instanceId:insert.id,deviceEpoch:current.device.epoch,revision:current.graph.revision}); } else {discoverFxOnFirstPickerOpen();scope?.openFastPicker?.(t,slot,btn);} @@ -2936,7 +3055,8 @@ const plugin=nativeCatalog.get(id) || (id==='armix.builtin.channel-eq.v1'?{id,name:'Parametric EQ'}: id==='armix.builtin.channel-compressor.v1'?{id,name:'Compressor'}: - id==='armix.builtin.arson-harmony.v1'?{id,name:'ArSon Harmony'}:null); + id==='armix.builtin.arson-harmony.v1'?{id,name:'ArSon Harmony'}: + id==='armix.builtin.vocal-throw.v1'?{id,name:'ArSon Vocal Throw'}:null); const track=scope?.tracks?.find(x=>x.id===target?.channelId)|| (scope?.master?.id===target?.channelId?scope.master:null); const channel=m4Index(track),slot=Number(target?.slot); @@ -3148,7 +3268,7 @@ const ready=()=>{ presentNativeOnlyTools(); installFirstSoundMenu(); - scope?.setNativeCatalog?.([]); // no synthetic/demo VST3 in Windows host + presentFxCatalog(); // compiled native FX, never demo or vendor placeholders updateHardwarePanel(null); stopDemo(); status("NATIVE: subscribed · waiting for true device and accepted ChannelId graph");