Beispiel #1
0
    IEnumerator Start()
    {
        isInitialized = false;

        // wait for csound to be initialized
        while (!csoundUnity.IsInitialized)
        {
            yield return(null);
        }

        csoundUnity.SetChannel("BPM", BPM);

        var count = 0;

        foreach (var clip in clips)
        {
            var name = "Samples/" + clip.name;

            Debug.Log("loading clip " + name);
            var samples = CsoundUnity.GetSamples(name, CsoundUnity.SamplesOrigin.Resources);
            Debug.Log("samples read: " + samples.Length);
            if (samples.Length > 0)
            {
                var nChan = clip.channels;
                var tn    = 900 + count;
                var res   = csoundUnity.CreateTable(tn, samples);
                //Debug.Log($"creating table: sampletable{tn}");
                csoundUnity.SetChannel($"sampletable{tn}", tn);
                Debug.Log(res == 0 ? $"<color=green>Table {tn} created, set channel sampletable{tn} = {tn} </color>" : $"<color=red>Error: Couldn't create Table {tn} </color>");
                count++;
            }
            yield return(new WaitForEndOfFrame());
        }

        if (showSequencerGUI)
        {
            pads = new GameObject[numpads];
            for (int voice = 0; voice < numberOfVoices; voice++)
            {
                for (int beat = 0; beat < numberOfBeats; beat++)
                {
                    GameObject gObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    gObj.transform.position   = new Vector3(beat - numberOfBeats + 8f, numberOfVoices - voice - 4f, 0);
                    gObj.transform.localScale = new Vector3(0.5f, 0.5f, 0.1f);
                    double enabled = csoundUnity.GetTableSample(voice + 1, beat);
                    gObj.GetComponent <Renderer>().material.color = (enabled == 1 ? new Color(1, 0, 0) : new Color(.5f, .5f, .5f));
                    gObj.AddComponent <PadController>();
                    gObj.name = padIndex++.ToString();
                    pads[beat + (voice * numberOfBeats)] = gObj;
                }
            }
        }
        //padScale = pads[0].transform.localScale;

        isInitialized = true;
        Debug.Log("start end!");
    }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        csoundUnity = GameObject.Find("CsoundUnity").GetComponent <CsoundUnity>();
        if (!csoundUnity)
        {
            Debug.LogError("Can't find CsoundUnity?");
        }

        var name = "Samples/" + audioClip.name;

        var samplesStereo = CsoundUnity.GetSamples(name, CsoundUnity.SamplesOrigin.Resources, 1, true);
        var samplesMono   = CsoundUnity.GetSamples(name, CsoundUnity.SamplesOrigin.Resources, 1, false);

        if (csoundUnity.CreateTable(9000, samplesStereo) == -1)
        {
            Debug.LogError("Couldn't create table");
        }
        if (csoundUnity.CreateTable(9001, samplesMono) == -1)
        {
            Debug.LogError("Couldn't create table");
        }
    }