-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathProgram.cs
61 lines (52 loc) · 2.15 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.IO;
using AlphaTab.Midi;
using AlphaTab.Synth;
using AlphaTab.Importer;
namespace AlphaTab.Samples.Player
{
public static class Program
{
private static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Usage AlphaTab.Samples.Player.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.On(() => { Console.WriteLine("Midi loaded"); });
player.SoundFontLoaded.On(() => { Console.WriteLine("SoundFont loaded"); });
player.MidiLoadFailed.On(e => { Console.WriteLine("Midi load failed"); });
player.SoundFontLoadFailed.On(e => { Console.WriteLine("SoundFont load failed"); });
player.Finished.On(() =>
{
Console.WriteLine("Playback finished");
((NAudioSynthOutput) player.Output).Close();
});
player.PositionChanged.On(e =>
{
var currentTime = TimeSpan.FromMilliseconds(e.CurrentTime);
var endTime = TimeSpan.FromMilliseconds(e.EndTime);
Console.Write("\r{0:mm\\:ss\\:fff} ({1}) of {2:mm\\:ss\\:fff} ({3})",
currentTime, e.CurrentTick, endTime, e.EndTick);
});
player.ReadyForPlayback.On(() => { Console.WriteLine("Ready for playback"); });
player.LoadSoundFont(File.ReadAllBytes(args[1]), false);
player.LoadMidiFile(midiFile);
Console.WriteLine("Start playing");
player.Play();
Console.WriteLine("Press enter to exit");
Console.ReadLine();
player.Pause();
Console.ReadLine();
}
}
}