1 /***************************************************************************
2 * Copyright (C) 2010 by Pascal Fleury (fleury@users.sourceforge.net) *
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. *
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. *
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 ***************************************************************************/
20 #include "jogaction.h"
24 #include <klocalizedstring.h>
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);
31 JogShuttleAction::JogShuttleAction (const JogShuttle* jogShuttle, const QStringList& actionMap, QObject * parent)
32 : QObject(parent), m_jogShuttle(jogShuttle), m_actionMap(actionMap)
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");
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
45 JogShuttleAction::~JogShuttleAction()
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 ) ));
53 void JogShuttleAction::slotJogBack()
55 emit rewindOneFrame();
58 void JogShuttleAction::slotJogForward()
60 emit forwardOneFrame();
63 void JogShuttleAction::slotShuttlePos(int shuttle_pos)
65 size_t magnitude = abs(shuttle_pos);
66 if (magnitude < SPEEDS_SIZE) {
68 emit rewind(-SPEEDS[magnitude]);
70 emit action(m_actionMap[0]);
72 emit forward(SPEEDS[magnitude]);
76 void JogShuttleAction::slotButton(int button_id)
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);
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]);