Skip to content

Commit e37ba34

Browse files
authored
Add video name setting (CLI and Lua) (#109)
1 parent 4600c74 commit e37ba34

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

include/commandLine.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ struct CommandLine
315315
extractArgument(script, arguments);
316316
extractArgument(globalAtomAlpha, arguments);
317317
extractArgument(globalBondAlpha, arguments);
318+
extractArgument(videoName, arguments);
318319

319320
#ifdef WITH_FFMPEG
320321
extractArgument(cq, arguments);
@@ -345,6 +346,7 @@ struct CommandLine
345346
Argument<float> bondClipCorrection = {"bondClipCorrection", "Correction for bond impostors.", "Increase if atoms clipped.", 5.0f};
346347
Argument<std::filesystem::path> colourmap = {"colourmap", "The colourmap path.", "", {}};
347348
Argument<std::filesystem::path> atomColours = {"atomColours", "Path for per-atom colour overrides.", "", {}};
349+
Argument<std::string> videoName = {"videoName", "Name of saved video.", "", ""};
348350
Argument<vec<2>> resolution = {"resolution", "Window resolution in pixels.", "", {512, 512}};
349351
Argument<uint64_t> bondFocus = {"bondFocus", "Only draw bonds for this atom.", "", NULL_INDEX};
350352
Argument<uint64_t> focus = {"focus", "Centre on a particular atom.", "", NULL_INDEX};
@@ -462,8 +464,10 @@ struct CommandLine
462464
std::string * sval = stringFromName(s.characters);
463465
if (sval != nullptr)
464466
{
467+
std::cout << "yes\n";
465468
if (lua_isstring(lua, 2))
466469
{
470+
std::cout << "yes2\n";
467471
LuaString v; v.read(lua, 2);
468472
*sval = v.characters;
469473
return 0;
@@ -619,6 +623,8 @@ struct CommandLine
619623
<< "\n"
620624
<< sidebyside(argumentHelp(levelOfDetail), argumentHelp(hideInfoText), 42)
621625
<< "\n"
626+
<< argumentHelp(videoName)
627+
<< "\n"
622628
#ifdef WITH_FFMPEG
623629
<< "\n FFMPEG recording options:\n\n"
624630
<< " See here for advice https://trac.ffmpeg.org/wiki/Encode/H.264\n\n"
@@ -1013,16 +1019,17 @@ END OF TERMS AND CONDITIONS)";
10131019
{
10141020
{preset.name, preset},
10151021
{codec.name, codec},
1016-
{profile.name, profile}
1022+
{profile.name, profile},
1023+
{videoName.name, videoName}
10171024
};
10181025
if (values.find(name) != values.cend())
10191026
{
10201027
return &values.at(name).value;
10211028
}
1022-
return nullptr;
10231029
#else
1024-
return nullptr;
1030+
if (name == videoName.name) { return &videoName.value; }
10251031
#endif
1032+
return nullptr;
10261033
}
10271034
};
10281035

