示例#1
0
        private MMLLength GetRest(MMLCommand cmd, out double measureLength)
        {
            MMLLength rest = GetLength(cmd.Args[0], cmd.Args[1]);

            measureLength = 1.0 / rest.Length * (rest.Dotted ? 1.5 : 1.0);
            return(rest);
        }
        private Note GetNoteNormal(MMLCommand cmd, out double measureLength, MMLLength defaultLength, int currentOctave, double currentSpm)
        {
            Note note = new Note
            {
                Volume = (float)this.volume / 15f,
                Octave = currentOctave,
                Type   = cmd.Args[0].ToLowerInvariant()[0]
            };
            string text = cmd.Args[1];

            if (text != null)
            {
                if (text == "#" || text == "+")
                {
                    base.Step(ref note, 1);
                    goto IL_9C;
                }
                if (text == "-")
                {
                    base.Step(ref note, -1);
                    goto IL_9C;
                }
            }
            note.Sharp = false;
IL_9C:
            MMLLength mmlLen = this.GetLength(cmd.Args[2], cmd.Args[3], defaultLength);

            note.Length   = mmlLen.ToTimeSpan(currentSpm);
            measureLength = 1.0 / (double)mmlLen.Length;
            if (mmlLen.Dotted)
            {
                measureLength *= 1.5;
            }
            return(note);
        }
        private Note GetNoteNumber(MMLCommand cmd, out double measureLength, MMLLength defaultLength, double currentSpm)
        {
            Note note = new Note
            {
                Volume = (float)this.volume / 15f,
                Octave = 1,
                Type   = 'c'
            };
            int noteNumber = Convert.ToInt32(cmd.Args[0]) - 12;
            int octavesUp  = noteNumber / 12;
            int steps;

            if (octavesUp != 0)
            {
                steps = noteNumber % (octavesUp * 12);
            }
            else
            {
                steps = noteNumber;
            }
            note.Octave += octavesUp;
            base.Step(ref note, steps);
            MMLLength mmlLen = this.GetLength("", cmd.Args[1], defaultLength);

            note.Length   = mmlLen.ToTimeSpan(currentSpm);
            measureLength = 1.0 / (double)mmlLen.Length;
            if (mmlLen.Dotted)
            {
                measureLength *= 1.5;
            }
            return(note);
        }
 private Note GetNote(MMLCommand cmd, out double measureLength, MMLLength defaultLength, int currentOctave, double currentSpm)
 {
     if (cmd.Type == MMLCommandType.Note)
     {
         return(this.GetNoteNormal(cmd, out measureLength, defaultLength, currentOctave, currentSpm));
     }
     return(this.GetNoteNumber(cmd, out measureLength, defaultLength, currentSpm));
 }
示例#5
0
 private void SetDefaultValues()
 {
     octave        = 4;
     length        = new MMLLength(4, false);
     Tempo         = 120;
     volume        = 8;
     cmdIndex      = 0;
     nextNoteIndex = 0;
     nextCommand   = 0;
 }
示例#6
0
        private MMLLength GetLength(string number, string dot, MMLLength defaultLength)
        {
            MMLLength l = defaultLength;

            if (!string.IsNullOrEmpty(number))
            {
                l = new MMLLength(Convert.ToInt32(number), dot != "");
            }
            else if (!string.IsNullOrEmpty(dot))
            {
                l.Dotted = true;
            }
            return(l);
        }
示例#7
0
        private Note GetNoteNumber(MMLCommand cmd, out double measureLength, MMLLength defaultLength, double currentSpm)
        {
            Note note = new Note();

            note.Volume = volume / 15f;
            note.Octave = 1;
            note.Type   = 'c';

            // 12 == C1
            int noteNumber = Convert.ToInt32(cmd.Args[0]) - 12;
            int octavesUp  = noteNumber / 12;

            int steps;

            if (octavesUp != 0)
            {
                steps = noteNumber % (octavesUp * 12);
            }
            else
            {
                steps = noteNumber;
            }

            note.Octave += octavesUp;
            Step(ref note, steps);

            var mmlLen = GetLength("", cmd.Args[1], defaultLength);

            note.Length = mmlLen.ToTimeSpan(currentSpm);

            measureLength = 1.0 / mmlLen.Length;
            if (mmlLen.Dotted)
            {
                measureLength *= 1.5;
            }

            return(note);
        }
