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_COMMON_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_BEOS_ADDONS_DIRECTORY, &addons_dir); 37 addons_dir.Append(vst_subdir); 38 ScanPluginsFolders(addons_dir.Path()); 39 } 40 41 VSTAddOn::~VSTAddOn() 42 { 43 44 } 45 46 status_t 47 VSTAddOn::InitCheck(const char** text) 48 { 49 return B_OK; 50 } 51 52 int32 53 VSTAddOn::CountFlavors() 54 { 55 return fPluginsList.CountItems(); 56 } 57 58 status_t 59 VSTAddOn::GetFlavorAt(int32 idx, const flavor_info** info) 60 { 61 if (idx < 0 || idx >= fPluginsList.CountItems()) 62 return B_ERROR; 63 64 VSTPlugin *plugin = (VSTPlugin*)fPluginsList.ItemAt(idx); 65 66 flavor_info *f_info = new flavor_info; 67 f_info->internal_id = idx; 68 f_info->kinds = B_BUFFER_CONSUMER | B_BUFFER_PRODUCER | B_CONTROLLABLE; 69 f_info->possible_count = 0; 70 f_info->flavor_flags = 0; 71 f_info->name = (char *)plugin->ModuleName(); 72 f_info->info = (char *)plugin->Product(); 73 74 media_format *format = new media_format; 75 format->type = B_MEDIA_RAW_AUDIO; 76 format->u.raw_audio = media_raw_audio_format::wildcard; 77 format->u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT; 78 79 f_info->in_format_count = 1; 80 f_info->in_formats = format; 81 82 format = new media_format; 83 format->type = B_MEDIA_RAW_AUDIO; 84 format->u.raw_audio = media_raw_audio_format::wildcard; 85 format->u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT; 86 87 f_info->out_format_count = 1; 88 f_info->out_formats = format; 89 90 *info = f_info; 91 92 return B_OK; 93 } 94 95 BMediaNode* 96 VSTAddOn::InstantiateNodeFor(const flavor_info* info, BMessage* config, 97 status_t* err) 98 { 99 VSTPlugin* plugin = (VSTPlugin*)fPluginsList.ItemAt(info->internal_id); 100 VSTNode* node = new VSTNode(this, plugin->ModuleName(), plugin->Path()); 101 return node; 102 } 103 104 int 105 VSTAddOn::ScanPluginsFolders(const char* path, bool make_dir) 106 { 107 BEntry ent; 108 109 BDirectory dir(path); 110 if (dir.InitCheck() != B_OK) { 111 create_directory(path, 0755); 112 return 0; 113 } 114 115 while(dir.GetNextEntry(&ent) == B_OK) { 116 BPath p(&ent); 117 if (ent.IsDirectory()) { 118 ScanPluginsFolders(p.Path()); 119 } else { 120 VSTPlugin* plugin = new VSTPlugin(); 121 int ret = plugin->LoadModule(p.Path()); 122 if (ret == B_OK) { 123 plugin->UnLoadModule(); 124 fPluginsList.AddItem(plugin); 125 } else 126 delete plugin; 127 } 128 } 129 return 0; 130 } 131 132 status_t 133 VSTAddOn::GetConfigurationFor(BMediaNode* node, BMessage* message) 134 { 135 return B_OK; 136 } 137 138 bool 139 VSTAddOn::WantsAutoStart() 140 { 141 return false; 142 } 143 144 status_t 145 VSTAddOn::AutoStart(int count, BMediaNode** node, int32* id, bool* more) 146 { 147 return B_OK; 148 } 149