Exemplo n.º 1
0
        public void Init(bool Persist, bool Timer, bool Remembered, bool Hotkeys)
        {
            _persist = Persist;
            _hotkeys = Hotkeys;

            if (Timer)
            {
                RecordingViewModel.InitTimer();
            }

            // Register Hotkeys if not console
            if (_hotkeys)
            {
                HotKeyManager.RegisterAll();
            }

            VideoWritersViewModel.RefreshCodecs();

            if (Remembered)
            {
                _remembered = true;

                _rememberByName.RestoreRemembered();
            }
        }
Exemplo n.º 2
0
        public ViewConditionsModel(VideoSourcesViewModel VideoSourcesViewModel,
                                   VideoWritersViewModel VideoWritersViewModel,
                                   Settings Settings,
                                   RecordingModel RecordingModel,
                                   AudioSource AudioSource)
        {
            IsRegionMode = VideoSourcesViewModel
                           .ObserveProperty(M => M.SelectedVideoSourceKind)
                           .Select(M => M is RegionSourceProvider)
                           .ToReadOnlyReactivePropertySlim();

            IsAudioMode = VideoSourcesViewModel
                          .ObserveProperty(M => M.SelectedVideoSourceKind)
                          .Select(M => M is NoVideoSourceProvider)
                          .ToReadOnlyReactivePropertySlim();

            MultipleVideoWriters = VideoWritersViewModel.AvailableVideoWriters
                                   .ObserveProperty(M => M.Count)
                                   .Select(M => M > 1)
                                   .ToReadOnlyReactivePropertySlim();

            IsFFmpeg = VideoWritersViewModel
                       .ObserveProperty(M => M.SelectedVideoWriterKind)
                       .Select(M => M is FFmpegWriterProvider || M is StreamingWriterProvider)
                       .ToReadOnlyReactivePropertySlim();

            IsVideoQuality = VideoWritersViewModel
                             .ObserveProperty(M => M.SelectedVideoWriterKind)
                             .Select(M => !(M is DiscardWriterProvider))
                             .ToReadOnlyReactivePropertySlim();

            CanChangeWebcam = new[]
            {
                RecordingModel
                .ObserveProperty(M => M.RecorderState)
                .Select(M => M == RecorderState.NotRecording),
                Settings.WebcamOverlay
                .ObserveProperty(M => M.SeparateFile)
            }
            .CombineLatest(M => !M[1] || M[0])     // Not SeparateFile or NotRecording
            .ToReadOnlyReactivePropertySlim();

            CanChangeAudioSources = new[]
            {
                RecordingModel
                .ObserveProperty(M => M.RecorderState)
                .Select(M => M == RecorderState.NotRecording),
                Settings.Audio
                .ObserveProperty(M => M.SeparateFilePerSource)
            }
            .CombineLatest(M =>
                           AudioSource.CanChangeSourcesDuringRecording ||
                           !M[1] || M[0]) // Not SeparateFilePerSource or NotRecording
            .ToReadOnlyReactivePropertySlim();

            IsEnabled = RecordingModel
                        .ObserveProperty(M => M.RecorderState)
                        .Select(M => M == RecorderState.NotRecording)
                        .ToReadOnlyReactivePropertySlim();
        }
Exemplo n.º 3
0
        public RecordingViewModel(RecordingModel RecordingModel,
                                  Settings Settings,
                                  TimerModel TimerModel,
                                  VideoSourcesViewModel VideoSourcesViewModel,
                                  VideoWritersViewModel VideoWritersViewModel,
                                  ISystemTray SystemTray,
                                  IMainWindow MainWindow,
                                  IAudioPlayer AudioPlayer,
                                  IRecentList RecentList,
                                  AudioSourceViewModel AudioSourceViewModel) : base(Settings)
        {
            _recordingModel        = RecordingModel;
            _timerModel            = TimerModel;
            _videoSourcesViewModel = VideoSourcesViewModel;
            _videoWritersViewModel = VideoWritersViewModel;
            _systemTray            = SystemTray;
            _mainWindow            = MainWindow;
            _audioPlayer           = AudioPlayer;
            _recentList            = RecentList;
            _audioSourceViewModel  = AudioSourceViewModel;

            this.RecordingModel = RecordingModel;

            TimerModel.DurationElapsed += () =>
            {
                _syncContext.Run(async() => await StopRecording(), true);
            };
        }
