1 /*
2 Copyright (C) 2005-2008 Remon Sijrier
3
4 This file is part of Traverso
5
6 Traverso is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 */
21
22 #include "TrackPan.h"
23
24 #include "ViewPort.h"
25
26 #include "ContextPointer.h"
27 #include "Track.h"
28
29
30 // Always put me below _all_ includes, this is needed
31 // in case we run with memory leak detection enabled!
32 #include "Debugger.h"
33
34 /**
35 * \class TrackPan
36 \brief Change (jog) the Panorama of a Track, or set to a pre-defined value
37
38 \sa TraversoCommands
39 */
40
41
TrackPan(Track * track,QVariantList args)42 TrackPan::TrackPan(Track* track, QVariantList args)
43 : Command(track, "")
44 , d(new Data)
45 {
46 m_track = track;
47
48 QString des;
49
50 if (args.size() > 0) {
51 m_newPan = args.at(0).toDouble();
52 des = tr("Track Pan: %1").arg("Reset");
53 m_origPan = m_track->get_pan();
54 } else {
55 des = tr("Track Pan");
56 }
57
58 setText(des);
59 }
60
61
prepare_actions()62 int TrackPan::prepare_actions()
63 {
64 delete d;
65 return 1;
66 }
67
68
begin_hold()69 int TrackPan::begin_hold()
70 {
71 d->origX = cpointer().x();
72 m_origPan = m_newPan = m_track->get_pan();
73
74 return 1;
75 }
76
77
finish_hold()78 int TrackPan::finish_hold()
79 {
80 QCursor::setPos(d->mousePos);
81 return 1;
82 }
83
84
do_action()85 int TrackPan::do_action()
86 {
87 m_track->set_pan(m_newPan);
88 return 1;
89 }
90
91
undo_action()92 int TrackPan::undo_action()
93 {
94 m_track->set_pan(m_origPan);
95 return 1;
96 }
97
cancel_action()98 void TrackPan::cancel_action()
99 {
100 finish_hold();
101 undo_action();
102 }
103
set_cursor_shape(int useX,int useY)104 void TrackPan::set_cursor_shape(int useX, int useY)
105 {
106 Q_UNUSED(useX);
107 Q_UNUSED(useY);
108
109 d->mousePos = QCursor::pos();
110 cpointer().get_viewport()->set_holdcursor(":/cursorHoldLr");
111 }
112
jog()113 int TrackPan::jog()
114 {
115 float w = 600.0;
116 float ofx = (float) d->origX - cpointer().x();
117 float p = -2.0f * (ofx) / w ;
118 m_newPan = p + m_newPan;
119
120 if (m_newPan < -1.0)
121 m_newPan = -1.0;
122 if (m_newPan > 1.0)
123 m_newPan = 1.0;
124
125 m_track->set_pan(m_newPan);
126
127 QCursor::setPos(d->mousePos);
128
129 cpointer().get_viewport()->set_holdcursor_text(QByteArray::number(m_newPan, 'f', 2));
130
131 return 1;
132 }
133
pan_left(bool autorepeat)134 void TrackPan::pan_left(bool autorepeat)
135 {
136 Q_UNUSED(autorepeat);
137
138 m_newPan -= 0.05;
139 if (m_newPan < -1.0)
140 m_newPan = -1.0;
141 m_track->set_pan(m_newPan);
142
143 cpointer().get_viewport()->set_holdcursor_text(QByteArray::number(m_newPan, 'f', 2));
144 }
145
pan_right(bool autorepeat)146 void TrackPan::pan_right(bool autorepeat)
147 {
148 Q_UNUSED(autorepeat);
149
150 m_newPan += 0.05;
151 if (m_newPan > 1.0)
152 m_newPan = 1.0;
153 m_track->set_pan(m_newPan);
154
155 cpointer().get_viewport()->set_holdcursor_text(QByteArray::number(m_newPan, 'f', 2));
156 }
157
158