예제 #1
0
        private void SetShift(Note note, string standardStep, string standardOctave)
        {
            ParamsGetter paramsGetter = ParamsGetter.GetInstance();
            int          shift        = -(GetDigitizedPitch(standardStep, standardOctave) - GetDigitizedPitch(_step, _octave)) *
                                        paramsGetter.GetPitchPositionDiff();

            note.SetShift(shift);
        }
예제 #2
0
        // 绘制和弦
        private void DrawChord()
        {
            bool leftOrRight  = _note.IsUpOrDown();
            int  headPosition = Start;
            int  lastPosition = 0;

//            int chordPaintNum = 0;
            // 绘制和弦中的其他乐符(最后一个乐符即当前乐符,已经绘制),去掉和弦表中的最后一个乐符
            for (int i = 0; i < _note.GetChordList().Count - 1; i++)
            {
                Note extraNote = _note.GetChordList()[i];
                DrawShiftLine(extraNote.GetShift() / ParamsGetter.GetPitchPositionDiff());
                int extraDuration = extraNote.GetType();
                int extraPosition = extraNote.GetShift() + ParamsGetter.GetStaffCenterPosition();
                if (Math.Abs(extraPosition - lastPosition) == ParamsGetter.GetPitchPositionDiff())
                {
                    if (leftOrRight)
                    {
                        headPosition += ParamsGetter.GetNoteHeadWidth();
                    }
                    else
                    {
                        headPosition -= ParamsGetter.GetNoteHeadWidth();
                    }
                    leftOrRight = !leftOrRight;
                }

                if (extraDuration == 1) // 全音符
                {
                    DrawSymbol("\uE12B", headPosition, extraPosition);
                    continue;
                }
                else
                {
                    if (extraDuration == 2)
                    {
                        DrawSymbol("\uE12C", headPosition, extraPosition);
                    }
                    else
                    {
                        DrawSymbol("\uE12D", headPosition, extraPosition);
                    }
                }

                lastPosition = extraPosition;
                int temp;
                if (_note.IsUpOrDown())
                {
                    temp = extraPosition + ParamsGetter.GetNoteStemHeight();
                }
                else
                {
                    temp = extraPosition - ParamsGetter.GetNoteStemHeight();
                }
                DrawLine(_stemX, extraPosition, _stemX, temp);
            }
        }
예제 #3
0
 // 绘制符干
 private void DrawStem()
 {
     if (_note.IsSlur())
     {
         DrawLine(_stemX, _stemY, _stemX, _beamY);
     }
     else
     {
         if (_note.IsUpOrDown())
         {
             DrawLine(_stemX, _stemY, _stemX, _stemY + ParamsGetter.GetNoteStemHeight());
         }
         else
         {
             DrawLine(_stemX, _stemY, _stemX, _stemY - ParamsGetter.GetNoteStemHeight());
         }
     }
 }
예제 #4
0
 // 绘制偏移线
 private void DrawShiftLine(int shift)
 {
     if (shift > 4)
     {
         int num = (shift - 4) / 2 + 1;
         for (int i = 1; i < num; i++)
         {
             int y = ParamsGetter.GetStaffCenterPosition() + (4 + 2 * i) * ParamsGetter.GetPitchPositionDiff();
             DrawLine(Start - 4 - ParamsGetter.GetNoteLeftShift(), y, Start + 4 + ParamsGetter.GetNoteRightShift(), y);
         }
     }
     else if (shift < -4)
     {
         int num = (-4 - shift) / 2 + 1;
         for (int i = 1; i < num; i++)
         {
             int y = ParamsGetter.GetStaffCenterPosition() - (4 + 2 * i) * ParamsGetter.GetPitchPositionDiff();
             DrawLine(Start - 4 - ParamsGetter.GetNoteLeftShift(), y, Start + 4 + ParamsGetter.GetNoteRightShift(), y);
         }
     }
 }
예제 #5
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;
            }
        }
예제 #6
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();
                }
            }
        }
예제 #7
0
        // 绘制符杠
        private void DrawBeam()
        {
            // 绘制符杠,根据之前计算出来的起始x坐标和起始y坐标,画到下一个连音符的x坐标,划的长度为乐符之间的间隔width
            // 两条符杠之间的间隔
            int beamDiff = -ParamsGetter.GetNoteBeamDiff(_note.IsUpOrDown());

            if (_note.IsLast())
            {
                switch (_note.GetLastNote().GetType())
                {
                case 8:
                    DrawLine(_beamX, _beamY, 0, _beamY, 2);
                    break;

                case 16:
                    DrawLine(_beamX, _beamY, 0, _beamY, 2);
                    DrawLine(_beamX, _beamY + beamDiff, 0, _beamY + beamDiff, 2);
                    break;

                case 64:
                    DrawLine(_beamX, _beamY, 0, _beamY, 2);
                    DrawLine(_beamX, _beamY + beamDiff, 0, _beamY + beamDiff, 2);
                    DrawLine(_beamX, _beamY + 2 * beamDiff, 0, _beamY + 2 * beamDiff, 2);
                    break;

                default: break;
                }

                if (_note.GetLastNote().GetDot() != 0)
                {
                    switch ((int)(_note.GetLastNote().GetType() * Math.Pow(2, _note.GetLastNote().GetDot())))
                    {
                    case 16:
                        DrawLine(_beamX, _beamY + beamDiff, 0, _beamY + beamDiff, 2);
                        break;

                    case 32:
                        DrawLine(_beamX, _beamY + beamDiff, 0, _beamY + beamDiff, 2);
                        DrawLine(_beamX, _beamY + 2 * beamDiff, 0, _beamY + 2 * beamDiff, 2);
                        break;

                    default: break;
                    }
                }
            }

            if (_note.IsNext())
            {
                switch (_note.GetType())
                {
                case 8:
                    DrawLine(_beamX - 1, _beamY, Width, _beamY, 2);
                    break;

                case 16:
                    DrawLine(_beamX - 1, _beamY, Width, _beamY, 2);
                    DrawLine(_beamX - 1, _beamY + beamDiff, Width, _beamY + beamDiff, 2);
                    break;

                case 32:
                    DrawLine(_beamX - 1, _beamY, Width, _beamY, 2);
                    DrawLine(_beamX - 1, _beamY + beamDiff, Width, _beamY + beamDiff, 2);
                    DrawLine(_beamX - 1, _beamY + 2 * beamDiff, Width, _beamY + 2 * beamDiff, 2);
                    break;

                default: break;
                }

                if (_note.GetDot() != 0)
                {
                    int temp  = (int)Math.Pow(2, _note.GetDot());
                    int start = (2 * temp - 1) * Width / (2 * temp);
                    switch (_note.GetType() * temp)
                    {
                    case 16:
                        DrawLine(start, _beamY + beamDiff, Width, _beamY + beamDiff, 2);
                        break;

                    case 32:
                        DrawLine(start, _beamY + beamDiff, Width, _beamY + beamDiff, 2);
                        DrawLine(start, _beamY + 2 * beamDiff, Width, _beamY + 2 * beamDiff, 2);
                        break;

                    default: break;
                    }
                }
            }
        }