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

Fix creating mix between color clip and AV clip

parent c3155b94
...@@ -801,46 +801,37 @@ bool TimelineModel::requestClipMove(int clipId, int trackId, int position, bool ...@@ -801,46 +801,37 @@ 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); pCore->displayMessage(i18n("Select a clip to apply the mix"), InformationMessage, 500);
return false; return false;
} }
std::pair<int, int> clipsToMix;
int mixPosition = 0;
int previousClip = -1;
if (idToMove != -1) {
initialSelection = {idToMove};
idToMove = -1;
}
for (int s : initialSelection) { for (int s : initialSelection) {
if (!isClip(s)) { if (!isClip(s)) {
continue; continue;
} }
if (selectedTrack == -1) { selectedTrack = getClipTrackId(s);
idToMove = s;
break;
}
}
}
if (idToMove == -1 || !isClip(idToMove)) {
pCore->displayMessage(i18n("Select a clip to apply the mix"), InformationMessage, 500);
return false;
}
selectedTrack = getClipTrackId(idToMove);
if (selectedTrack == -1 || !isTrack(selectedTrack)) { if (selectedTrack == -1 || !isTrack(selectedTrack)) {
pCore->displayMessage(i18n("Select a clip to apply the mix"), InformationMessage, 500); continue;
return false;
} }
int mixPosition = getItemPosition(idToMove); mixPosition = getItemPosition(s);
int clipDuration = getItemPlaytime(idToMove); int clipDuration = getItemPlaytime(s);
std::pair<int, int> clipsToMix;
// Check if we have a clip before and/or after // Check if we have a clip before and/or after
int previousClip = -1;
int nextClip = -1; int nextClip = -1;
// Check if clip already has a mix // Check if clip already has a mix
if (getTrackById_const(selectedTrack)->hasStartMix(idToMove)) { if (getTrackById_const(selectedTrack)->hasStartMix(s)) {
if (getTrackById_const(selectedTrack)->hasEndMix(idToMove)) { if (getTrackById_const(selectedTrack)->hasEndMix(s)) {
pCore->displayMessage(i18n("Clip already mixed"), InformationMessage, 500); continue;
return false;
} }
nextClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition + clipDuration + 1); nextClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition + clipDuration + 1);
} else if (getTrackById_const(selectedTrack)->hasEndMix(idToMove)) { } else if (getTrackById_const(selectedTrack)->hasEndMix(s)) {
previousClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition - 1); previousClip = getTrackById_const(selectedTrack)->getClipByPosition(mixPosition - 1);
if (previousClip > -1 && getTrackById_const(selectedTrack)->hasEndMix(previousClip)) { if (previousClip > -1 && getTrackById_const(selectedTrack)->hasEndMix(previousClip)) {
// Could happen if 2 clips before are mixed to full length // Could happen if 2 clips before are mixed to full length
...@@ -862,18 +853,29 @@ bool TimelineModel::mixClip(int idToMove) ...@@ -862,18 +853,29 @@ bool TimelineModel::mixClip(int idToMove)
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 // Mix at start of selected clip
clipsToMix.first = previousClip; clipsToMix.first = previousClip;
clipsToMix.second = idToMove; clipsToMix.second = s;
idToMove = s;
break;
} else { } else {
// Mix at end of selected clip // Mix at end of selected clip
mixPosition += clipDuration; mixPosition += clipDuration;
clipsToMix.first = idToMove; clipsToMix.first = s;
clipsToMix.second = nextClip; clipsToMix.second = nextClip;
idToMove = s;
break;
} }
}
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