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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_LevelMeter.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
14LevelMeterPlugin::LevelMeterPlugin (PluginCreationInfo info) : Plugin (info)
15{
16 showMidiActivity.referTo (state, IDs::showMidi, getUndoManager());
17
18 measurer.setShowMidi (showMidiActivity);
19}
20
21LevelMeterPlugin::~LevelMeterPlugin()
22{
23 notifyListenersOfDeletion();
24}
25
26juce::ValueTree LevelMeterPlugin::create()
27{
28 juce::ValueTree v (IDs::PLUGIN);
29 v.setProperty (IDs::type, xmlTypeName, nullptr);
30 return v;
31}
32
33const char* LevelMeterPlugin::xmlTypeName = "level";
34
35void LevelMeterPlugin::initialise (const PluginInitialisationInfo& info)
36{
37 measurer.clear();
38 initialiseWithoutStopping (info);
39}
40
41void LevelMeterPlugin::initialiseWithoutStopping (const PluginInitialisationInfo&)
42{
43 TRACKTION_ASSERT_MESSAGE_THREAD
44
45 if (auto t = getOwnerTrack())
46 {
47 controllerTrack = t->getIndexInEditTrackList();
48 startTimer (1000 / 50);
49 return;
50 }
51
52 controllerTrack = -1;
53 stopTimer();
54}
55
56void LevelMeterPlugin::deinitialise()
57{
58 measurer.clear();
59 stopTimer();
60}
61
62void LevelMeterPlugin::applyToBuffer (const PluginRenderContext& fc)
63{
64 SCOPED_REALTIME_CHECK
65
66 if (fc.destBuffer != nullptr)
67 measurer.processBuffer (*fc.destBuffer, fc.bufferStartSample, fc.bufferNumSamples);
68
69 if (fc.bufferForMidiMessages != nullptr)
70 {
71 measurer.setShowMidi (showMidiActivity);
72 measurer.processMidi (*fc.bufferForMidiMessages, nullptr);
73 }
74}
75
76void LevelMeterPlugin::timerCallback()
77{
78 if (controllerTrack >= 0)
79 {
80 auto& ecm = engine.getExternalControllerManager();
81
82 if (ecm.isAttachedToEdit (edit))
83 {
84 auto l = measurer.getLevelCache();
85 ecm.channelLevelChanged (controllerTrack, dbToGain (l.first), dbToGain (l.second));
86 }
87 }
88}
89
90void LevelMeterPlugin::restorePluginStateFromValueTree (const juce::ValueTree& v)
91{
92 copyPropertiesToCachedValues (v, showMidiActivity);
93
94 for (auto p : getAutomatableParameters())
95 p->updateFromAttachedValue();
96}
97
98}} // namespace tracktion { inline namespace engine
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.
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.