Exemplo n.º 1
0
//_______________________________________________________________________________
bool xmlreader::endElement (const char* eltName)
{
	debug("endElement", eltName);
	Sxmlelement top = fStack.top();
	fStack.pop();
	return top->getName() == eltName;
}
Exemplo n.º 2
0
//------------------------------------------------------------------------
// creates a part containing 'count' measures
//------------------------------------------------------------------------
Sxmlelement makePart(int count) {
	Sxmlelement part = factory::instance().create(k_part);
	part->add (newAttribute("id", kPartID));
	for (int i=1; i<=count; i++)			// and 'count' times
		part->push (makemeasure(i));			// adds a new measure to the part
	return part;
}
Exemplo n.º 3
0
//------------------------------------------------------------------------
Sxmlelement musicxmlfactory::newrest (int duration, const char* type)
{
	Sxmlelement elt = element(k_note);
	if (duration) elt->push(element(k_duration, duration));
	if (type) elt->push(element(k_type, type));
	return elt;
}
Exemplo n.º 4
0
//------------------------------------------------------------------------
// the function that creates and writes the score
//------------------------------------------------------------------------
static Sxmlelement randomMusic(int measuresCount) {
	Sxmlelement score = factory::instance().create(k_score_partwise);
	score->push (newElement(k_movement_title, "Random Music"));
	score->push (makeIdentification());
	score->push (makePartList());
	score->push(makePart(measuresCount));			// adds a part to the score
	return score;
}
Exemplo n.º 5
0
//------------------------------------------------------------------------
Sxmlelement musicxmlfactory::newdynamics (int type, const char* placement)
{
	Sxmlelement dynamics = element (k_dynamics);
	if (placement)
		dynamics->add (attribute( "placement", placement));
	dynamics->push (element(type));
	return dynamics;
}
Exemplo n.º 6
0
//------------------------------------------------------------------------
Sxmlelement	musicxmlfactory::scorepart (const char* id, const char* name, const char* abbrev)
{
	Sxmlelement part = element(k_score_part);
	part->add (attribute("id", id));
	if (name)			part->push (element(k_part_name, name));
	if (abbrev)			part->push (element(k_part_abbreviation, abbrev));
	return part;
}
Exemplo n.º 7
0
void unrolled_xml_tree_browser::visitStart( Sxmlelement& elt)
{
	bool forward = fForward;
	if (forward) enter(*elt);
	ctree<xmlelement>::literator iter;
	for (iter = elt->lbegin(); iter != elt->lend(); iter++)
		browse(**iter);
	if (forward) leave(*elt);
}
Exemplo n.º 8
0
//------------------------------------------------------------------------
Sxmlelement	musicxmlfactory::getSubElement (Sxmlelement elt, int type) const
{
	vector<Sxmlelement>&  subelts = elt->elements();
	for (unsigned int i=0; i < subelts.size(); i++) {
		if (subelts[i]->getType() == type)
			return subelts[i];
	}
	Sxmlelement sub = element(type);
	elt->push (sub);
	return sub;
}
Exemplo n.º 9
0
//------------------------------------------------------------------------
void musicxmlfactory::encoding(const char* software)
{
	Sxmlelement encoding = element (k_encoding);
	if (software) encoding->push (element(k_software, software));

	string lib = "MusicXML Library version ";
	lib += musicxmllibVersionStr();
	encoding->push (element(k_software, lib.c_str()));
	encoding->push (element (k_encoding_date, timestring()));
	fIdentification->push (encoding);
}
Exemplo n.º 10
0
//------------------------------------------------------------------------
void musicxmlfactory::header (const char* worknumber, const char* worktitle, const char* movementnumber, const char* movementtitle)
{
	if (worknumber || worktitle) {
		Sxmlelement work = element(k_work);
		if (worknumber) work->push (element(k_work_number, worknumber));
		if (worktitle) work->push (element(k_work_title, worktitle));
		fRoot->push (work);
	}
	if (movementnumber) fRoot->push (element(k_movement_number, movementnumber));
	if (movementtitle) fRoot->push (element(k_movement_title, movementtitle));
}
Exemplo n.º 11
0
//------------------------------------------------------------------------
void musicxmlfactory::addpart (const Sxmlelement& part)	
{ 
	switch (part->getType()) {
		case k_score_part:
			fPartList->push(part);
			break;
		case k_part:
			fRoot->push(part);
			break;
		default:
			cerr << "musicxmlfactory::addpart unexpected type " <<  part->getType() << endl;
	}
}
Exemplo n.º 12
0
//------------------------------------------------------------------------
// creates the part list element
//------------------------------------------------------------------------
static Sxmlelement makePartList() {
	Sxmlelement partlist = factory::instance().create(k_part_list);
	Sxmlelement scorepart = factory::instance().create(k_score_part);
	scorepart->add (newAttribute("id", kPartID));
	scorepart->push (newElement(k_part_name, "Part name"));
	Sxmlelement scoreinstr = factory::instance().create(k_score_instrument);
	scoreinstr->add (newAttribute("id", "I1"));
	scoreinstr->push (newElement(k_instrument_name, "Any instr."));
	scorepart->push (scoreinstr);
	partlist->push(scorepart);
	return partlist;
}
Exemplo n.º 13
0
//------------------------------------------------------------------------
void musicxmlfactory::tie (Sxmlelement start, Sxmlelement stop)
{
	Sxmlelement tieStart = element (k_tie);
	tieStart->add (attribute ("type", "start"));
	start->push (tieStart);
	Sxmlelement tiedStart = element (k_tied);
	tiedStart->add (attribute ("type", "start"));
	addnotation (start, tiedStart);
	
	Sxmlelement tieStop = element (k_tie);
	tieStop->add (attribute ("type", "stop"));
	stop->push (tieStop);
	Sxmlelement tiedStop = element (k_tied);
	tiedStop->add (attribute ("type", "stop"));
	addnotation (stop, tiedStop);
}
Exemplo n.º 14
0
//______________________________________________________________________________
void xml2guidovisitor::addPosition	( Sxmlelement elt, Sguidoelement& tag, int yoffset)
{
	float posx = elt->getAttributeFloatValue("default-x", 0) + elt->getAttributeFloatValue("relative-x", 0);
	if (posx) {
		posx = (posx / 10) * 2;   // convert to half spaces
		stringstream s;
		s << "dx=" << posx << "hs";
		tag->add (guidoparam::create(s.str(), false));
	}
	float posy = elt->getAttributeFloatValue("default-y", 0) + elt->getAttributeFloatValue("relative-y", 0);
	if (posy) {
		posy = (posy / 10) * 2;   // convert to half spaces
		posy += yoffset;		  // anchor point convertion (defaults to upper line in xml)
		stringstream s;
		s << "dy=" << posy << "hs";
		tag->add (guidoparam::create(s.str(), false));
	}
}
Exemplo n.º 15
0
//_______________________________________________________________________________
static void test3(Sxmlelement elt)
{
	cerr << "test3: insert a note before the par notes" << endl;
	ctree<xmlelement>::iterator next, iter = elt->begin();
	int note=1;
	while (iter != elt->end()) {
		Sxmlelement xml = *iter;
		assert (xml);
		if (xml->getType() == k_note) {
			if (!(note & 1)) {
				Sxmlelement note = factory::instance().create(k_note);
				iter = elt->insert(iter, note);
				iter++;
			}
			note++;
		}
		iter++;
	}
}
Exemplo n.º 16
0
//------------------------------------------------------------------------
Sxmlelement musicxmlfactory::newnote (const char* step, float alter, int octave, int duration, const char* type)
{
	Sxmlelement elt = element(k_note);
	Sxmlelement pitch = element(k_pitch);
	pitch->push (element (k_step, step));
	if (alter) pitch->push (element (k_alter, alter));
	pitch->push (element (k_octave, octave));
	elt->push(pitch);
	if (duration) elt->push(element(k_duration, duration));
	if (type) elt->push(element(k_type, type));
	return elt;
}
Exemplo n.º 17
0
//------------------------------------------------------------------------
static Sxmlelement makeAttributes() {
	Sxmlelement attributes = factory::instance().create(k_attributes);
	attributes->push (newElementI(k_divisions, kDivision));

	Sxmlelement time = factory::instance().create(k_time);
	time->push (newElement(k_beats, "4"));
	time->push (newElement(k_beat_type, "4"));
	attributes->push (time);

	Sxmlelement clef = factory::instance().create(k_clef);
	clef->push (newElement(k_sign, "G"));
	clef->push (newElement(k_line, "2"));
	attributes->push (clef);
	
	return attributes;
}
Exemplo n.º 18
0
//------------------------------------------------------------------------
void musicxmlfactory::addgroup (int number, const char* name, const char* abbrev, bool groupbarline, vector<Sxmlelement>& parts)
{
	Sxmlelement groupStart = element(k_part_group);
	groupStart->add (attribute ("number", number));
	groupStart->add (attribute ("type", "start"));
	if (name)			groupStart->push (element(k_group_name, name));
	if (abbrev)			groupStart->push (element(k_group_abbreviation, abbrev));
	if (groupbarline)	groupStart->push (element(k_group_barline, "yes"));
	fPartList->push (groupStart);

	for (vector<Sxmlelement>::const_iterator i = parts.begin(); i != parts.end(); i++)
		addpart(*i);

	Sxmlelement groupStop = element(k_part_group);
	groupStop->add (attribute ("number", number));
	groupStop->add (attribute ("type", "stop"));
	fPartList->push (groupStop);	
}
Exemplo n.º 19
0
//------------------------------------------------------------------------
// creates the identification element
//------------------------------------------------------------------------
static Sxmlelement makeIdentification() {
	Sxmlelement id = factory::instance().create(k_identification);
	Sxmlelement encoding = factory::instance().create(k_encoding);

	Sxmlelement creator = newElement(k_creator, "Georg Chance");
	creator->add(newAttribute("type", "Composer"));
	id->push (creator);
	
	encoding->push (newElement(k_software, "MusicXML Library v2"));
	id->push (encoding);
	return id;
}
Exemplo n.º 20
0
//------------------------------------------------------------------------
void musicxmlfactory::maketuplet(int actual, int normal, const std::vector<Sxmlelement>& notes)
{
	if (notes.empty()) return;
	Sxmlelement timemod = element(k_time_modification);
	timemod->push (element (k_actual_notes, actual));
	timemod->push (element (k_normal_notes, normal));
	for (unsigned int i=0; i < notes.size(); i++)
		notes[i]->push(timemod);
	Sxmlelement notations = getNotations (notes[0]);
	Sxmlelement tuplet = element (k_tuplet);
	tuplet->add (attribute ("type", "start"));
	notations->push (tuplet);

	notations = getNotations (notes[notes.size()-1]);
	tuplet = element (k_tuplet);
	tuplet->add (attribute ("type", "stop"));
	notations->push (tuplet);
}
Exemplo n.º 21
0
//------------------------------------------------------------------------
Sxmlelement musicxmlfactory::newbarline (const char* location, const char* barstyle, const char *repeat)
{
	Sxmlelement barline = element (k_barline);
	if (location)
		barline->add (attribute( "location", location));
	if (barstyle)
		barline->push (element(k_bar_style, barstyle));
	if (repeat) {
		Sxmlelement repeatelt = (element(k_repeat));
		repeatelt->add (attribute( "direction", repeat));
		barline->push (repeatelt);
	}
	return barline;
}
Exemplo n.º 22
0
//_______________________________________________________________________________
static void test1(Sxmlelement elt)
{
	cerr << "test1: iterate thru the tree" << endl;
	ctree<xmlelement>::iterator iter = elt->begin();
	cerr << "=> test1: iterate thru the tree" << endl;

	while (iter != elt->end()) {
		Sxmlelement xml = *iter;
		if (xml)
			cerr << "  element type " << xml->getType() 
				 << " - " << xml->getName()
				 << " - size: " << xml->size() << endl;
		else
			cerr << "iterate thru unknown element type " << endl;
		iter++;
	}

}
Exemplo n.º 23
0
//_______________________________________________________________________________
static void test2(Sxmlelement elt)
{
	cerr << "test2: erasing all the par measures" << endl;
	ctree<xmlelement>::iterator next, iter = elt->begin();
	int measure=1;
	while (iter != elt->end()) {
		Sxmlelement xml = *iter;
		next = iter;
		next++;
		assert (xml);
		if (xml->getType() == k_software) {
				next = elt->erase(iter);			
		}
		else if (xml->getType() == k_measure) {
			if (!(measure & 1)) {
				next = elt->erase(iter);
			}
			measure++;
		}
		iter = next;
	}
}
Exemplo n.º 24
0
//------------------------------------------------------------------------
static TElement		__retainElt  (Sxmlelement elt)		{ elt->addReference(); return (TElement)elt; }
Exemplo n.º 25
0
//------------------------------------------------------------------------
static Sxmlelement newElementI(int type, int value)
{
	Sxmlelement elt = factory::instance().create(type);
	elt->setValue (value);
	return elt;
}
Exemplo n.º 26
0
//_______________________________________________________________________________
static void count(Sxmlelement elt, int type)
{
	predicate p(type);
	cerr << "  count of type " << type << " elements: " 
		 << count_if(elt->begin(), elt->end(), p) << endl;
}
Exemplo n.º 27
0
	virtual bool operator () (const Sxmlelement elt) const { 
		return elt->getType() == fType;
	}
