Don't try to cut twice, prevent unnecessary refreshes

Don't allow rubber selection on timeline ruler to allow cut shortcut while seeking
parent dbb37e7e
......@@ -528,7 +528,7 @@ std::shared_ptr<Mlt::Producer> ProjectClip::thumbProducer()
void ProjectClip::createDisabledMasterProducer()
{
if (!m_disabledProducer) {
m_disabledProducer = cloneProducer(&pCore->getCurrentProfile()->profile());
m_disabledProducer = cloneProducer();
m_disabledProducer->set("set.test_audio", 1);
m_disabledProducer->set("set.test_image", 1);
m_effectStack->addService(m_disabledProducer);
......@@ -549,7 +549,7 @@ std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int clipId, Play
if (state == PlaylistState::AudioOnly) {
// We need to get an audio producer, if none exists
if (m_audioProducers.count(clipId) == 0) {
m_audioProducers[clipId] = cloneProducer(&pCore->getCurrentProfile()->profile(), true);
m_audioProducers[clipId] = cloneProducer(true);
m_audioProducers[clipId]->set("set.test_audio", 0);
m_audioProducers[clipId]->set("set.test_image", 1);
m_effectStack->addService(m_audioProducers[clipId]);
......@@ -568,7 +568,7 @@ std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int clipId, Play
return std::shared_ptr<Mlt::Producer>(m_masterProducer->cut(-1, duration > 0 ? duration : -1));
}
if (m_videoProducers.count(clipId) == 0) {
m_videoProducers[clipId] = cloneProducer(&pCore->getCurrentProfile()->profile(), true);
m_videoProducers[clipId] = cloneProducer(true);
m_videoProducers[clipId]->set("set.test_audio", 1);
m_videoProducers[clipId]->set("set.test_image", 0);
m_effectStack->addService(m_videoProducers[clipId]);
......@@ -746,10 +746,9 @@ std::shared_ptr<Mlt::Producer> ProjectClip::timelineProducer(PlaylistState::Clip
return std::shared_ptr<Mlt::Producer>(normalProd->cut());
}*/
std::shared_ptr<Mlt::Producer> ProjectClip::cloneProducer(Mlt::Profile *destProfile, bool removeEffects)
std::shared_ptr<Mlt::Producer> ProjectClip::cloneProducer(bool removeEffects)
{
Mlt::Profile master_profile(mlt_profile_clone(m_masterProducer->get_profile()));
Mlt::Consumer c(master_profile, "xml", "string");
Mlt::Consumer c(pCore->getCurrentProfile()->profile(), "xml", "string");
Mlt::Service s(m_masterProducer->get_service());
int ignore = s.get_int("ignore_points");
if (ignore) {
......@@ -767,10 +766,8 @@ std::shared_ptr<Mlt::Producer> ProjectClip::cloneProducer(Mlt::Profile *destProf
s.set("ignore_points", ignore);
}
const QByteArray clipXml = c.get("string");
c.stop();
c.purge();
std::shared_ptr<Mlt::Producer> prod;
prod.reset(new Mlt::Producer(destProfile ? *destProfile : master_profile, "xml-string", clipXml.constData()));
prod.reset(new Mlt::Producer(pCore->getCurrentProfile()->profile(), "xml-string", clipXml.constData()));
if (strcmp(prod->get("mlt_service"), "avformat") == 0) {
prod->set("mlt_service", "avformat-novalidate");
}
......
......@@ -213,7 +213,7 @@ public:
std::pair<std::shared_ptr<Mlt::Producer>, bool> giveMasterAndGetTimelineProducer(int clipId, std::shared_ptr<Mlt::Producer> master,
PlaylistState::ClipState state);
std::shared_ptr<Mlt::Producer> cloneProducer(Mlt::Profile *destProfile = nullptr, bool removeEffects = false);
std::shared_ptr<Mlt::Producer> cloneProducer(bool removeEffects = false);
static std::shared_ptr<Mlt::Producer> cloneProducer(std::shared_ptr<Mlt::Producer> producer);
std::shared_ptr<Mlt::Producer> softClone(const char *list);
void updateTimelineClips(QVector<int> roles);
......
......@@ -668,30 +668,27 @@ void GLWidget::requestSeek()
return;
}
if (m_proxy->seeking()) {
if (!qFuzzyIsNull(m_producer->get_speed())) {
m_consumer->purge();
}
m_producer->seek(m_proxy->seekPosition());
if (m_consumer->is_stopped()) {
m_consumer->start();
} else {
m_consumer->purge();
m_consumer->set("refresh", 1);
}
m_consumer->set("refresh", 1);
}
}
void GLWidget::seek(int pos)
{
// Testing puspose only
if (!m_proxy->seeking()) {
m_proxy->setSeekPosition(pos);
if (!qFuzzyIsNull(m_producer->get_speed())) {
m_consumer->purge();
}
m_producer->seek(pos);
if (m_consumer->is_stopped()) {
m_consumer->start();
} else {
m_consumer->purge();
m_consumer->set("refresh", 1);
}
m_consumer->set("refresh", 1);
} else {
m_proxy->setSeekPosition(pos);
}
......@@ -699,7 +696,10 @@ void GLWidget::seek(int pos)
void GLWidget::requestRefresh()
{
if (m_producer && qFuzzyIsNull(m_producer->get_speed())) {
if (m_proxy->seeking()) {
return;
}
if (!m_producer && qFuzzyIsNull(m_producer->get_speed())) {
m_refreshTimer.start();
}
}
......@@ -712,6 +712,9 @@ QString GLWidget::frameToTime(int frames) const
void GLWidget::refresh()
{
m_refreshTimer.stop();
if (m_proxy->seeking()) {
return;
}
QMutexLocker locker(&m_mltMutex);
if (m_consumer->is_stopped()) {
m_consumer->start();
......
......@@ -504,11 +504,12 @@ void Monitor::setupMenu(QMenu *goMenu, QMenu *overlayMenu, QAction *playZone, QA
overlayAudio->setCheckable(true);
connect(overlayAudio, &QAction::toggled, m_glMonitor, &GLWidget::slotSwitchAudioOverlay);
overlayAudio->setChecked(KdenliveSettings::displayAudioOverlay());
m_configMenu->addAction(overlayAudio);
QAction *switchAudioMonitor = m_configMenu->addAction(i18n("Show Audio Levels"), this, SLOT(slotSwitchAudioMonitor()));
switchAudioMonitor->setCheckable(true);
switchAudioMonitor->setChecked((KdenliveSettings::monitoraudio() & m_id) != 0);
m_configMenu->addAction(overlayAudio);
// For some reason, the frame in QAbstracSpinBox (base class of TimeCodeDisplay) needs to be displayed once, then hidden
// or it will never appear (supposed to appear on hover).
m_timePos->setFrame(false);
......
......@@ -531,7 +531,7 @@ Fun ClipModel::setClipState_lambda(PlaylistState::ClipState state)
break;
}
m_currentState = state;
if (ptr->isClip(m_id)) { // if this is false, the clip is being created. Don't update model in that case
if (m_currentTrackId != -1 && ptr->isClip(m_id)) { // if this is false, the clip is being created. Don't update model in that case
QModelIndex ix = ptr->makeClipIndexFromID(m_id);
ptr->dataChanged(ix, ix, {TimelineModel::StatusRole});
}
......
......@@ -96,6 +96,7 @@ bool TimelineFunctions::processClipCut(std::shared_ptr<TimelineItemModel> timeli
}
PlaylistState::ClipState state = timeline->m_allClips[clipId]->clipState();
bool res = copyClip(timeline, clipId, newId, state, undo, redo);
timeline->m_blockRefresh = true;
res = res && timeline->requestItemResize(clipId, position - start, true, true, undo, redo);
int newDuration = timeline->getClipPlaytime(clipId);
// parse effects
......@@ -116,6 +117,7 @@ bool TimelineFunctions::processClipCut(std::shared_ptr<TimelineItemModel> timeli
updateDuration();
PUSH_LAMBDA(updateDuration, redo);
}
timeline->m_blockRefresh = false;
return res;
}
......
......@@ -101,6 +101,7 @@ TimelineModel::TimelineModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack>
, m_audioTarget(-1)
, m_videoTarget(-1)
, m_editMode(TimelineMode::NormalEdit)
, m_blockRefresh(false)
{
// Create black background track
m_blackClip->set("id", "black_track");
......@@ -2640,6 +2641,9 @@ std::shared_ptr<Mlt::Producer> TimelineModel::producer()
void TimelineModel::checkRefresh(int start, int end)
{
if (m_blockRefresh) {
return;
}
int currentPos = tractor()->position();
if (currentPos >= start && currentPos < end) {
emit requestMonitorRefresh();
......
......@@ -680,6 +680,8 @@ protected:
/* @brief Send signal to require clearing effet/composition view */
void clearAssetView(int itemId);
bool m_blockRefresh;
signals:
/* @brief signal triggered by clearAssetView */
void requestClearAssetView(int);
......
......@@ -733,7 +733,7 @@ Rectangle {
clickY = mouseY
return
}
if (mouse.modifiers & Qt.ShiftModifier) {
if (mouse.modifiers & Qt.ShiftModifier && mouse.y > ruler.height) {
// rubber selection
rubberSelect.x = mouse.x + tracksArea.x
rubberSelect.y = mouse.y
......@@ -802,7 +802,7 @@ Rectangle {
}
root.mousePosChanged(Math.max(0, Math.round((mouse.x + scrollView.flickableItem.contentX) / timeline.scaleFactor)))
ruler.showZoneLabels = mouse.y < ruler.height
if ((mouse.modifiers & Qt.ShiftModifier) && mouse.buttons === Qt.LeftButton && !rubberSelect.visible) {
if ((mouse.modifiers & Qt.ShiftModifier) && mouse.buttons === Qt.LeftButton && !rubberSelect.visible && rubberSelect.y > 0) {
// rubber selection
rubberSelect.visible = true
}
......@@ -860,6 +860,7 @@ Rectangle {
var endFrame = (scrollView.flickableItem.contentX - tracksArea.x + rubberSelect.x + rubberSelect.width) / timeline.scaleFactor
timeline.selectItems(t, startFrame, endFrame, mouse.modifiers & Qt.ControlModifier);
}
rubberSelect.y = -1
} else if (mouse.modifiers & Qt.ShiftModifier) {
// Shift click, process seek
timeline.seekPosition = Math.min((scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor, timeline.fullDuration - 1)
......@@ -1225,6 +1226,7 @@ Rectangle {
id: rubberSelect
property int originX
property int originY
y: -1
color: Qt.rgba(activePalette.highlight.r, activePalette.highlight.g, activePalette.highlight.b, 0.4)
border.color: activePalette.highlight
border.width: 1
......
......@@ -1182,11 +1182,14 @@ void TimelineController::cutClipUnderCursor(int position, int track)
if (position == -1) {
position = timelinePosition();
}
QMutexLocker lk(&m_metaMutex);
bool foundClip = false;
for (int cid : m_selection.selectedItems) {
if (m_model->isClip(cid)) {
if (TimelineFunctions::requestClipCut(m_model, cid, position)) {
foundClip = true;
// Cutting clips in the selection group is handled in TimelineFunctions
break;
}
} else {
qDebug() << "//// TODO: COMPOSITION CUT!!!";
......
......@@ -481,6 +481,7 @@ private:
PreviewManager *m_timelinePreview;
QAction *m_disablePreview;
std::shared_ptr<AudioCorrelation> m_audioCorrelator;
QMutex m_metaMutex;
void emitSelectedFromSelection();
int getCurrentItem();
......
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