Skip to content

Commit

Permalink
Do not group audio/video clips when detaching audio
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Feb 10, 2024
1 parent 4d6fecc commit 19fdd8f
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/commands/timelinecommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1718,9 +1718,19 @@ void DetachAudioCommand::redo()
TimelineSelectionSilencer selectionSilencer(m_timeline);
Mlt::Producer audioClip(MLT.profile(), "xml-string", m_xml.toUtf8().constData());
Mlt::Producer videoClip(MLT.profile(), "xml-string", m_xml.toUtf8().constData());
int groupNumber = -1;
if (audioClip.is_valid() && videoClip.is_valid()) {
auto model = m_timeline.model();

// Save the group number if it exists
{
auto videoClipInfo = model->getClipInfo(m_trackIndex, m_clipIndex);
if (videoClipInfo && videoClipInfo->cut
&& videoClipInfo->cut->property_exists(kShotcutGroupProperty)) {
groupNumber = videoClipInfo->cut->get_int(kShotcutGroupProperty);
}
}

// Disable audio on the video clip.
videoClip.set("astream", -1);
videoClip.set("audio_index", -1);
Expand Down Expand Up @@ -1793,23 +1803,18 @@ void DetachAudioCommand::redo()
model->overwrite(m_targetTrackIndex, audioClip, m_position, false);
// Replace the original clip with the video only clip
model->overwrite(m_trackIndex, videoClip, m_position, false);
// Put the clips in a group
int groupNumber = getUniqueGroupNumber(*model);
int audioClipIndex = model->clipIndex(m_targetTrackIndex, m_position);
auto audioClipInfo = model->getClipInfo(m_targetTrackIndex, audioClipIndex);
if (audioClipInfo && audioClipInfo->cut) {
audioClipInfo->cut->set(kShotcutGroupProperty, groupNumber);
}
auto videoClipInfo = model->getClipInfo(m_trackIndex, m_clipIndex);
if (videoClipInfo && videoClipInfo->cut) {
videoClipInfo->cut->set(kShotcutGroupProperty, groupNumber);
// Restore the video clip group
if (groupNumber >= 0) {
auto videoClipInfo = model->getClipInfo(m_trackIndex, m_clipIndex);
if (videoClipInfo && videoClipInfo->cut) {
videoClipInfo->cut->set(kShotcutGroupProperty, groupNumber);
}
}
m_undoHelper.recordAfterState();
QModelIndex modelIndex = model->makeIndex(m_trackIndex, m_clipIndex);
emit model->dataChanged(modelIndex, modelIndex,
QVector<int>() << MultitrackModel::AudioIndexRole << MultitrackModel::GroupRole);
m_timeline.setSelection(QList<QPoint>() << QPoint(m_clipIndex,
m_trackIndex) << QPoint(audioClipIndex, m_targetTrackIndex));
m_timeline.setSelection(QList<QPoint>() << QPoint(m_clipIndex, m_trackIndex));
}
}
}
Expand Down

0 comments on commit 19fdd8f

Please sign in to comment.