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 "core/const.h"
32 #include "glue/plugin.h"
33 #include "glue/events.h"
34 #include "gui/elems/basics/boxtypes.h"
35 #include "gui/elems/basics/box.h"
36 #include "gui/elems/basics/slider.h"
37 #include "pluginParameter.h"
38 
39 
40 namespace giada {
41 namespace v
42 {
gePluginParameter(int X,int Y,int W,int labelWidth,const c::plugin::Param p)43 gePluginParameter::gePluginParameter(int X, int Y, int W, int labelWidth, const c::plugin::Param p)
44 : Fl_Group  (X, Y, W, G_GUI_UNIT)
45 , m_param   (p)
46 {
47 	begin();
48 
49 		const int VALUE_WIDTH = 100;
50 
51 		m_label = new geBox(x(), y(), labelWidth, G_GUI_UNIT);
52 		m_label->copy_label(m_param.name.c_str());
53 
54 		m_slider = new geSlider(m_label->x()+m_label->w()+G_GUI_OUTER_MARGIN, y(),
55 			w()-(m_label->x()+m_label->w()+G_GUI_OUTER_MARGIN)-VALUE_WIDTH, G_GUI_UNIT);
56 		m_slider->value(m_param.value);
57 		m_slider->callback(cb_setValue, (void*)this);
58 
59 		m_value = new geBox(m_slider->x()+m_slider->w()+G_GUI_OUTER_MARGIN, y(), VALUE_WIDTH, G_GUI_UNIT);
60 		m_value->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
61 		m_value->box(G_CUSTOM_BORDER_BOX);
62 
63 	end();
64 
65 	resizable(m_slider);
66 	update(m_param, false);
67 }
68 
69 
70 /* -------------------------------------------------------------------------- */
71 
72 
cb_setValue(Fl_Widget *,void * p)73 void gePluginParameter::cb_setValue(Fl_Widget* /*w*/, void* p) { ((gePluginParameter*)p)->cb_setValue(); }
74 
75 
76 /* -------------------------------------------------------------------------- */
77 
78 
cb_setValue()79 void gePluginParameter::cb_setValue()
80 {
81 	c::events::setPluginParameter(m_param.pluginId, m_param.index, m_slider->value(),
82 		/*gui=*/true);
83 }
84 
85 
86 /* -------------------------------------------------------------------------- */
87 
88 
update(const c::plugin::Param & p,bool changeSlider)89 void gePluginParameter::update(const c::plugin::Param& p, bool changeSlider)
90 {
91 	m_value->copy_label(std::string(p.text + " " + p.label).c_str());
92 	if (changeSlider)
93 		m_slider->value(p.value);
94 }
95 }} // giada::v::
96 
97 
98 #endif // #ifdef WITH_VST
99