Exemplo n.º 1
0
float ModulatorSamplerSound::getGainValueForVelocityXFade(int velocity)
{
	if (upperVeloXFadeValue == 0 && lowerVeloXFadeValue == 0) return 1.0f;

	Range<int> upperRange = Range<int>(velocityRange.getHighestBit() - upperVeloXFadeValue, velocityRange.getHighestBit());
	Range<int> lowerRange = Range<int>(velocityRange.findNextSetBit(0), velocityRange.findNextSetBit(0) + lowerVeloXFadeValue);

	float delta = 1.0f;

	if (upperRange.contains(velocity))
	{
		delta = (float)(velocity - upperRange.getStart()) / (upperRange.getLength());

		return Interpolator::interpolateLinear(1.0f, 0.0f, delta);
	}
	else if (lowerRange.contains(velocity))
	{
		delta = (float)(velocity - lowerRange.getStart()) / (lowerRange.getLength());

		return Interpolator::interpolateLinear(0.0f, 1.0f, delta);
	}
	else
	{
		return 1.0f;
	}
}
Exemplo n.º 2
0
list<UTMNode> RangeTree::searchTree(TreeNode *root, const Range &query, const Range &range)
{
    if (root->type == LEAF)
    {
        if (query.contains(root->point))
            return {root->point};
        return {};
    }


    bool vertical = root->type == VERTICAL;
    double line = root->line();
    TreeNode *left = root->left;
    TreeNode *right = root->right;
    list<UTMNode> result;

    Range leftRange = vertical ? range.left(line) : range.below(line); // if current node is vertical split, left child is what's to the left of line
    Range rightRange = vertical ? range.right(line) : range.above(line); // if current node is a horizontal vertical split, left child is what's to below the line

    // left child completely inside
    if (leftRange.inside(query))
        result.splice(result.end(), points(left));
    else if (query.intersects(leftRange))
        result.splice(result.end(), searchTree(left, query, leftRange));

    if (rightRange.inside(query))
        result.splice(result.end(), points(right));
    else if (query.intersects(rightRange))
        result.splice(result.end(), searchTree(right, query, rightRange));

    return result;
}
Exemplo n.º 3
0
vector<Range<T> > RoutingTree<T>::splitRange(Range<T> range, Node<T> *parentNode){
	vector<Node<T> *> childNodes = parentNode->getChildNodes();
	vector<Range<T> > result;
	int i = 0;
	try{
		for (; i < childNodes.size(); i++){
			Range<T> curRange = childNodes[i]->getRange();
			if (range.atLeft(curRange)){
				result.push_back(range);
				break;
			}
			else if (range.leftOverlap(curRange)){
				Range<T> tempResult(range.first, curRange.first); // overlap at the margin
				result.push_back(tempResult);
				break;  
			}
			else if (range.isContainedBy(curRange)){
				break;
			}
			else if (range.contains(curRange)){
				if (range.first != curRange.first){
					Range<T> tempResult(range.first, curRange.first); // overlap at the margin
					result.push_back(tempResult);
				}

				if (range.second != curRange.second){
					range.first = curRange.second;
				}
				else{
					break;
				}
			}
			else{ // right overlap or at right
				if (range.first < curRange.second){
					range.first = curRange.second;
				}
			}
		}
	}

	catch (string e){
		cerr<<e<<endl;
	}

	if (i == childNodes.size()){
		result.push_back(range);
	}

	return result;
}
Exemplo n.º 4
0
int RoutingTree<T>::checkRange(Range<T> range, Node<T> *node, Node<T> **subNode) {
	vector<Node<T> *> childNodes = node->getChildNodes();
	if (childNodes.size() == 0) {
		return 2;
	}
	
	for (int i = 0; i < childNodes.size(); i++) {
		if (range.overlap(childNodes[i]->getRange())) {
			if (range.contains(childNodes[i]->getRange()) && range.isContainedBy(childNodes[i]->getRange())) {
				return 1;
			}
			if (range.isContainedBy(childNodes[i]->getRange())) {
				*subNode = childNodes[i];
				return 0;
			}
			return 3;
		}
	}
	return 2;
}
Exemplo n.º 5
0
vector<Node<T> *> RoutingTree<T>::insert(vector<Range<T> > subRanges, Node<T> *parentNode){
	Range<T> parentNodeRange = parentNode->getRange();
	vector<Node<T> *> childrenNodes = parentNode->getChildNodes();
	vector<Node<T> *> result;
	int childrenNodesIndex = 0, subRangeIndex = 0;
	cout << "parentNode before insertion: ... \n";
	//DisplayCoveredRanges(parentNode);
	parentNode->printChildNodes();
	try{
		/* Error Handling Section */
		if (subRanges.size() == 0)
		{
			cerr << "ERROR: no subranges need to be inserted!\n";
		}
		for (int i = 0; i < subRanges.size(); i++)
		{
			Range<T> currentSubRange = subRanges.at(i);
			if (!parentNodeRange.contains(currentSubRange))
			{
				cerr << "ERROR: One or more splitted subrange exceeded the parent range! \n";
			}
			for (int j = i + 1; j < subRanges.size(); j++)
			{
				Range<T> rangeToBeChecked = subRanges.at(j);
				if (currentSubRange.overlap(rangeToBeChecked))
				{
					cerr << "ERROR: overlap in subranges! \n";
				}
			}	
		}
		/* Insertion */
		for (; childrenNodesIndex < childrenNodes.size(); childrenNodesIndex++)
		{
			Range<T> currentChildRange = (childrenNodes.at(childrenNodesIndex))->getRange();
			Range<T> currentSubRange = subRanges.at(subRangeIndex);
			if (currentChildRange.atLeft(currentSubRange))
			{
				//result.push_back(childrenNodes.at(childrenNodesIndex));
			}
			else if (currentSubRange.atLeft(currentChildRange))
			{
				Node<T> *newNode = new Node<T>(currentSubRange);
				parentNode->insertChildNode(newNode);
				result.push_back(newNode);
				//result.push_back(childrenNodes.at(childrenNodesIndex));
				if (++subRangeIndex < subRanges.size())
				{
					if ((subRanges.at(subRangeIndex)).equals(currentChildRange))
					{
						subRangeIndex++;
					}
				}
				else
				{
					break;
				}
			}
			else if (currentSubRange.equals(currentChildRange))
			{
				//result.push_back(childrenNodes.at(childrenNodesIndex));
				subRangeIndex++;
			}
			else
			{
				cerr << "Error:possible overlapping! \n";
			}
		}
		if (subRangeIndex < subRanges.size())
		{
			Node<T> *newNode = new Node<T>(subRanges.at(subRangeIndex));
			parentNode->insertChildNode(newNode);
			result.push_back(newNode);
		}
	}

	catch (string e){
		cerr<<e<<endl;
	}
	cout << "After Insertion: ... \n";
	//DisplayCoveredRanges(parentNode);
	//parentNode -> printChildNodes();
	return result;
}
Exemplo n.º 6
0
 ValueContainer split(const Range &my_range, const Key &new_end) {
     assert(my_range.contains(Range(new_end)));
     return *this;
 }
Exemplo n.º 7
0
	inline bool isContainedBy(const Range &other) const {
		return other.contains(*this);
	}