コード例 #1
0
        public Note(int octave, Tone tone, bool sharped)
        {
            if (sharped && !tone.IsSharpable())
            {
                var vals = Enum.GetValues(typeof(Tone)).Cast <Tone>().ToList();

                int index = -1;
                for (int i = 0; i < vals.Count; i++)
                {
                    if (vals[i] == tone)
                    {
                        index = i;

                        break;
                    }
                }

                tone    = vals[index + 1];
                sharped = false;
            }

            if (octave < 0 || octave > 2 || (octave == 2 && !(tone == Tone.F && sharped)))
            {
                throw new ArgumentException("Tone and octave have to be between F#0 and F#2");
            }

            this.note = (byte)(octave * Note.TONES_COUNT + tone.GetId(sharped));
        }