示例#1
0
        public static Note GetNote(Tone t)
        {
            // This is horrible code, thomas. Please fix this before
            // you rely on it too much and cant change it (again)
            switch (t)
            {
            case Tone.A:
                return(a);

            case Tone.B:
                return(b);

            case Tone.C:
                return(c);

            case Tone.Cs:
                return(c_s);

            case Tone.D:
                return(d);

            case Tone.Ds:
                return(d_s);

            case Tone.E:
                return(e);

            case Tone.F:
                return(f);

            case Tone.Fs:
                return(f_s);

            case Tone.G:
                return(g);

            case Tone.Gs:
                return(g_s);

            default:
                return(Rest);
            }
        }
示例#2
0
        /// <summary>
        /// Create a new measure from a string.
        /// </summary>
        /// <param name="ABCNotes">A string representing a measure, written in ABC notation.</param>
        /// <param name="scale">The scale the measure uses tones from.</param>
        public Measure(String ABCNotes, Scale scale)
        {
            Notes = new List <Note>();
            double    length    = .25;
            ToneClass toneClass = null;
            Tone      tone      = null;
            Note      note      = null;
            int       index     = 0;

            while (index < ABCNotes.Length)
            {
                if (Char.IsLetter(ABCNotes[index]))
                {
                    if (note != null)
                    {
                        Notes.Add(note);
                        note   = null;
                        tone   = null;
                        length = .25;
                    }
                    toneClass = scale.GetTone(ABCNotes[index].ToString());
                    tone      = new Tone(toneClass, Char.IsLower(ABCNotes[index]) ? 1 : 0);
                    note      = new Note(tone, length);
                }
                else if (Char.IsNumber(ABCNotes[index]))
                {
                    int numberLength = 1;
                    while (index + numberLength < ABCNotes.Length && Char.IsNumber(ABCNotes[index + numberLength]))
                    {
                        numberLength++;
                    }
                    int times = int.Parse(ABCNotes.Substring(index, numberLength));
                    note = new Note(tone, length * times);
                }
                index++;
            }
            Notes.Add(note);
        }
示例#3
0
 public Note(Tone value)
 {
     Value = value;
 }