void UpdateChannelPosition()
        {
            string channelPosLabel = "";

            switch (_timelineUnit)
            {
            case TimelineUnit.Samples:
                if (_soundPlayer != null)
                {
                    int channelSamplePos = _soundPlayer.ChannelSamplePosition;
                    channelPosLabel = string.Format("{0}", channelSamplePos);
                }
                break;

            case TimelineUnit.Time:
                if (_soundPlayer != null)
                {
                    channelPosLabel = TimeSpan.FromSeconds(CustomWaveViewer.SamplePositionToSeconds(_soundPlayer.ChannelSamplePosition, _soundPlayer.SampleRate)).ToString(@"hh\:mm\:ss\.fff");
                }
                break;

            case TimelineUnit.Seconds:
                if (_soundPlayer != null)
                {
                    channelPosLabel = string.Format("{0:0.000}", CustomWaveViewer.SamplePositionToSeconds(_soundPlayer.ChannelSamplePosition, _soundPlayer.SampleRate));
                }
                break;
            }

            ChangeChannelPosition(channelPosLabel);
        }
        void UpdateDuration()
        {
            string durationLabel = "";

            switch (_timelineUnit)
            {
            case TimelineUnit.Samples:
                if (_soundPlayer != null)
                {
                    durationLabel = String.Format("{0}", _soundPlayer.ChannelSampleLength);
                }
                break;

            case TimelineUnit.Time:
                if (_soundPlayer != null)
                {
                    durationLabel = TimeSpan.FromSeconds(CustomWaveViewer.SamplePositionToSeconds(_soundPlayer.ChannelSampleLength, _soundPlayer.SampleRate)).ToString(@"hh\:mm\:ss\.fff");
                }
                break;

            case TimelineUnit.Seconds:
                if (_soundPlayer != null)
                {
                    durationLabel = String.Format("{0:0.000}", CustomWaveViewer.SamplePositionToSeconds(_soundPlayer.ChannelSampleLength, _soundPlayer.SampleRate));
                }
                break;
            }

            lblDuration.Text = durationLabel;
        }
 public WaveViewerOverlay(CustomWaveViewer p)
 {
     DoubleBuffered = true;
     parent         = p;
     this.Parent    = parent;
     ticks          = new List <Rectangle>();
     posIndicator   = new Rectangle(parent.GetWaveformPadding(), 0, 1, (parent.Height * 2) - 25);
     selectMarker   = new Rectangle(parent.GetWaveformPadding(), 0, 2, (parent.Height * 2) - 25);
     loopEndMarker  = new Rectangle(-100, 0, 2, (parent.Height * 2) - 25);
     loopSection    = new Rectangle(-100, 0, 0, (parent.Height * 2) - 25);
 }
        void UpdateSelection()
        {
            string selectionLabel = "";

            switch (_timelineUnit)
            {
            case TimelineUnit.Samples:
                if (_soundPlayer != null)
                {
                    int selectionSampleBegin    = _soundPlayer.SelectionSampleBegin;
                    int selectionSampleEnd      = _soundPlayer.SelectionSampleEnd;
                    int selectionSampleDuration = selectionSampleEnd - selectionSampleBegin + 1;
                    selectionLabel = string.Format("{0} - {1} ({2})", selectionSampleBegin, selectionSampleEnd, selectionSampleDuration);
                }
                break;

            case TimelineUnit.Time:
                if (_soundPlayer != null)
                {
                    double selTimeBegin          = CustomWaveViewer.SamplePositionToSeconds(_soundPlayer.SelectionSampleBegin, _soundPlayer.SampleRate);
                    double selTimeEnd            = CustomWaveViewer.SamplePositionToSeconds(_soundPlayer.SelectionSampleEnd, _soundPlayer.SampleRate);
                    string selectionTimeBegin    = TimeSpan.FromSeconds(selTimeBegin).ToString(@"hh\:mm\:ss\.fff");
                    string selectionTimeEnd      = TimeSpan.FromSeconds(selTimeEnd).ToString(@"hh\:mm\:ss\.fff");
                    string selectionTimeDuration = TimeSpan.FromSeconds(selTimeEnd - selTimeBegin).ToString(@"hh\:mm\:ss\.fff");
                    selectionLabel = string.Format("{0} - {1} ({2})", selectionTimeBegin, selectionTimeEnd, selectionTimeDuration);
                }
                break;

            case TimelineUnit.Seconds:
                if (_soundPlayer != null)
                {
                    double selSecondsBegin    = CustomWaveViewer.SamplePositionToSeconds(_soundPlayer.SelectionSampleBegin, _soundPlayer.SampleRate);
                    double selSecondsEnd      = CustomWaveViewer.SamplePositionToSeconds(_soundPlayer.SelectionSampleEnd, _soundPlayer.SampleRate);
                    double selSecondsDuration = selSecondsEnd - selSecondsBegin;
                    selectionLabel = string.Format("{0:0.000} - {1:0.000} ({2:0.000})", selSecondsBegin, selSecondsEnd, selSecondsDuration);
                }
                break;
            }
            ChangeSelection(selectionLabel);
        }