annotate data/model/PathModel.h @ 913:b9d7352336ce

Fixes to FileSource from Ted Felix (for Rosegarden): avoid blowing up through calling abort() from cleanup() when error occurred; set status correctly for FTP transfers
author Chris Cannam
date Mon, 19 May 2014 10:54:45 +0100
parents f5e8f12d2e58
children 59e7fe1b1003
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@425 83
Chris@425 84 /**
Chris@425 85 * TabularModel is inherited via SparseModel, but we don't need it here.
Chris@425 86 */
Chris@425 87 virtual QString getHeading(int) const { return ""; }
Chris@425 88 virtual bool isColumnTimeValue(int) const { return false; }
Chris@425 89 virtual SortType getSortType(int) const { return SortNumeric; }
Chris@425 90
Chris@407 91 };
Chris@407 92
Chris@407 93
Chris@407 94 #endif