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); }
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; }
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; }
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); } }
// 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); }
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]); } } } }
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; }
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)); } }
public WhyFireMidiVisualizer( Configuration config, MidiInput midi, WhyFireOutput whyFire ) { this.config = config; this.midi = midi; this.whyFire = whyFire; this.whyFire.RegisterVisualizer(this); }
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(); }
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); }
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(); }
void Awake() { instance = this; notes = new float[128]; knobs = new Dictionary<int, Knob> (); #if UNITY_EDITOR messageHistory = new Queue<MidiMessage> (); #endif }
void Awake() { instance = this; learnt = -1; }