Chris@127
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@127
|
2
|
Chris@127
|
3 /*
|
Chris@127
|
4 Sonic Visualiser
|
Chris@127
|
5 An audio file viewer and annotation editor.
|
Chris@127
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@182
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@127
|
8
|
Chris@127
|
9 This program is free software; you can redistribute it and/or
|
Chris@127
|
10 modify it under the terms of the GNU General Public License as
|
Chris@127
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@127
|
12 License, or (at your option) any later version. See the file
|
Chris@127
|
13 COPYING included with this distribution for more information.
|
Chris@127
|
14 */
|
Chris@127
|
15
|
Chris@127
|
16 #include "ViewManager.h"
|
Chris@128
|
17 #include "base/AudioPlaySource.h"
|
Chris@1210
|
18 #include "base/AudioRecordTarget.h"
|
Chris@502
|
19 #include "base/RealTime.h"
|
Chris@128
|
20 #include "data/model/Model.h"
|
Chris@376
|
21 #include "widgets/CommandHistory.h"
|
Chris@211
|
22 #include "View.h"
|
Chris@503
|
23 #include "Overview.h"
|
Chris@127
|
24
|
Chris@133
|
25 #include <QSettings>
|
Chris@292
|
26 #include <QApplication>
|
Chris@1575
|
27 #include <QStyleFactory>
|
Chris@133
|
28
|
Chris@127
|
29 #include <iostream>
|
Chris@127
|
30
|
Chris@643
|
31 //#define DEBUG_VIEW_MANAGER 1
|
Chris@127
|
32
|
Chris@127
|
33 ViewManager::ViewManager() :
|
Chris@1408
|
34 m_playSource(nullptr),
|
Chris@1408
|
35 m_recordTarget(nullptr),
|
Chris@127
|
36 m_globalCentreFrame(0),
|
Chris@1327
|
37 m_globalZoom(ZoomLevel::FramesPerPixel, 1024),
|
Chris@127
|
38 m_playbackFrame(0),
|
Chris@127
|
39 m_mainModelSampleRate(0),
|
Chris@127
|
40 m_lastLeft(0),
|
Chris@127
|
41 m_lastRight(0),
|
Chris@127
|
42 m_inProgressExclusive(true),
|
Chris@127
|
43 m_toolMode(NavigateMode),
|
Chris@127
|
44 m_playLoopMode(false),
|
Chris@127
|
45 m_playSelectionMode(false),
|
Chris@301
|
46 m_playSoloMode(false),
|
Chris@314
|
47 m_alignMode(false),
|
Chris@741
|
48 m_overlayMode(StandardOverlays),
|
Chris@292
|
49 m_zoomWheelsEnabled(true),
|
Chris@1468
|
50 m_opportunisticEditingEnabled(true),
|
Chris@607
|
51 m_showCentreLine(true),
|
Chris@326
|
52 m_illuminateLocalFeatures(true),
|
Chris@326
|
53 m_showWorkTitle(false),
|
matthiasm@822
|
54 m_showDuration(true),
|
Chris@292
|
55 m_lightPalette(QApplication::palette()),
|
Chris@292
|
56 m_darkPalette(QApplication::palette())
|
Chris@127
|
57 {
|
Chris@133
|
58 QSettings settings;
|
Chris@133
|
59 settings.beginGroup("MainWindow");
|
Chris@133
|
60 m_overlayMode = OverlayMode
|
Chris@133
|
61 (settings.value("overlay-mode", int(m_overlayMode)).toInt());
|
Chris@607
|
62
|
Chris@607
|
63 if (m_overlayMode != NoOverlays &&
|
Chris@741
|
64 m_overlayMode != StandardOverlays &&
|
Chris@607
|
65 m_overlayMode != AllOverlays) {
|
Chris@741
|
66 m_overlayMode = StandardOverlays;
|
Chris@607
|
67 }
|
Chris@607
|
68
|
Chris@133
|
69 m_zoomWheelsEnabled =
|
Chris@133
|
70 settings.value("zoom-wheels-enabled", m_zoomWheelsEnabled).toBool();
|
Chris@607
|
71 m_showCentreLine =
|
Chris@607
|
72 settings.value("show-centre-line", m_showCentreLine).toBool();
|
Chris@133
|
73 settings.endGroup();
|
Chris@292
|
74
|
Chris@292
|
75 if (getGlobalDarkBackground()) {
|
Chris@1573
|
76 // i.e. widgets are already dark; create a light palette in
|
Chris@1573
|
77 // case we are asked to switch to it, but don't create a dark
|
Chris@1573
|
78 // one because it will be assigned from the actual application
|
Chris@1573
|
79 // palette if we switch
|
Chris@1573
|
80
|
Chris@293
|
81 m_lightPalette = QPalette(QColor("#000000"), // WindowText
|
Chris@293
|
82 QColor("#dddfe4"), // Button
|
Chris@293
|
83 QColor("#ffffff"), // Light
|
Chris@293
|
84 QColor("#555555"), // Dark
|
Chris@293
|
85 QColor("#c7c7c7"), // Mid
|
Chris@293
|
86 QColor("#000000"), // Text
|
Chris@293
|
87 QColor("#ffffff"), // BrightText
|
Chris@293
|
88 QColor("#ffffff"), // Base
|
Chris@293
|
89 QColor("#efefef")); // Window
|
Chris@293
|
90
|
Chris@293
|
91
|
Chris@292
|
92 } else {
|
Chris@1573
|
93 // i.e. widgets are currently light; create a dark palette in
|
Chris@1573
|
94 // case we are asked to switch to it, but don't create a light
|
Chris@1573
|
95 // one because it will be assigned from the actual application
|
Chris@1573
|
96 // palette if we switch
|
Chris@1573
|
97
|
Chris@1573
|
98 m_darkPalette = QPalette(QColor("#f0f0f0"), // WindowText
|
Chris@293
|
99 QColor("#3e3e3e"), // Button
|
Chris@293
|
100 QColor("#808080"), // Light
|
Chris@293
|
101 QColor("#1e1e1e"), // Dark
|
Chris@293
|
102 QColor("#404040"), // Mid
|
Chris@1573
|
103 QColor("#f0f0f0"), // Text
|
Chris@293
|
104 QColor("#ffffff"), // BrightText
|
Chris@293
|
105 QColor("#000000"), // Base
|
Chris@293
|
106 QColor("#202020")); // Window
|
Chris@1573
|
107
|
Chris@1576
|
108 m_darkPalette.setColor(QPalette::Highlight, QColor(25, 130, 220));
|
Chris@1576
|
109 m_darkPalette.setColor(QPalette::Link, QColor(50, 175, 255));
|
Chris@1576
|
110 m_darkPalette.setColor(QPalette::LinkVisited, QColor(50, 175, 255));
|
Chris@1576
|
111
|
Chris@1573
|
112 m_darkPalette.setColor(QPalette::Disabled, QPalette::WindowText,
|
Chris@1573
|
113 QColor("#808080"));
|
Chris@1573
|
114 m_darkPalette.setColor(QPalette::Disabled, QPalette::Text,
|
Chris@1573
|
115 QColor("#808080"));
|
Chris@1573
|
116 m_darkPalette.setColor(QPalette::Disabled, QPalette::Shadow,
|
Chris@1573
|
117 QColor("#000000"));
|
Chris@292
|
118 }
|
Chris@127
|
119 }
|
Chris@127
|
120
|
Chris@127
|
121 ViewManager::~ViewManager()
|
Chris@127
|
122 {
|
Chris@127
|
123 }
|
Chris@127
|
124
|
Chris@902
|
125 sv_frame_t
|
Chris@127
|
126 ViewManager::getGlobalCentreFrame() const
|
Chris@127
|
127 {
|
Chris@127
|
128 #ifdef DEBUG_VIEW_MANAGER
|
Chris@682
|
129 cerr << "ViewManager::getGlobalCentreFrame: returning " << m_globalCentreFrame << endl;
|
Chris@127
|
130 #endif
|
Chris@127
|
131 return m_globalCentreFrame;
|
Chris@127
|
132 }
|
Chris@127
|
133
|
Chris@180
|
134 void
|
Chris@902
|
135 ViewManager::setGlobalCentreFrame(sv_frame_t f)
|
Chris@180
|
136 {
|
Chris@180
|
137 #ifdef DEBUG_VIEW_MANAGER
|
Chris@682
|
138 cerr << "ViewManager::setGlobalCentreFrame to " << f << endl;
|
Chris@180
|
139 #endif
|
Chris@180
|
140 m_globalCentreFrame = f;
|
Chris@211
|
141 emit globalCentreFrameChanged(f);
|
Chris@180
|
142 }
|
Chris@180
|
143
|
Chris@1327
|
144 ZoomLevel
|
Chris@127
|
145 ViewManager::getGlobalZoom() const
|
Chris@127
|
146 {
|
Chris@127
|
147 #ifdef DEBUG_VIEW_MANAGER
|
Chris@682
|
148 cerr << "ViewManager::getGlobalZoom: returning " << m_globalZoom << endl;
|
Chris@127
|
149 #endif
|
Chris@127
|
150 return m_globalZoom;
|
Chris@127
|
151 }
|
Chris@127
|
152
|
Chris@902
|
153 sv_frame_t
|
Chris@127
|
154 ViewManager::getPlaybackFrame() const
|
Chris@127
|
155 {
|
Chris@1210
|
156 if (isRecording()) {
|
Chris@1210
|
157 m_playbackFrame = m_recordTarget->getRecordDuration();
|
Chris@1210
|
158 #ifdef DEBUG_VIEW_MANAGER
|
Chris@1210
|
159 cout << "ViewManager::getPlaybackFrame(recording) -> " << m_playbackFrame << endl;
|
Chris@1210
|
160 #endif
|
Chris@1210
|
161 } else if (isPlaying()) {
|
Chris@1266
|
162 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
|
Chris@1185
|
163 #ifdef DEBUG_VIEW_MANAGER
|
Chris@1185
|
164 cout << "ViewManager::getPlaybackFrame(playing) -> " << m_playbackFrame << endl;
|
Chris@1185
|
165 #endif
|
Chris@1185
|
166 } else {
|
Chris@1185
|
167 #ifdef DEBUG_VIEW_MANAGER
|
Chris@1185
|
168 cout << "ViewManager::getPlaybackFrame(not playing) -> " << m_playbackFrame << endl;
|
Chris@1185
|
169 #endif
|
Chris@127
|
170 }
|
Chris@127
|
171 return m_playbackFrame;
|
Chris@127
|
172 }
|
Chris@127
|
173
|
Chris@127
|
174 void
|
Chris@902
|
175 ViewManager::setPlaybackFrame(sv_frame_t f)
|
Chris@127
|
176 {
|
Chris@1185
|
177 #ifdef DEBUG_VIEW_MANAGER
|
Chris@1185
|
178 cerr << "ViewManager::setPlaybackFrame(" << f << ")" << endl;
|
Chris@1185
|
179 #endif
|
Chris@968
|
180 if (f < 0) f = 0;
|
Chris@127
|
181 if (m_playbackFrame != f) {
|
Chris@1266
|
182 m_playbackFrame = f;
|
Chris@1266
|
183 emit playbackFrameChanged(f);
|
Chris@1266
|
184 if (isPlaying()) {
|
Chris@1266
|
185 m_playSource->play(f);
|
Chris@1266
|
186 }
|
Chris@127
|
187 }
|
Chris@127
|
188 }
|
Chris@127
|
189
|
Chris@1479
|
190 ModelId
|
Chris@301
|
191 ViewManager::getPlaybackModel() const
|
Chris@301
|
192 {
|
Chris@301
|
193 return m_playbackModel;
|
Chris@301
|
194 }
|
Chris@301
|
195
|
Chris@301
|
196 void
|
Chris@1479
|
197 ViewManager::setPlaybackModel(ModelId model)
|
Chris@301
|
198 {
|
Chris@301
|
199 m_playbackModel = model;
|
Chris@301
|
200 }
|
Chris@301
|
201
|
Chris@902
|
202 sv_frame_t
|
Chris@902
|
203 ViewManager::alignPlaybackFrameToReference(sv_frame_t frame) const
|
Chris@333
|
204 {
|
Chris@830
|
205 #ifdef DEBUG_VIEW_MANAGER
|
Chris@830
|
206 cerr << "ViewManager::alignPlaybackFrameToReference(" << frame << "): playback model is " << m_playbackModel << endl;
|
Chris@830
|
207 #endif
|
Chris@1479
|
208 if (m_playbackModel.isNone() || !m_alignMode) {
|
Chris@830
|
209 return frame;
|
Chris@830
|
210 } else {
|
Chris@1479
|
211 auto playbackModel = ModelById::get(m_playbackModel);
|
Chris@1479
|
212 if (!playbackModel) {
|
Chris@1479
|
213 return frame;
|
Chris@1479
|
214 }
|
Chris@1479
|
215 sv_frame_t f = playbackModel->alignToReference(frame);
|
Chris@830
|
216 #ifdef DEBUG_VIEW_MANAGER
|
Chris@830
|
217 cerr << "aligned frame = " << f << endl;
|
Chris@830
|
218 #endif
|
Chris@830
|
219 return f;
|
Chris@830
|
220 }
|
Chris@333
|
221 }
|
Chris@333
|
222
|
Chris@902
|
223 sv_frame_t
|
Chris@902
|
224 ViewManager::alignReferenceToPlaybackFrame(sv_frame_t frame) const
|
Chris@333
|
225 {
|
Chris@830
|
226 #ifdef DEBUG_VIEW_MANAGER
|
Chris@830
|
227 cerr << "ViewManager::alignReferenceToPlaybackFrame(" << frame << "): playback model is " << m_playbackModel << endl;
|
Chris@830
|
228 #endif
|
Chris@1479
|
229 if (m_playbackModel.isNone() || !m_alignMode) {
|
Chris@830
|
230 return frame;
|
Chris@830
|
231 } else {
|
Chris@1479
|
232 auto playbackModel = ModelById::get(m_playbackModel);
|
Chris@1479
|
233 if (!playbackModel) {
|
Chris@1479
|
234 return frame;
|
Chris@1479
|
235 }
|
Chris@1479
|
236 sv_frame_t f = playbackModel->alignFromReference(frame);
|
Chris@830
|
237 #ifdef DEBUG_VIEW_MANAGER
|
Chris@830
|
238 cerr << "aligned frame = " << f << endl;
|
Chris@830
|
239 #endif
|
Chris@830
|
240 return f;
|
Chris@830
|
241 }
|
Chris@333
|
242 }
|
Chris@333
|
243
|
Chris@127
|
244 bool
|
Chris@127
|
245 ViewManager::haveInProgressSelection() const
|
Chris@127
|
246 {
|
Chris@127
|
247 return !m_inProgressSelection.isEmpty();
|
Chris@127
|
248 }
|
Chris@127
|
249
|
Chris@127
|
250 const Selection &
|
Chris@127
|
251 ViewManager::getInProgressSelection(bool &exclusive) const
|
Chris@127
|
252 {
|
Chris@127
|
253 exclusive = m_inProgressExclusive;
|
Chris@127
|
254 return m_inProgressSelection;
|
Chris@127
|
255 }
|
Chris@127
|
256
|
Chris@127
|
257 void
|
Chris@127
|
258 ViewManager::setInProgressSelection(const Selection &selection, bool exclusive)
|
Chris@127
|
259 {
|
Chris@127
|
260 m_inProgressExclusive = exclusive;
|
Chris@127
|
261 m_inProgressSelection = selection;
|
Chris@127
|
262 if (exclusive) clearSelections();
|
Chris@127
|
263 emit inProgressSelectionChanged();
|
Chris@127
|
264 }
|
Chris@127
|
265
|
Chris@127
|
266 void
|
Chris@127
|
267 ViewManager::clearInProgressSelection()
|
Chris@127
|
268 {
|
Chris@127
|
269 m_inProgressSelection = Selection();
|
Chris@127
|
270 emit inProgressSelectionChanged();
|
Chris@127
|
271 }
|
Chris@127
|
272
|
Chris@127
|
273 const MultiSelection &
|
Chris@127
|
274 ViewManager::getSelection() const
|
Chris@127
|
275 {
|
Chris@127
|
276 return m_selections;
|
Chris@127
|
277 }
|
Chris@127
|
278
|
Chris@127
|
279 const MultiSelection::SelectionList &
|
Chris@127
|
280 ViewManager::getSelections() const
|
Chris@127
|
281 {
|
Chris@127
|
282 return m_selections.getSelections();
|
Chris@127
|
283 }
|
Chris@127
|
284
|
Chris@127
|
285 void
|
Chris@127
|
286 ViewManager::setSelection(const Selection &selection)
|
Chris@127
|
287 {
|
Chris@127
|
288 MultiSelection ms(m_selections);
|
Chris@127
|
289 ms.setSelection(selection);
|
Chris@127
|
290 setSelections(ms);
|
Chris@127
|
291 }
|
Chris@127
|
292
|
Chris@127
|
293 void
|
Chris@127
|
294 ViewManager::addSelection(const Selection &selection)
|
Chris@127
|
295 {
|
Chris@127
|
296 MultiSelection ms(m_selections);
|
Chris@127
|
297 ms.addSelection(selection);
|
Chris@127
|
298 setSelections(ms);
|
Chris@127
|
299 }
|
Chris@127
|
300
|
Chris@127
|
301 void
|
Chris@762
|
302 ViewManager::addSelectionQuietly(const Selection &selection)
|
Chris@762
|
303 {
|
Chris@762
|
304 MultiSelection ms(m_selections);
|
Chris@762
|
305 ms.addSelection(selection);
|
Chris@762
|
306 setSelections(ms, true);
|
Chris@762
|
307 }
|
Chris@762
|
308
|
Chris@762
|
309 void
|
Chris@127
|
310 ViewManager::removeSelection(const Selection &selection)
|
Chris@127
|
311 {
|
Chris@127
|
312 MultiSelection ms(m_selections);
|
Chris@127
|
313 ms.removeSelection(selection);
|
Chris@127
|
314 setSelections(ms);
|
Chris@127
|
315 }
|
Chris@127
|
316
|
Chris@127
|
317 void
|
Chris@127
|
318 ViewManager::clearSelections()
|
Chris@127
|
319 {
|
Chris@127
|
320 MultiSelection ms(m_selections);
|
Chris@127
|
321 ms.clearSelections();
|
Chris@127
|
322 setSelections(ms);
|
Chris@127
|
323 }
|
Chris@127
|
324
|
Chris@127
|
325 void
|
Chris@762
|
326 ViewManager::setSelections(const MultiSelection &ms, bool quietly)
|
Chris@127
|
327 {
|
Chris@127
|
328 if (m_selections.getSelections() == ms.getSelections()) return;
|
Chris@127
|
329 SetSelectionCommand *command = new SetSelectionCommand(this, ms);
|
Chris@127
|
330 CommandHistory::getInstance()->addCommand(command);
|
Chris@762
|
331 if (!quietly) {
|
Chris@762
|
332 emit selectionChangedByUser();
|
Chris@762
|
333 }
|
Chris@127
|
334 }
|
Chris@127
|
335
|
Chris@902
|
336 sv_frame_t
|
Chris@902
|
337 ViewManager::constrainFrameToSelection(sv_frame_t frame) const
|
Chris@271
|
338 {
|
Chris@271
|
339 MultiSelection::SelectionList sl = getSelections();
|
Chris@271
|
340 if (sl.empty()) return frame;
|
Chris@271
|
341
|
Chris@368
|
342 for (MultiSelection::SelectionList::const_iterator i = sl.begin();
|
Chris@368
|
343 i != sl.end(); ++i) {
|
Chris@368
|
344
|
Chris@368
|
345 if (frame < i->getEndFrame()) {
|
Chris@368
|
346 if (frame < i->getStartFrame()) {
|
Chris@368
|
347 return i->getStartFrame();
|
Chris@368
|
348 } else {
|
Chris@368
|
349 return frame;
|
Chris@368
|
350 }
|
Chris@368
|
351 }
|
Chris@271
|
352 }
|
Chris@271
|
353
|
Chris@368
|
354 return sl.begin()->getStartFrame();
|
Chris@271
|
355 }
|
Chris@271
|
356
|
Chris@127
|
357 void
|
Chris@127
|
358 ViewManager::signalSelectionChange()
|
Chris@127
|
359 {
|
Chris@127
|
360 emit selectionChanged();
|
Chris@127
|
361 }
|
Chris@127
|
362
|
Chris@127
|
363 ViewManager::SetSelectionCommand::SetSelectionCommand(ViewManager *vm,
|
Chris@1266
|
364 const MultiSelection &ms) :
|
Chris@127
|
365 m_vm(vm),
|
Chris@127
|
366 m_oldSelection(vm->m_selections),
|
Chris@127
|
367 m_newSelection(ms)
|
Chris@127
|
368 {
|
Chris@127
|
369 }
|
Chris@127
|
370
|
Chris@127
|
371 ViewManager::SetSelectionCommand::~SetSelectionCommand() { }
|
Chris@127
|
372
|
Chris@127
|
373 void
|
Chris@127
|
374 ViewManager::SetSelectionCommand::execute()
|
Chris@127
|
375 {
|
Chris@127
|
376 m_vm->m_selections = m_newSelection;
|
Chris@127
|
377 m_vm->signalSelectionChange();
|
Chris@127
|
378 }
|
Chris@127
|
379
|
Chris@127
|
380 void
|
Chris@127
|
381 ViewManager::SetSelectionCommand::unexecute()
|
Chris@127
|
382 {
|
Chris@127
|
383 m_vm->m_selections = m_oldSelection;
|
Chris@127
|
384 m_vm->signalSelectionChange();
|
Chris@127
|
385 }
|
Chris@127
|
386
|
Chris@127
|
387 QString
|
Chris@127
|
388 ViewManager::SetSelectionCommand::getName() const
|
Chris@127
|
389 {
|
Chris@127
|
390 if (m_newSelection.getSelections().empty()) return tr("Clear Selection");
|
Chris@502
|
391 if (m_newSelection.getSelections().size() > 1) return tr("Select Multiple Regions");
|
Chris@502
|
392 else return tr("Select Region");
|
Chris@127
|
393 }
|
Chris@127
|
394
|
Chris@127
|
395 Selection
|
Chris@902
|
396 ViewManager::getContainingSelection(sv_frame_t frame, bool defaultToFollowing) const
|
Chris@127
|
397 {
|
Chris@127
|
398 return m_selections.getContainingSelection(frame, defaultToFollowing);
|
Chris@127
|
399 }
|
Chris@127
|
400
|
Chris@127
|
401 void
|
Chris@127
|
402 ViewManager::setToolMode(ToolMode mode)
|
Chris@127
|
403 {
|
Chris@127
|
404 m_toolMode = mode;
|
Chris@127
|
405
|
Chris@127
|
406 emit toolModeChanged();
|
Chris@502
|
407
|
Chris@502
|
408 switch (mode) {
|
Chris@502
|
409 case NavigateMode: emit activity(tr("Enter Navigate mode")); break;
|
Chris@502
|
410 case SelectMode: emit activity(tr("Enter Select mode")); break;
|
Chris@502
|
411 case EditMode: emit activity(tr("Enter Edit mode")); break;
|
Chris@502
|
412 case DrawMode: emit activity(tr("Enter Draw mode")); break;
|
Chris@502
|
413 case EraseMode: emit activity(tr("Enter Erase mode")); break;
|
Chris@502
|
414 case MeasureMode: emit activity(tr("Enter Measure mode")); break;
|
gyorgyf@645
|
415 case NoteEditMode: emit activity(tr("Enter NoteEdit mode")); break; // GF: NoteEditMode activity (I'm not yet certain why we need to emit this.)
|
Chris@502
|
416 };
|
Chris@127
|
417 }
|
Chris@127
|
418
|
Chris@711
|
419 ViewManager::ToolMode
|
Chris@711
|
420 ViewManager::getToolModeFor(const View *v) const
|
Chris@711
|
421 {
|
Chris@711
|
422 if (m_toolModeOverrides.find(v) == m_toolModeOverrides.end()) {
|
Chris@711
|
423 return getToolMode();
|
Chris@711
|
424 } else {
|
Chris@711
|
425 return m_toolModeOverrides.find(v)->second;
|
Chris@711
|
426 }
|
Chris@711
|
427 }
|
Chris@711
|
428
|
Chris@711
|
429 void
|
Chris@711
|
430 ViewManager::setToolModeFor(const View *v, ToolMode mode)
|
Chris@711
|
431 {
|
Chris@711
|
432 m_toolModeOverrides[v] = mode;
|
Chris@711
|
433 }
|
Chris@711
|
434
|
Chris@711
|
435 void
|
Chris@711
|
436 ViewManager::clearToolModeOverrides()
|
Chris@711
|
437 {
|
Chris@711
|
438 m_toolModeOverrides.clear();
|
Chris@711
|
439 }
|
Chris@711
|
440
|
Chris@127
|
441 void
|
Chris@127
|
442 ViewManager::setPlayLoopMode(bool mode)
|
Chris@127
|
443 {
|
Chris@177
|
444 if (m_playLoopMode != mode) {
|
Chris@127
|
445
|
Chris@177
|
446 m_playLoopMode = mode;
|
Chris@177
|
447
|
Chris@177
|
448 emit playLoopModeChanged();
|
Chris@177
|
449 emit playLoopModeChanged(mode);
|
Chris@502
|
450
|
Chris@502
|
451 if (mode) emit activity(tr("Switch on Loop mode"));
|
Chris@502
|
452 else emit activity(tr("Switch off Loop mode"));
|
Chris@177
|
453 }
|
Chris@127
|
454 }
|
Chris@127
|
455
|
Chris@127
|
456 void
|
Chris@127
|
457 ViewManager::setPlaySelectionMode(bool mode)
|
Chris@127
|
458 {
|
Chris@177
|
459 if (m_playSelectionMode != mode) {
|
Chris@127
|
460
|
Chris@177
|
461 m_playSelectionMode = mode;
|
Chris@177
|
462
|
Chris@177
|
463 emit playSelectionModeChanged();
|
Chris@177
|
464 emit playSelectionModeChanged(mode);
|
Chris@502
|
465
|
Chris@502
|
466 if (mode) emit activity(tr("Switch on Play Selection mode"));
|
Chris@502
|
467 else emit activity(tr("Switch off Play Selection mode"));
|
Chris@177
|
468 }
|
Chris@127
|
469 }
|
Chris@127
|
470
|
Chris@301
|
471 void
|
Chris@301
|
472 ViewManager::setPlaySoloMode(bool mode)
|
Chris@301
|
473 {
|
Chris@301
|
474 if (m_playSoloMode != mode) {
|
Chris@301
|
475
|
Chris@301
|
476 m_playSoloMode = mode;
|
Chris@301
|
477
|
Chris@301
|
478 emit playSoloModeChanged();
|
Chris@301
|
479 emit playSoloModeChanged(mode);
|
Chris@502
|
480
|
Chris@502
|
481 if (mode) emit activity(tr("Switch on Play Solo mode"));
|
Chris@502
|
482 else emit activity(tr("Switch off Play Solo mode"));
|
Chris@301
|
483 }
|
Chris@301
|
484 }
|
Chris@301
|
485
|
Chris@314
|
486 void
|
Chris@314
|
487 ViewManager::setAlignMode(bool mode)
|
Chris@314
|
488 {
|
Chris@314
|
489 if (m_alignMode != mode) {
|
Chris@314
|
490
|
Chris@314
|
491 m_alignMode = mode;
|
Chris@314
|
492
|
Chris@314
|
493 emit alignModeChanged();
|
Chris@314
|
494 emit alignModeChanged(mode);
|
Chris@502
|
495
|
Chris@502
|
496 if (mode) emit activity(tr("Switch on Alignment mode"));
|
Chris@502
|
497 else emit activity(tr("Switch off Alignment mode"));
|
Chris@314
|
498 }
|
Chris@314
|
499 }
|
Chris@314
|
500
|
Chris@902
|
501 sv_samplerate_t
|
Chris@224
|
502 ViewManager::getPlaybackSampleRate() const
|
Chris@224
|
503 {
|
Chris@224
|
504 if (m_playSource) {
|
Chris@224
|
505 return m_playSource->getSourceSampleRate();
|
Chris@224
|
506 }
|
Chris@224
|
507 return 0;
|
Chris@224
|
508 }
|
Chris@224
|
509
|
Chris@902
|
510 sv_samplerate_t
|
Chris@1181
|
511 ViewManager::getDeviceSampleRate() const
|
Chris@127
|
512 {
|
Chris@127
|
513 if (m_playSource) {
|
Chris@1266
|
514 return m_playSource->getDeviceSampleRate();
|
Chris@127
|
515 }
|
Chris@127
|
516 return 0;
|
Chris@127
|
517 }
|
Chris@127
|
518
|
Chris@127
|
519 void
|
Chris@127
|
520 ViewManager::setAudioPlaySource(AudioPlaySource *source)
|
Chris@127
|
521 {
|
Chris@127
|
522 if (!m_playSource) {
|
Chris@1266
|
523 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
|
Chris@127
|
524 }
|
Chris@127
|
525 m_playSource = source;
|
Chris@127
|
526 }
|
Chris@127
|
527
|
Chris@127
|
528 void
|
Chris@1210
|
529 ViewManager::setAudioRecordTarget(AudioRecordTarget *target)
|
Chris@1210
|
530 {
|
Chris@1210
|
531 if (!m_recordTarget) {
|
Chris@1266
|
532 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
|
Chris@1210
|
533 }
|
Chris@1210
|
534 m_recordTarget = target;
|
Chris@1210
|
535 }
|
Chris@1210
|
536
|
Chris@1210
|
537 void
|
Chris@248
|
538 ViewManager::playStatusChanged(bool /* playing */)
|
Chris@127
|
539 {
|
Chris@689
|
540 #ifdef DEBUG_VIEW_MANAGER
|
Chris@689
|
541 cerr << "ViewManager::playStatusChanged" << endl;
|
Chris@689
|
542 #endif
|
Chris@127
|
543 checkPlayStatus();
|
Chris@127
|
544 }
|
Chris@127
|
545
|
Chris@127
|
546 void
|
Chris@1210
|
547 ViewManager::recordStatusChanged(bool /* recording */)
|
Chris@1210
|
548 {
|
Chris@1210
|
549 #ifdef DEBUG_VIEW_MANAGER
|
Chris@1210
|
550 cerr << "ViewManager::recordStatusChanged" << endl;
|
Chris@1210
|
551 #endif
|
Chris@1210
|
552 checkPlayStatus();
|
Chris@1210
|
553 }
|
Chris@1210
|
554
|
Chris@1210
|
555 void
|
Chris@127
|
556 ViewManager::checkPlayStatus()
|
Chris@127
|
557 {
|
Chris@1210
|
558 if (isRecording()) {
|
Chris@1210
|
559
|
Chris@1266
|
560 float left = 0, right = 0;
|
Chris@1266
|
561 if (m_recordTarget->getInputLevels(left, right)) {
|
Chris@1266
|
562 if (left != m_lastLeft || right != m_lastRight) {
|
Chris@1266
|
563 emit monitoringLevelsChanged(left, right);
|
Chris@1266
|
564 m_lastLeft = left;
|
Chris@1266
|
565 m_lastRight = right;
|
Chris@1266
|
566 }
|
Chris@1266
|
567 }
|
Chris@1210
|
568
|
Chris@1266
|
569 m_playbackFrame = m_recordTarget->getRecordDuration();
|
Chris@1210
|
570
|
Chris@1210
|
571 #ifdef DEBUG_VIEW_MANAGER
|
Chris@1266
|
572 cerr << "ViewManager::checkPlayStatus: Recording, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
|
Chris@1210
|
573 #endif
|
Chris@1210
|
574
|
Chris@1266
|
575 emit playbackFrameChanged(m_playbackFrame);
|
Chris@1210
|
576
|
Chris@1266
|
577 QTimer::singleShot(500, this, SLOT(checkPlayStatus()));
|
Chris@1210
|
578
|
Chris@1210
|
579 } else if (isPlaying()) {
|
Chris@127
|
580
|
Chris@1266
|
581 float left = 0, right = 0;
|
Chris@1266
|
582 if (m_playSource->getOutputLevels(left, right)) {
|
Chris@1266
|
583 if (left != m_lastLeft || right != m_lastRight) {
|
Chris@1266
|
584 emit monitoringLevelsChanged(left, right);
|
Chris@1266
|
585 m_lastLeft = left;
|
Chris@1266
|
586 m_lastRight = right;
|
Chris@1266
|
587 }
|
Chris@1266
|
588 }
|
Chris@127
|
589
|
Chris@1266
|
590 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
|
Chris@127
|
591
|
Chris@127
|
592 #ifdef DEBUG_VIEW_MANAGER
|
Chris@1266
|
593 cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
|
Chris@127
|
594 #endif
|
Chris@127
|
595
|
Chris@1266
|
596 emit playbackFrameChanged(m_playbackFrame);
|
Chris@127
|
597
|
Chris@1266
|
598 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
|
Chris@127
|
599
|
Chris@127
|
600 } else {
|
Chris@127
|
601
|
Chris@1266
|
602 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
|
Chris@1266
|
603 emit monitoringLevelsChanged(0.0, 0.0);
|
Chris@1266
|
604 m_lastLeft = 0.0;
|
Chris@1266
|
605 m_lastRight = 0.0;
|
Chris@1266
|
606 }
|
Chris@127
|
607
|
Chris@127
|
608 #ifdef DEBUG_VIEW_MANAGER
|
Chris@1266
|
609 cerr << "ViewManager::checkPlayStatus: Not playing or recording" << endl;
|
Chris@127
|
610 #endif
|
Chris@127
|
611 }
|
Chris@127
|
612 }
|
Chris@127
|
613
|
Chris@127
|
614 bool
|
Chris@127
|
615 ViewManager::isPlaying() const
|
Chris@127
|
616 {
|
Chris@127
|
617 return m_playSource && m_playSource->isPlaying();
|
Chris@127
|
618 }
|
Chris@127
|
619
|
Chris@1210
|
620 bool
|
Chris@1210
|
621 ViewManager::isRecording() const
|
Chris@1210
|
622 {
|
Chris@1210
|
623 return m_recordTarget && m_recordTarget->isRecording();
|
Chris@1210
|
624 }
|
Chris@1210
|
625
|
Chris@127
|
626 void
|
Chris@902
|
627 ViewManager::viewCentreFrameChanged(sv_frame_t f, bool locked,
|
Chris@211
|
628 PlaybackFollowMode mode)
|
Chris@127
|
629 {
|
Chris@211
|
630 View *v = dynamic_cast<View *>(sender());
|
Chris@211
|
631
|
Chris@398
|
632 #ifdef DEBUG_VIEW_MANAGER
|
Chris@682
|
633 cerr << "ViewManager::viewCentreFrameChanged(" << f << ", " << locked << ", " << mode << "), view is " << v << endl;
|
Chris@398
|
634 #endif
|
Chris@394
|
635
|
Chris@127
|
636 if (locked) {
|
Chris@211
|
637 m_globalCentreFrame = f;
|
Chris@211
|
638 emit globalCentreFrameChanged(f);
|
Chris@211
|
639 } else {
|
Chris@211
|
640 if (v) emit viewCentreFrameChanged(v, f);
|
Chris@127
|
641 }
|
Chris@127
|
642
|
Chris@815
|
643 if (!dynamic_cast<Overview *>(v) || (mode != PlaybackIgnore)) {
|
Chris@527
|
644 if (m_mainModelSampleRate != 0) {
|
Chris@527
|
645 emit activity(tr("Scroll to %1")
|
Chris@527
|
646 .arg(RealTime::frame2RealTime
|
Chris@527
|
647 (f, m_mainModelSampleRate).toText().c_str()));
|
Chris@527
|
648 }
|
Chris@503
|
649 }
|
Chris@502
|
650
|
Chris@815
|
651 if (mode == PlaybackScrollPageWithCentre ||
|
Chris@815
|
652 mode == PlaybackScrollContinuous) {
|
Chris@815
|
653 seek(f);
|
Chris@211
|
654 }
|
Chris@211
|
655 }
|
Chris@211
|
656
|
Chris@211
|
657 void
|
Chris@902
|
658 ViewManager::seek(sv_frame_t f)
|
Chris@211
|
659 {
|
Chris@127
|
660 #ifdef DEBUG_VIEW_MANAGER
|
Chris@682
|
661 cerr << "ViewManager::seek(" << f << ")" << endl;
|
Chris@127
|
662 #endif
|
Chris@127
|
663
|
Chris@1210
|
664 if (isRecording()) {
|
Chris@1210
|
665 // ignore
|
Chris@1210
|
666 #ifdef DEBUG_VIEW_MANAGER
|
Chris@1210
|
667 cerr << "ViewManager::seek: Ignoring during recording" << endl;
|
Chris@1210
|
668 #endif
|
Chris@1210
|
669 return;
|
Chris@1210
|
670 }
|
Chris@1210
|
671
|
Chris@1210
|
672 if (isPlaying()) {
|
Chris@1266
|
673 sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame();
|
Chris@1266
|
674 sv_frame_t diff = std::max(f, playFrame) - std::min(f, playFrame);
|
Chris@1266
|
675 if (diff > 20000) {
|
Chris@1266
|
676 m_playbackFrame = f;
|
Chris@1266
|
677 m_playSource->play(f);
|
Chris@127
|
678 #ifdef DEBUG_VIEW_MANAGER
|
Chris@1266
|
679 cerr << "ViewManager::seek: reseeking from " << playFrame << " to " << f << endl;
|
Chris@127
|
680 #endif
|
Chris@211
|
681 emit playbackFrameChanged(f);
|
Chris@1266
|
682 }
|
Chris@127
|
683 } else {
|
Chris@211
|
684 if (m_playbackFrame != f) {
|
Chris@211
|
685 m_playbackFrame = f;
|
Chris@211
|
686 emit playbackFrameChanged(f);
|
Chris@211
|
687 }
|
Chris@127
|
688 }
|
Chris@127
|
689 }
|
Chris@127
|
690
|
Chris@127
|
691 void
|
Chris@1327
|
692 ViewManager::viewZoomLevelChanged(ZoomLevel z, bool locked)
|
Chris@127
|
693 {
|
Chris@222
|
694 View *v = dynamic_cast<View *>(sender());
|
Chris@222
|
695
|
Chris@222
|
696 if (!v) {
|
Chris@587
|
697 SVDEBUG << "ViewManager::viewZoomLevelChanged: WARNING: sender is not a view" << endl;
|
Chris@222
|
698 return;
|
Chris@222
|
699 }
|
Chris@222
|
700
|
Chris@222
|
701 //!!! emit zoomLevelChanged();
|
Chris@133
|
702
|
Chris@127
|
703 if (locked) {
|
Chris@1266
|
704 m_globalZoom = z;
|
Chris@127
|
705 }
|
Chris@127
|
706
|
Chris@127
|
707 #ifdef DEBUG_VIEW_MANAGER
|
Chris@682
|
708 cerr << "ViewManager::viewZoomLevelChanged(" << v << ", " << z << ", " << locked << ")" << endl;
|
Chris@127
|
709 #endif
|
Chris@222
|
710
|
Chris@222
|
711 emit viewZoomLevelChanged(v, z, locked);
|
Chris@503
|
712
|
Chris@503
|
713 if (!dynamic_cast<Overview *>(v)) {
|
Chris@1327
|
714 if (z.zone == ZoomLevel::FramesPerPixel) {
|
Chris@1327
|
715 emit activity(tr("Zoom to %n sample(s) per pixel", "", z.level));
|
Chris@1327
|
716 } else {
|
Chris@1327
|
717 emit activity(tr("Zoom to %n pixels per sample", "", z.level));
|
Chris@1327
|
718 }
|
Chris@503
|
719 }
|
Chris@127
|
720 }
|
Chris@127
|
721
|
Chris@127
|
722 void
|
Chris@127
|
723 ViewManager::setOverlayMode(OverlayMode mode)
|
Chris@127
|
724 {
|
Chris@127
|
725 if (m_overlayMode != mode) {
|
Chris@127
|
726 m_overlayMode = mode;
|
Chris@127
|
727 emit overlayModeChanged();
|
Chris@502
|
728 emit activity(tr("Change overlay level"));
|
Chris@127
|
729 }
|
Chris@133
|
730
|
Chris@133
|
731 QSettings settings;
|
Chris@133
|
732 settings.beginGroup("MainWindow");
|
Chris@133
|
733 settings.setValue("overlay-mode", int(m_overlayMode));
|
Chris@133
|
734 settings.endGroup();
|
Chris@127
|
735 }
|
Chris@127
|
736
|
Chris@133
|
737 void
|
Chris@133
|
738 ViewManager::setZoomWheelsEnabled(bool enabled)
|
Chris@133
|
739 {
|
Chris@133
|
740 if (m_zoomWheelsEnabled != enabled) {
|
Chris@133
|
741 m_zoomWheelsEnabled = enabled;
|
Chris@133
|
742 emit zoomWheelsEnabledChanged();
|
Chris@502
|
743 if (enabled) emit activity("Show zoom wheels");
|
Chris@502
|
744 else emit activity("Hide zoom wheels");
|
Chris@133
|
745 }
|
Chris@127
|
746
|
Chris@133
|
747 QSettings settings;
|
Chris@133
|
748 settings.beginGroup("MainWindow");
|
Chris@133
|
749 settings.setValue("zoom-wheels-enabled", m_zoomWheelsEnabled);
|
Chris@133
|
750 settings.endGroup();
|
Chris@133
|
751 }
|
Chris@133
|
752
|
Chris@292
|
753 void
|
Chris@1468
|
754 ViewManager::setOpportunisticEditingEnabled(bool enabled)
|
Chris@1468
|
755 {
|
Chris@1468
|
756 if (m_opportunisticEditingEnabled != enabled) {
|
Chris@1468
|
757 m_opportunisticEditingEnabled = enabled;
|
Chris@1468
|
758 emit opportunisticEditingEnabledChanged();
|
Chris@1468
|
759 }
|
Chris@1468
|
760 }
|
Chris@1468
|
761
|
Chris@1468
|
762 void
|
Chris@607
|
763 ViewManager::setShowCentreLine(bool show)
|
Chris@607
|
764 {
|
Chris@607
|
765 if (m_showCentreLine != show) {
|
Chris@607
|
766 m_showCentreLine = show;
|
Chris@607
|
767 emit showCentreLineChanged();
|
Chris@607
|
768 if (show) emit activity("Show centre line");
|
Chris@607
|
769 else emit activity("Hide centre line");
|
Chris@607
|
770 }
|
Chris@607
|
771
|
Chris@607
|
772 QSettings settings;
|
Chris@607
|
773 settings.beginGroup("MainWindow");
|
Chris@607
|
774 settings.setValue("show-centre-line", int(m_showCentreLine));
|
Chris@607
|
775 settings.endGroup();
|
Chris@607
|
776 }
|
Chris@607
|
777
|
Chris@607
|
778 void
|
Chris@292
|
779 ViewManager::setGlobalDarkBackground(bool dark)
|
Chris@292
|
780 {
|
Chris@292
|
781 // also save the current palette, in case the user has changed it
|
Chris@292
|
782 // since construction
|
Chris@292
|
783 if (getGlobalDarkBackground()) {
|
Chris@292
|
784 m_darkPalette = QApplication::palette();
|
Chris@292
|
785 } else {
|
Chris@292
|
786 m_lightPalette = QApplication::palette();
|
Chris@292
|
787 }
|
Chris@292
|
788
|
Chris@1574
|
789 #ifdef Q_OS_MAC
|
Chris@1574
|
790 return;
|
Chris@1574
|
791 #endif
|
Chris@1574
|
792
|
Chris@292
|
793 if (dark) {
|
Chris@1574
|
794
|
Chris@1574
|
795 #ifdef Q_OS_WIN32
|
Chris@1575
|
796 // The Windows Vista style doesn't use the palette for many of
|
Chris@1575
|
797 // its controls. They can be styled with stylesheets, but that
|
Chris@1575
|
798 // takes a lot of fiddly and fragile custom bits. Easier and
|
Chris@1575
|
799 // more reliable to switch to a non-Vista style which does use
|
Chris@1575
|
800 // the palette.
|
Chris@1574
|
801
|
Chris@1575
|
802 QStyle *plainWindowsStyle = QStyleFactory::create("windows");
|
Chris@1575
|
803 if (!plainWindowsStyle) {
|
Chris@1575
|
804 SVCERR << "Failed to load plain Windows style" << endl;
|
Chris@1575
|
805 } else {
|
Chris@1575
|
806 qApp->setStyle(plainWindowsStyle);
|
Chris@1574
|
807 }
|
Chris@1574
|
808 #endif
|
Chris@1574
|
809
|
Chris@292
|
810 QApplication::setPalette(m_darkPalette);
|
Chris@1574
|
811
|
Chris@292
|
812 } else {
|
Chris@1574
|
813
|
Chris@1574
|
814 #ifdef Q_OS_WIN32
|
Chris@1575
|
815 // Switch back to Vista style
|
Chris@1575
|
816
|
Chris@1575
|
817 QStyle *fancyWindowsStyle = QStyleFactory::create("windowsvista");
|
Chris@1575
|
818 if (!fancyWindowsStyle) {
|
Chris@1575
|
819 SVCERR << "Failed to load fancy Windows style" << endl;
|
Chris@1575
|
820 } else {
|
Chris@1575
|
821 qApp->setStyle(fancyWindowsStyle);
|
Chris@1575
|
822 }
|
Chris@1574
|
823 #endif
|
Chris@1574
|
824
|
Chris@292
|
825 QApplication::setPalette(m_lightPalette);
|
Chris@292
|
826 }
|
Chris@292
|
827 }
|
Chris@292
|
828
|
Chris@292
|
829 bool
|
Chris@292
|
830 ViewManager::getGlobalDarkBackground() const
|
Chris@292
|
831 {
|
Chris@292
|
832 bool dark = false;
|
Chris@292
|
833 QColor windowBg = QApplication::palette().color(QPalette::Window);
|
Chris@292
|
834 if (windowBg.red() + windowBg.green() + windowBg.blue() < 384) {
|
Chris@292
|
835 dark = true;
|
Chris@292
|
836 }
|
Chris@292
|
837 return dark;
|
Chris@292
|
838 }
|
Chris@292
|
839
|
Chris@894
|
840 int
|
Chris@894
|
841 ViewManager::scalePixelSize(int pixels)
|
Chris@894
|
842 {
|
Chris@908
|
843 static double ratio = 0.0;
|
Chris@908
|
844 if (ratio == 0.0) {
|
Chris@908
|
845 double baseEm;
|
Chris@894
|
846 #ifdef Q_OS_MAC
|
Chris@908
|
847 baseEm = 17.0;
|
Chris@894
|
848 #else
|
Chris@908
|
849 baseEm = 15.0;
|
Chris@894
|
850 #endif
|
Chris@908
|
851 double em = QFontMetrics(QFont()).height();
|
Chris@894
|
852 ratio = em / baseEm;
|
Chris@1224
|
853
|
Chris@1224
|
854 SVDEBUG << "ViewManager::scalePixelSize: ratio is " << ratio
|
Chris@1224
|
855 << " (em = " << em << ")" << endl;
|
Chris@894
|
856 }
|
Chris@894
|
857
|
Chris@894
|
858 int scaled = int(pixels * ratio + 0.5);
|
Chris@1273
|
859 // SVDEBUG << "scaledSize: " << pixels << " -> " << scaled << " at ratio " << ratio << endl;
|
Chris@894
|
860 if (pixels != 0 && scaled == 0) scaled = 1;
|
Chris@894
|
861 return scaled;
|
Chris@894
|
862 }
|
Chris@946
|
863
|