]> git.sesse.net Git - kdenlive/blob - src/jogaction.cpp
Fix label
[kdenlive] / src / jogaction.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Pascal Fleury (fleury@users.sourceforge.net)    *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20 #include "jogaction.h"
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <klocalizedstring.h>
25
26 // TODO(fleury): this should probably be a user configuration parameter (at least the max speed).
27 //const double SPEEDS[] = {0.0, 0.5, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0};
28 const double SPEEDS[] = {0.0, 1.0, 2.0, 4.0, 5.0, 8.0, 16.0, 60.0};
29 const size_t SPEEDS_SIZE = sizeof(SPEEDS) / sizeof(double);
30
31 JogShuttleAction::JogShuttleAction (const JogShuttle* jogShuttle, const QStringList& actionMap, QObject * parent)
32         : QObject(parent), m_jogShuttle(jogShuttle), m_actionMap(actionMap)
33 {
34     // Add action map 0 used for stopping the monitor when the shuttle is in neutral position.
35     if (m_actionMap.size() == 0)
36       m_actionMap.append("monitor_pause");
37     
38     connect(m_jogShuttle, SIGNAL(jogBack()), this, SLOT(slotJogBack()));
39     connect(m_jogShuttle, SIGNAL(jogForward()), this, SLOT(slotJogForward()));
40     connect(m_jogShuttle, SIGNAL(shuttlePos(int)), this, SLOT(slotShuttlePos(int)));
41     connect(m_jogShuttle, SIGNAL(button(int)), this, SLOT(slotButton(int)));
42     //for (int i = 0; i < actionMap.size(); ++i) fprintf(stderr, "button #%d -> action '%s'\n", i, actionMap[i].toAscii().constData());  //DBG
43 }
44
45 JogShuttleAction::~JogShuttleAction()
46 {
47     disconnect(m_jogShuttle, SIGNAL(jogBack()), this, SLOT(slotJogBack()));
48     disconnect(m_jogShuttle, SIGNAL(jogForward()), this, SLOT(slotJogForward()));
49     disconnect(m_jogShuttle, SIGNAL(shuttlePos(int)), this, SLOT(slotShuttlePos(int)));
50     disconnect(m_jogShuttle, SIGNAL(button(int)), this, SLOT(slotButton(int)));
51 }
52
53 void JogShuttleAction::slotJogBack()
54 {
55     emit rewindOneFrame();
56 }
57
58 void JogShuttleAction::slotJogForward()
59 {
60     emit forwardOneFrame();
61 }
62
63 void JogShuttleAction::slotShuttlePos(int shuttle_pos)
64 {
65     size_t magnitude = abs(shuttle_pos);
66     if (magnitude < SPEEDS_SIZE) {
67         if (shuttle_pos < 0)
68             emit rewind(-SPEEDS[magnitude]);
69         if (shuttle_pos == 0)
70             emit action(m_actionMap[0]);
71         if (shuttle_pos > 0)
72             emit forward(SPEEDS[magnitude]);
73     }
74 }
75
76 void JogShuttleAction::slotButton(int button_id)
77 {
78     if (button_id >= m_actionMap.size() || m_actionMap[button_id].isEmpty()) {
79         // TODO(fleury): Shoudl this go to the status bar to inform the user ?
80         fprintf(stderr, "Button %d has no action\n", button_id);
81         return;
82     }
83     //fprintf(stderr, "Button #%d maps to action '%s'\n", button_id, m_actionMap[button_id].toAscii().constData()); //DBG
84     emit action(m_actionMap[button_id]);
85 }
86
87 #include "jogaction.moc"