public void Generate(IPlayable recording, bool secondSide) { double overlap = 0.2; if (recording.TrackCount != Constants.TrackRadius.Length) { throw new ArgumentException("No of tracks do not match"); } _noteAngle = 2 * Math.PI / (double)recording.BeatCount; double inner; double outer; StringBuilder sb = new StringBuilder(); sb.AppendFormat("\t\t// Autogenerated pins for music tracks\r\n"); for (int track = 0; track < recording.TrackCount; track++) { inner = Constants.TrackRadius[track] - 0.5 - (track % 2 == 0 ? overlap : 0); outer = inner + 1 + overlap; for (int note = 0; note < recording.BeatCount; note++) { if (recording.HasNote(track, note)) { sb.AppendFormat("\t\tpin({0},{1},{2},{3});\r\n", inner, outer, NoteAngleDegrees(track, note, secondSide), (secondSide ? "1" : "0")); } } } sb.AppendLine(); _output = sb.ToString(); _titleOutput = String.Format("\t\ttitle(\"{0}\",{1});\r\n\r\n", recording.Title.ToUpper(), (secondSide ? "1" : "0")); }
private string Generate(IPlayable recording, int startNote, int endNote, bool isFull = false, bool rotate = false) { StringBuilder sb = new StringBuilder(String.Format(Prefix, Feedrate)); // Check we're aligned OK (only for half at the moment //sb.AppendLine("(Checking extents)"); //SpindleHighCommand(sb); //GoToCommand(sb, new Point(-CutoutRadius, CutoutRadius)); //GoToCommand(sb, new Point(CutoutRadius, 0)); //GoToCommand(sb, new Point(0, -HeadOffset)); sb.AppendFormat("(Autogenerated gcode for music tracks)\r\n"); for (int track = 0; track < recording.TrackCount; track++) { // Start track sb.AppendFormat("(Track {0})\r\n", track); SpindleHighCommand(sb); GoToCommand(sb, PinCoordinates(track, rotate, startNote, false)); SpindleDownCommand(sb); int neighbourTrack = track + (track % 2 == 0 ? 1 : -1); bool hasNoteOnTrack = false; for (int note = startNote; note < endNote; note++) { if (recording.HasNote(track, note)) { sb.AppendFormat("(***{0},{1}***)\r\n", track, note); if (note != startNote) { ArcCommand(sb, PinCoordinates(track, rotate, note, false)); } // Move across so pin isn't jagged MoveToCommand(sb, PinCoordinates(neighbourTrack, rotate, note, false)); // Don't slice of a neighbouring note if (recording.HasNote(neighbourTrack, note)) { SpindleUpCommand(sb); } ArcCommand(sb, PinCoordinates(neighbourTrack, rotate, note, true)); if (recording.HasNote(neighbourTrack, note)) { SpindleDownCommand(sb); } // Back to correct track again MoveToCommand(sb, PinCoordinates(track, rotate, note, true)); } // //Move to next note // ArcCommand(sb, PinCoordinates(track, rotate, note + 1, false)); } // Ensure we have an arc even if we had no notes at all if (isFull && !hasNoteOnTrack) { ArcCommand(sb, PinCoordinates(track, rotate, endNote / 2, false)); } ArcCommand(sb, PinCoordinates(track, rotate, endNote, false)); } sb.AppendLine("(cutout)"); if (isFull) { SpindleHighCommand(sb); GoToCommand(sb, new Point(CutoutRadius, 0)); for (double c = CutoutStep; c <= CutoutDepth; c += CutoutStep) { // Cut full circle SpindleDownCommand(sb, c); ArcCommand(sb, new Point(-CutoutRadius, 0)); ArcCommand(sb, new Point(CutoutRadius, 0)); } } else { for (double c = CutoutStep; c <= CutoutDepth; c += CutoutStep) { SpindleHighCommand(sb); GoToCommand(sb, new Point(CutoutRadius, 0)); // Cut one half SpindleDownCommand(sb, c); ArcCommand(sb, new Point(-CutoutRadius, 0)); } } // return to centre SpindleHighCommand(sb); GoToCommand(sb, new Point(0, 0)); sb.Append(Suffix); return(sb.ToString()); }