Fix crash on split audio/video.

Fixes #756
parent 031ab015
......@@ -765,7 +765,15 @@ bool TimelineFunctions::requestSplitAudio(const std::shared_ptr<TimelineItemMode
}
int position = timeline->getClipPosition(cid);
int track = timeline->getClipTrackId(cid);
QList<int> possibleTracks = audioTarget >= 0 ? QList<int>() << audioTarget : timeline->getLowerTracksId(track, TrackType::AudioTrack);
QList<int> possibleTracks;
if (audioTarget >= 0) {
possibleTracks = {audioTarget};
} else {
int mirror = timeline->getMirrorAudioTrackId(track);
if (mirror > -1) {
possibleTracks = {mirror};
}
}
if (possibleTracks.isEmpty()) {
// No available audio track for splitting, abort
undo();
......@@ -816,7 +824,16 @@ bool TimelineFunctions::requestSplitVideo(const std::shared_ptr<TimelineItemMode
continue;
}
int position = timeline->getClipPosition(cid);
QList<int> possibleTracks = QList<int>() << videoTarget;
int track = timeline->getClipTrackId(cid);
QList<int> possibleTracks;
if (videoTarget >= 0) {
possibleTracks = {videoTarget};
} else {
int mirror = timeline->getMirrorVideoTrackId(track);
if (mirror > -1) {
possibleTracks = {mirror};
}
}
if (possibleTracks.isEmpty()) {
// No available audio track for splitting, abort
undo();
......
......@@ -1165,13 +1165,14 @@ void TimelineController::setPosition(int position)
void TimelineController::setAudioTarget(QMap<int, int> tracks)
{
if ((!tracks.isEmpty() && !m_model->isTrack(tracks.firstKey())) || m_hasAudioTarget == 0) {
return;
}
// Clear targets before re-adding to trigger qml refresh
m_model->m_audioTarget.clear();
emit audioTargetChanged();
if ((!tracks.isEmpty() && !m_model->isTrack(tracks.firstKey())) || m_hasAudioTarget == 0) {
return;
}
m_model->m_audioTarget = tracks;
emit audioTargetChanged();
}
......@@ -1225,6 +1226,7 @@ int TimelineController::getFirstUnassignedStream() const
void TimelineController::setVideoTarget(int track)
{
if ((track > -1 && !m_model->isTrack(track)) || !m_hasVideoTarget) {
m_model->m_videoTarget = -1;
return;
}
m_model->m_videoTarget = track;
......@@ -2313,7 +2315,9 @@ bool TimelineController::splitAV()
if (clip->clipState() == PlaylistState::AudioOnly) {
return TimelineFunctions::requestSplitVideo(m_model, cid, videoTarget());
} else {
return TimelineFunctions::requestSplitAudio(m_model, cid, m_model->m_audioTarget.firstKey());
QVariantList aTargets = audioTarget();
int targetTrack = aTargets.isEmpty() ? -1 : aTargets.first().toInt();
return TimelineFunctions::requestSplitAudio(m_model, cid, targetTrack);
}
}
pCore->displayMessage(i18n("No clip found to perform AV split operation"), InformationMessage, 500);
......@@ -2322,7 +2326,9 @@ bool TimelineController::splitAV()
void TimelineController::splitAudio(int clipId)
{
TimelineFunctions::requestSplitAudio(m_model, clipId, m_model->m_audioTarget.firstKey());
QVariantList aTargets = audioTarget();
int targetTrack = aTargets.isEmpty() ? -1 : aTargets.first().toInt();
TimelineFunctions::requestSplitAudio(m_model, clipId, targetTrack);
}
void TimelineController::splitVideo(int clipId)
......@@ -2871,7 +2877,25 @@ void TimelineController::updateClipActions()
} else if (actionData == QLatin1Char('X') || actionData == QLatin1Char('S')) {
enableAction = clip && clip->canBeVideo() && clip->canBeAudio();
if (enableAction && actionData == QLatin1Char('S')) {
act->setText(clip->clipState() == PlaylistState::AudioOnly ? i18n("Split video") : i18n("Split audio"));
PlaylistState::ClipState state = clip->clipState();
if (m_model->m_groups->isInGroup(item)) {
// Check if all clips in the group have have same state (audio or video)
int targetRoot = m_model->m_groups->getRootId(item);
if (m_model->isGroup(targetRoot)) {
std::unordered_set<int> sub = m_model->m_groups->getLeaves(targetRoot);
for (int current_id : sub) {
if (current_id == item) {
continue;
}
if (m_model->isClip(current_id) && m_model->getClipPtr(current_id)->clipState() != state) {
// Group with audio and video clips, disable split action
enableAction = false;
break;
}
}
}
}
act->setText(state == PlaylistState::AudioOnly ? i18n("Split video") : i18n("Split audio"));
}
} else if (actionData == QLatin1Char('W')) {
enableAction = clip != nullptr;
......
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