Logo Search packages:      
Sourcecode: ultrastar-ng version File versions  Download package

void CLyrics::updateSentences ( unsigned int  timestamp  ) 

update the content of the sentence strings

Definition at line 80 of file lyrics.cpp.

References getEndTime(), getStartTime(), and getTimestampFromBeat().

{
      // If the sentences shouldn't change, do nothing
      if( lastSyllableIndex != -1 && lastSentenceIndex != -1
          && lastSentenceIndex < (int) formatedLyrics.size()
          && lastSyllableIndex < (int) formatedLyrics[lastSentenceIndex].size()
          && timestamp >= getTimestampFromBeat( formatedLyrics[lastSentenceIndex][lastSyllableIndex]->timestamp )
          && timestamp <= getTimestampFromBeat( formatedLyrics[lastSentenceIndex][lastSyllableIndex]->timestamp + formatedLyrics[lastSentenceIndex][lastSyllableIndex]->length ) ) {
            return;
      }
      // sentence changed, recompute it
      unsigned int i;
      
      // If we are further than the last time (no rewind) (optimisation)
      if( lastSentenceIndex != -1 && timestamp > getStartTime(lastSentenceIndex))
            i = lastSentenceIndex;
      else
            i = 0;

      // For all the detected sentences, find the first that have not yet ended
      for(  ; i < formatedLyrics.size() ; i++ ) {
            // If we're between the end of the last sentence and the end of the current sentence
            if( timestamp > getEndTime(i-1) && timestamp <= getEndTime(i) ) {
                  sentencePast[0]   = '\0';
                  sentenceNow[0]    = '\0';
                  sentenceFuture[0] = '\0';
                  for( unsigned int j = 0 ; j < formatedLyrics[i].size() ; j++ ) {
                        if( timestamp > getTimestampFromBeat( formatedLyrics[i][j]->timestamp + formatedLyrics[i][j]->length ) ) {
                              strcat( sentencePast , formatedLyrics[i][j]->syllable );
                        } else if( timestamp < getTimestampFromBeat( formatedLyrics[i][j]->timestamp ) ) {
                              strcat( sentenceFuture , formatedLyrics[i][j]->syllable );
                        } else {
                              lastSyllableIndex = j;
                              strcat( sentenceNow , formatedLyrics[i][j]->syllable );
                        }
                  }
                  // If we have change of sentence, we rebuild the next sentence
                  if( lastSentenceIndex == -1 || (unsigned int)lastSentenceIndex != i ) {
                        lastSentenceIndex = i;
                        sentenceNext[0]   = '\0';
                        sentenceWhole[0]  = '\0';
                        if( i != formatedLyrics.size() - 1 )
                              for( unsigned int j = 0 ; j < formatedLyrics[i+1].size() ; j++ )
                                    strcat( sentenceNext , formatedLyrics[i+1][j]->syllable );
                        for( unsigned int j = 0 ; j < formatedLyrics[i].size() ; j++ )
                              strcat( sentenceWhole , formatedLyrics[i][j]->syllable );
                  }
                  // No need to go further in the song
                  break;
            }
      }

}


Generated by  Doxygen 1.6.0   Back to index