public static bool Equals(MidiEvent midiEvent1, MidiEvent midiEvent2, MidiEventEqualityCheckSettings settings, out string message) { message = null; if (ReferenceEquals(midiEvent1, midiEvent2)) { return(true); } if (ReferenceEquals(null, midiEvent1) || ReferenceEquals(null, midiEvent2)) { message = "One of events is null."; return(false); } if (settings.CompareDeltaTimes) { var deltaTime1 = midiEvent1.DeltaTime; var deltaTime2 = midiEvent2.DeltaTime; if (deltaTime1 != deltaTime2) { message = $"Delta-times are different ({deltaTime1} vs {deltaTime2})."; return(false); } } var type1 = midiEvent1.GetType(); var type2 = midiEvent2.GetType(); if (type1 != type2) { message = $"Types of events are different ({type1} vs {type2})."; return(false); } if (midiEvent1 is SystemRealTimeEvent) { return(true); } var channelEvent1 = midiEvent1 as ChannelEvent; if (channelEvent1 != null) { var channelEvent2 = (ChannelEvent)midiEvent2; var channel1 = channelEvent1.Channel; var channel2 = channelEvent2.Channel; if (channel1 != channel2) { message = $"Channels of events are different ({channel1} vs {channel2})."; return(false); } if (channelEvent1._dataByte1 != channelEvent2._dataByte1) { message = $"First data bytes of events are different ({channelEvent1._dataByte1} vs {channelEvent2._dataByte1})."; return(false); } if (channelEvent1._dataByte2 != channelEvent2._dataByte2) { message = $"Second data bytes of events are different ({channelEvent1._dataByte2} vs {channelEvent2._dataByte2})."; return(false); } return(true); } var sysExEvent1 = midiEvent1 as SysExEvent; if (sysExEvent1 != null) { var sysExEvent2 = (SysExEvent)midiEvent2; var completed1 = sysExEvent1.Completed; var completed2 = sysExEvent2.Completed; if (completed1 != completed2) { message = $"'Completed' state of system exclusive events are different ({completed1} vs {completed2})."; return(false); } if (!ArrayUtilities.Equals(sysExEvent1.Data, sysExEvent2.Data)) { message = "System exclusive events data are different."; return(false); } return(true); } var sequencerSpecificEvent1 = midiEvent1 as SequencerSpecificEvent; if (sequencerSpecificEvent1 != null) { var sequencerSpecificEvent2 = (SequencerSpecificEvent)midiEvent2; if (!ArrayUtilities.Equals(sequencerSpecificEvent1.Data, sequencerSpecificEvent2.Data)) { message = "Sequencer specific events data are different."; return(false); } return(true); } var unknownMetaEvent1 = midiEvent1 as UnknownMetaEvent; if (unknownMetaEvent1 != null) { var unknownMetaEvent2 = (UnknownMetaEvent)midiEvent2; var statusByte1 = unknownMetaEvent1.StatusByte; var statusByte2 = unknownMetaEvent2.StatusByte; if (statusByte1 != statusByte2) { message = $"Unknown meta events status bytes are different ({statusByte1} vs {statusByte2})."; return(false); } if (!ArrayUtilities.Equals(unknownMetaEvent1.Data, unknownMetaEvent2.Data)) { message = "Unknown meta events data are different."; return(false); } return(true); } var baseTextEvent1 = midiEvent1 as BaseTextEvent; if (baseTextEvent1 != null) { var baseTextEvent2 = (BaseTextEvent)midiEvent2; var text1 = baseTextEvent1.Text; var text2 = baseTextEvent2.Text; if (!string.Equals(text1, text2, settings.TextComparison)) { message = $"Meta events texts are different ({text1} vs {text2})."; return(false); } return(true); } Func <MidiEvent, MidiEvent, bool> comparer; if (Comparers.TryGetValue(midiEvent1.EventType, out comparer)) { return(comparer(midiEvent1, midiEvent2)); } var result = midiEvent1.Equals(midiEvent2); if (!result) { message = $"Events {midiEvent1} and {midiEvent2} are not equal by result of Equals call on first event."; } return(result); }
/// <summary> /// Converts an instance of the <see cref="MidiEvent"/> to bytes array. /// </summary> /// <param name="midiEvent">MIDI event to convert.</param> /// <returns>Array of bytes representing <paramref name="midiEvent"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="midiEvent"/> is <c>null</c>.</exception> public byte[] Convert(MidiEvent midiEvent) { ThrowIfArgument.IsNull(nameof(midiEvent), midiEvent); return(Convert(midiEvent, 0)); }
public int CalculateSize(MidiEvent midiEvent, WritingSettings settings, bool writeStatusByte) { return((writeStatusByte ? 1 : 0) + midiEvent.GetSize(settings)); }
/// <summary> /// Determines whether two specified <see cref="MidiEvent"/> objects have the same content. /// </summary> /// <param name="midiEvent1">The first event to compare, or <c>null</c>.</param> /// <param name="midiEvent2">The second event to compare, or <c>null</c>.</param> /// <param name="message">Message containing information about what exactly is different in /// <paramref name="midiEvent1"/> and <paramref name="midiEvent2"/>.</param> /// <returns><c>true</c> if the <paramref name="midiEvent1"/> is equal to the <paramref name="midiEvent2"/>; /// otherwise, <c>false</c>.</returns> public static bool Equals(MidiEvent midiEvent1, MidiEvent midiEvent2, out string message) { return(Equals(midiEvent1, midiEvent2, null, out message)); }
/// <summary> /// Determines whether two specified <see cref="MidiEvent"/> objects have the same content using /// the specified comparison settings. /// </summary> /// <param name="midiEvent1">The first event to compare, or <c>null</c>.</param> /// <param name="midiEvent2">The second event to compare, or <c>null</c>.</param> /// <param name="settings">Settings according to which events should be compared.</param> /// <param name="message">Message containing information about what exactly is different in /// <paramref name="midiEvent1"/> and <paramref name="midiEvent2"/>.</param> /// <returns><c>true</c> if the <paramref name="midiEvent1"/> is equal to the <paramref name="midiEvent2"/>; /// otherwise, <c>false</c>.</returns> public static bool Equals(MidiEvent midiEvent1, MidiEvent midiEvent2, MidiEventEqualityCheckSettings settings, out string message) { return(MidiEventEquality.Equals(midiEvent1, midiEvent2, settings ?? new MidiEventEqualityCheckSettings(), out message)); }
/// <summary> /// Determines whether two specified <see cref="MidiEvent"/> objects have the same content. /// </summary> /// <param name="midiEvent1">The first event to compare, or <c>null</c>.</param> /// <param name="midiEvent2">The second event to compare, or <c>null</c>.</param> /// <returns><c>true</c> if the <paramref name="midiEvent1"/> is equal to the <paramref name="midiEvent2"/>; /// otherwise, <c>false</c>.</returns> public static bool Equals(MidiEvent midiEvent1, MidiEvent midiEvent2) { string message; return(Equals(midiEvent1, midiEvent2, out message)); }
public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte) { if (writeStatusByte) { writer.WriteByte(EventStatusBytes.Global.Meta); } // byte statusByte = 0; switch (midiEvent.EventType) { case MidiEventType.Lyric: statusByte = EventStatusBytes.Meta.Lyric; break; case MidiEventType.SetTempo: statusByte = EventStatusBytes.Meta.SetTempo; break; case MidiEventType.Text: statusByte = EventStatusBytes.Meta.Text; break; case MidiEventType.SequenceTrackName: statusByte = EventStatusBytes.Meta.SequenceTrackName; break; case MidiEventType.PortPrefix: statusByte = EventStatusBytes.Meta.PortPrefix; break; case MidiEventType.TimeSignature: statusByte = EventStatusBytes.Meta.TimeSignature; break; case MidiEventType.SequencerSpecific: statusByte = EventStatusBytes.Meta.SequencerSpecific; break; case MidiEventType.KeySignature: statusByte = EventStatusBytes.Meta.KeySignature; break; case MidiEventType.Marker: statusByte = EventStatusBytes.Meta.Marker; break; case MidiEventType.ChannelPrefix: statusByte = EventStatusBytes.Meta.ChannelPrefix; break; case MidiEventType.InstrumentName: statusByte = EventStatusBytes.Meta.InstrumentName; break; case MidiEventType.CopyrightNotice: statusByte = EventStatusBytes.Meta.CopyrightNotice; break; case MidiEventType.SmpteOffset: statusByte = EventStatusBytes.Meta.SmpteOffset; break; case MidiEventType.DeviceName: statusByte = EventStatusBytes.Meta.DeviceName; break; case MidiEventType.CuePoint: statusByte = EventStatusBytes.Meta.CuePoint; break; case MidiEventType.ProgramName: statusByte = EventStatusBytes.Meta.ProgramName; break; case MidiEventType.SequenceNumber: statusByte = EventStatusBytes.Meta.SequenceNumber; break; case MidiEventType.EndOfTrack: statusByte = EventStatusBytes.Meta.EndOfTrack; break; case MidiEventType.UnknownMeta: statusByte = ((UnknownMetaEvent)midiEvent).StatusByte; break; default: { var eventType = midiEvent.GetType(); if (settings.CustomMetaEventTypes?.TryGetStatusByte(eventType, out statusByte) != true) { Debug.Fail($"Unable to write the {eventType} event."); } } break; } writer.WriteByte(statusByte); // var contentSize = midiEvent.GetSize(settings); writer.WriteVlqNumber(contentSize); midiEvent.Write(writer, settings); }
public byte GetStatusByte(MidiEvent midiEvent) { return(EventStatusBytes.Global.Meta); }
public int CalculateSize(MidiEvent midiEvent, WritingSettings settings, bool writeStatusByte) { var contentSize = midiEvent.GetSize(settings); return((writeStatusByte ? 1 : 0) + 1 + contentSize.GetVlqLength() + contentSize); }
/// <summary> /// Determines whether two specified <see cref="MidiEvent"/> objects have the same content. /// </summary> /// <param name="midiEvent1">The first event to compare, or <c>null</c>.</param> /// <param name="midiEvent2">The second event to compare, or <c>null</c>.</param> /// <param name="settings">Settings according to which events should be compared.</param> /// <returns><c>true</c> if the <paramref name="midiEvent1"/> is equal to the <paramref name="midiEvent2"/>; /// otherwise, <c>false</c>.</returns> public static bool Equals(MidiEvent midiEvent1, MidiEvent midiEvent2, MidiEventEqualityCheckSettings settings) { string message; return(Equals(midiEvent1, midiEvent2, settings, out message)); }