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@1696
|
23 //#define DEBUG_COMPLETION 1
|
Chris@1696
|
24
|
Chris@150
|
25 Model::~Model()
|
Chris@150
|
26 {
|
Chris@1668
|
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@1668
|
64 SVDEBUG << "Model(" << this << ", \""
|
Chris@1668
|
65 << objectName() << "\", type name \""
|
Chris@1668
|
66 << getTypeName() << "\", type uri <"
|
Chris@1668
|
67 << m_typeUri << ">)::aboutToDelete()" << endl;
|
Chris@360
|
68
|
Chris@319
|
69 if (m_aboutToDelete) {
|
Chris@1384
|
70 SVDEBUG << "WARNING: Model(" << this << ", \""
|
Chris@1384
|
71 << objectName() << "\", type uri <"
|
Chris@1384
|
72 << m_typeUri << ">)::aboutToDelete: "
|
Chris@1384
|
73 << "aboutToDelete called more than once for the same model"
|
Chris@1384
|
74 << endl;
|
Chris@319
|
75 }
|
Chris@319
|
76
|
Chris@319
|
77 emit aboutToBeDeleted();
|
Chris@319
|
78 m_aboutToDelete = true;
|
Chris@319
|
79 }
|
Chris@319
|
80
|
Chris@319
|
81 void
|
Chris@319
|
82 Model::sourceModelAboutToBeDeleted()
|
Chris@319
|
83 {
|
Chris@1582
|
84 m_sourceModel = nullptr;
|
Chris@319
|
85 }
|
Chris@319
|
86
|
Chris@319
|
87 void
|
Chris@319
|
88 Model::setAlignment(AlignmentModel *alignment)
|
Chris@319
|
89 {
|
Chris@1668
|
90 SVDEBUG << "Model(" << this << "): accepting alignment model "
|
Chris@1668
|
91 << alignment << endl;
|
Chris@1668
|
92
|
Chris@319
|
93 if (m_alignment) {
|
Chris@319
|
94 m_alignment->aboutToDelete();
|
Chris@319
|
95 delete m_alignment;
|
Chris@319
|
96 }
|
Chris@1018
|
97
|
Chris@319
|
98 m_alignment = alignment;
|
Chris@1018
|
99
|
Chris@1018
|
100 if (m_alignment) {
|
Chris@1018
|
101 connect(m_alignment, SIGNAL(completionChanged()),
|
Chris@1018
|
102 this, SIGNAL(alignmentCompletionChanged()));
|
Chris@1018
|
103 }
|
Chris@319
|
104 }
|
Chris@319
|
105
|
Chris@407
|
106 const AlignmentModel *
|
Chris@407
|
107 Model::getAlignment() const
|
Chris@407
|
108 {
|
Chris@407
|
109 return m_alignment;
|
Chris@407
|
110 }
|
Chris@407
|
111
|
Chris@319
|
112 const Model *
|
Chris@319
|
113 Model::getAlignmentReference() const
|
Chris@319
|
114 {
|
Chris@333
|
115 if (!m_alignment) {
|
Chris@333
|
116 if (m_sourceModel) return m_sourceModel->getAlignmentReference();
|
Chris@1582
|
117 return nullptr;
|
Chris@333
|
118 }
|
Chris@319
|
119 return m_alignment->getReferenceModel();
|
Chris@319
|
120 }
|
Chris@319
|
121
|
Chris@1038
|
122 sv_frame_t
|
Chris@1038
|
123 Model::alignToReference(sv_frame_t frame) const
|
Chris@319
|
124 {
|
Chris@951
|
125 // cerr << "Model(" << this << ")::alignToReference(" << frame << ")" << endl;
|
Chris@333
|
126 if (!m_alignment) {
|
Chris@333
|
127 if (m_sourceModel) return m_sourceModel->alignToReference(frame);
|
Chris@333
|
128 else return frame;
|
Chris@333
|
129 }
|
Chris@1038
|
130 sv_frame_t refFrame = m_alignment->toReference(frame);
|
Chris@340
|
131 const Model *m = m_alignment->getReferenceModel();
|
Chris@340
|
132 if (m && refFrame > m->getEndFrame()) refFrame = m->getEndFrame();
|
Chris@951
|
133 // cerr << "have alignment, aligned is " << refFrame << endl;
|
Chris@333
|
134 return refFrame;
|
Chris@319
|
135 }
|
Chris@319
|
136
|
Chris@1038
|
137 sv_frame_t
|
Chris@1038
|
138 Model::alignFromReference(sv_frame_t refFrame) const
|
Chris@319
|
139 {
|
Chris@951
|
140 // cerr << "Model(" << this << ")::alignFromReference(" << refFrame << ")" << endl;
|
Chris@333
|
141 if (!m_alignment) {
|
Chris@333
|
142 if (m_sourceModel) return m_sourceModel->alignFromReference(refFrame);
|
Chris@333
|
143 else return refFrame;
|
Chris@333
|
144 }
|
Chris@1038
|
145 sv_frame_t frame = m_alignment->fromReference(refFrame);
|
Chris@340
|
146 if (frame > getEndFrame()) frame = getEndFrame();
|
Chris@951
|
147 // cerr << "have alignment, aligned is " << frame << endl;
|
Chris@333
|
148 return frame;
|
Chris@319
|
149 }
|
Chris@319
|
150
|
Chris@319
|
151 int
|
Chris@319
|
152 Model::getAlignmentCompletion() const
|
Chris@319
|
153 {
|
Chris@1696
|
154 #ifdef DEBUG_COMPLETION
|
Chris@1696
|
155 SVCERR << "Model(" << this << ")::getAlignmentCompletion: m_alignment = "
|
Chris@1696
|
156 << m_alignment << endl;
|
Chris@1696
|
157 #endif
|
Chris@333
|
158 if (!m_alignment) {
|
Chris@333
|
159 if (m_sourceModel) return m_sourceModel->getAlignmentCompletion();
|
Chris@333
|
160 else return 100;
|
Chris@333
|
161 }
|
Chris@319
|
162 int completion = 0;
|
Chris@319
|
163 (void)m_alignment->isReady(&completion);
|
Chris@1696
|
164 #ifdef DEBUG_COMPLETION
|
Chris@1696
|
165 SVCERR << "Model(" << this << ")::getAlignmentCompletion: completion = " << completion
|
Chris@1696
|
166 << endl;
|
Chris@1696
|
167 #endif
|
Chris@319
|
168 return completion;
|
Chris@319
|
169 }
|
Chris@319
|
170
|
Chris@333
|
171 QString
|
Chris@333
|
172 Model::getTitle() const
|
Chris@333
|
173 {
|
Chris@333
|
174 if (m_sourceModel) return m_sourceModel->getTitle();
|
Chris@345
|
175 else return "";
|
Chris@333
|
176 }
|
Chris@333
|
177
|
Chris@333
|
178 QString
|
Chris@333
|
179 Model::getMaker() const
|
Chris@333
|
180 {
|
Chris@333
|
181 if (m_sourceModel) return m_sourceModel->getMaker();
|
Chris@345
|
182 else return "";
|
Chris@345
|
183 }
|
Chris@345
|
184
|
Chris@345
|
185 QString
|
Chris@345
|
186 Model::getLocation() const
|
Chris@345
|
187 {
|
Chris@345
|
188 if (m_sourceModel) return m_sourceModel->getLocation();
|
Chris@345
|
189 else return "";
|
Chris@333
|
190 }
|
Chris@333
|
191
|
Chris@319
|
192 void
|
Chris@150
|
193 Model::toXml(QTextStream &stream, QString indent,
|
Chris@150
|
194 QString extraAttributes) const
|
Chris@150
|
195 {
|
Chris@150
|
196 stream << indent;
|
Chris@150
|
197 stream << QString("<model id=\"%1\" name=\"%2\" sampleRate=\"%3\" start=\"%4\" end=\"%5\" %6/>\n")
|
Chris@1677
|
198 .arg(getExportId())
|
Chris@1429
|
199 .arg(encodeEntities(objectName()))
|
Chris@1429
|
200 .arg(getSampleRate())
|
Chris@1429
|
201 .arg(getStartFrame())
|
Chris@1429
|
202 .arg(getEndFrame())
|
Chris@1429
|
203 .arg(extraAttributes);
|
Chris@150
|
204 }
|
Chris@150
|
205
|
Chris@150
|
206
|