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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_EditPlaybackContext.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//==========================================================================
15//==========================================================================
17{
18public:
21
22 void removeInstanceForDevice (InputDevice&);
23
26 void addMidiInputDeviceInstance (InputDevice&);
27
28 void clearNodes();
29 void createPlayAudioNodes (TimePosition startTime);
30 void createPlayAudioNodesIfNeeded (TimePosition startTime);
31 void reallocate();
32
34 bool isPlaybackGraphAllocated() const { return isAllocated; }
35
36 // Prepares the graph but doesn't actually start the playhead
37 void prepareForPlaying (TimePosition startTime);
38 void prepareForRecording (TimePosition startTime, TimePosition punchIn);
39
40 // Plays this context in sync with another context
41 void syncToContext (EditPlaybackContext* contextToSyncTo, TimePosition previousBarTime, TimeDuration syncInterval);
42
43 tl::expected<Clip::Array, juce::String> stopRecording (InputDeviceInstance&, bool discardRecordings);
44 tl::expected<Clip::Array, juce::String> stopRecording (TimePosition unloopedEnd, bool discardRecordings);
45 juce::Result applyRetrospectiveRecord (juce::Array<Clip*>* clipsCreated = nullptr, bool armedOnly = false);
46
48 InputDeviceInstance* getInputFor (InputDevice*) const;
49 OutputDeviceInstance* getOutputFor (OutputDevice*) const;
50
51 Edit& edit;
52 TransportControl& transport;
53 LevelMeasurer masterLevels;
54 MidiNoteDispatcher midiDispatcher;
55
67
68 // This is a global setting
69 static bool shouldAddAntiDenormalisationNoise (Engine&);
70 static void setAddAntiDenormalisationNoise (Engine&, bool);
71
72 //==============================================================================
84
85 //==============================================================================
86 // These methods deal directly with the playhead so won't have any latency induced by syncing to the messaged thread.
87 bool isPlaying() const;
88 bool isLooping() const;
89 bool isDragging() const;
90
91 TimePosition getPosition() const;
92 TimePosition getUnloopedPosition() const;
93 TimeRange getLoopTimes() const;
94
96 int getLatencySamples() const;
97 TimePosition getAudibleTimelineTime();
98 double getSampleRate() const;
99 void updateNumCPUs();
100
102 void setSpeedCompensation (double plusOrMinus);
103
105 void setTempoAdjustment (double plusOrMinusProportion);
106
117 void postPosition (TimePosition positionToJumpTo, std::optional<TimePosition> whenToJump = {});
118
121
122 void play();
123 void stop();
124
127
128 TimePosition globalStreamTimeToEditTime (double) const;
129 TimePosition globalStreamTimeToEditTimeUnlooped (double) const;
130 void resyncToGlobalStreamTime (juce::Range<double>, double sampleRate);
131
133 tracktion::graph::PlayHead* getNodePlayHead() const;
134
136 void blockUntilSyncPointChange();
137
139 static void setThreadPoolStrategy (int);
141 static int getThreadPoolStrategy();
142
146 static void enablePooledMemory (bool);
147
152 static void enableNodeMemorySharing (bool);
153
157 static void enableAudioWorkgroup (bool);
158
160 int getNumActivelyRecordingDevices() const;
162 void incrementNumActivelyRecordingDevices();
164 void decrementNumActivelyRecordingDevices();
165
166private:
167 bool isAllocated = false;
168
169 struct ProcessPriorityBooster
170 {
171 ProcessPriorityBooster (Engine& engine);
172 ~ProcessPriorityBooster();
173
174 Engine& engine;
175 };
176
178
179 juce::OwnedArray<InputDeviceInstance> waveInputs, midiInputs;
182
183 void releaseDeviceList();
184 void rebuildDeviceList();
185
186 void prepareOutputDevices (TimePosition start);
187 juce::Result startRecording (TimePosition start, TimePosition punchIn);
188 void startPlaying (TimePosition start);
189
190 friend class DeviceManager;
191
193 TimePosition previousBarTime;
194 TimeDuration syncInterval;
195 bool hasSynced = false;
196 double lastStreamPos = 0;
197
198 struct ContextSyncroniser;
199 std::unique_ptr<ContextSyncroniser> contextSyncroniser;
200
201 struct NodePlaybackContext;
202 std::unique_ptr<NodePlaybackContext> nodePlaybackContext;
203
205 std::atomic<double> audiblePlaybackTime { 0.0 };
206 std::atomic<int> activelyRecordingInputDevices { 0 };
207
208 void createNode();
209 void fillNextNodeBlock (float* const* allChannels, int numChannels, int numSamples);
210
211 JUCE_DECLARE_WEAK_REFERENCEABLE (EditPlaybackContext)
213};
214
215//==============================================================================
216//==============================================================================
218namespace detail
219{
222 {
224 {
225 epc.incrementNumActivelyRecordingDevices();
226 }
227
229 {
230 epc.decrementNumActivelyRecordingDevices();
231 }
232
234 };
235}
236
237}} // namespace tracktion { inline namespace engine
static void enablePooledMemory(bool)
Enables reusing of audio buffers during graph processing which may reduce the memory use at the cost ...
void addWaveInputDeviceInstance(InputDevice &)
Note this doesn't check for device enablement.
void postPosition(TimePosition positionToJumpTo, std::optional< TimePosition > whenToJump={})
Posts a transport position change.
void setSpeedCompensation(double plusOrMinus)
This will increase/decrease playback speed by resampling, pitching the output up or down.
bool isPlaybackGraphAllocated() const
Returns true if a playback graph is currently allocated.
int getLatencySamples() const
Returns the overall latency of the currently prepared graph.
static void enableNodeMemorySharing(bool)
Enables reusing of audio buffers during graph processing which may reduce the memory use at the cost ...
void setTempoAdjustment(double plusOrMinusProportion)
This will increase/decrease playback speed by changing the tempo, maintaining pitch where possible.
std::optional< TimePosition > getPendingPositionChange() const
Returns a pending position change if there is one.
std::optional< SyncPoint > getSyncPoint() const
Returns the last reference sample position and the edit time and beat that it corresponded to.
static void enableAudioWorkgroup(bool)
Enables using AudioWorkgroups.
The Tracktion Edit class!
The Engine is the central class for all tracktion sessions.
An instance of an InputDevice that's available to an Edit.
Represents an input device.
Monitors the levels of buffers that are passed in, and keeps peak values, overloads,...
Base class for audio or midi output devices, to which a track's output can be sent.
Controls the transport of an Edit's playback.
Converts a monotonically increasing reference range in to a timeline range.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_DECLARE_WEAK_REFERENCEABLE(Class)
Represents a duration in real-life time.
Represents a position in real-life time.
Used to temporarily reduce the process priority if a long operation like a file save is taking place.
Releases and then optionally reallocates the context's device list safely.