/// <summary>
        /// Reads the number of tracks in the Midi file.
        /// </summary>
        /// <returns>
        /// <b>MidiFileResult.Succes</b> if the track count and format type
        /// are valid; otherwise, <b>MidiFileResult.InvalidFormat</b>.
        /// </returns>
        private MidiFileResult ReadTrackCount()
        {
            MidiFileResult result = MidiFileResult.Success;

            byte[] trackCount = binReader.ReadBytes(TrackCountByteCount);

            // Convert array to the same byte order as this platform.
            ConvertByteArray(trackCount);

            // Convert array to number.
            tracks = new Track[BitConverter.ToInt16(trackCount, 0)];

            // If there are more than one track and the Midi file is type 0.
            if (tracks.Length > 1 && Format == 0)
            {
                // Indicate that the format is invalid. A type 0 Midi file can
                // only have one track.
                result = MidiFileResult.InvalidFormat;
            }

            // If the format is valid.
            if (result == MidiFileResult.Success)
            {
                // Allocate tracks.
                for (int i = 0; i < tracks.Length; i++)
                {
                    tracks[i] = new Track();
                }
            }

            return(result);
        }
 /// <summary>
 /// Throws exception based on the specified error result.
 /// </summary>
 /// <param name="result">
 /// A value representing which error occurred.
 /// </param>
 private void ThrowOnError(MidiFileResult result)
 {
     // If an error occurred.
     if (result != MidiFileResult.Success)
     {
         // Throw exception.
         throw new MidiFileException(result);
     }
 }
        /// <summary>
        /// Verifies that the file is a Midi file.
        /// </summary>
        /// <returns>
        /// <b>MidiFileResult.Success</b> if the file is a Midi file;
        /// otherwise, <b>MidiFileResult.NotMidiFile</b>.
        /// </returns>
        private MidiFileResult VerifyFileType()
        {
            MidiFileResult result = MidiFileResult.Success;

            // Matches file against Midi file header.
            for (int i = 0; i < FileHeaderID.Length &&
                 result == MidiFileResult.Success; i++)
            {
                // If there is a mismatch.
                if (binReader.ReadByte() != FileHeaderID[i])
                {
                    // Indicate that this is not a Midi file.
                    result = MidiFileResult.NotMidiFile;
                }
            }

            return(result);
        }
        /// <summary>
        /// Reads the format type.
        /// </summary>
        /// <returns>
        /// <b>MidiFileResult.Success</b> if the format was read and is valid;
        /// otherwise, <b>MidiFileResult.InvalidFormat</b>.
        /// </returns>
        private MidiFileResult ReadFormat()
        {
            MidiFileResult result = MidiFileResult.Success;

            byte[] f = binReader.ReadBytes(FormatByteCount);

            // Convert array to the same byte order as this platform.
            ConvertByteArray(f);

            // Convert array to number.
            format = BitConverter.ToInt16(f, 0);

            // If the format is an invalid value.
            if (format > FormatMax)
            {
                // Indicate that the format is invalid.
                result = MidiFileResult.InvalidFormat;
            }

            return(result);
        }
Пример #5
0
 /// <summary>
 /// Throws exception based on the specified error result.
 /// </summary>
 /// <param name="result">
 /// A value representing which error occurred.
 /// </param>
 private void ThrowOnError(MidiFileResult result)
 {
     // If an error occurred.
     if(result != MidiFileResult.Success)
     {
         // Throw exception.
         throw new MidiFileException(result);
     }
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the MidiFileException class with the
 /// specified error code.
 /// </summary>
 /// <param name="result">
 /// Error code.
 /// </param>
 internal MidiFileException(MidiFileResult result)
 {
     this.result = result;
 }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the MidiFileException class with the
        /// specified error code.
        /// </summary>
        /// <param name="result">
        /// Error code.
        /// </param>
		internal MidiFileException(MidiFileResult result)
		{
            this.result = result;
		}