Example #1
0
        // Draw the waveform in a graphics
        // TODO: handle other bit depths than 16 bit.
        private void DrawWaveform(Graphics g, AudioBlock block)
        {
            PCMFormatInfo format = this.audio.getPCMFormat();

            if (format.getBitDepth() != 16)
            {
                throw new Exception("Cannot deal with bitdepth others than 16.");
            }
            ushort channels        = format.getNumberOfChannels();
            ushort frameSize       = format.getBlockAlign();
            int    samplesPerPixel = (int)Math.Ceiling(this.audio.getPCMLength() / (float)frameSize / Width * channels);
            int    bytesPerPixel   = samplesPerPixel * frameSize / channels;

            byte[]           bytes   = new byte[bytesPerPixel];
            short[]          samples = new short[samplesPerPixel];
            System.IO.Stream au      = this.audio.getAudioData();
            for (int x = 0; x < Width; ++x)
            {
                int read = au.Read(bytes, 0, bytesPerPixel);
                Buffer.BlockCopy(bytes, 0, samples, 0, read);
                DrawChannel(g, block.Highlighted ? block.Colors.WaveformChannelSelectedPen :
                            channels == 1 ? block.Colors.WaveformMonoPen : block.Colors.WaveformChannel1Pen,
                            samples, x, read, frameSize, 0, channels);
                if (channels == 2)
                {
                    DrawChannel(g, block.Selected ? block.Colors.WaveformChannelSelectedPen : block.Colors.WaveformChannel2Pen,
                                samples, x, read, frameSize, 1, channels);
                }
            }
            au.Close();
        }
Example #2
0
        // Repaint the waveform bitmap.
        protected override void OnPaint(PaintEventArgs pe)
        {
            if (this.bitmap != null)
            {
                pe.Graphics.DrawImage(this.bitmap, new Point(0, 0));
            }
            AudioBlock block = Parent as AudioBlock;

            if (block != null)
            {
                AudioSelection selection = block.Selection as AudioSelection;
                if (selection != null)
                {
                    int from = block.XForTime(selection.From);
                    if (selection.IsRange)
                    {
                        int to = block.XForTime(selection.To);
                        pe.Graphics.FillRectangle(block.Colors.AudioSelectionBrush,
                                                  new Rectangle(from < to ? from : to, 0, from < to ? to - from : from - to, Height));
                        pe.Graphics.DrawLine(block.Colors.AudioSelectionPen, new Point(to, 0), new Point(to, Height - 1));
                    }
                    pe.Graphics.DrawLine(block.Colors.AudioSelectionPen, new Point(from, 0), new Point(from, Height - 1));
                }
                if (block.Playing)
                {
                    int at = block.XForTime(block.PlayingTime);
                    pe.Graphics.DrawLine(block.Colors.AudioPlaybackPen, new Point(at, 0), new Point(at, Height - 1));
                }
            }
            base.OnPaint(pe);
        }
Example #3
0
        private delegate void ClearProjectDelegate();                  // delegate for thread-safe clearing


        /// <summary>
        /// New project view
        /// </summary>
        public ProjectView()
        {
            InitializeComponent();
            DoubleBuffered     = true;
            Project            = null;
            this.clipboard     = null;
            this.selection     = null;
            this.playbackBlock = null;
            AudioScale         = 1.0;
            Zoom = 1.0;
        }
Example #4
0
 // Redraw the waveform to fit the available size.
 private void UpdateWaveform(AudioBlock block)
 {
     if (Width > 0 && Height > 0 && block != null && block.Parent != null)
     {
         this.bitmap = new Bitmap(Width, Height);
         Graphics g = Graphics.FromImage(this.bitmap);
         g.Clear(BackColor);
         g.DrawLine(block.Selected ? block.Colors.WaveformBaseLineSelectedPen : block.Colors.WaveformBaseLinePen,
                    new Point(0, Height / 2), new Point(Width - 1, Height / 2));
         if (this.audio != null)
         {
             DrawWaveform(g, block);
         }
         Invalidate();
     }
 }
Example #5
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            AudioBlock block = Parent as AudioBlock;

            if (block != null)
            {
                AudioSelection selection = block.Selection as AudioSelection;
                if (selection != null)
                {
                    int from = block.XForTime(selection.From < selection.To ? selection.From : selection.To);
                    int to   = block.XForTime(selection.To > selection.From ? selection.To : selection.From);
                    if (selection.IsRange)
                    {
                        pe.Graphics.FillRectangle(block.Colors.AudioSelectionBrush, new Rectangle(from, 0, to - from + 1, Height));
                    }
                    else
                    {
                        pe.Graphics.FillRectangle(block.Colors.AudioSelectionBrush,
                                                  new Rectangle(block.XForTime(selection.At) - Height / 2, 0, Height, Height));
                    }
                }
                if (block.Playing)
                {
                    int     at     = block.XForTime(block.PlayingTime);
                    Point[] points = new Point[3];
                    points[0] = new Point(at, 0);
                    points[1] = new Point(at + Height / 2, Height / 2);
                    points[2] = new Point(at, Height);
                    pe.Graphics.DrawLine(block.Colors.AudioPlaybackPen, new Point(at, 0), new Point(at, Height));
                    pe.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    pe.Graphics.FillPolygon(block.Colors.AudioPlaybackBrush, points);
                }
            }
            // Calling the base class OnPaint
            base.OnPaint(pe);
        }
Example #6
0
 /// <summary>
 /// Add a new audio block to the track.
 /// </summary>
 public void AddAudioBlock(AudioBlock block)
 {
     block.Colors = ((ProjectView)Parent).Colors;
     this.trackLayout.Controls.Add(block);
 }