Beispiel #1
0
        public static void Compile(string inputFileName, out List <ChanEnv> envInfo,
                                   out List <ChanWav> wavInfo, out List <ChanFM> fmInfo,
                                   out List <List <string> > commands, out string metadata, out int tickrate)
        {
            List <string> inputFile = new List <string>(
                File.ReadAllLines(inputFileName));

            inputFile = StripComments(inputFile);

            metadata = (SetMetadata(inputFile, "artist=") + " - "
                        + SetMetadata(inputFile, "name="));
            tickrate = Convert.ToInt32(SetMetadata(inputFile, "hz"));

            List <string> envMacros;
            List <string> envMacrosValues;
            List <string> envTypes;
            List <string> wavMacros;
            List <string> wavMacrosValues;
            List <string> wavTypes;
            List <string> fmMacros;
            List <string> fmMacrosValues;
            List <string> fmTypes;

            GetMacroBlock(inputFile, new [] { "/env", "/wav" }, out envMacros,
                          out envTypes, out envMacrosValues);

            GetMacroBlock(inputFile, new [] { "/wav", "/fm" }, out wavMacros,
                          out wavTypes, out wavMacrosValues);

            GetMacroBlock(inputFile, new [] { "/fm", "/mu" }, out fmMacros,
                          out fmTypes, out fmMacrosValues);

            LexDict dictionary = new LexDict(envMacros, envTypes, envMacrosValues,
                                             wavMacros, wavTypes, wavMacrosValues, fmMacros, fmTypes, fmMacrosValues);

            GetMusicBlock(inputFile, dictionary, out commands);

            envInfo = new List <ChanEnv>();

            for (int i = 0; i <  dictionary.envnames.Count; i++)
            {
                List <float> newEnvValues = new List <float>();
                foreach (var value in dictionary.envalues[i].Split(
                             new [] { ' ' }))
                {
                    newEnvValues.Add(Convert.ToSingle(value));
                }
                if (newEnvValues.Count <  4)
                {
                    newEnvValues.Add(0f);
                }
                ChanEnv newEnvInfo = new ChanEnv(dictionary.envnames[i],
                                                 dictionary.envtypes[i], newEnvValues);
                envInfo.Add(newEnvInfo);
            }

            wavInfo = new List <ChanWav>();

            for (int i = 0; i <  dictionary.wavnames.Count; i++)
            {
                List <float> newWavValues = new List <float>();
                foreach (var value in dictionary.wavalues[i].Split(
                             new [] { ' ' }))
                {
                    newWavValues.Add(Single.Parse(value));
                }
                if (newWavValues.Count <  2)
                {
                    newWavValues.Add(0f);
                }
                ChanWav newWavInfo = new ChanWav(dictionary.wavnames[i],
                                                 dictionary.wavtypes[i], newWavValues);
                wavInfo.Add(newWavInfo);
            }

            fmInfo = new List <ChanFM>();

            for (int i = 0; i < dictionary.fmnames.Count; i++)
            {
                string newEnvName      = dictionary.fmvalues[i].Split(' ')[0];
                float  newMult         = Single.Parse(dictionary.fmvalues[i].Split(' ')[1]);
                int    newTruncMod     = Int32.Parse(dictionary.fmvalues[i].Split(' ')[2]);
                int    newTruncCar     = Int32.Parse(dictionary.fmvalues[i].Split(' ')[3]);
                int    newInputChannel = Int32.Parse(
                    dictionary.fmvalues[i].Split(' ')[4]);
                fmInfo.Add(new ChanFM(dictionary.fmnames[i], dictionary.fmtypes[i],
                                      newEnvName, newMult, newTruncMod, newTruncCar, newInputChannel));
            }
        }
