src/GridMeasure.cpp
GridSlice* GridMeasure::addTransposeToken(const string& tok, HumNum timestamp,
		int part, int staff, int voice, int maxstaff) {
	GridSlice* gs = NULL;
	if (this->empty() || (this->back()->getTimestamp() < timestamp)) {
		// add a new GridSlice to an empty list or at end of list if timestamp
		// is after last entry in list.
		gs = new GridSlice(this, timestamp, SliceType::Transpositions, maxstaff);
		gs->addToken(tok, part, staff, voice);
		this->push_back(gs);
	} else {
		// search for existing line with same timestamp and the same slice type
		GridSlice* target = NULL;
		auto iterator = this->begin();
		while (iterator != this->end()) {
			if (((*iterator)->getTimestamp() == timestamp) && (*iterator)->isTransposeSlice()) {
				target = *iterator;
				target->addToken(tok, part, staff, voice);
				break;
			} else if (((*iterator)->getTimestamp() == timestamp) && (*iterator)->isDataSlice()) {
				// found the correct timestamp, but no clef slice at the timestamp
				// so add the clef slice before the data slice (eventually keeping
				// track of the order in which the other non-data slices should be placed).
				gs = new GridSlice(this, timestamp, SliceType::Transpositions, maxstaff);
				gs->addToken(tok, part, staff, voice);
				this->insert(iterator, gs);
				break;
			} else if ((*iterator)->getTimestamp() > timestamp) {
				gs = new GridSlice(this, timestamp, SliceType::Transpositions, maxstaff);
				gs->addToken(tok, part, staff, voice);
				this->insert(iterator, gs);
				break;
			}
			iterator++;
		}

		if (iterator == this->end()) {
			// Couldn't find a place for the key signature, so place at end of measure.
			gs = new GridSlice(this, timestamp, SliceType::Transpositions, maxstaff);
			gs->addToken(tok, part, staff, voice);
			this->insert(iterator, gs);
		}

	}
	return gs;
}
//////////////////////////////
//
// GridMeasure::addTransposeToken -- Add a transposition token in the data slice at
//    the given timestamp (or create a new transposition slice at that timestamp), placing
//    the token at the specified part, staff, and voice index.
//
//    Note: should placed after clef if present and no other transpose slice at
//    same time.
//
:addTransposeToken -- Add a transposition token in the data slice at
the given timestamp (or create a new transposition slice at that timestamp), placing
the token at the specified part, staff, and voice index.

should placed after clef if present and no other transpose slice at
same time.
: addTransposeToken -- Add a transposition token in the data slice at the given timestamp ( or create a new transposition slice at that timestamp ) placing the token at the specified part staff and voice index . should placed after clef if present and no other transpose slice at same time .
GridSlice* GridMeasure::addTransposeToken(const string& tok, HumNum timestamp,
		int part, int staff, int voice, int maxstaff) {
	GridSlice* gs = NULL;
	if (this->empty() || (this->back()->getTimestamp() < timestamp)) {
		gs = new GridSlice(this, timestamp, SliceType::Transpositions, maxstaff);
		gs->addToken(tok, part, staff, voice);
		this->push_back(gs);
	} else {
		GridSlice* target = NULL;
		auto iterator = this->begin();
		while (iterator != this->end()) {
			if (((*iterator)->getTimestamp() == timestamp) && (*iterator)->isTransposeSlice()) {
				target = *iterator;
				target->addToken(tok, part, staff, voice);
				break;
			} else if (((*iterator)->getTimestamp() == timestamp) && (*iterator)->isDataSlice()) {
				gs = new GridSlice(this, timestamp, SliceType::Transpositions, maxstaff);
				gs->addToken(tok, part, staff, voice);
				this->insert(iterator, gs);
				break;
			} else if ((*iterator)->getTimestamp() > timestamp) {
				gs = new GridSlice(this, timestamp, SliceType::Transpositions, maxstaff);
				gs->addToken(tok, part, staff, voice);
				this->insert(iterator, gs);
				break;
			}
			iterator++;
		}
		if (iterator == this->end()) {
			gs = new GridSlice(this, timestamp, SliceType::Transpositions, maxstaff);
			gs->addToken(tok, part, staff, voice);
			this->insert(iterator, gs);
		}
	}
	return gs;
}
GridSlice * GridMeasure :: addTransposeToken ( const string & tok , HumNum timestamp , int part , int staff , int voice , int maxstaff ) { GridSlice * gs = NULL ; if ( this -> empty ( ) || ( this -> back ( ) -> getTimestamp ( ) < timestamp ) ) { gs = new GridSlice ( this , timestamp , SliceType :: Transpositions , maxstaff ) ; gs -> addToken ( tok , part , staff , voice ) ; this -> push_back ( gs ) ; } else { GridSlice * target = NULL ; auto iterator = this -> begin ( ) ; while ( iterator != this -> end ( ) ) { if ( ( ( * iterator ) -> getTimestamp ( ) == timestamp ) && ( * iterator ) -> isTransposeSlice ( ) ) { target = * iterator ; target -> addToken ( tok , part , staff , voice ) ; break ; } else if ( ( ( * iterator ) -> getTimestamp ( ) == timestamp ) && ( * iterator ) -> isDataSlice ( ) ) { gs = new GridSlice ( this , timestamp , SliceType :: Transpositions , maxstaff ) ; gs -> addToken ( tok , part , staff , voice ) ; this -> insert ( iterator , gs ) ; break ; } else if ( ( * iterator ) -> getTimestamp ( ) > timestamp ) { gs = new GridSlice ( this , timestamp , SliceType :: Transpositions , maxstaff ) ; gs -> addToken ( tok , part , staff , voice ) ; this -> insert ( iterator , gs ) ; break ; } iterator ++ ; } if ( iterator == this -> end ( ) ) { gs = new GridSlice ( this , timestamp , SliceType :: Transpositions , maxstaff ) ; gs -> addToken ( tok , part , staff , voice ) ; this -> insert ( iterator , gs ) ; } } return gs ; }
GridMeasure::addTransposeToken -- Add a transposition token in the data slice at
the given timestamp (or create a new transposition slice at that timestamp), placing
the token at the specified part, staff, and voice index.
GridMeasure :: addTransposeToken -- Add a transposition token in the data slice at the given timestamp ( or create a new transposition slice at that timestamp ) placing the token at the specified part staff and voice index .
// add a new GridSlice to an empty list or at end of list if timestamp // is after last entry in list. // search for existing line with same timestamp and the same slice type // found the correct timestamp, but no clef slice at the timestamp // so add the clef slice before the data slice (eventually keeping // track of the order in which the other non-data slices should be placed). // Couldn't find a place for the key signature, so place at end of measure.