annotate data/model/Model.cpp @ 1478:8ff5505ad28d plugin-path-config

Get an expected value
author Chris Cannam
date Thu, 07 Jun 2018 16:40:28 +0100
parents 48e9f538e6e9
children 9d37c8cf9686
rev   line source
Chris@150 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@150 2
Chris@150 3 /*
Chris@150 4 Sonic Visualiser
Chris@150 5 An audio file viewer and annotation editor.
Chris@150 6 Centre for Digital Music, Queen Mary, University of London.
Chris@150 7 This file copyright 2006 Chris Cannam.
Chris@150 8
Chris@150 9 This program is free software; you can redistribute it and/or
Chris@150 10 modify it under the terms of the GNU General Public License as
Chris@150 11 published by the Free Software Foundation; either version 2 of the
Chris@150 12 License, or (at your option) any later version. See the file
Chris@150 13 COPYING included with this distribution for more information.
Chris@150 14 */
Chris@150 15
Chris@150 16 #include "Model.h"
Chris@319 17 #include "AlignmentModel.h"
Chris@150 18
Chris@150 19 #include <QTextStream>
Chris@150 20
Chris@150 21 #include <iostream>
Chris@150 22
Chris@150 23 const int Model::COMPLETION_UNKNOWN = -1;
Chris@150 24
Chris@150 25 Model::~Model()
Chris@150 26 {
Chris@690 27 // SVDEBUG << "Model::~Model(" << this << ")" << endl;
Chris@150 28
Chris@319 29 if (!m_aboutToDelete) {
Chris@1384 30 SVDEBUG << "NOTE: Model(" << this << ", \""
Chris@1384 31 << objectName() << "\", type uri <"
Chris@1384 32 << m_typeUri << ">)::~Model(): Model deleted "
Chris@1384 33 << "with no aboutToDelete notification"
Chris@1384 34 << endl;
Chris@319 35 }
Chris@319 36
Chris@319 37 if (m_alignment) {
Chris@319 38 m_alignment->aboutToDelete();
Chris@319 39 delete m_alignment;
Chris@319 40 }
Chris@150 41 }
Chris@150 42
Chris@150 43 void
Chris@319 44 Model::setSourceModel(Model *model)
Chris@319 45 {
Chris@319 46 if (m_sourceModel) {
Chris@319 47 disconnect(m_sourceModel, SIGNAL(aboutToBeDeleted()),
Chris@319 48 this, SLOT(sourceModelAboutToBeDeleted()));
Chris@319 49 }
Chris@319 50
Chris@319 51 m_sourceModel = model;
Chris@319 52
Chris@319 53 if (m_sourceModel) {
Chris@333 54 connect(m_sourceModel, SIGNAL(alignmentCompletionChanged()),
Chris@333 55 this, SIGNAL(alignmentCompletionChanged()));
Chris@319 56 connect(m_sourceModel, SIGNAL(aboutToBeDeleted()),
Chris@319 57 this, SLOT(sourceModelAboutToBeDeleted()));
Chris@319 58 }
Chris@319 59 }
Chris@319 60
Chris@319 61 void
Chris@319 62 Model::aboutToDelete()
Chris@319 63 {
Chris@1384 64 // SVDEBUG << "Model(" << this << ", \""
Chris@1384 65 // << objectName() << "\", type uri <"
Chris@1384 66 // << m_typeUri << ">)::aboutToDelete()" << endl;
Chris@360 67
Chris@319 68 if (m_aboutToDelete) {
Chris@1384 69 SVDEBUG << "WARNING: Model(" << this << ", \""
Chris@1384 70 << objectName() << "\", type uri <"
Chris@1384 71 << m_typeUri << ">)::aboutToDelete: "
Chris@1384 72 << "aboutToDelete called more than once for the same model"
Chris@1384 73 << endl;
Chris@319 74 }
Chris@319 75
Chris@319 76 emit aboutToBeDeleted();
Chris@319 77 m_aboutToDelete = true;
Chris@319 78 }
Chris@319 79
Chris@319 80 void
Chris@319 81 Model::sourceModelAboutToBeDeleted()
Chris@319 82 {
Chris@319 83 m_sourceModel = 0;
Chris@319 84 }
Chris@319 85
Chris@319 86 void
Chris@319 87 Model::setAlignment(AlignmentModel *alignment)
Chris@319 88 {
Chris@319 89 if (m_alignment) {
Chris@319 90 m_alignment->aboutToDelete();
Chris@319 91 delete m_alignment;
Chris@319 92 }
Chris@1018 93
Chris@319 94 m_alignment = alignment;
Chris@1018 95
Chris@1018 96 if (m_alignment) {
Chris@1018 97 connect(m_alignment, SIGNAL(completionChanged()),
Chris@1018 98 this, SIGNAL(alignmentCompletionChanged()));
Chris@1018 99 }
Chris@319 100 }
Chris@319 101
Chris@407 102 const AlignmentModel *
Chris@407 103 Model::getAlignment() const
Chris@407 104 {
Chris@407 105 return m_alignment;
Chris@407 106 }
Chris@407 107
Chris@319 108 const Model *
Chris@319 109 Model::getAlignmentReference() const
Chris@319 110 {
Chris@333 111 if (!m_alignment) {
Chris@333 112 if (m_sourceModel) return m_sourceModel->getAlignmentReference();
Chris@371 113 return 0;
Chris@333 114 }
Chris@319 115 return m_alignment->getReferenceModel();
Chris@319 116 }
Chris@319 117
Chris@1038 118 sv_frame_t
Chris@1038 119 Model::alignToReference(sv_frame_t frame) const
Chris@319 120 {
Chris@951 121 // cerr << "Model(" << this << ")::alignToReference(" << frame << ")" << endl;
Chris@333 122 if (!m_alignment) {
Chris@333 123 if (m_sourceModel) return m_sourceModel->alignToReference(frame);
Chris@333 124 else return frame;
Chris@333 125 }
Chris@1038 126 sv_frame_t refFrame = m_alignment->toReference(frame);
Chris@340 127 const Model *m = m_alignment->getReferenceModel();
Chris@340 128 if (m && refFrame > m->getEndFrame()) refFrame = m->getEndFrame();
Chris@951 129 // cerr << "have alignment, aligned is " << refFrame << endl;
Chris@333 130 return refFrame;
Chris@319 131 }
Chris@319 132
Chris@1038 133 sv_frame_t
Chris@1038 134 Model::alignFromReference(sv_frame_t refFrame) const
Chris@319 135 {
Chris@951 136 // cerr << "Model(" << this << ")::alignFromReference(" << refFrame << ")" << endl;
Chris@333 137 if (!m_alignment) {
Chris@333 138 if (m_sourceModel) return m_sourceModel->alignFromReference(refFrame);
Chris@333 139 else return refFrame;
Chris@333 140 }
Chris@1038 141 sv_frame_t frame = m_alignment->fromReference(refFrame);
Chris@340 142 if (frame > getEndFrame()) frame = getEndFrame();
Chris@951 143 // cerr << "have alignment, aligned is " << frame << endl;
Chris@333 144 return frame;
Chris@319 145 }
Chris@319 146
Chris@319 147 int
Chris@319 148 Model::getAlignmentCompletion() const
Chris@319 149 {
Chris@690 150 // SVDEBUG << "Model::getAlignmentCompletion" << endl;
Chris@333 151 if (!m_alignment) {
Chris@333 152 if (m_sourceModel) return m_sourceModel->getAlignmentCompletion();
Chris@333 153 else return 100;
Chris@333 154 }
Chris@319 155 int completion = 0;
Chris@319 156 (void)m_alignment->isReady(&completion);
Chris@843 157 // cerr << " -> " << completion << endl;
Chris@319 158 return completion;
Chris@319 159 }
Chris@319 160
Chris@333 161 QString
Chris@333 162 Model::getTitle() const
Chris@333 163 {
Chris@333 164 if (m_sourceModel) return m_sourceModel->getTitle();
Chris@345 165 else return "";
Chris@333 166 }
Chris@333 167
Chris@333 168 QString
Chris@333 169 Model::getMaker() const
Chris@333 170 {
Chris@333 171 if (m_sourceModel) return m_sourceModel->getMaker();
Chris@345 172 else return "";
Chris@345 173 }
Chris@345 174
Chris@345 175 QString
Chris@345 176 Model::getLocation() const
Chris@345 177 {
Chris@345 178 if (m_sourceModel) return m_sourceModel->getLocation();
Chris@345 179 else return "";
Chris@333 180 }
Chris@333 181
Chris@319 182 void
Chris@150 183 Model::toXml(QTextStream &stream, QString indent,
Chris@150 184 QString extraAttributes) const
Chris@150 185 {
Chris@150 186 stream << indent;
Chris@150 187 stream << QString("<model id=\"%1\" name=\"%2\" sampleRate=\"%3\" start=\"%4\" end=\"%5\" %6/>\n")
Chris@1429 188 .arg(getObjectExportId(this))
Chris@1429 189 .arg(encodeEntities(objectName()))
Chris@1429 190 .arg(getSampleRate())
Chris@1429 191 .arg(getStartFrame())
Chris@1429 192 .arg(getEndFrame())
Chris@1429 193 .arg(extraAttributes);
Chris@150 194 }
Chris@150 195
Chris@150 196