diff --git a/OpenUtau/Controls/TrackBackground.cs b/OpenUtau/Controls/TrackBackground.cs index 0b4a1e441..27425b2ee 100644 --- a/OpenUtau/Controls/TrackBackground.cs +++ b/OpenUtau/Controls/TrackBackground.cs @@ -30,6 +30,11 @@ class TrackBackground : TemplatedControl { nameof(IsKeyboard), o => o.IsKeyboard, (o, v) => o.IsKeyboard = v); + public static readonly DirectProperty KeyProperty = + AvaloniaProperty.RegisterDirect( + nameof(Key), + o => o.Key, + (o, v) => o.Key = v); public double TrackHeight { get => _trackHeight; @@ -47,11 +52,16 @@ public bool IsKeyboard { get => _isKeyboard; set => SetAndRaise(IsPianoRollProperty, ref _isKeyboard, value); } + public int Key { + get => _key; + set => SetAndRaise(KeyProperty, ref _key, value); + } private double _trackHeight; private double _trackOffset; private bool _isPianoRoll; private bool _isKeyboard; + private int _key; public TrackBackground() { MessageBus.Current.Listen() @@ -62,7 +72,8 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang base.OnPropertyChanged(change); if (change.Property == TrackHeightProperty || change.Property == TrackOffsetProperty || - change.Property == ForegroundProperty) { + change.Property == ForegroundProperty || + change.Property == KeyProperty) { InvalidateVisual(); } } @@ -77,7 +88,6 @@ public override void Render(DrawingContext context) { } int track = (int)TrackOffset; double top = TrackHeight * (track - TrackOffset); - int key = DocManager.Inst.Project == null ? 0 : DocManager.Inst.Project.key; string[] degreeNames; switch(Preferences.Default.DegreeStyle){ case 1: @@ -112,7 +122,7 @@ public override void Render(DrawingContext context) { toneTextLayout.Draw(context, new Point()); } //scale degree display - int degree = mod(tone - key, 12); + int degree = mod(tone - Key, 12); string degreeName = degreeNames[degree]; var degreeTextLayout = TextLayoutCache.Get(degreeName, brush, 12); var degreeTextPosition = new Point(4, (int)(top + (TrackHeight - degreeTextLayout.Height) / 2)); diff --git a/OpenUtau/ViewModels/NotesViewModel.cs b/OpenUtau/ViewModels/NotesViewModel.cs index c2a1d1fd5..3a319f43c 100644 --- a/OpenUtau/ViewModels/NotesViewModel.cs +++ b/OpenUtau/ViewModels/NotesViewModel.cs @@ -43,6 +43,7 @@ public class NotesViewModel : ViewModelBase, ICmdSubscriber { [Reactive] public double TickOffset { get; set; } [Reactive] public double TrackOffset { get; set; } [Reactive] public int SnapDiv { get; set; } + [Reactive] public int Key { get; set; } public ObservableCollectionExtended SnapTicks { get; } = new ObservableCollectionExtended(); [Reactive] public double PlayPosX { get; set; } [Reactive] public double PlayPosHighlightX { get; set; } @@ -108,6 +109,7 @@ public class NotesViewModel : ViewModelBase, ICmdSubscriber { private string? portraitSource; private readonly object portraitLock = new object(); private int userSnapDiv = -2; + private int userKey => Project.key; public NotesViewModel() { SnapDivs = new List(); @@ -317,8 +319,8 @@ private void UpdateSnapDiv() { } private void UpdateKey(){ - int key = Project.key; - KeyText = "1="+MusicMath.KeysInOctave[key].Item1; + Key = userKey; + KeyText = "1="+MusicMath.KeysInOctave[userKey].Item1; } public void OnXZoomed(Point position, double delta) { diff --git a/OpenUtau/Views/PianoRollWindow.axaml b/OpenUtau/Views/PianoRollWindow.axaml index 0dd283d6e..579338222 100644 --- a/OpenUtau/Views/PianoRollWindow.axaml +++ b/OpenUtau/Views/PianoRollWindow.axaml @@ -59,6 +59,7 @@ DataContext="{Binding NotesViewModel}" TrackHeight="{Binding TrackHeight}" TrackOffset="{Binding TrackOffset}" + Key="{Binding Key}" PointerWheelChanged="KeyboardPointerWheelChanged" PointerPressed="KeyboardPointerPressed" PointerMoved="KeyboardPointerMoved"