Ejemplo n.º 1
0
        /// <summary>
        /// Parse the rpp file.
        /// </summary>
        private void Example()
        {
            // open the file and parse it
            parser = new ReaperParser(pathToReaperFile);

            if (!parser.isValid)
            {
                Debug.LogError("The ReaperParser was not initialized.");
                return;
            }

            // get the parsed main ReaperNode object
            rpp = parser.rpp;

            // e.g. get the position of the cursor. There is only one value. Value returns always the first of all values.
            string cursorPosition = rpp.GetNode("CURSOR").value;

            Debug.Log("The cursor position: " + cursorPosition);

            // e.g. get the main tempo information of the session.
            List <string> tempo = rpp.GetNode("TEMPO").values;

            Debug.Log("Tempo information: " + string.Join(", ", tempo.ToArray()));

            // e.g. get the name of the first item on the last track
            string itemName = rpp.GetLastNode("TRACK").GetNode("ITEM").GetNode("NAME").value;

            Debug.Log("name of the first item on the last track: " + itemName);

            // load the audio in a coroutine to be sure the audioclip is loaded before assigned to a audiosource
            StartCoroutine(LoadAudio());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse the reaper file.
        /// </summary>
        /// <returns>The top node.</returns>
        /// <param name="parent">Parent.</param>
        /// <param name="parser">The parsing ReaperParser.</param>
        private ReaperNode Parse(ReaperNode parent, ReaperParser parser)
        {
            string cl = contentLines[currentLine];

            if (cl.Contains("<"))
            {
                var newNode = new ReaperNode(cl, parent, parser); // Create a new Node
                if (currentNode != null)                          // only happens for the first line <REAPER_PROJECT
                {
                    currentNode.addChild(newNode);
                }
                currentNode = newNode;                      // Set the current node
            }
            else if (cl.Contains(">"))
            {
                currentNode = currentNode.parent != null ? currentNode.parent : currentNode;
            }
            else if (currentNode != null)
            {
                currentNode.addChild(new ReaperNode(cl, currentNode, parser));
            }

            currentLine++;

            if (currentLine < contentLines.Length)
            {
                Parse(currentNode, this);
            }

            return(currentNode);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:UnityReaperParser.ReaperParser"/> class.
        /// </summary>
        /// <param name="path">The Absolute Path to the Reaper File .rpp.</param>
        public ReaperParser(string path)
        {
            // Read File and store it to member content
            try
            {
                StreamReader sf = new StreamReader(path);
                this.content      = sf.ReadToEnd();
                this.contentLines = content.Split('\n');
                rpp            = Parse(null, this);
                this.path      = path;
                this.directory = Path.GetDirectoryName(path);

                isValid = true;
            }
            catch (Exception e)
            {
                isValid = false;
                Debug.LogError(e.ToString());
            }
        }
Ejemplo n.º 4
0
// public:

        /// <summary>
        /// Initializes a new instance of the <see cref="T:ReaperNode"/> class.
        /// </summary>
        /// <param name="text">The current line as a string from the reaper file.</param>
        /// <param name="parent">The parent node. Pass null if there is no parent.</param>
        /// <param name="parser">The parsing instance of ReaperParser.</param>
        public ReaperNode(string text, ReaperNode parent, ReaperParser parser)
        {
            this.children = new List <ReaperNode>();
            this.parser   = parser;
            this.parent   = parent;
            text          = text.Trim();

            var matches   = Regex.Matches(text, "(\"[^\"]*\"|[\\S]+)");                   // split the values
            var matchList = matches.Cast <Match>().Select(match => match.Value).ToList(); // convert matches to string list

            matchList = matchList.Select(s => s.Trim(new char[] { ' ', '\"', '<', '>' })).ToList();



            /*
             * Try to parse the first element of matches as a float. If it is a
             * number, the node has no type but only values. if it is not a
             * number, the first element is the type of the node.
             */

            try
            {
                var num = float.Parse(matchList[0]);
                type   = "";
                values = matchList;
            }
            catch
            {
                if (matchList.Count > 0)
                {
                    type = matchList[0];
                    matchList.RemoveAt(0);
                    values = matchList;
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds a child.
 /// </summary>
 /// <param name="o">O.</param>
 public void addChild(ReaperNode o)
 {
     children.Add(o);
 }