Esempio n. 1
0
        private void OnDraw()
        {
            // 放置两个按钮
            PlaceButton();
            // 绘制乐谱信息
            DrawScoreInfo();

            // 绘制乐谱内容
            float   startX            = 67f / 2;
            float   startY            = _screenSize[1] - 250;
            Vector3 paragraphPosition = new Vector3(startX, startY, 0);

            // 遍历scoreList,对每一行来绘制
            for (int i = 0; i < _scoreList.Count; i++)
            {
                // 新建paragraph画布,每一行有自己的画布
                string     objName         = "Paragraph" + (i + 1);
                GameObject paragraphObject = new GameObject(objName);
                Canvas     paragraphCanvas = paragraphObject.AddComponent <Canvas>();
                paragraphCanvas.transform.SetParent(_parentObject.transform);
                RectTransform rect = paragraphCanvas.GetComponent <RectTransform>();
                // 设置位置为以画布左下角为坐标原点
                rect.anchorMin = Vector2.zero; rect.anchorMax = Vector2.zero; rect.pivot = new Vector2(0.5f, 0.5f);
                rect.position  = new Vector3(paragraphPosition.x,
                                             paragraphPosition.y - 2 * _paramsGetter.GetTotalHeight() * i,
                                             paragraphPosition.z);

                // 将paragraph画布对象赋为下一层的父对象
                // 绘制每一行的视图
                ParagraphView paragraphView = new ParagraphView(_scoreList[i], paragraphObject);
            }
        }
Esempio n. 2
0
        private void OnDraw()
        {
            Vector3 notePosition = Vector3.zero;
            float   noteLength   = _setLength;
            int     maxCount     = Math.Max(_highSymbolList.Count, _lowSymbolList.Count);

            if (_setList.Count != 0)
            {
                noteLength = _setLength / maxCount;
            }

            for (int i = 0; i < _highSymbolList.Count; i++)
            {
                // 新建HighNote对象作为目录
                string     objName     = "HighNote" + (i + 1);
                GameObject highNoteObj = new GameObject(objName);
                highNoteObj.transform.SetParent(_parentObject.transform);
                highNoteObj.transform.localPosition = new Vector3(
                    notePosition.x + _paramsGetter.GetBeatWidth() + noteLength * i,
                    notePosition.y + _paramsGetter.GetTotalHeight(),
                    notePosition.z);

                // 将Set对象赋为下一层的父对象
                if (_highSymbolList[i] is Note)
                {
                    NoteView noteView = new NoteView(_highSymbolList[i], (int)noteLength, _paramsGetter.GetSymbolStart(), highNoteObj);
                    _highSymbolList[i].SetSymbolView(noteView);
                }
                else if (_highSymbolList[i] is Rest)
                {
                    RestView restView = new RestView(_highSymbolList[i], (int)noteLength, _paramsGetter.GetSymbolStart(), highNoteObj);
                    _highSymbolList[i].SetSymbolView(restView);
                }
            }
            for (int i = 0; i < _lowSymbolList.Count; i++)
            {
                // 新建LowNote对象作为目录
                string     objName    = "LowNote" + (i + 1);
                GameObject lowNoteObj = new GameObject(objName);
                lowNoteObj.transform.SetParent(_parentObject.transform);
                lowNoteObj.transform.localPosition = new Vector3(
                    notePosition.x + _paramsGetter.GetBeatWidth() + noteLength * i,
                    notePosition.y,
                    notePosition.z);

                // 将Set对象赋为下一层的父对象
                if (_lowSymbolList[i] is Note)
                {
                    NoteView noteView = new NoteView(_lowSymbolList[i], (int)noteLength, _paramsGetter.GetSymbolStart(), lowNoteObj);
                    _lowSymbolList[i].SetSymbolView(noteView);
                }
                else if (_lowSymbolList[i] is Rest)
                {
                    RestView restView = new RestView(_lowSymbolList[i], (int)noteLength, _paramsGetter.GetSymbolStart(), lowNoteObj);
                    _lowSymbolList[i].SetSymbolView(restView);
                }
            }
        }
