X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprofilesdialog.cpp;h=15517ec533832ad0ca1b19b5d553af5e5cbec464;hb=480f1a1466bc87a050a04dcb8ee5176ee9ec7747;hp=09a73f6dc1739f4ff2b51ac6f6b1aa44184bbdd1;hpb=5ee798aed90c5a3a50024e6b5bd26753e03ec7cc;p=kdenlive diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 09a73f6d..15517ec5 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -29,12 +29,18 @@ #include ProfilesDialog::ProfilesDialog(QWidget * parent) : - QDialog(parent), - m_isCustomProfile(false), - m_profileIsModified(false) + QDialog(parent), + m_profileIsModified(false), + m_isCustomProfile(false) { m_view.setupUi(this); + // Fill colorspace list (see mlt_profile.h) + m_view.colorspace->addItem(getColorspaceDescription(601), 601); + m_view.colorspace->addItem(getColorspaceDescription(709), 709); + m_view.colorspace->addItem(getColorspaceDescription(240), 240); + m_view.colorspace->addItem(getColorspaceDescription(0), 0); + QStringList profilesFilter; profilesFilter << "*"; @@ -72,7 +78,7 @@ void ProfilesDialog::slotProfileEdited() void ProfilesDialog::fillList(const QString selectedProfile) { - // List the Mlt profiles + // List the Mlt profiles m_view.profiles_list->clear(); QMap profilesInfo = ProfilesDialog::getProfilesInfo(); QMapIterator i(profilesInfo); @@ -167,7 +173,7 @@ void ProfilesDialog::saveProfile(const QString path) return; } QTextStream out(&file); - out << "description=" << m_view.description->text() << "\n" << "frame_rate_num=" << m_view.frame_num->value() << "\n" << "frame_rate_den=" << m_view.frame_den->value() << "\n" << "width=" << m_view.size_w->value() << "\n" << "height=" << m_view.size_h->value() << "\n" << "progressive=" << m_view.progressive->isChecked() << "\n" << "sample_aspect_num=" << m_view.aspect_num->value() << "\n" << "sample_aspect_den=" << m_view.aspect_den->value() << "\n" << "display_aspect_num=" << m_view.display_num->value() << "\n" << "display_aspect_den=" << m_view.display_den->value() << "\n"; + out << "description=" << m_view.description->text() << "\n" << "frame_rate_num=" << m_view.frame_num->value() << "\n" << "frame_rate_den=" << m_view.frame_den->value() << "\n" << "width=" << m_view.size_w->value() << "\n" << "height=" << m_view.size_h->value() << "\n" << "progressive=" << m_view.progressive->isChecked() << "\n" << "sample_aspect_num=" << m_view.aspect_num->value() << "\n" << "sample_aspect_den=" << m_view.aspect_den->value() << "\n" << "display_aspect_num=" << m_view.display_num->value() << "\n" << "display_aspect_den=" << m_view.display_den->value() << "\n" << "colorspace=" << m_view.colorspace->itemData(m_view.colorspace->currentIndex()).toInt() << "\n"; if (file.error() != QFile::NoError) { KMessageBox::error(this, i18n("Cannot write to file %1", path)); } @@ -196,22 +202,22 @@ MltVideoProfile ProfilesDialog::getVideoProfile(QString name) if (name.contains('/')) isCustom = true; if (!isCustom) { - // List the Mlt profiles + // List the Mlt profiles profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); - if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + '/' + name; + if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + name; } - if (isCustom || path.isEmpty()) { + if (isCustom || path.isEmpty()) { path = name; } if (path.isEmpty() || !QFile::exists(path)) { if (name == "dv_pal") { - kDebug() << "!!! WARNING, COULD NOT FIND DEFAULT MLT PROFILE"; + kDebug() << "!!! WARNING, COULD NOT FIND DEFAULT MLT PROFILE"; return result; } if (name == KdenliveSettings::default_profile()) KdenliveSettings::setDefault_profile("dv_pal"); - kDebug() << "// WARNING, COULD NOT FIND PROFILE " << name; - return getVideoProfile("dv_pal"); + kDebug() << "// WARNING, COULD NOT FIND PROFILE " << name; + return result; } KConfig confFile(path, KConfig::SimpleConfig); result.path = name; @@ -225,34 +231,93 @@ MltVideoProfile ProfilesDialog::getVideoProfile(QString name) 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(); + result.colorspace = confFile.entryMap().value("colorspace").toInt(); return result; } // static -QString ProfilesDialog::getProfileDescription(QString name) +double ProfilesDialog::getStringEval(const MltVideoProfile &profile, QString eval) +{ + double result; + eval.replace("%width", QString::number(profile.width)); + eval.replace("%height", QString::number(profile.height)); + if (eval.contains('/')) result = (double) eval.section('/', 0, 0).toInt() / eval.section('/', 1, 1).toInt(); + else if (eval.contains('*')) result = (double) eval.section('*', 0, 0).toInt() * eval.section('*', 1, 1).toInt(); + else if (eval.contains('+')) result = (double) eval.section('+', 0, 0).toInt() + eval.section('+', 1, 1).toInt(); + else if (eval.contains('-')) result = (double) eval.section('-', 0, 0).toInt() - eval.section('-', 1, 1).toInt(); + else result = eval.toDouble(); + return result; +} + + +// static +bool ProfilesDialog::existingProfileDescription(const QString &desc) { - QStringList profilesNames; - QStringList profilesFiles; QStringList profilesFilter; profilesFilter << "*"; - // List the Mlt profiles - profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); - if (profilesFiles.contains(name)) { - KConfig confFile(KdenliveSettings::mltpath() + '/' + name, KConfig::SimpleConfig); - return confFile.entryMap().value("description"); + // List the Mlt profiles + QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); + for (int i = 0; i < profilesFiles.size(); ++i) { + KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig); + if (desc == confFile.entryMap().value("description")) return true; } // 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)) { - KConfig confFile(customProfiles.at(i) + '/' + name, KConfig::SimpleConfig); - return confFile.entryMap().value("description"); + for (int j = 0; j < profilesFiles.size(); ++j) { + KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig); + if (desc == confFile.entryMap().value("description")) return true; } } + return false; +} + +// static +QString ProfilesDialog::existingProfile(MltVideoProfile profile) +{ + // Check if the profile has a matching entry in existing ones + QStringList profilesFilter; + profilesFilter << "*"; + // Check the Mlt profiles + QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); + for (int i = 0; i < profilesFiles.size(); ++i) { + KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig); + if (profile.display_aspect_den != confFile.entryMap().value("display_aspect_den").toInt()) continue; + if (profile.display_aspect_num != confFile.entryMap().value("display_aspect_num").toInt()) continue; + if (profile.sample_aspect_den != confFile.entryMap().value("sample_aspect_den").toInt()) continue; + if (profile.sample_aspect_num != confFile.entryMap().value("sample_aspect_num").toInt()) continue; + if (profile.width != confFile.entryMap().value("width").toInt()) continue; + if (profile.height != confFile.entryMap().value("height").toInt()) continue; + if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue; + if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue; + if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue; + if (profile.colorspace != confFile.entryMap().value("colorspace").toInt()) continue; + return profilesFiles.at(i); + } + + // Check 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); + for (int j = 0; j < profilesFiles.size(); ++j) { + KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig); + if (profile.display_aspect_den != confFile.entryMap().value("display_aspect_den").toInt()) continue; + if (profile.display_aspect_num != confFile.entryMap().value("display_aspect_num").toInt()) continue; + if (profile.sample_aspect_den != confFile.entryMap().value("sample_aspect_den").toInt()) continue; + if (profile.sample_aspect_num != confFile.entryMap().value("sample_aspect_num").toInt()) continue; + if (profile.width != confFile.entryMap().value("width").toInt()) continue; + if (profile.height != confFile.entryMap().value("height").toInt()) continue; + if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue; + if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue; + if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue; + if (profile.colorspace != confFile.entryMap().value("colorspace").toInt()) continue; + return customProfiles.at(i) + profilesFiles.at(j); + } + } return QString(); } @@ -263,10 +328,10 @@ QMap ProfilesDialog::getProfilesInfo() QStringList profilesFilter; profilesFilter << "*"; - // List the Mlt profiles + // List the Mlt profiles QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); for (int i = 0; i < profilesFiles.size(); ++i) { - KConfig confFile(KdenliveSettings::mltpath() + '/' + profilesFiles.at(i), KConfig::SimpleConfig); + KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig); QString desc = confFile.entryMap().value("description"); if (!desc.isEmpty()) result.insert(desc, profilesFiles.at(i)); } @@ -276,9 +341,9 @@ QMap ProfilesDialog::getProfilesInfo() for (int i = 0; i < customProfiles.size(); ++i) { profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); for (int j = 0; j < profilesFiles.size(); ++j) { - KConfig confFile(customProfiles.at(i) + '/' + profilesFiles.at(j), KConfig::SimpleConfig); + KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig); QString desc = confFile.entryMap().value("description"); - if (!desc.isEmpty()) result.insert(desc, customProfiles.at(i) + '/' + profilesFiles.at(j)); + if (!desc.isEmpty()) result.insert(desc, customProfiles.at(i) + profilesFiles.at(j)); } } return result; @@ -294,7 +359,7 @@ QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path) if (!path.contains('/')) { // This is an MLT profile - KConfig confFile(KdenliveSettings::mltpath() + '/' + path, KConfig::SimpleConfig); + KConfig confFile(KdenliveSettings::mltpath() + path, KConfig::SimpleConfig); return confFile.entryMap(); } else { // This is a custom profile @@ -311,10 +376,10 @@ QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString pro QStringList profilesFilter; profilesFilter << "*"; - // List the Mlt profiles + // List the Mlt profiles profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); for (int i = 0; i < profilesFiles.size(); ++i) { - KConfig confFile(KdenliveSettings::mltpath() + '/' + profilesFiles.at(i), KConfig::SimpleConfig); + KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig); QMap< QString, QString > values = confFile.entryMap(); if (values.value("description") == profileName) { values.insert("path", profilesFiles.at(i)); @@ -326,11 +391,11 @@ QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString pro QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); for (int i = 0; i < customProfiles.size(); ++i) { QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); - for (int i = 0; i < profiles.size(); ++i) { - KConfig confFile(customProfiles.at(i) + '/' + profiles.at(i), KConfig::SimpleConfig); + for (int j = 0; j < profiles.size(); ++j) { + KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig); QMap< QString, QString > values = confFile.entryMap(); if (values.value("description") == profileName) { - values.insert("path", customProfiles.at(i) + '/' + profiles.at(i)); + values.insert("path", customProfiles.at(i) + profiles.at(j)); return values; } } @@ -338,6 +403,63 @@ QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString pro return QMap< QString, QString >(); } +// static +bool ProfilesDialog::matchProfile(int width, int height, double fps, double par, bool isImage, MltVideoProfile profile) +{ + int profileWidth; + if (isImage) { + // when using image, compare with display width + profileWidth = profile.height * profile.display_aspect_num / profile.display_aspect_den + 0.5; + } else profileWidth = profile.width; + if (width != profileWidth || height != profile.height || (fps > 0 && qAbs((double) profile.frame_rate_num / profile.frame_rate_den - fps) > 0.4) || (par > 0 && qAbs((double) profile.sample_aspect_num / profile.sample_aspect_den - par) > 0.1)) return false; + return true; +} + +// static +QMap ProfilesDialog::getProfilesFromProperties(int width, int height, double fps, double par, bool useDisplayWidth) +{ + QStringList profilesNames; + QStringList profilesFiles; + QStringList profilesFilter; + QMap result; + profilesFilter << "*"; + // List the Mlt profiles + profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); + for (int i = 0; i < profilesFiles.size(); ++i) { + KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig); + QMap< QString, QString > values = confFile.entryMap(); + int profileWidth; + if (useDisplayWidth) profileWidth = values.value("height").toInt() * values.value("display_aspect_num").toInt() / values.value("display_aspect_den").toInt() + 0.5; + else profileWidth = values.value("width").toInt(); + if (profileWidth == width && values.value("height").toInt() == height) { + double profile_fps = values.value("frame_rate_num").toDouble() / values.value("frame_rate_den").toDouble(); + double profile_par = values.value("sample_aspect_num").toDouble() / values.value("sample_aspect_den").toDouble(); + if ((fps <= 0 || qAbs(profile_fps - fps) < 0.5) && (par <= 0 || qAbs(profile_par - par) < 0.1)) + result.insert(profilesFiles.at(i), values.value("description")); + } + } + + // List custom profiles + QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); + for (int i = 0; i < customProfiles.size(); ++i) { + QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); + for (int j = 0; j < profiles.size(); j++) { + KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig); + QMap< QString, QString > values = confFile.entryMap(); + int profileWidth; + if (useDisplayWidth) profileWidth = values.value("height").toInt() * values.value("display_aspect_num").toInt() / values.value("display_aspect_den").toInt() + 0.5; + else profileWidth = values.value("width").toInt(); + if (profileWidth == width && values.value("height").toInt() == height) { + double profile_fps = values.value("frame_rate_num").toDouble() / values.value("frame_rate_den").toDouble(); + double profile_par = values.value("sample_aspect_num").toDouble() / values.value("sample_aspect_den").toDouble(); + if ((fps <= 0 || qAbs(profile_fps - fps) < 0.5) && (par <= 0 || qAbs(profile_par - par) < 0.1)) + result.insert(customProfiles.at(i) + profiles.at(j), values.value("description")); + } + } + } + return result; +} + // static QString ProfilesDialog::getPathFromDescription(const QString profileDesc) { @@ -346,10 +468,10 @@ QString ProfilesDialog::getPathFromDescription(const QString profileDesc) QStringList profilesFilter; profilesFilter << "*"; - // List the Mlt profiles + // List the Mlt profiles profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files); for (int i = 0; i < profilesFiles.size(); ++i) { - KConfig confFile(KdenliveSettings::mltpath() + '/' + profilesFiles.at(i), KConfig::SimpleConfig); + KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig); QMap< QString, QString > values = confFile.entryMap(); if (values.value("description") == profileDesc) return profilesFiles.at(i); } @@ -358,15 +480,40 @@ QString ProfilesDialog::getPathFromDescription(const QString profileDesc) QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); for (int i = 0; i < customProfiles.size(); ++i) { QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); - for (int i = 0; i < profiles.size(); ++i) { - KConfig confFile(customProfiles.at(i) + '/' + profiles.at(i), KConfig::SimpleConfig); + for (int j = 0; j < profiles.size(); ++j) { + KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig); QMap< QString, QString > values = confFile.entryMap(); - if (values.value("description") == profileDesc) return customProfiles.at(i) + '/' + profiles.at(i); + if (values.value("description") == profileDesc) return customProfiles.at(i) + profiles.at(j); } } return QString(); } +// static +void ProfilesDialog::saveProfile(MltVideoProfile &profile) +{ + int i = 0; + QString customName = "profiles/customprofile"; + QString profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i)); + kDebug() << " TYING PROFILE FILE: " << profilePath; + while (KIO::NetAccess::exists(KUrl(profilePath), KIO::NetAccess::SourceSide, 0)) { + i++; + profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i)); + } + QFile file(profilePath); + if (!file.open(QIODevice::WriteOnly)) { + KMessageBox::sorry(0, i18n("Cannot write to file %1", profilePath)); + return; + } + QTextStream out(&file); + out << "description=" << profile.description << "\n" << "frame_rate_num=" << profile.frame_rate_num << "\n" << "frame_rate_den=" << profile.frame_rate_den << "\n" << "width=" << profile.width << "\n" << "height=" << profile.height << "\n" << "progressive=" << profile.progressive << "\n" << "sample_aspect_num=" << profile.sample_aspect_num << "\n" << "sample_aspect_den=" << profile.sample_aspect_den << "\n" << "display_aspect_num=" << profile.display_aspect_num << "\n" << "display_aspect_den=" << profile.display_aspect_den << "\n" << "colorspace=" << profile.colorspace << "\n"; + if (file.error() != QFile::NoError) { + KMessageBox::error(0, i18n("Cannot write to file %1", profilePath)); + } + file.close(); + profile.path = profilePath; +} + void ProfilesDialog::slotUpdateDisplay() { @@ -380,6 +527,7 @@ void ProfilesDialog::slotUpdateDisplay() m_selectedProfileIndex = m_view.profiles_list->currentIndex(); QString currentProfile = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString(); m_isCustomProfile = currentProfile.contains('/'); + m_view.button_create->setEnabled(true); m_view.button_delete->setEnabled(m_isCustomProfile); m_view.properties->setEnabled(m_isCustomProfile); m_view.button_save->setEnabled(m_isCustomProfile); @@ -394,9 +542,32 @@ void ProfilesDialog::slotUpdateDisplay() m_view.frame_num->setValue(values.value("frame_rate_num").toInt()); m_view.frame_den->setValue(values.value("frame_rate_den").toInt()); m_view.progressive->setChecked(values.value("progressive").toInt()); + if (values.value("progressive").toInt()) { + m_view.fields->setText(QString::number((double) values.value("frame_rate_num").toInt() / values.value("frame_rate_den").toInt(), 'f', 2)); + } else { + m_view.fields->setText(QString::number((double) 2 * values.value("frame_rate_num").toInt() / values.value("frame_rate_den").toInt(), 'f', 2)); + } + + int colorix = m_view.colorspace->findData(values.value("colorspace").toInt()); + if (colorix > -1) m_view.colorspace->setCurrentIndex(colorix); m_profileIsModified = false; } +//static +QString ProfilesDialog::getColorspaceDescription(int colorspace) +{ + //TODO: should the descriptions be translated? + switch (colorspace) { + case 601: + return QString("ITU-R 601"); + case 709: + return QString("ITU-R 709"); + case 240: + return QString("SMPTE240M"); + default: + return i18n("Unknown"); + } +} #include "profilesdialog.moc"