Skip to content

Commit

Permalink
Merge pull request #1325 from rokujyushi/Fix-key-scale
Browse files Browse the repository at this point in the history
Key scale change function modified.
  • Loading branch information
stakira authored Dec 20, 2024
2 parents 0034e8d + daa93cd commit 07ddbb6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
16 changes: 13 additions & 3 deletions OpenUtau/Controls/TrackBackground.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class TrackBackground : TemplatedControl {
nameof(IsKeyboard),
o => o.IsKeyboard,
(o, v) => o.IsKeyboard = v);
public static readonly DirectProperty<TrackBackground, int> KeyProperty =
AvaloniaProperty.RegisterDirect<TrackBackground, int>(
nameof(Key),
o => o.Key,
(o, v) => o.Key = v);

public double TrackHeight {
get => _trackHeight;
Expand All @@ -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<ThemeChangedEvent>()
Expand All @@ -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();
}
}
Expand All @@ -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:
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 4 additions & 2 deletions OpenUtau/ViewModels/NotesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> SnapTicks { get; } = new ObservableCollectionExtended<int>();
[Reactive] public double PlayPosX { get; set; }
[Reactive] public double PlayPosHighlightX { get; set; }
Expand Down Expand Up @@ -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<MenuItemViewModel>();
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions OpenUtau/Views/PianoRollWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
DataContext="{Binding NotesViewModel}"
TrackHeight="{Binding TrackHeight}"
TrackOffset="{Binding TrackOffset}"
Key="{Binding Key}"
PointerWheelChanged="KeyboardPointerWheelChanged"
PointerPressed="KeyboardPointerPressed"
PointerMoved="KeyboardPointerMoved"
Expand Down

0 comments on commit 07ddbb6

Please sign in to comment.