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::slotPlay()
140 void StopmotionMonitor::slotMouseSeek(int /*eventDelta*/, bool /*fast*/)
144 StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder, QList< QAction* > actions, QWidget* parent) :
146 , Ui::Stopmotion_UI()
147 , m_projectFolder(projectFolder)
148 , m_captureDevice(NULL)
150 , m_animatedIndex(-1)
153 , m_monitor(new StopmotionMonitor(manager, this))
155 //setAttribute(Qt::WA_DeleteOnClose);
156 //HACK: the monitor widget is hidden, it is just used to control the capturedevice from monitormanager
157 m_monitor->setHidden(true);
158 connect(m_monitor, SIGNAL(stopCapture()), this, SLOT(slotStopCapture()));
159 m_manager->appendMonitor(m_monitor);
160 QAction* analyse = new QAction(i18n("Send frames to color scopes"), this);
161 analyse->setCheckable(true);
162 analyse->setChecked(KdenliveSettings::analyse_stopmotion());
163 connect(analyse, SIGNAL(triggered(bool)), this, SLOT(slotSwitchAnalyse(bool)));
165 QAction* mirror = new QAction(i18n("Mirror display"), this);
166 mirror->setCheckable(true);
167 //mirror->setChecked(KdenliveSettings::analyse_stopmotion());
168 connect(mirror, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMirror(bool)));
172 setWindowTitle(i18n("Stop Motion Capture"));
173 setFont(KGlobalSettings::toolBarFont());
175 live_button->setIcon(KIcon("camera-photo"));
177 m_captureAction = actions.at(0);
178 connect(m_captureAction, SIGNAL(triggered()), this, SLOT(slotCaptureFrame()));
179 m_captureAction->setCheckable(true);
180 m_captureAction->setChecked(false);
181 capture_button->setDefaultAction(m_captureAction);
183 connect(actions.at(1), SIGNAL(triggered()), this, SLOT(slotSwitchLive()));
185 QAction *intervalCapture = new QAction(i18n("Interval capture"), this);
186 intervalCapture->setIcon(KIcon("chronometer"));
187 intervalCapture->setCheckable(true);
188 intervalCapture->setChecked(false);
189 capture_interval->setDefaultAction(intervalCapture);
191 preview_button->setIcon(KIcon("media-playback-start"));
192 capture_button->setEnabled(false);
196 QMenu* confMenu = new QMenu;
197 m_showOverlay = actions.at(2);
198 connect(m_showOverlay, SIGNAL(triggered(bool)), this, SLOT(slotShowOverlay(bool)));
199 overlay_button->setDefaultAction(m_showOverlay);
200 //confMenu->addAction(m_showOverlay);
202 m_effectIndex = KdenliveSettings::stopmotioneffect();
203 QMenu* effectsMenu = new QMenu(i18n("Overlay effect"));
204 QActionGroup* effectGroup = new QActionGroup(this);
205 QAction* noEffect = new QAction(i18n("No Effect"), effectGroup);
206 noEffect->setData(0);
207 QAction* contrastEffect = new QAction(i18n("Contrast"), effectGroup);
208 contrastEffect->setData(1);
209 QAction* edgeEffect = new QAction(i18n("Edge detect"), effectGroup);
210 edgeEffect->setData(2);
211 QAction* brightEffect = new QAction(i18n("Brighten"), effectGroup);
212 brightEffect->setData(3);
213 QAction* invertEffect = new QAction(i18n("Invert"), effectGroup);
214 invertEffect->setData(4);
215 QAction* thresEffect = new QAction(i18n("Threshold"), effectGroup);
216 thresEffect->setData(5);
218 effectsMenu->addAction(noEffect);
219 effectsMenu->addAction(contrastEffect);
220 effectsMenu->addAction(edgeEffect);
221 effectsMenu->addAction(brightEffect);
222 effectsMenu->addAction(invertEffect);
223 effectsMenu->addAction(thresEffect);
224 QList <QAction*> list = effectsMenu->actions();
225 for (int i = 0; i < list.count(); i++) {
226 list.at(i)->setCheckable(true);
227 if (list.at(i)->data().toInt() == m_effectIndex) {
228 list.at(i)->setChecked(true);
231 connect(effectsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotUpdateOverlayEffect(QAction*)));
232 confMenu->addMenu(effectsMenu);
234 QAction* showThumbs = new QAction(KIcon("image-x-generic"), i18n("Show sequence thumbnails"), this);
235 showThumbs->setCheckable(true);
236 showThumbs->setChecked(KdenliveSettings::showstopmotionthumbs());
237 connect(showThumbs, SIGNAL(triggered(bool)), this, SLOT(slotShowThumbs(bool)));
239 QAction* removeCurrent = new QAction(KIcon("edit-delete"), i18n("Delete current frame"), this);
240 removeCurrent->setShortcut(Qt::Key_Delete);
241 connect(removeCurrent, SIGNAL(triggered()), this, SLOT(slotRemoveFrame()));
243 QAction* conf = new QAction(KIcon("configure"), i18n("Configure"), this);
244 connect(conf, SIGNAL(triggered()), this, SLOT(slotConfigure()));
246 confMenu->addAction(showThumbs);
247 confMenu->addAction(removeCurrent);
248 confMenu->addAction(analyse);
249 confMenu->addAction(mirror);
250 confMenu->addAction(conf);
251 config_button->setIcon(KIcon("configure"));
252 config_button->setMenu(confMenu);
254 connect(sequence_name, SIGNAL(textChanged(const QString&)), this, SLOT(sequenceNameChanged(const QString&)));
255 connect(sequence_name, SIGNAL(currentIndexChanged(int)), live_button, SLOT(setFocus()));
257 // Video widget holder
258 QVBoxLayout *layout = new QVBoxLayout;
259 layout->setContentsMargins(0, 0, 0, 0);
260 layout->setSpacing(0);
261 m_monitor->videoBox->setLineWidth(4);
262 layout->addWidget(m_monitor->videoBox);
264 #ifdef USE_BLACKMAGIC
265 if (BMInterface::getBlackMagicDeviceList(capture_device)) {
266 // Found a BlackMagic device
269 if (QFile::exists(KdenliveSettings::video4vdevice())) {
271 // Video 4 Linux device detection
272 for (int i = 0; i < 10; i++) {
273 QString path = "/dev/video" + QString::number(i);
274 if (QFile::exists(path)) {
275 QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path);
276 if (!deviceInfo.isEmpty()) {
277 capture_device->addItem(deviceInfo.at(0), "v4l");
278 capture_device->setItemData(capture_device->count() - 1, path, Qt::UserRole + 1);
279 capture_device->setItemData(capture_device->count() - 1, deviceInfo.at(1), Qt::UserRole + 2);
280 if (path == KdenliveSettings::video4vdevice()) capture_device->setCurrentIndex(capture_device->count() - 1);
287 connect(capture_device, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDeviceHandler()));
289 connect(m_bmCapture, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
290 connect(m_bmCapture, SIGNAL(gotFrame(QImage)), this, SIGNAL(gotFrame(QImage)));
291 } else live_button->setEnabled(false);*/
293 m_frame_preview = new MyLabel(this);
294 connect(m_frame_preview, SIGNAL(seek(bool)), this, SLOT(slotSeekFrame(bool)));
295 connect(m_frame_preview, SIGNAL(switchToLive()), this, SLOT(slotSwitchLive()));
296 layout->addWidget(m_frame_preview);
297 m_frame_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
298 video_preview->setLayout(layout);
300 //kDebug()<<video_preview->winId();
303 // Create MLT producer data
304 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
305 // Capture using a video4linux device
306 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
310 profilePath = KdenliveSettings::current_profile();
313 m_captureDevice = new MltDeviceCapture(profilePath, m_monitor->videoSurface, this);
314 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
315 m_monitor->setRender(m_captureDevice);
316 connect(m_captureDevice, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
318 live_button->setChecked(false);
319 button_addsequence->setEnabled(false);
320 connect(live_button, SIGNAL(toggled(bool)), this, SLOT(slotLive(bool)));
321 connect(button_addsequence, SIGNAL(clicked(bool)), this, SLOT(slotAddSequence()));
322 connect(preview_button, SIGNAL(clicked(bool)), this, SLOT(slotPlayPreview(bool)));
323 connect(frame_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotShowSelectedFrame()));
324 connect(frame_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slotShowSelectedFrame()));
325 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
327 frame_list->addAction(removeCurrent);
328 frame_list->setContextMenuPolicy(Qt::ActionsContextMenu);
329 frame_list->setHidden(!KdenliveSettings::showstopmotionthumbs());
330 parseExistingSequences();
331 QTimer::singleShot(500, this, SLOT(slotLive()));
332 connect(&m_intervalTimer, SIGNAL(timeout()), this, SLOT(slotCaptureFrame()));
333 m_intervalTimer.setSingleShot(true);
334 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
337 StopmotionWidget::~StopmotionWidget()
339 m_manager->removeMonitor(m_monitor);
340 if (m_captureDevice) {
341 m_captureDevice->stop();
342 delete m_captureDevice;
343 m_captureDevice = NULL;
349 void StopmotionWidget::slotUpdateOverlayEffect(QAction* act)
351 if (act) m_effectIndex = act->data().toInt();
352 KdenliveSettings::setStopmotioneffect(m_effectIndex);
356 void StopmotionWidget::closeEvent(QCloseEvent* e)
359 QDialog::closeEvent(e);
362 void StopmotionWidget::slotConfigure()
367 d.setWindowTitle(i18n("Configure Stop Motion"));
368 ui.sm_interval->setValue(KdenliveSettings::captureinterval());
369 ui.sm_interval->setSuffix(ki18np(" second", " seconds"));
370 ui.sm_notifytime->setSuffix(ki18np(" second", " seconds"));
371 ui.sm_notifytime->setValue(KdenliveSettings::sm_notifytime());
372 connect(ui.sm_prenotify, SIGNAL(toggled(bool)), ui.sm_notifytime, SLOT(setEnabled(bool)));
373 ui.sm_prenotify->setChecked(KdenliveSettings::sm_prenotify());
374 ui.sm_loop->setChecked(KdenliveSettings::sm_loop());
375 ui.sm_framesplayback->setValue(KdenliveSettings::sm_framesplayback());
377 if (d.exec() == QDialog::Accepted) {
378 KdenliveSettings::setSm_loop(ui.sm_loop->isChecked());
379 KdenliveSettings::setCaptureinterval(ui.sm_interval->value());
380 KdenliveSettings::setSm_framesplayback(ui.sm_framesplayback->value());
381 KdenliveSettings::setSm_notifytime(ui.sm_notifytime->value());
382 KdenliveSettings::setSm_prenotify(ui.sm_prenotify->isChecked());
383 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
387 void StopmotionWidget::slotShowThumbs(bool show)
389 KdenliveSettings::setShowstopmotionthumbs(show);
392 sequenceNameChanged(sequence_name->currentText());
397 frame_list->setHidden(!show);
401 void StopmotionWidget::slotUpdateDeviceHandler()
404 delete m_captureDevice;
405 m_captureDevice = NULL;
406 /*QString data = capture_device->itemData(capture_device->currentIndex()).toString();
411 m_layout->removeWidget(m_frame_preview);
414 m_bmCapture = new V4lCaptureHandler(m_layout);
415 m_bmCapture->setDevice(capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString(), capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 2).toString());
418 m_bmCapture = new BmdCaptureHandler(m_layout);
419 if (m_bmCapture) connect(m_bmCapture, SIGNAL(gotMessage(const QString&)), this, SLOT(slotGotHDMIMessage(const QString&)));
421 live_button->setEnabled(m_bmCapture != NULL);
422 m_layout->addWidget(m_frame_preview);*/
425 void StopmotionWidget::slotGotHDMIMessage(const QString& message)
427 log_box->insertItem(0, message);
430 void StopmotionWidget::parseExistingSequences()
432 sequence_name->clear();
433 sequence_name->addItem(QString());
434 QDir dir(m_projectFolder.path());
436 filters << "*_0000.png";
437 //dir.setNameFilters(filters);
438 QStringList sequences = dir.entryList(filters, QDir::Files, QDir::Name);
439 //kDebug()<<"PF: "<<<<", sm: "<<sequences;
440 foreach(QString sequencename, sequences) {
441 sequence_name->addItem(sequencename.section("_", 0, -2));
445 void StopmotionWidget::slotSwitchLive()
447 setUpdatesEnabled(false);
448 slotLive(!live_button->isChecked());
449 /*if (m_frame_preview->isHidden()) {
450 //if (m_bmCapture) m_bmCapture->hidePreview(true);
451 m_videoBox->setHidden(true);
452 m_frame_preview->setHidden(false);
454 m_frame_preview->setHidden(true);
455 //if (m_bmCapture) m_bmCapture->hidePreview(false);
456 m_videoBox->setHidden(false);
457 capture_button->setEnabled(true);
459 setUpdatesEnabled(true);
462 void StopmotionWidget::slotStopCapture()
467 void StopmotionWidget::slotLive(bool isOn)
469 live_button->blockSignals(true);
470 capture_button->setEnabled(false);
472 m_frame_preview->setHidden(true);
473 m_monitor->videoBox->setHidden(false);
476 MltVideoProfile profile;
480 // Create MLT producer data
481 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
482 // Capture using a video4linux device
483 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
484 profile = ProfilesDialog::getVideoProfile(profilePath);
485 service = "avformat-novalidate";
486 QString devicePath = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
487 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);
491 profilePath = KdenliveSettings::current_profile();
492 profile = ProfilesDialog::getVideoProfile(profilePath);
493 service = "decklink";
494 resource = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
497 if (m_captureDevice == NULL) {
498 m_captureDevice = new MltDeviceCapture(profilePath, m_monitor->videoSurface, this);
499 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
500 m_monitor->setRender(m_captureDevice);
501 connect(m_captureDevice, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
504 m_manager->activateMonitor(Kdenlive::stopmotionMonitor);
505 QString producer = createProducer(profile, service, resource);
506 if (m_captureDevice->slotStartPreview(producer, true)) {
507 if (m_showOverlay->isChecked()) {
511 capture_button->setEnabled(true);
512 live_button->setChecked(true);
513 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')));
514 log_box->setCurrentIndex(0);
517 kDebug()<<"// problem starting stopmo";
518 log_box->insertItem(-1, i18n("Failed to start device"));
519 log_box->setCurrentIndex(0);
523 m_frame_preview->setHidden(false);
524 live_button->setChecked(false);
525 if (m_captureDevice) {
526 m_captureDevice->stop();
527 m_monitor->videoBox->setHidden(true);
528 log_box->insertItem(-1, i18n("Stopped"));
529 log_box->setCurrentIndex(0);
530 //delete m_captureDevice;
531 //m_captureDevice = NULL;
536 if (isOn && m_bmCapture) {
537 //m_frame_preview->setImage(QImage());
538 m_frame_preview->setHidden(true);
539 m_bmCapture->startPreview(KdenliveSettings::hdmi_capturedevice(), KdenliveSettings::hdmi_capturemode(), false);
540 capture_button->setEnabled(true);
541 live_button->setChecked(true);
543 if (m_bmCapture) m_bmCapture->stopPreview();
544 m_frame_preview->setHidden(false);
545 capture_button->setEnabled(false);
546 live_button->setChecked(false);
548 live_button->blockSignals(false);
551 void StopmotionWidget::slotShowOverlay(bool isOn)
554 // Overlay last frame of the sequence
560 m_captureDevice->setOverlay(QString());
564 void StopmotionWidget::reloadOverlay()
566 QString path = getPathForFrame(m_sequenceFrame - 1);
567 if (!QFile::exists(path)) {
568 log_box->insertItem(-1, i18n("No previous frame found"));
569 log_box->setCurrentIndex(0);
572 m_captureDevice->setOverlay(path);
575 void StopmotionWidget::slotUpdateOverlay()
577 if (m_captureDevice == NULL) return;
582 switch (m_effectIndex) {
584 tag = "frei0r.contrast0r";
585 params << "Contrast=1.2";
589 params << "x_scatter=4" << "y_scatter=4" << "scale=1" << "mix=0";
592 tag = "frei0r.brightness";
593 params << "Brightness=0.7";
600 params << "midpoint=125";
606 m_captureDevice->setOverlayEffect(tag, params);
609 void StopmotionWidget::sequenceNameChanged(const QString& name)
611 // Get rid of frames from previous sequence
612 disconnect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
614 m_future.waitForFinished();
616 if (name.isEmpty()) {
617 button_addsequence->setEnabled(false);
619 // Check if we are editing an existing sequence
620 QString pattern = SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_filesList);
621 m_sequenceFrame = m_filesList.isEmpty() ? 0 : SlideshowClip::getFrameNumberFromPath(m_filesList.last()) + 1;
622 if (!m_filesList.isEmpty()) {
623 m_sequenceName = sequence_name->currentText();
624 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
625 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
626 button_addsequence->setEnabled(true);
629 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
630 button_addsequence->setEnabled(false);
632 capture_button->setEnabled(live_button->isChecked());
636 void StopmotionWidget::slotCaptureFrame()
638 if (m_captureDevice == NULL) return;
639 if (sequence_name->currentText().isEmpty()) {
640 QString seqName = QInputDialog::getText(this, i18n("Create New Sequence"), i18n("Enter sequence name"));
641 if (seqName.isEmpty()) {
642 m_captureAction->setChecked(false);
645 sequence_name->blockSignals(true);
646 sequence_name->setItemText(sequence_name->currentIndex(), seqName);
647 sequence_name->blockSignals(false);
649 if (m_sequenceName != sequence_name->currentText()) {
650 m_sequenceName = sequence_name->currentText();
653 //capture_button->setEnabled(false);
654 if (m_intervalTimer.isActive()) {
655 // stop interval capture
656 m_intervalTimer.stop();
659 QString currentPath = getPathForFrame(m_sequenceFrame);
660 m_captureDevice->captureFrame(currentPath);
661 KNotification::event("FrameCaptured", i18n("Frame Captured"), QPixmap(), this);
663 button_addsequence->setEnabled(true);
664 if (capture_interval->isChecked()) {
665 if (KdenliveSettings::sm_prenotify()) QTimer::singleShot((KdenliveSettings::captureinterval() - KdenliveSettings::sm_notifytime()) * 1000, this, SLOT(slotPreNotify()));
666 m_intervalTimer.start();
668 else m_captureAction->setChecked(false);
671 void StopmotionWidget::slotPreNotify()
673 if (m_captureAction->isChecked()) KNotification::event("ReadyToCapture", i18n("Going to Capture Frame"), QPixmap(), this);
677 void StopmotionWidget::slotNewThumb(const QString &path)
679 if (!KdenliveSettings::showstopmotionthumbs()) return;
680 m_filesList.append(path);
681 if (m_showOverlay->isChecked()) reloadOverlay();
682 if (!m_future.isRunning()) m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
686 void StopmotionWidget::slotPrepareThumbs()
688 if (m_filesList.isEmpty()) return;
689 QString path = m_filesList.takeFirst();
690 emit doCreateThumbs(QImage(path), SlideshowClip::getFrameNumberFromPath(path));
694 void StopmotionWidget::slotCreateThumbs(QImage img, int ix)
697 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
701 int width = height * img.width() / img.height();
702 frame_list->setIconSize(QSize(width, height));
703 QPixmap pix = QPixmap::fromImage(img).scaled(width, height);
704 QString nb = QString::number(ix);
706 QFontInfo finfo(font());
707 p.fillRect(0, 0, finfo.pixelSize() * nb.count() + 6, finfo.pixelSize() + 6, QColor(80, 80, 80, 150));
709 p.drawText(QPoint(3, finfo.pixelSize() + 3), nb);
712 QListWidgetItem* item = new QListWidgetItem(icon, QString(), frame_list);
713 item->setToolTip(getPathForFrame(ix, sequence_name->currentText()));
714 item->setData(Qt::UserRole, ix);
715 frame_list->blockSignals(true);
716 frame_list->setCurrentItem(item);
717 frame_list->blockSignals(false);
718 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
721 QString StopmotionWidget::getPathForFrame(int ix, QString seqName)
723 if (seqName.isEmpty()) seqName = m_sequenceName;
724 return m_projectFolder.path(KUrl::AddTrailingSlash) + seqName + "_" + QString::number(ix).rightJustified(4, '0', false) + ".png";
727 void StopmotionWidget::slotShowFrame(const QString& path)
731 capture_button->setEnabled(false);
734 //m_videoBox->setHidden(true);
736 m_frame_preview->setImage(img);
737 m_frame_preview->setHidden(false);
738 m_frame_preview->update();
742 void StopmotionWidget::slotShowSelectedFrame()
744 QListWidgetItem* item = frame_list->currentItem();
746 //int ix = item->data(Qt::UserRole).toInt();;
747 slotShowFrame(item->toolTip());
751 void StopmotionWidget::slotAddSequence()
753 emit addOrUpdateSequence(getPathForFrame(0));
756 void StopmotionWidget::slotPlayPreview(bool animate)
761 m_animationList.clear();
764 if (KdenliveSettings::showstopmotionthumbs()) {
765 if (KdenliveSettings::sm_framesplayback() == 0) frame_list->setCurrentRow(0);
766 else frame_list->setCurrentRow(frame_list->count() - KdenliveSettings::sm_framesplayback());
767 QTimer::singleShot(200, this, SLOT(slotAnimate()));
769 SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_animationList);
770 if (KdenliveSettings::sm_framesplayback() > 0) {
771 // only play the last x frames
772 while (m_animationList.count() > KdenliveSettings::sm_framesplayback() + 1) {
773 m_animationList.removeFirst();
781 void StopmotionWidget::slotAnimate()
784 if (KdenliveSettings::showstopmotionthumbs()) {
785 int newRow = frame_list->currentRow() + 1;
786 if (KdenliveSettings::sm_loop() || newRow < frame_list->count()) {
787 if (newRow >= frame_list->count()) {
788 if (KdenliveSettings::sm_framesplayback() == 0) newRow = 0;
790 // seek to correct frame
791 newRow = frame_list->count() - KdenliveSettings::sm_framesplayback();
794 frame_list->setCurrentRow(newRow);
795 QTimer::singleShot(100, this, SLOT(slotAnimate()));
799 if (m_animatedIndex >= m_animationList.count()) {
800 if (KdenliveSettings::sm_loop()) m_animatedIndex = 0;
801 else m_animatedIndex = -1;
803 if (m_animatedIndex > -1) {
804 slotShowFrame(m_animationList.at(m_animatedIndex));
806 QTimer::singleShot(100, this, SLOT(slotAnimate()));
812 preview_button->setChecked(false);
816 QListWidgetItem* StopmotionWidget::getFrameFromIndex(int ix)
818 QListWidgetItem* item = NULL;
820 if (ix >= frame_list->count()) {
821 pos = frame_list->count() - 1;
824 item = frame_list->item(pos);
826 int value = item->data(Qt::UserRole).toInt();
827 if (value == ix) return item;
828 else if (value < ix) {
830 while (pos < frame_list->count()) {
831 item = frame_list->item(pos);
832 value = item->data(Qt::UserRole).toInt();
833 if (value == ix) return item;
839 item = frame_list->item(pos);
840 value = item->data(Qt::UserRole).toInt();
841 if (value == ix) return item;
849 void StopmotionWidget::selectFrame(int ix)
851 frame_list->blockSignals(true);
852 QListWidgetItem* item = getFrameFromIndex(ix);
854 frame_list->setCurrentItem(item);
855 frame_list->blockSignals(false);
858 void StopmotionWidget::slotSeekFrame(bool forward)
860 int ix = frame_list->currentRow();
862 if (ix < frame_list->count() - 1) frame_list->setCurrentRow(ix + 1);
863 } else if (ix > 0) frame_list->setCurrentRow(ix - 1);
866 void StopmotionWidget::slotRemoveFrame()
868 if (frame_list->currentItem() == NULL) return;
869 QString path = frame_list->currentItem()->toolTip();
870 if (KMessageBox::questionYesNo(this, i18n("Delete frame %1 from disk?", path), i18n("Delete Frame")) != KMessageBox::Yes) return;
873 QListWidgetItem* item = frame_list->takeItem(frame_list->currentRow());
874 int ix = item->data(Qt::UserRole).toInt();
875 if (ix == m_sequenceFrame - 1) {
876 // We are removing the last frame, update counter
877 QListWidgetItem* item2 = frame_list->item(frame_list->count() - 1);
878 if (item2) m_sequenceFrame = item2->data(Qt::UserRole).toInt() + 1;
884 void StopmotionWidget::slotSwitchAnalyse(bool isOn)
886 KdenliveSettings::setAnalyse_stopmotion(isOn);
887 if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = isOn;
890 void StopmotionWidget::slotSwitchMirror(bool isOn)
892 //KdenliveSettings::setAnalyse_stopmotion(isOn);
893 if (m_captureDevice) m_captureDevice->mirror(isOn);
897 const QString StopmotionWidget::createProducer(MltVideoProfile profile, const QString &service, const QString &resource)
901 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>";
904 playlist.append("<playlist id=\"playlist0\"></playlist>");
907 playlist.append("<playlist id=\"playlist1\"><entry producer=\"producer0\" in=\"0\" out=\"99999\"/></playlist>");
909 playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"99999\">");
910 playlist.append("<track producer=\"playlist0\"/>");
911 playlist.append("<track producer=\"playlist1\"/>");
912 playlist.append("</tractor></mlt>");