Beispiel #2
0
        static void GetMusicBlock(List <string> inputList,
                                  LexDict dictionary, out List <List <string> > musicCommands)
        {
            bool currentBlock = false;

            musicCommands = new List <List <string> >();
            musicCommands.Add(new List <string>());
            int             channel         = 0;
            int             totalChannels   = 0;
            List <string[]> arbitraryMacros = new List <string[]>();

            foreach (var line in inputList)
            {
                List <string> currentCommand = new List <string>();
                if (!currentBlock)
                {
                    if (line.StartsWith("/mu"))
                    {
                        currentBlock = true;
                    }
                }
                else
                {
                    if (line.StartsWith("END"))
                    {
                        currentBlock = false;
                    }
                    else if (line.StartsWith("/mu"))
                    {
                        currentBlock = true;
                    }
                    else
                    {
                        bool isMacro = false;

                        List <string> newCurrentLine     = new List <string>();
                        List <string>  newerCurrentLine  = new List <string>();
                        List <string> newererCurrentLine = new List <string>();

                        string[] currentLine = line.Split(new [] { ' ' });

                        newCurrentLine.AddRange(currentLine);

                        if (currentLine[0].Contains("c"))
                        {
                            channel = Int32.Parse(
                                currentLine[0].TrimStart(new [] { 'c' }));
                            if (channel > totalChannels)
                            {
                                totalChannels = channel;
                                musicCommands.Add(new List <string>());
                            }
                            newerCurrentLine.AddRange(fillLoops(newCurrentLine));
                            newererCurrentLine.AddRange(newerCurrentLine);
                            int macroIndex = 0;
                            foreach (var command in newerCurrentLine)
                            {
                                macroIndex++;
                                foreach (var macro in arbitraryMacros)
                                {
                                    if (command.Contains(macro[0]))
                                    {
                                        newererCurrentLine
                                        .InsertRange(macroIndex,
                                                     macro);
                                        macroIndex += macro.Length;
                                    }
                                }
                            }
                        }
                        else
                        {
                            newererCurrentLine.AddRange(fillLoops(newCurrentLine));
                            arbitraryMacros.Add(newererCurrentLine.ToArray());
                            isMacro = true;
                        }

                        foreach (var command in newererCurrentLine.ToArray())
                        {
                            for (int i = 0; i < dictionary.notenames.Length; i++)
                            {
                                if (command.Contains(dictionary.notenames[i]))
                                {
                                    string newCommand = (
                                        Convert.ToString(dictionary.notevalues[i]));
                                    if (!command.Contains(">"))
                                    {
                                        currentCommand.Add("retrig " + newCommand);
                                        for (int r = 1;
                                             r < Int32.Parse(command.TrimStart(
                                                                 dictionary.notenames[i].ToCharArray())); r++  )
                                        {
                                            currentCommand.Add("noRetrig "
                                                               + newCommand);
                                        }
                                    }
                                    else
                                    {
                                        for (int r = 1;
                                             r < Int32.Parse(
                                                 command.TrimStart((">" +
                                                                    dictionary.notenames[i])
                                                                   .ToCharArray()));
                                             r++  )
                                        {
                                            currentCommand.Add("noRetrig "
                                                               + newCommand);
                                        }
                                    }
                                }
                            }
                            for (int i = 0; i  <  dictionary.commandnames.Length; i++)
                            {
                                if (command.Contains(dictionary.commandnames[i]))
                                {
                                    string newCommand = (
                                        dictionary.commandqualities[i] + " "
                                        + command.TrimStart(
                                            dictionary.commandnames[i].ToCharArray())
                                        );
                                    currentCommand.Add(newCommand);
                                }
                            }
                            for (int i = 0; i <  dictionary.envnames.Count; i++)
                            {
                                if (command.Equals(dictionary.envnames[i]))
                                {
                                    string newCommand = "envSet "
                                                        + dictionary.envnames[i];
                                    currentCommand.Add(newCommand);
                                }
                            }
                            for (int i = 0; i <  dictionary.wavnames.Count; i++)
                            {
                                if (command.Equals(dictionary.wavnames[i]))
                                {
                                    string newCommand = "wavSet "
                                                        + dictionary.wavnames[i];
                                    currentCommand.Add(newCommand);
                                }
                            }
                            for (int i = 0; i <  dictionary.fmnames.Count; i++)
                            {
                                if (command.Equals(dictionary.fmnames[i]))
                                {
                                    string newCommand = "fmSet "
                                                        + dictionary.fmnames[i];
                                    currentCommand.Add(newCommand);
                                }
                            }
                        }
                        if (!isMacro)
                        {
                            musicCommands[channel].AddRange(currentCommand);
                        }
                    }
                }
            }
            musicCommands[0].Add(Convert.ToString(totalChannels));
        }