private float PaintGroup(StaveGroup group, float totalHeight, ICanvas canvas) { // paint into canvas var height = group.Height + (GroupSpacing * Scale); canvas.BeginRender(Width, height); Renderer.Canvas.Color = Renderer.RenderingResources.MainGlyphColor; Renderer.Canvas.TextAlign = TextAlign.Left; // NOTE: we use this negation trick to make the group paint itself to 0/0 coordinates // since we use partial drawing group.Paint(0, -group.Y, canvas); // calculate coordinates for next group totalHeight += height; var result = canvas.EndRender(); var args = new RenderFinishedEventArgs(); args.TotalWidth = Width; args.TotalHeight = totalHeight; args.Width = Width; args.Height = height; args.RenderResult = result; args.FirstMasterBarIndex = group.FirstBarIndex; args.LastMasterBarIndex = group.LastBarIndex; Renderer.OnPartialRenderFinished(args); return(height); }
protected StaveGroup CreateEmptyStaveGroup() { var group = new StaveGroup(); group.Layout = this; var profile = Environment.StaveProfiles.ContainsKey(Renderer.Settings.Staves.Id) ? Environment.StaveProfiles[Renderer.Settings.Staves.Id] : Environment.StaveProfiles["default"]; var isFirstTrack = true; for (var trackIndex = 0; trackIndex < Renderer.Tracks.Length; trackIndex++) { var track = Renderer.Tracks[trackIndex]; for (int staveIndex = 0; staveIndex < track.Staves.Count; staveIndex++) { for (var renderStaveIndex = 0; renderStaveIndex < profile.Length; renderStaveIndex++) { var factory = profile[renderStaveIndex]; var staff = track.Staves[staveIndex]; if (factory.CanCreate(track, staff)) { group.AddStaff(track, new Staff(trackIndex, staff, factory, Renderer.Settings.Staves.AdditionalSettings)); } } } isFirstTrack = false; } return(group); }
protected StaveGroup CreateEmptyStaveGroup() { var group = new StaveGroup(); group.Layout = this; var isFirstTrack = true; for (var i = 0; i < Renderer.Tracks.Length; i++) { var track = Renderer.Tracks[i]; for (var j = 0; j < Renderer.Settings.Staves.Count; j++) { var s = Renderer.Settings.Staves[j]; if (Environment.StaveFactories.ContainsKey(s.Id)) { var factory = Environment.StaveFactories[s.Id](this); if (factory.CanCreate(track) && (isFirstTrack || !factory.HideOnMultiTrack)) { group.AddStave(track, new Stave(s.Id, factory, s.AdditionalSettings)); } } } isFirstTrack = false; } return(group); }
protected StaveGroup CreateEmptyStaveGroup() { var group = new StaveGroup(); group.Layout = this; var isFirstTrack = true; for (var trackIndex = 0; trackIndex < Renderer.Tracks.Length; trackIndex++) { var track = Renderer.Tracks[trackIndex]; for (int staveIndex = 0; staveIndex < track.Staves.Count; staveIndex++) { for (var renderStaveIndex = 0; renderStaveIndex < Renderer.Settings.Staves.Count; renderStaveIndex++) { var s = Renderer.Settings.Staves[renderStaveIndex]; if (Environment.StaveFactories.ContainsKey(s.Id)) { var factory = Environment.StaveFactories[s.Id](this); if (factory.CanCreate(track) && (isFirstTrack || !factory.HideOnMultiTrack) && (staveIndex == 0 || !factory.HideOnMultiTrack)) { group.AddStave(track, new Staff(track.Staves[staveIndex], s.Id, factory, s.AdditionalSettings)); } } } } isFirstTrack = false; } return(group); }
public override void DoLayoutAndRender() { if (Renderer.Settings.Staves.Count == 0) { return; } var score = Renderer.Score; var canvas = Renderer.Canvas; var startIndex = Renderer.Settings.Layout.Get("start", 1); startIndex--; // map to array index startIndex = Math.Min(score.MasterBars.Count - 1, Math.Max(0, startIndex)); var currentBarIndex = startIndex; var endBarIndex = Renderer.Settings.Layout.Get("count", score.MasterBars.Count); endBarIndex = startIndex + endBarIndex - 1; // map count to array index endBarIndex = Math.Min(score.MasterBars.Count - 1, Math.Max(0, endBarIndex)); var x = PagePadding[0]; var y = PagePadding[1]; _group = CreateEmptyStaveGroup(); while (currentBarIndex <= endBarIndex) { _group.AddBars(Renderer.Tracks, currentBarIndex); currentBarIndex++; } _group.X = x; _group.Y = y; _group.FinalizeGroup(this); y += _group.Height + (GroupSpacing * Scale); Height = y + PagePadding[3]; Width = _group.X + _group.Width + PagePadding[2]; // TODO: Find a good way to render the score partwise // we need to precalculate the final height somehow canvas.BeginRender(Width, Height); canvas.Color = Renderer.RenderingResources.MainGlyphColor; canvas.TextAlign = TextAlign.Left; _group.Paint(0, 0, Renderer.Canvas); var result = canvas.EndRender(); OnPartialRenderFinished(new RenderFinishedEventArgs { TotalWidth = Width, TotalHeight = y, Width = Width, Height = Height, RenderResult = result }); }
/// <summary> /// Realignes the bars in this line according to the available space /// </summary> private void FitGroup(StaveGroup group) { if (group.IsFull || group.Width > MaxWidth) { group.ScaleToWidth(MaxWidth); } Width = Math.Max(Width, group.Width); }
/// <summary> /// Realignes the bars in this line according to the available space /// </summary> private void FitGroup(StaveGroup group) { // calculate additional space for each bar (can be negative!) float barSpace = 0f; float freeSpace = MaxWidth - group.Width; if (freeSpace != 0 && group.MasterBars.Count > 0) { barSpace = freeSpace / group.MasterBars.Count; } if (group.IsFull || barSpace < 0) { // add it to the measures group.ApplyBarSpacing(barSpace); } Width = Math.Max(Width, group.Width); }
protected StaveGroup CreateEmptyStaveGroup() { var group = new StaveGroup(); group.Layout = this; for (var trackIndex = 0; trackIndex < Renderer.Tracks.Length; trackIndex++) { var track = Renderer.Tracks[trackIndex]; string staveProfile; // use optimal profile for track if (track.IsPercussion) { staveProfile = Environment.StaveProfileScore; } else if (track.IsStringed) { staveProfile = Renderer.Settings.Staves.Id; } else { staveProfile = Environment.StaveProfileScore; } var profile = Environment.StaveProfiles.ContainsKey(staveProfile) ? Environment.StaveProfiles[staveProfile] : Environment.StaveProfiles["default"]; for (int staveIndex = 0; staveIndex < track.Staves.Count; staveIndex++) { for (var renderStaveIndex = 0; renderStaveIndex < profile.Length; renderStaveIndex++) { var factory = profile[renderStaveIndex]; var staff = track.Staves[staveIndex]; if (factory.CanCreate(track, staff)) { group.AddStaff(track, new Staff(trackIndex, staff, factory)); } } } } return(group); }
protected override void DoLayoutAndRender() { _pagePadding = Renderer.Settings.Layout.Get("padding", PagePadding); if (_pagePadding.Length == 1) { _pagePadding = new[] { _pagePadding[0], _pagePadding[0], _pagePadding[0], _pagePadding[0] }; } else if (_pagePadding.Length == 2) { _pagePadding = new[] { _pagePadding[0], _pagePadding[1], _pagePadding[0], _pagePadding[1] }; } var score = Renderer.Score; var canvas = Renderer.Canvas; var startIndex = Renderer.Settings.Layout.Get("start", 1); startIndex--; // map to array index startIndex = Math.Min(score.MasterBars.Count - 1, Math.Max(0, startIndex)); var currentBarIndex = startIndex; var endBarIndex = Renderer.Settings.Layout.Get("count", score.MasterBars.Count); if (endBarIndex < 0) { endBarIndex = score.MasterBars.Count; } endBarIndex = startIndex + endBarIndex - 1; // map count to array index endBarIndex = Math.Min(score.MasterBars.Count - 1, Math.Max(0, endBarIndex)); _group = CreateEmptyStaveGroup(); _group.IsLast = true; _group.X = _pagePadding[0]; _group.Y = _pagePadding[1]; var countPerPartial = Renderer.Settings.Layout.Get("countPerPartial", 10); var partials = new FastList <HorizontalScreenLayoutPartialInfo>(); var currentPartial = new HorizontalScreenLayoutPartialInfo(); while (currentBarIndex <= endBarIndex) { var result = _group.AddBars(Renderer.Tracks, currentBarIndex); // if we detect that the new renderer is linked to the previous // renderer, we need to put it into the previous partial if (currentPartial.MasterBars.Count == 0 && result.IsLinkedToPrevious && partials.Count > 0) { var previousPartial = partials[partials.Count - 1]; previousPartial.MasterBars.Add(score.MasterBars[currentBarIndex]); previousPartial.Width += result.Width; } else { currentPartial.MasterBars.Add(score.MasterBars[currentBarIndex]); currentPartial.Width += result.Width; // no targetPartial here because previous partials already handled this code if (currentPartial.MasterBars.Count >= countPerPartial) { if (partials.Count == 0) { currentPartial.Width += _group.X + _group.AccoladeSpacing; } partials.Add(currentPartial); Logger.Info(Name, "Finished partial from bar " + currentPartial.MasterBars[0].Index + " to " + currentPartial.MasterBars[currentPartial.MasterBars.Count - 1].Index); currentPartial = new HorizontalScreenLayoutPartialInfo(); } } currentBarIndex++; } // don't miss the last partial if not empty if (currentPartial.MasterBars.Count > 0) { if (partials.Count == 0) { currentPartial.Width += _group.X + _group.AccoladeSpacing; } partials.Add(currentPartial); Logger.Info(Name, "Finished partial from bar " + currentPartial.MasterBars[0].Index + " to " + currentPartial.MasterBars[currentPartial.MasterBars.Count - 1].Index); } _group.FinalizeGroup(); Height = _group.Y + _group.Height + _pagePadding[3]; Width = _group.X + _group.Width + _pagePadding[2]; currentBarIndex = 0; for (var i = 0; i < partials.Count; i++) { var partial = partials[i]; canvas.BeginRender(partial.Width, Height); canvas.Color = Renderer.RenderingResources.MainGlyphColor; canvas.TextAlign = TextAlign.Left; var renderX = _group.GetBarX(partial.MasterBars[0].Index) + _group.AccoladeSpacing; if (i == 0) { renderX -= _group.X + _group.AccoladeSpacing; } Logger.Info(Name, "Rendering partial from bar " + partial.MasterBars[0].Index + " to " + partial.MasterBars[partial.MasterBars.Count - 1].Index); _group.PaintPartial(-renderX, _group.Y, Renderer.Canvas, currentBarIndex, partial.MasterBars.Count); var result = canvas.EndRender(); Renderer.OnPartialRenderFinished(new RenderFinishedEventArgs { TotalWidth = Width, TotalHeight = Height, Width = partial.Width, Height = Height, RenderResult = result, FirstMasterBarIndex = partial.MasterBars[0].Index, LastMasterBarIndex = partial.MasterBars[partial.MasterBars.Count - 1].Index }); currentBarIndex += partial.MasterBars.Count; } }
protected override void DoLayoutAndRender() { if (Renderer.Settings.Staves.Count == 0) { return; } var score = Renderer.Score; var canvas = Renderer.Canvas; var startIndex = Renderer.Settings.Layout.Get("start", 1); startIndex--; // map to array index startIndex = Math.Min(score.MasterBars.Count - 1, Math.Max(0, startIndex)); var currentBarIndex = startIndex; var endBarIndex = Renderer.Settings.Layout.Get("count", score.MasterBars.Count); if (endBarIndex < 0) { endBarIndex = score.MasterBars.Count; } endBarIndex = startIndex + endBarIndex - 1; // map count to array index endBarIndex = Math.Min(score.MasterBars.Count - 1, Math.Max(0, endBarIndex)); _group = CreateEmptyStaveGroup(); _group.X = PagePadding[0]; _group.Y = PagePadding[1]; var countPerPartial = Renderer.Settings.Layout.Get("countPerPartial", 10); var partials = new FastList <HorizontalScreenLayoutPartialInfo>(); var currentPartial = new HorizontalScreenLayoutPartialInfo(); if (Renderer.Settings.Staves.Count > 0) { while (currentBarIndex <= endBarIndex) { var result = _group.AddBars(Renderer.Tracks, currentBarIndex); // if we detect that the new renderer is linked to the previous // renderer, we need to put it into the previous partial if (currentPartial.MasterBars.Count == 0 && result.IsLinkedToPrevious && partials.Count > 0) { var previousPartial = partials[partials.Count - 1]; previousPartial.MasterBars.Add(score.MasterBars[currentBarIndex]); previousPartial.Width += result.Width; } else { currentPartial.MasterBars.Add(score.MasterBars[currentBarIndex]); currentPartial.Width += result.Width; // no targetPartial here because previous partials already handled this code if (currentPartial.MasterBars.Count >= countPerPartial) { if (partials.Count == 0) { currentPartial.Width += _group.X + _group.AccoladeSpacing; } partials.Add(currentPartial); currentPartial = new HorizontalScreenLayoutPartialInfo(); } } currentBarIndex++; } // don't miss the last partial if not empty if (currentPartial.MasterBars.Count > 0) { if (partials.Count == 0) { currentPartial.Width += _group.X + _group.AccoladeSpacing; } partials.Add(currentPartial); } } _group.FinalizeGroup(this); Height = _group.Y + _group.Height + PagePadding[3]; Width = _group.X + _group.Width + PagePadding[2]; // TODO: Find a good way to render the score partwise // we need to precalculate the final height somehow //canvas.BeginRender(Width, Height); //canvas.Color = Renderer.RenderingResources.MainGlyphColor; //canvas.TextAlign = TextAlign.Left; //_group.Paint(0, 0, Renderer.Canvas); //var result = canvas.EndRender(); //OnPartialRenderFinished(new RenderFinishedEventArgs //{ // TotalWidth = Width, // TotalHeight = y, // Width = Width, // Height = Height, // RenderResult = result //}); currentBarIndex = 0; for (var i = 0; i < partials.Count; i++) { var partial = partials[i]; canvas.BeginRender(partial.Width, Height); canvas.Color = Renderer.RenderingResources.MainGlyphColor; canvas.TextAlign = TextAlign.Left; var renderX = _group.GetBarX(partial.MasterBars[0].Index) + _group.AccoladeSpacing; if (i == 0) { renderX -= _group.X + _group.AccoladeSpacing; } _group.PaintPartial(-renderX, _group.Y, Renderer.Canvas, currentBarIndex, partial.MasterBars.Count); var result = canvas.EndRender(); Renderer.OnPartialRenderFinished(new RenderFinishedEventArgs { TotalWidth = Width, TotalHeight = Height, Width = partial.Width, Height = Height, RenderResult = result }); currentBarIndex += partial.MasterBars.Count; } }
protected StaveGroup CreateEmptyStaveGroup() { var group = new StaveGroup(); group.Layout = this; for (var trackIndex = 0; trackIndex < Renderer.Tracks.Length; trackIndex++) { var track = Renderer.Tracks[trackIndex]; var hasScore = false; //var hasTab = false; foreach (var staff in track.Staves) { switch (staff.StaffKind) { case StaffKind.Tablature: //hasTab = true; break; case StaffKind.Score: hasScore = true; break; case StaffKind.Percussion: break; case StaffKind.Mixed: hasScore = true; //hasTab = true; break; } } for (int staffIndex = 0; staffIndex < track.Staves.Count; staffIndex++) { var staff = track.Staves[staffIndex]; // use optimal profile for track string staveProfile; if (staff.StaffKind == StaffKind.Percussion) { staveProfile = Environment.StaveProfileScore; } else if (staff.StaffKind == StaffKind.Tablature) { if (hasScore) { staveProfile = Environment.StaveProfileTabMixed; } else { staveProfile = Environment.StaveProfileTab; } } else if (staff.IsStringed) { staveProfile = Renderer.Settings.Staves.Id; } else // if(staff.StaffKind == StaffKind.Score) { staveProfile = Environment.StaveProfileScore; } var profile = Environment.StaveProfiles.ContainsKey(staveProfile) ? Environment.StaveProfiles[staveProfile] : Environment.StaveProfiles["default"]; foreach (var factory in profile) { if (factory.CanCreate(track, staff)) { group.AddStaff(track, new Staff(trackIndex, staff, factory)); } } } } return(group); }