forked from ITotalJustice/sys-tune
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui_main.cpp
150 lines (127 loc) · 4.77 KB
/
gui_main.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "gui_main.hpp"
#include "elm_overlayframe.hpp"
#include "elm_volume.hpp"
#include "gui_browser.hpp"
#include "gui_playlist.hpp"
#include "pm/pm.hpp"
#include "config/config.hpp"
namespace {
constexpr const size_t num_steps = 66;
}
MainGui::MainGui() {
m_status_bar = new StatusBar();
}
tsl::elm::Element *MainGui::createUI() {
auto frame = new SysTuneOverlayFrame();
auto list = new tsl::elm::List();
u64 pid{}, tid{};
pm::getCurrentPidTid(&pid, &tid);
/* Current track. */
list->addItem(this->m_status_bar, tsl::style::ListItemDefaultHeight * 2);
/* Playlist. */
auto queue_button = new tsl::elm::ListItem("Playlist");
queue_button->setClickListener([](u64 keys) {
if (keys & HidNpadButton_A) {
tsl::changeTo<PlaylistGui>();
return true;
}
return false;
});
list->addItem(queue_button);
/* Browser. */
auto browser_button = new tsl::elm::ListItem("Music browser");
browser_button->setClickListener([](u64 keys) {
if (keys & HidNpadButton_A) {
tsl::changeTo<BrowserGui>();
return true;
}
return false;
});
list->addItem(browser_button);
/* Volume indicator */
list->addItem(new tsl::elm::CategoryHeader("Volume Control"));
/* Get initial volume. */
double tune_volume = 1.f;
double title_volume = 1.f;
double default_title_volume = 1.f;
double tune_bass = 1.f;
tuneGetVolume(&tune_volume);
tuneGetTitleVolume(&title_volume);
tuneGetDefaultTitleVolume(&default_title_volume);
tuneGetBass(&tune_bass);
auto tune_volume_slider = new ElmVolume("\uE13C", "Tune Volume", num_steps);
tune_volume_slider->setProgress(tune_volume * num_steps);
tune_volume_slider->setValueChangedListener([](u8 value){
const double volume = double(value) / double(num_steps);
tuneSetVolume(volume*6);
});
list->addItem(tune_volume_slider);
// empty pid means we are qlaunch :)
if (tid && pid) {
auto title_volume_slider = new ElmVolume("\uE13C", "Game Volume", num_steps);
title_volume_slider->setProgress(title_volume * num_steps);
title_volume_slider->setValueChangedListener([tid](u8 value){
const double volume = double(value) / double(num_steps);
tuneSetTitleVolume(volume*6);
config::set_title_volume(tid, volume*6);
});
list->addItem(title_volume_slider);
}
auto default_title_volume_slider = new ElmVolume("\uE13C", "Game Volume (default)", num_steps);
default_title_volume_slider->setProgress(default_title_volume * num_steps);
default_title_volume_slider->setValueChangedListener([](u8 value){
const double volume = double(value) / double(num_steps);
tuneSetDefaultTitleVolume(volume*6);
});
list->addItem(default_title_volume_slider);
auto tune_bass_slider = new ElmVolume("\uE13C", "Bass Boost", num_steps);
tune_bass_slider->setProgress(tune_bass * num_steps);
tune_bass_slider->setValueChangedListener([](u8 value){
const double bass = double(value) / double(num_steps);
tuneSetBass(bass / 2);
});
list->addItem(tune_bass_slider);
list->addItem(new tsl::elm::CategoryHeader("Play / Pause"));
/* Per title tune toggle. */
auto tune_play = new tsl::elm::ToggleListItem("Tune", config::get_title_enabled(tid), "Play", "Pause");
tune_play->setStateChangedListener([tid](bool new_value) {
config::set_title_enabled(tid, new_value);
if (new_value) {
tunePlay();
} else {
tunePause();
}
});
list->addItem(tune_play);
/* Default title tune toggle. */
auto tune_default_play = new tsl::elm::ToggleListItem("Tune (default)", config::get_title_enabled_default(), "Play", "Pause");
tune_default_play->setStateChangedListener([](bool new_value) {
config::set_title_enabled_default(new_value);
if (new_value) {
tunePlay();
} else {
tunePause();
}
});
list->addItem(tune_default_play);
list->addItem(new tsl::elm::CategoryHeader("Misc"));
auto exit_button = new tsl::elm::ListItem("Close sys-tune");
exit_button->setClickListener([](u64 keys) {
if (keys & HidNpadButton_A) {
tuneQuit();
tsl::goBack();
return true;
}
return false;
});
list->addItem(exit_button);
frame->setContent(list);
return frame;
}
void MainGui::update() {
static u8 tick = 0;
/* Update status 4 times per second. */
if ((tick % 15) == 0)
this->m_status_bar->update();
tick++;
}