Audacity  3.0.3
SampleBlock.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 SampleBlock.cpp
6 
7 **********************************************************************/
8 
9 
10 #include "InconsistencyException.h"
11 #include "SampleBlock.h"
12 #include "SampleFormat.h"
13 
14 #include <wx/defs.h>
15 
17 {
18  static SampleBlockFactoryFactory theFactory;
19  return theFactory;
20 }
21 
23  SampleBlockFactoryFactory newFactory )
24 {
25  auto &theFactory = installedFactory();
26  auto result = std::move( theFactory );
27  theFactory = std::move( newFactory );
28  return result;
29 }
30 
32 {
33  auto &factory = installedFactory();
34  if ( ! factory )
36  return factory( project );
37 }
38 
40 
42  size_t numsamples,
43  sampleFormat srcformat)
44 {
45  auto result = DoCreate(src, numsamples, srcformat);
46  if (!result)
48  return result;
49 }
50 
52  size_t numsamples,
53  sampleFormat srcformat)
54 {
55  auto result = DoCreateSilent(numsamples, srcformat);
56  if (!result)
58  return result;
59 }
60 
62  sampleFormat srcformat,
63  const wxChar **attrs)
64 {
65  auto result = DoCreateFromXML(srcformat, attrs);
66  if (!result)
68  return result;
69 }
70 
71 SampleBlock::~SampleBlock() = default;
72 
74  sampleFormat destformat,
75  size_t sampleoffset,
76  size_t numsamples, bool mayThrow)
77 {
78  try{ return DoGetSamples(dest, destformat, sampleoffset, numsamples); }
79  catch( ... ) {
80  if( mayThrow )
81  throw;
82  ClearSamples( dest, destformat, 0, numsamples );
83  return 0;
84  }
85 }
86 
88  size_t start, size_t len, bool mayThrow)
89 {
90  try{ return DoGetMinMaxRMS(start, len); }
91  catch( ... ) {
92  if( mayThrow )
93  throw;
94  return {};
95  }
96 }
97 
98  MinMaxRMS SampleBlock::GetMinMaxRMS(bool mayThrow) const
99 {
100  try{ return DoGetMinMaxRMS(); }
101  catch( ... ) {
102  if( mayThrow )
103  throw;
104  return {};
105  }
106 }
107 
ClearSamples
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
Definition: SampleFormat.cpp:77
SampleBlock::GetSamples
size_t GetSamples(samplePtr dest, sampleFormat destformat, size_t sampleoffset, size_t numsamples, bool mayThrow=true)
Definition: SampleBlock.cpp:73
SampleBlockFactory::DoCreate
virtual SampleBlockPtr DoCreate(constSamplePtr src, size_t numsamples, sampleFormat srcformat)=0
SampleBlockFactory::~SampleBlockFactory
virtual ~SampleBlockFactory()
InconsistencyException.h
MessageBoxException for violation of preconditions or assertions.
SampleBlockPtr
std::shared_ptr< SampleBlock > SampleBlockPtr
Definition: SampleBlock.h:23
SampleBlockFactory::DoCreateFromXML
virtual SampleBlockPtr DoCreateFromXML(sampleFormat srcformat, const wxChar **attrs)=0
MinMaxRMS
Definition: SampleBlock.h:32
SampleBlockFactory::DoCreateSilent
virtual SampleBlockPtr DoCreateSilent(size_t numsamples, sampleFormat srcformat)=0
SampleBlock.h
SampleBlockFactory::Create
SampleBlockPtr Create(constSamplePtr src, size_t numsamples, sampleFormat srcformat)
Definition: SampleBlock.cpp:41
installedFactory
static SampleBlockFactoryFactory & installedFactory()
Definition: SampleBlock.cpp:16
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:817
constSamplePtr
const char * constSamplePtr
Definition: SampleFormat.h:50
SampleBlock::DoGetSamples
virtual size_t DoGetSamples(samplePtr dest, sampleFormat destformat, size_t sampleoffset, size_t numsamples)=0
SampleBlock::~SampleBlock
virtual ~SampleBlock()
THROW_INCONSISTENCY_EXCEPTION
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
Definition: InconsistencyException.h:79
SampleBlockFactory::New
static SampleBlockFactoryPtr New(AudacityProject &project)
Definition: SampleBlock.cpp:31
SampleBlockFactory::RegisterFactoryFactory
static SampleBlockFactoryFactory RegisterFactoryFactory(SampleBlockFactoryFactory newFactory)
Definition: SampleBlock.cpp:22
sampleFormat
sampleFormat
Definition: SampleFormat.h:29
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
SampleBlockFactory::CreateFromXML
SampleBlockPtr CreateFromXML(sampleFormat srcformat, const wxChar **attrs)
Definition: SampleBlock.cpp:61
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
SampleBlockFactory::CreateSilent
SampleBlockPtr CreateSilent(size_t numsamples, sampleFormat srcformat)
Definition: SampleBlock.cpp:51
SampleBlockFactoryPtr
std::shared_ptr< SampleBlockFactory > SampleBlockFactoryPtr
Definition: SampleBlock.h:25
SampleBlock::DoGetMinMaxRMS
virtual MinMaxRMS DoGetMinMaxRMS() const =0
SampleBlock::GetMinMaxRMS
MinMaxRMS GetMinMaxRMS(size_t start, size_t len, bool mayThrow=true)
Gets extreme values for the specified region.
Definition: SampleBlock.cpp:87
SampleBlockFactoryFactory
std::function< SampleBlockFactoryPtr(AudacityProject &) > SampleBlockFactoryFactory
Definition: SampleBlock.h:27
SampleFormat.h