AlphaTab.Rendering.Utils.AccidentalHelper.ApplyAccidental C# (CSharp) Method

ApplyAccidental() public method

Calculates the accidental for the given note and assignes the value to it. The new accidental type is also registered within the current scope
public ApplyAccidental ( Note note ) : AccidentalType
note AlphaTab.Model.Note
return AccidentalType
        public AccidentalType ApplyAccidental(Note note)
        {
            var noteValue = note.RealValue;
            var ks = note.Beat.Voice.Bar.MasterBar.KeySignature;
            var ksi = (ks + 7);
            var index = (noteValue % 12);

            var accidentalToSet = AccidentalType.None;

            var line = RegisterNoteLine(note);

            if (!note.Beat.Voice.Bar.Staff.Track.IsPercussion)
            {
                // the key signature symbol required according to
                var keySignatureAccidental = ksi < 7 ? AccidentalType.Flat : AccidentalType.Sharp;

                // determine whether the current note requires an accidental according to the key signature
                var hasNoteAccidentalForKeySignature = KeySignatureLookup[ksi][index];
                var isAccidentalNote = AccidentalNotes[index];

                var isAccidentalRegistered = _registeredAccidentals.ContainsKey(line);
                if (hasNoteAccidentalForKeySignature != isAccidentalNote && !isAccidentalRegistered)
                {
                    _registeredAccidentals[line] = true;
                    accidentalToSet = isAccidentalNote ? keySignatureAccidental : AccidentalType.Natural;
                }
                else if (hasNoteAccidentalForKeySignature == isAccidentalNote && isAccidentalRegistered)
                {
                    _registeredAccidentals.Remove(line);
                    accidentalToSet = isAccidentalNote ? keySignatureAccidental : AccidentalType.Natural;
                }
            }

            // TODO: change accidentalToSet according to note.AccidentalMode

            return accidentalToSet;
        }