svcore  1.9
SparseModel.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 2006 Chris Cannam.
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 _SPARSE_MODEL_H_
17 #define _SPARSE_MODEL_H_
18 
19 #include "Model.h"
20 #include "TabularModel.h"
21 #include "base/Command.h"
22 #include "base/RealTime.h"
23 
24 #include <iostream>
25 
26 #include <set>
27 #include <vector>
28 #include <algorithm>
29 #include <iterator>
30 
31 #include <cmath>
32 
33 #include <QMutex>
34 #include <QTextStream>
35 
41 template <typename PointType>
42 class SparseModel : public Model,
43  public TabularModel
44 {
45 public:
46  SparseModel(int sampleRate, int resolution,
47  bool notifyOnAdd = true);
48  virtual ~SparseModel() { }
49 
50  virtual bool isOK() const { return true; }
51  virtual int getStartFrame() const;
52  virtual int getEndFrame() const;
53  virtual int getSampleRate() const { return m_sampleRate; }
54 
55  virtual Model *clone() const;
56 
57  // Number of frames of the underlying sample rate that this model
58  // is capable of resolving to. For example, if m_resolution == 10
59  // then every point in this model will be at a multiple of 10
60  // sample frames and should be considered to cover a window ending
61  // 10 sample frames later.
62  virtual int getResolution() const {
63  return m_resolution ? m_resolution : 1;
64  }
65  virtual void setResolution(int resolution);
66 
67  typedef PointType Point;
68  typedef std::multiset<PointType,
69  typename PointType::OrderComparator> PointList;
70  typedef typename PointList::iterator PointListIterator;
71  typedef typename PointList::const_iterator PointListConstIterator;
72 
76  virtual bool isEmpty() const;
77 
81  virtual int getPointCount() const;
82 
86  virtual const PointList &getPoints() const;
87 
94  virtual PointList getPoints(long start, long end) const;
95 
100  virtual PointList getPoints(long frame) const;
101 
106  virtual PointList getPreviousPoints(long frame) const;
107 
112  virtual PointList getNextPoints(long frame) const;
113 
117  virtual void clear();
118 
122  virtual void addPoint(const PointType &point);
123 
130  virtual void deletePoint(const PointType &point);
131 
132  virtual bool isReady(int *completion = 0) const {
133  bool ready = isOK() && (m_completion == 100);
134  if (completion) *completion = m_completion;
135  return ready;
136  }
137 
138  virtual void setCompletion(int completion, bool update = true);
139  virtual int getCompletion() const { return m_completion; }
140 
141  virtual bool hasTextLabels() const { return m_hasTextLabels; }
142 
143  QString getTypeName() const { return tr("Sparse"); }
144 
145  virtual QString getXmlOutputType() const { return "sparse"; }
146 
147  virtual void toXml(QTextStream &out,
148  QString indent = "",
149  QString extraAttributes = "") const;
150 
151  virtual QString toDelimitedDataString(QString delimiter) const
152  {
153  QString s;
154  for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) {
155  s += i->toDelimitedDataString(delimiter, m_sampleRate) + "\n";
156  }
157  return s;
158  }
159 
160  virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const
161  {
162  QString s;
163  for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) {
164  if (i->frame >= (long)f0 && i->frame < (long)f1) {
165  s += i->toDelimitedDataString(delimiter, m_sampleRate) + "\n";
166  }
167  }
168  return s;
169  }
170 
174  class AddPointCommand : public Command
175  {
176  public:
178  const PointType &point,
179  QString name = "") :
180  m_model(model), m_point(point), m_name(name) { }
181 
182  virtual QString getName() const {
183  return (m_name == "" ? tr("Add Point") : m_name);
184  }
185 
186  virtual void execute() { m_model->addPoint(m_point); }
187  virtual void unexecute() { m_model->deletePoint(m_point); }
188 
189  const PointType &getPoint() const { return m_point; }
190 
191  private:
193  PointType m_point;
194  QString m_name;
195  };
196 
197 
202  {
203  public:
205  const PointType &point) :
206  m_model(model), m_point(point) { }
207 
208  virtual QString getName() const { return tr("Delete Point"); }
209 
210  virtual void execute() { m_model->deletePoint(m_point); }
211  virtual void unexecute() { m_model->addPoint(m_point); }
212 
213  const PointType &getPoint() const { return m_point; }
214 
215  private:
217  PointType m_point;
218  };
219 
220 
225  class EditCommand : public MacroCommand
226  {
227  public:
228  EditCommand(SparseModel<PointType> *model, QString commandName);
229 
230  virtual void addPoint(const PointType &point);
231  virtual void deletePoint(const PointType &point);
232 
236  virtual void addCommand(Command *command) { addCommand(command, true); }
237 
243  virtual EditCommand *finish();
244 
245  protected:
246  virtual void addCommand(Command *command, bool executeFirst);
247 
249  };
250 
251 
255  class RelabelCommand : public Command
256  {
257  public:
259  const PointType &point,
260  QString newLabel) :
261  m_model(model), m_oldPoint(point), m_newPoint(point) {
262  m_newPoint.label = newLabel;
263  }
264 
265  virtual QString getName() const { return tr("Re-Label Point"); }
266 
267  virtual void execute() {
268  m_model->deletePoint(m_oldPoint);
269  m_model->addPoint(m_newPoint);
270  std::swap(m_oldPoint, m_newPoint);
271  }
272 
273  virtual void unexecute() { execute(); }
274 
275  private:
277  PointType m_oldPoint;
278  PointType m_newPoint;
279  };
280 
285  virtual int getRowCount() const
286  {
287  return m_points.size();
288  }
289 
290  virtual long getFrameForRow(int row) const
291  {
293  if (i == m_points.end()) return 0;
294  return i->frame;
295  }
296 
297  virtual int getRowForFrame(long frame) const
298  {
299  if (m_rows.empty()) rebuildRowVector();
300  std::vector<long>::iterator i =
301  std::lower_bound(m_rows.begin(), m_rows.end(), frame);
302 #if defined(__SUNPRO_CC) && defined(__STD_RW_ITERATOR__)
303  int row = 0;
304  std::distance(m_rows.begin(), i, row);
305 #else
306  int row = std::distance(m_rows.begin(), i);
307 #endif
308  if (i != m_rows.begin() && (i == m_rows.end() || *i != frame)) {
309  --row;
310  }
311  return row;
312  }
313 
314  virtual int getColumnCount() const { return 1; }
315  virtual QVariant getData(int row, int column, int role) const
316  {
318  if (i == m_points.end()) return QVariant();
319 
320  switch (column) {
321  case 0: {
322  if (role == SortRole) return int(i->frame);
324  if (role == Qt::EditRole) return rt.toString().c_str();
325  else return rt.toText().c_str();
326  }
327  case 1: return int(i->frame);
328  }
329 
330  return QVariant();
331  }
332 
333  virtual Command *getSetDataCommand(int row, int column,
334  const QVariant &value, int role)
335  {
336  if (role != Qt::EditRole) return 0;
338  if (i == m_points.end()) return 0;
339  EditCommand *command = new EditCommand(this, tr("Edit Data"));
340 
341  Point point(*i);
342  command->deletePoint(point);
343 
344  switch (column) {
345  case 0: point.frame = lrint(value.toDouble() * getSampleRate()); break;
346  case 1: point.frame = value.toInt(); break;
347  }
348 
349  command->addPoint(point);
350  return command->finish();
351  }
352 
353  virtual Command *getInsertRowCommand(int row)
354  {
355  EditCommand *command = new EditCommand(this, tr("Insert Data Point"));
356  Point point(0);
358  if (i == m_points.end() && i != m_points.begin()) --i;
359  if (i != m_points.end()) point = *i;
360  command->addPoint(point);
361  return command->finish();
362  }
363 
364  virtual Command *getRemoveRowCommand(int row)
365  {
367  if (i == m_points.end()) return 0;
368  EditCommand *command = new EditCommand(this, tr("Delete Data Point"));
369  command->deletePoint(*i);
370  return command->finish();
371  }
372 
373 protected:
380 
383  mutable QMutex m_mutex;
385 
386  void getPointIterators(long frame,
387  PointListIterator &startItr,
388  PointListIterator &endItr);
389  void getPointIterators(long frame,
390  PointListConstIterator &startItr,
391  PointListConstIterator &endItr) const;
392 
393  // This is only used if the model is called on to act in
394  // TabularModel mode
395  mutable std::vector<long> m_rows; // map from row number to frame
396  void rebuildRowVector() const
397  {
398  m_rows.clear();
399  for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) {
400 // std::cerr << "rebuildRowVector: row " << m_rows.size() << " -> " << i->frame << std::endl;
401  m_rows.push_back(i->frame);
402  }
403  }
404 
406  {
407  if (m_rows.empty()) rebuildRowVector();
408  if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end();
409 
410  int frame = m_rows[row];
411  int indexAtFrame = 0;
412  int ri = row;
413  while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; }
414  int initialIndexAtFrame = indexAtFrame;
415 
416  PointListIterator i0, i1;
417  getPointIterators(frame, i0, i1);
418  PointListIterator i = i0;
419 
420  for (i = i0; i != i1; ++i) {
421  if (i->frame < (int)frame) { continue; }
422  if (indexAtFrame > 0) { --indexAtFrame; continue; }
423  return i;
424  }
425 
426  if (indexAtFrame > 0) {
427  std::cerr << "WARNING: SparseModel::getPointListIteratorForRow: No iterator available for row " << row << " (frame = " << frame << ", index at frame = " << initialIndexAtFrame << ", leftover index " << indexAtFrame << ")" << std::endl;
428  }
429  return i;
430  }
431 
433  {
434  if (m_rows.empty()) rebuildRowVector();
435  if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end();
436 
437  int frame = m_rows[row];
438  int indexAtFrame = 0;
439  int ri = row;
440  while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; }
441  int initialIndexAtFrame = indexAtFrame;
442 
443 // std::cerr << "getPointListIteratorForRow " << row << ": initialIndexAtFrame = " << initialIndexAtFrame << std::endl;
444 
445  PointListConstIterator i0, i1;
446  getPointIterators(frame, i0, i1);
447  PointListConstIterator i = i0;
448 
449  for (i = i0; i != i1; ++i) {
450 // std::cerr << "i->frame is " << i->frame << ", wanting " << frame << std::endl;
451 
452  if (i->frame < (int)frame) { continue; }
453  if (indexAtFrame > 0) { --indexAtFrame; continue; }
454  return i;
455  }
456 
457 // std::cerr << "returning i with i->frame = " << i->frame << std::endl;
458 
459  if (indexAtFrame > 0) {
460  std::cerr << "WARNING: SparseModel::getPointListIteratorForRow: No iterator available for row " << row << " (frame = " << frame << ", index at frame = " << initialIndexAtFrame << ", leftover index " << indexAtFrame << ")" << std::endl;
461  }
462  return i;
463  }
464 };
465 
466 
467 template <typename PointType>
469  int resolution,
470  bool notifyOnAdd) :
471  m_sampleRate(sampleRate),
472  m_resolution(resolution),
473  m_notifyOnAdd(notifyOnAdd),
474  m_sinceLastNotifyMin(-1),
475  m_sinceLastNotifyMax(-1),
476  m_hasTextLabels(false),
477  m_pointCount(0),
478  m_completion(100)
479 {
480 }
481 
482 template <typename PointType>
483 int
485 {
486  QMutexLocker locker(&m_mutex);
487  int f = 0;
488  if (!m_points.empty()) {
489  f = m_points.begin()->frame;
490  }
491  return f;
492 }
493 
494 template <typename PointType>
495 int
497 {
498  QMutexLocker locker(&m_mutex);
499  int f = 0;
500  if (!m_points.empty()) {
501  PointListConstIterator i(m_points.end());
502  f = (--i)->frame;
503  }
504  return f;
505 }
506 
507 template <typename PointType>
508 Model *
510 {
511  return 0;
512 /*
513  SparseModel<PointType> *model =
514  new SparseModel<PointType>(m_sampleRate, m_resolution, m_notifyOnAdd);
515  model->m_points = m_points;
516  model->m_pointCount = m_pointCount;
517  return model;
518 */
519 }
520 
521 template <typename PointType>
522 bool
524 {
525  return m_pointCount == 0;
526 }
527 
528 template <typename PointType>
529 int
531 {
532  return m_pointCount;
533 }
534 
535 template <typename PointType>
536 const typename SparseModel<PointType>::PointList &
538 {
539  return m_points;
540 }
541 
542 template <typename PointType>
544 SparseModel<PointType>::getPoints(long start, long end) const
545 {
546  if (start > end) return PointList();
547  QMutexLocker locker(&m_mutex);
548 
549  PointType startPoint(start), endPoint(end);
550 
551  PointListConstIterator startItr = m_points.lower_bound(startPoint);
552  PointListConstIterator endItr = m_points.upper_bound(endPoint);
553 
554  if (startItr != m_points.begin()) --startItr;
555  if (startItr != m_points.begin()) --startItr;
556  if (endItr != m_points.end()) ++endItr;
557  if (endItr != m_points.end()) ++endItr;
558 
559  PointList rv;
560 
561  for (PointListConstIterator i = startItr; i != endItr; ++i) {
562  rv.insert(*i);
563  }
564 
565  return rv;
566 }
567 
568 template <typename PointType>
571 {
572  PointListConstIterator startItr, endItr;
573  getPointIterators(frame, startItr, endItr);
574 
575  PointList rv;
576 
577  for (PointListConstIterator i = startItr; i != endItr; ++i) {
578  rv.insert(*i);
579  }
580 
581  return rv;
582 }
583 
584 template <typename PointType>
585 void
587  PointListIterator &startItr,
588  PointListIterator &endItr)
589 {
590  QMutexLocker locker(&m_mutex);
591 
592  if (m_resolution == 0) {
593  startItr = m_points.end();
594  endItr = m_points.end();
595  return;
596  }
597 
598  long start = (frame / m_resolution) * m_resolution;
599  long end = start + m_resolution;
600 
601  PointType startPoint(start), endPoint(end);
602 
603  startItr = m_points.lower_bound(startPoint);
604  endItr = m_points.upper_bound(endPoint);
605 }
606 
607 template <typename PointType>
608 void
610  PointListConstIterator &startItr,
611  PointListConstIterator &endItr) const
612 {
613  QMutexLocker locker(&m_mutex);
614 
615  if (m_resolution == 0) {
616 // std::cerr << "getPointIterators: resolution == 0, returning end()" << std::endl;
617  startItr = m_points.end();
618  endItr = m_points.end();
619  return;
620  }
621 
622  long start = (frame / m_resolution) * m_resolution;
623  long end = start + m_resolution;
624 
625  PointType startPoint(start), endPoint(end);
626 
627 // std::cerr << "getPointIterators: start frame " << start << ", end frame " << end << ", m_resolution " << m_resolution << std::endl;
628 
629  startItr = m_points.lower_bound(startPoint);
630  endItr = m_points.upper_bound(endPoint);
631 }
632 
633 template <typename PointType>
636 {
637  QMutexLocker locker(&m_mutex);
638 
639  PointType lookupPoint(originFrame);
640  PointList rv;
641 
642  PointListConstIterator i = m_points.lower_bound(lookupPoint);
643  if (i == m_points.begin()) return rv;
644 
645  --i;
646  long frame = i->frame;
647  while (i->frame == frame) {
648  rv.insert(*i);
649  if (i == m_points.begin()) break;
650  --i;
651  }
652 
653  return rv;
654 }
655 
656 template <typename PointType>
659 {
660  QMutexLocker locker(&m_mutex);
661 
662  PointType lookupPoint(originFrame);
663  PointList rv;
664 
665  PointListConstIterator i = m_points.upper_bound(lookupPoint);
666  if (i == m_points.end()) return rv;
667 
668  long frame = i->frame;
669  while (i != m_points.end() && i->frame == frame) {
670  rv.insert(*i);
671  ++i;
672  }
673 
674  return rv;
675 }
676 
677 template <typename PointType>
678 void
680 {
681  {
682  QMutexLocker locker(&m_mutex);
683  m_resolution = resolution;
684  }
685  m_rows.clear();
686  emit modelChanged();
687 }
688 
689 template <typename PointType>
690 void
692 {
693  {
694  QMutexLocker locker(&m_mutex);
695  m_points.clear();
696  m_pointCount = 0;
697  }
698  m_rows.clear();
699  emit modelChanged();
700 }
701 
702 template <typename PointType>
703 void
704 SparseModel<PointType>::addPoint(const PointType &point)
705 {
706  {
707  QMutexLocker locker(&m_mutex);
708  m_points.insert(point);
709  m_pointCount++;
710  if (point.getLabel() != "") m_hasTextLabels = true;
711  }
712 
713  // Even though this model is nominally sparse, there may still be
714  // too many signals going on here (especially as they'll probably
715  // be queued from one thread to another), which is why we need the
716  // notifyOnAdd as an option rather than a necessity (the
717  // alternative is to notify on setCompletion).
718 
719  if (m_notifyOnAdd) {
720  m_rows.clear();
721  emit modelChangedWithin(point.frame, point.frame + m_resolution);
722  } else {
723  if (m_sinceLastNotifyMin == -1 ||
724  point.frame < m_sinceLastNotifyMin) {
725  m_sinceLastNotifyMin = point.frame;
726  }
727  if (m_sinceLastNotifyMax == -1 ||
728  point.frame > m_sinceLastNotifyMax) {
729  m_sinceLastNotifyMax = point.frame;
730  }
731  }
732 }
733 
734 template <typename PointType>
735 void
736 SparseModel<PointType>::deletePoint(const PointType &point)
737 {
738  {
739  QMutexLocker locker(&m_mutex);
740 
741  PointListIterator i = m_points.lower_bound(point);
742  typename PointType::Comparator comparator;
743  while (i != m_points.end()) {
744  if (i->frame > point.frame) break;
745  if (!comparator(*i, point) && !comparator(point, *i)) {
746  m_points.erase(i);
747  m_pointCount--;
748  break;
749  }
750  ++i;
751  }
752  }
753 // std::cout << "SparseOneDimensionalModel: emit modelChanged("
754 // << point.frame << ")" << std::endl;
755  m_rows.clear();
756  emit modelChangedWithin(point.frame, point.frame + m_resolution);
757 }
758 
759 template <typename PointType>
760 void
761 SparseModel<PointType>::setCompletion(int completion, bool update)
762 {
763 // std::cerr << "SparseModel::setCompletion(" << completion << ")" << std::endl;
764 
765  if (m_completion != completion) {
766  m_completion = completion;
767 
768  if (completion == 100) {
769 
770  if (!m_notifyOnAdd) {
771  emit completionChanged();
772  }
773 
774  m_notifyOnAdd = true; // henceforth
775  m_rows.clear();
776  emit modelChanged();
777 
778  } else if (!m_notifyOnAdd) {
779 
780  if (update &&
781  m_sinceLastNotifyMin >= 0 &&
782  m_sinceLastNotifyMax >= 0) {
783  m_rows.clear();
784  emit modelChangedWithin(m_sinceLastNotifyMin, m_sinceLastNotifyMax);
785  m_sinceLastNotifyMin = m_sinceLastNotifyMax = -1;
786  } else {
787  emit completionChanged();
788  }
789  } else {
790  emit completionChanged();
791  }
792  }
793 }
794 
795 template <typename PointType>
796 void
798  QString indent,
799  QString extraAttributes) const
800 {
801 // std::cerr << "SparseModel::toXml: extraAttributes = \""
802 // << extraAttributes.toStdString() << std::endl;
803 
804  QString type = getXmlOutputType();
805 
807  (out,
808  indent,
809  QString("type=\"%1\" dimensions=\"%2\" resolution=\"%3\" notifyOnAdd=\"%4\" dataset=\"%5\" %6")
810  .arg(type)
811  .arg(PointType(0).getDimensions())
812  .arg(m_resolution)
813  .arg(m_notifyOnAdd ? "true" : "false")
814  .arg(getObjectExportId(&m_points))
815  .arg(extraAttributes));
816 
817  out << indent;
818  out << QString("<dataset id=\"%1\" dimensions=\"%2\">\n")
819  .arg(getObjectExportId(&m_points))
820  .arg(PointType(0).getDimensions());
821 
822  for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) {
823  i->toXml(out, indent + " ");
824  }
825 
826  out << indent;
827  out << "</dataset>\n";
828 }
829 
830 template <typename PointType>
832  QString commandName) :
833  MacroCommand(commandName),
834  m_model(model)
835 {
836 }
837 
838 template <typename PointType>
839 void
841 {
842  addCommand(new AddPointCommand(m_model, point), true);
843 }
844 
845 template <typename PointType>
846 void
848 {
849  addCommand(new DeletePointCommand(m_model, point), true);
850 }
851 
852 template <typename PointType>
855 {
856  if (!m_commands.empty()) {
857  return this;
858  } else {
859  delete this;
860  return 0;
861  }
862 }
863 
864 template <typename PointType>
865 void
867  bool executeFirst)
868 {
869  if (executeFirst) command->execute();
870 
871  if (!m_commands.empty()) {
872  DeletePointCommand *dpc = dynamic_cast<DeletePointCommand *>(command);
873  if (dpc) {
874  AddPointCommand *apc = dynamic_cast<AddPointCommand *>
875  (m_commands[m_commands.size() - 1]);
876  typename PointType::Comparator comparator;
877  if (apc) {
878  if (!comparator(apc->getPoint(), dpc->getPoint()) &&
879  !comparator(dpc->getPoint(), apc->getPoint())) {
880  deleteCommand(apc);
881  return;
882  }
883  }
884  }
885  }
886 
887  MacroCommand::addCommand(command);
888 }
889 
890 
891 #endif
892 
893 
894 
long m_sinceLastNotifyMin
Definition: SparseModel.h:377
std::multiset< PointType, typename PointType::OrderComparator > PointList
Definition: SparseModel.h:69
virtual QString getName() const
Definition: SparseModel.h:265
SparseModel< PointType > * m_model
Definition: SparseModel.h:192
QMutex m_mutex
Definition: SparseModel.h:383
static RealTime frame2RealTime(long frame, unsigned int sampleRate)
Convert a sample frame at the given sample rate into a RealTime.
Definition: RealTime.cpp:450
std::string toText(bool fixedDp=false) const
Return a user-readable string to the nearest millisecond, in a form like HH:MM:SS....
Definition: RealTime.cpp:252
virtual QString getName() const
Definition: SparseModel.h:208
bool m_notifyOnAdd
Definition: SparseModel.h:376
virtual Command * getRemoveRowCommand(int row)
Definition: SparseModel.h:364
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
SparseModel< PointType > * m_model
Definition: SparseModel.h:276
int m_resolution
Definition: SparseModel.h:375
virtual void addPoint(const PointType &point)
Definition: SparseModel.h:840
PointList::const_iterator PointListConstIterator
Definition: SparseModel.h:71
virtual int getSampleRate() const
Return the frame rate in frames per second.
Definition: SparseModel.h:53
virtual void addCommand(Command *command)
Stack an arbitrary other command in the same sequence.
Definition: SparseModel.h:236
int m_pointCount
Definition: SparseModel.h:382
virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const
Definition: SparseModel.h:160
void rebuildRowVector() const
Definition: SparseModel.h:396
PointList m_points
Definition: SparseModel.h:381
RegionModel – a concrete IntervalModel for intervals associated with a value, which we call regions f...
Definition: RegionModel.h:36
void ready()
Emitted when internal processing is complete (i.e.
virtual long getFrameForRow(int row) const
Definition: SparseModel.h:290
const PointType & getPoint() const
Definition: SparseModel.h:189
PointListConstIterator getPointListIteratorForRow(int row) const
Definition: SparseModel.h:432
std::vector< long > m_rows
Definition: SparseModel.h:395
virtual void addPoint(const PointType &point)
Add a point.
Definition: SparseModel.h:704
virtual bool hasTextLabels() const
Definition: SparseModel.h:141
int m_sampleRate
Definition: SparseModel.h:374
virtual QString getName() const
Definition: SparseModel.h:182
virtual QVariant getData(int row, int column, int role) const
Definition: SparseModel.h:315
int m_completion
Definition: SparseModel.h:384
DeletePointCommand(SparseModel< PointType > *model, const PointType &point)
Definition: SparseModel.h:204
virtual int getPointCount() const
Get the total number of points in the model.
Definition: SparseModel.h:530
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Stream this exportable object out to XML on a text stream.
Definition: Model.cpp:174
virtual int getCompletion() const
Definition: SparseModel.h:139
virtual Command * getSetDataCommand(int row, int column, const QVariant &value, int role)
Definition: SparseModel.h:333
virtual ~SparseModel()
Definition: SparseModel.h:48
virtual int getRowForFrame(long frame) const
Definition: SparseModel.h:297
virtual void setResolution(int resolution)
Definition: SparseModel.h:679
Command to add or remove a series of points, with undo.
Definition: SparseModel.h:225
virtual int getStartFrame() const
Return the first audio frame spanned by the model.
Definition: SparseModel.h:484
virtual const PointList & getPoints() const
Get all points.
Definition: SparseModel.h:537
virtual QString getXmlOutputType() const
Definition: SparseModel.h:145
virtual PointList getNextPoints(long frame) const
Return all points that share the nearest frame number subsequent to the given one at which there are ...
Definition: SparseModel.h:658
SparseModel< PointType > * m_model
Definition: SparseModel.h:216
virtual void deletePoint(const PointType &point)
Definition: SparseModel.h:847
Model is the base class for all data models that represent any sort of data on a time scale based on ...
Definition: Model.h:35
TabularModel is an abstract base class for models that support direct access to data in a tabular for...
Definition: TabularModel.h:34
virtual bool isOK() const
Return true if the model was constructed successfully.
Definition: SparseModel.h:50
virtual void addCommand(Command *command)
Definition: Command.cpp:32
virtual void clear()
Remove all points.
Definition: SparseModel.h:691
EditCommand(SparseModel< PointType > *model, QString commandName)
Definition: SparseModel.h:831
const PointType & getPoint() const
Definition: SparseModel.h:213
virtual bool isEmpty() const
Return whether the model is empty or not.
Definition: SparseModel.h:523
PointList::iterator PointListIterator
Definition: SparseModel.h:70
virtual int getResolution() const
Definition: SparseModel.h:62
Command to remove a point, with undo.
Definition: SparseModel.h:201
virtual EditCommand * finish()
If any points have been added or deleted, return this command (so the caller can add it to the comman...
Definition: SparseModel.h:854
virtual int getColumnCount() const
Definition: SparseModel.h:314
virtual Model * clone() const
Return a copy of this model.
Definition: SparseModel.h:509
AddPointCommand(SparseModel< PointType > *model, const PointType &point, QString name="")
Definition: SparseModel.h:177
QString getTypeName() const
Return the type of the model.
Definition: SparseModel.h:143
virtual int getEndFrame() const
Return the last audio frame spanned by the model.
Definition: SparseModel.h:496
long m_sinceLastNotifyMax
Definition: SparseModel.h:378
RelabelCommand(SparseModel< PointType > *model, const PointType &point, QString newLabel)
Definition: SparseModel.h:258
SparseModel(int sampleRate, int resolution, bool notifyOnAdd=true)
Definition: SparseModel.h:468
Command to relabel a point.
Definition: SparseModel.h:255
Command to add a point, with undo.
Definition: SparseModel.h:174
long frame
Definition: RegionModel.h:46
virtual void setCompletion(int completion, bool update=true)
Definition: SparseModel.h:761
virtual PointList getPreviousPoints(long frame) const
Return all points that share the nearest frame number prior to the given one at which there are any p...
Definition: SparseModel.h:635
virtual int getRowCount() const
TabularModel methods.
Definition: SparseModel.h:285
virtual void execute()=0
SparseModel< PointType > * m_model
Definition: SparseModel.h:248
virtual Command * getInsertRowCommand(int row)
Definition: SparseModel.h:353
virtual bool isReady(int *completion=0) const
Return true if the model has finished loading or calculating all its data, for a model that is capabl...
Definition: SparseModel.h:132
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
bool m_hasTextLabels
Definition: SparseModel.h:379
virtual void deletePoint(const PointType &point)
Remove a point.
Definition: SparseModel.h:736
void getPointIterators(long frame, PointListIterator &startItr, PointListIterator &endItr)
Definition: SparseModel.h:586
PointListIterator getPointListIteratorForRow(int row)
Definition: SparseModel.h:405
virtual QString toDelimitedDataString(QString delimiter) const
Definition: SparseModel.h:151
Model containing sparse data (points with some properties).
Definition: SparseModel.h:42
PointType Point
Definition: SparseModel.h:67
RealTime represents time values to nanosecond precision with accurate arithmetic and frame-rate conve...
Definition: RealTime.h:35