public void SetUp() { this.timelineModel = new MockTimelineModel { Duration = TimeCode.FromAbsoluteTime(10000, SmpteFrameRate.Smpte30) }; }
/// <summary> /// Callback handler for the LoadProject method. /// </summary> /// <param name="project">The project.</param> private void LoadProjectCompleted(Project project) { if (project == null) { string projectId = null; if (!HtmlPage.Document.QueryString.TryGetValue("projectId", out projectId)) { projectId = Guid.NewGuid().ToString(); } project = new Project { Name = projectId, Creator = this.configurationService.GetUserName(), Created = DateTime.Now, SmpteFrameRate = SmpteFrameRate.Smpte2997NonDrop, AutoSaveInterval = 180, RippleMode = false }; Sequence sequence = this.CreateTimeline(); project.AddTimeline(sequence); project.StartTimeCode = TimeCode.FromAbsoluteTime(0, project.SmpteFrameRate); } this.currentProject = project; }
public void ShouldCallRemoveElementOnTimelineModelWhenUnExecute() { var track = new Track { TrackType = TrackType.Visual }; this.timelineModel.Tracks.Add(track); var position = TimeCode.FromAbsoluteTime(10, SmpteFrameRate.Smpte30); var element = new TimelineElement { Position = position, Asset = new VideoAsset { Duration = TimeCode.FromAbsoluteTime(30, SmpteFrameRate.Smpte30), FrameRate = SmpteFrameRate.Smpte30, Title = "Test Video #1" } }; var command = new AddElementCommand(this.timelineModel, track, element); command.Execute(); var addedElement = this.timelineModel.AddElementArgument; Assert.IsFalse(this.timelineModel.RemoveElementCalled); command.UnExecute(); Assert.IsTrue(this.timelineModel.RemoveElementCalled); Assert.AreEqual(addedElement, this.timelineModel.RemoveElementArgument); }
public void ShouldNotCallToLinkNextElementIfThereIsNoNextElement() { var track = new Track { TrackType = TrackType.Visual }; this.timelineModel.Tracks.Add(track); var currentElement = new TimelineElement { Position = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate), InPosition = TimeCode.FromAbsoluteTime(0, this.timelineModel.Duration.FrameRate), OutPosition = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate) }; track.Shots.Add(currentElement); ToggleLinkElementCommand command = new ToggleLinkElementCommand(this.timelineModel, track, currentElement, LinkPosition.Out); Assert.IsFalse(this.timelineModel.LinkNextElementCalled); command.Execute(); Assert.IsFalse(this.timelineModel.LinkNextElementCalled); }
public void ShouldGetANewProjectIfGetProjectIdIsNull() { this.configurationService.GetParameterValueReturnFunction = parameter => { if (parameter == "ProjectId") { return(null); } if (parameter == "UserName") { return("test"); } return(string.Empty); }; var projectService = this.CreateProjectService(); this.dataServiceFacade.InvokeLoadProjectCompleted(null); Assert.IsNotNull(projectService.GetCurrentProject()); Assert.IsNotNull(projectService.GetCurrentProject().Name); Assert.AreEqual(this.configurationService.GetUserName(), projectService.GetCurrentProject().Creator); Assert.AreNotEqual(DateTime.MinValue, projectService.GetCurrentProject().Created); Assert.AreEqual(SmpteFrameRate.Smpte2997NonDrop, projectService.GetCurrentProject().SmpteFrameRate); Assert.AreEqual(TimeCode.FromAbsoluteTime(0, SmpteFrameRate.Smpte2997NonDrop), projectService.GetCurrentProject().StartTimeCode); Assert.AreEqual(false, projectService.GetCurrentProject().RippleMode); Assert.AreEqual(180, projectService.GetCurrentProject().AutoSaveInterval); Assert.AreEqual(3, projectService.GetCurrentProject().Timelines[0].Tracks.Count); }
public void ShouldCallAddElementOnTimelineModelWhenAssetIsImageAsset() { var track = new Track { TrackType = TrackType.Visual }; this.sequenceModel.Tracks.Add(track); var position = TimeCode.FromAbsoluteTime(20, SmpteFrameRate.Smpte30); var element = new TimelineElement { Position = position, Asset = new ImageAsset { Title = "Test Image #1" } }; var command = new AddElementCommand(this.sequenceModel, track, element); Assert.IsFalse(this.sequenceModel.AddElementCalled); command.Execute(); Assert.IsTrue(this.sequenceModel.AddElementCalled); Assert.AreEqual(element, this.sequenceModel.AddElementArgument); }
public void ShouldCallAddElementOnTimelineModelWhenAssetIsAudioAsset() { var track = new Track { TrackType = TrackType.Audio }; this.timelineModel.Tracks.Add(track); var position = TimeCode.FromAbsoluteTime(5, SmpteFrameRate.Smpte30); var element = new TimelineElement { Position = position, Asset = new AudioAsset { Duration = 2, Title = "Test Audio #1" } }; var command = new AddElementCommand(this.timelineModel, track, element); Assert.IsFalse(this.timelineModel.AddElementCalled); command.Execute(); Assert.IsTrue(this.timelineModel.AddElementCalled); Assert.AreEqual(element, this.timelineModel.AddElementArgument); }
/// <summary> /// Removes a <see cref="TimelineElement"/> from the timeline model. If edit mode is <see cref="EditMode.Ripple"/> should move any adjacent elements. /// </summary> protected override void ExecuteCommand() { TimelineElement currentElement = this.timelineElement; this.timelineModel.RemoveElement(currentElement, this.layer); TimelineElement previousElement = this.timelineModel.GetElementAtPosition(currentElement.Position, this.layer, currentElement); if (this.editMode == EditMode.Ripple && previousElement != null) { // RIPPLE MODE, move any adjacent elements TimeCode offset = currentElement.Duration; TimelineElement nextElement = this.timelineModel.GetElementAtPosition(currentElement.Position + currentElement.Duration, this.layer, currentElement) ?? this.timelineModel.GetElementWithinRange(currentElement.Position + currentElement.Duration, currentElement.Position + currentElement.Duration, this.layer, currentElement); // Move next elements backward while (nextElement != null) { TimeCode previousPosition = nextElement.Position; this.memento.Add(nextElement.GetMemento()); this.timelineModel.MoveElement(nextElement, this.layer, TimeCode.FromAbsoluteTime(nextElement.Position.TotalSeconds - offset.TotalSeconds, nextElement.Position.FrameRate)); currentElement = nextElement; nextElement = this.timelineModel.GetElementAtPosition(previousPosition + currentElement.Duration, this.layer, currentElement); } } }
/// <summary> /// Gets the element C. /// </summary> /// <returns>The <see cref="TimelineElement"/>.</returns> private static TimelineElement GetElementC() { return(new TimelineElement { InPosition = TimeCode.FromAbsoluteTime(0, SmpteFrameRate.Smpte30), OutPosition = TimeCode.FromAbsoluteTime(1, SmpteFrameRate.Smpte30), Position = TimeCode.FromAbsoluteTime(2, SmpteFrameRate.Smpte30) }); }
public void ShouldCallToMoveElementsOnTimelineModelInRippleModeWhenExecuteCommand() { var track = new Track { TrackType = TrackType.Visual }; this.timelineModel.Tracks.Add(track); var previousElement = new TimelineElement { Position = TimeCode.FromAbsoluteTime(0, this.timelineModel.Duration.FrameRate), InPosition = TimeCode.FromAbsoluteTime(0, this.timelineModel.Duration.FrameRate), OutPosition = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate) }; var currentElement = new TimelineElement { Position = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate), InPosition = TimeCode.FromAbsoluteTime(0, this.timelineModel.Duration.FrameRate), OutPosition = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate) }; var nextElement = new TimelineElement { Position = TimeCode.FromAbsoluteTime(40, this.timelineModel.Duration.FrameRate), InPosition = TimeCode.FromAbsoluteTime(0, this.timelineModel.Duration.FrameRate), OutPosition = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate) }; this.timelineModel.GetElementAtPositionReturnFunction = () => { if (this.timelineModel.GetElementAtPositionPositionArgument == currentElement.Position) { return(previousElement); } else if (currentElement.Position + currentElement.Duration == this.timelineModel.GetElementAtPositionPositionArgument) { return(nextElement); } else { return(null); } }; RemoveElementCommand command = new RemoveElementCommand(this.timelineModel, track, EditMode.Ripple, currentElement); Assert.IsFalse(this.timelineModel.MoveElementCalled); command.Execute(); Assert.IsTrue(this.timelineModel.MoveElementCalled); Assert.AreEqual(nextElement, this.timelineModel.MoveElementElementArgument); }
/// <summary> /// Converts pixel to seconds. /// </summary> /// <param name="px">The pixel value.</param> /// <param name="element">The element.</param> /// <param name="width">The element width.</param> /// <returns>Conversion value fromPixel to seconds as <see cref="double"/>.</returns> private static double PixelToSeconds(double px, TimelineElement element, double width) { width = (width == 0 || double.IsNaN(width)) ? 1 : width; double absouluteTime = element.Duration.TotalSeconds * px / width; if (double.IsNaN(absouluteTime) || double.IsInfinity(absouluteTime)) { absouluteTime = 0; } return(Math.Floor(TimeCode.FromAbsoluteTime(absouluteTime, element.Duration.FrameRate).TotalSeconds)); }
public void ShouldCallToLinkNextElementIfTheElementsAreUnlinkedWhenUnExecuteCommand() { var track = new Track { TrackType = TrackType.Visual }; this.timelineModel.Tracks.Add(track); var currentElement = new TimelineElement { Position = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate), InPosition = TimeCode.FromAbsoluteTime(0, this.timelineModel.Duration.FrameRate), OutPosition = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate) }; var nextElement = new TimelineElement { Position = TimeCode.FromAbsoluteTime(40, this.timelineModel.Duration.FrameRate), InPosition = TimeCode.FromAbsoluteTime(0, this.timelineModel.Duration.FrameRate), OutPosition = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate) }; track.Shots.Add(currentElement); track.Shots.Add(nextElement); this.timelineModel.IsElementLinkedToReturnValue = true; this.timelineModel.GetElementAtPositionReturnFunction = () => { if (this.timelineModel.GetElementAtPositionPositionArgument == currentElement.Position + currentElement.Duration) { return(nextElement); } else { return(null); } }; ToggleLinkElementCommand command = new ToggleLinkElementCommand(this.timelineModel, track, currentElement, LinkPosition.Out); command.Execute(); this.timelineModel.IsElementLinkedToReturnValue = false; Assert.IsFalse(this.timelineModel.LinkNextElementCalled); command.UnExecute(); Assert.IsTrue(this.timelineModel.LinkNextElementCalled); }
public void ShouldRollbackMementoWhenUnExecuteCommand() { var track = new Track { TrackType = TrackType.Visual }; this.timelineModel.Tracks.Add(track); var previousElement = new TimelineElement { Position = TimeCode.FromAbsoluteTime(0, this.timelineModel.Duration.FrameRate), InPosition = TimeCode.FromAbsoluteTime(0, this.timelineModel.Duration.FrameRate), OutPosition = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate) }; var currentElement = new TimelineElement { Position = TimeCode.FromAbsoluteTime(60, this.timelineModel.Duration.FrameRate), InPosition = TimeCode.FromAbsoluteTime(0, this.timelineModel.Duration.FrameRate), OutPosition = TimeCode.FromAbsoluteTime(20, this.timelineModel.Duration.FrameRate) }; track.Shots.Add(previousElement); track.Shots.Add(currentElement); var memento = track.GetMemento(); previousElement.Position = TimeCode.FromAbsoluteTime(50, this.timelineModel.Duration.FrameRate); currentElement.Position = TimeCode.FromAbsoluteTime(100, this.timelineModel.Duration.FrameRate); var newMemento = track.GetMemento(); Assert.AreNotEqual(memento, newMemento); LayerSnapshotCommand command = new LayerSnapshotCommand(this.timelineModel, track, memento, newMemento); command.Execute(); command.UnExecute(); foreach (TimelineElement element in track.Shots) { TimelineElement mementoElement = memento.Where(x => x.Id == element.Id).FirstOrDefault(); Assert.AreEqual(mementoElement.Position, element.Position); Assert.AreEqual(mementoElement.InPosition, element.InPosition); Assert.AreEqual(mementoElement.OutPosition, element.OutPosition); } }
public void AddCommentInsertsLast() { var model = new TimelineModel(); model.Duration = TimeCode.FromAbsoluteTime(30, SmpteFrameRate.Smpte30); model.AddComment(new Comment { Text = "First", MarkIn = 0 }); model.AddComment(new Comment { Text = "Second", MarkIn = 1 }); Assert.AreEqual("First", model.CommentElements[0].Text); Assert.AreEqual("Second", model.CommentElements[1].Text); }
/// <summary> /// Validates that the string provided is a valid TimeCode. /// </summary> /// <param name="timeCode">String that is the time code.</param> /// <param name="smpteRate">Current smpte rate.</param> /// <exception cref="InputValidationException"></exception> private static void ValidateStartTimeCode(string timeCode, SmpteFrameRate smpteRate) { try { if (!TimeCode.ValidateSmpte12MTimecode(timeCode)) { throw new InputValidationException(Resources.Resources.InvalidStartTimeCode); } if (TimeCode.FromAbsoluteTime(DefaultTimelineDuration, smpteRate) <= new TimeCode(timeCode, smpteRate)) { throw new InputValidationException(string.Format(CultureInfo.InvariantCulture, Resources.Resources.InvalidStartTimeCodeValue, TimeCode.FromAbsoluteTime(DefaultTimelineDuration, smpteRate))); } } catch (Exception ex) { throw new InputValidationException(ex.Message, ex); } }
/// <summary> /// Callback handler for the LoadProject method. /// </summary> /// <param name="project">The project.</param> private void LoadProjectCompleted(Project project) { if (project == null) { project = new Project { Name = Guid.NewGuid().ToString(), Creator = this.configurationService.GetUserName(), Created = DateTime.Now, SmpteFrameRate = SmpteFrameRate.Smpte2997NonDrop, AutoSaveInterval = 5, RippleMode = false }; project.Timeline.Add(new Track { TrackType = TrackType.Visual }); int?maxNumberOfAudioTracks = this.configurationService.GetParameterValueAsInt("MaxNumberOfAudioTracks").GetValueOrDefault(1); for (int i = 1; i <= maxNumberOfAudioTracks.Value; i++) { project.Timeline.Add(new Track { Number = i, TrackType = TrackType.Audio }); } project.Timeline.Add(new Track { TrackType = TrackType.Title }); project.StartTimeCode = TimeCode.FromAbsoluteTime(0, project.SmpteFrameRate); } this.currentProject = project; }
public void ShouldSetSettingsValuesBasedOnProjectSettingsWhenInvokingTheProjectRetrievedEvent() { this.projectService.GetCurrentProjectReturnValue.AutoSaveInterval = 29; this.projectService.GetCurrentProjectReturnValue.RippleMode = true; this.projectService.GetCurrentProjectReturnValue.SmpteFrameRate = SmpteFrameRate.Smpte24; this.projectService.GetCurrentProjectReturnValue.StartTimeCode = TimeCode.FromAbsoluteTime(3603.62, SmpteFrameRate.Smpte24); this.projectService.State = ProjectState.Retrieving; var presentationModel = this.CreatePresentationModel(); Assert.AreNotEqual(29, presentationModel.SelectedAutoSaveTimeInterval); Assert.AreNotEqual("SMPTE Film Sync", presentationModel.SelectedSmpteTimeCode); Assert.AreNotEqual("Ripple Mode", presentationModel.SelectedEditMode); Assert.AreNotEqual("01:00:03:14", presentationModel.SelectedStartTimeCode); this.projectService.InvokeProjectRetrieved(); Assert.AreEqual(29, presentationModel.SelectedAutoSaveTimeInterval); Assert.AreEqual("SMPTE Film Sync", presentationModel.SelectedSmpteTimeCode); Assert.AreEqual("Ripple Mode", presentationModel.SelectedEditMode); Assert.AreEqual("01:00:03:14", presentationModel.SelectedStartTimeCode); }
public void ShouldGetAddMaxNumberOfAudioTracks() { this.configurationService.GetParameterValueReturnFunction = parameter => { if (parameter == "ProjectId") { return(null); } if (parameter == "UserName") { return("test"); } if (parameter == "MaxNumberOfAudioTracks") { return("5"); } return(string.Empty); }; var projectService = this.CreateProjectService(); this.dataServiceFacade.InvokeLoadProjectCompleted(null); Assert.IsNotNull(projectService.GetCurrentProject()); Assert.IsNotNull(projectService.GetCurrentProject().Name); Assert.AreEqual(this.configurationService.GetUserName(), projectService.GetCurrentProject().Creator); Assert.AreNotEqual(DateTime.MinValue, projectService.GetCurrentProject().Created); Assert.AreEqual(SmpteFrameRate.Smpte2997NonDrop, projectService.GetCurrentProject().SmpteFrameRate); Assert.AreEqual(TimeCode.FromAbsoluteTime(0, SmpteFrameRate.Smpte2997NonDrop), projectService.GetCurrentProject().StartTimeCode); Assert.AreEqual(false, projectService.GetCurrentProject().RippleMode); Assert.AreEqual(5, projectService.GetCurrentProject().AutoSaveInterval); Assert.AreEqual(7, projectService.GetCurrentProject().Timeline.Count); Assert.AreEqual(5, projectService.GetCurrentProject().Timeline.Where(x => x.TrackType == RCE.Infrastructure.Models.TrackType.Audio).Count()); }
public void GetElementWithinRange() { var elementA = GetElementA(); var elementB = GetElementB(); var elementC = GetElementC(); var model = new SequenceModel(new MockEventAggregator()); model.Tracks.Add(new Track { TrackType = TrackType.Visual }); model.Tracks[0].Shots.Add(elementA); model.Tracks[0].Shots.Add(elementB); model.Tracks[0].Shots.Add(elementC); Assert.AreSame(elementA, model.GetElementWithinRange(TimeCode.FromAbsoluteTime(0.1, SmpteFrameRate.Smpte30), TimeCode.FromAbsoluteTime(1, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.AreSame(elementA, model.GetElementWithinRange(TimeCode.FromAbsoluteTime(0.1, SmpteFrameRate.Smpte30), TimeCode.FromAbsoluteTime(2, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.AreSame(elementB, model.GetElementWithinRange(TimeCode.FromAbsoluteTime(1.1, SmpteFrameRate.Smpte30), TimeCode.FromAbsoluteTime(1.2, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.AreSame(elementC, model.GetElementWithinRange(TimeCode.FromAbsoluteTime(2, SmpteFrameRate.Smpte30), TimeCode.FromAbsoluteTime(2.1, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.IsNull(model.GetElementWithinRange(TimeCode.FromAbsoluteTime(3, SmpteFrameRate.Smpte30), TimeCode.FromAbsoluteTime(10, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.IsNull(model.GetElementWithinRange(TimeCode.FromAbsoluteTime(0.1, SmpteFrameRate.Smpte30), TimeCode.FromAbsoluteTime(0.2, SmpteFrameRate.Smpte30), model.Tracks[0], elementA)); Assert.IsNull(model.GetElementWithinRange(TimeCode.FromAbsoluteTime(4, SmpteFrameRate.Smpte30), TimeCode.FromAbsoluteTime(5, SmpteFrameRate.Smpte30), model.Tracks[0], null)); }
public void GetElementAtPosition() { var elementA = GetElementA(); var elementB = GetElementB(); var elementC = GetElementC(); var model = new TimelineModel(); model.Tracks.Add(new Track { TrackType = TrackType.Visual }); model.Tracks[0].Shots.Add(elementA); model.Tracks[0].Shots.Add(elementB); model.Tracks[0].Shots.Add(elementC); Assert.AreSame(elementA, model.GetElementAtPosition(TimeCode.FromAbsoluteTime(0.1, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.AreSame(elementA, model.GetElementAtPosition(TimeCode.FromAbsoluteTime(1, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.AreSame(elementB, model.GetElementAtPosition(TimeCode.FromAbsoluteTime(1.1, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.AreSame(elementB, model.GetElementAtPosition(TimeCode.FromAbsoluteTime(2, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.AreSame(elementC, model.GetElementAtPosition(TimeCode.FromAbsoluteTime(2.1, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.AreSame(elementC, model.GetElementAtPosition(TimeCode.FromAbsoluteTime(3, SmpteFrameRate.Smpte30), model.Tracks[0], null)); Assert.IsNull(model.GetElementAtPosition(TimeCode.FromAbsoluteTime(4, SmpteFrameRate.Smpte30), model.Tracks[0], null)); }
/// <summary> /// Converts the pixel to the timecode. /// </summary> /// <param name="px">The value in pixel.</param> /// <returns>The <see cref="TimeCode"/>.</returns> private TimeCode PixelToTimeCode(double px) { return(TimeCode.FromAbsoluteTime((this.duration.TotalSeconds * px) / this.actualWidth, this.duration.FrameRate)); }
public void SetUp() { this.sequenceModel = new MockSequenceModel(); this.sequenceModel.Duration = TimeCode.FromAbsoluteTime(10000, SmpteFrameRate.Smpte30); }