Exemplo n.º 4
0
        public RecordingViewModel(Settings Settings,
                                  LanguageManager LanguageManager,
                                  ISystemTray SystemTray,
                                  IRegionProvider RegionProvider,
                                  WebcamOverlay WebcamOverlay,
                                  IMainWindow MainWindow,
                                  IPreviewWindow PreviewWindow,
                                  VideoSourcesViewModel VideoSourcesViewModel,
                                  VideoWritersViewModel VideoWritersViewModel,
                                  AudioSource AudioSource,
                                  IWebCamProvider WebCamProvider,
                                  KeymapViewModel Keymap,
                                  IAudioPlayer AudioPlayer,
                                  IRecentList RecentList) : base(Settings, LanguageManager)
        {
            _systemTray            = SystemTray;
            _regionProvider        = RegionProvider;
            _webcamOverlay         = WebcamOverlay;
            _mainWindow            = MainWindow;
            _previewWindow         = PreviewWindow;
            _videoSourcesViewModel = VideoSourcesViewModel;
            _videoWritersViewModel = VideoWritersViewModel;
            _audioSource           = AudioSource;
            _webCamProvider        = WebCamProvider;
            _keymap      = Keymap;
            _audioPlayer = AudioPlayer;
            _recentList  = RecentList;

            RecordCommand = new DelegateCommand(OnRecordExecute);

            PauseCommand = new DelegateCommand(OnPauseExecute, false);

            SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
        }
Exemplo n.º 5
0
        public MainModel(Settings Settings,
                         IWebCamProvider WebCamProvider,
                         VideoWritersViewModel VideoWritersViewModel,
                         AudioSource AudioSource,
                         HotKeyManager HotKeyManager,
                         RememberByName RememberByName,
                         IRecentList RecentList,
                         RecordingModel RecordingModel)
        {
            _settings              = Settings;
            _webCamProvider        = WebCamProvider;
            _videoWritersViewModel = VideoWritersViewModel;
            _audioSource           = AudioSource;
            _hotKeyManager         = HotKeyManager;
            _rememberByName        = RememberByName;
            _recentList            = RecentList;
            _recordingModel        = RecordingModel;

            // If Output Dircetory is not set. Set it to Documents\Captura\
            if (string.IsNullOrWhiteSpace(Settings.OutPath))
            {
                Settings.OutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Captura");
            }

            // Create the Output Directory if it does not exist
            Settings.EnsureOutPath();
        }
Exemplo n.º 6
0
        public RecordingModel(Settings Settings,
                              ILocalizationProvider Loc,
                              ISystemTray SystemTray,
                              WebcamOverlay WebcamOverlay,
                              IMainWindow MainWindow,
                              IPreviewWindow PreviewWindow,
                              VideoSourcesViewModel VideoSourcesViewModel,
                              VideoWritersViewModel VideoWritersViewModel,
                              AudioSource AudioSource,
                              WebcamModel WebcamModel,
                              KeymapViewModel Keymap,
                              IAudioPlayer AudioPlayer,
                              IRecentList RecentList,
                              TimerModel TimerModel,
                              IMessageProvider MessageProvider,
                              IFFmpegViewsProvider FFmpegViewsProvider) : base(Settings, Loc)
        {
            _systemTray            = SystemTray;
            _webcamOverlay         = WebcamOverlay;
            _mainWindow            = MainWindow;
            _previewWindow         = PreviewWindow;
            _videoSourcesViewModel = VideoSourcesViewModel;
            _videoWritersViewModel = VideoWritersViewModel;
            _audioSource           = AudioSource;
            _webcamModel           = WebcamModel;
            _keymap              = Keymap;
            _audioPlayer         = AudioPlayer;
            _recentList          = RecentList;
            _timerModel          = TimerModel;
            _messageProvider     = MessageProvider;
            _ffmpegViewsProvider = FFmpegViewsProvider;

            SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

            TimerModel.CountdownElapsed += InternalStartRecording;
            TimerModel.DurationElapsed  += async() =>
            {
                if (_syncContext != null)
                {
                    _syncContext.Post(async State => await StopRecording(), null);
                }
                else
                {
                    await StopRecording();
                }
            };
        }
