public override void FinalizeRenderer(ScoreLayout layout) { base.FinalizeRenderer(layout); // after all layouting and sizing place and size the effect glyphs IsEmpty = true; #if MULTIVOICE_SUPPORT foreach (var v in Bar.Voices) { Glyph prevGlyph = null; if (Index > 0) { // check if previous renderer had an effect on his last beat // and use this as merging element EffectBarRenderer prevRenderer = (EffectBarRenderer)Stave.BarRenderers[Index - 1]; if (prevRenderer._lastBeat != null) { prevGlyph = prevRenderer._effectGlyphs[v.Index][prevRenderer._lastBeat.Index]; } } foreach (var beatIndex in _effectGlyphs[v.Index].Keys) { Glyph effect = _effectGlyphs[v.Index][beatIndex]; AlignGlyph(_info.SizingMode, beatIndex, 0, prevGlyph); prevGlyph = effect; IsEmpty = false; } } #else EffectGlyph prevGlyph = null; if (Index > 0) { // check if previous renderer had an effect on his last beat // and use this as merging element EffectBarRenderer prevRenderer = (EffectBarRenderer)Stave.BarRenderers[Index - 1]; if (prevRenderer._lastBeat != null && prevRenderer._effectGlyphs[0].ContainsKey(prevRenderer._lastBeat.Index)) { prevGlyph = prevRenderer._effectGlyphs[0][prevRenderer._lastBeat.Index]; } } foreach (var key in _effectGlyphs[0].Keys) { int beatIndex = Std.ParseInt(key); EffectGlyph effect = _effectGlyphs[0][beatIndex]; AlignGlyph(_info.SizingMode, beatIndex, 0, prevGlyph); prevGlyph = effect; IsEmpty = false; } #endif }
private EffectGlyph CreateOrResizeGlyph(EffectBarGlyphSizing sizing, Beat b) { switch (sizing) { case EffectBarGlyphSizing.SinglePreBeat: case EffectBarGlyphSizing.SingleOnBeat: var g = _info.CreateNewGlyph(this, b); g.Renderer = this; g.Beat = b; g.DoLayout(); _effectGlyphs[b.Voice.Index][b.Index] = g; _uniqueEffectGlyphs[b.Voice.Index].Add(g); return(g); case EffectBarGlyphSizing.GroupedOnBeat: if (b.Index > 0 || Index > 0) { // check if the previous beat also had this effect Beat prevBeat = b.PreviousBeat; if (_info.ShouldCreateGlyph(this, prevBeat)) { // first load the effect bar renderer and glyph EffectBarRenderer previousRenderer = null; EffectGlyph prevEffect = null; if (b.Index > 0 && _effectGlyphs[b.Voice.Index].ContainsKey(prevBeat.Index)) { // load effect from previous beat in the same renderer prevEffect = _effectGlyphs[b.Voice.Index][prevBeat.Index]; } else if (Index > 0) { // load the effect from the previous renderer if possible. previousRenderer = (EffectBarRenderer)Staff.BarRenderers[Index - 1]; var voiceGlyphs = previousRenderer._effectGlyphs[b.Voice.Index]; if (voiceGlyphs.ContainsKey(prevBeat.Index)) { prevEffect = voiceGlyphs[prevBeat.Index]; } } // if the effect cannot be expanded, create a new glyph // in case of expansion also create a new glyph, but also link the glyphs together // so for rendering it might be expanded. EffectGlyph newGlyph = CreateOrResizeGlyph(EffectBarGlyphSizing.SingleOnBeat, b); if (prevEffect != null && _info.CanExpand(this, prevBeat, b)) { // link glyphs prevEffect.NextGlyph = newGlyph; newGlyph.PreviousGlyph = prevEffect; // mark renderers as linked for consideration when layouting the renderers (line breaking, partial breaking) if (previousRenderer != null) { IsLinkedToPrevious = true; } } return(newGlyph); } // in case the previous beat did not have the same effect, we simply create a new glyph return(CreateOrResizeGlyph(EffectBarGlyphSizing.SingleOnBeat, b)); } // in case of the very first beat, we simply create the glyph. return(CreateOrResizeGlyph(EffectBarGlyphSizing.SingleOnBeat, b)); } return(null); }
private void CreateOrResizeGlyph(EffectBarGlyphSizing sizing, Beat b) { switch (sizing) { case EffectBarGlyphSizing.SinglePreBeatOnly: case EffectBarGlyphSizing.SinglePreBeatToOnBeat: case EffectBarGlyphSizing.SinglePreBeatToPostBeat: case EffectBarGlyphSizing.SingleOnBeatOnly: case EffectBarGlyphSizing.SingleOnBeatToPostBeat: case EffectBarGlyphSizing.SinglePostBeatOnly: var g = _info.CreateNewGlyph(this, b); g.Renderer = this; g.DoLayout(); _effectGlyphs[b.Voice.Index][b.Index] = g; _uniqueEffectGlyphs[b.Voice.Index].Add(g); break; case EffectBarGlyphSizing.GroupedPreBeatOnly: case EffectBarGlyphSizing.GroupedPreBeatToOnBeat: case EffectBarGlyphSizing.GroupedPreBeatToPostBeat: case EffectBarGlyphSizing.GroupedOnBeatOnly: case EffectBarGlyphSizing.GroupedOnBeatToPostBeat: case EffectBarGlyphSizing.GroupedPostBeatOnly: if (b.Index > 0 || Index > 0) { // check if the previous beat also had this effect Beat prevBeat = b.PreviousBeat; if (_info.ShouldCreateGlyph(this, prevBeat)) { EffectBarRenderer previousRenderer = null; // expand the previous effect EffectGlyph prevEffect = null; if (b.Index > 0 && _effectGlyphs[b.Voice.Index].ContainsKey(prevBeat.Index)) { prevEffect = _effectGlyphs[b.Voice.Index][prevBeat.Index]; } else if (Index > 0) { previousRenderer = ((EffectBarRenderer)(Stave.BarRenderers[Index - 1])); var voiceGlyphs = previousRenderer._effectGlyphs[b.Voice.Index]; if (voiceGlyphs.ContainsKey(prevBeat.Index)) { prevEffect = voiceGlyphs[prevBeat.Index]; } } if (prevEffect == null || !_info.CanExpand(this, prevBeat, b)) { CreateOrResizeGlyph(EffectBarGlyphSizing.SinglePreBeatOnly, b); } else { _effectGlyphs[b.Voice.Index][b.Index] = prevEffect; if (previousRenderer != null) { IsLinkedToPrevious = true; } } } else { CreateOrResizeGlyph(EffectBarGlyphSizing.SinglePreBeatOnly, b); } } else { CreateOrResizeGlyph(EffectBarGlyphSizing.SinglePreBeatOnly, b); } break; } }