Esempio n. 3
0
        protected override void OnDraw()
        {
            // 绘制定位光标
            if (Cursor)
            {
                int tempStart = Start - 2 + Num * _rest.GetSymbolWidth();
                DrawLine(tempStart, 0, tempStart, ParamsGetter.GetTotalHeight());
            }

            // 乐符的位置
            int yPosition = ParamsGetter.GetStaffCenterPosition();

            // 如果是点,绘制
            if (_rest.GetDot() == 1)
            {
                DrawPoint(Start + ParamsGetter.GetDotePosition(), yPosition);
            }

            // 乐符的内容
            switch (Type)
            {
            case 1: DrawSymbol("\uE100", Start, yPosition); break;

            case 2: DrawSymbol("\uE101", Start, yPosition); break;

            case 4: DrawSymbol("\uE107", Start, yPosition); break;

            case 8: DrawSymbol("\uE109", Start, yPosition); break;

            case 16: DrawSymbol("\uE10A", Start, yPosition); break;

            case 32: DrawSymbol("\uE10B", Start, yPosition); break;

            case 64: DrawSymbol("\uE10C", Start, yPosition); break;

            case 128: DrawSymbol("\uE10D", Start, yPosition); break;

            default: break;
            }
        }
Esempio n. 4
0
        private void OnDraw()
        {
            int shift = 0; // 谱号偏移,如果是高音谱号偏移整个五线谱长度

            switch (_head.GetSign())
            {
            case "G":     // 高音符号G
                shift = _paramsGetter.GetTotalHeight();
                DrawSymbol("\uE19E", _paramsGetter.GetClefPortraitShift(), _paramsGetter.GetStaffCenterPosition() + shift);
                break;

            case "F":     // 低音符号F
                shift = 0;
                DrawSymbol("\uE19C", _paramsGetter.GetClefPortraitShift(), _paramsGetter.GetStaffCenterPosition() + shift);
                break;

            default: break;
            }

            float first  = _paramsGetter.GetFirstFifthsPosition();
            float second = _paramsGetter.GetSecondFifthsPosition();

            switch (_head.GetFifths())
            {
            case "2":
            {
                DrawSymbol("\uE10E", first, _paramsGetter.GetStaffPosition() + shift);     // #
                DrawSymbol("\uE10E", second, _paramsGetter.GetStaffCenterPosition() + shift);
            }
            break;

            case "1": DrawSymbol("\uE10E", first, _paramsGetter.GetStaffPosition() + shift); break;

            case "-1": DrawSymbol("\uE114", first, _paramsGetter.GetStaffCenterPosition() + shift); break;     // B

            default: break;
            }
        }
Esempio n. 5
0
        // 绘制一行乐谱线,根据小节数来绘制
        private void DrawMeasureLines()
        {
            // 为线段构建一个Lines目录放置
            _measureLines = new GameObject("Lines");
            _measureLines.transform.SetParent(_parentObject.transform);
            _measureLines.transform.localPosition = new Vector3(0, 0, 0);

            int measureLength = _measure.GetMeasureLength();

            // 绘制高音五条横乐谱线
            for (int i = 0; i < 5; i++)
            {
                // 横线的纵坐标固定,第三条线(j==2)在乐谱中心位置
                float yPosition = _paramsGetter.GetTotalHeight() + _paramsGetter.GetStaffCenterPosition() + (i - 2) * _paramsGetter.GetUnit();
                // 设置线段宽高,横线,宽度为小节长度,高度为1
                DrawLine(0, yPosition, measureLength, yPosition);
            }
            // 绘制每个高音小节的两条竖线
            for (int i = 0; i < 2; i++)
            {
                // 竖线的纵坐标起点为五条横线的最下面一条线的纵坐标
                float startY = _paramsGetter.GetTotalHeight() + _paramsGetter.GetStaffCenterPosition() - 2 * _paramsGetter.GetUnit();
                float stopY  = _paramsGetter.GetTotalHeight() + _paramsGetter.GetStaffCenterPosition() + 2 * _paramsGetter.GetUnit();
                // 设置线段宽高,竖线,宽度为1,高度五线谱高度
                DrawLine(measureLength * i, startY, measureLength * i, stopY);
            }

            // 绘制低音五条横乐谱线
            for (int i = 0; i < 5; i++)
            {
                // 横线的纵坐标固定,第三条线(j==2)在乐谱中心位置
                float yPosition = _paramsGetter.GetTotalHeight() - _paramsGetter.GetStaffCenterPosition() + (i - 2) * _paramsGetter.GetUnit();
                // 设置线段宽高,横线,宽度为小节长度,高度为1
                DrawLine(0, yPosition, measureLength, yPosition);
            }
            // 绘制每个低音小节的两条竖线
            for (int i = 0; i < 2; i++)
            {
                // 竖线的纵坐标起点为五条横线的最下面一条线的纵坐标
                float startY = _paramsGetter.GetTotalHeight() - _paramsGetter.GetStaffCenterPosition() - 2 * _paramsGetter.GetUnit();
                float stopY  = _paramsGetter.GetTotalHeight() - _paramsGetter.GetStaffCenterPosition() + 2 * _paramsGetter.GetUnit();
                // 设置线段宽高,竖线,宽度为1,高度五线谱高度
                DrawLine(measureLength * i, startY, measureLength * i, stopY);
            }
        }
