Audacity  2.2.0
Generator.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Generator.h
6 
7  Two Abstract classes, Generator, and BlockGenerator, that effects which
8  generate audio should derive from.
9 
10  Block Generator breaks the synthesis task up into smaller parts.
11 
12  Dominic Mazzoni
13  Vaughan Johnson
14 
15 **********************************************************************/
16 
17 
18 #ifndef __AUDACITY_GENERATOR__
19 #define __AUDACITY_GENERATOR__
20 
21 #include "Effect.h"
22 
23 // Base class for Generators (effects which fill a given duration)
24 class Generator /* not final */ : public Effect
25 {
26 public:
27  Generator() { }
28 
29 protected:
30  // [ GenerateTrack() must be overridden by the actual generator class ]
31  // Precondition: mDuration > 0.0
32  // Postcondition: <tmp> is filled with the data intended for <track>
33  virtual bool GenerateTrack(WaveTrack *tmp,
34  const WaveTrack &track,
35  int ntrack) = 0;
36 
37  bool Init() override { return true; }
38 
39  // Actions to perform at the respective points in the generation process
40  // NEW virtuals
41  virtual void BeforeGenerate() { };
42  virtual void BeforeTrack(const WaveTrack & WXUNUSED(track)) { };
43 
44  // Actions to perform upon respective outcomes
45  // (For example, Success might save the parameters that were used.)
46  virtual void Success() { };
47  virtual void Failure() {};
48 
49  // Precondition:
50  // mDuration is set to the amount of time to generate in seconds
51  // Postcondition:
52  // If mDuration was valid (>= 0), then the tracks are replaced by the
53  // generated results and true is returned. Otherwise, return false.
54  bool Process() override;
55 };
56 
57 // Abstract generator which creates the sound in discrete blocks, whilst
58 // showing a progress bar
59 class BlockGenerator /* not final */ : public Generator {
60 public:
62 protected:
63  // Number of samples to generate
64  sampleCount numSamples;
65 
66  // Postcondition: data[0..block) filled with generated samples
67  virtual void GenerateBlock(float *data,
68  const WaveTrack &track,
69  size_t block) = 0;
70 
71  // Generate the track, one block at a time, & adding the results to tmp
72  bool GenerateTrack(WaveTrack *tmp, const WaveTrack &track, int ntrack) override;
73 };
74 
75 #endif
virtual void BeforeGenerate()
Definition: Generator.h:41
Base class for many of the effects in Audacity.
Definition: Effect.h:62
Definition: Generator.h:24
bool GenerateTrack(WaveTrack *tmp, const WaveTrack &track, int ntrack) override
Definition: Generator.cpp:117
Definition: Generator.h:59
A Track that contains audio waveform data.
Definition: WaveTrack.h:76
BlockGenerator()
Definition: Generator.h:61
bool Process() override
Definition: Generator.cpp:27
bool Init() override
Definition: Generator.h:37
virtual bool GenerateTrack(WaveTrack *tmp, const WaveTrack &track, int ntrack)=0
virtual void Success()
Definition: Generator.h:46
virtual void Failure()
Definition: Generator.h:47
virtual void GenerateBlock(float *data, const WaveTrack &track, size_t block)=0
Generator()
Definition: Generator.h:27
sampleCount numSamples
Definition: Generator.h:64
virtual void BeforeTrack(const WaveTrack &WXUNUSED(track))
Definition: Generator.h:42