client/src/Iri.Modernisation.Controls/ViewModel/ProductionTimeLine/ProductionTimeLineVM.cs
changeset 25 a9c815025a1b
parent 24 c031f1132dde
child 27 f292db96b050
equal deleted inserted replaced
24:c031f1132dde 25:a9c815025a1b
    15 using System.Collections.Generic;
    15 using System.Collections.Generic;
    16 using System.Collections.ObjectModel;
    16 using System.Collections.ObjectModel;
    17 
    17 
    18 namespace Iri.Modernisation.Controls.ViewModel
    18 namespace Iri.Modernisation.Controls.ViewModel
    19 {
    19 {
       
    20     /// <summary>
       
    21     /// ViewModel de la ProductionTimeLine
       
    22     /// </summary>
    20     public class ProductionTimeLineVM : BaseMVVM.ViewModel.ViewModel
    23     public class ProductionTimeLineVM : BaseMVVM.ViewModel.ViewModel
    21     {
    24     {
    22 
    25 
    23 
       
    24         private bool _isIndexing;
    26         private bool _isIndexing;
       
    27        
       
    28         /// <summary>
       
    29         /// Mode Indexation
       
    30         /// </summary>
    25         public bool IsIndexing
    31         public bool IsIndexing
    26         {
    32         {
    27             get
    33             get
    28             {
    34             {
    29                 return _isIndexing;
    35                 return _isIndexing;
    35             }
    41             }
    36         }
    42         }
    37 
    43 
    38         private VideoBook _newBook;
    44         private VideoBook _newBook;
    39         private ObservableCollection<VideoSequence>[] _listVideoSequences = new ObservableCollection<VideoSequence>[4];
    45         private ObservableCollection<VideoSequence>[] _listVideoSequences = new ObservableCollection<VideoSequence>[4];
       
    46        
       
    47         /// <summary>
       
    48         /// Ensembles des VideoSequences par Chapitre
       
    49         /// </summary>
    40         public ObservableCollection<VideoSequence>[] ListVideoSequences
    50         public ObservableCollection<VideoSequence>[] ListVideoSequences
    41         {
    51         {
    42             get
    52             get
    43             {
    53             {
    44                 return _listVideoSequences;
    54                 return _listVideoSequences;
    48                 _listVideoSequences = value;
    58                 _listVideoSequences = value;
    49                 OnPropertyChanged("ListVideoSequences");
    59                 OnPropertyChanged("ListVideoSequences");
    50             }
    60             }
    51         }
    61         }
    52         
    62         
       
    63         /// <summary>
       
    64         /// VideoSequences du Chapitre en cours
       
    65         /// </summary>
    53         public ObservableCollection<VideoSequence> SelectedVideoSequences
    66         public ObservableCollection<VideoSequence> SelectedVideoSequences
    54         {
    67         {
    55             get
    68             get
    56             {
    69             {
    57                 
    70                 
    62                 _listVideoSequences[SelectedChapter] = value;
    75                 _listVideoSequences[SelectedChapter] = value;
    63                 //_newBook.Chapters[SelectedChapter].VideoSequences = value;
    76                 //_newBook.Chapters[SelectedChapter].VideoSequences = value;
    64                 OnPropertyChanged("SelectedVideoSequences");
    77                 OnPropertyChanged("SelectedVideoSequences");
    65             }
    78             }
    66         }
    79         }
       
    80 
       
    81         /// <summary>
       
    82         /// Durée Total du livre
       
    83         /// </summary>
    67         public TimeSpan TotalBookDuration
    84         public TimeSpan TotalBookDuration
    68         {
    85         {
    69             get
    86             get
    70             {
    87             {
    71                 TimeSpan temp = TimeSpan.Zero;
    88                 TimeSpan temp = TimeSpan.Zero;
    77                     }
    94                     }
    78                 }
    95                 }
    79                 return temp;
    96                 return temp;
    80             }
    97             }
    81         }
    98         }
       
    99 
       
   100         /// <summary>
       
   101         /// Chapitres
       
   102         /// </summary>
    82         public VideoChapter[] Chapters
   103         public VideoChapter[] Chapters
    83         {
   104         {
    84             get
   105             get
    85             {
   106             {
    86                 return _newBook.Chapters;
   107                 return _newBook.Chapters;
    87             }
   108             }
    88           
   109           
    89         
   110         
    90         }
   111         }
       
   112 
       
   113         /// <summary>
       
   114         /// Chapites Courant
       
   115         /// </summary>
    91         public VideoChapter SelectedBookChapter
   116         public VideoChapter SelectedBookChapter
    92         {
   117         {
    93             get
   118             get
    94             {
   119             {
    95                 return _newBook.Chapters[SelectedChapter];
   120                 return _newBook.Chapters[SelectedChapter];
    96             }
   121             }
    97         }
   122         }
    98 
   123 
    99 
   124 
   100         private VideoSequence _actualVideoSequence;
   125         private VideoSequence _actualVideoSequence;
       
   126         /// <summary>
       
   127         /// VideoSequence en lecture sur le Master
       
   128         /// </summary>
   101         public VideoSequence ActualVideoSequence
   129         public VideoSequence ActualVideoSequence
   102         {
   130         {
   103             get
   131             get
   104             {
   132             {
   105                 return _actualVideoSequence;
   133                 return _actualVideoSequence;
   109                 _actualVideoSequence = value;
   137                 _actualVideoSequence = value;
   110                 OnPropertyChanged("ActualVideoSequence");
   138                 OnPropertyChanged("ActualVideoSequence");
   111             }
   139             }
   112         }
   140         }
   113 
   141 
   114      
   142         /// <summary>
       
   143         /// Ensemble des VideoSequences 
       
   144         /// </summary>
   115         public List<VideoSequence> TimeLine
   145         public List<VideoSequence> TimeLine
   116         {
   146         {
   117             get
   147             get
   118             {
   148             {
   119                 List<VideoSequence> _tmp = new List<VideoSequence>();
   149                 List<VideoSequence> _tmp = new List<VideoSequence>();
   144             {
   174             {
   145                 _selectedChapter = value;
   175                 _selectedChapter = value;
   146                 OnPropertyChanged("SelectedChapter");
   176                 OnPropertyChanged("SelectedChapter");
   147             }
   177             }
   148         }
   178         }
       
   179 
   149         private VideoViewerVM _videoViewerVM;
   180         private VideoViewerVM _videoViewerVM;
       
   181         /// <summary>
       
   182         /// ViewModel du Master
       
   183         /// </summary>
   150         public VideoViewerVM ViewModelVideoViewer
   184         public VideoViewerVM ViewModelVideoViewer
   151         {
   185         {
   152             get
   186             get
   153             {
   187             {
   154                 return _videoViewerVM;
   188                 return _videoViewerVM;
   159                 OnPropertyChanged("ViewModelVideoViewer");
   193                 OnPropertyChanged("ViewModelVideoViewer");
   160             }
   194             }
   161         }
   195         }
   162 
   196 
   163         private double _position;
   197         private double _position;
       
   198         /// <summary>
       
   199         /// Position Actuelle de lecture
       
   200         /// </summary>
   164         public double Position
   201         public double Position
   165         {
   202         {
   166             get
   203             get
   167             {
   204             {
   168                 return _position;
   205                 return _position;
   174                 OnPropertyChanged("Position");
   211                 OnPropertyChanged("Position");
   175             }
   212             }
   176         }
   213         }
   177 
   214 
   178         private ObservableCollection<SegmentIndex>[] _listSegmentIndex;
   215         private ObservableCollection<SegmentIndex>[] _listSegmentIndex;
       
   216         /// <summary>
       
   217         /// Ensemble des Index par Chapitre
       
   218         /// </summary>
   179         public ObservableCollection<SegmentIndex>[] ListIndex
   219         public ObservableCollection<SegmentIndex>[] ListIndex
   180         {
   220         {
   181             get
   221             get
   182             {
   222             {
   183                 return _listSegmentIndex;
   223                 return _listSegmentIndex;
   184             }
   224             }
   185         }
   225         }
       
   226         /// <summary>
       
   227         /// Index du Chapitre en cours
       
   228         /// </summary>
   186         public ObservableCollection<SegmentIndex> SelectedIndex
   229         public ObservableCollection<SegmentIndex> SelectedIndex
   187         {
   230         {
   188             get
   231             get
   189             {
   232             {
   190                 return _listSegmentIndex[SelectedChapter];
   233                 return _listSegmentIndex[SelectedChapter];
   196                 OnPropertyChanged("SelectedIndex");
   239                 OnPropertyChanged("SelectedIndex");
   197             }
   240             }
   198         }
   241         }
   199 
   242 
   200         private VideoChapterType _selectedChapterType;
   243         private VideoChapterType _selectedChapterType;
       
   244 
       
   245         /// <summary>
       
   246         /// Chapitre en cours
       
   247         /// </summary>
   201         public VideoChapterType SelectedChapterType
   248         public VideoChapterType SelectedChapterType
   202         {
   249         {
   203             get
   250             get
   204             {
   251             {
   205                 return _selectedChapterType;
   252                 return _selectedChapterType;
   208             {
   255             {
   209                 _selectedChapterType = value;
   256                 _selectedChapterType = value;
   210                 OnPropertyChanged("SelectedChapterType");
   257                 OnPropertyChanged("SelectedChapterType");
   211             }
   258             }
   212         }
   259         }
   213  
   260 
   214       
   261         private void InitializeCommands()
       
   262         {
       
   263             #region Commands
       
   264             Commands.ProductionView.DelVideoSequence.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(DelVideoSequence_Executed);
       
   265             Commands.ProductionTimeLine.EditorPartSelected.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(EditorPartSelected_Executed);
       
   266             Commands.ProductionTimeLine.EditorPartFinished.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(EditorPartFinished_Executed);
       
   267             Commands.ProductionView.ClickAddIndex.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(ClickAddIndex_Executed);
       
   268             Commands.TimeChange.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(TimeChange_Executed);
       
   269             #endregion
       
   270 
       
   271             #region VideoSequences CollectionChanged
       
   272             _listVideoSequences[0].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   273             _listVideoSequences[1].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   274             _listVideoSequences[2].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   275             _listVideoSequences[3].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   276             #endregion
       
   277 
       
   278             #region SegmentIndex CollectionChanged
       
   279             _listSegmentIndex[0].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   280             _listSegmentIndex[1].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   281             _listSegmentIndex[2].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   282             _listSegmentIndex[3].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   283             #endregion
       
   284         }
   215         public ProductionTimeLineVM()
   285         public ProductionTimeLineVM()
   216         {
   286         {
   217             _newBook = new VideoBook();
   287             _newBook = new VideoBook();
   218             _listVideoSequences = new ObservableCollection<VideoSequence>[4]
   288             _listVideoSequences = new ObservableCollection<VideoSequence>[4]
   219             {
   289             {
   220                 new ObservableCollection<VideoSequence>(),
   290                 new ObservableCollection<VideoSequence>(),
   221                 new ObservableCollection<VideoSequence>(),
   291                 new ObservableCollection<VideoSequence>(),
   222                 new ObservableCollection<VideoSequence>(),
   292                 new ObservableCollection<VideoSequence>(),
   223                 new ObservableCollection<VideoSequence>()
   293                 new ObservableCollection<VideoSequence>()
   224             };
   294             };
   225            // PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(ProductionTimeLineVM_PropertyChanged);
       
   226            // SelectedVideoSequences = new ObservableCollection<VideoSequence>();
       
   227             Commands.ProductionView.DelVideoSequence.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(DelVideoSequence_Executed);
       
   228             Commands.ProductionTimeLine.EditorPartSelected.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(EditorPartSelected_Executed);
       
   229             Commands.ProductionTimeLine.EditorPartFinished.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(EditorPartFinished_Executed);
       
   230             Commands.ProductionView.ClickAddIndex.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(ClickAddIndex_Executed);
       
   231             Commands.TimeChange.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(TimeChange_Executed);
       
   232             _listVideoSequences[0].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   233             _listVideoSequences[1].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   234             _listVideoSequences[2].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   235             _listVideoSequences[3].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
       
   236 
       
   237             _listSegmentIndex = new ObservableCollection<SegmentIndex>[4]
   295             _listSegmentIndex = new ObservableCollection<SegmentIndex>[4]
   238             {
   296             {
   239                 new ObservableCollection<SegmentIndex>(),
   297                 new ObservableCollection<SegmentIndex>(),
   240                 new ObservableCollection<SegmentIndex>(),
   298                 new ObservableCollection<SegmentIndex>(),
   241                 new ObservableCollection<SegmentIndex>(),
   299                 new ObservableCollection<SegmentIndex>(),
   242                 new ObservableCollection<SegmentIndex>()
   300                 new ObservableCollection<SegmentIndex>()
   243             };
   301             };
   244             _listSegmentIndex[0].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
   302            // PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(ProductionTimeLineVM_PropertyChanged);
   245             _listSegmentIndex[1].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
   303            // SelectedVideoSequences = new ObservableCollection<VideoSequence>();
   246             _listSegmentIndex[2].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
   304            InitializeCommands();
   247             _listSegmentIndex[3].CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedVideoSequences_CollectionChanged);
   305         }
   248         }
   306 
   249 
   307     
   250         void TimeChange_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
   308         private void TimeChange_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
   251         {
   309         {
   252             double newValue = ((double)e.Parameter);
   310             double newValue = ((double)e.Parameter);
   253             if(e.Source == this)
   311             if(e.Source == this)
   254             {
   312             {
   255                 if (ActualVideoSequence.TimerIn.TotalMilliseconds > newValue || ActualVideoSequence.TimerOut.TotalMilliseconds < newValue)
   313                 if (ActualVideoSequence.TimerIn.TotalMilliseconds > newValue || ActualVideoSequence.TimerOut.TotalMilliseconds < newValue)
   257                     foreach (VideoSequence Vs in TimeLine)
   315                     foreach (VideoSequence Vs in TimeLine)
   258                     {
   316                     {
   259                         if (Vs.TimerIn.TotalMilliseconds <= newValue && Vs.TimerOut.TotalMilliseconds > newValue)
   317                         if (Vs.TimerIn.TotalMilliseconds <= newValue && Vs.TimerOut.TotalMilliseconds > newValue)
   260                         {
   318                         {
   261                             ActualVideoSequence = Vs;
   319                             ActualVideoSequence = Vs;
       
   320                             ViewModelVideoViewer.Source = ActualVideoSequence.Path;
   262                             ViewModelVideoViewer.GoTo(TimeSpan.FromMilliseconds(newValue) - Vs.TimerIn +Vs.BeginTrim);
   321                             ViewModelVideoViewer.GoTo(TimeSpan.FromMilliseconds(newValue) - Vs.TimerIn +Vs.BeginTrim);
   263                         }
   322                         }
   264                     }
   323                     }
   265                 }
   324                 }
   266                 else
   325                 else
   270                 
   329                 
   271                
   330                
   272             }
   331             }
   273         }
   332         }
   274 
   333 
   275         void ClickAddIndex_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
   334         private void ClickAddIndex_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
   276         {
   335         {
   277             if(IsIndexing)
   336             if(IsIndexing)
   278             {
   337             {
   279                 TimeSpan dur = TimeSpan.Zero;
   338                 TimeSpan dur = TimeSpan.Zero;
   280                 // Permet de créer un Index avec une durée calé sur les videos.
   339                 // Permet de créer un Index avec une durée calé sur les videos.
   295 
   354 
   296             }
   355             }
   297  
   356  
   298         }
   357         }
   299 
   358 
   300         void DelVideoSequence_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
   359         private void DelVideoSequence_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
   301         {
   360         {
   302             SelectedVideoSequences.Remove(((CustomableVideoElementVM)e.Parameter).VideoSequence);
   361             SelectedVideoSequences.Remove(((CustomableVideoElementVM)e.Parameter).VideoSequence);
   303             OnPropertyChanged("TotalBookDuration");
   362             OnPropertyChanged("TotalBookDuration");
   304         }
   363         }
   305 
   364 
   306         void SelectedVideoSequences_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
   365         private void SelectedVideoSequences_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
   307         {
   366         {
   308             
   367             
   309             OnPropertyChanged("TotalBookDuration");
   368             OnPropertyChanged("TotalBookDuration");
   310             Commands.ProductionView.VideoRecordUpdated.Execute();
   369             Commands.ProductionView.VideoRecordUpdated.Execute();
   311         }
   370         }
   312 
   371 
   313         void ProductionTimeLineVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
   372         private void EditorPartFinished_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
   314         {
       
   315             //Commands.ProductionView.VideoRecordUpdated.Execute();
       
   316         }
       
   317 
       
   318         void EditorPartFinished_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
       
   319         {
   373         {
   320             SelectedChapter = -1;
   374             SelectedChapter = -1;
   321         }
   375         }
   322 
   376 
   323         void EditorPartSelected_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
   377         private void EditorPartSelected_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
   324         {
   378         {
   325            
   379            
   326             SelectedChapter = (int)((HeaderProductionEventArgs)e.Source).ChapterType;
   380             SelectedChapter = (int)((HeaderProductionEventArgs)e.Source).ChapterType;
   327             SelectedChapterType = ((HeaderProductionEventArgs)e.Source).ChapterType ;
   381             SelectedChapterType = ((HeaderProductionEventArgs)e.Source).ChapterType ;
   328             IsIndexing = ((HeaderProductionEventArgs)e.Source).IsIndexPart;
   382             IsIndexing = ((HeaderProductionEventArgs)e.Source).IsIndexPart;