Also consider moving clip's markers for snapping.

Fixes #661
parent 8796b4f9
......@@ -331,12 +331,12 @@ QList<CommentedTime> MarkerListModel::getAllMarkers() const
return markers;
}
std::vector<size_t> MarkerListModel::getSnapPoints() const
std::vector<int> MarkerListModel::getSnapPoints() const
{
READ_LOCK();
std::vector<size_t> markers;
std::vector<int> markers;
for (const auto &marker : m_markerList) {
markers.push_back((size_t)marker.first.frames(pCore->getCurrentFps()));
markers.push_back(marker.first.frames(pCore->getCurrentFps()));
}
return markers;
}
......
......@@ -99,7 +99,7 @@ public:
QList<CommentedTime> getAllMarkers() const;
/* @brief Returns all markers positions in model */
std::vector<size_t> getSnapPoints() const;
std::vector<int> getSnapPoints() const;
/* @brief Returns true if a marker exists at given pos
Notice that add/remove queries are done in real time (gentime), but this request is made in frame
......
......@@ -91,7 +91,7 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
return id;
}
void ClipModel::allSnaps(std::vector<size_t> &snaps)
void ClipModel::allSnaps(std::vector<int> &snaps)
{
m_clipMarkerModel->allSnaps(snaps);
}
......
......@@ -108,7 +108,7 @@ public:
QDomElement toXml(QDomDocument &document);
/* @brief Retrieve a list of all snaps for this clip */
void allSnaps(std::vector<size_t> &snaps);
void allSnaps(std::vector<int> &snaps);
protected:
// helper functions that creates the lambda
......
......@@ -89,10 +89,9 @@ void ClipSnapModel::removeAllSnaps()
}
}
void ClipSnapModel::allSnaps(std::vector<size_t> &snaps)
void ClipSnapModel::allSnaps(std::vector<int> &snaps)
{
snaps.push_back((size_t)m_position);
snaps.push_back((size_t)(m_position + m_outPoint - m_inPoint));
snaps.push_back(m_position);
if (auto ptr = m_registeredSnap.lock()) {
for (const auto &snap : m_snapPoints) {
if (snap >= m_inPoint * m_speed && snap < m_outPoint * m_speed) {
......@@ -100,6 +99,7 @@ void ClipSnapModel::allSnaps(std::vector<size_t> &snaps)
}
}
}
snaps.push_back(m_position + m_outPoint - m_inPoint + 1);
}
void ClipSnapModel::registerSnapModel(const std::weak_ptr<SnapModel> &snapModel, int position, int in, int out, double speed)
......
......@@ -54,7 +54,7 @@ public:
void updateSnapModelPos(int newPos);
void updateSnapModelInOut(std::pair<int, int> newInOut);
/* @brief Retrieve all snap points */
void allSnaps(std::vector<size_t> &snaps);
void allSnaps(std::vector<int> &snaps);
private:
......
......@@ -729,9 +729,14 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cu
}
for (int current_clipId : all_items) {
if (getItemTrackId(current_clipId) != -1) {
int in = getItemPosition(current_clipId);
ignored_pts.push_back(in);
ignored_pts.push_back(in + getItemPlaytime(current_clipId));
if (isClip(current_clipId)) {
m_allClips[current_clipId]->allSnaps(ignored_pts);
} else {
// Composition
int in = getItemPosition(current_clipId);
ignored_pts.push_back(in);
ignored_pts.push_back(in + getItemPlaytime(current_clipId));
}
}
}
int snapped = getBestSnapPos(currentPos, position - currentPos, m_editMode == TimelineMode::NormalEdit ? ignored_pts : std::vector<int>(),
......@@ -2759,7 +2764,7 @@ int TimelineModel::getBestSnapPos(int referencePos, int diff, std::vector<int> p
return closest;
}
int TimelineModel::getNextSnapPos(int pos, std::vector<size_t> &snaps)
int TimelineModel::getNextSnapPos(int pos, std::vector<int> &snaps)
{
QVector<int>tracks;
// Get active tracks
......@@ -2792,7 +2797,7 @@ int TimelineModel::getNextSnapPos(int pos, std::vector<size_t> &snaps)
return pos;
}
int TimelineModel::getPreviousSnapPos(int pos, std::vector<size_t> &snaps)
int TimelineModel::getPreviousSnapPos(int pos, std::vector<int> &snaps)
{
QVector<int>tracks;
// Get active tracks
......
......@@ -559,12 +559,12 @@ public:
/* @brief Requests the next snapped point
@param pos is the current position
*/
int getNextSnapPos(int pos, std::vector<size_t> &snaps);
int getNextSnapPos(int pos, std::vector<int> &snaps);
/* @brief Requests the previous snapped point
@param pos is the current position
*/
int getPreviousSnapPos(int pos, std::vector<size_t> &snaps);
int getPreviousSnapPos(int pos, std::vector<int> &snaps);
/* @brief Add a new snap point
@param pos is the current position
......
......@@ -686,8 +686,8 @@ void TimelineController::gotoNextSnap()
m_snapStackIndex = pCore->undoIndex();
m_activeSnaps.clear();
m_activeSnaps = pCore->projectManager()->current()->getGuideModel()->getSnapPoints();
m_activeSnaps.push_back((size_t)m_zone.x());
m_activeSnaps.push_back((size_t)(m_zone.y() - 1));
m_activeSnaps.push_back(m_zone.x());
m_activeSnaps.push_back(m_zone.y() - 1);
}
int nextSnap = m_model->getNextSnapPos(pCore->getTimelinePosition(), m_activeSnaps);
if (nextSnap > pCore->getTimelinePosition()) {
......@@ -702,8 +702,8 @@ void TimelineController::gotoPreviousSnap()
m_snapStackIndex = pCore->undoIndex();
m_activeSnaps.clear();
m_activeSnaps = pCore->projectManager()->current()->getGuideModel()->getSnapPoints();
m_activeSnaps.push_back((size_t)m_zone.x());
m_activeSnaps.push_back((size_t)(m_zone.y() - 1));
m_activeSnaps.push_back(m_zone.x());
m_activeSnaps.push_back(m_zone.y() - 1);
}
setPosition(m_model->getPreviousSnapPos(pCore->getTimelinePosition(), m_activeSnaps));
}
......
......@@ -588,7 +588,7 @@ private:
std::shared_ptr<AudioCorrelation> m_audioCorrelator;
QMutex m_metaMutex;
bool m_ready;
std::vector<size_t> m_activeSnaps;
std::vector<int> m_activeSnaps;
int m_snapStackIndex;
QMetaObject::Connection m_connection;
......
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