Exemplo n.º 7
0
        void OnRefresh()
        {
            VideoWritersViewModel.RefreshCodecs();

            AudioSource.Refresh();

            #region Webcam
            var lastWebcamName = WebCamProvider.SelectedCam?.Name;

            WebCamProvider.Refresh();

            var matchingWebcam = WebCamProvider.AvailableCams.FirstOrDefault(M => M.Name == lastWebcamName);

            if (matchingWebcam != null)
            {
                WebCamProvider.SelectedCam = matchingWebcam;
            }
            #endregion

            Refreshed?.Invoke();
        }
Exemplo n.º 8
0
        public MainModel(Settings Settings,
                         VideoWritersViewModel VideoWritersViewModel,
                         AudioSource AudioSource,
                         RememberByName RememberByName,
                         WebcamModel WebcamModel)
        {
            _settings = Settings;
            _videoWritersViewModel = VideoWritersViewModel;
            _audioSource           = AudioSource;
            _rememberByName        = RememberByName;
            _webcamModel           = WebcamModel;

            // If Output Dircetory is not set. Set it to Documents\Captura\
            if (string.IsNullOrWhiteSpace(Settings.GetOutputPath()))
            {
                Settings.OutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), nameof(Captura));
            }

            // Create the Output Directory if it does not exist
            Settings.EnsureOutPath();
        }
Exemplo n.º 9
0
        public RecordingViewModel(RecordingModel RecordingModel,
                                  Settings Settings,
                                  TimerModel TimerModel,
                                  WebcamModel WebcamModel,
                                  VideoSourcesViewModel VideoSourcesViewModel,
                                  VideoWritersViewModel VideoWritersViewModel,
                                  ISystemTray SystemTray,
                                  IMainWindow MainWindow,
                                  ILocalizationProvider Loc,
                                  IAudioPlayer AudioPlayer,
                                  IRecentList RecentList,
                                  IMessageProvider MessageProvider,
                                  AudioSourceViewModel AudioSourceViewModel,
                                  IFFmpegViewsProvider FFmpegViewsProvider) : base(Settings, Loc)
        {
            _recordingModel        = RecordingModel;
            _timerModel            = TimerModel;
            _videoSourcesViewModel = VideoSourcesViewModel;
            _videoWritersViewModel = VideoWritersViewModel;
            _systemTray            = SystemTray;
            _mainWindow            = MainWindow;
            _audioPlayer           = AudioPlayer;
            _recentList            = RecentList;
            _messageProvider       = MessageProvider;
            _audioSourceViewModel  = AudioSourceViewModel;
            _ffmpegViewsProvider   = FFmpegViewsProvider;

            var hasAudio = new[]
            {
                Settings
                .Audio
                .ObserveProperty(M => M.RecordMicrophone),
                Settings
                .Audio
                .ObserveProperty(M => M.RecordSpeaker)
            }
            .CombineLatest(M => M[0] || M[1]);

            RecordCommand = new[]
            {
                hasAudio,
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M is NoVideoSourceProvider),
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M is WebcamSourceProvider),
                WebcamModel
                .ObserveProperty(M => M.SelectedCam)
                .Select(M => M is NoWebcamItem),
                Settings
                .Video
                .ObserveProperty(M => M.RecorderMode)
                .Select(M => M == RecorderMode.Steps),
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M.SupportsStepsMode),
            }
            .CombineLatest(M =>
            {
                var audioEnabled      = M[0];
                var audioOnlyMode     = M[1];
                var webcamMode        = M[2];
                var noWebcam          = M[3];
                var stepsMode         = M[4];
                var supportsStepsMode = M[5];

                if (stepsMode)
                {
                    return(supportsStepsMode);
                }

                if (audioOnlyMode)
                {
                    return(audioEnabled);
                }

                if (webcamMode)
                {
                    return(!noWebcam);
                }

                return(true);
            })
            .ToReactiveCommand()
            .WithSubscribe(OnRecordExecute);

            PauseCommand = new[]
            {
                TimerModel
                .ObserveProperty(M => M.Waiting),
                RecordingModel
                .ObserveProperty(M => M.RecorderState)
                .Select(M => M != Models.RecorderState.NotRecording)
            }
            .CombineLatest(M => !M[0] && M[1])
            .ToReactiveCommand()
            .WithSubscribe(() =>
            {
                _audioPlayer.Play(SoundKind.Pause);

                RecordingModel.OnPauseExecute();
            });

            RecorderState = RecordingModel
                            .ObserveProperty(M => M.RecorderState)
                            .ToReadOnlyReactivePropertySlim();

            TimerModel.DurationElapsed += () =>
            {
                _syncContext.Run(async() => await StopRecording(), true);
            };
        }