include/visualisationState.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ struct VisualisationState
148148
{
149149
if (!recording)
150150
{
151-
std::string name = timeStamp()+std::string(".mp4");
151+
std::string name = options.videoName.value;
152+
if (name == "") { name = timeStamp()+std::string(".mp4"); }
152153
#ifdef WITH_FFMPEG
153154
record = std::make_unique<FFmpegRecord>
154155
(

tests/generate_lua_options_interop_tests.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,21 @@
5252
test = test.replace(k, v)
5353
tests += test+"\n"
5454

55+
for (option, default) in [("videoName", "\"\"")]:
56+
test = generate_test
57+
for (k, v) in [("meshes", option), ("DEFAULT", str(default)),
58+
("SET", "\\\"TEST\\\""), ("TYPE", "LuaString"),
59+
("MEMBER", "characters"),
60+
("CONDITION", "REQUIRE(\"TEST\" == console.getGlobal<LuaString>(\"v\").characters);")]:
61+
test = test.replace(k, v)
62+
tests += test+"\n"
63+
5564
tests += " #ifdef WITH_FFMPEG\n"
5665
for (option, default) in [("preset", "slow"), ("codec", "libx264"),
5766
("profile", "main")]:
5867
test = generate_test
5968
for (k, v) in [("meshes", option), ("DEFAULT", str(default)),
60-
("SET", "TEST"), ("TYPE", "LuaString"),
69+
("SET", "\\\"TEST\\\""), ("TYPE", "LuaString"),
6170
("MEMBER", "characters"),
6271
("CONDITION", "REQUIRE(\"TEST\" == console.getGlobal<LuaString>(\"v\").characters);")]:
6372
test = test.replace(k, v)

tests/test_console/test_console.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,23 @@ SCENARIO("Lua options interop")
759759
}
760760
}
761761

762+
WHEN("The script \"v = sfoav.getOption(\"videoName\");\"")
763+
{
764+
console.runString("v = sfoav.getOption(\"videoName\");");
765+
THEN("v is """)
766+
{
767+
REQUIRE(console.getGlobal<LuaString>("v").characters == "");
768+
}
769+
WHEN("The script \"sfoav.setOption(\"videoName\", \"TEST\"); v = sfoav.getOption(\"videoName\");\"")
770+
{
771+
console.runString("sfoav.setOption(\"videoName\", \"TEST\"); v = sfoav.getOption(\"videoName\");");
772+
THEN("v is \"TEST\"")
773+
{
774+
REQUIRE("TEST" == console.getGlobal<LuaString>("v").characters);
775+
}
776+
}
777+
}
778+
762779
#ifdef WITH_FFMPEG
763780
WHEN("The script \"v = sfoav.getOption(\"preset\");\"")
764781
{
@@ -767,10 +784,10 @@ SCENARIO("Lua options interop")
767784
{
768785
REQUIRE(console.getGlobal<LuaString>("v").characters == slow);
769786
}
770-
WHEN("The script \"sfoav.setOption(\"preset\", TEST); v = sfoav.getOption(\"preset\");\"")
787+
WHEN("The script \"sfoav.setOption(\"preset\", \"TEST\"); v = sfoav.getOption(\"preset\");\"")
771788
{
772-
console.runString("sfoav.setOption(\"preset\", TEST); v = sfoav.getOption(\"preset\");");
773-
THEN("v is TEST")
789+
console.runString("sfoav.setOption(\"preset\", \"TEST\"); v = sfoav.getOption(\"preset\");");
790+
THEN("v is \"TEST\"")
774791
{
775792
REQUIRE("TEST" == console.getGlobal<LuaString>("v").characters);
776793
}
@@ -783,10 +800,10 @@ SCENARIO("Lua options interop")
783800
{
784801
REQUIRE(console.getGlobal<LuaString>("v").characters == libx264);
785802
}
786-
WHEN("The script \"sfoav.setOption(\"codec\", TEST); v = sfoav.getOption(\"codec\");\"")
803+
WHEN("The script \"sfoav.setOption(\"codec\", \"TEST\"); v = sfoav.getOption(\"codec\");\"")
787804
{
788-
console.runString("sfoav.setOption(\"codec\", TEST); v = sfoav.getOption(\"codec\");");
789-
THEN("v is TEST")
805+
console.runString("sfoav.setOption(\"codec\", \"TEST\"); v = sfoav.getOption(\"codec\");");
806+
THEN("v is \"TEST\"")
790807
{
791808
REQUIRE("TEST" == console.getGlobal<LuaString>("v").characters);
792809
}
@@ -799,10 +816,10 @@ SCENARIO("Lua options interop")
799816
{
800817
REQUIRE(console.getGlobal<LuaString>("v").characters == main);
801818
}
802-
WHEN("The script \"sfoav.setOption(\"profile\", TEST); v = sfoav.getOption(\"profile\");\"")
819+
WHEN("The script \"sfoav.setOption(\"profile\", \"TEST\"); v = sfoav.getOption(\"profile\");\"")
803820
{
804-
console.runString("sfoav.setOption(\"profile\", TEST); v = sfoav.getOption(\"profile\");");
805-
THEN("v is TEST")
821+
console.runString("sfoav.setOption(\"profile\", \"TEST\"); v = sfoav.getOption(\"profile\");");
822+
THEN("v is \"TEST\"")
806823
{
807824
REQUIRE("TEST" == console.getGlobal<LuaString>("v").characters);
808825
}

0 commit comments

Comments
 (0)