-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwasabi.cpp
78 lines (60 loc) · 1.81 KB
/
wasabi.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
#include "player.hpp"
#include <iostream>
void parse_args(int argc, char* argv[], std::string* file_path, int* rendering_endpoint_buffer_duration) {
// Checks if all parameters are provided, if not, initializes all required but non defined parameters with their default values
int file_pos = -1;
int rendering_endpoint_buffer_duration_pos = -1;
for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "--file") == TRUE) {
if ((i + 1) < (argc - 1)) {
file_pos = i + 1;
}
}
else if (strcmp(argv[i], "--rendering_endpoint_buffer_duration") == TRUE) {
if ((i + 1) < (argc - 1)) {
rendering_endpoint_buffer_duration_pos = i + 1;
}
}
}
if (file_pos != -1) {
*file_path = argv[file_pos];
}
else {
std::string input_file_path;
std::cout << "Input file: ";
std::getline(std::cin, input_file_path);
*file_path = input_file_path;
}
if (rendering_endpoint_buffer_duration_pos != -1) {
*rendering_endpoint_buffer_duration = strtol(argv[rendering_endpoint_buffer_duration_pos], nullptr, 10);
}
else {
*rendering_endpoint_buffer_duration = 1;
}
}
void block_std_input() {
// Block standard input to be shown in the console
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
if (GetConsoleMode(h, &mode)) {
mode &= ~ENABLE_ECHO_INPUT;
SetConsoleMode(h, mode);
}
}
void hide_console_cursor() {
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);
}
int main(int argc, char* argv[]) {
std::string file;
int rendering_endpoint_buffer_duration;
parse_args(argc, argv, &file, &rendering_endpoint_buffer_duration);
block_std_input();
hide_console_cursor();
Player player = Player();
player.play_audio_stream(file, rendering_endpoint_buffer_duration);
return 0;
}