Exemplo n.º 10
0
        public ViewConditionsModel(VideoSourcesViewModel VideoSourcesViewModel,
                                   VideoWritersViewModel VideoWritersViewModel,
                                   Settings Settings,
                                   RecordingModel RecordingModel,
                                   AudioSourceViewModel AudioSourceViewModel)
        {
            IsRegionMode = VideoSourcesViewModel
                           .ObserveProperty(M => M.SelectedVideoSourceKind)
                           .Select(M => M is RegionSourceProvider)
                           .ToReadOnlyReactivePropertySlim();

            IsAudioMode = VideoSourcesViewModel
                          .ObserveProperty(M => M.SelectedVideoSourceKind)
                          .Select(M => M is NoVideoSourceProvider)
                          .ToReadOnlyReactivePropertySlim();

            MultipleVideoWriters = VideoWritersViewModel.AvailableVideoWriters
                                   .ObserveProperty(M => M.Count)
                                   .Select(M => M > 1)
                                   .ToReadOnlyReactivePropertySlim();

            IsFFmpeg = VideoWritersViewModel
                       .ObserveProperty(M => M.SelectedVideoWriterKind)
                       .Select(M => M is FFmpegWriterProvider || M is StreamingWriterProvider)
                       .ToReadOnlyReactivePropertySlim();

            IsVideoQuality = VideoWritersViewModel
                             .ObserveProperty(M => M.SelectedVideoWriterKind)
                             .Select(M => M is DiscardWriterProvider)
                             .Select(M => !M)
                             .ToReadOnlyReactivePropertySlim();

            IsReplayMode = Settings
                           .Video
                           .ObserveProperty(M => M.RecorderMode)
                           .Select(M => M == RecorderMode.Replay)
                           .ToReadOnlyReactivePropertySlim();

            CanChangeWebcam = new[]
            {
                RecordingModel
                .ObserveProperty(M => M.RecorderState)
                .Select(M => M == RecorderState.NotRecording),
                Settings.WebcamOverlay
                .ObserveProperty(M => M.SeparateFile),
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M is WebcamSourceProvider)
            }
            .CombineLatest(M =>
            {
                var notRecording = M[0];
                var separateFile = M[1];
                var webcamMode   = M[2];

                if (webcamMode)
                {
                    return(notRecording);
                }

                return(!separateFile || notRecording);
            })
            .ToReadOnlyReactivePropertySlim();

            IsEnabled = RecordingModel
                        .ObserveProperty(M => M.RecorderState)
                        .Select(M => M == RecorderState.NotRecording)
                        .ToReadOnlyReactivePropertySlim();

            CanWebcamSeparateFile = VideoSourcesViewModel
                                    .ObserveProperty(M => M.SelectedVideoSourceKind)
                                    .Select(M => M is WebcamSourceProvider)
                                    .Select(M => !M)
                                    .ToReadOnlyReactivePropertySlim();

            IsAroundMouseMode = VideoSourcesViewModel
                                .ObserveProperty(M => M.SelectedVideoSourceKind)
                                .Select(M => M is AroundMouseSourceProvider)
                                .ToReadOnlyReactivePropertySlim();

            ShowSourceNameBox = VideoSourcesViewModel
                                .ObserveProperty(M => M.SelectedVideoSourceKind)
                                .Select(M => M is RegionSourceProvider || M is AroundMouseSourceProvider)
                                .Select(M => !M)
                                .ToReadOnlyReactivePropertySlim();
        }
