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) { StreamReader reader = new StreamReader(PlatformHelper.StreamLoad(file)); if (!reader.ReadLine().Trim().ToUpper().Equals("[FM INSTRUMENT]")) { reader.Close(); throw new Exception("Invalid Program file: Incorrect Header!"); } string[] args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 4) { reader.Close(); throw new Exception("Invalid Program file: Parameters are missing"); } this.baseWaveType = SynthHelper.getTypeFromString(args[0]); this.modWaveType = SynthHelper.getTypeFromString(args[1]); this.mfreq = (ModulatorFrequencyFunction)getOpsAndValues(args[2], true); this.mamp = (ModulatorAmplitudeFunction)getOpsAndValues(args[3], false); args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None); if (args.Length < 3) { reader.Close(); 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 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(); }
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 Methods private void loadAnalog(string[] args, byte[] Programs, byte[] DrumPrograms) { bool ISdrum = args[4] == "d" ? true : false; int start = int.Parse(args[2]); int end = int.Parse(args[3]); List <int> Indices = new List <int>(); if (ISdrum == false) { if (Programs == null) { for (int i = start; i <= end; i++) { Indices.Add(i); } } else { for (int x2 = 0; x2 < Programs.Length; x2++) { if (Programs[x2] >= start && Programs[x2] <= end) { Indices.Add(Programs[x2]); } } } } else { if (DrumPrograms == null) { for (int i = start; i <= end; i++) { Indices.Add(i); } } else { for (int x2 = 0; x2 < DrumPrograms.Length; x2++) { if (DrumPrograms[x2] >= start && Programs[x2] <= end) { Indices.Add(DrumPrograms[x2]); } } } } if (Indices.Count > 0) { Instrument inst; inst = new AnalogInstrument(SynthHelper.getTypeFromString(args[0]), SampleRate_); //Resample if necessary if (SampleRate_ > 0) { inst.enforceSampleRate(SampleRate_); } //Loop through where to add the instruments for (int i = 0; i < Indices.Count; i++) { //Decide which bank to add too if (ISdrum == true) { DrumBank[Indices[i]] = inst; } else { Bank[Indices[i]] = inst; } } } }