示例#8
0
        private Note GetNoteNormal(MMLCommand cmd, out double measureLength, MMLLength defaultLength, int currentOctave, double currentSpm)
        {
            Note note = new Note
            {
                Volume = volume / 15f,
                Octave = currentOctave,
                Type   = cmd.Args[0].ToLowerInvariant()[0]
            };

            switch (cmd.Args[1])
            {
            case "#":
            case "+":
                Step(ref note, +1);
                break;

            case "-":
                Step(ref note, -1);
                break;

            default:
                note.Sharp = false;
                break;
            }

            var mmlLen = GetLength(cmd.Args[2], cmd.Args[3], defaultLength);

            note.Length = mmlLen.ToTimeSpan(currentSpm);

            measureLength = 1.0 / mmlLen.Length;
            if (mmlLen.Dotted)
            {
                measureLength *= 1.5;
            }

            return(note);
        }
示例#9
0
 protected virtual void SetLength(MMLCommand cmd, ref MMLLength len)
 {
     len = new MMLLength(Convert.ToInt32(cmd.Args[0]), cmd.Args[1] != "");
 }
        private void NextNote()
        {
            bool noteFound = false;

            while (!noteFound && this.cmdIndex < this.commands.Count)
            {
                MMLCommand cmd = this.commands[this.cmdIndex];
                if (cmd.Type == MMLCommandType.Note || cmd.Type == MMLCommandType.NoteNumber)
                {
                    noteFound = true;
                    double measureLength;
                    Note   note = this.GetNote(cmd, out measureLength, this.length, this.octave, this.spm);
                    this.nextCommand = this.nextNote + measureLength;
                    if (this.cmdIndex >= this.nextNoteIndex)
                    {
                        bool      tied            = false;
                        int       lookAheadIndex  = this.cmdIndex + 1;
                        int       lookAheadOctave = this.octave;
                        int       lookAheadTempo  = this.tempo;
                        double    lookAheadSpm    = this.spm;
                        MMLLength lookAheadLen    = this.length;
                        while (lookAheadIndex < this.commands.Count)
                        {
                            MMLCommandType type = this.commands[lookAheadIndex].Type;
                            if (type == MMLCommandType.Tie)
                            {
                                tied = true;
                            }
                            else
                            {
                                if (type == MMLCommandType.Rest)
                                {
                                    break;
                                }
                                if (type == MMLCommandType.Octave)
                                {
                                    lookAheadOctave = Convert.ToInt32(this.commands[lookAheadIndex].Args[0]);
                                }
                                else if (type == MMLCommandType.OctaveDown)
                                {
                                    lookAheadOctave--;
                                }
                                else if (type == MMLCommandType.OctaveDown)
                                {
                                    lookAheadOctave++;
                                }
                                else if (type == MMLCommandType.Tempo)
                                {
                                    this.SetTempoAndSecondsPerMeasure(Convert.ToInt32(this.commands[lookAheadIndex].Args[0]), ref lookAheadTempo, ref lookAheadSpm);
                                }
                                else if (type == MMLCommandType.Length)
                                {
                                    this.SetLength(this.commands[lookAheadIndex], ref lookAheadLen);
                                }
                                else if (type == MMLCommandType.Note || type == MMLCommandType.NoteNumber)
                                {
                                    if (!tied)
                                    {
                                        break;
                                    }
                                    tied = false;
                                    double tiedLength;
                                    Note   tiedNote = this.GetNote(this.commands[lookAheadIndex], out tiedLength, lookAheadLen, lookAheadOctave, lookAheadSpm);
                                    if (tiedNote.Sharp != note.Sharp || tiedNote.Type != note.Type || tiedNote.Octave != note.Octave)
                                    {
                                        break;
                                    }
                                    note.Length       += tiedNote.Length;
                                    measureLength     += tiedLength;
                                    this.nextNoteIndex = lookAheadIndex + 1;
                                }
                            }
                            lookAheadIndex++;
                        }
                        this.nextNote += measureLength;
                        this.notes.Add(this.ValidateAndPlayNote(note));
                    }
                }
                else if (cmd.Type == MMLCommandType.Rest)
                {
                    double measureLength2;
                    this.GetRest(cmd, out measureLength2);
                    this.nextNote   += measureLength2;
                    this.nextCommand = this.nextNote;
                    noteFound        = true;
                }
                else
                {
                    this.ProcessCommand(cmd);
                }
                this.cmdIndex++;
            }
        }
