public KaraokeWindow(byte[] file, int country, int MidiOutputA, int MidiOutputB) { InitializeComponent(); //https://social.msdn.microsoft.com/Forums/vstudio/en-US/2062f6ab-b4b5-487c-890a-9c3ffcdc1d2e/karaoke-text-effect-in-wpf?forum=wpf fill.StartPoint = new Point(0, 0.5); fill.EndPoint = new Point(1, 0.5); GradientStop gs1 = new GradientStop(); GradientStop gs2 = new GradientStop(); GradientStop gs3 = new GradientStop(); GradientStop gs4 = new GradientStop(); gs1.Offset = 0.0; gs2.Offset = 0.0; gs3.Offset = 0.0; gs4.Offset = 1.0; gs1.Color = Colors.Blue; gs2.Color = Colors.Blue; gs3.Color = Colors.Black; gs4.Color = Colors.Black; fill.GradientStops.Add(gs1); fill.GradientStops.Add(gs2); fill.GradientStops.Add(gs3); fill.GradientStops.Add(gs4); karaoke = new TJN(file, country); syncQue = new Queue <TickEvent>(karaoke.Lyrics.tickEvents); var midiFile = MidiFile.Read(new MemoryStream(karaoke.MidiData)); IEnumerable <TrackChunk> tracks = midiFile.GetTrackChunks(); foreach (var item in tracks) { foreach (var events in item.Events) { if (events is PortPrefixEvent) { if (((PortPrefixEvent)events).Port == 0) { midiFileA.Chunks.Add(item.Clone()); } else if (((PortPrefixEvent)events).Port == 1) { midiFileB.Chunks.Add(item.Clone()); } break; } } } midiFileA.ReplaceTempoMap(midiFile.GetTempoMap()); midiFileB.ReplaceTempoMap(midiFile.GetTempoMap()); outputDeviceA = OutputDevice.GetById(MidiOutputA); outputDeviceB = OutputDevice.GetById(MidiOutputB); playbackA = midiFileA.GetPlayback(outputDeviceA); playbackB = midiFileB.GetPlayback(outputDeviceB); playbackA.Start(); playbackB.Start(); CompositionTarget.Rendering += CompositionTarget_Rendering; }
static void Main(string[] args) { #if !DEBUG try { if (!(args.Length == 2 || args.Length == 3)) { Console.WriteLine("Usage : TJKaraoke.exe [File Name] [Country Code] [MIDI Device ID = 0 (Default)] [MIDI Device ID = 1 (Default)]"); Console.WriteLine(); Console.WriteLine("https://github.com/009342"); Console.WriteLine(); Console.WriteLine("OSS Notice"); Console.WriteLine("DryWetMIDI"); Console.WriteLine("https://github.com/melanchall/drywetmidi"); Console.WriteLine("Copyright (c) 2018 Maxim Dobroselsky"); Console.WriteLine("MIT License"); } else { TJN karaoke = new TJN(args[0], int.Parse(args[1]), false); Console.OutputEncoding = karaoke.encoding; syncQue = new Queue <TickEvent>(karaoke.lyrics.tickEvents); var midiFile = MidiFile.Read(new MemoryStream(karaoke.midi)); int deviceId = int.Parse((args.Length == 3) ? args[2] : "0"); Console.WriteLine(karaoke.lyrics.kNumber); Console.WriteLine(karaoke.lyrics.name); Console.WriteLine(karaoke.lyrics.lyricist); Console.WriteLine(karaoke.lyrics.composer); Console.WriteLine(karaoke.lyrics.singer); var outputDevice = OutputDevice.GetById(deviceId); var playback = midiFile.GetPlayback(outputDevice); playback.Finished += Playback_Finished; Thread thread = new Thread(() => { Playback(playback); }); playback.Start(); thread.Start(); Thread.Sleep(-1); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } #else TJN karaoke = new TJN(args[0], int.Parse(args[1]), false); Console.OutputEncoding = karaoke.Encoding; syncQue = new Queue <TickEvent>(karaoke.Lyrics.tickEvents); foreach (var item in syncQue) { Console.WriteLine("{0} {1} {2} {3} {4} {5}", item.tick, item.cmd, item.lineNumber, item.indexOfLine, item.str, item.PronGuide != null ? item.PronGuide.Pron : ""); } var midiFile = MidiFile.Read(new MemoryStream(karaoke.MidiData)); var midiFileA = new MidiFile(); var midiFileB = new MidiFile(); IEnumerable <TrackChunk> tracks = midiFile.GetTrackChunks(); foreach (var item in tracks) { foreach (var events in item.Events) { if (events is SequenceTrackNameEvent) { Console.WriteLine("{0} : {1}", item.ChunkId, ((SequenceTrackNameEvent)events).Text); } } } foreach (var item in tracks) { foreach (var events in item.Events) { if (events is PortPrefixEvent) { //Console.WriteLine("{0} : {1}", item.ChunkId, ((SequenceTrackNameEvent)events).Text); if (((PortPrefixEvent)events).Port == 0) { midiFileA.Chunks.Add(item.Clone()); } else if (((PortPrefixEvent)events).Port == 1) { midiFileB.Chunks.Add(item.Clone()); } break; } } } midiFileA.ReplaceTempoMap(midiFile.GetTempoMap()); midiFileB.ReplaceTempoMap(midiFile.GetTempoMap()); Console.WriteLine(karaoke.Lyrics.kNumber); Console.WriteLine(karaoke.Lyrics.title); Console.WriteLine(karaoke.Lyrics.subTitle); Console.WriteLine(karaoke.Lyrics.lyricist); Console.WriteLine(karaoke.Lyrics.composer); Console.WriteLine(karaoke.Lyrics.singer); var playbackA = midiFileA.GetPlayback(OutputDevice.GetById(args.Length >= 3 ? int.Parse(args[2]) : 0)); var playbackB = midiFileB.GetPlayback(OutputDevice.GetById(args.Length >= 4 ? int.Parse(args[3]) : 0)); playbackA.Finished += Playback_Finished; Thread thread = new Thread(() => { Playback(playbackA); }); playbackA.Start(); playbackB.Start(); thread.Start(); Console.ReadLine(); Environment.Exit(0); #endif }