Don't lose pitch shift when reloading a timeline clip

parent 255dc789
......@@ -411,7 +411,7 @@ bool ClipModel::isAudioOnly() const
return m_currentState == PlaylistState::AudioOnly;
}
void ClipModel::refreshProducerFromBin(int trackId, PlaylistState::ClipState state, double speed)
void ClipModel::refreshProducerFromBin(int trackId, PlaylistState::ClipState state, double speed, bool hasPitch)
{
// We require that the producer is not in the track when we refresh the producer, because otherwise the modification will not be propagated. Remove the clip
// first, refresh, and then replant.
......@@ -430,6 +430,12 @@ void ClipModel::refreshProducerFromBin(int trackId, PlaylistState::ClipState sta
std::shared_ptr<Mlt::Producer> binProducer = binClip->getTimelineProducer(trackId, m_id, state, m_speed);
m_producer = std::move(binProducer);
m_producer->set_in_and_out(in, out);
if (hasPitch) {
// Check if pitch shift is enabled
m_producer->parent().set("warp_pitch", 1);
} else if (!qFuzzyCompare(m_speed, 1.)) {
m_producer->parent().set("warp_pitch", 0);
}
// replant effect stack in updated service
m_effectStack->resetService(m_producer);
m_producer->set("kdenlive:id", binClip->clipId().toUtf8().constData());
......@@ -437,12 +443,12 @@ void ClipModel::refreshProducerFromBin(int trackId, PlaylistState::ClipState sta
m_endlessResize = !binClip->hasLimitedDuration();
}
void ClipModel::refreshProducerFromBin(int trackId)
void ClipModel::refreshProducerFromBin(int trackId, bool hasPitch)
{
if (trackId == -1) {
trackId = m_currentTrackId;
}
refreshProducerFromBin(trackId, m_currentState);
refreshProducerFromBin(trackId, m_currentState, 0, hasPitch);
}
bool ClipModel::useTimewarpProducer(double speed, bool pitchCompensate, bool changeDuration, Fun &undo, Fun &redo)
......@@ -521,8 +527,7 @@ Fun ClipModel::useTimewarpProducer_lambda(double speed, bool pitchCompensate)
QWriteLocker locker(&m_lock);
return [speed, pitchCompensate, this]() {
qDebug() << "timeWarp producer" << speed;
refreshProducerFromBin(m_currentTrackId, m_currentState, speed);
m_producer->parent().set("warp_pitch", pitchCompensate ? 1 : 0);
refreshProducerFromBin(m_currentTrackId, m_currentState, speed, pitchCompensate);
return true;
};
}
......
......@@ -179,8 +179,8 @@ protected:
* @param speed corresponds to the speed we need. Leave to 0 to keep current speed. Warning: this function doesn't notify the model. Unless you know what
* you are doing, better use useTimewarProducer to change the speed
*/
void refreshProducerFromBin(int trackId, PlaylistState::ClipState state, double speed = 0);
void refreshProducerFromBin(int trackId = -1);
void refreshProducerFromBin(int trackId, PlaylistState::ClipState state, double speed, bool hasPitch);
void refreshProducerFromBin(int trackId, bool hasPitch);
/* @brief This functions replaces the current producer with a slowmotion one
It also resizes the producer so that set of frames contained in the clip is the same
......
......@@ -3490,6 +3490,7 @@ void TimelineModel::requestClipReload(int clipId)
int oldPos = getClipPosition(clipId);
int oldOut = getClipIn(clipId) + getClipPlaytime(clipId);
int maxDuration = m_allClips[clipId]->getMaxDuration();
bool hasPitch = m_allClips[clipId]->getIntProperty(QStringLiteral("warp_pitch"));
// Check if clip out is longer than actual producer duration (if user forced duration)
std::shared_ptr<ProjectClip> binClip = pCore->projectItemModel()->getClipByBinID(getClipBinId(clipId));
bool refreshView = oldOut > (int)binClip->frameDuration();
......@@ -3497,7 +3498,7 @@ void TimelineModel::requestClipReload(int clipId)
getTrackById(old_trackId)->requestClipDeletion(clipId, refreshView, true, local_undo, local_redo, false, false);
}
if (old_trackId != -1) {
m_allClips[clipId]->refreshProducerFromBin(old_trackId);
m_allClips[clipId]->refreshProducerFromBin(old_trackId, hasPitch);
getTrackById(old_trackId)->requestClipInsertion(clipId, oldPos, refreshView, true, local_undo, local_redo);
if (maxDuration != m_allClips[clipId]->getMaxDuration()) {
QModelIndex ix = makeClipIndexFromID(clipId);
......
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