Exemplo n.º 11
0
        public ViewConditionsModel(VideoSourcesViewModel VideoSourcesViewModel,
                                   VideoWritersViewModel VideoWritersViewModel,
                                   Settings Settings,
                                   RecordingModel RecordingModel,
                                   AudioSourceViewModel AudioSourceViewModel)
        {
            IsRegionMode = VideoSourcesViewModel
                           .ObserveProperty(M => M.SelectedVideoSourceKind)
                           .Select(M => M is RegionSourceProvider)
                           .ToReadOnlyReactivePropertySlim();

            IsAudioMode = VideoSourcesViewModel
                          .ObserveProperty(M => M.SelectedVideoSourceKind)
                          .Select(M => M is NoVideoSourceProvider)
                          .ToReadOnlyReactivePropertySlim();

            IsStepsMode = Settings
                          .Video
                          .ObserveProperty(M => M.RecorderMode)
                          .Select(M => M == RecorderMode.Steps)
                          .ToReadOnlyReactivePropertySlim();

            IsNotAudioOrStepsMode = new[]
            {
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M is NoVideoSourceProvider),
                IsStepsMode
            }
            .CombineLatest(M =>
            {
                var audioMode = M[0];
                var stepsMode = M[1];

                return(!audioMode && !stepsMode);
            })
            .ToReadOnlyReactivePropertySlim();

            MultipleVideoWriters = VideoWritersViewModel.AvailableVideoWriters
                                   .ObserveProperty(M => M.Count)
                                   .Select(M => M > 1)
                                   .ToReadOnlyReactivePropertySlim();

            IsFFmpeg = VideoWritersViewModel
                       .ObserveProperty(M => M.SelectedVideoWriterKind)
                       .Select(M => M is FFmpegWriterProvider || M is StreamingWriterProvider)
                       .ToReadOnlyReactivePropertySlim();

            IsVideoQuality = VideoWritersViewModel
                             .ObserveProperty(M => M.SelectedVideoWriterKind)
                             .Select(M => M is DiscardWriterProvider)
                             .Select(M => !M)
                             .ToReadOnlyReactivePropertySlim();

            IsReplayMode = Settings
                           .Video
                           .ObserveProperty(M => M.RecorderMode)
                           .Select(M => M == RecorderMode.Replay)
                           .ToReadOnlyReactivePropertySlim();

            CanChangeWebcam = new[]
            {
                RecordingModel
                .ObserveProperty(M => M.RecorderState)
                .Select(M => M == RecorderState.NotRecording),
                Settings.WebcamOverlay
                .ObserveProperty(M => M.SeparateFile),
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M is WebcamSourceProvider)
            }
            .CombineLatest(M =>
            {
                var notRecording = M[0];
                var separateFile = M[1];
                var webcamMode   = M[2];

                if (webcamMode)
                {
                    return(notRecording);
                }

                return(!separateFile || notRecording);
            })
            .ToReadOnlyReactivePropertySlim();

            IsEnabled = RecordingModel
                        .ObserveProperty(M => M.RecorderState)
                        .Select(M => M == RecorderState.NotRecording)
                        .ToReadOnlyReactivePropertySlim();

            CanWebcamSeparateFile = VideoSourcesViewModel
                                    .ObserveProperty(M => M.SelectedVideoSourceKind)
                                    .Select(M => M is WebcamSourceProvider)
                                    .Select(M => !M)
                                    .ToReadOnlyReactivePropertySlim();

            IsAroundMouseMode = VideoSourcesViewModel
                                .ObserveProperty(M => M.SelectedVideoSourceKind)
                                .Select(M => M is AroundMouseSourceProvider)
                                .ToReadOnlyReactivePropertySlim();

            IsWebcamMode = VideoSourcesViewModel
                           .ObserveProperty(M => M.SelectedVideoSourceKind)
                           .Select(M => M is WebcamSourceProvider)
                           .ToReadOnlyReactivePropertySlim();

            ShowSourceNameBox = VideoSourcesViewModel
                                .ObserveProperty(M => M.SelectedVideoSourceKind)
                                .Select(M => M is RegionSourceProvider || M is AroundMouseSourceProvider)
                                .Select(M => !M)
                                .ToReadOnlyReactivePropertySlim();

            StepsBtnEnabled = new[]
            {
                IsEnabled,
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M.SupportsStepsMode)
            }
            .CombineLatestValuesAreAllTrue()
            .ToReadOnlyReactivePropertySlim();

            FpsVisibility = RecordingModel.ObserveProperty(M => M.RecorderState)
                            .CombineLatest(IsNotAudioOrStepsMode,
                                           (RecorderState, IsNotAudioOrStepsMode) => RecorderState == RecorderState.Recording && IsNotAudioOrStepsMode)
                            .Select(M => M ? Visibility.Visible : Visibility.Hidden)
                            .ToReadOnlyReactivePropertySlim();
        }
Exemplo n.º 12
0
        public MainViewModel(AudioSource AudioSource,
                             VideoSourcesViewModel VideoSourcesViewModel,
                             VideoWritersViewModel VideoWritersViewModel,
                             IWebCamProvider WebCamProvider,
                             Settings Settings,
                             LanguageManager LanguageManager,
                             HotKeyManager HotKeyManager,
                             IPreviewWindow PreviewWindow,
                             IDialogService DialogService,
                             RememberByName RememberByName,
                             ScreenShotViewModel ScreenShotViewModel,
                             RecordingViewModel RecordingViewModel,
                             HotkeyActionRegisterer HotkeyActionRegisterer,
                             IRecentList RecentList) : base(Settings, LanguageManager)
        {
            this.AudioSource           = AudioSource;
            this.VideoSourcesViewModel = VideoSourcesViewModel;
            this.VideoWritersViewModel = VideoWritersViewModel;
            this.WebCamProvider        = WebCamProvider;
            this.HotKeyManager         = HotKeyManager;
            _dialogService             = DialogService;
            _rememberByName            = RememberByName;
            this.ScreenShotViewModel   = ScreenShotViewModel;
            this.RecordingViewModel    = RecordingViewModel;
            _recentList = RecentList;

            ShowPreviewCommand = new DelegateCommand(PreviewWindow.Show);

            #region Commands
            RefreshCommand = new DelegateCommand(OnRefresh);

            OpenOutputFolderCommand = new DelegateCommand(OpenOutputFolder);

            SelectOutputFolderCommand = new DelegateCommand(SelectOutputFolder);

            ResetFFmpegFolderCommand = new DelegateCommand(() => Settings.FFmpeg.FolderPath = "");

            TrayLeftClickCommand = new DelegateCommand(() => HotKeyManager.FakeHotkey(Settings.Tray.LeftClickAction));
            #endregion

            Settings.Audio.PropertyChanged += (Sender, Args) =>
            {
                switch (Args.PropertyName)
                {
                case nameof(Settings.Audio.Enabled):
                case null:
                case "":
                    CheckFunctionalityAvailability();
                    break;
                }
            };

            VideoSourcesViewModel.PropertyChanged += (Sender, Args) =>
            {
                switch (Args.PropertyName)
                {
                case nameof(VideoSourcesViewModel.SelectedVideoSourceKind):
                case null:
                case "":
                    CheckFunctionalityAvailability();
                    break;
                }
            };

            RecordingViewModel.PropertyChanged += (Sender, Args) =>
            {
                switch (Args.PropertyName)
                {
                case nameof(RecordingViewModel.RecorderState):
                case null:
                case "":
                    RefreshCommand.RaiseCanExecuteChanged(RecordingViewModel.RecorderState == RecorderState.NotRecording);
                    break;
                }
            };

            // If Output Dircetory is not set. Set it to Documents\Captura\
            if (string.IsNullOrWhiteSpace(Settings.OutPath))
            {
                Settings.OutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Captura");
            }

            // Create the Output Directory if it does not exist
            Settings.EnsureOutPath();

            // Handle Hoykeys
            HotkeyActionRegisterer.Register();
        }
