1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-26 07:13:49 +01:00

All the catches are in place for BlockFile and other errors, now throw.

This commit is contained in:
Paul Licameli
2016-11-07 14:27:31 -05:00
parent b62bddfaeb
commit 55439247ad
12 changed files with 99 additions and 119 deletions

View File

@@ -27,6 +27,7 @@ The summary is eventually computed and written to a file in a background thread.
#include <wx/thread.h>
#include <sndfile.h>
#include "../FileException.h"
#include "../FileFormats.h"
#include "../Internat.h"
#include "NotYetAvailableException.h"
@@ -38,8 +39,9 @@ char bheaderTag[bheaderTagLen + 1] = "AudacityBlockFile112";
/// Create a disk file and write summary and sample data to it
ODDecodeBlockFile::ODDecodeBlockFile(wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&audioFileName, sampleCount aliasStart,
size_t aliasLen, int aliasChannel,unsigned int decodeType):
SimpleBlockFile{ std::move(baseFileName),
size_t aliasLen, int aliasChannel,unsigned int decodeType)
try
: SimpleBlockFile{ std::move(baseFileName),
NULL, aliasLen, floatSample, true, true },
//floatSample has no effect. last two bools - bypass writing of blockfile and cache
@@ -51,6 +53,14 @@ ODDecodeBlockFile::ODDecodeBlockFile(wxFileNameWrapper &&baseFileName, wxFileNam
mAudioFileName = std::move(audioFileName);
mFormat = int16Sample;
}
catch ( const FileException & e )
{
// The constructor SimpleBlockFile sometimes throws this,
// but it never will for the arguments that were passed to it here.
// So add a catch for completeness, but just assert that this won't happen.
wxASSERT(false);
throw;
}
/// Create the memory structure to refer to the given block file
ODDecodeBlockFile::ODDecodeBlockFile(wxFileNameWrapper &&existingFile, wxFileNameWrapper &&audioFileName, sampleCount aliasStart,
@@ -102,8 +112,7 @@ auto ODDecodeBlockFile::GetMinMaxRMS(
else
{
if (mayThrow)
// throw NotYetAvailableException{ mAudioFileName }
;
throw NotYetAvailableException{ mAudioFileName };
//fake values. These values are used usually for normalization and amplifying, so we want
//the max to be maximal and the min to be minimal
@@ -123,8 +132,7 @@ auto ODDecodeBlockFile::GetMinMaxRMS(bool mayThrow) const -> MinMaxRMS
else
{
if (mayThrow)
// throw NotYetAvailableException{ mAudioFileName }
;
throw NotYetAvailableException{ mAudioFileName };
//fake values. These values are used usually for normalization and amplifying, so we want
//the max to be maximal and the min to be minimal
@@ -446,8 +454,7 @@ size_t ODDecodeBlockFile::ReadData(samplePtr data, sampleFormat format,
else
{
if (mayThrow)
//throw NotYetAvailableException{ mFileName }
;
throw NotYetAvailableException{ mAudioFileName };
//we should do an ODRequest to start processing the data here, and wait till it finishes. and just do a SimpleBlockFile
//ReadData.

View File

@@ -133,8 +133,7 @@ auto ODPCMAliasBlockFile::GetMinMaxRMS(
else
{
if (mayThrow)
//throw NotYetAvailableException{ GetAliasedFileName() }
;
throw NotYetAvailableException{ GetAliasedFileName() };
//fake values. These values are used usually for normalization and amplifying, so we want
//the max to be maximal and the min to be minimal
@@ -156,8 +155,7 @@ auto ODPCMAliasBlockFile::GetMinMaxRMS(bool mayThrow) const -> MinMaxRMS
else
{
if (mayThrow)
//throw NotYetAvailableException{ GetAliasedFileName() }
;
throw NotYetAvailableException{ GetAliasedFileName() };
//fake values. These values are used usually for normalization and amplifying, so we want
//the max to be maximal and the min to be minimal
@@ -415,9 +413,8 @@ void ODPCMAliasBlockFile::WriteSummary()
//and wxLog calls are not thread safe.
printf("Unable to write summary data to file: %s", fileNameChar.get());
// throw FileException{
// FileException::Cause::Read, wxFileName{ fileNameChar.get() } };
return;
throw FileException{
FileException::Cause::Read, wxFileName{ fileNameChar.get() } };
}
ArrayOf<char> cleanup;

View File

@@ -57,15 +57,18 @@ to get its definition, rather than rolling our own.
*//*******************************************************************/
#include "../Audacity.h"
#include "SimpleBlockFile.h"
#include <wx/wx.h>
#include <wx/filefn.h>
#include <wx/ffile.h>
#include <wx/utils.h>
#include <wx/log.h>
#include "../FileException.h"
#include "../Prefs.h"
#include "SimpleBlockFile.h"
#include "../FileFormats.h"
#include "sndfile.h"
@@ -114,8 +117,9 @@ SimpleBlockFile::SimpleBlockFile(wxFileNameWrapper &&baseFileName,
if (!(allowDeferredWrite && useCache) && !bypassCache)
{
bool bSuccess = WriteSimpleBlockFile(sampleData, sampleLen, format, NULL);
wxASSERT(bSuccess); // TODO: Handle failure here by alert to user and undo partial op.
wxUnusedVar(bSuccess);
if (!bSuccess)
throw FileException{
FileException::Cause::Write, GetFileName().name };
}
if (useCache) {
@@ -404,8 +408,7 @@ size_t SimpleBlockFile::ReadData(samplePtr data, sampleFormat format,
if ( framesRead < len ) {
if (mayThrow)
// Not the best exception class?
//throw FileException{ FileException::Cause::Read, mFileName }
;
throw FileException{ FileException::Cause::Read, mFileName };
ClearSamples(data, format, framesRead, len - framesRead);
}