public MediaViewModel(ILiveDescribePlayer mediaVideo, ProjectManager projectManager)
        {
            _mediaVideo = mediaVideo;
            PlayCommand = new RelayCommand(Play, PlayCheck);
            PauseCommand = new RelayCommand(Pause, PauseCheck);
            MuteCommand = new RelayCommand(Mute, () => true);
            PauseForExtendedDescriptionCommand = new RelayCommand(PauseForExtendedDescription, () => true);

            //Marker commands {
            MarkerMouseDownCommand = new RelayCommand(OnMarkerMouseDown, () => true);
            MarkerMouseUpCommand = new RelayCommand(OnMarkerMouseUp, () => true);
            MarkerMouseMoveCommand = new RelayCommand(OnMarkerMouseMove, () => true);
            //}

            //bound to when the video loads and is opened via the mediaelement
            VideoOpenedCommand = new RelayCommand(VideoOpen, () => true);
            MediaFailedCommand = new RelayCommand(MediaFailed, () => true);

            MediaEndedCommand = new RelayCommand(MediaEnded, () => true);
            _mediaVideo.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName.Equals("CurrentState"))
                {
                    VideoState = _mediaVideo.CurrentState;
                    RaisePropertyChanged("VideoState");
                }
            };

            projectManager.ProjectLoaded += (sender, args) =>
            {
                Waveform = args.Value.Waveform;
            };

            projectManager.ProjectClosed += (sender, args) => CloseMediaControlViewModel();
        }
        public AudioCanvasViewModel(ILiveDescribePlayer mediaPlayer, ProjectManager projectManager,
            UndoRedoManager undoRedoManager)
        {
            _projectManager = projectManager;
            _undoRedoManager = undoRedoManager;
            _player = mediaPlayer;

            //TODO: Just refer to MediaPlayer?
            mediaPlayer.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName.Equals("CurrentState"))
                    CurrentVideoState = mediaPlayer.CurrentState;
            };

            _projectManager.ProjectLoaded += (sender, args) => Waveform = args.Value.Waveform;

            GetNewSpaceTime = new RelayCommand(
                canExecute: () => CurrentVideoState != LiveDescribeVideoStates.VideoNotLoaded,
                execute: () =>
                {
                    var s = new Space();
                    OnRequestSpaceTime(s);
                    projectManager.AddSpaceAndTrackForUndo(s);
                });
        }
 public DescriptionCanvasViewModel(ILiveDescribePlayer videoMedia, ProjectManager projectManager)
 {
     _projectManager = projectManager;
     DescriptionCanvasMouseUpCommand = new RelayCommand<MouseEventArgs>(DescriptionCanvasMouseUp, param => true);
     DescriptionCanvasMouseMoveCommand = new RelayCommand<MouseEventArgs>(DescriptionCanvasMouseMove, param => true);
     DescriptionCanvasMouseDownCommand = new RelayCommand<MouseEventArgs>(DescriptionCanvasMouseDown, param => true);
     videoMedia.PropertyChanged += (sender, args) =>
     {
         if (args.PropertyName.Equals("CurrentState"))
             CurrentVideoState = videoMedia.CurrentState;
     };
 }
        public DescriptionCanvasViewModel(ILiveDescribePlayer videoMedia, ProjectManager projectManager,
            UndoRedoManager undoRedoManager)
        {
            _projectManager = projectManager;
            _undoRedoManager = undoRedoManager;
            _player = videoMedia;

            videoMedia.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName.Equals("CurrentState"))
                    CurrentVideoState = videoMedia.CurrentState;
            };
        }
        public MarkingSpacesViewModel(IntervalInfoListViewModel intervalInfoList, ILiveDescribePlayer player, UndoRedoManager undoRedoManager)
        {
            intervalInfoList.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName.Equals("SelectedSpace"))
                    SelectedSpace = intervalInfoList.SelectedSpace;
            };

            _undoRedoManager = undoRedoManager;
            _player = player;

            EditingEnabled = false;

            InitCommands();
        }
        public MarkingSpacesControlViewModel(DescriptionInfoTabViewModel descriptionInfo, ILiveDescribePlayer player, UndoRedoManager undoRedoManager)
        {
            descriptionInfo.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName.Equals("SelectedSpace"))
                    SelectedSpace = descriptionInfo.SelectedSpace;
            };

            _undoRedoManager = undoRedoManager;
            _player = player;

            EditingEnabled = false;

            InitCommands();
        }
        public AudioCanvasViewModel(ILiveDescribePlayer mediaPlayer, ProjectManager projectManager)
        {
            _projectManager = projectManager;

            AudioCanvasMouseDownCommand = new RelayCommand<MouseEventArgs>(AudioCanvasMouseDown, param => true);
            AudioCanvasMouseRightButtonDownCommand = new RelayCommand<MouseEventArgs>(AudioCanvasMouseRightButtonDown, param => true);
            mediaPlayer.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName.Equals("CurrentState"))
                    CurrentVideoState = mediaPlayer.CurrentState;
            };

            GetNewSpaceTime = new RelayCommand(
            canExecute: () => CurrentVideoState != LiveDescribeVideoStates.VideoNotLoaded,
            execute: () =>
            {
                var s = new Space();
                OnRequestSpaceTime(s);
                projectManager.AddSpaceAndTrackForUndo(s);
            });
        }
        public DescriptionRecordingViewModel(ILiveDescribePlayer mediaVideo, ProjectManager projectManager)
        {
            _mediaVideo = mediaVideo;
            _projectManager = projectManager;

            _recorder = GetDescriptionRecorder();

            InitCommands();

            Settings.Default.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName != "Microphone")
                    return;

                Recorder.MicrophoneDeviceNumber = Settings.Default.Microphone.DeviceNumber;
                try
                {
                    Log.Info("Product Name of Apply Requested Microphone: "
                        + WaveIn.GetCapabilities(Recorder.MicrophoneDeviceNumber).ProductName);
                }
                catch (MmException) { Log.Info("No Microphone is plugged in."); }
            };
        }
 public NumberLineViewModel(ILiveDescribePlayer player)
 {
     _player = player;
 }
        public MainWindowViewModel(ILiveDescribePlayer mediaVideo)
        {
            DispatcherHelper.Initialize();

            _undoRedoManager = new UndoRedoManager();
            _loadingViewModel = new LoadingViewModel(100, null, 0, false);
            _projectManager = new ProjectManager(_loadingViewModel, _undoRedoManager);
            _descriptionRecordingControlViewModel = new DescriptionRecordingControlViewModel(mediaVideo,
                _projectManager);
            _mediaControlViewModel = new MediaControlViewModel(mediaVideo, _projectManager);
            _preferences = new PreferencesViewModel();
            _descriptionInfoTabViewModel = new DescriptionInfoTabViewModel(_projectManager, _descriptionRecordingControlViewModel);
            _markingSpacesControlViewModel = new MarkingSpacesControlViewModel(_descriptionInfoTabViewModel, mediaVideo, _undoRedoManager);
            _audioCanvasViewModel = new AudioCanvasViewModel(mediaVideo, _projectManager);
            _descriptionCanvasViewModel = new DescriptionCanvasViewModel(mediaVideo, _projectManager);

            _mediaVideo = mediaVideo;

            DescriptionPlayer = new DescriptionPlayer();
            DescriptionPlayer.DescriptionFinishedPlaying += (sender, e) =>
            {
                try
                {
                    DispatcherHelper.UIDispatcher.Invoke(() =>
                        _mediaControlViewModel.ResumeFromDescription(e.Value));
                }
                catch (TaskCanceledException exception)
                {
                    Log.Warn("Task Canceled Exception", exception);
                }
            };

            #region Commands
            //Commands
            CloseProject = new RelayCommand(
                canExecute: () => _projectManager.HasProjectLoaded,
                execute: () =>
                {
                    if (_projectManager.IsProjectModified)
                    {
                        var result = MessageBoxFactory.ShowWarningQuestion(
                            string.Format(UiStrings.MessageBox_Format_SaveProjectWarning, _project.ProjectName));

                        if (result == MessageBoxResult.Yes)
                            SaveProject.Execute();
                        else if (result == MessageBoxResult.Cancel)
                            return;
                    }

                    _projectManager.CloseProject();
                });

            NewProject = new RelayCommand(() =>
            {
                var viewModel = DialogShower.SpawnNewProjectView();

                if (viewModel.DialogResult != true)
                    return;

                if (viewModel.CopyVideo)
                    CopyVideoAndSetProject(viewModel.VideoPath, viewModel.Project);
                else
                    SetProject(viewModel.Project);
            });

            OpenProject = new RelayCommand(() =>
            {
                var projectChooser = new OpenFileDialog
                {
                    Filter = string.Format(UiStrings.OpenFileDialog_Format_OpenProject, Project.Names.ProjectExtension)
                };

                bool? dialogSuccess = projectChooser.ShowDialog();
                if (dialogSuccess != true)
                    return;

                OpenProjectPath.Execute(projectChooser.FileName);
            });

            OpenProjectPath = new RelayCommand<string>(path =>
            {
                //Attempt to read project. If object fields are missing, an error window pops up.
                try
                {
                    Project p = FileReader.ReadProjectFile(path);
                    SetProject(p);
                }
                catch (JsonSerializationException)
                {
                    MessageBoxFactory.ShowError(UiStrings.MessageBox_OpenProjectFileMissingError);
                }
                catch (DirectoryNotFoundException e)
                {
                    Log.Warn("Directory not found while trying to open project", e);
                    MessageBoxFactory.ShowError(UiStrings.MessageBox_DirectoryNotFoundError);
                }
                catch (FileNotFoundException e)
                {
                    Log.Warn("FileNotFound while trying to open project", e);
                    MessageBoxFactory.ShowError(string.Format(UiStrings.MessageBox_Format_FileNotFoundError,
                        e.FileName));
                }
            });

            ClearRecentProjects = new RelayCommand(() =>
            {
                Settings.Default.RecentProjects.Clear();
                Settings.Default.Save();
            });

            ShowImportAudioDescription = new RelayCommand(
                canExecute: () => _projectManager.HasProjectLoaded,
                execute: () =>
                {
                    var viewModel = DialogShower.SpawnImportAudioDescriptionView(_projectManager, _mediaVideo.DurationMilliseconds);
                }
               );

            SaveProject = new RelayCommand(
                canExecute: () => _projectManager.IsProjectModified,
                execute: () => _projectManager.SaveProject()
            );

            ExportWithDescriptions = new RelayCommand(
                canExecute: () => _projectManager.HasProjectLoaded,
                execute: () =>
                {
                    var viewModel = DialogShower.SpawnExportWindowView(_project, _mediaVideo.Path,
                        _mediaVideo.DurationSeconds, _projectManager.AllDescriptions.ToList(),
                        _loadingViewModel);

                    if (viewModel.DialogResult != true)
                        return;
                });

            ClearCache = new RelayCommand(
                canExecute: () => _projectManager.HasProjectLoaded,
                execute: () =>
                {
                    var p = _project;

                    CloseProject.Execute();

                    Directory.Delete(p.Folders.Cache, true);

                    SetProject(p);
                });

            ShowPreferences = new RelayCommand(() =>
            {
                _preferences.RetrieveApplicationSettings();
                var preferencesWindow = new PreferencesWindow(_preferences);
                preferencesWindow.ShowDialog();
            });

            FindSpaces = new RelayCommand(
                canExecute: () => _projectManager.HasProjectLoaded,
                execute: () =>
                {
                    var spaces = AudioAnalyzer.FindSpaces(_mediaControlViewModel.Waveform);
                    _projectManager.Spaces.AddRange(spaces);
                }
            );

            ExportDescriptionsTextToSrt = new RelayCommand(
                canExecute: () => _projectManager.HasProjectLoaded,
                execute: () =>
                {
                    var saveFileDialog = new SaveFileDialog
                    {
                        FileName = Path.GetFileNameWithoutExtension(_mediaControlViewModel.Path),
                        Filter = UiStrings.SaveFileDialog_ExportToSrt
                    };

                    saveFileDialog.ShowDialog();
                    FileWriter.WriteDescriptionsTextToSrtFile(saveFileDialog.FileName,
                        _projectManager.AllDescriptions);
                }
            );

            ExportSpacesTextToSrt = new RelayCommand(
                canExecute: () => _projectManager.HasProjectLoaded,
                execute: () =>
                {
                    var saveFileDialog = new SaveFileDialog
                    {
                        FileName = Path.GetFileNameWithoutExtension(_mediaControlViewModel.Path),
                        Filter = UiStrings.SaveFileDialog_ExportToSrt
                    };

                    saveFileDialog.ShowDialog();
                    FileWriter.WriteSpacesTextToSrtFile(saveFileDialog.FileName, _projectManager.Spaces);
                }
            );

            ShowDescriptionFolder = new RelayCommand(
                canExecute: () => _projectManager.HasProjectLoaded,
                execute: () =>
                {
                    var pfi = new ProcessStartInfo("Explorer.exe", _project.Folders.Descriptions.AbsolutePath);
                    Process.Start(pfi);
                }
            );

            ShowAboutInfo = new RelayCommand(DialogShower.SpawnAboutInfoView);
            #endregion

            //If apply requested happens  in the preferences use the new saved microphone in the settings
            _descriptiontimer = new Timer(10);
            _descriptiontimer.Elapsed += Play_Tick;
            _descriptiontimer.AutoReset = true;

            #region MediaControlViewModel Events
            _mediaControlViewModel.PlayRequested += (sender, e) =>
            {
                _mediaVideo.Play();
                _descriptiontimer.Start();
                //this Handler should be attached to the view to update the graphics
                OnPlayRequested(sender, e);
            };

            _mediaControlViewModel.PauseRequested += (sender, e) =>
            {
                _mediaVideo.Pause();
                _descriptiontimer.Stop();
                if (_lastRegularDescriptionPlayed != null && _lastRegularDescriptionPlayed.IsPlaying)
                    DescriptionPlayer.Stop();
                //this Handler should be attached to the view to update the graphics
                OnPauseRequested(sender, e);
            };

            _mediaControlViewModel.OnPausedForExtendedDescription += (sender, e) =>
            {
                _mediaVideo.Pause();
                _descriptiontimer.Stop();
                CommandManager.InvalidateRequerySuggested();
            };

            _mediaControlViewModel.MuteRequested += OnMuteRequested;

            _mediaControlViewModel.MediaEndedEvent += (sender, e) =>
            {
                _descriptiontimer.Stop();
                _mediaVideo.Stop();
                OnMediaEnded(sender, e);
            };
            #endregion

            #region Property Changed Events

            _mediaControlViewModel.PropertyChanged += PropertyChangedHandler;

            //Update window title based on project name
            PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "IsProjectModified")
                    SetWindowTitle();
            };

            #endregion

            #region ProjectManager Events
            _projectManager.ProjectLoaded += (sender, args) =>
            {
                _project = args.Value;

                _mediaControlViewModel.LoadVideo(_project.Files.Video);

                SetWindowTitle();
            };

            _projectManager.ProjectModifiedStateChanged += (sender, args) => SetWindowTitle();

            _projectManager.ProjectClosed += (sender, args) =>
            {
                TryToCleanUpUnusedDescriptionAudioFiles();
                _project = null;

                SetWindowTitle();
            };
            #endregion

            SetWindowTitle();
        }