1 /***************************************************************************
2 stopmotion.cpp - description
5 copyright : (C) 2010 by Jean-Baptiste Mardelle
6 email : jb@kdenlive.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "stopmotion.h"
20 #include "blackmagic/devices.h"
23 #include "v4l/v4lcapture.h"
25 #include "slideshowclip.h"
26 #include "profilesdialog.h"
27 #include "mltdevicecapture.h"
28 #include "recmonitor.h"
29 #include "monitormanager.h"
30 #include "ui_smconfig_ui.h"
31 #include "kdenlivesettings.h"
34 #include <KGlobalSettings>
35 #include <KFileDialog>
36 #include <KStandardDirs>
37 #include <KMessageBox>
38 #include <kdeversion.h>
39 #include <KNotification>
41 #include <QtConcurrentRun>
42 #include <QInputDialog>
44 #include <QVBoxLayout>
48 #include <QWheelEvent>
51 MyLabel::MyLabel(QWidget* parent) :
56 void MyLabel::setImage(QImage img)
62 void MyLabel::wheelEvent(QWheelEvent* event)
64 if (event->delta() > 0) emit seek(true);
65 else emit seek(false);
69 void MyLabel::mousePressEvent(QMouseEvent*)
75 void MyLabel::paintEvent(QPaintEvent* event)
79 QRect r(0, 0, width(), height());
81 p.fillRect(r, QColor(KdenliveSettings::window_background()));
82 double aspect_ratio = (double) m_img.width() / m_img.height();
83 int pictureHeight = height();
84 int pictureWidth = width();
85 int calculatedWidth = aspect_ratio * height();
86 if (calculatedWidth > width()) pictureHeight = width() / aspect_ratio;
88 int calculatedHeight = width() / aspect_ratio;
89 if (calculatedHeight > height()) pictureWidth = height() * aspect_ratio;
91 p.drawImage(QRect((width() - pictureWidth) / 2, (height() - pictureHeight) / 2, pictureWidth, pictureHeight), m_img, QRect(0, 0, m_img.width(), m_img.height()));
96 StopmotionMonitor::StopmotionMonitor(MonitorManager *manager, QWidget *parent) :
97 AbstractMonitor(Kdenlive::stopmotionMonitor, manager, parent),
102 StopmotionMonitor::~StopmotionMonitor()
106 void StopmotionMonitor::slotSwitchFullScreen()
110 void StopmotionMonitor::setRender(MltDeviceCapture *render)
112 m_captureDevice = render;
115 AbstractRender *StopmotionMonitor::abstractRender()
117 return m_captureDevice;
120 Kdenlive::MONITORID StopmotionMonitor::id() const
122 return Kdenlive::stopmotionMonitor;
126 void StopmotionMonitor::stop()
128 if (m_captureDevice) m_captureDevice->stop();
132 void StopmotionMonitor::start()
136 void StopmotionMonitor::pause()
140 void StopmotionMonitor::unpause()
144 void StopmotionMonitor::slotPlay()
148 void StopmotionMonitor::slotMouseSeek(int /*eventDelta*/, bool /*fast*/)
152 StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder, QList< QAction* > actions, QWidget* parent) :
154 , Ui::Stopmotion_UI()
155 , m_projectFolder(projectFolder)
156 , m_captureDevice(NULL)
158 , m_animatedIndex(-1)
161 , m_monitor(new StopmotionMonitor(manager, this))
163 //setAttribute(Qt::WA_DeleteOnClose);
164 //HACK: the monitor widget is hidden, it is just used to control the capturedevice from monitormanager
165 m_monitor->setHidden(true);
166 connect(m_monitor, SIGNAL(stopCapture()), this, SLOT(slotStopCapture()));
167 m_manager->appendMonitor(m_monitor);
168 QAction* analyse = new QAction(i18n("Send frames to color scopes"), this);
169 analyse->setCheckable(true);
170 analyse->setChecked(KdenliveSettings::analyse_stopmotion());
171 connect(analyse, SIGNAL(triggered(bool)), this, SLOT(slotSwitchAnalyse(bool)));
173 QAction* mirror = new QAction(i18n("Mirror display"), this);
174 mirror->setCheckable(true);
175 //mirror->setChecked(KdenliveSettings::analyse_stopmotion());
176 connect(mirror, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMirror(bool)));
180 setWindowTitle(i18n("Stop Motion Capture"));
181 setFont(KGlobalSettings::toolBarFont());
183 live_button->setIcon(KIcon("camera-photo"));
185 m_captureAction = actions.at(0);
186 connect(m_captureAction, SIGNAL(triggered()), this, SLOT(slotCaptureFrame()));
187 m_captureAction->setCheckable(true);
188 m_captureAction->setChecked(false);
189 capture_button->setDefaultAction(m_captureAction);
191 connect(actions.at(1), SIGNAL(triggered()), this, SLOT(slotSwitchLive()));
193 QAction *intervalCapture = new QAction(i18n("Interval capture"), this);
194 intervalCapture->setIcon(KIcon("chronometer"));
195 intervalCapture->setCheckable(true);
196 intervalCapture->setChecked(false);
197 capture_interval->setDefaultAction(intervalCapture);
199 preview_button->setIcon(KIcon("media-playback-start"));
200 capture_button->setEnabled(false);
204 QMenu* confMenu = new QMenu;
205 m_showOverlay = actions.at(2);
206 connect(m_showOverlay, SIGNAL(triggered(bool)), this, SLOT(slotShowOverlay(bool)));
207 overlay_button->setDefaultAction(m_showOverlay);
208 //confMenu->addAction(m_showOverlay);
210 m_effectIndex = KdenliveSettings::stopmotioneffect();
211 QMenu* effectsMenu = new QMenu(i18n("Overlay effect"));
212 QActionGroup* effectGroup = new QActionGroup(this);
213 QAction* noEffect = new QAction(i18n("No Effect"), effectGroup);
214 noEffect->setData(0);
215 QAction* contrastEffect = new QAction(i18n("Contrast"), effectGroup);
216 contrastEffect->setData(1);
217 QAction* edgeEffect = new QAction(i18n("Edge detect"), effectGroup);
218 edgeEffect->setData(2);
219 QAction* brightEffect = new QAction(i18n("Brighten"), effectGroup);
220 brightEffect->setData(3);
221 QAction* invertEffect = new QAction(i18n("Invert"), effectGroup);
222 invertEffect->setData(4);
223 QAction* thresEffect = new QAction(i18n("Threshold"), effectGroup);
224 thresEffect->setData(5);
226 effectsMenu->addAction(noEffect);
227 effectsMenu->addAction(contrastEffect);
228 effectsMenu->addAction(edgeEffect);
229 effectsMenu->addAction(brightEffect);
230 effectsMenu->addAction(invertEffect);
231 effectsMenu->addAction(thresEffect);
232 QList <QAction*> list = effectsMenu->actions();
233 for (int i = 0; i < list.count(); i++) {
234 list.at(i)->setCheckable(true);
235 if (list.at(i)->data().toInt() == m_effectIndex) {
236 list.at(i)->setChecked(true);
239 connect(effectsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotUpdateOverlayEffect(QAction*)));
240 confMenu->addMenu(effectsMenu);
242 QAction* showThumbs = new QAction(KIcon("image-x-generic"), i18n("Show sequence thumbnails"), this);
243 showThumbs->setCheckable(true);
244 showThumbs->setChecked(KdenliveSettings::showstopmotionthumbs());
245 connect(showThumbs, SIGNAL(triggered(bool)), this, SLOT(slotShowThumbs(bool)));
247 QAction* removeCurrent = new QAction(KIcon("edit-delete"), i18n("Delete current frame"), this);
248 removeCurrent->setShortcut(Qt::Key_Delete);
249 connect(removeCurrent, SIGNAL(triggered()), this, SLOT(slotRemoveFrame()));
251 QAction* conf = new QAction(KIcon("configure"), i18n("Configure"), this);
252 connect(conf, SIGNAL(triggered()), this, SLOT(slotConfigure()));
254 confMenu->addAction(showThumbs);
255 confMenu->addAction(removeCurrent);
256 confMenu->addAction(analyse);
257 confMenu->addAction(mirror);
258 confMenu->addAction(conf);
259 config_button->setIcon(KIcon("configure"));
260 config_button->setMenu(confMenu);
262 connect(sequence_name, SIGNAL(textChanged(const QString&)), this, SLOT(sequenceNameChanged(const QString&)));
263 connect(sequence_name, SIGNAL(currentIndexChanged(int)), live_button, SLOT(setFocus()));
265 // Video widget holder
266 QVBoxLayout *layout = new QVBoxLayout;
267 layout->setContentsMargins(0, 0, 0, 0);
268 layout->setSpacing(0);
269 m_videoBox = new VideoContainer(m_monitor);
270 m_videoBox->setLineWidth(4);
271 layout->addWidget(m_videoBox);
273 #ifdef USE_BLACKMAGIC
274 if (BMInterface::getBlackMagicDeviceList(capture_device)) {
275 // Found a BlackMagic device
278 if (QFile::exists(KdenliveSettings::video4vdevice())) {
280 // Video 4 Linux device detection
281 for (int i = 0; i < 10; i++) {
282 QString path = "/dev/video" + QString::number(i);
283 if (QFile::exists(path)) {
284 QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path);
285 if (!deviceInfo.isEmpty()) {
286 capture_device->addItem(deviceInfo.at(0), "v4l");
287 capture_device->setItemData(capture_device->count() - 1, path, Qt::UserRole + 1);
288 capture_device->setItemData(capture_device->count() - 1, deviceInfo.at(1), Qt::UserRole + 2);
289 if (path == KdenliveSettings::video4vdevice()) capture_device->setCurrentIndex(capture_device->count() - 1);
296 connect(capture_device, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDeviceHandler()));
298 connect(m_bmCapture, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
299 connect(m_bmCapture, SIGNAL(gotFrame(QImage)), this, SIGNAL(gotFrame(QImage)));
300 } else live_button->setEnabled(false);*/
302 m_frame_preview = new MyLabel(this);
303 connect(m_frame_preview, SIGNAL(seek(bool)), this, SLOT(slotSeekFrame(bool)));
304 connect(m_frame_preview, SIGNAL(switchToLive()), this, SLOT(slotSwitchLive()));
305 layout->addWidget(m_frame_preview);
306 m_frame_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
307 video_preview->setLayout(layout);
309 //kDebug()<<video_preview->winId();
312 // Create MLT producer data
313 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
314 // Capture using a video4linux device
315 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
319 profilePath = KdenliveSettings::current_profile();
322 m_captureDevice = new MltDeviceCapture(profilePath, m_videoBox, this);
323 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
324 m_monitor->setRender(m_captureDevice);
325 connect(m_captureDevice, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
327 live_button->setChecked(false);
328 button_addsequence->setEnabled(false);
329 connect(live_button, SIGNAL(toggled(bool)), this, SLOT(slotLive(bool)));
330 connect(button_addsequence, SIGNAL(clicked(bool)), this, SLOT(slotAddSequence()));
331 connect(preview_button, SIGNAL(clicked(bool)), this, SLOT(slotPlayPreview(bool)));
332 connect(frame_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotShowSelectedFrame()));
333 connect(frame_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slotShowSelectedFrame()));
334 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
336 frame_list->addAction(removeCurrent);
337 frame_list->setContextMenuPolicy(Qt::ActionsContextMenu);
338 frame_list->setHidden(!KdenliveSettings::showstopmotionthumbs());
339 parseExistingSequences();
340 QTimer::singleShot(500, this, SLOT(slotLive()));
341 connect(&m_intervalTimer, SIGNAL(timeout()), this, SLOT(slotCaptureFrame()));
342 m_intervalTimer.setSingleShot(true);
343 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
346 StopmotionWidget::~StopmotionWidget()
348 m_manager->removeMonitor(m_monitor);
349 if (m_captureDevice) {
350 m_captureDevice->stop();
351 delete m_captureDevice;
352 m_captureDevice = NULL;
358 void StopmotionWidget::slotUpdateOverlayEffect(QAction* act)
360 if (act) m_effectIndex = act->data().toInt();
361 KdenliveSettings::setStopmotioneffect(m_effectIndex);
365 void StopmotionWidget::closeEvent(QCloseEvent* e)
368 QDialog::closeEvent(e);
371 void StopmotionWidget::slotConfigure()
376 d.setWindowTitle(i18n("Configure Stop Motion"));
377 ui.sm_interval->setValue(KdenliveSettings::captureinterval());
378 ui.sm_interval->setSuffix(ki18np(" second", " seconds"));
379 ui.sm_notifytime->setSuffix(ki18np(" second", " seconds"));
380 ui.sm_notifytime->setValue(KdenliveSettings::sm_notifytime());
381 connect(ui.sm_prenotify, SIGNAL(toggled(bool)), ui.sm_notifytime, SLOT(setEnabled(bool)));
382 ui.sm_prenotify->setChecked(KdenliveSettings::sm_prenotify());
383 ui.sm_loop->setChecked(KdenliveSettings::sm_loop());
384 ui.sm_framesplayback->setValue(KdenliveSettings::sm_framesplayback());
386 if (d.exec() == QDialog::Accepted) {
387 KdenliveSettings::setSm_loop(ui.sm_loop->isChecked());
388 KdenliveSettings::setCaptureinterval(ui.sm_interval->value());
389 KdenliveSettings::setSm_framesplayback(ui.sm_framesplayback->value());
390 KdenliveSettings::setSm_notifytime(ui.sm_notifytime->value());
391 KdenliveSettings::setSm_prenotify(ui.sm_prenotify->isChecked());
392 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
396 void StopmotionWidget::slotShowThumbs(bool show)
398 KdenliveSettings::setShowstopmotionthumbs(show);
401 sequenceNameChanged(sequence_name->currentText());
406 frame_list->setHidden(!show);
410 void StopmotionWidget::slotUpdateDeviceHandler()
413 delete m_captureDevice;
414 m_captureDevice = NULL;
415 /*QString data = capture_device->itemData(capture_device->currentIndex()).toString();
420 m_layout->removeWidget(m_frame_preview);
423 m_bmCapture = new V4lCaptureHandler(m_layout);
424 m_bmCapture->setDevice(capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString(), capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 2).toString());
427 m_bmCapture = new BmdCaptureHandler(m_layout);
428 if (m_bmCapture) connect(m_bmCapture, SIGNAL(gotMessage(const QString&)), this, SLOT(slotGotHDMIMessage(const QString&)));
430 live_button->setEnabled(m_bmCapture != NULL);
431 m_layout->addWidget(m_frame_preview);*/
434 void StopmotionWidget::slotGotHDMIMessage(const QString& message)
436 log_box->insertItem(0, message);
439 void StopmotionWidget::parseExistingSequences()
441 sequence_name->clear();
442 sequence_name->addItem(QString());
443 QDir dir(m_projectFolder.path());
445 filters << "*_0000.png";
446 //dir.setNameFilters(filters);
447 QStringList sequences = dir.entryList(filters, QDir::Files, QDir::Name);
448 //kDebug()<<"PF: "<<<<", sm: "<<sequences;
449 foreach(QString sequencename, sequences) {
450 sequence_name->addItem(sequencename.section("_", 0, -2));
454 void StopmotionWidget::slotSwitchLive()
456 setUpdatesEnabled(false);
457 slotLive(!live_button->isChecked());
458 /*if (m_frame_preview->isHidden()) {
459 //if (m_bmCapture) m_bmCapture->hidePreview(true);
460 m_videoBox->setHidden(true);
461 m_frame_preview->setHidden(false);
463 m_frame_preview->setHidden(true);
464 //if (m_bmCapture) m_bmCapture->hidePreview(false);
465 m_videoBox->setHidden(false);
466 capture_button->setEnabled(true);
468 setUpdatesEnabled(true);
471 void StopmotionWidget::slotStopCapture()
476 void StopmotionWidget::slotLive(bool isOn)
478 live_button->blockSignals(true);
479 capture_button->setEnabled(false);
481 m_frame_preview->setHidden(true);
482 m_videoBox->setHidden(false);
485 MltVideoProfile profile;
489 // Create MLT producer data
490 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
491 // Capture using a video4linux device
492 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
493 profile = ProfilesDialog::getVideoProfile(profilePath);
494 service = "avformat-novalidate";
495 QString devicePath = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
496 resource = QString("video4linux2:%1?width:%2&height:%3&frame_rate:%4").arg(devicePath).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den);
500 profilePath = KdenliveSettings::current_profile();
501 profile = ProfilesDialog::getVideoProfile(profilePath);
502 service = "decklink";
503 resource = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
506 if (m_captureDevice == NULL) {
507 m_captureDevice = new MltDeviceCapture(profilePath, m_videoBox, this);
508 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
509 m_monitor->setRender(m_captureDevice);
510 connect(m_captureDevice, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
513 m_manager->activateMonitor(Kdenlive::stopmotionMonitor);
514 QString producer = createProducer(profile, service, resource);
515 if (m_captureDevice->slotStartPreview(producer, true)) {
516 if (m_showOverlay->isChecked()) {
520 capture_button->setEnabled(true);
521 live_button->setChecked(true);
522 log_box->insertItem(-1, i18n("Playing %1x%2 (%3 fps)", profile.width, profile.height, locale.toString((double)profile.frame_rate_num/profile.frame_rate_den).rightJustified(2, '0')));
523 log_box->setCurrentIndex(0);
526 kDebug()<<"// problem starting stopmo";
527 log_box->insertItem(-1, i18n("Failed to start device"));
528 log_box->setCurrentIndex(0);
532 m_frame_preview->setHidden(false);
533 live_button->setChecked(false);
534 if (m_captureDevice) {
535 m_captureDevice->stop();
536 m_videoBox->setHidden(true);
537 log_box->insertItem(-1, i18n("Stopped"));
538 log_box->setCurrentIndex(0);
539 //delete m_captureDevice;
540 //m_captureDevice = NULL;
545 if (isOn && m_bmCapture) {
546 //m_frame_preview->setImage(QImage());
547 m_frame_preview->setHidden(true);
548 m_bmCapture->startPreview(KdenliveSettings::hdmi_capturedevice(), KdenliveSettings::hdmi_capturemode(), false);
549 capture_button->setEnabled(true);
550 live_button->setChecked(true);
552 if (m_bmCapture) m_bmCapture->stopPreview();
553 m_frame_preview->setHidden(false);
554 capture_button->setEnabled(false);
555 live_button->setChecked(false);
557 live_button->blockSignals(false);
560 void StopmotionWidget::slotShowOverlay(bool isOn)
563 // Overlay last frame of the sequence
569 m_captureDevice->setOverlay(QString());
573 void StopmotionWidget::reloadOverlay()
575 QString path = getPathForFrame(m_sequenceFrame - 1);
576 if (!QFile::exists(path)) {
577 log_box->insertItem(-1, i18n("No previous frame found"));
578 log_box->setCurrentIndex(0);
581 m_captureDevice->setOverlay(path);
584 void StopmotionWidget::slotUpdateOverlay()
586 if (m_captureDevice == NULL) return;
591 switch (m_effectIndex) {
593 tag = "frei0r.contrast0r";
594 params << "Contrast=1.2";
598 params << "x_scatter=4" << "y_scatter=4" << "scale=1" << "mix=0";
601 tag = "frei0r.brightness";
602 params << "Brightness=0.7";
609 params << "midpoint=125";
615 m_captureDevice->setOverlayEffect(tag, params);
618 void StopmotionWidget::sequenceNameChanged(const QString& name)
620 // Get rid of frames from previous sequence
621 disconnect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
623 m_future.waitForFinished();
625 if (name.isEmpty()) {
626 button_addsequence->setEnabled(false);
628 // Check if we are editing an existing sequence
629 QString pattern = SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_filesList);
630 m_sequenceFrame = m_filesList.isEmpty() ? 0 : SlideshowClip::getFrameNumberFromPath(m_filesList.last()) + 1;
631 if (!m_filesList.isEmpty()) {
632 m_sequenceName = sequence_name->currentText();
633 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
634 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
635 button_addsequence->setEnabled(true);
638 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
639 button_addsequence->setEnabled(false);
641 capture_button->setEnabled(live_button->isChecked());
645 void StopmotionWidget::slotCaptureFrame()
647 if (m_captureDevice == NULL) return;
648 if (sequence_name->currentText().isEmpty()) {
649 QString seqName = QInputDialog::getText(this, i18n("Create New Sequence"), i18n("Enter sequence name"));
650 if (seqName.isEmpty()) {
651 m_captureAction->setChecked(false);
654 sequence_name->blockSignals(true);
655 sequence_name->setItemText(sequence_name->currentIndex(), seqName);
656 sequence_name->blockSignals(false);
658 if (m_sequenceName != sequence_name->currentText()) {
659 m_sequenceName = sequence_name->currentText();
662 //capture_button->setEnabled(false);
663 if (m_intervalTimer.isActive()) {
664 // stop interval capture
665 m_intervalTimer.stop();
668 QString currentPath = getPathForFrame(m_sequenceFrame);
669 m_captureDevice->captureFrame(currentPath);
670 KNotification::event("FrameCaptured", i18n("Frame Captured"), QPixmap(), this);
672 button_addsequence->setEnabled(true);
673 if (capture_interval->isChecked()) {
674 if (KdenliveSettings::sm_prenotify()) QTimer::singleShot((KdenliveSettings::captureinterval() - KdenliveSettings::sm_notifytime()) * 1000, this, SLOT(slotPreNotify()));
675 m_intervalTimer.start();
677 else m_captureAction->setChecked(false);
680 void StopmotionWidget::slotPreNotify()
682 if (m_captureAction->isChecked()) KNotification::event("ReadyToCapture", i18n("Going to Capture Frame"), QPixmap(), this);
686 void StopmotionWidget::slotNewThumb(const QString &path)
688 if (!KdenliveSettings::showstopmotionthumbs()) return;
689 m_filesList.append(path);
690 if (m_showOverlay->isChecked()) reloadOverlay();
691 if (!m_future.isRunning()) m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
695 void StopmotionWidget::slotPrepareThumbs()
697 if (m_filesList.isEmpty()) return;
698 QString path = m_filesList.takeFirst();
699 emit doCreateThumbs(QImage(path), SlideshowClip::getFrameNumberFromPath(path));
703 void StopmotionWidget::slotCreateThumbs(QImage img, int ix)
706 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
710 int width = height * img.width() / img.height();
711 frame_list->setIconSize(QSize(width, height));
712 QPixmap pix = QPixmap::fromImage(img).scaled(width, height);
713 QString nb = QString::number(ix);
715 QFontInfo finfo(font());
716 p.fillRect(0, 0, finfo.pixelSize() * nb.count() + 6, finfo.pixelSize() + 6, QColor(80, 80, 80, 150));
718 p.drawText(QPoint(3, finfo.pixelSize() + 3), nb);
721 QListWidgetItem* item = new QListWidgetItem(icon, QString(), frame_list);
722 item->setToolTip(getPathForFrame(ix, sequence_name->currentText()));
723 item->setData(Qt::UserRole, ix);
724 frame_list->blockSignals(true);
725 frame_list->setCurrentItem(item);
726 frame_list->blockSignals(false);
727 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
730 QString StopmotionWidget::getPathForFrame(int ix, QString seqName)
732 if (seqName.isEmpty()) seqName = m_sequenceName;
733 return m_projectFolder.path(KUrl::AddTrailingSlash) + seqName + "_" + QString::number(ix).rightJustified(4, '0', false) + ".png";
736 void StopmotionWidget::slotShowFrame(const QString& path)
740 capture_button->setEnabled(false);
743 //m_videoBox->setHidden(true);
745 m_frame_preview->setImage(img);
746 m_frame_preview->setHidden(false);
747 m_frame_preview->update();
751 void StopmotionWidget::slotShowSelectedFrame()
753 QListWidgetItem* item = frame_list->currentItem();
755 //int ix = item->data(Qt::UserRole).toInt();;
756 slotShowFrame(item->toolTip());
760 void StopmotionWidget::slotAddSequence()
762 emit addOrUpdateSequence(getPathForFrame(0));
765 void StopmotionWidget::slotPlayPreview(bool animate)
770 m_animationList.clear();
773 if (KdenliveSettings::showstopmotionthumbs()) {
774 if (KdenliveSettings::sm_framesplayback() == 0) frame_list->setCurrentRow(0);
775 else frame_list->setCurrentRow(frame_list->count() - KdenliveSettings::sm_framesplayback());
776 QTimer::singleShot(200, this, SLOT(slotAnimate()));
778 SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_animationList);
779 if (KdenliveSettings::sm_framesplayback() > 0) {
780 // only play the last x frames
781 while (m_animationList.count() > KdenliveSettings::sm_framesplayback() + 1) {
782 m_animationList.removeFirst();
790 void StopmotionWidget::slotAnimate()
793 if (KdenliveSettings::showstopmotionthumbs()) {
794 int newRow = frame_list->currentRow() + 1;
795 if (KdenliveSettings::sm_loop() || newRow < frame_list->count()) {
796 if (newRow >= frame_list->count()) {
797 if (KdenliveSettings::sm_framesplayback() == 0) newRow = 0;
799 // seek to correct frame
800 newRow = frame_list->count() - KdenliveSettings::sm_framesplayback();
803 frame_list->setCurrentRow(newRow);
804 QTimer::singleShot(100, this, SLOT(slotAnimate()));
808 if (m_animatedIndex >= m_animationList.count()) {
809 if (KdenliveSettings::sm_loop()) m_animatedIndex = 0;
810 else m_animatedIndex = -1;
812 if (m_animatedIndex > -1) {
813 slotShowFrame(m_animationList.at(m_animatedIndex));
815 QTimer::singleShot(100, this, SLOT(slotAnimate()));
821 preview_button->setChecked(false);
825 QListWidgetItem* StopmotionWidget::getFrameFromIndex(int ix)
827 QListWidgetItem* item = NULL;
829 if (ix >= frame_list->count()) {
830 pos = frame_list->count() - 1;
833 item = frame_list->item(pos);
835 int value = item->data(Qt::UserRole).toInt();
836 if (value == ix) return item;
837 else if (value < ix) {
839 while (pos < frame_list->count()) {
840 item = frame_list->item(pos);
841 value = item->data(Qt::UserRole).toInt();
842 if (value == ix) return item;
848 item = frame_list->item(pos);
849 value = item->data(Qt::UserRole).toInt();
850 if (value == ix) return item;
858 void StopmotionWidget::selectFrame(int ix)
860 frame_list->blockSignals(true);
861 QListWidgetItem* item = getFrameFromIndex(ix);
863 frame_list->setCurrentItem(item);
864 frame_list->blockSignals(false);
867 void StopmotionWidget::slotSeekFrame(bool forward)
869 int ix = frame_list->currentRow();
871 if (ix < frame_list->count() - 1) frame_list->setCurrentRow(ix + 1);
872 } else if (ix > 0) frame_list->setCurrentRow(ix - 1);
875 void StopmotionWidget::slotRemoveFrame()
877 if (frame_list->currentItem() == NULL) return;
878 QString path = frame_list->currentItem()->toolTip();
879 if (KMessageBox::questionYesNo(this, i18n("Delete frame %1 from disk?", path), i18n("Delete Frame")) != KMessageBox::Yes) return;
882 QListWidgetItem* item = frame_list->takeItem(frame_list->currentRow());
883 int ix = item->data(Qt::UserRole).toInt();
884 if (ix == m_sequenceFrame - 1) {
885 // We are removing the last frame, update counter
886 QListWidgetItem* item2 = frame_list->item(frame_list->count() - 1);
887 if (item2) m_sequenceFrame = item2->data(Qt::UserRole).toInt() + 1;
893 void StopmotionWidget::slotSwitchAnalyse(bool isOn)
895 KdenliveSettings::setAnalyse_stopmotion(isOn);
896 if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = isOn;
899 void StopmotionWidget::slotSwitchMirror(bool isOn)
901 //KdenliveSettings::setAnalyse_stopmotion(isOn);
902 if (m_captureDevice) m_captureDevice->mirror(isOn);
906 const QString StopmotionWidget::createProducer(MltVideoProfile profile, const QString &service, const QString &resource)
910 QString playlist = "<mlt title=\"capture\"><producer id=\"producer0\" in=\"0\" out=\"99999\"><property name=\"mlt_type\">producer</property><property name=\"length\">100000</property><property name=\"eof\">pause</property><property name=\"resource\">" + resource + "</property><property name=\"mlt_service\">" + service + "</property></producer>";
913 playlist.append("<playlist id=\"playlist0\"></playlist>");
916 playlist.append("<playlist id=\"playlist1\"><entry producer=\"producer0\" in=\"0\" out=\"99999\"/></playlist>");
918 playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"99999\">");
919 playlist.append("<track producer=\"playlist0\"/>");
920 playlist.append("<track producer=\"playlist1\"/>");
921 playlist.append("</tractor></mlt>");