From 69ccb55d615c8e097358d2adb98c620ef48bd4d2 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 10 Jan 2019 13:14:49 +1100 Subject: [PATCH] split passage get into separate io device --- effects/internal/voideffect.cpp | 82 ++++--- io/loadthread.cpp | 60 ++--- project/effect.cpp | 412 ++++++++++++++++---------------- 3 files changed, 280 insertions(+), 274 deletions(-) diff --git a/effects/internal/voideffect.cpp b/effects/internal/voideffect.cpp index eee3b4e87..11a8c25ff 100644 --- a/effects/internal/voideffect.cpp +++ b/effects/internal/voideffect.cpp @@ -2,55 +2,61 @@ #include #include +#include #include "ui/collapsiblewidget.h" #include "debug.h" VoidEffect::VoidEffect(Clip *c, const QString& n) : Effect(c, NULL) { - name = n; - QString display_name; - if (n.isEmpty()) { - display_name = "(unknown)"; - } else { - display_name = n; - } - EffectRow* row = add_row("Missing Effect", false, false); - row->add_widget(new QLabel(display_name)); - container->setText(display_name); + name = n; + QString display_name; + if (n.isEmpty()) { + display_name = "(unknown)"; + } else { + display_name = n; + } + EffectRow* row = add_row("Missing Effect", false, false); + row->add_widget(new QLabel(display_name)); + container->setText(display_name); } void VoidEffect::load(QXmlStreamReader &stream) { - QString tag = stream.name().toString(); - qint64 start_index = stream.characterOffset(); - qint64 end_index = start_index; - while (!stream.atEnd() && !(stream.name() == tag && stream.isEndElement())) { - end_index = stream.characterOffset(); - stream.readNext(); - } - qint64 passage_length = end_index - start_index; - if (passage_length > 0) { - // store xml data verbatim - QIODevice* device = stream.device(); - device->seek(start_index); - bytes = device->read(passage_length); - int passage_end = bytes.lastIndexOf('>')+1; - bytes.remove(passage_end, bytes.size()-passage_end); - } + QString tag = stream.name().toString(); + qint64 start_index = stream.characterOffset(); + qint64 end_index = start_index; + while (!stream.atEnd() && !(stream.name() == tag && stream.isEndElement())) { + end_index = stream.characterOffset(); + stream.readNext(); + } + qint64 passage_length = end_index - start_index; + if (passage_length > 0) { + // store xml data verbatim + QFile* device = static_cast(stream.device()); + + QFile passage_get(device->fileName()); + if (passage_get.open(QFile::ReadOnly)) { + passage_get.seek(start_index); + bytes = passage_get.read(passage_length); + int passage_end = bytes.lastIndexOf('>')+1; + bytes.remove(passage_end, bytes.size()-passage_end); + passage_get.close(); + } + } } void VoidEffect::save(QXmlStreamWriter &stream) { - if (!name.isEmpty()) { - stream.writeAttribute("name", name); - stream.writeAttribute("enabled", QString::number(is_enabled())); + if (!name.isEmpty()) { + stream.writeAttribute("name", name); + stream.writeAttribute("enabled", QString::number(is_enabled())); - // force xml writer to expand tag, ignored when loading - stream.writeStartElement("void"); - stream.writeEndElement(); + // force xml writer to expand tag, ignored when loading + stream.writeStartElement("void"); + stream.writeEndElement(); - if (!bytes.isEmpty()) { - // write stored data - QIODevice* device = stream.device(); - device->write(bytes); - } - } + if (!bytes.isEmpty()) { + // write stored data + QIODevice* device = stream.device(); + device->write(bytes); + } + } } diff --git a/io/loadthread.cpp b/io/loadthread.cpp index 71fa7035a..3ae94d103 100644 --- a/io/loadthread.cpp +++ b/io/loadthread.cpp @@ -34,7 +34,7 @@ LoadThread::LoadThread(LoadDialog* l, bool a) : ld(l), autorecovery(a), cancelle connect(this, SIGNAL(success()), this, SLOT(success_func())); connect(this, SIGNAL(error()), this, SLOT(error_func())); connect(this, SIGNAL(start_create_dual_transition(const TransitionData*,Clip*,Clip*,const EffectMeta*)), this, SLOT(create_dual_transition(const TransitionData*,Clip*,Clip*,const EffectMeta*))); - connect(this, SIGNAL(start_create_effect_ui(QXmlStreamReader*, Clip*, int, const QString*, const EffectMeta*, long, bool)), this, SLOT(create_effect_ui(QXmlStreamReader*, Clip*, int, const QString*, const EffectMeta*, long, bool))); + connect(this, SIGNAL(start_create_effect_ui(QXmlStreamReader*, Clip*, int, const QString*, const EffectMeta*, long, bool)), this, SLOT(create_effect_ui(QXmlStreamReader*, Clip*, int, const QString*, const EffectMeta*, long, bool))); } const EffectMeta* get_meta_from_name(const QString& name) { @@ -62,10 +62,10 @@ void LoadThread::load_effect(QXmlStreamReader& stream, Clip* c) { } else if (attr.name() == "length") { effect_length = attr.value().toLong(); } - } + } // wait for effects to be loaded - panel_effect_controls->effects_loaded.lock(); + panel_effect_controls->effects_loaded.lock(); const EffectMeta* meta = NULL; @@ -74,21 +74,21 @@ void LoadThread::load_effect(QXmlStreamReader& stream, Clip* c) { meta = get_meta_from_name(effect_name); } - panel_effect_controls->effects_loaded.unlock(); + panel_effect_controls->effects_loaded.unlock(); - QString tag = stream.name().toString(); + QString tag = stream.name().toString(); - int type; - if (tag == "opening") { - type = TA_OPENING_TRANSITION; - } else if (tag == "closing") { - type = TA_CLOSING_TRANSITION; - } else { - type = TA_NO_TRANSITION; - } + int type; + if (tag == "opening") { + type = TA_OPENING_TRANSITION; + } else if (tag == "closing") { + type = TA_CLOSING_TRANSITION; + } else { + type = TA_NO_TRANSITION; + } - emit start_create_effect_ui(&stream, c, type, &effect_name, meta, effect_length, effect_enabled); - waitCond.wait(&mutex); + emit start_create_effect_ui(&stream, c, type, &effect_name, meta, effect_length, effect_enabled); + waitCond.wait(&mutex); } void LoadThread::read_next(QXmlStreamReader &stream) { @@ -162,7 +162,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { internal_proj_url = stream.readElementText(); internal_proj_dir = QFileInfo(internal_proj_url).absoluteDir(); } else { - while (!cancelled && !(stream.name() == root_search && stream.isEndElement())) { + while (!cancelled && !stream.atEnd() && !(stream.name() == root_search && stream.isEndElement())) { read_next(stream); if (stream.name() == child_search && stream.isStartElement()) { switch (type) { @@ -582,7 +582,7 @@ void LoadThread::run() { xml_error = false; if (show_err) emit error(); } else if (stream.hasError()) { - error_str = stream.errorString(); + error_str = stream.errorString() + " - Line: " + QString::number(stream.lineNumber()) + " Col:" + QString::number(stream.columnNumber()); xml_error = true; emit error(); cont = false; @@ -657,7 +657,7 @@ void LoadThread::create_effect_ui( QXmlStreamReader* stream, Clip* c, int type, - const QString* effect_name, + const QString* effect_name, const EffectMeta* meta, long effect_length, bool effect_enabled) @@ -685,19 +685,19 @@ void LoadThread::create_effect_ui( if (cancelled) return; if (type == TA_NO_TRANSITION) { - if (meta == NULL) { - // create void effect - VoidEffect* ve = new VoidEffect(c, *effect_name); - ve->set_enabled(effect_enabled); - ve->load(*stream); - c->effects.append(ve); - } else { - Effect* e = create_effect(c, meta); - e->set_enabled(effect_enabled); - e->load(*stream); + if (meta == NULL) { + // create void effect + VoidEffect* ve = new VoidEffect(c, *effect_name); + ve->set_enabled(effect_enabled); + ve->load(*stream); + c->effects.append(ve); + } else { + Effect* e = create_effect(c, meta); + e->set_enabled(effect_enabled); + e->load(*stream); - c->effects.append(e); - } + c->effects.append(e); + } } else { int transition_index = create_transition(c, NULL, meta); Transition* t = c->sequence->transitions.at(transition_index); diff --git a/project/effect.cpp b/project/effect.cpp index f4ec6e3ab..7468a757d 100644 --- a/project/effect.cpp +++ b/project/effect.cpp @@ -93,7 +93,7 @@ void load_internal_effects() { em.name = "Volume"; em.internal = EFFECT_INTERNAL_VOLUME; - effects.append(em); + effects.append(em); em.name = "Pan"; em.internal = EFFECT_INTERNAL_PAN; @@ -244,7 +244,7 @@ void init_effects() { } EffectInit::EffectInit() { - panel_effect_controls->effects_loaded.lock(); + panel_effect_controls->effects_loaded.lock(); } void EffectInit::run() { @@ -252,7 +252,7 @@ void EffectInit::run() { load_internal_effects(); load_shader_effects(); load_vst_effects(); - panel_effect_controls->effects_loaded.unlock(); + panel_effect_controls->effects_loaded.unlock(); dout << "[INFO] Finished initializing effects"; } @@ -280,195 +280,195 @@ Effect::Effect(Clip* c, const EffectMeta *em) : connect(container->title_bar, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu(const QPoint&))); - if (em != NULL) { - // set up UI from effect file - container->setText(em->name); + if (em != NULL) { + // set up UI from effect file + container->setText(em->name); - if (!em->filename.isEmpty()) { - QFile effect_file(em->filename); - if (effect_file.open(QFile::ReadOnly)) { - QXmlStreamReader reader(&effect_file); + if (!em->filename.isEmpty()) { + QFile effect_file(em->filename); + if (effect_file.open(QFile::ReadOnly)) { + QXmlStreamReader reader(&effect_file); - while (!reader.atEnd()) { - if (reader.name() == "row" && reader.isStartElement()) { - QString row_name; - const QXmlStreamAttributes& attributes = reader.attributes(); - for (int i=0;ifilename << "- ID cannot be empty."; - } else if (type > -1) { - EffectField* field = row->add_field(type, id); - connect(field, SIGNAL(changed()), this, SLOT(field_changed())); - switch (type) { - case EFFECT_FIELD_DOUBLE: - for (int i=0;iset_double_default_value(attr.value().toDouble()); - } else if (attr.name() == "min") { - field->set_double_minimum_value(attr.value().toDouble()); - } else if (attr.name() == "max") { - field->set_double_maximum_value(attr.value().toDouble()); - } - } - break; - case EFFECT_FIELD_COLOR: - { - QColor color; - for (int i=0;iset_color_value(color); - } - break; - case EFFECT_FIELD_STRING: - for (int i=0;iset_string_value(attr.value().toString()); - } - } - break; - case EFFECT_FIELD_BOOL: - for (int i=0;iset_bool_value(attr.value() == "1"); - } - } - break; - case EFFECT_FIELD_COMBO: - { - int combo_index = 0; - for (int i=0;iadd_combo_item(reader.text().toString(), 0); - } - } - field->set_combo_index(combo_index); - } - break; - case EFFECT_FIELD_FONT: - for (int i=0;iset_font_name(attr.value().toString()); - } - } - break; - case EFFECT_FIELD_FILE: - for (int i=0;iset_filename(attr.value().toString()); - } - } - break; - } - } - } - } - } - } else if (reader.name() == "shader" && reader.isStartElement()) { - enable_shader = true; - const QXmlStreamAttributes& attributes = reader.attributes(); - for (int i=0;ifilename; - enable_superimpose = false; - } - break; - } - } - }*/ - reader.readNext(); - } + if (id.isEmpty()) { + dout << "[ERROR] Couldn't load field from" << em->filename << "- ID cannot be empty."; + } else if (type > -1) { + EffectField* field = row->add_field(type, id); + connect(field, SIGNAL(changed()), this, SLOT(field_changed())); + switch (type) { + case EFFECT_FIELD_DOUBLE: + for (int i=0;iset_double_default_value(attr.value().toDouble()); + } else if (attr.name() == "min") { + field->set_double_minimum_value(attr.value().toDouble()); + } else if (attr.name() == "max") { + field->set_double_maximum_value(attr.value().toDouble()); + } + } + break; + case EFFECT_FIELD_COLOR: + { + QColor color; + for (int i=0;iset_color_value(color); + } + break; + case EFFECT_FIELD_STRING: + for (int i=0;iset_string_value(attr.value().toString()); + } + } + break; + case EFFECT_FIELD_BOOL: + for (int i=0;iset_bool_value(attr.value() == "1"); + } + } + break; + case EFFECT_FIELD_COMBO: + { + int combo_index = 0; + for (int i=0;iadd_combo_item(reader.text().toString(), 0); + } + } + field->set_combo_index(combo_index); + } + break; + case EFFECT_FIELD_FONT: + for (int i=0;iset_font_name(attr.value().toString()); + } + } + break; + case EFFECT_FIELD_FILE: + for (int i=0;iset_filename(attr.value().toString()); + } + } + break; + } + } + } + } + } + } else if (reader.name() == "shader" && reader.isStartElement()) { + enable_shader = true; + const QXmlStreamAttributes& attributes = reader.attributes(); + for (int i=0;ifilename; + enable_superimpose = false; + } + break; + } + } + }*/ + reader.readNext(); + } - effect_file.close(); - } else { - dout << "[ERROR] Failed to open effect file" << em->filename; - } - } - } + effect_file.close(); + } else { + dout << "[ERROR] Failed to open effect file" << em->filename; + } + } + } } Effect::~Effect() { @@ -794,28 +794,28 @@ void Effect::open() { validate_meta_path(); bool glsl_compiled = true; if (!vertPath.isEmpty()) { - if (glslProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, meta->path + "/" + vertPath)) { - dout << "[INFO] Vertex shader added successfully"; - } else { - glsl_compiled = false; - dout << "[WARNING] Vertex shader could not be added"; - } + if (glslProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, meta->path + "/" + vertPath)) { + dout << "[INFO] Vertex shader added successfully"; + } else { + glsl_compiled = false; + dout << "[WARNING] Vertex shader could not be added"; + } } if (!fragPath.isEmpty()) { - if (glslProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, meta->path + "/" + fragPath)) { - dout << "[INFO] Fragment shader added successfully"; - } else { - glsl_compiled = false; - dout << "[WARNING] Fragment shader could not be added"; - } + if (glslProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, meta->path + "/" + fragPath)) { + dout << "[INFO] Fragment shader added successfully"; + } else { + glsl_compiled = false; + dout << "[WARNING] Fragment shader could not be added"; + } + } + if (glsl_compiled) { + if (glslProgram->link()) { + dout << "[INFO] Shader program linked successfully"; + } else { + dout << "[WARNING] Shader program failed to link"; + } } - if (glsl_compiled) { - if (glslProgram->link()) { - dout << "[INFO] Shader program linked successfully"; - } else { - dout << "[WARNING] Shader program failed to link"; - } - } isOpen = true; } } else {