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