Commit c354bb15 authored by Nicolas Carion's avatar Nicolas Carion

more interface cleanup

parent 6d4a820b
......@@ -371,7 +371,7 @@ void ClipModel::refreshProducerFromBin()
refreshProducerFromBin(m_currentState);
}
bool ClipModel::useTimewarpProducer(double speed, int extraSpace, Fun &undo, Fun &redo)
bool ClipModel::useTimewarpProducer(double speed, Fun &undo, Fun &redo)
{
if (m_endlessResize) {
// no timewarp for endless producers
......
......@@ -151,7 +151,7 @@ protected:
/* @brief This functions should be called when the producer of the binClip changes, to allow refresh
* @param state corresponds to the state of the clip we want (audio or video)
* @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 uteTimewarProducer to change the speed
* you are doing, better use useTimewarProducer to change the speed
*/
void refreshProducerFromBin(PlaylistState::ClipState state, double speed = 0);
void refreshProducerFromBin();
......@@ -159,7 +159,7 @@ protected:
/* @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
*/
bool useTimewarpProducer(double speed, int extraSpace, Fun &undo, Fun &redo);
bool useTimewarpProducer(double speed, Fun &undo, Fun &redo);
// @brief Lambda that merely changes the speed (in and out are untouched)
Fun useTimewarpProducer_lambda(double speed);
......
......@@ -39,7 +39,7 @@ bool TimelineFunctions::copyClip(std::shared_ptr<TimelineItemModel> timeline, in
timeline->m_allClips[newId]->m_endlessResize = timeline->m_allClips[clipId]->m_endlessResize;
// Apply speed effect if necessary
if (!qFuzzyCompare(clipSpeed, 1.0)) {
timeline->m_allClips[newId]->useTimewarpProducer(clipSpeed, -1, undo, redo);
timeline->m_allClips[newId]->useTimewarpProducer(clipSpeed, undo, redo);
}
// copy useful timeline properties
timeline->m_allClips[clipId]->passTimelineProperties(timeline->m_allClips[newId]);
......
......@@ -2196,7 +2196,7 @@ void TimelineModel::requestClipUpdate(int clipId, const QVector<int> &roles)
notifyChange(modelIndex, modelIndex, roles);
}
bool TimelineModel::requestClipTimeWarp(int clipId, int blankSpace, double speed, Fun &undo, Fun &redo)
bool TimelineModel::requestClipTimeWarp(int clipId, double speed, Fun &undo, Fun &redo)
{
QWriteLocker locker(&m_lock);
if (qFuzzyCompare(speed, m_allClips[clipId]->getSpeed())) {
......@@ -2212,7 +2212,7 @@ bool TimelineModel::requestClipTimeWarp(int clipId, int blankSpace, double speed
success = success && getTrackById(trackId)->requestClipDeletion(clipId, true, true, local_undo, local_redo);
}
if (success) {
success = m_allClips[clipId]->useTimewarpProducer(speed, blankSpace, local_undo, local_redo);
success = m_allClips[clipId]->useTimewarpProducer(speed, local_undo, local_redo);
}
if (trackId != -1) {
success = success && getTrackById(trackId)->requestClipInsertion(clipId, oldPos, true, true, local_undo, local_redo);
......@@ -2225,7 +2225,7 @@ bool TimelineModel::requestClipTimeWarp(int clipId, int blankSpace, double speed
return success;
}
bool TimelineModel::changeItemSpeed(int clipId, double speed)
bool TimelineModel::requestClipTimeWarp(int clipId, double speed)
{
Fun undo = []() { return true; };
Fun redo = []() { return true; };
......@@ -2237,26 +2237,18 @@ bool TimelineModel::changeItemSpeed(int clipId, double speed)
// Check if clip has a split partner
int splitId = m_groups->getSplitPartner(clipId);
if (splitId > -1) {
int split_trackId = getClipTrackId(splitId);
int partnerSpace = getTrackById(split_trackId)->getBlankSizeNearClip(splitId, true);
if (partnerSpace > 0) {
if (blankSpace < 0) {
blankSpace = partnerSpace;
} else {
blankSpace = qMin(blankSpace, partnerSpace);
}
}
result = requestClipTimeWarp(splitId, blankSpace, speed / 100.0, undo, redo);
result = requestClipTimeWarp(splitId, speed / 100.0, undo, redo);
}
if (result) {
result = requestClipTimeWarp(clipId, blankSpace, speed / 100.0, undo, redo);
result = requestClipTimeWarp(clipId, speed / 100.0, undo, redo);
} else {
pCore->displayMessage(i18n("Change speed failed"), ErrorMessage);
undo();
return false;
}
} else {
// If clip is not inserted on a track, we just change the producer
m_allClips[clipId]->useTimewarpProducer(speed, -1, undo, redo);
m_allClips[clipId]->useTimewarpProducer(speed, undo, redo);
}
if (result) {
PUSH_UNDO(undo, redo, i18n("Change clip speed"));
......
......@@ -527,9 +527,17 @@ public:
std::shared_ptr<EffectStackModel> getClipEffectStack(int itemId);
std::shared_ptr<EffectStackModel> getTrackEffectStackModel(int trackId);
/** @brief Add slowmotion effect to clip in timeline. */
bool requestClipTimeWarp(int clipId, int blankSpace, double speed, Fun &undo, Fun &redo);
bool changeItemSpeed(int clipId, double speed);
/** @brief Add slowmotion effect to clip in timeline.
@param clipId id of the target clip
@param speed: speed in percentage. 100 corresponds to original speed, 50 to half the speed
This functions create an undo object and also apply the effect to the corresponding audio if there is any.
Returns true on success, false otherwise (and nothing is modifed)
*/
bool requestClipTimeWarp(int clipId, double speed);
/* @brief Same function as above, but doesn't check for paired audio and accumulate undo/redo
*/
bool requestClipTimeWarp(int clipId, double speed, Fun &undo, Fun &redo);
void replugClip(int clipId);
/** @brief Refresh the tractor profile in case a change was requested. */
void updateProfile(Mlt::Profile *profile);
......
......@@ -1294,7 +1294,7 @@ void TimelineController::changeItemSpeed(int clipId, double speed)
return;
}
}
m_model->changeItemSpeed(clipId, speed);
m_model->requestClipTimeWarp(clipId, speed);
}
void TimelineController::switchCompositing(int mode)
......
......@@ -52,7 +52,7 @@ TEST_CASE("Test of timewarping", "[Timewarp]")
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
REQUIRE(timeline->requestClipTimeWarp(cid3, 100000, 0.1, undo, redo));
REQUIRE(timeline->requestClipTimeWarp(cid3, 0.1, undo, redo));
CHECK_UPDATE(TimelineModel::SpeedRole);
REQUIRE(timeline->getClipSpeed(cid3) == 0.1);
......@@ -74,7 +74,7 @@ TEST_CASE("Test of timewarping", "[Timewarp]")
std::function<bool(void)> undo2 = []() { return true; };
std::function<bool(void)> redo2 = []() { return true; };
REQUIRE(timeline->requestClipTimeWarp(cid3, 100000, 1.2, undo2, redo2));
REQUIRE(timeline->requestClipTimeWarp(cid3, 1.2, undo2, redo2));
CHECK_UPDATE(TimelineModel::SpeedRole);
REQUIRE(timeline->getClipSpeed(cid3) == 1.2);
......@@ -95,13 +95,13 @@ TEST_CASE("Test of timewarping", "[Timewarp]")
int curLength = timeline->getClipPlaytime(cid3);
// This is the limit, should work
REQUIRE(timeline->requestClipTimeWarp(cid3, 100000, double(curLength), undo2, redo2));
REQUIRE(timeline->requestClipTimeWarp(cid3, double(curLength), undo2, redo2));
CHECK_UPDATE(TimelineModel::SpeedRole);
REQUIRE(timeline->getClipSpeed(cid3) == double(curLength));
REQUIRE(timeline->getClipPlaytime(cid3) == 1);
// This is the higher than the limit, should not work
REQUIRE_FALSE(timeline->requestClipTimeWarp(cid3, 100000, double(curLength) + 0.1, undo2, redo2));
REQUIRE_FALSE(timeline->requestClipTimeWarp(cid3, double(curLength) + 0.1, undo2, redo2));
}
}
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