Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Requires CMake 3.22+ and Ninja; on macOS also Xcode. macOS builds target Apple S
- `ui/`: JUCE components, compiled into the app and plugin targets.
- `third_party/`: vendored KISS FFT, the build glue for the LSP meters, and provenance and licence notes. Its READMEs say what to check when a pin changes.
- `tests/`: Catch2 tests for `core/`, plus the optional offline UI checks (`*UiChecks.cpp`), a JUCE program that `ui/CMakeLists.txt` builds as `visona_ui_checks` only with `-DVISONA_BUILD_UI_CHECKS=ON`. Keep JUCE out of `core/` and the Catch2 tests. Multi-threaded stress tests are tagged `[stress]`.
- Optional `VISONA_BUILD_PLUGIN_CHECKS=ON` adds `visona_effect_checks` and `visona_sync_checks` when plugins are built. CTest runs these offline processor checks when tests are enabled; they cover lifecycle, saved state and callback allocation without a DAW.
- `site/`: the static website, visona.org, with the download page and the user manual. `python3 site/build.py --serve` previews it; `.github/workflows/site.yml` deploys it to GitHub Pages. See `docs/website.md`. When a change alters what the user sees or does, update the manual in `site/static/manual/index.html` too.

## Website and manual on every pull request
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ All notable changes to this project are documented here. The format is based on
- The diagnostics overlay refreshes at 4 Hz in the app, so it costs less while measuring.


### Fixed

- Plugin preparation detaches the old audio stream before replacing it, including repeated host preparation and destruction without an explicit release.
- Visona Sync schedules bar impulses without heap allocation and retains impulses that round across a block boundary. Missing PPQ positions no longer produce repeated bar impulses; invalid host tempo and time signatures retain valid defaults.
- Plugin state clamps saved colour and window indices. Small host blocks retain enough timing slots, and time-signature changes update the scope's window length.
- Auto gain retains more than ten seconds of input peaks. If the UI misses the entire retained history, gain is preserved and waits for a new ten-second history before rising; current peaks can still lower it immediately. App settings writes are coalesced and flushed on shutdown.
- The app retries an input device that fails to start, stops or reports an error. Selecting the active view preserves its history, and plugin diagnostics no longer share timing counters between instances or consume modified D shortcuts.
- Visona Sync's editor reads atomic transport display values. Stereo diagnostics report the physical display scale and recent timing maxima; scope-only counters are hidden in other views. The spectrum stress test consumes the final snapshot even when its producer finishes first.


## [1.0.0-beta.1] - 2026-10-16

### Added
Expand Down
52 changes: 22 additions & 30 deletions app/src/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <visona/AudioInputWriter.h>
#include <visona/AudioRingBuffer.h>
#include <visona/AudioRingSizing.h>

#include <algorithm>
#include <atomic>
Expand All @@ -22,17 +23,8 @@ namespace
// so every input channel is opened.
constexpr int allInputChannels = 1024;

constexpr double ringSeconds = 1.0;

// The frames fill up before the timings unless blocks average fewer frames than this.
constexpr std::size_t framesPerTimingSlot = 16;

constexpr int devicePollMs = 500;

// A running device that delivers nothing for this long is lost. JUCE's ALSA thread ends without
// telling anyone when its device is unplugged or fails, and the device still reports that it plays.
constexpr int stallTicks = 4;

// How often opening the chosen device is tried while it is listed but does not open.
constexpr juce::uint32 openRetryMs = 2'000;

Expand All @@ -46,13 +38,6 @@ juce::String soundCards()
#endif
}

std::size_t ringCapacityFrames(double sampleRate, int bufferSize)
{
const auto oneSecond =
static_cast<std::size_t>(std::ceil(std::max(sampleRate, 1.0) * ringSeconds));
return std::max(oneSecond, static_cast<std::size_t>(std::max(bufferSize, 1)) * 4);
}

