/// <summary>
        ///   Initializes a new instance of the <see cref="KeyboardPreviewForm"/> class.
        /// </summary>
        /// 
        public KeyboardPreviewForm()
        {
            InitializeComponent();

            capture = new CaptureKeyboard()
            {
                Preview = true,
                Enabled = false
            };
        }
        /// <summary>
        ///   Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// 
        /// <param name="disposing"><c>true</c> to release both managed
        /// and unmanaged resources; <c>false</c> to release only unmanaged
        /// resources.</param>
        ///
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // free managed resources
                if (clickCapture != null)
                {
                    clickCapture.Dispose();
                    clickCapture = null;
                }

                if (cursorCapture != null)
                {
                    cursorCapture.Dispose();
                    cursorCapture = null;
                }

                if (keyCapture != null)
                {
                    keyCapture.Dispose();
                    keyCapture = null;
                }

                if (audioDevice != null)
                {
                    audioDevice.Dispose();
                    audioDevice = null;
                }

                if (videoWriter != null)
                {
                    videoWriter.Dispose();
                    videoWriter = null;
                }
            }
        }
        /// <summary>
        ///   Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        /// 
        public RecorderViewModel(MainViewModel main, VideoSourcePlayer player)
        {
            if (main == null)
                throw new ArgumentNullException("main");

            if (player == null)
                throw new ArgumentNullException("player");

            this.main = main;
            this.videoPlayer = player;
            this.videoPlayer.NewFrame += Player_NewFrame;

            this.CaptureMode = CaptureRegionOption.Primary;
            this.CaptureRegion = new Rectangle(0, 0, 640, 480);

            this.clickCapture = new CaptureClick();
            this.cursorCapture = new CaptureCursor();
            this.keyCapture = new CaptureKeyboard();

            if (Settings.Default.CaptureAudio)
                this.CaptureAudioDevice = new AudioDeviceCollection(AudioDeviceCategory.Capture).Default;
        }
        /// <summary>
        ///   Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        /// 
        public RecorderViewModel(MainViewModel main, VideoSourcePlayer2 player)
        {
            if (main == null)
                throw new ArgumentNullException("main");

            if (player == null)
                throw new ArgumentNullException("player");

            this.main = main;
            this.videoPlayer = player;
            this.videoPlayer.NewFrame += Player_NewFrame;

            this.CaptureMode = CaptureRegionOption.Primary;
            this.CaptureRegion = new Rectangle(0, 0, 640, 480);

            this.clickCapture = new CaptureClick();
            this.cursorCapture = new CaptureCursor();
            this.keyCapture = new CaptureKeyboard();

            this.AudioCaptureDevices = new AudioViewModelCollection(RecorderViewModel.AudioDevices);


            // Search and mark last selected devices
            foreach (var dev in AudioCaptureDevices)
                dev.Checked = Settings.Default.LastAudioDevices
                    .Contains(dev.DeviceInfo.Guid.ToString());
        }