public Staff(Score score, Type type, double left, double top) { this.score = score; this.type = type; this.left = left; this.top = top; }
public override double Show(Score score, Staff trebleStaff, Staff bassStaff, double left) { foreach (Staff staff in new[] { trebleStaff, bassStaff }) { double top = staff.top * score.Magnification; UIElement barLine = new Line { X1 = left, X2 = left, Y1 = top, Y2 = top + Staff.spaceBetweenLines * 4 * score.Magnification, Stroke = Brushes.Black, StrokeThickness = 1 }; base.AddElement(score, barLine); //score.Children.Add(barLine); //base.elements.Add(barLine); } double right = left + 1; // Czy znak zmieścił sie na pięcolinii? if (right >= score.ActualWidth - Staff.marginLeft) { // Nie zmieścił się - narysujemy ją na następnej pieciolinii. Hide(score); return -1; } right = left + 1 + Staff.spaceBetweenSigns * score.Magnification; return right; }
public override double Show(Score score, Staff trebleStaff, Staff bassStaff, double left) { double maxRightClef = left; foreach (Staff staff in new[] { trebleStaff, bassStaff }) { string glyphCode = null; double glyphTop = staff.StaffPositionToY(StaffPosition.ByLine(2)); switch (staff.type) { case Staff.Type.Treble: glyphCode = "\x00c9"; glyphTop -= 57 * score.Magnification; break; case Staff.Type.Bass: glyphCode = "\x00c7"; glyphTop -= 77.5 * score.Magnification; break; } double rightClef = base.AddFetaGlyph(score, left, glyphTop, glyphCode); //Rect boundaryClef = base.AddFetaGlyph(score, left, glyphTop, glyphCode); //double rightClef = boundaryClef.Left + boundaryClef.Width; if (rightClef > maxRightClef) maxRightClef = rightClef; } double right = maxRightClef + Staff.spaceBetweenSigns * score.Magnification; return right; }
public virtual void Hide(Score score) { foreach (var uiElement in elements) score.Children.Remove(uiElement); elements.Clear(); highlightElements.Clear(); bounds = Rect.Empty; }
public override double Show(Score score, Staff trebleStaff, Staff bassStaff, double left) { double signLeft = left; foreach (Accidental accidental in accidentals) { signLeft = accidental.Show(score, trebleStaff, bassStaff, signLeft) + Staff.spaceBetweenScaleSigns * score.Magnification; base.ExtendBounds(score, accidental.bounds); } double scaleRight = signLeft + Staff.spaceBetweenSigns; return scaleRight; }
public override double Show(Score score, Staff trebleStaff, Staff bassStaff, double left) { double right = left; string glyphCode = "\x002e"; foreach (Staff staff in new[] { trebleStaff, bassStaff }) { double glyphTop = staff.StaffPositionToY(staffPosition); glyphTop -= 57 * score.Magnification; right = base.AddFetaGlyph(score, left, glyphTop, glyphCode); } return right; }
protected double AddFetaGlyph(Score score, double glyphLeft, double glyphTop, string glyphCode, int zindex = 0) { const string familyName = "feta26"; double fontSize = 42 * score.Magnification; // Rysujemy symbol. UIElement uiElement = new TextBlock { FontFamily = new FontFamily(familyName), FontSize = fontSize, Text = glyphCode, Padding = new Thickness(0, 0, 0, 0), Margin = new Thickness(glyphLeft, glyphTop, 0, 0) }; AddElement(score, uiElement, zindex); // Wyznaczamy wymiary symbolu. FormattedText formattedText = new FormattedText( glyphCode, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface(familyName), fontSize, Brushes.Black); // Wyznaczamy granice w ktorych mieszczą się czarne piksele symbolu. Rect boundsGlyph = new Rect( glyphLeft, glyphTop + formattedText.Height + formattedText.OverhangAfter - formattedText.Extent, formattedText.Width, formattedText.Extent); ExtendBounds(score, boundsGlyph); highlightElements.Add(uiElement); // Zwracamy nowe położenie kursora. return glyphLeft + formattedText.Width; }
public void Show(Score score, Staff trebleStaff, Staff bassStaff) { const double height = 7; // Czy trzeba coś dorysować? double y; double vertLineTop, verLineBottom; double textTop; string text; switch (howTo) { case HowTo.TwoOctaveHigher: // Tak, trzeba dorysować znak 15ma y = trebleStaff.StaffPositionToY(StaffPosition.ByLegerAbove(3)); vertLineTop = y; verLineBottom = y + height; textTop = trebleStaff.StaffPositionToY(StaffPosition.ByLegerAbove(5)); text = "15ma"; break; case HowTo.OneOctaveHigher: // Tak, trzeba dorysować znak 8va. y = trebleStaff.StaffPositionToY(StaffPosition.ByLegerAbove(6)); vertLineTop = y; verLineBottom = y + height; textTop = trebleStaff.StaffPositionToY(StaffPosition.ByLegerAbove(8)); text = "8va"; break; case HowTo.OneOctaveLower: // Tak, trzeba dorysować znak 8vb. y = bassStaff.StaffPositionToY(StaffPosition.ByLegerBelow(4)); vertLineTop = y - height; verLineBottom = y; textTop = bassStaff.StaffPositionToY(StaffPosition.ByLegerBelow(4)); text = "8vb"; break; case HowTo.AtPlace: default: // Nie trzeba nic rysować. return; } // Rysuję linię poziomą. double delta = Staff.spaceBetweenSigns / 4 * score.Magnification; Line horizontalLine = new Line { X1 = left - delta, X2 = right + delta, Y1 = y, Y2 = y, Stroke = Brushes.Black, StrokeDashArray = new DoubleCollection { 7, 7 }, StrokeThickness = 0.5 }; base.AddElement(score, horizontalLine); // Rysuję linię pionową. Line verticalLine = new Line { X1 = right + delta, X2 = right + delta, Y1 = vertLineTop, Y2 = verLineBottom, Stroke = Brushes.Black, StrokeThickness = 0.5 }; base.AddElement(score, verticalLine); // Rysuję oznaczenie 8va, 8vb lub 15ma Label name = new Label { //name.FontFamily = new FontFamily(familyName), FontSize = 12 * score.Magnification, Content = text, Padding = new Thickness(0, 0, 0, 0), Margin = new Thickness(left - delta, textTop, 0, 0) }; base.AddElement(score, name); }
public double Show(Score score, Keyboard keyboard) { // szerokość klawiszy białych i czarnych double whiteWidth = keyboard.ActualWidth / Keyboard.numberOfWhiteKeys; double blackWidth = whiteWidth * 0.6; // wysokość klawiszy białych i czarnych double whiteHeight = whiteWidth * 4.0; double blackHeight = whiteHeight * 0.6; // serokość i długość klawisza double width = isWhite ? whiteWidth : blackWidth; double height = isWhite ? whiteHeight : blackHeight; // położenie klawisza wynikające z położenia w oktawie double left = 0; switch(keyNoInOctave) { case 0: left = 0; break; case 1: left = whiteWidth - blackWidth / 2; break; case 2: left = whiteWidth; break; case 3: left = whiteWidth * 2 - blackWidth / 2; break; case 4: left = whiteWidth * 2; break; case 5: left = whiteWidth * 3; break; case 6: left = whiteWidth * 4 - blackWidth / 2; break; case 7: left = whiteWidth * 4; break; case 8: left = whiteWidth * 5 - blackWidth / 2; break; case 9: left = whiteWidth * 5; break; case 10: left = whiteWidth * 6 - blackWidth / 2; break; case 11: left = whiteWidth * 6; break; } // przesunięcie wynikające z oktawy left += (int)note.octave * whiteWidth * 7; // przesunięcie wynikające z tego że w oktawie SubContra są tylko klawisze A, A# i H left -= whiteWidth * 5; // Rysuje klawisz. Rectangle keyRectangle = new Rectangle { Width = width, Height = height, Margin = new Thickness(left, 0, 0, 0), Fill = new SolidColorBrush(isWhite ? whiteKeyColor : blackKeyColor), Stroke = Brushes.Black, StrokeThickness = isWhite ? 0.2 : 0.8 }; Canvas.SetZIndex(keyRectangle, isWhite ? 0 : 2); keyboard.Children.Add(keyRectangle); // Transparentny prostokąt modyfikujący kolor klawisza i reagujący na myszę. highlightRectangle = new Rectangle { Width = width, Height = height, Margin = new Thickness(left, 0, 0, 0), Fill = Brushes.Transparent, Stroke = Brushes.Transparent, Tag = keyboard }; Canvas.SetZIndex(highlightRectangle, isWhite ? 1 : 3); keyboard.Children.Add(highlightRectangle); highlightRectangle.MouseEnter += HighlightRectangle_MouseEnter; highlightRectangle.MouseLeave += HighlightRectangle_MouseLeave; highlightRectangle.MouseDown += HighlightRectangle_MouseDown; highlightRectangle.MouseUp += HighlightRectangle_MouseUp; // Rysuję nazwy oktaw. double keyboardHeight = whiteHeight; if (note.letter == Note.Letter.C && isWhite) { const string familyName = "Consolas"; double fontSize = 12; TextBlock octaveNameTextBlock = new TextBlock { FontFamily = new FontFamily(familyName), FontSize = fontSize, Text = note.octave.ToString(), Foreground = Brushes.Red, //Margin = new Thickness(line.X1, line.Y2, 0, 0) Margin = new Thickness(left + 3, height, 0, 0) }; // Wyznaczamy wysokość napisu. FormattedText ft = new FormattedText( octaveNameTextBlock.Text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface(familyName), fontSize, Brushes.Black); keyboardHeight += ft.Height; keyboard.Children.Add(octaveNameTextBlock); } // Rysuję linie oddzielające klawisze i linie oddzielające oktawy. if (isWhite) { Line line = new Line { X1 = left, Y1 = 0, X2 = left, //Y2 = height, Y2 = keyboardHeight, Stroke = note.letter == Note.Letter.C && isWhite ? Brushes.Red : Brushes.Black, StrokeThickness = note.letter == Note.Letter.C && isWhite ? 1.0 : 0.4 }; Canvas.SetZIndex(line, 0); keyboard.Children.Add(line); } return keyboardHeight; }
public override void Hide(Score score) { base.Hide(score); foreach (Accidental accidental in accidentals) accidental.Hide(score); }
public StaffGrand(Score score, double top) { this.score = score; this.top = top; }
public Rectangle AddHighlightRectangle(Score score, Staff trebleStaff, Staff bassStaff, int zindex) { double top = trebleStaff.StaffPositionToY(StaffPosition.ByLegerAbove(6)); double bottom = bassStaff.StaffPositionToY(StaffPosition.ByLegerBelow(4)); highlightRectangle = new Rectangle { Width = bounds.Width, Height = bottom - top, Margin = new Thickness(bounds.Left, top, 0, 0), Fill = Brushes.Transparent, Stroke = Brushes.Transparent, Tag = score // potrzebne w event handlerze }; highlightRectangle.MouseEnter += HighlightRectangle_MouseEnter; highlightRectangle.MouseLeave += HightlightRectangle_MouseLeave; highlightRectangle.MouseDown += HighlightRectangle_MouseDown; AddElement(score, highlightRectangle, zindex); return highlightRectangle; }
protected void ExtendBounds(Score score, Rect extendBy) { bounds = Rect.Union(bounds, extendBy); }
protected void AddElement(Score score, UIElement uiElement, int zindex = 0) { score.Children.Add(uiElement); Canvas.SetZIndex(uiElement, zindex); elements.Add(uiElement); }
public virtual double Show(Score score, Staff trebleStaff, Staff bassStaff, double left) { return left; }