Mercurial > hg > svgui
comparison layer/Layer.cpp @ 944:78c152e4db95
Merge from branch tonioni
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:12:17 +0100 |
parents | 4a578a360011 |
children | 4fe7a09be0fe |
comparison
equal
deleted
inserted
replaced
896:78e041e45ff0 | 944:78c152e4db95 |
---|---|
49 Layer::connectSignals(const Model *model) | 49 Layer::connectSignals(const Model *model) |
50 { | 50 { |
51 connect(model, SIGNAL(modelChanged()), | 51 connect(model, SIGNAL(modelChanged()), |
52 this, SIGNAL(modelChanged())); | 52 this, SIGNAL(modelChanged())); |
53 | 53 |
54 connect(model, SIGNAL(modelChangedWithin(int, int)), | 54 connect(model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), |
55 this, SIGNAL(modelChangedWithin(int, int))); | 55 this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t))); |
56 | 56 |
57 connect(model, SIGNAL(completionChanged()), | 57 connect(model, SIGNAL(completionChanged()), |
58 this, SIGNAL(modelCompletionChanged())); | 58 this, SIGNAL(modelCompletionChanged())); |
59 | 59 |
60 connect(model, SIGNAL(alignmentCompletionChanged()), | 60 connect(model, SIGNAL(alignmentCompletionChanged()), |
137 setLayerDormant(view, !show); | 137 setLayerDormant(view, !show); |
138 emit layerParametersChanged(); | 138 emit layerParametersChanged(); |
139 } | 139 } |
140 | 140 |
141 bool | 141 bool |
142 Layer::getXScaleValue(const View *v, int x, float &value, QString &unit) const | 142 Layer::getXScaleValue(const View *v, int x, double &value, QString &unit) const |
143 { | 143 { |
144 if (!hasTimeXAxis()) return false; | 144 if (!hasTimeXAxis()) return false; |
145 | 145 |
146 const Model *m = getModel(); | 146 const Model *m = getModel(); |
147 if (!m) return false; | 147 if (!m) return false; |
148 | 148 |
149 value = float(v->getFrameForX(x)) / m->getSampleRate(); | 149 value = double(v->getFrameForX(x)) / m->getSampleRate(); |
150 unit = "s"; | 150 unit = "s"; |
151 return true; | 151 return true; |
152 } | 152 } |
153 | 153 |
154 bool | 154 bool |
155 Layer::getYScaleDifference(const View *v, int y0, int y1, | 155 Layer::getYScaleDifference(const View *v, int y0, int y1, |
156 float &diff, QString &unit) const | 156 double &diff, QString &unit) const |
157 { | 157 { |
158 float v0, v1; | 158 double v0, v1; |
159 if (!getYScaleValue(v, y0, v0, unit) || | 159 if (!getYScaleValue(v, y0, v0, unit) || |
160 !getYScaleValue(v, y1, v1, unit)) { | 160 !getYScaleValue(v, y1, v1, unit)) { |
161 diff = 0.f; | 161 diff = 0.f; |
162 return false; | 162 return false; |
163 } | 163 } |
164 diff = fabsf(v1 - v0); | 164 diff = fabs(v1 - v0); |
165 return true; | 165 return true; |
166 } | 166 } |
167 | 167 |
168 int | 168 sv_frame_t |
169 Layer::alignToReference(View *v, int frame) const | 169 Layer::alignToReference(View *v, sv_frame_t frame) const |
170 { | 170 { |
171 const Model *m = getModel(); | 171 const Model *m = getModel(); |
172 SVDEBUG << "Layer::alignToReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl; | 172 SVDEBUG << "Layer::alignToReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl; |
173 if (m && m->getAlignmentReference()) { | 173 if (m && m->getAlignmentReference()) { |
174 return m->alignToReference(frame); | 174 return m->alignToReference(frame); |
175 } else { | 175 } else { |
176 return v->alignToReference(frame); | 176 return v->alignToReference(frame); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 int | 180 sv_frame_t |
181 Layer::alignFromReference(View *v, int frame) const | 181 Layer::alignFromReference(View *v, sv_frame_t frame) const |
182 { | 182 { |
183 const Model *m = getModel(); | 183 const Model *m = getModel(); |
184 SVDEBUG << "Layer::alignFromReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl; | 184 SVDEBUG << "Layer::alignFromReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl; |
185 if (m && m->getAlignmentReference()) { | 185 if (m && m->getAlignmentReference()) { |
186 return m->alignFromReference(frame); | 186 return m->alignFromReference(frame); |
248 // What if the clipboard point has no reference frame? Then | 248 // What if the clipboard point has no reference frame? Then |
249 // we have to treat it as having its own frame as the | 249 // we have to treat it as having its own frame as the |
250 // reference (i.e. having been copied from the reference | 250 // reference (i.e. having been copied from the reference |
251 // model). | 251 // model). |
252 | 252 |
253 int sourceFrame = i->getFrame(); | 253 sv_frame_t sourceFrame = i->getFrame(); |
254 int referenceFrame = sourceFrame; | 254 sv_frame_t referenceFrame = sourceFrame; |
255 if (i->haveReferenceFrame()) { | 255 if (i->haveReferenceFrame()) { |
256 referenceFrame = i->getReferenceFrame(); | 256 referenceFrame = i->getReferenceFrame(); |
257 } | 257 } |
258 int myMappedFrame = alignToReference(v, sourceFrame); | 258 sv_frame_t myMappedFrame = alignToReference(v, sourceFrame); |
259 | 259 |
260 // cerr << "sourceFrame = " << sourceFrame << ", referenceFrame = " << referenceFrame << " (have = " << i->haveReferenceFrame() << "), myMappedFrame = " << myMappedFrame << endl; | 260 // cerr << "sourceFrame = " << sourceFrame << ", referenceFrame = " << referenceFrame << " (have = " << i->haveReferenceFrame() << "), myMappedFrame = " << myMappedFrame << endl; |
261 | 261 |
262 if (myMappedFrame != referenceFrame) return true; | 262 if (myMappedFrame != referenceFrame) return true; |
263 } | 263 } |
468 } | 468 } |
469 | 469 |
470 void | 470 void |
471 Layer::updateMeasurePixrects(View *v) const | 471 Layer::updateMeasurePixrects(View *v) const |
472 { | 472 { |
473 int sf = v->getStartFrame(); | 473 sv_frame_t sf = v->getStartFrame(); |
474 int ef = v->getEndFrame(); | 474 sv_frame_t ef = v->getEndFrame(); |
475 | 475 |
476 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); | 476 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); |
477 i != m_measureRects.end(); ++i) { | 477 i != m_measureRects.end(); ++i) { |
478 | 478 |
479 // This logic depends on the fact that if one measure rect in | 479 // This logic depends on the fact that if one measure rect in |
507 } | 507 } |
508 | 508 |
509 void | 509 void |
510 Layer::updateMeasureRectYCoords(View *v, const MeasureRect &r) const | 510 Layer::updateMeasureRectYCoords(View *v, const MeasureRect &r) const |
511 { | 511 { |
512 int y0 = lrint(r.startY * v->height()); | 512 int y0 = int(lrint(r.startY * v->height())); |
513 int y1 = lrint(r.endY * v->height()); | 513 int y1 = int(lrint(r.endY * v->height())); |
514 r.pixrect = QRect(r.pixrect.x(), y0, r.pixrect.width(), y1 - y0); | 514 r.pixrect = QRect(r.pixrect.x(), y0, r.pixrect.width(), y1 - y0); |
515 } | 515 } |
516 | 516 |
517 void | 517 void |
518 Layer::setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const | 518 Layer::setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const |
539 } | 539 } |
540 | 540 |
541 Layer::MeasureRectSet::const_iterator | 541 Layer::MeasureRectSet::const_iterator |
542 Layer::findFocusedMeasureRect(QPoint focusPoint) const | 542 Layer::findFocusedMeasureRect(QPoint focusPoint) const |
543 { | 543 { |
544 float frDist = 0; | 544 double frDist = 0; |
545 MeasureRectSet::const_iterator focusRectItr = m_measureRects.end(); | 545 MeasureRectSet::const_iterator focusRectItr = m_measureRects.end(); |
546 | 546 |
547 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); | 547 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); |
548 i != m_measureRects.end(); ++i) { | 548 i != m_measureRects.end(); ++i) { |
549 | 549 |
552 int cx = i->pixrect.x() + i->pixrect.width()/2; | 552 int cx = i->pixrect.x() + i->pixrect.width()/2; |
553 int cy = i->pixrect.y() + i->pixrect.height()/2; | 553 int cy = i->pixrect.y() + i->pixrect.height()/2; |
554 int xd = focusPoint.x() - cx; | 554 int xd = focusPoint.x() - cx; |
555 int yd = focusPoint.y() - cy; | 555 int yd = focusPoint.y() - cy; |
556 | 556 |
557 float d = sqrt(float(xd * xd + yd * yd)); | 557 double d = sqrt(double(xd * xd + yd * yd)); |
558 | 558 |
559 if (focusRectItr == m_measureRects.end() || d < frDist) { | 559 if (focusRectItr == m_measureRects.end() || d < frDist) { |
560 focusRectItr = i; | 560 focusRectItr = i; |
561 frDist = d; | 561 frDist = d; |
562 } | 562 } |