Skip to content

Commit

Permalink
bpm修改
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYunPlayer committed May 18, 2024
1 parent 807170c commit 5b9588b
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 15 deletions.
10 changes: 5 additions & 5 deletions TuneLab/Views/PianoWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace TuneLab.Views;

internal class PianoWindow : Panel, PianoRoll.IDependency, PianoScrollView.IDependency, TimelineView.IDependency, ParameterTabBar.IDependency, AutomationRenderer.IDependency, PlayheadLayer.IDependency, FunctionBar.IDependency
internal class PianoWindow : Panel, PianoRoll.IDependency, PianoScrollView.IDependency, TimelineScrollView.IDependency, ParameterTabBar.IDependency, AutomationRenderer.IDependency, PlayheadLayer.IDependency, FunctionBar.IDependency
{
public event Action? ActiveAutomationChanged;
public event Action? VisibleAutomationChanged;
Expand Down Expand Up @@ -81,8 +81,8 @@ public PianoWindow(IDependency dependency)
mPianoScrollView = new PianoScrollView(this);
Children.Add(mPianoScrollView);

mPianoTimelineView = new TimelineView(this);
Children.Add(mPianoTimelineView);
mPianoTimelineScrollView = new TimelineScrollView(this);
Children.Add(mPianoTimelineScrollView);

mPlayheadLayer = new PlayheadLayer(this);
Children.Add(mPlayheadLayer);
Expand Down Expand Up @@ -151,7 +151,7 @@ protected override Size ArrangeOverride(Size finalSize)
{
double parameterHeight = mParameterHeight.Limit(0, finalSize.Height - TIME_AXIS_HEIGHT - PARAMETER_TAB_BAR_HEIGHT - PARAMETER_TITLE_BAR_HEIGHT);
mPianoScrollView.Arrange(new Rect(finalSize).Adjusted(ROLL_WIDTH, TIME_AXIS_HEIGHT, 0, -PARAMETER_TAB_BAR_HEIGHT));
mPianoTimelineView.Arrange(new Rect(ROLL_WIDTH, 0, finalSize.Width - ROLL_WIDTH, TIME_AXIS_HEIGHT));
mPianoTimelineScrollView.Arrange(new Rect(ROLL_WIDTH, 0, finalSize.Width - ROLL_WIDTH, TIME_AXIS_HEIGHT));
mPlayheadLayer.Arrange(new Rect(ROLL_WIDTH, 0, finalSize.Width - ROLL_WIDTH, finalSize.Height - PARAMETER_TAB_BAR_HEIGHT));
mParameterContainer.Arrange(new Rect(ROLL_WIDTH, finalSize.Height - PARAMETER_TAB_BAR_HEIGHT - parameterHeight, finalSize.Width - ROLL_WIDTH, parameterHeight));
mParameterTitleBar.Arrange(new Rect(ROLL_WIDTH, finalSize.Height - PARAMETER_TAB_BAR_HEIGHT - parameterHeight - PARAMETER_TITLE_BAR_HEIGHT, finalSize.Width - ROLL_WIDTH, PARAMETER_TITLE_BAR_HEIGHT));
Expand Down Expand Up @@ -260,7 +260,7 @@ void OnParameterTabBarStateChangeAsked(string automationID, ParameterButton.Butt
readonly PitchAxis mPitchAxis;

readonly PianoScrollView mPianoScrollView;
readonly TimelineView mPianoTimelineView;
readonly TimelineScrollView mPianoTimelineScrollView;
readonly PlayheadLayer mPlayheadLayer;
readonly ParameterContainer mParameterContainer;
readonly ParameterTitleBar mParameterTitleBar;
Expand Down
122 changes: 122 additions & 0 deletions TuneLab/Views/TimelineScrollView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using DynamicData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TuneLab.Base.Event;
using TuneLab.Base.Science;
using TuneLab.Data;
using TuneLab.GUI.Components;

namespace TuneLab.Views;

internal class TimelineScrollView : Panel, TimelineView.IDependency
{
public TimelineView TimelineView => mTimelineView;
public TickAxis TickAxis => mDependency.TickAxis;
public IQuantization Quantization => mDependency.Quantization;
public IProvider<ITimeline> TimelineProvider => mDependency.TimelineProvider;
public IPlayhead Playhead => mDependency.Playhead;
public bool IsAutoPage => mDependency.IsAutoPage;

public interface IDependency
{
TickAxis TickAxis { get; }
IQuantization Quantization { get; }
IProvider<ITimeline> TimelineProvider { get; }
IPlayhead Playhead { get; }
bool IsAutoPage { get; }
}

public TimelineScrollView(IDependency dependency)
{
mDependency = dependency;

mTimelineView = new(this);
Children.Add(mTimelineView);

mBpmInput = new TextInput()
{
Padding = new Thickness(8, 4),
Background = Brushes.White,
Foreground = Brushes.Black,
BorderThickness = new(0),
FontSize = 12,
CaretBrush = Brushes.Black,
MinWidth = 24,
CornerRadius = new CornerRadius(0),
IsVisible = false
};
mBpmInput.EndInput.Subscribe(OnBpmInputComplete);
Children.Add(mBpmInput);

Height = 48;
ClipToBounds = true;

TickAxis.AxisChanged += InvalidateArrange;
}

protected override Size ArrangeOverride(Size finalSize)
{
mTimelineView.Arrange(new Rect(finalSize));
if (mBpmInput.IsVisible)
mBpmInput.Arrange(BpmInputRect());

return finalSize;
}

public void EnterInputBpm(ITempo tempo)
{
if (mInputBpmTempo != null)
return;

mInputBpmTempo = tempo;
mBpmInput.Text = mTimelineView.BpmString(tempo);
mBpmInput.IsVisible = true;
mBpmInput.Focus();
mBpmInput.SelectAll();
}

void OnBpmInputComplete()
{
if (mInputBpmTempo == null)
return;

if (Timeline == null)
return;

if (!double.TryParse(mBpmInput.Text, out var newBpm))
{
newBpm = mInputBpmTempo.Bpm.Value;
}
newBpm = newBpm.Limit(10, 960);
if (newBpm != mInputBpmTempo.Bpm.Value)
{
Timeline.TempoManager.SetBpm(mInputBpmTempo, newBpm);
mInputBpmTempo.Commit();
}

mBpmInput.IsVisible = false;
mInputBpmTempo = null;
}

Rect BpmInputRect()
{
if (mInputBpmTempo == null)
return new Rect();

return new Rect(mDependency.TickAxis.Tick2X(mInputBpmTempo.Pos.Value), 24, 54, 24);
}

ITempo? mInputBpmTempo;
ITimeline? Timeline => mDependency.TimelineProvider.Object;

readonly TimelineView mTimelineView;
readonly TextInput mBpmInput;

readonly IDependency mDependency;
}
5 changes: 3 additions & 2 deletions TuneLab/Views/TimelineView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface IDependency
IProvider<ITimeline> TimelineProvider { get; }
IPlayhead Playhead { get; }
bool IsAutoPage { get; }
void EnterInputBpm(ITempo tempo);
}

public TimelineView(IDependency dependency)
Expand Down Expand Up @@ -156,12 +157,12 @@ protected override void OnRender(DrawingContext context)
}
}

