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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_AuxSend.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
14AuxSendPlugin::AuxSendPlugin (PluginCreationInfo info) : Plugin (info)
15{
16 auto um = getUndoManager();
17 busNumber.referTo (state, IDs::busNum, um);
18 gainLevel.referTo (state, IDs::auxSendSliderPos, um, decibelsToVolumeFaderPosition (0.0f));
19 invertPhase.referTo (state, IDs::phase, um, false);
20 lastVolumeBeforeMute.referTo (state, IDs::lastVolumeBeforeMuteDb, um, 0.0f);
21
22 gain = addParam ("send level", TRANS("Send level"), { 0.0f, 1.0f },
23 [] (float value) { return juce::Decibels::toString (volumeFaderPositionToDB (value)); },
24 [] (const juce::String& s) { return decibelsToVolumeFaderPosition (dbStringToDb (s)); });
25
26 gain->attachToCurrentValue (gainLevel);
27
28 quickParamName = "send level";
29}
30
31AuxSendPlugin::~AuxSendPlugin()
32{
33 notifyListenersOfDeletion();
34 gain->detachFromCurrentValue();
35}
36
37bool AuxSendPlugin::shouldProcess()
38{
39 const juce::ScopedLock sl (ownerTrackLock);
40
41 if (ownerTrack != nullptr)
42 {
43 // If this track gets disabled when muted,
44 // we don't need to worry about this since
45 // our plugin will be disabled anyway
46 if (! ownerTrack->processAudioNodesWhileMuted())
47 return true;
48
49 return ! ownerTrack->isMuted (true);
50 }
51
52 return true;
53}
54
55const char* AuxSendPlugin::xmlTypeName = "auxsend";
56
57juce::String AuxSendPlugin::getName() const
58{
59 juce::String nm (edit.getAuxBusName (busNumber));
60
61 if (nm.isNotEmpty())
62 return "S:" + nm;
63
64 return TRANS("Aux Send") + " #" + juce::String (busNumber + 1);
65}
66
67juce::String AuxSendPlugin::getShortName (int)
68{
69 auto nm = edit.getAuxBusName (busNumber);
70
71 if (nm.isNotEmpty())
72 return "S:" + nm;
73
74 return TRANS("Send") + ":" + juce::String (busNumber + 1);
75}
76
77void AuxSendPlugin::initialise (const PluginInitialisationInfo& info)
78{
79 lastGain = volumeFaderPositionToGain (gain->getCurrentValue());
80
81 initialiseWithoutStopping (info);
82}
83
84void AuxSendPlugin::initialiseWithoutStopping (const PluginInitialisationInfo&)
85{
86 TRACKTION_ASSERT_MESSAGE_THREAD
87 auto newOwnerTrack = getOwnerTrack();
88
89 const juce::ScopedLock sl (ownerTrackLock);
90 ownerTrack = newOwnerTrack;
91}
92
93void AuxSendPlugin::deinitialise()
94{
95}
96
97void AuxSendPlugin::applyToBuffer (const PluginRenderContext&)
98{
99}
100
101juce::String AuxSendPlugin::getBusName()
102{
103 auto busName = edit.getAuxBusName (busNumber);
104
105 if (busName.isNotEmpty())
106 return busName;
107
108 return getDefaultBusName (busNumber);
109}
110
111void AuxSendPlugin::setGainDb (float newDb)
112{
113 float newPos = decibelsToVolumeFaderPosition (newDb);
114
115 if (gain->getCurrentValue() != newPos)
116 {
117 gain->setParameter (newPos, juce::sendNotification);
118 changed();
119 }
120}
121
122void AuxSendPlugin::setMute (bool b)
123{
124 if (b)
125 {
126 lastVolumeBeforeMute = getGainDb();
127 setGainDb (lastVolumeBeforeMute - 0.01f); // needed so that automation is recorded correctly
128 setGainDb (-100.0f);
129 }
130 else
131 {
132 if (lastVolumeBeforeMute < -100.0f)
133 lastVolumeBeforeMute = 0.0f;
134
135 setGainDb (getGainDb() + 0.01f); // needed so that automation is recorded correctly
136 setGainDb (lastVolumeBeforeMute);
137 }
138}
139
140bool AuxSendPlugin::isMute()
141{
142 return getGainDb() <= -90.0f;
143}
144
145juce::String AuxSendPlugin::getDefaultBusName (int index)
146{
147 return "Bus #" + juce::String (index + 1);
148}
149
150juce::StringArray AuxSendPlugin::getBusNames (Edit& ed, int maxNumBusses)
151{
152 juce::StringArray buses;
153
154 for (int i = 0; i < maxNumBusses; ++i)
155 {
156 auto nm = getDefaultBusName (i);
157
158 if (ed.getAuxBusName (i).isNotEmpty())
159 nm << " (" << ed.getAuxBusName (i) << ")";
160
161 buses.add (nm);
162 }
163
164 return buses;
165}
166
167void AuxSendPlugin::restorePluginStateFromValueTree (const juce::ValueTree& v)
168{
169 copyPropertiesToCachedValues (v, gainLevel, busNumber, invertPhase);
170
171 for (auto p : getAutomatableParameters())
172 p->updateFromAttachedValue();
173}
174
175}} // namespace tracktion { inline namespace engine
static String toString(Type decibels, int decimalPlaces=2, Type minusInfinityDb=Type(defaultMinusInfinitydB), bool shouldIncludeSuffix=true, StringRef customMinusInfinityString={})
void add(String stringToAdd)
bool isNotEmpty() const noexcept
#define TRANS(stringLiteral)
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.