svcore  1.9
PathModel.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2007 QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef _PATH_MODEL_H_
17 #define _PATH_MODEL_H_
18 
19 #include "Model.h"
20 #include "SparseModel.h"
21 #include "base/RealTime.h"
22 
23 #include <QStringList>
24 
25 
26 struct PathPoint
27 {
28  PathPoint(long _frame) : frame(_frame), mapframe(_frame) { }
29  PathPoint(long _frame, long _mapframe) :
30  frame(_frame), mapframe(_mapframe) { }
31 
32  int getDimensions() const { return 2; }
33 
34  long frame;
35  long mapframe;
36 
37  QString getLabel() const { return ""; }
38 
39  void toXml(QTextStream &stream, QString indent = "",
40  QString extraAttributes = "") const {
41  stream << QString("%1<point frame=\"%2\" mapframe=\"%3\" %4/>\n")
42  .arg(indent).arg(frame).arg(mapframe).arg(extraAttributes);
43  }
44 
45  QString toDelimitedDataString(QString delimiter,
46  int sampleRate) const {
47  QStringList list;
48  list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
49  list << QString("%1").arg(mapframe);
50  return list.join(delimiter);
51  }
52 
53  struct Comparator {
54  bool operator()(const PathPoint &p1, const PathPoint &p2) const {
55  if (p1.frame != p2.frame) return p1.frame < p2.frame;
56  return p1.mapframe < p2.mapframe;
57  }
58  };
59 
60  struct OrderComparator {
61  bool operator()(const PathPoint &p1, const PathPoint &p2) const {
62  return p1.frame < p2.frame;
63  }
64  };
65 };
66 
67 class PathModel : public SparseModel<PathPoint>
68 {
69 public:
70  PathModel(int sampleRate, int resolution, bool notify = true) :
71  SparseModel<PathPoint>(sampleRate, resolution, notify) { }
72 
73  virtual void toXml(QTextStream &out,
74  QString indent = "",
75  QString extraAttributes = "") const
76  {
78  (out,
79  indent,
80  QString("%1 subtype=\"path\"")
81  .arg(extraAttributes));
82  }
83 
87  virtual QString getHeading(int) const { return ""; }
88  virtual bool isColumnTimeValue(int) const { return false; }
89  virtual SortType getSortType(int) const { return SortNumeric; }
90 
91 };
92 
93 
94 #endif
virtual void toXml(QTextStream &out, QString indent="", QString extraAttributes="") const
Stream this exportable object out to XML on a text stream.
Definition: PathModel.h:73
virtual SortType getSortType(int) const
Definition: PathModel.h:89
PathPoint(long _frame)
Definition: PathModel.h:28
static RealTime frame2RealTime(long frame, unsigned int sampleRate)
Convert a sample frame at the given sample rate into a RealTime.
Definition: RealTime.cpp:450
QString getLabel() const
Definition: PathModel.h:37
bool operator()(const PathPoint &p1, const PathPoint &p2) const
Definition: PathModel.h:54
virtual QString getHeading(int) const
TabularModel is inherited via SparseModel, but we don't need it here.
Definition: PathModel.h:87
virtual void toXml(QTextStream &out, QString indent="", QString extraAttributes="") const
Stream this exportable object out to XML on a text stream.
Definition: SparseModel.h:797
long frame
Definition: PathModel.h:34
PathModel(int sampleRate, int resolution, bool notify=true)
Definition: PathModel.h:70
QString toDelimitedDataString(QString delimiter, int sampleRate) const
Definition: PathModel.h:45
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Definition: PathModel.h:39
bool operator()(const PathPoint &p1, const PathPoint &p2) const
Definition: PathModel.h:61
int getDimensions() const
Definition: PathModel.h:32
virtual bool isColumnTimeValue(int) const
Definition: PathModel.h:88
long mapframe
Definition: PathModel.h:35
std::string toString(bool align=false) const
Return a human-readable debug-type string to full precision (probably not a format to show to a user ...
Definition: RealTime.cpp:191
Model containing sparse data (points with some properties).
Definition: SparseModel.h:42
PathPoint(long _frame, long _mapframe)
Definition: PathModel.h:29