Ejemplo n.º 1
0
        /// <summary>Removes from this file the MidiItem object at the specified index.</summary>
        /// <param name="index">The index in this file's list of the MidiItem object to remove.</param>
        public void RemoveItem(int index)
        {
            /* Determine how many bytes to remove from the array.  If the item is chunk info, the entire
             * chunk will be removed.  If it is a track (MTrk) chunk, decrement the number of tracks.
             */
            MidiItem      item = this.Items[index];
            int           i, n = item.Size;
            MidiChunkInfo chunkInfo = item as MidiChunkInfo;

            if (chunkInfo != null)
            {
                n += chunkInfo.Length;
                i  = this.Bytes.Length - item.Offset;
                if (n > i)
                {
                    n = i;
                }
                if (chunkInfo.Type == MidiChunkInfo.TrackType)
                {
                    --this.Header.NumberOfTracks;
                }
            }

            /* If the item is an MTrk event with a nonzero delta-time, the total time of each subsequent
             * event in the track/chunk will need to be adjusted accordingly (after this item is removed).
             */
            MidiEvent mtrkEvent = item as MidiEvent;
            int       deltaTime = (mtrkEvent == null) ? 0 : mtrkEvent.DeltaTime;

            /* Remove from the list all items whose offsets are within the range of data being removed. */
            for (i = item.Offset + n; index < this.ItemCount && this.Items[index].Offset < i; this.Items.RemoveAt(index))
            {
                item = this.Items[index];

                /* If the item being removed is a channel message/event that does not use running status, there
                 * should be a corresponding entry in the map of running statuses that needs to be removed.
                 */
                MidiChannelEvent channelEvent = item as MidiChannelEvent;
                if (channelEvent != null && !channelEvent.RunningStatus)
                {
                    this.RunningStatusMap.Remove(item.Offset);
                }

                /* If the item being removed is a meta-event representing a key signature, there should
                 * be a corresponding entry in the key signature map that also needs to be removed.
                 */
                MidiMetaEvent metaEvent = MidiFile.ItemToKeySignatureEvent(item);
                if (metaEvent != null)
                {
                    this.KeySignatureMap.Remove(metaEvent.TotalTime);
                }
            }

            /* If applicable, cascade total time changes through all subsequent events in the track. */
            this.AdjustTotalTimes(index, -deltaTime);

            /* Remove the appropriate number of bytes from the array. */
            this.Resize(-n, i, (chunkInfo == null) ? index : -1);
        }
Ejemplo n.º 2
0
        private static MidiMetaEvent ItemToKeySignatureEvent(MidiItem item)
        {
            MidiMetaEvent metaEvent = item as MidiMetaEvent;

            if (metaEvent == null)
            {
                return(null);
            }
            return((metaEvent.Type == MidiMetaEvent.KeySignatureType) ? metaEvent : null);
        }
Ejemplo n.º 3
0
        /****************
        * Constructors *
        ****************/

        #region Protected Constructors

        /// <summary>Initializes a new instance of the MidiItemDialog class.</summary>
        /// <param name="item">MIDI item to edit, or null to create a new item.</param>
        protected MidiItemDialog(MidiItem item)
        {
            this._ForNewItem = (item == null);
        }