Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new music note control
 /// </summary>
 /// <param name="parent">The parent staff control</param>
 /// <param name="keyboard">The associated piano keyboard control</param>
 /// <param name="pitch">The note pitch</param>
 /// <param name="lengthInMs">The note length in milliseconds</param>
 /// <param name="location">The location on the score</param>
 public MusicNote(MusicStaff parent, MusicKeyboard keyboard, NoteEnum pitch, float lengthInMs, Point location)
 {
     Staff                = parent;
     Keyboard             = keyboard;
     bottomBarY           = location.Y;
     Bounds               = new Rectangle(location.X, location.Y, MusicStaff.NoteWidth, MusicStaff.LineSpace * 6);
     Pitch                = pitch;
     LengthInMilliseconds = lengthInMs;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Draws the current note
        /// </summary>
        public void DrawNote(Graphics g, Point location)
        {
            g.CompositingMode    = CompositingMode.SourceOver;
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
            g.SmoothingMode      = SmoothingMode.HighQuality;
            Size size = Bounds.Size;

            size.Height -= MusicStaff.LineSpace * 2;
            bool upsideDown = pitch >= NoteEnum.C6 || (pitch <= NoteEnum.B4 && pitch >= NoteEnum.D4);

            if (pitch == NoteEnum.None)               //rest
            {
                switch (length)
                {
                case NoteLength.HemiDemiSemiQuaver:
                case NoteLength.DottedHemiDemiSemiQuaver:
                    DrawCenteredImage(g, highlighted ? Images.HemiDemiSemiQuaverRHighlight : Images.HemiDemiSemiQuaverR, location.X, location.Y);
                    break;

                case NoteLength.DemiSemiQuaver:
                case NoteLength.DottedDemiSemiQuaver:
                    DrawCenteredImage(g, highlighted ? Images.DemiSemiQuaverRHighlight : Images.DemiSemiQuaverR, location.X, location.Y);
                    break;

                case NoteLength.SemiQuaver:
                case NoteLength.DottedSemiQuaver:
                    DrawCenteredImage(g, highlighted ? Images.SemiQuaverRHighlight : Images.SemiQuaverR, location.X, location.Y);
                    break;

                case NoteLength.Quaver:
                case NoteLength.DottedQuaver:
                    DrawCenteredImage(g, highlighted ? Images.QuaverRHighlight : Images.QuaverR, location.X, location.Y);
                    break;

                case NoteLength.Crotchet:
                case NoteLength.DottedCrotchet:
                    DrawCenteredImage(g, highlighted ? Images.CrotchetRHighlight : Images.CrotchetR, location.X, location.Y);
                    break;

                case NoteLength.Minim:
                case NoteLength.DottedMinim:
                    DrawCenteredImage(g, highlighted ? Images.MinimRHighlight : Images.MinimR, location.X, location.Y);
                    break;

                case NoteLength.SemiBreve:
                    DrawCenteredImage(g, highlighted ? Images.SemiBreveRHighlight : Images.SemiBreveR, location.X, location.Y);
                    break;
                }
            }
            else                 //note
            {
                int centerLeft = 0;
                switch (length)
                {
                case NoteLength.HemiDemiSemiQuaver:
                case NoteLength.DottedHemiDemiSemiQuaver:
                    centerLeft = upsideDown ? DrawNoteImage(g, highlighted ? Images.HemiDemiSemiQuaverUpsideDownHighlight : Images.HemiDemiSemiQuaverUpsideDown, location.X, location.Y) : DrawNoteImage(g, highlighted ? Images.HemiDemiSemiQuaverHighlight : Images.HemiDemiSemiQuaver, location.X + 3, location.Y);
                    break;

                case NoteLength.DemiSemiQuaver:
                case NoteLength.DottedDemiSemiQuaver:
                    centerLeft = upsideDown ? DrawNoteImage(g, highlighted ? Images.DemiSemiQuaverUpsideDownHighlight : Images.DemiSemiQuaverUpsideDown, location.X, location.Y) : DrawNoteImage(g, highlighted ? Images.DemiSemiQuaverHighlight : Images.DemiSemiQuaver, location.X + 3, location.Y);
                    break;

                case NoteLength.SemiQuaver:
                case NoteLength.DottedSemiQuaver:
                    centerLeft = upsideDown ? DrawNoteImage(g, highlighted ? Images.SemiQuaverUpsideDownHighlight : Images.SemiQuaverUpsideDown, location.X, location.Y) : DrawNoteImage(g, highlighted ? Images.SemiQuaverHighlight : Images.SemiQuaver, location.X + 3, location.Y);
                    break;

                case NoteLength.Quaver:
                case NoteLength.DottedQuaver:
                    centerLeft = upsideDown ? DrawNoteImage(g, highlighted ? Images.QuaverUpsideDownHighlight : Images.QuaverUpsideDown, location.X, location.Y) : DrawNoteImage(g, highlighted ? Images.QuaverHighlight : Images.Quaver, location.X + 3, location.Y);
                    break;

                case NoteLength.Crotchet:
                case NoteLength.DottedCrotchet:
                    centerLeft = DrawNoteImage(g, upsideDown ? (highlighted ? Images.CrotchetUpsideDownHighlight : Images.CrotchetUpsideDown) : (highlighted ? Images.CrotchetHighlight : Images.Crotchet), location.X, location.Y);
                    break;

                case NoteLength.Minim:
                case NoteLength.DottedMinim:
                    centerLeft = DrawNoteImage(g, upsideDown ? (highlighted ? Images.MinimUpsideDownHighlight : Images.MinimUpsideDown) : (highlighted ? Images.MinimHighlight : Images.Minim), location.X, location.Y);
                    break;

                case NoteLength.SemiBreve:
                    centerLeft = DrawNoteImage(g, upsideDown ? (highlighted ? Images.SemiBreveUpsideDownHighlight : Images.SemiBreveUpsideDown) : (highlighted ? Images.SemiBreveHighlight : Images.SemiBreve), location.X, location.Y);
                    break;
                }
                if (MusicKeyboard.IsSharp(pitch))                 //draw sharp
                {
                    g.DrawImage(highlighted ? Images.SharpHighlight : Images.Sharp, location.X, location.Y + (upsideDown ? MusicStaff.LineSpace / 3: (MusicStaff.LineSpace * 13) / 4), ((MusicStaff.LineSpace * 5 * Images.Sharp.Width) / (Images.Sharp.Height * 2)), (MusicStaff.LineSpace * 5) / 2);
                }
                g.CompositingMode    = CompositingMode.SourceCopy;
                g.CompositingQuality = CompositingQuality.HighSpeed;
                g.PixelOffsetMode    = PixelOffsetMode.HighSpeed;
                g.SmoothingMode      = SmoothingMode.HighSpeed;
                const int lineProtrusion = 2;
                //draw auxiliary lines if note is outside of the bar
                if (pitch <= NoteEnum.E3)
                {
                    int bottom = MusicStaff.LineSpace * 7 + bottomBarY + MusicStaff.BarTopDistance * 2 - Bounds.Y;
                    int y      = size.Height + MusicStaff.LineSpace / 2;
                    if ((y - bottom) % MusicStaff.LineSpace != 0)
                    {
                        y -= MusicStaff.LineSpace / 2;
                    }
                    for (; y > bottom; y -= MusicStaff.LineSpace)
                    {
                        g.DrawLine(BlackPen, location.X + centerLeft - lineProtrusion, location.Y + y, location.X + size.Width + lineProtrusion - centerLeft, location.Y + y);
                    }
                }
                else if (pitch == NoteEnum.C5 || pitch == NoteEnum.CSharp5)
                {
                    const int y = (MusicStaff.LineSpace * 9) / 2;
                    g.DrawLine(BlackPen, location.X + centerLeft - lineProtrusion, location.Y + y, location.X + size.Width + lineProtrusion - centerLeft, location.Y + y);
                }
                else if (pitch >= NoteEnum.A6)
                {
                    int bottom = bottomBarY - Bounds.Y;
                    int y      = (MusicStaff.LineSpace * 3) / 2;
                    if ((bottom - y) % MusicStaff.LineSpace != 0)
                    {
                        y += MusicStaff.LineSpace / 2;
                    }
                    for (; y < bottom; y += MusicStaff.LineSpace)
                    {
                        g.DrawLine(BlackPen, location.X + centerLeft - lineProtrusion, location.Y + y, location.X + size.Width + lineProtrusion - centerLeft, location.Y + y);
                    }
                }
            }
            if (IsDotted(length))               //draw dot noxt to note
            {
                g.CompositingMode    = CompositingMode.SourceOver;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                g.SmoothingMode      = SmoothingMode.HighQuality;
                g.FillEllipse(highlighted ? HighlightedBrush : DotBrush, location.X + size.Width - 3, location.Y + (pitch == NoteEnum.None ? ((size.Height + MusicStaff.LineSpace - 3) / 2) : (upsideDown ? (MusicStaff.LineSpace * 9) / 8 : (MusicStaff.LineSpace * 33) / 8)), 3, 3);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new music note control
 /// </summary>
 /// <param name="parent">The parent staff control</param>
 /// <param name="keyboard">The associated piano keyboard control</param>
 /// <param name="pitch">The note pitch</param>
 /// <param name="length">The note length</param>
 /// <param name="location">The location on the score</param>
 public MusicNote(MusicStaff parent, MusicKeyboard keyboard, NoteEnum pitch, NoteLength length, Point location) :
     this(parent, keyboard, pitch, (int)length * parent.MillisPerHalfHemiDemiSemiQuaver, location)
 {
 }
Exemplo n.º 4
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor
 /// </summary>
 private void InitializeComponent()
 {
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainWindow));
     this.splitContainer1    = new System.Windows.Forms.SplitContainer();
     this.splitContainer2    = new System.Windows.Forms.SplitContainer();
     this.controlPanel       = new System.Windows.Forms.Panel();
     this.beatLengthLabel    = new System.Windows.Forms.Label();
     this.clearAllButton     = new System.Windows.Forms.Button();
     this.stopButton         = new System.Windows.Forms.Button();
     this.playButton         = new System.Windows.Forms.Button();
     this.beatLengthSelector = new System.Windows.Forms.NumericUpDown();
     this.saveButton         = new System.Windows.Forms.Button();
     this.loadButton         = new System.Windows.Forms.Button();
     this.zoomTrackBar       = new System.Windows.Forms.TrackBar();
     this.musicStaff         = new PianoNoteRecorder.MusicStaff();
     this.musicKeyboard      = new PianoNoteRecorder.MusicKeyboard();
     ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
     this.splitContainer1.Panel1.SuspendLayout();
     this.splitContainer1.Panel2.SuspendLayout();
     this.splitContainer1.SuspendLayout();
     ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
     this.splitContainer2.Panel1.SuspendLayout();
     this.splitContainer2.Panel2.SuspendLayout();
     this.splitContainer2.SuspendLayout();
     this.controlPanel.SuspendLayout();
     ((System.ComponentModel.ISupportInitialize)(this.beatLengthSelector)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.zoomTrackBar)).BeginInit();
     this.SuspendLayout();
     //
     // splitContainer1
     //
     this.splitContainer1.BackColor   = System.Drawing.SystemColors.Control;
     this.splitContainer1.Dock        = System.Windows.Forms.DockStyle.Fill;
     this.splitContainer1.Location    = new System.Drawing.Point(0, 0);
     this.splitContainer1.Name        = "splitContainer1";
     this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
     //
     // splitContainer1.Panel1
     //
     this.splitContainer1.Panel1.Controls.Add(this.splitContainer2);
     //
     // splitContainer1.Panel2
     //
     this.splitContainer1.Panel2.Controls.Add(this.musicKeyboard);
     this.splitContainer1.Panel2.Controls.Add(this.zoomTrackBar);
     this.splitContainer1.Panel2MinSize    = 35;
     this.splitContainer1.Size             = new System.Drawing.Size(632, 454);
     this.splitContainer1.SplitterDistance = 321;
     this.splitContainer1.SplitterWidth    = 7;
     this.splitContainer1.TabIndex         = 10;
     //
     // splitContainer2
     //
     this.splitContainer2.BackColor       = System.Drawing.SystemColors.Control;
     this.splitContainer2.Dock            = System.Windows.Forms.DockStyle.Fill;
     this.splitContainer2.FixedPanel      = System.Windows.Forms.FixedPanel.Panel2;
     this.splitContainer2.IsSplitterFixed = true;
     this.splitContainer2.Location        = new System.Drawing.Point(0, 0);
     this.splitContainer2.Name            = "splitContainer2";
     this.splitContainer2.Orientation     = System.Windows.Forms.Orientation.Horizontal;
     //
     // splitContainer2.Panel1
     //
     this.splitContainer2.Panel1.Controls.Add(this.musicStaff);
     //
     // splitContainer2.Panel2
     //
     this.splitContainer2.Panel2.BackColor = System.Drawing.SystemColors.Control;
     this.splitContainer2.Panel2.Controls.Add(this.controlPanel);
     this.splitContainer2.Panel2MinSize    = 35;
     this.splitContainer2.Size             = new System.Drawing.Size(632, 321);
     this.splitContainer2.SplitterDistance = 285;
     this.splitContainer2.SplitterWidth    = 1;
     this.splitContainer2.TabIndex         = 1;
     this.splitContainer2.TabStop          = false;
     //
     // controlPanel
     //
     this.controlPanel.BackColor = System.Drawing.SystemColors.Control;
     this.controlPanel.Controls.Add(this.beatLengthLabel);
     this.controlPanel.Controls.Add(this.clearAllButton);
     this.controlPanel.Controls.Add(this.stopButton);
     this.controlPanel.Controls.Add(this.playButton);
     this.controlPanel.Controls.Add(this.beatLengthSelector);
     this.controlPanel.Controls.Add(this.saveButton);
     this.controlPanel.Controls.Add(this.loadButton);
     this.controlPanel.Location = new System.Drawing.Point(12, 2);
     this.controlPanel.Name     = "controlPanel";
     this.controlPanel.Size     = new System.Drawing.Size(595, 30);
     this.controlPanel.TabIndex = 7;
     //
     // beatLengthLabel
     //
     this.beatLengthLabel.Font      = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.beatLengthLabel.Location  = new System.Drawing.Point(0, 0);
     this.beatLengthLabel.Name      = "beatLengthLabel";
     this.beatLengthLabel.Size      = new System.Drawing.Size(96, 30);
     this.beatLengthLabel.TabIndex  = 5;
     this.beatLengthLabel.Text      = "Beat Length in Milliseconds:";
     this.beatLengthLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
     //
     // clearAllButton
     //
     this.clearAllButton.Font     = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.clearAllButton.Location = new System.Drawing.Point(495, 0);
     this.clearAllButton.Name     = "clearAllButton";
     this.clearAllButton.Size     = new System.Drawing.Size(95, 31);
     this.clearAllButton.TabIndex = 4;
     this.clearAllButton.Text     = "Clear All ×";
     this.clearAllButton.UseVisualStyleBackColor = true;
     this.clearAllButton.Click += new System.EventHandler(this.clearAllButton_Click);
     //
     // stopButton
     //
     this.stopButton.Font     = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.stopButton.Location = new System.Drawing.Point(246, 0);
     this.stopButton.Name     = "stopButton";
     this.stopButton.Size     = new System.Drawing.Size(77, 31);
     this.stopButton.TabIndex = 1;
     this.stopButton.Text     = "Stop ■";
     this.stopButton.UseVisualStyleBackColor = true;
     this.stopButton.Click += new System.EventHandler(this.stopButton_Click);
     //
     // playButton
     //
     this.playButton.Font     = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.playButton.Location = new System.Drawing.Point(163, 0);
     this.playButton.Name     = "playButton";
     this.playButton.Size     = new System.Drawing.Size(77, 31);
     this.playButton.TabIndex = 0;
     this.playButton.Text     = "Play ▶";
     this.playButton.UseVisualStyleBackColor = true;
     this.playButton.Click += new System.EventHandler(this.playButton_Click);
     //
     // beatLengthSelector
     //
     this.beatLengthSelector.Font     = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.beatLengthSelector.Location = new System.Drawing.Point(97, 5);
     this.beatLengthSelector.Maximum  = new decimal(new int[] {
         10000,
         0,
         0,
         0
     });
     this.beatLengthSelector.Minimum = new decimal(new int[] {
         1,
         0,
         0,
         0
     });
     this.beatLengthSelector.Name     = "beatLengthSelector";
     this.beatLengthSelector.Size     = new System.Drawing.Size(60, 21);
     this.beatLengthSelector.TabIndex = 5;
     this.beatLengthSelector.Value    = new decimal(new int[] {
         467,
         0,
         0,
         0
     });
     this.beatLengthSelector.ValueChanged += new System.EventHandler(this.beatLengthSelector_ValueChanged);
     //
     // saveButton
     //
     this.saveButton.Font     = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.saveButton.Location = new System.Drawing.Point(329, 0);
     this.saveButton.Name     = "saveButton";
     this.saveButton.Size     = new System.Drawing.Size(77, 31);
     this.saveButton.TabIndex = 2;
     this.saveButton.Text     = "Save 💾";
     this.saveButton.UseVisualStyleBackColor = true;
     this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
     //
     // loadButton
     //
     this.loadButton.Font     = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.loadButton.Location = new System.Drawing.Point(412, 0);
     this.loadButton.Name     = "loadButton";
     this.loadButton.Size     = new System.Drawing.Size(77, 31);
     this.loadButton.TabIndex = 3;
     this.loadButton.Text     = "Load ←";
     this.loadButton.UseVisualStyleBackColor = true;
     this.loadButton.Click += new System.EventHandler(this.loadButton_Click);
     //
     // zoomTrackBar
     //
     this.zoomTrackBar.AutoSize    = false;
     this.zoomTrackBar.BackColor   = System.Drawing.SystemColors.Control;
     this.zoomTrackBar.Dock        = System.Windows.Forms.DockStyle.Left;
     this.zoomTrackBar.Location    = new System.Drawing.Point(0, 0);
     this.zoomTrackBar.Maximum     = 100;
     this.zoomTrackBar.Minimum     = 33;
     this.zoomTrackBar.Name        = "zoomTrackBar";
     this.zoomTrackBar.Orientation = System.Windows.Forms.Orientation.Vertical;
     this.zoomTrackBar.Size        = new System.Drawing.Size(25, 126);
     this.zoomTrackBar.TabIndex    = 6;
     this.zoomTrackBar.TickStyle   = System.Windows.Forms.TickStyle.None;
     this.zoomTrackBar.Value       = 100;
     this.zoomTrackBar.Scroll     += new System.EventHandler(this.zoomTrackBar_Scroll);
     //
     // musicStaff
     //
     this.musicStaff.AutoScroll        = true;
     this.musicStaff.AutoScrollMinSize = new System.Drawing.Size(1, 340);
     this.musicStaff.BackColor         = System.Drawing.Color.White;
     this.musicStaff.BorderStyle       = System.Windows.Forms.BorderStyle.Fixed3D;
     this.musicStaff.Dock          = System.Windows.Forms.DockStyle.Fill;
     this.musicStaff.Location      = new System.Drawing.Point(0, 0);
     this.musicStaff.MillisPerBeat = 400F;
     this.musicStaff.Name          = "musicStaff";
     this.musicStaff.Size          = new System.Drawing.Size(632, 285);
     this.musicStaff.TabIndex      = 100;
     //
     // musicKeyboard
     //
     this.musicKeyboard.BackColor             = System.Drawing.SystemColors.Control;
     this.musicKeyboard.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
     this.musicKeyboard.Dock                 = System.Windows.Forms.DockStyle.Fill;
     this.musicKeyboard.Font                 = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.musicKeyboard.Location             = new System.Drawing.Point(25, 0);
     this.musicKeyboard.Name                 = "musicKeyboard";
     this.musicKeyboard.ShowHint             = false;
     this.musicKeyboard.Size                 = new System.Drawing.Size(607, 126);
     this.musicKeyboard.TabIndex             = 1;
     this.musicKeyboard.Text                 = "Top of piano can also be resized using mouse";
     this.musicKeyboard.WidthScalePercentage = 100;
     //
     // MainWindow
     //
     this.AcceptButton        = this.playButton;
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
     this.ClientSize          = new System.Drawing.Size(632, 454);
     this.Controls.Add(this.splitContainer1);
     this.DoubleBuffered = true;
     this.Icon           = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
     this.KeyPreview     = true;
     this.MinimumSize    = new System.Drawing.Size(300, 100);
     this.Name           = "MainWindow";
     this.Text           = "Piano Note Recorder";
     this.splitContainer1.Panel1.ResumeLayout(false);
     this.splitContainer1.Panel2.ResumeLayout(false);
     ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
     this.splitContainer1.ResumeLayout(false);
     this.splitContainer2.Panel1.ResumeLayout(false);
     this.splitContainer2.Panel2.ResumeLayout(false);
     ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
     this.splitContainer2.ResumeLayout(false);
     this.controlPanel.ResumeLayout(false);
     ((System.ComponentModel.ISupportInitialize)(this.beatLengthSelector)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.zoomTrackBar)).EndInit();
     this.ResumeLayout(false);
 }