暂无描述

mainwindow.cpp 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /// \file
  2. #include "mainwindow.h"
  3. #include "ui_mainwindow.h"
  4. #include "audiomanip.h"
  5. /// \fn MainWindow::MainWindow(QWidget *parent)
  6. /// \~English
  7. /// \brief GUI Constructor
  8. /// \~Spanish
  9. /// \brief Constructor del GUI
  10. MainWindow::MainWindow(QWidget *parent):
  11. QMainWindow(parent), ui(new Ui::MainWindow)
  12. {
  13. ui->setupUi(this);
  14. MediaPlayer = new QMediaPlayer(this);
  15. }
  16. /// \fn MainWindow::~MainWindow()
  17. /// \~English
  18. /// \brief GUI Destructor
  19. /// \~Spanish
  20. /// \brief Destructor del GUI
  21. MainWindow::~MainWindow()
  22. {
  23. if (MediaPlayer != NULL) delete MediaPlayer;
  24. if (ui) delete ui;
  25. }
  26. /// \fn void MainWindow::on_actionExit_triggered()
  27. /// \~English
  28. /// \brief Exits the application
  29. /// \~Spanish
  30. /// \brief Sale del programado
  31. void MainWindow::on_actionExit_triggered()
  32. {
  33. ws.~WaveSound() ;
  34. QApplication::quit();
  35. }
  36. /// \fn void MainWindow::on_actionAbout_triggered()
  37. /// \~English
  38. /// \brief Display about message
  39. /// \~Spanish
  40. /// \brief Despliega mensaje sobre la aplicacion.
  41. void MainWindow::on_actionAbout_triggered()
  42. {
  43. //display a message box
  44. QMessageBox::about(this, tr("About Wave Editor"),
  45. tr("The program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY "
  46. "OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE."));
  47. }
  48. /// \fn void MainWindow::on_Filter_Box_currentIndexChanged(int index)
  49. /// \~English
  50. /// \brief When filter box is set to a pan or fade filter the pan/fade
  51. /// filter length box in enabled, otherwise it is disabled.
  52. /// \param index Index position of the filter option.
  53. /// \~Spanish
  54. /// \brief Cuando la caja de filtro es cambiada a un filtro de panoramica,
  55. /// desbanecimiento de sonido o incremento de sonido, la caja del largo de la
  56. /// panoramica o del desbanecimiento se pone activa, de los contranio se
  57. /// desactiva.
  58. /// \param index Posicion del indice de la opcion del filtro.
  59. void MainWindow::on_Filter_Box_currentIndexChanged(int index)
  60. {
  61. ui->Fade_Pan_Lenght->setEnabled(bool(index));
  62. ui->label_3->setEnabled(bool(index));
  63. }
  64. /// \fn void MainWindow::setFilesAndButtonStatus(const QString &fileName)
  65. /// \~English
  66. /// \brief Put the values of the path of the audio file searched and selected
  67. /// and enables and disbles the buttons.
  68. /// \param fileName the path of the audio file.
  69. /// \~Spanish
  70. /// \brief Pone los valores del camino a el archivo de audio buscando y
  71. /// seleccionado, y activa y desactiva los botones.
  72. /// \param fileName el camino del archivo de audio
  73. void MainWindow::setFilesAndButtonStatus(const QString &fileName) {
  74. AudioInFile = AudioOutFile = fileName;
  75. AudioOutFile.truncate(AudioInFile.size()-3);
  76. AudioOutFile = AudioOutFile+"out.wav";
  77. ui->Audio_In->addItem(AudioInFile);
  78. ui->Audio_In->setCurrentText(AudioInFile);
  79. ui->Audio_Out->addItem(AudioOutFile);
  80. ui->Audio_Out->setCurrentText(AudioOutFile);
  81. ui->Play_Audio_In->setEnabled(true);
  82. ui->Stop_Audio_In->setEnabled(true);
  83. ui->Play_Audio_Out->setEnabled(false);
  84. ui->Stop_Audio_Out->setEnabled(false);
  85. ui->run_filter->setEnabled(true);
  86. }
  87. /// \fn void MainWindow::on_Action_Input_Audio_File_triggered()
  88. /// \~English
  89. /// \brief Display the window to search and select an input audio file.
  90. /// \~Spanish
  91. /// \brief Despliega la pantalla para buscar y seleccionar un archivo de audio de entrada.
  92. void MainWindow::on_Action_Input_Audio_File_triggered()
  93. {
  94. QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Files (*.wav)"));
  95. Frames = ws.getAudioSamples(fileName);
  96. setFilesAndButtonStatus(fileName);
  97. }
  98. /// \fn void MainWindow::on_Search_Audio_In_clicked()
  99. /// \~English
  100. /// \brief Set the Input Audio File with the Search Button
  101. /// \~Spanish
  102. /// \brief Establece el archivo de entrada de audio con el Boton de Busqueda
  103. /// (Search Button)
  104. void MainWindow::on_Search_Audio_In_clicked()
  105. {
  106. on_Action_Input_Audio_File_triggered();
  107. }
  108. //Set Input Audio File With Combo Box
  109. /// \fn void MainWindow::on_Audio_In_currentIndexChanged(const QString &arg1)
  110. /// \~English
  111. /// \brief Set the Input Audio File with the Text Box value
  112. /// \param arg1 path to audio file
  113. /// \~Spanish
  114. /// \brief Establece el archivo de entrada de audio con el valor en la
  115. /// caja de texto.
  116. /// \param arg1 camino al archivo de audio
  117. void MainWindow::on_Audio_In_currentIndexChanged(const QString &arg1)
  118. {
  119. setFilesAndButtonStatus(arg1);
  120. }
  121. /// \fn void MainWindow::on_Action_Output_Audio_File_triggered()
  122. /// \~English
  123. /// \brief Display the window to search and select an input audio file.
  124. /// \~Spanish
  125. /// \brief Despliega la pantalla para buscar y seleccionar un archivo de audio de entrada.
  126. void MainWindow::on_Action_Output_Audio_File_triggered()
  127. {
  128. QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Files (*.wav)"));
  129. AudioOutFile = fileName;
  130. ui->Audio_Out->addItem(AudioOutFile);
  131. ui->Audio_Out->setCurrentText(AudioOutFile);
  132. }
  133. /// \fn void MainWindow::on_Search_Audio_Out_clicked()
  134. /// \~English
  135. /// \brief Set the Output Audio File with the Search Button
  136. /// \~Spanish
  137. /// \brief Establece el archivo de salida de audio con el Boton de Busqueda
  138. /// (Search Button)
  139. void MainWindow::on_Search_Audio_Out_clicked()
  140. {
  141. on_Action_Output_Audio_File_triggered();
  142. }
  143. /// \fn void MainWindow::on_Audio_Out_currentIndexChanged(const QString &arg1)
  144. /// \~English
  145. /// \brief Set Output Audio File With the value in the Text Box
  146. /// \param arg1 Path to the audio file.
  147. /// \~Spanish
  148. /// \brief Establece el archivo de salida de audio con el valor en la
  149. /// caja de texto
  150. /// \param Camino al archivo de audio.
  151. ///
  152. void MainWindow::on_Audio_Out_currentIndexChanged(const QString &arg1)
  153. {
  154. AudioOutFile = arg1;
  155. }
  156. /// \fn void MainWindow::on_Play_Audio_In_clicked()
  157. /// \~English
  158. /// \brief Play the Input Audio
  159. /// \~Spanish
  160. /// \brief Toca el audio de entrada
  161. void MainWindow::on_Play_Audio_In_clicked()
  162. {
  163. MediaPlayer->stop();
  164. MediaPlayer->setMedia(QUrl::fromLocalFile(AudioInFile));
  165. MediaPlayer->stop();
  166. MediaPlayer->play();
  167. }
  168. /// \fn void MainWindow::on_Stop_Audio_In_clicked()
  169. /// \~English
  170. /// \brief Stop playing the Input Audio
  171. /// \~Spanish
  172. /// \brief Para de tocar el audio de entrada
  173. void MainWindow::on_Stop_Audio_In_clicked()
  174. {
  175. MediaPlayer->stop();
  176. }
  177. /// \fn void MainWindow::on_Play_Audio_Out_clicked()
  178. /// \~English
  179. /// \brief Play the Output Audio
  180. /// \~Spanish
  181. /// \brief Toca el audio de salida
  182. void MainWindow::on_Play_Audio_Out_clicked()
  183. {
  184. MediaPlayer->stop();
  185. MediaPlayer->setMedia(QUrl::fromLocalFile(AudioOutFile));
  186. MediaPlayer->stop();
  187. MediaPlayer->play();
  188. }
  189. /// \fn void MainWindow::on_Stop_Audio_Out_clicked()
  190. /// \~English
  191. /// \brief Stop playing the Output Audio
  192. /// \~Spanish
  193. /// \brief Para de tocar el audio de salida
  194. void MainWindow::on_Stop_Audio_Out_clicked()
  195. {
  196. MediaPlayer->stop();
  197. }
  198. /// \fn void MainWindow::on_Play_Audio_In_clicked()
  199. /// \~English
  200. /// \brief Run the selected audio filter
  201. /// \~Spanish
  202. /// \brief Corre el filtro de audio seleccionado.
  203. void MainWindow::on_run_filter_clicked()
  204. {
  205. Frames = ws.getAudioSamples(AudioInFile);
  206. switch(ui->Filter_Box->currentIndex())
  207. {
  208. case 0:
  209. RemoveVocals(Frames, ws.frameCount()) ;
  210. break;
  211. case 1:
  212. AudioFadeIn(Frames, ws.frameCount(), ui->Fade_Pan_Lenght->value());
  213. break;
  214. case 2:
  215. AudioFadeOut(Frames, ws.frameCount(), ui->Fade_Pan_Lenght->value());
  216. break;
  217. case 3:
  218. LeftToRight(Frames, ws.frameCount(), ui->Fade_Pan_Lenght->value());
  219. break;
  220. };
  221. cout<<endl<<"running filter"<<endl;
  222. cout<<endl<<AudioOutFile.toStdString()<<endl;
  223. ws.writeNewAudioFile(AudioOutFile);
  224. ui->Play_Audio_Out->setEnabled(true);
  225. ui->Stop_Audio_Out->setEnabled(true);
  226. }