/// <summary> /// Reset all input fields /// </summary> /// <param name="resetMessageType">If true, reset message type list as well</param> private void ResetMessageTypeAndParameters(bool resetMessageType) { // If the flag is set, reset the message type list as well if (resetMessageType) { this.messageType.SelectedIndex = -1; this.currentMessageType = MidiMessageType.None; } // Ensure the message type list and reset button are enabled this.messageType.IsEnabled = true; this.resetButton.IsEnabled = true; // Reset selections on parameters this.parameter1.SelectedIndex = -1; this.parameter2.SelectedIndex = -1; this.parameter3.SelectedIndex = -1; // New selection values will cause parameter boxes to be hidden and disabled UpdateParameterList1(); UpdateParameterList2(); UpdateParameterList3(); // Disable send button & hide/clear the SysEx buffer text this.sendButton.IsEnabled = false; this.rawBufferHeader.Visibility = Visibility.Collapsed; this.sysExMessageContent.Text = ""; this.sysExMessageContent.Visibility = Visibility.Collapsed; }
public const int MaxMessageLength = 7 + (3 * DeviceInfo.MaxLightCount) + 1; //MK2 = 80, Pro = 97 public static byte[] CreateBuffer(MidiMessageType type, byte channel, int length = 0) { if (length == 0) { switch (type) { case MidiMessageType.NoteOff: length = 3; break; case MidiMessageType.NoteOn: length = 3; break; case MidiMessageType.PolyphonicAftertouch: length = 3; break; case MidiMessageType.ControlModeChange: length = 3; break; case MidiMessageType.ProgramChange: length = 2; break; case MidiMessageType.ChannelAftertouch: length = 2; break; case MidiMessageType.PitchWheelRange: length = 3; break; case MidiMessageType.MidiClock: return(new[] { (byte)MidiMessageType.MidiClock }); default: throw new InvalidOperationException("Unknown MIDI message type"); } } byte[] data = new byte[length + 1]; data[0] = (byte)((byte)type | ((channel - 1) & 0x0F)); return(data); }
public TwoWayEncoder(MidiMessageType MessageType, int MidiChannel, int NoteNumber, int IncRange) { this.MessageType = MessageType; this.MidiChannel = MidiChannel; this.NoteNumber = NoteNumber; this.IncRange = IncRange; }
/// <summary>Returns a comment for the first data byte of a channel message/event.</summary> /// <param name="messageType">Identifies the type of channel message (high nibble of status byte).</param> /// <param name="data">The first data byte of the event.</param> /// <param name="channel">One of the sixteen logical MIDI channels on which the event is transmitted.</param> /// <param name="keySignature">A MidiKeySignature value that applies to the event.</param> /// <returns>A comment for the data byte.</returns> public static string GetData1Comment(MidiMessageType messageType, int data, int channel, MidiKeySignature keySignature) { string s = (MidiChannelEvent.TypeMap[messageType].DescribeData1 == null) ? null : MidiChannelEvent.TypeMap[messageType].DescribeData1(data, channel, keySignature); return(MidiChannelEvent.BuildDataComment(MidiChannelEvent.TypeMap[messageType].Data1Name, data, s)); }
/// <summary> /// Reset all input fields /// </summary> /// <param name="resetMessageType">If true, reset message type list as well</param> private void ResetMessageTypeAndParameters(bool resetMessageType) { // If the flag is set, reset the message type list as well if (resetMessageType) { messageType.SelectedIndex = -1; _currentMessageType = MidiMessageType.None; } // Ensure the message type list and reset button are enabled messageType.IsEnabled = true; resetButton.IsEnabled = true; // Reset selections on parameters #if !WINDOWS_UWP parameter1.Value = 0; parameter2.Value = 0; parameter3.Value = 0; #else parameter1.Text = "0"; parameter2.Text = "0"; parameter3.Text = "0"; #endif // New selection values will cause parameter boxes to be hidden and disabled UpdateParameterList1(); UpdateParameterList2(); UpdateParameterList3(); // Disable send button & hide/clear the SysEx buffer text sendButton.IsEnabled = true; rawBufferHeader.Visibility = Visibility.Collapsed; sysExMessageContent.Text = ""; sysExMessageContent.Visibility = Visibility.Collapsed; }
public MidiMessage(MidiMessageType messageType, int? channel = null, int? data1 = null, int? data2 = null) { MessageType = messageType; Channel = channel; Data1 = data1; Data2 = data2; }
public bool ConvertXY(MidiMessageType type, int noteNumber, out int x, out int y, out ImplantEventType eventType) { if (type == MidiMessageType.ControlChange) { if (noteNumber < KNOB_BOTTOMROW) { x = noteNumber - KNOB_TOPROW; y = 0; } else { x = noteNumber - KNOB_BOTTOMROW; y = 1; } eventType = ImplantEventType.KnobChange; return(true); } else { x = noteNumber < PAD5 ? noteNumber - PAD1 : noteNumber - PAD5 + 4; y = 2; eventType = ImplantEventType.PadPress; return(true); } }
public MidiMessage(MidiMessageType MessageType, Int32 MidiChannel, Int32 NoteNumber, Int32 NoteVelocity) { this.MessageType = MessageType; this.MidiChannel = MidiChannel; this.NoteNumber = NoteNumber; this.NoteVelocity = NoteVelocity; }
public static byte BindTypeAndChannel(MidiMessageType type, int channel) { switch (type) { case MidiMessageType.NoteOn: return((byte)(0x90 + channel)); case MidiMessageType.NoteOff: return((byte)(0x80 + channel)); case MidiMessageType.ControlChange: return((byte)(0xB0 + (byte)channel)); case MidiMessageType.ClockStart: return(0xFA); case MidiMessageType.ClockStop: return(0xFC); case MidiMessageType.ClockTick: return(0xF8); case MidiMessageType.ClockContinue: return(0xFB); default: return(0x00); } }
internal MidiPitchBendMessage(Core.MidiIO.Data.MidiEvent ev, MidiMessageType type) : base(ev, type) { int p = ((ev.AllData[2] & 0x7F) << 7) | (ev.AllData[1] & 0x7F); Pitch = p - 8192; }
public ToggleButton(MidiMessageType MessageType, int MidiChannel, int NoteNumber) { this.MessageType = MessageType; this.MidiChannel = MidiChannel; this.NoteNumber = NoteNumber; this.Value = false; }
void DispatchMessageReceived(MidiInPort port, MidiMessageReceivedEventArgs args) { MidiMessageType type = args.Message.Type; var data = args.Message.RawData.ToArray(); MessageReceived(this, new MidiReceivedEventArgs { Data = data, Start = 0, Length = data.Length, Timestamp = (long)args.Message.Timestamp.TotalMilliseconds }); }
public SimpleMakroButton(MidiMessageType MessageType, int MidiChannel, int NoteNumber) { this.MessageType = MessageType; this.MidiChannel = MidiChannel; this.NoteNumber = NoteNumber; worker = new BackgroundWorker (); worker.DoWork += HandleDoWork; }
internal static void VerifyMessageType(byte firstByte, MidiMessageType type) { var typeByte = (byte)type; if ((firstByte & typeByte) != typeByte) { throw new ArgumentException( $"The message does not match expected type of {type}"); } }
public static void ParseTypeAndChannel(byte b, out MidiMessageType type, out int channel) { switch ((int)b & MIDI_TYPE_MASK) { case 0x80: channel = (int)b % MIDI_CHANNEL_MASK; type = MidiMessageType.NoteOff; break; case 0x90: channel = (int)b % MIDI_CHANNEL_MASK; type = MidiMessageType.NoteOn; break; case 0xb0: channel = (int)b % MIDI_CHANNEL_MASK; type = MidiMessageType.ControlChange; break; case 0xf0: switch ((int)b) { case 0xfa: channel = 0; type = MidiMessageType.ClockStart; break; case 0xfc: channel = 0; type = MidiMessageType.ClockStop; break; case 0xf8: channel = 0; type = MidiMessageType.ClockTick; break; case 0xfb: channel = 0; type = MidiMessageType.ClockContinue; break; default: channel = 0; type = MidiMessageType.Unsupported; break; } break; default: channel = 0; type = MidiMessageType.Unsupported; break; } }
/// <summary>Returns a comment for the second data byte of a channel message/event.</summary> /// <param name="messageType">Identifies the type of channel message (high nibble of status byte).</param> /// <param name="data">The second data byte of the event.</param> /// <returns>A comment for the data byte.</returns> public static string GetData2Comment(MidiMessageType messageType, int data) { if (!MidiChannelEvent.HasData2(messageType)) { return(null); } string s = (MidiChannelEvent.TypeMap[messageType].DescribeData2 == null) ? null : MidiChannelEvent.TypeMap[messageType].DescribeData2(data, 0, MidiKeySignature.NA); return(MidiChannelEvent.BuildDataComment(MidiChannelEvent.TypeMap[messageType].Data2Name, data, s)); }
/// <summary>Inserts a new MIDI channel message/event into this file at the specified index.</summary> /// <param name="index">The index in this file's list at which the event should be inserted.</param> /// <param name="deltaTime">The amount of time (in ticks) between the previous event in the track and this one.</param> /// <param name="status">The status byte of the event, or -1 for running status.</param> /// <param name="data1">The first data byte of the event.</param> /// <param name="data2">The second data byte of the event (if applicable).</param> /// <returns>The new MidiChannelEvent object that is inserted.</returns> public MidiChannelEvent InsertChannelEvent(int index, int deltaTime, int status, int data1, int data2) { int offset = this.Items[index].Offset, n = (status < 0) ? this.GetRunningStatus(offset) : status; MidiMessageType messageType = (MidiMessageType)Midi.GetHighNibble(n); n = MidiChannelEvent.SizeItem(0, (status < 0), messageType); this.Resize(n, offset, index); MidiChannelEvent channelEvent = this.CreateChannelEvent(offset, deltaTime, status, data1, data2); this.Items.Insert(index, channelEvent); this.SetTotalTime(index); return(channelEvent); }
/// <summary>Adds a new MIDI channel message/event to the end of this file.</summary> /// <param name="deltaTime">The amount of time (in ticks) between the previous event in the track and this one.</param> /// <param name="status">The status byte of the event, or -1 for running status.</param> /// <param name="data1">The first data byte of the event.</param> /// <param name="data2">The second data byte of the event (if applicable).</param> /// <returns>The new MidiChannelEvent object that is added.</returns> public MidiChannelEvent AddChannelEvent(int deltaTime, int status, int data1, int data2) { int offset = this.Bytes.Length, n = (status < 0) ? this.GetRunningStatus(offset) : status; MidiMessageType messageType = (MidiMessageType)Midi.GetHighNibble(n); n = MidiChannelEvent.SizeItem(0, (status < 0), messageType); this.Resize(n, offset, this.ItemCount); MidiChannelEvent channelEvent = this.CreateChannelEvent(offset, deltaTime, status, data1, data2); this.Items.Add(channelEvent); this.SetTotalTime(this.ItemCount - 1); return(channelEvent); }
public bool ConvertXY(int x, int y, out MidiMessageType type, out int noteNumber) { if (y < 1) { type = MidiMessageType.ControlChange; noteNumber = FirstModeControl + x; } else { type = MidiMessageType.NoteOn; noteNumber = (y - 1) * 16 + x; } return(true); }
/// <summary> /// Convert a MIDI type enum to a string. /// </summary> public static string GetString(this MidiMessageType type) { switch (type) { case MidiMessageType.NoteOff: return("noteoff"); case MidiMessageType.NoteOn: return("noteon"); case MidiMessageType.ControlChange: return("cc"); default: return("unknown"); } }
/// <summary> /// Constructs the type-specific message object using the given data. Use MessageType property /// to determine the type of the message. /// </summary> /// <param name="Data">The binary coded data from the style file</param> /// <param name="TotalTime">The timestamp of the message in ticks</param> /// <returns>An object derived from MidiMessage class that represents the message</returns> public static MidiMessage CreateFromData(byte[] Data, int TotalTime) { MidiMessageType type = MidiMessage.GetMessageType(Data[1]); Type Class = Type.GetType("TomiSoft.RolandStyleReader." + type.ToString() + "Message", true); try { return((MidiMessage)Class.GetConstructor( new Type[] { typeof(byte[]), typeof(int) } ).Invoke(new object[] { Data, TotalTime })); } catch (TargetInvocationException e) { throw e.InnerException; } }
public void midiSend(MidiMessageType type, int channel, int data1, int data2) { //OSC midi message basic format, with 0xff bytes as placeholders for the actual midi message bytes. byte[] message = new byte[] { 0x2f, 0x6d, 0x69, 0x64, 0x69, 0x00, 0x00, 0x00, 0x2c, 0x6d, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff }; //Sanity check on input if (channel < 1 || channel > 15 || data1 < 0 || data1 > 127 || data2 < 0 || data2 > 127) { Debug.LogError("midiSend: Bad input format."); return; } message[15] = (byte)type; message[15] += (byte)(channel - 1); message[14] = (byte)data1; message[13] = (byte)data2; udpClient.Send(message, 16); Debug.Log("Midi Message Sent!"); }
public bool ConvertXY(MidiMessageType type, int noteNumber, out int x, out int y, out ImplantEventType eventType) { switch (type) { case MidiMessageType.ControlChange: y = 0; x = noteNumber - FirstModeControl; eventType = ImplantEventType.PadPress; return(true); case MidiMessageType.NoteOn: case MidiMessageType.NoteOff: y = noteNumber / 16 + 1; x = noteNumber % 16; eventType = ImplantEventType.PadPress; return(true); } x = y = 0; eventType = ImplantEventType.PadPress; return(false); }
public bool ConvertXY(int x, int y, out MidiMessageType type, out int noteNumber) { if (y == 2) // PAD { type = MidiMessageType.NoteOn; // what about note off? noteNumber = x < 4 ? PAD1 + x : PAD5 + (x - 4); return(true); } else if (y == 0) // KNOB TOP { type = MidiMessageType.ControlChange; noteNumber = KNOB_TOPROW + x; } else if (y == 1) // KNOB BOTTOM { type = MidiMessageType.ControlChange; noteNumber = KNOB_BOTTOMROW + x; } type = MidiMessageType.NoteOn; noteNumber = 0; return(false); }
/// <summary>Returns a general comment on a type of channel message/event.</summary> /// <param name="messageType">Identifies the type of channel message (high nibble of status byte).</param> /// <returns>Comment on the type of channel message.</returns> public static string GetTypeComment(MidiMessageType messageType) { return(MidiChannelEvent.TypeMap[messageType].Comment); }
internal MidiNoteMessage(Core.MidiIO.Data.MidiEvent ev, MidiMessageType type) : base(ev, type) { _key = ev.AllData[1] & 0x7F; _velocity = ev.AllData[2] & 0x7F; }
public SimpleButton(MidiMessageType MessageType, int MidiChannel, int NoteNumber) { this.MessageType = MessageType; this.MidiChannel = MidiChannel; this.NoteNumber = NoteNumber; }
public NoneButton(MidiMessageType MessageType, int MidiChannel, int NoteNumber) : base(MessageType, MidiChannel, NoteNumber) { }
/// <summary>Indicates whether a type of channel message has two data bytes or just one.</summary> /// <param name="messageType">Identifies the type of channel message (high nibble of status byte).</param> /// <returns>True if the type of channel message has two data bytes; otherwise (only one data byte), false.</returns> public static bool HasData2(MidiMessageType messageType) { return(MidiChannelEvent.TypeMap[messageType].Data2Name != null); }
internal MidiControlChangeMessage(Core.MidiIO.Data.MidiEvent ev, MidiMessageType type) : base(ev, type) { ControlId = ev.AllData[1]; ControlValue = ev.AllData[2]; }
/*********** * Methods * ***********/ #region Public Methods /// <summary>Returns the number of bytes required to store an item of this type.</summary> public static int SizeItem(int deltaTime, bool runningStatus, MidiMessageType messageType) { return(Midi.SizeVLQ(deltaTime) + (runningStatus ? 0 : 1) + (MidiChannelEvent.HasData2(messageType) ? 2 : 1)); }
/// <summary> /// Construct a MIDI message possibly with additional parameters, /// depending on the type of message /// </summary> /// <param name="sender">Element that fired the event</param> /// <param name="e">Event arguments</param> private void messageType_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Find the index of the user's choice int messageTypeSelectedIndex = messageType.SelectedIndex; // Return if reset if (messageTypeSelectedIndex == -1) { return; } // Clear the UI ResetMessageTypeAndParameters(false); // Find the key by index; that's our message type int count = 0; foreach (var messageType in _messageTypes) { if (messageTypeSelectedIndex == count) { _currentMessageType = messageType.Key; break; } count++; } // Some MIDI message types don't need additional parameters // For them, show the Send button as soon as user selects message type from the list switch (_currentMessageType) { // SysEx messages need to be in a particular format case MidiMessageType.SystemExclusive: rawBufferHeader.Visibility = Visibility.Visible; sysExMessageContent.Visibility = Visibility.Visible; // Provide start (0xF0) and end (0xF7) of SysEx values sysExMessageContent.Text = "F0 F7"; // Let the user know the expected format of the message NotifyUser("Expecting a string of format 'NN NN NN NN....', where NN is a byte in hex"); sendButton.IsEnabled = true; break; // These messages do not need additional parameters case MidiMessageType.ActiveSensing: case MidiMessageType.Continue: case MidiMessageType.Start: case MidiMessageType.Stop: case MidiMessageType.SystemReset: case MidiMessageType.TimingClock: case MidiMessageType.TuneRequest: sendButton.IsEnabled = true; break; default: sendButton.IsEnabled = false; break; } // Update the first parameter lists depending on the MIDI message type // If no further parameters are required, the list is emptied and hidden UpdateParameterList1(); UpdateParameterList2(); UpdateParameterList3(); }
internal MidiProgramChangeMessage(Core.MidiIO.Data.MidiEvent ev, MidiMessageType type) : base(ev, type) { _instrument = (MidiInstrument)(ev.AllData[1] & 0x7F); }
protected void RaiseButtonUp(MidiMessageType type, byte midiId) => ButtonUp?.Invoke(type, midiId);
internal static void VerifyMessageLength(byte[] messageData, int expectedLength, MidiMessageType type) { if (messageData is null) { throw new ArgumentNullException(nameof(messageData)); } if (messageData.Length != expectedLength) { throw new ArgumentException( $"MIDI message of type {type} must have length of {expectedLength} bytes", nameof(messageData)); } }
/// <summary> /// Construct a MIDI message possibly with additional parameters, /// depending on the type of message /// </summary> /// <param name="sender">Element that fired the event</param> /// <param name="e">Event arguments</param> private void messageType_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Find the index of the user's choice int messageTypeSelectedIndex = this.messageType.SelectedIndex; // Return if reset if (messageTypeSelectedIndex == -1) { return; } // Clear the UI ResetMessageTypeAndParameters(false); // Find the key by index; that's our message type int count = 0; foreach (var messageType in messageTypes) { if (messageTypeSelectedIndex == count) { this.currentMessageType = messageType.Key; break; } count++; } // Some MIDI message types don't need additional parameters // For them, show the Send button as soon as user selects message type from the list switch (this.currentMessageType) { // SysEx messages need to be in a particular format case MidiMessageType.SystemExclusive: this.rawBufferHeader.Visibility = Visibility.Visible; this.sysExMessageContent.Visibility = Visibility.Visible; // Provide start (0xF0) and end (0xF7) of SysEx values sysExMessageContent.Text = "F0 F7"; // Let the user know the expected format of the message this.rootPage.NotifyUser("Expecting a string of format 'NN NN NN NN....', where NN is a byte in hex", NotifyType.StatusMessage); this.sendButton.IsEnabled = true; break; // These messages do not need additional parameters case MidiMessageType.ActiveSensing: case MidiMessageType.Continue: case MidiMessageType.Start: case MidiMessageType.Stop: case MidiMessageType.SystemReset: case MidiMessageType.TimingClock: case MidiMessageType.TuneRequest: this.sendButton.IsEnabled = true; break; default: this.sendButton.IsEnabled = false; break; } // Update the first parameter list depending on the MIDI message type // If no further parameters are required, the list is emptied and hidden UpdateParameterList1(); }
internal MidiMessage(cmdr.MidiLib.Core.MidiIO.Data.MidiEvent ev, MidiMessageType type) { _coreMessage = ev; _type = type; }
public MidiClockMessageReceivedEventArgs(IBuffer rawData, TimeSpan timestamp, MidiMessageType type) { RawData = rawData; TimeStamp = timestamp; Type = type; }