-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
114 lines (101 loc) · 3.5 KB
/
Copy pathmain.cpp
File metadata and controls
114 lines (101 loc) · 3.5 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
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
#include <iostream>
#include <thread>
#include <chrono>
#include <conio.h> //eventos de teclado
#include <filesystem>
#include <Handler/FileManager.h>
#include <Handler/Directive.h>
#include <Handler/Config.h>
#include <Handler/Terminal.h>
#include <Handler/Player.h>
void terminalEvent(Terminal& terminal, Player& player, int ch) {
switch (ch) {
case 72: // Flecha hacia arriba
terminal.backwardsCursor();
break;
case 80: // Flecha hacia abajo
terminal.forwardCursor();
break;
case 77: // Flecha hacia dercha
player.jump();
break;
case 75: // Flecha hacia atras
player.back();
break;
case 'q': // Carácter 'q' para salir del bucle
player.stop_current();
terminal.stop();
break;
case 'n': //next in playlist
player.next();
break;
case 's': // play or resume music
player.play_current();
break;
case 'p': // Pause music
player.pause_current();
break;
case '\r': // Enter key, Select music
player.load(terminal.getLine(terminal.getCursorPos()));
break;
case 'a': // Enqueue music;
player.add_to_playlist(terminal.getLine(terminal.getCursorPos()));
break;
case 'f': // Enqueue back music;
player.add_front_playlist(terminal.getLine(terminal.getCursorPos()));
break;
default:
break;
}
}
std::string getFilename(std::string path) {
std::filesystem::path filePath(path);
return " " + filePath.filename().string();
}
void updateMusicInfo(Terminal& terminal, Player& player ,int namePos, int barPos, int playlistPos) {
while (terminal.isRunning()) {
terminal.setLine(namePos, player.getCurrentMusic());
terminal.setLine(barPos, player.getProgressBar());
terminal.cut(playlistPos);
player.getPlayList().print(terminal.getBuffer(),&getFilename);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
}
int main(int argc, char** argv) {
//capturas de directivas
Directive d(argc,argv);
d.init();
if (!Config::ready_to_start)
return EXIT_SUCCESS;
FileManager fm(Config::album_path);
fm.typeFile(".ogg");
fm.typeFile(".wav");
fm.typeFile(".flac");
fm.startSearch();
Terminal terminal;
terminal.addLine("\tExplorador de Archivos");
//Tree is the one to select
terminal.minRangePos();
fm.getTree().print(terminal.getBuffer());
terminal.maxRangePos();
// Not reachable
terminal.addLine("___________________________________________________________");
terminal.addLine("\tEn Reproduccion:");
Player player(fm.getTree());
int namePos = terminal.getSize();
int barPos = namePos + 1;
terminal.addLine(player.getCurrentMusic());
terminal.addLine(player.getProgressBar());
terminal.addLine("___________________________________________________________");
terminal.addLine("\tPlay List:");
int playlistPos = terminal.getSize();
terminal.start();
std::thread updateThread(updateMusicInfo, std::ref(terminal), std::ref(player), namePos, barPos, playlistPos);
while (terminal.isRunning()) {
terminalEvent(terminal, player, getch());
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
if (updateThread.joinable())
updateThread.join();
return EXIT_SUCCESS;
}