3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / media / media-add-ons / vst_host / VSTAddOn.cpp
bloba1ea8acafd3db526f494d28d340c71d97130e116
1 /*
2 * Copyright 2012, Gerasim Troeglazov (3dEyes**), 3dEyes@gmail.com.
3 * All rights reserved.
4 * Distributed under the terms of the MIT License.
5 */
7 #include <Entry.h>
8 #include <Directory.h>
9 #include <FindDirectory.h>
10 #include <PathFinder.h>
11 #include <StringList.h>
13 #include "VSTNode.h"
14 #include "VSTAddOn.h"
16 extern "C" _EXPORT BMediaAddOn* make_media_addon(image_id image)
18 return new VSTAddOn(image);
21 VSTAddOn::VSTAddOn(image_id image)
23 BMediaAddOn(image)
25 fPluginsList.MakeEmpty();
27 BStringList folders;
29 BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY,
30 "media/vstplugins/", B_FIND_PATH_EXISTING_ONLY, folders);
32 for (int32 i = 0; i < folders.CountStrings(); i++)
33 ScanPluginsFolder(folders.StringAt(i).String());
36 VSTAddOn::~VSTAddOn()
41 status_t
42 VSTAddOn::InitCheck(const char** text)
44 return B_OK;
47 int32
48 VSTAddOn::CountFlavors()
50 return fPluginsList.CountItems();
53 status_t
54 VSTAddOn::GetFlavorAt(int32 idx, const flavor_info** info)
56 if (idx < 0 || idx >= fPluginsList.CountItems())
57 return B_ERROR;
59 VSTPlugin *plugin = (VSTPlugin*)fPluginsList.ItemAt(idx);
61 flavor_info *f_info = new flavor_info;
62 f_info->internal_id = idx;
63 f_info->kinds = B_BUFFER_CONSUMER | B_BUFFER_PRODUCER | B_CONTROLLABLE;
64 f_info->possible_count = 0;
65 f_info->flavor_flags = 0;
66 f_info->name = (char *)plugin->ModuleName();
67 f_info->info = (char *)plugin->Product();
69 media_format *format = new media_format;
70 format->type = B_MEDIA_RAW_AUDIO;
71 format->u.raw_audio = media_raw_audio_format::wildcard;
72 format->u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT;
74 f_info->in_format_count = 1;
75 f_info->in_formats = format;
77 format = new media_format;
78 format->type = B_MEDIA_RAW_AUDIO;
79 format->u.raw_audio = media_raw_audio_format::wildcard;
80 format->u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT;
82 f_info->out_format_count = 1;
83 f_info->out_formats = format;
85 *info = f_info;
87 return B_OK;
90 BMediaNode*
91 VSTAddOn::InstantiateNodeFor(const flavor_info* info, BMessage* config,
92 status_t* err)
94 VSTPlugin* plugin = (VSTPlugin*)fPluginsList.ItemAt(info->internal_id);
95 VSTNode* node = new VSTNode(this, plugin->ModuleName(), plugin->Path());
96 return node;
99 int
100 VSTAddOn::ScanPluginsFolder(const char* path, bool make_dir)
102 BEntry ent;
104 BDirectory dir(path);
105 if (dir.InitCheck() != B_OK) {
106 if (make_dir == true)
107 create_directory(path, 0755);
108 return 0;
111 while(dir.GetNextEntry(&ent) == B_OK) {
112 BPath p(&ent);
113 if (ent.IsDirectory()) {
114 ScanPluginsFolder(p.Path());
115 } else {
116 VSTPlugin* plugin = new VSTPlugin();
117 int ret = plugin->LoadModule(p.Path());
118 if (ret == B_OK) {
119 plugin->UnLoadModule();
120 fPluginsList.AddItem(plugin);
121 } else
122 delete plugin;
125 return 0;
128 status_t
129 VSTAddOn::GetConfigurationFor(BMediaNode* node, BMessage* message)
131 return B_OK;
134 bool
135 VSTAddOn::WantsAutoStart()
137 return false;
140 status_t
141 VSTAddOn::AutoStart(int count, BMediaNode** node, int32* id, bool* more)
143 return B_OK;