#include <string.h>

#include "sentence.h"

Sentence::Sentence(  )
{
  m_lstSyllable = new Syllable[100];
  m_nbSyllable = 0;
  m_start = 0;
  m_duration = 0;
  m_posSyllable = 0;
}

Sentence::~Sentence(  )
{
  delete[]m_lstSyllable;
  m_lstSyllable = NULL;
  // dtor
}

int Sentence::addSyllable( int start, int duration, int note,
                           char *strSyllable )
{
  m_duration += duration;
  m_lstSyllable[m_nbSyllable].addSyllable( start, duration, note,
                                           strSyllable );
  m_nbSyllable++;

  return ( 0 );
}

int Sentence::setStart( int Start )
{
  m_start = Start;

  return ( 0 );
}

int Sentence::setAtBegin( void )
{
  m_posSyllable = 0;

  return ( 0 );
}

int Sentence::getNextSyllable( Syllable & syll, int *status, int currentTime )
{
  int fd = 0;

  if( m_posSyllable < m_nbSyllable )
  {
    if( currentTime < m_lstSyllable[m_posSyllable].m_start )
    {
      *status = 0;
    }
    if( currentTime >= m_lstSyllable[m_posSyllable].m_start &&
        currentTime <=
        m_lstSyllable[m_posSyllable].m_start +
        m_lstSyllable[m_posSyllable].m_duration )
    {
      *status =
        ( 100 * ( currentTime - m_lstSyllable[m_posSyllable].m_start ) ) /
        m_lstSyllable[m_posSyllable].m_duration;
    }
    if( currentTime >
        m_lstSyllable[m_posSyllable].m_start +
        m_lstSyllable[m_posSyllable].m_duration )
    {
      *status = 100;
    }

    syll = m_lstSyllable[m_posSyllable];
    m_posSyllable++;
  }
  else
  {
    fd = 1;
  }

  return ( fd );
}
