annotate data/model/PathModel.h @ 409:6075c90744d4

...
author Chris Cannam
date Fri, 09 May 2008 12:39:02 +0000
parents 88ad01799040
children f5e8f12d2e58
rev   line source
Chris@407 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@407 2
Chris@407 3 /*
Chris@407 4 Sonic Visualiser
Chris@407 5 An audio file viewer and annotation editor.
Chris@407 6 Centre for Digital Music, Queen Mary, University of London.
Chris@407 7 This file copyright 2007 QMUL.
Chris@407 8
Chris@407 9 This program is free software; you can redistribute it and/or
Chris@407 10 modify it under the terms of the GNU General Public License as
Chris@407 11 published by the Free Software Foundation; either version 2 of the
Chris@407 12 License, or (at your option) any later version. See the file
Chris@407 13 COPYING included with this distribution for more information.
Chris@407 14 */
Chris@407 15
Chris@407 16 #ifndef _PATH_MODEL_H_
Chris@407 17 #define _PATH_MODEL_H_
Chris@407 18
Chris@407 19 #include "Model.h"
Chris@407 20 #include "SparseModel.h"
Chris@407 21 #include "base/RealTime.h"
Chris@407 22
Chris@407 23 #include <QStringList>
Chris@407 24
Chris@407 25
Chris@407 26 struct PathPoint
Chris@407 27 {
Chris@407 28 PathPoint(long _frame) : frame(_frame), mapframe(_frame) { }
Chris@407 29 PathPoint(long _frame, long _mapframe) :
Chris@407 30 frame(_frame), mapframe(_mapframe) { }
Chris@407 31
Chris@407 32 int getDimensions() const { return 2; }
Chris@407 33
Chris@407 34 long frame;
Chris@407 35 long mapframe;
Chris@407 36
Chris@407 37 QString getLabel() const { return ""; }
Chris@407 38
Chris@407 39 void toXml(QTextStream &stream, QString indent = "",
Chris@407 40 QString extraAttributes = "") const {
Chris@407 41 stream << QString("%1<point frame=\"%2\" mapframe=\"%3\" %4/>\n")
Chris@407 42 .arg(indent).arg(frame).arg(mapframe).arg(extraAttributes);
Chris@407 43 }
Chris@407 44
Chris@407 45 QString toDelimitedDataString(QString delimiter,
Chris@407 46 size_t sampleRate) const {
Chris@407 47 QStringList list;
Chris@407 48 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
Chris@407 49 list << QString("%1").arg(mapframe);
Chris@407 50 return list.join(delimiter);
Chris@407 51 }
Chris@407 52
Chris@407 53 struct Comparator {
Chris@407 54 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
Chris@407 55 if (p1.frame != p2.frame) return p1.frame < p2.frame;
Chris@407 56 return p1.mapframe < p2.mapframe;
Chris@407 57 }
Chris@407 58 };
Chris@407 59
Chris@407 60 struct OrderComparator {
Chris@407 61 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
Chris@407 62 return p1.frame < p2.frame;
Chris@407 63 }
Chris@407 64 };
Chris@407 65 };
Chris@407 66
Chris@407 67 class PathModel : public SparseModel<PathPoint>
Chris@407 68 {
Chris@407 69 public:
Chris@407 70 PathModel(size_t sampleRate, size_t resolution, bool notify = true) :
Chris@407 71 SparseModel<PathPoint>(sampleRate, resolution, notify) { }
Chris@407 72
Chris@407 73 virtual void toXml(QTextStream &out,
Chris@407 74 QString indent = "",
Chris@407 75 QString extraAttributes = "") const
Chris@407 76 {
Chris@407 77 SparseModel<PathPoint>::toXml
Chris@407 78 (out,
Chris@407 79 indent,
Chris@407 80 QString("%1 subtype=\"path\"")
Chris@407 81 .arg(extraAttributes));
Chris@407 82 }
Chris@407 83 };
Chris@407 84
Chris@407 85
Chris@407 86 #endif