/** The index of a device input channel among the channels the callback delivers, or noInput. The
callback delivers the active channels in ascending order, without gaps. */
int callbackInputIndex(const juce::BigInteger& activeInputs, int deviceChannel)
Expand All @@ -68,8 +53,7 @@ struct AudioEngine::Stream
{
Stream(std::size_t numChannels, std::size_t capacityFrames, juce::BigInteger activeInputsIn,
int numDeviceInputsIn)
: ring(numChannels, capacityFrames,
std::max<std::size_t>(capacityFrames / framesPerTimingSlot, 1))
: ring(numChannels, capacityFrames, ringTimingSlots(capacityFrames))
, writer(ring)
, activeInputs(std::move(activeInputsIn))
, numDeviceInputs(numDeviceInputsIn)
Expand Down Expand Up @@ -138,7 +122,8 @@ void AudioEngine::openSavedDevice()
bool AudioEngine::isInputRunning() const
{
auto* const device = deviceManager_.getCurrentAudioDevice();
return device != nullptr && device->isPlaying() && !device->getActiveInputChannels().isZero();
return !deviceFailed_.load(std::memory_order_relaxed) && device != nullptr &&
device->isPlaying() && !device->getActiveInputChannels().isZero();
}

juce::String AudioEngine::noInputReason() const
Expand All @@ -158,6 +143,8 @@ juce::String AudioEngine::noInputReason() const
return "The audio device \"" + savedDevice + "\" is not connected." +
(waitingForChosen_ ? " Visona opens it when it is plugged in." : "");
}
if (deviceManager_.getCurrentAudioDevice() != nullptr)
return "The audio device stopped. Visona will try to reopen it.";
if (lastError_.isNotEmpty())
return lastError_;
if (availableDevices.isEmpty())
Expand Down Expand Up @@ -324,6 +311,7 @@ void AudioEngine::setSyncInputChannel(int deviceInputChannel)

