public void Init(TablatureRenderingOptions options, GuitarTablatureModel tab, int crsrWidth, int crsrHeight) { Options = options; Tablature = tab; cursorWith = crsrWidth; cursorHeight = crsrHeight; }
public TabGenerationStatus BuildOutputContent(IInstrumentTablature tab, TablatureRenderingOptions options, out string outputContent) { outputContent = null; Tablature = (GuitarTablatureModel)tab; // TODO: remove casting => https://adrientorris.github.io/elegant-code/why-i-always-think-twice-before-using-casting.html Options = options; try { // Build common part of the document (title, ...) if (!string.IsNullOrWhiteSpace(Tablature.SongName)) { cursorHeight += 8; svgHeight += 8; SVGContent += "<text x=\"50%\" y=\"" + cursorHeight + "\" font-family=\"" + Options.Typeface + "\" font-size=\"30\" text-anchor=\"middle\">" + Tablature.SongName + "</text>"; cursorHeight += 30; svgHeight += 30; } if (!string.IsNullOrWhiteSpace(Tablature.ArtistName)) { cursorHeight += 5; svgHeight += 5; SVGContent += "<text x=\"50%\" y=\"" + cursorHeight + "\" font-family=\"" + Options.Typeface + "\" font-size=\"15\" text-anchor=\"middle\" font-style=\"italic\">" + Tablature.ArtistName + "</text>"; cursorHeight += 15; svgHeight += 15; } if (Tablature.Tempo.HasValue && Tablature.Tempo.Value > 0) { cursorHeight += 5; svgHeight += 5; SVGContent += "<text x=\"0\" y=\"" + cursorHeight + "\" font-family=\"" + Options.Typeface + "\" font-size=\"12\" text-anchor=\"left\">Tempo: " + Tablature.Tempo.Value + "</text>"; cursorHeight += 15; svgHeight += 15; } if (Options.DisplayEnchainement && Tablature.Structure != null && Tablature.Structure.Count > 0) { cursorHeight += 5; svgHeight += 5; if (!Options.AffichageEnchainementDetaille.HasValue || !Options.AffichageEnchainementDetaille.Value) { // Affichage simple SVGContent += "<text x=\"0\" y=\"" + cursorHeight + "\" font-family=\"" + Options.Typeface + "\" font-size=\"12\" text-anchor=\"left\">Enchaînement: "; foreach (StructureSectionModel ei in Tablature.Structure) { SVGContent += "(" + Tablature.GetPartName(ei.PartId, Options.Culture) + " x" + ei.Repeat + ") "; } SVGContent += "</text>"; } else { // Affichage détaillé SVGContent += "<text x=\"0\" y=\"" + cursorHeight + "\" font-family=\"" + Options.Typeface + "\" font-size=\"12\" text-anchor=\"left\">Enchaînement:</text>"; foreach (StructureSectionModel ei in Tablature.Structure) { cursorHeight += 15; svgHeight += 15; SVGContent += "<text x=\"20\" y=\"" + cursorHeight + "\" font-family=\"" + Options.Typeface + "\" font-size=\"12\" text-anchor=\"left\">- " + Tablature.GetPartName(ei.PartId, Options.Culture) + " x" + ei.Repeat + "</text>"; } } cursorHeight += 15; svgHeight += 15; } // Implement instrument stuff (only guitar for now) switch (Tablature.Instrument) { case InstrumentEnum.Guitar: GuitarRenderingBuilder guitarRenderingBuilder = new GuitarRenderingBuilder(); guitarRenderingBuilder.Init(Options, Tablature, cursorWith, cursorHeight); string _SVGContent = SVGContent; guitarRenderingBuilder.TryBuild(ref _SVGContent); SVGContent = _SVGContent; break; default: throw new NotImplementedException(); } // outputContent = SVGContent; return(TabGenerationStatus.Succeed); } catch (Exception) { return(TabGenerationStatus.Failed); } finally { Options = null; Tablature = null; SVGContent = null; } }