-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAXEScrubberClockWidget.cpp
More file actions
89 lines (59 loc) · 2.09 KB
/
AXEScrubberClockWidget.cpp
File metadata and controls
89 lines (59 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui.h"
#include "AXETypes.hpp"
#include <cstdint>
#include <string>
namespace Shadow::AXE {
enum ScrubberClockWidgetStyle_ {
ScrubberClockWidgetStyle_PCMFrames,
ScrubberClockWidgetStyle_BPM
};
static ScrubberClockWidgetStyle_ style = ScrubberClockWidgetStyle_PCMFrames;
void drawScrubberClockWidget(Song& song, EditorState& edState, uint64_t playbackFrames) {
using namespace ImGui;
PushFont(edState.segmentDisplayFont);
std::string displayText;
if (style == ScrubberClockWidgetStyle_PCMFrames) {
displayText = std::to_string(playbackFrames * 100);
} else if (style == ScrubberClockWidgetStyle_BPM) {
// 1 PCM frame is 1 sample per channel.
// AXE Audio is 2 samples per channel. So 1 PCM frame has 2 samples.
// There's typically 48000 PCM frames per second. (96000 samples / second)
auto framePerSecond = edState.sampleRate / 2;
// BPM = Beats per minute
float bpm = song.bpm;
// BPS = Beats per second
float bps = bpm / 60;
auto samplesPerBeat = framePerSecond / bps;
TextUnformatted(std::string(std::to_string(samplesPerBeat)).c_str());
SameLine();
auto beatsPassed = (playbackFrames * 100) / samplesPerBeat;
displayText = std::to_string(beatsPassed);
}
auto textSize = CalcTextSize(displayText.c_str());
// auto dl = GetWindowDrawList();
// auto cursor = GetCursorScreenPos();
// dl->AddRectFilled(cursor, cursor + textSize, IM_COL32(34, 34, 34, 255));
if (InvisibleButton("##ClockWidget", textSize))
OpenPopup("ScrubberClockWidgetStylePopup");
SameLine();
TextUnformatted(displayText.c_str());
if (style == ScrubberClockWidgetStyle_BPM) {
SameLine();
Text(" at %f BPM", song.bpm);
} else if (style == ScrubberClockWidgetStyle_PCMFrames) {
SameLine();
TextUnformatted(" PCM");
}
PopFont();
if (BeginPopup("ScrubberClockWidgetStylePopup")) {
if (RadioButton("PCM Frames",
style == ScrubberClockWidgetStyle_PCMFrames))
style = ScrubberClockWidgetStyle_PCMFrames;
if (RadioButton("BPM",
style == ScrubberClockWidgetStyle_BPM))
style = ScrubberClockWidgetStyle_BPM;
EndPopup();
}
}
}