Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Fix track compositing/audio mix broken on track insertion

parent fc756cf8
......@@ -419,38 +419,6 @@ const QString TimelineItemModel::getTrackFullName(int tid) const
return trackName.isEmpty() ? tag : tag + QStringLiteral(" - ") + trackName;
}
void TimelineItemModel::buildTrackCompositing()
{
auto it = m_allTracks.cbegin();
QScopedPointer<Mlt::Field> field(m_tractor->field());
field->lock();
QString composite = TransitionsRepository::get()->getCompositingTransition();
while (it != m_allTracks.cend()) {
int trackId = getTrackMltIndex((*it)->getId());
if (!composite.isEmpty() && !(*it)->isAudioTrack()) {
// video track, add composition
Mlt::Transition *transition = TransitionsRepository::get()->getTransition(composite);
transition->set("internal_added", 237);
transition->set("always_active", 1);
field->plant_transition(*transition, 0, trackId);
transition->set_tracks(0, trackId);
} else if ((*it)->isAudioTrack()) {
// audio mix
Mlt::Transition *transition = TransitionsRepository::get()->getTransition(QStringLiteral("mix"));
transition->set("internal_added", 237);
transition->set("always_active", 1);
transition->set("sum", 1);
field->plant_transition(*transition, 0, trackId);
transition->set_tracks(0, trackId);
}
++it;
}
field->unlock();
if (composite.isEmpty()) {
pCore->displayMessage(i18n("Could not setup track compositing, check your install"), MessageType::ErrorMessage);
}
}
const QString TimelineItemModel::groupsData()
{
return m_groups->toJson();
......@@ -493,6 +461,53 @@ void TimelineItemModel::notifyChange(const QModelIndex &topleft, const QModelInd
emit dataChanged(topleft, bottomright, roles);
}
void TimelineItemModel::buildTrackCompositing(bool rebuild)
{
auto it = m_allTracks.cbegin();
QScopedPointer<Mlt::Field> field(m_tractor->field());
field->lock();
// Make sure all previous track compositing is removed
if (rebuild) {
QScopedPointer<Mlt::Service> service(new Mlt::Service(field->get_service()));
while ((service != nullptr) && service->is_valid()) {
if (service->type() == transition_type) {
Mlt::Transition t((mlt_transition)service->get_service());
QString serviceName = t.get("mlt_service");
if (t.get_int("internal_added") == 237) {
// remove all compositing transitions
field->disconnect_service(t);
}
}
service.reset(service->producer());
}
}
QString composite = TransitionsRepository::get()->getCompositingTransition();
while (it != m_allTracks.cend()) {
int trackId = getTrackMltIndex((*it)->getId());
if (!composite.isEmpty() && !(*it)->isAudioTrack()) {
// video track, add composition
Mlt::Transition *transition = TransitionsRepository::get()->getTransition(composite);
transition->set("internal_added", 237);
transition->set("always_active", 1);
field->plant_transition(*transition, 0, trackId);
transition->set_tracks(0, trackId);
} else if ((*it)->isAudioTrack()) {
// audio mix
Mlt::Transition *transition = TransitionsRepository::get()->getTransition(QStringLiteral("mix"));
transition->set("internal_added", 237);
transition->set("always_active", 1);
transition->set("sum", 1);
field->plant_transition(*transition, 0, trackId);
transition->set_tracks(0, trackId);
}
++it;
}
field->unlock();
if (composite.isEmpty()) {
pCore->displayMessage(i18n("Could not setup track compositing, check your install"), MessageType::ErrorMessage);
}
}
void TimelineItemModel::notifyChange(const QModelIndex &topleft, const QModelIndex &bottomright, int role)
{
emit dataChanged(topleft, bottomright, {role});
......
......@@ -88,7 +88,10 @@ public:
void notifyChange(const QModelIndex &topleft, const QModelIndex &bottomright, bool start, bool duration, bool updateThumb) override;
void notifyChange(const QModelIndex &topleft, const QModelIndex &bottomright, const QVector<int> &roles) override;
void notifyChange(const QModelIndex &topleft, const QModelIndex &bottomright, int role) override;
void buildTrackCompositing();
/** @brief Rebuild track compositing */
void buildTrackCompositing(bool rebuild = false);
const QString groupsData();
bool loadGroups(const QString &groupsData);
/* @brief returns true if clip is in temporary selection group.
......
......@@ -553,6 +553,7 @@ public:
bool requestClipTimeWarp(int clipId, double speed, Fun &undo, Fun &redo);
void replugClip(int clipId);
/** @brief Refresh the tractor profile in case a change was requested. */
void updateProfile(Mlt::Profile *profile);
......
......@@ -495,6 +495,7 @@ void TimelineController::addTrack(int tid)
if (d->exec() == QDialog::Accepted) {
int newTid;
m_model->requestTrackInsertion(d->selectedTrackPosition(), newTid, d->trackName(), d->addAudioTrack());
m_model->buildTrackCompositing(true);
}
}
......@@ -506,6 +507,7 @@ void TimelineController::deleteTrack(int tid)
QPointer<TrackDialog> d = new TrackDialog(m_model, tid, qApp->activeWindow(), true);
if (d->exec() == QDialog::Accepted) {
m_model->requestTrackDeletion(d->selectedTrackId());
m_model->buildTrackCompositing(true);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment