Chris@867
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@867
|
2
|
Chris@867
|
3 /*
|
Chris@867
|
4 Sonic Visualiser
|
Chris@867
|
5 An audio file viewer and annotation editor.
|
Chris@867
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@867
|
7 This file copyright 2006-2014 Chris Cannam and QMUL.
|
Chris@867
|
8
|
Chris@867
|
9 This program is free software; you can redistribute it and/or
|
Chris@867
|
10 modify it under the terms of the GNU General Public License as
|
Chris@867
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@867
|
12 License, or (at your option) any later version. See the file
|
Chris@867
|
13 COPYING included with this distribution for more information.
|
Chris@867
|
14 */
|
Chris@867
|
15
|
Chris@867
|
16 #include "AlignmentView.h"
|
Chris@867
|
17
|
Chris@867
|
18 #include <QPainter>
|
Chris@867
|
19
|
Chris@867
|
20 using std::vector;
|
Chris@867
|
21
|
Chris@867
|
22 AlignmentView::AlignmentView(QWidget *w) :
|
Chris@867
|
23 View(w, false),
|
Chris@867
|
24 m_above(0),
|
Chris@867
|
25 m_below(0)
|
Chris@867
|
26 {
|
Chris@867
|
27 setObjectName(tr("AlignmentView"));
|
Chris@867
|
28 }
|
Chris@867
|
29
|
Chris@867
|
30 void
|
Chris@867
|
31 AlignmentView::globalCentreFrameChanged(int f)
|
Chris@867
|
32 {
|
Chris@867
|
33 View::globalCentreFrameChanged(f);
|
Chris@867
|
34 update();
|
Chris@867
|
35 }
|
Chris@867
|
36
|
Chris@867
|
37 void
|
Chris@867
|
38 AlignmentView::viewCentreFrameChanged(View *v, int f)
|
Chris@867
|
39 {
|
Chris@867
|
40 View::viewCentreFrameChanged(v, f);
|
Chris@867
|
41 if (v == m_above) {
|
Chris@867
|
42 m_centreFrame = f;
|
Chris@867
|
43 update();
|
Chris@867
|
44 } else if (v == m_below) {
|
Chris@867
|
45 update();
|
Chris@867
|
46 }
|
Chris@867
|
47 }
|
Chris@867
|
48
|
Chris@867
|
49 void
|
Chris@867
|
50 AlignmentView::viewManagerPlaybackFrameChanged(int)
|
Chris@867
|
51 {
|
Chris@867
|
52 update();
|
Chris@867
|
53 }
|
Chris@867
|
54
|
Chris@867
|
55 void
|
Chris@867
|
56 AlignmentView::viewAboveZoomLevelChanged(int level, bool)
|
Chris@867
|
57 {
|
Chris@867
|
58 m_zoomLevel = level;
|
Chris@867
|
59 update();
|
Chris@867
|
60 }
|
Chris@867
|
61
|
Chris@867
|
62 void
|
Chris@867
|
63 AlignmentView::viewBelowZoomLevelChanged(int, bool)
|
Chris@867
|
64 {
|
Chris@867
|
65 update();
|
Chris@867
|
66 }
|
Chris@867
|
67
|
Chris@867
|
68 void
|
Chris@867
|
69 AlignmentView::setViewAbove(View *v)
|
Chris@867
|
70 {
|
Chris@867
|
71 if (m_above) {
|
Chris@867
|
72 disconnect(m_above, 0, this, 0);
|
Chris@867
|
73 }
|
Chris@867
|
74
|
Chris@867
|
75 m_above = v;
|
Chris@867
|
76
|
Chris@867
|
77 if (m_above) {
|
Chris@867
|
78 connect(m_above,
|
Chris@867
|
79 SIGNAL(zoomLevelChanged(int, bool)),
|
Chris@867
|
80 this,
|
Chris@867
|
81 SLOT(viewAboveZoomLevelChanged(int, bool)));
|
Chris@867
|
82 }
|
Chris@867
|
83 }
|
Chris@867
|
84
|
Chris@867
|
85 void
|
Chris@867
|
86 AlignmentView::setViewBelow(View *v)
|
Chris@867
|
87 {
|
Chris@867
|
88 if (m_below) {
|
Chris@867
|
89 disconnect(m_below, 0, this, 0);
|
Chris@867
|
90 }
|
Chris@867
|
91
|
Chris@867
|
92 m_below = v;
|
Chris@867
|
93
|
Chris@867
|
94 if (m_below) {
|
Chris@867
|
95 connect(m_below,
|
Chris@867
|
96 SIGNAL(zoomLevelChanged(int, bool)),
|
Chris@867
|
97 this,
|
Chris@867
|
98 SLOT(viewBelowZoomLevelChanged(int, bool)));
|
Chris@867
|
99 }
|
Chris@867
|
100 }
|
Chris@867
|
101
|
Chris@867
|
102 void
|
Chris@867
|
103 AlignmentView::paintEvent(QPaintEvent *)
|
Chris@867
|
104 {
|
Chris@867
|
105 if (m_above == 0 || m_below == 0 || !m_manager) return;
|
Chris@867
|
106
|
Chris@867
|
107 int rate = m_manager->getMainModelSampleRate();
|
Chris@867
|
108 if (rate == 0) return;
|
Chris@867
|
109
|
Chris@867
|
110 bool darkPalette = false;
|
Chris@867
|
111 if (m_manager) darkPalette = m_manager->getGlobalDarkBackground();
|
Chris@867
|
112
|
Chris@867
|
113 QColor fg = Qt::black, bg = Qt::white;
|
Chris@867
|
114 if (darkPalette) std::swap(fg, bg);
|
Chris@867
|
115
|
Chris@867
|
116 QPainter paint(this);
|
Chris@867
|
117 paint.setPen(QPen(fg, 2));
|
Chris@867
|
118 paint.setBrush(Qt::NoBrush);
|
Chris@867
|
119 paint.setRenderHint(QPainter::Antialiasing, true);
|
Chris@867
|
120
|
Chris@867
|
121 paint.fillRect(rect(), bg);
|
Chris@867
|
122
|
Chris@867
|
123 vector<int> keyFrames;
|
Chris@867
|
124 for (int f = m_above->getModelsStartFrame();
|
Chris@867
|
125 f <= m_above->getModelsEndFrame();
|
Chris@867
|
126 f += rate * 5) {
|
Chris@867
|
127 keyFrames.push_back(f);
|
Chris@867
|
128 }
|
Chris@867
|
129
|
Chris@867
|
130 foreach (int f, keyFrames) {
|
Chris@867
|
131 int af = m_above->alignFromReference(f);
|
Chris@867
|
132 int ax = m_above->getXForFrame(af);
|
Chris@867
|
133 int bf = m_below->alignFromReference(f);
|
Chris@867
|
134 int bx = m_below->getXForFrame(bf);
|
Chris@867
|
135 paint.drawLine(ax, 0, bx, height());
|
Chris@867
|
136 }
|
Chris@867
|
137
|
Chris@867
|
138 paint.end();
|
Chris@867
|
139 }
|
Chris@867
|
140
|