using QuikDawEditor.MiscClasses; using QuikDawEditor.EditingClasses; using QuikDawEditor.Undo; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; using static QuikDawEditor.EDITING.MiscMethods; using static QuikDawEditor.EDITING.StaticProperties; namespace QuikDawEditor.EDITING.PianoRollModel; public partial class PianoRollModel { private static SolidColorBrush MeasureLineStrokeBrush = Brushes.White; double strokeThicknessFactor = 0.6; public ObservableCollection HorizontalLines { get; set; } = new ObservableCollection(); //This gets drawn each time piano roll is zoomed... need to optimize! internal void DrawMeasureLines() { GridMeasureNos.Clear(); GridMeasureScaleLines.Clear(); GridMeasureContentLines.Clear(); //Draw beat lines int measure = 0; for (int msec = 0; msec <= myClip.ClipSourceLenMilliseconds; msec += (int)(MillisecondsPerBeat * editingProject.BeatsPerMeasure)) { string MeasureNoString = (measure + 1).ToString(); double x1 = MsecToPixelsGrid(msec); GridMeasureScaleLines.Add(new Line() { X1 = x1, X2 = x1, Y1 = 0, Y2 = PianoRollHeight, Stroke = MeasureLineStrokeBrush, StrokeThickness = WorkingGridXZoomFacReverse * strokeThicknessFactor }); GridMeasureContentLines.Add(new Line() { X1 = x1, X2 = x1, Y1 = 0, Y2 = PianoRollHeight, Stroke = MeasureLineStrokeBrush, StrokeThickness = WorkingGridXZoomFacReverse * strokeThicknessFactor }); GridMeasureNos.Add(new TextBlock() { Text = MeasureNoString, Foreground = MeasureLineStrokeBrush, Margin = new Thickness(x1 + 3, 0, 0, 0), FontWeight = FontWeights.Bold, FontSize = 16, LayoutTransform = new ScaleTransform(WorkingGridXZoomFacReverse, 1) }); DoubleCollection strokeDA = null; double strokeThickness = strokeThicknessFactor; double resolution = 16; for (double sfor = 1; sfor <= resolution; sfor += 1) { x1 += measurePixels / resolution; if (sfor % resolution % 4 == 0) { strokeThickness = WorkingGridXZoomFacReverse * strokeThicknessFactor; strokeDA = null; if (sfor % resolution != 0) GridMeasureNos.Add(new TextBlock() { Text = ((int)(sfor % resolution / 4) + 1).ToString(), Foreground =MeasureLineStrokeBrush, Margin = new Thickness(x1 + 2, 6, 0, 0), FontSize = 11, LayoutTransform = new ScaleTransform(WorkingGridXZoomFacReverse, 1) }); } else { if (sfor % resolution % 2 == 0) { strokeDA = new DoubleCollection() { 0, 4 * WorkingGridXZoomFac, 6 * WorkingGridXZoomFac }; strokeThickness = 0.7 * strokeThicknessFactor * WorkingGridXZoomFacReverse; } else { strokeDA = new DoubleCollection() { 0, 3 * WorkingGridXZoomFac, 4 * WorkingGridXZoomFac }; strokeThickness = 0.5 * strokeThicknessFactor * WorkingGridXZoomFacReverse; } } GridMeasureScaleLines.Add(new Line() { X1 = x1, X2 = x1, Y1 = 0, Y2 = PianoRollHeight, Stroke = MeasureLineStrokeBrush, StrokeThickness = strokeThickness, StrokeDashArray = strokeDA }); GridMeasureContentLines.Add(new Line() { X1 = x1, X2 = x1, Y1 = 0, Y2 = PianoRollHeight, Stroke = MeasureLineStrokeBrush, StrokeThickness = strokeThickness, StrokeDashArray = strokeDA }); } measure += 1; } DrawTripletLines(); UpdateUnusedSourceWidth(); } internal double tripletRes = 1; internal void DrawTripletLines() { //Draw triplet lines TripletLines.Clear(); int measure = 0; for (int msec = 0; msec <= myClip.ClipSourceLenMilliseconds; msec += (int)(MillisecondsPerBeat * editingProject.BeatsPerMeasure)) { double x1 = MsecToPixelsGrid(msec); DoubleCollection strokeDA = null; double strokeThickness = WorkingGridXZoomFacReverse; double resolution = 6 / tripletRes; double lineOpacity = 1; for (double sfor = 1; sfor <= resolution; sfor += 1) { if (sfor % resolution % (6 / tripletRes) == 0) { strokeThickness = WorkingGridXZoomFacReverse; lineOpacity = 0.5; strokeDA = null; } else { strokeDA = null; lineOpacity = 1; //strokeDA = new DoubleCollection() { 0, 3, 4 }; strokeThickness = 0.8 * WorkingGridXZoomFacReverse; } x1 += measurePixels / resolution; TripletLines.Add(new Line() { X1 = x1, X2 = x1, Y1 = 0, Y2 = PianoRollHeight, Opacity = lineOpacity, Stroke = Brushes.Crimson, StrokeThickness = strokeThickness, StrokeDashArray = strokeDA }); } measure += 1; } } //Only drawn once private void DrawHorizontalLines() { for (int noteno = 0; noteno < NumMidiNotesVertical; noteno++) { double lineYText = NoteYPix(noteno); double lineY = NoteYPix(noteno); Separator newSep = new Separator() { BorderBrush = Brushes.Black, BorderThickness = new Thickness(0, 0.1, 0, 0), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Stretch, Height = 1, Margin = new Thickness(0, lineY, 0, 0) }; newSep.LayoutTransform = new ScaleTransform(1, 10); HorizontalLines.Add(newSep); switch (noteno % 12) { case 1: case 3: case 6: case 8: case 10: // C#, Eb, F#, Ab, Bb // Black key lines newSep.Background = Brushes.DarkGray; break; default: // White key lines newSep.Background = Brushes.Transparent; if (noteno % 12 == 0) { var tbl = new TextBlock() { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; tbl.Margin = new Thickness(54, lineYText - 6, 0, 0); string ktext = "C" + Convert.ToInt32(noteno / (double)12).ToString(); tbl.Text = ktext.PadLeft(3, ' '); NoteNames.Add(tbl); } break; } } } }