private void TargetChanged(IAudioSource newTarget)
        {
            if (_targetSource == newTarget)
                return;

            Close();

            if ((_targetSource = newTarget) == null)
                return;
            if ((TargetStreams = _targetSource.CreateStreams()) == null)
                return;
            if (_targetStream == null)
                return;

            //Create provider
            if (_provider == null)
            {
                _provider = AudioProvider.Create(null);
                _provider.Attach(this);
            }

            chkLoop.Checked = false;
            chkLoop.Enabled = _targetStream.IsLooping;

            //Create buffer for stream
            for (int i = 0; i < _buffers.Length; i++)
                _buffers[i] = _provider.CreateBuffer(_targetStreams[i]);

            if (_targetStream.Frequency > 0)
                _sampleTime = new DateTime((long)_targetStream.Samples * 10000000 / _targetStream.Frequency);

            trackBar1.Value = 0;
            trackBar1.TickStyle = TickStyle.None;
            trackBar1.Maximum = _targetStream.Samples;
            trackBar1.TickFrequency = _targetStream.Samples / 8;
            trackBar1.TickStyle = TickStyle.BottomRight;

            if (_targetStream.Frequency > 0)
                UpdateTimeDisplay();

            Enabled = _targetStream.Samples > 0;
        }
        protected override void OnShown(EventArgs e)
        {
            if (_provider == null)
            {
                _provider = AudioProvider.Create(null);
                _provider.Attach(this);
            }

            if (_audioSource == null)
            {
                if (!LoadAudio())
                {
                    Close();
                    return;
                }
            }
            else if (!LoadAudio(_audioSource))
            {
                Close();
                return;
            }

            base.OnShown(e);
        }
        private void TargetChanged(THPNode newTarget)
        {
            if (_targetSource == newTarget)
                return;

            Close();

            if ((_targetSource = newTarget) == null)
                return;

            previewPanel1.RenderingTarget = _targetSource;

            IAudioStream s = _targetSource._audio;

            //Create provider
            if (_provider == null && s != null)
            {
                _provider = AudioProvider.Create(null);
                _provider.Attach(this);
            }

            chkLoop.Checked = false;

            //Create buffer for stream
            if (s != null)
                _buffer = _provider.CreateBuffer(s);

            if (_targetSource.FrameRate > 0)
                _frameTime = new DateTime((long)((float)_targetSource.NumFrames * 10000000.0f / _targetSource.FrameRate));

            trackBar1.Value = 0;
            trackBar1.TickStyle = TickStyle.None;
            trackBar1.Maximum = (int)_targetSource.NumFrames;
            trackBar1.TickFrequency = (int)_targetSource.NumFrames;
            trackBar1.TickStyle = TickStyle.BottomRight;

            if (_targetSource.FrameRate > 0)
                UpdateTimeDisplay();

            Enabled = _targetSource.NumFrames > 0;
        }