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