public void JsonDeserializationTestWithProxyOnRealExample() { var assembly = typeof(SerializationTests).Assembly; var scoreResourceName = $"{typeof(SerializationTests).Namespace}.Assets.JohannChristophBachFull3.0.xml"; using (var scoreStream = assembly.GetManifestResourceStream(scoreResourceName)) using (var scoreReader = new StreamReader(scoreStream)) { var sw = new Stopwatch(); sw.Start(); var scoreString = scoreReader.ReadToEnd(); var settings = new HtmlScoreRendererSettings(); settings.RenderSurface = HtmlScoreRendererSettings.HtmlRenderSurface.Svg; var profile = SMuFLMusicFont.CreateFromJsonResource <SerializationTests>("bravura_metadata.json"); settings.SetMusicFont(profile, "Bravura", "/fakeuri"); settings.Scale = 1; settings.CustomElementPositionRatio = 0.8; settings.IgnorePageMargins = true; var renderer = new HtmlSvgScoreRenderer(new XElement("root"), "testCanvas", settings); renderer.Render(scoreString.ToScore()); sw.Stop(); var metadataAsProxy = (LazyLoadJsonProxy)profile.SMuFLMetadata; Debug.WriteLine($"All rendering done in {sw.Elapsed}"); var deserTime = metadataAsProxy.GetTotalDeserializationTimeWithChildElements(); Debug.WriteLine($"Deserialization done in {deserTime}"); } }
private HtmlScoreRendererSettings CreateScoreRendererSettings(string musicFontName, string fontMetadataPath, params string[] musicFontUris) { var fontMetadata = string.IsNullOrWhiteSpace(fontMetadataPath) ? null : File.ReadAllText( Path.Combine(hostingEnvironment.ContentRootPath, "wwwroot") + fontMetadataPath); var settings = new HtmlScoreRendererSettings(); settings.RenderSurface = HtmlScoreRendererSettings.HtmlRenderSurface.Svg; settings.CustomElementPositionRatio = 1; if (musicFontName == "Polihymnia") { settings.Fonts.Add(MusicFontStyles.MusicFont, new HtmlFontInfo(musicFontName, 22, musicFontUris)); settings.Fonts.Add(MusicFontStyles.StaffFont, new HtmlFontInfo(musicFontName, 24, musicFontUris)); settings.Fonts.Add(MusicFontStyles.GraceNoteFont, new HtmlFontInfo(musicFontName, 12, musicFontUris)); settings.Fonts.Add(MusicFontStyles.TimeSignatureFont, new HtmlFontInfo("Open Sans", 12, "/fonts/OpenSans-Regular.ttf")); settings.Fonts.Add(MusicFontStyles.LyricsFont, new HtmlFontInfo("Open Sans", 12, "/fonts/OpenSans-Regular.ttf")); settings.Fonts.Add(MusicFontStyles.DirectionFont, new HtmlFontInfo("Open Sans", 14, "/fonts/OpenSans-Regular.ttf")); } else { var profile = SMuFLMusicFont.CreateFromJsonString(fontMetadata); profile.FontSizes[MusicFontStyles.MusicFont] = 20; profile.FontSizes[MusicFontStyles.TimeSignatureFont] = 20; profile.FontSizes[MusicFontStyles.StaffFont] = 20; settings.SetMusicFont(profile, musicFontName, musicFontUris); } settings.RenderingMode = Controls.Rendering.ScoreRenderingModes.AllPages; settings.IgnorePageMargins = true; return(settings); }
public ActionResult Index() { var fontMetadataPath = Server.MapPath("~/fonts/bravura_metadata.json"); var useSmufl = true; var vm = new HomeViewModel(); if (useSmufl) { var fontProfile = SMuFLMusicFont.CreateFromJsonString(System.IO.File.ReadAllText(fontMetadataPath)); fontProfile.SetFontSize(Model.Fonts.MusicFontStyles.MusicFont, 20); vm.Settings.SetMusicFont(fontProfile, "Bravura", "/fonts/Bravura.otf"); } //var serverPath = Server.MapPath("~/Content/036 Bogurodzica[1].xml"); //var serverPath = Server.MapPath("~/Content/010 DWOK tom 25, s. 120, nr 273.xml"); //var serverPath = Server.MapPath("~/Content/Kyrie.Salamon2.xml"); var serverPath = Server.MapPath("~/Content/JohannChristophBachFull3.0.xml"); //var serverPath = Server.MapPath("~/Content/030 Oj, zabujały 67 I nr 214.xml"); //var serverPath = Server.MapPath("~/Content/0014 Larum w obozie.xml"); //var serverPath = Server.MapPath("~/Content/Dzidzm.xml"); vm.SampleScore = System.IO.File.ReadAllText(serverPath).ToScore(); return(View(vm)); }
public void TestBinarySerialization() { var profile = SMuFLMusicFont.CreateFromJsonResource <SerializationTests>("Assets.bravura_metadata.json", false); using (var ms = new MemoryStream()) { var serializationSw = new Stopwatch(); serializationSw.Start(); profile.SerializeMetadataAsBinary(ms); serializationSw.Stop(); var serializedData = ms.ToArray(); var deserializationSw = new Stopwatch(); deserializationSw.Start(); var newProfile = SMuFLMusicFont.CreateFromBinaryArray(serializedData); deserializationSw.Stop(); Debug.WriteLine($"Serialization: {serializationSw.Elapsed}, Deserialization: {deserializationSw.Elapsed}"); } }
public MainWindow() { InitializeComponent(); var family = dummyTextBlock.FontFamily; //noteViewerTest.IsMusicPaperMode = true; var useSMuFL = true; if (useSMuFL) { var fontProfile = SMuFLMusicFont.CreateFromJsonResource <MainWindow>("Assets.bravura_metadata.json"); //SMuFLMusicFont.CreateFromBinaryResource<MainWindow>("Assets.bravura_metadata.bin"); noteViewerTest.SetFont(family, fontProfile); noteViewer1.SetFont(family, fontProfile); noteViewer2.SetFont(family, fontProfile); noteViewer3.SetFont(family, fontProfile); } LoadTestModel(HookDirectionAlgorithm.ProductionCandidate); }
public Form1() { InitializeComponent(); //noteViewer1.Settings.IsMusicPaperMode = true; var fontPath = Path.Combine(Application.StartupPath, "Assets", "Bravura.otf"); var metaPath = Path.Combine(Application.StartupPath, "Assets", "bravura_metadata.json"); var smuflProfile = SMuFLMusicFont.CreateFromJsonString(File.ReadAllText(metaPath)); noteViewer1.SetFontFromPath(fontPath, smuflProfile); var mScore = Score.CreateOneStaffScore(Clef.Treble, Music.Model.MajorAndMinor.MajorScale.G); mScore.FirstStaff.AddTimeSignature(TimeSignatureType.Numbers, 4, 4); mScore.FirstStaff.AddNote(Pitch.G4, RhythmicDuration.Half); mScore.FirstStaff.Add(new Rest(RhythmicDuration.Quarter)); mScore.FirstStaff.AddNote(Pitch.FromMidiPitch(60, Pitch.MidiPitchTranslationMode.Auto), RhythmicDuration.Half); mScore.FirstStaff.AddBarline(BarlineStyle.Regular); mScore.FirstStaff.AddNote(Pitch.G4, RhythmicDuration.Quarter); mScore.FirstStaff.AddNote(Pitch.FromMidiPitch(61, Pitch.MidiPitchTranslationMode.Auto), RhythmicDuration.Quarter); mScore.FirstStaff.AddRange(new Note[] { Note.FromMidiPitch(63, RhythmicDuration.Quarter), Note.FromMidiPitch(67, RhythmicDuration.Quarter) }.MakeChord()); mScore.FirstStaff.AddBarline(BarlineStyle.Regular); mScore.FirstStaff.AddRange(StaffBuilder.FromPitches( Pitch.C4, Pitch.E4, Pitch.G4, Pitch.A4, Pitch.C4, Pitch.E4, Pitch.G4, Pitch.A4).AddUniformRhythm(RhythmicDuration.Sixteenth).ApplyStemDirection(VerticalDirection.Up).Rebeam()); Note n1 = new Note(); n1.ApplyMidiPitch(63); n1.Duration = RhythmicDuration.Quarter; n1.Tuplet = TupletType.Start; n1.TupletWeightOverride = 1; mScore.FirstStaff.Add(n1); n1 = new Note(); n1.ApplyMidiPitch(66); n1.Duration = RhythmicDuration.Quarter; n1.TupletWeightOverride = 1; mScore.FirstStaff.Add(n1); n1 = new Note(); n1.ApplyMidiPitch(66); n1.Duration = RhythmicDuration.Quarter; n1.TupletWeightOverride = 1; n1.Tuplet = TupletType.Stop; mScore.FirstStaff.Add(n1); mScore.FirstStaff.AddBarline(BarlineStyle.Regular); PrintSuggestion ps = new PrintSuggestion { IsSystemBreak = true }; mScore.FirstStaff.Add(ps); mScore.FirstStaff.AddRange(StaffBuilder.FromPitches(Pitch.G4, Pitch.B4, Pitch.D5, Pitch.C4, Pitch.E4, Pitch.G4, Pitch.D4, Pitch.DSharp4, Pitch.A4) .AddRhythm("8 8 8 8 4 4 4 4 4")); mScore.FirstStaff.AddBarline(BarlineStyle.Regular); mScore.FirstStaff.AddRange(StaffBuilder.FromPitches(Pitch.G4, Pitch.B4, Pitch.D5, Pitch.C4, Pitch.E4, Pitch.G4, Pitch.D4, Pitch.DSharp4, Pitch.A4) .AddRhythm("8 8 8 8 4 4 4 4 4")); mScore.FirstStaff.Elements.Add(new Barline()); mScore.FirstStaff.Add(new PrintSuggestion() { IsSystemBreak = true }); mScore.FirstStaff.AddBarline(BarlineStyle.LightHeavy); mScore.FirstStaff.Elements.Add(new TimeSignature(TimeSignatureType.Numbers, 3, 4)); mScore.FirstStaff.Elements.Add(new Note(Pitch.C4, RhythmicDuration.Half.AddDots(1)) { TieType = NoteTieType.Start }); mScore.FirstStaff.Elements.Add(new Barline()); mScore.FirstStaff.Elements.Add(new Note(Pitch.C4, RhythmicDuration.Half.AddDots(1)) { TieType = NoteTieType.Stop }); mScore.FirstStaff.Elements.Add(new Barline()); mScore.FirstStaff.Elements.Add(new Note(Pitch.C4, RhythmicDuration.Half.AddDots(1))); mScore.FirstStaff.Elements.Add(new Barline(BarlineStyle.LightHeavy)); noteViewer1.DataSource = mScore; noteViewer1.Refresh(); }