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