π π A Python library for audio.
C audioaudio-processingaudio-productionaudio-researchaudio-unitaugmentationjucemachine-learningpybind11pythonvst3vst3-host
Improve error message for bad seek positions. (#359)
Peter Sobot9858e9529eb9
diff --git a/pedalboard/io/ReadableAudioFile.h b/pedalboard/io/ReadableAudioFile.hindex 574c342..219ef09 100644--- a/pedalboard/io/ReadableAudioFile.h+++ b/pedalboard/io/ReadableAudioFile.h@@ -572,15 +572,20 @@ public:const juce::ScopedReadLock scopedReadLock(objectLock);if (!reader)throw std::runtime_error("I/O operation on a closed file.");- if (targetPosition >- (reader->lengthInSamples + (lengthCorrection ? *lengthCorrection : 0)))++ long long endOfFile =+ (reader->lengthInSamples + (lengthCorrection ? *lengthCorrection : 0));++ if (targetPosition > endOfFile)throw std::domain_error(- "Cannot seek beyond end of file (" +- std::to_string(reader->lengthInSamples +- (lengthCorrection ? *lengthCorrection : 0)) +- " frames).");+ "Cannot seek to position " + std::to_string(targetPosition) ++ " frames, which is beyond end of file (" + std::to_string(endOfFile) ++ " frames) by " + std::to_string(endOfFile - targetPosition) ++ " frames.");+if (targetPosition < 0)- throw std::domain_error("Cannot seek before start of file.");+ throw std::domain_error("Cannot seek before start of file (to position " ++ std::to_string(targetPosition) + ").");// Promote to a write lock as we're now modifying the object:ScopedTryWriteLock scopedTryWriteLock(objectLock);