# HG changeset patch # User Chris Cannam # Date 1137675278 0 # Node ID 2d5005f2b3d9ed7e7004315d2153e2d4af1fbd8c # Parent 8f5b812baaeec9d46478921714dccf5cb44c8ca3 * Rework handling of layer properties in file I/O -- we now get the individual layers to load and save them rather than doing it via generic property lists in the base class, so as to ensure we read and write meaningful values rather than generic int values requiring conversion. diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/Colour3DPlotLayer.h --- a/layer/Colour3DPlotLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/Colour3DPlotLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -58,6 +58,8 @@ virtual QString getPropertyContainerIconName() const { return "colour3d"; } + void setProperties(const QXmlAttributes &attributes) { } + protected slots: void cacheInvalid(); void cacheInvalid(size_t startFrame, size_t endFrame); diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/LayerFactory.cpp --- a/layer/LayerFactory.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/LayerFactory.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -51,6 +51,8 @@ // fact -- there's nothing permanently melodic-range about it // that should be encoded in its name return Layer::tr("Spectrogram"); + + default: break; } return Layer::tr("Layer"); @@ -189,6 +191,8 @@ layer = new SpectrogramLayer(view, SpectrogramLayer::MelodicRange); static_cast(layer)->setChannel(channel); break; + + default: break; } if (!layer) { diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -1778,6 +1778,44 @@ return Layer::toXmlString(indent, extraAttributes + " " + s); } +void +SpectrogramLayer::setProperties(const QXmlAttributes &attributes) +{ + bool ok = false; + + int channel = attributes.value("channel").toInt(&ok); + if (ok) setChannel(channel); + + size_t windowSize = attributes.value("windowSize").toUInt(&ok); + if (ok) setWindowSize(windowSize); + + WindowType windowType = (WindowType) + attributes.value("windowType").toInt(&ok); + if (ok) setWindowType(windowType); + + size_t windowOverlap = attributes.value("windowOverlap").toUInt(&ok); + if (ok) setWindowOverlap(windowOverlap); + + float gain = attributes.value("gain").toFloat(&ok); + if (ok) setGain(gain); + + size_t maxFrequency = attributes.value("maxFrequency").toUInt(&ok); + if (ok) setMaxFrequency(maxFrequency); + + ColourScale colourScale = (ColourScale) + attributes.value("colourScale").toInt(&ok); + if (ok) setColourScale(colourScale); + + ColourScheme colourScheme = (ColourScheme) + attributes.value("colourScheme").toInt(&ok); + if (ok) setColourScheme(colourScheme); + + FrequencyScale frequencyScale = (FrequencyScale) + attributes.value("frequencyScale").toInt(&ok); + if (ok) setFrequencyScale(frequencyScale); +} + + #ifdef INCLUDE_MOCFILES #include "SpectrogramLayer.moc.cpp" #endif diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/SpectrogramLayer.h --- a/layer/SpectrogramLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/SpectrogramLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -135,6 +135,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + void setProperties(const QXmlAttributes &attributes); + protected slots: void cacheInvalid(); void cacheInvalid(size_t startFrame, size_t endFrame); diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/TimeInstantLayer.cpp --- a/layer/TimeInstantLayer.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeInstantLayer.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -305,6 +305,18 @@ QString(" colour=\"%1\"").arg(encodeColour(m_colour))); } +void +TimeInstantLayer::setProperties(const QXmlAttributes &attributes) +{ + QString colourSpec = attributes.value("colour"); + if (colourSpec != "") { + QColor colour(colourSpec); + if (colour.isValid()) { + setBaseColour(QColor(colourSpec)); + } + } +} + #ifdef INCLUDE_MOCFILES #include "TimeInstantLayer.moc.cpp" #endif diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/TimeInstantLayer.h --- a/layer/TimeInstantLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeInstantLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -54,6 +54,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + void setProperties(const QXmlAttributes &attributes); + protected: SparseOneDimensionalModel::PointList getLocalPoints(int) const; diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/TimeRulerLayer.cpp --- a/layer/TimeRulerLayer.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeRulerLayer.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -288,6 +288,18 @@ QString(" colour=\"%1\"").arg(encodeColour(m_colour))); } +void +TimeRulerLayer::setProperties(const QXmlAttributes &attributes) +{ + QString colourSpec = attributes.value("colour"); + if (colourSpec != "") { + QColor colour(colourSpec); + if (colour.isValid()) { + setBaseColour(QColor(colourSpec)); + } + } +} + #ifdef INCLUDE_MOCFILES #include "TimeRulerLayer.moc.cpp" diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/TimeRulerLayer.h --- a/layer/TimeRulerLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeRulerLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -51,6 +51,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + void setProperties(const QXmlAttributes &attributes); + protected: Model *m_model; QColor m_colour; diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/TimeValueLayer.cpp --- a/layer/TimeValueLayer.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeValueLayer.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -287,6 +287,7 @@ SparseTimeValueModel::PointList points(m_model->getPoints (frame0, frame1)); + if (points.empty()) return; paint.setPen(m_colour); @@ -438,6 +439,23 @@ .arg(encodeColour(m_colour)).arg(m_plotStyle)); } +void +TimeValueLayer::setProperties(const QXmlAttributes &attributes) +{ + QString colourSpec = attributes.value("colour"); + if (colourSpec != "") { + QColor colour(colourSpec); + if (colour.isValid()) { + setBaseColour(QColor(colourSpec)); + } + } + + bool ok; + PlotStyle style = (PlotStyle) + attributes.value("plotStyle").toInt(&ok); + if (ok) setPlotStyle(style); +} + #ifdef INCLUDE_MOCFILES #include "TimeValueLayer.moc.cpp" diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/TimeValueLayer.h --- a/layer/TimeValueLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeValueLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -59,6 +59,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + void setProperties(const QXmlAttributes &attributes); + protected: SparseTimeValueModel::PointList getLocalPoints(int) const; diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/WaveformLayer.cpp --- a/layer/WaveformLayer.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/WaveformLayer.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -768,6 +768,46 @@ return Layer::toXmlString(indent, extraAttributes + " " + s); } +void +WaveformLayer::setProperties(const QXmlAttributes &attributes) +{ + bool ok = false; + + float gain = attributes.value("gain").toFloat(&ok); + if (ok) setGain(gain); + + QString colourSpec = attributes.value("colour"); + if (colourSpec != "") { + QColor colour(colourSpec); + if (colour.isValid()) { + setBaseColour(QColor(colourSpec)); + } + } + + bool showMeans = (attributes.value("showMeans") == "1" || + attributes.value("showMeans") == "true"); + setShowMeans(showMeans); + + bool greyscale = (attributes.value("greyscale") == "1" || + attributes.value("greyscale") == "true"); + setUseGreyscale(greyscale); + + ChannelMode channelMode = (ChannelMode) + attributes.value("channelMode").toInt(&ok); + if (ok) setChannelMode(channelMode); + + int channel = attributes.value("channel").toInt(&ok); + if (ok) setChannel(channel); + + Scale scale = (Scale) + attributes.value("scale").toInt(&ok); + if (ok) setScale(scale); + + bool aggressive = (attributes.value("aggressive") == "1" || + attributes.value("aggressive") == "true"); + setUseGreyscale(aggressive); +} + #ifdef INCLUDE_MOCFILES #include "WaveformLayer.moc.cpp" #endif diff -r 8f5b812baaee -r 2d5005f2b3d9 layer/WaveformLayer.h --- a/layer/WaveformLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/WaveformLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -160,6 +160,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + void setProperties(const QXmlAttributes &attributes); + protected: int dBscale(float sample, int m) const;