105 lines
1.9 KiB
C++
105 lines
1.9 KiB
C++
|
|
#include "song_info.hpp"
|
|
#include "packet.hpp"
|
|
#include "util.hpp"
|
|
#include <cmath>
|
|
#include <ncurses.h>
|
|
|
|
struct ScreenGuard {
|
|
ScreenGuard() {
|
|
initscr();
|
|
keypad(stdscr, true);
|
|
nonl();
|
|
cbreak();
|
|
noecho();
|
|
}
|
|
|
|
~ScreenGuard() {
|
|
endwin();
|
|
}
|
|
};
|
|
|
|
void song_info::collect(Info& info) {
|
|
ScreenGuard guard;
|
|
bool running = true;
|
|
int x = 0;
|
|
int y = 0;
|
|
|
|
while(running) {
|
|
|
|
// render info screen
|
|
clear();
|
|
mvaddstr(1, 0, "Configuring ");
|
|
addstr(info.path.c_str());
|
|
|
|
mvaddstr(3, 0, "Volume");
|
|
mvaddstr(3, 32, util::sprintf("[ %d / 256 ]", info.volume).c_str());
|
|
|
|
mvaddstr(6, 0, "Track Name");
|
|
mvaddstr(6, 32, "Enable");
|
|
mvaddstr(6, 48, "Gain");
|
|
mvaddstr(6, 64, "Instrument");
|
|
|
|
for(unsigned i = 0; i < info.tracks.size(); i++) {
|
|
Track& t = info.tracks[i];
|
|
mvaddstr(8+i, 0, t.name.c_str());
|
|
mvaddstr(8+i, 32, util::sprintf("[ %s ]", t.enabled ? "*" : " ").c_str());
|
|
if(t.enabled) {
|
|
mvaddstr(8+i, 48, util::sprintf("[ %d% ]", (t.gain + 1) * 100).c_str());
|
|
mvaddstr(8+i, 64, util::sprintf("[ %s ]", packet::tone_type_get_str(t.type)).c_str());
|
|
}
|
|
}
|
|
|
|
if(y == 0) {
|
|
move(3, 32);
|
|
} else {
|
|
move(8+y-1, 34+x*16);
|
|
}
|
|
|
|
int c = getch();
|
|
int dir = 1;
|
|
|
|
switch(c) {
|
|
case KEY_UP:
|
|
y = std::max(0, y - 1);
|
|
break;
|
|
case KEY_DOWN:
|
|
y = std::min((int)info.tracks.size(), y + 1);
|
|
break;
|
|
case KEY_LEFT:
|
|
x = ((x - 1) % 3 + 3) % 3;
|
|
break;
|
|
case KEY_RIGHT:
|
|
x = (x + 1) % 3;
|
|
break;
|
|
case 27:
|
|
running = false;
|
|
break;
|
|
case 'z': case 'Z':
|
|
dir = -1;
|
|
case 'x': case 'X': case 13: case ' ': case KEY_ENTER: {
|
|
if(y == 0) {
|
|
info.volume += dir;
|
|
info.volume &= 255;
|
|
break;
|
|
}
|
|
Track& t = info.tracks[y - 1];
|
|
switch(x) {
|
|
case 0:
|
|
t.enabled ^= 1;
|
|
break;
|
|
case 1:
|
|
t.gain += dir;
|
|
t.gain &= 3;
|
|
break;
|
|
case 2:
|
|
t.type = (packet::ToneType)((t.type + dir) & 3);
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|