Beispiel #1
0
        public static SEQ Load(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            // All SEP/SEQ stuff is big-endian, like MIDI
            if (data.Length < 15)
            {
                ErrorManager.SignalError("SEQ: Data is too short");
            }
            int magic   = BEBitConv.FromInt32(data, 0);
            int version = BEBitConv.FromInt32(data, 4);

            if (magic != Magic)
            {
                ErrorManager.SignalIgnorableError("SEQ: Magic number is wrong");
            }
            if (version != Version)
            {
                ErrorManager.SignalIgnorableError("SEQ: Version number is wrong");
            }
            short resolution = BEBitConv.FromInt16(data, 8);
            int   tempo      = MIDIConv.From3BE(data, 10);
            short rhythm     = BEBitConv.FromInt16(data, 13);

            byte[] scoredata = new byte [data.Length - 15];
            Array.Copy(data, 15, scoredata, 0, scoredata.Length);
            return(new SEQ(resolution, tempo, rhythm, scoredata));
        }
Beispiel #2
0
        public static int FromInt32(Endianness endianness, byte[] str, int offset)
        {
            switch (endianness)
            {
            case Endianness.LittleEndian:
                return(BitConv.FromInt32(str, offset));

            case Endianness.BigEndian:
                return(BEBitConv.FromInt32(str, offset));

            default:
                throw new ArgumentException("Endianness is invalid.");
            }
        }
Beispiel #3
0
        public static SEP Load(byte[] data, int seqcount)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (seqcount < 0)
            {
                throw new ArgumentOutOfRangeException("seqcount");
            }
            // All SEP/SEQ stuff is big-endian, like MIDI
            if (data.Length < 6)
            {
                ErrorManager.SignalError("SEP: Data is too short");
            }
            int   magic   = BEBitConv.FromInt32(data, 0);
            short version = BEBitConv.FromInt16(data, 4);

            if (magic != Magic)
            {
                ErrorManager.SignalIgnorableError("SEP: Magic number is wrong");
            }
            if (version != Version)
            {
                ErrorManager.SignalIgnorableError("SEP: Version number is wrong");
            }
            int offset = 6;

            SEQ[] seqs = new SEQ [seqcount];
            for (int i = 0; i < seqcount; i++)
            {
                if (data.Length < offset + 13)
                {
                    ErrorManager.SignalError("SEP: Data is too short");
                }
                short seqid      = BEBitConv.FromInt16(data, offset);
                short resolution = BEBitConv.FromInt16(data, offset + 2);
                // tempo is 3 (yes, three) bytes
                int   tempo  = MIDIConv.From3BE(data, offset + 4);
                short rhythm = BEBitConv.FromInt16(data, offset + 7);
                int   length = BEBitConv.FromInt32(data, offset + 9);
                if (seqid != i)
                {
                    ErrorManager.SignalIgnorableError("SEP: Track number is wrong");
                }
                if (length < 0)
                {
                    ErrorManager.SignalError("SEP: Track length is negative");
                }
                offset += 13;
                if (data.Length < offset + length)
                {
                    ErrorManager.SignalError("SEP: Data is too short");
                }
                byte[] seqdata = new byte [length];
                Array.Copy(data, offset, seqdata, 0, length);
                seqs[i] = new SEQ(resolution, tempo, rhythm, seqdata);
                offset += length;
            }
            return(new SEP(seqs));
        }