Exemplo n.º 1
0
        MidiMaster()
        {
            GameObject sourceGo = new GameObject("Midi Master Source");

            sourceGo.hideFlags = HideFlags.HideInHierarchy;
            _source            = sourceGo.AddComponent <MidiSource>();
            _source.endpointId = uint.MaxValue;

            GameObject destinationGo = new GameObject("Midi Master Destination");

            destinationGo.hideFlags = HideFlags.HideInHierarchy;
            _destination            = destinationGo.AddComponent <MidiDestination>();
            _destination.endpointId = uint.MaxValue;
        }
Exemplo n.º 2
0
        MidiMaster()
        {
            GameObject sourceGo = new GameObject("Midi Master Source");

            GameObject.DontDestroyOnLoad(sourceGo);
            sourceGo.hideFlags = HideFlags.HideInHierarchy;
            _source            = sourceGo.AddComponent <MidiSource>();
            _source.endpointId = Application.platform.Equals(RuntimePlatform.Android) ? 0 : uint.MaxValue;

            GameObject destinationGo = new GameObject("Midi Master Destination");

            GameObject.DontDestroyOnLoad(destinationGo);
            destinationGo.hideFlags = HideFlags.HideInHierarchy;
            _destination            = destinationGo.AddComponent <MidiDestination>();
            _destination.endpointId = Application.platform.Equals(RuntimePlatform.Android) ? 0 : uint.MaxValue;
        }
Exemplo n.º 3
0
        void Update()
        {
            if (Application.platform.Equals(RuntimePlatform.Android))
            {
                return;
            }

            while (true)
            {
                // Pop from the queue.
                var data = DequeueIncomingData();
                if (data == 0)
                {
                    break;
                }

                // Relay the message.
                var message = new MidiMessage(data);

                if (_sourceMap.ContainsKey(message.endpoint))
                {
                    MidiSource source = _sourceMap[message.endpoint];
                    source.msgQueue.Enqueue(message);
                }

                // Send to all?
                if (_sourceMap.ContainsKey(uint.MaxValue))
                {
                    MidiSource source = _sourceMap[uint.MaxValue];
                    source.msgQueue.Enqueue(message);
                }

                #if UNITY_EDITOR
                // Record the message.
                _totalMessageCount++;
                _messageHistory.Enqueue(message);
                #endif
            }

            #if UNITY_EDITOR
            // Truncate the history.
            while (_messageHistory.Count > 8)
            {
                _messageHistory.Dequeue();
            }
            #endif
        }
Exemplo n.º 4
0
 public static void AddSource(MidiSource source)
 {
     Instance._sourceMap[source.endpointId] = source;
 }