private void AlignGlyph(EffectBarGlyphSizing sizing, Beat beat) { EffectGlyph g = _effectGlyphs[beat.Voice.Index][beat.Index]; Glyph pos; var container = Renderer.GetBeatContainer(beat); switch (sizing) { case EffectBarGlyphSizing.SinglePreBeat: pos = container.PreNotes; g.X = Renderer.BeatGlyphsStart + pos.X + container.X; g.Width = pos.Width; break; case EffectBarGlyphSizing.SingleOnBeat: case EffectBarGlyphSizing.GroupedOnBeat: // grouping is achieved by linking the normaly aligned glyphs pos = container.OnNotes; g.X = Renderer.BeatGlyphsStart + pos.X + container.X; g.Width = pos.Width; break; case EffectBarGlyphSizing.FullBar: g.Width = Renderer.Width; break; } }
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) { EffectGlyph g; switch (sizing) { case EffectBarGlyphSizing.FullBar: g = Info.CreateNewGlyph(Renderer, b); g.Renderer = Renderer; g.Beat = b; g.DoLayout(); _effectGlyphs[b.Voice.Index][b.Index] = g; _uniqueEffectGlyphs[b.Voice.Index].Add(g); return(g); case EffectBarGlyphSizing.SinglePreBeat: case EffectBarGlyphSizing.SingleOnBeat: g = Info.CreateNewGlyph(Renderer, b); g.Renderer = Renderer; 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 || Renderer.Index > 0) { // check if the previous beat also had this effect Beat prevBeat = b.PreviousBeat; if (Info.ShouldCreateGlyph(prevBeat)) { // first load the effect bar renderer and glyph 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 (Renderer.Index > 0) { // load the effect from the previous renderer if possible. var previousRenderer = (EffectBarRenderer)Renderer.PreviousRenderer; var previousBand = previousRenderer.BandLookup[Info.EffectId]; var voiceGlyphs = previousBand._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(prevBeat, b)) { // link glyphs prevEffect.NextGlyph = newGlyph; newGlyph.PreviousGlyph = prevEffect; // mark renderers as linked for consideration when layouting the renderers (line breaking, partial breaking) 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; } }
private void AlignGlyph(EffectBarGlyphSizing sizing, int beatIndex, int voiceIndex, EffectGlyph prevGlyph) { EffectGlyph g = _effectGlyphs[voiceIndex][beatIndex]; Glyph pos; var container = GetBeatContainer(voiceIndex, beatIndex); switch (sizing) { case EffectBarGlyphSizing.SinglePreBeatOnly: pos = container.PreNotes; g.X = pos.X + container.X; g.Width = pos.Width; break; case EffectBarGlyphSizing.SinglePreBeatToOnBeat: pos = container.PreNotes; g.X = pos.X + container.X; pos = container.OnNotes; g.Width = (pos.X + container.X + pos.Width) - g.X; break; case EffectBarGlyphSizing.SinglePreBeatToPostBeat: pos = container.PreNotes; g.X = pos.X + container.X; pos = container.PostNotes; g.Width = (pos.X + container.X + pos.Width) - g.X; break; case EffectBarGlyphSizing.SingleOnBeatOnly: pos = container.OnNotes; g.X = pos.X + container.X; g.Width = pos.Width; break; case EffectBarGlyphSizing.SingleOnBeatToPostBeat: pos = container.OnNotes; g.X = pos.X + container.X; pos = container.PostNotes; g.Width = (pos.X + container.X + pos.Width) - g.X; break; case EffectBarGlyphSizing.SinglePostBeatOnly: pos = container.PostNotes; g.X = pos.X + container.X; g.Width = pos.Width; break; case EffectBarGlyphSizing.GroupedPreBeatOnly: if (g != prevGlyph) { AlignGlyph(EffectBarGlyphSizing.SinglePreBeatOnly, beatIndex, voiceIndex, prevGlyph); } else { pos = container.PreNotes; var posR = (EffectBarRenderer)pos.Renderer; var gR = (EffectBarRenderer)g.Renderer; g.Width = (posR.X + posR.BeatGlyphsStart + container.X + pos.X + pos.Width) - (gR.X + gR.BeatGlyphsStart + g.X); g.ExpandTo(container.Beat); } break; case EffectBarGlyphSizing.GroupedPreBeatToOnBeat: if (g != prevGlyph) { AlignGlyph(EffectBarGlyphSizing.SinglePreBeatToOnBeat, beatIndex, voiceIndex, prevGlyph); } else { pos = container.OnNotes; var posR = (EffectBarRenderer)pos.Renderer; var gR = (EffectBarRenderer)g.Renderer; g.Width = (posR.X + posR.BeatGlyphsStart + container.X + pos.X + pos.Width) - (gR.X + gR.BeatGlyphsStart + g.X); g.ExpandTo(container.Beat); } break; case EffectBarGlyphSizing.GroupedPreBeatToPostBeat: if (g != prevGlyph) { AlignGlyph(EffectBarGlyphSizing.SinglePreBeatToPostBeat, beatIndex, voiceIndex, prevGlyph); } else { pos = container.PostNotes; var posR = (EffectBarRenderer)pos.Renderer; var gR = (EffectBarRenderer)g.Renderer; g.Width = (posR.X + posR.BeatGlyphsStart + container.X + pos.X + pos.Width) - (gR.X + gR.BeatGlyphsStart + g.X); g.ExpandTo(container.Beat); } break; case EffectBarGlyphSizing.GroupedOnBeatOnly: if (g != prevGlyph) { AlignGlyph(EffectBarGlyphSizing.SingleOnBeatOnly, beatIndex, voiceIndex, prevGlyph); } else { pos = container.OnNotes; var posR = (EffectBarRenderer)pos.Renderer; var gR = (EffectBarRenderer)g.Renderer; g.Width = (posR.X + posR.BeatGlyphsStart + container.X + pos.X + pos.Width) - (gR.X + gR.BeatGlyphsStart + g.X); g.ExpandTo(container.Beat); } break; case EffectBarGlyphSizing.GroupedOnBeatToPostBeat: if (g != prevGlyph) { AlignGlyph(EffectBarGlyphSizing.SingleOnBeatToPostBeat, beatIndex, voiceIndex, prevGlyph); } else { pos = container.PostNotes; var posR = (EffectBarRenderer)pos.Renderer; var gR = (EffectBarRenderer)g.Renderer; g.Width = (posR.X + posR.BeatGlyphsStart + container.X + pos.X + pos.Width) - (gR.X + gR.BeatGlyphsStart + g.X); g.ExpandTo(container.Beat); } break; case EffectBarGlyphSizing.GroupedPostBeatOnly: if (g != prevGlyph) { AlignGlyph(EffectBarGlyphSizing.GroupedPostBeatOnly, beatIndex, voiceIndex, prevGlyph); } else { pos = container.PostNotes; var posR = (EffectBarRenderer)pos.Renderer; var gR = (EffectBarRenderer)g.Renderer; g.Width = (posR.X + posR.BeatGlyphsStart + container.X + pos.X + pos.Width) - (gR.X + gR.BeatGlyphsStart + g.X); g.ExpandTo(container.Beat); } break; } }