From 024a8b00915dadce2a470f3802101542528513f0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Thu, 13 Mar 2008 22:46:24 +0000 Subject: [PATCH] =?utf8?q?Looks=20like=20I=C2=A0finally=20got=20the=20prof?= =?utf8?q?ile=20switching=20work!?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit svn path=/branches/KDE4/; revision=2053 --- src/kdenlivedoc.cpp | 34 ++++++++++++++++++++- src/kdenlivedoc.h | 5 ++++ src/mainwindow.cpp | 55 +++++++++++++++++++++++----------- src/mainwindow.h | 2 +- src/monitor.cpp | 8 +++-- src/monitor.h | 3 +- src/monitormanager.cpp | 17 ++++++++++- src/monitormanager.h | 1 + src/profilesdialog.cpp | 32 +++++++++++--------- src/renderer.cpp | 68 ++++++++++++++++++++++++++++++------------ src/renderer.h | 2 +- 11 files changed, 169 insertions(+), 58 deletions(-) diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index fa83913f..e01e86f1 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -27,8 +27,10 @@ #include "kdenlivedoc.h" #include "docclipbase.h" +#include "profilesdialog.h" +#include "kdenlivesettings.h" -KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, QUndoGroup *undoGroup, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)) { +KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, QUndoGroup *undoGroup, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)), m_modified(false) { m_clipManager = new ClipManager(this); if (!url.isEmpty()) { QString tmpFile; @@ -36,6 +38,12 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, QUndoGroup *u QFile file(tmpFile); m_document.setContent(&file, false); file.close(); + QDomNode infoXmlNode = m_document.elementsByTagName("kdenlive").at(0); + if (!infoXmlNode.isNull()) { + QDomElement infoXml = infoXmlNode.toElement(); + QString profilePath = infoXml.attribute("profile"); + if (!profilePath.isEmpty()) setProfilePath(profilePath); + } KIO::NetAccess::removeTempFile(tmpFile); } else { KMessageBox::error(parent, KIO::NetAccess::lastErrorString()); @@ -110,6 +118,15 @@ KdenliveDoc::~KdenliveDoc() { delete m_clipManager; } +QDomElement KdenliveDoc::documentInfoXml() { + QDomDocument doc; + QDomElement addedXml = doc.createElement("kdenlive"); + addedXml.setAttribute("version", "0.7"); + addedXml.setAttribute("profile", profilePath()); + return addedXml; +} + + ClipManager *KdenliveDoc::clipManager() { return m_clipManager; } @@ -124,6 +141,16 @@ QString KdenliveDoc::profilePath() const { return m_profile.path; } +void KdenliveDoc::setProfilePath(QString path) { + KdenliveSettings::setCurrent_profile(path); + m_profile = ProfilesDialog::getVideoProfile(path); + m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den; + m_width = m_profile.width; + m_height = m_profile.height; + if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true); + else m_timecode.setFormat((int) m_fps); +} + void KdenliveDoc::setThumbsProgress(KUrl url, int progress) { emit thumbsProgress(url, progress); } @@ -230,6 +257,11 @@ KUrl KdenliveDoc::url() const { return m_url; } +void KdenliveDoc::setUrl(KUrl url) { + m_url = url; + m_modified = false; +} + QString KdenliveDoc::description() const { if (m_url.isEmpty()) return i18n("Untitled") + " / " + m_profile.description; diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index 738e3898..6d09167d 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -71,6 +71,9 @@ Q_OBJECT public: QString description() const; /** Returns the document format: PAL or NTSC */ QString getDocumentStandard(); + void setUrl(KUrl url); + QDomElement documentInfoXml(); + void setProfilePath(QString path); private: KUrl m_url; @@ -86,6 +89,8 @@ private: ClipManager *m_clipManager; MltVideoProfile m_profile; QString m_scenelist; + /** tells whether current doc has been changed since last save event */ + bool m_modified; public slots: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8d443e15..4faeff4f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include @@ -64,7 +64,7 @@ MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent), - fileName(QString()), m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL) { + m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL) { parseProfiles(); m_commandStack = new QUndoGroup; @@ -202,6 +202,10 @@ bool MainWindow::queryClose() { } } +void MainWindow::slotFullScreen() { + KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked()); +} + void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) { if (!m_activeDocument) return; if (effect.isNull()) { @@ -293,7 +297,9 @@ void MainWindow::setupActions() { KStandardAction::redo(this, SLOT(redo()), actionCollection()); - connect(actionCollection(), SIGNAL(actionHighlighted(QAction*)), + KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection()); + + connect(actionCollection(), SIGNAL(actionHovered(QAction*)), this, SLOT(slotDisplayActionMessage(QAction*))); //connect(actionCollection(), SIGNAL( clearStatusText() ), //statusBar(), SLOT( clear() ) ); @@ -365,27 +371,27 @@ void MainWindow::closeDocument(QWidget *w) { } void MainWindow::saveFileAs(const QString &outputFileName) { - KSaveFile file(outputFileName); - file.open(); - - QByteArray outputByteArray; - //outputByteArray.append(textArea->toPlainText()); - file.write(outputByteArray); - file.finalize(); - file.close(); - - fileName = outputFileName; + m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml()); + m_activeDocument->setUrl(KUrl(outputFileName)); + setCaption(m_activeDocument->description()); + m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description()); + m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path()); } void MainWindow::saveFileAs() { - saveFileAs(KFileDialog::getSaveFileName()); + QString outputFile = KFileDialog::getSaveFileName(); + if (QFile::exists(outputFile)) { + if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return; + } + saveFileAs(outputFile); } void MainWindow::saveFile() { - if (!fileName.isEmpty()) { - saveFileAs(fileName); - } else { + if (!m_activeDocument) return; + if (m_activeDocument->url().isEmpty()) { saveFileAs(); + } else { + saveFileAs(m_activeDocument->url().path()); } } @@ -468,7 +474,19 @@ void MainWindow::slotEditProfiles() { void MainWindow::slotEditProjectSettings() { ProjectSettings *w = new ProjectSettings; - w->exec(); + if (w->exec() == QDialog::Accepted) { + QString profile = w->selectedProfile(); + m_activeDocument->setProfilePath(profile); + m_monitorManager->resetProfiles(profile); + setCaption(m_activeDocument->description()); + KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath()); + if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard()); + m_monitorManager->setTimecode(m_activeDocument->timecode()); + m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description()); + + // We need to desactivate & reactivate monitors to get a refresh + m_monitorManager->switchMonitors(); + } delete w; } @@ -565,6 +583,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha m_activeTimeline = trackView; + KdenliveSettings::setCurrent_profile(doc->profilePath()); if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard()); m_monitorManager->setTimecode(doc->timecode()); doc->setRenderer(m_projectMonitor->render); diff --git a/src/mainwindow.h b/src/mainwindow.h index 95dfb2c9..3c2657f9 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -62,7 +62,6 @@ private: QProgressBar *statusProgressBar; QLabel* statusLabel; void setupActions(); - QString fileName; KdenliveDoc *m_activeDocument; TrackView *m_activeTimeline; MonitorManager *m_monitorManager; @@ -135,6 +134,7 @@ private slots: void slotSwitchAudioThumbs(); void slotRenderProject(); void slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter); + void slotFullScreen(); }; #endif diff --git a/src/monitor.cpp b/src/monitor.cpp index 2c9dc449..92982dfe 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -67,6 +67,10 @@ Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent) kDebug() << "/////// BUILDING MONITOR, ID: " << ui.video_frame->winId(); } +QString Monitor::name() const { + return m_name; +} + // virtual void Monitor::mousePressEvent(QMouseEvent * event) { slotPlay(); @@ -223,9 +227,9 @@ void Monitor::resetProfile(QString prof) { render->resetProfile(prof); } -void Monitor::saveSceneList(QString path) { +void Monitor::saveSceneList(QString path, QDomElement e) { if (render == NULL) return; - render->saveSceneList(path); + render->saveSceneList(path, e); } void Monitor::paintEvent(QPaintEvent * event) { diff --git a/src/monitor.h b/src/monitor.h index deaffa90..62977381 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -37,6 +37,7 @@ public: Monitor(QString name, MonitorManager *manager, QWidget *parent = 0); Render *render; void resetProfile(QString prof); + QString name() const; virtual void resizeEvent(QResizeEvent * event); protected: @@ -74,7 +75,7 @@ public slots: void start(); void activateMonitor(); void slotPlay(); - void saveSceneList(QString path); + void saveSceneList(QString path, QDomElement e = QDomElement()); signals: void renderPosition(int); diff --git a/src/monitormanager.cpp b/src/monitormanager.cpp index 3cad95b4..1765fa86 100644 --- a/src/monitormanager.cpp +++ b/src/monitormanager.cpp @@ -59,13 +59,28 @@ void MonitorManager::activateMonitor(QString name) { m_activeMonitor = name; } +void MonitorManager::switchMonitors() { + if (m_activeMonitor == "clip") { + m_clipMonitor->stop(); + m_projectMonitor->start(); + m_projectMonitor->raise(); + m_activeMonitor = m_projectMonitor->name(); + emit raiseClipMonitor(false); + } else { + m_projectMonitor->stop(); + m_clipMonitor->start(); + m_activeMonitor = m_clipMonitor->name(); + emit raiseClipMonitor(true); + } +} + void MonitorManager::slotPlay() { if (m_activeMonitor == "clip") m_clipMonitor->slotPlay(); else m_projectMonitor->slotPlay(); } void MonitorManager::resetProfiles(QString prof) { - //m_clipMonitor->resetProfile(prof); + m_clipMonitor->resetProfile(prof); m_projectMonitor->resetProfile(prof); } diff --git a/src/monitormanager.h b/src/monitormanager.h index 03eeaec6..c2160b1a 100644 --- a/src/monitormanager.h +++ b/src/monitormanager.h @@ -35,6 +35,7 @@ public: Timecode timecode(); void setTimecode(Timecode tc); void resetProfiles(QString prof); + void switchMonitors(); public slots: void activateMonitor(QString name = QString::null); diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 6bec5c5b..e85b0e45 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -57,26 +57,30 @@ MltVideoProfile ProfilesDialog::getVideoProfile(QString name) { QStringList profilesFilter; profilesFilter << "*"; QString path; + bool isCustom = false; + if (name.contains('/')) isCustom = true; - // List the Mlt profiles - profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); - if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + "/" + name; - - if (path.isEmpty()) { + if (!isCustom) { + // List the Mlt profiles + profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); + if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + "/" + name; + } + if (isCustom || path.isEmpty()) { // List custom profiles - QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); - for (int i = 0; i < customProfiles.size(); ++i) { - profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); - if (profilesFiles.contains(name)) { - path = customProfiles.at(i) + "/" + name; - break; - } - } + path = name; + /* QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); + for (int i = 0; i < customProfiles.size(); ++i) { + profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); + if (profilesFiles.contains(name)) { + path = customProfiles.at(i) + "/" + name; + break; + } + }*/ } if (path.isEmpty()) return result; KConfig confFile(path); - result.path = path; + result.path = name; result.description = confFile.entryMap().value("description"); result.frame_rate_num = confFile.entryMap().value("frame_rate_num").toInt(); result.frame_rate_den = confFile.entryMap().value("frame_rate_den").toInt(); diff --git a/src/renderer.cpp b/src/renderer.cpp index d86af5a2..c7b0c109 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -25,7 +25,7 @@ // ffmpeg Header files extern "C" { -#include +#include } #include #include @@ -76,7 +76,7 @@ Render::Render(const QString & rendererName, int winid, int extid, QWidget *pare m_externalwinid = extid; m_winid = winid; m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); - Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", ""); + Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", ""); m_mltProducer = producer; m_mltConsumer->connect(*m_mltProducer); m_mltProducer->set_speed(0.0); @@ -120,16 +120,35 @@ int Render::resetProfile(QString profile) { if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); m_mltConsumer->set("refresh", 0); m_mltConsumer->purge(); - //TODO: we should also rebuild filters and delete existing m_mltProfile + delete m_mltConsumer; + m_mltConsumer = NULL; + QString scene = sceneList(); + if (m_mltProducer) delete m_mltProducer; + m_mltProducer = NULL; + if (m_mltProfile) delete m_mltProfile; + m_mltProfile = NULL; - //delete m_mltProfile; m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data()); - kDebug() << " ++++++++++ RESET CONSUMER WITH PROFILE: " << m_mltProfile->width(); + m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer; + m_mltConsumer->set("resize", 1); + m_mltConsumer->set("window_id", m_winid); + m_mltConsumer->set("terminate_on_pause", 1); + m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); + + Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", (char *) scene.toUtf8().data()); + m_mltProducer = producer; + m_mltConsumer->connect(*m_mltProducer); + m_mltProducer->set_speed(0.0); + + //delete m_mltProfile; // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer()); //mlt_profile prof = m_mltProfile->get_profile(); //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL); //mlt_properties_set(properties, "profile", "hdv_1080_50i"); - m_mltConsumer->set("profile", (char *) profile.toUtf8().data()); + //m_mltConsumer->set("profile", (char *) profile.toUtf8().data()); + //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data()); + kDebug() << " ++++++++++ RESET CONSUMER WITH PROFILE: " << profile << ", WIDTH: " << m_mltProfile->width(); + //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties ); //refresh(); return 1; @@ -489,12 +508,7 @@ void Render::setSceneList(QString playlist, int position) { if (m_mltConsumer) { m_mltConsumer->set("refresh", 0); - if (!m_mltConsumer->is_stopped()) { - //emitConsumerStopped(); - m_mltConsumer->stop(); - } - } - + } else return; if (m_mltProducer) { m_mltProducer->set_speed(0.0); //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo); @@ -536,7 +550,7 @@ void Render::setSceneList(QString playlist, int position) { m_fps = m_mltProducer->get_fps(); emit durationChanged(m_mltProducer->get_playtime()); - //m_connectTimer->start( 500 ); + //m_connectTimer->start( 1000 ); connectPlaylist(); m_generateScenelist = false; @@ -544,16 +558,16 @@ void Render::setSceneList(QString playlist, int position) { /** Create the producer from the Westley QDomDocument */ QString Render::sceneList() { - if (m_winid == -1) return QString(); KTemporaryFile temp; QString result; if (temp.open()) { saveSceneList(temp.fileName()); QFile file(temp.fileName()); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + kWarning() << "++++++++++++++++ CANNOT READ TMP SCENELIST FILE"; return QString(); - + } QTextStream in(&file); while (!in.atEnd()) { result.append(in.readLine()); @@ -562,7 +576,7 @@ QString Render::sceneList() { return result; } -void Render::saveSceneList(QString path) { +void Render::saveSceneList(QString path, QDomElement addedXml) { char *tmppath = decodedString("westley:" + path); Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath); delete[] tmppath; @@ -570,6 +584,21 @@ void Render::saveSceneList(QString path) { Mlt::Producer prod(m_mltProducer->get_producer()); westleyConsumer.connect(prod); westleyConsumer.start(); + if (!addedXml.isNull()) { + // add Kdenlive specific tags + QFile file(path); + QDomDocument doc; + doc.setContent(&file, false); + doc.documentElement().appendChild(doc.importNode(addedXml, true)); + file.close(); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + kWarning() << "////// ERROR writing to file: " << path; + return; + } + QTextStream out(&file); + out << doc.toString(); + file.close(); + } } @@ -578,12 +607,13 @@ const double Render::fps() const { } void Render::connectPlaylist() { - + if (!m_mltConsumer) return; m_connectTimer->stop(); + m_mltConsumer->set("refresh", "0"); m_mltConsumer->connect(*m_mltProducer); m_mltProducer->set_speed(0.0); m_mltConsumer->start(); - //refresh(); + refresh(); /* if (m_mltConsumer->start() == -1) { KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it.")); diff --git a/src/renderer.h b/src/renderer.h index 7c8bd031..a63219f9 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -95,7 +95,7 @@ Q_OBJECT public: void setSceneList(QDomDocument list, int position = 0); void setSceneList(QString playlist, int position = 0); QString sceneList(); - void saveSceneList(QString path); + void saveSceneList(QString path, QDomElement addedXml = QDomElement()); /** Wraps the VEML command of the same name. Tells the renderer to play the current scene at the speed specified, relative to normal -- 2.39.2