Example #1
0
File: Note.cs Project: wjk17/WSA
        public static NoteVal operator +(NoteVal note, int i)
        {
            var n = new NoteVal(note.scale, note.pitch, note.value);
            var p = n.pitch + i;

loop:
            if (p > Pitch.B)
            {
                p -= 12;
                n.scale++;
            }
            else if (p < Pitch.C)
            {
                p += 12;
                n.scale--;
            }
            else
            {
                n.pitch = p;
                return(n);
            }
            goto loop;
        }
Example #2
0
        private void ReadParaChar(char c)
        {
            switch (c)
            {
            case 'B':     // 如果谱是已经降了的,升回来到原调
                if (pitchParaShifted)
                {
                    pitchParaShift++;
                }
                ppShifts.Add(new PPShift(notesTotal.Count, -1));
                break;

            case 'S':     // 相反
                if (pitchParaShifted)
                {
                    pitchParaShift--;
                }
                ppShifts.Add(new PPShift(notesTotal.Count, 1));
                break;

            case '@':
                chordMode = true;
                break;

            case '_':     // 时值减半 Half Value
                if (lyricMode)
                {
                    lyric.Append(' ');
                }
                else
                {
                    value *= 2;
                }
                break;

            case ' ':     // Beat
                if (lyricMode)
                {
                    if (lyric.multiChars)
                    {
                        lyric.NewWord();
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    if (notes.Count == 0)
                    {
                        break;
                    }
                    beat.notes = notes;
                    notes      = new List <NoteVal>();

                    beats.Add(beat);
                    beat = new Beat();
                }
                break;

            case ',':     // Bar
                if (notes.Count == 0)
                {
                    break;
                }

                ReadParaChar(' ');

                bar.beats = beats;
                beats     = new List <Beat>();

                bars.Add(bar);
                bar = new Bar();
                break;

            case '.':
                break;

            case '-':
                break;

            case '(':     // Flat
                scale--;
                break;

            case ')':     //
                scale++;
                break;

            case '[':     // Sharp
                scale++;
                break;

            case ']':     //
                scale--;
                break;

            case '{':     // Link
                var line = new LinkLine(notesTotal.Count, 0);
                linesStack.Push(line);
                lines.Add(line);
                break;

            case '}':     //
                linesStack.Pop().end = notesTotal.Count - 1;
                break;

            case 'b':
                pitch = -1;
                break;

            case '#':
                pitch = 1;
                break;

            case '0':
                break;    //休止符暂不支持

            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
                int i = PitchTool.Pitch8_to_12(int.Parse(c.ToString()) - 1);
                var n = new NoteVal(scale, (Pitch)(pitch + i), value);
                n += pitchParaShift;
                notes.Add(n);
                notesTotal.Add(n);

                pitch = 0;
                value = valueDivideNum;
                break;

            case '\r':
            case '\n':     // end lyric
                lyricMode        = false;
                lyric.multiChars = false;
                break;

            case '\\':     // start lyric
                lyricMode = true;
                break;

            case '*':
                if (lyricMode)
                {
                    lyric.multiChars = true;
                    lyric.NewWord();
                }
                else
                {
                    goto default;
                }
                break;

            default:
                if (lyricMode)
                {
                    lyric.Append(c);
                }
                else
                {
                    throw new Exception("undef Para Character " + c + ".");
                }
                break;
            }
        }