16 #ifndef _SPARSE_MODEL_H_ 17 #define _SPARSE_MODEL_H_ 34 #include <QTextStream> 41 template <
typename Po
intType>
47 bool notifyOnAdd =
true);
50 virtual bool isOK()
const {
return true; }
68 typedef std::multiset<PointType,
117 virtual void clear();
122 virtual void addPoint(
const PointType &point);
132 virtual bool isReady(
int *completion = 0)
const {
138 virtual void setCompletion(
int completion,
bool update =
true);
147 virtual void toXml(QTextStream &out,
149 QString extraAttributes =
"")
const;
155 s += i->toDelimitedDataString(delimiter,
m_sampleRate) +
"\n";
164 if (i->frame >= (
long)f0 && i->frame < (long)f1) {
165 s += i->toDelimitedDataString(delimiter,
m_sampleRate) +
"\n";
178 const PointType &point,
205 const PointType &point) :
208 virtual QString
getName()
const {
return tr(
"Delete Point"); }
230 virtual void addPoint(
const PointType &point);
259 const PointType &point,
265 virtual QString
getName()
const {
return tr(
"Re-Label Point"); }
300 std::vector<long>::iterator i =
302 #if defined(__SUNPRO_CC) && defined(__STD_RW_ITERATOR__) 304 std::distance(
m_rows.begin(), i, row);
306 int row = std::distance(
m_rows.begin(), i);
308 if (i !=
m_rows.begin() && (i ==
m_rows.end() || *i != frame)) {
315 virtual QVariant
getData(
int row,
int column,
int role)
const 318 if (i ==
m_points.end())
return QVariant();
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();
327 case 1:
return int(i->frame);
334 const QVariant &value,
int role)
336 if (role != Qt::EditRole)
return 0;
339 EditCommand *command =
new EditCommand(
this, tr(
"Edit Data"));
342 command->deletePoint(point);
346 case 1: point.
frame = value.toInt();
break;
349 command->addPoint(point);
350 return command->finish();
355 EditCommand *command =
new EditCommand(
this, tr(
"Insert Data Point"));
359 if (i !=
m_points.end()) point = *i;
360 command->addPoint(point);
361 return command->finish();
368 EditCommand *command =
new EditCommand(
this, tr(
"Delete Data Point"));
369 command->deletePoint(*i);
370 return command->finish();
401 m_rows.push_back(i->frame);
408 if (row < 0 || row + 1 >
int(
m_rows.size()))
return m_points.end();
411 int indexAtFrame = 0;
413 while (ri > 0 &&
m_rows[ri-1] ==
m_rows[row]) { --ri; ++indexAtFrame; }
414 int initialIndexAtFrame = indexAtFrame;
420 for (i = i0; i != i1; ++i) {
421 if (i->frame < (
int)frame) {
continue; }
422 if (indexAtFrame > 0) { --indexAtFrame;
continue; }
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;
435 if (row < 0 || row + 1 >
int(
m_rows.size()))
return m_points.end();
438 int indexAtFrame = 0;
440 while (ri > 0 &&
m_rows[ri-1] ==
m_rows[row]) { --ri; ++indexAtFrame; }
441 int initialIndexAtFrame = indexAtFrame;
449 for (i = i0; i != i1; ++i) {
452 if (i->frame < (
int)frame) {
continue; }
453 if (indexAtFrame > 0) { --indexAtFrame;
continue; }
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;
467 template <
typename Po
intType>
471 m_sampleRate(sampleRate),
472 m_resolution(resolution),
473 m_notifyOnAdd(notifyOnAdd),
474 m_sinceLastNotifyMin(-1),
475 m_sinceLastNotifyMax(-1),
476 m_hasTextLabels(false),
482 template <
typename Po
intType>
486 QMutexLocker locker(&m_mutex);
488 if (!m_points.empty()) {
489 f = m_points.begin()->frame;
494 template <
typename Po
intType>
498 QMutexLocker locker(&m_mutex);
500 if (!m_points.empty()) {
507 template <
typename Po
intType>
521 template <
typename Po
intType>
525 return m_pointCount == 0;
528 template <
typename Po
intType>
535 template <
typename Po
intType>
542 template <
typename Po
intType>
547 QMutexLocker locker(&m_mutex);
549 PointType startPoint(start), endPoint(end);
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;
568 template <
typename Po
intType>
573 getPointIterators(frame, startItr, endItr);
584 template <
typename Po
intType>
590 QMutexLocker locker(&m_mutex);
592 if (m_resolution == 0) {
593 startItr = m_points.end();
594 endItr = m_points.end();
598 long start = (frame / m_resolution) * m_resolution;
599 long end = start + m_resolution;
601 PointType startPoint(start), endPoint(end);
603 startItr = m_points.lower_bound(startPoint);
604 endItr = m_points.upper_bound(endPoint);
607 template <
typename Po
intType>
613 QMutexLocker locker(&m_mutex);
615 if (m_resolution == 0) {
617 startItr = m_points.end();
618 endItr = m_points.end();
622 long start = (frame / m_resolution) * m_resolution;
623 long end = start + m_resolution;
625 PointType startPoint(start), endPoint(end);
629 startItr = m_points.lower_bound(startPoint);
630 endItr = m_points.upper_bound(endPoint);
633 template <
typename Po
intType>
637 QMutexLocker locker(&m_mutex);
639 PointType lookupPoint(originFrame);
643 if (i == m_points.begin())
return rv;
646 long frame = i->frame;
647 while (i->frame == frame) {
649 if (i == m_points.begin())
break;
656 template <
typename Po
intType>
660 QMutexLocker locker(&m_mutex);
662 PointType lookupPoint(originFrame);
666 if (i == m_points.end())
return rv;
668 long frame = i->frame;
669 while (i != m_points.end() && i->frame == frame) {
677 template <
typename Po
intType>
682 QMutexLocker locker(&m_mutex);
683 m_resolution = resolution;
689 template <
typename Po
intType>
694 QMutexLocker locker(&m_mutex);
702 template <
typename Po
intType>
707 QMutexLocker locker(&m_mutex);
708 m_points.insert(point);
710 if (point.getLabel() !=
"") m_hasTextLabels =
true;
721 emit modelChangedWithin(point.frame, point.frame + m_resolution);
723 if (m_sinceLastNotifyMin == -1 ||
724 point.frame < m_sinceLastNotifyMin) {
725 m_sinceLastNotifyMin = point.frame;
727 if (m_sinceLastNotifyMax == -1 ||
728 point.frame > m_sinceLastNotifyMax) {
729 m_sinceLastNotifyMax = point.frame;
734 template <
typename Po
intType>
739 QMutexLocker locker(&m_mutex);
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)) {
756 emit modelChangedWithin(point.frame, point.frame + m_resolution);
759 template <
typename Po
intType>
765 if (m_completion != completion) {
766 m_completion = completion;
768 if (completion == 100) {
770 if (!m_notifyOnAdd) {
771 emit completionChanged();
774 m_notifyOnAdd =
true;
778 }
else if (!m_notifyOnAdd) {
781 m_sinceLastNotifyMin >= 0 &&
782 m_sinceLastNotifyMax >= 0) {
784 emit modelChangedWithin(m_sinceLastNotifyMin, m_sinceLastNotifyMax);
785 m_sinceLastNotifyMin = m_sinceLastNotifyMax = -1;
787 emit completionChanged();
790 emit completionChanged();
795 template <
typename Po
intType>
799 QString extraAttributes)
const 804 QString type = getXmlOutputType();
809 QString(
"type=\"%1\" dimensions=\"%2\" resolution=\"%3\" notifyOnAdd=\"%4\" dataset=\"%5\" %6")
811 .arg(PointType(0).getDimensions())
813 .arg(m_notifyOnAdd ?
"true" :
"false")
814 .arg(getObjectExportId(&m_points))
815 .arg(extraAttributes));
818 out << QString(
"<dataset id=\"%1\" dimensions=\"%2\">\n")
819 .arg(getObjectExportId(&m_points))
820 .arg(PointType(0).getDimensions());
823 i->toXml(out, indent +
" ");
827 out <<
"</dataset>\n";
830 template <
typename Po
intType>
832 QString commandName) :
838 template <
typename Po
intType>
845 template <
typename Po
intType>
852 template <
typename Po
intType>
856 if (!m_commands.empty()) {
864 template <
typename Po
intType>
869 if (executeFirst) command->
execute();
871 if (!m_commands.empty()) {
875 (m_commands[m_commands.size() - 1]);
876 typename PointType::Comparator comparator;
long m_sinceLastNotifyMin
std::multiset< PointType, typename PointType::OrderComparator > PointList
virtual QString getName() const
SparseModel< PointType > * m_model
static RealTime frame2RealTime(long frame, unsigned int sampleRate)
Convert a sample frame at the given sample rate into a RealTime.
std::string toText(bool fixedDp=false) const
Return a user-readable string to the nearest millisecond, in a form like HH:MM:SS....
virtual QString getName() const
virtual Command * getRemoveRowCommand(int row)
virtual void toXml(QTextStream &out, QString indent="", QString extraAttributes="") const
Stream this exportable object out to XML on a text stream.
SparseModel< PointType > * m_model
virtual void addPoint(const PointType &point)
PointList::const_iterator PointListConstIterator
virtual int getSampleRate() const
Return the frame rate in frames per second.
virtual void addCommand(Command *command)
Stack an arbitrary other command in the same sequence.
virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const
void rebuildRowVector() const
RegionModel – a concrete IntervalModel for intervals associated with a value, which we call regions f...
void ready()
Emitted when internal processing is complete (i.e.
virtual long getFrameForRow(int row) const
const PointType & getPoint() const
PointListConstIterator getPointListIteratorForRow(int row) const
std::vector< long > m_rows
virtual void addPoint(const PointType &point)
Add a point.
virtual bool hasTextLabels() const
virtual QString getName() const
virtual QVariant getData(int row, int column, int role) const
DeletePointCommand(SparseModel< PointType > *model, const PointType &point)
virtual int getPointCount() const
Get the total number of points in the model.
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Stream this exportable object out to XML on a text stream.
virtual int getCompletion() const
virtual Command * getSetDataCommand(int row, int column, const QVariant &value, int role)
virtual int getRowForFrame(long frame) const
virtual void setResolution(int resolution)
Command to add or remove a series of points, with undo.
virtual int getStartFrame() const
Return the first audio frame spanned by the model.
virtual const PointList & getPoints() const
Get all points.
virtual QString getXmlOutputType() const
virtual PointList getNextPoints(long frame) const
Return all points that share the nearest frame number subsequent to the given one at which there are ...
SparseModel< PointType > * m_model
virtual void deletePoint(const PointType &point)
Model is the base class for all data models that represent any sort of data on a time scale based on ...
TabularModel is an abstract base class for models that support direct access to data in a tabular for...
virtual bool isOK() const
Return true if the model was constructed successfully.
virtual void addCommand(Command *command)
virtual void clear()
Remove all points.
EditCommand(SparseModel< PointType > *model, QString commandName)
const PointType & getPoint() const
virtual bool isEmpty() const
Return whether the model is empty or not.
PointList::iterator PointListIterator
virtual int getResolution() const
Command to remove a point, with undo.
virtual EditCommand * finish()
If any points have been added or deleted, return this command (so the caller can add it to the comman...
virtual int getColumnCount() const
virtual Model * clone() const
Return a copy of this model.
AddPointCommand(SparseModel< PointType > *model, const PointType &point, QString name="")
QString getTypeName() const
Return the type of the model.
virtual int getEndFrame() const
Return the last audio frame spanned by the model.
long m_sinceLastNotifyMax
RelabelCommand(SparseModel< PointType > *model, const PointType &point, QString newLabel)
SparseModel(int sampleRate, int resolution, bool notifyOnAdd=true)
Command to relabel a point.
Command to add a point, with undo.
virtual void setCompletion(int completion, bool update=true)
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...
virtual int getRowCount() const
TabularModel methods.
SparseModel< PointType > * m_model
virtual Command * getInsertRowCommand(int row)
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...
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 ...
virtual void deletePoint(const PointType &point)
Remove a point.
void getPointIterators(long frame, PointListIterator &startItr, PointListIterator &endItr)
PointListIterator getPointListIteratorForRow(int row)
virtual QString toDelimitedDataString(QString delimiter) const
Model containing sparse data (points with some properties).
RealTime represents time values to nanosecond precision with accurate arithmetic and frame-rate conve...