Chris@58
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@30
|
2
|
Chris@30
|
3 /*
|
Chris@59
|
4 Sonic Visualiser
|
Chris@59
|
5 An audio file viewer and annotation editor.
|
Chris@59
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@59
|
7 This file copyright 2006 Chris Cannam.
|
Chris@30
|
8
|
Chris@59
|
9 This program is free software; you can redistribute it and/or
|
Chris@59
|
10 modify it under the terms of the GNU General Public License as
|
Chris@59
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@59
|
12 License, or (at your option) any later version. See the file
|
Chris@59
|
13 COPYING included with this distribution for more information.
|
Chris@30
|
14 */
|
Chris@30
|
15
|
matthiasm@620
|
16 #include "FlexiNoteLayer.h"
|
Chris@30
|
17
|
Chris@128
|
18 #include "data/model/Model.h"
|
Chris@30
|
19 #include "base/RealTime.h"
|
Chris@30
|
20 #include "base/Profiler.h"
|
Chris@30
|
21 #include "base/Pitch.h"
|
Chris@197
|
22 #include "base/LogRange.h"
|
Chris@439
|
23 #include "base/RangeMapper.h"
|
Chris@376
|
24 #include "ColourDatabase.h"
|
Chris@128
|
25 #include "view/View.h"
|
Chris@30
|
26
|
matthiasm@620
|
27 #include "data/model/FlexiNoteModel.h"
|
Chris@30
|
28
|
Chris@70
|
29 #include "widgets/ItemEditDialog.h"
|
Chris@70
|
30
|
Chris@30
|
31 #include <QPainter>
|
Chris@30
|
32 #include <QPainterPath>
|
Chris@30
|
33 #include <QMouseEvent>
|
Chris@316
|
34 #include <QTextStream>
|
Chris@360
|
35 #include <QMessageBox>
|
Chris@30
|
36
|
Chris@30
|
37 #include <iostream>
|
Chris@30
|
38 #include <cmath>
|
Chris@551
|
39 #include <utility>
|
Chris@30
|
40
|
matthiasm@620
|
41 FlexiNoteLayer::FlexiNoteLayer() :
|
gyorgyf@646
|
42 SingleColourLayer(),
|
gyorgyf@625
|
43
|
gyorgyf@646
|
44 // m_model(0),
|
gyorgyf@646
|
45 // m_editing(false),
|
gyorgyf@646
|
46 // m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")),
|
gyorgyf@646
|
47 // m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")),
|
gyorgyf@646
|
48 // m_editingCommand(0),
|
gyorgyf@646
|
49 // m_verticalScale(AutoAlignScale),
|
gyorgyf@646
|
50 // m_scaleMinimum(0),
|
gyorgyf@646
|
51 // m_scaleMaximum(0)
|
gyorgyf@625
|
52
|
gyorgyf@627
|
53 m_model(0),
|
gyorgyf@628
|
54 m_editing(false),
|
gyorgyf@627
|
55 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")),
|
gyorgyf@627
|
56 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")),
|
gyorgyf@627
|
57 m_editingCommand(0),
|
matthiasm@634
|
58 m_verticalScale(AutoAlignScale),
|
gyorgyf@628
|
59 m_scaleMinimum(34),
|
gyorgyf@627
|
60 m_scaleMaximum(77)
|
Chris@30
|
61 {
|
Chris@30
|
62 }
|
Chris@30
|
63
|
Chris@30
|
64 void
|
gyorgyf@626
|
65 FlexiNoteLayer::setModel(FlexiNoteModel *model)
|
Chris@30
|
66 {
|
Chris@30
|
67 if (m_model == model) return;
|
Chris@30
|
68 m_model = model;
|
Chris@30
|
69
|
Chris@320
|
70 connectSignals(m_model);
|
Chris@30
|
71
|
gyorgyf@628
|
72 // m_scaleMinimum = 0;
|
gyorgyf@628
|
73 // m_scaleMaximum = 0;
|
Chris@439
|
74
|
Chris@30
|
75 emit modelReplaced();
|
Chris@30
|
76 }
|
Chris@30
|
77
|
Chris@30
|
78 Layer::PropertyList
|
matthiasm@620
|
79 FlexiNoteLayer::getProperties() const
|
Chris@30
|
80 {
|
Chris@287
|
81 PropertyList list = SingleColourLayer::getProperties();
|
Chris@87
|
82 list.push_back("Vertical Scale");
|
Chris@100
|
83 list.push_back("Scale Units");
|
Chris@30
|
84 return list;
|
Chris@30
|
85 }
|
Chris@30
|
86
|
Chris@87
|
87 QString
|
matthiasm@620
|
88 FlexiNoteLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@87
|
89 {
|
Chris@87
|
90 if (name == "Vertical Scale") return tr("Vertical Scale");
|
Chris@116
|
91 if (name == "Scale Units") return tr("Scale Units");
|
Chris@287
|
92 return SingleColourLayer::getPropertyLabel(name);
|
Chris@87
|
93 }
|
Chris@87
|
94
|
Chris@30
|
95 Layer::PropertyType
|
matthiasm@620
|
96 FlexiNoteLayer::getPropertyType(const PropertyName &name) const
|
Chris@30
|
97 {
|
Chris@100
|
98 if (name == "Scale Units") return UnitsProperty;
|
Chris@287
|
99 if (name == "Vertical Scale") return ValueProperty;
|
Chris@287
|
100 return SingleColourLayer::getPropertyType(name);
|
Chris@30
|
101 }
|
Chris@30
|
102
|
Chris@198
|
103 QString
|
matthiasm@620
|
104 FlexiNoteLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@198
|
105 {
|
Chris@198
|
106 if (name == "Vertical Scale" || name == "Scale Units") {
|
Chris@198
|
107 return tr("Scale");
|
Chris@198
|
108 }
|
Chris@287
|
109 return SingleColourLayer::getPropertyGroupName(name);
|
Chris@198
|
110 }
|
Chris@198
|
111
|
Chris@30
|
112 int
|
matthiasm@620
|
113 FlexiNoteLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
114 int *min, int *max, int *deflt) const
|
Chris@30
|
115 {
|
Chris@216
|
116 int val = 0;
|
Chris@30
|
117
|
Chris@287
|
118 if (name == "Vertical Scale") {
|
gyorgyf@646
|
119
|
gyorgyf@646
|
120 if (min) *min = 0;
|
gyorgyf@646
|
121 if (max) *max = 3;
|
Chris@216
|
122 if (deflt) *deflt = int(AutoAlignScale);
|
gyorgyf@646
|
123
|
gyorgyf@646
|
124 val = int(m_verticalScale);
|
Chris@30
|
125
|
Chris@100
|
126 } else if (name == "Scale Units") {
|
Chris@100
|
127
|
Chris@216
|
128 if (deflt) *deflt = 0;
|
Chris@100
|
129 if (m_model) {
|
Chris@216
|
130 val = UnitDatabase::getInstance()->getUnitId
|
Chris@100
|
131 (m_model->getScaleUnits());
|
Chris@100
|
132 }
|
Chris@100
|
133
|
Chris@30
|
134 } else {
|
Chris@216
|
135
|
gyorgyf@646
|
136 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@30
|
137 }
|
Chris@30
|
138
|
Chris@216
|
139 return val;
|
Chris@30
|
140 }
|
Chris@30
|
141
|
Chris@30
|
142 QString
|
matthiasm@620
|
143 FlexiNoteLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@287
|
144 int value) const
|
Chris@30
|
145 {
|
Chris@287
|
146 if (name == "Vertical Scale") {
|
gyorgyf@646
|
147 switch (value) {
|
gyorgyf@646
|
148 default:
|
gyorgyf@646
|
149 case 0: return tr("Auto-Align");
|
gyorgyf@646
|
150 case 1: return tr("Linear");
|
gyorgyf@646
|
151 case 2: return tr("Log");
|
gyorgyf@646
|
152 case 3: return tr("MIDI Notes");
|
gyorgyf@646
|
153 }
|
Chris@30
|
154 }
|
Chris@287
|
155 return SingleColourLayer::getPropertyValueLabel(name, value);
|
Chris@30
|
156 }
|
Chris@30
|
157
|
Chris@30
|
158 void
|
matthiasm@620
|
159 FlexiNoteLayer::setProperty(const PropertyName &name, int value)
|
Chris@30
|
160 {
|
Chris@287
|
161 if (name == "Vertical Scale") {
|
gyorgyf@646
|
162 setVerticalScale(VerticalScale(value));
|
Chris@100
|
163 } else if (name == "Scale Units") {
|
Chris@100
|
164 if (m_model) {
|
Chris@100
|
165 m_model->setScaleUnits
|
Chris@100
|
166 (UnitDatabase::getInstance()->getUnitById(value));
|
Chris@100
|
167 emit modelChanged();
|
Chris@100
|
168 }
|
Chris@287
|
169 } else {
|
Chris@287
|
170 return SingleColourLayer::setProperty(name, value);
|
Chris@30
|
171 }
|
Chris@30
|
172 }
|
Chris@30
|
173
|
Chris@30
|
174 void
|
matthiasm@620
|
175 FlexiNoteLayer::setVerticalScale(VerticalScale scale)
|
Chris@30
|
176 {
|
Chris@30
|
177 if (m_verticalScale == scale) return;
|
Chris@30
|
178 m_verticalScale = scale;
|
Chris@30
|
179 emit layerParametersChanged();
|
Chris@30
|
180 }
|
Chris@30
|
181
|
Chris@30
|
182 bool
|
matthiasm@620
|
183 FlexiNoteLayer::isLayerScrollable(const View *v) const
|
Chris@30
|
184 {
|
Chris@30
|
185 QPoint discard;
|
Chris@44
|
186 return !v->shouldIlluminateLocalFeatures(this, discard);
|
Chris@30
|
187 }
|
Chris@30
|
188
|
Chris@79
|
189 bool
|
matthiasm@620
|
190 FlexiNoteLayer::shouldConvertMIDIToHz() const
|
Chris@101
|
191 {
|
Chris@101
|
192 QString unit = m_model->getScaleUnits();
|
Chris@101
|
193 return (unit != "Hz");
|
Chris@101
|
194 // if (unit == "" ||
|
Chris@101
|
195 // unit.startsWith("MIDI") ||
|
Chris@101
|
196 // unit.startsWith("midi")) return true;
|
Chris@101
|
197 // return false;
|
Chris@101
|
198 }
|
Chris@101
|
199
|
Chris@101
|
200 bool
|
matthiasm@620
|
201 FlexiNoteLayer::getValueExtents(float &min, float &max,
|
Chris@101
|
202 bool &logarithmic, QString &unit) const
|
Chris@79
|
203 {
|
Chris@79
|
204 if (!m_model) return false;
|
Chris@79
|
205 min = m_model->getValueMinimum();
|
Chris@79
|
206 max = m_model->getValueMaximum();
|
Chris@101
|
207
|
Chris@105
|
208 if (shouldConvertMIDIToHz()) {
|
Chris@105
|
209 unit = "Hz";
|
Chris@105
|
210 min = Pitch::getFrequencyForPitch(lrintf(min));
|
Chris@105
|
211 max = Pitch::getFrequencyForPitch(lrintf(max + 1));
|
Chris@105
|
212 } else unit = m_model->getScaleUnits();
|
Chris@101
|
213
|
Chris@101
|
214 if (m_verticalScale == MIDIRangeScale ||
|
Chris@101
|
215 m_verticalScale == LogScale) logarithmic = true;
|
Chris@101
|
216
|
Chris@101
|
217 return true;
|
Chris@101
|
218 }
|
Chris@101
|
219
|
Chris@101
|
220 bool
|
matthiasm@620
|
221 FlexiNoteLayer::getDisplayExtents(float &min, float &max) const
|
Chris@101
|
222 {
|
matthiasm@623
|
223 if (!m_model || shouldAutoAlign()) {
|
gyorgyf@646
|
224 std::cerr << "No model or shouldAutoAlign()" << std::endl;
|
gyorgyf@646
|
225 return false;
|
gyorgyf@646
|
226 }
|
Chris@101
|
227
|
Chris@101
|
228 if (m_verticalScale == MIDIRangeScale) {
|
Chris@101
|
229 min = Pitch::getFrequencyForPitch(0);
|
matthiasm@634
|
230 max = Pitch::getFrequencyForPitch(127);
|
Chris@101
|
231 return true;
|
Chris@101
|
232 }
|
Chris@101
|
233
|
Chris@439
|
234 if (m_scaleMinimum == m_scaleMaximum) {
|
Chris@455
|
235 min = m_model->getValueMinimum();
|
Chris@455
|
236 max = m_model->getValueMaximum();
|
Chris@455
|
237 } else {
|
Chris@455
|
238 min = m_scaleMinimum;
|
Chris@455
|
239 max = m_scaleMaximum;
|
Chris@439
|
240 }
|
Chris@439
|
241
|
Chris@101
|
242 if (shouldConvertMIDIToHz()) {
|
Chris@101
|
243 min = Pitch::getFrequencyForPitch(lrintf(min));
|
Chris@101
|
244 max = Pitch::getFrequencyForPitch(lrintf(max + 1));
|
Chris@101
|
245 }
|
Chris@101
|
246
|
Chris@79
|
247 return true;
|
Chris@79
|
248 }
|
Chris@79
|
249
|
Chris@439
|
250 bool
|
matthiasm@620
|
251 FlexiNoteLayer::setDisplayExtents(float min, float max)
|
Chris@439
|
252 {
|
Chris@439
|
253 if (!m_model) return false;
|
Chris@439
|
254
|
Chris@439
|
255 if (min == max) {
|
Chris@439
|
256 if (min == 0.f) {
|
Chris@439
|
257 max = 1.f;
|
Chris@439
|
258 } else {
|
Chris@439
|
259 max = min * 1.0001;
|
Chris@439
|
260 }
|
Chris@439
|
261 }
|
Chris@439
|
262
|
Chris@439
|
263 m_scaleMinimum = min;
|
Chris@439
|
264 m_scaleMaximum = max;
|
Chris@439
|
265
|
matthiasm@620
|
266 // SVDEBUG << "FlexiNoteLayer::setDisplayExtents: min = " << min << ", max = " << max << endl;
|
Chris@439
|
267
|
Chris@439
|
268 emit layerParametersChanged();
|
Chris@439
|
269 return true;
|
Chris@439
|
270 }
|
Chris@439
|
271
|
Chris@439
|
272 int
|
matthiasm@620
|
273 FlexiNoteLayer::getVerticalZoomSteps(int &defaultStep) const
|
Chris@439
|
274 {
|
Chris@439
|
275 if (shouldAutoAlign()) return 0;
|
Chris@439
|
276 if (!m_model) return 0;
|
Chris@439
|
277
|
Chris@439
|
278 defaultStep = 0;
|
Chris@439
|
279 return 100;
|
Chris@439
|
280 }
|
Chris@439
|
281
|
Chris@439
|
282 int
|
matthiasm@620
|
283 FlexiNoteLayer::getCurrentVerticalZoomStep() const
|
Chris@439
|
284 {
|
Chris@439
|
285 if (shouldAutoAlign()) return 0;
|
Chris@439
|
286 if (!m_model) return 0;
|
Chris@439
|
287
|
Chris@439
|
288 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
|
Chris@439
|
289 if (!mapper) return 0;
|
Chris@439
|
290
|
Chris@439
|
291 float dmin, dmax;
|
Chris@439
|
292 getDisplayExtents(dmin, dmax);
|
Chris@439
|
293
|
Chris@439
|
294 int nr = mapper->getPositionForValue(dmax - dmin);
|
Chris@439
|
295
|
Chris@439
|
296 delete mapper;
|
Chris@439
|
297
|
Chris@439
|
298 return 100 - nr;
|
Chris@439
|
299 }
|
Chris@439
|
300
|
Chris@439
|
301 //!!! lots of duplication with TimeValueLayer
|
Chris@439
|
302
|
Chris@439
|
303 void
|
matthiasm@620
|
304 FlexiNoteLayer::setVerticalZoomStep(int step)
|
Chris@439
|
305 {
|
Chris@439
|
306 if (shouldAutoAlign()) return;
|
Chris@439
|
307 if (!m_model) return;
|
Chris@439
|
308
|
Chris@439
|
309 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
|
Chris@439
|
310 if (!mapper) return;
|
Chris@439
|
311
|
Chris@439
|
312 float min, max;
|
Chris@439
|
313 bool logarithmic;
|
Chris@439
|
314 QString unit;
|
Chris@439
|
315 getValueExtents(min, max, logarithmic, unit);
|
Chris@439
|
316
|
Chris@439
|
317 float dmin, dmax;
|
Chris@439
|
318 getDisplayExtents(dmin, dmax);
|
Chris@439
|
319
|
Chris@439
|
320 float newdist = mapper->getValueForPosition(100 - step);
|
Chris@439
|
321
|
Chris@439
|
322 float newmin, newmax;
|
Chris@439
|
323
|
Chris@439
|
324 if (logarithmic) {
|
Chris@439
|
325
|
Chris@439
|
326 // see SpectrogramLayer::setVerticalZoomStep
|
Chris@439
|
327
|
Chris@439
|
328 newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2;
|
Chris@439
|
329 newmin = newmax - newdist;
|
Chris@439
|
330
|
Chris@439
|
331 // std::cerr << "newmin = " << newmin << ", newmax = " << newmax << std::endl;
|
Chris@439
|
332
|
Chris@439
|
333 } else {
|
Chris@439
|
334 float dmid = (dmax + dmin) / 2;
|
Chris@439
|
335 newmin = dmid - newdist / 2;
|
Chris@439
|
336 newmax = dmid + newdist / 2;
|
Chris@439
|
337 }
|
Chris@439
|
338
|
Chris@439
|
339 if (newmin < min) {
|
Chris@439
|
340 newmax += (min - newmin);
|
Chris@439
|
341 newmin = min;
|
Chris@439
|
342 }
|
Chris@439
|
343 if (newmax > max) {
|
Chris@439
|
344 newmax = max;
|
Chris@439
|
345 }
|
Chris@439
|
346
|
matthiasm@620
|
347 SVDEBUG << "FlexiNoteLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl;
|
Chris@439
|
348
|
Chris@439
|
349 setDisplayExtents(newmin, newmax);
|
Chris@439
|
350 }
|
Chris@439
|
351
|
Chris@439
|
352 RangeMapper *
|
matthiasm@620
|
353 FlexiNoteLayer::getNewVerticalZoomRangeMapper() const
|
Chris@439
|
354 {
|
Chris@439
|
355 if (!m_model) return 0;
|
Chris@439
|
356
|
Chris@439
|
357 RangeMapper *mapper;
|
Chris@439
|
358
|
Chris@439
|
359 float min, max;
|
Chris@439
|
360 bool logarithmic;
|
Chris@439
|
361 QString unit;
|
Chris@439
|
362 getValueExtents(min, max, logarithmic, unit);
|
Chris@439
|
363
|
Chris@439
|
364 if (min == max) return 0;
|
Chris@439
|
365
|
Chris@439
|
366 if (logarithmic) {
|
Chris@439
|
367 mapper = new LogRangeMapper(0, 100, min, max, unit);
|
Chris@439
|
368 } else {
|
Chris@439
|
369 mapper = new LinearRangeMapper(0, 100, min, max, unit);
|
Chris@439
|
370 }
|
Chris@439
|
371
|
Chris@439
|
372 return mapper;
|
Chris@439
|
373 }
|
Chris@439
|
374
|
matthiasm@620
|
375 FlexiNoteModel::PointList
|
matthiasm@620
|
376 FlexiNoteLayer::getLocalPoints(View *v, int x) const
|
Chris@30
|
377 {
|
matthiasm@620
|
378 if (!m_model) return FlexiNoteModel::PointList();
|
Chris@30
|
379
|
Chris@44
|
380 long frame = v->getFrameForX(x);
|
Chris@30
|
381
|
matthiasm@620
|
382 FlexiNoteModel::PointList onPoints =
|
gyorgyf@646
|
383 m_model->getPoints(frame);
|
Chris@30
|
384
|
Chris@30
|
385 if (!onPoints.empty()) {
|
gyorgyf@646
|
386 return onPoints;
|
Chris@30
|
387 }
|
Chris@30
|
388
|
matthiasm@620
|
389 FlexiNoteModel::PointList prevPoints =
|
gyorgyf@646
|
390 m_model->getPreviousPoints(frame);
|
matthiasm@620
|
391 FlexiNoteModel::PointList nextPoints =
|
gyorgyf@646
|
392 m_model->getNextPoints(frame);
|
Chris@30
|
393
|
matthiasm@620
|
394 FlexiNoteModel::PointList usePoints = prevPoints;
|
Chris@30
|
395
|
Chris@30
|
396 if (prevPoints.empty()) {
|
gyorgyf@646
|
397 usePoints = nextPoints;
|
Chris@248
|
398 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() &&
|
gyorgyf@646
|
399 !(nextPoints.begin()->frame > v->getEndFrame())) {
|
gyorgyf@646
|
400 usePoints = nextPoints;
|
Chris@248
|
401 } else if (long(nextPoints.begin()->frame) - frame <
|
gyorgyf@646
|
402 frame - long(prevPoints.begin()->frame)) {
|
gyorgyf@646
|
403 usePoints = nextPoints;
|
Chris@30
|
404 }
|
Chris@30
|
405
|
Chris@30
|
406 if (!usePoints.empty()) {
|
gyorgyf@646
|
407 int fuzz = 2;
|
gyorgyf@646
|
408 int px = v->getXForFrame(usePoints.begin()->frame);
|
gyorgyf@646
|
409 if ((px > x && px - x > fuzz) ||
|
gyorgyf@646
|
410 (px < x && x - px > fuzz + 1)) {
|
gyorgyf@646
|
411 usePoints.clear();
|
gyorgyf@646
|
412 }
|
Chris@30
|
413 }
|
Chris@30
|
414
|
Chris@30
|
415 return usePoints;
|
Chris@30
|
416 }
|
Chris@30
|
417
|
Chris@550
|
418 bool
|
matthiasm@622
|
419 FlexiNoteLayer::getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &p) const
|
Chris@550
|
420 {
|
Chris@550
|
421 if (!m_model) return false;
|
Chris@550
|
422
|
Chris@550
|
423 long frame = v->getFrameForX(x);
|
Chris@550
|
424
|
matthiasm@620
|
425 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
|
Chris@550
|
426 if (onPoints.empty()) return false;
|
Chris@550
|
427
|
Chris@551
|
428 // std::cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << std::endl;
|
Chris@550
|
429
|
Chris@550
|
430 int nearestDistance = -1;
|
Chris@550
|
431
|
matthiasm@620
|
432 for (FlexiNoteModel::PointList::const_iterator i = onPoints.begin();
|
Chris@550
|
433 i != onPoints.end(); ++i) {
|
Chris@550
|
434
|
Chris@550
|
435 int distance = getYForValue(v, (*i).value) - y;
|
Chris@550
|
436 if (distance < 0) distance = -distance;
|
Chris@550
|
437 if (nearestDistance == -1 || distance < nearestDistance) {
|
Chris@550
|
438 nearestDistance = distance;
|
Chris@550
|
439 p = *i;
|
Chris@550
|
440 }
|
Chris@550
|
441 }
|
Chris@550
|
442
|
Chris@550
|
443 return true;
|
Chris@550
|
444 }
|
Chris@550
|
445
|
gyorgyf@646
|
446 bool
|
gyorgyf@646
|
447 FlexiNoteLayer::getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &p) const
|
gyorgyf@646
|
448 {
|
gyorgyf@646
|
449 if (!m_model) return false;
|
gyorgyf@646
|
450
|
gyorgyf@646
|
451 long frame = v->getFrameForX(x);
|
gyorgyf@646
|
452
|
gyorgyf@646
|
453 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
|
gyorgyf@646
|
454 if (onPoints.empty()) return false;
|
gyorgyf@646
|
455
|
gyorgyf@646
|
456 // std::cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << std::endl;
|
gyorgyf@646
|
457
|
gyorgyf@646
|
458 int nearestDistance = -1;
|
gyorgyf@646
|
459
|
gyorgyf@646
|
460 for (FlexiNoteModel::PointList::const_iterator i = onPoints.begin();
|
gyorgyf@646
|
461 i != onPoints.end(); ++i) {
|
gyorgyf@646
|
462
|
gyorgyf@646
|
463 int distance = getYForValue(v, (*i).value) - y;
|
gyorgyf@646
|
464 if (distance < 0) distance = -distance;
|
gyorgyf@646
|
465 if (nearestDistance == -1 || distance < nearestDistance) {
|
gyorgyf@646
|
466 nearestDistance = distance;
|
gyorgyf@646
|
467 p = *i;
|
gyorgyf@646
|
468 }
|
gyorgyf@646
|
469 }
|
gyorgyf@646
|
470
|
gyorgyf@646
|
471 return true;
|
gyorgyf@646
|
472 }
|
gyorgyf@646
|
473
|
Chris@30
|
474 QString
|
matthiasm@620
|
475 FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const
|
Chris@30
|
476 {
|
Chris@30
|
477 int x = pos.x();
|
Chris@30
|
478
|
Chris@30
|
479 if (!m_model || !m_model->getSampleRate()) return "";
|
Chris@30
|
480
|
matthiasm@620
|
481 FlexiNoteModel::PointList points = getLocalPoints(v, x);
|
Chris@30
|
482
|
Chris@30
|
483 if (points.empty()) {
|
gyorgyf@646
|
484 if (!m_model->isReady()) {
|
gyorgyf@646
|
485 return tr("In progress");
|
gyorgyf@646
|
486 } else {
|
gyorgyf@646
|
487 return tr("No local points");
|
gyorgyf@646
|
488 }
|
Chris@30
|
489 }
|
Chris@30
|
490
|
matthiasm@620
|
491 FlexiNote note(0);
|
matthiasm@620
|
492 FlexiNoteModel::PointList::iterator i;
|
Chris@30
|
493
|
Chris@30
|
494 for (i = points.begin(); i != points.end(); ++i) {
|
Chris@30
|
495
|
gyorgyf@646
|
496 int y = getYForValue(v, i->value);
|
gyorgyf@646
|
497 int h = 3;
|
Chris@30
|
498
|
gyorgyf@646
|
499 if (m_model->getValueQuantization() != 0.0) {
|
gyorgyf@646
|
500 h = y - getYForValue(v, i->value + m_model->getValueQuantization());
|
gyorgyf@646
|
501 if (h < 3) h = 3;
|
gyorgyf@646
|
502 }
|
Chris@30
|
503
|
gyorgyf@646
|
504 if (pos.y() >= y - h && pos.y() <= y) {
|
gyorgyf@646
|
505 note = *i;
|
gyorgyf@646
|
506 break;
|
gyorgyf@646
|
507 }
|
Chris@30
|
508 }
|
Chris@30
|
509
|
Chris@30
|
510 if (i == points.end()) return tr("No local points");
|
Chris@30
|
511
|
Chris@30
|
512 RealTime rt = RealTime::frame2RealTime(note.frame,
|
gyorgyf@646
|
513 m_model->getSampleRate());
|
Chris@30
|
514 RealTime rd = RealTime::frame2RealTime(note.duration,
|
gyorgyf@646
|
515 m_model->getSampleRate());
|
Chris@30
|
516
|
Chris@101
|
517 QString pitchText;
|
Chris@101
|
518
|
Chris@101
|
519 if (shouldConvertMIDIToHz()) {
|
Chris@101
|
520
|
Chris@101
|
521 int mnote = lrintf(note.value);
|
Chris@101
|
522 int cents = lrintf((note.value - mnote) * 100);
|
Chris@101
|
523 float freq = Pitch::getFrequencyForPitch(mnote, cents);
|
Chris@544
|
524 pitchText = tr("%1 (%2, %3 Hz)")
|
Chris@544
|
525 .arg(Pitch::getPitchLabel(mnote, cents))
|
Chris@544
|
526 .arg(mnote)
|
Chris@544
|
527 .arg(freq);
|
Chris@101
|
528
|
Chris@101
|
529 } else if (m_model->getScaleUnits() == "Hz") {
|
Chris@101
|
530
|
Chris@544
|
531 pitchText = tr("%1 Hz (%2, %3)")
|
Chris@101
|
532 .arg(note.value)
|
Chris@544
|
533 .arg(Pitch::getPitchLabelForFrequency(note.value))
|
Chris@544
|
534 .arg(Pitch::getPitchForFrequency(note.value));
|
Chris@101
|
535
|
Chris@101
|
536 } else {
|
Chris@234
|
537 pitchText = tr("%1 %2")
|
Chris@101
|
538 .arg(note.value).arg(m_model->getScaleUnits());
|
Chris@101
|
539 }
|
Chris@101
|
540
|
Chris@30
|
541 QString text;
|
Chris@30
|
542
|
Chris@30
|
543 if (note.label == "") {
|
gyorgyf@646
|
544 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nNo label"))
|
gyorgyf@646
|
545 .arg(rt.toText(true).c_str())
|
gyorgyf@646
|
546 .arg(pitchText)
|
gyorgyf@646
|
547 .arg(rd.toText(true).c_str());
|
Chris@30
|
548 } else {
|
gyorgyf@646
|
549 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nLabel:\t%4"))
|
gyorgyf@646
|
550 .arg(rt.toText(true).c_str())
|
gyorgyf@646
|
551 .arg(pitchText)
|
gyorgyf@646
|
552 .arg(rd.toText(true).c_str())
|
gyorgyf@646
|
553 .arg(note.label);
|
Chris@30
|
554 }
|
Chris@30
|
555
|
Chris@44
|
556 pos = QPoint(v->getXForFrame(note.frame),
|
gyorgyf@646
|
557 getYForValue(v, note.value));
|
Chris@30
|
558 return text;
|
Chris@30
|
559 }
|
Chris@30
|
560
|
Chris@30
|
561 bool
|
matthiasm@620
|
562 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame,
|
gyorgyf@646
|
563 size_t &resolution,
|
gyorgyf@646
|
564 SnapType snap) const
|
Chris@30
|
565 {
|
Chris@30
|
566 if (!m_model) {
|
gyorgyf@646
|
567 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
|
Chris@30
|
568 }
|
Chris@30
|
569
|
Chris@30
|
570 resolution = m_model->getResolution();
|
matthiasm@620
|
571 FlexiNoteModel::PointList points;
|
Chris@30
|
572
|
Chris@30
|
573 if (snap == SnapNeighbouring) {
|
gyorgyf@646
|
574
|
gyorgyf@646
|
575 points = getLocalPoints(v, v->getXForFrame(frame));
|
gyorgyf@646
|
576 if (points.empty()) return false;
|
gyorgyf@646
|
577 frame = points.begin()->frame;
|
gyorgyf@646
|
578 return true;
|
Chris@30
|
579 }
|
Chris@30
|
580
|
Chris@30
|
581 points = m_model->getPoints(frame, frame);
|
Chris@30
|
582 int snapped = frame;
|
Chris@30
|
583 bool found = false;
|
Chris@30
|
584
|
matthiasm@620
|
585 for (FlexiNoteModel::PointList::const_iterator i = points.begin();
|
gyorgyf@646
|
586 i != points.end(); ++i) {
|
Chris@30
|
587
|
gyorgyf@646
|
588 if (snap == SnapRight) {
|
Chris@30
|
589
|
gyorgyf@646
|
590 if (i->frame > frame) {
|
gyorgyf@646
|
591 snapped = i->frame;
|
gyorgyf@646
|
592 found = true;
|
gyorgyf@646
|
593 break;
|
gyorgyf@646
|
594 }
|
Chris@30
|
595
|
gyorgyf@646
|
596 } else if (snap == SnapLeft) {
|
Chris@30
|
597
|
gyorgyf@646
|
598 if (i->frame <= frame) {
|
gyorgyf@646
|
599 snapped = i->frame;
|
gyorgyf@646
|
600 found = true; // don't break, as the next may be better
|
gyorgyf@646
|
601 } else {
|
gyorgyf@646
|
602 break;
|
gyorgyf@646
|
603 }
|
Chris@30
|
604
|
gyorgyf@646
|
605 } else { // nearest
|
Chris@30
|
606
|
gyorgyf@646
|
607 FlexiNoteModel::PointList::const_iterator j = i;
|
gyorgyf@646
|
608 ++j;
|
Chris@30
|
609
|
gyorgyf@646
|
610 if (j == points.end()) {
|
Chris@30
|
611
|
gyorgyf@646
|
612 snapped = i->frame;
|
gyorgyf@646
|
613 found = true;
|
gyorgyf@646
|
614 break;
|
Chris@30
|
615
|
gyorgyf@646
|
616 } else if (j->frame >= frame) {
|
Chris@30
|
617
|
gyorgyf@646
|
618 if (j->frame - frame < frame - i->frame) {
|
gyorgyf@646
|
619 snapped = j->frame;
|
gyorgyf@646
|
620 } else {
|
gyorgyf@646
|
621 snapped = i->frame;
|
gyorgyf@646
|
622 }
|
gyorgyf@646
|
623 found = true;
|
gyorgyf@646
|
624 break;
|
gyorgyf@646
|
625 }
|
gyorgyf@646
|
626 }
|
Chris@30
|
627 }
|
Chris@30
|
628
|
Chris@30
|
629 frame = snapped;
|
Chris@30
|
630 return found;
|
Chris@30
|
631 }
|
Chris@30
|
632
|
Chris@101
|
633 void
|
matthiasm@620
|
634 FlexiNoteLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const
|
Chris@30
|
635 {
|
Chris@101
|
636 min = 0.0;
|
Chris@101
|
637 max = 0.0;
|
Chris@101
|
638 log = false;
|
Chris@42
|
639
|
Chris@101
|
640 QString queryUnits;
|
Chris@101
|
641 if (shouldConvertMIDIToHz()) queryUnits = "Hz";
|
Chris@101
|
642 else queryUnits = m_model->getScaleUnits();
|
Chris@30
|
643
|
Chris@439
|
644 if (shouldAutoAlign()) {
|
Chris@30
|
645
|
Chris@101
|
646 if (!v->getValueExtents(queryUnits, min, max, log)) {
|
Chris@30
|
647
|
Chris@101
|
648 min = m_model->getValueMinimum();
|
Chris@101
|
649 max = m_model->getValueMaximum();
|
Chris@42
|
650
|
Chris@101
|
651 if (shouldConvertMIDIToHz()) {
|
Chris@101
|
652 min = Pitch::getFrequencyForPitch(lrintf(min));
|
Chris@101
|
653 max = Pitch::getFrequencyForPitch(lrintf(max + 1));
|
Chris@101
|
654 }
|
Chris@42
|
655
|
gyorgyf@635
|
656 // std::cerr << "FlexiNoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl;
|
Chris@105
|
657
|
Chris@101
|
658 } else if (log) {
|
Chris@101
|
659
|
Chris@197
|
660 LogRange::mapRange(min, max);
|
Chris@105
|
661
|
gyorgyf@635
|
662 // std::cerr << "FlexiNoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl;
|
Chris@105
|
663
|
Chris@101
|
664 }
|
Chris@101
|
665
|
Chris@101
|
666 } else {
|
Chris@101
|
667
|
Chris@439
|
668 getDisplayExtents(min, max);
|
Chris@101
|
669
|
Chris@101
|
670 if (m_verticalScale == MIDIRangeScale) {
|
Chris@101
|
671 min = Pitch::getFrequencyForPitch(0);
|
matthiasm@623
|
672 max = Pitch::getFrequencyForPitch(70);
|
Chris@101
|
673 } else if (shouldConvertMIDIToHz()) {
|
Chris@101
|
674 min = Pitch::getFrequencyForPitch(lrintf(min));
|
Chris@101
|
675 max = Pitch::getFrequencyForPitch(lrintf(max + 1));
|
Chris@101
|
676 }
|
Chris@101
|
677
|
Chris@101
|
678 if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) {
|
Chris@197
|
679 LogRange::mapRange(min, max);
|
Chris@101
|
680 log = true;
|
Chris@101
|
681 }
|
Chris@30
|
682 }
|
Chris@30
|
683
|
Chris@101
|
684 if (max == min) max = min + 1.0;
|
Chris@101
|
685 }
|
Chris@30
|
686
|
Chris@101
|
687 int
|
matthiasm@620
|
688 FlexiNoteLayer::getYForValue(View *v, float val) const
|
Chris@101
|
689 {
|
Chris@101
|
690 float min = 0.0, max = 0.0;
|
Chris@101
|
691 bool logarithmic = false;
|
Chris@101
|
692 int h = v->height();
|
Chris@101
|
693
|
Chris@101
|
694 getScaleExtents(v, min, max, logarithmic);
|
Chris@101
|
695
|
matthiasm@620
|
696 // std::cerr << "FlexiNoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl;
|
Chris@101
|
697
|
Chris@101
|
698 if (shouldConvertMIDIToHz()) {
|
Chris@101
|
699 val = Pitch::getFrequencyForPitch(lrintf(val),
|
Chris@101
|
700 lrintf((val - lrintf(val)) * 100));
|
Chris@101
|
701 // std::cerr << "shouldConvertMIDIToHz true, val now = " << val << std::endl;
|
Chris@101
|
702 }
|
Chris@101
|
703
|
Chris@101
|
704 if (logarithmic) {
|
Chris@197
|
705 val = LogRange::map(val);
|
Chris@101
|
706 // std::cerr << "logarithmic true, val now = " << val << std::endl;
|
Chris@101
|
707 }
|
Chris@101
|
708
|
Chris@101
|
709 int y = int(h - ((val - min) * h) / (max - min)) - 1;
|
Chris@101
|
710 // std::cerr << "y = " << y << std::endl;
|
Chris@101
|
711 return y;
|
Chris@30
|
712 }
|
Chris@30
|
713
|
Chris@30
|
714 float
|
matthiasm@620
|
715 FlexiNoteLayer::getValueForY(View *v, int y) const
|
Chris@30
|
716 {
|
Chris@101
|
717 float min = 0.0, max = 0.0;
|
Chris@101
|
718 bool logarithmic = false;
|
Chris@44
|
719 int h = v->height();
|
Chris@30
|
720
|
Chris@101
|
721 getScaleExtents(v, min, max, logarithmic);
|
Chris@101
|
722
|
Chris@101
|
723 float val = min + (float(h - y) * float(max - min)) / h;
|
Chris@101
|
724
|
Chris@101
|
725 if (logarithmic) {
|
Chris@197
|
726 val = powf(10.f, val);
|
Chris@101
|
727 }
|
Chris@101
|
728
|
Chris@101
|
729 if (shouldConvertMIDIToHz()) {
|
Chris@101
|
730 val = Pitch::getPitchForFrequency(val);
|
Chris@101
|
731 }
|
Chris@101
|
732
|
Chris@101
|
733 return val;
|
Chris@30
|
734 }
|
Chris@30
|
735
|
Chris@439
|
736 bool
|
matthiasm@620
|
737 FlexiNoteLayer::shouldAutoAlign() const
|
Chris@439
|
738 {
|
Chris@439
|
739 if (!m_model) return false;
|
Chris@439
|
740 return (m_verticalScale == AutoAlignScale);
|
Chris@439
|
741 }
|
Chris@439
|
742
|
Chris@30
|
743 void
|
matthiasm@620
|
744 FlexiNoteLayer::paint(View *v, QPainter &paint, QRect rect) const
|
Chris@30
|
745 {
|
Chris@30
|
746 if (!m_model || !m_model->isOK()) return;
|
Chris@30
|
747
|
Chris@30
|
748 int sampleRate = m_model->getSampleRate();
|
Chris@30
|
749 if (!sampleRate) return;
|
Chris@30
|
750
|
matthiasm@620
|
751 // Profiler profiler("FlexiNoteLayer::paint", true);
|
Chris@30
|
752
|
Chris@30
|
753 int x0 = rect.left(), x1 = rect.right();
|
Chris@44
|
754 long frame0 = v->getFrameForX(x0);
|
Chris@44
|
755 long frame1 = v->getFrameForX(x1);
|
Chris@30
|
756
|
matthiasm@620
|
757 FlexiNoteModel::PointList points(m_model->getPoints(frame0, frame1));
|
Chris@30
|
758 if (points.empty()) return;
|
Chris@30
|
759
|
Chris@287
|
760 paint.setPen(getBaseQColor());
|
Chris@30
|
761
|
Chris@287
|
762 QColor brushColour(getBaseQColor());
|
Chris@30
|
763 brushColour.setAlpha(80);
|
Chris@30
|
764
|
matthiasm@620
|
765 // SVDEBUG << "FlexiNoteLayer::paint: resolution is "
|
gyorgyf@646
|
766 // << m_model->getResolution() << " frames" << endl;
|
Chris@30
|
767
|
Chris@30
|
768 float min = m_model->getValueMinimum();
|
Chris@30
|
769 float max = m_model->getValueMaximum();
|
Chris@30
|
770 if (max == min) max = min + 1.0;
|
Chris@30
|
771
|
Chris@30
|
772 QPoint localPos;
|
matthiasm@620
|
773 FlexiNoteModel::Point illuminatePoint(0);
|
Chris@551
|
774 bool shouldIlluminate = false;
|
Chris@30
|
775
|
Chris@44
|
776 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
|
Chris@551
|
777 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(),
|
Chris@551
|
778 illuminatePoint);
|
Chris@30
|
779 }
|
Chris@30
|
780
|
Chris@30
|
781 paint.save();
|
Chris@30
|
782 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@30
|
783
|
matthiasm@620
|
784 for (FlexiNoteModel::PointList::const_iterator i = points.begin();
|
gyorgyf@646
|
785 i != points.end(); ++i) {
|
Chris@30
|
786
|
gyorgyf@646
|
787 const FlexiNoteModel::Point &p(*i);
|
Chris@30
|
788
|
gyorgyf@646
|
789 int x = v->getXForFrame(p.frame);
|
gyorgyf@646
|
790 int y = getYForValue(v, p.value);
|
gyorgyf@646
|
791 int w = v->getXForFrame(p.frame + p.duration) - x;
|
gyorgyf@646
|
792 int h = 8; //GF: larger notes
|
gyorgyf@646
|
793
|
gyorgyf@646
|
794 if (m_model->getValueQuantization() != 0.0) {
|
gyorgyf@646
|
795 h = y - getYForValue(v, p.value + m_model->getValueQuantization());
|
gyorgyf@646
|
796 if (h < 3) h = 8; //GF: larger notes
|
gyorgyf@646
|
797 }
|
Chris@30
|
798
|
gyorgyf@646
|
799 if (w < 1) w = 1;
|
gyorgyf@646
|
800 paint.setPen(getBaseQColor());
|
gyorgyf@646
|
801 paint.setBrush(brushColour);
|
Chris@30
|
802
|
gyorgyf@646
|
803 if (shouldIlluminate &&
|
Chris@551
|
804 // "illuminatePoint == p"
|
matthiasm@620
|
805 !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) &&
|
matthiasm@620
|
806 !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) {
|
Chris@551
|
807
|
Chris@551
|
808 paint.setPen(v->getForeground());
|
Chris@551
|
809 paint.setBrush(v->getForeground());
|
Chris@551
|
810
|
Chris@551
|
811 QString vlabel = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits());
|
Chris@551
|
812 v->drawVisibleText(paint,
|
Chris@551
|
813 x - paint.fontMetrics().width(vlabel) - 2,
|
Chris@551
|
814 y + paint.fontMetrics().height()/2
|
Chris@551
|
815 - paint.fontMetrics().descent(),
|
Chris@551
|
816 vlabel, View::OutlinedText);
|
Chris@551
|
817
|
Chris@551
|
818 QString hlabel = RealTime::frame2RealTime
|
Chris@551
|
819 (p.frame, m_model->getSampleRate()).toText(true).c_str();
|
Chris@551
|
820 v->drawVisibleText(paint,
|
Chris@551
|
821 x,
|
Chris@551
|
822 y - h/2 - paint.fontMetrics().descent() - 2,
|
Chris@551
|
823 hlabel, View::OutlinedText);
|
gyorgyf@646
|
824 }
|
gyorgyf@646
|
825
|
gyorgyf@646
|
826 paint.drawRect(x, y - h/2, w, h);
|
Chris@30
|
827 }
|
Chris@30
|
828
|
Chris@30
|
829 paint.restore();
|
Chris@30
|
830 }
|
Chris@30
|
831
|
Chris@30
|
832 void
|
matthiasm@620
|
833 FlexiNoteLayer::drawStart(View *v, QMouseEvent *e)
|
Chris@30
|
834 {
|
matthiasm@620
|
835 // SVDEBUG << "FlexiNoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl;
|
Chris@30
|
836
|
Chris@30
|
837 if (!m_model) return;
|
Chris@30
|
838
|
Chris@44
|
839 long frame = v->getFrameForX(e->x());
|
Chris@30
|
840 if (frame < 0) frame = 0;
|
Chris@30
|
841 frame = frame / m_model->getResolution() * m_model->getResolution();
|
Chris@30
|
842
|
Chris@44
|
843 float value = getValueForY(v, e->y());
|
Chris@30
|
844
|
matthiasm@620
|
845 m_editingPoint = FlexiNoteModel::Point(frame, value, 0, 0.8, tr("New Point"));
|
Chris@30
|
846 m_originalPoint = m_editingPoint;
|
Chris@30
|
847
|
Chris@376
|
848 if (m_editingCommand) finish(m_editingCommand);
|
matthiasm@620
|
849 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
|
gyorgyf@646
|
850 tr("Draw Point"));
|
Chris@30
|
851 m_editingCommand->addPoint(m_editingPoint);
|
Chris@30
|
852
|
Chris@30
|
853 m_editing = true;
|
Chris@30
|
854 }
|
Chris@30
|
855
|
Chris@30
|
856 void
|
matthiasm@620
|
857 FlexiNoteLayer::drawDrag(View *v, QMouseEvent *e)
|
Chris@30
|
858 {
|
matthiasm@620
|
859 // SVDEBUG << "FlexiNoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl;
|
Chris@30
|
860
|
Chris@30
|
861 if (!m_model || !m_editing) return;
|
Chris@30
|
862
|
Chris@44
|
863 long frame = v->getFrameForX(e->x());
|
Chris@30
|
864 if (frame < 0) frame = 0;
|
Chris@30
|
865 frame = frame / m_model->getResolution() * m_model->getResolution();
|
Chris@30
|
866
|
Chris@101
|
867 float newValue = getValueForY(v, e->y());
|
Chris@101
|
868
|
Chris@101
|
869 long newFrame = m_editingPoint.frame;
|
Chris@101
|
870 long newDuration = frame - newFrame;
|
Chris@101
|
871 if (newDuration < 0) {
|
Chris@101
|
872 newFrame = frame;
|
Chris@101
|
873 newDuration = -newDuration;
|
Chris@101
|
874 } else if (newDuration == 0) {
|
Chris@101
|
875 newDuration = 1;
|
Chris@101
|
876 }
|
Chris@30
|
877
|
Chris@30
|
878 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@101
|
879 m_editingPoint.frame = newFrame;
|
Chris@101
|
880 m_editingPoint.value = newValue;
|
Chris@101
|
881 m_editingPoint.duration = newDuration;
|
Chris@30
|
882 m_editingCommand->addPoint(m_editingPoint);
|
Chris@30
|
883 }
|
Chris@30
|
884
|
Chris@30
|
885 void
|
matthiasm@620
|
886 FlexiNoteLayer::drawEnd(View *, QMouseEvent *)
|
Chris@30
|
887 {
|
matthiasm@620
|
888 // SVDEBUG << "FlexiNoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl;
|
Chris@30
|
889 if (!m_model || !m_editing) return;
|
Chris@376
|
890 finish(m_editingCommand);
|
Chris@30
|
891 m_editingCommand = 0;
|
Chris@30
|
892 m_editing = false;
|
Chris@30
|
893 }
|
Chris@30
|
894
|
Chris@30
|
895 void
|
matthiasm@620
|
896 FlexiNoteLayer::eraseStart(View *v, QMouseEvent *e)
|
Chris@335
|
897 {
|
Chris@335
|
898 if (!m_model) return;
|
Chris@335
|
899
|
Chris@550
|
900 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
|
Chris@335
|
901
|
Chris@335
|
902 if (m_editingCommand) {
|
gyorgyf@646
|
903 finish(m_editingCommand);
|
gyorgyf@646
|
904 m_editingCommand = 0;
|
Chris@335
|
905 }
|
Chris@335
|
906
|
Chris@335
|
907 m_editing = true;
|
Chris@335
|
908 }
|
Chris@335
|
909
|
Chris@335
|
910 void
|
matthiasm@620
|
911 FlexiNoteLayer::eraseDrag(View *v, QMouseEvent *e)
|
Chris@335
|
912 {
|
Chris@335
|
913 }
|
Chris@335
|
914
|
Chris@335
|
915 void
|
matthiasm@620
|
916 FlexiNoteLayer::eraseEnd(View *v, QMouseEvent *e)
|
Chris@335
|
917 {
|
Chris@335
|
918 if (!m_model || !m_editing) return;
|
Chris@335
|
919
|
Chris@335
|
920 m_editing = false;
|
Chris@335
|
921
|
matthiasm@620
|
922 FlexiNoteModel::Point p(0);
|
Chris@550
|
923 if (!getPointToDrag(v, e->x(), e->y(), p)) return;
|
Chris@550
|
924 if (p.frame != m_editingPoint.frame || p.value != m_editingPoint.value) return;
|
Chris@550
|
925
|
matthiasm@620
|
926 m_editingCommand = new FlexiNoteModel::EditCommand(m_model, tr("Erase Point"));
|
Chris@335
|
927
|
Chris@335
|
928 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@335
|
929
|
Chris@376
|
930 finish(m_editingCommand);
|
Chris@335
|
931 m_editingCommand = 0;
|
Chris@335
|
932 m_editing = false;
|
Chris@335
|
933 }
|
Chris@335
|
934
|
Chris@335
|
935 void
|
matthiasm@620
|
936 FlexiNoteLayer::editStart(View *v, QMouseEvent *e)
|
Chris@30
|
937 {
|
matthiasm@620
|
938 // SVDEBUG << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl;
|
gyorgyf@635
|
939 std::cerr << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@30
|
940
|
Chris@30
|
941 if (!m_model) return;
|
Chris@30
|
942
|
Chris@550
|
943 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
|
Chris@30
|
944 m_originalPoint = m_editingPoint;
|
Chris@30
|
945
|
Chris@551
|
946 m_dragPointX = v->getXForFrame(m_editingPoint.frame);
|
Chris@551
|
947 m_dragPointY = getYForValue(v, m_editingPoint.value);
|
Chris@551
|
948
|
Chris@30
|
949 if (m_editingCommand) {
|
gyorgyf@646
|
950 finish(m_editingCommand);
|
gyorgyf@646
|
951 m_editingCommand = 0;
|
Chris@30
|
952 }
|
Chris@30
|
953
|
Chris@30
|
954 m_editing = true;
|
Chris@551
|
955 m_dragStartX = e->x();
|
Chris@551
|
956 m_dragStartY = e->y();
|
Chris@30
|
957 }
|
Chris@30
|
958
|
Chris@30
|
959 void
|
matthiasm@620
|
960 FlexiNoteLayer::editDrag(View *v, QMouseEvent *e)
|
Chris@30
|
961 {
|
matthiasm@620
|
962 // SVDEBUG << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl;
|
gyorgyf@635
|
963 std::cerr << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@30
|
964
|
Chris@30
|
965 if (!m_model || !m_editing) return;
|
Chris@30
|
966
|
Chris@551
|
967 int xdist = e->x() - m_dragStartX;
|
Chris@551
|
968 int ydist = e->y() - m_dragStartY;
|
Chris@551
|
969 int newx = m_dragPointX + xdist;
|
Chris@551
|
970 int newy = m_dragPointY + ydist;
|
Chris@551
|
971
|
Chris@551
|
972 long frame = v->getFrameForX(newx);
|
Chris@30
|
973 if (frame < 0) frame = 0;
|
Chris@30
|
974 frame = frame / m_model->getResolution() * m_model->getResolution();
|
Chris@30
|
975
|
Chris@551
|
976 float value = getValueForY(v, newy);
|
Chris@30
|
977
|
Chris@30
|
978 if (!m_editingCommand) {
|
gyorgyf@646
|
979 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
|
gyorgyf@646
|
980 tr("Drag Point"));
|
Chris@30
|
981 }
|
Chris@30
|
982
|
Chris@30
|
983 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@30
|
984 m_editingPoint.frame = frame;
|
Chris@30
|
985 m_editingPoint.value = value;
|
Chris@30
|
986 m_editingCommand->addPoint(m_editingPoint);
|
Chris@30
|
987 }
|
Chris@30
|
988
|
Chris@30
|
989 void
|
gyorgyf@635
|
990 FlexiNoteLayer::editEnd(View *v, QMouseEvent *e)
|
Chris@30
|
991 {
|
matthiasm@620
|
992 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl;
|
gyorgyf@635
|
993 std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
|
gyorgyf@635
|
994
|
Chris@30
|
995 if (!m_model || !m_editing) return;
|
Chris@30
|
996
|
Chris@30
|
997 if (m_editingCommand) {
|
Chris@30
|
998
|
gyorgyf@646
|
999 QString newName = m_editingCommand->getName();
|
Chris@30
|
1000
|
gyorgyf@646
|
1001 if (m_editingPoint.frame != m_originalPoint.frame) {
|
gyorgyf@646
|
1002 if (m_editingPoint.value != m_originalPoint.value) {
|
gyorgyf@646
|
1003 newName = tr("Edit Point");
|
gyorgyf@646
|
1004 } else {
|
gyorgyf@646
|
1005 newName = tr("Relocate Point");
|
gyorgyf@646
|
1006 }
|
gyorgyf@646
|
1007 } else {
|
gyorgyf@646
|
1008 newName = tr("Change Point Value");
|
gyorgyf@646
|
1009 }
|
Chris@30
|
1010
|
gyorgyf@646
|
1011 m_editingCommand->setName(newName);
|
gyorgyf@646
|
1012 finish(m_editingCommand);
|
Chris@30
|
1013 }
|
Chris@30
|
1014
|
Chris@30
|
1015 m_editingCommand = 0;
|
Chris@30
|
1016 m_editing = false;
|
Chris@30
|
1017 }
|
Chris@30
|
1018
|
gyorgyf@635
|
1019 void
|
gyorgyf@635
|
1020 FlexiNoteLayer::splitStart(View *v, QMouseEvent *e)
|
gyorgyf@635
|
1021 {
|
gyorgyf@646
|
1022 // GF: note splitting starts (!! remove printing soon)
|
gyorgyf@646
|
1023 std::cerr << "splitStart" << std::endl;
|
gyorgyf@646
|
1024 if (!m_model) return;
|
gyorgyf@635
|
1025
|
gyorgyf@635
|
1026 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
|
gyorgyf@635
|
1027 // m_originalPoint = m_editingPoint;
|
gyorgyf@635
|
1028 //
|
gyorgyf@635
|
1029 // m_dragPointX = v->getXForFrame(m_editingPoint.frame);
|
gyorgyf@635
|
1030 // m_dragPointY = getYForValue(v, m_editingPoint.value);
|
gyorgyf@635
|
1031
|
gyorgyf@635
|
1032 if (m_editingCommand) {
|
gyorgyf@646
|
1033 finish(m_editingCommand);
|
gyorgyf@646
|
1034 m_editingCommand = 0;
|
gyorgyf@635
|
1035 }
|
gyorgyf@635
|
1036
|
gyorgyf@635
|
1037 m_editing = true;
|
gyorgyf@635
|
1038 m_dragStartX = e->x();
|
gyorgyf@635
|
1039 m_dragStartY = e->y();
|
gyorgyf@635
|
1040
|
gyorgyf@635
|
1041 }
|
gyorgyf@635
|
1042
|
gyorgyf@635
|
1043 void
|
gyorgyf@635
|
1044 FlexiNoteLayer::splitEnd(View *v, QMouseEvent *e)
|
gyorgyf@635
|
1045 {
|
gyorgyf@646
|
1046 // GF: note splitting ends. (!! remove printing soon)
|
gyorgyf@646
|
1047 std::cerr << "splitEnd" << std::endl;
|
gyorgyf@646
|
1048 if (!m_model || !m_editing) return;
|
gyorgyf@635
|
1049
|
gyorgyf@635
|
1050 int xdist = e->x() - m_dragStartX;
|
gyorgyf@635
|
1051 int ydist = e->y() - m_dragStartY;
|
gyorgyf@635
|
1052 if (xdist != 0 || ydist != 0) {
|
gyorgyf@646
|
1053 std::cerr << "mouse moved" << std::endl;
|
gyorgyf@635
|
1054 return;
|
gyorgyf@635
|
1055 }
|
gyorgyf@635
|
1056
|
gyorgyf@635
|
1057 FlexiNoteModel::Point note(0);
|
gyorgyf@635
|
1058 if (!getPointToDrag(v, e->x(), e->y(), note)) return;
|
gyorgyf@635
|
1059
|
gyorgyf@635
|
1060 long frame = v->getFrameForX(e->x());
|
gyorgyf@635
|
1061
|
gyorgyf@635
|
1062 FlexiNoteModel::Point newNote1 = note;
|
gyorgyf@635
|
1063 newNote1.frame = note.frame;
|
gyorgyf@635
|
1064 newNote1.value = note.value;
|
gyorgyf@635
|
1065 // newNote1.duration = note.duration+10000;
|
gyorgyf@646
|
1066 newNote1.duration = frame - note.frame - 100;
|
gyorgyf@635
|
1067 newNote1.label = note.label;
|
gyorgyf@635
|
1068
|
gyorgyf@635
|
1069 FlexiNoteModel::Point newNote2 = note;
|
gyorgyf@635
|
1070 newNote2.frame = frame + 100;
|
gyorgyf@635
|
1071 newNote2.value = note.value;
|
gyorgyf@646
|
1072 newNote2.duration = note.duration - (frame - note.frame - 100);
|
gyorgyf@635
|
1073 newNote2.label = note.label;
|
gyorgyf@635
|
1074
|
gyorgyf@635
|
1075
|
gyorgyf@635
|
1076 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
|
gyorgyf@635
|
1077 (m_model, tr("Edit Point"));
|
gyorgyf@635
|
1078 command->deletePoint(note);
|
gyorgyf@635
|
1079 command->addPoint(newNote1);
|
gyorgyf@635
|
1080 command->addPoint(newNote2);
|
gyorgyf@635
|
1081 finish(command);
|
gyorgyf@646
|
1082
|
gyorgyf@646
|
1083 }
|
gyorgyf@646
|
1084
|
gyorgyf@646
|
1085 void
|
gyorgyf@646
|
1086 FlexiNoteLayer::mouseMoveEvent(View *v, QMouseEvent *e)
|
gyorgyf@646
|
1087 {
|
gyorgyf@646
|
1088 // GF: context sensitive cursors
|
gyorgyf@646
|
1089 // v->setCursor(Qt::ArrowCursor);
|
gyorgyf@646
|
1090 FlexiNoteModel::Point note(0);
|
gyorgyf@646
|
1091 if (!getNoteToEdit(v, e->x(), e->y(), note)) {
|
gyorgyf@646
|
1092 // v->setCursor(Qt::UpArrowCursor);
|
gyorgyf@646
|
1093 return;
|
gyorgyf@646
|
1094 }
|
gyorgyf@646
|
1095
|
gyorgyf@646
|
1096 bool closeToLeft = false, closeToRight = false, closeToTop = false, closeToBottom = false;
|
gyorgyf@646
|
1097 getRelativeMousePosition(v, note, e->x(), e->y(), closeToLeft, closeToRight, closeToTop, closeToBottom);
|
gyorgyf@646
|
1098 // if (!closeToLeft) return;
|
gyorgyf@646
|
1099 if (closeToLeft || closeToRight) { v->setCursor(Qt::SizeHorCursor); return; }
|
gyorgyf@646
|
1100 // if (closeToTop) v->setCursor(Qt::SizeVerCursor);
|
gyorgyf@646
|
1101 if (closeToTop) { v->setCursor(Qt::CrossCursor); return; }
|
gyorgyf@646
|
1102 if (closeToBottom) { v->setCursor(Qt::UpArrowCursor); return; }
|
gyorgyf@646
|
1103 v->setCursor(Qt::ArrowCursor);
|
gyorgyf@646
|
1104
|
gyorgyf@646
|
1105
|
gyorgyf@646
|
1106 std::cerr << "Mouse moved in edit mode over FlexiNoteLayer" << std::endl;
|
gyorgyf@646
|
1107 // v->setCursor(Qt::SizeHorCursor);
|
gyorgyf@646
|
1108
|
gyorgyf@646
|
1109 }
|
gyorgyf@646
|
1110
|
gyorgyf@646
|
1111 void
|
gyorgyf@646
|
1112 FlexiNoteLayer::getRelativeMousePosition(View *v, FlexiNoteModel::Point ¬e, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const
|
gyorgyf@646
|
1113 {
|
gyorgyf@646
|
1114 if (!m_model) return;
|
gyorgyf@646
|
1115
|
gyorgyf@646
|
1116 int ctol = 2;
|
gyorgyf@646
|
1117 int noteStartX = v->getXForFrame(note.frame);
|
gyorgyf@646
|
1118 int noteEndX = v->getXForFrame(note.frame + note.duration);
|
gyorgyf@646
|
1119 int noteValueY = getYForValue(v,note.value);
|
gyorgyf@646
|
1120 int noteStartY = noteValueY - (NOTE_HEIGHT / 2);
|
gyorgyf@646
|
1121 int noteEndY = noteValueY + (NOTE_HEIGHT / 2);
|
gyorgyf@646
|
1122
|
gyorgyf@646
|
1123 bool closeToNote = false;
|
gyorgyf@646
|
1124
|
gyorgyf@646
|
1125 if (y >= noteStartY-ctol && y <= noteEndY+ctol && x >= noteStartX-ctol && x <= noteEndX+ctol) closeToNote = true;
|
gyorgyf@646
|
1126 if (!closeToNote) return;
|
gyorgyf@646
|
1127
|
gyorgyf@646
|
1128 int tol = 4;
|
gyorgyf@646
|
1129
|
gyorgyf@646
|
1130 if (x >= noteStartX - tol && x <= noteStartX + tol) closeToLeft = true;
|
gyorgyf@646
|
1131 if (x >= noteEndX - tol && x <= noteEndX + tol) closeToRight = true;
|
gyorgyf@646
|
1132 if (y >= noteStartY - tol && y <= noteStartY + tol) closeToTop = true;
|
gyorgyf@646
|
1133 if (y >= noteEndY - tol && y <= noteEndY + tol) closeToBottom = true;
|
gyorgyf@646
|
1134
|
gyorgyf@635
|
1135 }
|
gyorgyf@635
|
1136
|
gyorgyf@635
|
1137
|
Chris@255
|
1138 bool
|
matthiasm@620
|
1139 FlexiNoteLayer::editOpen(View *v, QMouseEvent *e)
|
Chris@70
|
1140 {
|
gyorgyf@633
|
1141 std::cerr << "Opening note editor dialog" << std::endl;
|
Chris@255
|
1142 if (!m_model) return false;
|
Chris@70
|
1143
|
matthiasm@620
|
1144 FlexiNoteModel::Point note(0);
|
Chris@550
|
1145 if (!getPointToDrag(v, e->x(), e->y(), note)) return false;
|
Chris@550
|
1146
|
matthiasm@620
|
1147 // FlexiNoteModel::Point note = *points.begin();
|
Chris@70
|
1148
|
Chris@70
|
1149 ItemEditDialog *dialog = new ItemEditDialog
|
Chris@70
|
1150 (m_model->getSampleRate(),
|
Chris@70
|
1151 ItemEditDialog::ShowTime |
|
Chris@70
|
1152 ItemEditDialog::ShowDuration |
|
Chris@70
|
1153 ItemEditDialog::ShowValue |
|
Chris@100
|
1154 ItemEditDialog::ShowText,
|
Chris@100
|
1155 m_model->getScaleUnits());
|
Chris@70
|
1156
|
Chris@70
|
1157 dialog->setFrameTime(note.frame);
|
Chris@70
|
1158 dialog->setValue(note.value);
|
Chris@70
|
1159 dialog->setFrameDuration(note.duration);
|
Chris@70
|
1160 dialog->setText(note.label);
|
Chris@70
|
1161
|
Chris@70
|
1162 if (dialog->exec() == QDialog::Accepted) {
|
Chris@70
|
1163
|
matthiasm@620
|
1164 FlexiNoteModel::Point newNote = note;
|
Chris@70
|
1165 newNote.frame = dialog->getFrameTime();
|
Chris@70
|
1166 newNote.value = dialog->getValue();
|
Chris@70
|
1167 newNote.duration = dialog->getFrameDuration();
|
Chris@70
|
1168 newNote.label = dialog->getText();
|
Chris@70
|
1169
|
matthiasm@620
|
1170 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
|
Chris@70
|
1171 (m_model, tr("Edit Point"));
|
Chris@70
|
1172 command->deletePoint(note);
|
Chris@70
|
1173 command->addPoint(newNote);
|
Chris@376
|
1174 finish(command);
|
Chris@70
|
1175 }
|
Chris@70
|
1176
|
Chris@70
|
1177 delete dialog;
|
Chris@255
|
1178 return true;
|
Chris@70
|
1179 }
|
Chris@70
|
1180
|
Chris@70
|
1181 void
|
matthiasm@620
|
1182 FlexiNoteLayer::moveSelection(Selection s, size_t newStartFrame)
|
Chris@43
|
1183 {
|
Chris@99
|
1184 if (!m_model) return;
|
Chris@99
|
1185
|
matthiasm@620
|
1186 FlexiNoteModel::EditCommand *command =
|
gyorgyf@646
|
1187 new FlexiNoteModel::EditCommand(m_model, tr("Drag Selection"));
|
Chris@43
|
1188
|
matthiasm@620
|
1189 FlexiNoteModel::PointList points =
|
gyorgyf@646
|
1190 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@43
|
1191
|
matthiasm@620
|
1192 for (FlexiNoteModel::PointList::iterator i = points.begin();
|
gyorgyf@646
|
1193 i != points.end(); ++i) {
|
Chris@43
|
1194
|
gyorgyf@646
|
1195 if (s.contains(i->frame)) {
|
gyorgyf@646
|
1196 FlexiNoteModel::Point newPoint(*i);
|
gyorgyf@646
|
1197 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
|
gyorgyf@646
|
1198 command->deletePoint(*i);
|
gyorgyf@646
|
1199 command->addPoint(newPoint);
|
gyorgyf@646
|
1200 }
|
Chris@43
|
1201 }
|
Chris@43
|
1202
|
Chris@376
|
1203 finish(command);
|
Chris@43
|
1204 }
|
Chris@43
|
1205
|
Chris@43
|
1206 void
|
matthiasm@620
|
1207 FlexiNoteLayer::resizeSelection(Selection s, Selection newSize)
|
Chris@43
|
1208 {
|
Chris@99
|
1209 if (!m_model) return;
|
Chris@99
|
1210
|
matthiasm@620
|
1211 FlexiNoteModel::EditCommand *command =
|
gyorgyf@646
|
1212 new FlexiNoteModel::EditCommand(m_model, tr("Resize Selection"));
|
Chris@43
|
1213
|
matthiasm@620
|
1214 FlexiNoteModel::PointList points =
|
gyorgyf@646
|
1215 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@43
|
1216
|
Chris@43
|
1217 double ratio =
|
gyorgyf@646
|
1218 double(newSize.getEndFrame() - newSize.getStartFrame()) /
|
gyorgyf@646
|
1219 double(s.getEndFrame() - s.getStartFrame());
|
Chris@43
|
1220
|
matthiasm@620
|
1221 for (FlexiNoteModel::PointList::iterator i = points.begin();
|
gyorgyf@646
|
1222 i != points.end(); ++i) {
|
Chris@43
|
1223
|
gyorgyf@646
|
1224 if (s.contains(i->frame)) {
|
Chris@43
|
1225
|
gyorgyf@646
|
1226 double targetStart = i->frame;
|
gyorgyf@646
|
1227 targetStart = newSize.getStartFrame() +
|
gyorgyf@646
|
1228 double(targetStart - s.getStartFrame()) * ratio;
|
Chris@43
|
1229
|
gyorgyf@646
|
1230 double targetEnd = i->frame + i->duration;
|
gyorgyf@646
|
1231 targetEnd = newSize.getStartFrame() +
|
gyorgyf@646
|
1232 double(targetEnd - s.getStartFrame()) * ratio;
|
Chris@43
|
1233
|
gyorgyf@646
|
1234 FlexiNoteModel::Point newPoint(*i);
|
gyorgyf@646
|
1235 newPoint.frame = lrint(targetStart);
|
gyorgyf@646
|
1236 newPoint.duration = lrint(targetEnd - targetStart);
|
gyorgyf@646
|
1237 command->deletePoint(*i);
|
gyorgyf@646
|
1238 command->addPoint(newPoint);
|
gyorgyf@646
|
1239 }
|
Chris@43
|
1240 }
|
Chris@43
|
1241
|
Chris@376
|
1242 finish(command);
|
Chris@43
|
1243 }
|
Chris@43
|
1244
|
Chris@76
|
1245 void
|
matthiasm@620
|
1246 FlexiNoteLayer::deleteSelection(Selection s)
|
Chris@76
|
1247 {
|
Chris@99
|
1248 if (!m_model) return;
|
Chris@99
|
1249
|
matthiasm@620
|
1250 FlexiNoteModel::EditCommand *command =
|
gyorgyf@646
|
1251 new FlexiNoteModel::EditCommand(m_model, tr("Delete Selected Points"));
|
Chris@76
|
1252
|
matthiasm@620
|
1253 FlexiNoteModel::PointList points =
|
gyorgyf@646
|
1254 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@76
|
1255
|
matthiasm@620
|
1256 for (FlexiNoteModel::PointList::iterator i = points.begin();
|
gyorgyf@646
|
1257 i != points.end(); ++i) {
|
Chris@76
|
1258
|
Chris@76
|
1259 if (s.contains(i->frame)) {
|
Chris@76
|
1260 command->deletePoint(*i);
|
Chris@76
|
1261 }
|
Chris@76
|
1262 }
|
Chris@76
|
1263
|
Chris@376
|
1264 finish(command);
|
Chris@76
|
1265 }
|
Chris@76
|
1266
|
Chris@76
|
1267 void
|
matthiasm@620
|
1268 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to)
|
Chris@76
|
1269 {
|
Chris@99
|
1270 if (!m_model) return;
|
Chris@99
|
1271
|
matthiasm@620
|
1272 FlexiNoteModel::PointList points =
|
gyorgyf@646
|
1273 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@76
|
1274
|
matthiasm@620
|
1275 for (FlexiNoteModel::PointList::iterator i = points.begin();
|
gyorgyf@646
|
1276 i != points.end(); ++i) {
|
gyorgyf@646
|
1277 if (s.contains(i->frame)) {
|
Chris@335
|
1278 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label);
|
Chris@360
|
1279 point.setReferenceFrame(alignToReference(v, i->frame));
|
Chris@76
|
1280 to.addPoint(point);
|
Chris@76
|
1281 }
|
Chris@76
|
1282 }
|
Chris@76
|
1283 }
|
Chris@76
|
1284
|
Chris@125
|
1285 bool
|
matthiasm@620
|
1286 FlexiNoteLayer::paste(View *v, const Clipboard &from, int frameOffset, bool /* interactive */)
|
Chris@76
|
1287 {
|
Chris@125
|
1288 if (!m_model) return false;
|
Chris@99
|
1289
|
Chris@76
|
1290 const Clipboard::PointList &points = from.getPoints();
|
Chris@76
|
1291
|
Chris@360
|
1292 bool realign = false;
|
Chris@360
|
1293
|
Chris@360
|
1294 if (clipboardHasDifferentAlignment(v, from)) {
|
Chris@360
|
1295
|
Chris@360
|
1296 QMessageBox::StandardButton button =
|
Chris@360
|
1297 QMessageBox::question(v, tr("Re-align pasted items?"),
|
Chris@360
|
1298 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"),
|
Chris@360
|
1299 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
Chris@360
|
1300 QMessageBox::Yes);
|
Chris@360
|
1301
|
Chris@360
|
1302 if (button == QMessageBox::Cancel) {
|
Chris@360
|
1303 return false;
|
Chris@360
|
1304 }
|
Chris@360
|
1305
|
Chris@360
|
1306 if (button == QMessageBox::Yes) {
|
Chris@360
|
1307 realign = true;
|
Chris@360
|
1308 }
|
Chris@360
|
1309 }
|
Chris@360
|
1310
|
matthiasm@620
|
1311 FlexiNoteModel::EditCommand *command =
|
gyorgyf@646
|
1312 new FlexiNoteModel::EditCommand(m_model, tr("Paste"));
|
Chris@76
|
1313
|
Chris@76
|
1314 for (Clipboard::PointList::const_iterator i = points.begin();
|
Chris@76
|
1315 i != points.end(); ++i) {
|
Chris@76
|
1316
|
Chris@76
|
1317 if (!i->haveFrame()) continue;
|
Chris@76
|
1318 size_t frame = 0;
|
Chris@360
|
1319
|
Chris@360
|
1320 if (!realign) {
|
Chris@360
|
1321
|
Chris@360
|
1322 frame = i->getFrame();
|
Chris@360
|
1323
|
Chris@360
|
1324 } else {
|
Chris@360
|
1325
|
Chris@360
|
1326 if (i->haveReferenceFrame()) {
|
Chris@360
|
1327 frame = i->getReferenceFrame();
|
Chris@360
|
1328 frame = alignFromReference(v, frame);
|
Chris@360
|
1329 } else {
|
Chris@360
|
1330 frame = i->getFrame();
|
Chris@360
|
1331 }
|
Chris@76
|
1332 }
|
Chris@360
|
1333
|
matthiasm@620
|
1334 FlexiNoteModel::Point newPoint(frame);
|
Chris@76
|
1335
|
Chris@76
|
1336 if (i->haveLabel()) newPoint.label = i->getLabel();
|
Chris@76
|
1337 if (i->haveValue()) newPoint.value = i->getValue();
|
Chris@76
|
1338 else newPoint.value = (m_model->getValueMinimum() +
|
Chris@76
|
1339 m_model->getValueMaximum()) / 2;
|
Chris@335
|
1340 if (i->haveLevel()) newPoint.level = i->getLevel();
|
Chris@76
|
1341 if (i->haveDuration()) newPoint.duration = i->getDuration();
|
Chris@125
|
1342 else {
|
Chris@125
|
1343 size_t nextFrame = frame;
|
Chris@125
|
1344 Clipboard::PointList::const_iterator j = i;
|
Chris@125
|
1345 for (; j != points.end(); ++j) {
|
Chris@125
|
1346 if (!j->haveFrame()) continue;
|
Chris@125
|
1347 if (j != i) break;
|
Chris@125
|
1348 }
|
Chris@125
|
1349 if (j != points.end()) {
|
Chris@125
|
1350 nextFrame = j->getFrame();
|
Chris@125
|
1351 }
|
Chris@125
|
1352 if (nextFrame == frame) {
|
Chris@125
|
1353 newPoint.duration = m_model->getResolution();
|
Chris@125
|
1354 } else {
|
Chris@125
|
1355 newPoint.duration = nextFrame - frame;
|
Chris@125
|
1356 }
|
Chris@125
|
1357 }
|
Chris@76
|
1358
|
Chris@76
|
1359 command->addPoint(newPoint);
|
Chris@76
|
1360 }
|
Chris@76
|
1361
|
Chris@376
|
1362 finish(command);
|
Chris@125
|
1363 return true;
|
Chris@76
|
1364 }
|
Chris@76
|
1365
|
Chris@507
|
1366 void
|
matthiasm@620
|
1367 FlexiNoteLayer::addNoteOn(long frame, int pitch, int velocity)
|
Chris@507
|
1368 {
|
matthiasm@620
|
1369 m_pendingNoteOns.insert(FlexiNote(frame, pitch, 0, float(velocity) / 127.0, ""));
|
Chris@507
|
1370 }
|
Chris@507
|
1371
|
Chris@507
|
1372 void
|
matthiasm@620
|
1373 FlexiNoteLayer::addNoteOff(long frame, int pitch)
|
Chris@507
|
1374 {
|
matthiasm@620
|
1375 for (FlexiNoteSet::iterator i = m_pendingNoteOns.begin();
|
Chris@507
|
1376 i != m_pendingNoteOns.end(); ++i) {
|
Chris@507
|
1377 if (lrintf((*i).value) == pitch) {
|
matthiasm@620
|
1378 FlexiNote note(*i);
|
Chris@507
|
1379 m_pendingNoteOns.erase(i);
|
Chris@507
|
1380 note.duration = frame - note.frame;
|
Chris@507
|
1381 if (m_model) {
|
matthiasm@620
|
1382 FlexiNoteModel::AddPointCommand *c = new FlexiNoteModel::AddPointCommand
|
matthiasm@620
|
1383 (m_model, note, tr("Record FlexiNote"));
|
Chris@507
|
1384 // execute and bundle:
|
Chris@507
|
1385 CommandHistory::getInstance()->addCommand(c, true, true);
|
Chris@507
|
1386 }
|
Chris@507
|
1387 break;
|
Chris@507
|
1388 }
|
Chris@507
|
1389 }
|
Chris@507
|
1390 }
|
Chris@507
|
1391
|
Chris@507
|
1392 void
|
matthiasm@620
|
1393 FlexiNoteLayer::abandonNoteOns()
|
Chris@507
|
1394 {
|
Chris@507
|
1395 m_pendingNoteOns.clear();
|
Chris@507
|
1396 }
|
Chris@507
|
1397
|
Chris@287
|
1398 int
|
matthiasm@620
|
1399 FlexiNoteLayer::getDefaultColourHint(bool darkbg, bool &impose)
|
Chris@287
|
1400 {
|
Chris@287
|
1401 impose = false;
|
Chris@287
|
1402 return ColourDatabase::getInstance()->getColourIndex
|
Chris@287
|
1403 (QString(darkbg ? "White" : "Black"));
|
Chris@287
|
1404 }
|
Chris@287
|
1405
|
Chris@316
|
1406 void
|
matthiasm@620
|
1407 FlexiNoteLayer::toXml(QTextStream &stream,
|
Chris@316
|
1408 QString indent, QString extraAttributes) const
|
Chris@30
|
1409 {
|
Chris@316
|
1410 SingleColourLayer::toXml(stream, indent, extraAttributes +
|
Chris@445
|
1411 QString(" verticalScale=\"%1\" scaleMinimum=\"%2\" scaleMaximum=\"%3\" ")
|
Chris@445
|
1412 .arg(m_verticalScale)
|
Chris@445
|
1413 .arg(m_scaleMinimum)
|
Chris@445
|
1414 .arg(m_scaleMaximum));
|
Chris@30
|
1415 }
|
Chris@30
|
1416
|
Chris@30
|
1417 void
|
matthiasm@620
|
1418 FlexiNoteLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@30
|
1419 {
|
Chris@287
|
1420 SingleColourLayer::setProperties(attributes);
|
Chris@30
|
1421
|
Chris@445
|
1422 bool ok, alsoOk;
|
Chris@30
|
1423 VerticalScale scale = (VerticalScale)
|
gyorgyf@646
|
1424 attributes.value("verticalScale").toInt(&ok);
|
Chris@30
|
1425 if (ok) setVerticalScale(scale);
|
Chris@445
|
1426
|
Chris@445
|
1427 float min = attributes.value("scaleMinimum").toFloat(&ok);
|
Chris@445
|
1428 float max = attributes.value("scaleMaximum").toFloat(&alsoOk);
|
Chris@445
|
1429 if (ok && alsoOk) setDisplayExtents(min, max);
|
Chris@30
|
1430 }
|
Chris@30
|
1431
|
Chris@30
|
1432
|