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),
100 createVideoSurface();
103 StopmotionMonitor::~StopmotionMonitor()
107 void StopmotionMonitor::slotSwitchFullScreen()
111 void StopmotionMonitor::setRender(MltDeviceCapture *render)
113 m_captureDevice = render;
116 AbstractRender *StopmotionMonitor::abstractRender()
118 return m_captureDevice;
121 Kdenlive::MONITORID StopmotionMonitor::id() const
123 return Kdenlive::stopmotionMonitor;
127 void StopmotionMonitor::stop()
129 if (m_captureDevice) m_captureDevice->stop();
133 void StopmotionMonitor::start()
137 void StopmotionMonitor::slotPlay()
141 void StopmotionMonitor::slotMouseSeek(int /*eventDelta*/, bool /*fast*/)
145 StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder, QList< QAction* > actions, QWidget* parent) :
147 , Ui::Stopmotion_UI()
148 , m_projectFolder(projectFolder)
149 , m_captureDevice(NULL)
151 , m_animatedIndex(-1)
154 , m_monitor(new StopmotionMonitor(manager, this))
156 //setAttribute(Qt::WA_DeleteOnClose);
157 //HACK: the monitor widget is hidden, it is just used to control the capturedevice from monitormanager
158 m_monitor->setHidden(true);
159 connect(m_monitor, SIGNAL(stopCapture()), this, SLOT(slotStopCapture()));
160 m_manager->appendMonitor(m_monitor);
161 QAction* analyse = new QAction(i18n("Send frames to color scopes"), this);
162 analyse->setCheckable(true);
163 analyse->setChecked(KdenliveSettings::analyse_stopmotion());
164 connect(analyse, SIGNAL(triggered(bool)), this, SLOT(slotSwitchAnalyse(bool)));
166 QAction* mirror = new QAction(i18n("Mirror display"), this);
167 mirror->setCheckable(true);
168 //mirror->setChecked(KdenliveSettings::analyse_stopmotion());
169 connect(mirror, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMirror(bool)));
173 setWindowTitle(i18n("Stop Motion Capture"));
174 setFont(KGlobalSettings::toolBarFont());
176 live_button->setIcon(KIcon("camera-photo"));
178 m_captureAction = actions.at(0);
179 connect(m_captureAction, SIGNAL(triggered()), this, SLOT(slotCaptureFrame()));
180 m_captureAction->setCheckable(true);
181 m_captureAction->setChecked(false);
182 capture_button->setDefaultAction(m_captureAction);
184 connect(actions.at(1), SIGNAL(triggered()), this, SLOT(slotSwitchLive()));
186 QAction *intervalCapture = new QAction(i18n("Interval capture"), this);
187 intervalCapture->setIcon(KIcon("chronometer"));
188 intervalCapture->setCheckable(true);
189 intervalCapture->setChecked(false);
190 capture_interval->setDefaultAction(intervalCapture);
192 preview_button->setIcon(KIcon("media-playback-start"));
193 capture_button->setEnabled(false);
197 QMenu* confMenu = new QMenu;
198 m_showOverlay = actions.at(2);
199 connect(m_showOverlay, SIGNAL(triggered(bool)), this, SLOT(slotShowOverlay(bool)));
200 overlay_button->setDefaultAction(m_showOverlay);
201 //confMenu->addAction(m_showOverlay);
203 m_effectIndex = KdenliveSettings::stopmotioneffect();
204 QMenu* effectsMenu = new QMenu(i18n("Overlay effect"));
205 QActionGroup* effectGroup = new QActionGroup(this);
206 QAction* noEffect = new QAction(i18n("No Effect"), effectGroup);
207 noEffect->setData(0);
208 QAction* contrastEffect = new QAction(i18n("Contrast"), effectGroup);
209 contrastEffect->setData(1);
210 QAction* edgeEffect = new QAction(i18n("Edge detect"), effectGroup);
211 edgeEffect->setData(2);
212 QAction* brightEffect = new QAction(i18n("Brighten"), effectGroup);
213 brightEffect->setData(3);
214 QAction* invertEffect = new QAction(i18n("Invert"), effectGroup);
215 invertEffect->setData(4);
216 QAction* thresEffect = new QAction(i18n("Threshold"), effectGroup);
217 thresEffect->setData(5);
219 effectsMenu->addAction(noEffect);
220 effectsMenu->addAction(contrastEffect);
221 effectsMenu->addAction(edgeEffect);
222 effectsMenu->addAction(brightEffect);
223 effectsMenu->addAction(invertEffect);
224 effectsMenu->addAction(thresEffect);
225 QList <QAction*> list = effectsMenu->actions();
226 for (int i = 0; i < list.count(); i++) {
227 list.at(i)->setCheckable(true);
228 if (list.at(i)->data().toInt() == m_effectIndex) {
229 list.at(i)->setChecked(true);
232 connect(effectsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotUpdateOverlayEffect(QAction*)));
233 confMenu->addMenu(effectsMenu);
235 QAction* showThumbs = new QAction(KIcon("image-x-generic"), i18n("Show sequence thumbnails"), this);
236 showThumbs->setCheckable(true);
237 showThumbs->setChecked(KdenliveSettings::showstopmotionthumbs());
238 connect(showThumbs, SIGNAL(triggered(bool)), this, SLOT(slotShowThumbs(bool)));
240 QAction* removeCurrent = new QAction(KIcon("edit-delete"), i18n("Delete current frame"), this);
241 removeCurrent->setShortcut(Qt::Key_Delete);
242 connect(removeCurrent, SIGNAL(triggered()), this, SLOT(slotRemoveFrame()));
244 QAction* conf = new QAction(KIcon("configure"), i18n("Configure"), this);
245 connect(conf, SIGNAL(triggered()), this, SLOT(slotConfigure()));
247 confMenu->addAction(showThumbs);
248 confMenu->addAction(removeCurrent);
249 confMenu->addAction(analyse);
250 confMenu->addAction(mirror);
251 confMenu->addAction(conf);
252 config_button->setIcon(KIcon("configure"));
253 config_button->setMenu(confMenu);
255 connect(sequence_name, SIGNAL(textChanged(const QString&)), this, SLOT(sequenceNameChanged(const QString&)));
256 connect(sequence_name, SIGNAL(currentIndexChanged(int)), live_button, SLOT(setFocus()));
258 // Video widget holder
259 QVBoxLayout *layout = new QVBoxLayout;
260 layout->setContentsMargins(0, 0, 0, 0);
261 layout->setSpacing(0);
262 m_monitor->videoBox->setLineWidth(4);
263 layout->addWidget(m_monitor->videoBox);
265 #ifdef USE_BLACKMAGIC
266 if (BMInterface::getBlackMagicDeviceList(capture_device)) {
267 // Found a BlackMagic device
270 if (QFile::exists(KdenliveSettings::video4vdevice())) {
272 // Video 4 Linux device detection
273 for (int i = 0; i < 10; i++) {
274 QString path = "/dev/video" + QString::number(i);
275 if (QFile::exists(path)) {
276 QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path);
277 if (!deviceInfo.isEmpty()) {
278 capture_device->addItem(deviceInfo.at(0), "v4l");
279 capture_device->setItemData(capture_device->count() - 1, path, Qt::UserRole + 1);
280 capture_device->setItemData(capture_device->count() - 1, deviceInfo.at(1), Qt::UserRole + 2);
281 if (path == KdenliveSettings::video4vdevice()) capture_device->setCurrentIndex(capture_device->count() - 1);
288 connect(capture_device, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDeviceHandler()));
290 connect(m_bmCapture, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
291 connect(m_bmCapture, SIGNAL(gotFrame(QImage)), this, SIGNAL(gotFrame(QImage)));
292 } else live_button->setEnabled(false);*/
294 m_frame_preview = new MyLabel(this);
295 connect(m_frame_preview, SIGNAL(seek(bool)), this, SLOT(slotSeekFrame(bool)));
296 connect(m_frame_preview, SIGNAL(switchToLive()), this, SLOT(slotSwitchLive()));
297 layout->addWidget(m_frame_preview);
298 m_frame_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
299 video_preview->setLayout(layout);
301 //kDebug()<<video_preview->winId();
304 // Create MLT producer data
305 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
306 // Capture using a video4linux device
307 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
311 profilePath = KdenliveSettings::current_profile();
314 m_captureDevice = new MltDeviceCapture(profilePath, m_monitor->videoSurface, this);
315 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
316 m_monitor->setRender(m_captureDevice);
317 connect(m_captureDevice, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
319 live_button->setChecked(false);
320 button_addsequence->setEnabled(false);
321 connect(live_button, SIGNAL(toggled(bool)), this, SLOT(slotLive(bool)));
322 connect(button_addsequence, SIGNAL(clicked(bool)), this, SLOT(slotAddSequence()));
323 connect(preview_button, SIGNAL(clicked(bool)), this, SLOT(slotPlayPreview(bool)));
324 connect(frame_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotShowSelectedFrame()));
325 connect(frame_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slotShowSelectedFrame()));
326 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
328 frame_list->addAction(removeCurrent);
329 frame_list->setContextMenuPolicy(Qt::ActionsContextMenu);
330 frame_list->setHidden(!KdenliveSettings::showstopmotionthumbs());
331 parseExistingSequences();
332 QTimer::singleShot(500, this, SLOT(slotLive()));
333 connect(&m_intervalTimer, SIGNAL(timeout()), this, SLOT(slotCaptureFrame()));
334 m_intervalTimer.setSingleShot(true);
335 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
338 StopmotionWidget::~StopmotionWidget()
340 m_manager->removeMonitor(m_monitor);
341 if (m_captureDevice) {
342 m_captureDevice->stop();
343 delete m_captureDevice;
344 m_captureDevice = NULL;
350 void StopmotionWidget::slotUpdateOverlayEffect(QAction* act)
352 if (act) m_effectIndex = act->data().toInt();
353 KdenliveSettings::setStopmotioneffect(m_effectIndex);
357 void StopmotionWidget::closeEvent(QCloseEvent* e)
360 QDialog::closeEvent(e);
363 void StopmotionWidget::slotConfigure()
368 d.setWindowTitle(i18n("Configure Stop Motion"));
369 ui.sm_interval->setValue(KdenliveSettings::captureinterval());
370 ui.sm_interval->setSuffix(ki18np(" second", " seconds"));
371 ui.sm_notifytime->setSuffix(ki18np(" second", " seconds"));
372 ui.sm_notifytime->setValue(KdenliveSettings::sm_notifytime());
373 connect(ui.sm_prenotify, SIGNAL(toggled(bool)), ui.sm_notifytime, SLOT(setEnabled(bool)));
374 ui.sm_prenotify->setChecked(KdenliveSettings::sm_prenotify());
375 ui.sm_loop->setChecked(KdenliveSettings::sm_loop());
376 ui.sm_framesplayback->setValue(KdenliveSettings::sm_framesplayback());
378 if (d.exec() == QDialog::Accepted) {
379 KdenliveSettings::setSm_loop(ui.sm_loop->isChecked());
380 KdenliveSettings::setCaptureinterval(ui.sm_interval->value());
381 KdenliveSettings::setSm_framesplayback(ui.sm_framesplayback->value());
382 KdenliveSettings::setSm_notifytime(ui.sm_notifytime->value());
383 KdenliveSettings::setSm_prenotify(ui.sm_prenotify->isChecked());
384 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
388 void StopmotionWidget::slotShowThumbs(bool show)
390 KdenliveSettings::setShowstopmotionthumbs(show);
393 sequenceNameChanged(sequence_name->currentText());
398 frame_list->setHidden(!show);
402 void StopmotionWidget::slotUpdateDeviceHandler()
405 delete m_captureDevice;
406 m_captureDevice = NULL;
407 /*QString data = capture_device->itemData(capture_device->currentIndex()).toString();
412 m_layout->removeWidget(m_frame_preview);
415 m_bmCapture = new V4lCaptureHandler(m_layout);
416 m_bmCapture->setDevice(capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString(), capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 2).toString());
419 m_bmCapture = new BmdCaptureHandler(m_layout);
420 if (m_bmCapture) connect(m_bmCapture, SIGNAL(gotMessage(const QString&)), this, SLOT(slotGotHDMIMessage(const QString&)));
422 live_button->setEnabled(m_bmCapture != NULL);
423 m_layout->addWidget(m_frame_preview);*/
426 void StopmotionWidget::slotGotHDMIMessage(const QString& message)
428 log_box->insertItem(0, message);
431 void StopmotionWidget::parseExistingSequences()
433 sequence_name->clear();
434 sequence_name->addItem(QString());
435 QDir dir(m_projectFolder.path());
437 filters << "*_0000.png";
438 //dir.setNameFilters(filters);
439 QStringList sequences = dir.entryList(filters, QDir::Files, QDir::Name);
440 //kDebug()<<"PF: "<<<<", sm: "<<sequences;
441 foreach(QString sequencename, sequences) {
442 sequence_name->addItem(sequencename.section('_', 0, -2));
446 void StopmotionWidget::slotSwitchLive()
448 setUpdatesEnabled(false);
449 slotLive(!live_button->isChecked());
450 /*if (m_frame_preview->isHidden()) {
451 //if (m_bmCapture) m_bmCapture->hidePreview(true);
452 m_videoBox->setHidden(true);
453 m_frame_preview->setHidden(false);
455 m_frame_preview->setHidden(true);
456 //if (m_bmCapture) m_bmCapture->hidePreview(false);
457 m_videoBox->setHidden(false);
458 capture_button->setEnabled(true);
460 setUpdatesEnabled(true);
463 void StopmotionWidget::slotStopCapture()
468 void StopmotionWidget::slotLive(bool isOn)
470 live_button->blockSignals(true);
471 capture_button->setEnabled(false);
473 m_frame_preview->setHidden(true);
474 m_monitor->videoBox->setHidden(false);
477 MltVideoProfile profile;
481 // Create MLT producer data
482 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
483 // Capture using a video4linux device
484 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
485 profile = ProfilesDialog::getVideoProfile(profilePath);
486 service = "avformat-novalidate";
487 QString devicePath = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
488 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);
492 profilePath = KdenliveSettings::current_profile();
493 profile = ProfilesDialog::getVideoProfile(profilePath);
494 service = "decklink";
495 resource = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
498 if (m_captureDevice == NULL) {
499 m_captureDevice = new MltDeviceCapture(profilePath, m_monitor->videoSurface, this);
500 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
501 m_monitor->setRender(m_captureDevice);
502 connect(m_captureDevice, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
505 m_manager->activateMonitor(Kdenlive::stopmotionMonitor);
506 QString producer = createProducer(profile, service, resource);
507 if (m_captureDevice->slotStartPreview(producer, true)) {
508 if (m_showOverlay->isChecked()) {
512 capture_button->setEnabled(true);
513 live_button->setChecked(true);
514 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')));
515 log_box->setCurrentIndex(0);
518 kDebug()<<"// problem starting stopmo";
519 log_box->insertItem(-1, i18n("Failed to start device"));
520 log_box->setCurrentIndex(0);
524 m_frame_preview->setHidden(false);
525 live_button->setChecked(false);
526 if (m_captureDevice) {
527 m_captureDevice->stop();
528 m_monitor->videoBox->setHidden(true);
529 log_box->insertItem(-1, i18n("Stopped"));
530 log_box->setCurrentIndex(0);
531 //delete m_captureDevice;
532 //m_captureDevice = NULL;
537 if (isOn && m_bmCapture) {
538 //m_frame_preview->setImage(QImage());
539 m_frame_preview->setHidden(true);
540 m_bmCapture->startPreview(KdenliveSettings::hdmi_capturedevice(), KdenliveSettings::hdmi_capturemode(), false);
541 capture_button->setEnabled(true);
542 live_button->setChecked(true);
544 if (m_bmCapture) m_bmCapture->stopPreview();
545 m_frame_preview->setHidden(false);
546 capture_button->setEnabled(false);
547 live_button->setChecked(false);
549 live_button->blockSignals(false);
552 void StopmotionWidget::slotShowOverlay(bool isOn)
555 // Overlay last frame of the sequence
561 m_captureDevice->setOverlay(QString());
565 void StopmotionWidget::reloadOverlay()
567 QString path = getPathForFrame(m_sequenceFrame - 1);
568 if (!QFile::exists(path)) {
569 log_box->insertItem(-1, i18n("No previous frame found"));
570 log_box->setCurrentIndex(0);
573 m_captureDevice->setOverlay(path);
576 void StopmotionWidget::slotUpdateOverlay()
578 if (m_captureDevice == NULL) return;
583 switch (m_effectIndex) {
585 tag = "frei0r.contrast0r";
586 params << "Contrast=1.2";
590 params << "x_scatter=4" << "y_scatter=4" << "scale=1" << "mix=0";
593 tag = "frei0r.brightness";
594 params << "Brightness=0.7";
601 params << "midpoint=125";
607 m_captureDevice->setOverlayEffect(tag, params);
610 void StopmotionWidget::sequenceNameChanged(const QString& name)
612 // Get rid of frames from previous sequence
613 disconnect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
615 m_future.waitForFinished();
617 if (name.isEmpty()) {
618 button_addsequence->setEnabled(false);
620 // Check if we are editing an existing sequence
621 QString pattern = SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_filesList);
622 m_sequenceFrame = m_filesList.isEmpty() ? 0 : SlideshowClip::getFrameNumberFromPath(m_filesList.last()) + 1;
623 if (!m_filesList.isEmpty()) {
624 m_sequenceName = sequence_name->currentText();
625 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
626 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
627 button_addsequence->setEnabled(true);
630 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
631 button_addsequence->setEnabled(false);
633 capture_button->setEnabled(live_button->isChecked());
637 void StopmotionWidget::slotCaptureFrame()
639 if (m_captureDevice == NULL) return;
640 if (sequence_name->currentText().isEmpty()) {
641 QString seqName = QInputDialog::getText(this, i18n("Create New Sequence"), i18n("Enter sequence name"));
642 if (seqName.isEmpty()) {
643 m_captureAction->setChecked(false);
646 sequence_name->blockSignals(true);
647 sequence_name->setItemText(sequence_name->currentIndex(), seqName);
648 sequence_name->blockSignals(false);
650 if (m_sequenceName != sequence_name->currentText()) {
651 m_sequenceName = sequence_name->currentText();
654 //capture_button->setEnabled(false);
655 if (m_intervalTimer.isActive()) {
656 // stop interval capture
657 m_intervalTimer.stop();
660 QString currentPath = getPathForFrame(m_sequenceFrame);
661 m_captureDevice->captureFrame(currentPath);
662 KNotification::event("FrameCaptured", i18n("Frame Captured"), QPixmap(), this);
664 button_addsequence->setEnabled(true);
665 if (capture_interval->isChecked()) {
666 if (KdenliveSettings::sm_prenotify()) QTimer::singleShot((KdenliveSettings::captureinterval() - KdenliveSettings::sm_notifytime()) * 1000, this, SLOT(slotPreNotify()));
667 m_intervalTimer.start();
669 else m_captureAction->setChecked(false);
672 void StopmotionWidget::slotPreNotify()
674 if (m_captureAction->isChecked()) KNotification::event("ReadyToCapture", i18n("Going to Capture Frame"), QPixmap(), this);
678 void StopmotionWidget::slotNewThumb(const QString &path)
680 if (!KdenliveSettings::showstopmotionthumbs()) return;
681 m_filesList.append(path);
682 if (m_showOverlay->isChecked()) reloadOverlay();
683 if (!m_future.isRunning()) m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
687 void StopmotionWidget::slotPrepareThumbs()
689 if (m_filesList.isEmpty()) return;
690 QString path = m_filesList.takeFirst();
691 emit doCreateThumbs(QImage(path), SlideshowClip::getFrameNumberFromPath(path));
695 void StopmotionWidget::slotCreateThumbs(QImage img, int ix)
698 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
702 int width = height * img.width() / img.height();
703 frame_list->setIconSize(QSize(width, height));
704 QPixmap pix = QPixmap::fromImage(img).scaled(width, height);
705 QString nb = QString::number(ix);
707 QFontInfo finfo(font());
708 p.fillRect(0, 0, finfo.pixelSize() * nb.count() + 6, finfo.pixelSize() + 6, QColor(80, 80, 80, 150));
710 p.drawText(QPoint(3, finfo.pixelSize() + 3), nb);
713 QListWidgetItem* item = new QListWidgetItem(icon, QString(), frame_list);
714 item->setToolTip(getPathForFrame(ix, sequence_name->currentText()));
715 item->setData(Qt::UserRole, ix);
716 frame_list->blockSignals(true);
717 frame_list->setCurrentItem(item);
718 frame_list->blockSignals(false);
719 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
722 QString StopmotionWidget::getPathForFrame(int ix, QString seqName)
724 if (seqName.isEmpty()) seqName = m_sequenceName;
725 return m_projectFolder.path(KUrl::AddTrailingSlash) + seqName + '_' + QString::number(ix).rightJustified(4, '0', false) + ".png";
728 void StopmotionWidget::slotShowFrame(const QString& path)
732 capture_button->setEnabled(false);
735 //m_videoBox->setHidden(true);
737 m_frame_preview->setImage(img);
738 m_frame_preview->setHidden(false);
739 m_frame_preview->update();
743 void StopmotionWidget::slotShowSelectedFrame()
745 QListWidgetItem* item = frame_list->currentItem();
747 //int ix = item->data(Qt::UserRole).toInt();;
748 slotShowFrame(item->toolTip());
752 void StopmotionWidget::slotAddSequence()
754 emit addOrUpdateSequence(getPathForFrame(0));
757 void StopmotionWidget::slotPlayPreview(bool animate)
762 m_animationList.clear();
765 if (KdenliveSettings::showstopmotionthumbs()) {
766 if (KdenliveSettings::sm_framesplayback() == 0) frame_list->setCurrentRow(0);
767 else frame_list->setCurrentRow(frame_list->count() - KdenliveSettings::sm_framesplayback());
768 QTimer::singleShot(200, this, SLOT(slotAnimate()));
770 SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_animationList);
771 if (KdenliveSettings::sm_framesplayback() > 0) {
772 // only play the last x frames
773 while (m_animationList.count() > KdenliveSettings::sm_framesplayback() + 1) {
774 m_animationList.removeFirst();
782 void StopmotionWidget::slotAnimate()
785 if (KdenliveSettings::showstopmotionthumbs()) {
786 int newRow = frame_list->currentRow() + 1;
787 if (KdenliveSettings::sm_loop() || newRow < frame_list->count()) {
788 if (newRow >= frame_list->count()) {
789 if (KdenliveSettings::sm_framesplayback() == 0) newRow = 0;
791 // seek to correct frame
792 newRow = frame_list->count() - KdenliveSettings::sm_framesplayback();
795 frame_list->setCurrentRow(newRow);
796 QTimer::singleShot(100, this, SLOT(slotAnimate()));
800 if (m_animatedIndex >= m_animationList.count()) {
801 if (KdenliveSettings::sm_loop()) m_animatedIndex = 0;
802 else m_animatedIndex = -1;
804 if (m_animatedIndex > -1) {
805 slotShowFrame(m_animationList.at(m_animatedIndex));
807 QTimer::singleShot(100, this, SLOT(slotAnimate()));
813 preview_button->setChecked(false);
817 QListWidgetItem* StopmotionWidget::getFrameFromIndex(int ix)
819 QListWidgetItem* item = NULL;
821 if (ix >= frame_list->count()) {
822 pos = frame_list->count() - 1;
825 item = frame_list->item(pos);
827 int value = item->data(Qt::UserRole).toInt();
828 if (value == ix) return item;
829 else if (value < ix) {
831 while (pos < frame_list->count()) {
832 item = frame_list->item(pos);
833 value = item->data(Qt::UserRole).toInt();
834 if (value == ix) return item;
840 item = frame_list->item(pos);
841 value = item->data(Qt::UserRole).toInt();
842 if (value == ix) return item;
850 void StopmotionWidget::selectFrame(int ix)
852 frame_list->blockSignals(true);
853 QListWidgetItem* item = getFrameFromIndex(ix);
855 frame_list->setCurrentItem(item);
856 frame_list->blockSignals(false);
859 void StopmotionWidget::slotSeekFrame(bool forward)
861 int ix = frame_list->currentRow();
863 if (ix < frame_list->count() - 1) frame_list->setCurrentRow(ix + 1);
864 } else if (ix > 0) frame_list->setCurrentRow(ix - 1);
867 void StopmotionWidget::slotRemoveFrame()
869 if (frame_list->currentItem() == NULL) return;
870 QString path = frame_list->currentItem()->toolTip();
871 if (KMessageBox::questionYesNo(this, i18n("Delete frame %1 from disk?", path), i18n("Delete Frame")) != KMessageBox::Yes) return;
874 QListWidgetItem* item = frame_list->takeItem(frame_list->currentRow());
875 int ix = item->data(Qt::UserRole).toInt();
876 if (ix == m_sequenceFrame - 1) {
877 // We are removing the last frame, update counter
878 QListWidgetItem* item2 = frame_list->item(frame_list->count() - 1);
879 if (item2) m_sequenceFrame = item2->data(Qt::UserRole).toInt() + 1;
885 void StopmotionWidget::slotSwitchAnalyse(bool isOn)
887 KdenliveSettings::setAnalyse_stopmotion(isOn);
888 if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = isOn;
891 void StopmotionWidget::slotSwitchMirror(bool isOn)
893 //KdenliveSettings::setAnalyse_stopmotion(isOn);
894 if (m_captureDevice) m_captureDevice->mirror(isOn);
898 const QString StopmotionWidget::createProducer(MltVideoProfile profile, const QString &service, const QString &resource)
902 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>";
905 playlist.append("<playlist id=\"playlist0\"></playlist>");
908 playlist.append("<playlist id=\"playlist1\"><entry producer=\"producer0\" in=\"0\" out=\"99999\"/></playlist>");
910 playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"99999\">");
911 playlist.append("<track producer=\"playlist0\"/>");
912 playlist.append("<track producer=\"playlist1\"/>");
913 playlist.append("</tractor></mlt>");