mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-23 15:41:09 +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:
parent
a8a2598ba3
commit
8e5975b10d
@ -22,6 +22,7 @@ effect that uses SBSMS to do its processing (TimeScale)
|
|||||||
#include "../WaveTrack.h"
|
#include "../WaveTrack.h"
|
||||||
#include "../Project.h"
|
#include "../Project.h"
|
||||||
#include "TimeWarper.h"
|
#include "TimeWarper.h"
|
||||||
|
#include "../FileException.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SBSMSOutBlockSize = 512
|
SBSMSOutBlockSize = 512
|
||||||
@ -62,6 +63,9 @@ public:
|
|||||||
std::unique_ptr<SBSMSQuality> quality;
|
std::unique_ptr<SBSMSQuality> quality;
|
||||||
std::unique_ptr<WaveTrack> outputLeftTrack;
|
std::unique_ptr<WaveTrack> outputLeftTrack;
|
||||||
std::unique_ptr<WaveTrack> outputRightTrack;
|
std::unique_ptr<WaveTrack> outputRightTrack;
|
||||||
|
|
||||||
|
wxFileName failedFileName;
|
||||||
|
bool error{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class SBSMSEffectInterface final : public SBSMSInterfaceSliding {
|
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.
|
// Get the samples from the tracks and put them in the buffers.
|
||||||
r->leftTrack->Get((samplePtr)(r->leftBuffer.get()), floatSample, r->offset, blockSize);
|
// I don't know if we can safely propagate errors through sbsms, and it
|
||||||
r->rightTrack->Get((samplePtr)(r->rightBuffer.get()), floatSample, r->offset, blockSize);
|
// 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
|
// convert to sbsms audio format
|
||||||
for(decltype(blockSize) i=0; i<blockSize; i++) {
|
for(decltype(blockSize) i=0; i<blockSize; i++) {
|
||||||
@ -216,7 +240,7 @@ bool EffectSBSMS::Process()
|
|||||||
mTotalStretch = rateSlide.getTotalStretch();
|
mTotalStretch = rateSlide.getTotalStretch();
|
||||||
|
|
||||||
t = iter.First();
|
t = iter.First();
|
||||||
while (t != NULL) {
|
while (bGoodResult && t != NULL) {
|
||||||
if (t->GetKind() == Track::Label &&
|
if (t->GetKind() == Track::Label &&
|
||||||
(t->GetSelected() || (mustSync && t->IsSyncLockSelected())) )
|
(t->GetSelected() || (mustSync && t->IsSyncLockSelected())) )
|
||||||
{
|
{
|
||||||
@ -403,22 +427,34 @@ bool EffectSBSMS::Process()
|
|||||||
if (TrackProgress(nWhichTrack, frac))
|
if (TrackProgress(nWhichTrack, frac))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
rb.outputLeftTrack->Flush();
|
if (rb.failedFileName.IsOk())
|
||||||
if(rightTrack)
|
// re-construct an exception
|
||||||
rb.outputRightTrack->Flush();
|
// 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(),
|
leftTrack->ClearAndPaste(mCurT0, mCurT1, rb.outputLeftTrack.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.
|
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++;
|
mCurTrackNum++;
|
||||||
|
@ -45,7 +45,7 @@ effects from this one class.
|
|||||||
#include <wx/numformatter.h>
|
#include <wx/numformatter.h>
|
||||||
|
|
||||||
#include "../../AudacityApp.h"
|
#include "../../AudacityApp.h"
|
||||||
#include "../../AudacityException.h"
|
#include "../../FileException.h"
|
||||||
#include "../../FileNames.h"
|
#include "../../FileNames.h"
|
||||||
#include "../../Internat.h"
|
#include "../../Internat.h"
|
||||||
#include "../../LabelTrack.h"
|
#include "../../LabelTrack.h"
|
||||||
@ -834,6 +834,9 @@ bool NyquistEffect::TransferDataFromWindow()
|
|||||||
|
|
||||||
bool NyquistEffect::ProcessOne()
|
bool NyquistEffect::ProcessOne()
|
||||||
{
|
{
|
||||||
|
mError = false;
|
||||||
|
mFailedFileName.Clear();
|
||||||
|
|
||||||
nyx_rval rval;
|
nyx_rval rval;
|
||||||
|
|
||||||
wxString cmd;
|
wxString cmd;
|
||||||
@ -1236,10 +1239,22 @@ bool NyquistEffect::ProcessOne()
|
|||||||
|
|
||||||
int success = nyx_get_audio(StaticPutCallback, (void *)this);
|
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) {
|
if (!success) {
|
||||||
for(i = 0; i < outChannels; i++) {
|
for(i = 0; i < outChannels; i++) {
|
||||||
mOutputTrack[i].reset();
|
mOutputTrack[i].reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1790,11 +1805,19 @@ int NyquistEffect::GetCallback(float *buffer, int ch,
|
|||||||
mCurStart[ch] + mCurLen - mCurBufferStart[ch] );
|
mCurStart[ch] + mCurLen - mCurBufferStart[ch] );
|
||||||
|
|
||||||
mCurBuffer[ch].Allocate(mCurBufferLen[ch], floatSample);
|
mCurBuffer[ch].Allocate(mCurBufferLen[ch], floatSample);
|
||||||
if (!mCurTrack[ch]->Get(mCurBuffer[ch].ptr(), floatSample,
|
try {
|
||||||
mCurBufferStart[ch], mCurBufferLen[ch])) {
|
mCurTrack[ch]->Get(
|
||||||
|
mCurBuffer[ch].ptr(), floatSample,
|
||||||
wxPrintf(wxT("GET error\n"));
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,6 +237,9 @@ private:
|
|||||||
wxTextCtrl *mCommandText;
|
wxTextCtrl *mCommandText;
|
||||||
wxCheckBox *mVersionCheckBox;
|
wxCheckBox *mVersionCheckBox;
|
||||||
|
|
||||||
|
bool mError{ false };
|
||||||
|
wxFileName mFailedFileName;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
|
||||||
friend class NyquistEffectsModule;
|
friend class NyquistEffectsModule;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user