Пример #1
0
        /* Create a new MIDI file (represented by this instance), including the header chunk and appropriate
         * number of track chunks (with End of Track events).  This does not set delta-time division.
         */
        private MidiHeader Create(int format, int numberOfTracks)
        {
            /* Make sure we start with a clean slate. */
            this.Clear();
            int n = MidiChunkInfo.SizeItem();

            this.Bytes = new byte[n + MidiHeader.SizeItem()];

            /* Start the header chunk. */
            MidiChunkInfo chunkInfo = this.CreateChunkInfo(0, MidiChunkInfo.HeaderType);

            this.Items.Add(chunkInfo);

            /* Finish the header chunk.  (Don't set NumberOfTracks here; AddTrack will set it.) */
            MidiHeader header = new MidiHeader(this, n);

            header.Format = format;
            this.Items.Add(header);

            /* Add each track chunk (with an End of Track meta-event). */
            for (int i = 0; i < numberOfTracks; ++i)
            {
                this.AddTrack();
                this.AddMetaEvent(0, MidiMetaEvent.EndOfTrackType, null);
            }

            /* Delta-time division still needs to be set. */
            return(header);
        }
Пример #2
0
        private MidiChunkInfo CreateChunkInfo(int offset, string type)
        {
            MidiChunkInfo chunkInfo = new MidiChunkInfo(this, offset);

            chunkInfo.Type   = type;
            chunkInfo.Length = (type == MidiChunkInfo.HeaderType) ? MidiHeader.SizeItem() : 0;
            if (type == MidiChunkInfo.TrackType)
            {
                ++this.Header.NumberOfTracks;
            }
            return(chunkInfo);
        }