public static void SendNextMidiOutMessage(int message, int note, int velocity) { //byte[] onCommand = { 0x90, 0x3C, 0x7F }; //Standard Values for Midi On, C5, and 127 Velocity byte[] onCommand = { (byte)message, (byte)note, (byte)velocity }; port.sendCommand(onCommand); }
public static void WorkThreadFunction() { byte[] command; try { while (true) { command = port.getCommand(); port.sendCommand(command); var arrayToString = byteArrayToString(command); if (arrayToString.Length < 2) { continue; } if (arrayToString == "90, 0x02, 0x4D" || arrayToString == "90, 0x04, 0x0D" || arrayToString == "90, 0x03, 0x0D") { continue; } Console.WriteLine("byteList.Add(new byte[] {0x" + arrayToString + "});"); } } catch (Exception ex) { Console.WriteLine("thread aborting: " + ex.Message); } }
private static void WorkThreadFunction(TeVirtualMIDI port) { while (true) { port.sendCommand(port.getCommand()); } }
public void SendReceiveMIDI() { byte[] command; try { while (true) { command = midiPort.getCommand(); midiPort.sendCommand(command); //Debug.Log("command: " + byteArrayToString(command)); } } catch (Exception ex) { Debug.Log("Fail while sending / retrieving message: " + ex.Message); } }
private static void RedirectorRun() { byte[] command; try { while (true) { command = _port.getCommand(); _port.sendCommand(command); } } catch (Exception ex) { System.Console.WriteLine("thread aborting: " + ex.Message); } }
public static void WorkThreadFunction() { byte[] command; try { while (true) { command = port.getCommand(); port.sendCommand(command); Console.WriteLine("command: " + byteArrayToString(command)); } } catch (Exception ex) { Console.WriteLine("thread aborting: " + ex.Message); } }
private static void WorkThreadFunction() { byte[] command; try { port = new TeVirtualMIDI("Midi Visualizer"); Console.WriteLine("Virtual port created"); while (true) { command = port.getCommand(); asi.processMidiCommand(command); // echo command port.sendCommand(command); Console.WriteLine("command: " + byteArrayToString(command)); } } catch (Exception ex) { Console.WriteLine("thread aborting: " + ex.Message); } }
private void MIDIInputReceived(object sender, MIDIMessage e) { var msgBytes = BitConverter.GetBytes(e.wMsg); var param1bytes = BitConverter.GetBytes(e.dwParam1); var param2bytes = BitConverter.GetBytes(e.dwParam2); var command = param1bytes[0]; var note = param1bytes[1]; var velocity = param2bytes[2]; Log($"Received local MIDI data: 0x{e.dwParam1.ToString("X")}"); // Loopback MIDI if (metroCheckBoxLoopbackMIDI.Checked) { vMIDI.sendCommand(e.Data); } // Check if connected if (client == null) { return; } if (client.Connected) { // Send data to remote Log("Sending data ..."); try { stream.Write(e.Data, 0, e.Data.Length); stream.Flush(); Log("Sent data!"); } catch (Exception ex) { Log("Couldn't send data! " + ex.Message); } } }
/// <summary> /// Evenement quand nouveaux message du APC40 /// </summary> /// <param name="sender"></param> /// <param name="e" ></param> private void _InputAPC40_ChannelMessageReceived(object sender, ChannelMessageEventArgs e) { _InputAPC40.StopRecording(); Log.writeLine("----------------------------------------------------------------------------"); Log.writeLine("Nouvelle Input : " + e.Message.Message); if (e.Message.Command == ChannelCommand.Controller) { if (e.Message.Data1 == 47 || e.Message.Data1 == 13) //Si Codeur { APC40_Code_ID _CODEID; bool _ISCLOCKWISE; _CODEID = (APC40_Code_ID)e.Message.Data1; if (e.Message.Data2 == 127) { _ISCLOCKWISE = false; } else { _ISCLOCKWISE = true; } if (APC40_Code_Input != null) { APC40_Code_Input(this, new APC40InputCodeEventArgs { CodeID = _CODEID, IsClockWise = _ISCLOCKWISE }); } } else { if (e.Message.Data1 == 7) //si fader groupé { int _CHANNEL; int _VALUE; _CHANNEL = e.Message.MidiChannel; _VALUE = e.Message.Data2; if (APC40_GroupedFader_Input != null) { APC40_GroupedFader_Input(this, new APC40InputGroupedFaderEventArgs { channel = _CHANNEL, value = _VALUE }); } } else //Si Potentiometre { APC40_pot_ID _POTID; int _VALUE; _POTID = (APC40_pot_ID)e.Message.Data1; _VALUE = e.Message.Data2; if (APC40_Pot_Input != null) { APC40_Pot_Input(this, new APC40InputPotEventArgs { PotID = _POTID, value = _VALUE }); } } } } else { if ((e.Message.Data1 <= 52 && e.Message.Data1 >= 48) || e.Message.Data1 == 66) //Si Bouton groupé { APC40_GroupedButton_ID _GROUPEDBUTTONID; int _CHANNEL; bool _ISON; _GROUPEDBUTTONID = (APC40_GroupedButton_ID)e.Message.Data1; _CHANNEL = e.Message.MidiChannel; if (e.Message.Command == ChannelCommand.NoteOn) { _ISON = true; } else { _ISON = false; } if (APC40_GroupedButton_Input != null) { APC40_GroupedButton_Input(this, new APC40InputGroupedButtonEventArgs { GroupedButtonID = _GROUPEDBUTTONID, channel = _CHANNEL, isOn = _ISON }); } } else //Si Boutton { APC40_Button_ID _BUTTONID; bool _ISON; _BUTTONID = (APC40_Button_ID)e.Message.Data1; if (e.Message.Command == ChannelCommand.NoteOn) { _ISON = true; } else { _ISON = false; } if (APC40_Button_Input != null) { APC40_Button_Input(this, new APC40InputButtonEventArgs { ButtonID = _BUTTONID, isOn = _ISON }); } _virtualMidiPort.sendCommand(e.Message.GetBytes()); #region Mapping if (Mapping != null) { if (((int)_BUTTONID >= 0 && (int)_BUTTONID <= 39) || ((int)_BUTTONID >= 82 && (int)_BUTTONID <= 86)) //si Boutton avec Led RGB { RGBButton button = Mapping.RGBBT.Find(x => x.ID == (int)_BUTTONID); //récuperation du mapping du bouton if (_ISON) // si appui { if (button.Type == buttonType.Momentary) //si Bouton Momentanné { Led((RGB_Led)_BUTTONID, button.onFlashingtype, button.onprimaryColor, button.onsecondaryColor, button.onFlashingspeed); if (button.Groupe != -1) // si bouton groupé { foreach (RGBButton bt in Mapping.RGBBT) //on éteint tout les autres boutons du même groupe { if (bt.Groupe == button.Groupe && bt.ID != (int)_BUTTONID) { RGBButton samegroupebutton = Mapping.RGBBT.Find(x => x.ID == bt.ID); //on recupère le mapping du bouton du meme groupe Led((RGB_Led)bt.ID, samegroupebutton.offFlashingtype, samegroupebutton.offprimaryColor, samegroupebutton.offsecondaryColor, samegroupebutton.offFlashingspeed); samegroupebutton.IsOnToogle = false; } } } } if (button.Type == buttonType.Toogle) //si Bouton Toogle { if (button.IsOnToogle == true) { Led((RGB_Led)_BUTTONID, button.offFlashingtype, button.offprimaryColor, button.offsecondaryColor, button.offFlashingspeed); button.IsOnToogle = false; } else { Led((RGB_Led)_BUTTONID, button.onFlashingtype, button.onprimaryColor, button.onsecondaryColor, button.onFlashingspeed); button.IsOnToogle = true; if (button.Groupe != -1) // si bouton groupé { foreach (RGBButton bt in Mapping.RGBBT) //on éteint tout les autres boutons du même groupe { if (bt.Groupe == button.Groupe && bt.ID != (int)_BUTTONID) { RGBButton samegroupebutton = Mapping.RGBBT.Find(x => x.ID == bt.ID); //on recupère le mapping du bouton du meme groupe Led((RGB_Led)bt.ID, samegroupebutton.offFlashingtype, samegroupebutton.offprimaryColor, samegroupebutton.offsecondaryColor, samegroupebutton.offFlashingspeed); samegroupebutton.IsOnToogle = false; } } } } } } else //si relachement { if (button.Type == buttonType.Momentary) //si Bouton Momentanné { Led((RGB_Led)_BUTTONID, button.offFlashingtype, button.offprimaryColor, button.offsecondaryColor, button.offFlashingspeed); } } } } #endregion } } _InputAPC40.StartRecording(); }
public void SendMidiData(byte[] data) { port.sendCommand(data); }
public void Send(TeVirtualMIDI port) { port.sendCommand(buffer); }
private void Client_OnMessageReceived(object sender, OnMessageReceivedArgs e) { ChatMessage message = e.ChatMessage; Setting settings = repository.LoadSettings(); if (message.Channel.ToLower() != settings.Username.ToLower()) { Console.WriteLine("wrong timeline, friend"); return; } if (String.IsNullOrEmpty(settings.Application)) { Console.WriteLine("is there any point?"); return; } if (IsOnCooldown(settings.GlobalLastTriggered, settings.GlobalCooldown, settings.GlobalCooldownUnit)) { Console.WriteLine("trigger on global cooldown"); return; } List <Trigger> triggers = repository.GetTriggers().Where(trigger => String.IsNullOrEmpty(trigger.RewardName)).ToList <Trigger>(); foreach (Trigger trigger in triggers) { if (IsOnCooldown(trigger.LastTriggered, trigger.Cooldown, trigger.CooldownUnit)) { Console.WriteLine("trigger on cooldown"); continue; } bool bitsRequired = (trigger.BitsEnabled && trigger.BitsAmount > 0); if (!bitsRequired && trigger.Keywords == "[]") { Console.WriteLine("either bits or keywords needed"); continue; } if (bitsRequired && message.Bits == 0) { Console.WriteLine("bits expected and none given"); continue; } bool validBits = false; switch (trigger.BitsCondition) { case 0: validBits = message.Bits >= trigger.BitsAmount; break; case 1: validBits = message.Bits <= trigger.BitsAmount; break; case 2: validBits = message.Bits == trigger.BitsAmount; break; case 3: validBits = message.Bits >= trigger.BitsAmount && message.Bits <= trigger.BitsAmount2; break; } if (!bitsRequired && trigger.Keywords != "[]") { validBits = true; } if (!validBits) { Console.WriteLine("not enough bits given"); continue; } ; if (message.IsBroadcaster == false && (trigger.UserLevelEveryone || (trigger.UserLevelSubs && message.IsSubscriber) || (trigger.UserLevelVips && message.IsVip) || (trigger.UserLevelMods && message.IsModerator)) == false) { Console.WriteLine("wrong userlevel"); continue; } ; if (trigger.Keywords != "[]" && !PassesKeywordCheck(trigger.Keywords, message.Message)) { continue; } Console.WriteLine("matched!!"); if (trigger.CharAnimTriggerKeyChar == "midi") { if (trigger.CharAnimTriggerKeyValue > 127) { trigger.CharAnimTriggerKeyValue = 127; } Console.WriteLine("Sending midi message!!"); byte[] dataOn = new byte[3]; dataOn[0] = Convert.ToByte("10010000", 2); dataOn[1] = (byte)trigger.CharAnimTriggerKeyValue; dataOn[2] = 127; midiController.sendCommand(dataOn); byte[] dataOff = new byte[3]; dataOff[0] = Convert.ToByte("10000000", 2); dataOff[1] = (byte)trigger.CharAnimTriggerKeyValue; dataOff[2] = 0; midiController.sendCommand(dataOff); } else { SendKeystroke.Send(settings.Application, trigger.CharAnimTriggerKeyValue); } DateTime triggeredAt = DateTime.Now; repository.UpdateTriggerUsage(trigger.Name, triggeredAt); BotTriggeredArgs args = new BotTriggeredArgs { TriggeredAt = triggeredAt }; BotTriggered?.Invoke(this, args); if (settings.LoggingEnabled) { Logger.Write(trigger.Name, message.DisplayName, message.Bits, message.Message); } } }
/// <summary> /// Event Input, Génere un événement avec la position et l'état de l'input /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void HandleChannelMessageReceived(object sender, ChannelMessageEventArgs e) { bool ISSYSTEMLED; int POSITION; bool ISON; if (e.Message.Command == ChannelCommand.Controller) { ISSYSTEMLED = true; POSITION = e.Message.Data1 - 104; } else { ISSYSTEMLED = false; POSITION = e.Message.Data1; } if (e.Message.Data2 == 127) { ISON = true; } else { ISON = false; } if (LaunchPadInput != null) { LaunchPadInput(_InputLaunchPad, new LaunchPadInputEventArgs { isSystemLed = ISSYSTEMLED, position = POSITION, isOn = ISON, }); } _VirtualMidiPort.sendCommand(e.Message.GetBytes()); //Mapping if (Mapping != null) { List <Button> BTlist; if (!ISSYSTEMLED) { BTlist = LaunchPadControl.Mapping.BT; } else { BTlist = LaunchPadControl.Mapping.SysBT; } if (ISON) { if (BTlist.Find(x => x.ID == POSITION).Type == buttonType.Momentary) { LaunchPadControl.Led(POSITION, BTlist.Find(x => x.ID == POSITION).onColor, BTlist.Find(x => x.ID == POSITION).onFlashing, ISSYSTEMLED); } if (BTlist.Find(x => x.ID == POSITION).Type == buttonType.Toogle) { if (BTlist.Find(x => x.ID == POSITION).IsOnToogle == true) { LaunchPadControl.Led(POSITION, BTlist.Find(x => x.ID == POSITION).offColor, BTlist.Find(x => x.ID == POSITION).offFlashing, ISSYSTEMLED); BTlist.Find(x => x.ID == POSITION).IsOnToogle = false; } else { LaunchPadControl.Led(POSITION, BTlist.Find(x => x.ID == POSITION).onColor, BTlist.Find(x => x.ID == POSITION).onFlashing, ISSYSTEMLED); BTlist.Find(x => x.ID == POSITION).IsOnToogle = true; } } } else { if (BTlist.Find(x => x.ID == POSITION).Type == buttonType.Momentary) { LaunchPadControl.Led(POSITION, BTlist.Find(x => x.ID == POSITION).offColor, BTlist.Find(x => x.ID == POSITION).offFlashing, ISSYSTEMLED); } } } }