1 /* 2 * Copyright 2012, Gerasim Troeglazov (3dEyes**), 3dEyes@gmail.com. 3 * All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 #include <Entry.h> 8 #include <Directory.h> 9 #include <FindDirectory.h> 10 11 #include "VSTNode.h" 12 #include "VSTAddOn.h" 13 14 extern "C" _EXPORT BMediaAddOn* make_media_addon(image_id image) 15 { 16 return new VSTAddOn(image); 17 } 18 19 VSTAddOn::VSTAddOn(image_id image) 20 : 21 BMediaAddOn(image) 22 { 23 const char vst_subdir[]={"media/vstplugins"}; 24 25 BPath addons_dir; 26 fPluginsList.MakeEmpty(); 27 28 find_directory(B_USER_NONPACKAGED_ADDONS_DIRECTORY, &addons_dir); 29 addons_dir.Append(vst_subdir); 30 ScanPluginsFolders(addons_dir.Path(), true); 31 32 find_directory(B_USER_ADDONS_DIRECTORY, &addons_dir); 33 addons_dir.Append(vst_subdir); 34 ScanPluginsFolders(addons_dir.Path() ,true); 35 36 find_directory(B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY, &addons_dir); 37 addons_dir.Append(vst_subdir); 38 ScanPluginsFolders(addons_dir.Path()); 39 40 find_directory(B_SYSTEM_ADDONS_DIRECTORY, &addons_dir); 41 addons_dir.Append(vst_subdir); 42 ScanPluginsFolders(addons_dir.Path()); 43 } 44 45 VSTAddOn::~VSTAddOn() 46 { 47 48 } 49 50 status_t 51 VSTAddOn::InitCheck(const char** text) 52 { 53 return B_OK; 54 } 55 56 int32 57 VSTAddOn::CountFlavors() 58 { 59 return fPluginsList.CountItems(); 60 } 61 62 status_t 63 VSTAddOn::GetFlavorAt(int32 idx, const flavor_info** info) 64 { 65 if (idx < 0 || idx >= fPluginsList.CountItems()) 66 return B_ERROR; 67 68 VSTPlugin *plugin = (VSTPlugin*)fPluginsList.ItemAt(idx); 69 70 flavor_info *f_info = new flavor_info; 71 f_info->internal_id = idx; 72 f_info->kinds = B_BUFFER_CONSUMER | B_BUFFER_PRODUCER | B_CONTROLLABLE; 73 f_info->possible_count = 0; 74 f_info->flavor_flags = 0; 75 f_info->name = (char *)plugin->ModuleName(); 76 f_info->info = (char *)plugin->Product(); 77 78 media_format *format = new media_format; 79 format->type = B_MEDIA_RAW_AUDIO; 80 format->u.raw_audio = media_raw_audio_format::wildcard; 81 format->u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT; 82 83 f_info->in_format_count = 1; 84 f_info->in_formats = format; 85 86 format = new media_format; 87 format->type = B_MEDIA_RAW_AUDIO; 88 format->u.raw_audio = media_raw_audio_format::wildcard; 89 format->u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT; 90 91 f_info->out_format_count = 1; 92 f_info->out_formats = format; 93 94 *info = f_info; 95 96 return B_OK; 97 } 98 99 BMediaNode* 100 VSTAddOn::InstantiateNodeFor(const flavor_info* info, BMessage* config, 101 status_t* err) 102 { 103 VSTPlugin* plugin = (VSTPlugin*)fPluginsList.ItemAt(info->internal_id); 104 VSTNode* node = new VSTNode(this, plugin->ModuleName(), plugin->Path()); 105 return node; 106 } 107 108 int 109 VSTAddOn::ScanPluginsFolders(const char* path, bool make_dir) 110 { 111 BEntry ent; 112 113 BDirectory dir(path); 114 if (dir.InitCheck() != B_OK) { 115 create_directory(path, 0755); 116 return 0; 117 } 118 119 while(dir.GetNextEntry(&ent) == B_OK) { 120 BPath p(&ent); 121 if (ent.IsDirectory()) { 122 ScanPluginsFolders(p.Path()); 123 } else { 124 VSTPlugin* plugin = new VSTPlugin(); 125 int ret = plugin->LoadModule(p.Path()); 126 if (ret == B_OK) { 127 plugin->UnLoadModule(); 128 fPluginsList.AddItem(plugin); 129 } else 130 delete plugin; 131 } 132 } 133 return 0; 134 } 135 136 status_t 137 VSTAddOn::GetConfigurationFor(BMediaNode* node, BMessage* message) 138 { 139 return B_OK; 140 } 141 142 bool 143 VSTAddOn::WantsAutoStart() 144 { 145 return false; 146 } 147 148 status_t 149 VSTAddOn::AutoStart(int count, BMediaNode** node, int32* id, bool* more) 150 { 151 return B_OK; 152 } 153