Example #1
0
        /// <summary>
        /// Creates a new midi event that represents a meta event.
        /// </summary>
        /// <param name="absoluteTime">The absolute-time of the event.</param>
        /// <param name="deltaTime">The delta-time of the event.</param>
        /// <param name="metaType">The type of meta event.</param>
        /// <param name="data">The data for the meta event.</param>
        /// <returns>Never returns null.</returns>
        private MidiFileEvent CreateMetaEvent(long absoluteTime, long deltaTime, byte metaType, byte[] data)
        {
            var midiEvent = new MidiFileEvent();

            midiEvent.AbsoluteTime = absoluteTime;
            midiEvent.DeltaTime    = deltaTime;
            midiEvent.Message      = this.midiMessageFactory.CreateMetaMessage((MidiMetaType)metaType, data);

            return(midiEvent);
        }
Example #2
0
        /// <summary>
        /// Creates a new midi event that represents a system exclusive event.
        /// </summary>
        /// <param name="absoluteTime">The absolute-time of the event.</param>
        /// <param name="deltaTime">The delta-time of the event.</param>
        /// <param name="data">The data for the sysex event.</param>
        /// <param name="isContinuation">An indication if the sysex data is a continuation on a previous message.</param>
        /// <returns>Never returns null.</returns>
        private MidiFileEvent CreateSysExEvent(long absoluteTime, long deltaTime, byte[] data, bool isContinuation)
        {
            var midiEvent = new MidiFileEvent();

            midiEvent.AbsoluteTime = absoluteTime;
            midiEvent.DeltaTime    = deltaTime;
            midiEvent.Message      = this.midiMessageFactory.CreateSysExMessage(data, isContinuation);

            return(midiEvent);
        }
Example #3
0
        /// <summary>
        /// Creates a new midi event that represents a midi event.
        /// </summary>
        /// <param name="absoluteTime">The absolute-time of the event.</param>
        /// <param name="deltaTime">The delta-time of the event.</param>
        /// <param name="midiMsg">The midi event data.</param>
        /// <returns>Never returns null.</returns>
        private MidiFileEvent CreateMidiEvent(long absoluteTime, long deltaTime, int midiMsg)
        {
            var midiEvent = new MidiFileEvent();

            midiEvent.AbsoluteTime = absoluteTime;
            midiEvent.DeltaTime    = deltaTime;
            midiEvent.Message      = this.midiMessageFactory.CreateShortMessage(midiMsg);

            return(midiEvent);
        }
Example #4
0
        /// <summary>
        /// Creates a new midi event that represents a midi event.
        /// </summary>
        /// <param name="absoluteTime">The absolute-time of the event.</param>
        /// <param name="deltaTime">The delta-time of the event.</param>
        /// <param name="midiMsg">The midi event data.</param>
        /// <returns>Never returns null.</returns>
        private MidiFileEvent CreateMidiEvent(long absoluteTime, long deltaTime, int midiMsg)
        {
            var midiEvent = new MidiFileEvent
            {
                AbsoluteTime = absoluteTime,
                DeltaTime    = deltaTime,
                Message      = _midiMessageFactory.CreateShortMessage(midiMsg)
            };

            return(midiEvent);
        }
Example #5
0
        /// <summary>
        /// Creates a new midi event that represents a meta event.
        /// </summary>
        /// <param name="absoluteTime">The absolute-time of the event.</param>
        /// <param name="deltaTime">The delta-time of the event.</param>
        /// <param name="metaType">The type of meta event.</param>
        /// <param name="data">The data for the meta event.</param>
        /// <returns>Never returns null.</returns>
        private MidiFileEvent CreateMetaEvent(long absoluteTime, long deltaTime, byte metaType, byte[] data)
        {
            var midiEvent = new MidiFileEvent
            {
                AbsoluteTime = absoluteTime,
                DeltaTime    = deltaTime,
                Message      = _midiMessageFactory.CreateMetaMessage((MidiMetaType)metaType, data)
            };

            return(midiEvent);
        }
Example #6
0
        /// <summary>
        /// Reads the midi track from the midi file.
        /// </summary>
        /// <param name="context">File context of the midi file being read. Must not be null.</param>
        /// <returns>Returns the custom chunk object containing the data that was read.</returns>
        public override object Read(ChunkFileContext context)
        {
            Check.IfArgumentNull(context, nameof(context));

            var reader = context.Services.GetService <FileChunkReader>();
            var stream = reader.CurrentStream;
            var chunk  = new MTrkChunk();
            var events = new List <MidiFileEvent>();

            chunk.Events = events;

            var midiReader = new MidiFileStreamReader(stream);

            // use the indication to copy buffers.
            _midiMessageFactory.CopyData = context.CopyStreams;

            while (midiReader.ReadNextEvent())
            {
                MidiFileEvent midiEvent = null;

                switch (midiReader.EventType)
                {
                case MidiFileEventType.Event:
                    midiEvent = CreateMidiEvent(midiReader.AbsoluteTime, midiReader.DeltaTime, midiReader.MidiEvent);
                    break;

                case MidiFileEventType.SystemExclusive:
                    midiEvent = CreateSysExEvent(midiReader.AbsoluteTime, midiReader.DeltaTime, midiReader.Data, false);
                    break;

                case MidiFileEventType.SystemExclusiveContinuation:
                    midiEvent = CreateSysExEvent(midiReader.AbsoluteTime, midiReader.DeltaTime, midiReader.Data, true);
                    break;

                case MidiFileEventType.Meta:
                    midiEvent = CreateMetaEvent(midiReader.AbsoluteTime, midiReader.DeltaTime, midiReader.MetaEvent, midiReader.Data);
                    break;
                }

                if (midiEvent != null)
                {
                    events.Add(midiEvent);
                }
            }

            return(chunk);
        }