tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_RenderManager.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
14//==============================================================================
20 private juce::AsyncUpdater
21{
22public:
23 //==============================================================================
31 private juce::Timer
32 {
33 public:
34 //==============================================================================
36
37 ~Job() override;
38
40 JobStatus runJob() override;
41
43 float getCurrentTaskProgress() override { return progress; }
44
46 void cancelJob();
47
51 void cleanUpDanglingJob() { selfReference = nullptr; }
52
53 //==============================================================================
54 void incReferenceCount() noexcept { ++refCount; }
55 bool decReferenceCountWithoutDeleting() noexcept;
56 int getReferenceCount() const noexcept { return refCount.get(); }
57
58 //==============================================================================
59 struct Listener
60 {
61 virtual ~Listener() {}
62 virtual void jobStarted (RenderManager::Job&) {}
63 virtual void jobFinished (RenderManager::Job&, bool completedOk) = 0;
64 };
65
66 void addListener (Listener* l) { listeners.add (l); }
67 void removeListener (Listener* l) { listeners.remove (l); }
68
69 //==============================================================================
70 Engine& engine;
71 AudioFile proxy;
72 std::atomic<float> progress { 0 };
73
78 virtual bool setUpRender() = 0;
79
83 virtual bool renderNextBlock() = 0;
84
89 virtual bool completeRender() = 0;
90
91 protected:
92 //==============================================================================
93 Job (Engine&, const AudioFile& proxy); // don't instantiate directly!
94
95 private:
96 //==============================================================================
97 struct UpdateMessage : public juce::Message
98 {
99 enum Type
100 {
101 started,
102 succeded,
103 cancelled,
104 unknown
105 };
106
107 UpdateMessage (Type t) : type (t) {}
108
109 static Type getType (const juce::Message& message)
110 {
111 if (auto um = dynamic_cast<const UpdateMessage*> (&message))
112 return um->type;
113
114 return unknown;
115 }
116
117 Type type;
118
120 };
121
122 //==============================================================================
123 enum { messageRetryTimeout = 50 };
124
126 juce::Atomic<int> refCount;
127 Ptr selfReference;
128 juce::CriticalSection messageLock, finishedLock;
129 juce::Array<UpdateMessage::Type> messagesToResend;
130 bool isInitialised = false, hasFinished = false;
131
132 void sendCompletionMessages (bool success);
133
134 void handleMessage (const juce::Message&) override;
135 void timerCallback() override;
136
138 };
139
140 //==============================================================================
141 RenderManager (Engine&);
142 ~RenderManager() override;
143
145 void cleanUp();
146
147 //==============================================================================
152 static AudioFile getAudioFileForHash (Engine&, const juce::File& directory, HashCode hash);
153
155 Job::Ptr getRenderJobWithoutCreating (const AudioFile& audioFile) { return findJob (audioFile); }
156
159
161 int getNumJobs() noexcept;
162
163 //==============================================================================
165 static juce::StringRef getFileRenderPrefix() { return "render_"; }
166
168 bool isProxyBeingGenerated (const AudioFile& proxyFile) noexcept;
169
171 float getProportionComplete (const AudioFile& proxyFile, float defaultVal) noexcept;
172
173 Engine& engine;
174
175private:
176 //==============================================================================
177 juce::Array<Job*> jobs, danglingJobs;
178 juce::OwnedArray<Job> jobsToDelete;
179 juce::CriticalSection jobListLock, deleteListLock;
180
181 Job::Ptr findJob (const AudioFile&) noexcept;
182 void addJobInternal (Job*) noexcept;
183 void removeJobInternal (Job*) noexcept;
184 void addJobToPool (Job*) noexcept;
185 void deleteJob (Job*);
186
187 void handleAsyncUpdate() override;
188
190};
191
192}} // namespace tracktion { inline namespace engine
The Engine is the central class for all tracktion sessions.
The base class that all generator jobs derive from.
virtual bool completeRender()=0
This is called once after all the render blocks have completed.
virtual bool renderNextBlock()=0
During a render process this will be repeatedly called.
void cleanUpDanglingJob()
Called during app shutdown by the manager on any jobs that haven't had a chance to recieve their asyn...
float getCurrentTaskProgress() override
Returns the progress of the job.
JobStatus runJob() override
Performs the render.
void cancelJob()
Cancels the current job safely making sure any listeners are called appropriately.
virtual bool setUpRender()=0
Subclasses should override this to set-up their render process.
Manages a set of reference counted render jobs and can be used to retrieve matching jobs or create ne...
void cleanUp()
Cleans up any remaining jobs - should be called before the manager is deleted.
static juce::StringRef getFileRenderPrefix()
Returns the prefix used for render files.
static AudioFile getAudioFileForHash(Engine &, const juce::File &directory, HashCode hash)
Returns the AudioFile for a particular hash.
Job::Ptr getRenderJobWithoutCreating(const AudioFile &audioFile)
This will return a Ptr to an existing render job for an audio file or nullptr if no job is in progres...
juce::ReferenceCountedArray< Job > getRenderJobsWithoutCreating(const AudioFile &)
Returns all the jobs that may be processing the given file.
int getNumJobs() noexcept
Returns the number of jobs in the pool.
bool isProxyBeingGenerated(const AudioFile &proxyFile) noexcept
Returns true if a render is currently being performed for this AudioFile.
float getProportionComplete(const AudioFile &proxyFile, float defaultVal) noexcept
Returns true if a render is currently being performed for this AudioFile.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Type get() const noexcept