Compare commits

..

No commits in common. "b700113b8820e53e0b7b18b31e3e6a098d56181f" and "d09b991771f7cc796fdff7ad03915ffec61b72ce" have entirely different histories.

View File

@ -12,6 +12,7 @@
#define NS_PER_S 1000000000 #define NS_PER_S 1000000000
struct timespec finish, delta; struct timespec finish, delta;
int pausedTime = 0;
bool timerActive = false; bool timerActive = false;
bool paused = false; bool paused = false;
bool alive = true; bool alive = true;
@ -76,9 +77,10 @@ void sendInt(int sock, int value);
void sendValue(int sock, char* name); void sendValue(int sock, char* name);
void sendString(int sock, char* str); void sendString(int sock, char* str);
void process_socket_input(int sock); void process_socket_input(int sock);
void addPauseTime();
void subtractPauseTime();
void set_metadata(char *key, char *value); void set_metadata(char *key, char *value);
void save_metadata_to_file(char *token, char *token2); void save_metadata_to_file(char *token, char *token2);
void reset_timer();
int current_ms(); int current_ms();
//basic timer commands //basic timer commands
@ -90,11 +92,9 @@ void undo();
void redo(); void redo();
void pause_timer(); void pause_timer();
void resume(); void resume();
void reset();
//convenient combination commands //convenient combination commands
void start_split_stop(); void start_split_stop();
void start_reset();
void start_split(); void start_split();
void split_stop(); void split_stop();
void start_stop(); void start_stop();
@ -157,6 +157,7 @@ void add_event(enum event_type t)
void reset_timer() void reset_timer()
{ {
pausedTime = 0;
runMarker = 0; runMarker = 0;
runMarker2 = 0; runMarker2 = 0;
} }
@ -184,16 +185,6 @@ void stop()
runUnsaved = true; runUnsaved = true;
} }
//Identical function to stop() but with a RESET event
void reset()
{
if (!timerActive) return;
timerActive = false;
add_event(RESET);
finish = run[runMarker - 1].time;
runUnsaved = true;
}
void start_split_stop() void start_split_stop()
{ {
if (!timerActive) { if (!timerActive) {
@ -225,12 +216,6 @@ void start_stop()
else stop(); else stop();
} }
void start_reset()
{
if (!timerActive) start();
else reset();
}
void split() void split()
{ {
if (!timerActive) return; if (!timerActive) return;
@ -243,6 +228,32 @@ void skip()
add_event(SKIP); add_event(SKIP);
} }
void addPauseTime()
{
int pauseEvent = 0;
for (int i = runMarker - 2; i >= 1; i--) {
if (run[i].type == PAUSE) {
pauseEvent = i;
break;
}
}
sub_timespec(run[pauseEvent].time, run[runMarker - 1].time, &delta);
pausedTime += timespecToMS(delta);
}
void subtractPauseTime()
{
int pauseEvent = 0;
for (int i = runMarker - 1; i >= i; i--) {
if (run[i].type == PAUSE) {
pauseEvent = i;
break;
}
}
sub_timespec(run[pauseEvent].time, run[runMarker].time, &delta);
pausedTime -= timespecToMS(delta);
}
void undo() void undo()
{ {
if (runMarker > 0) { if (runMarker > 0) {
@ -257,6 +268,7 @@ void undo()
paused = false; paused = false;
if (run[runMarker].type == RESUME) { if (run[runMarker].type == RESUME) {
paused = true; paused = true;
subtractPauseTime();
} }
hasUndoneAtLeastOnce = true; hasUndoneAtLeastOnce = true;
} }
@ -278,6 +290,7 @@ void redo()
paused = true; paused = true;
if (run[runMarker - 1].type == RESUME) { if (run[runMarker - 1].type == RESUME) {
paused = false; paused = false;
addPauseTime();
} }
} }
if (runMarker == runMarker2) { if (runMarker == runMarker2) {
@ -307,6 +320,7 @@ void resume()
if (paused) { if (paused) {
add_event(RESUME); add_event(RESUME);
paused = false; paused = false;
addPauseTime();
} }
} }
@ -474,12 +488,12 @@ int current_ms()
{ {
if (timerActive) if (timerActive)
clock_gettime(CLOCK_REALTIME, &finish); clock_gettime(CLOCK_REALTIME, &finish);
//if (paused) { if (paused) {
// sub_timespec(run[0].time, run[runMarker - 1].time, &delta); sub_timespec(run[0].time, run[runMarker - 1].time, &delta);
//} else { } else {
sub_timespec(run[0].time, finish, &delta); sub_timespec(run[0].time, finish, &delta);
//} }
return timespecToMS(delta); return timespecToMS(delta) - pausedTime;
} }
void sendInt(int sock, int value) void sendInt(int sock, int value)
@ -586,8 +600,6 @@ void process_socket_input(int sock)
start(); start();
} else if (!strcmp(token, "stop")) { } else if (!strcmp(token, "stop")) {
stop(); stop();
} else if (!strcmp(token, "reset")) {
reset();
} else if (!strcmp(token, "kill")) { } else if (!strcmp(token, "kill")) {
alive = false; alive = false;
} else if (!strcmp(token, "split")) { } else if (!strcmp(token, "split")) {
@ -610,8 +622,6 @@ void process_socket_input(int sock)
pause_resume(); pause_resume();
} else if (!strcmp(token, "start-stop")) { } else if (!strcmp(token, "start-stop")) {
start_stop(); start_stop();
} else if (!strcmp(token, "start-reset")) {
start_reset();
} else if (!strcmp(token, "start-split")) { } else if (!strcmp(token, "start-split")) {
start_split(); start_split();
} else if (!strcmp(token, "split-stop")) { } else if (!strcmp(token, "split-stop")) {
@ -624,24 +634,6 @@ void process_socket_input(int sock)
token = strtok(NULL, " "); token = strtok(NULL, " ");
if (!strcmp(token, "current_time")) { if (!strcmp(token, "current_time")) {
sendInt(sock, current_ms()); sendInt(sock, current_ms());
} else if (!strcmp(token, "current_time_with_pause")) {
int running_pause = 0;
struct timespec p, r;
bool tracking_pause = false;
for (int i = 0; i < runMarker; i++) {
if (run[i].type == PAUSE) {
sub_timespec(run[0].time, run[i].time, &p);
tracking_pause = true;
}
if (run[i].type == RESUME) {
sub_timespec(run[0].time, run[i].time, &r);
running_pause += timespecToMS(r) - timespecToMS(p);
tracking_pause = false;
} else if (i == runMarker - 1 && tracking_pause) {
running_pause += current_ms() - timespecToMS(p);
}
}
sendInt(sock, current_ms() - running_pause);
} else if (!strcmp(token, "run_count")) { } else if (!strcmp(token, "run_count")) {
sendInt(sock, run_count); sendInt(sock, run_count);
} else if (!strcmp(token, "segment_count")) { } else if (!strcmp(token, "segment_count")) {
@ -688,35 +680,6 @@ void process_socket_input(int sock)
struct timespec t; struct timespec t;
sub_timespec(run[0].time, run[x].time, &t); sub_timespec(run[0].time, run[x].time, &t);
sendInt(sock, timespecToMS(t)); sendInt(sock, timespecToMS(t));
} else if (!strcmp(token, "event_time_with_pause")) {
token = strtok(NULL, " ");
int x;
if (!strcmp(token, "last"))
x = runMarker - 1;
else if (!strcmp(token, "first"))
x = 0;
else
x = atoi(token);
int running_pause = 0;
struct timespec p, r;
bool tracking_pause = false;
for (int i = 0; i < x; i++) {
if (run[i].type == PAUSE) {
sub_timespec(run[0].time, run[i].time, &p);
tracking_pause = true;
}
if (run[i].type == RESUME) {
sub_timespec(run[0].time, run[i].time, &r);
running_pause += timespecToMS(r) - timespecToMS(p);
tracking_pause = false;
} else if (i == x - 1 && tracking_pause) {
sub_timespec(run[0].time, run[x].time, &r);
running_pause += timespecToMS(r) - timespecToMS(p);
}
}
struct timespec t;
sub_timespec(run[0].time, run[x].time, &t);
sendInt(sock, timespecToMS(t) - running_pause);
} else if (!strcmp(token, "event_type")) { } else if (!strcmp(token, "event_type")) {
token = strtok(NULL, " "); token = strtok(NULL, " ");
int x; int x;