Seek to next snap only considers active tracks

parent 62e1428d
Pipeline #16456 passed with stage
in 15 minutes and 9 seconds
......@@ -91,6 +91,11 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
return id;
}
void ClipModel::allSnaps(std::vector<size_t> &snaps)
{
m_clipMarkerModel->allSnaps(snaps);
}
int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, const std::shared_ptr<Mlt::Producer> &producer,
PlaylistState::ClipState state)
{
......
......@@ -107,6 +107,9 @@ public:
/* @brief Returns an XML representation of the clip with its effects */
QDomElement toXml(QDomDocument &document);
/* @brief Retrieve a list of all snaps for this clip */
void allSnaps(std::vector<size_t> &snaps);
protected:
// helper functions that creates the lambda
Fun setClipState_lambda(PlaylistState::ClipState state);
......
......@@ -89,6 +89,19 @@ void ClipSnapModel::removeAllSnaps()
}
}
void ClipSnapModel::allSnaps(std::vector<size_t> &snaps)
{
snaps.push_back(m_position);
snaps.push_back(m_position + m_outPoint - m_inPoint);
if (auto ptr = m_registeredSnap.lock()) {
for (const auto &snap : m_snapPoints) {
if (snap >= m_inPoint * m_speed && snap < m_outPoint * m_speed) {
snaps.push_back(m_speed < 0 ? ceil(m_outPoint + m_position + snap / m_speed - m_inPoint) : ceil(m_position + snap / m_speed - m_inPoint));
}
}
}
}
void ClipSnapModel::registerSnapModel(const std::weak_ptr<SnapModel> &snapModel, int position, int in, int out, double speed)
{
// make sure ptr is valid
......
......@@ -53,6 +53,8 @@ public:
void updateSnapModelPos(int newPos);
void updateSnapModelInOut(std::pair<int, int> newInOut);
/* @brief Retrieve all snap points */
void allSnaps(std::vector<size_t> &snaps);
private:
......
......@@ -2713,14 +2713,72 @@ int TimelineModel::getBestSnapPos(int pos, int length, const std::vector<int> &p
return -1;
}
int TimelineModel::getNextSnapPos(int pos)
int TimelineModel::getNextSnapPos(int pos, std::vector<size_t> &snaps)
{
return m_snaps->getNextPoint(pos);
QVector<int>tracks;
// Get active tracks
auto it = m_allTracks.cbegin();
while (it != m_allTracks.cend()) {
if ((*it)->shouldReceiveTimelineOp()) {
tracks << (*it)->getId();
}
++it;
}
if (tracks.isEmpty()) {
// No active track, use all possible snap points
return m_snaps->getNextPoint((int)pos);
}
// Build snap points for selected tracks
for (const auto &cp : m_allClips) {
// Check if clip is on a target track
if (tracks.contains(cp.second->getCurrentTrackId())) {
auto clip = (cp.second);
clip->allSnaps(snaps);
}
}
// sort snaps
std::sort(snaps.begin(), snaps.end());
for (auto i : snaps) {
if (i > pos) {
return i;
}
}
return pos;
}
int TimelineModel::getPreviousSnapPos(int pos)
int TimelineModel::getPreviousSnapPos(int pos, std::vector<size_t> &snaps)
{
return m_snaps->getPreviousPoint(pos);
QVector<int>tracks;
// Get active tracks
auto it = m_allTracks.cbegin();
while (it != m_allTracks.cend()) {
if ((*it)->shouldReceiveTimelineOp()) {
tracks << (*it)->getId();
}
++it;
}
if (tracks.isEmpty()) {
// No active track, use all possible snap points
return m_snaps->getPreviousPoint((int)pos);
}
// Build snap points for selected tracks
for (const auto &cp : m_allClips) {
// Check if clip is on a target track
if (tracks.contains(cp.second->getCurrentTrackId())) {
auto clip = (cp.second);
clip->allSnaps(snaps);
}
}
// sort snaps
std::sort(snaps.begin(), snaps.end());
// sort descending
std::reverse(snaps.begin(),snaps.end());
for (auto i : snaps) {
if (i < pos) {
return i;
}
}
return 0;
}
void TimelineModel::addSnap(int pos)
......
......@@ -559,12 +559,12 @@ public:
/* @brief Requests the next snapped point
@param pos is the current position
*/
int getNextSnapPos(int pos);
int getNextSnapPos(int pos, std::vector<size_t> &snaps);
/* @brief Requests the previous snapped point
@param pos is the current position
*/
int getPreviousSnapPos(int pos);
int getPreviousSnapPos(int pos, std::vector<size_t> &snaps);
/* @brief Add a new snap point
@param pos is the current position
......
......@@ -266,7 +266,7 @@ protected:
bool importEffects(std::weak_ptr<Mlt::Service> service);
/* @brief Copy effects from anoter effect stack */
bool copyEffect(const std::shared_ptr<EffectStackModel> &stackModel, int rowId);
/* @brief Returns true if we have a blank at position for duration */
bool isAvailable(int position, int duration);
public slots:
......
......@@ -663,7 +663,10 @@ void TimelineController::showConfig(int page, int tab)
void TimelineController::gotoNextSnap()
{
int nextSnap = m_model->getNextSnapPos(pCore->getTimelinePosition());
std::vector<size_t> snaps = pCore->projectManager()->current()->getGuideModel()->getSnapPoints();
snaps.push_back(m_zone.x());
snaps.push_back(m_zone.y());
int nextSnap = m_model->getNextSnapPos(pCore->getTimelinePosition(), snaps);
if (nextSnap > pCore->getTimelinePosition()) {
setPosition(nextSnap);
}
......@@ -672,7 +675,10 @@ void TimelineController::gotoNextSnap()
void TimelineController::gotoPreviousSnap()
{
if (pCore->getTimelinePosition() > 0) {
setPosition(m_model->getPreviousSnapPos(pCore->getTimelinePosition()));
std::vector<size_t> snaps = pCore->projectManager()->current()->getGuideModel()->getSnapPoints();
snaps.push_back(m_zone.x());
snaps.push_back(m_zone.y());
setPosition(m_model->getPreviousSnapPos(pCore->getTimelinePosition(), snaps));
}
}
......@@ -2958,4 +2964,3 @@ const QVariant TimelineController::getActiveTrackProperty(const QString &name) c
}
return QVariant();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment