Skip to content

Commit

Permalink
Add loop definition selection
Browse files Browse the repository at this point in the history
Use "-d (name)" to pull the loop definition named "name".
Implements #2.
  • Loading branch information
codylico committed Mar 20, 2020
1 parent 5f84b30 commit 42e75ed
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ Input files use the following format:
song=/path/to/song.ogg
start=start_seconds
end=end_seconds

[alternate]
start=other_start_seconds
end=other_end_seconds
```
The `song` field corresponds to the file path to the audio file to loop.
The `start` and `end` fields map to the beginning and end loop points
for the audio, specified in seconds.

Alternate loop parameters for the same song can be specified using
separate sections (i.e. `[like this]`) for each collection of parameters.
Any parameters unspecified in the section are taken from the global
parameters at top. The example above provides a single `[alternate]`
section holding different `start` and `end` parameters, implicitly using
the same `song`.

## Build

This project uses the CMake build system, which one can obtain at
Expand Down Expand Up @@ -67,6 +78,9 @@ Optional arguments are:
+ `-a`: If the `loopsong` program is stopped or put to sleep,
setting this option will allow `loopsong` to reclaim most of
the time it missed.
+ `-d (section_name)`: Pull parameters from the `[section_name]` section
in addition to the global parameters. The section-specific parameters
have the final say.

Other arguments configure how `loopsong` adjusts the playback time.
+ `-m`: The default mode, _middle_, cuts the song off exactly after
Expand Down
28 changes: 27 additions & 1 deletion loopsong.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ int main(int argc, char**argv){
double end = 5.0;
double seek_point = 0.0;
char const* song_file;
char const* loop_def_name = NULL;

/*
* short-play switch:
Expand Down Expand Up @@ -170,6 +171,10 @@ int main(int argc, char**argv){
shortplay_switch = 0;
} else if (strcmp(argv[argi],"-l") == 0){
shortplay_switch = +1;
} else if (strcmp(argv[argi],"-d") == 0){
if (++argi < argc){
loop_def_name = argv[argi];
}
} else {
fprintf(stderr, "unrecognized option %s\n", argv[argi]);
help_tf = 1;
Expand Down Expand Up @@ -201,7 +206,10 @@ int main(int argc, char**argv){
" -l\n"
" take extra time to finish out the song\n"
" -a\n"
" adjust for when the player sleeps too long\n",
" adjust for when the player sleeps too long\n"
" -d (name)\n"
" pull additional loop definition parameters\n"
" from section [name]\n",
stderr);
return EXIT_FAILURE;
}
Expand All @@ -219,6 +227,24 @@ int main(int argc, char**argv){
end = local_atof_seconds(
al_get_config_value(cfg, NULL, "end")
);
if (loop_def_name != NULL && loop_def_name[0] != '\0') {
char const* const subsong_file =
al_get_config_value(cfg, loop_def_name, "song");
char const* const substart =
al_get_config_value(cfg, loop_def_name, "start");
char const* const subend =
al_get_config_value(cfg, loop_def_name, "end");
if (subsong_file != NULL) {
free((char*)song_file);
song_file = local_strdup(subsong_file);
}
if (substart != NULL) {
start = local_atof_seconds(substart);
}
if (subend != NULL) {
end = local_atof_seconds(subend);
}
}
al_destroy_config(cfg);
} else {
result = EXIT_FAILURE;
Expand Down

0 comments on commit 42e75ed

Please sign in to comment.