From f2d9c6cd9fc477a1dd4f624548b986f8c6e65b51 Mon Sep 17 00:00:00 2001 From: Daniel Walz Date: Mon, 31 Jul 2023 14:04:20 +0200 Subject: [PATCH] Fixed length and zoom factor --- Examples/PlayerExample/Source/AudioThumbnail.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Examples/PlayerExample/Source/AudioThumbnail.cpp b/Examples/PlayerExample/Source/AudioThumbnail.cpp index 6004ee53..0ce5d39e 100644 --- a/Examples/PlayerExample/Source/AudioThumbnail.cpp +++ b/Examples/PlayerExample/Source/AudioThumbnail.cpp @@ -53,7 +53,10 @@ void WaveformDisplay::paint (juce::Graphics& g) g.setColour (juce::Colours::red); if (thumbnail) - thumbnail->drawChannels (g, getLocalBounds().reduced (3), 0.0, 10.0, 1.0); + { + auto peak = thumbnail->getApproximatePeak(); + thumbnail->drawChannels (g, getLocalBounds().reduced (3), 0.0, thumbnail->getTotalLength(), peak > 0.0f ? 1.0f / peak : 1.0f); + } else g.drawFittedText (TRANS ("No File"), getLocalBounds(), juce::Justification::centred, 1); } @@ -79,6 +82,9 @@ void WaveformDisplay::updateAudioFile() return; } + if (!audioThumb->getAudioFile().existsAsFile()) + return; + thumbnail = std::make_unique (256, audioThumb->getManager(), audioThumb->getCache()); thumbnail->setSource (new juce::FileInputSource (audioThumb->getAudioFile())); thumbnail->addChangeListener (this);