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 <FL/Fl_Double_Window.H>
29 #include "core/conf.h"
30 #include "core/clock.h"
31 #include "utils/math.h"
32 #include "gui/elems/basics/choice.h"
33 #include "gui/elems/basics/check.h"
34 #include "gridTool.h"
35
36
37 namespace giada {
38 namespace v
39 {
geGridTool(Pixel x,Pixel y)40 geGridTool::geGridTool(Pixel x, Pixel y)
41 : Fl_Group(x, y, 80, 20)
42 {
43 gridType = new geChoice(x, y, 40, 20);
44 gridType->add("1");
45 gridType->add("2");
46 gridType->add("3");
47 gridType->add("4");
48 gridType->add("6");
49 gridType->add("8");
50 gridType->add("16");
51 gridType->add("32");
52 gridType->value(0);
53 gridType->callback(cb_changeType, (void*)this);
54
55 active = new geCheck(gridType->x() + gridType->w() + 4, y, 20, 20);
56
57 gridType->value(m::conf::conf.actionEditorGridVal);
58 active->value(m::conf::conf.actionEditorGridOn);
59
60 end();
61 }
62
63
64 /* -------------------------------------------------------------------------- */
65
66
~geGridTool()67 geGridTool::~geGridTool()
68 {
69 m::conf::conf.actionEditorGridVal = gridType->value();
70 m::conf::conf.actionEditorGridOn = active->value();
71 }
72
73
74 /* -------------------------------------------------------------------------- */
75
76
cb_changeType(Fl_Widget *,void * p)77 void geGridTool::cb_changeType(Fl_Widget* /*w*/, void* p) { ((geGridTool*)p)->cb_changeType(); }
78
79
80 /* -------------------------------------------------------------------------- */
81
82
cb_changeType()83 void geGridTool::cb_changeType()
84 {
85 window()->redraw();
86 }
87
88
89 /* -------------------------------------------------------------------------- */
90
91
isOn() const92 bool geGridTool::isOn() const
93 {
94 return active->value();
95 }
96
97
98 /* -------------------------------------------------------------------------- */
99
100
getValue() const101 int geGridTool::getValue() const
102 {
103 switch (gridType->value()) {
104 case 0: return 1;
105 case 1: return 2;
106 case 2: return 3;
107 case 3: return 4;
108 case 4: return 6;
109 case 5: return 8;
110 case 6: return 16;
111 case 7: return 32;
112 }
113 return 0;
114 }
115
116
117 /* -------------------------------------------------------------------------- */
118
119
getSnapFrame(Frame v) const120 Frame geGridTool::getSnapFrame(Frame v) const
121 {
122 if (!isOn())
123 return v;
124 return u::math::quantize(v, getCellSize());
125 }
126
127
128 /* -------------------------------------------------------------------------- */
129
130
getCellSize() const131 Frame geGridTool::getCellSize() const
132 {
133 return m::clock::getFramesInBeat() / getValue();
134 }
135 }} // giada::v::