Skip to content

Commit

Permalink
feat: 播放控制添加回到开头与跳到结尾
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYunPlayer committed Dec 6, 2024
1 parent bfbce50 commit 2d44dc3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions TuneLab/Audio/AudioEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal static class AudioEngine
public static int SamplingRate => mAudioProvider!.SamplingRate;
public static double CurrentTime => mAudioProvider!.CurrentTime;
public static double MasterGain { get; set; } = 0;
public static double EndTime => AudioGraph.EndTime;

public static void Init(IAudioPlaybackHandler playbackHandler)
{
Expand Down
2 changes: 1 addition & 1 deletion TuneLab/Data/ITempoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace TuneLab.Data;

internal interface ITempoManager : IDataObject<List<TempoInfo>>
{
IProject Project { get; }
IProject Project { get; } // TODO: Remove this
IReadOnlyList<ITempo> Tempos { get; }
int AddTempo(double pos, double bpm);
void RemoveTempoAt(int index);
Expand Down
2 changes: 2 additions & 0 deletions TuneLab/GUI/Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal static class Assets
public static SvgIcon Hyphen = new("<svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n<rect x=\"4\" y=\"7\" width=\"8\" height=\"2\" rx=\"1\" fill=\"white\"/>\r\n</svg>");
public static SvgIcon Anchor = new("<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n<circle cx=\"6\" cy=\"16\" r=\"2.5\" stroke=\"white\"/>\r\n<circle cx=\"18\" cy=\"12\" r=\"2.5\" stroke=\"white\"/>\r\n<circle cx=\"10\" cy=\"8\" r=\"2.5\" stroke=\"white\"/>\r\n<path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M11.7939 8.88516C11.9259 8.61833 12 8.31783 12 8.00002C12 7.56902 11.8636 7.16987 11.6318 6.84332C12.8738 6.96097 14.0258 7.49932 14.8895 8.01753C15.5705 8.42616 16.1442 8.8654 16.5464 9.20055C16.7485 9.36892 16.9096 9.51304 17.022 9.61678C17.0783 9.6687 17.1224 9.71065 17.1536 9.74064L17.1904 9.77645L17.2013 9.78719L17.2049 9.79069L17.2061 9.79196L17.2067 9.79248C17.2069 9.7927 17.2071 9.79291 16.5 10.5C15.7929 11.2071 15.7931 11.2073 15.7932 11.2075L15.7893 11.2036L15.7663 11.1813C15.7447 11.1605 15.7108 11.1282 15.6655 11.0864C15.5747 11.0026 15.439 10.8811 15.266 10.737C14.9182 10.4471 14.4294 10.0739 13.8605 9.73251C13.1819 9.32538 12.4738 9.01369 11.7939 8.88516ZM9.12041 9.79673C8.47773 9.48151 8.02898 8.83164 8.00133 8.07428C7.09234 8.93355 6.53025 10.0844 6.18519 11.0333C5.91226 11.7838 5.74374 12.4937 5.6432 13.0132C5.59268 13.2742 5.5587 13.4904 5.5371 13.6438C5.52629 13.7206 5.51854 13.7818 5.51336 13.8253L5.50743 13.877L5.50578 13.8924L5.50526 13.8974L5.50508 13.8992L5.505 13.8999C5.50497 13.9003 5.50494 13.9005 6.49998 14.0001C7.49502 14.0996 7.49499 14.0998 7.49497 14.1001L7.49493 14.1004L7.49488 14.1009L7.49493 14.1005L7.49497 14.1001L7.49558 14.0944L7.4993 14.062C7.5029 14.0318 7.50883 13.9846 7.51755 13.9227C7.53501 13.7988 7.56353 13.6165 7.60676 13.3932C7.69373 12.9439 7.8377 12.3412 8.06477 11.7168C8.33341 10.978 8.68222 10.3057 9.12041 9.79673Z\" fill=\"white\"/>\r\n</svg>\r\n");
public static SvgIcon Pause = new("<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n<rect x=\"6\" y=\"4\" width=\"4\" height=\"16\" rx=\"1\" fill=\"white\"/>\r\n<rect x=\"14\" y=\"4\" width=\"4\" height=\"16\" rx=\"1\" fill=\"white\"/>\r\n</svg>");
public static SvgIcon GotoStart = new("<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n<g clip-path=\"url(#clip0_2010_563)\">\r\n<path d=\"M8 13.7321C6.66667 12.9623 6.66667 11.0377 8 10.2679L17 5.0718C18.3333 4.302 20 5.26425 20 6.80385V17.1962C20 18.7358 18.3333 19.698 17 18.9282L8 13.7321Z\" fill=\"white\"/>\r\n<rect x=\"4\" y=\"4\" width=\"2\" height=\"16\" rx=\"1\" fill=\"white\"/>\r\n</g>\r\n<defs>\r\n<clipPath id=\"clip0_2010_563\">\r\n<rect width=\"24\" height=\"24\" fill=\"white\"/>\r\n</clipPath>\r\n</defs>\r\n</svg>");
public static SvgIcon GotoEnd = new("<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\r\n<g clip-path=\"url(#clip0_2010_562)\">\r\n<path d=\"M16 10.2679C17.3333 11.0377 17.3333 12.9623 16 13.7321L7 18.9282C5.66667 19.698 4 18.7358 4 17.1962L4 6.80385C4 5.26425 5.66667 4.302 7 5.0718L16 10.2679Z\" fill=\"white\"/>\r\n<rect x=\"18\" y=\"4\" width=\"2\" height=\"16\" rx=\"1\" fill=\"white\"/>\r\n</g>\r\n<defs>\r\n<clipPath id=\"clip0_2010_562\">\r\n<rect width=\"24\" height=\"24\" fill=\"white\"/>\r\n</clipPath>\r\n</defs>\r\n</svg>");
public static SvgIcon None = new("");

public static FontFamily NotoMono = new FontFamily("NotoMono");
Expand Down
22 changes: 22 additions & 0 deletions TuneLab/UI/MainWindow/Editor/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ public Editor()

mFunctionBar.Moved += y => TrackWindowHeight = y;
mFunctionBar.CollapsePropertiesAsked += show => mRightSideBar.IsVisible = show;
mFunctionBar.GotoStartAsked += () =>
{
var startTime = 0;
AudioEngine.Seek(startTime);
if (Project == null)
return;

var startTick = Project.TempoManager.GetTick(startTime);
mTrackWindow.TickAxis.AnimateMoveTickToX(startTick, 0);
mPianoWindow.TickAxis.AnimateMoveTickToX(startTick, 0);
};
mFunctionBar.GotoEndAsked += () =>
{
var endTime = AudioEngine.EndTime;
AudioEngine.Seek(endTime);
if (Project == null)
return;

var endTick = Project.TempoManager.GetTick(endTime);
mTrackWindow.TickAxis.AnimateMoveTickToX(endTick, mTrackWindow.TickAxis.ViewLength);
mPianoWindow.TickAxis.AnimateMoveTickToX(endTick, mPianoWindow.TickAxis.ViewLength);
};
ProjectProvider.ObjectWillChange.Subscribe(OnProjectWillChange, s);
ProjectProvider.ObjectChanged.Subscribe(OnProjectChanged, s);
ProjectProvider.When(project => project.Tracks.Any(track => track.Parts.ItemRemoved)).Subscribe(part => { if (part == mEditingPart) SwitchEditingPart(null); });
Expand Down
20 changes: 18 additions & 2 deletions TuneLab/UI/MainWindow/Editor/FunctionBar/FunctionBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ internal class FunctionBar : LayerPanel
{
public event Action<double>? Moved;
public event Action<bool>? CollapsePropertiesAsked;
public event Action? GotoStartAsked;
public event Action? GotoEndAsked;

public INotifiableProperty<PlayScrollTarget> PlayScrollTarget => mDependency.PlayScrollTarget;
public IActionEvent<QuantizationBase, QuantizationDivision> QuantizationChanged => mQuantizationChanged;

public interface IDependency
{
public INotifiableProperty<PianoTool> PianoTool { get; }
public INotifiableProperty<PlayScrollTarget> PlayScrollTarget { get; }
INotifiableProperty<PianoTool> PianoTool { get; }
INotifiableProperty<PlayScrollTarget> PlayScrollTarget { get; }
}

public FunctionBar(IDependency dependency)
Expand Down Expand Up @@ -79,6 +81,20 @@ void SetupToolTip(Control toggleButton,string ToolTipText)

SetupToolTip(autoPageButton, "Auto Scroll".Tr(this));
audioControlPanel.Children.Add(autoPageButton);

var gotoStartButton = new GUI.Components.Button() { Width = 36, Height = 36 }
.AddContent(new() { Item = new BorderItem() { CornerRadius = 4 }, ColorSet = new() { HoveredColor = hoverBack, PressedColor = hoverBack } })
.AddContent(new() { Item = new IconItem() { Icon = Assets.GotoStart }, ColorSet = new() { Color = Style.LIGHT_WHITE.Opacity(0.5) } });
SetupToolTip(gotoStartButton, "Go to Start".Tr(this));
gotoStartButton.Clicked += () => { GotoStartAsked?.Invoke(); };
audioControlPanel.Children.Add(gotoStartButton);

var gotoEndButton = new GUI.Components.Button() { Width = 36, Height = 36 }
.AddContent(new() { Item = new BorderItem() { CornerRadius = 4 }, ColorSet = new() { HoveredColor = hoverBack, PressedColor = hoverBack } })
.AddContent(new() { Item = new IconItem() { Icon = Assets.GotoEnd }, ColorSet = new() { Color = Style.LIGHT_WHITE.Opacity(0.5) } });
SetupToolTip(gotoEndButton, "Go to End".Tr(this));
gotoEndButton.Clicked += () => { GotoEndAsked?.Invoke(); };
audioControlPanel.Children.Add(gotoEndButton);
}
dockPanel.AddDock(audioControlPanel, Dock.Left);

Expand Down
5 changes: 5 additions & 0 deletions TuneLab/UI/MainWindow/Editor/TimelineView/TimelineView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public TimelineView(IDependency dependency)
{
if (AudioEngine.IsPlaying)
{
// Auto Page
if (mDependency.PlayScrollTarget.Value == PlayScrollTarget.None)
return;

Expand Down Expand Up @@ -87,9 +88,13 @@ public TimelineView(IDependency dependency)
else
{
mFixedPlayheadX = TickAxis.Tick2X(Playhead.Pos);
if (!mIsSeeking)
return;

if (mState == State.Seeking)
return;

// Move view
if (Playhead.Pos < TickAxis.MinVisibleTick)
{
TickAxis.MoveTickToX(Playhead.Pos, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public void Down(double x)
if (State != State.None)
return;

mIsSeeking = true;
State = State.Seeking;
mIsPlaying = AudioEngine.IsPlaying;
if (mIsPlaying) AudioEngine.Pause();
Expand Down Expand Up @@ -263,6 +264,7 @@ public void Up()
if (!IsOperating)
return;

mIsSeeking = false;
State = State.None;
TimelineView.TickAxis.StopMoveAnimation();
if (mIsPlaying) AudioEngine.Play();
Expand All @@ -272,6 +274,7 @@ public void Up()
}

readonly SeekOperation mSeekOperation;
static bool mIsSeeking = false;

class TempoMovingOperation(TimelineView timelineView) : Operation(timelineView)
{
Expand Down

0 comments on commit 2d44dc3

Please sign in to comment.