]> git.sesse.net Git - kdenlive/blob - src/jogaction.cpp
Compare with isEmpty() instead of null string "" [krazy 36/37] by Mikko Rapeli
[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 size_t SPEEDS_SIZE = sizeof(SPEEDS) / sizeof(double);
29
30 JogShuttleAction::JogShuttleAction (const JogShuttle* jogShuttle, const QStringList& actionMap, QObject * parent)
31         : QObject(parent), m_jogShuttle(jogShuttle), m_actionMap(actionMap)
32 {
33     // Add action map 0 used for stopping the monitor when the shuttle is in neutral position.
34     if (m_actionMap.size() == 0)
35       m_actionMap.append("monitor_pause");
36     
37     connect(m_jogShuttle, SIGNAL( jogBack() ), this, SLOT( slotJogBack() ));
38     connect(m_jogShuttle, SIGNAL( jogForward() ), this, SLOT( slotJogForward() ));
39     connect(m_jogShuttle, SIGNAL( shuttlePos ( int ) ), this, SLOT( slotShuttlePos ( int ) ));
40     connect(m_jogShuttle, SIGNAL( button ( int ) ), this, SLOT( slotButton ( int ) ));
41     //for (int i = 0; i < actionMap.size(); i++) fprintf(stderr, "button #%d -> action '%s'\n", i, actionMap[i].toAscii().constData());  //DBG
42 }
43
44 JogShuttleAction::~JogShuttleAction()
45 {
46     disconnect(m_jogShuttle, SIGNAL( jogBack() ), this, SLOT( slotJogBack() ));
47     disconnect(m_jogShuttle, SIGNAL( jogForward() ), this, SLOT( slotJogForward() ));
48     disconnect(m_jogShuttle, SIGNAL( shuttlePos ( int ) ), this, SLOT( slotShuttlePos ( int ) ));
49     disconnect(m_jogShuttle, SIGNAL( button ( int ) ), this, SLOT( slotButton ( int ) ));
50 }
51
52 void JogShuttleAction::slotJogBack()
53 {
54     emit rewindOneFrame();
55 }
56
57 void JogShuttleAction::slotJogForward()
58 {
59     emit forwardOneFrame();
60 }
61
62 void JogShuttleAction::slotShuttlePos(int shuttle_pos)
63 {
64     size_t magnitude = abs(shuttle_pos);
65     if (magnitude < SPEEDS_SIZE) {
66         if (shuttle_pos < 0)
67             emit rewind(-SPEEDS[magnitude]);
68         if (shuttle_pos == 0)
69             emit action(m_actionMap[0]);
70         if (shuttle_pos > 0)
71             emit forward(SPEEDS[magnitude]);
72     }
73 }
74
75 void JogShuttleAction::slotButton(int button_id)
76 {
77     if (button_id >= m_actionMap.size() || m_actionMap[button_id].isEmpty()) {
78         // TODO(fleury): Shoudl this go to the status bar to inform the user ?
79         fprintf(stderr, "Button %d has no action\n", button_id);
80         return;
81     }
82     //fprintf(stderr, "Button #%d maps to action '%s'\n", button_id, m_actionMap[button_id].toAscii().constData()); //DBG
83     emit action(m_actionMap[button_id]);
84 }