示例#11
0
 private void SetDefaultValues()
 {
     octave = 4;
     length = new MMLLength(4, false);
     Tempo = 120;
     volume = 8;
     cmdIndex = 0;
     nextNoteIndex = 0;
     nextCommand = 0;
 }
示例#12
0
        private Note GetNoteNumber(MMLCommand cmd, out double measureLength, MMLLength defaultLength, double currentSpm)
        {
            Note note = new Note();

            note.Volume = volume / 15f;
            note.Octave = 1;
            note.Type = 'c';

            // 12 == C1
            int noteNumber = Convert.ToInt32(cmd.Args[0]) - 12;
            int octavesUp = noteNumber / 12;

            int steps;
            if (octavesUp != 0)
                steps = noteNumber % (octavesUp * 12);
            else
                steps = noteNumber;

            note.Octave += octavesUp;
            Step(ref note, steps);

            var mmlLen = GetLength("", cmd.Args[1], defaultLength);
            note.Length = mmlLen.ToTimeSpan(currentSpm);

            measureLength = 1.0 / mmlLen.Length;
            if (mmlLen.Dotted)
                measureLength *= 1.5;

            return note;
        }
示例#13
0
        private Note GetNoteNormal(MMLCommand cmd, out double measureLength, MMLLength defaultLength, int currentOctave, double currentSpm)
        {
            Note note = new Note();

            note.Volume = volume / 15f;
            note.Octave = currentOctave;
            note.Type = cmd.Args[0].ToLowerInvariant()[0];

            switch (cmd.Args[1]) {
                case "#":
                case "+":
                    Step(ref note, +1);
                    break;
                case "-":
                    Step(ref note, -1);
                    break;
                default:
                    note.Sharp = false;
                    break;
            }

            var mmlLen = GetLength(cmd.Args[2], cmd.Args[3], defaultLength);
            note.Length = mmlLen.ToTimeSpan(currentSpm);

            measureLength = 1.0 / mmlLen.Length;
            if (mmlLen.Dotted)
                measureLength *= 1.5;

            return note;
        }
示例#14
0
 private Note GetNote(MMLCommand cmd, out double measureLength, MMLLength defaultLength, int currentOctave, double currentSpm)
 {
     if (cmd.Type == MMLCommandType.Note) {
         return GetNoteNormal(cmd, out measureLength, defaultLength, currentOctave, currentSpm);
     }
     else {
         return GetNoteNumber(cmd, out measureLength, defaultLength, currentSpm);
     }
 }
示例#15
0
 private MMLLength GetLength(string number, string dot, MMLLength defaultLength)
 {
     MMLLength l = defaultLength;
     if (!string.IsNullOrEmpty(number))
         l = new MMLLength(Convert.ToInt32(number), dot != "");
     else if (!string.IsNullOrEmpty(dot))
         l.Dotted = true;
     return l;
 }
示例#16
0
 protected virtual void SetLength(MMLCommand cmd, ref MMLLength len)
 {
     len = new MMLLength(Convert.ToInt32(cmd.Args[0]), cmd.Args[1] != "");
 }