1 /* -----------------------------------------------------------------------------
2  *
3  * Giada - Your Hardcore Loopmachine
4  *
5  * -----------------------------------------------------------------------------
6  *
7  * Copyright (C) 2010-2020 Giovanni A. Zuliani | Monocasual
8  *
9  * This file is part of Giada - Your Hardcore Loopmachine.
10  *
11  * Giada - Your Hardcore Loopmachine is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation, either
14  * version 3 of the License, or (at your option) any later version.
15  *
16  * Giada - Your Hardcore Loopmachine is distributed in the hope that it
17  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
18  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with Giada - Your Hardcore Loopmachine. If not, see
23  * <http://www.gnu.org/licenses/>.
24  *
25  * -------------------------------------------------------------------------- */
26 
27 
28 #ifdef WITH_VST
29 
30 
31 #include <FL/fl_draw.H>
32 #include "core/plugins/plugin.h"
33 #include "core/const.h"
34 #include "core/plugins/pluginManager.h"
35 #include "core/plugins/pluginHost.h"
36 #include "gui/elems/basics/boxtypes.h"
37 #include "pluginBrowser.h"
38 
39 
40 namespace giada {
41 namespace v
42 {
gePluginBrowser(int x,int y,int w,int h)43 gePluginBrowser::gePluginBrowser(int x, int y, int w, int h)
44 	: Fl_Browser(x, y, w, h)
45 {
46 	box(G_CUSTOM_BORDER_BOX);
47 	textsize(G_GUI_FONT_SIZE_BASE);
48 	textcolor(G_COLOR_LIGHT_2);
49 	selection_color(G_COLOR_GREY_4);
50 	color(G_COLOR_GREY_2);
51 
52 	this->scrollbar.color(G_COLOR_GREY_2);
53 	this->scrollbar.selection_color(G_COLOR_GREY_4);
54 	this->scrollbar.labelcolor(G_COLOR_LIGHT_1);
55 	this->scrollbar.slider(G_CUSTOM_BORDER_BOX);
56 
57 	this->hscrollbar.color(G_COLOR_GREY_2);
58 	this->hscrollbar.selection_color(G_COLOR_GREY_4);
59 	this->hscrollbar.labelcolor(G_COLOR_LIGHT_1);
60 	this->hscrollbar.slider(G_CUSTOM_BORDER_BOX);
61 
62 	type(FL_HOLD_BROWSER);
63 
64 	computeWidths();
65 
66 	column_widths(widths);
67 	column_char('\t');       // tabs as column delimiters
68 
69 	refresh();
70 
71 	end();
72 }
73 
74 
75 /* -------------------------------------------------------------------------- */
76 
77 
refresh()78 void gePluginBrowser::refresh()
79 {
80 	clear();
81 
82 	add("NAME\tMANUFACTURER\tCATEGORY\tFORMAT\tUID");
83 	add("---\t---\t---\t---\t---");
84 
85 	for (int i=0; i<m::pluginManager::countAvailablePlugins(); i++) {
86 		m::pluginManager::PluginInfo pi = m::pluginManager::getAvailablePluginInfo(i);
87 		std::string m = m::pluginManager::doesPluginExist(pi.uid) ? "" : "@-";
88 		std::string s = m + pi.name + "\t" + m + pi.manufacturerName + "\t" + m +
89 			pi.category +	"\t" + m + pi.format + "\t" + m + pi.uid;
90 		add(s.c_str());
91 	}
92 
93 	for (int i = 0; i < m::pluginManager::countUnknownPlugins(); i++) {
94 		std::string s = "?\t?\t?\t?\t? " + m::pluginManager::getUnknownPluginInfo(i) + " ?";
95 		add(s.c_str());
96 	}
97 }
98 
99 
100 /* -------------------------------------------------------------------------- */
101 
102 
computeWidths()103 void gePluginBrowser::computeWidths()
104 {
105 	int w0, w1, w3;
106 	for (int i = 0; i < m::pluginManager::countAvailablePlugins(); i++) {
107 		m::pluginManager::PluginInfo pi = m::pluginManager::getAvailablePluginInfo(i);
108 		w0 = (int) fl_width(pi.name.c_str());
109 		w1 = (int) fl_width(pi.manufacturerName.c_str());
110 		w3 = (int) fl_width(pi.format.c_str());
111 		if (w0 > widths[0]) widths[0] = w0;
112 		if (w1 > widths[1]) widths[1] = w1;
113 		if (w3 > widths[3]) widths[3] = w3;
114 	}
115 	widths[0] += 60;
116 	widths[1] += 60;
117 	widths[2] = static_cast<int>(fl_width("CATEGORY") + 60);
118 	widths[3] += 60;
119 	widths[4] = 0;
120 }
121 }} // giada::v::
122 
123 
124 #endif
125