Created
September 4, 2009 21:12
-
-
Save atsushieno/181136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Parses SC-8850 tone list at http://www.roland.co.jp/lib/download/Tone_list.html#SC8850 | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Text; | |
namespace Monotone.Tools | |
{ | |
public class ToneName | |
{ | |
public ToneName (int p, int b, string n) | |
{ | |
Program = p; | |
Bank = b; | |
Name = n; | |
} | |
public int Program; | |
public int Bank; | |
public string Name; | |
} | |
public class ParseToneList | |
{ | |
public static void Main (string [] args) | |
{ | |
new ParseToneList ().Run (args); | |
} | |
List<ToneName> tones = new List<ToneName> (); | |
StreamReader reader; | |
int line; | |
string ReadLine () | |
{ | |
line++; | |
return reader.ReadLine (); | |
} | |
char [] sep = new char [] {'\t'}; | |
ToneName ParseTone (string s, int program) | |
{ | |
var l = s.Trim ().Split (sep, StringSplitOptions.RemoveEmptyEntries); | |
if (l [0] == "0") | |
return new ToneName (int.Parse (l [1]), int.Parse (l [0]), l [2]); | |
else | |
return new ToneName (program, int.Parse (l [0]), l [1]); | |
} | |
public void Run (string [] args) | |
{ | |
try { | |
DoParse (args); | |
} catch (Exception ex) { | |
Console.WriteLine ("at line " + line); | |
Console.WriteLine (ex); | |
} | |
} | |
void DoParse (string [] args) | |
{ | |
reader = new StreamReader (args [0], Encoding.GetEncoding (932)); | |
for (int i = 0; i < 4; i++) | |
ReadLine (); | |
int program = 0; | |
string s = ReadLine (); | |
while (s != null) { | |
if (s.StartsWith ("SC-55 Map")) | |
break; | |
if (s.Length == 0) { | |
ReadLine (); | |
s = ReadLine (); | |
continue; | |
} | |
if (s.Trim () == "^^^^^") { | |
program++; | |
ReadLine (); // blank | |
s = reader.ReadLine (); | |
continue; | |
} | |
if (!char.IsNumber (s [0])) { | |
string categoryLabel = s; | |
for (int i = 0; i < 5; i++) | |
ReadLine (); | |
s = ReadLine (); | |
continue; | |
} | |
if (s != null) | |
tones.Add (ParseTone (s, program)); | |
ReadLine (); | |
s = ReadLine (); | |
} | |
foreach (var l in tones) | |
Console.WriteLine (l); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment