Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject locked track modifications #74

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 60 additions & 3 deletions src/docks/timelinedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,18 @@ bool TimelineDock::isBlank(int trackIndex, int clipIndex)
.data(MultitrackModel::IsBlankRole).toBool();
}

void TimelineDock::pulseLockButtonOnTrack(int trackIndex)
{
QMetaObject::invokeMethod(m_quickView.rootObject(), "pulseLockButtonOnTrack",
Qt::DirectConnection, Q_ARG(QVariant, trackIndex));
}

void TimelineDock::chooseClipAtPosition(int position, int * trackIndex, int * clipIndex)
{
QScopedPointer<Mlt::Producer> clip;

// Start by checking for a hit at the specified track
if (*trackIndex != -1) {
if (*trackIndex != -1 && !isTrackLocked(*trackIndex)) {
*clipIndex = clipIndexAtPosition(*trackIndex, position);
if (*clipIndex != -1 && !isBlank(*trackIndex, *clipIndex))
return;
Expand All @@ -161,13 +167,16 @@ void TimelineDock::chooseClipAtPosition(int position, int * trackIndex, int * cl
*trackIndex = currentTrack();
*clipIndex = clipIndexAtPosition(*trackIndex, position);

if (*clipIndex != -1 && !isBlank(*trackIndex, *clipIndex))
if (!isTrackLocked(*trackIndex) && *clipIndex != -1 && !isBlank(*trackIndex, *clipIndex)) {
return;
}

// if there was no hit, look through the other tracks
for (*trackIndex = 0; *trackIndex < m_model.trackList().size(); (*trackIndex)++) {
if (*trackIndex == currentTrack())
continue;
if (isTrackLocked(*trackIndex))
continue;
*clipIndex = clipIndexAtPosition(*trackIndex, position);
if (*clipIndex != -1 && !isBlank(*trackIndex, *clipIndex))
return;
Expand Down Expand Up @@ -259,11 +268,15 @@ void TimelineDock::selectClipUnderPlayhead()
int track = -1, clip = -1;
chooseClipAtPosition(m_position, &track, &clip);
if (clip == -1) {
if (isTrackLocked(currentTrack())) {
pulseLockButtonOnTrack(currentTrack());
return;
}
int idx = clipIndexAtPlayhead(-1);
if (idx == -1)
setSelection(QList<int>());
else
setSelection(QList<int>() << clipIndexAtPlayhead(-1));
setSelection(QList<int>() << idx);
return;
}

Expand All @@ -283,6 +296,8 @@ int TimelineDock::centerOfClip(int trackIndex, int clipIndex)

bool TimelineDock::isTrackLocked(int trackIndex) const
{
if (trackIndex < 0 || trackIndex >= m_model.trackList().size())
return false;
int i = m_model.trackList().at(trackIndex).mlt_index;
QScopedPointer<Mlt::Producer> track(m_model.tractor()->track(i));
return track->get_int(kTrackLockProperty);
Expand Down Expand Up @@ -336,6 +351,10 @@ void TimelineDock::onSeeked(int position)

void TimelineDock::append(int trackIndex)
{
if (isTrackLocked(trackIndex)) {
pulseLockButtonOnTrack(trackIndex);
return;
}
if (MLT.isSeekableClip() || MLT.savedProducer()) {
if (trackIndex < 0)
trackIndex = currentTrack();
Expand All @@ -347,6 +366,10 @@ void TimelineDock::append(int trackIndex)

void TimelineDock::remove(int trackIndex, int clipIndex)
{
if (isTrackLocked(trackIndex)) {
pulseLockButtonOnTrack(trackIndex);
return;
}
Q_ASSERT(trackIndex >= 0 && clipIndex >= 0);
Mlt::Producer* clip = producerForClip(trackIndex, clipIndex);
if (clip) {
Expand All @@ -361,6 +384,10 @@ void TimelineDock::remove(int trackIndex, int clipIndex)

void TimelineDock::lift(int trackIndex, int clipIndex)
{
if (isTrackLocked(trackIndex)) {
pulseLockButtonOnTrack(trackIndex);
return;
}
Q_ASSERT(trackIndex >= 0 && clipIndex >= 0);
QScopedPointer<Mlt::Producer> clip(producerForClip(trackIndex, clipIndex));
if (clip) {
Expand All @@ -376,6 +403,10 @@ void TimelineDock::lift(int trackIndex, int clipIndex)

void TimelineDock::removeSelection()
{
if (isTrackLocked(currentTrack())) {
pulseLockButtonOnTrack(currentTrack());
return;
}
if (selection().isEmpty())
selectClipUnderPlayhead();
if (selection().isEmpty())
Expand All @@ -386,6 +417,10 @@ void TimelineDock::removeSelection()

void TimelineDock::liftSelection()
{
if (isTrackLocked(currentTrack())) {
pulseLockButtonOnTrack(currentTrack());
return;
}
if (selection().isEmpty())
selectClipUnderPlayhead();
if (selection().isEmpty())
Expand Down Expand Up @@ -530,6 +565,10 @@ bool TimelineDock::trimClipOut(int trackIndex, int clipIndex, int delta)

void TimelineDock::insert(int trackIndex, int position, const QString &xml)
{
if (isTrackLocked(trackIndex)) {
pulseLockButtonOnTrack(trackIndex);
return;
}
if (MLT.isSeekableClip() || MLT.savedProducer() || !xml.isEmpty()) {
QString xmlToUse = !xml.isEmpty()? xml
: MLT.XML(MLT.isClip()? 0 : MLT.savedProducer());
Expand All @@ -544,6 +583,10 @@ void TimelineDock::insert(int trackIndex, int position, const QString &xml)

void TimelineDock::overwrite(int trackIndex, int position, const QString &xml)
{
if (isTrackLocked(trackIndex)) {
pulseLockButtonOnTrack(trackIndex);
return;
}
if (MLT.isSeekableClip() || MLT.savedProducer() || !xml.isEmpty()) {
QString xmlToUse = !xml.isEmpty()? xml
: MLT.XML(MLT.isClip()? 0 : MLT.savedProducer());
Expand All @@ -559,13 +602,19 @@ void TimelineDock::overwrite(int trackIndex, int position, const QString &xml)
void TimelineDock::appendFromPlaylist(Mlt::Playlist *playlist)
{
int trackIndex = currentTrack();
if (isTrackLocked(trackIndex)) {
pulseLockButtonOnTrack(trackIndex);
return;
}
m_model.appendFromPlaylist(playlist, trackIndex);
}

void TimelineDock::splitClip(int trackIndex, int clipIndex)
{
if (trackIndex < 0 || clipIndex < 0)
chooseClipAtPosition(m_position, &trackIndex, &clipIndex);
if (trackIndex < 0 || clipIndex < 0)
return;
setCurrentTrack(trackIndex);
if (clipIndex >= 0 && trackIndex >= 0) {
int i = m_model.trackList().at(trackIndex).mlt_index;
Expand All @@ -587,6 +636,10 @@ void TimelineDock::splitClip(int trackIndex, int clipIndex)

void TimelineDock::fadeIn(int trackIndex, int clipIndex, int duration)
{
if (isTrackLocked(trackIndex)) {
pulseLockButtonOnTrack(trackIndex);
return;
}
if (duration < 0) return;
Q_ASSERT(trackIndex >= 0 && clipIndex >= 0);
MAIN.undoStack()->push(
Expand All @@ -596,6 +649,10 @@ void TimelineDock::fadeIn(int trackIndex, int clipIndex, int duration)

void TimelineDock::fadeOut(int trackIndex, int clipIndex, int duration)
{
if (isTrackLocked(trackIndex)) {
pulseLockButtonOnTrack(trackIndex);
return;
}
if (duration < 0) return;
Q_ASSERT(trackIndex >= 0 && clipIndex >= 0);
MAIN.undoStack()->push(
Expand Down
1 change: 1 addition & 0 deletions src/docks/timelinedock.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public slots:

private:
bool isBlank(int trackIndex, int clipIndex);
void pulseLockButtonOnTrack(int trackIndex);
Ui::TimelineDock *ui;
ForwardingQuickViewWorkaround m_quickView;
MultitrackModel m_model;
Expand Down
4 changes: 4 additions & 0 deletions src/qml/timeline/timeline.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Rectangle {
tracksRepeater.itemAt(i).redrawWaveforms()
}

function pulseLockButtonOnTrack(index) {
trackHeaderRepeater.itemAt(index).pulseLockButton()
}

property int headerWidth: 140
property int currentTrack: 0
property color selectedTrackColor: Qt.rgba(0.8, 0.8, 0, 0.3);
Expand Down