X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Frenderer.cpp;h=acc2c3888a12c2f3f8aa795669ff8d37686460c3;hb=33b512d9309f5d4efbe08fbb9ba6f44aacae12e4;hp=7bfb8473bfa2c99b9df6af3ac79c7a05877c9400;hpb=1230e3912b72b4fed3cf9dc6ec2453ba5813a95d;p=kdenlive diff --git a/src/renderer.cpp b/src/renderer.cpp index 7bfb8473..acc2c388 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -42,6 +42,16 @@ #include + + +static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl) +{ + if (level > MLT_LOG_ERROR) return; + QString error; + QApplication::postEvent(qApp->activeWindow() , new MltErrorEvent(error.vsprintf(fmt, vl).simplified())); +} + + static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) { // detect if the producer has finished playing. Is there a better way to do it? @@ -55,7 +65,7 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget *parent) : QObject(parent), - m_isBlocked(true), + m_isBlocked(0), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), @@ -67,13 +77,11 @@ Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget m_winid(winid) { kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data(); - m_refreshTimer = new QTimer(this); - connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); /*if (rendererName == "project") m_monitorId = 10000; else m_monitorId = 10001;*/ - m_osdTimer = new QTimer(this); - connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout())); + /*m_osdTimer = new QTimer(this); + connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));*/ buildConsumer(); @@ -84,14 +92,30 @@ Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget Render::~Render() { + m_isBlocked = 1; closeMlt(); } void Render::closeMlt() { - delete m_osdTimer; - delete m_refreshTimer; + //delete m_osdTimer; + if (m_mltProducer) { + 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)); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); + trackPlaylist.clear(); + trackNb--; + } + } + } + + kDebug() << "// // // CLOSE RENDERER " << m_name; delete m_mltConsumer; delete m_mltProducer; delete m_blackClip; @@ -133,6 +157,7 @@ void Render::buildConsumer() // FIXME: the event object returned by the listen gets leaked... m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); m_mltConsumer->set("rescale", "nearest"); + mlt_log_set_callback(kdenlive_callback); QString audioDevice = KdenliveSettings::audiodevicename(); if (!audioDevice.isEmpty()) { @@ -148,8 +173,13 @@ void Render::buildConsumer() } QString audioDriver = KdenliveSettings::audiodrivername(); + + /* + // Disabled because the "auto" detected driver was sometimes wrong if (audioDriver.isEmpty()) audioDriver = KdenliveSettings::autoaudiodrivername(); + */ + if (!audioDriver.isEmpty()) { tmp = decodedString(audioDriver); m_mltConsumer->set("audio_driver", tmp); @@ -181,15 +211,31 @@ int Render::resetProfile() m_mltConsumer = NULL; QString scene = sceneList(); int pos = 0; + + delete m_blackClip; + m_blackClip = NULL; + if (m_mltProducer) { pos = m_mltProducer->position(); + + 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)); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); + trackPlaylist.clear(); + trackNb--; + } + } + delete m_mltProducer; } m_mltProducer = NULL; - //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards... - /*if (m_mltProfile) delete m_mltProfile; - m_mltProfile = NULL;*/ + if (m_mltProfile) delete m_mltProfile; + m_mltProfile = NULL; buildConsumer(); @@ -495,14 +541,23 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo { KUrl url = KUrl(xml.attribute("resource", QString())); Mlt::Producer *producer = NULL; - if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) { + /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) { emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer); return; - } + }*/ if (xml.attribute("type").toInt() == COLOR) { char *tmp = decodedString("colour:" + xml.attribute("colour")); producer = new Mlt::Producer(*m_mltProfile, 0, tmp); delete[] tmp; + } else if (xml.attribute("type").toInt() == TEXT) { + 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")); + producer->set("xmldata", tmp); + delete[] tmp; + } } else if (url.isEmpty()) { QDomDocument doc; QDomElement mlt = doc.createElement("mlt"); @@ -549,6 +604,12 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo producer->set("id", tmp); delete[] tmp; + if (!replaceProducer && xml.hasAttribute("file_hash")) { + // Clip already has all properties + emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer); + return; + } + int height = 50; int width = (int)(height * m_mltProfile->dar()); QMap < QString, QString > filePropertyMap; @@ -603,25 +664,18 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo else filePropertyMap["type"] = "video"; - mlt_image_format format = mlt_image_yuv422; - int frame_width = 0; - int frame_height = 0; - //frame->set("rescale.interp", "hyper"); - frame->set("normalised_height", height); - frame->set("normalised_width", width); + mlt_image_format format = mlt_image_rgb24a; + int frame_width = width; + int frame_height = height; QPixmap pix(width, height); - uint8_t *data = frame->get_image(format, frame_width, frame_height, 0); - uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4); - mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height); - QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32); + QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32); if (!image.isNull()) { pix = QPixmap::fromImage(image.rgbSwapped()); } else pix.fill(Qt::black); - mlt_pool_release(new_image); emit replyGetImage(clipId, pix); } else if (frame->get_int("test_audio") == 0) { @@ -757,13 +811,13 @@ void Render::initSceneList() /** Create the producer from the MLT XML QDomDocument */ -void Render::setProducer(Mlt::Producer *producer, int position) +int Render::setProducer(Mlt::Producer *producer, int position) { - if (m_winid == -1) return; + if (m_winid == -1) return -1; if (m_mltConsumer) { m_mltConsumer->stop(); - } else return; + } else return -1; m_mltConsumer->purge(); @@ -784,27 +838,29 @@ void Render::setProducer(Mlt::Producer *producer, int position) if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: "; m_fps = m_mltProducer->get_fps(); - connectPlaylist(); + int error = connectPlaylist(); if (position != -1) { m_mltProducer->seek(position); emit rendererPosition(position); } m_isBlocked = false; + return error; } /** Create the producer from the MLT XML QDomDocument */ -void Render::setSceneList(QDomDocument list, int position) +int Render::setSceneList(QDomDocument list, int position) { - setSceneList(list.toString(), position); + return setSceneList(list.toString(), position); } /** Create the producer from the MLT XML QDomDocument */ -void Render::setSceneList(QString playlist, int position) +int Render::setSceneList(QString playlist, int position) { - if (m_winid == -1) return; + if (m_winid == -1) return -1; m_isBlocked = true; + int error; qDeleteAll(m_slowmotionProducers.values()); m_slowmotionProducers.clear(); @@ -813,7 +869,7 @@ void Render::setSceneList(QString playlist, int position) if (m_mltConsumer == NULL) { kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER"; m_isBlocked = false; - return; + return -1; } if (!m_mltConsumer->is_stopped()) { @@ -825,6 +881,19 @@ void Render::setSceneList(QString playlist, int position) m_mltProducer->set_speed(0); //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo); + + 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)); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); + trackPlaylist.clear(); + trackNb--; + } + } + delete m_mltProducer; m_mltProducer = NULL; emit stopped(); @@ -872,12 +941,13 @@ void Render::setSceneList(QString playlist, int position) } kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime(); - connectPlaylist(); + error = connectPlaylist(); fillSlowMotionProducers(); m_isBlocked = false; blockSignals(false); emit refreshDocumentProducers(); + return error; //kDebug()<<"// SETSCN LST, POS: "<set("refresh", "0"); m_mltConsumer->connect(*m_mltProducer); m_mltProducer->set_speed(0); - m_mltConsumer->start(); + 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; + return -1; + } emit durationChanged(m_mltProducer->get_playtime()); + return 0; //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.")); - delete m_mltConsumer; - m_mltConsumer = NULL; - } - else { - refresh(); - }*/ } void Render::refreshDisplay() @@ -1019,7 +1089,7 @@ void Render::setVolume(double /*volume*/) if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter"; }*/ refresh(); - m_osdTimer->setSingleShot(2500); + //m_osdTimer->setSingleShot(2500); } void Render::slotOsdTimeout() @@ -1038,14 +1108,13 @@ void Render::start() kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART"; return; } - 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.")); - delete m_mltConsumer; - m_mltConsumer = NULL; - return; + emit blockMonitors(); + delete m_mltProducer; + m_mltProducer = NULL; } else { kDebug() << "----- MONITOR: " << m_name << " REFRESH"; m_isBlocked = false; @@ -1055,25 +1124,9 @@ void Render::start() m_isBlocked = false; } -void Render::clear() -{ - kDebug() << " ********* RENDER CLEAR"; - if (m_mltConsumer) { - //m_mltConsumer->set("refresh", 0); - if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); - } - - if (m_mltProducer) { - //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo); - m_mltProducer->set_speed(0.0); - delete m_mltProducer; - m_mltProducer = NULL; - emit stopped(); - } -} - void Render::stop() { + if (m_mltProducer == NULL) return; if (m_mltConsumer && !m_mltConsumer->is_stopped()) { kDebug() << "///////////// RENDER STOPPED: " << m_name; m_isBlocked = true; @@ -1218,10 +1271,15 @@ void Render::seekToFrame(int pos) refresh(); } -void Render::askForRefresh() +void Render::seekToFrameDiff(int diff) { - // Use a Timer so that we don't refresh too much - m_refreshTimer->start(200); + //kDebug()<<" ********* RENDER SEEK TO POS"; + if (!m_mltProducer) + return; + m_isBlocked = false; + resetZoneMode(); + m_mltProducer->seek(m_mltProducer->position() + diff); + refresh(); } void Render::doRefresh() @@ -1234,12 +1292,27 @@ void Render::refresh() { if (!m_mltProducer || m_isBlocked) return; - m_refreshTimer->stop(); if (m_mltConsumer) { m_mltConsumer->set("refresh", 1); } } +void Render::setDropFrames(bool show) +{ + if (m_mltConsumer) { + int dropFrames = 1; + if (show == false) dropFrames = 0; + m_mltConsumer->stop(); + m_mltConsumer->set("play.real_time", dropFrames); + if (m_mltConsumer->start() == -1) { + emit blockMonitors(); + delete m_mltProducer; + m_mltProducer = NULL; + } + + } +} + double Render::playSpeed() { if (m_mltProducer) return m_mltProducer->get_speed(); @@ -1252,6 +1325,11 @@ GenTime Render::seekPosition() const else return GenTime(); } +int Render::seekFramePosition() const +{ + if (m_mltProducer) return (int) m_mltProducer->position(); + return 0; +} const QString & Render::rendererName() const { @@ -1316,83 +1394,103 @@ void Render::exportCurrentFrame(KUrl url, bool /*notify*/) /** MLT PLAYLIST DIRECT MANIPULATON **/ -void Render::mltCheckLength() +void Render::mltCheckLength(Mlt::Tractor *tractor) { //kDebug()<<"checking track length: "<get_service()); - Mlt::Tractor tractor(service); - - int trackNb = tractor.count(); + int trackNb = tractor->count(); int duration = 0; int trackDuration; if (trackNb == 1) { - Mlt::Producer trackProducer(tractor.track(0)); + Mlt::Producer trackProducer(tractor->track(0)); duration = trackProducer.get_playtime() - 1; m_mltProducer->set("out", duration); emit durationChanged(duration); return; } while (trackNb > 1) { - Mlt::Producer trackProducer(tractor.track(trackNb - 1)); + Mlt::Producer trackProducer(tractor->track(trackNb - 1)); trackDuration = trackProducer.get_playtime() - 1; - //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration; if (trackDuration > duration) duration = trackDuration; trackNb--; } - Mlt::Producer blackTrackProducer(tractor.track(0)); + Mlt::Producer blackTrackProducer(tractor->track(0)); if (blackTrackProducer.get_playtime() - 1 != duration) { Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service()); Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0); - if (duration > m_blackClip->get_length()) { - m_blackClip->set("length", duration); - if (blackclip) blackclip->set("length", duration); + if (blackclip && blackclip->is_blank()) { + delete blackclip; + blackclip = NULL; } - if (blackclip == NULL || blackclip->is_blank() || blackTrackPlaylist.count() != 1) { + + if (blackclip == NULL || blackTrackPlaylist.count() != 1) { blackTrackPlaylist.clear(); - blackTrackPlaylist.append(*m_blackClip, 0, duration - 1); - } else blackTrackPlaylist.resize_clip(0, 0, duration - 1); + m_blackClip->set("length", duration); + m_blackClip->set("out", duration - 1); + blackclip = m_blackClip->cut(0, duration - 1); + 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); + } + blackTrackPlaylist.resize_clip(0, 0, duration - 1); + } + delete blackclip; m_mltProducer->set("out", duration); emit durationChanged(duration); } } -void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) +int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) { if (m_mltProducer == NULL) { kDebug() << "PLAYLIST NOT INITIALISED //////"; - return; + return -1; } Mlt::Producer parentProd(m_mltProducer->parent()); if (parentProd.get_producer() == NULL) { kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////"; - return; + return -1; } Mlt::Service service(parentProd.get_service()); + if (service.type() != tractor_type) { + kWarning() << "// TRACTOR PROBLEM"; + return -1; + } Mlt::Tractor tractor(service); + if (info.track > tractor.count() - 1) { + kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25); + return -1; + } mlt_service_lock(service.get_service()); Mlt::Producer trackProducer(tractor.track(info.track)); 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; @@ -1402,16 +1500,16 @@ void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pr } Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1); - int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1); - + int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), clip, 1); + delete clip; /*if (QString(prod->get("transparency")).toInt() == 1) mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/ + if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor); mlt_service_unlock(service.get_service()); - - if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(); - //tractor.multitrack()->refresh(); - //tractor.refresh(); + /*tractor.multitrack()->refresh(); + tractor.refresh();*/ + return 0; } @@ -1460,6 +1558,8 @@ void Render::mltCutClip(int track, GenTime position) } Mlt::Service clipService(original->get_service()); Mlt::Service dupService(clip->get_service()); + delete original; + delete clip; int ct = 0; Mlt::Filter *filter = clipService.filter(ct); while (filter) { @@ -1470,7 +1570,7 @@ void Render::mltCutClip(int track, GenTime position) Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service")); if (dup && dup->is_valid()) { Mlt::Properties entries(filter->get_properties()); - for (int i = 0;i < entries.count();i++) { + for (int i = 0; i < entries.count(); i++) { dup->set(entries.get_name(i), entries.get(i)); } dupService.attach(*dup); @@ -1507,27 +1607,29 @@ bool Render::mltRemoveClip(int track, GenTime position) if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM"; Mlt::Tractor tractor(service); + mlt_service_lock(service.get_service()); Mlt::Producer trackProducer(tractor.track(track)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps)); - /* // Display playlist info - kDebug()<<"//// BEFORE"; - for (int i = 0; i < trackPlaylist.count(); i++) { + // Display playlist info + //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------"; + /*for (int i = 0; i < trackPlaylist.count(); i++) { int blankStart = trackPlaylist.clip_start(i); int blankDuration = trackPlaylist.clip_length(i) - 1; QString blk; if (trackPlaylist.is_blank(i)) blk = "(blank)"; kDebug()<<"CLIP "< trackClipStartList, QMap if (!trackPlaylist.is_blank(clipIndex)) clipIndex --; if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos; int position = trackPlaylist.clip_start(clipIndex); - trackPlaylist.remove_region(position, - diff - 1); + int blankDuration = trackPlaylist.clip_length(clipIndex); + diff = -diff; + if (blankDuration - diff == 0) + trackPlaylist.remove(clipIndex); + else trackPlaylist.remove_region(position, diff); } trackPlaylist.consolidate_blanks(0); } @@ -1681,7 +1787,10 @@ void Render::mltInsertSpace(QMap trackClipStartList, QMap if (!trackPlaylist.is_blank(clipIndex)) clipIndex --; if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos; int position = trackPlaylist.clip_start(clipIndex); - trackPlaylist.remove_region(position, - diff - 1); + int blankDuration = trackPlaylist.clip_length(clipIndex); + if (diff + blankDuration == 0) + trackPlaylist.remove(clipIndex); + else trackPlaylist.remove_region(position, - diff); } trackPlaylist.consolidate_blanks(0); } @@ -1714,11 +1823,29 @@ void Render::mltInsertSpace(QMap trackClipStartList, QMap } } mlt_service_unlock(service.get_service()); - mltCheckLength(); + mltCheckLength(&tractor); m_mltConsumer->set("refresh", 1); } -int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) + +void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest) +{ + Mlt::Service sourceService(source->get_service()); + Mlt::Service destService(dest->get_service()); + + // move all effects to the correct producer + int ct = 0; + Mlt::Filter *filter = sourceService.filter(ct); + while (filter) { + if (filter->get("kdenlive_ix") != 0) { + sourceService.detach(*filter); + destService.attach(*filter); + } else ct++; + filter = sourceService.filter(ct); + } +} + +int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, int strobe, Mlt::Producer *prod) { m_isBlocked = true; int newLength = 0; @@ -1732,35 +1859,44 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt int clipIndex = trackPlaylist.get_clip_index_at(startPos); int clipLength = trackPlaylist.clip_length(clipIndex); - Mlt::Producer clip(trackPlaylist.get_clip(clipIndex)); - if (!clip.is_valid() || clip.is_blank()) { + Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); + if (clip == NULL) { + return -1; + } + if (!clip->is_valid() || clip->is_blank()) { // invalid clip + delete clip; return -1; } - Mlt::Producer clipparent = clip.parent(); + Mlt::Producer clipparent = clip->parent(); if (!clipparent.is_valid() || clipparent.is_blank()) { // invalid clip + delete clip; return -1; } + QString serv = clipparent.get("mlt_service"); QString id = clipparent.get("id"); //kDebug() << "CLIP SERVICE: " << serv; - if (serv == "avformat" && speed != 1.0) { + if (serv == "avformat" && (speed != 1.0 || strobe > 1)) { mlt_service_lock(service.get_service()); QString url = QString::fromUtf8(clipparent.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 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); } - trackPlaylist.replace_with_blank(clipIndex); + Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex); trackPlaylist.consolidate_blanks(0); // Check that the blank space is long enough for our new duration clipIndex = trackPlaylist.get_clip_index_at(startPos); @@ -1770,14 +1906,19 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos; cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1)); } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1)); - trackPlaylist.insert_at(startPos, *cut, 1); + + // move all effects to the correct producer + mltPasteEffects(clip, cut); + trackPlaylist.insert_at(startPos, cut, 1); + delete cut; + delete clip; clipIndex = trackPlaylist.get_clip_index_at(startPos); newLength = trackPlaylist.clip_length(clipIndex); mlt_service_unlock(service.get_service()); - } else if (speed == 1.0) { + } else if (speed == 1.0 && strobe < 2) { mlt_service_lock(service.get_service()); - trackPlaylist.replace_with_blank(clipIndex); + Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex); trackPlaylist.consolidate_blanks(0); // Check that the blank space is long enough for our new duration @@ -1791,7 +1932,13 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos; cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1)); } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1); - trackPlaylist.insert_at(startPos, *cut, 1); + + // move all effects to the correct producer + mltPasteEffects(clip, cut); + + trackPlaylist.insert_at(startPos, cut, 1); + delete cut; + delete clip; clipIndex = trackPlaylist.get_clip_index_at(startPos); newLength = trackPlaylist.clip_length(clipIndex); mlt_service_unlock(service.get_service()); @@ -1801,22 +1948,25 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt QString url = QString::fromUtf8(clipparent.get("resource")); url = url.section('?', 0, 0); 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); delete[] tmp; + slowprod->set("strobe", strobe); QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + 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); } - trackPlaylist.replace_with_blank(clipIndex); + Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex); trackPlaylist.consolidate_blanks(0); GenTime oldDuration = GenTime(clipLength, m_fps); - GenTime newDuration = oldDuration * oldspeed / speed; + GenTime newDuration = oldDuration * (oldspeed / speed); // Check that the blank space is long enough for our new duration clipIndex = trackPlaylist.get_clip_index_at(startPos); @@ -1828,20 +1978,26 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1)); } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1)); - trackPlaylist.insert_at(startPos, *cut, 1); + // move all effects to the correct producer + mltPasteEffects(clip, cut); + + trackPlaylist.insert_at(startPos, cut, 1); + delete cut; + delete clip; clipIndex = trackPlaylist.get_clip_index_at(startPos); newLength = trackPlaylist.clip_length(clipIndex); mlt_service_unlock(service.get_service()); } - if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(); + + delete clip; + if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor); m_isBlocked = false; return newLength; } bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh) { - kDebug() << "// TRYing to remove effect at: " << index; Mlt::Service service(m_mltProducer->parent().get_service()); bool success = false; Mlt::Tractor tractor(service); @@ -1854,6 +2010,7 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool up return success; } Mlt::Service clipService(clip->get_service()); + delete clip; // if (tag.startsWith("ladspa")) tag = "ladspa"; m_isBlocked = true; int ct = 0; @@ -1861,7 +2018,7 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool up while (filter) { if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) { if (clipService.detach(*filter) == 0) success = true; - kDebug() << " / / / DLEETED EFFECT: " << ct; + //kDebug()<<"Deleted filter id:"<get("kdenlive_id")<<", ix:"<get("kdenlive_ix")<<", SERVICE:"<get("mlt_service"); } else if (updateIndex) { // Adjust the other effects index if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1); @@ -1890,7 +2047,7 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para } Mlt::Service clipService(clip->get_service()); m_isBlocked = true; - + delete clip; // temporarily remove all effects after insert point QList filtersList; const int filter_ix = params.paramValue("kdenlive_ix").toInt(); @@ -2020,12 +2177,12 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") { // This is a keyframe effect, to edit it, we remove it and re-add it. - mltRemoveEffect(track, position, index, true); + mltRemoveEffect(track, position, index, false); bool success = mltAddEffect(track, position, params); return success; } - // create filter + // find filter Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); @@ -2038,6 +2195,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par return false; } Mlt::Service clipService(clip->get_service()); + delete clip; m_isBlocked = true; int ct = 0; Mlt::Filter *filter = clipService.filter(ct); @@ -2071,7 +2229,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par m_isBlocked = false; return success; } - + mlt_service_lock(service.get_service()); for (int j = 0; j < params.count(); j++) { char *name = decodedString(params.at(j).name()); char *value = decodedString(params.at(j).value()); @@ -2079,6 +2237,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par delete[] name; delete[] value; } + mlt_service_unlock(service.get_service()); m_isBlocked = false; refresh(); @@ -2101,6 +2260,7 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) return; } Mlt::Service clipService(clip->get_service()); + delete clip; m_isBlocked = true; int ct = 0; QList filtersList; @@ -2160,9 +2320,7 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) { m_isBlocked = true; - Mlt::Service service(m_mltProducer->parent().get_service()); - Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(info.track)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); @@ -2182,16 +2340,23 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) m_isBlocked = false; return false; } + mlt_service_lock(service.get_service()); int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps)); //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex); Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); int previousStart = clip->get_in(); int newDuration = (int) clipDuration.frames(m_fps) - 1; - int diff = newDuration - trackPlaylist.clip_length(clipIndex) - 1; + int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1); if (newDuration > clip->get_length()) { clip->parent().set("length", newDuration + 1); + clip->parent().set("out", newDuration); clip->set("length", newDuration + 1); } + if (newDuration > clip->get_out()) { + clip->parent().set_in_and_out(0, newDuration + 1); + clip->set_in_and_out(0, newDuration + 1); + } + delete clip; trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart); trackPlaylist.consolidate_blanks(0); // skip to next clip @@ -2203,21 +2368,20 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) // If this is not the last clip in playlist if (trackPlaylist.is_blank(clipIndex)) { int blankStart = trackPlaylist.clip_start(clipIndex); - int blankDuration = trackPlaylist.clip_length(clipIndex) - 1; + int blankDuration = trackPlaylist.clip_length(clipIndex); if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!"; - if (diff - blankDuration == 1) { + if (diff - blankDuration == 0) { trackPlaylist.remove(clipIndex); - } else trackPlaylist.remove_region(blankStart, diff - 1); + } else trackPlaylist.remove_region(blankStart, diff); } else { kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex; } } } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1); - trackPlaylist.consolidate_blanks(0); + mlt_service_unlock(service.get_service()); - - if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(); + if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor); /*if (QString(clip->parent().get("transparency")).toInt() == 1) { //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt()); mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt()); @@ -2272,6 +2436,7 @@ bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) return false; } int previousStart = clip->get_in(); + delete clip; int previousDuration = trackPlaylist.clip_length(clipIndex) - 1; m_isBlocked = true; trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset); @@ -2302,6 +2467,7 @@ bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) return false; } int previousStart = clip->get_in(); + delete clip; int previousDuration = trackPlaylist.clip_length(clipIndex) - 1; m_isBlocked = true; kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame; @@ -2348,7 +2514,7 @@ void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) return; } kDebug() << "NEW PROD ID: " << prod->get("id"); - m_mltConsumer->set("refresh", 0); + m_isBlocked++; kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track; mlt_service_lock(m_mltConsumer->get_service()); Mlt::Service service(m_mltProducer->parent().get_service()); @@ -2358,62 +2524,54 @@ void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) Mlt::Producer trackProducer(tractor.track(track)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); int clipIndex = trackPlaylist.get_clip_index_at(pos + 1); - Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex)); - if (clipProducer.is_blank()) { + Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex); + if (clipProducer->is_blank()) { kDebug() << "// ERROR UPDATING CLIP PROD"; + delete clipProducer; mlt_service_unlock(m_mltConsumer->get_service()); - m_isBlocked = false; + m_isBlocked--; return; } - Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out()); + Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out()); // move all effects to the correct producer - Mlt::Service clipService(clipProducer.get_service()); - Mlt::Service newClipService(clip->get_service()); - - int ct = 0; - Mlt::Filter *filter = clipService.filter(ct); - while (filter) { - if (filter->get("kdenlive_ix") != 0) { - clipService.detach(*filter); - newClipService.attach(*filter); - } else ct++; - filter = clipService.filter(ct); - } - + mltPasteEffects(clipProducer, clip); trackPlaylist.insert_at(pos, clip, 1); + delete clip; + delete clipProducer; mlt_service_unlock(m_mltConsumer->get_service()); - m_isBlocked = false; + m_isBlocked--; } bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) { - m_isBlocked = true; + m_isBlocked++; - m_mltConsumer->set("refresh", 0); - mlt_service_lock(m_mltConsumer->get_service()); Mlt::Service service(m_mltProducer->parent().get_service()); if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM"; Mlt::Tractor tractor(service); + mlt_service_lock(service.get_service()); Mlt::Producer trackProducer(tractor.track(startTrack)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); - int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1); + int clipIndex = trackPlaylist.get_clip_index_at(moveStart); kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex; bool checkLength = false; if (endTrack == startTrack) { - Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex)); - if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) { + Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex); + if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer->is_blank()) { // error, destination is not empty if (!trackPlaylist.is_blank_at(moveEnd)) 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(m_mltConsumer->get_service()); - m_isBlocked = false; + mlt_service_unlock(service.get_service()); + m_isBlocked--; return false; } else { trackPlaylist.consolidate_blanks(0); int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1); + delete clipProducer; /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) { mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt()); }*/ @@ -2425,52 +2583,49 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service()); if (!destTrackPlaylist.is_blank_at(moveEnd)) { // error, destination is not empty - mlt_service_unlock(m_mltConsumer->get_service()); - m_isBlocked = false; + mlt_service_unlock(service.get_service()); + m_isBlocked--; return false; } else { - Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex)); - if (clipProducer.is_blank()) { + Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex); + if (clipProducer->is_blank()) { // error, destination is not empty //int ix = trackPlaylist.get_clip_index_at(moveEnd); + delete clipProducer; kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd; - mlt_service_unlock(m_mltConsumer->get_service()); - m_isBlocked = false; + mlt_service_unlock(service.get_service()); + m_isBlocked--; return false; } trackPlaylist.consolidate_blanks(0); destTrackPlaylist.consolidate_blanks(1); Mlt::Producer *clip; // check if we are moving a slowmotion producer - QString serv = clipProducer.parent().get("mlt_service"); - QString currentid = clipProducer.parent().get("id"); + QString serv = clipProducer->parent().get("mlt_service"); + QString currentid = clipProducer->parent().get("id"); if (serv == "framebuffer" || currentid.endsWith("_video")) { - clip = &clipProducer; + clip = clipProducer; } else { if (prod == NULL) { // Special case: prod is null when using placeholder clips. // in that case, use the producer existing in playlist. Note that // it will bypass the one producer per track logic and might cause // Sound cracks if clip is moved so that it overlaps another copy of itself - clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out()); - } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out()); + clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out()); + } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out()); } // move all effects to the correct producer - Mlt::Service clipService(clipProducer.get_service()); - Mlt::Service newClipService(clip->get_service()); - - int ct = 0; - Mlt::Filter *filter = clipService.filter(ct); - while (filter) { - if (filter->get("kdenlive_ix") != 0) { - clipService.detach(*filter); - newClipService.attach(*filter); - } else ct++; - filter = clipService.filter(ct); - } + mltPasteEffects(clipProducer, clip); int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1); + if (clip == clipProducer) { + delete clip; + clip = NULL; + } else { + delete clip; + delete clipProducer; + } destTrackPlaylist.consolidate_blanks(0); /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) { kDebug() << "//////// moving clip transparency"; @@ -2480,11 +2635,11 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true; } } - - if (checkLength) mltCheckLength(); - mlt_service_unlock(m_mltConsumer->get_service()); - m_isBlocked = false; - m_mltConsumer->set("refresh", 1); + mlt_service_unlock(service.get_service()); + if (checkLength) mltCheckLength(&tractor); + m_isBlocked--; + //askForRefresh(); + //m_mltConsumer->set("refresh", 1); return true; } @@ -2494,14 +2649,12 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n int new_out = (int)newOut.frames(m_fps) - 1; if (new_in >= new_out) return false; - Mlt::Service service(m_mltProducer->parent().get_service()); - Mlt::Tractor tractor(service); + mlt_service serv = m_mltProducer->parent().get_service(); + m_isBlocked++; + mlt_service_lock(serv); + //m_mltConsumer->set("refresh", 0); - mlt_service_lock(service.get_service()); - m_mltConsumer->set("refresh", 0); - m_isBlocked = true; - mlt_service serv = m_mltProducer->parent().get_service(); mlt_service nextservice = mlt_service_get_producer(serv); mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice); QString mlt_type = mlt_properties_get(properties, "mlt_type"); @@ -2517,7 +2670,7 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) { mlt_transition_set_in_and_out(tr, new_in, new_out); if (newTrack - startTrack != 0) { - kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack; + //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack; mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr); mlt_properties_set_int(properties, "a_track", newTransitionTrack); @@ -2532,31 +2685,29 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n mlt_type = mlt_properties_get(properties, "mlt_type"); resource = mlt_properties_get(properties, "mlt_service"); } - m_isBlocked = false; - mlt_service_unlock(service.get_service()); - m_mltConsumer->set("refresh", 1); + mlt_service_unlock(serv); + m_isBlocked--; + refresh(); + //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1); return true; } void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) { - // kDebug() << "update transition" << tag << " at pos " << in.frames(25); if (oldTag == tag) 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); + mltAddTransition(tag, a_track, b_track, in, out, xml, false); } + refresh(); //mltSavePlaylist(); } void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) { - m_isBlocked = true; - Mlt::Service service(m_mltProducer->parent().get_service()); - Mlt::Tractor tractor(service); - - //m_mltConsumer->set("refresh", 0); mlt_service serv = m_mltProducer->parent().get_service(); + mlt_service_lock(serv); + m_isBlocked++; mlt_service nextservice = mlt_service_get_producer(serv); mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice); @@ -2580,6 +2731,10 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G QString key; mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr); mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt()); + // update the transition id in case it uses the same MLT service but different Kdenlive id + char *tmp = decodedString(xml.attribute("id")); + mlt_properties_set(transproperties, "kdenlive_id", tmp); + delete[] tmp; if (currentBTrack != a_track) { mlt_properties_set_int(properties, "a_track", a_track); } @@ -2601,18 +2756,23 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G mlt_type = mlt_properties_get(properties, "mlt_type"); resource = mlt_properties_get(properties, "mlt_service"); } - m_isBlocked = false; - m_mltConsumer->set("refresh", 1); + mlt_service_unlock(serv); + m_isBlocked--; + //askForRefresh(); + //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1); } void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/) { - Mlt::Service service(m_mltProducer->parent().get_service()); + mlt_service serv = m_mltProducer->parent().get_service(); + m_isBlocked++; + mlt_service_lock(serv); + + Mlt::Service service(serv); Mlt::Tractor tractor(service); Mlt::Field *field = tractor.field(); //if (do_refresh) m_mltConsumer->set("refresh", 0); - mlt_service serv = m_mltProducer->parent().get_service(); mlt_service nextservice = mlt_service_get_producer(serv); mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice); @@ -2620,6 +2780,7 @@ void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenT QString resource = mlt_properties_get(properties, "mlt_service"); const int old_pos = (int)((in + out).frames(m_fps) / 2); + kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25); while (mlt_type == "transition") { mlt_transition tr = (mlt_transition) nextservice; @@ -2638,14 +2799,17 @@ void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenT mlt_type = mlt_properties_get(properties, "mlt_type"); resource = mlt_properties_get(properties, "mlt_service"); } - //if (do_refresh) m_mltConsumer->set("refresh", 1); + mlt_service_unlock(serv); + m_isBlocked--; + //askForRefresh(); + //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1); } QMap Render::mltGetTransitionParamsFromXml(QDomElement xml) { QDomNodeList attribs = xml.elementsByTagName("parameter"); QMap map; - for (int i = 0;i < attribs.count();i++) { + for (int i = 0; i < attribs.count(); i++) { QDomElement e = attribs.item(i).toElement(); QString name = e.attribute("name"); //kDebug()<<"-- TRANSITION PARAM: "< Render::mltGetTransitionParamsFromXml(QDomElement xml) if (values.size() > 0) txtNeu << (int)values[0].toDouble(); int i = 0; - for (i = 0;i < separators.size() && i + 1 < values.size();i++) { + for (i = 0; i < separators.size() && i + 1 < values.size(); i++) { txtNeu << separators[i]; txtNeu << (int)(values[i+1].toDouble()); } @@ -2739,7 +2903,7 @@ void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int t mlt_service_lock(service.get_service()); m_mltConsumer->set("refresh", 0); - m_isBlocked = true; + m_isBlocked++; mlt_service serv = m_mltProducer->parent().get_service(); mlt_service nextservice = mlt_service_get_producer(serv); @@ -2765,9 +2929,9 @@ void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int t mlt_type = mlt_properties_get(properties, "mlt_type"); resource = mlt_properties_get(properties, "mlt_service"); } - m_isBlocked = false; mlt_service_unlock(service.get_service()); - m_mltConsumer->set("refresh", 1); + m_isBlocked--; + if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1); } @@ -2778,7 +2942,7 @@ void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int mlt_service_lock(service.get_service()); m_mltConsumer->set("refresh", 0); - m_isBlocked = true; + m_isBlocked++; mlt_service serv = m_mltProducer->parent().get_service(); mlt_service nextservice = mlt_service_get_producer(serv); @@ -2811,13 +2975,13 @@ void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int mlt_type = mlt_properties_get(properties, "mlt_type"); resource = mlt_properties_get(properties, "mlt_service"); } - m_isBlocked = false; + m_isBlocked--; mlt_service_unlock(service.get_service()); m_mltConsumer->set("refresh", 1); } -bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/) +bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) { if (in >= out) return false; QMap args = mltGetTransitionParamsFromXml(xml); @@ -2849,7 +3013,7 @@ bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, // attach filter to the clip field->plant_transition(*transition, a_track, b_track); delete[] transId; - refresh(); + if (do_refresh) refresh(); return true; } @@ -2868,6 +3032,7 @@ void Render::mltSavePlaylist() QList Render::producersList() { QList prods; + if (m_mltProducer == NULL) return prods; Mlt::Service service(m_mltProducer->parent().get_service()); if (service.type() != tractor_type) return prods; Mlt::Tractor tractor(service); @@ -2898,6 +3063,7 @@ QList Render::producersList() void Render::fillSlowMotionProducers() { + if (m_mltProducer == NULL) return; Mlt::Service service(m_mltProducer->parent().get_service()); if (service.type() != tractor_type) return; @@ -2918,6 +3084,8 @@ void Render::fillSlowMotionProducers() if (id.startsWith("slowmotion:") && !nprod->is_blank()) { // this is a slowmotion producer, add it to the list QString url = QString::fromUtf8(nprod->get("resource")); + int strobe = nprod->get_int("strobe"); + if (strobe > 1) url.append("&strobe=" + QString::number(strobe)); if (!m_slowmotionProducers.contains(url)) { m_slowmotionProducers.insert(url, nprod); } @@ -2931,11 +3099,10 @@ void Render::fillSlowMotionProducers() void Render::mltInsertTrack(int ix, bool videoTrack) { blockSignals(true); - m_isBlocked = true; + m_isBlocked++; - m_mltConsumer->set("refresh", 0); - mlt_service_lock(m_mltConsumer->get_service()); Mlt::Service service(m_mltProducer->parent().get_service()); + mlt_service_lock(service.get_service()); if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM"; Mlt::Tractor tractor(service); @@ -2994,16 +3161,17 @@ void Render::mltInsertTrack(int ix, bool videoTrack) // Add audio mix transition to last track Mlt::Field *field = tractor.field(); Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix"); - //transition->set("mlt_service", "mix"); transition->set("a_track", 1); transition->set("b_track", ct); transition->set("always_active", 1); transition->set("internal_added", 237); transition->set("combine", 1); field->plant_transition(*transition, 1, ct); - - mlt_service_unlock(m_mltConsumer->get_service()); - m_isBlocked = false; + //mlt_service_unlock(m_mltConsumer->get_service()); + mlt_service_unlock(service.get_service()); + //tractor.multitrack()->refresh(); + //tractor.refresh(); + m_isBlocked--; blockSignals(false); } @@ -3026,12 +3194,13 @@ void Render::mltDeleteTrack(int ix) } if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) { tractor.removeChild(transitions.at(i)); - } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) { + i--; + } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) { // Transition needs to be moved int a_track = mappedProps.value("a_track").toInt(); int b_track = mappedProps.value("b_track").toInt(); - if (a_track > 0) a_track --; - if (b_track > 0) b_track --; + if (a_track > 0 && a_track >= ix) a_track --; + 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)); @@ -3041,8 +3210,19 @@ void Render::mltDeleteTrack(int ix) } } tractor.removeChild(track); + //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString(); setSceneList(doc.toString(), m_framePosition); - mltCheckLength(); + + if (m_mltProducer != NULL) { + Mlt::Producer parentProd(m_mltProducer->parent()); + if (parentProd.get_producer() != NULL) { + Mlt::Service service(parentProd.get_service()); + if (service.type() == tractor_type) { + Mlt::Tractor tractor(service); + mltCheckLength(&tractor); + } + } + } } @@ -3061,9 +3241,8 @@ void Render::updatePreviewSettings() int pos = 0; if (m_mltProducer) { pos = m_mltProducer->position(); - delete m_mltProducer; } - m_mltProducer = NULL; + setSceneList(scene, pos); }