예제 #1
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);
        }
예제 #2
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());
        }
예제 #3
0
        IEnumerator LoadAudio()
        {
            var tracks = rpp.GetNodes("TRACK");

            /*
             * Iterate through all the tracks in the reaper file. Then
             * find the corresponding Gameobject in the Unity Scene. Load the
             * first item on the track and assign it to the corresponding
             * GameObject in the scene.
             *
             * This is an example how to create your own middleware using
             * UnityReaperParser. Here we use the names of the GameObjects
             * and the names of the tracks in reaper to assign audio to
             * AudioSources. This one is aasy, but there are no limits to
             * your creativity.
             */

            var reaperObject = GameObject.Find("Reaper");

            foreach (var t in tracks)
            {
                var name_ = t.GetNode("NAME").value;
                var item_ = t.GetNode("ITEM");

                var g = new GameObject(name_);
                g.transform.parent = reaperObject.transform;
                g.AddComponent <AudioSource>();

                //var g = GameObject.Find(name_);

                if (item_ == null || g == null)
                {
                    continue;
                }

                var src_ = g.GetComponent <AudioSource>();

                if (src_ == null)
                {
                    continue;
                }

                var container = new ReaperParser.Container <AudioClip>();
                yield return(ReaperParser.LoadAudioFromDisk(item_, container));

                src_.clip = container.t;
                src_.loop = item_.GetNode("LOOP").value == "1" ? true : false;
                src_.Play();
            }
        }
예제 #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;
                }
            }
        }