128 lines
4.2 KiB
C++
128 lines
4.2 KiB
C++
#include <guitar/LineParser.hpp>
|
|
|
|
int LineParser::getElement(Element &element)
|
|
{
|
|
char ch;
|
|
|
|
element.setFret(-1);
|
|
element.setAction(Action::None);
|
|
if(mPosition>=mLength)return -1;
|
|
ch=charAt(mPosition++);
|
|
if(::isdigit(ch)&&(ch>='0'&&ch<='9'))
|
|
{
|
|
element.setAction(Action::Pick);
|
|
element.setFret(ch-48);
|
|
}
|
|
else if(::isalpha(ch))
|
|
{
|
|
if('o'==ch||'O'==ch) // instead of zero some tabs have an alpha 'O' - for (O)pen.
|
|
{
|
|
element.setAction(Action::Pick);
|
|
element.setFret(0);
|
|
return 1;
|
|
}
|
|
else if('p'==ch||'P'==ch) // pull-off
|
|
{
|
|
int result=getElement(element); // fetch the next element, this is what we are pulling into
|
|
if(1!=result)return result; // if we didn't get anything return;
|
|
element.setAction(Action::PullOff); // set action to pull-off
|
|
return result;
|
|
}
|
|
else if('b'==ch||'B'==ch) // Bend
|
|
{
|
|
int result=getElement(element); // fetch the next element, this is what we are bending into
|
|
if(1!=result)return result; // if we didn't get anything return;
|
|
element.setAction(Action::Bend); // set action to bend
|
|
return result;
|
|
}
|
|
else if('h'==ch||'H'==ch) // hammer-on
|
|
{
|
|
int result=getElement(element); // fetch the next element, this is what we are hammering onto
|
|
if(1!=result)return result; // if we didn't get anything return;
|
|
element.setAction(Action::HammerOn); // set action to hammer-on
|
|
return result;
|
|
}
|
|
else if('r'==ch||'R'==ch) // Release(bend) into this note
|
|
{
|
|
int result=getElement(element); // fetch the next element, this is what we are releasing into
|
|
if(1!=result)return result; // if we didn't get anything return;
|
|
element.setAction(Action::Release); // set action to Release
|
|
return result;
|
|
}
|
|
else if('s'==ch||'S'==ch) // Slide
|
|
{
|
|
int result=getElement(element); // fetch the next element, this is what we are sliding into
|
|
if(1!=result)return result; // if we didn't get anything return;
|
|
element.setAction(Action::SlideUp); // set action to SlideUp
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
element.setAction(Action::None); // invalid entry
|
|
element.setFret(-1); // no referenced note
|
|
return 0; // return not-handled
|
|
}
|
|
}
|
|
else if('^'==ch) // Bend
|
|
{
|
|
int result=getElement(element); // fetch the next element, this is what we are bending into
|
|
if(1!=result)return result; // if we didn't get anything return;
|
|
element.setAction(Action::Bend); // set action to bend
|
|
return result;
|
|
}
|
|
else if('\\'==ch)
|
|
{
|
|
int result=getElement(element); // fetch the next element, this is what we are sliding into
|
|
if(1!=result)return result; // if we didn't get anything return;
|
|
element.setAction(Action::SlideDown); // set action to SlideDown
|
|
return result;
|
|
}
|
|
else if('/'==ch)
|
|
{
|
|
int result=getElement(element); // fetch the next element, this is what we are sliding
|
|
if(1!=result)return result; // if we didn't get anything return;
|
|
element.setAction(Action::SlideUp); // set action to SlideUp
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
element.setAction(Action::None); // invalid entry
|
|
element.setFret(-1); // no referenced note
|
|
return 0; // return not-handled
|
|
}
|
|
ch=charAt(mPosition);
|
|
|
|
if(!(::isdigit(ch)&&(ch>='0'&&ch<='9'))&&!(::isalpha(ch)&&'O'==ch))
|
|
{
|
|
element.setAction(Action::Pick); // fretted note
|
|
return 1; // return handled
|
|
}
|
|
if('O'==ch||'o'==ch)ch='0';
|
|
mPosition++;
|
|
element.setFret((element.getFret()*10)+(ch-48));
|
|
return 1; // return handled
|
|
}
|
|
|
|
void LineParser::putElement(const Element &element)
|
|
{
|
|
String strItem=Action(element.getAction()).toStringShort()+String().fromInt(element.getFret());
|
|
*this+=strItem;
|
|
mPosition+=strItem.length();
|
|
return;
|
|
}
|
|
|
|
void LineParser::putElement(char ch)
|
|
{
|
|
*this+=ch;
|
|
mPosition++;
|
|
return;
|
|
}
|
|
|
|
int LineParser::peekElement(Element &element)
|
|
{
|
|
int position=mPosition;
|
|
int result=getElement(element);
|
|
mPosition=position;
|
|
return result;
|
|
}
|