Esempio n. 1
0
        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();
        }
Esempio n. 2
0
 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();
 }
Esempio n. 3
0
 private IFMComponent getOpsAndValues(string arg, bool isFrequencyFunction)
 {
     arg = arg + "    ";
     char[] chars = arg.ToCharArray();
     List<byte> opList = new List<byte>();
     List<double> valueList = new List<double>();
     string start = arg.Substring(0, 4).ToLower();
     byte select = 0;
     if (!start.Contains("freq") && !start.Contains("amp"))
     {//if "freq" isnt used then we make sure the value passed in is negated by *0;
         opList.Add(0);
         valueList.Add(0);
     }
     else if (start.Contains("freq"))
     {
         select = 0;
     }
     else
     {
         select = 1;
     }
     bool opOcurred = false;
     bool neg = false;
     for (int x = 0; x < arg.Length; x++)
     {
         switch (chars[x])
         {
             case '*':
                 if (opOcurred == false)
                 {
                     opList.Add(0);
                     opOcurred = true;
                 }
                 break;
             case '/':
                 if (opOcurred == false)
                 {
                     opList.Add(1);
                     opOcurred = true;
                 }
                 break;
             case '+':
                 if (opOcurred == false)
                 {
                     opList.Add(2);
                     opOcurred = true;
                 }
                 break;
             case '-':
                 if (opOcurred == true)
                     neg = !neg;
                 else
                 {
                     opList.Add(3);
                     opOcurred = true;
                 }
                 break;
             default:
                 string number = "";
                 while (Char.IsDigit(chars[x]) || chars[x] == '.')
                 {
                     number = number + chars[x];
                     x++;
                     if (x >= chars.Length)
                         break;
                 }
                 if (number.Length > 0)
                 {
                     x--;
                     opOcurred = false;
                     if (neg)
                         number = "-" + number;
                     neg = false;
                     valueList.Add(double.Parse(number));
                 }
                 break;
         }
     }
     while (opList.Count < valueList.Count)
         opList.Add(2);
     if (isFrequencyFunction)
     {
         ModulatorFrequencyFunction ifm = new ModulatorFrequencyFunction(opList.ToArray(), valueList.ToArray());
         ifm.inputSelect = select;
         return ifm;
     }
     else
     {
         ModulatorAmplitudeFunction ifm = new ModulatorAmplitudeFunction(opList.ToArray(), valueList.ToArray());
         ifm.inputSelect = select;
         return ifm;
     }
 }
Esempio n. 4
0
        private IFMComponent getOpsAndValues(string arg, bool isFrequencyFunction)
        {
            arg = arg + "    ";
            char[]        chars     = arg.ToCharArray();
            List <byte>   opList    = new List <byte>();
            List <double> valueList = new List <double>();
            string        start     = arg.Substring(0, 4).ToLower();
            byte          select    = 0;

            if (!start.Contains("freq") && !start.Contains("amp"))
            {//if "freq" isnt used then we make sure the value passed in is negated by *0;
                opList.Add(0);
                valueList.Add(0);
            }
            else if (start.Contains("freq"))
            {
                select = 0;
            }
            else
            {
                select = 1;
            }
            bool opOcurred = false;
            bool neg       = false;

            for (int x = 0; x < arg.Length; x++)
            {
                switch (chars[x])
                {
                case '*':
                    if (opOcurred == false)
                    {
                        opList.Add(0);
                        opOcurred = true;
                    }
                    break;

                case '/':
                    if (opOcurred == false)
                    {
                        opList.Add(1);
                        opOcurred = true;
                    }
                    break;

                case '+':
                    if (opOcurred == false)
                    {
                        opList.Add(2);
                        opOcurred = true;
                    }
                    break;

                case '-':
                    if (opOcurred == true)
                    {
                        neg = !neg;
                    }
                    else
                    {
                        opList.Add(3);
                        opOcurred = true;
                    }
                    break;

                default:
                    string number = "";
                    while (Char.IsDigit(chars[x]) || chars[x] == '.')
                    {
                        number = number + chars[x];
                        x++;
                        if (x >= chars.Length)
                        {
                            break;
                        }
                    }
                    if (number.Length > 0)
                    {
                        x--;
                        opOcurred = false;
                        if (neg)
                        {
                            number = "-" + number;
                        }
                        neg = false;
                        valueList.Add(double.Parse(number));
                    }
                    break;
                }
            }
            while (opList.Count < valueList.Count)
            {
                opList.Add(2);
            }
            if (isFrequencyFunction)
            {
                ModulatorFrequencyFunction ifm = new ModulatorFrequencyFunction(opList.ToArray(), valueList.ToArray());
                ifm.inputSelect = select;
                return(ifm);
            }
            else
            {
                ModulatorAmplitudeFunction ifm = new ModulatorAmplitudeFunction(opList.ToArray(), valueList.ToArray());
                ifm.inputSelect = select;
                return(ifm);
            }
        }