string BpmString(ITempo tempo)
public string BpmString(ITempo tempo)
{
return tempo.Bpm.Value.ToString("F2");
}

double TempoWidth(ITempo tempo)
public double TempoWidth(ITempo tempo)
{
return new FormattedText(BpmString(tempo), System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, Typeface.Default, 12, null).Width + 16;
}
Expand Down
4 changes: 2 additions & 2 deletions TuneLab/Views/TimelineViewOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override void OnMouseDown(MouseDownEventArgs e)
{
if (e.IsDoubleClick)
{
// Enter Input Tempo
mDependency.EnterInputBpm(tempoItem.Tempo);
}
else
{
Expand All @@ -69,7 +69,7 @@ protected override void OnMouseDown(MouseDownEventArgs e)
{
var menuItem = new MenuItem().SetName("Edit Tempo").SetAction(() =>
{
// Enter edit
mDependency.EnterInputBpm(tempoItem.Tempo);
});
menu.Items.Add(menuItem);
}
Expand Down
12 changes: 6 additions & 6 deletions TuneLab/Views/TrackWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace TuneLab.Views;

internal class TrackWindow : DockPanel, TimelineView.IDependency, TrackScrollView.IDependency, PlayheadLayer.IDependency, TrackVerticalAxis.IDependency, TrackHeadList.IDependency
internal class TrackWindow : DockPanel, TimelineScrollView.IDependency, TrackScrollView.IDependency, PlayheadLayer.IDependency, TrackVerticalAxis.IDependency, TrackHeadList.IDependency
{
public IProvider<Project> ProjectProvider => mDependency.ProjectProvider;
public IProvider<ITimeline> TimelineProvider => mDependency.ProjectProvider;
Expand Down Expand Up @@ -74,9 +74,9 @@ public TrackWindow(IDependency dependency)
{
var layer = new DockPanel();
{
mTimelineView = new(this) { VerticalAlignment = Avalonia.Layout.VerticalAlignment.Top };
layer.Children.Add(mTimelineView);
DockPanel.SetDock(mTimelineView, Dock.Top);
mTimelineScrollView = new(this) { VerticalAlignment = Avalonia.Layout.VerticalAlignment.Top };
layer.Children.Add(mTimelineScrollView);
DockPanel.SetDock(mTimelineScrollView, Dock.Top);

mTrackScrollView = new(this);
layer.Children.Add(mTrackScrollView);
Expand All @@ -99,7 +99,7 @@ public void SwitchEditingPart(IPart part)
protected override void OnSizeChanged(SizeChangedEventArgs e)
{
mTickAxis.ViewLength = e.NewSize.Width - mTrackHeadList.Width;
mTrackVerticalAxis.ViewLength = e.NewSize.Height - mTimelineView.Height;
mTrackVerticalAxis.ViewLength = e.NewSize.Height - mTimelineScrollView.Height;
}

protected override void OnKeyDown(KeyEventArgs e)
Expand Down Expand Up @@ -144,7 +144,7 @@ protected override void OnKeyDown(KeyEventArgs e)
readonly TrackVerticalAxis mTrackVerticalAxis;

readonly TrackHeadList mTrackHeadList;
readonly TimelineView mTimelineView;
readonly TimelineScrollView mTimelineScrollView;
readonly TrackScrollView mTrackScrollView;
readonly PlayheadLayer mPlayheadLayer;

Expand Down

0 comments on commit 5b9588b

Please sign in to comment.