Exemple #1
0
    /**
     * CsoundUnity Awake function. Called when this script is first instantiated. This should never be called directly.
     * This functions behaves in more or less the same way as a class constructor. When creating references to the
     * CsoundUnity object make sure to create them in the scripts Awake() function.
     *
     * \code
     *  using UnityEngine;
     *  using System.Collections;
     *
     *  public class MyScript : MonoBehaviour
     *  {
     *      private CsoundUnity csoundUnity;
     *
     *      void Awake()
     *      {
     *          csoundUnity = Camera.main.GetComponent<CsoundUnity>();
     *      }
     *   }
     * \endcode
     */
    void Awake()
    {
        /* I M P O R T A N T
         *
         * Please ensure that all csd files reside in your Assets/Scripts directory
         *
         */
        string csoundFilePath = Application.streamingAssetsPath + "/" + csoundFile + "_";
        string dataPath       = Application.streamingAssetsPath;

        System.Environment.SetEnvironmentVariable("Path", Application.streamingAssetsPath);
        Debug.Log(Application.streamingAssetsPath);

        /*
         * the CsoundUnity constructor takes a path to the project's Data folder, and path to the file name.
         * It then calls createCsound() to create an instance of Csound and compile the 'csdFile'.
         * After this we start the performance of Csound. After this, we send the streaming assets path to
         * Csound on a string channel. This means we can then load samples contained within that folder.
         */
        csound = new CsoundUnityBridge(dataPath, csoundFilePath);

        csound.startPerformance();
        csound.setStringChannel("AudioPath", Application.dataPath + "/Assets/Audio/");

        /*
         * This method prints the Csound output to the Unity console
         */
        if (logCsoundOutput)
        {
            InvokeRepeating("logCsoundMessages", 0, .5f);
        }

        IDs       = new List <string>();
        fileNames = new List <string>();
    }
    /**
     * CsoundUnity Awake function. Called when this script is first instantiated. This should never be called directly.
     * This functions behaves in more or less the same way as a class constructor. When creating references to the
     * CsoundUnity object make sure to create them in the scripts Awake() function.
     *
     */
    void Awake()
    {
        /* I M P O R T A N T
         *
         * Please ensure that all csd files reside in your Assets/Scripts directory
         *
         */
        string csoundFilePath = Application.streamingAssetsPath + "/" + csoundFile + "_";
        string dataPath       = Application.streamingAssetsPath;
        string path           = System.Environment.GetEnvironmentVariable("Path");
        string updatedPath    = path + ";" + Application.streamingAssetsPath;

        System.Environment.SetEnvironmentVariable("Path", updatedPath);
        print("Updated path:" + updatedPath);
        audioSource = GetComponent <AudioSource>();
        channels    = new List <CsoundChannelController>();

        /*
         * the CsoundUnity constructor takes a path to the project's Data folder, and path to the file name.
         * It then calls createCsound() to create an instance of Csound and compile the 'csdFile'.
         * After this we start the performance of Csound. After this, we send the streaming assets path to
         * Csound on a string channel. This means we can then load samples contained within that folder.
         */
        csound = new CsoundUnityBridge(dataPath, csoundFilePath);

        channels = parseCsdFile(csoundFilePath);
        //initialise channels if found in xml descriptor..
        for (int i = 0; i < channels.Count; i++)
        {
            //print("Channel:"+channels[i].channel + " Value:" + channels[i].value.ToString());
            csound.setChannel(channels[i].channel, channels[i].value);
        }


        /*
         * This method prints the Csound output to the Unity console
         */
        if (logCsoundOutput)
        {
            InvokeRepeating("logCsoundMessages", 0, .5f);
        }

        compiledOk = csound.compiledWithoutError();

        if (compiledOk)
        {
            csound.setStringChannel("AudioPath", Application.dataPath + "/Audio/");
            if (Application.isEditor)
            {
                csound.setStringChannel("CsoundFiles", Application.dataPath + "/CsoundFiles/");
            }
            else
            {
                csound.setStringChannel("CsoundFiles", Application.streamingAssetsPath + "/CsoundFiles/");
            }
            csound.setStringChannel("StreamingAssets", Application.streamingAssetsPath);
        }
    }
Exemple #3
0
    /**
     * CsoundUnity Awake function. Called when this script is first instantiated. This should never be called directly.
     * This functions behaves in more or less the same way as a class constructor. When creating references to the
     * CsoundUnity object make sure to create them in the scripts Awake() function.
     *
     * \code
        using UnityEngine;
        using System.Collections;

        public class MyScript : MonoBehaviour
        {
            private CsoundUnity csoundUnity;

            void Awake()
            {
                csoundUnity = Camera.main.GetComponent<CsoundUnity>();
            }
         }
         * \endcode
     */
    void Awake()
    {
        /* I M P O R T A N T
        *
        * Please ensure that all csd files reside in your Assets/Scripts directory
        *
        */
        string csoundFilePath = Application.streamingAssetsPath + "/" + csoundFile + "_";
        string dataPath = Application.streamingAssetsPath;
        System.Environment.SetEnvironmentVariable("Path", Application.streamingAssetsPath);
        Debug.Log(Application.streamingAssetsPath);
        /*
         * the CsoundUnity constructor takes a path to the project's Data folder, and path to the file name.
         * It then calls createCsound() to create an instance of Csound and compile the 'csdFile'.
         * After this we start the performance of Csound. After this, we send the streaming assets path to
         * Csound on a string channel. This means we can then load samples contained within that folder.
         */
        csound = new CsoundUnityBridge(dataPath, csoundFilePath);

        csound.startPerformance();
        csound.setStringChannel("AudioPath", Application.dataPath + "/Assets/Audio/");

        /*
         * This method prints the Csound output to the Unity console
         */
        if (logCsoundOutput)
            InvokeRepeating("logCsoundMessages", 0, .5f);

        IDs = new List<string>();
        fileNames = new List<string>();
    }
Exemple #4
0
    /**
     * CsoundUnity Awake function. Called when this script is first instantiated. This should never be called directly.
     * This functions behaves in more or less the same way as a class constructor. When creating references to the
     * CsoundUnity object make sure to create them in the scripts Awake() function.
     *
     */
    void Awake()
    {
        /* I M P O R T A N T
        *
        * Please ensure that all csd files reside in your Assets/Scripts directory
        *
        */
        string csoundFilePath = Application.streamingAssetsPath + "/" + csoundFile + "_";
        string dataPath = Application.streamingAssetsPath;
        System.Environment.SetEnvironmentVariable("Path", Application.streamingAssetsPath);
        channels = new List<CsoundChannelController>();
        /*
         * the CsoundUnity constructor takes a path to the project's Data folder, and path to the file name.
         * It then calls createCsound() to create an instance of Csound and compile the 'csdFile'.
         * After this we start the performance of Csound. After this, we send the streaming assets path to
         * Csound on a string channel. This means we can then load samples contained within that folder.
         */
        csound = new CsoundUnityBridge(dataPath, csoundFilePath);

        channels = parseCsdFile(csoundFilePath);
        //initialise channels if found in xml descriptor..
        for(int i=0;i<channels.Count;i++)
        {
            //print("Channel:"+channels[i].channel + " Value:" + channels[i].value.ToString());
            csound.setChannel(channels[i].channel, channels[i].value);
        }

        /*
         * This method prints the Csound output to the Unity console
         */
        if (logCsoundOutput)
            InvokeRepeating("logCsoundMessages", 0, .5f);

        compiledOk = csound.compiledWithoutError();

        if(compiledOk)
            csound.setStringChannel("AudioPath", Application.dataPath + "/Assets/Audio/");
    }