/// <summary> /// sets specific LEDs in a single message. /// Note: due to the nature of sysex messages, the max amount of LEDs to light up is 78. /// </summary> /// <param name="port">port number the launchpad pro is located.</param> /// <param name="notes">all the note numbers to send messages to.</param> /// <param name="color">Color to set all the values given.</param> public static void setMultipleSpecificNoteLED(uint port, byte[] notes, Color color) { if (notes.Length == 0 || notes == null) { return; } if (notes.Length > 78) { Debug.LogWarning("setMultiplSpecificLED() can only send 78 different note values at once!"); } byte[] result; byte[] col = { (byte)(color.r * 63), (byte)(color.g * 63), (byte)(color.b * 63) }; //set up sysex message StartSysex(out result); //setup sysexMessage to send multiple LED AddSysex(ref result, 11); //add every note to desired color for (int i = 0; i < 78; i++) { AddSysex(ref result, notes[i]); AddSysex(ref result, col); } //end sysex message EndSysex(ref result); //send message MidiOutput.SendRawData(port, result); }
public static void setMultipleNoteLEDGrid(uint port, LaunchpadGridType type, Color[] colors) { //set the amount of led to light int size = (type == LaunchpadGridType.Full) ? 100 : 64; byte[] result; StartSysex(out result); //specify that message is a grid led message AddSysex(ref result, 15); //specify the grid type AddSysex(ref result, (byte)type); //add all the colors for (int i = 0; i < size; i++) { //if the array is too small, quit if (i >= colors.Length) { break; } byte[] col = { (byte)(colors[i].r * 63), (byte)(colors[i].g * 63), (byte)(colors[i].b * 63) }; AddSysex(ref result, col); } //end sysex message EndSysex(ref result); //send message MidiOutput.SendRawData(port, result); }
/// <summary> /// sets an LED to a predetermined color based on a number from 0-127 /// </summary> /// <param name="port">port where the launchpad is located</param> /// <param name="note">note value coresponding to the LED that is lit</param> /// <param name="color">value from 0-127 that will light up the LED</param> public static void setSingleNoteLED(int port, byte note, byte color) { byte[] data = { 144, note, color }; MidiOutput.SendRawData((uint)port, data); }
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; }
/// <summary> /// Set multiple leds with a single color using the launchpad's standard color format. /// The amount of LEDs to set is limited to 78 leds per message using this method. /// </summary> /// <param name="port">number representing the location of the Launchpad.</param> /// <param name="notes">the note numbers representing the LED to set</param> /// <param name="color">color to set all the LEDs to (0-127)</param> /// <param name="type">type of LED status to use</param> public static void SetNoteLEDs(uint port, byte[] notes, byte color, LaunchpadNoteType type = LaunchpadNoteType.Basic) { if (notes.Length == 0) { return; } if (notes.Length > 78) { Debug.LogWarning("SetNoteLEDs() can only send 78 different note values at once!"); } byte[] result; //set up sysex message StartSysex(out result); //set the type of led to light up AddSysex(ref result, (byte)type); //add every note to desired color for (int i = 0; i < notes.Length; i++) { //break when limit is reached. if (i >= 78) { return; } AddSysex(ref result, notes[i]); AddSysex(ref result, color); } //end sysex message EndSysex(ref result); //send message MidiOutput.SendRawData(port, result); }
/// <summary> /// Yes, this device can display text. /// The text will scroll across the launchpad with color given (0-127). /// The speed of the text can vary by using escape characters(\x01 = slowest speed, \x07 = fastest) /// inside the text itself. /// </summary> /// <param name="port">Port that the launchpad pro is located.</param> /// <param name="text">Text to display in the launchpad</param> /// <param name="color">Color the text is going to be</param> /// <param name="loop">set the text to loop across the screen</param> public static void SendText(uint port, string text, byte color, bool loop = false) { //TODO: Optimize this code ffs //set string to be ascii text byte[] AsciiText = Encoding.ASCII.GetBytes(text); //store sysEx message byte[] result; //initialize message StartSysex(out result); //specify message is text AddSysex(ref result, 20); //specify color AddSysex(ref result, color); //add loop status AddSysex(ref result, (byte)(loop ? 1 : 0)); //add text AddSysex(ref result, AsciiText); //end message EndSysex(ref result); //send message MidiOutput.SendRawData(port, result); }
/// <summary> /// sets an LED to a predetermined color based on a number from 0-127 /// </summary> /// <param name="port">port where the launchpad is located</param> /// <param name="note">note value coresponding to the LED that is lit</param> /// <param name="color">value from 0-127 that will light up the LED</param> /// <param name="type">sets the type of LED state for the launchpad, Basic = on, flashing = flashing with Midi clock, pulsing = pulsing with midiClock</param> public static void SetNoteLED(uint port, byte note, byte color, LaunchpadNoteType type = LaunchpadNoteType.Basic) { byte[] result; byte[] data = { (byte)type, note, color }; StartSysex(out result); AddSysex(ref result, data); EndSysex(ref result); MidiOutput.SendRawData(port, data); }
public static void ClearAllLEDs(uint port) { //start sysex byte[] result; StartSysex(out result); byte[] clear = { 14, 0 }; AddSysex(ref result, clear); EndSysex(ref result); MidiOutput.SendRawData(port, result); }
private void octaveUp() { if (KeyOffset < 95) { KeyOffset += 12; } PianoController.Redraw(); MidiOutput.play(KeyOffset); Console.WriteLine("current octave: " + CurrentOctave().ToString()); }
private void midiInReceived(object sender, MidiInMessageEventArgs e) { if (e.MidiEvent == null) { return; } NoteEvent noteEvent; try { noteEvent = (NoteEvent)e.MidiEvent; } catch (Exception) { Console.WriteLine("midicontroller exc"); return; } if (MidiEvent.IsNoteOn(e.MidiEvent)) { int calculatedNote = offsetNote(noteEvent.NoteNumber, KeyboardController.KeyOffset); MidiOutput.play(calculatedNote); if (currentlyPressedKeys.ContainsKey(calculatedNote)) { return; } if (Guide == null) { return; } currentlyPressedKeys.Add(calculatedNote, GuidesController.StopWatch.ElapsedMilliseconds); Guide.ActiveKeys = currentlyPressedKeys; Guide.UpdatePianoKeys(); //Thread.Sleep inside GUI is just for example } else { int calculatedNote = offsetNote(noteEvent.NoteNumber, KeyboardController.KeyOffset); MidiOutput.stop(calculatedNote); if (Guide == null) { return; } currentlyPressedKeys.Remove(calculatedNote); Guide.ActiveKeys = currentlyPressedKeys; Guide.UpdatePianoKeys(); } }
public static void SetLEDsByLine(uint port, LaunchpadLineType type, uint lineIndex, byte color) { if (lineIndex > 9) { lineIndex = 9; } byte[] result; StartSysex(out result); byte[] data = { (byte)type, (byte)lineIndex, color }; AddSysex(ref result, data); EndSysex(ref result); MidiOutput.SendRawData(port, result); }
public void CloseDevice() { if (InputDevice != null) { InputDevice.Stop(); InputDevice.Close(); InputDevice = null; } if (OutputDevice != null) { OutputDevice.Close(); OutputDevice = null; } Connected = false; }
public static void SetAllLEDs(uint port, Color color) { byte[] result; StartSysex(out result); //specify that message is a grid led message AddSysex(ref result, 15); //specify the grid type AddSysex(ref result, 0); byte[] col = { (byte)(color.r * 63), (byte)(color.g * 63), (byte)(color.b * 63) }; for (int i = 0; i < 100; i++) { AddSysex(ref result, col); } EndSysex(ref result); MidiOutput.SendRawData(port, result); }
/// <summary> /// sets an note LED to a specific color given. /// </summary> /// <param name="port">Device port</param> /// <param name="note">Note number based on the LED to be lit</param> /// <param name="color">the color to set the LED</param> public static void setSingleNoteLED(int port, byte note, Color color) { //check if all parameters are valid if (port < 0 || port >= MidiInput.portCount) { return; } //set color data byte[] col = { (byte)(color.r * 63), (byte)(color.g * 63), (byte)(color.b * 63) }; //set data to send to launchpad byte[] result; StartSysex(out result); //send led color flag AddSysex(ref result, 11); AddSysex(ref result, note); AddSysex(ref result, col); EndSysex(ref result); //send data to launchpad pro. MidiOutput.SendRawData((uint)port, result); }
public void ConnectDevice(int index, int outputIndex) { InputDevice = new MidiInput(); if (InputDevice.Open(index)) { InputDevice.MessageReceived += new MidiMessageReceived(InputDevice_MessageReceived); InputDevice.Start(); Connected = true; } else { InputDevice = null; } OutputDevice = new MidiOutput(); if (OutputDevice.Open(outputIndex)) { Connected = true; } else { OutputDevice = null; } }
/// <summary> /// Get Output port based on the type of Launchpad pro state /// </summary> /// <param name="state"> the type of port to look for in the launchpad pro. </param> /// <returns>device port based on the type of state, MIDIOUTERROR if the launchpad was not found. </returns> public static uint GetOutputPort(LaunchpadProState state) { return(MidiOutput.FindPortByName(StateToNameOutput(state))); }
public void KeyDown(KeyEventArgs e) { int pressedKey = -1; switch (e.Key) { case Key.Q: pressedKey = KeyOffset; break; case Key.D2: pressedKey = KeyOffset + 1; break; case Key.W: pressedKey = KeyOffset + 2; break; case Key.D3: pressedKey = KeyOffset + 3; break; case Key.E: pressedKey = KeyOffset + 4; break; case Key.R: pressedKey = KeyOffset + 5; break; case Key.D5: pressedKey = KeyOffset + 6; break; case Key.T: pressedKey = KeyOffset + 7; break; case Key.D6: pressedKey = KeyOffset + 8; break; case Key.Y: pressedKey = KeyOffset + 9; break; case Key.D7: pressedKey = KeyOffset + 10; break; case Key.U: pressedKey = KeyOffset + 11; break; case Key.I: pressedKey = KeyOffset + 12; break; case Key.D9: pressedKey = KeyOffset + 13; break; case Key.O: pressedKey = KeyOffset + 14; break; case Key.D0: pressedKey = KeyOffset + 15; break; case Key.P: pressedKey = KeyOffset + 16; break; case Key.Z: pressedKey = KeyOffset + 17; break; case Key.S: pressedKey = KeyOffset + 18; break; case Key.X: pressedKey = KeyOffset + 19; break; case Key.D: pressedKey = KeyOffset + 20; break; case Key.C: pressedKey = KeyOffset + 21; break; case Key.F: pressedKey = KeyOffset + 22; break; case Key.V: pressedKey = KeyOffset + 23; break; case Key.B: pressedKey = KeyOffset + 24; break; case Key.H: pressedKey = KeyOffset + 25; break; case Key.N: pressedKey = KeyOffset + 26; break; case Key.J: pressedKey = KeyOffset + 27; break; case Key.M: pressedKey = KeyOffset + 28; break; case Key.OemComma: pressedKey = KeyOffset + 29; break; case Key.L: pressedKey = KeyOffset + 30; break; case Key.OemPeriod: pressedKey = KeyOffset + 31; break; case Key.Up: octaveUp(); break; case Key.Down: octaveDown(); break; } if (pressedKey < 0 || currentlyPressedKeys.ContainsKey(pressedKey)) { return; } MidiOutput.play(pressedKey); currentlyPressedKeys.Add(pressedKey, GuidesController.StopWatch.ElapsedMilliseconds); if (Guide == null) { return; } Guide.Piano.UpdatePressedPianoKeys(currentlyPressedKeys); Console.WriteLine("----------On----------"); Console.WriteLine(pressedKey.ToString()); }
public void KeyUp(KeyEventArgs e) { int pressedKey = -1; switch (e.Key) { case Key.Q: pressedKey = KeyOffset; break; case Key.D2: pressedKey = KeyOffset + 1; break; case Key.W: pressedKey = KeyOffset + 2; break; case Key.D3: pressedKey = KeyOffset + 3; break; case Key.E: pressedKey = KeyOffset + 4; break; case Key.R: pressedKey = KeyOffset + 5; break; case Key.D5: pressedKey = KeyOffset + 6; break; case Key.T: pressedKey = KeyOffset + 7; break; case Key.D6: pressedKey = KeyOffset + 8; break; case Key.Y: pressedKey = KeyOffset + 9; break; case Key.D7: pressedKey = KeyOffset + 10; break; case Key.U: pressedKey = KeyOffset + 11; break; case Key.I: pressedKey = KeyOffset + 12; break; case Key.D9: pressedKey = KeyOffset + 13; break; case Key.O: pressedKey = KeyOffset + 14; break; case Key.D0: pressedKey = KeyOffset + 15; break; case Key.P: pressedKey = KeyOffset + 16; break; case Key.Z: pressedKey = KeyOffset + 17; break; case Key.S: pressedKey = KeyOffset + 18; break; case Key.X: pressedKey = KeyOffset + 19; break; case Key.D: pressedKey = KeyOffset + 20; break; case Key.C: pressedKey = KeyOffset + 21; break; case Key.F: pressedKey = KeyOffset + 22; break; case Key.V: pressedKey = KeyOffset + 23; break; case Key.B: pressedKey = KeyOffset + 24; break; case Key.H: pressedKey = KeyOffset + 25; break; case Key.N: pressedKey = KeyOffset + 26; break; case Key.J: pressedKey = KeyOffset + 27; break; case Key.M: pressedKey = KeyOffset + 28; break; case Key.OemComma: pressedKey = KeyOffset + 29; break; case Key.L: pressedKey = KeyOffset + 30; break; case Key.OemPeriod: pressedKey = KeyOffset + 31; break; } if (pressedKey < 0 || !currentlyPressedKeys.ContainsKey(pressedKey)) { return; } currentlyPressedKeys.Remove(pressedKey); MidiOutput.stop(pressedKey); if (Guide == null) { return; } Guide.Piano.UpdatePressedPianoKeys(currentlyPressedKeys); Console.WriteLine("----------Off----------"); Console.WriteLine(pressedKey.ToString()); }
private static void SceneTrackPreferencesItem() { EditorGUILayout.BeginHorizontal(); if (GUILayout.Toggle(_currentTab == 0, "Recording", EditorStyles.miniButtonLeft)) { _currentTab = 0; } if (GUILayout.Toggle(_currentTab == 1, "Animation", EditorStyles.miniButtonMid)) { _currentTab = 1; } if (GUILayout.Toggle(_currentTab == 2, "Events", EditorStyles.miniButtonMid)) { _currentTab = 2; } if (GUILayout.Toggle(_currentTab == 3, "Video", EditorStyles.miniButtonMid)) { _currentTab = 3; } if (GUILayout.Toggle(_currentTab == 4, "About", EditorStyles.miniButtonRight)) { _currentTab = 4; } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); EditorGUILayout.BeginVertical(); switch (_currentTab) { case 1: FBXOutput.EditorPreferences(); break; case 2: MidiOutput.EditorPreferences(); break; case 3: VideoOutput.EditorPreferences(); break; case 4: About(); break; default: { EditorGUILayout.BeginVertical(); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Default", EditorStyles.miniButton)) { AppendRecordFrames = 2; MemoryReserveFramePool = 0; MemoryReserveFrameDataPool = 0; } EditorGUILayout.EndHorizontal(); OpenAfterExporting = EditorGUILayout.Toggle("Open Output after Exporting", OpenAfterExporting); EditorGUILayout.EndVertical(); GUILayout.FlexibleSpace(); EditorGUILayout.BeginVertical(); GUILayout.Label("Advanced Recording Settings", EditorStyles.boldLabel); AppendRecordFrames = Mathf.Clamp(EditorGUILayout.IntPopup("Save Frame Time", AppendRecordFrames, AppendRecordFramesStr, AppendRecordFramesInt), 1, 60); if (AppendRecordFrames > 2) { GUILayout.BeginHorizontal(); GUILayout.Label("Warning:\nLonger save times will result in increased memory usage.\nThis can cause reduced recording performance or errors.", EditorStyles.miniLabel); GUILayout.EndHorizontal(); } MemoryReserveFramePool = Mathf.Clamp(EditorGUILayout.IntField("Extra Frame Pools", MemoryReserveFramePool), 0, 16); MemoryReserveFrameDataPool = Mathf.Clamp(EditorGUILayout.IntField("Extra Frame Data Pools", MemoryReserveFrameDataPool), 0, 16); GUILayout.Space(60); EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical(); break; } } EditorGUILayout.EndVertical(); }