-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
176 lines (163 loc) · 5.54 KB
/
main.cpp
File metadata and controls
176 lines (163 loc) · 5.54 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <iostream>
#include "ScreenRecorder.h"
#include <thread>
#include <csignal>
#include <vector>
enum Command{
stop,
start,
pause,
resume,
audio,
out,
dim,
offset,
help
};
std::vector<std::string> commands{ "stop", "start", "pause", "resume", "audio", "out", "dim", "offset", "help" };
ScreenRecorder screenRecorder;
bool justPause = false;
void stopSignalHandler(int signum){
std::cout << "\nInterrupt signal (" << signum << ") received.\n";
if(screenRecorder.getStarted()){
if (!screenRecorder.getActiveMenu()) {
screenRecorder.setActiveMenu(true);
while (!screenRecorder.getDisabledMenu()) ;
justPause = true;
std::cout << "Insert command: " << std::flush;
}
else {
justPause = false;
screenRecorder.setActiveMenu(false);
}
}
else{
std::cout << "\nInsert command: " << std::flush;
}
}
Command stringToInt(std::string cmd){
int len = commands.size();
for (int i = 0; i < len; i++)
if (cmd == commands[i])
return static_cast<Command>(i);
return static_cast<Command>(-1);
}
void showCommands(){
std::cout << "Commands: " << std::endl;
std::cout << "start --> begin registration" << std::endl;
std::cout << "audio --> enable audio registration" << std::endl;
std::cout << "pause --> pause registration" << std::endl;
std::cout << "resume --> resume registration after pause" << std::endl;
std::cout << "stop --> stop registration and/or exit" << std::endl;
std::cout << "dim --> set screen section to record" << std::endl;
std::cout << "offset --> set top left point of screen section to record" << std::endl;
std::cout << "out --> set output direcotry (relative or absolute path)" << std::endl;
std::cout << "help --> show all commands" << std::endl;
std::cout << "ctrl + c --> show menu while recording" << std::endl;
}
int main(){
std::string cmd, dir;
int w, h, x_off, y_off;
bool endWhile = false;
//bool started = false;
bool inPause = false;
showCommands();
while (!endWhile) {
signal(SIGINT, stopSignalHandler);
if (!justPause && screenRecorder.getActiveMenu())
std::cout << "\nInsert command: ";
std::cin >> cmd;
Command c = stringToInt(cmd);
std::cin.clear();
switch (c) {
case stop:
if (screenRecorder.getStarted()){
screenRecorder.stopCommand();
}
endWhile = true;
break;
case start:
if (!screenRecorder.getStarted()) {
screenRecorder.setActiveMenu(false);
//started = true;
//screenRecorder.setStarted(started);
try{
screenRecorder.startRecording();
}
catch (std::exception e){
std::cout << e.what() << std::endl;
exit(-1);
}
}
else{
std::cout << "Already started." << std::endl;
}
break;
case pause:
justPause = false;
if (screenRecorder.getStarted()){
screenRecorder.pauseCommand();
inPause = true;
while (!screenRecorder.getDisabledMenu());
std::cout << "Pause recording" << std::endl;
}
else{
std::cout << "Not yet started!" << std::endl;
}
break;
case resume:
if (inPause){
std::cout << "Resume recording" << std::endl;
screenRecorder.setActiveMenu(false);
inPause = false;
screenRecorder.resumeCommand();
}
else {
std::cout << "Not in pause!" << std::endl;
}
break;
case audio:
if (!screenRecorder.getStarted()) {
std::cout << "Audio enabled" << std::endl;
screenRecorder.setRecordAudio(true);
}
else std::cout << "Command disabled during recording" << std::endl;
break;
case help:
showCommands();
break;
case out:
if (!screenRecorder.getStarted()) {
std::cout << "Insert path of output directory: ";
std::cin >> dir;
screenRecorder.setOutputDir(const_cast<char*>(dir.c_str()));
}
else std::cout << "Command disabled during recording" << std::endl;
break;
case dim:
if (!screenRecorder.getStarted()) {
std::cout << "Insert dimension of screen to record [width heigth]: ";
std::cin >> w >> h;
screenRecorder.setScreenDimension(w, h);
std::cin.clear();
}
else std::cout << "Command disabled during recording" << std::endl;
break;
case offset:
if (!screenRecorder.getStarted()) {
std::cout << "Insert dimension of offset screen to record [x_offset y_offset]: ";
std::cin >> x_off >> y_off;
screenRecorder.setScreenOffset(x_off, y_off);
std::cin.clear();
}
else std::cout << "Command disabled during recording" << std::endl;
break;
default:
std::cout << "Command: "
<< "\"" << cmd << "\""
<< " does not exist" << std::endl;
break;
}
}
return 0;
}