コード例 #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!");
    }