コード例 #1
0
        public static void SendRawData(uint port, byte[] data)
        {
            if (!_init)
            {
                //setup values
                Initialize();

                //if initialization did not happen, print error message
                if (!_init)
                {
                    //if something went wrong, print error
                    Debug.LogError("Data to MIDI not sent!\n An error occured during the Initialization process!");
                    return;
                }
            }
            //check if port is valid
            if (port < OutPorts.Length)
            {
                //send message
                MidiInternal.rtmidi_out_send_message(OutPorts[port], data, data.Length);
            }
            else
            {
                Debug.LogError("Device port #" + port + " is invalid for output!");
            }
        }
コード例 #2
0
ファイル: cool.cs プロジェクト: lopea/VFXGraphSandbox
    // Update is called once per frame
    void Update()
    {
        list = new List <byte>();

        for (int i = 0; i < header.Length; i++)
        {
            list.Add(header[i]);
        }
        list.Add(15);
        list.Add(0);
        for (int i = 0; i < circles.Count; i++)
        {
            if (circles[i].timer >= 100)
            {
                circles.RemoveAt(i);
            }
            var data = circles[i];
            data.timer += Time.deltaTime * 30;
            circles[i]  = data;
        }
        for (int i = 0, y = 0; y < 10; y++)
        {
            for (int x = 0; x < 10; x++, i++)
            {
                //reset color
                colors[i] = Color.black;



                for (int j = 0; j < circles.Count; j++)
                {
                    float dist = Vector2.Distance(new Vector2(x, y), circles[j].center);
                    Color col  = gradient.Evaluate(Mathf.Sin(dist + Time.time * 30) / 2 + 0.5f);
                    if (Mathf.Abs(dist - circles[j].timer) < 1)
                    {
                        colors[i] = col;
                    }
                }
                //Color col = gradient.Evaluate(Mathf.Sin((x + y + Time.time) * Mathf.PI)); // checkerboard pattern


                list.Add((byte)(colors[i].r * 62));
                list.Add((byte)(colors[i].g * 62));
                list.Add((byte)(colors[i].b * 62));
            }
        }

        list.Add(247);
        MidiInternal.rtmidi_out_send_message(o, list.ToArray(), list.Count);

        //store pointers
        IntPtr message = IntPtr.Zero;
        IntPtr size    = IntPtr.Zero;

        //allocate pointers
        size    = Marshal.AllocHGlobal(4);
        message = Marshal.AllocHGlobal(1024);

        // useful code right here
        while (true)
        {
            //get data from Midi device
            MidiInternal.rtmidi_in_get_message(ptr, message, size);

            //store size of message
            int s = Marshal.ReadInt32(size);

            //check if no message is sent
            if (s == 0)
            {
                //de-allocate and exit loop
                Marshal.FreeHGlobal(message);
                Marshal.FreeHGlobal(size);
                break;
            }

            //change center position
            byte[] data = new byte[s];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = Marshal.ReadByte(message, i);
            }

            //change center
            changeCenter(data);
        }
    }