Advertisement
Guest User

Untitled

a guest
Mar 31st, 2010
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.44 KB | None | 0 0
  1. diff --git a/rbutil/rbutilqt/base/encoders.cpp b/rbutil/rbutilqt/base/encoders.cpp
  2. index 795b622..b61180b 100644
  3. --- a/rbutil/rbutilqt/base/encoders.cpp
  4. +++ b/rbutil/rbutilqt/base/encoders.cpp
  5. @@ -131,7 +131,7 @@ bool EncExes::encode(QString input,QString output)
  6.      execstring.replace("%options",m_EncOpts);
  7.      execstring.replace("%input",input);
  8.      execstring.replace("%output",output);
  9. -    qDebug() << execstring;
  10. +    qDebug() << "[EncExes] cmd: " << execstring;
  11.      int result = QProcess::execute(execstring);
  12.      return (result == 0) ? true : false;
  13.  }
  14. @@ -197,16 +197,16 @@ bool EncRbSpeex::start()
  15.  
  16.  bool EncRbSpeex::encode(QString input,QString output)
  17.  {
  18. -    qDebug() << "encoding " << input << " to "<< output;
  19. +    qDebug() << "[RbSpeex] Encoding " << input << " to "<< output;
  20.      char errstr[512];
  21.  
  22.      FILE *fin,*fout;
  23.      if ((fin = fopen(input.toLocal8Bit(), "rb")) == NULL) {
  24. -        qDebug() << "Error: could not open input file\n";
  25. +        qDebug() << "[RbSpeex] Error: could not open input file\n";
  26.          return false;
  27.      }
  28.      if ((fout = fopen(output.toLocal8Bit(), "wb")) == NULL) {
  29. -        qDebug() << "Error: could not open output file\n";
  30. +        qDebug() << "[RbSpeex] Error: could not open output file\n";
  31.          return false;
  32.      }
  33.  
  34. @@ -218,7 +218,7 @@ bool EncRbSpeex::encode(QString input,QString output)
  35.  
  36.      if (!ret) {
  37.          /* Attempt to delete unfinished output */
  38. -        qDebug() << "Error:" << errstr;
  39. +        qDebug() << "[RbSpeex] Error:" << errstr;
  40.          QFile(output).remove();
  41.          return false;
  42.      }
  43. diff --git a/rbutil/rbutilqt/base/talkgenerator.cpp b/rbutil/rbutilqt/base/talkgenerator.cpp
  44. index 5c0f8e9..42f84be 100644
  45. --- a/rbutil/rbutilqt/base/talkgenerator.cpp
  46. +++ b/rbutil/rbutilqt/base/talkgenerator.cpp
  47. @@ -22,7 +22,7 @@
  48.  #include "systeminfo.h"
  49.  #include "wavtrim.h"
  50.  
  51. -TalkGenerator::TalkGenerator(QObject* parent): QObject(parent)
  52. +TalkGenerator::TalkGenerator(QObject* parent): QObject(parent), encFutureWatcher(this)
  53.  {
  54.  
  55.  }
  56. @@ -184,50 +184,69 @@ TalkGenerator::Status TalkGenerator::voiceList(QList<TalkEntry>* list,int wavtri
  57.  //!
  58.  TalkGenerator::Status TalkGenerator::encodeList(QList<TalkEntry>* list)
  59.  {
  60. -    QStringList dublicates;
  61. +    QStringList duplicates;
  62.  
  63. -    int progressMax = list->size();
  64. -    int m_progress = 0;
  65. -    emit logProgress(m_progress,progressMax);
  66. +    int itemsCount = list->size();
  67. +    emit logProgress(0, itemsCount);
  68.  
  69. -    for(int i=0; i < list->size(); i++)
  70. +    /* Do some preprocessing and remove the invalid entries. As far as I can see,
  71. +     * this list is not going to be used anywhere else, so we might as well butcher it*/
  72. +    for (int idx=0; idx < itemsCount; idx++)
  73.      {
  74. -        if(m_abort)
  75. +        if(list->at(idx).voiced == false)
  76.          {
  77. -            emit logItem(tr("Encoding aborted"), LOGERROR);
  78. -            return eERROR;
  79. +            qDebug() << "non voiced entry" << list->at(idx).toSpeak <<"detected";
  80. +            list->removeAt(idx);
  81. +            itemsCount--;
  82. +            idx--;
  83. +            continue;
  84.          }
  85. -
  86. -         //skip non-voiced entrys
  87. -        if(list->at(i).voiced == false)
  88. +        if(duplicates.contains(list->at(idx).talkfilename))
  89.          {
  90. -            qDebug() << "non voiced entry" << list->at(i).toSpeak <<"detected";
  91. -            emit logProgress(++m_progress,progressMax);
  92. +            list->removeAt(idx);
  93. +            itemsCount--;
  94. +            idx--;
  95.              continue;
  96.          }
  97. -        //skip dublicates
  98. -         if(!dublicates.contains(list->at(i).talkfilename))
  99. -            dublicates.append(list->at(i).talkfilename);
  100. +        duplicates.append(list->at(idx).talkfilename);
  101. +        (*list)[idx].encoder = m_enc;
  102. +        (*list)[idx].generator = this;
  103. +    }
  104. +
  105. +    connect(&encFutureWatcher, SIGNAL(progressValueChanged(int)), this, SLOT(encProgress(int)));
  106. +    encFutureWatcher.setFuture(QtConcurrent::map(*list, &TalkGenerator::encEntryPoint));
  107. +
  108. +    /* We use this loop as an equivalent to encFutureWatcher.waitForFinished()
  109. +     * since the latter blocks all events */
  110. +    while (encFutureWatcher.isRunning())
  111. +        QCoreApplication::processEvents(QEventLoop::AllEvents);
  112. +
  113. +    if (encFutureWatcher.isCanceled())
  114. +        return eERROR;
  115.          else
  116. -        {
  117. -            qDebug() << "dublicate skipped";
  118. -            (*list)[i].encoded = true;
  119. -            emit logProgress(++m_progress,progressMax);
  120. -            continue;
  121. +        return eOK;
  122.          }
  123.  
  124. -        //encode entry
  125. -        qDebug() << "encoding " << list->at(i).wavfilename << "to" << list->at(i).talkfilename;
  126. -        if(!m_enc->encode(list->at(i).wavfilename,list->at(i).talkfilename))
  127. +void TalkGenerator::encEntryPoint(TalkEntry& entry)
  128.          {
  129. -            emit logItem(tr("Encoding of %1 failed").arg(list->at(i).wavfilename), LOGERROR);
  130. -            return eERROR;
  131. +    bool res = entry.encoder->encode(entry.wavfilename, entry.talkfilename);
  132. +    entry.encoded = res;
  133. +    if (!entry.encoded)
  134. +        entry.generator->encFailEntry(entry);
  135. +    return;
  136.          }
  137. -        (*list)[i].encoded = true;
  138. -        emit logProgress(++m_progress,progressMax);
  139. -        QCoreApplication::processEvents();
  140. +
  141. +void TalkGenerator::encProgress(int value)
  142. +{
  143. +    qDebug() << "[TalkGen] Progress at " << value;
  144. +    emit logProgress(value, encFutureWatcher.progressMaximum());
  145.      }
  146. -    return eOK;
  147. +
  148. +void TalkGenerator::encFailEntry(const TalkEntry& entry)
  149. +{
  150. +    encFutureWatcher.cancel();
  151. +    encFutureWatcher.waitForFinished();
  152. +    emit logItem(tr("Encoding of %1 failed").arg(entry.wavfilename), LOGERROR);
  153.  }
  154.  
  155.  //! \brief slot, which is connected to the abort of the Logger. Sets a flag, so Creating Talkfiles ends at the next possible position
  156. @@ -235,5 +254,12 @@ TalkGenerator::Status TalkGenerator::encodeList(QList<TalkEntry>* list)
  157.  void TalkGenerator::abort()
  158.  {
  159.      m_abort = true;
  160. +
  161. +    if (encFutureWatcher.isRunning())
  162. +    {
  163. +        encFutureWatcher.cancel();
  164. +        encFutureWatcher.waitForFinished();
  165. +        emit logItem(tr("Encoding aborted"), LOGERROR);
  166. +    }
  167.  }
  168.  
  169. diff --git a/rbutil/rbutilqt/base/talkgenerator.h b/rbutil/rbutilqt/base/talkgenerator.h
  170. index b139c18..87ab33e 100644
  171. --- a/rbutil/rbutilqt/base/talkgenerator.h
  172. +++ b/rbutil/rbutilqt/base/talkgenerator.h
  173. @@ -49,14 +49,22 @@ public:
  174.          QString target;
  175.          bool voiced;
  176.          bool encoded;
  177. +
  178. +      /* We need the following members because
  179. +       * 1) the QtConcurrent entry points are all static methods (and we need to communicate
  180. +       * with the TalkGenerator
  181. +       * 2) we are not guaranteed to go through the list in any particular order,
  182. +       * so we can't use the progress slot for error checking */
  183. +      EncBase* encoder;
  184. +      TalkGenerator* generator;
  185.      };
  186.  
  187.      TalkGenerator(QObject* parent);
  188. -
  189.      Status process(QList<TalkEntry>* list,int wavtrimth = -1);
  190.  
  191.  public slots:
  192.      void abort();
  193. +    void encProgress(int value);
  194.  
  195.  signals:
  196.      void done(bool);
  197. @@ -64,9 +72,14 @@ signals:
  198.      void logProgress(int, int); //! set progress bar.
  199.  
  200.  private:
  201. +    QFutureWatcher<void> encFutureWatcher;
  202. +    void encFailEntry(const TalkEntry& entry);
  203. +
  204.      Status voiceList(QList<TalkEntry>* list,int wavetrimth);
  205.      Status encodeList(QList<TalkEntry>* list);
  206.  
  207. +    static void encEntryPoint(TalkEntry& entry);
  208. +
  209.      TTSBase* m_tts;
  210.      EncBase* m_enc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement