forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVSTEffect.cpp
More file actions
4022 lines (3340 loc) · 97.3 KB
/
Copy pathVSTEffect.cpp
File metadata and controls
4022 lines (3340 loc) · 97.3 KB
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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************************
Audacity: A Digital Audio Editor
VSTEffect.cpp
Dominic Mazzoni
This class implements a VST Plug-in effect. The plug-in must be
loaded in a platform-specific way and passed into the constructor,
but from here this class handles the interfacing.
********************************************************************//**
\class AEffect
\brief VST Effects class, conforming to VST layout.
*//********************************************************************/
//#define VST_DEBUG
//#define DEBUG_VST
// *******************************************************************
// WARNING: This is NOT 64-bit safe
// *******************************************************************
#include "../../Audacity.h" // for USE_* macros
#include "VSTEffect.h"
#include "../../widgets/ProgressDialog.h"
#if 0
#if defined(BUILDING_AUDACITY)
#include "../../PlatformCompatibility.h"
// Make the main function private
#else
#define USE_VST 1
#endif
#endif
#if USE_VST
#include <limits.h>
#include <stdio.h>
#include <wx/setup.h> // for wxUSE_* macros
#include <wx/dynlib.h>
#include <wx/app.h>
#include <wx/defs.h>
#include <wx/buffer.h>
#include <wx/busyinfo.h>
#include <wx/button.h>
#include <wx/combobox.h>
#include <wx/file.h>
#include <wx/filename.h>
#include <wx/imaglist.h>
#include <wx/listctrl.h>
#include <wx/log.h>
#include <wx/module.h>
#include <wx/process.h>
#include <wx/recguard.h>
#include <wx/sizer.h>
#include <wx/slider.h>
#include <wx/scrolwin.h>
#include <wx/sstream.h>
#include <wx/statbox.h>
#include <wx/stattext.h>
#include <wx/timer.h>
#include <wx/tokenzr.h>
#include <wx/utils.h>
#if defined(__WXMSW__)
#include <shlwapi.h>
#pragma comment(lib, "shlwapi")
#else
#include <dlfcn.h>
#endif
// TODO: Unfortunately we have some dependencies on Audacity provided
// dialogs, widgets and other stuff. This will need to be cleaned up.
#include "../../FileNames.h"
#include "../../PlatformCompatibility.h"
#include "../../ShuttleGui.h"
#include "../../effects/Effect.h"
#include "../../widgets/valnum.h"
#include "../../widgets/AudacityMessageBox.h"
#include "../../widgets/NumericTextCtrl.h"
#include "../../xml/XMLFileReader.h"
#if wxUSE_ACCESSIBILITY
#include "../../widgets/WindowAccessible.h"
#endif
#include "audacity/ConfigInterface.h"
#include <cstring>
// Put this inclusion last. On Linux it makes some unfortunate pollution of
// preprocessor macro name space that interferes with other headers.
#if defined(__WXOSX__)
#include "VSTControlOSX.h"
#elif defined(__WXMSW__)
#include "VSTControlMSW.h"
#elif defined(__WXGTK__)
#include "VSTControlGTK.h"
#endif
static float reinterpretAsFloat(uint32_t x)
{
static_assert(sizeof(float) == sizeof(uint32_t), "Cannot reinterpret uint32_t to float since sizes are different.");
float f;
std::memcpy(&f, &x, sizeof(float));
return f;
}
static uint32_t reinterpretAsUint32(float f)
{
static_assert(sizeof(float) == sizeof(uint32_t), "Cannot reinterpret float to uint32_t since sizes are different.");
uint32_t x;
std::memcpy(&x, &f, sizeof(uint32_t));
return x;
}
// NOTE: To debug the subprocess, use wxLogDebug and, on Windows, Debugview
// from TechNet (Sysinternals).
// ============================================================================
//
// Module registration entry point
//
// This is the symbol that Audacity looks for when the module is built as a
// dynamic library.
//
// When the module is builtin to Audacity, we use the same function, but it is
// declared static so as not to clash with other builtin modules.
//
// ============================================================================
DECLARE_MODULE_ENTRY(AudacityModule)
{
// Create our effects module and register
// Trust the module manager not to leak this
return safenew VSTEffectsModule(path);
}
// ============================================================================
//
// Register this as a builtin module
//
// We also take advantage of the fact that wxModules are initialized before
// the wxApp::OnInit() method is called. We check to see if Audacity was
// executed to scan a VST effect in a different process.
//
// ============================================================================
DECLARE_BUILTIN_MODULE(VSTBuiltin);
///////////////////////////////////////////////////////////////////////////////
///
/// Auto created at program start up, this initialises VST.
///
///////////////////////////////////////////////////////////////////////////////
class VSTSubEntry final : public wxModule
{
public:
bool OnInit()
{
// Have we been started to check a plugin?
if (wxTheApp && wxTheApp->argc == 3 && wxStrcmp(wxTheApp->argv[1], VSTCMDKEY) == 0)
{
// NOTE: This can really hide failures, which is what we want for those pesky
// VSTs that are bad or that our support isn't correct. But, it can also
// hide Audacity failures in the subprocess, so if you're having an unruley
// VST or odd Audacity failures, comment it out and you might get more info.
//wxHandleFatalExceptions();
VSTEffectsModule::Check(wxTheApp->argv[2]);
// Returning false causes default processing to display a message box, but we don't
// want that so disable logging.
wxLog::EnableLogging(false);
return false;
}
return true;
};
void OnExit() {};
DECLARE_DYNAMIC_CLASS(VSTSubEntry)
};
IMPLEMENT_DYNAMIC_CLASS(VSTSubEntry, wxModule);
//----------------------------------------------------------------------------
// VSTSubProcess
//----------------------------------------------------------------------------
#define OUTPUTKEY wxT("<VSTLOADCHK>-")
enum InfoKeys
{
kKeySubIDs,
kKeyBegin,
kKeyName,
kKeyPath,
kKeyVendor,
kKeyVersion,
kKeyDescription,
kKeyEffectType,
kKeyInteractive,
kKeyAutomatable,
kKeyEnd
};
///////////////////////////////////////////////////////////////////////////////
///
/// Information about one VST effect.
///
///////////////////////////////////////////////////////////////////////////////
class VSTSubProcess final : public wxProcess,
public EffectDefinitionInterface
{
public:
VSTSubProcess()
{
Redirect();
}
// EffectClientInterface implementation
PluginPath GetPath() override
{
return mPath;
}
ComponentInterfaceSymbol GetSymbol() override
{
return mName;
}
VendorSymbol GetVendor() override
{
return { mVendor };
}
wxString GetVersion() override
{
return mVersion;
}
TranslatableString GetDescription() override
{
return mDescription;
}
EffectFamilySymbol GetFamily() override
{
return VSTPLUGINTYPE;
}
EffectType GetType() override
{
return mType;
}
bool IsInteractive() override
{
return mInteractive;
}
bool IsDefault() override
{
return false;
}
bool IsLegacy() override
{
return false;
}
bool SupportsRealtime() override
{
return mType == EffectTypeProcess;
}
bool SupportsAutomation() override
{
return mAutomatable;
}
public:
wxString mPath;
wxString mName;
wxString mVendor;
wxString mVersion;
TranslatableString mDescription;
EffectType mType;
bool mInteractive;
bool mAutomatable;
};
// ============================================================================
//
// VSTEffectsModule
//
// ============================================================================
VSTEffectsModule::VSTEffectsModule(const wxString *path)
{
if (path)
{
mPath = *path;
}
}
VSTEffectsModule::~VSTEffectsModule()
{
mPath = wxEmptyString;
}
// ============================================================================
// ComponentInterface implementation
// ============================================================================
PluginPath VSTEffectsModule::GetPath()
{
return mPath;
}
ComponentInterfaceSymbol VSTEffectsModule::GetSymbol()
{
return XO("VST Effects");
}
VendorSymbol VSTEffectsModule::GetVendor()
{
return XO("The Audacity Team");
}
wxString VSTEffectsModule::GetVersion()
{
// This "may" be different if this were to be maintained as a separate DLL
return AUDACITY_VERSION_STRING;
}
TranslatableString VSTEffectsModule::GetDescription()
{
return XO("Adds the ability to use VST effects in Audacity.");
}
// ============================================================================
// ModuleInterface implementation
// ============================================================================
bool VSTEffectsModule::Initialize()
{
// Nothing to do here
return true;
}
void VSTEffectsModule::Terminate()
{
// Nothing to do here
return;
}
EffectFamilySymbol VSTEffectsModule::GetOptionalFamilySymbol()
{
#if USE_VST
return VSTPLUGINTYPE;
#else
return {};
#endif
}
const FileExtensions &VSTEffectsModule::GetFileExtensions()
{
static FileExtensions result{{ _T("vst") }};
return result;
}
FilePath VSTEffectsModule::InstallPath()
{
// Not yet ready for VST drag-and-drop...
// return FileNames::PlugInDir();
return {};
}
bool VSTEffectsModule::AutoRegisterPlugins(PluginManagerInterface & WXUNUSED(pm))
{
// We don't auto-register
return true;
}
PluginPaths VSTEffectsModule::FindPluginPaths(PluginManagerInterface & pm)
{
FilePaths pathList;
FilePaths files;
// Check for the VST_PATH environment variable
wxString vstpath = wxString::FromUTF8(getenv("VST_PATH"));
if (!vstpath.empty())
{
wxStringTokenizer tok(vstpath, wxPATH_SEP);
while (tok.HasMoreTokens())
{
pathList.push_back(tok.GetNextToken());
}
}
#if defined(__WXMAC__)
#define VSTPATH wxT("/Library/Audio/Plug-Ins/VST")
// Look in ~/Library/Audio/Plug-Ins/VST and /Library/Audio/Plug-Ins/VST
pathList.push_back(wxGetHomeDir() + wxFILE_SEP_PATH + VSTPATH);
pathList.push_back(VSTPATH);
// Recursively search all paths for Info.plist files. This will identify all
// bundles.
pm.FindFilesInPathList(wxT("Info.plist"), pathList, files, true);
// Remove the 'Contents/Info.plist' portion of the names
for (size_t i = 0; i < files.size(); i++)
{
files[i] = wxPathOnly(wxPathOnly(files[i]));
if (!files[i].EndsWith(wxT(".vst")))
{
files.erase( files.begin() + i-- );
}
}
#elif defined(__WXMSW__)
TCHAR dpath[MAX_PATH];
TCHAR tpath[MAX_PATH];
DWORD len;
// Try HKEY_CURRENT_USER registry key first
len = WXSIZEOF(tpath);
if (SHRegGetUSValue(wxT("Software\\VST"),
wxT("VSTPluginsPath"),
NULL,
tpath,
&len,
FALSE,
NULL,
0) == ERROR_SUCCESS)
{
tpath[len] = 0;
dpath[0] = 0;
ExpandEnvironmentStrings(tpath, dpath, WXSIZEOF(dpath));
pathList.push_back(dpath);
}
// Then try HKEY_LOCAL_MACHINE registry key
len = WXSIZEOF(tpath);
if (SHRegGetUSValue(wxT("Software\\VST"),
wxT("VSTPluginsPath"),
NULL,
tpath,
&len,
TRUE,
NULL,
0) == ERROR_SUCCESS)
{
tpath[len] = 0;
dpath[0] = 0;
ExpandEnvironmentStrings(tpath, dpath, WXSIZEOF(dpath));
pathList.push_back(dpath);
}
// Add the default path last
dpath[0] = 0;
ExpandEnvironmentStrings(wxT("%ProgramFiles%\\Steinberg\\VSTPlugins"),
dpath,
WXSIZEOF(dpath));
pathList.push_back(dpath);
// Recursively scan for all DLLs
pm.FindFilesInPathList(wxT("*.dll"), pathList, files, true);
#else
// Nothing specified in the VST_PATH environment variable...provide defaults
if (vstpath.empty())
{
// We add this "non-default" one
pathList.push_back(wxT(LIBDIR) wxT("/vst"));
// These are the defaults used by other hosts
pathList.push_back(wxT("/usr/lib/vst"));
pathList.push_back(wxT("/usr/local/lib/vst"));
pathList.push_back(wxGetHomeDir() + wxFILE_SEP_PATH + wxT(".vst"));
}
// Recursively scan for all shared objects
pm.FindFilesInPathList(wxT("*.so"), pathList, files, true);
#endif
return { files.begin(), files.end() };
}
unsigned VSTEffectsModule::DiscoverPluginsAtPath(
const PluginPath & path, TranslatableString &errMsg,
const RegistrationCallback &callback)
{
bool error = false;
unsigned nFound = 0;
errMsg = {};
// TODO: Fix this for external usage
const auto &cmdpath = PlatformCompatibility::GetExecutablePath();
wxString effectIDs = wxT("0;");
wxStringTokenizer effectTzr(effectIDs, wxT(";"));
Optional<ProgressDialog> progress{};
size_t idCnt = 0;
size_t idNdx = 0;
bool cont = true;
while (effectTzr.HasMoreTokens() && cont)
{
wxString effectID = effectTzr.GetNextToken();
wxString cmd;
cmd.Printf(wxT("\"%s\" %s \"%s;%s\""), cmdpath, VSTCMDKEY, path, effectID);
VSTSubProcess proc;
try
{
int flags = wxEXEC_SYNC | wxEXEC_NODISABLE;
#if defined(__WXMSW__)
flags += wxEXEC_NOHIDE;
#endif
wxExecute(cmd, flags, &proc);
}
catch (...)
{
wxLogMessage(wxT("VST plugin registration failed for %s\n"), path);
error = true;
}
wxString output;
wxStringOutputStream ss(&output);
proc.GetInputStream()->Read(ss);
int keycount = 0;
bool haveBegin = false;
wxStringTokenizer tzr(output, wxT("\n"));
while (tzr.HasMoreTokens())
{
wxString line = tzr.GetNextToken();
// Our output may follow any output the plugin may have written.
if (!line.StartsWith(OUTPUTKEY))
{
continue;
}
long key;
if (!line.Mid(wxStrlen(OUTPUTKEY)).BeforeFirst(wxT('=')).ToLong(&key))
{
continue;
}
wxString val = line.AfterFirst(wxT('=')).BeforeFirst(wxT('\r'));
switch (key)
{
case kKeySubIDs:
effectIDs = val;
effectTzr.Reinit(effectIDs);
idCnt = effectTzr.CountTokens();
if (idCnt > 3)
{
progress.emplace( XO("Scanning Shell VST"),
XO("Registering %d of %d: %-64.64s")
.Format( 0, idCnt, proc.GetSymbol().Translation())
/*
, wxPD_APP_MODAL |
wxPD_AUTO_HIDE |
wxPD_CAN_ABORT |
wxPD_ELAPSED_TIME |
wxPD_ESTIMATED_TIME |
wxPD_REMAINING_TIME
*/
);
progress->Show();
}
break;
case kKeyBegin:
haveBegin = true;
keycount++;
break;
case kKeyName:
proc.mName = val;
keycount++;
break;
case kKeyPath:
proc.mPath = val;
keycount++;
break;
case kKeyVendor:
proc.mVendor = val;
keycount++;
break;
case kKeyVersion:
proc.mVersion = val;
keycount++;
break;
case kKeyDescription:
proc.mDescription = Verbatim( val );
keycount++;
break;
case kKeyEffectType:
long type;
val.ToLong(&type);
proc.mType = (EffectType) type;
keycount++;
break;
case kKeyInteractive:
proc.mInteractive = val == wxT("1");
keycount++;
break;
case kKeyAutomatable:
proc.mAutomatable = val == wxT("1");
keycount++;
break;
case kKeyEnd:
{
if (!haveBegin || ++keycount != kKeyEnd)
{
keycount = 0;
haveBegin = false;
continue;
}
bool skip = false;
if (progress)
{
idNdx++;
auto result = progress->Update((int)idNdx, (int)idCnt,
XO("Registering %d of %d: %-64.64s")
.Format( idNdx, idCnt, proc.GetSymbol().Translation() ));
cont = (result == ProgressResult::Success);
}
if (!skip && cont)
{
if (callback)
callback( this, &proc );
++nFound;
}
}
break;
default:
keycount = 0;
haveBegin = false;
break;
}
}
}
if (error)
errMsg = XO("Could not load the library");
return nFound;
}
bool VSTEffectsModule::IsPluginValid(const PluginPath & path, bool bFast)
{
if( bFast )
return true;
wxString realPath = path.BeforeFirst(wxT(';'));
return wxFileName::FileExists(realPath) || wxFileName::DirExists(realPath);
}
ComponentInterface *VSTEffectsModule::CreateInstance(const PluginPath & path)
{
// Acquires a resource for the application.
// For us, the ID is simply the path to the effect
// Safety of this depends on complementary calls to DeleteInstance on the module manager side.
return safenew VSTEffect(path);
}
void VSTEffectsModule::DeleteInstance(ComponentInterface *instance)
{
std::unique_ptr < VSTEffect > {
dynamic_cast<VSTEffect *>(instance)
};
}
// ============================================================================
// ModuleEffectInterface implementation
// ============================================================================
// ============================================================================
// VSTEffectsModule implementation
// ============================================================================
// static
//
// Called from reinvokation of Audacity or DLL to check in a separate process
void VSTEffectsModule::Check(const wxChar *path)
{
VSTEffect effect(path);
if (effect.SetHost(NULL))
{
auto effectIDs = effect.GetEffectIDs();
wxString out;
if (effectIDs.size() > 0)
{
wxString subids;
for (size_t i = 0, cnt = effectIDs.size(); i < cnt; i++)
{
subids += wxString::Format(wxT("%d;"), effectIDs[i]);
}
out = wxString::Format(wxT("%s%d=%s\n"), OUTPUTKEY, kKeySubIDs, subids.RemoveLast());
}
else
{
out += wxString::Format(wxT("%s%d=%s\n"), OUTPUTKEY, kKeyBegin, wxEmptyString);
out += wxString::Format(wxT("%s%d=%s\n"), OUTPUTKEY, kKeyPath, effect.GetPath());
out += wxString::Format(wxT("%s%d=%s\n"), OUTPUTKEY, kKeyName, effect.GetSymbol().Internal());
out += wxString::Format(wxT("%s%d=%s\n"), OUTPUTKEY, kKeyVendor,
effect.GetVendor().Internal());
out += wxString::Format(wxT("%s%d=%s\n"), OUTPUTKEY, kKeyVersion, effect.GetVersion());
out += wxString::Format(wxT("%s%d=%s\n"), OUTPUTKEY, kKeyDescription, effect.GetDescription().Translation());
out += wxString::Format(wxT("%s%d=%d\n"), OUTPUTKEY, kKeyEffectType, effect.GetType());
out += wxString::Format(wxT("%s%d=%d\n"), OUTPUTKEY, kKeyInteractive, effect.IsInteractive());
out += wxString::Format(wxT("%s%d=%d\n"), OUTPUTKEY, kKeyAutomatable, effect.SupportsAutomation());
out += wxString::Format(wxT("%s%d=%s\n"), OUTPUTKEY, kKeyEnd, wxEmptyString);
}
// We want to output info in one chunk to prevent output
// from the effect intermixing with the info
const wxCharBuffer buf = out.ToUTF8();
fwrite(buf, 1, strlen(buf), stdout);
fflush(stdout);
}
}
///////////////////////////////////////////////////////////////////////////////
//
// Dialog for configuring latency, buffer size and graphics mode for a
// VST effect.
//
///////////////////////////////////////////////////////////////////////////////
class VSTEffectOptionsDialog final : public wxDialogWrapper
{
public:
VSTEffectOptionsDialog(wxWindow * parent, EffectHostInterface *host);
virtual ~VSTEffectOptionsDialog();
void PopulateOrExchange(ShuttleGui & S);
void OnOk(wxCommandEvent & evt);
private:
EffectHostInterface *mHost;
int mBufferSize;
bool mUseLatency;
bool mUseGUI;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(VSTEffectOptionsDialog, wxDialogWrapper)
EVT_BUTTON(wxID_OK, VSTEffectOptionsDialog::OnOk)
END_EVENT_TABLE()
VSTEffectOptionsDialog::VSTEffectOptionsDialog(wxWindow * parent, EffectHostInterface *host)
: wxDialogWrapper(parent, wxID_ANY, XO("VST Effect Options"))
{
mHost = host;
mHost->GetSharedConfig(wxT("Options"), wxT("BufferSize"), mBufferSize, 8192);
mHost->GetSharedConfig(wxT("Options"), wxT("UseLatency"), mUseLatency, true);
mHost->GetSharedConfig(wxT("Options"), wxT("UseGUI"), mUseGUI, true);
ShuttleGui S(this, eIsCreating);
PopulateOrExchange(S);
}
VSTEffectOptionsDialog::~VSTEffectOptionsDialog()
{
}
void VSTEffectOptionsDialog::PopulateOrExchange(ShuttleGui & S)
{
S.SetBorder(5);
S.StartHorizontalLay(wxEXPAND, 1);
{
S.StartVerticalLay(false);
{
S.StartStatic(XO("Buffer Size"));
{
S.AddVariableText( XO(
"The buffer size controls the number of samples sent to the effect "
"on each iteration. Smaller values will cause slower processing and "
"some effects require 8192 samples or less to work properly. However "
"most effects can accept large buffers and using them will greatly "
"reduce processing time."),
false, 0, 650);
S.StartHorizontalLay(wxALIGN_LEFT);
{
wxTextCtrl *t;
t = S.Validator<IntegerValidator<int>>(
&mBufferSize, NumValidatorStyle::DEFAULT, 8, 1048576 * 1)
.MinSize( { 100, -1 } )
.TieNumericTextBox(XXO("&Buffer Size (8 to 1048576 samples):"),
mBufferSize,
12);
}
S.EndHorizontalLay();
}
S.EndStatic();
S.StartStatic(XO("Latency Compensation"));
{
S.AddVariableText( XO(
"As part of their processing, some VST effects must delay returning "
"audio to Audacity. When not compensating for this delay, you will "
"notice that small silences have been inserted into the audio. "
"Enabling this option will provide that compensation, but it may "
"not work for all VST effects."),
false, 0, 650);
S.StartHorizontalLay(wxALIGN_LEFT);
{
S.TieCheckBox(XXO("Enable &compensation"),
mUseLatency);
}
S.EndHorizontalLay();
}
S.EndStatic();
S.StartStatic(XO("Graphical Mode"));
{
S.AddVariableText( XO(
"Most VST effects have a graphical interface for setting parameter values."
" A basic text-only method is also available. "
" Reopen the effect for this to take effect."),
false, 0, 650);
S.TieCheckBox(XXO("Enable &graphical interface"),
mUseGUI);
}
S.EndStatic();
}
S.EndVerticalLay();
}
S.EndHorizontalLay();
S.AddStandardButtons();
Layout();
Fit();
Center();
}
void VSTEffectOptionsDialog::OnOk(wxCommandEvent & WXUNUSED(evt))
{
if (!Validate())
{
return;
}
ShuttleGui S(this, eIsGettingFromDialog);
PopulateOrExchange(S);
mHost->SetSharedConfig(wxT("Options"), wxT("BufferSize"), mBufferSize);
mHost->SetSharedConfig(wxT("Options"), wxT("UseLatency"), mUseLatency);
mHost->SetSharedConfig(wxT("Options"), wxT("UseGUI"), mUseGUI);
EndModal(wxID_OK);
}
///////////////////////////////////////////////////////////////////////////////
///
/// Wrapper for wxTimer that calls a VST effect at regular intervals.
///
/// \todo should there be tests for no timer available?
///
///////////////////////////////////////////////////////////////////////////////
class VSTEffectTimer final : public wxTimer
{
public:
VSTEffectTimer(VSTEffect *effect)
: wxTimer(),
mEffect(effect)
{
}
~VSTEffectTimer()
{
}
void Notify()
{
mEffect->OnTimer();
}
private:
VSTEffect *mEffect;
};
///////////////////////////////////////////////////////////////////////////////
//
// VSTEffect
//
///////////////////////////////////////////////////////////////////////////////
enum
{
ID_Duration = 20000,
ID_Sliders = 21000,
};
DEFINE_LOCAL_EVENT_TYPE(EVT_SIZEWINDOW);
DEFINE_LOCAL_EVENT_TYPE(EVT_UPDATEDISPLAY);
BEGIN_EVENT_TABLE(VSTEffect, wxEvtHandler)
EVT_COMMAND_RANGE(ID_Sliders, ID_Sliders + 999, wxEVT_COMMAND_SLIDER_UPDATED, VSTEffect::OnSlider)
// Events from the audioMaster callback
EVT_COMMAND(wxID_ANY, EVT_SIZEWINDOW, VSTEffect::OnSizeWindow)
END_EVENT_TABLE()
// Needed to support shell plugins...sucks, but whatcha gonna do???
intptr_t VSTEffect::mCurrentEffectID;
typedef AEffect *(*vstPluginMain)(audioMasterCallback audioMaster);
intptr_t VSTEffect::AudioMaster(AEffect * effect,
int32_t opcode,
int32_t index,
intptr_t value,
void * ptr,
float opt)
{
VSTEffect *vst = (effect ? (VSTEffect *) effect->ptr2 : NULL);
// Handles operations during initialization...before VSTEffect has had a
// chance to set its instance pointer.
switch (opcode)
{
case audioMasterVersion:
return (intptr_t) 2400;
case audioMasterCurrentId:
return mCurrentEffectID;
case audioMasterGetVendorString:
strcpy((char *) ptr, "Audacity Team"); // Do not translate, max 64 + 1 for null terminator
return 1;
case audioMasterGetProductString:
strcpy((char *) ptr, "Audacity"); // Do not translate, max 64 + 1 for null terminator
return 1;
case audioMasterGetVendorVersion:
return (intptr_t) (AUDACITY_VERSION << 24 |
AUDACITY_RELEASE << 16 |
AUDACITY_REVISION << 8 |
AUDACITY_MODLEVEL);
// Some (older) effects depend on an effIdle call when requested. An
// example is the Antress Modern plugins which uses the call to update
// the editors display when the program (preset) changes.
case audioMasterNeedIdle:
if (vst)
{
vst->NeedIdle();
return 1;
}
return 0;
// We would normally get this if the effect editor is dipslayed and something "major"
// has changed (like a program change) instead of multiple automation calls.
// Since we don't do anything with the parameters while the editor is displayed,
// there's no need for us to do anything.
case audioMasterUpdateDisplay:
if (vst)
{