-
Notifications
You must be signed in to change notification settings - Fork 65
/
PluginProcessor.cpp
761 lines (589 loc) · 23.1 KB
/
PluginProcessor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
#pragma once
#include "PluginProcessor.h"
#include <filesystem>
#include "StandalonePluginWindow.h"
static std::mutex PLUGIN_INSTANCE_MUTEX;
using juce::ExtensionsVisitor;
#define THROW_ERROR_IF_NO_PLUGIN if (!myPlugin) {throw std::runtime_error("Please load the plugin first!");}
struct PresetVisitor : public ExtensionsVisitor {
const std::string presetFilePath;
PresetVisitor(const std::string presetFilePath) : presetFilePath(presetFilePath) { }
void visitVST3Client(const ExtensionsVisitor::VST3Client& client) override {
juce::File presetFile(presetFilePath);
juce::MemoryBlock presetData;
if (!presetFile.loadFileAsData(presetData)) {
throw std::runtime_error("Failed to read preset file: " + presetFilePath);
}
if (!client.setPreset(presetData)) {
throw std::runtime_error("Failed to set preset file: " + presetFilePath);
}
}
};
PluginProcessor::PluginProcessor(std::string newUniqueName, double sampleRate, int samplesPerBlock, std::string path) : ProcessorBase{ newUniqueName }
{
myPluginPath = path;
loadPlugin(sampleRate, samplesPerBlock);
}
void
PluginProcessor::openEditor() {
THROW_ERROR_IF_NO_PLUGIN
if (!juce::Desktop::getInstance().getDisplays().getPrimaryDisplay()) {
throw std::runtime_error(
"Editor cannot be shown because no visual display devices are available.");
}
if (!juce::MessageManager::getInstance()->isThisTheMessageThread()) {
throw std::runtime_error(
"Plugin UI windows can only be shown from the main thread.");
}
StandalonePluginWindow::openWindowAndWait(*this, *myPlugin);
}
bool
PluginProcessor::loadPlugin(double sampleRate, int samplesPerBlock) {
OwnedArray<PluginDescription> pluginDescriptions;
KnownPluginList pluginList;
AudioPluginFormatManager pluginFormatManager;
pluginFormatManager.addDefaultFormats();
juce::MessageManager::getInstance(); // to avoid runtime jassert(false) thrown by JUCE
for (int i = pluginFormatManager.getNumFormats(); --i >= 0;)
{
pluginList.scanAndAddFile(String(myPluginPath),
true,
pluginDescriptions,
*pluginFormatManager.getFormat(i));
}
if (myPlugin.get())
{
std::lock_guard<std::mutex> lock(PLUGIN_INSTANCE_MUTEX);
myPlugin.reset();
}
// If there is a problem here first check the preprocessor definitions
// in the projucer are sensible - is it set up to scan for plugin's?
if (pluginDescriptions.size() <= 0) {
throw std::runtime_error("Unable to load plugin.");
}
String errorMessage;
std::lock_guard<std::mutex> lock(PLUGIN_INSTANCE_MUTEX);
myPlugin = pluginFormatManager.createPluginInstance(*pluginDescriptions[0],
sampleRate,
samplesPerBlock,
errorMessage);
if (myPlugin.get() == nullptr)
{
throw std::runtime_error("PluginProcessor::loadPlugin error: " + errorMessage.toStdString());
}
myPlugin->enableAllBuses();
auto inputs = myPlugin->getTotalNumInputChannels();
auto outputs = myPlugin->getTotalNumOutputChannels();
this->setPlayConfigDetails(inputs, outputs, sampleRate, samplesPerBlock);
myPlugin->setPlayConfigDetails(inputs, outputs, sampleRate, samplesPerBlock);
myPlugin->prepareToPlay(sampleRate, samplesPerBlock);
myPlugin->setNonRealtime(true);
mySampleRate = sampleRate;
createParameterLayout();
{
// Process a block of silence a few times to "warm up" the processor.
juce::AudioSampleBuffer audioBuffer = AudioSampleBuffer(std::max(inputs, outputs), samplesPerBlock);
MidiBuffer emptyMidiBuffer;
for (int i = 0; i < 5; i++) {
audioBuffer.clear();
myPlugin->processBlock(audioBuffer, emptyMidiBuffer);
}
}
return true;
}
PluginProcessor::~PluginProcessor() {
if (myPlugin.get())
{
std::lock_guard<std::mutex> lock(PLUGIN_INSTANCE_MUTEX);
myPlugin.reset();
}
delete myMidiIteratorQN;
delete myMidiIteratorSec;
}
void PluginProcessor::setPlayHead(AudioPlayHead* newPlayHead)
{
ProcessorBase::setPlayHead(newPlayHead);
if (myPlugin.get()) {
myPlugin->setPlayHead(newPlayHead);
}
}
bool
PluginProcessor::canApplyBusesLayout(const juce::AudioProcessor::BusesLayout& layout) {
THROW_ERROR_IF_NO_PLUGIN
return myPlugin->checkBusesLayoutSupported(layout);
}
bool
PluginProcessor::setBusesLayout(const BusesLayout& arr) {
THROW_ERROR_IF_NO_PLUGIN
ProcessorBase::setBusesLayout(arr);
return myPlugin->setBusesLayout(arr);
}
void
PluginProcessor::numChannelsChanged() {
THROW_ERROR_IF_NO_PLUGIN
ProcessorBase::numChannelsChanged();
myPlugin->setPlayConfigDetails(this->getTotalNumInputChannels(), this->getTotalNumOutputChannels(), this->getSampleRate(), this->getBlockSize());
}
void
PluginProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
{
THROW_ERROR_IF_NO_PLUGIN
myPlugin->prepareToPlay(sampleRate, samplesPerBlock);
}
void
PluginProcessor::processBlock(juce::AudioSampleBuffer& buffer, juce::MidiBuffer& midiBuffer)
{
// todo: PluginProcessor should be able to use the incoming midiBuffer too.
THROW_ERROR_IF_NO_PLUGIN
auto posInfo = getPlayHead()->getPosition();
myRenderMidiBuffer.clear();
{
auto start = *posInfo->getTimeInSamples();
auto end = start + buffer.getNumSamples();
myIsMessageBetweenSec = myMidiMessagePositionSec >= start && myMidiMessagePositionSec < end;
while (myIsMessageBetweenSec && myMidiEventsDoRemainSec) {
// steps for saving midi to file output
auto messageCopy = MidiMessage(myMidiMessageSec);
messageCopy.setTimeStamp(myMidiMessagePositionSec*(2400./mySampleRate));
if (!(messageCopy.isEndOfTrackMetaEvent() || messageCopy.isTempoMetaEvent())) {
myRecordedMidiSequence.addEvent(messageCopy);
}
// steps for playing MIDI
myRenderMidiBuffer.addEvent(myMidiMessageSec, int(myMidiMessagePositionSec - start));
myMidiEventsDoRemainSec = myMidiIteratorSec->getNextEvent(myMidiMessageSec, myMidiMessagePositionSec);
myIsMessageBetweenSec = myMidiMessagePositionSec >= start && myMidiMessagePositionSec < end;
}
}
{
auto pulseStart = std::floor(*posInfo->getPpqPosition() * PPQN);
auto pulseEnd = pulseStart + buffer.getNumSamples() * (*posInfo->getBpm() * PPQN) / (mySampleRate * 60.);
myIsMessageBetweenQN = myMidiMessagePositionQN >= pulseStart && myMidiMessagePositionQN < pulseEnd;
while (myIsMessageBetweenQN && myMidiEventsDoRemainQN) {
// steps for saving midi to file output
auto messageCopy = MidiMessage(myMidiMessageQN);
messageCopy.setTimeStamp((*posInfo->getTimeInSeconds() + (myMidiMessagePositionQN-pulseStart)*(60./(*posInfo->getBpm()))/PPQN )*2400.);
if (!(messageCopy.isEndOfTrackMetaEvent() || messageCopy.isTempoMetaEvent())) {
myRecordedMidiSequence.addEvent(messageCopy);
}
// steps for playing MIDI
myRenderMidiBuffer.addEvent(myMidiMessageQN, int( (myMidiMessagePositionQN - pulseStart)*60.*mySampleRate/(PPQN**posInfo->getBpm())));
myMidiEventsDoRemainQN = myMidiIteratorQN->getNextEvent(myMidiMessageQN, myMidiMessagePositionQN);
myIsMessageBetweenQN = myMidiMessagePositionQN >= pulseStart && myMidiMessagePositionQN < pulseEnd;
}
}
myPlugin->processBlock(buffer, myRenderMidiBuffer);
ProcessorBase::processBlock(buffer, midiBuffer);
}
void
PluginProcessor::automateParameters(AudioPlayHead::PositionInfo& posInfo, int numSamples) {
THROW_ERROR_IF_NO_PLUGIN
int i = 0;
for (juce::AudioProcessorParameter *parameter : myPlugin->getParameters()) {
auto name = parameter->getName(DAW_PARARAMETER_MAX_NAME_LENGTH);
if (name.compare("") == 0 || !parameter->isAutomatable()) {
i++;
continue;
}
auto paramID = std::to_string(i);
auto theParameter = ((AutomateParameterFloat*)myParameters.getParameter(paramID));
if (theParameter->isAutomated()) {
parameter->beginChangeGesture();
parameter->setValueNotifyingHost(theParameter->sample(posInfo));
parameter->endChangeGesture();
}
i++;
}
}
void
PluginProcessor::reset()
{
if (myPlugin.get()) {
myPlugin->reset();
juce::AudioPlayHead::PositionInfo posInfo;
// It's important to initialize these.
posInfo.setTimeInSamples(0);
posInfo.setTimeInSeconds(0);
posInfo.setPpqPosition(0);
// Set all parameters, even ones which aren't automatable.
// Loop twice because some parameters are meta parameters.
for (int j=0; j<2; j++) {
int i = 0;
for (juce::AudioProcessorParameter *parameter : myPlugin->getParameters()) {
auto paramID = std::to_string(i);
auto theParameter = ((AutomateParameterFloat*)myParameters.getParameter(paramID));
parameter->beginChangeGesture();
parameter->setValueNotifyingHost(theParameter->sample(posInfo));
parameter->endChangeGesture();
i++;
}
}
}
delete myMidiIteratorSec;
myMidiIteratorSec = new MidiBuffer::Iterator(myMidiBufferSec); // todo: deprecated.
myMidiEventsDoRemainSec = myMidiIteratorSec->getNextEvent(myMidiMessageSec, myMidiMessagePositionSec);
delete myMidiIteratorQN;
myMidiIteratorQN = new MidiBuffer::Iterator(myMidiBufferQN); // todo: deprecated.
myMidiEventsDoRemainQN = myMidiIteratorQN->getNextEvent(myMidiMessageQN, myMidiMessagePositionQN);
myRenderMidiBuffer.clear();
myRecordedMidiSequence.clear();
myRecordedMidiSequence.addEvent(juce::MidiMessage::midiStart());
myRecordedMidiSequence.addEvent(juce::MidiMessage::timeSignatureMetaEvent(4, 4));
myRecordedMidiSequence.addEvent(juce::MidiMessage::tempoMetaEvent(500*1000));
myRecordedMidiSequence.addEvent(juce::MidiMessage::midiChannelMetaEvent(1));
ProcessorBase::reset();
}
bool
PluginProcessor::loadPreset(const std::string& path)
{
THROW_ERROR_IF_NO_PLUGIN
try {
if (!std::filesystem::exists(path.c_str())) {
throw std::runtime_error("File not found: " + path);
}
MemoryBlock mb;
File file = File(path);
file.loadFileAsData(mb);
// The VST2 way of loading preset.
bool result = VSTPluginFormat::loadFromFXBFile(myPlugin.get(), mb.getData(), mb.getSize());
int i = 0;
for (auto *parameter : myPlugin->getParameters()) {
setParameter(i, parameter->getValue());
i++;
}
return result;
}
catch (std::exception& e) {
throw std::runtime_error(std::string("Error: (PluginProcessor::loadPreset) ") + e.what());
}
}
bool
PluginProcessor::loadVST3Preset(const std::string& path)
{
THROW_ERROR_IF_NO_PLUGIN
juce::File fPath(path);
if (!fPath.getFileExtension().equalsIgnoreCase(".VSTPRESET")) {
throw std::runtime_error("The file extension is not .vstpreset for file: " + path);
}
if (!std::filesystem::exists(path.c_str())) {
throw std::runtime_error("Preset file not found: " + path);
}
PresetVisitor presetVisitor{ path };
try
{
myPlugin->getExtensions(presetVisitor);
}
catch (const std::exception&)
{
throw std::runtime_error("PluginProcessor::loadVST3Preset: unknown error.");
}
int i = 0;
for (auto *parameter : myPlugin->getParameters()) {
setParameter(i, parameter->getValue());
i++;
}
return true;
}
void
PluginProcessor::loadStateInformation(std::string filepath) {
if (!std::filesystem::exists(filepath.c_str())) {
throw std::runtime_error("File not found: " + filepath);
}
MemoryBlock state;
File file = File(filepath);
file.loadFileAsData(state);
myPlugin->setStateInformation((const char*)state.getData(), (int)state.getSize());
int i = 0;
for (auto *parameter : myPlugin->getParameters()) {
std::string paramID = std::to_string(i);
ProcessorBase::setAutomationVal(paramID, parameter->getValue());
i++;
}
// todo: this is a little hacky. We create a window because this forces the loaded state to take effect
// in certain plugins.
// This allows us to call load_state and not bother calling open_editor().
StandalonePluginWindow tmp_window(*this, *myPlugin);
}
void
PluginProcessor::saveStateInformation(std::string filepath) {
THROW_ERROR_IF_NO_PLUGIN
MemoryBlock state;
myPlugin->getStateInformation(state);
juce::File file(filepath);
juce::FileOutputStream stream(file);
if (stream.openedOk())
{
// overwrite existing file.
stream.setPosition(0);
stream.truncate();
}
stream.write(state.getData(), state.getSize());
}
void
PluginProcessor::createParameterLayout()
{
juce::AudioProcessorValueTreeState::ParameterLayout blankLayout;
// clear existing parameters in the layout?
ValueTree blankState;
myParameters.replaceState(blankState);
int i = 0;
for (auto *parameter : myPlugin->getParameters()) {
auto parameterName = parameter->getName(DAW_PARARAMETER_MAX_NAME_LENGTH);
std::string paramID = std::to_string(i);
myParameters.createAndAddParameter(std::make_unique<AutomateParameterFloat>(paramID, parameterName, NormalisableRange<float>(0.f, 1.f), 0.f));
// give it a valid single sample of automation.
ProcessorBase::setAutomationVal(paramID, parameter->getValue());
i++;
}
}
void
PluginProcessor::setPatch(const PluginPatch patch)
{
for (auto pair : patch) {
if (pair.first < myPlugin->getNumParameters()) {
setParameter(pair.first, pair.second);
}
else {
throw std::runtime_error(
"RenderEngine::setPatch error: Incorrect parameter index!"
"\n- Current index: " + std::to_string(pair.first) +
"\n- Max index: " + std::to_string(myPlugin->getNumParameters() - 1)
);
}
}
}
std::uint32_t
PluginProcessor::getLatencySamples()
{
THROW_ERROR_IF_NO_PLUGIN
return (uint32_t) myPlugin->getLatencySamples();
}
//==============================================================================
std::string
PluginProcessor::getParameterAsText(const int parameter)
{
THROW_ERROR_IF_NO_PLUGIN
return myPlugin->getParameterText(parameter).toStdString();
}
//==============================================================================
void
PluginProcessor::setParameter(const int parameterIndex, const float value)
{
THROW_ERROR_IF_NO_PLUGIN
myPlugin->setParameter(parameterIndex, value); // todo: instead we need to do parameter->setValue(value)
std::string paramID = std::to_string(parameterIndex);
ProcessorBase::setAutomationVal(paramID, value);
}
//==============================================================================
const PluginPatch
PluginProcessor::getPatch() {
PluginPatch params;
THROW_ERROR_IF_NO_PLUGIN
params.clear();
params.reserve(myPlugin->getNumParameters());
AudioPlayHead::PositionInfo posInfo;
posInfo.setTimeInSeconds(0.);
posInfo.setTimeInSamples(0.);
for (int i = 0; i < myPlugin->getNumParameters(); i++) {
auto theName = myPlugin->getParameterName(i);
if (theName == "Param") {
continue;
}
auto parameter = ((AutomateParameterFloat*)myParameters.getParameter(theName));
if (parameter) {
float val = parameter->sample(posInfo);
if (parameter) {
params.push_back(std::make_pair(i, val));
}
else {
throw std::runtime_error("Error getPatch : " + theName.toStdString());
}
}
else {
throw std::runtime_error("Error getPatch with parameter: " + theName.toStdString());
}
}
params.shrink_to_fit();
return params;
}
const size_t
PluginProcessor::getPluginParameterSize()
{
THROW_ERROR_IF_NO_PLUGIN
return myPlugin->getNumParameters();
}
int
PluginProcessor::getNumMidiEvents() {
return myMidiBufferSec.getNumEvents() + myMidiBufferQN.getNumEvents();
};
bool
PluginProcessor::loadMidi(const std::string& path, bool clearPrevious, bool isBeats, bool allEvents)
{
if (!std::filesystem::exists(path.c_str())) {
throw std::runtime_error("File not found: " + path);
}
File file = File(path);
FileInputStream fileStream(file);
MidiFile midiFile;
midiFile.readFrom(fileStream);
if (clearPrevious) {
myMidiBufferSec.clear();
myMidiBufferQN.clear();
}
if (!isBeats) {
midiFile.convertTimestampTicksToSeconds();
for (int t = 0; t < midiFile.getNumTracks(); t++) {
const MidiMessageSequence* track = midiFile.getTrack(t);
for (int i = 0; i < track->getNumEvents(); i++) {
MidiMessage& m = track->getEventPointer(i)->message;
int sampleOffset = (int)(mySampleRate * m.getTimeStamp());
if (allEvents || m.isNoteOff() || m.isNoteOn()) {
myMidiBufferSec.addEvent(m, sampleOffset);
}
}
}
}
else {
auto timeFormat = midiFile.getTimeFormat(); // the ppqn (Ableton makes midi files with 96 ppqn)
for (int t = 0; t < midiFile.getNumTracks(); t++) {
const MidiMessageSequence* track = midiFile.getTrack(t);
for (int i = 0; i < track->getNumEvents(); i++) {
MidiMessage& m = track->getEventPointer(i)->message;
if (allEvents || m.isNoteOff() || m.isNoteOn()) {
// convert timestamp from its original time format to our high resolution PPQN
auto timeStamp = m.getTimeStamp() * PPQN / timeFormat;
myMidiBufferQN.addEvent(m, timeStamp);
}
}
}
}
return true;
}
void
PluginProcessor::clearMidi() {
myMidiBufferSec.clear();
myMidiBufferQN.clear();
}
bool
PluginProcessor::addMidiNote(uint8 midiNote,
uint8 midiVelocity,
const double noteStart,
const double noteLength,
bool isBeats) {
if (midiNote > 255) midiNote = 255;
if (midiNote < 0) midiNote = 0;
if (midiVelocity > 255) midiVelocity = 255;
if (midiVelocity < 0) midiVelocity = 0;
if (noteLength <= 0) {
throw std::runtime_error("The note length must be greater than zero.");
}
// Get the note on midiBuffer.
MidiMessage onMessage = MidiMessage::noteOn(1,
midiNote,
midiVelocity);
MidiMessage offMessage = MidiMessage::noteOff(1,
midiNote,
midiVelocity);
if (!isBeats) {
auto startTime = noteStart * mySampleRate;
onMessage.setTimeStamp(startTime);
offMessage.setTimeStamp(startTime + noteLength * mySampleRate);
myMidiBufferSec.addEvent(onMessage, (int)onMessage.getTimeStamp());
myMidiBufferSec.addEvent(offMessage, (int)offMessage.getTimeStamp());
}
else {
auto startTime = noteStart * PPQN;
onMessage.setTimeStamp(startTime);
offMessage.setTimeStamp(startTime + noteLength * PPQN);
myMidiBufferQN.addEvent(onMessage, (int)onMessage.getTimeStamp());
myMidiBufferQN.addEvent(offMessage, (int)offMessage.getTimeStamp());
}
return true;
}
void PluginProcessor::saveMIDI(std::string& savePath) {
MidiFile file;
// 30*80 = 2400, so that's why the MIDI messages had their
// timestamp set to seconds*2400
file.setSmpteTimeFormat(30, 80);
File myFile(savePath);
file.addTrack( myRecordedMidiSequence );
juce::FileOutputStream stream( myFile );
if (stream.openedOk())
{
// overwrite existing file.
stream.setPosition(0);
stream.truncate();
}
file.writeTo( stream );
}
//==============================================================================
PluginProcessorWrapper::PluginProcessorWrapper(std::string newUniqueName, double sampleRate, int samplesPerBlock, std::string path) :
PluginProcessor(newUniqueName, sampleRate, samplesPerBlock, path)
{
}
void
PluginProcessorWrapper::wrapperSetPatch(py::list listOfTuples)
{
PluginPatch patch = customBoost::listOfTuplesToPluginPatch(listOfTuples);
PluginProcessor::setPatch(patch);
}
py::list
PluginProcessorWrapper::wrapperGetPatch()
{
return customBoost::pluginPatchToListOfTuples(PluginProcessor::getPatch());
}
float
PluginProcessorWrapper::wrapperGetParameter(int parameterIndex)
{
THROW_ERROR_IF_NO_PLUGIN
if (parameterIndex >= myPlugin->getNumParameters()) {
throw std::runtime_error("Parameter not found for index: " + std::to_string(parameterIndex));
return 0.;
}
return ProcessorBase::getAutomationAtZero(std::to_string(parameterIndex));
}
std::string
PluginProcessorWrapper::wrapperGetParameterName(int parameter)
{
return myPlugin->getParameterName(parameter).toStdString();
}
bool
PluginProcessorWrapper::wrapperSetParameter(int parameterIndex, float value)
{
THROW_ERROR_IF_NO_PLUGIN
myPlugin->setParameter(parameterIndex, value); // todo: instead we need to do parameter->setValue(value)
std::string paramID = std::to_string(parameterIndex);
return ProcessorBase::setAutomationVal(paramID, value);
}
bool
PluginProcessorWrapper::wrapperSetAutomation(int parameterIndex, py::array input, std::uint32_t ppqn) {
return PluginProcessorWrapper::setAutomation(std::to_string(parameterIndex), input, ppqn);
}
int
PluginProcessorWrapper::wrapperGetPluginParameterSize()
{
return int(PluginProcessor::getPluginParameterSize());
}
py::list
PluginProcessorWrapper::getPluginParametersDescription()
{
THROW_ERROR_IF_NO_PLUGIN
py::list myList;
//get the parameters as an AudioProcessorParameter array
const Array<AudioProcessorParameter*>& processorParams = myPlugin->getParameters();
for (int i = 0; i < myPlugin->getNumParameters(); i++) {
std::string theName = (processorParams[i])->getName(DAW_PARARAMETER_MAX_NAME_LENGTH).toStdString();
std::string currentText = processorParams[i]->getText(processorParams[i]->getValue(), DAW_PARARAMETER_MAX_NAME_LENGTH).toStdString();
std::string label = processorParams[i]->getLabel().toStdString();
py::dict myDictionary;
myDictionary["index"] = i;
myDictionary["name"] = theName;
myDictionary["numSteps"] = processorParams[i]->getNumSteps();
myDictionary["isDiscrete"] = processorParams[i]->isDiscrete();
myDictionary["label"] = label;
myDictionary["text"] = currentText;
myDictionary["isMetaParameter"] = processorParams[i]->isMetaParameter();
myDictionary["isAutomatable"] = processorParams[i]->isAutomatable();
myList.append(myDictionary);
}
return myList;
}