From dc901ca8ff2ca827ea117a420a7bbd8e26d0e28b Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 3 Feb 2019 18:48:02 +1100 Subject: [PATCH] load/save effect settings --- io/loadthread.cpp | 18 ------- project/effect.cpp | 119 ++++++++++++++++++++++++++++++++++++++++++++- project/effect.h | 4 ++ 3 files changed, 122 insertions(+), 19 deletions(-) diff --git a/io/loadthread.cpp b/io/loadthread.cpp index 39df0c6c6..ff44fffd1 100644 --- a/io/loadthread.cpp +++ b/io/loadthread.cpp @@ -37,24 +37,6 @@ LoadThread::LoadThread(LoadDialog* l, bool a) : ld(l), autorecovery(a), cancelle connect(this, SIGNAL(start_question(const QString&, const QString &, int)), this, SLOT(question_func(const QString &, const QString &, int))); } -const EffectMeta* get_meta_from_name(const QString& input) { - int split_index = input.indexOf('/'); - QString category; - if (split_index > -1) { - category = input.left(split_index); - } - QString name = input.mid(split_index + 1); - - for (int j=0;j #include #include +#include QVector effects; @@ -397,6 +398,12 @@ void Effect::show_context_menu(const QPoint& pos) { menu.addAction(tr("D&elete"), this, SLOT(delete_self())); + menu.addSeparator(); + + menu.addAction(tr("Load Settings to File"), this, SLOT(load_from_file())); + + menu.addAction(tr("Save Settings to File"), this, SLOT(save_to_file())); + menu.exec(container->title_bar->mapToGlobal(pos)); } } @@ -426,7 +433,99 @@ void Effect::move_down() { command->to = command->from + 1; undo_stack.push(command); panel_effect_controls->reload_clips(); - panel_sequence_viewer->viewer_widget->frame_update(); + panel_sequence_viewer->viewer_widget->frame_update(); +} + +void Effect::save_to_file() { + // save effect settings to file + QString file = QFileDialog::getSaveFileName(mainWindow, + tr("Save Effect Settings"), + QString(), + tr("Effect XML Settings %1").arg("(*.xml)")); + + // if the user picked a file + if (!file.isEmpty()) { + QFile file_handle(file); + if (file_handle.open(QFile::WriteOnly)) { + + // write settings with xml writer + QXmlStreamWriter stream(&file_handle); + + stream.writeStartDocument(); + + stream.writeStartElement("effect"); + + // pass off to standard saving function + save(stream); + + stream.writeEndElement(); // effect + + stream.writeEndDocument(); + + file_handle.close(); + } else { + QMessageBox::critical(mainWindow, + tr("Save Settings Failed"), + tr("Failed to open \"%1\" for writing.").arg(file), + QMessageBox::Ok); + } + } +} + +void Effect::load_from_file() { + // load effect settings from file + QString file = QFileDialog::getOpenFileName(mainWindow, + tr("Load Effect Settings"), + QString(), + tr("Effect XML Settings %1").arg("(*.xml)")); + + // if the user picked a file + if (!file.isEmpty()) { + QFile file_handle(file); + if (file_handle.open(QFile::ReadOnly)) { + + // write settings with xml writer + QXmlStreamReader stream(&file_handle); + + while (!stream.atEnd()) { + stream.readNext(); + + // find the effect opening tag + if (stream.name() == "effect" && stream.isStartElement()) { + + // check the name to see if it matches this effect + const QXmlStreamAttributes& attributes = stream.attributes(); + for (int i=0;i -1) { + category = input.left(split_index); + } + QString name = input.mid(split_index + 1); + + for (int j=0;j(a) + static_cast(b); mixed_sample = qMax(qMin(mixed_sample, static_cast(INT16_MAX)), static_cast(INT16_MIN)); diff --git a/project/effect.h b/project/effect.h index 665cdcedf..43b960c7f 100644 --- a/project/effect.h +++ b/project/effect.h @@ -135,6 +135,8 @@ struct GLTextureCoords { float opacity; }; +const EffectMeta* get_meta_from_name(const QString& input); + qint16 mix_audio_sample(qint16 a, qint16 b); #include "effectfield.h" @@ -207,6 +209,8 @@ private slots: void delete_self(); void move_up(); void move_down(); + void save_to_file(); + void load_from_file(); protected: // glsl effect QOpenGLShaderProgram* glslProgram;