Esempio n. 6
0
 private void OnDraw()
 {
     DrawText(_beat.GetBeats(), _paramsGetter.GetBeatPortraitShift(), _paramsGetter.GetStaffCenterPosition() + _paramsGetter.GetUnit() + _paramsGetter.GetTotalHeight());
     DrawText(_beat.GetBeatType(), _paramsGetter.GetBeatPortraitShift(), _paramsGetter.GetStaffCenterPosition() - _paramsGetter.GetUnit() + _paramsGetter.GetTotalHeight());
 }
Esempio n. 7
0
        protected override void OnDraw()
        {
            // 绘制定位线
            if (Cursor)
            {
                int tempStart = Start - 2 + Num * _note.GetSymbolWidth();
                DrawLine(tempStart, 0, tempStart, ParamsGetter.GetTotalHeight());
            }

            // 乐符纵坐标
            int yPosition = ParamsGetter.GetStaffCenterPosition() + _note.GetShift();

            int shift = _note.GetShift() / ParamsGetter.GetPitchPositionDiff();

            // 偏移线,当超过6的时候会画线。传入参数为shift,因为以左下角为原点
            DrawShiftLine(shift);
            // 绘制变音记号
            DrawAccidental(_note.GetAccidental(), yPosition);

            if (_note.GetDot() == 1)
            {
                DrawPoint(Start + ParamsGetter.GetDotePosition(), yPosition);
            }

            if (Type == 1) // 全音符
            {
                DrawSymbol("\uE12B", Start, yPosition);
                if (_note.HasChord())
                {
                    DrawChord();
                }
            }
            else
            {
                if (Type == 2) // 二分之一音符
                {
                    DrawSymbol("\uE12C", Start, yPosition);
                }
                else // 其余的所有
                {
                    DrawSymbol("\uE12D", Start, yPosition);
                }

                if (_note.IsUpOrDown())
                {
                    _stemX = Start + ParamsGetter.GetNoteRightShift(); // 符干向上时横坐标向右偏移
                    _stemY = yPosition;                                // 符干向上时纵坐标与乐符中心纵坐标位置相同
                    _tailX = Start + ParamsGetter.GetNoteTailUpLandscapeShift();
                    _tailY = _stemY + ParamsGetter.GetNoteStemHeight() - ParamsGetter.GetNoteTailDownPortraitShift();
                }
                else
                {
                    _stemX = Start - ParamsGetter.GetNoteLeftShift();         // 符干向下时横坐标向左偏移
                    _stemY = yPosition - ParamsGetter.GetNoteStemDownShift(); // 符干向下时纵坐标与乐符中心纵坐标位置偏移
                    _tailX = Start - ParamsGetter.GetNoteTailDownLandscapeShift();
                    _tailY = _stemY - ParamsGetter.GetNoteStemHeight() + ParamsGetter.GetNoteTailDownPortraitShift();
                }

                _beamX = _stemX;
                _beamY = _note.GetEnd();

                if (_note.HasChord())
                {
                    if (_note.IsUpOrDown())
                    {
                        int temp = _note.GetShift();
                        foreach (Note noteChord in _note.GetChordList())
                        {
                            if (temp > noteChord.GetShift())
                            {
                                temp = noteChord.GetShift();
                            }
                        }
                        _tailY = temp + ParamsGetter.GetNoteStemHeight();
                    }
                    DrawChord();
                }
                DrawStem(); // 画符干
                if (_note.IsSlur())
                {
                    DrawBeam(); // 画符杠
                }
                else
                {
                    DrawTail();
                }
            }
        }