<commit_before>using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using Commons.Music.Midi;
using PortMidiSharp;
using Timer = System.Timers.Timer;

namespace Commons.Music.Midi.Player
{
	public class Driver
	{
		static void ShowHelp ()
		{
			Console.WriteLine (@"
managed-midi-player-console [options] SMF-files(*.mid)

Options:
--help		show this help.
--device:x	specifies MIDI output device by ID.
");
			Console.WriteLine ("List of MIDI output device IDs: ");
			foreach (var dev in MidiDeviceManager.AllDevices)
				if (dev.IsOutput)
					Console.WriteLine ("\t{0}: {1}", dev.ID, dev.Name);
		}

		public static void Main (string [] args)
		{
			int outdev = MidiDeviceManager.DefaultOutputDeviceID;
			var files = new List<string> ();
			if (args.Length == 0) {
				ShowHelp ();
				return;
			}
			foreach (var arg in args) {
				if (arg == "--help") {
					ShowHelp ();
					return;
				}
				if (arg.StartsWith ("--device:")) {
					if (!int.TryParse (arg.Substring (9), out outdev)) {
						ShowHelp ();
						Console.WriteLine ();
						Console.WriteLine ("Invalid MIDI output device ID.");
						return;
					}
				}
				else
					files.Add (arg);
			}
			var output = MidiDeviceManager.OpenOutput (outdev);

			foreach (var arg in files) {
				var parser = new SmfReader (File.OpenRead (arg));
				parser.Parse ();
				var player = new PortMidiPlayer (output, parser.Music);
				player.StartLoop ();
				player.PlayAsync ();
				Console.WriteLine ("empty line to quit, P to pause and resume");
				while (true) {
					string line = Console.ReadLine ();
					if (line == "P") {
						if (player.State == PlayerState.Playing)
							player.PauseAsync ();
						else
							player.PlayAsync ();
					}
					else if (line == "") {
						player.Dispose ();
						break;
					}
					else
						Console.WriteLine ("what do you mean by '{0}' ?", line);<commit_msg>add hacky diagnostic mode.<commit_after>using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using Commons.Music.Midi;
using PortMidiSharp;
using Timer = System.Timers.Timer;

namespace Commons.Music.Midi.Player
{
	public class Driver
	{
		static void ShowHelp ()
		{
			Console.WriteLine (@"
managed-midi-player-console [options] SMF-files(*.mid)

Options:
--help		show this help.
--device:x	specifies MIDI output device by ID.
--diagnose	diagnose MIDI message outputs to console.
");
			Console.WriteLine ("List of MIDI output device IDs: ");
			foreach (var dev in MidiDeviceManager.AllDevices)
				if (dev.IsOutput)
					Console.WriteLine ("\t{0}: {1}", dev.ID, dev.Name);
		}

		public static void Main (string [] args)
		{
			int outdev = MidiDeviceManager.DefaultOutputDeviceID;
			var files = new List<string> ();
			bool diagnostic = false;
			if (args.Length == 0) {
				ShowHelp ();
				return;
			}
			foreach (var arg in args) {
				if (arg == "--help") {
					ShowHelp ();
					return;
				}
				else if (arg == "--diagnose")
					diagnostic = true;
				else if (arg.StartsWith ("--device:")) {
					if (!int.TryParse (arg.Substring (9), out outdev)) {
						ShowHelp ();
						Console.WriteLine ();
						Console.WriteLine ("Invalid MIDI output device ID.");
						return;
					}
				}
				else
					files.Add (arg);
			}
			var output = MidiDeviceManager.OpenOutput (outdev);

			foreach (var arg in files) {
				var parser = new SmfReader (File.OpenRead (arg));
				parser.Parse ();
				var player = new PortMidiPlayer (output, parser.Music);
				DateTimeOffset start = DateTimeOffset.Now;
				if (diagnostic)
					player.MessageReceived += m => Console.WriteLine ("{0:06} {1:X08}", (DateTimeOffset.Now - start).TotalMilliseconds, m.Value);
				player.StartLoop ();
				player.PlayAsync ();
				Console.WriteLine ("empty line to quit, P to pause and resume");
				while (true) {
					string line = Console.ReadLine ();
					if (line == "P") {
						if (player.State == PlayerState.Playing)
							player.PauseAsync ();
						else
							player.PlayAsync ();
					}
					else if (line == "") {
						player.Dispose ();
						break;
					}
					else
						Console.WriteLine ("what do you mean by '{0}' ?", line);
{'fraction_non_alphanumeric': 0.1368496079828938, 'fraction_numerical': 0.003801377999524828, 'mean_word_length': 2.7757847533632285, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3402324', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1302, 'n_words': 374}