상속: MonoBehaviour
예제 #1
0
        public static bool Initialize()
        {
            if (_initialized)
            {
                return(true);
            }

            var portCount = MidiInput.GetPortCount();

            if (portCount == 0)
            {
                return(false);
            }

            devices = new IntPtr[portCount];
            for (uint i = 0; i < portCount; i++)
            {
                devices[i] = MidiInternal.rtmidi_in_create_default();
                MidiInternal.rtmidi_in_ignore_types(devices[i], true, false, false);
                MidiInternal.rtmidi_open_port(devices[i], i, "Why am i doing this? " + i);
            }

            startTime = EditorApplication.timeSinceStartup;
            EditorApplication.update += Update;
            EditorApplication.playModeStateChanged += EditorApplicationOnplayModeStateChanged;
            _initialized = true;
            return(true);
        }
예제 #2
0
    IEnumerator Start()
    {
        message = "MOVE THE 1ST\nCONTROLLER.";

        MidiInput.StartLearn();
        while (MidiInput.LearntChannel < 0)
        {
            yield return(null);
        }

        rackets [0].channel = MidiInput.LearntChannel;
        rackets [0].gameObject.SetActive(true);

        message = "THEN, THE 2ND\nONE PLEASE.";

        while (true)
        {
            MidiInput.StartLearn();
            while (MidiInput.LearntChannel < 0)
            {
                yield return(null);
            }
            if (MidiInput.LearntChannel != rackets [0].channel)
            {
                break;
            }
            yield return(null);
        }

        rackets [1].channel = MidiInput.LearntChannel;
        rackets [1].gameObject.SetActive(true);

        manager.SetActive(true);
        enabled = false;
    }
예제 #3
0
파일: VFXTest.cs 프로젝트: lopea/LopeaMidi
    void Update()
    {
        var main = vs.main;
        var size = vs.sizeOverLifetime;

        if (MidiInput.OnMidi(OnPulse))
        {
            main.startSizeMultiplier = 3;
            size.sizeMultiplier     += 0.3f;
        }

        if (main.startSizeMultiplier > 1)
        {
            main.startSizeMultiplier -= Time.deltaTime * 6;
        }
        else
        {
            main.startSizeMultiplier = 1;
        }

        float t = Mathf.InverseLerp(1, 3, main.startSizeMultiplier);

        main.startColor     = Color.Lerp(Color.white, HighlightedColor, t);
        size.sizeMultiplier = Mathf.Lerp(1, 1.3f, t);
        var v = vs.noise;

        v.frequency = v.strengthMultiplier = 6 * MidiInput.GetMidiValue(OnShake) / (float)MidiInput.MaxMidiValue;
    }
예제 #4
0
        public bool OpenDevice(string name = null)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(name))
                {
                    _info = MidiDeviceManager.AllDevices.FirstOrDefault(device =>
                                                                        device.IsInput && device.Name.ToLower().Contains(name.ToLower()));
                }
                else
                {
                    _info = MidiDeviceManager.AllDevices.FirstOrDefault(device =>
                                                                        device.ID == MidiDeviceManager.DefaultInputDeviceId);
                }

                _input = MidiDeviceManager.OpenInput(_info.ID);
                _input.SetFilter(MidiFilter.Active | MidiFilter.SysEx | MidiFilter.Clock | MidiFilter.Play | MidiFilter.Tick | MidiFilter.Undefined | MidiFilter.Reset | MidiFilter.RealTime | MidiFilter.AF | MidiFilter.Program | MidiFilter.PitchBend | MidiFilter.SystemCommon);
                _data = new byte[1024];
                return(true);
            }
            catch (Exception e)
            {
                #if VRC_CLIENT
                VRC.Core.Logger.LogError($"Error opening Default Device: {e.Message}");
                #else
                Debug.Log($"Error opening Default Device: {e.Message}");
                #endif
                return(false);
            }
        }
예제 #5
0
파일: Rotator.cs 프로젝트: lopea/LopeaMidi
    // Update is called once per frame
    void Update()
    {
        float midi = (MidiInput.GetMidiValue(OnRotate) / (float)MidiInput.MaxMidiValue);

        currrot           += midi * speed * Time.deltaTime;
        transform.rotation = Quaternion.Euler(axis * currrot);
    }
예제 #6
0
    public void checkDials(bool refresh)
    {
        int q = -1;

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                ++q;
                if (refresh || !(MidiInput.GetKnob(dialID [q], MidiInput.Filter.Realtime) * mult).Equals(prevDials [i, j]))
                {
                    dials [i, j]     = (prevDials[i, j] * 10 + MidiInput.GetKnob(dialID [q], MidiInput.Filter.Realtime) * mult) / 11;
                    prevDials [i, j] = dials[i, j];
                }
                if (refresh || !(MidiInput.GetKnob(knobID [q], MidiInput.Filter.Realtime) * mult).Equals(prevKnobs [i, j]))
                {
                    knobs [i, j]     = (prevKnobs[i, j] * 10 + MidiInput.GetKnob(knobID [q], MidiInput.Filter.Realtime) * mult) / 11;
                    prevKnobs [i, j] = knobs[i, j];
                }
                if (i < 2)
                {
                    buttons [i, j] =
                        MidiInput.GetKey(buttonID[q]);
                }
            }
        }
    }
예제 #7
0
        private static void UpdateDevices()
        {
            int count = MidiInput.Count;

            CloseAllConnections();

            int index = 0;

            foreach (string dev in MidiInput.GetDeviceList())
            {
                if (Maps.ContainsKey(dev))
                {
                    MidiMap map      = Maps[dev];
                    int     outIndex = MidiOutput.GetDeviceIdByName(dev);
                    map.ConnectDevice(index, outIndex);
                }
                else
                {
                    // Can't find map so create a new default map
                    MidiMap map = new MidiMap();
                    map.Name  = dev;
                    map.Dirty = true;
                    int outIndex = MidiOutput.GetDeviceIdByName(dev);
                    map.ConnectDevice(index, outIndex);
                    map.UpdateMapLinks();
                    Maps[map.Name] = map;
                }
                index++;
            }
            MidiSetup.UpdateDeviceList();

            MidiInputCount = count;
        }
예제 #8
0
        public InputsUi()
        {
            InitializeComponent();
            inputStack.Children.Add(new PcKeyboardUi(KeyboardInput.singleton1));
            var allMidis = MidiInput.getAllObject();

            foreach (var midi in allMidis)
            {
                inputStack.Children.Add(new MidiInUi(midi));
            }
        }
예제 #9
0
 public WhyFireMidiVisualizer(
     Configuration config,
     MidiInput midi,
     WhyFireOutput whyFire
     )
 {
     this.config  = config;
     this.midi    = midi;
     this.whyFire = whyFire;
     this.whyFire.RegisterVisualizer(this);
 }
예제 #10
0
파일: midiLaserer.cs 프로젝트: dlobser/prt
    void objSwitcher()
    {
        for (int i = 0; i < things.Length; i++)
        {
            if (MidiInput.GetKey(i + 23) > .5f)
            {
                switch3DObject(i);
            }
//			print (MidiInput.GetKey (i + 23)+" , " +  (i+ 23));
        }
    }
 public LEDDomeMidiTestVisualizer(
     Configuration config,
     MidiInput midi,
     LEDDomeOutput dome
     )
 {
     this.config = config;
     this.midi   = midi;
     this.dome   = dome;
     this.dome.RegisterVisualizer(this);
     this.strutStates = new Dictionary <int, int>();
     this.rand        = new Random();
 }
예제 #12
0
        private static void Update()
        {
            if (!_initialized)
            {
                return;
            }
            if (EditorApplication.isPlaying ||
                EditorApplication.timeSinceStartup - startTime > 10 ||
                devices.Length != MidiInput.GetPortCount())
            {
                OnNextNote?.Invoke(new MidiID(-1, -1, -1, MidiStatus.Dummy));
                Shutdown();
                return;
            }

            IntPtr messages = Marshal.AllocHGlobal(1024);
            IntPtr size     = Marshal.AllocHGlobal(4);

            for (int i = 0; i < devices.Length; i++)
            {
                while (true)
                {
                    Marshal.WriteInt32(size, 1024);

                    MidiInternal.rtmidi_in_get_message(devices[i], messages, size);
                    if (Marshal.ReadInt32(size) == 0)
                    {
                        break;
                    }

                    byte[] m = new byte[Marshal.ReadInt32(size)];
                    Marshal.Copy(messages, m, 0, m.Length);
                    var status = (MidiStatus)((m[0] >> 4));

                    if (status == MidiStatus.NoteOff)
                    {
                        status = MidiStatus.NoteOn;
                    }

                    OnNextNote?.Invoke(new MidiID(m[0] & 0x0F, m[1], i, status));
                    Shutdown();
                    Marshal.FreeHGlobal(size);
                    Marshal.FreeHGlobal(messages);
                    return;
                }
            }
            //deallocate pointers
            Marshal.FreeHGlobal(size);
            Marshal.FreeHGlobal(messages);
        }
예제 #13
0
        static void Main(string[] args)
        {
            var input = new MidiInput();

            input.MidiDataReceived += Input_MidiDataReceived;
            Console.WriteLine(MidiInput.GetNumDevices());
            foreach (var device in MidiInput.GetDevices())
            {
                Console.WriteLine(device.Name);
            }
            Console.WriteLine(input.Initialize(1));
            input.Start();
            Console.WriteLine(input.Name);
            Console.ReadKey();
        }
예제 #14
0
파일: MidiInput.cs 프로젝트: TravisDean/MEZ
 void Awake()
 {
     instance = this;
     notes = new float[128];
     knobs = new Dictionary<int, Knob> ();
     #if UNITY_EDITOR
     messageHistory = new Queue<MidiMessage> ();
     #endif
 }
예제 #15
0
 void Awake()
 {
     instance = this;
     learnt = -1;
 }