From 970d11e60e52464af0baa7765f9905bacc92c5b0 Mon Sep 17 00:00:00 2001 From: Tyler Date: Mon, 25 May 2026 09:36:36 -0700 Subject: [PATCH] fix: new-file load resets full nav state (zoom out both axes, stop playback) ResetForNewSignal only reset the time view + selection, leaving the previous file's frequency zoom, in-progress drags, and playback running. Loading a new file now zooms out both axes, cancels any drag/pan/divide, clears the selection, and stops playback + rewinds the playhead. Display preferences (colormap, dB scale, FFT size, grid, scope layout) are preserved by design. All three load paths funnel through this function. Co-Authored-By: Claude Opus 4.7 --- src/spectrogram.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/spectrogram.c b/src/spectrogram.c index 7b27974..6cbdb83 100644 --- a/src/spectrogram.c +++ b/src/spectrogram.c @@ -118,9 +118,24 @@ void ResetForNewSignal(void) // Cached STFT results are tied to the old signal data. FreeAllCacheEntries(&app.fftCache); - // Reset view + selection to full range. + // Zoom out both axes and drop the old selection / any in-progress drags. + // Display preferences (colormap, dB scale, FFT size, grid, scope layout) + // are intentionally preserved across loads. app.view.start = 0.0f; app.view.end = 1.0f; + app.view.freqStart = 0.0f; app.view.freqEnd = 1.0f; + app.view.isPanning = false; ClearSelection(); + app.sel.isDragging = false; + app.sel.isTimeSelecting = false; + app.sel.isFreqSelecting = false; + app.isDividing = false; + + // Stop any playback from the previous signal and rewind the playhead. + if (app.isPlaying && AudioPlaybackSound.frameCount > 0) StopSound(AudioPlaybackSound); + app.isPlaying = false; + app.playbackFinished = false; + app.playheadElapsed = 0.0f; + app.playheadT = 0.0f; // Invalidate the cached visible texture. if (app.visibleTexture.id != 0) UnloadTexture(app.visibleTexture);