Пример #1
0
        public override string ToString()
        {
            var alt = string.Empty;

            if (Accidental == Accidental.Sharp)
            {
                alt = "#";
            }
            else if (Accidental == Accidental.Flat)
            {
                alt = "b";
            }
            return((1 < numberOfKey && numberOfKey <= 52) ? $"{Note.ToString()}{alt}" : "Key don't exist!");
        }
Пример #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Brush blackBrush   = new SolidBrush(Color.Black),
                  whiteBrush   = new SolidBrush(Color.White),
                  grayBrush    = new SolidBrush(Color.DarkGray),
                  gutterBrush  = new SolidBrush(Color.FromArgb(0x20, 0x20, 0x20)),
                  pressedBrush = new SolidBrush(Color.Red);

            int kActualKeyLength = KeyLength + 1;
            int kNumberOfKeys    = ClientRectangle.Width / kActualKeyLength + 1;

            Note currentNote;

            // Draw the white keys
            currentNote = new Note(NomNote.Do, startOctave_);
            for (int i = 0; i < kNumberOfKeys; ++i, currentNote = currentNote.next())
            {
                int xStart      = kActualKeyLength * i,
                    xEnd        = kActualKeyLength * (i + 1) - 1,
                    xBlackStart = xEnd - (KeyLength / 2),
                    blackHeight = (2 * ClientRectangle.Height) / 3;

                Brush noteBrush = whiteBrush;

                if ((pressedKeys_.Find(currentNote) != null) && highlightNotes_)
                {
                    noteBrush = pressedBrush;
                }

                Rectangle thisKey = new Rectangle(xStart, 0, KeyLength, ClientRectangle.Height),
                          border  = new Rectangle(xEnd, 0, 1, ClientRectangle.Height);

                e.Graphics.FillRectangle(noteBrush, thisKey);
                e.Graphics.FillRectangle(grayBrush, border);
            }

            // Draw the black keys
            currentNote = new Note(NomNote.Do, startOctave_);
            for (int i = 0; i < kNumberOfKeys; ++i, currentNote = currentNote.next())
            {
                // Only draw black keys where they exist
                if (!currentNote.hasBlack())
                {
                    continue;
                }

                int xEnd        = kActualKeyLength * (i + 1),
                    blackLength = (2 * kActualKeyLength) / 3,
                    xBlackStart = xEnd - (blackLength / 2),
                    blackHeight = (2 * ClientRectangle.Height) / 3;

                Brush noteBrush = blackBrush;

                if ((pressedKeys_.Find(currentNote.getBlackOf()) != null) && highlightNotes_)
                {
                    noteBrush = pressedBrush;
                }

                Rectangle blackKey = new Rectangle(xBlackStart, 0, blackLength, blackHeight);
                e.Graphics.FillRectangle(noteBrush, blackKey);
            }

            // Draw the gutter
            if (showNotes_)
            {
                Rectangle gutter = new Rectangle(0, 0, ClientRectangle.Width, 18);
                e.Graphics.FillRectangle(gutterBrush, gutter);

                Font         font = new Font("Monospace", 8);
                StringFormat format = new StringFormat();
                float        x, y = 2.0F;

                currentNote = new Note(NomNote.Do, startOctave_);
                for (int i = 0; i < kNumberOfKeys; ++i, currentNote = currentNote.next())
                {
                    String toDraw = currentNote.ToString();
                    SizeF  size   = e.Graphics.MeasureString(toDraw, font);

                    x  = (float)kActualKeyLength * i;
                    x += ((float)kActualKeyLength - size.Width) / 2.0F;

                    Brush brush = whiteBrush;
                    if ((pressedKeys_.Find(currentNote) != null) && highlightNotes_)
                    {
                        brush = pressedBrush;
                    }

                    e.Graphics.DrawString(currentNote.ToString(), font, brush, x, y, format);
                }
            }
            else
            {
                Rectangle line = new Rectangle(0, 0, ClientRectangle.Width, 2);
                e.Graphics.FillRectangle(gutterBrush, line);
            }
        }
Пример #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Brush blackBrush = new SolidBrush(Color.Black),
                  whiteBrush = new SolidBrush(Color.White),
                  grayBrush = new SolidBrush(Color.DarkGray),
                  gutterBrush = new SolidBrush(Color.FromArgb(0x20, 0x20, 0x20)),
                  pressedBrush = new SolidBrush(Color.Red);

            int kActualKeyLength = KeyLength + 1;
            int kNumberOfKeys = ClientRectangle.Width / kActualKeyLength + 1;

            Note currentNote;

            // Draw the white keys
            currentNote = new Note(NomNote.Do, startOctave_);
            for ( int i=0; i < kNumberOfKeys; ++i, currentNote = currentNote.next())
            {
                int xStart = kActualKeyLength * i,
                    xEnd = kActualKeyLength * (i + 1) - 1,
                    xBlackStart = xEnd - (KeyLength / 2),
                    blackHeight = (2 * ClientRectangle.Height) / 3;

                Brush noteBrush = whiteBrush;

                if( (pressedKeys_.Find(currentNote) != null) && highlightNotes_ )
                    noteBrush = pressedBrush;

                Rectangle thisKey = new Rectangle(xStart, 0, KeyLength, ClientRectangle.Height),
                          border = new Rectangle(xEnd, 0, 1, ClientRectangle.Height);

                e.Graphics.FillRectangle(noteBrush, thisKey);
                e.Graphics.FillRectangle(grayBrush, border);
            }

            // Draw the black keys
            currentNote = new Note(NomNote.Do, startOctave_);
            for ( int i=0; i < kNumberOfKeys; ++i, currentNote = currentNote.next()){
                // Only draw black keys where they exist
                if (!currentNote.hasBlack() )
                    continue;

                int xEnd = kActualKeyLength * (i+1),
                    blackLength = (2 * kActualKeyLength) / 3,
                    xBlackStart = xEnd - (blackLength / 2),
                    blackHeight = (2 * ClientRectangle.Height) / 3;

                Brush noteBrush = blackBrush;

                if( (pressedKeys_.Find(currentNote.getBlackOf()) != null) && highlightNotes_ )
                    noteBrush = pressedBrush;

                Rectangle blackKey = new Rectangle(xBlackStart, 0, blackLength, blackHeight);
                e.Graphics.FillRectangle(noteBrush, blackKey);
            }

            // Draw the gutter
            if ( showNotes_){
                Rectangle gutter = new Rectangle(0, 0, ClientRectangle.Width, 18 );
                e.Graphics.FillRectangle(gutterBrush, gutter);

                Font font = new Font("Monospace", 8);
                StringFormat format = new StringFormat();
                float x, y = 2.0F;

                currentNote = new Note(NomNote.Do, startOctave_);
                for ( int i=0; i < kNumberOfKeys; ++i, currentNote = currentNote.next()){
                    String toDraw = currentNote.ToString();
                    SizeF size = e.Graphics.MeasureString(toDraw, font);

                    x = (float)kActualKeyLength * i;
                    x += ((float)kActualKeyLength - size.Width) / 2.0F;

                    Brush brush = whiteBrush;
                    if ( (pressedKeys_.Find(currentNote) != null) && highlightNotes_ )
                        brush = pressedBrush;

                    e.Graphics.DrawString(currentNote.ToString(), font, brush, x, y, format);
                }
            } else {
                Rectangle line = new Rectangle(0, 0, ClientRectangle.Width, 2);
                e.Graphics.FillRectangle(gutterBrush, line);
            }
        }