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(QWidget *parent) :
97 AbstractMonitor(Kdenlive::stopmotionMonitor, parent),
102 StopmotionMonitor::~StopmotionMonitor()
106 void StopmotionMonitor::setRender(MltDeviceCapture *render)
108 m_captureDevice = render;
111 AbstractRender *StopmotionMonitor::abstractRender()
113 return m_captureDevice;
116 Kdenlive::MONITORID StopmotionMonitor::id() const
118 return Kdenlive::stopmotionMonitor;
122 void StopmotionMonitor::stop()
124 if (m_captureDevice) m_captureDevice->stop();
128 void StopmotionMonitor::start()
132 StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder, QList< QAction* > actions, QWidget* parent) :
134 , Ui::Stopmotion_UI()
135 , m_projectFolder(projectFolder)
136 , m_captureDevice(NULL)
138 , m_animatedIndex(-1)
141 , m_monitor(new StopmotionMonitor(this))
143 //setAttribute(Qt::WA_DeleteOnClose);
144 //HACK: the monitor widget is hidden, it is just used to control the capturedevice from monitormanager
145 m_monitor->setHidden(true);
146 connect(m_monitor, SIGNAL(stopCapture()), this, SLOT(slotStopCapture()));
147 m_manager->appendMonitor(m_monitor);
148 QAction* analyse = new QAction(i18n("Send frames to color scopes"), this);
149 analyse->setCheckable(true);
150 analyse->setChecked(KdenliveSettings::analyse_stopmotion());
151 connect(analyse, SIGNAL(triggered(bool)), this, SLOT(slotSwitchAnalyse(bool)));
153 QAction* mirror = new QAction(i18n("Mirror display"), this);
154 mirror->setCheckable(true);
155 //mirror->setChecked(KdenliveSettings::analyse_stopmotion());
156 connect(mirror, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMirror(bool)));
160 setWindowTitle(i18n("Stop Motion Capture"));
161 setFont(KGlobalSettings::toolBarFont());
163 live_button->setIcon(KIcon("camera-photo"));
165 m_captureAction = actions.at(0);
166 connect(m_captureAction, SIGNAL(triggered()), this, SLOT(slotCaptureFrame()));
167 m_captureAction->setCheckable(true);
168 m_captureAction->setChecked(false);
169 capture_button->setDefaultAction(m_captureAction);
171 connect(actions.at(1), SIGNAL(triggered()), this, SLOT(slotSwitchLive()));
173 QAction *intervalCapture = new QAction(i18n("Interval capture"), this);
174 intervalCapture->setIcon(KIcon("chronometer"));
175 intervalCapture->setCheckable(true);
176 intervalCapture->setChecked(false);
177 capture_interval->setDefaultAction(intervalCapture);
179 preview_button->setIcon(KIcon("media-playback-start"));
180 capture_button->setEnabled(false);
184 QMenu* confMenu = new QMenu;
185 m_showOverlay = actions.at(2);
186 connect(m_showOverlay, SIGNAL(triggered(bool)), this, SLOT(slotShowOverlay(bool)));
187 overlay_button->setDefaultAction(m_showOverlay);
188 //confMenu->addAction(m_showOverlay);
190 m_effectIndex = KdenliveSettings::stopmotioneffect();
191 QMenu* effectsMenu = new QMenu(i18n("Overlay effect"));
192 QActionGroup* effectGroup = new QActionGroup(this);
193 QAction* noEffect = new QAction(i18n("No Effect"), effectGroup);
194 noEffect->setData(0);
195 QAction* contrastEffect = new QAction(i18n("Contrast"), effectGroup);
196 contrastEffect->setData(1);
197 QAction* edgeEffect = new QAction(i18n("Edge detect"), effectGroup);
198 edgeEffect->setData(2);
199 QAction* brightEffect = new QAction(i18n("Brighten"), effectGroup);
200 brightEffect->setData(3);
201 QAction* invertEffect = new QAction(i18n("Invert"), effectGroup);
202 invertEffect->setData(4);
203 QAction* thresEffect = new QAction(i18n("Threshold"), effectGroup);
204 thresEffect->setData(5);
206 effectsMenu->addAction(noEffect);
207 effectsMenu->addAction(contrastEffect);
208 effectsMenu->addAction(edgeEffect);
209 effectsMenu->addAction(brightEffect);
210 effectsMenu->addAction(invertEffect);
211 effectsMenu->addAction(thresEffect);
212 QList <QAction*> list = effectsMenu->actions();
213 for (int i = 0; i < list.count(); i++) {
214 list.at(i)->setCheckable(true);
215 if (list.at(i)->data().toInt() == m_effectIndex) {
216 list.at(i)->setChecked(true);
219 connect(effectsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotUpdateOverlayEffect(QAction*)));
220 confMenu->addMenu(effectsMenu);
222 QAction* showThumbs = new QAction(KIcon("image-x-generic"), i18n("Show sequence thumbnails"), this);
223 showThumbs->setCheckable(true);
224 showThumbs->setChecked(KdenliveSettings::showstopmotionthumbs());
225 connect(showThumbs, SIGNAL(triggered(bool)), this, SLOT(slotShowThumbs(bool)));
227 QAction* removeCurrent = new QAction(KIcon("edit-delete"), i18n("Delete current frame"), this);
228 removeCurrent->setShortcut(Qt::Key_Delete);
229 connect(removeCurrent, SIGNAL(triggered()), this, SLOT(slotRemoveFrame()));
231 QAction* conf = new QAction(KIcon("configure"), i18n("Configure"), this);
232 connect(conf, SIGNAL(triggered()), this, SLOT(slotConfigure()));
234 confMenu->addAction(showThumbs);
235 confMenu->addAction(removeCurrent);
236 confMenu->addAction(analyse);
237 confMenu->addAction(mirror);
238 confMenu->addAction(conf);
239 config_button->setIcon(KIcon("configure"));
240 config_button->setMenu(confMenu);
242 connect(sequence_name, SIGNAL(textChanged(const QString&)), this, SLOT(sequenceNameChanged(const QString&)));
243 connect(sequence_name, SIGNAL(currentIndexChanged(int)), live_button, SLOT(setFocus()));
245 // Video widget holder
246 QVBoxLayout *layout = new QVBoxLayout;
247 layout->setContentsMargins(0, 0, 0, 0);
248 layout->setSpacing(0);
249 m_videoBox = new VideoPreviewContainer();
250 m_videoBox->setContentsMargins(0, 0, 0, 0);
251 m_videoBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
252 //m_videoBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
253 m_videoBox->setLineWidth(4);
254 layout->addWidget(m_videoBox);
256 #ifdef USE_BLACKMAGIC
257 if (BMInterface::getBlackMagicDeviceList(capture_device)) {
258 // Found a BlackMagic device
261 if (QFile::exists(KdenliveSettings::video4vdevice())) {
263 // Video 4 Linux device detection
264 for (int i = 0; i < 10; i++) {
265 QString path = "/dev/video" + QString::number(i);
266 if (QFile::exists(path)) {
267 QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path);
268 if (!deviceInfo.isEmpty()) {
269 capture_device->addItem(deviceInfo.at(0), "v4l");
270 capture_device->setItemData(capture_device->count() - 1, path, Qt::UserRole + 1);
271 capture_device->setItemData(capture_device->count() - 1, deviceInfo.at(1), Qt::UserRole + 2);
272 if (path == KdenliveSettings::video4vdevice()) capture_device->setCurrentIndex(capture_device->count() - 1);
279 connect(capture_device, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDeviceHandler()));
281 connect(m_bmCapture, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
282 connect(m_bmCapture, SIGNAL(gotFrame(QImage)), this, SIGNAL(gotFrame(QImage)));
283 } else live_button->setEnabled(false);*/
285 m_frame_preview = new MyLabel(this);
286 connect(m_frame_preview, SIGNAL(seek(bool)), this, SLOT(slotSeekFrame(bool)));
287 connect(m_frame_preview, SIGNAL(switchToLive()), this, SLOT(slotSwitchLive()));
288 layout->addWidget(m_frame_preview);
289 m_frame_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
290 video_preview->setLayout(layout);
292 //kDebug()<<video_preview->winId();
295 // Create MLT producer data
296 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
297 // Capture using a video4linux device
298 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
302 profilePath = KdenliveSettings::current_profile();
305 m_captureDevice = new MltDeviceCapture(profilePath, m_videoBox, this);
306 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
307 m_monitor->setRender(m_captureDevice);
308 connect(m_captureDevice, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
310 live_button->setChecked(false);
311 button_addsequence->setEnabled(false);
312 connect(live_button, SIGNAL(toggled(bool)), this, SLOT(slotLive(bool)));
313 connect(button_addsequence, SIGNAL(clicked(bool)), this, SLOT(slotAddSequence()));
314 connect(preview_button, SIGNAL(clicked(bool)), this, SLOT(slotPlayPreview(bool)));
315 connect(frame_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotShowSelectedFrame()));
316 connect(frame_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slotShowSelectedFrame()));
317 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
319 frame_list->addAction(removeCurrent);
320 frame_list->setContextMenuPolicy(Qt::ActionsContextMenu);
321 frame_list->setHidden(!KdenliveSettings::showstopmotionthumbs());
322 parseExistingSequences();
323 QTimer::singleShot(500, this, SLOT(slotLive()));
324 connect(&m_intervalTimer, SIGNAL(timeout()), this, SLOT(slotCaptureFrame()));
325 m_intervalTimer.setSingleShot(true);
326 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
329 StopmotionWidget::~StopmotionWidget()
331 m_manager->removeMonitor(m_monitor);
332 if (m_captureDevice) {
333 m_captureDevice->stop();
334 delete m_captureDevice;
335 m_captureDevice = NULL;
341 void StopmotionWidget::slotUpdateOverlayEffect(QAction* act)
343 if (act) m_effectIndex = act->data().toInt();
344 KdenliveSettings::setStopmotioneffect(m_effectIndex);
348 void StopmotionWidget::closeEvent(QCloseEvent* e)
351 QDialog::closeEvent(e);
354 void StopmotionWidget::slotConfigure()
359 d.setWindowTitle(i18n("Configure Stop Motion"));
360 ui.sm_interval->setValue(KdenliveSettings::captureinterval());
361 ui.sm_interval->setSuffix(ki18np(" second", " seconds"));
362 ui.sm_notifytime->setSuffix(ki18np(" second", " seconds"));
363 ui.sm_notifytime->setValue(KdenliveSettings::sm_notifytime());
364 connect(ui.sm_prenotify, SIGNAL(toggled(bool)), ui.sm_notifytime, SLOT(setEnabled(bool)));
365 ui.sm_prenotify->setChecked(KdenliveSettings::sm_prenotify());
366 ui.sm_loop->setChecked(KdenliveSettings::sm_loop());
367 ui.sm_framesplayback->setValue(KdenliveSettings::sm_framesplayback());
369 if (d.exec() == QDialog::Accepted) {
370 KdenliveSettings::setSm_loop(ui.sm_loop->isChecked());
371 KdenliveSettings::setCaptureinterval(ui.sm_interval->value());
372 KdenliveSettings::setSm_framesplayback(ui.sm_framesplayback->value());
373 KdenliveSettings::setSm_notifytime(ui.sm_notifytime->value());
374 KdenliveSettings::setSm_prenotify(ui.sm_prenotify->isChecked());
375 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
379 void StopmotionWidget::slotShowThumbs(bool show)
381 KdenliveSettings::setShowstopmotionthumbs(show);
384 sequenceNameChanged(sequence_name->currentText());
389 frame_list->setHidden(!show);
393 void StopmotionWidget::slotUpdateDeviceHandler()
396 delete m_captureDevice;
397 m_captureDevice = NULL;
398 /*QString data = capture_device->itemData(capture_device->currentIndex()).toString();
403 m_layout->removeWidget(m_frame_preview);
406 m_bmCapture = new V4lCaptureHandler(m_layout);
407 m_bmCapture->setDevice(capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString(), capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 2).toString());
410 m_bmCapture = new BmdCaptureHandler(m_layout);
411 if (m_bmCapture) connect(m_bmCapture, SIGNAL(gotMessage(const QString&)), this, SLOT(slotGotHDMIMessage(const QString&)));
413 live_button->setEnabled(m_bmCapture != NULL);
414 m_layout->addWidget(m_frame_preview);*/
417 void StopmotionWidget::slotGotHDMIMessage(const QString& message)
419 log_box->insertItem(0, message);
422 void StopmotionWidget::parseExistingSequences()
424 sequence_name->clear();
425 sequence_name->addItem(QString());
426 QDir dir(m_projectFolder.path());
428 filters << "*_0000.png";
429 //dir.setNameFilters(filters);
430 QStringList sequences = dir.entryList(filters, QDir::Files, QDir::Name);
431 //kDebug()<<"PF: "<<<<", sm: "<<sequences;
432 foreach(QString sequencename, sequences) {
433 sequence_name->addItem(sequencename.section("_", 0, -2));
437 void StopmotionWidget::slotSwitchLive()
439 setUpdatesEnabled(false);
440 slotLive(!live_button->isChecked());
441 /*if (m_frame_preview->isHidden()) {
442 //if (m_bmCapture) m_bmCapture->hidePreview(true);
443 m_videoBox->setHidden(true);
444 m_frame_preview->setHidden(false);
446 m_frame_preview->setHidden(true);
447 //if (m_bmCapture) m_bmCapture->hidePreview(false);
448 m_videoBox->setHidden(false);
449 capture_button->setEnabled(true);
451 setUpdatesEnabled(true);
454 void StopmotionWidget::slotStopCapture()
459 void StopmotionWidget::slotLive(bool isOn)
461 live_button->blockSignals(true);
462 capture_button->setEnabled(false);
464 m_frame_preview->setHidden(true);
465 m_videoBox->setHidden(false);
468 MltVideoProfile profile;
472 // Create MLT producer data
473 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
474 // Capture using a video4linux device
475 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
476 profile = ProfilesDialog::getVideoProfile(profilePath);
477 service = "avformat-novalidate";
478 QString devicePath = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
479 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);
483 profilePath = KdenliveSettings::current_profile();
484 profile = ProfilesDialog::getVideoProfile(profilePath);
485 service = "decklink";
486 resource = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
489 if (m_captureDevice == NULL) {
490 m_captureDevice = new MltDeviceCapture(profilePath, m_videoBox, this);
491 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
492 m_monitor->setRender(m_captureDevice);
493 connect(m_captureDevice, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
496 m_manager->activateMonitor(Kdenlive::stopmotionMonitor);
497 QString producer = createProducer(profile, service, resource);
498 if (m_captureDevice->slotStartPreview(producer, true)) {
499 if (m_showOverlay->isChecked()) {
503 capture_button->setEnabled(true);
504 live_button->setChecked(true);
505 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')));
506 log_box->setCurrentIndex(0);
509 kDebug()<<"// problem starting stopmo";
510 log_box->insertItem(-1, i18n("Failed to start device"));
511 log_box->setCurrentIndex(0);
515 m_frame_preview->setHidden(false);
516 live_button->setChecked(false);
517 if (m_captureDevice) {
518 m_captureDevice->stop();
519 m_videoBox->setHidden(true);
520 log_box->insertItem(-1, i18n("Stopped"));
521 log_box->setCurrentIndex(0);
522 //delete m_captureDevice;
523 //m_captureDevice = NULL;
528 if (isOn && m_bmCapture) {
529 //m_frame_preview->setImage(QImage());
530 m_frame_preview->setHidden(true);
531 m_bmCapture->startPreview(KdenliveSettings::hdmi_capturedevice(), KdenliveSettings::hdmi_capturemode(), false);
532 capture_button->setEnabled(true);
533 live_button->setChecked(true);
535 if (m_bmCapture) m_bmCapture->stopPreview();
536 m_frame_preview->setHidden(false);
537 capture_button->setEnabled(false);
538 live_button->setChecked(false);
540 live_button->blockSignals(false);
543 void StopmotionWidget::slotShowOverlay(bool isOn)
546 // Overlay last frame of the sequence
552 m_captureDevice->setOverlay(QString());
556 void StopmotionWidget::reloadOverlay()
558 QString path = getPathForFrame(m_sequenceFrame - 1);
559 if (!QFile::exists(path)) {
560 log_box->insertItem(-1, i18n("No previous frame found"));
561 log_box->setCurrentIndex(0);
564 m_captureDevice->setOverlay(path);
567 void StopmotionWidget::slotUpdateOverlay()
569 if (m_captureDevice == NULL) return;
574 switch (m_effectIndex) {
576 tag = "frei0r.contrast0r";
577 params << "Contrast=1.2";
581 params << "x_scatter=4" << "y_scatter=4" << "scale=1" << "mix=0";
584 tag = "frei0r.brightness";
585 params << "Brightness=0.7";
592 params << "midpoint=125";
598 m_captureDevice->setOverlayEffect(tag, params);
601 void StopmotionWidget::sequenceNameChanged(const QString& name)
603 // Get rid of frames from previous sequence
604 disconnect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
606 m_future.waitForFinished();
608 if (name.isEmpty()) {
609 button_addsequence->setEnabled(false);
611 // Check if we are editing an existing sequence
612 QString pattern = SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_filesList);
613 m_sequenceFrame = m_filesList.isEmpty() ? 0 : SlideshowClip::getFrameNumberFromPath(m_filesList.last()) + 1;
614 if (!m_filesList.isEmpty()) {
615 m_sequenceName = sequence_name->currentText();
616 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
617 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
618 button_addsequence->setEnabled(true);
621 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
622 button_addsequence->setEnabled(false);
624 capture_button->setEnabled(live_button->isChecked());
628 void StopmotionWidget::slotCaptureFrame()
630 if (m_captureDevice == NULL) return;
631 if (sequence_name->currentText().isEmpty()) {
632 QString seqName = QInputDialog::getText(this, i18n("Create New Sequence"), i18n("Enter sequence name"));
633 if (seqName.isEmpty()) {
634 m_captureAction->setChecked(false);
637 sequence_name->blockSignals(true);
638 sequence_name->setItemText(sequence_name->currentIndex(), seqName);
639 sequence_name->blockSignals(false);
641 if (m_sequenceName != sequence_name->currentText()) {
642 m_sequenceName = sequence_name->currentText();
645 //capture_button->setEnabled(false);
646 if (m_intervalTimer.isActive()) {
647 // stop interval capture
648 m_intervalTimer.stop();
651 QString currentPath = getPathForFrame(m_sequenceFrame);
652 m_captureDevice->captureFrame(currentPath);
653 KNotification::event("FrameCaptured", i18n("Frame Captured"), QPixmap(), this);
655 button_addsequence->setEnabled(true);
656 if (capture_interval->isChecked()) {
657 if (KdenliveSettings::sm_prenotify()) QTimer::singleShot((KdenliveSettings::captureinterval() - KdenliveSettings::sm_notifytime()) * 1000, this, SLOT(slotPreNotify()));
658 m_intervalTimer.start();
660 else m_captureAction->setChecked(false);
663 void StopmotionWidget::slotPreNotify()
665 if (m_captureAction->isChecked()) KNotification::event("ReadyToCapture", i18n("Going to Capture Frame"), QPixmap(), this);
669 void StopmotionWidget::slotNewThumb(const QString &path)
671 if (!KdenliveSettings::showstopmotionthumbs()) return;
672 m_filesList.append(path);
673 if (m_showOverlay->isChecked()) reloadOverlay();
674 if (!m_future.isRunning()) m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
678 void StopmotionWidget::slotPrepareThumbs()
680 if (m_filesList.isEmpty()) return;
681 QString path = m_filesList.takeFirst();
682 emit doCreateThumbs(QImage(path), SlideshowClip::getFrameNumberFromPath(path));
686 void StopmotionWidget::slotCreateThumbs(QImage img, int ix)
689 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
693 int width = height * img.width() / img.height();
694 frame_list->setIconSize(QSize(width, height));
695 QPixmap pix = QPixmap::fromImage(img).scaled(width, height);
696 QString nb = QString::number(ix);
698 QFontInfo finfo(font());
699 p.fillRect(0, 0, finfo.pixelSize() * nb.count() + 6, finfo.pixelSize() + 6, QColor(80, 80, 80, 150));
701 p.drawText(QPoint(3, finfo.pixelSize() + 3), nb);
704 QListWidgetItem* item = new QListWidgetItem(icon, QString(), frame_list);
705 item->setToolTip(getPathForFrame(ix, sequence_name->currentText()));
706 item->setData(Qt::UserRole, ix);
707 frame_list->blockSignals(true);
708 frame_list->setCurrentItem(item);
709 frame_list->blockSignals(false);
710 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
713 QString StopmotionWidget::getPathForFrame(int ix, QString seqName)
715 if (seqName.isEmpty()) seqName = m_sequenceName;
716 return m_projectFolder.path(KUrl::AddTrailingSlash) + seqName + "_" + QString::number(ix).rightJustified(4, '0', false) + ".png";
719 void StopmotionWidget::slotShowFrame(const QString& path)
723 capture_button->setEnabled(false);
726 //m_videoBox->setHidden(true);
728 m_frame_preview->setImage(img);
729 m_frame_preview->setHidden(false);
730 m_frame_preview->update();
734 void StopmotionWidget::slotShowSelectedFrame()
736 QListWidgetItem* item = frame_list->currentItem();
738 //int ix = item->data(Qt::UserRole).toInt();;
739 slotShowFrame(item->toolTip());
743 void StopmotionWidget::slotAddSequence()
745 emit addOrUpdateSequence(getPathForFrame(0));
748 void StopmotionWidget::slotPlayPreview(bool animate)
753 m_animationList.clear();
756 if (KdenliveSettings::showstopmotionthumbs()) {
757 if (KdenliveSettings::sm_framesplayback() == 0) frame_list->setCurrentRow(0);
758 else frame_list->setCurrentRow(frame_list->count() - KdenliveSettings::sm_framesplayback());
759 QTimer::singleShot(200, this, SLOT(slotAnimate()));
761 SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_animationList);
762 if (KdenliveSettings::sm_framesplayback() > 0) {
763 // only play the last x frames
764 while (m_animationList.count() > KdenliveSettings::sm_framesplayback() + 1) {
765 m_animationList.removeFirst();
773 void StopmotionWidget::slotAnimate()
776 if (KdenliveSettings::showstopmotionthumbs()) {
777 int newRow = frame_list->currentRow() + 1;
778 if (KdenliveSettings::sm_loop() || newRow < frame_list->count()) {
779 if (newRow >= frame_list->count()) {
780 if (KdenliveSettings::sm_framesplayback() == 0) newRow = 0;
782 // seek to correct frame
783 newRow = frame_list->count() - KdenliveSettings::sm_framesplayback();
786 frame_list->setCurrentRow(newRow);
787 QTimer::singleShot(100, this, SLOT(slotAnimate()));
791 if (m_animatedIndex >= m_animationList.count()) {
792 if (KdenliveSettings::sm_loop()) m_animatedIndex = 0;
793 else m_animatedIndex = -1;
795 if (m_animatedIndex > -1) {
796 slotShowFrame(m_animationList.at(m_animatedIndex));
798 QTimer::singleShot(100, this, SLOT(slotAnimate()));
804 preview_button->setChecked(false);
808 QListWidgetItem* StopmotionWidget::getFrameFromIndex(int ix)
810 QListWidgetItem* item = NULL;
812 if (ix >= frame_list->count()) {
813 pos = frame_list->count() - 1;
816 item = frame_list->item(pos);
818 int value = item->data(Qt::UserRole).toInt();
819 if (value == ix) return item;
820 else if (value < ix) {
822 while (pos < frame_list->count()) {
823 item = frame_list->item(pos);
824 value = item->data(Qt::UserRole).toInt();
825 if (value == ix) return item;
831 item = frame_list->item(pos);
832 value = item->data(Qt::UserRole).toInt();
833 if (value == ix) return item;
841 void StopmotionWidget::selectFrame(int ix)
843 frame_list->blockSignals(true);
844 QListWidgetItem* item = getFrameFromIndex(ix);
846 frame_list->setCurrentItem(item);
847 frame_list->blockSignals(false);
850 void StopmotionWidget::slotSeekFrame(bool forward)
852 int ix = frame_list->currentRow();
854 if (ix < frame_list->count() - 1) frame_list->setCurrentRow(ix + 1);
855 } else if (ix > 0) frame_list->setCurrentRow(ix - 1);
858 void StopmotionWidget::slotRemoveFrame()
860 if (frame_list->currentItem() == NULL) return;
861 QString path = frame_list->currentItem()->toolTip();
862 if (KMessageBox::questionYesNo(this, i18n("Delete frame %1 from disk?", path), i18n("Delete Frame")) != KMessageBox::Yes) return;
865 QListWidgetItem* item = frame_list->takeItem(frame_list->currentRow());
866 int ix = item->data(Qt::UserRole).toInt();
867 if (ix == m_sequenceFrame - 1) {
868 // We are removing the last frame, update counter
869 QListWidgetItem* item2 = frame_list->item(frame_list->count() - 1);
870 if (item2) m_sequenceFrame = item2->data(Qt::UserRole).toInt() + 1;
876 void StopmotionWidget::slotSwitchAnalyse(bool isOn)
878 KdenliveSettings::setAnalyse_stopmotion(isOn);
879 if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = isOn;
882 void StopmotionWidget::slotSwitchMirror(bool isOn)
884 //KdenliveSettings::setAnalyse_stopmotion(isOn);
885 if (m_captureDevice) m_captureDevice->mirror(isOn);
888 const QString StopmotionWidget::createProducer(MltVideoProfile profile, const QString &service, const QString &resource)
892 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>";
895 playlist.append("<playlist id=\"playlist0\"></playlist>");
898 playlist.append("<playlist id=\"playlist1\"><entry producer=\"producer0\" in=\"0\" out=\"99999\"/></playlist>");
900 playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"99999\">");
901 playlist.append("<track producer=\"playlist0\"/>");
902 playlist.append("<track producer=\"playlist1\"/>");
903 playlist.append("</tractor></mlt>");