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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_FreezePoint.cpp
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
14FreezePointPlugin::ScopedTrackUnsoloer::ScopedTrackUnsoloer (Edit& e) : edit (e)
15{
16 int i = 0;
17
18 for (auto t : getAllTracks (edit))
19 {
20 if (t->isSolo (false))
21 {
22 soloed.setBit (i);
23 t->setSolo (false);
24 }
25
26 if (t->isSoloIsolate (false))
27 {
28 soloIsolated.setBit (i);
29 t->setSoloIsolate (false);
30 }
31
32 ++i;
33 }
34}
35
36FreezePointPlugin::ScopedTrackUnsoloer::~ScopedTrackUnsoloer()
37{
38 int i = 0;
39
40 for (auto t : getAllTracks (edit))
41 {
42 if (soloed[i])
43 t->setSolo (true);
44
45 if (soloIsolated[i])
46 t->setSoloIsolate (true);
47
48 ++i;
49 }
50}
51
52//==============================================================================
53FreezePointPlugin::ScopedTrackSoloIsolator::ScopedTrackSoloIsolator (Edit& e, Track::Array& trks)
54 : edit (e), tracks (trks)
55{
56 int i = 0;
57
58 for (auto t : tracks)
59 {
60 if (! t->isSoloIsolate (false))
61 {
62 notSoloIsolated.setBit (i);
63 t->setSoloIsolate (true);
64 }
65
66 if (t->isMuted (false))
67 {
68 muted.setBit (i);
69 t->setMute (false);
70 }
71
72 ++i;
73 }
74}
75
76FreezePointPlugin::ScopedTrackSoloIsolator::~ScopedTrackSoloIsolator()
77{
78 int i = 0;
79
80 for (auto t : tracks)
81 {
82 if (notSoloIsolated[i])
83 t->setSoloIsolate (false);
84
85 if (muted[i])
86 t->setMute (true);
87
88 ++i;
89 }
90}
91
92//==============================================================================
93FreezePointPlugin::ScopedPluginDisabler::ScopedPluginDisabler (Track& t, juce::Range<int> pluginsToDisable)
94 : track (t)
95{
96 indexes = pluginsToDisable.getIntersectionWith (juce::Range<int> (0, track.pluginList.size()));
97
98 int i = 0;
99
100 for (auto p : track.pluginList)
101 enabled.setBit (i++, p->isEnabled());
102
103 enablePlugins (false);
104}
105
106FreezePointPlugin::ScopedPluginDisabler::~ScopedPluginDisabler()
107{
108 enablePlugins (true);
109}
110
111void FreezePointPlugin::ScopedPluginDisabler::enablePlugins (bool enable)
112{
113 int i = 0;
114
115 for (auto p : track.pluginList)
116 {
117 if (indexes.contains (i))
118 p->setEnabled (enable && enabled[i]);
119
120 ++i;
121 }
122}
123
124//==============================================================================
125FreezePointPlugin::ScopedTrackFreezer::ScopedTrackFreezer (FreezePointPlugin& o)
126 : owner (o), wasFrozen (o.isTrackFrozen())
127{
128 if (auto at = dynamic_cast<AudioTrack*> (owner.getOwnerTrack()))
129 trackID = at->itemID;
130}
131
132FreezePointPlugin::ScopedTrackFreezer::~ScopedTrackFreezer()
133{
134 if (! wasFrozen && trackID.isValid())
135 return;
136
137 if (auto at = dynamic_cast<AudioTrack*> (owner.getOwnerTrack()))
138 if (! at->isFrozen (Track::groupFreeze))
139 if (trackID != at->itemID)
140 if (at->edit.engine.getPropertyStorage().getProperty (SettingID::autoFreeze, 1))
141 at->freezeTrackAsync();
142
143 owner.updateTrackFreezeStatus();
144}
145
146std::unique_ptr<FreezePointPlugin::ScopedTrackFreezer> FreezePointPlugin::createTrackFreezer (const Plugin::Ptr& p)
147{
148 if (auto fp = dynamic_cast<FreezePointPlugin*> (p.get()))
149 return std::unique_ptr<FreezePointPlugin::ScopedTrackFreezer> (new ScopedTrackFreezer (*fp));
150
151 return {};
152}
153
154//==============================================================================
155const char* FreezePointPlugin::xmlTypeName ("freezePoint");
156
157FreezePointPlugin::FreezePointPlugin (PluginCreationInfo info) : Plugin (info)
158{
159}
160
161FreezePointPlugin::~FreezePointPlugin()
162{
163 notifyListenersOfDeletion();
164}
165
166juce::ValueTree FreezePointPlugin::create()
167{
168 return createValueTree (IDs::PLUGIN,
169 IDs::type, xmlTypeName);
170}
171
172void FreezePointPlugin::initialiseFully()
173{
174 Plugin::initialiseFully();
175 updateTrackFreezeStatus();
176}
177
178void FreezePointPlugin::initialise (const PluginInitialisationInfo&) {}
179void FreezePointPlugin::deinitialise() {}
180void FreezePointPlugin::applyToBuffer (const PluginRenderContext&) {}
181
182//==============================================================================
183void FreezePointPlugin::updateTrackFreezeStatus()
184{
185 if (auto at = dynamic_cast<AudioTrack*> (getOwnerTrack()))
186 {
187 auto newIndex = at->pluginList.indexOf (this);
188
189 if (lastFreezeIndex != newIndex)
190 {
191 if (lastFreezeIndex != -1
192 && isTrackFrozen()
193 && ! at->pluginList.getEdit().isLoading())
194 {
195 freezeTrack (false);
196 at->freezeTrackAsync();
197 }
198
199 lastFreezeIndex = newIndex;
200 }
201 }
202}
203
204bool FreezePointPlugin::isTrackFrozen() const
205{
206 if (auto at = dynamic_cast<AudioTrack*> (getOwnerTrack()))
207 return at->isFrozen (Track::individualFreeze);
208
209 return false;
210}
211
212void FreezePointPlugin::freezeTrack (bool shouldBeFrozen)
213{
214 if (auto at = dynamic_cast<AudioTrack*> (getOwnerTrack()))
215 {
216 const AudioTrack::FreezePointRemovalInhibitor inhibitor (*at);
217 at->setFrozen (shouldBeFrozen, Track::individualFreeze);
218 }
219
220 changed();
221}
222
223}} // namespace tracktion { inline namespace engine
constexpr Range getIntersectionWith(Range other) const noexcept
T is_pointer_v
juce::Array< Track * > getAllTracks(const Edit &edit)
Returns all the tracks in an Edit.
Passed into Plugins when they are being initialised, to give them useful contextual information that ...
The context passed to plugin render methods to provide it with buffers to fill.