示例#1
0
 /// <summary>
 /// Constructor accepting the device this range is for.
 /// </summary>
 public RangeMap(MappedMidiDevice device)
 {
     if (device == null)
     {
         throw new ArgumentNullException("MappedMidiDevice");
     }
     if (device.Device == null)
     {
         throw new ArgumentNullException("MappedMidiDevice.MidiDevice");
     }
     Device = device;
 }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Outputs the relative virtual x/y address for a given
        /// physical address, returning true if the mapping worked.
        /// The returned address assumes the current scrolling is
        /// at 0,0, and will need to be adjusted if the view is
        /// scrolled.
        /// </summary>
        public bool GetVirtualAddress(MappedMidiDevice device, int x, int y, out int vx, out int vy)
        {
            var range = GetRangeFor(device, x, y);

            if (range != null)
            {
                // compute the virtual address for discovered mapping
                var dx = x - range.X;
                var dy = y - range.Y;
                vx = range.VirtualX + dx;
                vy = range.VirtualY + dy;
                return(true);
            }

            // return a failed mapping
            vx = 0;
            vy = 0;
            return(false);
        }
示例#4
0
        /// <summary>
        /// Gets the device and physical XY address for a given
        /// virtual address, returning false if it cannot be mapped.
        /// </summary>
        public bool GetPhysicalAddress(int x, int y, out MappedMidiDevice device, out int px, out int py)
        {
            var range = GetRangeForVirtual(x, y);

            if (range != null)
            {
                // compute the physical address for discovered mapping
                var dx = x - range.VirtualX;
                var dy = y - range.VirtualY;
                device = range.Device;
                px     = range.X + dx;
                py     = range.Y + dy;
                return(true);
            }

            // return a failed mapping
            device = null;
            px     = 0;
            py     = 0;
            return(false);
        }
示例#5
0
 /// <summary>
 /// Returns true iff the provided physical coordinate for the
 /// given device, including any of its children.
 /// </summary>
 public bool Contains(MappedMidiDevice device, int x, int y)
 {
     return(GetRangeFor(device, x, y) != null);
 }
示例#6
0
 /// <summary>
 /// Creates a caching key for _contains for mapping physical
 /// address to virtual address.
 /// </summary>
 private string GetCacheKey(MappedMidiDevice device, int x, int y)
 {
     return(string.Format("PHYS_{0}_{1}_{2}", device.Device.ID, x, y));
 }