Esempio n. 1
0
        private void DealNums()
        {
            int i = int.Parse(str);

            str = "";
            if (arrange)
            {
                chordArr.Add(i);
            }
            if (i == 0)
            {
                return;        //休止符暂不支持
            }
            int pitch = PitchTool.Pitch8_to_12(i - 1);

            note.scale = scale;
            note.pitch = (Pitch)(pitchShift + pitch);
            pitchShift = 0;

            if (multiNote)
            {
                noteMulti.Append(); // 往多音音符里 添加新的单音
            }
            else//!multiNote
            {
                chord_Append();
            }
        }
Esempio n. 2
0
 void Start()
 {
     loader           = FindObjectOfType <ScoreLoader>();
     gen              = FindObjectOfType <ScoreGen>();
     grids[0].onClick = (i) => PlayPitch(PitchTool.Pitch8_to_12(i));
     grids[1].onClick = (i) => PlayPitch(PitchTool.Pitch5_to_12(i));
     this.AddInput(Input, -1, false);
 }
Esempio n. 3
0
        private void Input()
        {
            if (Events.Shift)
            {
                scaleCurr = scaleMid + 1;
            }
            else if (Events.Ctrl)
            {
                scaleCurr = scaleMid - 1;
            }
            else
            {
                scaleCurr = scaleMid;
            }
            src.UnHold();
            foreach (var grid in grids)
            {
                foreach (var gup in grid.gridUnitProp)
                {
                    gup.clickable = true;
                }
            }
            piano.notePress = new List <Note>();
            for (int i = 0; i < keys.Length; i++)
            {
                var idx  = PitchTool.Pitch12To8_5_Align(i);
                var grid = idx > 0 ? 0 : 1;
                if (Events.KeyDown(keys[i]))
                {
                    PlayPitch(i);
                    grids[grid].gridUnitProp[Mathf.Abs(idx) - 1].clickable = false;
                }
                if (Events.Key(keys[i]))
                {
                    grids[grid].gridUnitProp[Mathf.Abs(idx) - 1].clickable = false;
                    HoldPitch(i);
                }
            }
            // 支持同时按下的按键数量取决键盘设备(的电路设计?),一般为2~5个键,
            // 不包括Shift和Ctrl,这类特殊键一般可以额外同时按下。
            // A~Z字母键能确保2个键同时按下,3个及以上就“不一定”了。
            // 据说专门的游戏可以支持更多键。
            // 比如我的键盘可以同时按 QRXC 四个键, 但按不了 QRV、QRB。
            scaleCurr--;
            for (int i = 0; i < keysLow.Length; i++)
            {
                if (Events.KeyDown(keysLow[i]))
                {
                    PlayPitch(i);
                }
                if (Events.Key(keysLow[i]))
                {
                    HoldPitch(i);
                }
            }
            for (int i = 0; i < keysChord.Length; i++)
            {
                if (Events.KeyDown(keysChord[i]))
                {
                    PlayChord(i);
                }
            }
            if (Events.KeyDown(KeyCode.CapsLock))
            {
                UIChord.I.scaleShift = !UIChord.I.scaleShift;
            }
            if (Events.KeyDown(KeyCode.F1, KeyCode.F5))
            {
                loader.Start();
            }
            if (Events.KeyDown(KeyCode.BackQuote, KeyCode.Alpha1))
            {
                if (chordIdx > 0 && chordIdx - 1 < loader.chordParser.chordArr.Count)
                {
                    PlayChordArr(chordIdx - 1);
                }
            }
            else if (Events.KeyDown(KeyCode.Space))
            {
                chordIdx++;
                if (chordIdx > 0 && chordIdx - 1 < loader.chordParser.chordArr.Count)
                {
                    PlayChordArr(chordIdx - 1);
                }
            }

            if (chordPlaying != null && chordPlaying.notes.NotEmpty())
            {
                chordPlaying.Update();
                if (chordPlaying.t >= chordPlaying.endTime.Last())
                {
                    chordPlaying = null;
                }
            }
        }
Esempio n. 4
0
        void Update()
        {
            if (notePress.Count == 0)
            {
                whiteMesh.vertices = whiteMeshVerts;
                blackMesh.vertices = blackMeshVerts;
                return;
            }

            Vector3[] vsWhite, vsBlack;
            vsWhite = whiteMeshVerts.CloneArray();
            vsBlack = blackMeshVerts.CloneArray();

            var stack = new Stack <Note>(notePress);

stackLoop:

            var posIdx = stack.Pop() - rng.min;

            idx0 = posIdx;
            if (posIdx > (rng.max - rng.min))
            {
                throw new Exception("over range");
            }
            posIdx += os;
            int pitch = posIdx % 12;
            int scale = posIdx / 12;
            var idx   = PitchTool.Pitch12To8_5(pitch);

            white  = idx > 0;
            posIdx = Mathf.Abs(idx) - 1;


            Vector3 pos;

            if (white)
            {
                posIdx += 2 + scale * 7;

                posIdx = Mathf.Clamp(posIdx, 0, whiteKeysPos.vectors.Count);
                pos    = whiteKeysPos.vectors[posIdx];
                var whiteListDI = new List <DistIdx>();
                for (int i = 0; i < whiteMeshVerts.Length; i++)
                {
                    var p = whiteKeys.TransformPoint(whiteMeshVerts[i]);
                    whiteListDI.Add(new DistIdx(i, Vector3.Distance(p.X(), pos.X())));
                }

                if (sortRev)
                {
                    whiteListDI.Sort(DistIdx.SortRev);
                }
                else
                {
                    whiteListDI.Sort(DistIdx.Sort);
                }

                for (int i = 0; i < whiteNearsCount; i++)
                {
                    vsWhite[whiteListDI[i].idx] += whitePressOffset;
                }
            }
            else
            {
                posIdx += 1 + scale * 5;

                posIdx = Mathf.Clamp(posIdx, 0, blackKeysPos.vectors.Count);
                pos    = blackKeysPos.vectors[posIdx];
                var blackListDI = new List <DistIdx>();
                for (int i = 0; i < blackMeshVerts.Length; i++)
                {
                    var p = blackKeys.TransformPoint(blackMeshVerts[i]);
                    blackListDI.Add(new DistIdx(i, Vector3.Distance(p.X(), pos.X())));
                }

                if (sortRev)
                {
                    blackListDI.Sort(DistIdx.SortRev);
                }
                else
                {
                    blackListDI.Sort(DistIdx.Sort);
                }

                for (int i = 0; i < blackNearsCount; i++)
                {
                    vsBlack[blackListDI[i].idx] += blackPressOffset;
                }
            }
            if (stack.Count > 0)
            {
                goto stackLoop;
            }

            whiteMesh.vertices = vsWhite;
            blackMesh.vertices = vsBlack;
        }
Esempio n. 5
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;
            }
        }