Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key scale change function modified. #1325

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading