Пример #1
0
        /// <summary>
        /// Determines whether the specified event is equal to the current one.
        /// </summary>
        /// <param name="copyrightNoticeEvent">The event to compare with the current one.</param>
        /// <param name="respectDeltaTime">If true the <see cref="MidiEvent.DeltaTime"/> will be taken into an account
        /// while comparing events; if false - delta-times will be ignored.</param>
        /// <returns>true if the specified event is equal to the current one; otherwise, false.</returns>
        public bool Equals(CopyrightNoticeEvent copyrightNoticeEvent, bool respectDeltaTime)
        {
            if (ReferenceEquals(null, copyrightNoticeEvent))
            {
                return(false);
            }

            if (ReferenceEquals(this, copyrightNoticeEvent))
            {
                return(true);
            }

            return(base.Equals(copyrightNoticeEvent, respectDeltaTime));
        }
Пример #2
0
        private static Tuple <Option <MidiEvent>, int, byte> NextEvent(List <byte> trackData, int startIndex, byte lastMidiChannel)
        {
            var i = startIndex - 1;

            MidiEvent midiEvent = null;

            {
                int deltaTime;
                {
                    var lengthTemp = new List <byte>();
                    do
                    {
                        i += 1;
                        lengthTemp.Add(trackData.ElementAt(i));
                    } while (trackData.ElementAt(i) > 0x7F);

                    deltaTime = VariableLengthUtil.decode_to_int(lengthTemp);
                }

                i += 1;

                var eventTypeValue = trackData.ElementAt(i);

                // MIDI Channel Events
                if ((eventTypeValue & 0xF0) < 0xF0)
                {
                    var midiChannelEventType = (byte)(eventTypeValue & 0xF0);
                    var midiChannel          = (byte)(eventTypeValue & 0x0F);
                    i += 1;
                    var  parameter1 = trackData.ElementAt(i);
                    byte parameter2;

                    // One or two parameter type
                    switch (midiChannelEventType)
                    {
                    // One parameter types
                    case 0xC0:
                        midiEvent       = new ProgramChangeEvent(deltaTime, midiChannel, parameter1);
                        lastMidiChannel = midiChannel;
                        break;

                    case 0xD0:
                        midiEvent       = new ChannelAftertouchEvent(deltaTime, midiChannel, parameter1);
                        lastMidiChannel = midiChannel;
                        break;

                    // Two parameter types
                    case 0x80:
                        i              += 1;
                        parameter2      = trackData.ElementAt(i);
                        midiEvent       = new NoteOffEvent(deltaTime, midiChannel, parameter1, parameter2);
                        lastMidiChannel = midiChannel;
                        break;

                    case 0x90:
                        i              += 1;
                        parameter2      = trackData.ElementAt(i);
                        midiEvent       = new NoteOnEvent(deltaTime, midiChannel, parameter1, parameter2);
                        lastMidiChannel = midiChannel;
                        break;

                    case 0xA0:
                        i              += 1;
                        parameter2      = trackData.ElementAt(i);
                        midiEvent       = new NoteAftertouchEvent(deltaTime, midiChannel, parameter1, parameter2);
                        lastMidiChannel = midiChannel;
                        break;

                    case 0xB0:
                        i              += 1;
                        parameter2      = trackData.ElementAt(i);
                        midiEvent       = new ControllerEvent(deltaTime, midiChannel, parameter1, parameter2);
                        lastMidiChannel = midiChannel;
                        break;

                    case 0xE0:
                        i              += 1;
                        parameter2      = trackData.ElementAt(i);
                        midiEvent       = new PitchBendEvent(deltaTime, midiChannel, parameter1, parameter2);
                        lastMidiChannel = midiChannel;
                        break;

                    // Might be a Control Change Messages LSB
                    default:
                        midiEvent = new ControllerEvent(deltaTime, lastMidiChannel, eventTypeValue, parameter1);
                        break;
                    }

                    i += 1;
                }
                // Meta Events
                else if (eventTypeValue == 0xFF)
                {
                    i += 1;
                    var metaEventType = trackData.ElementAt(i);
                    i += 1;
                    var metaEventLength = trackData.ElementAt(i);
                    i += 1;
                    var metaEventData = Enumerable.Range(i, metaEventLength).Select(trackData.ElementAt).ToArray();

                    switch (metaEventType)
                    {
                    case 0x00:
                        midiEvent = new SequenceNumberEvent(BitConverter.ToUInt16(metaEventData.Reverse().ToArray(), 0));
                        break;

                    case 0x01:
                        midiEvent = new TextEvent(deltaTime, StringEncoder.GetString(metaEventData));
                        break;

                    case 0x02:
                        midiEvent = new CopyrightNoticeEvent(StringEncoder.GetString(metaEventData));
                        break;

                    case 0x03:
                        midiEvent = new SequenceOrTrackNameEvent(StringEncoder.GetString(metaEventData));
                        break;

                    case 0x04:
                        midiEvent = new InstrumentNameEvent(deltaTime, StringEncoder.GetString(metaEventData));
                        break;

                    case 0x05:
                        midiEvent = new LyricsEvent(deltaTime, StringEncoder.GetString(metaEventData));
                        break;

                    case 0x06:
                        midiEvent = new MarkerEvent(deltaTime, StringEncoder.GetString(metaEventData));
                        break;

                    case 0x07:
                        midiEvent = new CuePointEvent(deltaTime, StringEncoder.GetString(metaEventData));
                        break;

                    case 0x20:
                        midiEvent = new MIDIChannelPrefixEvent(deltaTime, metaEventData[0]);
                        break;

                    case 0x2F:
                        midiEvent = new EndOfTrackEvent(deltaTime);
                        break;

                    case 0x51:
                        var tempo =
                            (metaEventData[2] & 0x0F) +
                            ((metaEventData[2] & 0xF0) * 16) +
                            ((metaEventData[1] & 0x0F) * 256) +
                            ((metaEventData[1] & 0xF0) * 4096) +
                            ((metaEventData[0] & 0x0F) * 65536) +
                            ((metaEventData[0] & 0xF0) * 1048576);
                        midiEvent = new SetTempoEvent(deltaTime, tempo);
                        break;

                    case 0x54:
                        midiEvent = new SMPTEOffsetEvent(deltaTime, metaEventData[0], metaEventData[1], metaEventData[2], metaEventData[3], metaEventData[4]);
                        break;

                    case 0x58:
                        midiEvent = new TimeSignatureEvent(deltaTime, metaEventData[0], metaEventData[1], metaEventData[2], metaEventData[3]);
                        break;

                    case 0x59:
                        midiEvent = new KeySignatureEvent(deltaTime, metaEventData[0], metaEventData[1]);
                        break;

                    case 0x7F:
                        midiEvent = new SequencerSpecificEvent(deltaTime, metaEventData);
                        break;
                    }

                    i += metaEventLength;
                }
                // System Exclusive Events
                else if (eventTypeValue == 0xF0 || eventTypeValue == 0xF7)
                {
                    var lengthTemp = new List <byte>();
                    do
                    {
                        i += 1;
                        lengthTemp.Add(trackData.ElementAt(i));
                    } while (trackData.ElementAt(i) > 0x7F);

                    var eventLength = VariableLengthUtil.decode_to_int(lengthTemp);

                    i += 1;

                    var eventData = Enumerable.Range(i, eventLength).Select(trackData.ElementAt);

                    midiEvent = new SysexEvent(deltaTime, eventTypeValue, eventData);

                    i += eventLength;
                }
            }

            return(midiEvent != null
                ? new Tuple <Option <MidiEvent>, int, byte>(new Some <MidiEvent>(midiEvent), i - startIndex, lastMidiChannel)
                : new Tuple <Option <MidiEvent>, int, byte>(new None <MidiEvent>(), i - startIndex, lastMidiChannel));
        }
Пример #3
0
 /// <summary>
 /// Determines whether the specified event is equal to the current one.
 /// </summary>
 /// <param name="copyrightNoticeEvent">The event to compare with the current one.</param>
 /// <returns>true if the specified event is equal to the current one; otherwise, false.</returns>
 public bool Equals(CopyrightNoticeEvent copyrightNoticeEvent)
 {
     return(Equals(copyrightNoticeEvent, true));
 }