summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Theato <root@ttill.de>2014-05-04 20:09:40 (GMT)
committerVincent PINON <vincent.pinon@laposte.net>2014-05-04 23:02:41 (GMT)
commit56acd92470a1cf7e30c1163f2260dc31212458cb (patch)
treeb5cb158a24d4ff97fbad2eebb835fa1c787b8635
parent6335d463702a48305d0b5b62fd4ba7c61d316e30 (diff)
Reduce code duplication when changing clip type.
-rw-r--r--src/customtrackview.cpp94
-rw-r--r--src/customtrackview.h5
-rw-r--r--src/mainwindow.cpp10
3 files changed, 29 insertions, 80 deletions
diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp
index d07092d..81b92e7 100644
--- a/src/customtrackview.cpp
+++ b/src/customtrackview.cpp
@@ -6928,58 +6928,14 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, EffectsList ef
}
}
-void CustomTrackView::setVideoOnly()
+void CustomTrackView::setClipType(bool videoOnly, bool audioOnly)
{
- resetSelectionGroup();
- QList<QGraphicsItem *> selection = scene()->selectedItems();
- if (selection.isEmpty()) {
- emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
- return;
- }
- QUndoCommand *videoCommand = new QUndoCommand();
- videoCommand->setText(i18n("Video only"));
- for (int i = 0; i < selection.count(); ++i) {
- if (selection.at(i)->type() == AVWidget) {
- ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
- if (clip->clipType() == AV || clip->clipType() == Playlist) {
- if (clip->parentItem()) {
- emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
- } else {
- new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), true, false, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
- }
- }
- }
- }
- m_commandStack->push(videoCommand);
-}
-
-void CustomTrackView::setAudioOnly()
-{
- resetSelectionGroup();
- QList<QGraphicsItem *> selection = scene()->selectedItems();
- if (selection.isEmpty()) {
- emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
- return;
- }
- QUndoCommand *videoCommand = new QUndoCommand();
- videoCommand->setText(i18n("Audio only"));
- for (int i = 0; i < selection.count(); ++i) {
- if (selection.at(i)->type() == AVWidget) {
- ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
- if (clip->clipType() == AV || clip->clipType() == Playlist) {
- if (clip->parentItem()) {
- emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
- } else {
- new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), false, true, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
- }
- }
- }
- }
- m_commandStack->push(videoCommand);
-}
+ QString text = i18n("Audio and Video");
+ if (videoOnly)
+ text = i18n("Video only");
+ else if (audioOnly)
+ text = i18n("Audio only");
-void CustomTrackView::setAudioAndVideo()
-{
resetSelectionGroup();
QList<QGraphicsItem *> selection = scene()->selectedItems();
if (selection.isEmpty()) {
@@ -6987,7 +6943,7 @@ void CustomTrackView::setAudioAndVideo()
return;
}
QUndoCommand *videoCommand = new QUndoCommand();
- videoCommand->setText(i18n("Audio and Video"));
+ videoCommand->setText(text);
for (int i = 0; i < selection.count(); ++i) {
if (selection.at(i)->type() == AVWidget) {
ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
@@ -6995,7 +6951,7 @@ void CustomTrackView::setAudioAndVideo()
if (clip->parentItem()) {
emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
} else {
- new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), false, false, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
+ new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), videoOnly, audioOnly, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
}
}
}
@@ -7016,28 +6972,18 @@ void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool video
return;
}
Mlt::Tractor *tractor = m_document->renderer()->lockService();
- if (videoOnly) {
- int start = pos.frames(m_document->fps());
- clip->setVideoOnly(true);
- clip->setAudioOnly(false);
- if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->videoProducer(track)) == false) {
- emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
- }
- } else if (audioOnly) {
- int start = pos.frames(m_document->fps());
- clip->setAudioOnly(true);
- clip->setVideoOnly(false);
- if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->audioProducer(track)) == false) {
- emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
- }
- } else {
- int start = pos.frames(m_document->fps());
- clip->setAudioOnly(false);
- clip->setVideoOnly(false);
- if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->getProducer(track)) == false) {
- emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
- }
- }
+ int start = pos.frames(m_document->fps());
+ clip->setAudioOnly(audioOnly);
+ clip->setVideoOnly(videoOnly);
+ Mlt::Producer *producer;
+ if (videoOnly)
+ producer = clip->baseClip()->videoProducer(track);
+ else if (audioOnly)
+ producer = clip->baseClip()->audioProducer(track);
+ else
+ producer = clip->baseClip()->getProducer(track);
+ if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, producer) == false)
+ emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
m_document->renderer()->unlockService(tractor);
clip->update();
setDocumentModified();
diff --git a/src/customtrackview.h b/src/customtrackview.h
index 71c414e..88c303d 100644
--- a/src/customtrackview.h
+++ b/src/customtrackview.h
@@ -161,9 +161,8 @@ public:
* @param track Track of the clip
* @param split Split or unsplit */
void doSplitAudio(const GenTime &pos, int track, EffectsList effects, bool split);
- void setVideoOnly();
- void setAudioOnly();
- void setAudioAndVideo();
+ /** @brief Sets the clip type (av, video only, audio only) of the current selection. */
+ void setClipType(bool videoOnly, bool audioOnly);
void doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly);
int hasGuide(int pos, int offset);
void reloadTransitionLumas();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index c33f79e..7be7c40 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -4135,9 +4135,13 @@ void MainWindow::slotAlignAudio()
void MainWindow::slotUpdateClipType(QAction *action)
{
if (m_activeTimeline) {
- if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
- else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
- else m_activeTimeline->projectView()->setAudioAndVideo();
+ bool videoOnly = false;
+ bool audioOnly = false;
+ if (action->data().toString() == "clip_audio_only")
+ audioOnly = true;
+ else if (action->data().toString() == "clip_video_only")
+ videoOnly = true;
+ m_activeTimeline->projectView()->setClipType(videoOnly, audioOnly);
}
}