11namespace tracktion {
inline namespace engine
24 notifyListenersOfDeletion();
34 return decibelsToVolumeFaderPosition (dbStringToDb (str));
49 notifyListenersOfDeletion();
54 return getPanString (value);
75 notifyListenersOfDeletion();
78 juce::String getPluginAndParamName()
const override {
return getParameterName(); }
79 juce::String getFullName()
const override {
return getParameterName(); }
93 notifyListenersOfDeletion();
96 juce::String getPluginAndParamName()
const override {
return getParameterName(); }
97 juce::String getFullName()
const override {
return getParameterName(); }
101VolumeAndPanPlugin::VolumeAndPanPlugin (
PluginCreationInfo info,
bool isMasterVolumeNode)
103 isMasterVolume (isMasterVolumeNode)
105 auto um = getUndoManager();
107 volume.referTo (state, IDs::volume, um, decibelsToVolumeFaderPosition (0));
108 pan.referTo (state, IDs::pan, um);
109 applyToMidi.referTo (state, IDs::applyToMidi, um);
110 ignoreVca.referTo (state, IDs::ignoreVca, um);
111 polarity.referTo (state, IDs::polarity, um);
112 panLaw.referTo (state, IDs::panLaw, um);
114 if (isMasterVolumeNode)
116 addAutomatableParameter (volParam =
new MasterVolParameter (
"master volume",
TRANS(
"Master volume"), *
this, { 0.0f, 1.0f }));
117 addAutomatableParameter (panParam =
new MasterPanParameter (
"master pan",
TRANS(
"Master pan"), *
this, { -1.0f, 1.0f }));
121 addAutomatableParameter (volParam =
new VolAutomatableParameter (
"volume",
TRANS(
"Volume"), *
this, { 0.0f, 1.0f }));
122 addAutomatableParameter (panParam =
new PanAutomatableParameter (
"pan",
TRANS(
"Pan"), *
this, { -1.0f, 1.0f }));
125 volParam->attachToCurrentValue (volume);
126 panParam->attachToCurrentValue (pan);
129VolumeAndPanPlugin::VolumeAndPanPlugin (Edit& ed,
const juce::ValueTree& v,
bool isMaster)
130 : VolumeAndPanPlugin (PluginCreationInfo (ed, v, false), isMaster)
134VolumeAndPanPlugin::~VolumeAndPanPlugin()
136 notifyListenersOfDeletion();
138 volParam->detachFromCurrentValue();
139 panParam->detachFromCurrentValue();
145 v.setProperty (IDs::type, xmlTypeName,
nullptr);
149const char* VolumeAndPanPlugin::xmlTypeName =
"volume";
156 auto sliderPos = getSliderPos();
157 getGainsFromVolumeFaderPositionAndPan (sliderPos, getPan(), getPanLaw(), lastGainL, lastGainR);
158 lastGainS = volumeFaderPositionToGain (sliderPos);
163 TRACKTION_ASSERT_MESSAGE_THREAD
180 float posOffset = 0.0f;
182 for (
FolderTrack::Ptr p = track.getParentFolderTrack(); p !=
nullptr; p = p->getParentFolderTrack())
184 float db = p->getVcaDb (time);
189 posOffset += decibelsToVolumeFaderPosition (db)
190 - decibelsToVolumeFaderPosition (0.0f);
193 return volumeFaderPositionToDB (decibelsToVolumeFaderPosition (0) + posOffset);
200 SCOPED_REALTIME_CHECK
205 float vcaPosDelta = 0.0f;
209 vcaPosDelta = vcaTrack !=
nullptr
210 ? decibelsToVolumeFaderPosition (getParentVcaDb (*vcaTrack, fc.
editTime.getStart()))
211 - decibelsToVolumeFaderPosition (0.0f)
216 getGainsFromVolumeFaderPositionAndPan (getSliderPos() + vcaPosDelta, getPan(), getPanLaw(), lgain, rgain);
217 lgain *= (polarity ? -1 : 1);
218 rgain *= (polarity ? -1 : 1);
231 const float gain = volumeFaderPositionToGain (getSliderPos() + vcaPosDelta) * (polarity ? -1 : 1);
233 for (
int i = 2; i < numChansIn; ++i)
245void VolumeAndPanPlugin::refreshVCATrack()
255float VolumeAndPanPlugin::getVolumeDb()
const
257 return volumeFaderPositionToDB (volParam->getCurrentValue());
260void VolumeAndPanPlugin::setVolumeDb (
float vol)
262 setSliderPos (decibelsToVolumeFaderPosition (vol));
265void VolumeAndPanPlugin::setSliderPos (
float newV)
270void VolumeAndPanPlugin::setPan (
float p)
272 if (p >= -0.005f && p <= 0.005f)
278PanLaw VolumeAndPanPlugin::getPanLaw() const noexcept
281 return p == PanLawDefault ? getDefaultPanLaw() : p;
285void VolumeAndPanPlugin::setAppliedToMidiVolumes (
bool b)
287 if (b != applyToMidi)
294void VolumeAndPanPlugin::muteOrUnmute()
296 if (getVolumeDb() > -90.0f)
298 lastVolumeBeforeMute = getVolumeDb();
299 setVolumeDb (lastVolumeBeforeMute - 0.01f);
300 setVolumeDb (-100.0f);
304 if (lastVolumeBeforeMute < -100.0f)
305 lastVolumeBeforeMute = 0.0f;
307 setVolumeDb (getVolumeDb() + 0.01f);
308 setVolumeDb (lastVolumeBeforeMute);
312void VolumeAndPanPlugin::restorePluginStateFromValueTree (
const juce::ValueTree& v)
314 copyPropertiesToCachedValues (v, volume, pan, panLaw, applyToMidi, ignoreVca, polarity);
316 for (
auto p : getAutomatableParameters())
317 p->updateFromAttachedValue();
int getNumChannels() const noexcept
void applyGainRamp(int channel, int startSample, int numSamples, Type startGain, Type endGain) noexcept
Type get() const noexcept
static String toString(Type decibels, int decimalPlaces=2, Type minusInfinityDb=Type(defaultMinusInfinitydB), bool shouldIncludeSuffix=true, StringRef customMinusInfinityString={})
float getFloatValue() const noexcept
String retainCharacters(StringRef charactersToRetain) const
bool contains(StringRef text) const noexcept
void changed() override
method from Selectable, that's been overridden here to also tell the edit that it's changed.
Track * getOwnerTrack() const
Returns the track if it's a track or clip plugin.
Base class for tracks which contain clips and plugins and can be added to Edit[s].
void deinitialise() override
Called after play stops to release resources.
void initialiseWithoutStopping(const PluginInitialisationInfo &) override
Tells the plugin that the audio graph has changed but the plugin isn't being re-initialised - i....
void applyToBuffer(const PluginRenderContext &) override
Process the next block of data.
#define TRANS(stringLiteral)
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
PanLaw
All laws have been designed to be equal-power, excluding linear respectively.
Passed into Plugins when they are being initialised, to give them useful contextual information that ...
Represents a position in real-life time.
The context passed to plugin render methods to provide it with buffers to fill.
int bufferNumSamples
The number of samples to write into the audio buffer.
MidiMessageArray * bufferForMidiMessages
A buffer of MIDI events to process.
juce::AudioBuffer< float > * destBuffer
The target audio buffer which needs to be filled.
int bufferStartSample
The index of the start point in the audio buffer from which data must be written.
TimeRange editTime
The edit time range this context represents.