Exemplo n.º 1
0
        /// <summary>
        /// Returns the specific block within this range that is
        /// mapping a device's physical x/y address.  Returns null
        /// if this address is not mapped to this object or its
        /// children.
        /// </summary>
        public RangeMap GetRangeFor(MappedMidiDevice device, int x, int y)
        {
            RangeMap result = null;

            // check input
            if (device == null)
            {
                throw new ArgumentNullException("MidiDevice");
            }

            // check if this result is cached
            string cacheKey = GetCacheKey(device, x, y);

            if (_contains.TryGetValue(cacheKey, out result))
            {
                return(result);
            }

            // compute result if not cached
            try
            {
                // check this block
                if (device.Device.ID == Device.Device.ID)
                {
                    if (x >= X && x < X + Width)
                    {
                        if (y >= Y && y < Y + Height)
                        {
                            return(result = this);
                        }
                    }
                }

                // check child blocks
                foreach (var child in Children)
                {
                    result = child.GetRangeFor(device, x, y);
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }
            finally
            {
                // cache result
                _contains[cacheKey] = result;
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the specific block within this range that is
        /// mapped to a virtual address
        /// </summary>
        public RangeMap GetRangeForVirtual(int x, int y)
        {
            RangeMap result = null;

            // check if this result is cached
            string cacheKey = GetVirtualCacheKey(x, y);

            if (_contains.TryGetValue(cacheKey, out result))
            {
                return(result);
            }

            // compute result if not cached
            try
            {
                // check this block
                if (x >= VirtualX && x < VirtualX + Width)
                {
                    if (y >= VirtualY && y < VirtualY + Height)
                    {
                        return(result = this);
                    }
                }

                // check child blocks
                foreach (var child in Children)
                {
                    result = child.GetRangeForVirtual(x, y);
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }
            finally
            {
                // cache result
                _contains[cacheKey] = result;
            }
            return(result);
        }