Mercurial > hg > svapp
changeset 226:2c827ac7c8e7 templating
When saving a session as a template, use the silent.wav placeholder instead of the main model
author | Chris Cannam |
---|---|
date | Wed, 11 May 2011 12:23:55 +0100 |
parents | 9d50c42d7ca0 |
children | a6398a7400c1 |
files | framework/Document.cpp framework/Document.h framework/MainWindowBase.cpp framework/MainWindowBase.h |
diffstat | 4 files changed, 40 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/framework/Document.cpp Tue May 10 19:37:45 2011 +0100 +++ b/framework/Document.cpp Wed May 11 12:23:55 2011 +0100 @@ -1072,12 +1072,29 @@ void Document::toXml(QTextStream &out, QString indent, QString extraAttributes) const { + toXml(out, indent, extraAttributes, false); +} + +void +Document::toXmlAsTemplate(QTextStream &out, QString indent, QString extraAttributes) const +{ + toXml(out, indent, extraAttributes, true); +} + +void +Document::toXml(QTextStream &out, QString indent, QString extraAttributes, + bool asTemplate) const +{ out << indent + QString("<data%1%2>\n") .arg(extraAttributes == "" ? "" : " ").arg(extraAttributes); if (m_mainModel) { - m_mainModel->toXml(out, indent + " ", "mainModel=\"true\""); + if (asTemplate) { + writePlaceholderMainModel(out, indent + " "); + } else { + m_mainModel->toXml(out, indent + " ", "mainModel=\"true\""); + } PlayParameters *playParameters = PlayParameterRepository::getInstance()->getPlayParameters(m_mainModel); @@ -1189,6 +1206,15 @@ } void +Document::writePlaceholderMainModel(QTextStream &out, QString indent) const +{ + out << indent; + out << QString("<model id=\"%1\" name=\"placeholder\" sampleRate=\"%2\" type=\"wavefile\" file=\":samples/silent.wav\" mainModel=\"true\"/>\n") + .arg(getObjectExportId(m_mainModel)) + .arg(m_mainModel->getSampleRate()); +} + +void Document::writeBackwardCompatibleDerivation(QTextStream &out, QString indent, Model *targetModel, const ModelRecord &rec) const
--- a/framework/Document.h Tue May 10 19:37:45 2011 +0100 +++ b/framework/Document.h Wed May 11 12:23:55 2011 +0100 @@ -214,6 +214,7 @@ void alignModels(); void toXml(QTextStream &, QString indent, QString extraAttributes) const; + void toXmlAsTemplate(QTextStream &, QString indent, QString extraAttributes) const; signals: void layerAdded(Layer *); @@ -334,6 +335,9 @@ static TransformId getAlignmentTransformName(); + void toXml(QTextStream &, QString, QString, bool asTemplate) const; + void writePlaceholderMainModel(QTextStream &, QString) const; + /** * And these are the layers. We also control the lifespans of * these (usually through the commands used to add and remove them).
--- a/framework/MainWindowBase.cpp Tue May 10 19:37:45 2011 +0100 +++ b/framework/MainWindowBase.cpp Wed May 11 12:23:55 2011 +0100 @@ -1961,7 +1961,7 @@ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QTextStream out(&bzFile); - toXml(out); + toXml(out, false); out.flush(); QApplication::restoreOverrideCursor(); @@ -2006,7 +2006,7 @@ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QTextStream out(&file); - toXml(out); + toXml(out, true); out.flush(); QApplication::restoreOverrideCursor(); @@ -2025,7 +2025,7 @@ } void -MainWindowBase::toXml(QTextStream &out) +MainWindowBase::toXml(QTextStream &out, bool asTemplate) { QString indent(" "); @@ -2033,7 +2033,11 @@ out << "<!DOCTYPE sonic-visualiser>\n"; out << "<sv>\n"; - m_document->toXml(out, "", ""); + if (asTemplate) { + m_document->toXmlAsTemplate(out, "", ""); + } else { + m_document->toXml(out, "", ""); + } out << "<display>\n";
--- a/framework/MainWindowBase.h Tue May 10 19:37:45 2011 +0100 +++ b/framework/MainWindowBase.h Wed May 11 12:23:55 2011 +0100 @@ -411,7 +411,7 @@ virtual void connectLayerEditDialog(ModelDataTableDialog *dialog); - virtual void toXml(QTextStream &stream); + virtual void toXml(QTextStream &stream, bool asTemplate); };