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 #include <cstring>
29 #include "core/conf.h"
30 #include "core/const.h"
31 #include "core/mixer.h"
32 #include "core/clock.h"
33 #include "glue/main.h"
34 #include "utils/gui.h"
35 #include "utils/string.h"
36 #include "gui/elems/basics/button.h"
37 #include "gui/elems/basics/input.h"
38 #include "bpmInput.h"
39 #include "mainWindow.h"
40
41
42 extern giada::v::gdMainWindow* mainWin;
43
44
45 namespace giada {
46 namespace v
47 {
gdBpmInput(const char * label)48 gdBpmInput::gdBpmInput(const char* label)
49 : gdWindow(u::gui::centerWindowX(144), u::gui::centerWindowY(36), 144, 36, "Bpm")
50 {
51 set_modal();
52
53 input_a = new geInput(8, 8, 30, G_GUI_UNIT);
54 input_b = new geInput(42, 8, 20, G_GUI_UNIT);
55 ok = new geButton(66, 8, 70, G_GUI_UNIT, "Ok");
56 end();
57
58 input_a->maximum_size(3);
59 input_a->type(FL_INT_INPUT);
60 input_a->value(u::string::fToString(m::clock::getBpm(), 0).c_str());
61
62 /* Use the decimal value from the string label. */
63
64 std::vector<std::string> tokens = u::string::split(label, ".");
65
66 input_b->maximum_size(1);
67 input_b->type(FL_INT_INPUT);
68 input_b->value(tokens[1].c_str());
69
70 ok->shortcut(FL_Enter);
71 ok->callback(cb_update, (void*)this);
72
73 u::gui::setFavicon(this);
74 setId(WID_BPM);
75 show();
76 }
77
78
79 /* -------------------------------------------------------------------------- */
80
81
cb_update(Fl_Widget *,void * p)82 void gdBpmInput::cb_update(Fl_Widget* /*w*/, void* p) { ((gdBpmInput*)p)->cb_update(); }
83
84
85 /* -------------------------------------------------------------------------- */
86
87
cb_update()88 void gdBpmInput::cb_update()
89 {
90 if (strcmp(input_a->value(), "") == 0)
91 return;
92 c::main::setBpm(input_a->value(), input_b->value());
93 do_callback();
94 }
95
96
97 }} // giada::v::