Commit 40085a04 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Fix creating mix between color clip and AV clip

parent c3155b94
...@@ -801,79 +801,81 @@ bool TimelineModel::requestClipMove(int clipId, int trackId, int position, bool ...@@ -801,79 +801,81 @@ bool TimelineModel::requestClipMove(int clipId, int trackId, int position, bool
bool TimelineModel::mixClip(int idToMove) bool TimelineModel::mixClip(int idToMove)
{ {
int selectedTrack = -1; int selectedTrack = -1;
std::unordered_set<int> initialSelection; std::unordered_set<int> initialSelection = getCurrentSelection();
if (idToMove == -1) { if (idToMove == -1 && initialSelection.empty()) {
initialSelection = getCurrentSelection();
if (initialSelection.empty()) {
pCore->displayMessage(i18n("Select a clip to apply the mix"), InformationMessage, 500);
return false;
}
for (int s : initialSelection) {
if (!isClip(s)) {
continue;
}
if (selectedTrack == -1) {
idToMove = s;
break;
}
}
}
if (idToMove == -1 || !isClip(idToMove)) {
pCore->displayMessage(i18n("Select a clip to apply the mix"), InformationMessage, 500); pCore->displayMessage(i18n("Select a clip to apply the mix"), InformationMessage, 500);
return false; return false;
} }
selectedTrack = getClipTrackId(idToMove);
if (selectedTrack == -1 || !isTrack(selectedTrack)) {
pCore->displayMessage(i18n("Select a clip to apply the mix"), InformationMessage, 500);
return false;
}
int mixPosition = getItemPosition(idToMove);
int clipDuration = getItemPlaytime(idToMove);
std::pair<int, int> clipsToMix; std::pair<int, int> clipsToMix;
// Check if we have a clip before and/or after int mixPosition = 0;
int previousClip = -1; int previousClip = -1;
int nextClip = -1; if (idToMove != -1) {
// Check if clip already has a mix initialSelection = {idToMove};
if (getTrackById_const(selectedTrack)->hasStartMix(idToMove)) { idToMove = -1;
if (getTrackById_const(selectedTrack)->hasEndMix(idToMove)) { }
pCore->displayMessage(i18n("Clip already mixed"), InformationMessage, 500); for (int s : initialSelection) {
return false; if (!isClip(s)) {
continue;
} }
nextClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition + clipDuration + 1); selectedTrack = getClipTrackId(s);
} else if (getTrackById_const(selectedTrack)->hasEndMix(idToMove)) { if (selectedTrack == -1 || !isTrack(selectedTrack)) {
previousClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition - 1); continue;
if (previousClip > -1 && getTrackById_const(selectedTrack)->hasEndMix(previousClip)) {
// Could happen if 2 clips before are mixed to full length
previousClip = -1;
} }
} else { mixPosition = getItemPosition(s);
previousClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition - 1); int clipDuration = getItemPlaytime(s);
nextClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition + clipDuration + 1); // Check if we have a clip before and/or after
} int nextClip = -1;
if (previousClip > -1 && nextClip > -1) { // Check if clip already has a mix
// We have a clip before and a clip after, check timeline cursor position to decide where to mix if (getTrackById_const(selectedTrack)->hasStartMix(s)) {
int cursor = pCore->getTimelinePosition(); if (getTrackById_const(selectedTrack)->hasEndMix(s)) {
if (cursor < mixPosition + clipDuration / 2) { continue;
nextClip = -1; }
nextClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition + clipDuration + 1);
} else if (getTrackById_const(selectedTrack)->hasEndMix(s)) {
previousClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition - 1);
if (previousClip > -1 && getTrackById_const(selectedTrack)->hasEndMix(previousClip)) {
// Could happen if 2 clips before are mixed to full length
previousClip = -1;
}
} else { } else {
previousClip = -1; previousClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition - 1);
nextClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition + clipDuration + 1);
}
if (previousClip > -1 && nextClip > -1) {
// We have a clip before and a clip after, check timeline cursor position to decide where to mix
int cursor = pCore->getTimelinePosition();
if (cursor < mixPosition + clipDuration / 2) {
nextClip = -1;
} else {
previousClip = -1;
}
} }
} if (nextClip == -1) {
if (nextClip == -1) { if (previousClip == -1) {
if (previousClip == -1) {
// No clip to mix, abort // No clip to mix, abort
pCore->displayMessage(i18n("No adjacent clip to perform mix"), InformationMessage, 500); continue;
return false; }
// Mix at start of selected clip
clipsToMix.first = previousClip;
clipsToMix.second = s;
idToMove = s;
break;
} else {
// Mix at end of selected clip
mixPosition += clipDuration;
clipsToMix.first = s;
clipsToMix.second = nextClip;
idToMove = s;
break;
} }
// Mix at start of selected clip
clipsToMix.first = previousClip;
clipsToMix.second = idToMove;
} else {
// Mix at end of selected clip
mixPosition += clipDuration;
clipsToMix.first = idToMove;
clipsToMix.second = nextClip;
} }
if (idToMove == -1 || !isClip(idToMove)) {
pCore->displayMessage(i18n("Select a clip to apply the mix"), InformationMessage, 500);
return false;
}
std::function<bool(void)> undo = []() { return true; }; std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; }; std::function<bool(void)> redo = []() { return true; };
bool result = requestClipMix(clipsToMix, selectedTrack, mixPosition, true, true, true, undo, bool result = requestClipMix(clipsToMix, selectedTrack, mixPosition, true, true, true, undo,
......
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