public void UnlickedTrackTest() { var cuesheet = new Cuesheet(); var testHelper = new TestHelper(); var track1 = new Track { Position = 1, End = new TimeSpan(0, 3, 23) }; var track2 = new Track { Position = 2 }; var track3 = new Track { Position = 3 }; cuesheet.AddTrack(track1, testHelper.ApplicationOptions); cuesheet.AddTrack(track2, testHelper.ApplicationOptions); cuesheet.AddTrack(track3, testHelper.ApplicationOptions); Assert.AreEqual(track1.End, track2.Begin); Assert.IsNull(track2.End); Assert.IsNull(track3.Begin); track3.Begin = new TimeSpan(0, 7, 32); Assert.IsNull(track2.End); }
public void TrackRecalculationTest() { var testHelper = new TestHelper(); var cuesheet = new Cuesheet(); var track1 = new Track(); var track2 = new Track(); var track3 = new Track(); cuesheet.AddTrack(track1, testHelper.ApplicationOptions); cuesheet.AddTrack(track2, testHelper.ApplicationOptions); cuesheet.AddTrack(track3, testHelper.ApplicationOptions); Assert.AreEqual(track1.Position.Value, (uint)1); Assert.AreEqual(track2.Position.Value, (uint)2); Assert.AreEqual(track3.Position.Value, (uint)3); Assert.AreEqual(track1.Begin, TimeSpan.Zero); Assert.IsNull(track1.End); Assert.IsNull(track2.Begin); Assert.IsNull(track2.End); Assert.IsNull(track3.Begin); Assert.IsNull(track3.End); track1.Begin = TimeSpan.Zero; track2.Begin = new TimeSpan(0, 2, 43); Assert.IsNull(track1.End); Assert.IsNull(track2.End); track3.End = new TimeSpan(0, 12, 14); Assert.IsNull(track2.End); Assert.IsNull(track3.Begin); track3.Begin = new TimeSpan(0, 7, 56); Assert.IsNull(track2.End); }
public void MoveTrackTest() { var testHelper = new TestHelper(); var cuesheet = new Cuesheet(); var track1 = new Track(); cuesheet.AddTrack(track1, testHelper.ApplicationOptions); var track2 = new Track(); cuesheet.AddTrack(track2, testHelper.ApplicationOptions); var track3 = new Track(); cuesheet.AddTrack(track3, testHelper.ApplicationOptions); Assert.AreEqual(cuesheet.Tracks.Count, 3); Assert.IsTrue(track1.Position.Value == 1); cuesheet.MoveTrack(track1, MoveDirection.Up); Assert.IsTrue(track1.Position.Value == 1); Assert.IsTrue(track3.Position.Value == 3); cuesheet.MoveTrack(track3, MoveDirection.Down); Assert.IsTrue(track3.Position.Value == 3); Assert.IsTrue(track2.Position.Value == 2); cuesheet.MoveTrack(track2, MoveDirection.Up); Assert.AreEqual(track2, cuesheet.Tracks.ElementAt(0)); Assert.AreEqual(track1, cuesheet.Tracks.ElementAt(1)); cuesheet.MoveTrack(track2, MoveDirection.Down); cuesheet.MoveTrack(track2, MoveDirection.Down); Assert.AreEqual(track2, cuesheet.Tracks.ElementAt(2)); Assert.AreEqual(track1, cuesheet.Tracks.ElementAt(0)); Assert.AreEqual(track3, cuesheet.Tracks.ElementAt(1)); }
public void TrackOverlappingTest() { var testHelper = new TestHelper(); var cuesheet = new Cuesheet(); var track1 = new Track(); var track2 = new Track(); var track3 = new Track(); cuesheet.AddTrack(track1, testHelper.ApplicationOptions); cuesheet.AddTrack(track2, testHelper.ApplicationOptions); cuesheet.AddTrack(track3, testHelper.ApplicationOptions); Assert.AreEqual(track1.Position.Value, (uint)1); Assert.AreEqual(track2.Position.Value, (uint)2); Assert.AreEqual(track3.Position.Value, (uint)3); track1.Position = 1; track2.Position = 1; track3.Position = 1; track1.End = new TimeSpan(0, 2, 30); track2.Begin = new TimeSpan(0, 2, 0); track2.End = new TimeSpan(0, 5, 30); track3.Begin = new TimeSpan(0, 4, 54); track3.End = new TimeSpan(0, 8, 12); var validationErrors = track1.GetValidationErrorsFiltered(nameof(Track.Position)); Assert.IsTrue(validationErrors.Count >= 1); validationErrors = track2.GetValidationErrorsFiltered(nameof(Track.Position)); Assert.IsTrue(validationErrors.Count >= 1); validationErrors = track3.GetValidationErrorsFiltered(nameof(Track.Position)); Assert.IsTrue(validationErrors.Count >= 1); validationErrors = track2.GetValidationErrorsFiltered(nameof(Track.Begin)); Assert.IsTrue(validationErrors.Count >= 1); validationErrors = track3.GetValidationErrorsFiltered(nameof(Track.Begin)); Assert.IsTrue(validationErrors.Count >= 1); track2.End = new TimeSpan(0, 5, 15); validationErrors = track2.GetValidationErrorsFiltered(nameof(Track.End)); Assert.IsTrue(validationErrors.Count >= 1); track1.Position = 1; track2.Position = 2; track3.Position = 3; var clone = track1.Clone(); validationErrors = clone.GetValidationErrorsFiltered(nameof(Track.Position)); Assert.IsTrue(validationErrors.Count == 0); clone.Position = 2; validationErrors = clone.GetValidationErrorsFiltered(nameof(Track.Position)); Assert.IsTrue(validationErrors.Count == 1); clone.Position = 4; validationErrors = clone.GetValidationErrorsFiltered(nameof(Track.Position)); Assert.IsTrue(validationErrors.Count == 0); }
public void AddTrackTest() { var testHelper = new TestHelper(); var cuesheet = new Cuesheet(); Assert.AreEqual(cuesheet.Tracks.Count, 0); cuesheet.AddTrack(new Track(), testHelper.ApplicationOptions); Assert.AreEqual(cuesheet.Tracks.Count, 1); }
public void EmptyCuesheetTracksValidationTest() { var testHelper = new TestHelper(); var cuesheet = new Cuesheet(); Assert.AreEqual(cuesheet.Tracks.Count, 0); var validationErrorTracks = cuesheet.GetValidationErrorsFiltered(String.Format("{0}.{1}", nameof(Cuesheet), nameof(Cuesheet.Tracks))).FirstOrDefault(); Assert.IsNotNull(validationErrorTracks); cuesheet.AddTrack(new Track(), testHelper.ApplicationOptions); validationErrorTracks = cuesheet.GetValidationErrorsFiltered(nameof(Cuesheet.Tracks)).FirstOrDefault(); Assert.IsNull(validationErrorTracks); }
public void RecordTest() { var testHelper = new TestHelper(); var cuesheet = new Cuesheet(); Assert.IsFalse(cuesheet.IsRecording); Assert.IsNull(cuesheet.RecordingTime); cuesheet.StartRecording(); Assert.IsTrue(cuesheet.IsRecording); Assert.IsNotNull(cuesheet.RecordingTime); var track = new Track(); Assert.IsNull(track.Begin); Assert.IsNull(track.End); cuesheet.AddTrack(track, testHelper.ApplicationOptions); Assert.AreEqual(TimeSpan.Zero, track.Begin); Assert.IsNull(track.End); var track2 = new Track(); cuesheet.AddTrack(track2, testHelper.ApplicationOptions); Assert.IsNotNull(track.End); Assert.AreNotEqual(TimeSpan.Zero, track.End); }
public void TrackPositionChangedTest() { var testHelper = new TestHelper(); var cuesheet = new Cuesheet(); var track1 = new Track { Position = 3, End = new TimeSpan(0, 5, 0) }; var track2 = new Track { Position = 2, Begin = track1.End, End = new TimeSpan(0, 7, 30) }; cuesheet.AddTrack(track2, testHelper.ApplicationOptions); cuesheet.AddTrack(track1, testHelper.ApplicationOptions); Assert.AreEqual(track2, cuesheet.Tracks.First()); Assert.AreEqual(track1, cuesheet.Tracks.Last()); track1.Position = 1; Assert.AreEqual(track1, cuesheet.Tracks.First()); Assert.AreEqual(track2, cuesheet.Tracks.Last()); }
public void GenerateFileTest() { var cuesheet = new Cuesheet { Artist = "CuesheetArtist", Title = "CuesheetTitle", Audiofile = new Audiofile("AudioFile.mp3"), CDTextfile = new CDTextfile("CDTextfile.cdt"), }; cuesheet.Cataloguenumber.Value = "A123"; var begin = TimeSpan.Zero; for (int i = 1; i <= 10; i++) { var track = new Track { Position = (uint)i, Artist = String.Format("Artist {0}", i), Title = String.Format("Title {0}", i), Begin = begin }; var rand = new Random(); var flagsToAdd = rand.Next(1, 3); for (int x = 0; x < flagsToAdd; x++) { track.SetFlag(Flag.AvailableFlags.ElementAt(x), SetFlagMode.Add); } begin = begin.Add(new TimeSpan(0, i, i)); track.End = begin; cuesheet.AddTrack(track, new Options.ApplicationOptions() { LinkTracksWithPreviousOne = true }); } var projectFile = new Projectfile(cuesheet); var generatedFile = projectFile.GenerateFile(); Assert.IsNotNull(generatedFile); var fileName = Path.GetTempFileName(); File.WriteAllBytes(fileName, generatedFile); var fileContent = File.ReadAllLines(fileName); var json = JsonSerializer.Serialize <Cuesheet>(cuesheet, Projectfile.Options); Assert.AreEqual(json, fileContent.FirstOrDefault()); File.Delete(fileName); }
public void ExportProfileTest() { //Prepare cuesheet var testHelper = new TestHelper(); Cuesheet cuesheet = testHelper.CuesheetController.Cuesheet; cuesheet.Artist = "Demo Artist"; cuesheet.Title = "Demo Title"; cuesheet.AudioFile = new AudioFile("Testfile.mp3"); var begin = TimeSpan.Zero; for (int i = 1; i < 25; i++) { var track = testHelper.CuesheetController.NewTrack(); track.Artist = String.Format("Demo Track Artist {0}", i); track.Title = String.Format("Demo Track Title {0}", i); track.Begin = begin; begin = begin.Add(new TimeSpan(0, i, i)); track.End = begin; cuesheet.AddTrack(track); } //Test class var exportProfile = new ExportProfile(testHelper.Localizer); exportProfile.SchemeHead.Scheme = "%Cuesheet.Artist%;%Cuesheet.Title%"; Assert.IsTrue(exportProfile.SchemeHead.IsValid); exportProfile.SchemeTracks.Scheme = "%Track.Position%;%Track.Artist%;%Track.Title%;%Track.Begin%;%Track.End%;%Track.Length%"; Assert.IsTrue(exportProfile.SchemeTracks.IsValid); exportProfile.SchemeFooter.Scheme = "Exported %Cuesheet.Title% from %Cuesheet.Artist% using AudioCuesheetEditor"; Assert.IsTrue(exportProfile.SchemeFooter.IsValid); Assert.IsTrue(exportProfile.IsExportable); var fileContent = exportProfile.GenerateExport(cuesheet); Assert.IsNotNull(fileContent); var tempFile = Path.GetTempFileName(); File.WriteAllBytes(tempFile, fileContent); var content = File.ReadAllLines(tempFile); Assert.AreEqual(content[0], "Demo Artist;Demo Title"); for (int i = 1; i < content.Length - 1; i++) { Assert.IsFalse(String.IsNullOrEmpty(content[i])); Assert.AreNotEqual(content[i], ";;;;;"); Assert.IsTrue(content[i].StartsWith(cuesheet.Tracks.ToList()[i - 1].Position + ";")); } Assert.AreEqual(content[^ 1], "Exported Demo Title from Demo Artist using AudioCuesheetEditor");
public void CheckPositionInCuesheetTest() { var testHelper = new TestHelper(); var cuesheet = new Cuesheet(); var track1 = new Track { Position = 3, End = new TimeSpan(0, 5, 0) }; cuesheet.AddTrack(track1, testHelper.ApplicationOptions); var validationErrors = track1.GetValidationErrorsFiltered(nameof(Track.Position)); Assert.IsTrue(validationErrors.Any(x => x.Message.Message.Contains(" of this track does not match track position in cuesheet. Please correct the"))); track1.Position = 1; Assert.IsTrue(track1.GetValidationErrorsFiltered(nameof(Track.Position)).Count == 0); }
public void GenerateCuesheetFileTest() { var testHelper = new TestHelper(); Cuesheet cuesheet = testHelper.CuesheetController.Cuesheet; cuesheet.Artist = "Demo Artist"; cuesheet.Title = "Demo Title"; cuesheet.AudioFile = new AudioFile("Testfile.mp3"); var begin = TimeSpan.Zero; for (int i = 1; i < 25; i++) { var track = testHelper.CuesheetController.NewTrack(); track.Artist = String.Format("Demo Track Artist {0}", i); track.Title = String.Format("Demo Track Title {0}", i); track.Begin = begin; begin = begin.Add(new TimeSpan(0, i, i)); track.End = begin; cuesheet.AddTrack(track); } var cuesheetFile = new CuesheetFile(cuesheet); var generatedFile = cuesheetFile.GenerateCuesheetFile(); Assert.IsNotNull(generatedFile); var fileName = Path.GetTempFileName(); File.WriteAllBytes(fileName, generatedFile); var fileContent = File.ReadAllLines(fileName); Assert.AreEqual(fileContent[0], String.Format("{0} \"{1}\"", CuesheetFile.CuesheetTitle, cuesheet.Title)); Assert.AreEqual(fileContent[1], String.Format("{0} \"{1}\"", CuesheetFile.CuesheetArtist, cuesheet.Artist)); Assert.AreEqual(fileContent[2], String.Format("{0} \"{1}\" {2}", CuesheetFile.CuesheetFileName, cuesheet.AudioFile.FileName, cuesheet.AudioFile.AudioFileType)); var position = 1; for (int i = 3; i < fileContent.Length; i += 4) { var track = cuesheet.Tracks.Single(x => x.Position == position); position++; Assert.AreEqual(fileContent[i], String.Format("{0}{1} {2:00} {3}", CuesheetFile.Tab, CuesheetFile.CuesheetTrack, track.Position, CuesheetFile.CuesheetTrackAudio)); Assert.AreEqual(fileContent[i + 1], String.Format("{0}{1}{2} \"{3}\"", CuesheetFile.Tab, CuesheetFile.Tab, CuesheetFile.TrackTitle, track.Title)); Assert.AreEqual(fileContent[i + 2], String.Format("{0}{1}{2} \"{3}\"", CuesheetFile.Tab, CuesheetFile.Tab, CuesheetFile.TrackArtist, track.Artist)); Assert.AreEqual(fileContent[i + 3], String.Format("{0}{1}{2} {3:00}:{4:00}:{5:00}", CuesheetFile.Tab, CuesheetFile.Tab, CuesheetFile.TrackIndex01, Math.Floor(track.Begin.Value.TotalMinutes), track.Begin.Value.Seconds, track.Begin.Value.Milliseconds / 75)); } File.Delete(fileName); }
public void RemoveTrackTest() { var testHelper = new TestHelper(); testHelper.ApplicationOptions.LinkTracksWithPreviousOne = true; var cuesheet = new Cuesheet(); var track1 = new Track() { Artist = "1", Title = "1" }; var track2 = new Track() { Artist = "2", Title = "2" }; var track3 = new Track() { Artist = "3", Title = "3" }; var track4 = new Track() { Artist = "4", Title = "4" }; var track5 = new Track() { Artist = "5", Title = "5" }; cuesheet.AddTrack(track1, testHelper.ApplicationOptions); cuesheet.AddTrack(track2, testHelper.ApplicationOptions); cuesheet.AddTrack(track3, testHelper.ApplicationOptions); cuesheet.AddTrack(track4, testHelper.ApplicationOptions); cuesheet.AddTrack(track5, testHelper.ApplicationOptions); track1.End = new TimeSpan(0, 5, 0); track2.End = new TimeSpan(0, 10, 0); track3.End = new TimeSpan(0, 15, 0); track4.End = new TimeSpan(0, 20, 0); track5.End = new TimeSpan(0, 25, 0); Assert.AreEqual(5, cuesheet.Tracks.Count); cuesheet.RemoveTrack(track2); Assert.AreEqual((uint)2, track3.Position.Value); Assert.AreEqual((uint)3, track4.Position.Value); Assert.AreEqual((uint)4, track5.Position.Value); testHelper = new TestHelper(); testHelper.ApplicationOptions.LinkTracksWithPreviousOne = true; cuesheet = new Cuesheet(); track1 = new Track { Artist = "Track 1", Title = "Track 1" }; cuesheet.AddTrack(track1, testHelper.ApplicationOptions); track2 = new Track { Title = "Track 2", Artist = "Track 2", Begin = new TimeSpan(0, 5, 0) }; cuesheet.AddTrack(track2, testHelper.ApplicationOptions); track3 = new Track { Artist = "Track 3", Title = "Track 3", Begin = new TimeSpan(0, 10, 0) }; cuesheet.AddTrack(track3, testHelper.ApplicationOptions); track4 = new Track { Artist = "Track 4", Title = "Track 4", Begin = new TimeSpan(0, 15, 0) }; cuesheet.AddTrack(track4, testHelper.ApplicationOptions); track5 = new Track { Artist = "Track 5", Title = "Track 5", Begin = new TimeSpan(0, 20, 0) }; cuesheet.AddTrack(track5, testHelper.ApplicationOptions); var list = new List <Track>() { track2, track4 }; cuesheet.RemoveTracks(list.AsReadOnly()); Assert.AreEqual(3, cuesheet.Tracks.Count); Assert.AreEqual(new TimeSpan(0, 5, 0), track3.Begin); Assert.AreEqual(new TimeSpan(0, 15, 0), track5.Begin); Assert.AreEqual((uint)1, track1.Position); Assert.AreEqual((uint)2, track3.Position); Assert.AreEqual((uint)3, track5.Position); }
public void ExportprofileTest() { var testHelper = new TestHelper(); //Prepare cuesheet Cuesheet cuesheet = new Cuesheet { Artist = "Demo Artist", Title = "Demo Title", Audiofile = new Audiofile("Testfile.mp3") }; var begin = TimeSpan.Zero; for (int i = 1; i < 25; i++) { var track = new Track { Artist = String.Format("Demo Track Artist {0}", i), Title = String.Format("Demo Track Title {0}", i), Begin = begin }; begin = begin.Add(new TimeSpan(0, i, i)); track.End = begin; cuesheet.AddTrack(track, testHelper.ApplicationOptions); var rand = new Random(); var flagsToAdd = rand.Next(0, 3); if (flagsToAdd > 0) { for (int x = 0; x < flagsToAdd; x++) { track.SetFlag(Flag.AvailableFlags.ElementAt(x), SetFlagMode.Add); } } } cuesheet.Cataloguenumber.Value = "Testcatalognumber"; cuesheet.CDTextfile = new CDTextfile("Testfile.cdt"); //Test class var exportProfile = new Exportprofile(); exportProfile.SchemeHead.Scheme = "%Cuesheet.Artist%;%Cuesheet.Title%;%Cuesheet.Cataloguenumber%;%Cuesheet.CDTextfile%"; Assert.IsTrue(exportProfile.SchemeHead.IsValid); exportProfile.SchemeTracks.Scheme = "%Track.Position%;%Track.Artist%;%Track.Title%;%Track.Begin%;%Track.End%;%Track.Length%"; Assert.IsTrue(exportProfile.SchemeTracks.IsValid); exportProfile.SchemeFooter.Scheme = "Exported %Cuesheet.Title% from %Cuesheet.Artist% using AudioCuesheetEditor"; Assert.IsTrue(exportProfile.SchemeFooter.IsValid); Assert.IsTrue(exportProfile.IsExportable); var fileContent = exportProfile.GenerateExport(cuesheet); Assert.IsNotNull(fileContent); var tempFile = Path.GetTempFileName(); File.WriteAllBytes(tempFile, fileContent); var content = File.ReadAllLines(tempFile); Assert.AreEqual(content[0], "Demo Artist;Demo Title;Testcatalognumber;Testfile.cdt"); for (int i = 1; i < content.Length - 1; i++) { Assert.IsFalse(String.IsNullOrEmpty(content[i])); Assert.AreNotEqual(content[i], ";;;;;"); Assert.IsTrue(content[i].StartsWith(cuesheet.Tracks.ToList()[i - 1].Position + ";")); } Assert.AreEqual(content[^ 1], "Exported Demo Title from Demo Artist using AudioCuesheetEditor");
public static Cuesheet ImportCuesheet(CuesheetController cuesheetController, MemoryStream fileContent) { if (fileContent == null) { throw new ArgumentNullException(nameof(fileContent)); } var cuesheet = new Cuesheet(cuesheetController); fileContent.Position = 0; using var reader = new StreamReader(fileContent); var regexCuesheetArtist = new Regex("^" + CuesheetArtist); var regexCuesheetTitle = new Regex("^" + CuesheetTitle); var regexCuesheetFile = new Regex("^" + CuesheetFileName); var regexTrackBegin = new Regex(CuesheetTrack + " [0-9]{1,} " + CuesheetTrackAudio); var regexTrackArtist = new Regex("(?<!^)" + TrackArtist); var regexTrackTitle = new Regex("(?<!^)" + TrackTitle); var regexTrackIndex = new Regex("(?<!^)" + TrackIndex01); Track track = null; while (reader.EndOfStream == false) { var line = reader.ReadLine(); if (regexCuesheetArtist.IsMatch(line) == true) { var artist = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); cuesheet.Artist = artist; } if (regexCuesheetTitle.IsMatch(line) == true) { var title = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); cuesheet.Title = title; } if (regexCuesheetFile.IsMatch(line) == true) { var audioFile = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); cuesheet.AudioFile = new AudioFile(audioFile); } if (regexTrackBegin.IsMatch(line) == true) { track = new Track(cuesheetController); } if (regexTrackArtist.IsMatch(line) == true) { var artist = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); track.Artist = artist; } if (regexTrackTitle.IsMatch(line) == true) { var title = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); track.Title = title; } if (regexTrackIndex.IsMatch(line) == true) { //TODO: Match frames also and import var regExValue = new Regex("[0-9]{2}:[0-9]{2}"); var match = regExValue.Match(line); if (match.Success == true) { var minutes = int.Parse(match.Value.Substring(0, 2)); var seconds = int.Parse(match.Value.Substring(3, 2)); var begin = new TimeSpan(0, minutes, seconds); track.Begin = begin; } cuesheet.AddTrack(track); track = null; } } return(cuesheet); }
public static Cuesheet ImportCuesheet(MemoryStream fileContent, ApplicationOptions applicationOptions) { if (fileContent == null) { throw new ArgumentNullException(nameof(fileContent)); } if (applicationOptions == null) { throw new ArgumentNullException(nameof(applicationOptions)); } var cuesheet = new Cuesheet(); fileContent.Position = 0; using var reader = new StreamReader(fileContent); var regexCuesheetArtist = new Regex("^" + CuesheetArtist); var regexCuesheetTitle = new Regex("^" + CuesheetTitle); var regexCuesheetFile = new Regex("^" + CuesheetFileName); var regexTrackBegin = new Regex(CuesheetTrack + " [0-9]{1,} " + CuesheetTrackAudio); var regexTrackArtist = new Regex("(?<!^)" + TrackArtist); var regexTrackTitle = new Regex("(?<!^)" + TrackTitle); var regexTrackIndex = new Regex("(?<!^)" + TrackIndex01); var regexTrackFlags = new Regex("(?<!^)" + TrackFlags); var regexTrackPreGap = new Regex("(?<!^)" + TrackPreGap); var regexTrackPostGap = new Regex("(?<!^)" + TrackPostGap); var regexCDTextfile = new Regex(String.Format("^{0}", CuesheetCDTextfile)); var regexCatalogueNumber = new Regex(String.Format("^{0} ", CuesheetCatalogueNumber)); var regExTimespanValue = new Regex("[0-9]{2,}:[0-9]{2,}:[0-9]{2,}"); Track track = null; while (reader.EndOfStream == false) { var line = reader.ReadLine(); if (regexCuesheetArtist.IsMatch(line) == true) { var artist = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); cuesheet.Artist = artist; } if (regexCuesheetTitle.IsMatch(line) == true) { var title = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); cuesheet.Title = title; } if (regexCuesheetFile.IsMatch(line) == true) { var audioFile = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); cuesheet.Audiofile = new Audiofile(audioFile); } if (regexCDTextfile.IsMatch(line) == true) { var cdTextfile = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); cuesheet.CDTextfile = new CDTextfile(cdTextfile); } if (regexCatalogueNumber.IsMatch(line) == true) { var catalogueNumber = line.Substring(regexCatalogueNumber.Match(line).Length); cuesheet.Cataloguenumber.Value = catalogueNumber; } if (regexTrackBegin.IsMatch(line) == true) { track = new Track(); } if (regexTrackArtist.IsMatch(line) == true) { var artist = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); track.Artist = artist; } if (regexTrackTitle.IsMatch(line) == true) { var title = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1)); track.Title = title; } if (regexTrackFlags.IsMatch(line) == true) { var match = regexTrackFlags.Match(line); var flags = line.Substring(match.Index + match.Length + 1); var flagList = Flag.AvailableFlags.Where(x => flags.Contains(x.CuesheetLabel)); track.SetFlags(flagList); } if (regexTrackPreGap.IsMatch(line) == true) { var match = regExTimespanValue.Match(line); if (match.Success == true) { var minutes = int.Parse(match.Value.Substring(0, match.Value.IndexOf(":"))); var seconds = int.Parse(match.Value.Substring(match.Value.IndexOf(":") + 1, 2)); var frames = int.Parse(match.Value.Substring(match.Value.LastIndexOf(":") + 1)); track.PreGap = new TimeSpan(0, 0, minutes, seconds, Convert.ToInt32((frames / 75.0) * 1000)); } } if (regexTrackIndex.IsMatch(line) == true) { var match = regExTimespanValue.Match(line); if (match.Success == true) { var minutes = int.Parse(match.Value.Substring(0, match.Value.IndexOf(":"))); var seconds = int.Parse(match.Value.Substring(match.Value.IndexOf(":") + 1, 2)); var frames = int.Parse(match.Value.Substring(match.Value.LastIndexOf(":") + 1)); track.Begin = new TimeSpan(0, 0, minutes, seconds, Convert.ToInt32((frames / 75.0) * 1000)); } cuesheet.AddTrack(track, applicationOptions); } if (regexTrackPostGap.IsMatch(line) == true) { var match = regExTimespanValue.Match(line); if (match.Success == true) { var minutes = int.Parse(match.Value.Substring(0, match.Value.IndexOf(":"))); var seconds = int.Parse(match.Value.Substring(match.Value.IndexOf(":") + 1, 2)); var frames = int.Parse(match.Value.Substring(match.Value.LastIndexOf(":") + 1)); track.PostGap = new TimeSpan(0, 0, minutes, seconds, Convert.ToInt32((frames / 75.0) * 1000)); } } } return(cuesheet); }
public void MoveAndDeleteTrackTest() { var testHelper = new TestHelper(); var cuesheet = new Cuesheet(); var track1 = new Track { Artist = "Track 1", Title = "Track 1" }; cuesheet.AddTrack(track1, testHelper.ApplicationOptions); var track2 = new Track { Title = "Track 2", Artist = "Track 2", Begin = new TimeSpan(0, 5, 0) }; cuesheet.AddTrack(track2, testHelper.ApplicationOptions); var track3 = new Track { Artist = "Track 3", Title = "Track 3", Begin = new TimeSpan(0, 10, 0) }; cuesheet.AddTrack(track3, testHelper.ApplicationOptions); var track4 = new Track { Artist = "Track 4", Title = "Track 4", Begin = new TimeSpan(0, 15, 0) }; cuesheet.AddTrack(track4, testHelper.ApplicationOptions); var track5 = new Track { Artist = "Track 5", Title = "Track 5", Begin = new TimeSpan(0, 20, 0) }; cuesheet.AddTrack(track5, testHelper.ApplicationOptions); cuesheet.RemoveTrack(track2); cuesheet.RemoveTrack(track4); Assert.AreEqual(3, cuesheet.Tracks.Count); track1.IsLinkedToPreviousTrack = true; track3.IsLinkedToPreviousTrack = true; track5.IsLinkedToPreviousTrack = true; var track1End = track1.End; testHelper.ApplicationOptions.LinkTracksWithPreviousOne = true; cuesheet.MoveTrack(track3, MoveDirection.Up); Assert.AreEqual((uint)1, track3.Position); Assert.AreEqual(track3, cuesheet.Tracks.ElementAt(0)); Assert.AreEqual(track1, cuesheet.GetPreviousLinkedTrack(track5)); Assert.AreEqual(TimeSpan.Zero, track3.Begin.Value); Assert.AreEqual(track1End, track1.Begin); cuesheet.MoveTrack(track5, MoveDirection.Up); Assert.AreEqual((uint)2, track5.Position); Assert.AreEqual(track5, cuesheet.Tracks.ElementAt(1)); Assert.AreEqual(track5, cuesheet.GetPreviousLinkedTrack(track1)); Assert.IsNull(cuesheet.Tracks.Last().End); //Reset for move down cuesheet.RemoveTracks(cuesheet.Tracks); track1 = new Track { Artist = "Track 1", Title = "Track 1" }; cuesheet.AddTrack(track1, testHelper.ApplicationOptions); track2 = new Track { Title = "Track 2", Artist = "Track 2", Begin = new TimeSpan(0, 5, 0) }; cuesheet.AddTrack(track2, testHelper.ApplicationOptions); track3 = new Track { Artist = "Track 3", Title = "Track 3", Begin = new TimeSpan(0, 10, 0) }; cuesheet.AddTrack(track3, testHelper.ApplicationOptions); track4 = new Track { Artist = "Track 4", Title = "Track 4", Begin = new TimeSpan(0, 15, 0) }; cuesheet.AddTrack(track4, testHelper.ApplicationOptions); track5 = new Track { Artist = "Track 5", Title = "Track 5", Begin = new TimeSpan(0, 20, 0) }; cuesheet.AddTrack(track5, testHelper.ApplicationOptions); cuesheet.RemoveTrack(track2); cuesheet.RemoveTrack(track4); Assert.AreEqual(3, cuesheet.Tracks.Count); testHelper.ApplicationOptions.LinkTracksWithPreviousOne = true; track3.IsLinkedToPreviousTrack = true; track5.IsLinkedToPreviousTrack = true; track1End = track1.End; cuesheet.MoveTrack(track1, MoveDirection.Down); Assert.AreEqual(track1, cuesheet.Tracks.ElementAt(1)); Assert.AreEqual(track3, cuesheet.GetPreviousLinkedTrack(track1)); Assert.AreEqual((uint)2, track1.Position.Value); Assert.AreEqual((uint)3, track5.Position.Value); Assert.AreEqual(track1, cuesheet.GetPreviousLinkedTrack(track5)); Assert.AreEqual(track1End, track3.End); }