Exemplo n.º 28
0
//_______________________________________________________________________________
void xmlreader::newProcessingInstruction (const char* pi)
{
	Sxmlelement elt = factory::instance().create("pi");
	elt->setValue(pi);
	fStack.top()->push(elt);
}
Exemplo n.º 29
0
//_______________________________________________________________________________
void xmlreader::newComment (const char* comment)
{
	Sxmlelement elt = factory::instance().create("comment");
	elt->setValue(comment);
	fStack.top()->push(elt);
}
Exemplo n.º 30
0
//------------------------------------------------------------------------
// creates a measure containing random notes
// the function takes the measure number as an argument
//------------------------------------------------------------------------
static Sxmlelement makemeasure(unsigned long num) {
	Sxmlelement measure = factory::instance().create(k_measure);
	measure->add (newAttributeI("number", num));
	if (num==1) {					//  creates specific elements of the first measure
		measure->push(makeAttributes());		// division, time, clef...
	}
	for (int i = 0; i < 4; i++) {		// next adds 4 quarter notes
		Sxmlelement note = factory::instance().create(k_note);		// creates the note
		Sxmlelement pitch = factory::instance().create(k_pitch);	// creates a pitch
		pitch->push (newElement(k_step, randomNote()));				// sets the pitch to a random value
		pitch->push (newElementI(k_octave, 4 + getrandom(2)));		// sets the octave to a random value
		note->push (pitch);											// adds the pitch to the note
		note->push (newElementI(k_duration, kDivision));				// sets the note duration to a quarter note
		note->push (newElement(k_type, "quarter"));					// creates the graphic elements of the note
		measure->push (note);		// and finally adds the note to the measure
	}
	return measure;
}