private void loadProgramFile(string file) { //StreamReader reader = new StreamReader(File.Open(file, FileMode.Open)); StreamReader reader = new StreamReader(Application.GetResourceStream(new Uri(file, UriKind.Relative)).Stream); if (!reader.ReadLine().Trim().ToUpper().Equals("[FM INSTRUMENT]")) { reader.Close(); throw new InvalidDataException("Invalid Program file: Incorrect Header!"); } string[] args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 4) { reader.Close(); throw new InvalidDataException("Invalid Program file: Parameters are missing"); } this.baseWaveType = SynthHelper.getTypeFromString(args[0]); this.modWaveType = SynthHelper.getTypeFromString(args[1]); this.mfreq = getOpsAndValues(args[2], true); this.mamp = getOpsAndValues(args[3], false); args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 3) { reader.Close(); throw new InvalidDataException("Invalid Program file: Parameters are missing"); } if (int.Parse(args[0]) == 0) { looping = true; } start_time = double.Parse(args[1]); end_time = double.Parse(args[2]); args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 3) { reader.Close(); throw new InvalidDataException("Invalid Program file: Parameters are missing"); } switch (args[0].ToLower().Trim()) { case "fadein": env = Envelope.CreateBasicFadeIn(double.Parse(args[2])); break; case "fadeout": env = Envelope.CreateBasicFadeOut(double.Parse(args[2])); break; case "fadein&out": double p = double.Parse(args[2]) / 2.0; env = Envelope.CreateBasicFadeInAndOut(p, p); break; default: env = Envelope.CreateBasicConstant(); break; } env.Peak = double.Parse(args[1]); reader.Close(); }
private void loadProgramFile(string file) { //CSSynth //StreamReader reader = new StreamReader(File.Open(file, FileMode.Open)); //Debug.Log(this.ToString() + " AppDataPath " + Application.dataPath + " Filename: " + file); #if NETFX_CORE StreamReader reader = LegacyFile.OpenText(Application.dataPath + "/Resources/" + file); #else StreamReader reader = new StreamReader(Application.dataPath + "/Resources/" + file); #endif if (!reader.ReadLine().Trim().ToUpper().Equals("[FM INSTRUMENT]")) { #if NETFX_CORE reader.Dispose(); #else reader.Close(); #endif throw new InvalidOperationException("Invalid Program file: Incorrect Header!"); } string[] args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 4) { #if NETFX_CORE reader.Dispose(); #else reader.Close(); #endif throw new InvalidOperationException("Invalid Program file: Parameters are missing"); } this.baseWaveType = SynthHelper.getTypeFromString(args[0]); this.modWaveType = SynthHelper.getTypeFromString(args[1]); this.mfreq = getOpsAndValues(args[2], true); this.mamp = getOpsAndValues(args[3], false); args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 3) { #if NETFX_CORE reader.Dispose(); #else reader.Close(); #endif throw new InvalidOperationException("Invalid Program file: Parameters are missing"); } if (int.Parse(args[0]) == 0) { looping = true; } start_time = double.Parse(args[1]); end_time = double.Parse(args[2]); args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 3) { #if NETFX_CORE reader.Dispose(); #else reader.Close(); #endif throw new InvalidOperationException("Invalid Program file: Parameters are missing"); } switch (args[0].ToLower().Trim()) { case "fadein": env = Envelope.CreateBasicFadeIn(double.Parse(args[2])); break; case "fadeout": env = Envelope.CreateBasicFadeOut(double.Parse(args[2])); break; case "fadein&out": double p = double.Parse(args[2]) / 2.0; env = Envelope.CreateBasicFadeInAndOut(p, p); break; default: env = Envelope.CreateBasicConstant(); break; } env.Peak = double.Parse(args[1]); #if NETFX_CORE reader.Dispose(); #else reader.Close(); #endif }
private void loadProgramFile(string file) { //UnitySynth //StreamReader reader = new StreamReader(File.Open(file, FileMode.Open)); //Debug.Log(this.ToString() + " AppDataPath " + Application.dataPath + " Filename: " + file); StreamReader reader = new StreamReader(Application.dataPath + "/Resources/" + file); if (!reader.ReadLine().Trim().ToUpper().Equals("[FM INSTRUMENT]")) { reader.Close(); //MANGLING FOR WEB BUILD //throw new InvalidDataException("Invalid Program file: Incorrect Header!"); throw new Exception("Invalid Program file: Incorrect Header!"); } string[] args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 4) { reader.Close(); //MANGLING FOR WEB BUILD //throw new InvalidDataException("Invalid Program file: Parameters are missing"); throw new Exception("Invalid Program file: Parameters are missing"); } this.baseWaveType = SynthHelper.getTypeFromString(args[0]); this.modWaveType = SynthHelper.getTypeFromString(args[1]); this.mfreq = getOpsAndValues(args[2], true); this.mamp = getOpsAndValues(args[3], false); args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 3) { reader.Close(); //MANGLING FOR WEB BUILD //throw new InvalidDataException("Invalid Program file: Parameters are missing"); throw new Exception("Invalid Program file: Parameters are missing"); } if (int.Parse(args[0]) == 0) looping = true; start_time = double.Parse(args[1]); end_time = double.Parse(args[2]); args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 3) { reader.Close(); //throw new InvalidDataException("Invalid Program file: Parameters are missing"); throw new Exception("Invalid Program file: Parameters are missing"); } switch (args[0].ToLower().Trim()) { case "fadein": env = Envelope.CreateBasicFadeIn(double.Parse(args[2])); break; case "fadeout": env = Envelope.CreateBasicFadeOut(double.Parse(args[2])); break; case "fadein&out": double p = double.Parse(args[2]) / 2.0; env = Envelope.CreateBasicFadeInAndOut(p, p); break; default: env = Envelope.CreateBasicConstant(); break; } env.Peak = double.Parse(args[1]); reader.Close(); }