Пример #1
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();
                }
            };
        }
Пример #2
0
        public MainModel(Settings Settings,
                         RememberByName RememberByName,
                         WebcamModel WebcamModel)
        {
            _settings       = Settings;
            _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();
        }
Пример #3
0
        public RecordingModel(Settings Settings,
                              ILocalizationProvider Loc,
                              ISystemTray SystemTray,
                              IPreviewWindow PreviewWindow,
                              IAudioSource AudioSource,
                              WebcamModel WebcamModel,
                              KeymapViewModel Keymap,
                              TimerModel TimerModel,
                              IMessageProvider MessageProvider,
                              IFFmpegViewsProvider FFmpegViewsProvider) : base(Settings, Loc)
        {
            _systemTray          = SystemTray;
            _previewWindow       = PreviewWindow;
            _audioSource         = AudioSource;
            _webcamModel         = WebcamModel;
            _keymap              = Keymap;
            _timerModel          = TimerModel;
            _messageProvider     = MessageProvider;
            _ffmpegViewsProvider = FFmpegViewsProvider;

            SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

            TimerModel.CountdownElapsed += InternalStartRecording;
        }
Пример #4
0
        public MainModel(Settings Settings,
                         IWebCamProvider WebCamProvider,
                         VideoWritersViewModel VideoWritersViewModel,
                         AudioSource AudioSource,
                         HotKeyManager HotKeyManager,
                         RememberByName RememberByName,
                         WebcamModel WebcamModel)
        {
            _settings = Settings;
            _videoWritersViewModel = VideoWritersViewModel;
            _audioSource           = AudioSource;
            _hotKeyManager         = HotKeyManager;
            _rememberByName        = RememberByName;
            _webcamModel           = WebcamModel;

            // 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();
        }
Пример #5
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);
            };
        }
Пример #6
0
        public ScreenShotViewModel(ILocalizationProvider Loc,
                                   Settings Settings,
                                   DiskWriter DiskWriter,
                                   ClipboardWriter ClipboardWriter,
                                   ImageUploadWriter ImgurWriter,
                                   ScreenShotModel ScreenShotModel,
                                   VideoSourcesViewModel VideoSourcesViewModel,
                                   WebcamModel WebcamModel,
                                   IPlatformServices PlatformServices) : base(Settings, Loc)
        {
            this.DiskWriter      = DiskWriter;
            this.ClipboardWriter = ClipboardWriter;
            this.ImgurWriter     = ImgurWriter;

            ScreenShotCommand = new[]
            {
                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 noVideo    = M[0];
                var webcamMode = M[1];
                var noWebcam   = M[2];

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

                return(!noVideo);
            })
            .ToReactiveCommand()
            .WithSubscribe(async M =>
            {
                var bmp = await ScreenShotModel.GetScreenShot(VideoSourcesViewModel.SelectedVideoSourceKind);

                await ScreenShotModel.SaveScreenShot(bmp);
            });

            async Task ScreenShotWindow(IWindow Window)
            {
                var img = ScreenShotModel.ScreenShotWindow(Window);

                await ScreenShotModel.SaveScreenShot(img);
            }

            ScreenShotActiveCommand = new ReactiveCommand()
                                      .WithSubscribe(async() => await ScreenShotWindow(PlatformServices.ForegroundWindow));

            ScreenShotDesktopCommand = new ReactiveCommand()
                                       .WithSubscribe(async() => await ScreenShotWindow(PlatformServices.DesktopWindow));

            ScreenshotRegionCommand = new ReactiveCommand()
                                      .WithSubscribe(async() => await ScreenShotModel.ScreenshotRegion());

            ScreenshotWindowCommand = new ReactiveCommand()
                                      .WithSubscribe(async() => await ScreenShotModel.ScreenshotWindow());

            ScreenshotScreenCommand = new ReactiveCommand()
                                      .WithSubscribe(async() => await ScreenShotModel.ScreenshotScreen());
        }
        public RecordingViewModel(RecordingModel RecordingModel,
                                  Settings Settings,
                                  TimerModel TimerModel,
                                  WebcamModel WebcamModel,
                                  VideoSourcesViewModel VideoSourcesViewModel)
        {
            _recordingModel = RecordingModel;

            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(RecordingModel.OnRecordExecute);

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

            RecordingModel.PropertyChanged += (S, E) =>
            {
                switch (E.PropertyName)
                {
                case "":
                case null:
                case nameof(RecorderState):
                    RaisePropertyChanged(nameof(RecorderState));
                    break;
                }
            };
        }
Пример #8
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();
                }
            };
        }
Пример #9
0
        public RecordingViewModel(RecordingModel RecordingModel,
                                  Settings Settings,
                                  TimerModel TimerModel,
                                  WebcamModel WebcamModel,
                                  VideoSourcesViewModel VideoSourcesViewModel,
                                  ISystemTray SystemTray,
                                  IMainWindow MainWindow,
                                  ILocalizationProvider Loc,
                                  IAudioPlayer AudioPlayer) : base(Settings, Loc)
        {
            _recordingModel = RecordingModel;
            _systemTray     = SystemTray;
            _mainWindow     = MainWindow;
            _audioPlayer    = AudioPlayer;

            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();
        }