1 /* -----------------------------------------------------------------------------
2  *
3  * Giada - Your Hardcore Loopmachine
4  *
5  * beatMeter
6  *
7  * -----------------------------------------------------------------------------
8  *
9  * Copyright (C) 2010-2020 Giovanni A. Zuliani | Monocasual
10  *
11  * This file is part of Giada - Your Hardcore Loopmachine.
12  *
13  * Giada - Your Hardcore Loopmachine is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation, either
16  * version 3 of the License, or (at your option) any later version.
17  *
18  * Giada - Your Hardcore Loopmachine is distributed in the hope that it
19  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  * See the GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with Giada - Your Hardcore Loopmachine. If not, see
25  * <http://www.gnu.org/licenses/>.
26  *
27  * -------------------------------------------------------------------------- */
28 
29 
30 #include <FL/fl_draw.H>
31 #include "core/const.h"
32 #include "core/recManager.h"
33 #include "core/mixer.h"
34 #include "core/clock.h"
35 #include "utils/gui.h"
36 #include "beatMeter.h"
37 
38 
39 namespace giada {
40 namespace v
41 {
geBeatMeter(int x,int y,int w,int h)42 geBeatMeter::geBeatMeter(int x, int y, int w, int h)
43 : Fl_Box(x, y, w, h)
44 {
45 }
46 
47 
48 /* -------------------------------------------------------------------------- */
49 
50 
getCursorColor()51 Fl_Color geBeatMeter::getCursorColor()
52 {
53 	if (m::clock::getStatus() == ClockStatus::WAITING && u::gui::shouldBlink())
54 		return FL_BACKGROUND_COLOR;
55 	return G_COLOR_LIGHT_1;
56 }
57 
58 
59 /* -------------------------------------------------------------------------- */
60 
61 
refresh()62 void geBeatMeter::refresh()
63 {
64 	redraw();
65 }
66 
67 
68 /* -------------------------------------------------------------------------- */
69 
70 
draw()71 void geBeatMeter::draw()
72 {
73 	using namespace giada::m;
74 
75 	int cursorW = w() / G_MAX_BEATS;
76 	int greyX   = clock::getBeats() * cursorW;
77 
78 	/* Border and background. */
79 
80 	fl_rect(x(), y(), w(), h(), G_COLOR_GREY_4);
81 	fl_rectf(x()+1, y()+1, w()-2, h()-2, FL_BACKGROUND_COLOR);
82 
83 	/* Cursor. */
84 
85 	fl_rectf(x() + (clock::getCurrentBeat() * cursorW) + 3, y() + 3, cursorW - 5, h() - 6, getCursorColor());
86 
87 	/* Beat cells. */
88 
89 	fl_color(G_COLOR_GREY_4);
90 	for (int i=1; i<=clock::getBeats(); i++)
91 		fl_line(x()+cursorW*i, y()+1, x()+cursorW*i, y()+h()-2);
92 
93 	/* Bar line. */
94 
95 	fl_color(G_COLOR_LIGHT_1);
96 	int delta = clock::getBeats() / clock::getBars();
97 	for (int i=1; i<clock::getBars(); i++)
98 		fl_line(x()+cursorW*(i*delta), y()+1, x()+cursorW*(i*delta), y()+h()-2);
99 
100 	/* Unused grey area. */
101 
102 	fl_rectf(x()+greyX+1, y()+1, w()-greyX-1,  h()-2, G_COLOR_GREY_4);
103 }
104 }} // giada::v::
105