From: Jean-Baptiste Mardelle Date: Tue, 4 Mar 2008 10:38:16 +0000 (+0000) Subject: Start using mlt profiles X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=fa2e7f5b194c12c81167e1a7afefbb1727132017;p=kdenlive Start using mlt profiles svn path=/branches/KDE4/; revision=1997 --- diff --git a/src/definitions.h b/src/definitions.h index 56733d65..ad87e9fc 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -27,11 +27,18 @@ enum OPERATIONTYPE { NONE = 0, MOVE = 1, RESIZESTART = 2, RESIZEEND = 3, FADEIN = 4, FADEOUT = 5}; enum CLIPTYPE { UNKNOWN = 0, AUDIO = 1, VIDEO = 2, AV = 3, COLOR = 4, IMAGE = 5, TEXT = 6, SLIDESHOW = 7, VIRTUAL = 8, PLAYLIST = 9}; -struct TrackViewClip { - int startTime; - int duration; - int cropTime; - QString producer; +struct MltVideoProfile { + QString path; + QString description; + int frame_rate_num; + int frame_rate_den; + int width; + int height; + bool progressive; + int sample_aspect_num; + int sample_aspect_den; + int display_aspect_num; + int display_aspect_den; }; #endif diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 47006dcf..dc4ab309 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -67,7 +67,7 @@ DocClipBase & DocClipBase::operator=(const DocClipBase & clip) { } DocClipBase::~DocClipBase() { - //if (m_thumbProd) delete m_thumbProd; + if (m_thumbProd) delete m_thumbProd; } void DocClipBase::slotRequestAudioThumbs() { diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 72da0645..35e50d31 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -28,7 +28,7 @@ #include "kdenlivedoc.h" #include "docclipbase.h" -KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL), m_commandStack(new KUndoStack()) { +KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, 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_projectName(NULL), m_commandStack(new KUndoStack()) { m_clipManager = new ClipManager(this); if (!url.isEmpty()) { QString tmpFile; @@ -101,8 +101,8 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWi doc.appendChild(tractor); } - if (fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true); - else m_timecode.setFormat((int) fps); + if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true); + else m_timecode.setFormat((int) m_fps); } KdenliveDoc::~KdenliveDoc() { @@ -114,6 +114,10 @@ ClipManager *KdenliveDoc::clipManager() { return m_clipManager; } +QString KdenliveDoc::profilePath() { + return m_profile.path; +} + void KdenliveDoc::setThumbsProgress(KUrl url, int progress) { emit thumbsProgress(url, progress); } diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index 4eb8f5ed..78839441 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -34,11 +34,12 @@ #include "timecode.h" #include "renderer.h" #include "clipmanager.h" +#include "definitions.h" class KdenliveDoc: public QObject { Q_OBJECT public: - KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent = 0); + KdenliveDoc(const KUrl &url, MltVideoProfile profile, QWidget *parent = 0); ~KdenliveDoc(); QString documentName(); QDomNodeList producersList(); @@ -66,6 +67,7 @@ Q_OBJECT public: void deleteProjectClip(const uint clipId); /** Inform application of the audio thumbnails generation progress */ void setThumbsProgress(KUrl url, int progress); + QString profilePath(); private: KUrl m_url; @@ -79,6 +81,7 @@ private: KUndoStack *m_commandStack; QDomDocument generateSceneList(); ClipManager *m_clipManager; + MltVideoProfile m_profile; public slots: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5710622e..322324e0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -295,9 +295,11 @@ void MainWindow::readOptions() { } void MainWindow::newFile() { - KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576); + MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile()); + if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal"); + KdenliveDoc *doc = new KdenliveDoc(KUrl(), prof); TrackView *trackView = new TrackView(doc); - m_timelineArea->addTab(trackView, i18n("Untitled") + " / " + ProfilesDialog::getProfileDescription(KdenliveSettings::default_profile())); + m_timelineArea->addTab(trackView, i18n("Untitled") + " / " + prof.description); if (m_timelineArea->count() == 1) connectDocument(trackView, doc); else m_timelineArea->setTabBarHidden(false); @@ -342,9 +344,12 @@ void MainWindow::openFile() { //changed } void MainWindow::openFile(const KUrl &url) { //new - KdenliveDoc *doc = new KdenliveDoc(url, 25, 720, 576); + //TODO: get video profile from url before opening it + MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile()); + if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal"); + KdenliveDoc *doc = new KdenliveDoc(url, prof); TrackView *trackView = new TrackView(doc); - m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName())); + m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName() + " / " + prof.description)); m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path()); if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false); //connectDocument(trackView, doc); @@ -452,6 +457,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha m_projectList->setDocument(doc); m_monitorManager->setTimecode(doc->timecode()); + m_monitorManager->resetProfiles(doc->profilePath()); doc->setRenderer(m_projectMonitor->render); //m_undoView->setStack(0); m_commandStack = doc->commandStack(); diff --git a/src/monitor.cpp b/src/monitor.cpp index 7a888242..3d78f08b 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -220,6 +220,10 @@ void Monitor::slotOpenFile(const QString &file) { render->setSceneList(doc, 0); } +void Monitor::resetProfile(QString prof) { + if (render == NULL) return; + render->resetProfile(prof); +} #include "monitor.moc" diff --git a/src/monitor.h b/src/monitor.h index 4e4f4c10..bea893e0 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -36,6 +36,8 @@ class Monitor : public QWidget { public: Monitor(QString name, MonitorManager *manager, QWidget *parent = 0); Render *render; + void resetProfile(QString prof); + virtual void resizeEvent(QResizeEvent * event); protected: virtual void mousePressEvent(QMouseEvent * event); diff --git a/src/monitormanager.cpp b/src/monitormanager.cpp index 0d6ff685..28e5825c 100644 --- a/src/monitormanager.cpp +++ b/src/monitormanager.cpp @@ -80,4 +80,9 @@ void MonitorManager::slotPlay() { else m_projectMonitor->slotPlay(); } +void MonitorManager::resetProfiles(QString prof) { + m_clipMonitor->resetProfile(prof); + m_projectMonitor->resetProfile(prof); +} + #include "monitormanager.moc" diff --git a/src/monitormanager.h b/src/monitormanager.h index 7de76206..6466002a 100644 --- a/src/monitormanager.h +++ b/src/monitormanager.h @@ -34,6 +34,7 @@ public: void initMonitors(Monitor *clipMonitor, Monitor *projectMonitor); Timecode timecode(); void setTimecode(Timecode tc); + void resetProfiles(QString prof); public slots: void activateMonitor(QString name = QString::null); diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 497bfacf..0f338a0d 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -49,6 +49,46 @@ ProfilesDialog::ProfilesDialog(QWidget * parent): QDialog(parent), m_isCustomPro connect(m_view.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay())); } +// static +MltVideoProfile ProfilesDialog::getVideoProfile(QString name) { + MltVideoProfile result; + QStringList profilesNames; + QStringList profilesFiles; + QStringList profilesFilter; + profilesFilter << "*"; + QString path; + + // List the Mlt profiles + profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); + if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + "/" + name; + + if (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; + } + } + } + + if (path.isEmpty()) return result; + KConfig confFile(path); + result.path = path; + 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(); + result.width = confFile.entryMap().value("width").toInt(); + result.height = confFile.entryMap().value("height").toInt(); + result.progressive = confFile.entryMap().value("progressive").toInt(); + result.sample_aspect_num = confFile.entryMap().value("sample_aspect_num").toInt(); + result.sample_aspect_den = confFile.entryMap().value("sample_aspect_den").toInt(); + result.display_aspect_num = confFile.entryMap().value("display_aspect_num").toInt(); + result.display_aspect_den = confFile.entryMap().value("display_aspect_den").toInt(); + return result; +} // static QString ProfilesDialog::getProfileDescription(QString name) { diff --git a/src/profilesdialog.h b/src/profilesdialog.h index a4f4d574..0046104e 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -23,6 +23,7 @@ #include +#include "definitions.h" #include "ui_profiledialog_ui.h" class ProfilesDialog : public QDialog { @@ -35,6 +36,7 @@ public: static QString getProfileDescription(QString name); static QMap< QString, QString > getSettingsForProfile(const QString profileName); static QMap< QString, QString > getSettingsFromFile(const QString path); + static MltVideoProfile getVideoProfile(QString name); private slots: void slotUpdateDisplay(); diff --git a/src/renderer.cpp b/src/renderer.cpp index b890f0eb..597235d2 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -114,14 +114,16 @@ void Render::closeMlt() { -int Render::resetRendererProfile(char * profile) { +int Render::resetProfile(QString profile) { if (!m_mltConsumer) return 0; if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); m_mltConsumer->set("refresh", 0); - //m_mltConsumer->set("profile", profile); + //TODO: we should also rebuild filters and delete existing m_mltProfile + m_mltProfile = new Mlt::Profile((char*) qstrdup(profile.toUtf8())); kDebug() << " + + RESET CONSUMER WITH PROFILE: " << profile; mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer()); -// apply_profile_properties( m_profile, m_mltConsumer->get_consumer(), properties ); + mlt_properties_set_data(properties, "profile", m_mltProfile->get_profile(), 0, 0, NULL); + //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties ); refresh(); return 1; } diff --git a/src/renderer.h b/src/renderer.h index fadc295f..082dda9e 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -145,7 +145,7 @@ Q_OBJECT public: void refreshDisplay(); /** returns the current scenelist */ QDomDocument sceneList() const; - int resetRendererProfile(char * profile); + int resetProfile(QString profile); const double fps() const; /** Playlist manipulation */