private async Task RipTrack(ICdDrive cdDrive, Track track, TrackIdentification trackIdentification, CancellationToken token) { var currentTrackNumber = track.TrackNumber; using (var reader = new TrackReader(cdDrive)) { var settings = _settings.Get(); using (var lame = new LameMp3Encoder(new EncoderSettings { Track = trackIdentification, Mp3Settings = new Mp3Settings { Bitrate = settings.BitRate, Type = settings.BitRateType }, Output = new OutputLocationBuilder(settings.MusicCollectionRoot, settings.FileNameMask) })) { reader.Progress += (read, bytes) => { var percentageComplete = Math.Round(((double)read / (double)bytes) * 100d, 0); _tracker.RippingProgress(currentTrackNumber, percentageComplete); }; await reader.ReadTrack(track, lame.Write, token); } } }
protected Vector2d TrySnapPoint(TrackReader track, Vector2d point, out bool snapped) { Vector2d notpoint = point; //This is somewhat lazy code used in GetSnapPoint_Grid to represent a point not equal to the actual point (TODO make something better) notpoint.X += 1.0; var lines = this.LineEndsInRadius(track, point, SnapRadius); if (lines.Length == 0) { Vector2d gsnappos; snapped = GetSnapPoint_Grid(point, notpoint, point, out gsnappos); if (snapped) { return(gsnappos); } else { return(point); } } var snap = lines[0]; snapped = true; return(Utility.CloserPoint(point, snap.Position, snap.Position2)); }
public void CheckIfCorrectSectorsAreRead() { var toc = DummyData.SteekJeVingerInDeLucht.TableOfContents; var dummyDrive = new DummyDrive(toc); var bytesRead = 0; using (var reader = new TrackReader(dummyDrive)) { reader.Progress += (read, bytes) => { }; reader.ReadTrack(150, 25, buffer => { Assert.That(buffer, Has.All.EqualTo((byte)1)); bytesRead += buffer.Length; }, CancellationToken.None).Wait(); } Assert.That(dummyDrive.StartSectors[0], Is.EqualTo(0), "We don't want the 2s lead-in when reading from the disc"); Assert.That(dummyDrive.StartSectors[1], Is.EqualTo(13), "We use 13 byte buffers (why?)"); Assert.That(dummyDrive.NumberOfSectors[0], Is.EqualTo(13), "We use 13 byte buffers (why?)"); Assert.That(dummyDrive.NumberOfSectors[1], Is.EqualTo(12), "Unless there are not enough bytes left to read"); Assert.That(bytesRead, Is.EqualTo(25)); }
public void RailwayPartGenerator_Generate_ExpectEqual() { Railway.RailwayParts.Clear(); var dataRead = TrackReader.Read(new string[] { "[1]" }); var railParts = RailwayPartsORM.Map(dataRead); var expected = new List <IRailwayPart> { new Rail() { Char = '[', CoordinateX = 0, CoordinateY = 0, }, new Station() { Char = '1', CoordinateX = 1, CoordinateY = 0, }, new Rail() { Char = ']', CoordinateX = 2, CoordinateY = 0, }, }; var railString = JsonConvert.SerializeObject(railParts); var expString = JsonConvert.SerializeObject(expected); Assert.Equal(expString, railString); }
protected IEnumerable <GameLine> SelectLines(TrackReader trk, Vector2d position) { var ends = LineEndsInRadius(trk, position, SnapRadius); foreach (var line in ends) { yield return(line); } var zoom = game.Track.Zoom; var lines = trk.GetLinesInRect( new DoubleRect((Vector2d)position - new Vector2d(24, 24), new Vector2d(24 * 2, 24 * 2)), false); foreach (var line in lines) { if (ends.Contains(line)) { continue; } double lnradius = line.Width; var angle = Angle.FromLine(line.Position, line.Position2); var rect = Utility.GetThickLine( line.Position, line.Position2, angle, lnradius * 2); if (Utility.PointInRectangle(rect, position)) { yield return(line); } } yield break; }
/// <summary> /// Gets line ends near the point by radius. /// does not support large distances as it only gets a small number of grid cells /// </summary> /// <returns>a sorted array of lines where 0 is the closest point within the radius</returns> protected GameLine[] LineEndsInRadius(TrackReader trk, Vector2d point, double rad) { var lines = trk.GetLinesInRect(new DoubleRect(point - new Vector2d(24, 24), new Vector2d(24 * 2, 24 * 2)), false); SortedList <double, List <GameLine> > ret = new SortedList <double, List <GameLine> >(); foreach (var line in lines) { var p1 = (point - line.Position).Length; var p2 = (point - line.Position2).Length; var closer = Math.Min(p1, p2); if (closer - line.Width < rad) { if (ret.ContainsKey(closer)) { ret[closer].Add(line); } else { var l = new List <GameLine>(); l.Add(line); ret[closer] = l; } } } List <GameLine> retn = new List <GameLine>(); for (int i = 0; i < ret.Values.Count; i++) { retn.AddRange(ret.Values[i]); } return(retn.ToArray()); }
private bool CheckSol(TrackReader trk) { Dictionary <string, bool> features; features = trk.GetFeatures(); bool six_one; bool redmultiplier; bool scenerywidth; features.TryGetValue(TrackFeatures.six_one, out six_one); features.TryGetValue(TrackFeatures.redmultiplier, out redmultiplier); features.TryGetValue(TrackFeatures.scenerywidth, out scenerywidth); if (six_one || redmultiplier || scenerywidth) { var msg = "*Error\nThe following features are incompatible with .sol:\n"; if (six_one) { msg += "\n* The track is based on 6.1"; } if (redmultiplier) { msg += "\n* Red line multipliers"; } if (scenerywidth) { msg += "\n* Variable width scenery"; } _errorbox.Text = msg; return(false); } return(true); }
protected bool LifeLock(TrackReader track, Timeline timeline, StandardLine line) { int offset = game.Track.Offset; int iteration = game.Track.IterationsOffset; if (offset == 0) { return(false); } var frame = timeline.GetFrame(offset, iteration); if (!frame.Crashed) { if (Settings.PinkLifelock) { var diagnosis = timeline.DiagnoseFrame(offset, iteration); foreach (var v in diagnosis) { //the next frame dies on something that isnt a fakie, so we cant stop here if (v >= 0) { return(false); } } } if (timeline.IsLineHit(line.ID, game.Track.Offset)) { return(true); } } return(false); }
private void SnapJoints(TrackReader trk, GameLine line, ref Vector2d joint1, ref Vector2d joint2) { HashSet <int> ignoreids = new HashSet <int>(); ignoreids.Add(_selection.line.ID); foreach (var snapped in _selection.snapped) { ignoreids.Add(snapped.line.ID); } var snapj1 = joint1; var snapj2 = joint2; bool j1snapped = false; bool j2snapped = false; bool ignorescenery = line is StandardLine; if (_selection.joint1) { j1snapped = GetSnapPoint(trk, joint1, line.Position2, joint1, ignoreids, out snapj1, ignorescenery); } if (_selection.joint2) { j2snapped = GetSnapPoint(trk, line.Position, joint2, joint2, ignoreids, out snapj2, ignorescenery); } if (_selection.BothJoints) { var j1diff = snapj1 - joint1; var j2diff = snapj2 - joint2; if (j1snapped && j2snapped) { if (j1diff.Length < j2diff.Length) { j2snapped = false; } else { j1snapped = false; } } if (j1snapped) { joint2 += j1diff; } else if (j2snapped) { joint1 += j2diff; } } if (j1snapped) { joint1 = snapj1; } else if (j2snapped) { joint2 = snapj2; } }
public void SilverstoneDataIntegration() { var trackData = TrackFactsHelper.GetTrackSilverstone(); var trackReader = new TrackReader(); var track = trackReader.Read(trackData.Path); track.TrackSections.Count.Should().Be(126, "contains 125 sections and 1 with only command data"); }
public void RailwayPartGenerator_Generate_ExpectThree2() { Railway.RailwayParts.Clear(); var dataRead = TrackReader.Read(new string[] { "-1-" }); var railParts = RailwayPartsORM.Map(dataRead); Assert.True(railParts.Count == 3); }
public void Station_Generate_ExpectStation() { Railway.RailwayParts.Clear(); var dataRead = TrackReader.Read(new string[] { "-1-" }); var railParts = RailwayPartsORM.Map(dataRead); Assert.IsType <Station>(railParts[1]); }
public void Phoenix8990_Contains_22_PitLane_Sections() { var trackData = TrackFactsHelper.GetTrackPhoenix8990(); var trackReader = new TrackReader(); var track = trackReader.Read(trackData.Path); track.PitLaneSections.Count.Should().Be(22); track.PitLaneSections[20].Length.Should().Be(0); }
public void ConnectStations_raw_2_Check_last() { Railway.RailwayParts.Clear(); var read = TrackReader.Read(File.ReadAllLines(@"TrainTestTrack.txt")); var parts = RailwayPartsORM.Map(read); Railway.AppendParts(parts); var station = parts[^ 1];
public void AidaDataIntegration() { var trackData = TrackFactsHelper.GetTrackAida(); var trackReader = new TrackReader(); var track = trackReader.Read(trackData.Path); track.TrackSections.Count.Should().Be(70); track.PitLaneSections.Count.Should().Be(24); track.ComputerCarLineSegments.Count.Should().Be(53); }
public void ConnectStations_raw_2_test_to_Railway() { Railway.RailwayParts.Clear(); var read = TrackReader.Read(File.ReadAllLines(@"TrainTestTrack.txt")); var parts = RailwayPartsORM.Map(read); Railway.AppendParts(parts); Assert.True(parts.Count == 5); }
/// <summary> /// Loads a MIDI file into the Sequence. /// </summary> /// <param name="fileName"> /// The MIDI file's name. /// </param> public void Load(string fileName) { #region Require if (disposed) { throw new ObjectDisposedException("Sequence"); } else if (IsBusy) { throw new InvalidOperationException(); } else if (fileName == null) { throw new ArgumentNullException("fileName"); } #endregion FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); using (stream) { MidiFileProperties newProperties = new MidiFileProperties(); TrackReader reader = new TrackReader(); List <Track> newTracks = new List <Track>(); newProperties.Read(stream); for (int i = 0; i < newProperties.TrackCount; i++) { reader.Read(stream, i); newTracks.Add(reader.Track); if (timeSignatureNumerator == -1) { timeSignatureNumerator = reader.TimeSignatureNumerator; } if (timeSignatureDenominator == -1) { timeSignatureDenominator = reader.TimeSignatureDenominator; } } properties = newProperties; tracks = newTracks; } #region Ensure Debug.Assert(Count == properties.TrackCount); #endregion }
public void MonacoDataIntegration() { var trackData = TrackFactsHelper.GetTrackMonaco(); var trackReader = new TrackReader(); var track = trackReader.Read(trackData.Path); track.TrackSections.Count.Should().Be(132); track.PitLaneSections.Count.Should().Be(22); track.ComputerCarLineSegments.Count.Should().Be(68); track.TrackSettings.LapCount.Should().Be(78); }
public void ConnectStations_raw_2_CheckStation() { Railway.RailwayParts.Clear(); var read = TrackReader.Read(File.ReadAllLines(@"TrainTestTrack.txt")); var parts = RailwayPartsORM.Map(read); Railway.AppendParts(parts); var station = parts[0]; Assert.IsType <Station>(station); }
public void ConnectionRoutesAddedCorrectly() { // Arrange var p1 = new Waypoint("P1", 0.0, 0.0); var p2 = new Waypoint("P2", 5.0, 5.0); var q1 = new Waypoint("Q1", 3.0, 3.0); var q2 = new Waypoint("Q2", 2.0, 3.0); var q3 = new Waypoint("Q3", 1.0, 3.0); var wptList = new WaypointList(); int p1Index = wptList.AddWaypoint(p1); wptList.AddWaypoint(p2); int q1Index = wptList.AddWaypoint(q1); int q2Index = wptList.AddWaypoint(q2); int q3Index = wptList.AddWaypoint(q3); var neighbor = new Neighbor("A1", q1.Distance(q2)); wptList.AddNeighbor(q1Index, q2Index, neighbor); var reader = new TrackReader <PacificTrack>( wptList, new AirportManager()); string[] routeFrom = { "Q1", "A1", "Q2", "UPR", "Q3", "P1" }; // Act var nodes = reader.Read( new PacificTrack( PacotDirection.Westbound, "A", "", "", "", RouteString.From("P1", "P2"), new[] { routeFrom.ToRouteString() }, new[] { RouteString.Empty }, new LatLon(0.0, 0.0), new LatLon(0.0, 0.0))); // Assert var pairs = nodes.ConnectionRoutes.ToList(); Assert.AreEqual(1, pairs.Count); var pair = pairs.First(); Assert.AreEqual(q3Index, pair.IndexFrom); Assert.AreEqual(p1Index, pair.IndexTo); }
protected Vector2d TrySnapPoint(TrackReader track, Vector2d point, out bool snapped) { var lines = this.LineEndsInRadius(track, point, SnapRadius); if (lines.Length == 0) { snapped = false; return(point); } var snap = lines[0]; snapped = true; return(Utility.CloserPoint(point, snap.Position, snap.Position2)); }
protected bool IsLineSnappedByKnob(TrackReader trk, Vector2d point, GameLine line, out bool knob1) { var rad = SnapRadius; var closer = Utility.CloserPoint(point, line.Position, line.Position2); if ((point - closer).Length - line.Width < rad) { knob1 = closer == line.Position; return(true); } knob1 = false; return(false); }
protected GameLine SelectLine(TrackReader trk, Vector2d position, out bool knob) { knob = false; var zoom = game.Track.Zoom; var ends = LineEndsInRadius(trk, position, SnapRadius); if (ends.Length > 0) { knob = true; return(ends[0]); } return(SelectLines(trk, position).FirstOrDefault()); }
/// <summary> /// Snaps the point specified in endpoint of line to another line if /// within snapradius, ignoring all lines specified. /// </summary> protected bool GetSnapPoint( TrackReader trk, Vector2d position1, Vector2d position2, Vector2d endpoint, ICollection <int> ignorelines, out Vector2d snappoint, bool ignorescenery) { var lines = LineEndsInRadius(trk, endpoint, SnapRadius); for (int i = 0; i < lines.Length; i++) { var curr = lines[i]; if (!ignorelines.Contains(curr.ID)) { if (ignorescenery && curr is SceneryLine) { continue;//phys lines dont wanna snap to scenery } var snap = Utility.CloserPoint(endpoint, curr.Position, curr.Position2); if (position1 == endpoint) { // don't snap to the same point. if (position2 != snap) { snappoint = snap; return(true); } } else if (position2 == endpoint) { // don't snap to the same point. if (position1 != snap) { snappoint = snap; return(true); } } else { throw new Exception("Endpoint does not match line position in snap. It's not one of the ends of the line."); } break; } } snappoint = endpoint; return(false); }
/// <summary> /// Return the line (if any) in the point that we've selected /// </summary> private LineSelection SelectInSelection(TrackReader trk, Vector2d gamepos) { foreach (var line in SelectLines(trk, gamepos)) { if (_selectedlines.Contains(line.ID)) { foreach (var s in _selection) { if (s.line.ID == line.ID) { return(s); } } } } return(null); }
private void LoadDoWork(object sender, DoWorkEventArgs e) { string fileName = (string)e.Argument; FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); using (stream) { MidiFileProperties newProperties = new MidiFileProperties(); TrackReader reader = new TrackReader(); List <Track> newTracks = new List <Track>(); newProperties.Read(stream); float percentage; for (int i = 0; i < newProperties.TrackCount && !loadWorker.CancellationPending; i++) { reader.Read(stream, i); newTracks.Add(reader.Track); if (timeSignatureNumerator == -1) { timeSignatureNumerator = reader.TimeSignatureNumerator; } if (timeSignatureDenominator == -1) { timeSignatureDenominator = reader.TimeSignatureDenominator; } percentage = (i + 1f) / newProperties.TrackCount; loadWorker.ReportProgress((int)(100 * percentage)); } if (loadWorker.CancellationPending) { e.Cancel = true; } else { properties = newProperties; tracks = newTracks; } } }
public void MontrealDataIntegration() { var trackData = TrackFactsHelper.GetTrackMontreal(); var trackReader = new TrackReader(); var track = trackReader.Read(trackData.Path); track.TrackSections.Count.Should().Be(79, "contains 78 normal sections and 1 with only command data"); track.PitLaneSections.Count.Should().Be(26); track.ComputerCarLineSegments.Count.Should().Be(48); track.ObjectShapes.Count.Should().Be(31); track.ObjectSettings.Count.Should().Be(153); track.ComputerCarLineHeader.LineStartX.Should().Be(4); track.ComputerCarSetup.FrontWing.Should().Be(11); track.TrackSettings.LapCount.Should().Be(69); }
static void Main(string[] args) { TrackReader trackReader = new TrackReader(args[0]); var points = trackReader.GetAllPoints(); Track track = new Track(points.ToList()); var calculatorService = new CalculatorService(track) .AddCalculator(new DistanceCalculator()) .AddCalculator(new ElevationCalculator()) .AddCalculator(new SpeedCalculator()) .AddCalculator(new TimeCalculator()) .SetSlope(2) .AddTimeFilter(7200) .CalculateAll(); calculatorService.PrintAllCalculations(); }
public void TrackReader_ReadFile_ExpectEqual() { var dataRead = TrackReader.Read(File.ReadAllLines(@"Railway/test-track.txt")); var expected = new List <(char chr, int X, int Y)> { ('[', 0, 0), ('1', 1, 0), ('-', 2, 0), ('<', 3, 0), ('>', 4, 0), (']', 5, 0), ('/', 6, 0), ('\\', 7, 0), ('=', 9, 0), }; Assert.Equal(expected, dataRead); }
public void AddsMainRouteCorrectly() { // Arrange var p1 = new Waypoint("P1", 0.0, 0.0); var p2 = new Waypoint("P2", 5.0, 5.0); var wptList = new WaypointList(); wptList.AddWaypoint(p1); wptList.AddWaypoint(p2); var reader = new TrackReader <PacificTrack>( wptList, new AirportManager()); // Act var nodes = reader.Read( new PacificTrack( PacotDirection.Westbound, "A", "", "", "", RouteString.From("P1", "P2"), new[] { RouteString.Empty }, new[] { RouteString.Empty }, new LatLon(0.0, 0.0), new LatLon(0.0, 0.0))); // Assert var route = nodes.MainRoute; Assert.AreEqual(2, route.Count); var n = route.First.Value; Assert.IsTrue(n.Waypoint.Equals(p1)); Assert.IsTrue(n.Neighbor.Airway == "DCT" && n.Neighbor.Distance == p1.Distance(p2)); Assert.IsTrue(route.LastWaypoint.Equals(p2)); }