mirror of
https://github.com/cookiengineer/audacity
synced 2026-03-08 07:25:39 +01:00
* Change usage of AutoCommitTransaction::Rollback... ... It is the more useful pattern (as in many finally blocks) for the failure path in the destructor (which rolls back) to be the default, but an explicit call must inform it of success. This corrects the early return paths in Effect::DoEffect(). Throw inconsistency exception if Commit() is called again after having been called once, successfully Also remove a friend declaration * UndoManager's interface uses consistent 0-based indexing of states... ... Returned by GetCurrentState() and used by SetStateTo(), GetLongDescription(), GetShortDescription() * SampleBlock::GetBlockID is const * Generalized function to visit sample blocks used in a TrackList... ... Eliminating some duplication; put it in WaveTrack, not Track, to avoid a dependency cycle. * Eliminate more repetition with BlockSpaceUsageAccumulator * Function to delete all blocks of/not-of a given set in one command
159 lines
4.9 KiB
C++
159 lines
4.9 KiB
C++
/**********************************************************************
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
SampleBlock.h
|
|
|
|
**********************************************************************/
|
|
|
|
#ifndef __AUDACITY_SAMPLE_BLOCK__
|
|
#define __AUDACITY_SAMPLE_BLOCK__
|
|
|
|
#include "audacity/Types.h"
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
|
|
class AudacityProject;
|
|
class ProjectFileIO;
|
|
class XMLWriter;
|
|
|
|
class SampleBlock;
|
|
using SampleBlockPtr = std::shared_ptr<SampleBlock>;
|
|
class SampleBlockFactory;
|
|
using SampleBlockFactoryPtr = std::shared_ptr<SampleBlockFactory>;
|
|
using SampleBlockFactoryFactory =
|
|
std::function< SampleBlockFactoryPtr( AudacityProject& ) >;
|
|
|
|
using SampleBlockID = long long;
|
|
|
|
class MinMaxRMS
|
|
{
|
|
public:
|
|
float min = 0;
|
|
float max = 0;
|
|
float RMS = 0;
|
|
};
|
|
|
|
class SqliteSampleBlockFactory;
|
|
|
|
///\brief Abstract class allows access to contents of a block of sound samples,
|
|
/// serialization as XML, and reference count management that can suppress
|
|
/// reclamation of its storage
|
|
class SampleBlock
|
|
{
|
|
public:
|
|
virtual ~SampleBlock();
|
|
|
|
virtual void CloseLock() = 0;
|
|
|
|
virtual SampleBlockID GetBlockID() const = 0;
|
|
|
|
// If !mayThrow and there is an error, ignores it and returns zero.
|
|
// That may be appropriate when only attempting to display samples, not edit.
|
|
size_t GetSamples(samplePtr dest,
|
|
sampleFormat destformat,
|
|
size_t sampleoffset,
|
|
size_t numsamples, bool mayThrow = true);
|
|
|
|
virtual size_t GetSampleCount() const = 0;
|
|
|
|
virtual bool
|
|
GetSummary256(float *dest, size_t frameoffset, size_t numframes) = 0;
|
|
virtual bool
|
|
GetSummary64k(float *dest, size_t frameoffset, size_t numframes) = 0;
|
|
|
|
/// Gets extreme values for the specified region
|
|
// If !mayThrow and there is an error, ignores it and returns zeroes.
|
|
// That may be appropriate when only attempting to display samples, not edit.
|
|
MinMaxRMS GetMinMaxRMS(
|
|
size_t start, size_t len, bool mayThrow = true);
|
|
|
|
/// Gets extreme values for the entire block
|
|
// If !mayThrow and there is an error, ignores it and returns zeroes.
|
|
// That may be appropriate when only attempting to display samples, not edit.
|
|
MinMaxRMS GetMinMaxRMS(bool mayThrow = true) const;
|
|
|
|
virtual size_t GetSpaceUsage() const = 0;
|
|
|
|
virtual void SaveXML(XMLWriter &xmlFile) = 0;
|
|
|
|
protected:
|
|
virtual size_t DoGetSamples(samplePtr dest,
|
|
sampleFormat destformat,
|
|
size_t sampleoffset,
|
|
size_t numsamples) = 0;
|
|
|
|
virtual MinMaxRMS DoGetMinMaxRMS(size_t start, size_t len) = 0;
|
|
|
|
virtual MinMaxRMS DoGetMinMaxRMS() const = 0;
|
|
};
|
|
|
|
// Makes a useful function object
|
|
inline std::function< void(const SampleBlock&) >
|
|
BlockSpaceUsageAccumulator (unsigned long long &total)
|
|
{
|
|
return [&total]( const SampleBlock &block ){
|
|
total += block.GetSpaceUsage();
|
|
};
|
|
};
|
|
|
|
///\brief abstract base class with methods to produce @ref SampleBlock objects
|
|
class SampleBlockFactory
|
|
{
|
|
public:
|
|
// Install global function that produces a sample block factory object for
|
|
// a given project; the factory has methods that later make sample blocks.
|
|
// Return the previously installed factory.
|
|
static SampleBlockFactoryFactory RegisterFactoryFactory(
|
|
SampleBlockFactoryFactory newFactory );
|
|
|
|
// Invoke the installed factory (throw an exception if none was installed)
|
|
static SampleBlockFactoryPtr New( AudacityProject &project );
|
|
|
|
virtual ~SampleBlockFactory();
|
|
|
|
// Returns a non-null pointer or else throws an exception
|
|
SampleBlockPtr Get(SampleBlockID sbid);
|
|
|
|
// Returns a non-null pointer or else throws an exception
|
|
SampleBlockPtr Create(samplePtr src,
|
|
size_t numsamples,
|
|
sampleFormat srcformat);
|
|
|
|
// Returns a non-null pointer or else throws an exception
|
|
SampleBlockPtr CreateSilent(
|
|
size_t numsamples,
|
|
sampleFormat srcformat);
|
|
|
|
// Returns a non-null pointer or else throws an exception
|
|
SampleBlockPtr CreateFromXML(
|
|
sampleFormat srcformat,
|
|
const wxChar **attrs);
|
|
|
|
protected:
|
|
// The override should throw more informative exceptions on error than the
|
|
// default InconsistencyException thrown by Create
|
|
virtual SampleBlockPtr DoGet(SampleBlockID sbid) = 0;
|
|
|
|
// The override should throw more informative exceptions on error than the
|
|
// default InconsistencyException thrown by Create
|
|
virtual SampleBlockPtr DoCreate(samplePtr src,
|
|
size_t numsamples,
|
|
sampleFormat srcformat) = 0;
|
|
|
|
// The override should throw more informative exceptions on error than the
|
|
// default InconsistencyException thrown by CreateSilent
|
|
virtual SampleBlockPtr DoCreateSilent(
|
|
size_t numsamples,
|
|
sampleFormat srcformat) = 0;
|
|
|
|
// The override should throw more informative exceptions on error than the
|
|
// default InconsistencyException thrown by CreateFromXML
|
|
virtual SampleBlockPtr DoCreateFromXML(
|
|
sampleFormat srcformat,
|
|
const wxChar **attrs) = 0;
|
|
};
|
|
|
|
#endif
|