Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Fix automatic split on clip insertion

parent 0644c505
......@@ -31,6 +31,7 @@
#include "kdenlivesettings.h"
#include "snapmodel.hpp"
#include "trackmodel.hpp"
#include "timelinefunctions.hpp"
#include <QDebug>
#include <QModelIndex>
......@@ -62,6 +63,8 @@ TimelineModel::TimelineModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack>
, m_id(getNextId())
, m_temporarySelectionGroup(-1)
, m_overlayTrackCount(-1)
, m_audioTarget(-1)
, m_videoTarget(-1)
{
// Create black background track
m_blackClip->set("id", "black_track");
......@@ -606,6 +609,30 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
if (KdenliveSettings::splitaudio()) {
res = requestClipCreation(binClipId, id, PlaylistState::VideoOnly, local_undo, local_redo);
res = res && requestClipMove(id, trackId, position, refreshView, logUndo, local_undo, local_redo);
if (res && logUndo) {
QList<int> possibleTracks = m_audioTarget >= 0 ? QList<int>() <<m_audioTarget : getLowerTracksId(trackId, TrackType::AudioTrack);
if (possibleTracks.isEmpty()) {
// No available audio track for splitting, abort
pCore->displayMessage(i18n("No available audio track for split operation"), ErrorMessage);
res = false;
} else {
int newId;
res =requestClipCreation(binClipId, newId, PlaylistState::AudioOnly, local_undo, local_redo);
bool move = false;
while (!move && !possibleTracks.isEmpty()) {
int newTrack = possibleTracks.takeFirst();
move = requestClipMove(newId, newTrack, position, true, false, undo, redo);
}
/*std::unordered_set<int> groupClips;
groupClips.insert(cid);
groupClips.insert(newId);*/
if (!res || !move) {
pCore->displayMessage(i18n("Audio split failed"), ErrorMessage);
} else {
requestClipsGroup({id, newId}, local_undo, local_redo, GroupType::AVSplit);
}
}
}
} else {
res = requestClipCreation(binClipId, id, PlaylistState::Original, local_undo, local_redo);
res = res && requestClipMove(id, trackId, position, refreshView, logUndo, local_undo, local_redo);
......
......@@ -627,6 +627,11 @@ protected:
// The index of the temporary overlay track in tractor, or -1 if not connected
int m_overlayTrackCount;
// The preferred audio target for clip insertion or -1 if not defined
int m_audioTarget;
// The preferred video target for clip insertion or -1 if not defined
int m_videoTarget;
// what follows are some virtual function that corresponds to the QML. They are implemented in TimelineItemModel
protected:
......
......@@ -54,8 +54,6 @@ TimelineController::TimelineController(KActionCollection *actionCollection, QObj
, m_usePreview(false)
, m_position(0)
, m_seekPosition(-1)
, m_audioTarget(-1)
, m_videoTarget(-1)
, m_activeTrack(0)
, m_scale(3.0)
, m_timelinePreview(nullptr)
......@@ -658,13 +656,13 @@ void TimelineController::setPosition(int position)
void TimelineController::setAudioTarget(int track)
{
m_audioTarget = track;
m_model->m_audioTarget = track;
emit audioTargetChanged();
}
void TimelineController::setVideoTarget(int track)
{
m_videoTarget = track;
m_model->m_videoTarget = track;
emit videoTargetChanged();
}
......@@ -1277,11 +1275,11 @@ void TimelineController::switchCompositing(int mode)
void TimelineController::extractZone()
{
QVector<int> tracks;
if (m_audioTarget >= 0) {
tracks << m_audioTarget;
if (audioTarget() >= 0) {
tracks << audioTarget();
}
if (m_videoTarget >= 0) {
tracks << m_videoTarget;
if (videoTarget() >= 0) {
tracks << videoTarget();
}
if (tracks.isEmpty()) {
tracks << m_activeTrack;
......@@ -1301,11 +1299,11 @@ void TimelineController::extract(int clipId)
void TimelineController::liftZone()
{
QVector<int> tracks;
if (m_audioTarget >= 0) {
tracks << m_audioTarget;
if (audioTarget() >= 0) {
tracks << audioTarget();
}
if (m_videoTarget >= 0) {
tracks << m_videoTarget;
if (videoTarget() >= 0) {
tracks << videoTarget();
}
if (tracks.isEmpty()) {
tracks << m_activeTrack;
......@@ -1318,9 +1316,9 @@ bool TimelineController::insertZone(const QString &binId, QPoint zone, bool over
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(binId);
int targetTrack = -1;
if (clip->clipType() == ClipType::Audio) {
targetTrack = m_audioTarget;
targetTrack = audioTarget();
} else {
targetTrack = m_videoTarget;
targetTrack = videoTarget();
}
if (targetTrack == -1) {
targetTrack = m_activeTrack;
......@@ -1353,7 +1351,7 @@ void TimelineController::setClipStatus(int clipId, int status)
void TimelineController::splitAudio(int clipId)
{
TimelineFunctions::requestSplitAudio(m_model, clipId, m_audioTarget);
TimelineFunctions::requestSplitAudio(m_model, clipId, audioTarget());
}
void TimelineController::switchTrackLock(bool applyToAll)
......@@ -1393,8 +1391,18 @@ void TimelineController::switchTargetTrack()
{
bool isAudio = m_model->getTrackById_const(m_activeTrack)->getProperty("kdenlive:audio_track").toInt() == 1;
if (isAudio) {
setAudioTarget(m_audioTarget == m_activeTrack ? -1 : m_activeTrack);
setAudioTarget(audioTarget() == m_activeTrack ? -1 : m_activeTrack);
} else {
setVideoTarget(m_videoTarget == m_activeTrack ? -1 : m_activeTrack);
setVideoTarget(videoTarget() == m_activeTrack ? -1 : m_activeTrack);
}
}
int TimelineController::audioTarget() const
{
return m_model->m_audioTarget;
}
int TimelineController::videoTarget() const
{
return m_model->m_videoTarget;
}
......@@ -90,8 +90,8 @@ public:
/* @brief Returns the seek request position (-1 = no seek pending)
*/
Q_INVOKABLE int seekPosition() const { return m_seekPosition; }
Q_INVOKABLE int audioTarget() const { return m_audioTarget; }
Q_INVOKABLE int videoTarget() const { return m_videoTarget; }
Q_INVOKABLE int audioTarget() const;
Q_INVOKABLE int videoTarget() const;
Q_INVOKABLE int activeTrack() const { return m_activeTrack; }
/* @brief Request a seek operation
@param position is the desired new timeline position
......
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