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 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); } }
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); }