Пример #1
0
        /// <summary>
        /// Reads a tempoevent into a list of trackevents
        /// </summary>
        /// <param name="from">audiostream to read from</param>
        /// <param name="to">list of trackevents where to read</param>
        /// <returns>number of bytes read from the stream</returns>
        public static int Read(AudioStream from, TrackEvent original, List <TempoEvent> to)
        {
            int        eventSize = 0;
            TempoEvent t         = new TempoEvent();

            t.CopyFrom(original);
            eventSize += from.Read(t, skipFields: new string[] { "Timing", "Prefix", "Size", "Type", "AbsoluteTiming" });
#if TEMPODEBUG
            this.Debug();
#endif
            to.Add(t);
            return(eventSize);
        }
Пример #2
0
        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);
        }