# HG changeset patch # User Chris Cannam # Date 1137086348 0 # Node ID 02aaea1ffaf7152880e7d37899bc2803e5d4cd70 # Parent 37b110168acf247ab7933c52340f433aac5a28fa * Beginnings of session save code * Add spline curve mode to time value layer diff -r 37b110168acf -r 02aaea1ffaf7 layer/LayerFactory.cpp --- a/layer/LayerFactory.cpp Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/LayerFactory.cpp Thu Jan 12 17:19:08 2006 +0000 @@ -89,14 +89,40 @@ } LayerFactory::LayerType -LayerFactory::getLayerType(Layer *layer) +LayerFactory::getLayerType(const Layer *layer) { - if (dynamic_cast(layer)) return Waveform; - if (dynamic_cast(layer)) return Spectrogram; - if (dynamic_cast(layer)) return TimeRuler; - if (dynamic_cast(layer)) return TimeInstants; - if (dynamic_cast(layer)) return TimeValues; - if (dynamic_cast(layer)) return Colour3DPlot; + if (dynamic_cast(layer)) return Waveform; + if (dynamic_cast(layer)) return Spectrogram; + if (dynamic_cast(layer)) return TimeRuler; + if (dynamic_cast(layer)) return TimeInstants; + if (dynamic_cast(layer)) return TimeValues; + if (dynamic_cast(layer)) return Colour3DPlot; + return UnknownLayer; +} + +QString +LayerFactory::getLayerTypeName(LayerType type) +{ + switch (type) { + case Waveform: return "waveform"; + case Spectrogram: return "spectrogram"; + case TimeRuler: return "timeruler"; + case TimeInstants: return "timeinstants"; + case TimeValues: return "timevalues"; + case Colour3DPlot: return "colour3dplot"; + default: return "unknown"; + } +} + +LayerFactory::LayerType +LayerFactory::getLayerTypeForName(QString name) +{ + if (name == "waveform") return Waveform; + if (name == "spectrogram") return Spectrogram; + if (name == "timeruler") return TimeRuler; + if (name == "timeinstants") return TimeInstants; + if (name == "timevalues") return TimeValues; + if (name == "colour3dplot") return Colour3DPlot; return UnknownLayer; } diff -r 37b110168acf -r 02aaea1ffaf7 layer/LayerFactory.h --- a/layer/LayerFactory.h Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/LayerFactory.h Thu Jan 12 17:19:08 2006 +0000 @@ -44,7 +44,7 @@ typedef std::set LayerTypeSet; LayerTypeSet getValidLayerTypes(Model *model); - LayerType getLayerType(Layer *); + LayerType getLayerType(const Layer *); Layer *createLayer(LayerType type, View *view, Model *model = 0, int channel = -1); @@ -53,6 +53,9 @@ void setModel(Layer *layer, Model *model); + QString getLayerTypeName(LayerType); + LayerType getLayerTypeForName(QString); + protected: template bool trySetModel(Layer *layerBase, Model *modelBase) { diff -r 37b110168acf -r 02aaea1ffaf7 layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Thu Jan 12 17:19:08 2006 +0000 @@ -1643,6 +1643,33 @@ } } +QString +SpectrogramLayer::toXmlString(QString indent, QString extraAttributes) const +{ + QString s; + + s += QString("channel=\"%1\" " + "windowSize=\"%2\" " + "windowType=\"%3\" " + "windowOverlap=\"%4\" " + "gain=\"%5\" " + "maxFrequency=\"%6\" " + "colourScale=\"%7\" " + "colourScheme=\"%8\" " + "frequencyScale=\"%9\"") + .arg(m_channel) + .arg(m_windowSize) + .arg(m_windowType) + .arg(m_windowOverlap) + .arg(m_gain) + .arg(m_maxFrequency) + .arg(m_colourScale) + .arg(m_colourScheme) + .arg(m_frequencyScale); + + return Layer::toXmlString(indent, extraAttributes + " " + s); +} + #ifdef INCLUDE_MOCFILES #include "SpectrogramLayer.moc.cpp" #endif diff -r 37b110168acf -r 02aaea1ffaf7 layer/SpectrogramLayer.h --- a/layer/SpectrogramLayer.h Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/SpectrogramLayer.h Thu Jan 12 17:19:08 2006 +0000 @@ -126,6 +126,9 @@ virtual QString getPropertyContainerIconName() const { return "spectrogram"; } + virtual QString toXmlString(QString indent = "", + QString extraAttributes = "") const; + protected slots: void cacheInvalid(); void cacheInvalid(size_t startFrame, size_t endFrame); @@ -135,14 +138,14 @@ protected: const DenseTimeValueModel *m_model; // I do not own this - int m_channel; - size_t m_windowSize; - WindowType m_windowType; - size_t m_windowOverlap; - float m_gain; - size_t m_maxFrequency; - ColourScale m_colourScale; - ColourScheme m_colourScheme; + int m_channel; + size_t m_windowSize; + WindowType m_windowType; + size_t m_windowOverlap; + float m_gain; + size_t m_maxFrequency; + ColourScale m_colourScale; + ColourScheme m_colourScheme; FrequencyScale m_frequencyScale; class CacheFillThread : public QThread diff -r 37b110168acf -r 02aaea1ffaf7 layer/TimeInstantLayer.cpp --- a/layer/TimeInstantLayer.cpp Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/TimeInstantLayer.cpp Thu Jan 12 17:19:08 2006 +0000 @@ -298,6 +298,12 @@ } } +QString +TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const +{ + return Layer::toXmlString(indent, extraAttributes + + QString(" colour=\"%1\"").arg(encodeColour(m_colour))); +} #ifdef INCLUDE_MOCFILES #include "TimeInstantLayer.moc.cpp" diff -r 37b110168acf -r 02aaea1ffaf7 layer/TimeInstantLayer.h --- a/layer/TimeInstantLayer.h Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/TimeInstantLayer.h Thu Jan 12 17:19:08 2006 +0000 @@ -51,6 +51,9 @@ virtual int getCompletion() const { return m_model->getCompletion(); } + virtual QString toXmlString(QString indent = "", + QString extraAttributes = "") const; + protected: SparseOneDimensionalModel::PointList getLocalPoints(int) const; diff -r 37b110168acf -r 02aaea1ffaf7 layer/TimeRulerLayer.cpp --- a/layer/TimeRulerLayer.cpp Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/TimeRulerLayer.cpp Thu Jan 12 17:19:08 2006 +0000 @@ -281,6 +281,13 @@ paint.restore(); } +QString +TimeRulerLayer::toXmlString(QString indent, QString extraAttributes) const +{ + return Layer::toXmlString(indent, extraAttributes + + QString(" colour=\"%1\"").arg(encodeColour(m_colour))); +} + #ifdef INCLUDE_MOCFILES #include "TimeRulerLayer.moc.cpp" diff -r 37b110168acf -r 02aaea1ffaf7 layer/TimeRulerLayer.h --- a/layer/TimeRulerLayer.h Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/TimeRulerLayer.h Thu Jan 12 17:19:08 2006 +0000 @@ -48,6 +48,9 @@ virtual QString getPropertyContainerIconName() const { return "timeruler"; } + virtual QString toXmlString(QString indent = "", + QString extraAttributes = "") const; + protected: Model *m_model; QColor m_colour; diff -r 37b110168acf -r 02aaea1ffaf7 layer/TimeValueLayer.cpp --- a/layer/TimeValueLayer.cpp Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/TimeValueLayer.cpp Thu Jan 12 17:19:08 2006 +0000 @@ -17,6 +17,7 @@ #include "model/SparseTimeValueModel.h" #include +#include #include #include @@ -25,7 +26,7 @@ Layer(w), m_model(0), m_colour(Qt::black), - m_plotStyle(PlotLines) + m_plotStyle(PlotConnectedPoints) { m_view->addLayer(this); } @@ -86,7 +87,7 @@ } else if (name == tr("Plot Type")) { *min = 0; - *max = 3; + *max = 4; deft = int(m_plotStyle); @@ -117,8 +118,9 @@ default: case 0: return tr("Points"); case 1: return tr("Stems"); - case 2: return tr("Lines"); - case 3: return tr("Curve"); + case 2: return tr("Connected Points"); + case 3: return tr("Lines"); + case 4: return tr("Curve"); } } return tr(""); @@ -161,6 +163,12 @@ bool TimeValueLayer::isLayerScrollable() const { + // We don't illuminate sections in the line or curve modes, so + // they're always scrollable + + if (m_plotStyle == PlotLines || + m_plotStyle == PlotCurve) return true; + QPoint discard; return !m_view->shouldIlluminateLocalFeatures(this, discard); } @@ -304,7 +312,15 @@ getLocalPoints(localPos.x()); if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; } - + + paint.save(); + + if (m_plotStyle == PlotLines || + m_plotStyle == PlotCurve) { + paint.setRenderHint(QPainter::Antialiasing, true); + } + QPainterPath path; + for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); i != points.end(); ++i) { @@ -318,12 +334,14 @@ if (w < 1) w = 1; - if (m_plotStyle == PlotCurve) { - paint.setPen(QPen(QBrush(m_colour), 2)); + if (m_plotStyle == PlotLines || + m_plotStyle == PlotCurve) { + paint.setPen(m_colour); + paint.setBrush(Qt::NoBrush); } else { paint.setPen(m_colour); + paint.setBrush(brushColour); } - paint.setBrush(brushColour); if (m_plotStyle == PlotStems) { paint.setPen(brushColour); @@ -336,18 +354,29 @@ } if (illuminateFrame == p.frame) { + //!!! aside from the problem of choosing a colour, it'd be //better to save the highlighted rects and draw them at //the end perhaps - paint.setPen(Qt::black);//!!! - paint.setBrush(Qt::black);//!!! + + //!!! not equipped to illuminate the right section in line + //or curve mode + + if (m_plotStyle != PlotCurve && + m_plotStyle != PlotLines) { + paint.setPen(Qt::black);//!!! + paint.setBrush(Qt::black);//!!! + } } - if (m_plotStyle != PlotCurve) { + if (m_plotStyle != PlotLines && + m_plotStyle != PlotCurve) { paint.drawRect(x, y - 1, w, 2); } - if (m_plotStyle == PlotLines || m_plotStyle == PlotCurve) { + if (m_plotStyle == PlotConnectedPoints || + m_plotStyle == PlotLines || + m_plotStyle == PlotCurve) { SparseTimeValueModel::PointList::const_iterator j = i; ++j; @@ -360,22 +389,51 @@ ((q.value - min) * m_view->height()) / (max - min))); - if (m_plotStyle == PlotLines) { + if (m_plotStyle == PlotConnectedPoints) { + paint.setPen(brushColour); paint.drawLine(x + w, y, nx, ny); + + } else if (m_plotStyle == PlotLines) { + + paint.drawLine(x + w/2, y, nx + w/2, ny); + } else { - paint.drawLine(x, y, nx, ny); + + if (path.isEmpty()) { + path.moveTo(x + w/2, y); + } + + if (nx - x > 5) { + path.cubicTo(x + w, y, nx, ny, nx + w/2, ny); + } else { + path.lineTo(nx + w/2, ny); + } } } } - /// if (p.label != "") { /// paint.drawText(x + 5, y - paint.fontMetrics().height() + paint.fontMetrics().ascent(), p.label); /// } } - - + + if (m_plotStyle == PlotCurve && !path.isEmpty()) { + paint.drawPath(path); + } + + paint.restore(); + + // looks like save/restore doesn't deal with this: + paint.setRenderHint(QPainter::Antialiasing, false); +} + +QString +TimeValueLayer::toXmlString(QString indent, QString extraAttributes) const +{ + return Layer::toXmlString(indent, extraAttributes + + QString(" colour=\"%1\" plotStyle=\"%2\"") + .arg(encodeColour(m_colour)).arg(m_plotStyle)); } diff -r 37b110168acf -r 02aaea1ffaf7 layer/TimeValueLayer.h --- a/layer/TimeValueLayer.h Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/TimeValueLayer.h Thu Jan 12 17:19:08 2006 +0000 @@ -45,7 +45,7 @@ void setBaseColour(QColor); QColor getBaseColour() const { return m_colour; } - enum PlotStyle { PlotPoints, PlotStems, PlotLines, PlotCurve }; + enum PlotStyle { PlotPoints, PlotStems, PlotConnectedPoints, PlotLines, PlotCurve }; void setPlotStyle(PlotStyle style); PlotStyle getPlotStyle() const { return m_plotStyle; } @@ -56,6 +56,9 @@ virtual int getCompletion() const { return m_model->getCompletion(); } + virtual QString toXmlString(QString indent = "", + QString extraAttributes = "") const; + protected: SparseTimeValueModel::PointList getLocalPoints(int) const; diff -r 37b110168acf -r 02aaea1ffaf7 layer/WaveformLayer.cpp --- a/layer/WaveformLayer.cpp Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/WaveformLayer.cpp Thu Jan 12 17:19:08 2006 +0000 @@ -739,6 +739,31 @@ } } +QString +WaveformLayer::toXmlString(QString indent, QString extraAttributes) const +{ + QString s; + + s += QString("gain=\"%1\" " + "colour=\"%2\" " + "showMeans=\"%3\" " + "greyscale=\"%4\" " + "channelMode=\"%5\" " + "channel=\"%6\" " + "scale=\"%7\" " + "aggressive=\"%8\"") + .arg(m_gain) + .arg(encodeColour(m_colour)) + .arg(m_showMeans) + .arg(m_greyscale) + .arg(m_channelMode) + .arg(m_channel) + .arg(m_scale) + .arg(m_aggressive); + + return Layer::toXmlString(indent, extraAttributes + " " + s); +} + #ifdef INCLUDE_MOCFILES #include "WaveformLayer.moc.cpp" #endif diff -r 37b110168acf -r 02aaea1ffaf7 layer/WaveformLayer.h --- a/layer/WaveformLayer.h Thu Jan 12 13:45:27 2006 +0000 +++ b/layer/WaveformLayer.h Thu Jan 12 17:19:08 2006 +0000 @@ -157,6 +157,9 @@ virtual QString getPropertyContainerIconName() const { return "waveform"; } + virtual QString toXmlString(QString indent = "", + QString extraAttributes = "") const; + protected: int dBscale(float sample, int m) const; @@ -165,14 +168,14 @@ /// Return value is number of channels displayed size_t getChannelArrangement(size_t &min, size_t &max, bool &merging) const; - float m_gain; - QColor m_colour; - bool m_showMeans; - bool m_greyscale; - ChannelMode m_channelMode; - int m_channel; - Scale m_scale; - bool m_aggressive; + float m_gain; + QColor m_colour; + bool m_showMeans; + bool m_greyscale; + ChannelMode m_channelMode; + int m_channel; + Scale m_scale; + bool m_aggressive; mutable QPixmap *m_cache; mutable bool m_cacheValid;