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"
19 #include "../blackmagic/devices.h"
20 #include "../v4l/v4lcapture.h"
21 #include "../slideshowclip.h"
22 #include "../profilesdialog.h"
23 #include "../mltdevicecapture.h"
24 #include "../recmonitor.h"
25 #include "../monitormanager.h"
26 #include "ui_smconfig_ui.h"
27 #include "kdenlivesettings.h"
31 #include <KGlobalSettings>
32 #include <KFileDialog>
33 #include <KStandardDirs>
34 #include <KMessageBox>
35 #include <kdeversion.h>
36 #include <KNotification>
38 #include <QtConcurrentRun>
39 #include <QInputDialog>
41 #include <QVBoxLayout>
45 #include <QWheelEvent>
48 MyLabel::MyLabel(QWidget* parent) :
53 void MyLabel::setImage(QImage img)
59 void MyLabel::wheelEvent(QWheelEvent* event)
61 if (event->delta() > 0) emit seek(true);
62 else emit seek(false);
66 void MyLabel::mousePressEvent(QMouseEvent*)
72 void MyLabel::paintEvent(QPaintEvent* event)
76 QRect r(0, 0, width(), height());
78 p.fillRect(r, QColor(KdenliveSettings::window_background()));
79 double aspect_ratio = (double) m_img.width() / m_img.height();
80 int pictureHeight = height();
81 int pictureWidth = width();
82 int calculatedWidth = aspect_ratio * height();
83 if (calculatedWidth > width()) pictureHeight = width() / aspect_ratio;
85 int calculatedHeight = width() / aspect_ratio;
86 if (calculatedHeight > height()) pictureWidth = height() * aspect_ratio;
88 p.drawImage(QRect((width() - pictureWidth) / 2, (height() - pictureHeight) / 2, pictureWidth, pictureHeight), m_img, QRect(0, 0, m_img.width(), m_img.height()));
93 StopmotionMonitor::StopmotionMonitor(QWidget *parent) :
94 AbstractMonitor(parent),
99 StopmotionMonitor::~StopmotionMonitor()
103 void StopmotionMonitor::setRender(MltDeviceCapture *render)
105 m_captureDevice = render;
108 AbstractRender *StopmotionMonitor::abstractRender()
110 return m_captureDevice;
113 const QString StopmotionMonitor::name() const
115 return QString("stopmotion");
119 void StopmotionMonitor::stop()
121 if (m_captureDevice) m_captureDevice->stop();
125 void StopmotionMonitor::start()
129 StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder, QList< QAction* > actions, QWidget* parent) :
131 , Ui::Stopmotion_UI()
132 , m_projectFolder(projectFolder)
133 , m_captureDevice(NULL)
135 , m_animatedIndex(-1)
138 , m_monitor(new StopmotionMonitor(this))
140 //setAttribute(Qt::WA_DeleteOnClose);
141 //HACK: the monitor widget is hidden, it is just used to control the capturedevice from monitormanager
142 m_monitor->setHidden(true);
143 connect(m_monitor, SIGNAL(stopCapture()), this, SLOT(slotStopCapture()));
144 m_manager->appendMonitor(m_monitor);
145 QAction* analyse = new QAction(i18n("Send frames to color scopes"), this);
146 analyse->setCheckable(true);
147 analyse->setChecked(KdenliveSettings::analyse_stopmotion());
148 connect(analyse, SIGNAL(triggered(bool)), this, SLOT(slotSwitchAnalyse(bool)));
150 QAction* mirror = new QAction(i18n("Mirror display"), this);
151 mirror->setCheckable(true);
152 //mirror->setChecked(KdenliveSettings::analyse_stopmotion());
153 connect(mirror, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMirror(bool)));
157 setWindowTitle(i18n("Stop Motion Capture"));
158 setFont(KGlobalSettings::toolBarFont());
160 live_button->setIcon(KIcon("camera-photo"));
162 m_captureAction = actions.at(0);
163 connect(m_captureAction, SIGNAL(triggered()), this, SLOT(slotCaptureFrame()));
164 m_captureAction->setCheckable(true);
165 m_captureAction->setChecked(false);
166 capture_button->setDefaultAction(m_captureAction);
168 connect(actions.at(1), SIGNAL(triggered()), this, SLOT(slotSwitchLive()));
170 QAction *intervalCapture = new QAction(i18n("Interval capture"), this);
171 intervalCapture->setIcon(KIcon("chronometer"));
172 intervalCapture->setCheckable(true);
173 intervalCapture->setChecked(false);
174 capture_interval->setDefaultAction(intervalCapture);
176 preview_button->setIcon(KIcon("media-playback-start"));
177 capture_button->setEnabled(false);
181 QMenu* confMenu = new QMenu;
182 m_showOverlay = actions.at(2);
183 connect(m_showOverlay, SIGNAL(triggered(bool)), this, SLOT(slotShowOverlay(bool)));
184 overlay_button->setDefaultAction(m_showOverlay);
185 //confMenu->addAction(m_showOverlay);
187 m_effectIndex = KdenliveSettings::stopmotioneffect();
188 QMenu* effectsMenu = new QMenu(i18n("Overlay effect"));
189 QActionGroup* effectGroup = new QActionGroup(this);
190 QAction* noEffect = new QAction(i18n("No Effect"), effectGroup);
191 noEffect->setData(0);
192 QAction* contrastEffect = new QAction(i18n("Contrast"), effectGroup);
193 contrastEffect->setData(1);
194 QAction* edgeEffect = new QAction(i18n("Edge detect"), effectGroup);
195 edgeEffect->setData(2);
196 QAction* brightEffect = new QAction(i18n("Brighten"), effectGroup);
197 brightEffect->setData(3);
198 QAction* invertEffect = new QAction(i18n("Invert"), effectGroup);
199 invertEffect->setData(4);
200 QAction* thresEffect = new QAction(i18n("Threshold"), effectGroup);
201 thresEffect->setData(5);
203 effectsMenu->addAction(noEffect);
204 effectsMenu->addAction(contrastEffect);
205 effectsMenu->addAction(edgeEffect);
206 effectsMenu->addAction(brightEffect);
207 effectsMenu->addAction(invertEffect);
208 effectsMenu->addAction(thresEffect);
209 QList <QAction*> list = effectsMenu->actions();
210 for (int i = 0; i < list.count(); i++) {
211 list.at(i)->setCheckable(true);
212 if (list.at(i)->data().toInt() == m_effectIndex) {
213 list.at(i)->setChecked(true);
216 connect(effectsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotUpdateOverlayEffect(QAction*)));
217 confMenu->addMenu(effectsMenu);
219 QAction* showThumbs = new QAction(KIcon("image-x-generic"), i18n("Show sequence thumbnails"), this);
220 showThumbs->setCheckable(true);
221 showThumbs->setChecked(KdenliveSettings::showstopmotionthumbs());
222 connect(showThumbs, SIGNAL(triggered(bool)), this, SLOT(slotShowThumbs(bool)));
224 QAction* removeCurrent = new QAction(KIcon("edit-delete"), i18n("Delete current frame"), this);
225 removeCurrent->setShortcut(Qt::Key_Delete);
226 connect(removeCurrent, SIGNAL(triggered()), this, SLOT(slotRemoveFrame()));
228 QAction* conf = new QAction(KIcon("configure"), i18n("Configure"), this);
229 connect(conf, SIGNAL(triggered()), this, SLOT(slotConfigure()));
231 confMenu->addAction(showThumbs);
232 confMenu->addAction(removeCurrent);
233 confMenu->addAction(analyse);
234 confMenu->addAction(mirror);
235 confMenu->addAction(conf);
236 config_button->setIcon(KIcon("configure"));
237 config_button->setMenu(confMenu);
239 connect(sequence_name, SIGNAL(textChanged(const QString&)), this, SLOT(sequenceNameChanged(const QString&)));
240 connect(sequence_name, SIGNAL(currentIndexChanged(int)), live_button, SLOT(setFocus()));
242 // Video widget holder
243 QVBoxLayout *layout = new QVBoxLayout;
244 layout->setContentsMargins(0, 0, 0, 0);
245 layout->setSpacing(0);
246 m_videoBox = new VideoPreviewContainer();
247 m_videoBox->setContentsMargins(0, 0, 0, 0);
248 m_videoBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
249 //m_videoBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
250 m_videoBox->setLineWidth(4);
251 layout->addWidget(m_videoBox);
254 if (BMInterface::getBlackMagicDeviceList(capture_device)) {
255 // Found a BlackMagic device
257 if (QFile::exists(KdenliveSettings::video4vdevice())) {
258 #if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD)
259 // Video 4 Linux device detection
260 for (int i = 0; i < 10; i++) {
261 QString path = "/dev/video" + QString::number(i);
262 if (QFile::exists(path)) {
263 QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path);
264 if (!deviceInfo.isEmpty()) {
265 capture_device->addItem(deviceInfo.at(0), "v4l");
266 capture_device->setItemData(capture_device->count() - 1, path, Qt::UserRole + 1);
267 capture_device->setItemData(capture_device->count() - 1, deviceInfo.at(1), Qt::UserRole + 2);
268 if (path == KdenliveSettings::video4vdevice()) capture_device->setCurrentIndex(capture_device->count() - 1);
275 connect(capture_device, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDeviceHandler()));
277 connect(m_bmCapture, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString)));
278 connect(m_bmCapture, SIGNAL(gotFrame(QImage)), this, SIGNAL(gotFrame(QImage)));
279 } else live_button->setEnabled(false);*/
281 m_frame_preview = new MyLabel(this);
282 connect(m_frame_preview, SIGNAL(seek(bool)), this, SLOT(slotSeekFrame(bool)));
283 connect(m_frame_preview, SIGNAL(switchToLive()), this, SLOT(slotSwitchLive()));
284 layout->addWidget(m_frame_preview);
285 m_frame_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
286 video_preview->setLayout(layout);
288 //kDebug()<<video_preview->winId();
291 // Create MLT producer data
292 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
293 // Capture using a video4linux device
294 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
298 profilePath = KdenliveSettings::current_profile();
301 m_captureDevice = new MltDeviceCapture(profilePath, m_videoBox, this);
302 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
303 m_monitor->setRender(m_captureDevice);
304 connect(m_captureDevice, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString)));
306 live_button->setChecked(false);
307 button_addsequence->setEnabled(false);
308 connect(live_button, SIGNAL(toggled(bool)), this, SLOT(slotLive(bool)));
309 connect(button_addsequence, SIGNAL(clicked(bool)), this, SLOT(slotAddSequence()));
310 connect(preview_button, SIGNAL(clicked(bool)), this, SLOT(slotPlayPreview(bool)));
311 connect(frame_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotShowSelectedFrame()));
312 connect(frame_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slotShowSelectedFrame()));
313 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
315 frame_list->addAction(removeCurrent);
316 frame_list->setContextMenuPolicy(Qt::ActionsContextMenu);
317 frame_list->setHidden(!KdenliveSettings::showstopmotionthumbs());
318 parseExistingSequences();
319 QTimer::singleShot(500, this, SLOT(slotLive()));
320 connect(&m_intervalTimer, SIGNAL(timeout()), this, SLOT(slotCaptureFrame()));
321 m_intervalTimer.setSingleShot(true);
322 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
325 StopmotionWidget::~StopmotionWidget()
328 m_bmCapture->stopPreview();*/
329 if (m_captureDevice) {
330 m_captureDevice->stop();
331 delete m_captureDevice;
332 m_captureDevice = NULL;
338 void StopmotionWidget::slotUpdateOverlayEffect(QAction* act)
340 if (act) m_effectIndex = act->data().toInt();
341 KdenliveSettings::setStopmotioneffect(m_effectIndex);
345 void StopmotionWidget::closeEvent(QCloseEvent* e)
348 QDialog::closeEvent(e);
351 void StopmotionWidget::slotConfigure()
356 d.setWindowTitle(i18n("Configure Stop Motion"));
357 ui.sm_interval->setValue(KdenliveSettings::captureinterval());
358 ui.sm_interval->setSuffix(ki18np(" second", " seconds"));
359 ui.sm_notifytime->setSuffix(ki18np(" second", " seconds"));
360 ui.sm_notifytime->setValue(KdenliveSettings::sm_notifytime());
361 connect(ui.sm_prenotify, SIGNAL(toggled(bool)), ui.sm_notifytime, SLOT(setEnabled(bool)));
362 ui.sm_prenotify->setChecked(KdenliveSettings::sm_prenotify());
363 ui.sm_loop->setChecked(KdenliveSettings::sm_loop());
364 ui.sm_framesplayback->setValue(KdenliveSettings::sm_framesplayback());
366 if (d.exec() == QDialog::Accepted) {
367 KdenliveSettings::setSm_loop(ui.sm_loop->isChecked());
368 KdenliveSettings::setCaptureinterval(ui.sm_interval->value());
369 KdenliveSettings::setSm_framesplayback(ui.sm_framesplayback->value());
370 KdenliveSettings::setSm_notifytime(ui.sm_notifytime->value());
371 KdenliveSettings::setSm_prenotify(ui.sm_prenotify->isChecked());
372 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
376 void StopmotionWidget::slotShowThumbs(bool show)
378 KdenliveSettings::setShowstopmotionthumbs(show);
381 sequenceNameChanged(sequence_name->currentText());
386 frame_list->setHidden(!show);
390 void StopmotionWidget::slotUpdateDeviceHandler()
393 delete m_captureDevice;
394 m_captureDevice = NULL;
395 /*QString data = capture_device->itemData(capture_device->currentIndex()).toString();
400 m_layout->removeWidget(m_frame_preview);
402 #if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD)
403 m_bmCapture = new V4lCaptureHandler(m_layout);
404 m_bmCapture->setDevice(capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString(), capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 2).toString());
407 m_bmCapture = new BmdCaptureHandler(m_layout);
408 if (m_bmCapture) connect(m_bmCapture, SIGNAL(gotMessage(const QString&)), this, SLOT(slotGotHDMIMessage(const QString&)));
410 live_button->setEnabled(m_bmCapture != NULL);
411 m_layout->addWidget(m_frame_preview);*/
414 void StopmotionWidget::slotGotHDMIMessage(const QString& message)
416 log_box->insertItem(0, message);
419 void StopmotionWidget::parseExistingSequences()
421 sequence_name->clear();
422 sequence_name->addItem(QString());
423 QDir dir(m_projectFolder.path());
425 filters << "*_0000.png";
426 //dir.setNameFilters(filters);
427 QStringList sequences = dir.entryList(filters, QDir::Files, QDir::Name);
428 //kDebug()<<"PF: "<<<<", sm: "<<sequences;
429 foreach(QString sequencename, sequences) {
430 sequence_name->addItem(sequencename.section("_", 0, -2));
434 void StopmotionWidget::slotSwitchLive()
436 setUpdatesEnabled(false);
437 slotLive(!live_button->isChecked());
438 /*if (m_frame_preview->isHidden()) {
439 //if (m_bmCapture) m_bmCapture->hidePreview(true);
440 m_videoBox->setHidden(true);
441 m_frame_preview->setHidden(false);
443 m_frame_preview->setHidden(true);
444 //if (m_bmCapture) m_bmCapture->hidePreview(false);
445 m_videoBox->setHidden(false);
446 capture_button->setEnabled(true);
448 setUpdatesEnabled(true);
451 void StopmotionWidget::slotStopCapture()
456 void StopmotionWidget::slotLive(bool isOn)
458 live_button->blockSignals(true);
459 capture_button->setEnabled(false);
461 m_frame_preview->setHidden(true);
462 m_videoBox->setHidden(false);
464 MltVideoProfile profile;
468 // Create MLT producer data
469 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
470 // Capture using a video4linux device
471 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
472 profile = ProfilesDialog::getVideoProfile(profilePath);
473 service = "avformat-novalidate";
474 QString devicePath = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
475 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);
479 profilePath = KdenliveSettings::current_profile();
480 profile = ProfilesDialog::getVideoProfile(profilePath);
481 service = "decklink";
482 resource = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
485 if (m_captureDevice == NULL) {
486 m_captureDevice = new MltDeviceCapture(profilePath, m_videoBox, this);
487 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
488 m_monitor->setRender(m_captureDevice);
489 connect(m_captureDevice, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString)));
492 m_manager->activateMonitor("stopmotion");
493 QString producer = createProducer(profile, service, resource);
494 if (m_captureDevice->slotStartPreview(producer, true)) {
495 if (m_showOverlay->isChecked()) {
499 capture_button->setEnabled(true);
500 live_button->setChecked(true);
501 log_box->insertItem(-1, i18n("Playing %1x%2 (%3 fps)", profile.width, profile.height, QString::number((double)profile.frame_rate_num/profile.frame_rate_den).rightJustified(2, '0')));
502 log_box->setCurrentIndex(0);
505 kDebug()<<"// problem starting stopmo";
506 log_box->insertItem(-1, i18n("Failed to start device"));
507 log_box->setCurrentIndex(0);
511 m_frame_preview->setHidden(false);
512 live_button->setChecked(false);
513 if (m_captureDevice) {
514 m_captureDevice->stop();
515 m_videoBox->setHidden(true);
516 log_box->insertItem(-1, i18n("Stopped"));
517 log_box->setCurrentIndex(0);
518 //delete m_captureDevice;
519 //m_captureDevice = NULL;
524 if (isOn && m_bmCapture) {
525 //m_frame_preview->setImage(QImage());
526 m_frame_preview->setHidden(true);
527 m_bmCapture->startPreview(KdenliveSettings::hdmi_capturedevice(), KdenliveSettings::hdmi_capturemode(), false);
528 capture_button->setEnabled(true);
529 live_button->setChecked(true);
531 if (m_bmCapture) m_bmCapture->stopPreview();
532 m_frame_preview->setHidden(false);
533 capture_button->setEnabled(false);
534 live_button->setChecked(false);
536 live_button->blockSignals(false);
539 void StopmotionWidget::slotShowOverlay(bool isOn)
542 // Overlay last frame of the sequence
548 m_captureDevice->setOverlay(QString());
552 void StopmotionWidget::reloadOverlay()
554 QString path = getPathForFrame(m_sequenceFrame - 1);
555 if (!QFile::exists(path)) {
556 log_box->insertItem(-1, i18n("No previous frame found"));
557 log_box->setCurrentIndex(0);
560 m_captureDevice->setOverlay(path);
563 void StopmotionWidget::slotUpdateOverlay()
565 if (m_captureDevice == NULL) return;
570 switch (m_effectIndex) {
572 tag = "frei0r.contrast0r";
573 params << "Contrast=1.2";
577 params << "x_scatter=4" << "y_scatter=4" << "scale=1" << "mix=0";
580 tag = "frei0r.brightness";
581 params << "Brightness=0.7";
588 params << "midpoint=125";
594 m_captureDevice->setOverlayEffect(tag, params);
597 void StopmotionWidget::sequenceNameChanged(const QString& name)
599 // Get rid of frames from previous sequence
600 disconnect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
602 m_future.waitForFinished();
604 if (name.isEmpty()) {
605 button_addsequence->setEnabled(false);
607 // Check if we are editing an existing sequence
608 QString pattern = SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_filesList);
609 m_sequenceFrame = m_filesList.isEmpty() ? 0 : SlideshowClip::getFrameNumberFromPath(m_filesList.last()) + 1;
610 if (!m_filesList.isEmpty()) {
611 m_sequenceName = sequence_name->currentText();
612 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
613 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
614 button_addsequence->setEnabled(true);
617 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
618 button_addsequence->setEnabled(false);
620 capture_button->setEnabled(live_button->isChecked());
624 void StopmotionWidget::slotCaptureFrame()
626 if (m_captureDevice == NULL) return;
627 if (sequence_name->currentText().isEmpty()) {
628 QString seqName = QInputDialog::getText(this, i18n("Create New Sequence"), i18n("Enter sequence name"));
629 if (seqName.isEmpty()) {
630 m_captureAction->setChecked(false);
633 sequence_name->blockSignals(true);
634 sequence_name->setItemText(sequence_name->currentIndex(), seqName);
635 sequence_name->blockSignals(false);
637 if (m_sequenceName != sequence_name->currentText()) {
638 m_sequenceName = sequence_name->currentText();
641 //capture_button->setEnabled(false);
642 if (m_intervalTimer.isActive()) {
643 // stop interval capture
644 m_intervalTimer.stop();
647 QString currentPath = getPathForFrame(m_sequenceFrame);
648 m_captureDevice->captureFrame(currentPath);
649 KNotification::event("FrameCaptured", i18n("Frame Captured"), QPixmap(), this);
651 button_addsequence->setEnabled(true);
652 if (capture_interval->isChecked()) {
653 if (KdenliveSettings::sm_prenotify()) QTimer::singleShot((KdenliveSettings::captureinterval() - KdenliveSettings::sm_notifytime()) * 1000, this, SLOT(slotPreNotify()));
654 m_intervalTimer.start();
656 else m_captureAction->setChecked(false);
659 void StopmotionWidget::slotPreNotify()
661 if (m_captureAction->isChecked()) KNotification::event("ReadyToCapture", i18n("Going to Capture Frame"), QPixmap(), this);
665 void StopmotionWidget::slotNewThumb(const QString path)
667 if (!KdenliveSettings::showstopmotionthumbs()) return;
668 m_filesList.append(path);
669 if (m_showOverlay->isChecked()) reloadOverlay();
670 if (!m_future.isRunning()) m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
674 void StopmotionWidget::slotPrepareThumbs()
676 if (m_filesList.isEmpty()) return;
677 QString path = m_filesList.takeFirst();
678 emit doCreateThumbs(QImage(path), SlideshowClip::getFrameNumberFromPath(path));
682 void StopmotionWidget::slotCreateThumbs(QImage img, int ix)
685 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
689 int width = height * img.width() / img.height();
690 frame_list->setIconSize(QSize(width, height));
691 QPixmap pix = QPixmap::fromImage(img).scaled(width, height);
692 QString nb = QString::number(ix);
694 QFontInfo finfo(font());
695 p.fillRect(0, 0, finfo.pixelSize() * nb.count() + 6, finfo.pixelSize() + 6, QColor(80, 80, 80, 150));
697 p.drawText(QPoint(3, finfo.pixelSize() + 3), nb);
700 QListWidgetItem* item = new QListWidgetItem(icon, QString(), frame_list);
701 item->setToolTip(getPathForFrame(ix, sequence_name->currentText()));
702 item->setData(Qt::UserRole, ix);
703 frame_list->blockSignals(true);
704 frame_list->setCurrentItem(item);
705 frame_list->blockSignals(false);
706 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
709 QString StopmotionWidget::getPathForFrame(int ix, QString seqName)
711 if (seqName.isEmpty()) seqName = m_sequenceName;
712 return m_projectFolder.path(KUrl::AddTrailingSlash) + seqName + "_" + QString::number(ix).rightJustified(4, '0', false) + ".png";
715 void StopmotionWidget::slotShowFrame(const QString& path)
719 capture_button->setEnabled(false);
722 //m_videoBox->setHidden(true);
724 m_frame_preview->setImage(img);
725 m_frame_preview->setHidden(false);
726 m_frame_preview->update();
730 void StopmotionWidget::slotShowSelectedFrame()
732 QListWidgetItem* item = frame_list->currentItem();
734 //int ix = item->data(Qt::UserRole).toInt();;
735 slotShowFrame(item->toolTip());
739 void StopmotionWidget::slotAddSequence()
741 emit addOrUpdateSequence(getPathForFrame(0));
744 void StopmotionWidget::slotPlayPreview(bool animate)
749 m_animationList.clear();
752 if (KdenliveSettings::showstopmotionthumbs()) {
753 if (KdenliveSettings::sm_framesplayback() == 0) frame_list->setCurrentRow(0);
754 else frame_list->setCurrentRow(frame_list->count() - KdenliveSettings::sm_framesplayback());
755 QTimer::singleShot(200, this, SLOT(slotAnimate()));
757 SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_animationList);
758 if (KdenliveSettings::sm_framesplayback() > 0) {
759 // only play the last x frames
760 while (m_animationList.count() > KdenliveSettings::sm_framesplayback() + 1) {
761 m_animationList.removeFirst();
769 void StopmotionWidget::slotAnimate()
772 if (KdenliveSettings::showstopmotionthumbs()) {
773 int newRow = frame_list->currentRow() + 1;
774 if (KdenliveSettings::sm_loop() || newRow < frame_list->count()) {
775 if (newRow >= frame_list->count()) {
776 if (KdenliveSettings::sm_framesplayback() == 0) newRow = 0;
778 // seek to correct frame
779 newRow = frame_list->count() - KdenliveSettings::sm_framesplayback();
782 frame_list->setCurrentRow(newRow);
783 QTimer::singleShot(100, this, SLOT(slotAnimate()));
787 if (m_animatedIndex >= m_animationList.count()) {
788 if (KdenliveSettings::sm_loop()) m_animatedIndex = 0;
789 else m_animatedIndex = -1;
791 if (m_animatedIndex > -1) {
792 slotShowFrame(m_animationList.at(m_animatedIndex));
794 QTimer::singleShot(100, this, SLOT(slotAnimate()));
800 preview_button->setChecked(false);
804 QListWidgetItem* StopmotionWidget::getFrameFromIndex(int ix)
806 QListWidgetItem* item = NULL;
808 if (ix >= frame_list->count()) {
809 pos = frame_list->count() - 1;
812 item = frame_list->item(pos);
814 int value = item->data(Qt::UserRole).toInt();
815 if (value == ix) return item;
816 else if (value < ix) {
818 while (pos < frame_list->count()) {
819 item = frame_list->item(pos);
820 value = item->data(Qt::UserRole).toInt();
821 if (value == ix) return item;
827 item = frame_list->item(pos);
828 value = item->data(Qt::UserRole).toInt();
829 if (value == ix) return item;
837 void StopmotionWidget::selectFrame(int ix)
839 frame_list->blockSignals(true);
840 QListWidgetItem* item = getFrameFromIndex(ix);
842 frame_list->setCurrentItem(item);
843 frame_list->blockSignals(false);
846 void StopmotionWidget::slotSeekFrame(bool forward)
848 int ix = frame_list->currentRow();
850 if (ix < frame_list->count() - 1) frame_list->setCurrentRow(ix + 1);
851 } else if (ix > 0) frame_list->setCurrentRow(ix - 1);
854 void StopmotionWidget::slotRemoveFrame()
856 if (frame_list->currentItem() == NULL) return;
857 QString path = frame_list->currentItem()->toolTip();
858 if (KMessageBox::questionYesNo(this, i18n("Delete frame %1 from disk?", path), i18n("Delete Frame")) != KMessageBox::Yes) return;
861 QListWidgetItem* item = frame_list->takeItem(frame_list->currentRow());
862 int ix = item->data(Qt::UserRole).toInt();
863 if (ix == m_sequenceFrame - 1) {
864 // We are removing the last frame, update counter
865 QListWidgetItem* item2 = frame_list->item(frame_list->count() - 1);
866 if (item2) m_sequenceFrame = item2->data(Qt::UserRole).toInt() + 1;
872 void StopmotionWidget::slotSwitchAnalyse(bool isOn)
874 KdenliveSettings::setAnalyse_stopmotion(isOn);
875 if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = isOn;
878 void StopmotionWidget::slotSwitchMirror(bool isOn)
880 //KdenliveSettings::setAnalyse_stopmotion(isOn);
881 if (m_captureDevice) m_captureDevice->mirror(isOn);
884 const QString StopmotionWidget::createProducer(MltVideoProfile profile, const QString service, const QString resource)
887 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>";
890 playlist.append("<playlist id=\"playlist0\"></playlist>");
893 playlist.append("<playlist id=\"playlist1\"><entry producer=\"producer0\" in=\"0\" out=\"99999\"/></playlist>");
895 playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"99999\">");
896 playlist.append("<track producer=\"playlist0\"/>");
897 playlist.append("<track producer=\"playlist1\"/>");
898 playlist.append("</tractor></mlt>");