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 <cassert>
32 #include <string>
33 #include "core/conf.h"
34 #include "core/const.h"
35 #include "utils/string.h"
36 #include "utils/gui.h"
37 #include "gui/elems/basics/liquidScroll.h"
38 #include "gui/elems/basics/boxtypes.h"
39 #include "gui/elems/basics/button.h"
40 #include "gui/elems/basics/statusButton.h"
41 #include "gui/elems/mainWindow/mainIO.h"
42 #include "gui/elems/mainWindow/keyboard/channel.h"
43 #include "gui/elems/plugin/pluginElement.h"
44 #include "pluginChooser.h"
45 #include "mainWindow.h"
46 #include "pluginList.h"
47 
48 
49 extern giada::v::gdMainWindow* G_MainWin;
50 
51 
52 namespace giada {
53 namespace v
54 {
gdPluginList(ID channelId)55 gdPluginList::gdPluginList(ID channelId)
56 : gdWindow   (m::conf::conf.pluginListX, m::conf::conf.pluginListY, 468, 204)
57 , m_channelId(channelId)
58 {
59 	end();
60 
61 	list = new geLiquidScroll(G_GUI_OUTER_MARGIN, G_GUI_OUTER_MARGIN,
62 		w() - (G_GUI_OUTER_MARGIN*2), h() - (G_GUI_OUTER_MARGIN*2));
63 	list->end();
64 	add(list);
65 	resizable(list);
66 
67 	u::gui::setFavicon(this);
68 	set_non_modal();
69 	rebuild();
70 	show();
71 }
72 
73 
74 /* -------------------------------------------------------------------------- */
75 
76 
~gdPluginList()77 gdPluginList::~gdPluginList()
78 {
79 	m::conf::conf.pluginListX = x();
80 	m::conf::conf.pluginListY = y();
81 }
82 
83 
84 /* -------------------------------------------------------------------------- */
85 
86 
cb_addPlugin(Fl_Widget *,void * p)87 void gdPluginList::cb_addPlugin(Fl_Widget* /*v*/, void* p) { ((gdPluginList*)p)->cb_addPlugin(); }
88 
89 
90 /* -------------------------------------------------------------------------- */
91 
92 
rebuild()93 void gdPluginList::rebuild()
94 {
95 	m_plugins = c::plugin::getPlugins(m_channelId);
96 
97 	if (m_plugins.channelId == m::mixer::MASTER_OUT_CHANNEL_ID)
98 		label("Master Out Plug-ins");
99 	else
100 	if (m_plugins.channelId == m::mixer::MASTER_IN_CHANNEL_ID)
101 		label("Master In Plug-ins");
102 	else {
103 		std::string l = "Channel " + u::string::iToString(m_plugins.channelId) + " Plug-ins";
104 		copy_label(l.c_str());
105 	}
106 
107 	/* Clear the previous list. */
108 
109 	list->clear();
110 	list->scroll_to(0, 0);
111 
112 	for (ID pluginId : m_plugins.pluginIds)
113 		list->addWidget(new gePluginElement(0, 0, c::plugin::getPlugin(pluginId, m_plugins.channelId)));
114 
115 	addPlugin = list->addWidget(new geButton(0, 0, 0, G_GUI_UNIT, "-- add new plugin --"));
116 
117 	addPlugin->callback(cb_addPlugin, (void*)this);
118 }
119 
120 
121 /* -------------------------------------------------------------------------- */
122 
123 
cb_addPlugin()124 void gdPluginList::cb_addPlugin()
125 {
126 	int wx = m::conf::conf.pluginChooserX;
127 	int wy = m::conf::conf.pluginChooserY;
128 	int ww = m::conf::conf.pluginChooserW;
129 	int wh = m::conf::conf.pluginChooserH;
130 	u::gui::openSubWindow(G_MainWin, new v::gdPluginChooser(wx, wy, ww, wh,
131 		m_plugins.channelId), WID_FX_CHOOSER);
132 }
133 
134 
135 /* -------------------------------------------------------------------------- */
136 
137 
getNextElement(const gePluginElement & currEl) const138 const gePluginElement& gdPluginList::getNextElement(const gePluginElement& currEl) const
139 {
140 	int curr = list->find(currEl);
141 	int next = curr + 1;
142 	if (next > list->countChildren() - 2)
143 		next = list->countChildren() - 2;
144 	return *static_cast<gePluginElement*>(list->child(next));
145 }
146 
147 
getPrevElement(const gePluginElement & currEl) const148 const gePluginElement& gdPluginList::getPrevElement(const gePluginElement& currEl) const
149 {
150 	int curr = list->find(currEl);
151 	int prev = curr - 1;
152 	if (prev < 0)
153 		prev = 0;
154 	return *static_cast<gePluginElement*>(list->child(prev));
155 }
156 }} // giada::v::
157 
158 
159 #endif // #ifdef WITH_VST
160