private void AddPitchToSymbol(int keyCode)
        {
            Tone       tone = Tone.C;
            Accidental acc  = Accidental.None;

            int toneNumber = keyCode % Constants.TONES_IN_OCTAVE;

            var values = Enum.GetValues(typeof(Tone)).Cast <int>();

            for (int i = 0; i <= toneNumber; i++)
            {
                if (values.Contains(i))
                {
                    tone = (Tone)i;
                    acc  = Accidental.None;
                }
                else
                {
                    acc = Accidental.Sharp;
                }
            }

            if (currentSymbolBuilder == null)
            {
                currentSymbolBuilder = new SymbolBuilder();
            }
            currentSymbolBuilder.WithPitch(tone, acc, GetOctaveOffset(keyCode));
        }
Exemplo n.º 2
0
        public Token Convert(LilypondTokenEnumerator enumerator)
        {
            var input = enumerator.Current;
            var match = noteRegex.Match(input.TokenText);

            if (match.Success)
            {
                SymbolBuilder builder    = new SymbolBuilder();
                var           tone       = GetToneFromLetter(match.Groups[1].Value);
                Accidental    accidental = Accidental.None;
                if (match.Groups[2].Success)
                {
                    accidental = match.Groups[2].Value == "is" ? Accidental.Sharp : Accidental.Flat;
                }
                // determine octave
                MoveToClosestOctaveOffset(tone);
                previousNoteTone = tone;
                if (match.Groups[3].Success)
                {
                    UpdateOctaveOffset(match.Groups[3].Value);
                }
                // set pitch
                builder.WithPitch(tone, accidental, octaveOffset);
                // determine length
                if (int.TryParse(match.Groups[4].Value, out int denominator))
                {
                    int dots = match.Groups[5].Length;
                    builder.WithLength(denominator, dots);
                }
                return(builder.Build());
            }
            else
            {
                throw new InvalidOperationException("Not a note that can be read");
            }
        }