Skip to content

Commit

Permalink
要素を分割したとき、動画の再生位置を調整するようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
yuto-trd committed Sep 12, 2023
1 parent eda2a87 commit 37b0ad2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Beutl.Operators/Source/SourceVideoOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,16 @@ public override bool TryGetOriginalLength(out TimeSpan timeSpan)
return false;
}
}

public override IRecordableCommand? OnSplit(bool backward, TimeSpan startDelta, TimeSpan lengthDelta)
{
if (backward)
{
return new ChangeSetterValueCommand<TimeSpan>(OffsetPosition, OffsetPosition.Value, OffsetPosition.Value + startDelta);
}
else
{
return base.OnSplit(backward, startDelta, lengthDelta);
}
}
}
29 changes: 29 additions & 0 deletions src/Beutl.ProjectSystem/ChangeSetterValueCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Beutl.Styling;

namespace Beutl;

public sealed class ChangeSetterValueCommand<T> : IRecordableCommand
{
private readonly Setter<T> _setter;
private readonly T _oldValue;
private readonly T _newValue;

public ChangeSetterValueCommand(Setter<T> setter, T oldValue, T newValue)
{
_setter = setter;
_oldValue = oldValue;
_newValue = newValue;
}

public void Do()
{
_setter.Value = _newValue;
}

public void Redo() => Do();

public void Undo()
{
_setter.Value = _oldValue;
}
}
8 changes: 8 additions & 0 deletions src/Beutl.ProjectSystem/Operation/SourceOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public SourceOperation()
[NotAutoSerialized]
public ICoreList<SourceOperator> Children => _children;

public IRecordableCommand OnSplit(bool backward, TimeSpan startDelta,TimeSpan lengthDelta)
{
return _children.Select(v => v.OnSplit(backward, startDelta, lengthDelta))
.Where(v => v != null)
.ToArray()!
.ToCommand();
}

public override void ReadFromJson(JsonObject json)
{
base.ReadFromJson(json);
Expand Down
5 changes: 5 additions & 0 deletions src/Beutl.ProjectSystem/Operation/SourceOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public virtual bool TryGetOriginalLength(out TimeSpan timeSpan)
return false;
}

public virtual IRecordableCommand? OnSplit(bool backward, TimeSpan startDelta, TimeSpan lengthDelta)
{
return null;
}

protected void RaiseInvalidated(RenderInvalidatedEventArgs args)
{
Invalidated?.Invoke(this, args);
Expand Down
4 changes: 4 additions & 0 deletions src/Beutl/ViewModels/ElementViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,12 @@ private void OnSplit(TimeSpan timeSpan)

backwardLayer.Save(RandomFileNameGenerator.Generate(Path.GetDirectoryName(Scene.FileName)!, Constants.ElementFileExtension));
IRecordableCommand command2 = Scene.AddChild(backwardLayer);
IRecordableCommand command3 = backwardLayer.Operation.OnSplit(true, forwardLength, -forwardLength);
IRecordableCommand command4 = Model.Operation.OnSplit(false, TimeSpan.Zero, -backwardLength);

command1.Append(command2)
.Append(command3)
.Append(command4)
.DoAndRecord(CommandRecorder.Default);
}

Expand Down

0 comments on commit 37b0ad2

Please sign in to comment.