Exemplo n.º 1
0
void ARKey::setTagParameterList(TagParameterList & tpl)
{
	if (ltpls.GetCount() == 0)
	{
		// create a list of string ...
		ListOfStrings lstrs; // (1); std::vector test impl

		// either a key-string ("G") or a key-number key=3
		lstrs.AddTail(( "S,key,,r"));
		lstrs.AddTail(( "I,key,,r"));
		CreateListOfTPLs(ltpls,lstrs);
	}

	TagParameterList * rtpl = 0;
	int ret = MatchListOfTPLsWithTPL(ltpls,tpl,&rtpl);

	if( ret >= 0 && rtpl )
	{
		// we found a match!
		if (ret == 0)
		{
			// then, we now the match for the first ParameterList
			// w, h, ml, mt, mr, mb
			GuidoPos pos = rtpl->GetHeadPosition();

			TagParameterString * tps = TagParameterString::cast(rtpl->GetNext(pos));
			assert(tps);

			NVstring name = tps->getValue();

			// ist free-Tag gesetzt?
			if (name.substr(0, 5) == "free=" ) {
				mIsFree = true;
//				getKeyArray(name.substr(5, name.length()-5));
				newgetKeyArray (name.substr(5, name.length()-5));
			}
			else {
                if (name.size() == 0)
                    name = "C"; // C by default

				mIsFree = false;
				int t = (int)name[0];
				int major = (t == toupper(t));

				t = toupper(t);				
				switch (t) 
				{
					case 'F': 	fKeyNumber = -1;	break;
					case 'C': 	fKeyNumber = 0;	break;
					case 'G': 	fKeyNumber = 1;	break;
					case 'D': 	fKeyNumber = 2;	break;
					case 'A': 	fKeyNumber = 3;	break;
					case 'E': 	fKeyNumber = 4;	break;
					case 'H':
					case 'B':	fKeyNumber = 5;	break;
					default:
                        major = true;
                        fKeyNumber = 0;
				}
				
				if (!major)				fKeyNumber -= 3;		// minus 3 accidentals  (A-Major ->  a-minor ...)				
				if (name.length() > 1)
				{
					t = name[1];
					if (t == '#')		fKeyNumber += 7;
					else if (t == '&')	fKeyNumber -= 7;
				}
			}
		}
		else if (ret == 1)
		{
			// then, we now the match for the first ParameterList
			// w, h, ml, mt, mr, mb
			GuidoPos pos = rtpl->GetHeadPosition();
			TagParameterInt * tpi = TagParameterInt::cast(rtpl->GetNext(pos));
			assert(tpi);
			fKeyNumber = tpi->getValue();
		}
		delete rtpl;
	}
	else
	{
		// failure
	}
	tpl.RemoveAll();
}
Exemplo n.º 2
0
/** \brief Builds a TagParameterList out of a definition string.
	By default it owns elements.
*/
TagParameterList::TagParameterList(const NVstring & str)
		: KF_IPointerList<TagParameter>(1)
{
	// now we have to go through the string and build the TagParmaters according to the specification ...	
	minimum = 0;
	int len = int(str.length()+1);
	char * buffer = new char[len];;
	char * ptr = buffer;
	strncpy(ptr, str.c_str(), len);
	char * oldp;
	bool done = false;
	
	while (ptr && *ptr)
	{
		while (!done)
		{
			oldp = ptr;
			ptr = nextToken (ptr, ',');
			if (!ptr) break;
			
			TagParameter * tp = NULL;

			if (!strcmp("U", oldp))
			{
				TagParameterFloat * tpf = new TagParameterFloat(0.0f);
				tpf->fUnittag = true;
				tp = tpf;
			}
			else if (!strcmp("S",oldp))
				tp = new TagParameterString("");
			else if (!strcmp("F",oldp))
			{
				TagParameterFloat * tpf = new TagParameterFloat(0.0f);
				tpf->fUnittag = false;
				tp = tpf;
			}
			else if (!strcmp("I",oldp))
				tp = new TagParameterInt(0);
			else 
				cerr << "Warning: unknown tag parameter type " << oldp << endl;
			
			oldp = ptr;
			ptr = nextToken (ptr, ',');
			if (!ptr) break;
			
			if (tp) tp->setName(oldp);
			oldp = ptr;
			ptr = nextToken (ptr, ',');
			if (!ptr) break;

			if (tp) tp->setValue(oldp);
			
			oldp = ptr;
			// the last one is different!
			ptr = nextToken (ptr, ';');
			if (!ptr) done = true;

			if (tp) {
				if (!strcmp(oldp,"r"))
				{
					tp->setRequired(1);
					++minimum;
				}
				else if (!strcmp(oldp,"o"))	tp->setRequired(0);	
				AddTail(tp);
			}
		}
	}
	delete [] buffer;
}