public AttributePointSetting GetSettingForAttributeName(string attributeName) { // TODO: Maybe store these in a hash table to make this more efficient? AttributePointSetting theSetting = null; foreach (AttributePointSetting setting in _attributePointSettings) { if (setting.AttributeName == attributeName) { theSetting = setting; break; } } return(theSetting); }
public List <AttributePoint> GetAttributePoints(List <Point> movementPoints, Fixture fixture) { // Make a new list of attribute points, one per movement point List <AttributePoint> attrPoints = new List <AttributePoint>(); foreach (Point pt in movementPoints) { attrPoints.Add(new AttributePoint(new Point(pt.X, pt.Y), fixture)); } // Assign each attribute point to its closest movement point foreach (AttributePoint attrPt in _attributePoints) { int closestMovementPointIndex = Utilities.GetClosestPointIndexInList(attrPt.Point, movementPoints); attrPoints[closestMovementPointIndex] = attrPt; } // If there isn't a key attribute point assigned to the first movement point, we don't // know what value each fixture attribute should start at. So, we ask each fixture // attribute what its current DMX value is foreach (AttributePointSetting setting in attrPoints[0].AttributePointSettings) { if (!setting.Active) { // If the setting isn't active, get the fixture attribute's current value setting.Value = setting.Attribute.GetLevel(); } } // Now fill in the intermediate values for the movement points that // don't have a corresponding attribute point. // First, we keep track of the last key point for each attribute, currently 0 Dictionary <string, int> lastKeyPointForAttribute = new Dictionary <string, int>(); foreach (FixtureAttribute attr in fixture.Attributes) { lastKeyPointForAttribute[attr.Name] = 0; } // Next, step through the attribute points; whenever we hit a "key" point // (that is, a point that has an active setting), if we were supposed to // fade to that value, go back and fill in the intermediate values for (int i = 0; i < attrPoints.Count; i++) { AttributePoint attrPoint = attrPoints[i]; foreach (AttributePointSetting setting in attrPoint.AttributePointSettings) { if (setting.Active) { if (!setting.Snap) { // If we aren't supposed to snap to this value, that means // we were supposed to have been fading to it. So we have // to go back and fill in the intermediate values between // this AttributePoint and this attribute's last key point. int lastKeyPointIndex = lastKeyPointForAttribute[setting.AttributeName]; int startVal = attrPoints[lastKeyPointIndex].GetSettingForAttributeName(setting.AttributeName).Value; int endVal = setting.Value; int incrementPerIntermediatePoint = (endVal - startVal) / (i - lastKeyPointIndex); for (int j = lastKeyPointIndex + 1; j < i; j++) { AttributePointSetting intermediateSetting = attrPoints[j].GetSettingForAttributeName(setting.AttributeName); intermediateSetting.Value = startVal + incrementPerIntermediatePoint * (j - lastKeyPointIndex); intermediateSetting.Active = true; } } // Since the setting is active, this is this attribute's // most recent "key" attributePoint lastKeyPointForAttribute[setting.AttributeName] = i; } else { // Since this is not a "key" point for this attribute, copy // in the value from the last key point. It might turn out that // we're supposed to be fading to the next key point here, but // if this turns out to be the case, we'll come back and // correct this point when we get the next key point AttributePoint lastKeyPoint = attrPoints[lastKeyPointForAttribute[setting.AttributeName]]; setting.Value = lastKeyPoint.GetSettingForAttributeName(setting.AttributeName).Value; } } } return(attrPoints); }