public async Task <Score> FetchSongScore(Song song, bool skipIfCached) { if (song.LatestAvailableRevision?.GuitarProTab?.BinaryData != null) { return(ScoreLoader.LoadScoreFromBytes(song.LatestAvailableRevision.GuitarProTab.BinaryData)); } //if not cached, download it again string datafileUrl = song.LatestAvailableRevision.GuitarProTab.AttachmentUrl; string fileName = RootFolder + "s" + song.ID + "." + datafileUrl.Substring(datafileUrl.LastIndexOf('.') + 1, 3); LogMessage("Fetching Track GP File: " + song.ID + " " + song.LatestAvailableRevision.GuitarProTab.AttachmentUrl); byte[] data = await _resourceManager.GetAttachmentWithCaching(song.LatestAvailableRevision.GuitarProTab.AttachmentUrl, true, song.ID.ToString()); song.LatestAvailableRevision.GuitarProTab.BinaryData = data; //save file to local cache //await CacheBinaryData(fileName, song.ID.ToString(), data); if (data != null) { return(ScoreLoader.LoadScoreFromBytes(data)); } else { return(null); } }
public bool Load(object?data, Action <Score> success, Action <Error> error) { switch (data) { case Score score: success(score); return(true); case byte[] b: success(ScoreLoader.LoadScoreFromBytes(new Uint8Array(b), Api.Settings)); return(true); case Stream s: { using (var ms = new MemoryStream()) { s.CopyTo(ms); success(ScoreLoader.LoadScoreFromBytes(new Uint8Array(ms.ToArray()), Api.Settings)); } return(true); } default: return(false); } }
public async Task <Score> LoadScoreFromUrl(string url) { byte[] data = await _resourceManager.GetAttachmentWithCaching(url, false, "notcached"); return(ScoreLoader.LoadScoreFromBytes(data, new AlphaTab.Settings { })); }
private static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage AlphaTab.Samples.ScoreDump.exe Path"); return; } var score = ScoreLoader.LoadScoreFromBytes(File.ReadAllBytes(args[0])); // score info Console.WriteLine("Title: {0}", score.Title); Console.WriteLine("Subtitle: {0}", score.SubTitle); Console.WriteLine("Artist: {0}", score.Artist); Console.WriteLine("Tempo: {0}", score.Tempo); Console.WriteLine("Bars: {0}", score.MasterBars.Count); Console.WriteLine("Time Signature: {0}/{1}", score.MasterBars[0].TimeSignatureNumerator, score.MasterBars[0].TimeSignatureDenominator); // tracks Console.WriteLine("Tracks: "); for (var i = 0; i < score.Tracks.Count; i++) { var track = score.Tracks[i]; Console.WriteLine(" {0} - {1} - {2}", i + 1, track.Name, track.Staves.Any(s => s.IsPercussion) ? "Percussion" : "Midi Instrument: " + track.PlaybackInfo.Program); } }
public void Load(object data) { Element.classList.add("loading"); try { if (Std.InstanceOf <ArrayBuffer>(data)) { ScoreLoaded(ScoreLoader.LoadScoreFromBytes(Std.ArrayBufferToByteArray((ArrayBuffer)data))); } else if (Std.InstanceOf <Uint8Array>(data)) { ScoreLoaded(ScoreLoader.LoadScoreFromBytes((byte[])data)); } else if (JsTypeOf(data) == JsTypes.@string) { ScoreLoader.LoadScoreAsync((string)data, s => ScoreLoaded(s), e => { Error("import", e); }); } } catch (Exception e) { Error("import", e); } }
private void InternalOpenFile(string file) { try { // load the score from the filesystem Score = ScoreLoader.LoadScoreFromBytes(File.ReadAllBytes(file)); trackDetails.Controls.Clear(); trackBars.Controls.Clear(); for (int i = Score.Tracks.Count - 1; i >= 0; i--) { TrackDetailsControl details = new TrackDetailsControl(Score.Tracks[i]); details.Dock = DockStyle.Top; details.Height = 25; trackDetails.Controls.Add(details); details.Selected += details_Click; TrackBarsControl bars = new TrackBarsControl(Score.Tracks[i]); bars.Dock = DockStyle.Top; trackBars.Controls.Add(bars); } UpdateSelectedTrack(); } catch (Exception e) { MessageBox.Show(this, e.Message, "An error during opening the file occured", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage AlphaTab.ScoreDump.exe Path"); return; } // load score var score = ScoreLoader.LoadScoreFromBytes(File.ReadAllBytes(args[0])); // render score with svg engine and desired rendering width var settings = Settings.Defaults; settings.Engine = "gdi"; settings.Width = 970; var renderer = new ScoreRenderer(settings); // iterate tracks for (int i = 0, j = score.Tracks.Count; i < j; i++) { var track = score.Tracks[i]; // render track Console.WriteLine("Rendering track {0} - {1}", i + 1, track.Name); var images = new List <Image>(); var totalWidth = 0; var totalHeight = 0; renderer.PartialRenderFinished += r => { images.Add((Image)r.RenderResult); }; renderer.RenderFinished += r => { totalWidth = (int)r.TotalWidth; totalHeight = (int)r.TotalHeight; }; renderer.Render(track); // write png var info = new FileInfo(args[0]); var path = Path.Combine(info.DirectoryName, Path.GetFileNameWithoutExtension(info.Name) + "-" + i + ".png"); using (var bmp = new Bitmap(totalWidth, totalHeight)) { int y = 0; using (var g = Graphics.FromImage(bmp)) { foreach (var image in images) { g.DrawImage(image, new Rectangle(0, y, image.Width, image.Height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel); y += image.Height; } } bmp.Save(path, ImageFormat.Png); } } }
private void LoadScore(byte[] bytes) { _score = ScoreLoader.LoadScoreFromBytes(bytes); AlphaTabControl.Tracks = new[] { _score.Tracks[0] }; }
static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage AlphaTab.ScoreDump.exe PathToFile PathToSoundFont"); return; } // load score var score = ScoreLoader.LoadScoreFromBytes(File.ReadAllBytes(args[0])); // generate midi var midiFile = new MidiFile(); var handler = new AlphaSynthMidiFileHandler(midiFile); var generator = new MidiFileGenerator(score, null, handler); generator.Generate(); var player = new AlphaSynth(new NAudioSynthOutput()); player.MidiLoaded += () => { Console.WriteLine("Midi loaded"); }; player.SoundFontLoaded += () => { Console.WriteLine("SoundFont loaded"); }; player.MidiLoadFailed += e => { Console.WriteLine("Midi load failed"); }; player.SoundFontLoadFailed += e => { Console.WriteLine("SoundFont load failed"); }; player.Finished += _ => { Console.WriteLine("Playback finished"); ((NAudioSynthOutput)player.Output).Close(); }; player.PositionChanged += e => { TimeSpan currentTime = TimeSpan.FromMilliseconds(e.CurrentTime); TimeSpan endTime = TimeSpan.FromMilliseconds(e.EndTime); Console.CursorTop--; Console.Write("".PadLeft(Console.BufferWidth - 1, ' ')); Console.CursorLeft = 0; Console.WriteLine("{0:mm\\:ss\\:fff} ({1}) of {2:mm\\:ss\\:fff} ({3})", currentTime, e.CurrentTick, endTime, e.EndTick); }; player.ReadyForPlayback += () => { Console.WriteLine("Ready for playback"); }; player.LoadSoundFont(File.ReadAllBytes(args[1])); player.LoadMidi(midiFile); Console.WriteLine("Start playing"); player.Play(); Console.WriteLine("Press enter to exit"); Console.ReadLine(); player.Pause(); Console.ReadLine(); }
public override void Load(object data) { if (Std.InstanceOf <ArrayBuffer>(data)) { ScoreLoaded(ScoreLoader.LoadScoreFromBytes(Std.ArrayBufferToByteArray((ArrayBuffer)data))); } else if (Std.InstanceOf <Uint8Array>(data)) { ScoreLoaded(ScoreLoader.LoadScoreFromBytes((byte[])data)); } else if (JsTypeOf(data) == JsTypes.@string) { ScoreLoader.LoadScoreAsync((string)data, s => ScoreLoaded(s), e => console.error(e)); } }
public static async Task RunVisualTest(string inputFile, Settings?settings = null, IList <double>?tracks = null, string?message = null) { try { inputFile = $"test-data/visual-tests/{inputFile}"; var inputFileData = await TestPlatform.LoadFile(inputFile); var referenceFileName = TestPlatform.ChangeExtension(inputFile, ".png"); var score = ScoreLoader.LoadScoreFromBytes(inputFileData, settings); await VisualTestHelper.RunVisualTestScore(score, referenceFileName, settings, tracks, message); } catch (Exception e) { Assert.Fail($"Failed to run visual test {e}"); } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage AlphaTab.MidiDump.exe Path"); return; } // load score var score = ScoreLoader.LoadScoreFromBytes(File.ReadAllBytes(args[0])); // generate midi MidiFile file = MidiFileGenerator.GenerateMidiFile(score); // write midi file string path = Path.ChangeExtension(args[0], "mid"); using (var fs = new StreamWrapper(File.OpenWrite(path))) { file.WriteTo(fs); } }
private void InternalOpenFile(string file) { Task.Factory.StartNew(() => { try { // load the score from the filesystem Score = ScoreLoader.LoadScoreFromBytes(File.ReadAllBytes(file)); // build the track info objects for the ui TrackViewModel[] trackInfos = new TrackViewModel[Score.Tracks.Count]; for (int i = 0; i < trackInfos.Length; i++) { trackInfos[i] = new TrackViewModel(Score.Tracks[i]); } TrackInfos = trackInfos; } catch (Exception e) { _errorService.OpenFailed(e); } }); }
private void Load(object data, int[] trackIndexes) { try { _trackIndexes = trackIndexes; if (Std.InstanceOf <ArrayBuffer>(data)) { ScoreLoaded(ScoreLoader.LoadScoreFromBytes(Std.ArrayBufferToByteArray((ArrayBuffer)data))); } else if (Std.InstanceOf <Uint8Array>(data)) { ScoreLoaded(ScoreLoader.LoadScoreFromBytes((byte[])data)); } else if (JsContext.JsTypeOf(data) == JsTypes.@string) { ScoreLoader.LoadScoreAsync((string)data, ScoreLoaded, Error); } } catch (Exception e) { Error(e); } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage AlphaTab.ScoreDump.exe Path"); return; } // load score var score = ScoreLoader.LoadScoreFromBytes(File.ReadAllBytes(args[0])); // render score with svg engine and desired rendering width var settings = Settings.Defaults; settings.Engine = "skia"; settings.Width = 970; var renderer = new ScoreRenderer(settings); // iterate tracks for (int i = 0, j = score.Tracks.Count; i < j; i++) { var track = score.Tracks[i]; // render track Console.WriteLine("Rendering track {0} - {1}", i + 1, track.Name); var images = new List <SKImage>(); var totalWidth = 0; var totalHeight = 0; renderer.PartialRenderFinished += r => { images.Add((SKImage)r.RenderResult); }; renderer.RenderFinished += r => { totalWidth = (int)r.TotalWidth; totalHeight = (int)r.TotalHeight; }; renderer.Render(score, new[] { track.Index }); // write png var info = new FileInfo(args[0]); var path = Path.Combine(info.DirectoryName, Path.GetFileNameWithoutExtension(info.Name) + "-" + i + ".png"); using (var full = SKSurface.Create(totalWidth, totalHeight, SKImageInfo.PlatformColorType, SKAlphaType.Premul)) { int y = 0; foreach (var image in images) { full.Canvas.DrawImage(image, new SKRect(0, 0, image.Width, image.Height), new SKRect(0, y, image.Width, y + image.Height)); y += image.Height; } using (var fullImage = full.Snapshot()) { using (var data = fullImage.Encode(SKEncodedImageFormat.Png, 100).AsStream(true)) { using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write)) { data.CopyTo(fileStream); } } } } } }