コード例 #1
0
        /// <summary>
        /// reads and determines the type of a track event, and adds that to the proper list
        /// </summary>
        /// <param name="from">stream where to read from</param>
        /// <param name="allevents">list of all events (notes and controllers)</param>
        /// <param name="tempoevents">list of tempo events</param>
        /// <param name="tsigevents">list of time signature events</param>
        /// <returns>number of bytes read</returns>
        public static int Read(AudioStream from, TrackChunk track, List <TempoEvent> tempoevents, List <TimeSignatureEvent> tsigevents)
        {
            track.Events.Add(new TrackEvent());
            int index     = track.Events.Count - 1;
            int eventSize = from.Read(track.Events[index], vlv: "Timing", skipFields: new string[1] {
                "AbsoluteTiming"
            });

            track.TickSize += ByteConverter.ToInt(track.Events[index].Timing);
            track.Events[index].AbsoluteTiming = track.TickSize;

            // meta and sysex events
            switch (track.Events[index].Prefix)
            {
            case (byte)TrackEvent.EventType.SysEx1:
            case (byte)TrackEvent.EventType.SysEx2:
                Console.WriteLine("System exclusive events are not supported.");
                return(-1);

            case (byte)TrackEvent.EventType.Meta:
                eventSize += MetaEvent.Read(from, track, tempoevents, tsigevents);
                break;

            default:
                int midiread = MidiEvent.Read(from, track.Events);
                if (midiread == -1)
                {
                    return(-1);
                }
                eventSize += midiread;
                break;
            }
            return(eventSize);
        }
コード例 #2
0
ファイル: MetaEvent.cs プロジェクト: santerinogelainen/midify
        public byte[] Size; //VLV

        /// <summary>
        /// Reads a metaevent from the filestream
        /// </summary>
        /// <param name="from">stream where to read from</param>
        /// <param name="allevents">list of all trackevents</param>
        /// <param name="tempoevents">list of tempoevents</param>
        /// <param name="tsigevents">list of timesignatureevents</param>
        /// <returns>number of bytes read / skipped</returns>
        public new static int Read(AudioStream from, TrackChunk track, List <TempoEvent> tempoevents, List <TimeSignatureEvent> tsigevents)
        {
            // index is always last one in list
            int index = track.Events.Count - 1;

            // new meta event with the prefix and timing
            MetaEvent m = new MetaEvent();

            m.CopyFrom(track.Events[index]);

            // read new data into the meta event class, Size is a VLV and skip over Timing and Prefix
            int eventSize = from.Read(m, vlv: "Size", skipFields: new string[] { "Timing", "Prefix", "AbsoluteTiming" });

            // read tempo or time signature events
            switch (m.Type)
            {
            case (byte)MetaEvent.MetaEventType.Tempo:
                eventSize += TempoEvent.Read(from, track.Events[index], tempoevents);
                track.Events.RemoveAt(index);
                return(eventSize);

            case (byte)MetaEvent.MetaEventType.TimeSignature:
                eventSize += TimeSignatureEvent.Read(from, track.Events[index], tsigevents);
                track.Events.RemoveAt(index);
                return(eventSize);
            }

            // skip the meta event data
            int skip = ByteConverter.ToInt(m.Size);

            from.Skip(skip);

            // remove the event since we do not need it
            track.Events.RemoveAt(index);

#if (METADEBUG)
            this.Debug();
            Console.WriteLine("Bytes skipped: {0}", skip);
#endif

            return(eventSize + skip);
        }