Skip to content

Adds ability to dynamically adjust seconds-per-day. #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/gource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,12 @@ void Gource::logic(float t, float dt) {
idle_time = 0.0;
}

if(gGourceSettings.transitions.size() > 0 && commit.timestamp > gGourceSettings.transitions.front()) {
Copy link
Owner

@acaudwell acaudwell Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Gource can be used interactively and you could seek the timeline back to before the transition, this should really iterate over the transitions to find the relevant transition rather than modify the setting.

gGourceSettings.days_per_second = gGourceSettings.days_per_second_list.front();
gGourceSettings.days_per_second_list.pop_front();
gGourceSettings.transitions.pop_front();
}

if(commit.timestamp > currtime) break;

processCommit(commit, t);
Expand Down
56 changes: 49 additions & 7 deletions src/gource_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void GourceSettings::help(bool extended_help) {
printf(" for a number of seconds (default: 3)\n");
printf(" --disable-auto-skip Disable auto skip\n");
printf(" -s, --seconds-per-day SECONDS Speed in seconds per day (default: 10)\n");
printf(" --transition TIMESTAMP Timestamp for transitions\n");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps Timestamp for seconds per day transition

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will also need a bit of README / man page documentation for how to use this feature.

printf(" --realtime Realtime playback speed\n");
printf(" --no-time-travel Use the time of the last commit if the\n");
printf(" time of a commit is in the past\n");
Expand Down Expand Up @@ -288,7 +289,7 @@ GourceSettings::GourceSettings() {
arg_types["bloom-intensity"] = "float";
arg_types["bloom-multiplier"] = "float";
arg_types["elasticity"] = "float";
arg_types["seconds-per-day"] = "float";
arg_types["seconds-per-day"] = "multi-value";
arg_types["auto-skip-seconds"] = "float";
arg_types["stop-at-time"] = "float";
arg_types["max-user-speed"] = "float";
Expand All @@ -312,6 +313,7 @@ GourceSettings::GourceSettings() {
arg_types["file-show-filter"] = "multi-value";
arg_types["follow-user"] = "multi-value";
arg_types["highlight-user"] = "multi-value";
arg_types["transition"] = "multi-value";

arg_types["log-level"] = "string";
arg_types["background-image"] = "string";
Expand Down Expand Up @@ -1179,16 +1181,56 @@ void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gourc

if((entry = gource_settings->getEntry("seconds-per-day")) != 0) {

if(!entry->hasValue()) conffile.entryException(entry, "specify seconds-per-day (seconds)");
ConfEntryList* seconds_list = gource_settings->getEntries("seconds-per-day");

float seconds_per_day = entry->getFloat();
for(ConfEntryList::iterator it = seconds_list->begin(); it != seconds_list->end(); it++) {

if(seconds_per_day<=0.0f) {
conffile.invalidValueException(entry);
entry = *it;

if(!entry->hasValue()) conffile.entryException(entry, "specify seconds-per-day (seconds)");

float seconds_per_day = entry->getFloat();
if(seconds_per_day<=0.0f) {
conffile.invalidValueException(entry);
}

// convert seconds-per-day to days-per-second
days_per_second_list.push_back(1.0 / seconds_per_day);
}

// initialize with first value
days_per_second = days_per_second_list.front();
days_per_second_list.pop_front();
}

if((entry = gource_settings->getEntry("transition")) != 0) {

ConfEntryList* timestamps = gource_settings->getEntries("transition");

for(ConfEntryList::iterator it = timestamps->begin(); it != timestamps->end(); it++) {

entry = *it;

if(!entry->hasValue()) conffile.entryException(entry, "specify transition timestamp (YYYY-MM-DD hh:mm:ss)");

std::string timestamp_string = entry->getString();

time_t transition;

if (parseDateTime(timestamp_string, transition)) {
transitions.push_back(transition);
} else {
conffile.invalidValueException(entry);
}
}

// convert seconds-per-day to days-per-second
days_per_second = 1.0 / seconds_per_day;
// Make sure that seconds-per-day is specified and that there are
// exactly 1 more seconds-per-day specified than transitions.
if(gource_settings->getEntry("seconds-per-day") == 0 || (
gource_settings->getEntries("seconds-per-day")->size() !=
timestamps->size() + 1)) {
conffile.entryException(entry, "transition requires exactly 1 more seconds-per-day specified");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe seconds-per-day should be specified 1 more times than transition would be easier to understand.

}
}

if((entry = gource_settings->getEntry("auto-skip-seconds")) != 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/gource_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "core/settings.h"
#include "core/regex.h"

#include <deque>

class GourceSettings : public SDLAppSettings {
protected:
void commandLineOption(const std::string& name, const std::string& value);
Expand Down Expand Up @@ -145,6 +147,8 @@ class GourceSettings : public SDLAppSettings {
std::vector<Regex*> file_show_filters;
std::vector<Regex*> user_filters;
std::vector<Regex*> user_show_filters;
std::deque<float> days_per_second_list;
std::deque<time_t> transitions;
bool file_extensions;
bool file_extension_fallback;

Expand Down
2 changes: 0 additions & 2 deletions src/gource_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ Gource* GourceShell::getNext() {
return 0;
}

gGourceSettings.importGourceSettings(*conf, *gource_settings);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gource supports config file having mutiple [gource] sections, so you can have multiple configurations in one file and it will cycle to the next one when the current one concludes. So it still needs to handle that, we'll just need to come up with another way to avoid it creating duplicate multi value entries.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overwriting behaviour is kind of nice as it allows for instance having a config file, but also having command line parameters in addition to the config file settings. Appending to existing multi value lists probably isnt useful though.

Copy link
Owner

@acaudwell acaudwell Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could avoid dealing with this issue if you use comma separators (e.g. like the --hide option) rather than multi value fields, which would also be easier to specify. e.g. --seconds-per-day 1,2,3 --transition 2020-01-01,2020-01-02


//recording a video kind of implies you want this, unless:
// -- dont stop requested
// -- loop requested
Expand Down