void AudioEngine::audioDeviceAboutToStart(juce::AudioIODevice* device)
{
deviceFailed_.store(false, std::memory_order_relaxed);
const auto sampleRate = device->getCurrentSampleRate();
// The source channels, and the sync input after them.
auto stream = std::make_unique<Stream>(
Expand Down Expand Up @@ -460,24 +448,28 @@ bool AudioEngine::followChosenDevice()
bool AudioEngine::closeStalledDevice()
{
const auto status = streamStatus();
if (!status.has_value() || !isInputRunning() || status->framesDelivered != lastFramesDelivered_)
{
lastFramesDelivered_ = status.has_value() ? status->framesDelivered : 0;
stalledTicks_ = 0;
return false;
}
if (++stalledTicks_ < stallTicks)
auto* const device = deviceManager_.getCurrentAudioDevice();
const bool selected =
device != nullptr && deviceManager_.getAudioDeviceSetup().inputDeviceName.isNotEmpty();
const auto frames =
status ? std::optional<std::uint64_t>(status->framesDelivered) : std::nullopt;
if (!watchdog_.shouldRestart(selected, device != nullptr && device->isPlaying(), frames,
deviceFailed_.exchange(false, std::memory_order_relaxed)))
return false;

stalledTicks_ = 0;
deviceManager_.closeAudioDevice();
waitingForChosen_ = true;
lastError_ = "The audio device stopped delivering audio.";
// It may be back already, so it is opened again at once if it is listed.
nextOpenAttemptMs_ = juce::Time::getMillisecondCounter();
lastError_ = "The audio device stopped. Visona will try to reopen it.";
nextOpenAttemptMs_ = juce::Time::getMillisecondCounter() + openRetryMs;
return true;
}

void AudioEngine::audioDeviceError(const juce::String& /*errorMessage*/)
{
// JUCE may call this from a device thread. Recovery and UI updates stay on the timer.
deviceFailed_.store(true, std::memory_order_relaxed);
}

void AudioEngine::rescanDevices()
{
// An open device does not depend on its type, so it keeps running if it is still there. The
Expand Down
8 changes: 5 additions & 3 deletions app/src/AudioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MidiClockInput.h"
#include "ui/AudioSettings.h"

#include <visona/AudioDeviceWatchdog.h>
#include <visona/SourceLayout.h>
#include <visona/SweepSnapshot.h>
#include <visona/TripleBuffer.h>
Expand Down Expand Up @@ -158,6 +159,7 @@ class AudioEngine final : public AudioSettings,
int numSamples,
const juce::AudioIODeviceCallbackContext& context) override;
void audioDeviceStopped() override;
void audioDeviceError(const juce::String& errorMessage) override;
void changeListenerCallback(juce::ChangeBroadcaster* source) override;
void timerCallback() override;

Expand All @@ -167,7 +169,7 @@ class AudioEngine final : public AudioSettings,
/** Closes a device that is not the chosen one or has gone, and opens the chosen device while it
is missing and listed again. */
bool followChosenDevice();
/** Closes a running device that has delivered nothing for stallTicks timer ticks. */
/** Closes an input that failed to start, stopped or stalled. */
bool closeStalledDevice();
/** Replaces the device types with fresh ones, which list the devices there are now. */
void rescanDevices();
Expand Down Expand Up @@ -199,8 +201,8 @@ class AudioEngine final : public AudioSettings,
// error it shows.
bool waitingForChosen_ = false;
juce::uint32 nextOpenAttemptMs_ = 0;
std::uint64_t lastFramesDelivered_ = 0;
int stalledTicks_ = 0;
AudioDeviceWatchdog watchdog_;
std::atomic<bool> deviceFailed_{false};
juce::String soundCards_;
juce::MidiDeviceListConnection midiDevicesChanged_;

Expand Down
26 changes: 9 additions & 17 deletions app/src/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ void MainComponent::timerCallback()

void MainComponent::setAnalysisView(int view)
{
analysisView_ = std::clamp(view, 0, 3);
view = std::clamp(view, 0, 3);
if (analysisView_ == view)
return;
analysisView_ = view;
scope_.setVisible(analysisView_ == 0);
spectrum_.setActive(analysisView_ == 1);
bandSpectrum_.setActive(analysisView_ == 2);
Expand Down Expand Up @@ -746,22 +749,11 @@ void MainComponent::updateDiagnostics()
values.callbackAllocations = callbackAllocations;
values.allocationCheckWorks = allocationCheckWorks_;
values.analysisLoad = analysisLoad;
values.rendering = scope_.stats();
if (analysisView_ != 0)
{
const auto stats = analysisView_ == 3 ? stereo_.stats()
: analysisView_ == 2 ? bandSpectrum_.stats()
: spectrum_.stats();
values.rendering = {};
values.rendering.framesPerSecond = stats.framesPerSecond;
values.rendering.renderMsAverage = stats.renderMsAverage;
values.rendering.renderMsMax = stats.renderMsMax;
values.rendering.paintMsAverage = stats.paintMsAverage;
values.rendering.paintMsMax = stats.paintMsMax;
values.rendering.imageWidth = stats.imageWidth;
values.rendering.imageHeight = stats.imageHeight;
values.rendering.scale = stats.scale;
}
values.scopeRendering = analysisView_ == 0;
values.rendering = analysisView_ == 3 ? stereo_.stats()
: analysisView_ == 2 ? bandSpectrum_.stats()
: analysisView_ == 1 ? spectrum_.stats()
: scope_.stats();
values.processCpu = processCpu;

const auto& snapshot = scope_.snapshot();
Expand Down
2 changes: 1 addition & 1 deletion app/src/MainComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MainComponent final : public juce::Component,

/** Sets the gain by hand, which turns auto gain off. */
void setAnalysisView(int view);
int analysisView_ = 0;
int analysisView_ = -1;
void setGainDb(int gainDb);
void showGainDb(int gainDb);
void setAutoGain(bool isOn);
Expand Down
7 changes: 6 additions & 1 deletion app/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ juce::PropertiesFile::Options fileOptions()
options.folderName = "Visona";
#endif
options.storageFormat = juce::PropertiesFile::storeAsXML;
options.millisecondsBeforeSaving = 0;
options.millisecondsBeforeSaving = 1000;
return options;
}

Expand All @@ -49,6 +49,11 @@ Settings::Settings()
{
}

Settings::~Settings()
{
applicationProperties_.saveIfNeeded();
}

std::unique_ptr<juce::XmlElement> Settings::audioDeviceState() const
{
return properties_.getXmlValue(audioDeviceStateKey);
Expand Down
4 changes: 3 additions & 1 deletion app/src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ namespace visona

/**
Visona's saved user configuration, kept with juce::ApplicationProperties. On macOS the file is
~/Library/Application Support/Visona/Visona.settings. Every change is written to disk at once.
~/Library/Application Support/Visona/Visona.settings. Changes are coalesced for one second and
flushed on orderly shutdown.
*/
class Settings
{
public:
Settings();
~Settings();
int analysisView() const
{
const auto view = properties_.getIntValue("analysisView", 0);
Expand Down
3 changes: 3 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ add_library(visona_core STATIC
include/visona/AnalysisPipeline.h
include/visona/AudioInputWriter.h
include/visona/AudioRingBuffer.h
include/visona/AudioRingSizing.h
include/visona/AudioDeviceWatchdog.h
include/visona/HostPlayheadReader.h
include/visona/AutoGain.h
include/visona/Band.h
include/visona/BarPeaks.h
Expand Down
50 changes: 50 additions & 0 deletions core/include/visona/AudioDeviceWatchdog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include <cstdint>
#include <optional>

namespace visona
{

/** Message-thread watchdog, polled every 500 ms. A stopped or stalled input gets two
seconds to recover before reopening. Device callbacks only supply an error flag. */
class AudioDeviceWatchdog
{
public:
[[nodiscard]] bool shouldRestart(bool inputSelected, bool playing,
std::optional<std::uint64_t> frames, bool error) noexcept
{
if (!inputSelected)
{
reset();
return false;
}
if (error)
{
reset();
return true;
}
if (playing && frames && (!lastFrames_ || *frames != *lastFrames_))
{
lastFrames_ = frames;
stalledPolls_ = 0;
return false;
}
if (++stalledPolls_ < 4)
return false;
reset();
return true;
}

void reset() noexcept
{
lastFrames_.reset();
stalledPolls_ = 0;
}

private:
std::optional<std::uint64_t> lastFrames_;
int stalledPolls_ = 0;
};

} // namespace visona
24 changes: 24 additions & 0 deletions core/include/visona/AudioRingSizing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <algorithm>
#include <cmath>
#include <cstddef>

namespace visona
{

/** One second of audio, or four maximum-sized blocks, whichever is larger. */
inline std::size_t ringCapacityFrames(double sampleRate, int bufferSize)
{
const auto oneSecond = static_cast<std::size_t>(std::ceil(std::max(sampleRate, 1.0)));
return std::max(oneSecond, static_cast<std::size_t>(std::max(bufferSize, 1)) * 4);
}

/** Independent of the maximum block size: hosts may send much smaller actual blocks. */
inline std::size_t ringTimingSlots(std::size_t capacityFrames) noexcept
{
constexpr std::size_t framesPerTimingSlot = 16;
return std::max<std::size_t>(capacityFrames / framesPerTimingSlot, 1);
}

} // namespace visona
15 changes: 9 additions & 6 deletions core/include/visona/BarImpulseScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <visona/TimeSignature.h>

#include <cstddef>
#include <cstdint>
#include <span>
#include <vector>

namespace visona
{
Expand All @@ -21,14 +21,17 @@ class BarImpulseScheduler
{
public:
/**
Appends sample offsets within `[0, numFrames)` where a bar impulse should fire.
Writes sample offsets within `[0, numFrames)` where a bar impulse should fire.
`ppqAtBlockStart` is the host PPQ at the first frame of this block. Ableton Live
reports playhead PPQ at block start; anchoring placement there keeps impulses on the
arrangement grid instead of one buffer late.
arrangement grid instead of one buffer late. Returns the number written. Storage for
numFrames offsets always suffices. With smaller storage, only the first offsets fit.
Non-finite inputs, invalid signatures and bar periods below one sample are ignored.
*/
static void impulsesInBlock(std::uint64_t blockStartSample, std::uint32_t numFrames,
double ppqAtBlockStart, double bpm, TimeSignature timeSignature,
double sampleRate, std::vector<std::uint32_t>& offsetsOut);
[[nodiscard]] static std::size_t impulsesInBlock(std::uint32_t numFrames,
double ppqAtBlockStart, double bpm,
TimeSignature timeSignature, double sampleRate,
std::span<std::uint32_t> offsetsOut) noexcept;

/** The stream sample index of the bar boundary for `ppq`. */
[[nodiscard]] static double sampleIndexOfBarBoundary(double ppqAtReference,
Expand Down
3 changes: 2 additions & 1 deletion core/include/visona/BarPeaks.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct BarPeak
*/
struct RecentBarPeaks
{
static constexpr std::size_t capacity = 16;
// Covers the complete ten-second auto-gain hold at 100 ms per input window.
static constexpr std::size_t capacity = 128;

/** How many bars have ended in all. */
std::uint64_t count = 0;
Expand Down
Loading