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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_VCA.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
15{
16public:
17 VcaAutomatableParameter (const juce::String& xmlTag, const juce::String& name,
18 Plugin& owner, juce::Range<float> valueRangeToUse)
19 : AutomatableParameter (xmlTag, name, owner, valueRangeToUse)
20 {
21 }
22
24 {
25 notifyListenersOfDeletion();
26 }
27
28 juce::String valueToString (float value) override
29 {
30 return juce::Decibels::toString (volumeFaderPositionToDB (value) + 0.001);
31 }
32
33 float stringToValue (const juce::String& str) override
34 {
35 return decibelsToVolumeFaderPosition (dbStringToDb (str));
36 }
37};
38
39//==============================================================================
40VCAPlugin::VCAPlugin (PluginCreationInfo info) : Plugin (info)
41{
42 addAutomatableParameter (volParam = new VcaAutomatableParameter ("vca", TRANS("VCA"), *this, { 0.0f, 1.0f }));
43
44 volumeValue.referTo (state, IDs::volume, getUndoManager(), decibelsToVolumeFaderPosition (0.0f));
45 volParam->attachToCurrentValue (volumeValue);
46}
47
48VCAPlugin::~VCAPlugin()
49{
50 notifyListenersOfDeletion();
51
52 volParam->detachFromCurrentValue();
53}
54
55juce::ValueTree VCAPlugin::create()
56{
57 juce::ValueTree v (IDs::PLUGIN);
58 v.setProperty (IDs::type, xmlTypeName, nullptr);
59 return v;
60}
61
62const char* VCAPlugin::xmlTypeName = "vca";
63
64void VCAPlugin::initialise (const PluginInitialisationInfo&) {}
67
68float VCAPlugin::getSliderPos() const
69{
70 return volParam->getCurrentValue();
71}
72
73void VCAPlugin::setVolumeDb (float dB)
74{
75 setSliderPos (decibelsToVolumeFaderPosition (dB));
76}
77
78float VCAPlugin::getVolumeDb() const
79{
80 return volumeFaderPositionToDB (volParam->getCurrentValue());
81}
82
83void VCAPlugin::setSliderPos (float newV)
84{
85 volParam->setParameter (juce::jlimit (0.0f, 1.0f, newV), juce::sendNotification);
86}
87
88void VCAPlugin::muteOrUnmute()
89{
90 if (getVolumeDb() > -90.0f)
91 {
92 lastVolumeBeforeMute = getVolumeDb();
93 setVolumeDb (lastVolumeBeforeMute - 0.01f); // needed so that automation is recorded correctly
94 setVolumeDb (-100.0f);
95 }
96 else
97 {
98 if (lastVolumeBeforeMute < -100.0f)
99 lastVolumeBeforeMute = 0.0f;
100
101 setVolumeDb (getVolumeDb() + 0.01f); // needed so that automation is recorded correctly
102 setVolumeDb (lastVolumeBeforeMute);
103 }
104}
105
106float VCAPlugin::updateAutomationStreamAndGetVolumeDb (TimePosition time)
107{
108 if (isAutomationNeeded())
109 {
111 updateLastPlaybackTime();
112 }
113
114 return getVolumeDb();
115}
116
117bool VCAPlugin::canBeMoved()
118{
119 if (auto ft = dynamic_cast<FolderTrack*> (getOwnerTrack()))
120 return ft->isSubmixFolder();
121
122 return false;
123}
124
125void VCAPlugin::restorePluginStateFromValueTree (const juce::ValueTree& v)
126{
127 copyPropertiesToCachedValues (v, volumeValue);
128
129 for (auto p : getAutomatableParameters())
130 p->updateFromAttachedValue();
131}
132
133}} // namespace tracktion { inline namespace engine
static String toString(Type decibels, int decimalPlaces=2, Type minusInfinityDb=Type(defaultMinusInfinitydB), bool shouldIncludeSuffix=true, StringRef customMinusInfinityString={})
void updateParameterStreams(TimePosition)
Updates all the parameter streams to their positions at this time.
Track * getOwnerTrack() const
Returns the track if it's a track or clip plugin.
void deinitialise() override
Called after play stops to release resources.
void applyToBuffer(const PluginRenderContext &) override
Process the next block of data.
#define TRANS(stringLiteral)
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
sendNotification
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.