# HG changeset patch # User Chris Cannam # Date 1137086348 0 # Node ID 581f67f370f34de6b6bfd4a629cb3fd287215739 # Parent d86891498eef37926e3576fb2f0493d3eb354810 * Beginnings of session save code * Add spline curve mode to time value layer diff -r d86891498eef -r 581f67f370f3 base/Layer.cpp --- a/base/Layer.cpp Thu Jan 12 13:45:27 2006 +0000 +++ b/base/Layer.cpp Thu Jan 12 17:19:08 2006 +0000 @@ -12,6 +12,8 @@ #include +#include "layer/LayerFactory.h" //!!! shouldn't be including this here -- does that suggest we need to move this into layer/ ? + Layer::Layer(View *w) { m_view = w; @@ -32,6 +34,23 @@ emit layerNameChanged(); } +QString +Layer::toXmlString(QString indent, QString extraAttributes) const +{ + QString s; + + s += indent; + + s += QString("\n") + .arg(LayerFactory::instance()->getLayerTypeName + (LayerFactory::instance()->getLayerType(this))) + .arg((intptr_t)this) + .arg(objectName()) + .arg((intptr_t)getModel()) + .arg(extraAttributes); + + return s; +} #ifdef INCLUDE_MOCFILES #include "Layer.moc.cpp" diff -r d86891498eef -r 581f67f370f3 base/Layer.h --- a/base/Layer.h Thu Jan 12 13:45:27 2006 +0000 +++ b/base/Layer.h Thu Jan 12 17:19:08 2006 +0000 @@ -12,6 +12,7 @@ #define _VIEWER_H_ #include "PropertyContainer.h" +#include "XmlExportable.h" #include #include @@ -28,7 +29,8 @@ */ class Layer : public QObject, - public PropertyContainer + public PropertyContainer, + public XmlExportable { Q_OBJECT @@ -86,6 +88,9 @@ virtual void setObjectName(const QString &name); + virtual QString toXmlString(QString indent = "", + QString extraAttributes = "") const; + signals: void modelChanged(); void modelCompletionChanged(); diff -r d86891498eef -r 581f67f370f3 base/Model.cpp --- a/base/Model.cpp Thu Jan 12 13:45:27 2006 +0000 +++ b/base/Model.cpp Thu Jan 12 17:19:08 2006 +0000 @@ -1,8 +1,31 @@ +/* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ + +/* + A waveform viewer and audio annotation editor. + Chris Cannam, Queen Mary University of London, 2005-2006 + + This is experimental software. Not for distribution. +*/ #include "Model.h" const int Model::COMPLETION_UNKNOWN = -1; +QString +Model::toXmlString(QString indent, QString extraAttributes) const +{ + QString s; + + s += indent; + + s += QString("\n") + .arg((intptr_t)this) + .arg(objectName()) + .arg(extraAttributes); + + return s; +} + #ifdef INCLUDE_MOCFILES #ifdef INCLUDE_MOCFILES #include "Model.moc.cpp" diff -r d86891498eef -r 581f67f370f3 base/Model.h --- a/base/Model.h Thu Jan 12 13:45:27 2006 +0000 +++ b/base/Model.h Thu Jan 12 17:19:08 2006 +0000 @@ -13,6 +13,8 @@ #include #include +#include "XmlExportable.h" + typedef std::vector SampleBlock; /** @@ -20,7 +22,8 @@ * of data on a time scale based on an audio frame rate. */ -class Model : virtual public QObject +class Model : virtual public QObject, + public XmlExportable { Q_OBJECT @@ -82,6 +85,9 @@ } static const int COMPLETION_UNKNOWN; + virtual QString toXmlString(QString indent = "", + QString extraAttributes = "") const; + signals: /** * Emitted when a model has been edited (or more data retrieved diff -r d86891498eef -r 581f67f370f3 base/View.cpp --- a/base/View.cpp Thu Jan 12 13:45:27 2006 +0000 +++ b/base/View.cpp Thu Jan 12 17:19:08 2006 +0000 @@ -953,6 +953,39 @@ QFrame::paintEvent(e); } +QString +View::toXmlString(QString indent, QString extraAttributes) const +{ + QString s; + + s += indent; + + s += QString("\n") + .arg(m_centreFrame) + .arg(m_zoomLevel) + .arg(m_followPan) + .arg(m_followZoom) + .arg(m_followPlay == PlaybackScrollContinuous ? "scroll" : + m_followPlay == PlaybackScrollPage ? "page" : "ignore") + .arg(m_lightBackground) + .arg(extraAttributes); + + for (size_t i = 0; i < m_layers.size(); ++i) { + s += m_layers[i]->toXmlString(indent + " "); + } + + s += indent + ""; + + return s; +} + + #ifdef INCLUDE_MOCFILES #include "View.moc.cpp" #endif diff -r d86891498eef -r 581f67f370f3 base/View.h --- a/base/View.h Thu Jan 12 13:45:27 2006 +0000 +++ b/base/View.h Thu Jan 12 17:19:08 2006 +0000 @@ -15,6 +15,7 @@ #include "base/ZoomConstraint.h" #include "base/PropertyContainer.h" +#include "base/XmlExportable.h" class Layer; class ViewManager; @@ -35,7 +36,8 @@ */ class View : public QFrame, - public PropertyContainer + public PropertyContainer, + public XmlExportable { Q_OBJECT @@ -148,6 +150,9 @@ return objectName(); } + virtual QString toXmlString(QString indent = "", + QString extraAttributes = "") const; + signals: void propertyContainerAdded(PropertyContainer *pc); void propertyContainerRemoved(PropertyContainer *pc); @@ -191,23 +196,23 @@ void checkProgress(void *object); - size_t m_centreFrame; - int m_zoomLevel; - bool m_newModel; - bool m_followPan; - bool m_followZoom; - PlaybackFollowMode m_followPlay; - size_t m_playPointerFrame; - bool m_lightBackground; - bool m_showProgress; + size_t m_centreFrame; + int m_zoomLevel; + bool m_newModel; + bool m_followPan; + bool m_followZoom; + PlaybackFollowMode m_followPlay; + size_t m_playPointerFrame; + bool m_lightBackground; + bool m_showProgress; - QPixmap *m_cache; - size_t m_cacheCentreFrame; - int m_cacheZoomLevel; + QPixmap *m_cache; + size_t m_cacheCentreFrame; + int m_cacheZoomLevel; - bool m_deleting; + bool m_deleting; - LayerList m_layers; // I don't own these, but see note in dtor comment above + LayerList m_layers; // I don't own these, but see dtor note above // caches for use in getScrollableBackLayers, getNonScrollableFrontLayers mutable LayerList m_lastScrollableBackLayers; diff -r d86891498eef -r 581f67f370f3 base/XmlExportable.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/XmlExportable.cpp Thu Jan 12 17:19:08 2006 +0000 @@ -0,0 +1,41 @@ +/* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ + +/* + A waveform viewer and audio annotation editor. + Chris Cannam, Queen Mary University of London, 2005-2006 + + This is experimental software. Not for distribution. +*/ + +#include "XmlExportable.h" + +QString +XmlExportable::encodeEntities(QString s) +{ + s + .replace("&", "&") + .replace("<", "<") + .replace(">", ">") + .replace("\"", """) + .replace("'", "'"); + + return s; +} + +QString +XmlExportable::encodeColour(QColor c) +{ + QString r, g, b; + + r.setNum(c.red(), 16); + if (c.red() < 16) r = "0" + r; + + g.setNum(c.green(), 16); + if (c.green() < 16) g = "0" + g; + + b.setNum(c.blue(), 16); + if (c.blue() < 16) b = "0" + b; + + return "#" + r + g + b; +} + diff -r d86891498eef -r 581f67f370f3 base/XmlExportable.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/XmlExportable.h Thu Jan 12 17:19:08 2006 +0000 @@ -0,0 +1,27 @@ +/* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ + +/* + A waveform viewer and audio annotation editor. + Chris Cannam, Queen Mary University of London, 2005-2006 + + This is experimental software. Not for distribution. +*/ + +#ifndef _XML_EXPORTABLE_H_ +#define _XML_EXPORTABLE_H_ + +#include +#include + +class XmlExportable +{ +public: + virtual QString toXmlString(QString indent = "", + QString extraAttributes = "") const = 0; + + static QString encodeEntities(QString); + + static QString encodeColour(QColor); +}; + +#endif