using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows; using static QuikDawEditor.EDITING.StaticProperties; namespace QuikDawEditor.EDITING.PianoRollModel; public class PianoKey : INotifyPropertyChanged { public PianoKey(int noteval, double keyheight) { NoteNo = noteval; keyYPos = (NumMidiNotesVertical - noteval - 1) * keyheight; switch (noteval % 12) { // C#, Eb, F#, Ab, Bb // Black keys case 1: case 3: PianoKeySourcePlay = "/EDITING/images/PianoKeyB.png"; PianoKeySourceHover = "/EDITING/images/PianoKeyBx.png"; keyYPos -= 1; break; case 6: PianoKeySourcePlay = "/EDITING/images/PianoKeyB.png"; PianoKeySourceHover = "/EDITING/images/PianoKeyBx.png"; keyYPos -= 3; break; case 8: PianoKeySourcePlay = "/EDITING/images/PianoKeyB.png"; PianoKeySourceHover = "/EDITING/images/PianoKeyBx.png"; keyYPos -= 2; break; case 10: PianoKeySourcePlay = "/EDITING/images/PianoKeyB.png"; PianoKeySourceHover = "/EDITING/images/PianoKeyBx.png"; break; case 0: case 5: PianoKeySourcePlay = "/EDITING/images/PianoKeyWL.png"; PianoKeySourceHover = "/EDITING/images/PianoKeyWLx.png"; keyYPos -= 6; break; case 4: case 11: PianoKeySourcePlay = "/EDITING/images/PianoKeyWR.png"; PianoKeySourceHover = "/EDITING/images/PianoKeyWRx.png"; keyYPos -= 1; break; case 2: case 7: case 9: PianoKeySourcePlay = "/EDITING/images/PianoKeyWC.png"; PianoKeySourceHover = "/EDITING/images/PianoKeyWCx.png"; keyYPos -= 5; break; } } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public int NoteNo; public Visibility PianoKeyVisibility { get { return _IsPlaying | _IsHovering ? Visibility.Visible : Visibility.Hidden; } } public string PianoKeySource { get { return IsPlaying ? PianoKeySourcePlay : IsHovering ? PianoKeySourceHover : PianoKeySourceHover; } } private string PianoKeySourcePlay; private string PianoKeySourceHover; private double _PianoKeyOpacity = 0.8; public double PianoKeyOpacity { get { return _PianoKeyOpacity; } set { _PianoKeyOpacity = value; NotifyPropertyChanged(nameof(PianoKeyOpacity)); } } private bool _IsPlaying = false; private bool _IsHovering = false; public bool IsPlaying { get { return _IsPlaying; } set { _IsPlaying = value; NotifyPropertyChanged(nameof(PianoKeySource)); NotifyPropertyChanged(nameof(PianoKeyVisibility)); } } public bool IsHovering { get { return _IsHovering; } set { _IsHovering = value; NotifyPropertyChanged(nameof(PianoKeySource)); NotifyPropertyChanged(nameof(PianoKeyVisibility)); } } public Thickness PianoKeyMargin { get { return new Thickness(-1, _keyYPos, 0, 0); } } private double _keyYPos = 0; public double keyYPos { get { return _keyYPos; } set { _keyYPos = value; NotifyPropertyChanged(nameof(PianoKeyMargin)); } } }