X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Frenderer.cpp;h=ab4c1db3e59d321e7dda87e4faea814cde53f8fc;hb=c06da322c72717fea0744282e4e925145a90dc72;hp=2744f6619f57fd19282b2572ca417e86bd1926b7;hpb=0699631e8b9cdb5f0da0ddb0a16d04ee9600a064;p=kdenlive diff --git a/src/renderer.cpp b/src/renderer.cpp index 2744f661..ab4c1db3 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -38,9 +38,11 @@ #include #include +#include #include -#include +#include +#include @@ -49,6 +51,7 @@ static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list if (level > MLT_LOG_ERROR) return; QString error; QApplication::postEvent(qApp->activeWindow() , new MltErrorEvent(error.vsprintf(fmt, vl).simplified())); + va_end(vl); } @@ -60,13 +63,17 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr #ifdef Q_WS_MAC self->showFrame(frame); #endif + + self->emitFrameNumber(mlt_frame_get_position(frame_ptr)); if (frame.get_double("_speed") == 0.0) { self->emitConsumerStopped(); - } else { - self->emitFrameNumber(mlt_frame_get_position(frame_ptr)); + } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) { + self->pause(); + self->emitConsumerStopped(); } } + Render::Render(const QString & rendererName, int winid, int /* extid */, QString profile, QWidget *parent) : QObject(parent), m_isBlocked(0), @@ -130,12 +137,10 @@ void Render::closeMlt() resource = mlt_properties_get(properties, "mlt_service"); } - int trackNb = tractor.count(); - while (trackNb > 0) { - Mlt::Producer trackProducer(tractor.track(trackNb - 1)); + for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) { + Mlt::Producer trackProducer(tractor.track(trackNb)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); if (trackPlaylist.type() == playlist_type) trackPlaylist.clear(); - trackNb--; } } mlt_service_unlock(service.get_service()); @@ -148,6 +153,11 @@ void Render::closeMlt() //delete m_osdInfo; } +void Render::slotSwitchFullscreen() +{ + if (m_mltConsumer) m_mltConsumer->set("full_screen", 1); +} + void Render::buildConsumer(const QString profileName) { char *tmp; @@ -227,22 +237,37 @@ void Render::buildConsumer(const QString profileName) m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black"); m_blackClip->set("id", "black"); + m_blackClip->set("mlt_type", "producer"); } +Mlt::Producer *Render::invalidProducer(const QString &id) +{ + Mlt::Producer *clip = new Mlt::Producer(*m_mltProfile , "colour", "red"); + char *tmp = decodedString(id); + clip->set("id", tmp); + delete[] tmp; + clip->set("mlt_type", "producer"); + return clip; +} + int Render::resetProfile(const QString profileName) { - if (!m_mltConsumer) return 0; - if (m_activeProfile == profileName) { - kDebug() << "reset to same profile, nothing to do"; - return 1; + if (m_mltConsumer) { + QString videoDriver = KdenliveSettings::videodrivername(); + QString currentDriver = m_mltConsumer->get("video_driver"); + if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel"; + if (m_activeProfile == profileName && currentDriver == videoDriver) { + kDebug() << "reset to same profile, nothing to do"; + return 1; + } + + if (m_isSplitView) slotSplitView(false); + if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); + m_mltConsumer->purge(); + delete m_mltConsumer; + m_mltConsumer = NULL; } - kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << profileName; //KdenliveSettings::current_profile(); - if (m_isSplitView) slotSplitView(false); - if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); - m_mltConsumer->purge(); - delete m_mltConsumer; - m_mltConsumer = NULL; QString scene = sceneList(); int pos = 0; double current_fps = m_mltProfile->fps(); @@ -255,12 +280,10 @@ int Render::resetProfile(const QString profileName) Mlt::Service service(m_mltProducer->get_service()); if (service.type() == tractor_type) { Mlt::Tractor tractor(service); - int trackNb = tractor.count(); - while (trackNb > 0) { - Mlt::Producer trackProducer(tractor.track(trackNb - 1)); + for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) { + Mlt::Producer trackProducer(tractor.track(trackNb)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); trackPlaylist.clear(); - trackNb--; } } @@ -300,7 +323,6 @@ int Render::resetProfile(const QString profileName) return 1; } -/** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */ void Render::seek(GenTime time) { if (!m_mltProducer) @@ -340,7 +362,7 @@ char *Render::decodedString(QString str) */ int Render::renderWidth() const { - return (int)(m_mltProfile->height() * m_mltProfile->dar()); + return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5); } int Render::renderHeight() const @@ -516,8 +538,7 @@ void Render::slotSplitView(bool doit) if (service.type() != tractor_type || tractor.count() < 2) return; Mlt::Field *field = tractor.field(); if (doit) { - int screen = 0; - for (int i = 1; i < tractor.count() && screen < 4; i++) { + for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) { Mlt::Producer trackProducer(tractor.track(i)); kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide"); if (QString(trackProducer.get("hide")).toInt() != 1) { @@ -574,7 +595,7 @@ void Render::slotSplitView(bool doit) } } -void Render::getFileProperties(const QDomElement xml, const QString &clipId, bool replaceProducer) +void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer) { KUrl url = KUrl(xml.attribute("resource", QString())); Mlt::Producer *producer = NULL; @@ -591,8 +612,8 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo char *tmp = decodedString("kdenlivetitle:" + xml.attribute("resource")); producer = new Mlt::Producer(*m_mltProfile, 0, tmp); delete[] tmp; - if (xml.hasAttribute("xmldata")) { - char *tmp = decodedString(xml.attribute("xmldata")); + if (producer && xml.hasAttribute("xmldata")) { + tmp = decodedString(xml.attribute("xmldata")); producer->set("xmldata", tmp); delete[] tmp; } @@ -623,6 +644,17 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo double aspect = xml.attribute("force_aspect_ratio").toDouble(); if (aspect > 0) producer->set("force_aspect_ratio", aspect); } + + if (xml.hasAttribute("force_fps")) { + double fps = xml.attribute("force_fps").toDouble(); + if (fps > 0) producer->set("force_fps", fps); + } + + if (xml.hasAttribute("force_progressive")) { + bool ok; + int progressive = xml.attribute("force_progressive").toInt(&ok); + if (ok) producer->set("force_progressive", progressive); + } if (xml.hasAttribute("threads")) { int threads = xml.attribute("threads").toInt(); if (threads != 1) producer->set("threads", threads); @@ -654,8 +686,7 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo return; } - int height = 50; - int width = (int)(height * m_mltProfile->dar()); + int width = (int)(imageHeight * m_mltProfile->dar() + 0.5); QMap < QString, QString > filePropertyMap; QMap < QString, QString > metadataPropertyMap; @@ -710,10 +741,10 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo mlt_image_format format = mlt_image_rgb24a; int frame_width = width; - int frame_height = height; - QPixmap pix(width, height); + int frame_height = imageHeight; uint8_t *data = frame->get_image(format, frame_width, frame_height, 0); QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32); + QPixmap pix(frame_width, frame_height); if (!image.isNull()) { pix = QPixmap::fromImage(image.rgbSwapped()); @@ -723,12 +754,12 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo emit replyGetImage(clipId, pix); } else if (frame->get_int("test_audio") == 0) { - QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height)); + QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight)); emit replyGetImage(clipId, pixmap); filePropertyMap["type"] = "audio"; } } - + delete frame; // Retrieve audio / video codec name // If there is a @@ -805,17 +836,16 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, boo if (name.endsWith("markup") && !value.isEmpty()) metadataPropertyMap[ name.section('.', 0, -2)] = value; } - - emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer); + producer->seek(0); kDebug() << "REquested fuile info for: " << url.path(); - delete frame; + emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer); // FIXME: should delete this to avoid a leak... //delete producer; } -/** Create the producer from the MLT XML QDomDocument */ #if 0 +/** Create the producer from the MLT XML QDomDocument */ void Render::initSceneList() { kDebug() << "-------- INIT SCENE LIST ------_"; @@ -852,9 +882,6 @@ void Render::initSceneList() } #endif - - -/** Create the producer from the MLT XML QDomDocument */ int Render::setProducer(Mlt::Producer *producer, int position) { if (m_winid == -1) return -1; @@ -886,6 +913,7 @@ int Render::setProducer(Mlt::Producer *producer, int position) m_fps = m_mltProducer->get_fps(); int error = connectPlaylist(); + if (position != -1) { m_mltProducer->seek(position); emit rendererPosition(position); @@ -894,34 +922,29 @@ int Render::setProducer(Mlt::Producer *producer, int position) return error; } - - -/** Create the producer from the MLT XML QDomDocument */ int Render::setSceneList(QDomDocument list, int position) { return setSceneList(list.toString(), position); } -/** Create the producer from the MLT XML QDomDocument */ int Render::setSceneList(QString playlist, int position) { if (m_winid == -1) return -1; m_isBlocked = true; - int error; + int error = 0; kDebug() << "////// RENDER, SET SCENE LIST: " << playlist; - if (m_mltConsumer == NULL) { + if (m_mltConsumer) { + if (!m_mltConsumer->is_stopped()) { + m_mltConsumer->stop(); + } + m_mltConsumer->set("refresh", 0); + } else { kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER"; - m_isBlocked = false; - return -1; + error = -1; } - if (!m_mltConsumer->is_stopped()) { - m_mltConsumer->stop(); - } - m_mltConsumer->set("refresh", 0); - if (m_mltProducer) { m_mltProducer->set_speed(0); //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo); @@ -949,12 +972,10 @@ int Render::setSceneList(QString playlist, int position) resource = mlt_properties_get(properties, "mlt_service"); } - int trackNb = tractor.count(); - while (trackNb > 0) { - Mlt::Producer trackProducer(tractor.track(trackNb - 1)); + for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) { + Mlt::Producer trackProducer(tractor.track(trackNb)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); if (trackPlaylist.type() == playlist_type) trackPlaylist.clear(); - trackNb--; } delete field; } @@ -975,6 +996,7 @@ int Render::setSceneList(QString playlist, int position) if (!m_mltProducer || !m_mltProducer->is_valid()) { kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp; m_mltProducer = m_blackClip->cut(0, 50); + error = -1; } delete[] tmp; @@ -1010,7 +1032,8 @@ int Render::setSceneList(QString playlist, int position) } kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime(); - error = connectPlaylist(); + if (error == 0) error = connectPlaylist(); + else connectPlaylist(); fillSlowMotionProducers(); m_isBlocked = false; @@ -1021,7 +1044,6 @@ int Render::setSceneList(QString playlist, int position) //if (position != 0) emit rendererPosition(position); } -/** Create the producer from the MLT XML QDomDocument */ const QString Render::sceneList() { QString playlist; @@ -1062,7 +1084,6 @@ bool Render::saveSceneList(QString path, QDomElement kdenliveData) return true; } - void Render::saveZone(KUrl url, QString desc, QPoint zone) { kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name; @@ -1111,9 +1132,8 @@ int Render::connectPlaylist() if (m_mltConsumer->start() == -1) { // ARGH CONSUMER BROKEN!!!! 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.")); - emit blockMonitors(); - delete m_mltProducer; - m_mltProducer = NULL; + delete m_mltConsumer; + m_mltConsumer = NULL; return -1; } emit durationChanged(m_mltProducer->get_playtime()); @@ -1180,10 +1200,8 @@ void Render::start() if (m_mltConsumer && m_mltConsumer->is_stopped()) { kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED"; 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.")); - emit blockMonitors(); - delete m_mltProducer; - m_mltProducer = NULL; + //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.")); + kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR"; } else { kDebug() << "----- MONITOR: " << m_name << " REFRESH"; m_isBlocked = false; @@ -1237,8 +1255,10 @@ void Render::pause() m_isBlocked = true; m_mltConsumer->set("refresh", 0); m_mltProducer->set_speed(0.0); + /* + The 2 lines below create a flicker loop emit rendererPosition(m_framePosition); - m_mltProducer->seek(m_framePosition); + m_mltProducer->seek(m_framePosition);*/ m_mltConsumer->purge(); } @@ -1249,13 +1269,14 @@ void Render::switchPlay() if (m_isZoneMode) resetZoneMode(); if (m_mltProducer->get_speed() == 0.0) { m_isBlocked = false; + if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0); m_mltProducer->set_speed(1.0); m_mltConsumer->set("refresh", 1); } else { m_isBlocked = true; m_mltConsumer->set("refresh", 0); m_mltProducer->set_speed(0.0); - emit rendererPosition(m_framePosition); + //emit rendererPosition(m_framePosition); m_mltProducer->seek(m_framePosition); m_mltConsumer->purge(); //kDebug()<<" ********* RENDER PAUSE: "<get_speed(); @@ -1313,7 +1334,7 @@ void Render::playZone(const GenTime & startTime, const GenTime & stopTime) return; m_isBlocked = false; if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1; - m_mltProducer->set("out", stopTime.frames(m_fps)); + m_mltProducer->set("out", (int)(stopTime.frames(m_fps))); m_mltProducer->seek((int)(startTime.frames(m_fps))); m_mltProducer->set_speed(1.0); m_mltConsumer->set("refresh", 1); @@ -1378,9 +1399,7 @@ void Render::setDropFrames(bool show) m_mltConsumer->set("play.real_time", dropFrames); #endif if (m_mltConsumer->start() == -1) { - emit blockMonitors(); - delete m_mltProducer; - m_mltProducer = NULL; + kDebug(QtWarningMsg) << "ERROR, Cannot start monitor"; } } @@ -1409,12 +1428,11 @@ const QString & Render::rendererName() const return m_name; } - void Render::emitFrameNumber(double position) { + if (position == m_framePosition) return; m_framePosition = position; emit rendererPosition((int) position); - //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId)); } void Render::emitConsumerStopped() @@ -1430,14 +1448,11 @@ void Render::emitConsumerStopped() } } - - void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/) { KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive")); } - void Render::exportCurrentFrame(KUrl url, bool /*notify*/) { if (!m_mltProducer) { @@ -1477,8 +1492,9 @@ void Render::showFrame(Mlt::Frame& frame) } #endif -/** MLT PLAYLIST DIRECT MANIPULATON **/ - +/* + * MLT playlist direct manipulation. + */ void Render::mltCheckLength(Mlt::Tractor *tractor) { @@ -1497,7 +1513,7 @@ void Render::mltCheckLength(Mlt::Tractor *tractor) while (trackNb > 1) { Mlt::Producer trackProducer(tractor->track(trackNb - 1)); trackDuration = trackProducer.get_playtime() - 1; - //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration; + // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration; if (trackDuration > duration) duration = trackDuration; trackNb--; } @@ -1514,17 +1530,17 @@ void Render::mltCheckLength(Mlt::Tractor *tractor) if (blackclip == NULL || blackTrackPlaylist.count() != 1) { blackTrackPlaylist.clear(); - m_blackClip->set("length", duration); - m_blackClip->set("out", duration - 1); - blackclip = m_blackClip->cut(0, duration - 1); + m_blackClip->set("length", duration + 1); + m_blackClip->set("out", duration); + blackclip = m_blackClip->cut(0, duration); blackTrackPlaylist.insert_at(0, blackclip, 1); } else { if (duration > blackclip->parent().get_length()) { - blackclip->parent().set("length", duration); - blackclip->parent().set("out", duration - 1); - blackclip->set("length", duration); + blackclip->parent().set("length", duration + 1); + blackclip->parent().set("out", duration); + blackclip->set("length", duration + 1); } - blackTrackPlaylist.resize_clip(0, 0, duration - 1); + blackTrackPlaylist.resize_clip(0, 0, duration); } delete blackclip; @@ -1533,6 +1549,34 @@ void Render::mltCheckLength(Mlt::Tractor *tractor) } } +Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element) +{ + if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod; + + // We want a slowmotion producer + double speed = element.attribute("speed", "1.0").toDouble(); + int strobe = element.attribute("strobe", "1").toInt(); + QString url = QString::fromUtf8(prod->get("resource")); + url.append('?' + QString::number(speed)); + if (strobe > 1) url.append("&strobe=" + QString::number(strobe)); + Mlt::Producer *slowprod = m_slowmotionProducers.value(url); + if (!slowprod || slowprod->get_producer() == NULL) { + char *tmp = decodedString(url); + slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp); + if (strobe > 1) slowprod->set("strobe", strobe); + delete[] tmp; + QString id = prod->get("id"); + if (id.contains('_')) id = id.section('_', 0, 0); + QString producerid = "slowmotion:" + id + ':' + QString::number(speed); + if (strobe > 1) producerid.append(':' + QString::number(strobe)); + tmp = decodedString(producerid); + slowprod->set("id", tmp); + delete[] tmp; + m_slowmotionProducers.insert(url, slowprod); + } + return slowprod; +} + int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push) { if (m_mltProducer == NULL) { @@ -1564,36 +1608,14 @@ int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pro int trackDuration = trackProducer.get_playtime() - 1; Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); //kDebug()<<"/// INSERT cLIP: "< 1) { - // We want a slowmotion producer - double speed = element.attribute("speed", "1.0").toDouble(); - int strobe = element.attribute("strobe", "1").toInt(); - QString url = QString::fromUtf8(prod->get("resource")); - url.append('?' + QString::number(speed)); - if (strobe > 1) url.append("&strobe=" + QString::number(strobe)); - Mlt::Producer *slowprod = m_slowmotionProducers.value(url); - if (!slowprod || slowprod->get_producer() == NULL) { - char *tmp = decodedString(url); - slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp); - if (strobe > 1) slowprod->set("strobe", strobe); - delete[] tmp; - QString id = prod->get("id"); - if (id.contains('_')) id = id.section('_', 0, 0); - QString producerid = "slowmotion:" + id + ':' + QString::number(speed); - if (strobe > 1) producerid.append(':' + QString::number(strobe)); - tmp = decodedString(producerid); - slowprod->set("id", tmp); - delete[] tmp; - m_slowmotionProducers.insert(url, slowprod); - } - prod = slowprod; - if (prod == NULL || !prod->is_valid()) { - mlt_service_unlock(service.get_service()); - return -1; - } + prod = checkSlowMotionProducer(prod, element); + if (prod == NULL || !prod->is_valid()) { + mlt_service_unlock(service.get_service()); + return -1; } + int cutPos = (int) info.cropStart.frames(m_fps); + if (cutPos < 0) cutPos = 0; int insertPos = (int) info.startPos.frames(m_fps); int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1; Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos); @@ -1721,8 +1743,12 @@ bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *pr Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); int startPos = info.startPos.frames(m_fps); int clipIndex = trackPlaylist.get_clip_index_at(startPos); + if (trackPlaylist.is_blank(clipIndex)) { + kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos; + return false; + } + mlt_service_lock(service.get_service()); Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); - // keep effects QList filtersList; Mlt::Service sourceService(clip->get_service()); @@ -1735,8 +1761,21 @@ bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *pr ct++; filter = sourceService.filter(ct); } - if (!mltRemoveClip(info.track, info.startPos)) return false; - if (mltInsertClip(info, element, prod) == -1) return false; + + trackPlaylist.replace_with_blank(clipIndex); + delete clip; + //if (!mltRemoveClip(info.track, info.startPos)) return false; + prod = checkSlowMotionProducer(prod, element); + if (prod == NULL || !prod->is_valid()) { + mlt_service_unlock(service.get_service()); + return false; + } + Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps)); + trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1); + delete clip2; + + + //if (mltInsertClip(info, element, prod) == -1) return false; if (!filtersList.isEmpty()) { clipIndex = trackPlaylist.get_clip_index_at(startPos); Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex); @@ -1745,6 +1784,7 @@ bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *pr for (int i = 0; i < filtersList.count(); i++) destService.attach(*(filtersList.at(i))); } + mlt_service_unlock(service.get_service()); return true; } @@ -1918,14 +1958,12 @@ void Render::mltInsertSpace(QMap trackClipStartList, QMap resource = mlt_properties_get(properties, "mlt_service"); } } else { - int trackNb = tractor.count(); - while (trackNb > 1) { - Mlt::Producer trackProducer(tractor.track(trackNb - 1)); + for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) { + Mlt::Producer trackProducer(tractor.track(trackNb)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); - //int clipNb = trackPlaylist.count(); - insertPos = trackClipStartList.value(trackNb - 1); + insertPos = trackClipStartList.value(trackNb); if (insertPos != -1) { insertPos += offset; @@ -1957,7 +1995,6 @@ void Render::mltInsertSpace(QMap trackClipStartList, QMap } trackPlaylist.consolidate_blanks(0); } - trackNb--; } // now move transitions mlt_service serv = m_mltProducer->parent().get_service(); @@ -2009,7 +2046,7 @@ void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest) } } -int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double oldspeed, int strobe, Mlt::Producer *prod) +int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod) { m_isBlocked = true; int newLength = 0; @@ -2044,6 +2081,7 @@ int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, dou QString serv = clipparent.get("mlt_service"); QString id = clipparent.get("id"); + if (speed <= 0 && speed > -1) speed = 1.0; //kDebug() << "CLIP SERVICE: " << serv; if (serv == "avformat" && (speed != 1.0 || strobe > 1)) { mlt_service_lock(service.get_service()); @@ -2064,8 +2102,12 @@ int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, dou // copy producer props double ar = original->parent().get_double("force_aspect_ratio"); if (ar != 0.0) slowprod->set("force_aspect_ratio", ar); + double fps = original->parent().get_double("force_fps"); + if (fps != 0.0) slowprod->set("force_fps", fps); int threads = original->parent().get_int("threads"); if (threads != 0) slowprod->set("threads", threads); + if (original->parent().get("force_progressive")) + slowprod->set("force_progressive", original->parent().get_int("force_progressive")); int ix = original->parent().get_int("video_index"); if (ix != 0) slowprod->set("video_index", ix); m_slowmotionProducers.insert(url, slowprod); @@ -2137,6 +2179,10 @@ int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, dou // copy producer props double ar = original->parent().get_double("force_aspect_ratio"); if (ar != 0.0) slowprod->set("force_aspect_ratio", ar); + double fps = original->parent().get_double("force_fps"); + if (fps != 0.0) slowprod->set("force_fps", fps); + if (original->parent().get("force_progressive")) + slowprod->set("force_progressive", original->parent().get_int("force_progressive")); int threads = original->parent().get_int("threads"); if (threads != 0) slowprod->set("threads", threads); int ix = original->parent().get_int("video_index"); @@ -2232,6 +2278,7 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para delete clip; const int filter_ix = params.paramValue("kdenlive_ix").toInt(); + const QString region = params.paramValue("region"); int ct = 0; Mlt::Filter *filter = clipService.filter(ct); while (filter) { @@ -2275,7 +2322,7 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para // create filter QString tag = params.paramValue("tag"); - kDebug() << " / / INSERTING EFFECT: " << tag; + kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region; if (tag.startsWith("ladspa")) tag = "ladspa"; char *filterTag = decodedString(tag); char *filterId = decodedString(params.paramValue("id")); @@ -2328,19 +2375,34 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para delete[] starttag; delete[] endtag; } else { - Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag); - if (filter && filter->is_valid()) + Mlt::Filter *filter; + QString prefix; + if (!region.isEmpty()) { + filter = new Mlt::Filter(*m_mltProfile, "region"); + } else filter = new Mlt::Filter(*m_mltProfile, filterTag); + if (filter && filter->is_valid()) { filter->set("kdenlive_id", filterId); - else { + if (!region.isEmpty()) { + char *tmp = decodedString(region); + filter->set("resource", tmp); + tmp = decodedString(params.paramValue("kdenlive_ix")); + filter->set("kdenlive_ix", tmp); + filter->set("filter0", filterTag); + prefix = "filter0."; + delete[] tmp; + params.removeParam("id"); + params.removeParam("region"); + params.removeParam("kdenlive_ix"); + } + } else { kDebug() << "filter is NULL"; m_isBlocked = false; return false; } - params.removeParam("kdenlive_id"); for (int j = 0; j < params.count(); j++) { - char *name = decodedString(params.at(j).name()); + char *name = decodedString(prefix + params.at(j).name()); char *value = decodedString(params.at(j).value()); filter->set(name, value); delete[] name; @@ -2353,7 +2415,8 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para params.removeParam("id"); params.removeParam("kdenlive_ix"); params.removeParam("tag"); - params.removeParam("disabled"); + params.removeParam("disable"); + params.removeParam("region"); for (int j = 0; j < params.count(); j++) { effectArgs.append(' ' + params.at(j).value()); @@ -2388,7 +2451,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par QString index = params.paramValue("kdenlive_ix"); QString tag = params.paramValue("tag"); - if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") { + if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) { // This is a keyframe effect, to edit it, we remove it and re-add it. mltRemoveEffect(track, position, index, false); bool success = mltAddEffect(track, position, params); @@ -2411,10 +2474,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par delete clip; m_isBlocked = true; int ct = 0; - Mlt::Filter *filter = clipService.filter(ct); - - /* - kDebug() << "EDITING FILTER: "<get("kdenlive_id") <<", IX: "<get("kdenlive_ix"); @@ -2422,9 +2482,10 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par filter = clipService.filter(ct); } kDebug() << "++++++++++++++++++++++++++"; - */ ct = 0; - filter = clipService.filter(ct); + filter = clipService.filter(ct); */ + + Mlt::Filter *filter = clipService.filter(ct); while (filter) { if (filter->get("kdenlive_ix") == index) { break; @@ -2441,9 +2502,12 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par m_isBlocked = false; return success; } + QString prefix; + QString ser = filter->get("mlt_service"); + if (ser == "region") prefix = "filter0."; mlt_service_lock(service.get_service()); for (int j = 0; j < params.count(); j++) { - char *name = decodedString(params.at(j).name()); + char *name = decodedString(prefix + params.at(j).name()); char *value = decodedString(params.at(j).value()); filter->set(name, value); delete[] name; @@ -2682,10 +2746,10 @@ bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) return false; } int previousStart = clip->get_in(); + int previousOut = clip->get_out(); delete clip; - int previousDuration = trackPlaylist.clip_length(clipIndex) - 1; m_isBlocked = true; - trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset); + trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset); m_isBlocked = false; mlt_service_unlock(service.get_service()); m_mltConsumer->set("refresh", 1); @@ -2694,7 +2758,7 @@ bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) { - //kDebug() << "//////// RSIZING CLIP from: "<parent().get_service()); int moveFrame = (int) diff.frames(m_fps); Mlt::Tractor tractor(service); @@ -2707,17 +2771,17 @@ bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) mlt_service_lock(service.get_service()); int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps)); Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); - if (clip == NULL) { + if (clip == NULL || clip->is_blank()) { kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!"; mlt_service_unlock(service.get_service()); return false; } int previousStart = clip->get_in(); + int previousOut = clip->get_out(); delete clip; - int previousDuration = trackPlaylist.clip_length(clipIndex) - 1; m_isBlocked = true; - kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame; - trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration); + //kDebug() << "RESIZE, old start: " << previousStart + moveFrame << ", " << previousStart + previousOut; + trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousOut); if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1); else { //int midpos = info.startPos.frames(m_fps) + moveFrame - 1; @@ -2767,8 +2831,7 @@ bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) kWarning() << "// TRACTOR PROBLEM"; return false; } - mlt_service_lock(m_mltConsumer->get_service()); - + mlt_service_lock(service.get_service()); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); @@ -2777,23 +2840,29 @@ bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) if (clipProducer == NULL || clipProducer->is_blank()) { kDebug() << "// ERROR UPDATING CLIP PROD"; delete clipProducer; - mlt_service_unlock(m_mltConsumer->get_service()); + mlt_service_unlock(service.get_service()); m_isBlocked--; return false; } Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out()); - if (!clip) return false; + if (!clip || !clip->is_valid()) { + if (clip) delete clip; + delete clipProducer; + mlt_service_unlock(service.get_service()); + m_isBlocked--; + return false; + } // move all effects to the correct producer mltPasteEffects(clipProducer, clip); trackPlaylist.insert_at(pos, clip, 1); delete clip; delete clipProducer; - mlt_service_unlock(m_mltConsumer->get_service()); + mlt_service_unlock(service.get_service()); m_isBlocked--; return true; } -bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool insert) +bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/) { m_isBlocked++; @@ -2812,10 +2881,12 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn bool checkLength = false; if (endTrack == startTrack) { Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex); - if (!overwrite && (!trackPlaylist.is_blank_at(moveEnd) || !clipProducer || clipProducer->is_blank())) { + if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) { // error, destination is not empty - if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1); - if (clipProducer) delete clipProducer; + if (clipProducer) { + if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1); + delete clipProducer; + } //int ix = trackPlaylist.get_clip_index_at(moveEnd); kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd; mlt_service_unlock(service.get_service()); @@ -2972,7 +3043,8 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n new_trans_props.inherit(trans_props); new_transition.set_in_and_out(new_in, new_out); field->disconnect_service(transition); - field->plant_transition(new_transition, newTransitionTrack, newTrack); + mltPlantTransition(field, new_transition, newTransitionTrack, newTrack); + //field->plant_transition(new_transition, newTransitionTrack, newTrack); } else transition.set_in_and_out(new_in, new_out); break; } @@ -2989,9 +3061,50 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n return found; } -void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) + +void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track) { - if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml); + mlt_service nextservice = mlt_service_get_producer(field->get_service()); + mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice); + QString mlt_type = mlt_properties_get(properties, "mlt_type"); + QString resource = mlt_properties_get(properties, "mlt_service"); + QList trList; + + while (mlt_type == "transition") { + Mlt::Transition transition((mlt_transition) nextservice); + int aTrack = transition.get_a_track(); + int bTrack = transition.get_b_track(); + if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) { + Mlt::Properties trans_props(transition.get_properties()); + char *tmp = decodedString(transition.get("mlt_service")); + Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, tmp); + delete[] tmp; + Mlt::Properties new_trans_props(cp->get_properties()); + new_trans_props.inherit(trans_props); + trList.append(cp); + field->disconnect_service(transition); + } + //else kDebug() << "// FOUND TRANS OK, "<plant_transition(tr, a_track, b_track); + + // re-add upper transitions + for (int i = 0; i < trList.count(); i++) { + // kDebug()<< "REPLANT ON TK: "<get_a_track()<<", "<get_b_track(); + field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track()); + } +} + +void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force) +{ + if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml); else { mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false); mltAddTransition(tag, a_track, b_track, in, out, xml, false); @@ -3308,8 +3421,9 @@ bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, delete[] name; delete[] value; } - // attach filter to the clip - field->plant_transition(*transition, a_track, b_track); + // attach transition + mltPlantTransition(field, *transition, a_track, b_track); + // field->plant_transition(*transition, a_track, b_track); delete[] transId; if (do_refresh) refresh(); return true; @@ -3501,13 +3615,13 @@ void Render::mltDeleteTrack(int ix) int a_track = mappedProps.value("a_track").toInt(); int b_track = mappedProps.value("b_track").toInt(); if (a_track > 0 && a_track >= ix) a_track --; - if (b_track > 0 && b_track > ix) b_track --; if (b_track == ix) { // transition was on the deleted track, so remove it tractor.removeChild(transitions.at(i)); i--; continue; } + if (b_track > 0 && b_track > ix) b_track --; for (int j = 0; j < props.count(); j++) { QDomElement f = props.at(j).toElement(); if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));