File indexing completed on 2025-01-12 04:26:31
0001 /* 0002 SPDX-FileCopyrightText: 2010 Pascal Fleury <fleury@users.sourceforge.net> 0003 0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "jogaction.h" 0008 #include "core.h" 0009 #include "monitor/monitormanager.h" 0010 0011 #include "kdenlive_debug.h" 0012 #include <KLocalizedString> 0013 #include <cstdio> 0014 #include <cstdlib> 0015 #include <utility> 0016 // TODO(fleury): this should probably be a user configuration parameter (at least the max speed). 0017 // const double SPEEDS[] = {0.0, 0.5, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0}; 0018 const double SPEEDS[] = {0.0, 1.0, 2.0, 4.0, 5.0, 8.0, 16.0, 60.0}; 0019 const size_t SPEEDS_SIZE = sizeof(SPEEDS) / sizeof(double); 0020 0021 JogShuttleAction::JogShuttleAction(const JogShuttle *jogShuttle, QStringList actionMap, QObject *parent) 0022 : QObject(parent) 0023 , m_jogShuttle(jogShuttle) 0024 , m_actionMap(std::move(actionMap)) 0025 { 0026 // Add action map 0 used for stopping the monitor when the shuttle is in neutral position. 0027 if (m_actionMap.isEmpty()) { 0028 m_actionMap.append(QStringLiteral("monitor_pause")); 0029 } 0030 0031 connect(m_jogShuttle, &JogShuttle::jogBack, pCore->monitorManager(), &MonitorManager::slotRewindOneFrame); 0032 connect(m_jogShuttle, &JogShuttle::jogForward, pCore->monitorManager(), &MonitorManager::slotForwardOneFrame); 0033 connect(m_jogShuttle, &JogShuttle::shuttlePos, this, &JogShuttleAction::slotShuttlePos); 0034 connect(m_jogShuttle, &JogShuttle::button, this, &JogShuttleAction::slotButton); 0035 0036 connect(this, &JogShuttleAction::rewind, pCore->monitorManager(), &MonitorManager::slotRewind); 0037 connect(this, &JogShuttleAction::forward, pCore->monitorManager(), &MonitorManager::slotForward); 0038 } 0039 0040 JogShuttleAction::~JogShuttleAction() = default; 0041 0042 void JogShuttleAction::slotShuttlePos(int shuttle_pos) 0043 { 0044 size_t magnitude = size_t(abs(shuttle_pos)); 0045 if (magnitude < SPEEDS_SIZE) { 0046 if (shuttle_pos < 0) { 0047 Q_EMIT rewind(-SPEEDS[magnitude]); 0048 } else if (shuttle_pos == 0) { 0049 ////qCDebug(KDENLIVE_LOG) << "Shuttle pos0 action: " << m_actionMap[0]; 0050 Q_EMIT action(m_actionMap[0]); 0051 } else if (shuttle_pos > 0) { 0052 Q_EMIT forward(SPEEDS[magnitude]); 0053 } 0054 } 0055 } 0056 0057 void JogShuttleAction::slotButton(int button_id) 0058 { 0059 if (button_id >= m_actionMap.size() || m_actionMap[button_id].isEmpty()) { 0060 // TODO(fleury): Should this go to the status bar to inform the user ? 0061 // qCDebug(KDENLIVE_LOG) << "No action applied for button: " << button_id; 0062 return; 0063 } 0064 ////qCDebug(KDENLIVE_LOG) << "Shuttle button =" << button_id << ": action=" << m_actionMap[button_id]; 0065 Q_EMIT action(m_actionMap[button_id]); 0066 }