Exemplo n.º 13
0
        public RecordingViewModel(RecordingModel RecordingModel,
                                  Settings Settings,
                                  TimerModel TimerModel,
                                  WebcamModel WebcamModel,
                                  VideoSourcesViewModel VideoSourcesViewModel,
                                  VideoWritersViewModel VideoWritersViewModel,
                                  ISystemTray SystemTray,
                                  IMainWindow MainWindow,
                                  ILocalizationProvider Loc,
                                  IAudioPlayer AudioPlayer,
                                  IRecentList RecentList,
                                  IMessageProvider MessageProvider) : base(Settings, Loc)
        {
            _recordingModel        = RecordingModel;
            _timerModel            = TimerModel;
            _videoSourcesViewModel = VideoSourcesViewModel;
            _videoWritersViewModel = VideoWritersViewModel;
            _systemTray            = SystemTray;
            _mainWindow            = MainWindow;
            _audioPlayer           = AudioPlayer;
            _recentList            = RecentList;
            _messageProvider       = MessageProvider;

            RecordCommand = new[]
            {
                Settings.Audio
                .ObserveProperty(M => M.Enabled),
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M is NoVideoSourceProvider),
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M is WebcamSourceProvider),
                WebcamModel
                .ObserveProperty(M => M.SelectedCam)
                .Select(M => M is NoWebcamItem)
            }
            .CombineLatest(M =>
            {
                var audioEnabled  = M[0];
                var audioOnlyMode = M[1];
                var webcamMode    = M[2];
                var noWebcam      = M[3];

                if (audioOnlyMode)
                {
                    return(audioEnabled);
                }

                if (webcamMode)
                {
                    return(!noWebcam);
                }

                return(true);
            })
            .ToReactiveCommand()
            .WithSubscribe(OnRecordExecute);

            PauseCommand = new[]
            {
                TimerModel
                .ObserveProperty(M => M.Waiting),
                RecordingModel
                .ObserveProperty(M => M.RecorderState)
                .Select(M => M != Models.RecorderState.NotRecording)
            }
            .CombineLatest(M => !M[0] && M[1])
            .ToReactiveCommand()
            .WithSubscribe(() =>
            {
                _audioPlayer.Play(SoundKind.Pause);

                RecordingModel.OnPauseExecute();
            });

            RecorderState = RecordingModel
                            .ObserveProperty(M => M.RecorderState)
                            .ToReadOnlyReactivePropertySlim();

            TimerModel.DurationElapsed += async() =>
            {
                if (_syncContext != null)
                {
                    _syncContext.Post(async State => await StopRecording(), null);
                }
                else
                {
                    await StopRecording();
                }
            };
        }