File: LoadVSTWin.cpp

package info (click to toggle)
audacity 0.98-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,896 kB
  • ctags: 4,089
  • sloc: cpp: 26,099; ansic: 4,961; sh: 2,465; makefile: 156; perl: 23
file content (97 lines) | stat: -rw-r--r-- 2,584 bytes parent folder | download
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
/**********************************************************************

  Audacity: A Digital Audio Editor

  LoadVSTWin.cpp

  Mark Tomlinson

**********************************************************************/

#include <windows.h>

#include "AudioEffect.hpp"      // VST API

#include "VSTEffect.h"          // This class's header
#include "../DirManager.h"      // Audacity class which handles data structures

int audacityVSTID = 1;

extern "C" {

   long audioMaster(AEffect * effect, long opcode, long index,
                    long value, void *ptr, float opt) {
      switch (opcode) {
      case audioMasterVersion:
         return 2;
         case audioMasterCurrentId:return audacityVSTID;
         default:return 0;
   }} typedef AEffect *(*vstPluginMain) (audioMasterCallback audioMaster);

   void LoadVSTPlugins(wxString searchDir) {
      wxString pathChar = DirManager::GetPathChar();
      wxString vstDirPath = searchDir + pathChar + "vst";
      wxString fname;

      fname =
          wxFindFirstFile((const char *) (vstDirPath + pathChar +
                                          "*.DLL"));

      while (fname != "") {
         HANDLE hLib = LoadLibrary(fname);

         if (hLib != NULL) {

            // get the address of the main() function

            vstPluginMain pDllMain =
                (vstPluginMain) GetProcAddress((HINSTANCE) hLib, "main");

            if (pDllMain != NULL) {

               AEffect *theEffect;

               theEffect = (pDllMain) (audioMaster);

               if (theEffect->magic == kEffectMagic) {
                  wxString title = wxFileNameFromPath(fname);
                  int len = title.Len();
                  if (len > 4 && (title.Mid(len - 4) == ".DLL"
                                  || title.Mid(len - 4) == ".dll"))
                     title = title.Mid(0, len - 4);

                  VSTEffect *vst = new VSTEffect(title, theEffect);
                  Effect::RegisterEffect(vst);
               }
            }

            audacityVSTID++;
         } else {
            FreeLibrary((HINSTANCE) hLib);
         }

         fname = wxFindNextFile();
      }
   }


};                              // extern "C"

/*

How to enumerate symbols:

        long numSymbols;
    
        err = CountSymbols(connID, &numSymbols);
        if (!err)
            for(int y=0; y<numSymbols; y++) {
            
                Str255 symbolName;
            
                err = GetIndSymbol(connID, y, symbolName, &symbolAddress, &symbolClass);
                
                
            }

*/