private void Close()
        {
            //Stop playback
            Stop();

            _targetSource = null;

            //Reset fields
            chkLoop.Checked = false;
        }
        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;
        }