예제 #1
0
        public Int32 LoadData(byte[] data)
        {
            Console.WriteLine();
            Console.Write("Load data ");
            Console.Write(data.Length);
            Console.WriteLine("(Bytes)");

            int P = 0;

//*
            //header
            for (int i = 0; i < 4; i++)
            {
                if (data[P++] != HeaderChunk.CHUNK_TYPE_HEADER[i])
                {
                    Console.WriteLine("    Error ! Bad Header Chunk .");
                    System.Exception err = new System.Exception("Bad Header Chunk !");
                    throw(err);
                }
            }
            header = new HeaderChunk(Midi.readMSB32(data, P)); P += 4;
            P     += header.LoadChunkData(data, P);

            if (header.MidiType != HeaderChunk.MIDI_TYPE_0 && header.MidiType != HeaderChunk.MIDI_TYPE_1)
            {
                Console.WriteLine("    Error ! Only support Midi Format 0 or 1 .");
                System.Exception err = new System.Exception("Only support Midi Format 0 or 1 !");
                throw(err);
            }
//*
            //track
            track = new TrackChunk[header.Tracks];
            for (int t = 0; t < header.Tracks; t++)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (data[P++] != TrackChunk.CHUNK_TYPE_TRACK[i])
                    {
                        Console.Write("    Error ! Bad Track Chunk.(" + t + ") .");
                        System.Exception err = new System.Exception("Bad Track Chunk.(" + t + ") !");
                        throw(err);
                    }
                }
                track[t] = new TrackChunk(Midi.readMSB32(data, P)); P += 4;
                P       += track[t].LoadChunkData(data, P);
            }
//*/

            Data = data;

            Console.Write("Midi Created ! Process ");
            Console.Write(P);
            Console.WriteLine("(Bytes)");

            return(P);
        }
예제 #2
0
        public Int32 LoadData(byte[] data)
        {
            Console.WriteLine();
            Console.Write("Load data ");
            Console.Write(data.Length);
            Console.WriteLine("(Bytes)");

            int  P = 0;
            //*
            //header
            for(int i=0;i<4;i++)
            {
                if(data[P++]!=HeaderChunk.CHUNK_TYPE_HEADER[i])
                {
                    Console.WriteLine("    Error ! Bad Header Chunk .");
                    System.Exception err = new System.Exception("Bad Header Chunk !");
                    throw(err);
                }
            }
            header = new HeaderChunk(Midi.readMSB32(data,P));P+=4;
            P+=header.LoadChunkData(data,P);

            if(header.MidiType!=HeaderChunk.MIDI_TYPE_0 && header.MidiType!=HeaderChunk.MIDI_TYPE_1)
            {
                Console.WriteLine("    Error ! Only support Midi Format 0 or 1 .");
                System.Exception err = new System.Exception("Only support Midi Format 0 or 1 !");
                throw(err);
            }
            //*
            //track
            track = new TrackChunk[header.Tracks];
            for(int t=0;t<header.Tracks;t++)
            {
                for(int i=0;i<4;i++)
                {
                    if(data[P++]!=TrackChunk.CHUNK_TYPE_TRACK[i])
                    {
                        Console.Write("    Error ! Bad Track Chunk.("+t+") .");
                        System.Exception err = new System.Exception("Bad Track Chunk.("+t+") !");
                        throw(err);
                    }
                }
                track[t] = new TrackChunk(Midi.readMSB32(data,P));P+=4;
                P+=track[t].LoadChunkData(data,P);
            }
            //*/

            Data = data ;

            Console.Write("Midi Created ! Process ");
            Console.Write(P);
            Console.WriteLine("(Bytes)");

            return P;
        }