#include <stdlib.h>
+
+
+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 ?
+ // detect if the producer has finished playing. Is there a better way to do it?
if (self->m_isBlocked) return;
- if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
+ Mlt::Frame frame(frame_ptr);
+#ifdef Q_WS_MAC
+ self->showFrame(frame);
+#endif
+ if (frame.get_double("_speed") == 0.0) {
self->emitConsumerStopped();
} else {
self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
}
}
-Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(winid), m_externalwinid(extid), m_framePosition(0), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false), m_isZoneMode(false), m_isLoopMode(false)
+Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget *parent) :
+ QObject(parent),
+ m_isBlocked(0),
+ m_name(rendererName),
+ m_mltConsumer(NULL),
+ m_mltProducer(NULL),
+ m_mltProfile(NULL),
+ m_framePosition(0),
+ m_isZoneMode(false),
+ m_isLoopMode(false),
+ m_isSplitView(false),
+ m_blackClip(NULL),
+ m_winid(winid)
+#ifdef Q_WS_MAC
+ , m_glWidget(0)
+#endif
{
- kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
- refreshTimer = new QTimer(this);
- connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
+ kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
/*if (rendererName == "project") m_monitorId = 10000;
else m_monitorId = 10001;*/
- osdTimer = new QTimer(this);
- connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
-
- m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
+ /*m_osdTimer = new QTimer(this);
+ connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));*/
buildConsumer();
Render::~Render()
{
+ m_isBlocked = 1;
closeMlt();
}
void Render::closeMlt()
{
- delete osdTimer;
- delete refreshTimer;
- if (m_mltConsumer)
- delete m_mltConsumer;
- if (m_mltProducer)
- delete m_mltProducer;
- if (m_blackClip) delete m_blackClip;
+ //delete m_osdTimer;
+ if (m_mltProducer) {
+ Mlt::Service service(m_mltProducer->parent().get_service());
+ mlt_service_lock(service.get_service());
+
+ if (service.type() == tractor_type) {
+ Mlt::Tractor tractor(service);
+ Mlt::Field *field = tractor.field();
+ mlt_service nextservice = mlt_service_get_producer(service.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");
+ // Delete all transitions
+ while (mlt_type == "transition") {
+ mlt_field_disconnect_service(field->get_field(), nextservice);
+ nextservice = mlt_service_producer(nextservice);
+ if (nextservice == NULL) break;
+ properties = MLT_SERVICE_PROPERTIES(nextservice);
+ mlt_type = mlt_properties_get(properties, "mlt_type");
+ resource = mlt_properties_get(properties, "mlt_service");
+ }
+
+ int trackNb = tractor.count();
+ while (trackNb > 0) {
+ Mlt::Producer trackProducer(tractor.track(trackNb - 1));
+ Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
+ if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
+ trackNb--;
+ }
+ }
+ mlt_service_unlock(service.get_service());
+ }
+
+ kDebug() << "// // // CLOSE RENDERER " << m_name;
+ delete m_mltConsumer;
+ delete m_mltProducer;
+ delete m_blackClip;
//delete m_osdInfo;
}
m_activeProfile = KdenliveSettings::current_profile();
tmp = decodedString(m_activeProfile);
setenv("MLT_PROFILE", tmp, 1);
- if (m_blackClip) delete m_blackClip;
+ delete m_blackClip;
m_blackClip = NULL;
+ //TODO: uncomment following line when everything is clean
+ //if (m_mltProfile) delete m_mltProfile;
m_mltProfile = new Mlt::Profile(tmp);
delete[] tmp;
}
setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
+#ifdef Q_WS_MAC
+ m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_audio");
+ m_mltConsumer->set("preview_off", 1);
+ m_mltConsumer->set("preview_format", mlt_image_rgb24a);
+#else
m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
+#endif
m_mltConsumer->set("resize", 1);
m_mltConsumer->set("window_id", m_winid);
m_mltConsumer->set("terminate_on_pause", 1);
- m_mltConsumer->set("window_background", decodedString(KdenliveSettings::window_background().name()));
+ tmp = decodedString(KdenliveSettings::window_background().name());
+ m_mltConsumer->set("window_background", tmp);
+ delete [] tmp;
+ // 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()) {
}
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);
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;*/
-
buildConsumer();
//kDebug() << "//RESET WITHSCENE: " << scene;
setSceneList(scene, pos);
/*char *tmp = decodedString(scene);
- Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
+ Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", tmp);
delete[] tmp;
m_mltProducer = producer;
m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
if (width == -1) {
width = renderWidth();
height = renderHeight();
- }
+ } else if (width % 2 == 1) width++;
QPixmap pix(width, height);
if (!m_mltProducer) {
pix.fill(Qt::black);
}
}
-void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer)
+void Render::getFileProperties(const QDomElement xml, const QString &clipId, bool replaceProducer)
{
KUrl url = KUrl(xml.attribute("resource", QString()));
Mlt::Producer *producer = NULL;
- if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
+ //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
+ /*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, "fezzik", tmp);
+ 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 westley = doc.createElement("westley");
+ QDomElement mlt = doc.createElement("mlt");
QDomElement play = doc.createElement("playlist");
- doc.appendChild(westley);
- westley.appendChild(play);
+ doc.appendChild(mlt);
+ mlt.appendChild(play);
play.appendChild(doc.importNode(xml, true));
char *tmp = decodedString(doc.toString());
- producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
+ producer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
delete[] tmp;
} else {
char *tmp = decodedString(url.path());
if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
- emit removeInvalidClip(clipId);
+ emit removeInvalidClip(clipId, replaceProducer);
+ delete producer;
return;
}
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;
filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
if (frame->get_int("test_image") == 0) {
- if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
+ if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
filePropertyMap["type"] = "playlist";
metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
} else if (frame->get_int("test_audio") == 0)
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) {
/*if (context->duration == AV_NOPTS_VALUE) {
kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
emit removeInvalidClip(clipId);
+ delete producer;
return;
}*/
// Get the video_index
}
if (KdenliveSettings::dropbframes()) {
- kDebug() << "// LOOKING FOR H264 on: " << default_video;
+ kDebug() << "// LOOKING FOR H264 on: " << default_video;
snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
kDebug() << "PROP: " << property << " = " << producer->get(property);
if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
- kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
+ kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
producer->set("skip_loop_filter", "all");
producer->set("skip_frame", "bidir");
}
emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
kDebug() << "REquested fuile info for: " << url.path();
- if (frame) delete frame;
- //if (producer) delete producer;
+ delete frame;
+ // FIXME: should delete this to avoid a leak...
+ //delete producer;
}
-/** Create the producer from the Westley QDomDocument */
+/** Create the producer from the MLT XML QDomDocument */
#if 0
void Render::initSceneList()
{
kDebug() << "-------- INIT SCENE LIST ------_";
QDomDocument doc;
- QDomElement westley = doc.createElement("westley");
- doc.appendChild(westley);
+ QDomElement mlt = doc.createElement("mlt");
+ doc.appendChild(mlt);
QDomElement prod = doc.createElement("producer");
prod.setAttribute("resource", "colour");
prod.setAttribute("colour", "red");
QDomElement playlist5 = doc.createElement("playlist");
multitrack.appendChild(playlist5);
tractor.appendChild(multitrack);
- westley.appendChild(tractor);
+ mlt.appendChild(tractor);
// kDebug()<<doc.toString();
/*
- QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
+ QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
setSceneList(doc, 0);
}
#endif
-/** Create the producer from the Westley QDomDocument */
-void Render::setProducer(Mlt::Producer *producer, int position)
+/** Create the producer from the MLT XML QDomDocument */
+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();
m_mltProducer->set("skip_loop_filter", "all");
m_mltProducer->set("skip_frame", "bidir");
}*/
- if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
+ if (!m_mltProducer || !m_mltProducer->is_valid()) {
+ kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
+ return -1;
+ }
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 Westley QDomDocument */
-void Render::setSceneList(QDomDocument list, int position)
+/** Create the producer from the MLT XML QDomDocument */
+int Render::setSceneList(QDomDocument list, int position)
{
- setSceneList(list.toString(), position);
+ return setSceneList(list.toString(), position);
}
-/** Create the producer from the Westley QDomDocument */
-void Render::setSceneList(QString playlist, int position)
+/** Create the producer from the MLT XML QDomDocument */
+int Render::setSceneList(QString playlist, int position)
{
- if (m_winid == -1) return;
+ if (m_winid == -1) return -1;
m_isBlocked = true;
- m_slowmotionProducers.clear();
+ int error;
//kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
- if (m_mltConsumer) {
- m_mltConsumer->stop();
- //m_mltConsumer->set("refresh", 0);
- } else {
+ if (m_mltConsumer == NULL) {
+ kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
m_isBlocked = false;
- return;
+ return -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);
+
+ Mlt::Service service(m_mltProducer->parent().get_service());
+ mlt_service_lock(service.get_service());
+
+ if (service.type() == tractor_type) {
+ Mlt::Tractor tractor(service);
+ Mlt::Field *field = tractor.field();
+ mlt_service nextservice = mlt_service_get_producer(service.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");
+ // Delete all transitions
+ while (mlt_type == "transition") {
+ mlt_field_disconnect_service(field->get_field(), nextservice);
+ nextservice = mlt_service_producer(nextservice);
+ if (nextservice == NULL) break;
+ properties = MLT_SERVICE_PROPERTIES(nextservice);
+ mlt_type = mlt_properties_get(properties, "mlt_type");
+ resource = mlt_properties_get(properties, "mlt_service");
+ }
+
+ int trackNb = tractor.count();
+ while (trackNb > 0) {
+ Mlt::Producer trackProducer(tractor.track(trackNb - 1));
+ Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
+ if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
+ trackNb--;
+ }
+ }
+ mlt_service_unlock(service.get_service());
+
+ qDeleteAll(m_slowmotionProducers.values());
+ m_slowmotionProducers.clear();
+
delete m_mltProducer;
m_mltProducer = NULL;
emit stopped();
blockSignals(true);
char *tmp = decodedString(playlist);
- m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
- delete[] tmp;
+ m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
if (!m_mltProducer || !m_mltProducer->is_valid()) {
kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
+ m_mltProducer = m_blackClip->cut(0, 50);
}
+ delete[] tmp;
+
m_mltProducer->optimise();
/*if (KdenliveSettings::osdtimecode()) {
delete m_osdInfo;
QString attr = "attr_check";
mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
- mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
+ mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
mlt_producer_attach( m_mltProducer->get_producer(), filter );
mlt_filter_close( filter );
}*/
m_fps = m_mltProducer->get_fps();
- kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
- connectPlaylist();
- fillSlowMotionProducers();
if (position != 0) {
- //TODO: seek to correct place after opening project.
- // Needs to be done from another place since it crashes here.
+ // Seek to correct place after opening project.
m_mltProducer->seek(position);
}
+
+ kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
+ error = connectPlaylist();
+ fillSlowMotionProducers();
+
m_isBlocked = false;
blockSignals(false);
+ emit refreshDocumentProducers();
+ return error;
//kDebug()<<"// SETSCN LST, POS: "<<position;
//if (position != 0) emit rendererPosition(position);
}
-/** Create the producer from the Westley QDomDocument */
+/** Create the producer from the MLT XML QDomDocument */
const QString Render::sceneList()
{
QString playlist;
- Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
+ Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
m_mltProducer->optimise();
- westleyConsumer.set("terminate_on_pause", 1);
+ xmlConsumer.set("terminate_on_pause", 1);
Mlt::Producer prod(m_mltProducer->get_producer());
bool split = m_isSplitView;
if (split) slotSplitView(false);
- westleyConsumer.connect(prod);
- westleyConsumer.start();
- while (!westleyConsumer.is_stopped()) {}
- playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist"));
+ xmlConsumer.connect(prod);
+ xmlConsumer.start();
+ while (!xmlConsumer.is_stopped()) {}
+ playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
if (split) slotSplitView(true);
return playlist;
}
doc.setContent(sceneList(), false);
if (!kdenliveData.isNull()) {
// add Kdenlive specific tags
- QDomNode wes = doc.elementsByTagName("westley").at(0);
- wes.appendChild(doc.importNode(kdenliveData, true));
+ QDomNode mlt = doc.elementsByTagName("mlt").at(0);
+ mlt.appendChild(doc.importNode(kdenliveData, true));
}
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
kWarning() << "////// ERROR writing to file: " << path;
void Render::saveZone(KUrl url, QString desc, QPoint zone)
{
kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
- char *tmppath = decodedString("westley:" + url.path());
- Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
+ char *tmppath = decodedString("xml:" + url.path());
+ Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
m_mltProducer->optimise();
delete[] tmppath;
- westleyConsumer.set("terminate_on_pause", 1);
+ xmlConsumer.set("terminate_on_pause", 1);
if (m_name == "clip") {
Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
tmppath = decodedString(desc);
Mlt::Playlist list;
list.insert_at(0, prod, 0);
+ delete prod;
list.set("title", tmppath);
delete[] tmppath;
- westleyConsumer.connect(list);
+ xmlConsumer.connect(list);
} else {
//TODO: not working yet, save zone from timeline
tmppath = decodedString(desc);
//prod->set("title", tmppath);
delete[] tmppath;
- westleyConsumer.connect(*p1); //list);
+ xmlConsumer.connect(*p1); //list);
}
- westleyConsumer.start();
+ xmlConsumer.start();
}
double Render::fps() const
return m_fps;
}
-void Render::connectPlaylist()
+int Render::connectPlaylist()
{
- if (!m_mltConsumer) return;
+ if (!m_mltConsumer) return -1;
//m_mltConsumer->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."));
- m_mltConsumer = NULL;
- }
- else {
- refresh();
- }*/
}
void Render::refreshDisplay()
if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
}*/
refresh();
- osdTimer->setSingleShot(2500);
+ //m_osdTimer->setSingleShot(2500);
}
void Render::slotOsdTimeout()
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."));
- m_mltConsumer = NULL;
- return;
+ emit blockMonitors();
+ delete m_mltProducer;
+ m_mltProducer = NULL;
} else {
kDebug() << "----- MONITOR: " << m_name << " REFRESH";
m_isBlocked = false;
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;
refresh();
}
-void Render::askForRefresh()
+void Render::seekToFrameDiff(int diff)
{
- // Use a Timer so that we don't refresh too much
- 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()
{
if (!m_mltProducer || m_isBlocked)
return;
- 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();
else return GenTime();
}
+int Render::seekFramePosition() const
+{
+ if (m_mltProducer) return (int) m_mltProducer->position();
+ return 0;
+}
const QString & Render::rendererName() const
{
//if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
}
+#ifdef Q_WS_MAC
+void Render::showFrame(Mlt::Frame& frame)
+{
+ mlt_image_format format = mlt_image_rgb24a;
+ int width = 0;
+ int height = 0;
+ const uchar* image = frame.get_image(format, width, height);
+ QImage qimage(width, height, QImage::Format_ARGB32);
+ memcpy(qimage.scanLine(0), image, width * height * 4);
+ emit showImageSignal(qimage);
+}
+#endif
+
/** MLT PLAYLIST DIRECT MANIPULATON **/
-void Render::mltCheckLength()
+void Render::mltCheckLength(Mlt::Tractor *tractor)
{
//kDebug()<<"checking track length: "<<track<<"..........";
- Mlt::Service service(m_mltProducer->get_service());
- Mlt::Tractor tractor(service);
-
- int trackNb = tractor.count();
- double duration = 0;
- double trackDuration;
+ 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((int) 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));
- double blackDuration = blackTrackProducer.get_playtime() - 1;
+ Mlt::Producer blackTrackProducer(tractor->track(0));
- if (blackDuration != duration) {
+ if (blackTrackProducer.get_playtime() - 1 != duration) {
Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
- blackTrackPlaylist.clear();
- int dur = (int)duration;
- while (dur > 14000) {
- blackTrackPlaylist.append(*m_blackClip, 0, 13999);
- dur = dur - 14000;
+ Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
+ if (blackclip && blackclip->is_blank()) {
+ delete blackclip;
+ blackclip = NULL;
}
- if (dur > 0) {
- blackTrackPlaylist.append(*m_blackClip, 0, dur);
+
+ 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);
+ 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((int)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) {
- kDebug() << "PLAYLIST NOT INITIALISED //////";
- return;
+ if (m_mltProducer == NULL) {
+ kDebug() << "PLAYLIST NOT INITIALISED //////";
+ return -1;
}
Mlt::Producer parentProd(m_mltProducer->parent());
if (parentProd.get_producer() == NULL) {
- kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
- return;
+ kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
+ 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: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
- if (element.attribute("speed", "1.0").toDouble() != 1.0) {
+ if (element.attribute("speed", "1.0").toDouble() != 1.0 || element.attribute("strobe", "1").toInt() > 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;
}
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;
}
m_isBlocked = true;
Mlt::Service service(m_mltProducer->parent().get_service());
- if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
+ if (service.type() != tractor_type) {
+ kWarning() << "// TRACTOR PROBLEM";
+ return;
+ }
Mlt::Tractor tractor(service);
Mlt::Producer trackProducer(tractor.track(track));
}
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) {
- if (filter->is_valid() && filter->get("kdenlive_id") != "") {
+ // Only duplicate Kdenlive filters, and skip the fade in effects
+ if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
// looks like there is no easy way to duplicate a filter,
// so we will create a new one and duplicate its properties
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);
bool Render::mltRemoveClip(int track, GenTime position)
{
Mlt::Service service(m_mltProducer->parent().get_service());
- if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
+ if (service.type() != tractor_type) {
+ kWarning() << "// TRACTOR PROBLEM";
+ return false;
+ }
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 "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
}*/
-
if (trackPlaylist.is_blank(clipIndex)) {
- kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
+ kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
+ mlt_service_unlock(service.get_service());
return false;
}
+ //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
m_isBlocked = true;
- Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
- trackPlaylist.replace_with_blank(clipIndex);
+ Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
+ if (clip) delete clip;
trackPlaylist.consolidate_blanks(0);
/*if (QString(clip.parent().get("transparency")).toInt() == 1)
mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
if (trackPlaylist.is_blank(i)) blk = "(blank)";
kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
}*/
-
- if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
+ mlt_service_unlock(service.get_service());
+ if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
m_isBlocked = false;
return true;
}
int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
{
if (!m_mltProducer) {
- kDebug() << "PLAYLIST NOT INITIALISED //////";
+ kDebug() << "PLAYLIST NOT INITIALISED //////";
return -1;
}
Mlt::Producer parentProd(m_mltProducer->parent());
if (parentProd.get_producer() == NULL) {
- kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
+ kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
return -1;
}
int Render::mltTrackDuration(int track)
{
if (!m_mltProducer) {
- kDebug() << "PLAYLIST NOT INITIALISED //////";
+ kDebug() << "PLAYLIST NOT INITIALISED //////";
return -1;
}
Mlt::Producer parentProd(m_mltProducer->parent());
if (parentProd.get_producer() == NULL) {
- kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
+ kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
return -1;
}
void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
{
if (!m_mltProducer) {
- kDebug() << "PLAYLIST NOT INITIALISED //////";
+ kDebug() << "PLAYLIST NOT INITIALISED //////";
return;
}
Mlt::Producer parentProd(m_mltProducer->parent());
if (parentProd.get_producer() == NULL) {
- kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
+ kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
return;
}
//kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
if (insertPos != -1) {
insertPos += offset;
int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
- if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
- else {
+ if (diff > 0) {
+ trackPlaylist.insert_blank(clipIndex, diff - 1);
+ } else {
if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
- if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
+ 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);
}
- // now move transitions
+ // now move transitions
mlt_service serv = m_mltProducer->parent().get_service();
mlt_service nextservice = mlt_service_get_producer(serv);
mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
- if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
- else {
- if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
- if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
+ if (diff > 0) {
+ trackPlaylist.insert_blank(clipIndex, diff - 1);
+ } else {
+ 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);
}
trackNb--;
}
- // now move transitions
+ // now move transitions
mlt_service serv = m_mltProducer->parent().get_service();
mlt_service nextservice = mlt_service_get_producer(serv);
mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
}
}
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;
Mlt::Service service(m_mltProducer->parent().get_service());
- if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
+ if (service.type() != tractor_type) {
+ kWarning() << "// TRACTOR PROBLEM";
+ return -1;
+ }
//kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
Mlt::Tractor tractor(service);
Mlt::Producer trackProducer(tractor.track(info.track));
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);
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
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());
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);
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);
return success;
}
Mlt::Service clipService(clip->get_service());
+ delete clip;
// if (tag.startsWith("ladspa")) tag = "ladspa";
m_isBlocked = true;
int ct = 0;
Mlt::Filter *filter = clipService.filter(ct);
while (filter) {
- if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
+ 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:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
} else if (updateIndex) {
- // Adjust the other effects index
+ // 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);
ct++;
} else ct++;
}
Mlt::Service clipService(clip->get_service());
m_isBlocked = true;
-
+ int duration = clip->get_playtime();
+ delete clip;
// temporarily remove all effects after insert point
QList <Mlt::Filter *> filtersList;
const int filter_ix = params.paramValue("kdenlive_ix").toInt();
char *starttag = decodedString(params.paramValue("starttag", "start"));
char *endtag = decodedString(params.paramValue("endtag", "end"));
kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
- int duration = clip->get_playtime();
//double max = params.paramValue("max").toDouble();
double min = params.paramValue("min").toDouble();
double factor = params.paramValue("factor", "1").toDouble();
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);
//int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
if (!clip) {
- kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
+ kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
return false;
}
Mlt::Service clipService(clip->get_service());
+ delete clip;
m_isBlocked = true;
int ct = 0;
Mlt::Filter *filter = clipService.filter(ct);
if (!filter) {
kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
- // filter was not found, it was probably a disabled filter, so add it to the correct place...
+ // filter was not found, it was probably a disabled filter, so add it to the correct place...
int ct = 0;
filter = clipService.filter(ct);
QList <Mlt::Filter *> filtersList;
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());
delete[] name;
delete[] value;
}
+ mlt_service_unlock(service.get_service());
m_isBlocked = false;
refresh();
void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
{
- kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
+ kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
Mlt::Service service(m_mltProducer->parent().get_service());
Mlt::Tractor tractor(service);
//int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
if (!clip) {
- kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
+ kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
return;
}
Mlt::Service clipService(clip->get_service());
+ delete clip;
m_isBlocked = true;
int ct = 0;
QList <Mlt::Filter *> filtersList;
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());
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);
+ //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
int previousStart = clip->get_in();
- int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
int newDuration = (int) clipDuration.frames(m_fps) - 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
clipIndex++;
- int diff = newDuration - previousDuration;
- kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
+ //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
if (diff > 0) {
// clip was made longer, trim next blank if there is one.
if (clipIndex < trackPlaylist.count()) {
- // If this is not the last clip in playlist
+ // 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;
- if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
- if (diff - blankDuration == 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 == 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());
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);
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;
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());
- if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
+ if (service.type() != tractor_type) {
+ kWarning() << "// TRACTOR PROBLEM";
+ return;
+ }
+ mlt_service_lock(m_mltConsumer->get_service());
Mlt::Tractor tractor(service);
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";
+ if (service.type() != tractor_type) {
+ kWarning() << "// TRACTOR PROBLEM";
+ return false;
+ }
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_service_lock(service.get_service());
- 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());
}*/
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;
- } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
+ 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());
+ }
// 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";
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;
}
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");
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);
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);
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);
}
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);
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;
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<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
{
QDomNodeList attribs = xml.elementsByTagName("parameter");
QMap<QString, QString> 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: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
+ //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
map[name] = e.attribute("default");
if (!e.attribute("value").isEmpty()) {
map[name] = e.attribute("value");
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());
}
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);
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);
}
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);
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<QString, QString> args = mltGetTransitionParamsFromXml(xml);
QString key;
if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
//kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
+ if (xml.hasAttribute("id"))
+ transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
for (it = args.begin(); it != args.end(); ++it) {
key = it.key();
char *value = decodedString(it.value());
if (it.value().isEmpty() == false) transition->set(name, value);
//kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
- //filter->set("kdenlive_id", id);
delete[] name;
delete[] value;
}
// attach filter to the clip
field->plant_transition(*transition, a_track, b_track);
delete[] transId;
- refresh();
+ if (do_refresh) refresh();
return true;
}
void Render::mltSavePlaylist()
{
kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
- Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
- fileConsumer.set("resource", "/tmp/playlist.westley");
+ Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
+ fileConsumer.set("resource", "/tmp/playlist.mlt");
Mlt::Service service(m_mltProducer->get_service());
fileConsumer.start();
}
-QList <Mlt::Producer *> Render::producersList()
+const QList <Mlt::Producer *> Render::producersList()
{
QList <Mlt::Producer *> 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);
int trackNb = tractor.count();
for (int t = 1; t < trackNb; t++) {
- Mlt::Producer trackProducer(tractor.track(t));
+ Mlt::Producer *tt = tractor.track(t);
+ Mlt::Producer trackProducer(tt);
+ delete tt;
Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
int clipNb = trackPlaylist.count();
//kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
for (int i = 0; i < clipNb; i++) {
- Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
- if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
- ids.append(nprod->get("id"));
- prods.append(nprod);
+ Mlt::Producer *c = trackPlaylist.get_clip(i);
+ Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
+ if (nprod) {
+ if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
+ ids.append(nprod->get("id"));
+ prods.append(nprod);
+ } else delete nprod;
}
+ delete c;
}
}
return prods;
void Render::fillSlowMotionProducers()
{
+ if (m_mltProducer == NULL) return;
Mlt::Service service(m_mltProducer->parent().get_service());
if (service.type() != tractor_type) return;
int trackNb = tractor.count();
for (int t = 1; t < trackNb; t++) {
- Mlt::Producer trackProducer(tractor.track(t));
+ Mlt::Producer *tt = tractor.track(t);
+ Mlt::Producer trackProducer(tt);
+ delete tt;
Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
int clipNb = trackPlaylist.count();
for (int i = 0; i < clipNb; i++) {
- Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
- if (nprod && !nprod->is_blank()) {
+ Mlt::Producer *c = trackPlaylist.get_clip(i);
+ Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
+ if (nprod) {
QString id = nprod->get("id");
- if (id.startsWith("slowmotion:")) {
+ 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);
}
- }
+ } else delete nprod;
}
+ delete c;
}
}
}
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());
- if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
+ mlt_service_lock(service.get_service());
+ if (service.type() != tractor_type) {
+ kWarning() << "// TRACTOR PROBLEM";
+ return;
+ }
Mlt::Tractor tractor(service);
- Mlt::Playlist playlist;// = new Mlt::Playlist();
+ Mlt::Playlist playlist;
int ct = tractor.count();
- // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
+ if (ix > ct) {
+ kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
+ ix = ct;
+ }
+
int pos = ix;
if (pos < ct) {
Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
// 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);
}
}
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));
}
}
tractor.removeChild(track);
+ //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
setSceneList(doc.toString(), m_framePosition);
- mltCheckLength();
- return;
-
- blockSignals(true);
- m_isBlocked = true;
-
- 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::Multitrack *multi = tractor.multitrack();
-
-
- int ct = tractor.count();
- kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
- int pos = ix;
- for (; pos < ct ; pos++) {
- Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
- //mlt_service_close(lastTrack->get_service());
- delete lastTrack;
- Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
- Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
- mlt_service_close(prodToMove->get_service());
- mlt_service_close(prodToClose->get_service());
- tractor.set_track(*prodToMove, pos);
- }*/
- // Move transitions
- /*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");
- QString resource = mlt_properties_get(properties, "mlt_service");
-
- while (mlt_type == "transition") {
- if (resource != "mix") {
- mlt_transition tr = (mlt_transition) nextservice;
- int currentTrack = mlt_transition_get_b_track(tr);
- int currentaTrack = mlt_transition_get_a_track(tr);
- mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
-
- if (currentTrack >= ix) {
- mlt_properties_set_int(properties, "b_track", currentTrack + 1);
- mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
+ /* 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);
+ }
}
- }
- nextservice = mlt_service_producer(nextservice);
- if (nextservice == NULL) break;
- properties = MLT_SERVICE_PROPERTIES(nextservice);
- mlt_type = mlt_properties_get(properties, "mlt_type");
- resource = mlt_properties_get(properties, "mlt_service");
- }
-
- // 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;
- blockSignals(false);
+ }*/
}
int pos = 0;
if (m_mltProducer) {
pos = m_mltProducer->position();
- delete m_mltProducer;
}
- m_mltProducer = NULL;
+
setSceneList(scene, pos);
}