Skip to content

Commit

Permalink
Allow decimation function in saved script to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1t3cht committed Mar 22, 2024
1 parent bf9222a commit 3203e27
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/shared/WobblyProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4199,7 +4199,7 @@ void WobblyProject::freezeFramesToScript(std::string &script) const {
}


void WobblyProject::decimatedFramesToScript(std::string &script) const {
void WobblyProject::decimatedFramesToScript(std::string &script, DecimationFunction decimation_function) const {
std::string delete_frames;

const DecimationRangeVector &decimation_ranges = getDecimationRanges();
Expand Down Expand Up @@ -4283,7 +4283,7 @@ void WobblyProject::decimatedFramesToScript(std::string &script) const {

select_every += "\n" + splice + "])\n\n";

if (delete_frames.size() < select_every.size())
if (decimation_function == DELETEFRAMES || (decimation_function == AUTO && delete_frames.size() < select_every.size()))
script += delete_frames;
else
script += select_every;
Expand Down Expand Up @@ -4328,7 +4328,7 @@ void WobblyProject::setOutputToScript(std::string &script) const {
}


std::string WobblyProject::generateFinalScript(bool save_source_node) const {
std::string WobblyProject::generateFinalScript(bool save_source_node, FinalScriptFormat format) const {
// XXX Insert comments before and after each part.
std::string script;

Expand Down Expand Up @@ -4361,7 +4361,7 @@ std::string WobblyProject::generateFinalScript(bool save_source_node) const {
break;
}
if (decimation_needed)
decimatedFramesToScript(script);
decimatedFramesToScript(script, format.decimation_function);

customListsToScript(script, PostDecimate);

Expand Down
14 changes: 12 additions & 2 deletions src/shared/WobblyProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ struct UndoStep {
};


enum DecimationFunction {
AUTO = 0,
SELECTEVERY,
DELETEFRAMES,
};

struct FinalScriptFormat {
DecimationFunction decimation_function;
};

class WobblyProject : public QObject {
Q_OBJECT

Expand Down Expand Up @@ -432,12 +442,12 @@ class WobblyProject : public QObject {
void trimToScript(std::string &script) const;
void fieldHintToScript(std::string &script) const;
void freezeFramesToScript(std::string &script) const;
void decimatedFramesToScript(std::string &script) const;
void decimatedFramesToScript(std::string &script, DecimationFunction decimation_function) const;
void cropToScript(std::string &script) const;
void resizeAndBitDepthToScript(std::string &script, bool resize_enabled, bool depth_enabled) const;
void setOutputToScript(std::string &script) const;

std::string generateFinalScript(bool save_source_node = true) const;
std::string generateFinalScript(bool save_source_node = true, FinalScriptFormat format = {}) const;
std::string generateMainDisplayScript() const;

std::string generateTimecodesV1() const;
Expand Down
23 changes: 22 additions & 1 deletion src/wobbly/WobblyWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ SOFTWARE.

#define KEY_COMPACT_PROJECT_FILES QStringLiteral("projects/compact_project_files")
#define KEY_USE_RELATIVE_PATHS QStringLiteral("projects/use_relative_paths")
#define KEY_DECIMATION_FUNCTION QStringLiteral("projects/decimation_function")


struct CallbackData {
Expand Down Expand Up @@ -176,6 +177,8 @@ void WobblyWindow::readSettings() {

settings_bookmark_description_check->setChecked(settings.value(KEY_ASK_FOR_BOOKMARK_DESCRIPTION, true).toBool());

settings_decimation_function_combo->setCurrentText(settings.value(KEY_DECIMATION_FUNCTION, "Auto").toString());

settings_colormatrix_combo->setCurrentText(settings.value(KEY_COLORMATRIX, "BT 601").toString());

settings_cache_spin->setValue(settings.value(KEY_MAXIMUM_CACHE_SIZE, 4096).toInt());
Expand Down Expand Up @@ -2766,6 +2769,9 @@ void WobblyWindow::createSettingsWindow() {

settings_bookmark_description_check = new QCheckBox(QStringLiteral("Ask for bookmark description"));

settings_decimation_function_combo = new QComboBox;
settings_decimation_function_combo->addItems({ "Auto", "SelectEvery", "DeleteFrames" });

settings_font_spin = new QSpinBox;
settings_font_spin->setRange(4, 99);

Expand Down Expand Up @@ -2830,6 +2836,10 @@ void WobblyWindow::createSettingsWindow() {
settings.setValue(KEY_ASK_FOR_BOOKMARK_DESCRIPTION, checked);
});

connect(settings_decimation_function_combo, &QComboBox::currentTextChanged, [this] (const QString &text) {
settings.setValue(KEY_DECIMATION_FUNCTION, text);
});

connect(settings_font_spin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this] (int value) {
QFont font = QApplication::font();
font.setPointSize(value);
Expand Down Expand Up @@ -2995,6 +3005,7 @@ void WobblyWindow::createSettingsWindow() {
form->addRow(settings_use_relative_paths_check);
form->addRow(settings_print_details_check);
form->addRow(settings_bookmark_description_check);
form->addRow(QStringLiteral("Decimation function"), settings_decimation_function_combo);
form->addRow(QStringLiteral("Font size"), settings_font_spin);
form->addRow(QStringLiteral("Overlay size"), overlay_size_spin);
form->addRow(QStringLiteral("Application style"), application_style_combo);
Expand Down Expand Up @@ -4031,7 +4042,17 @@ void WobblyWindow::realSaveScript(const QString &path) {
// The currently selected preset might not have been stored in the project yet.
presetEdited();

std::string script = project->generateFinalScript(false);
FinalScriptFormat format{};

QString decimation_function = settings_decimation_function_combo->currentText();
if (decimation_function == "SelectEvery")
format.decimation_function = DecimationFunction::SELECTEVERY;
else if (decimation_function == "DeleteFrames")
format.decimation_function = DecimationFunction::DELETEFRAMES;
else
format.decimation_function = DecimationFunction::AUTO;

std::string script = project->generateFinalScript(false, format);

QFile file(path);

Expand Down
1 change: 1 addition & 0 deletions src/wobbly/WobblyWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class WobblyWindow : public QMainWindow {
SpinBox *settings_undo_steps_spin;
QCheckBox *settings_print_details_check;
QCheckBox *settings_bookmark_description_check;
QComboBox *settings_decimation_function_combo;
SpinBox *settings_num_thumbnails_spin;
QDoubleSpinBox *settings_thumbnail_size_dspin;
TableWidget *settings_shortcuts_table;
Expand Down

0 comments on commit 3203e27

Please sign in to comment.