New Settings export and command-line load

Allows exporting settings in XML file and launch vimix from command line with given XML filename as argument to restore all settings and windows configuration.
This commit is contained in:
Bruno Herbelin
2024-02-24 20:05:19 +01:00
parent 7238eccfd2
commit b022be49a1
8 changed files with 75 additions and 12 deletions

View File

@@ -38,3 +38,17 @@ Mac OSX specificities
enter "/Users/[username]/Library/Application Support/vimix" and delete the folder 'vimix'
-
Testing performance
-------------------
Linux perf command
- Allow perf on your system
sudo sysctl -w kernel.perf_event_paranoid=-1
- Launch command to record
perf record ./vimix
perf record --pid=XXXXX
- Analyse using https://github.com/KDAB/hotspot

View File

@@ -37,6 +37,14 @@ and exit.
.BR \-F ", " \-\^\-fontsize N
Set interface font size to specified value N.
.TP
.BR \-S ", " \-\^\-settings settingsfile.xml
Run using the given settings file.
.TP
.BR \-L ", " \-\^\-headless
Run without graphical user interface (only if output windows are configured).
.TP
.BR \-C ", " \-\^\-clean
Clean the user stored preferences of

View File

@@ -69,7 +69,7 @@ XMLElement *save_knownhost(Settings::KnownHosts &h, const char *nodename, XMLDoc
void Settings::Save(uint64_t runtime)
void Settings::Save(uint64_t runtime, const std::string &filename)
{
// impose C locale for all app
setlocale(LC_ALL, "C");
@@ -332,7 +332,8 @@ void Settings::Save(uint64_t runtime)
if (settingsFilename.empty())
settingsFilename = SystemToolkit::full_filename(SystemToolkit::settings_path(), APP_SETTINGS);
XMLError eResult = xmlDoc.SaveFile(settingsFilename.c_str());
XMLError eResult = xmlDoc.SaveFile( filename.empty() ?
settingsFilename.c_str() : filename.c_str());
XMLResultError(eResult);
}
@@ -395,7 +396,7 @@ void load_knownhost(Settings::KnownHosts &h, const char *nodename, XMLElement *r
}
}
void Settings::Load()
void Settings::Load(const string &filename)
{
// impose C locale for all app
setlocale(LC_ALL, "C");
@@ -406,7 +407,8 @@ void Settings::Load()
// try to load settings file
XMLDocument xmlDoc;
XMLError eResult = xmlDoc.LoadFile(settingsFilename.c_str());
XMLError eResult = xmlDoc.LoadFile( filename.empty() ?
settingsFilename.c_str() : filename.c_str());
// do not warn if non existing file
if (eResult == XML_ERROR_FILE_NOT_FOUND)

View File

@@ -390,8 +390,8 @@ struct Application
extern Application application;
// Save and Load store settings in XML file
void Save(uint64_t runtime = 0);
void Load();
void Save(uint64_t runtime = 0, const std::string &filename = "");
void Load(const std::string &filename = "");
void Lock();
void Unlock();
void Check();

View File

@@ -222,6 +222,8 @@ bool UserInterface::Init(int font_size)
VIMIX_FILE_TYPE, VIMIX_FILE_PATTERN);
sessionimportdialog = new DialogToolkit::OpenFileDialog("Import Sources",
VIMIX_FILE_TYPE, VIMIX_FILE_PATTERN);
settingsexportdialog = new DialogToolkit::SaveFileDialog("Export settings",
SETTINGS_FILE_TYPE, SETTINGS_FILE_PATTERN);
// init tooltips
ImGuiToolkit::setToolTipsEnabled(Settings::application.show_tooptips);
@@ -880,6 +882,10 @@ void UserInterface::NewFrame()
if (sessionsavedialog && sessionsavedialog->closed() && !sessionsavedialog->path().empty())
Mixer::manager().saveas(sessionsavedialog->path(), Settings::application.save_version_snapshot);
if (settingsexportdialog && settingsexportdialog->closed()
&& !settingsexportdialog->path().empty())
Settings::Save(0, settingsexportdialog->path());
// overlay to ensure file dialog is modal
if (DialogToolkit::FileDialog::busy()){
if (!ImGui::IsPopupOpen("Busy"))
@@ -1187,7 +1193,7 @@ void UserInterface::showMenuFile()
ImGui::MenuItem( MENU_SAVE_ON_EXIT, nullptr, &Settings::application.recentSessions.save_on_exit);
// HELP AND QUIT
// QUIT
ImGui::Separator();
if (ImGui::MenuItem( MENU_QUIT, SHORTCUT_QUIT) && TryClose())
Rendering::manager().close();
@@ -5418,6 +5424,17 @@ void Navigator::RenderMainPannelSettings()
// Appearance
//
ImGui::Text("Settings");
ImGui::SameLine();
ImGui::SetCursorPosX( pannel_width_ IMGUI_RIGHT_ALIGN);
if ( ImGuiToolkit::IconButton(ICON_FA_SAVE,"Export settings\nYou can then "
"launch vimix with the option "
"'--settings filename.xml' "
"to restore output windows and configuration.") ){
// launch file dialog to select file to save settings
if (UserInterface::manager().settingsexportdialog)
UserInterface::manager().settingsexportdialog->open();
}
int v = Settings::application.accent_color;
ImGui::Spacing();
ImGui::SetCursorPosX(0.5f * width_);

View File

@@ -202,6 +202,7 @@ protected:
DialogToolkit::OpenFileDialog *sessionopendialog;
DialogToolkit::OpenFileDialog *sessionimportdialog;
DialogToolkit::SaveFileDialog *sessionsavedialog;
DialogToolkit::SaveFileDialog *settingsexportdialog;
// Favorites and playlists
Playlist favorites;

View File

@@ -42,6 +42,12 @@
{ \
"*.srt", "*.sub" \
}
#define SETTINGS_FILE_TYPE "vimix settings (XML)"
#define SETTINGS_FILE_EXT "xml"
#define SETTINGS_FILE_PATTERN \
{ \
"*.xml" \
}
#define MINI(a, b) (((a) < (b)) ? (a) : (b))
#define MAXI(a, b) (((a) > (b)) ? (a) : (b))
#define ABS(a) (((a) < 0) ? -(a) : (a))
@@ -173,6 +179,7 @@
#define MENU_SAVE_ON_EXIT ICON_FA_LEVEL_DOWN_ALT " Save on exit"
#define MENU_OPEN_ON_START ICON_FA_LEVEL_UP_ALT " Restore on start"
#define SHORTCUT_SAVEAS_FILE CTRL_MOD "Shift+S"
#define MENU_EXPORT_SETTINGS ICON_FA_FILE_EXCEL " Export settings"
#define MENU_QUIT ICON_FA_POWER_OFF " Quit"
#define SHORTCUT_QUIT CTRL_MOD "Q"
#define MENU_CUT ICON_FA_CUT " Cut"

View File

@@ -71,6 +71,7 @@ int main(int argc, char *argv[])
int headlessRequested = 0;
int helpRequested = 0;
int fontsizeRequested = 0;
std::string settingsRequested;
int ret = -1;
for (int i = 1; i < argc; ++i) {
@@ -82,6 +83,15 @@ int main(int argc, char *argv[])
cleanRequested = 1;
} else if (strcmp(argv[i], "--headless") == 0 || strcmp(argv[i], "-L") == 0) {
headlessRequested = 1;
} else if (strcmp(argv[i], "--settings") == 0 || strcmp(argv[i], "-S") == 0) {
// get settings file argument
if (i + 1 < argc) {
settingsRequested = argv[i + 1]; // Parse next argument as integer
i++; // Skip the next argument since it's already processed
} else {
fprintf(stderr, "Error: filename missing after --settings\n");
helpRequested = 1;
}
} else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-H") == 0) {
helpRequested = 1;
} else if (strcmp(argv[i], "--fontsize") == 0 || strcmp(argv[i], "-F") == 0) {
@@ -135,15 +145,19 @@ int main(int argc, char *argv[])
}
if (helpRequested) {
printf("Usage: %s [-H, --help] [-V, --version] [-F N, --fontsize N] [-L, --headless] [-T, --test] [-C, --clean] [filename]\n",
printf("Usage: %s [-H, --help] [-V, --version] [-F, --fontsize] [-L, --headless]\n"
" [-S, --settings] [-T, --test] [-C, --clean] [filename]\n",
argv[0]);
printf("Options:\n");
printf(" --help : Display usage information\n");
printf(" --version : Display version information\n");
printf(" --fontsize N : Force rendering font size to specified value N\n");
printf(" --headless : Run without GUI\n");
printf(" --test : Run rendering test\n");
printf(" --fontsize : Force rendering font size to specified value, e.g., '-F 25'\n");
printf(" --settings : Run with given settings file, e.g., '-S settingsfile.xml'\n");
printf(" --headless : Run without GUI (only if output windows configured)\n");
printf(" --test : Run rendering test and return\n");
printf(" --clean : Reset user settings\n");
printf("Filename:\n");
printf(" vimix session file (.mix extension)\n");
ret = 0;ret = 0;
}
@@ -156,7 +170,7 @@ int main(int argc, char *argv[])
///
/// Settings
///
Settings::Load();
Settings::Load( settingsRequested );
Settings::application.executable = std::string(argv[0]);
/// lock to inform an instance is running