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

First version of split audio

parent 5791d472
......@@ -322,11 +322,11 @@ bool TimelineFunctions::changeClipState(std::shared_ptr<TimelineItemModel> timel
int end = start + timeline->getItemPlaytime(clipId);
if (trackId != -1) {
timeline->getTrackById(trackId)->replugClip(clipId);
QModelIndex ix = timeline->makeClipIndexFromID(clipId);
timeline->dataChanged(ix, ix, {TimelineModel::StatusRole});
timeline->invalidateClip(clipId);
timeline->checkRefresh(start, end);
}
QModelIndex ix = timeline->makeClipIndexFromID(clipId);
timeline->dataChanged(ix, ix, {TimelineModel::StatusRole});
timeline->invalidateClip(clipId);
timeline->checkRefresh(start, end);
return res;
};
undo = [timeline, clipId, oldState]() {
......@@ -354,3 +354,32 @@ bool TimelineFunctions::changeClipState(std::shared_ptr<TimelineItemModel> timel
return result;
}
bool TimelineFunctions::requestSplitAudio(std::shared_ptr<TimelineItemModel> timeline, int clipId)
{
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
const std::unordered_set<int> clips = timeline->getGroupElements(clipId);
int count = 0;
for (int cid : clips) {
int position = timeline->getClipPosition(cid);
int duration = timeline->getClipPlaytime(cid);
int track = timeline->getClipTrackId(cid);
int newTrack = timeline->getNextTrackId(track);
int newId;
bool res = copyClip(timeline, cid, newId, undo, redo);
TimelineFunctions::changeClipState(timeline, clipId, PlaylistState::VideoOnly);
res = res && timeline->requestClipMove(newId, newTrack, position, true, false, undo, redo);
TimelineFunctions::changeClipState(timeline, newId, PlaylistState::AudioOnly);
std::unordered_set<int> clips;
clips.insert(clipId);
clips.insert(newId);
timeline->requestClipsGroup(clips, true);
if (!res) {
bool undone = undo();
Q_ASSERT(undone);
return false;
}
}
pCore->pushUndo(undo, redo, i18n("Split Audio"));
return true;
}
......@@ -61,6 +61,7 @@ struct TimelineFunctions {
static void showClipKeyframes(std::shared_ptr<TimelineItemModel> timeline, int clipId, bool value);
static void showCompositionKeyframes(std::shared_ptr<TimelineItemModel> timeline, int compoId, bool value);
static bool changeClipState(std::shared_ptr<TimelineItemModel> timeline, int clipId, PlaylistState::ClipState status);
static bool requestSplitAudio(std::shared_ptr<TimelineItemModel> timeline, int clipId);
};
#endif
......@@ -255,8 +255,8 @@ int TimelineModel::getNextTrackId(int trackId) const
READ_LOCK();
Q_ASSERT(isTrack(trackId));
auto it = m_iteratorTable.at(trackId);
++it;
return (it != m_allTracks.end()) ? (*it)->getId() : -1;
--it;
return (it != m_allTracks.begin()) ? (*it)->getId() : -1;
}
int TimelineModel::getPreviousVideoTrackPos(int trackId) const
......
......@@ -715,6 +715,11 @@ Rectangle {
MenuSeparator {
visible: true
}
MenuItem {
text: i18n('Split Audio')
onTriggered: timeline.splitAudio(clipRoot.clipId)
visible: clipStatus == 0
}
MenuItem {
text: i18n('Remove')
onTriggered: timeline.triggerAction('delete_timeline_clip')
......
......@@ -1158,3 +1158,9 @@ void TimelineController::setClipStatus(int clipId, int status)
{
TimelineFunctions::changeClipState(m_model, clipId, (PlaylistState::ClipState) status);
}
void TimelineController::splitAudio(int clipId)
{
TimelineFunctions::requestSplitAudio(m_model, clipId);
}
......@@ -228,6 +228,8 @@ public:
Q_INVOKABLE void extract(int clipId);
Q_INVOKABLE void splitAudio(int clipId);
const QString getTrackNameFromIndex(int trackIndex);
/* @brief Seeks to selected clip start / end
*/
......
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