1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-19 17:40:15 +02:00

Report read exceptions met in SBSMS and Nyquist callbacks to user...

... without letting them propagate through the libraries.
This commit is contained in:
Paul Licameli 2016-12-22 23:23:23 -05:00
parent a8a2598ba3
commit 8e5975b10d
3 changed files with 84 additions and 22 deletions

View File

@ -22,6 +22,7 @@ effect that uses SBSMS to do its processing (TimeScale)
#include "../WaveTrack.h"
#include "../Project.h"
#include "TimeWarper.h"
#include "../FileException.h"
enum {
SBSMSOutBlockSize = 512
@ -62,6 +63,9 @@ public:
std::unique_ptr<SBSMSQuality> quality;
std::unique_ptr<WaveTrack> outputLeftTrack;
std::unique_ptr<WaveTrack> outputRightTrack;
wxFileName failedFileName;
bool error{ false };
};
class SBSMSEffectInterface final : public SBSMSInterfaceSliding {
@ -95,8 +99,28 @@ long resampleCB(void *cb_data, SBSMSFrame *data)
);
// Get the samples from the tracks and put them in the buffers.
r->leftTrack->Get((samplePtr)(r->leftBuffer.get()), floatSample, r->offset, blockSize);
r->rightTrack->Get((samplePtr)(r->rightBuffer.get()), floatSample, r->offset, blockSize);
// I don't know if we can safely propagate errors through sbsms, and it
// does not seem to let us report error codes, so use this roundabout to
// stop the effect early.
// This would be easier with std::exception_ptr but we don't have that yet.
try {
r->leftTrack->Get(
(samplePtr)(r->leftBuffer.get()), floatSample, r->offset, blockSize);
r->rightTrack->Get(
(samplePtr)(r->rightBuffer.get()), floatSample, r->offset, blockSize);
}
catch ( const FileException& e ) {
if ( e.cause == FileException::Cause::Read )
r->failedFileName = e.fileName;
data->size = 0;
r->error = true;
return 0;
}
catch ( ... ) {
data->size = 0;
r->error = true;
return 0;
}
// convert to sbsms audio format
for(decltype(blockSize) i=0; i<blockSize; i++) {
@ -216,7 +240,7 @@ bool EffectSBSMS::Process()
mTotalStretch = rateSlide.getTotalStretch();
t = iter.First();
while (t != NULL) {
while (bGoodResult && t != NULL) {
if (t->GetKind() == Track::Label &&
(t->GetSelected() || (mustSync && t->IsSyncLockSelected())) )
{
@ -403,22 +427,34 @@ bool EffectSBSMS::Process()
if (TrackProgress(nWhichTrack, frac))
return false;
}
rb.outputLeftTrack->Flush();
if(rightTrack)
rb.outputRightTrack->Flush();
if (rb.failedFileName.IsOk())
// re-construct an exception
// I wish I had std::exception_ptr instead
// and could re-throw any AudacityException
throw FileException{
FileException::Cause::Read, rb.failedFileName };
else if (rb.error)
// well, what?
bGoodResult = false;
bool bResult =
if (bGoodResult) {
rb.outputLeftTrack->Flush();
if(rightTrack)
rb.outputRightTrack->Flush();
bool bResult =
leftTrack->ClearAndPaste(mCurT0, mCurT1, rb.outputLeftTrack.get(),
true, false, warper.get());
wxASSERT(bResult); // TO DO: Actually handle this.
wxUnusedVar(bResult);
if(rightTrack)
{
bResult =
rightTrack->ClearAndPaste(mCurT0, mCurT1, rb.outputRightTrack.get(),
true, false, warper.get());
true, false, warper.get());
wxASSERT(bResult); // TO DO: Actually handle this.
wxUnusedVar(bResult);
if(rightTrack)
{
bResult =
rightTrack->ClearAndPaste(mCurT0, mCurT1, rb.outputRightTrack.get(),
true, false, warper.get());
wxASSERT(bResult); // TO DO: Actually handle this.
}
}
}
mCurTrackNum++;

View File

@ -45,7 +45,7 @@ effects from this one class.
#include <wx/numformatter.h>
#include "../../AudacityApp.h"
#include "../../AudacityException.h"
#include "../../FileException.h"
#include "../../FileNames.h"
#include "../../Internat.h"
#include "../../LabelTrack.h"
@ -834,6 +834,9 @@ bool NyquistEffect::TransferDataFromWindow()
bool NyquistEffect::ProcessOne()
{
mError = false;
mFailedFileName.Clear();
nyx_rval rval;
wxString cmd;
@ -1236,10 +1239,22 @@ bool NyquistEffect::ProcessOne()
int success = nyx_get_audio(StaticPutCallback, (void *)this);
// See if GetCallback found read errors
if (mFailedFileName.IsOk())
// re-construct an exception
// I wish I had std::exception_ptr instead
// and could re-throw any AudacityException
throw FileException{
FileException::Cause::Read, mFailedFileName };
else if (mError)
// what, then?
success = false;
if (!success) {
for(i = 0; i < outChannels; i++) {
mOutputTrack[i].reset();
}
return false;
}
@ -1790,11 +1805,19 @@ int NyquistEffect::GetCallback(float *buffer, int ch,
mCurStart[ch] + mCurLen - mCurBufferStart[ch] );
mCurBuffer[ch].Allocate(mCurBufferLen[ch], floatSample);
if (!mCurTrack[ch]->Get(mCurBuffer[ch].ptr(), floatSample,
mCurBufferStart[ch], mCurBufferLen[ch])) {
wxPrintf(wxT("GET error\n"));
try {
mCurTrack[ch]->Get(
mCurBuffer[ch].ptr(), floatSample,
mCurBufferStart[ch], mCurBufferLen[ch]);
}
catch ( const FileException& e ) {
if ( e.cause == FileException::Cause::Read )
mFailedFileName = e.fileName;
mError = true;
return -1;
}
catch ( ... ) {
mError = true;
return -1;
}
}

View File

@ -237,6 +237,9 @@ private:
wxTextCtrl *mCommandText;
wxCheckBox *mVersionCheckBox;
bool mError{ false };
wxFileName mFailedFileName;
DECLARE_EVENT_TABLE()
friend class NyquistEffectsModule;