Esempio n. 1
0
        public Note(int _step, int _octave, double _duration)
        {
            int codeIdx = _step;

            #region Code
            code = (MusicDefine.Code)codeIdx;
            #endregion

            #region Octave
            if (_octave == 0)
            {
                octave = MusicDefine.Octave.Default;
            }
            else
            {
                if (_octave > 1)
                {
                    octave = MusicDefine.Octave.DoubleUp;
                }
                else if (_octave > 0)
                {
                    octave = MusicDefine.Octave.Up;
                }
                else
                {
                    octave = MusicDefine.Octave.Down;
                }
            }
            #endregion

            duration = _duration;
            str      = (codeIdx < MusicDefine.CodeStr.Length) ? MusicDefine.GetStringCode(code, octave) : string.Empty;
        }
Esempio n. 2
0
        public Note(MusicDefine.Code _code, MusicDefine.Octave _octave, double _duration)
        {
            code     = _code;
            octave   = _octave;
            duration = _duration;

            int codeIdx = (int)code;

            str = (codeIdx < MusicDefine.CodeStr.Length) ? MusicDefine.GetStringCode(code, octave) : string.Empty;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            if (Visible)
            {
                Graphics g = e.Graphics;

                int count = (int)MusicDefine.Code.Count + 1;
                for (int i = 0; i < count; i++)
                {
                    DrawBackground(g, i);
                    if (!player.IsPlaying)
                    {
                        int idx = (i < (int)MusicDefine.Code.Count) ? i : 0;
                        DrawText(g, i, MusicDefine.CodeStr[idx]);
                    }
                }

                if (player.IsPlaying)
                {
                    notes = player.GetNotes();
                    for (int i = 0; i < notes.Count; i++)
                    {
                        if (notes[i].code == MusicDefine.Code.REST)
                        {
                            continue;
                        }

                        int startPixel = GetPixel(notes[i].startTime);
                        int endPixel   = GetPixel(notes[i].endTime);

                        if (!ValidatePixel(ref startPixel, ref endPixel))
                        {
                            continue;
                        }

                        if (i >= notes.Count - 1)
                        {
                            if (IsEndOfSheet(startPixel, endPixel))
                            {
                                player.Stop();
                                return;
                            }
                        }

                        if (notes[i].code == MusicDefine.Code.C && notes[i].octave >= MusicDefine.Octave.Default)
                        {
                            MusicDefine.Octave octave = notes[i].octave - 1;
                            string             s      = MusicDefine.GetStringCode(MusicDefine.Code.C, octave);
                            DrawBar(g, Setting.barX.Length - 1, startPixel, endPixel, s);
                        }

                        if (notes[i].octave != MusicDefine.Octave.DoubleUp)
                        {
                            int idx = (int)notes[i].code;
                            DrawBar(g, idx, startPixel, endPixel, notes[i].str);
                        }
                    }
                }

                DrawMoveRect(g);
            }
        }