protected AbstractKey(ClefSignMusicXML clefSign, int line, int keyFifths) { drawingVisualHost = new DrawingVisualHost(); keyAccidentals = GetKeyAccidentals(keyFifths); keyStaffSpaceIndex = GetKeyStaffSpaceIndex(clefSign, line, keyFifths > 0 ? false:true); this.keyFifths = keyFifths; }
public static void AddCharacterGlyph(this DrawingVisualHost visualHost, Point position, string character, bool isSmall = false, Brush color = null) { Brush characterColor = color ?? Brushes.Black; DrawingVisual visual = new DrawingVisual(); ushort glyphIndex = character.GetGlyphIndexOfCharacter(); PageProperties pageProperties = (PageProperties)ViewModel.ViewModelLocator.Instance.Main.CurrentPageLayout; GlyphTypeface gtf; Typeface typeFace = TypeFaces.BravuraMusicFont; typeFace.TryGetGlyphTypeface(out gtf); double smallFactor = isSmall ? 0.7 : 1; Point calculatedPosition = new Point(position.X, position.Y /* + pageProperties.IndexStaffLinePositions[3]*/); double characterSize = pageProperties.StaffHeight.MMToWPFUnit() * smallFactor; using (DrawingContext dc = visual.RenderOpen()) { GlyphRun gr = new GlyphRun(gtf, 0, // Bi-directional nesting level false, // isSideways characterSize, // pt size new ushort[] { glyphIndex }, // glyphIndices calculatedPosition, // baselineOrigin new double[] { 0.0 }, // advanceWidths null, // glyphOffsets null, // characters null, // deviceFontName null, // clusterMap null, // caretStops null); // xmlLanguage dc.DrawGlyphRun(characterColor, gr); } visualHost.AddVisual(visual); }
private void Draw(bool measure) { staffLines = ViewModel.ViewModelLocator.Instance.Main.CurrentPageLayout.AvaliableIndexLinePositions; DrawingVisualHost rest = new DrawingVisualHost(); Brush color = ViewModel.ViewModelLocator.Instance.Main.CurrentLayout.LayoutStyle.Colors[int.Parse(noteItem.Voice)]; double positionY = 0.0; if (measure) { measureRest = true; GetSymbol(); positionY = SetPosition(CalculateRestPositionY()); rest.AddCharacterGlyph(new Point(0, positionY), symbol, color: color); } else { GetSymbol(); positionY = SetPosition(CalculateRestPositionY()); rest.AddCharacterGlyph(new Point(0, positionY), symbol, color: color); } if (dotCount != 0) { double shiftUp = (int)restType >= 6 ? SetPosition(1) : restType == NoteTypeValueMusicXML.Item32nd ? SetPosition(3) : restType == NoteTypeValueMusicXML.Item64th ? SetPosition(5) : SetPosition(5); Point dotPosition = new Point(DrawingMethods.GetTextWidth(symbol, TypeFaces.GetMusicFont()) + 4.0.TenthsToWPFUnit(), positionY - shiftUp); rest.AddCharacterGlyph(dotPosition, MusicSymbols.Dot, color: color); } ItemCanvas.Children.Add(rest); }
private void Draw() { LayoutStyle.NotesLayoutStyle notesStyle = ViewModel.ViewModelLocator.Instance.Main.CurrentLayout.LayoutStyle.NotesStyle; DrawingVisual dravingVisualStem = new DrawingVisual(); using (DrawingContext dc = dravingVisualStem.RenderOpen()) { dc.DrawLine(new Pen(note.Color, notesStyle.StemThickness * sizeFactor), startPoint, endPoint); } //! check if added previously to prevent unnecessary remove+add calls bool stemVisualAdded = false; if (stemVisual == null) { stemVisual = new DrawingVisualHost(); stemVisual.Tag = "stem"; } else { stemVisual.ClearVisuals(); stemVisualAdded = true; //! no need to add to noteVisual } //! stemVisual.AddVisual(dravingVisualStem); //! add visual to noteVisual (one time only) if (!stemVisualAdded) { note.AddStem(stemVisual); } }
protected AbstractTime(string beatTime, string beatType, TimeSymbolMusicXML timeSymbol, AbstractStaff staff) { visualHost = new DrawingVisualHost(); this.timeSymbol = timeSymbol; SetTimeAndBeats(beatTime, beatType); this.staff = staff; }
protected AbstractStaff(int linesCount, double desiredHeight, double desiredWidth) { this.linesCount = linesCount; this.desiredWidth = desiredWidth; this.desiredHeight = desiredHeight; visualHost = new DrawingVisualHost(); }
protected override void Update() { var staffLineCoords = ViewModel.ViewModelLocator.Instance.Main.CurrentPageLayout.AvaliableIndexLinePositions; DrawingVisualHost cl = new DrawingVisualHost(); if (fifts == 0) { itemWidth = 0; } else { int symbolsCount = Math.Abs(fifts); if (symbolsCount > 7) { symbolsCount = 0; } Point currentPosition = new Point(); double symbolWidth = DrawingMethods.GetTextWidth(keySymbol, TypeFaces.GetMusicFont()); double keySignatureWidth = symbolsCount * symbolWidth; for (int i = 0; i < symbolsCount; i++) { currentPosition = new Point(i * symbolWidth, staffLineCoords[8 - keyIndexes[i]]); cl.AddCharacterGlyph(currentPosition, keySymbol); } itemWidth = keySignatureWidth; } ItemCanvas.Children.Add(cl); }
public MeasureClef(ClefSignMusicXML clefSign, int lineOfStaff, int octaveChange, AbstractStaff staff) { _visualsHost = new DrawingVisualHost(); _lineOfStaff = lineOfStaff; _clefSign = clefSign; MusicSymbols.TryGetClefSymbol(clefSign, octaveChange, out _symbol); this.staff = staff; }
internal void AddStem(DrawingVisualHost dvh) { var stem = ItemCanvas.Children.OfType <DrawingVisualHost>().FirstOrDefault(x => (string)x.Tag == "stem"); if (stem == null) { ItemCanvas.Children.Add(dvh); } }
//todo if width changed update visual private void Draw() { GetVisualControl().Children.Clear(); var symbolWidth = DrawingHelpers.DrawingMethods.GetTextWidth(restSymbol, TypeFaces.GetMusicFont()); var visualHost = new DrawingVisualHost(); visualHost.AddCharacterGlyph(new Point(Width / 2 - (symbolWidth / 2), Staff[4, 1]), restSymbol); GetVisualControl().Children.Add(visualHost); }
public void Draw(Dictionary <int, double> positionsTable) { Dictionary <int, Point> stemPositions = new Dictionary <int, Point>(); CalculateSlopes(positionsTable); CorrectStems(); foreach (var item in beamedStems) { int direction = item.Value.Stem.IsDirectionDown() ? -1 : 1; double offset = 2.5.TenthsToWPFUnit() * direction; Dictionary <string, Point> beamPositions = new Dictionary <string, Point>(); Point position = new Point(positionsTable[item.Key] + beamedStems[item.Key].Stem.GetStemEndCalculated().X, beamedStems[item.Key].Stem.GetStemEndCalculated().Y); double tempYOffset = offset; for (int i = 1; i <= item.Value.Beams.Count; i++) { beamPositions.Add(i.ToString(), new Point(position.X, position.Y + tempYOffset)); tempYOffset += 7.5.TenthsToWPFUnit() * direction; } stemPositions.Add(item.Key, new Point(positionsTable[item.Key] + beamedStems[item.Key].Stem.GetStemEndCalculated().X, beamedStems[item.Key].Stem.GetStemEndCalculated().Y + offset)); } DrawingVisual beamsDrawingVisual = new DrawingVisual(); var fractionKeys = stemPositions.Keys.ToArray(); int dir = beamedStems.FirstOrDefault().Value.Stem.IsDirectionDown() ? -1 : 1; using (DrawingContext dc = beamsDrawingVisual.RenderOpen()) { for (int i = 1; i < stemPositions.Count; i++) { //! skip counting beam hooks int beamsCount = beamedStems[fractionKeys[i - 1]].Beams.Count( x => x.Value != Model.Helpers.SimpleTypes.BeamValueMusicXML.forwardhook || x.Value != Model.Helpers.SimpleTypes.BeamValueMusicXML.backwardhook); for (int j = 0; j < beamsCount; j++) { if (beamedStems[fractionKeys[i]].Beams.ContainsKey(j + 1))//? necessary to skip beam drawing if current beam is end { dc.DrawLine(new Pen(beamedStems.FirstOrDefault().Value.Stem.GetColor(), 5.0.TenthsToWPFUnit()), new Point(stemPositions[fractionKeys[i - 1]].X, stemPositions[fractionKeys[i - 1]].Y + j * (7.5.TenthsToWPFUnit() * dir)), new Point(stemPositions[fractionKeys[i]].X, stemPositions[fractionKeys[i]].Y + j * (7.5.TenthsToWPFUnit() * dir))); } if (beamedStems[fractionKeys[i]].Beams.ContainsValue(Model.Helpers.SimpleTypes.BeamValueMusicXML.backwardhook) && j + 1 == beamsCount) { DrawBeamHooks(dc, i, j, stemPositions, Model.Helpers.SimpleTypes.BeamValueMusicXML.backwardhook); } if (beamedStems[fractionKeys[i - 1]].Beams.ContainsValue(Model.Helpers.SimpleTypes.BeamValueMusicXML.forwardhook) && j + 1 == beamsCount) { //? j-1 temp, need tests (without decrementing hook is drawn with one beamSpacing lower DrawBeamHooks(dc, i, j - 1, stemPositions, Model.Helpers.SimpleTypes.BeamValueMusicXML.forwardhook); } } } } DrawingVisualHost drawingVisualHost = new DrawingVisualHost(); drawingVisualHost.AddVisual(beamsDrawingVisual); beamVisuals.Add(drawingVisualHost); }
private void AddFlag(DrawingVisualHost flagHost) { var flag = ItemCanvas.Children.OfType <DrawingVisualHost>().FirstOrDefault(x => (string)x.Tag == "flag"); if (flag != null) { ItemCanvas.Children.Remove(flag); } ItemCanvas.Children.Add(flagHost); }
private void GetMeasureProperties() { visualObject = new DrawingVisualHost(); measureSerializable = ViewModelLocator.Instance.Main.CurrentSelectedScore.Part[partId.GetPartIdIndex()].Measure.FirstOrDefault(x => x.Number == id); measureSerializable.PropertyChanged += OnWidthChanged; measureHeight = layout.PageProperties.StaffHeight.MMToWPFUnit() * stavesCount + (stavesDistance.TenthsToWPFUnit() * (stavesCount - 1)); measureWidth = measureSerializable.CalculatedWidth.TenthsToWPFUnit(); size = new Size(measureWidth, measureHeight); }
protected override void Update() { if (isSymbol) { itemWidth = DrawingMethods.GetTextWidth(symbol, TypeFaces.GetMusicFont()); DrawingVisualHost canvas = new DrawingVisualHost(); canvas.AddCharacterGlyph(new Point(0, staffLine[3]), symbol); ItemCanvas.Children.Add(canvas); } if (!isSymbol || symbolValue == TimeSymbolMusicXML.normal) { char[] beatChars = beatSymbol.ToCharArray(); double[] beatCharWidths = beatSymbol.ToCharArray().GetCharsVisualWidth(); double beatWidth = beatCharWidths.Sum(); DrawingVisualHost canvasBeat = new DrawingVisualHost(); double offset = 0; for (int i = 0; i < beatChars.Length; i++) { canvasBeat.AddCharacterGlyph(new Point(offset, 0), beatChars[i].ToString()); offset += beatCharWidths[i]; } //beatTime char[] beatTimeChars = beatTimeSymbol.ToCharArray(); double[] beatTimeCharWidths = beatTimeSymbol.ToCharArray().GetCharsVisualWidth(); double beatTimeWidth = beatTimeCharWidths.Sum(); DrawingVisualHost canvasBeatTime = new DrawingVisualHost(); offset = 0.0; for (int i = 0; i < beatTimeChars.Length; i++) { canvasBeatTime.AddCharacterGlyph(new Point(offset, 0), beatTimeChars[i].ToString()); offset += beatTimeCharWidths[i]; } //measure legth + align itemWidth = beatWidth > beatTimeWidth ? beatWidth : beatTimeWidth; ItemCanvas.Width = itemWidth; if (beatWidth > beatTimeWidth) { Canvas.SetLeft(canvasBeat, 0); double shift = (beatWidth - beatTimeWidth) / 2; Canvas.SetLeft(canvasBeatTime, shift); } else { Canvas.SetLeft(canvasBeatTime, 0); double shift = (beatTimeWidth - beatWidth) / 2; Canvas.SetLeft(canvasBeat, shift); } Canvas.SetTop(canvasBeat, staffLine[4]); Canvas.SetTop(canvasBeatTime, staffLine[2]); ItemCanvas.Children.Add(canvasBeat); ItemCanvas.Children.Add(canvasBeatTime); } }
private void DrawAccidental(NoteMusicXML note, int index, DrawingVisualHost noteVisualHost) { AccidentalMusicXML accidental = note.Accidental; string accidentalSymbol = GetAccidentalSymbolString(accidental.Value); double size = 1.0; double totalAccidentalSize = 0.0; bool hasBracket = accidental.BracketSpecified ? accidental.Bracket == YesNoMusicXML.yes: false; bool hasParentheses = accidental.ParenthesesSpecified ? accidental.Parentheses == YesNoMusicXML.yes: false; if (isSmall) { size = 0.7; } if (accidental.SizeSpecified) { size = accidental.Size == SymbolSizeMusicXML.cue ? 0.7 : accidental.Size == SymbolSizeMusicXML.large ? 1.2 : 1.0; } if (accidental.CautionarySpecified) { hasParentheses = accidental.Cautionary == YesNoMusicXML.yes; //! missing implementation if yes } //! accidental.Editiorial skipped... double accidentalWidth = DrawingMethods.GetTextWidth(accidentalSymbol, TypeFaces.GetMusicFont(), isSmall); double accidentalMargin = layoutStyle.NotesStyle.AccidentalToNoteSpace.TenthsToWPFUnit(); double noteHeadYPosition = pitchedValue[index]; if (hasBracket) { totalAccidentalSize += 2 * DrawingMethods.GetTextWidth(MusicSymbols.AccidentalBracketL, TypeFaces.GetMusicFont(), size); } if (hasParentheses) { totalAccidentalSize += 2 * DrawingMethods.GetTextWidth(MusicSymbols.AccidentalParenthesesL, TypeFaces.GetMusicFont(), size); } if (hasBracket || hasParentheses) { string left = hasBracket ? MusicSymbols.AccidentalBracketL : MusicSymbols.AccidentalParenthesesL; noteVisualHost.AddCharacterGlyph(new Point(0 - (totalAccidentalSize + accidentalWidth + accidentalMargin), noteHeadYPosition), left, isSmall, color); string rigth = hasBracket ? MusicSymbols.AccidentalBracketR : MusicSymbols.AccidentalParenthesesR; noteVisualHost.AddCharacterGlyph(new Point(0 - (totalAccidentalSize / 2 + accidentalWidth + accidentalMargin), noteHeadYPosition), accidentalSymbol, isSmall, color); noteVisualHost.AddCharacterGlyph(new Point(0 - (totalAccidentalSize / 2) - accidentalMargin, noteHeadYPosition), rigth, isSmall, color); SetLeftMargin(totalAccidentalSize + accidentalWidth + accidentalMargin); } else { noteVisualHost.AddCharacterGlyph(new Point(0 - accidentalWidth - accidentalMargin, noteHeadYPosition), accidentalSymbol, isSmall, color); SetLeftMargin(accidentalWidth + accidentalMargin); } }
public static void AddLedgerLine(this DrawingVisualHost canvas, Point position, double noteHeadWidth) { DrawingVisual ledgerLine = new DrawingVisual(); Pen pen = new Pen(Brushes.Black, (0.9).TenthsToWPFUnit()); double offset = noteHeadWidth / 4; Point p1 = new Point(position.X - offset, position.Y); Point p2 = new Point(position.X + noteHeadWidth + offset, position.Y); using (DrawingContext dc = ledgerLine.RenderOpen()) { dc.DrawLine(pen, p1, p2); } canvas.AddVisual(ledgerLine); }
public CanvasRoadManager(DrawingVisualHost drawing, float width, float height) { this.width = width; this.height = height; this.Drawing = drawing; var parent = VisualTreeHelper.GetParent(drawing) as FrameworkElement; parent.MouseMove += Drawing_MouseMove; var adornerLayer = AdornerLayer.GetAdornerLayer(drawing); adornerLayer.Add(pointerAdorner = new PointerAdorner(this, drawing)); pointerAdorner.PreviewMouseUp += PointerAdorner_PreviewMouseUp; }
private void DrawFlag() { bool isFlagDownwards = stem.IsDirectionDown(); string flagSymbol = MusicSymbols.GetFlag(noteType, isFlagDownwards); Point stemEnd = stem.GetStemEnd(); DrawingVisualHost flagHost = new DrawingVisualHost(); flagHost.AddCharacterGlyph(stemEnd, flagSymbol, isSmall, color); flagHost.Tag = "flag"; if (!isFlagDownwards) { itemRightMargin = DrawingMethods.GetTextWidth(flagSymbol, TypeFaces.GetMusicFont()); } AddFlag(flagHost); }
/// <summary> /// Visual red barline drawn at the beginning of measure /// </summary> /// <param name="staffHeight">Staff Line height (WPFUnits)</param> private void DrawTempStartBarline(double staffHeight) { temporaryStartBarline = new Canvas(); Point p1 = new Point(); Point p2 = new Point(0, staffHeight); Pen pen = new Pen(Brushes.Red, 1.5.TenthsToWPFUnit()); DrawingVisual dv = new DrawingVisual(); using (DrawingContext dc = dv.RenderOpen()) { dc.DrawLine(pen, p1, p2); } DrawingVisualHost dvh = new DrawingVisualHost(); dvh.AddVisual(dv); temporaryStartBarline.Children.Add(dvh); Children.Add(temporaryStartBarline); }
private void DrawDots(DrawingVisualHost noteVisualHost, int index) { double dotPositionY = pitchedValue[index]; if (pitchedPosition[index] % 2 == 0) { double sizeFactor = isSmall ? 0.8 : 1.0; double shiftUp = 5.0.TenthsToWPFUnit() * sizeFactor; dotPositionY -= shiftUp; } int dotCount = noteItem[index].Dot.Count; double noteWidth = DrawingMethods.GetTextWidth(symbol, TypeFaces.GetMusicFont(), isSmall); double dotWidth = DrawingMethods.GetTextWidth(MusicSymbols.Dot, TypeFaces.GetMusicFont(), isSmall); Point dotPosition = new Point(noteWidth + layoutStyle.NotesStyle.DotStandardOffset.TenthsToWPFUnit(), dotPositionY); for (int i = 0; i < dotCount; i++) { noteVisualHost.AddCharacterGlyph(dotPosition, MusicSymbols.Dot, isSmall, color); dotPosition.X += layoutStyle.NotesStyle.DotStandardOffset.TenthsToWPFUnit() + dotWidth; } }
protected override void Update() { GetSymbol(); GetLine(); if (IsVisible) { double tempLine = _staffLine; string tempSymbol = _symbol; if (_isEmpty) // used for proper layout spacing, invisible but taking space; //TODO_LATER more test/refactor { _itemWidth = DrawingMethods.GetTextWidth(MusicSymbols.GClef, TypeFaces.GetMusicFont(), _isAdditional); tempSymbol = ""; tempLine = 0.0; } else { _itemWidth = DrawingMethods.GetTextWidth(_symbol, TypeFaces.GetMusicFont(), _isAdditional); } DrawingVisualHost clefVisualsHost = new DrawingVisualHost(); clefVisualsHost.AddCharacterGlyph(new Point(0, tempLine), tempSymbol, _isAdditional, Color); ItemCanvas.Children.Clear(); ItemCanvas.Children.Add(clefVisualsHost); } }
private void InitCanvas() { _visual = new DrawingVisualHost(); CanvasVisual = new Canvas(); CanvasVisual.Children.Add(_visual); }
private void Draw() { isSmall = noteVisualType == NoteChoiceTypeMusicXML.cue || noteVisualType == NoteChoiceTypeMusicXML.grace; DrawingVisualHost noteVisualHost = new DrawingVisualHost(); int index = 0; for (int i = 0; i < noteItem.Count; i++) { double noteHeadOffset = 0; if (i > 0) { int maxPitch = pitchedPosition.Values.Max(); int stemDir = maxPitch < 5 ? -1 : 1; if (Math.Abs(pitchedPosition[index - 1] - pitchedPosition[index]) == 1) { noteHeadOffset = DrawingHelpers.DrawingMethods.GetTextWidth(symbol, TypeFaces.GetMusicFont()) * stemDir; } } if (noteItem[i].Voice == null) { Log.LoggIt.Log($"Missing note voice element, setting to default", Log.LogType.Warning); noteItem[i].Voice = "1"; //! voice set to "1" if null- bugfix } color = ViewModel.ViewModelLocator.Instance.Main.CurrentLayout.LayoutStyle.Colors[int.Parse(noteItem[i].Voice)]; noteVisualHost.AddCharacterGlyph(new Point(noteHeadOffset, pitchedValue[index]), symbol, isSmall, color); if (noteItem[i].Accidental != null) { DrawAccidental(noteItem[i], noteItem.IndexOf(noteItem[i]), noteVisualHost); } if (hasDots) { DrawDots(noteVisualHost, index); } index++; } /*foreach (var note in noteItem) * { * if (note.Voice == null) * { * Log.LoggIt.Log($"Missing note voice element, setting to default", Log.LogType.Warning); * note.Voice = "1"; //! voice set to "1" if null- bugfix * } * color = ViewModel.ViewModelLocator.Instance.Main.CurrentLayout.LayoutStyle.Colors[int.Parse(note.Voice)]; * noteVisualHost.AddCharacterGlyph(new Point(0, pitchedValue[index]), symbol, isSmall, color); * if (note.Accidental != null) * { * DrawAccidental(note, noteItem.IndexOf(note), noteVisualHost); * } * if (hasDots) * { * DrawDots(noteVisualHost, index); * } * index++; * } */ itemWidthMin = DrawingMethods.GetTextWidth(symbol, TypeFaces.GetMusicFont(), isSmall); itemWidth = itemWidthMin; CheckForLedgerLines(); if (needLedgerLines) { Point position = new Point(); int indexLedgers = 0; foreach (var ledgerPosition in ledgerLinesPositions) { noteVisualHost.AddLedgerLine(new Point(position.X, ledgerLinesPositions[indexLedgers]), itemWidthMin); indexLedgers++; } } ItemCanvas.Children.Add(noteVisualHost); }