コード例 #1
0
ファイル: MidiFileReader.cs プロジェクト: Jbtyson/cis598
        /// <summary>
        /// Reads the data for the next track from the Midi file.
        /// </summary>
        /// <param name="trackNum">
        /// The track number.
        /// </param>
        private void ReadNextTrack(int trackNum)
        {
            MetaType metaType = MetaType.TrackName;
            int status = 0;
            int runningStatus = 0;

            // Read length of track.
            binReader.ReadBytes(LengthByteCount);

            // Continue reading Midi events until the end of the track.
            while(metaType != MetaType.EndOfTrack)
            {
                // Next Midi message in track.
                IMidiMessage msg = null;

                // Ticks for next Midi event.
                int ticks = ReadVariableLengthQuantity();

                // Read status byte for the next Midi message.
                status = binReader.ReadByte(); 

                // If this is a status byte.
                if((status & StatusFlag) == StatusFlag)
                { 
                    // If the next Midi message is a channel message.
                    if(ChannelMessage.IsChannelMessage(status))
                    {
                        // Read channel message from the Midi file.
                        msg = ReadChannelMessage(status);  
                      
                        // Update running status.
                        runningStatus = status;                         
                    }
                    // Else if the next Midi message is a meta message.
                    else if(MetaMessage.IsMetaMessage(status))
                    {
                        // Read the type of meta message.
                        metaType = (MetaType)binReader.ReadByte();

                        // Read the length of the meta message data.
                        int length = ReadVariableLengthQuantity();

                        // Read the meta message data.
                        byte[] data = binReader.ReadBytes(length);

                        // Create meta message.
                        msg = new MetaMessage(metaType, data);
                    }
                    // Else if the next Midi message is a system exclusive 
                    // message.
                    else if(SysExMessage.IsSysExMessage(status))
                    {
                        // The type of system exclusive message.
                        SysExType type = (SysExType)status;

                        // Read the length of the system exclusive data.
                        int length = ReadVariableLengthQuantity();

                        // Read the system exclusive data.
                        byte[] data = binReader.ReadBytes(length);

                        // Create system exclusive message.
                        msg = new SysExMessage(type, data);
                    }
                }
                // Assumes running status.
                else
                {
                    // Create channel message.
                    msg = ReadChannelMessage(runningStatus, status);
                }

                // Create the next Midi event and store it in the specified
                // track.
                MidiEvent e = new MidiEvent(msg, ticks);
                tracks[trackNum].Add(e);
            } 
        }
コード例 #2
0
ファイル: Track.cs プロジェクト: Jbtyson/cis598
        /// <summary>
        /// Inserts a MidiEvent into the Track at the specified index.
        /// </summary>
        /// <param name="index">
        /// The zero-based index at which <i>e</i> should be inserted. 
        /// </param>
        /// <param name="e">
        /// The MidiEvent to insert.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown if index is less than zero or greater than or equal to 
        /// Count.
        /// </exception>
        public void Insert(int index, MidiEvent e)
        {
            // Enforce preconditions.
            if(index < 0 || index >= Count)
                throw new ArgumentOutOfRangeException("index", index,
                    "Index into track out of range.");

            MidiEvents.Insert(index, e);

            // Indicate that the track has changed.
            version++;
        }
コード例 #3
0
ファイル: MidiEvent.cs プロジェクト: Jbtyson/cis598
 /// <summary>
 /// Initializes a new instance of the MidiEventArgs class with the
 /// specified Midi event.
 /// </summary>
 /// <param name="e">
 /// The Midi event for this event.
 /// </param>
 public MidiEventArgs(MidiEvent e)
 {
     evt = e;
 }
コード例 #4
0
ファイル: Track.cs プロジェクト: Jbtyson/cis598
 /// <summary>
 /// Add a Midi event to the end of the track.
 /// </summary>
 /// <param name="e">
 /// The Midi event to add to the track.
 /// </param>
 public void Add(MidiEvent e)
 {
     MidiEvents.Add(e);
     version++;
 }       
コード例 #5
0
ファイル: Track.cs プロジェクト: Jbtyson/cis598
        /// <summary>
        /// Removes the first occurrance of a MidiEvent from the Track.
        /// </summary>
        /// <param name="e">
        /// The MidiEvent to remove from the Track.
        /// </param>
        public void Remove(MidiEvent e)
        {
            MidiEvents.Remove(e);

            // Indicate that the track has changed.
            version++;
        }
コード例 #6
0
        /// <summary>
        /// Reads the data for the next track from the Midi file.
        /// </summary>
        /// <param name="trackNum">
        /// The track number.
        /// </param>
        private void ReadNextTrack(int trackNum)
        {
            MetaType metaType      = MetaType.TrackName;
            int      status        = 0;
            int      runningStatus = 0;

            // Read length of track.
            binReader.ReadBytes(LengthByteCount);

            // Continue reading Midi events until the end of the track.
            while (metaType != MetaType.EndOfTrack)
            {
                // Next Midi message in track.
                IMidiMessage msg = null;

                // Ticks for next Midi event.
                int ticks = ReadVariableLengthQuantity();

                // Read status byte for the next Midi message.
                status = binReader.ReadByte();

                // If this is a status byte.
                if ((status & StatusFlag) == StatusFlag)
                {
                    // If the next Midi message is a channel message.
                    if (ChannelMessage.IsChannelMessage(status))
                    {
                        // Read channel message from the Midi file.
                        msg = ReadChannelMessage(status);

                        // Update running status.
                        runningStatus = status;
                    }
                    // Else if the next Midi message is a meta message.
                    else if (MetaMessage.IsMetaMessage(status))
                    {
                        // Read the type of meta message.
                        metaType = (MetaType)binReader.ReadByte();

                        // Read the length of the meta message data.
                        int length = ReadVariableLengthQuantity();

                        // Read the meta message data.
                        byte[] data = binReader.ReadBytes(length);

                        // Create meta message.
                        msg = new MetaMessage(metaType, data);
                    }
                    // Else if the next Midi message is a system exclusive
                    // message.
                    else if (SysExMessage.IsSysExMessage(status))
                    {
                        // The type of system exclusive message.
                        SysExType type = (SysExType)status;

                        // Read the length of the system exclusive data.
                        int length = ReadVariableLengthQuantity();

                        // Read the system exclusive data.
                        byte[] data = binReader.ReadBytes(length);

                        // Create system exclusive message.
                        msg = new SysExMessage(type, data);
                    }
                }
                // Assumes running status.
                else
                {
                    // Create channel message.
                    msg = ReadChannelMessage(runningStatus, status);
                }

                // Create the next Midi event and store it in the specified
                // track.
                MidiEvent e = new MidiEvent(msg, ticks);
                tracks[trackNum].Add(e);
            }
        }
コード例 #7
0
 /// <summary>
 /// Add a Midi event to the end of the track.
 /// </summary>
 /// <param name="e">
 /// The Midi event to add to the track.
 /// </param>
 public void Add(MidiEvent e)
 {
     MidiEvents.Add(e);
     version++;
 }
コード例 #8
0
ファイル: MidiEvent.cs プロジェクト: Pyrdacor/AmiMus
 /// <summary>
 /// Initializes a new instance of the MidiEventArgs class with the
 /// specified Midi event.
 /// </summary>
 /// <param name="e">
 /// The Midi event for this event.
 /// </param>
 public MidiEventArgs(MidiEvent e)
 {
     evt = e;
 }