11namespace tracktion {
inline namespace engine
14static void getPossibleInputDeviceNames (
Engine& e,
19 auto& dm = e.getDeviceManager();
21 for (
int i = 0; i < dm.getNumInputDevices(); ++i)
23 if (
auto in = dm.getInputDevice (i))
25 if (! in->isEnabled())
28 if (
dynamic_cast<MidiInputDevice*
> (in) !=
nullptr)
33 s.
add (in->getName());
34 a.
add (in->getAlias());
39static void getPossibleOutputDeviceNames (
Engine& e,
44 auto& dm = e.getDeviceManager();
46 for (
int i = 0; i < dm.getNumOutputDevices(); ++i)
48 if (
auto out = dm.getOutputDeviceAt (i))
50 if (! out->isEnabled())
53 if (
auto m =
dynamic_cast<MidiOutputDevice*
> (out))
55 if (m->isConnectedToExternalController())
65 s.
add (out->getName());
66 a.
add (out->getAlias());
73InsertPlugin::InsertPlugin (PluginCreationInfo info) : Plugin (info)
75 auto um = getUndoManager();
76 name.referTo (state, IDs::name, um);
77 inputDevice.referTo (state, IDs::inputDevice, um);
78 outputDevice.referTo (state, IDs::outputDevice, um);
79 manualAdjustMs.referTo (state, IDs::manualAdjustMs, um);
84InsertPlugin::~InsertPlugin()
86 notifyListenersOfDeletion();
90const char* InsertPlugin::xmlTypeName (
"insert");
92juce::String InsertPlugin::getName()
const {
return name.get().isNotEmpty() ? name :
TRANS(
"Insert Plugin"); }
93juce::String InsertPlugin::getPluginType() {
return xmlTypeName; }
95double InsertPlugin::getLatencySeconds() {
return latencySeconds; }
97bool InsertPlugin::takesAudioInput() {
return true; }
98bool InsertPlugin::takesMidiInput() {
return true; }
99bool InsertPlugin::canBeAddedToClip() {
return false; }
100bool InsertPlugin::needsConstantBufferSize() {
return true; }
104 initialiseWithoutStopping (info);
109 TRACKTION_ASSERT_MESSAGE_THREAD
112 int latency =
static_cast<int> (timeToSample (manualAdjustMs / 1000.0, info.sampleRate));
114 if (
auto device = engine.getDeviceManager().deviceManager.getCurrentAudioDevice())
116 if (sendDeviceType == audioDevice)
117 latency += device->getOutputLatencyInSamples();
119 if (returnDeviceType == audioDevice)
120 latency += device->getInputLatencyInSamples();
124 latencyNumSamples = latency;
125 latencySeconds = TimeDuration::fromSamples (latency, info.sampleRate).inSeconds();
128void InsertPlugin::deinitialise()
140 return TRANS(
"Insert Plugin");
143void InsertPlugin::restorePluginStateFromValueTree (
const juce::ValueTree& v)
145 if (v.hasProperty (IDs::name))
146 name = v.getProperty (IDs::name).
toString();
148 if (v.hasProperty (IDs::outputDevice))
149 outputDevice = v.getProperty (IDs::outputDevice).
toString();
151 if (v.hasProperty (IDs::inputDevice))
152 inputDevice = v.getProperty (IDs::inputDevice).
toString();
154 for (
auto p : getAutomatableParameters())
155 p->updateFromAttachedValue();
158void InsertPlugin::updateDeviceTypes()
161 TRACKTION_ASSERT_MESSAGE_THREAD
168 if (audio[index]) deviceType = audioDevice;
169 else if (midi[index]) deviceType = midiDevice;
170 else deviceType = noDevice;
173 getPossibleInputDeviceNames (engine, devices, aliases, hasAudio, hasMidi);
174 setDeviceType (returnDeviceType, hasAudio, hasMidi, devices.indexOf (inputDevice.get()));
176 getPossibleOutputDeviceNames (engine, devices, aliases, hasAudio, hasMidi);
177 setDeviceType (sendDeviceType, hasAudio, hasMidi, devices.indexOf (outputDevice.get()));
183void InsertPlugin::getPossibleDeviceNames (
Engine& e,
190 getPossibleInputDeviceNames (e, s, a, hasAudio, hasMidi);
192 getPossibleOutputDeviceNames (e, s, a, hasAudio, hasMidi);
195bool InsertPlugin::hasAudio()
const {
return sendDeviceType == audioDevice || returnDeviceType == audioDevice; }
196bool InsertPlugin::hasMidi()
const {
return sendDeviceType == midiDevice || returnDeviceType == midiDevice; }
198int InsertPlugin::getLatencyNumSamples()
const
209 if (i != deviceName.getPropertyID())
212 deviceName.forceUpdateOfCachedValue();
216 if (update (outputDevice) || update (inputDevice))
220 Plugin::valueTreePropertyChanged (v, i);
BigInteger & setBit(int bitNumber)
const String & toString() const noexcept
int size() const noexcept
void add(String stringToAdd)
#define TRANS(stringLiteral)
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.
#define CRASH_TRACER
This macro adds the current location to a stack which gets logged if a crash happens.