123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- /*
- Copyright (C) 2016 Tobias Platen
-
- This file is part of OREMO2.
- OREMO2 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "QTextStream"
- #include "QTreeView"
- #include "QFileSystemModel"
- #include <math.h>
- #include <qcustomplot.h>
- #include <QTableView>
- #include "tablemodel.h"
- #include "qcustomplot.h"
- MainWindow::MainWindow(RecordingManager* rec,QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- this->rec = rec;
- connect(rec,&RecordingManager::recFinished,this,&MainWindow::recFinished);
- table= new QTableView();
- model = nullptr;
- QWidget* widget = new QWidget();
- QHBoxLayout* layout = new QHBoxLayout();
- this->setCentralWidget(table);
- layout->addWidget(table);
- widget->setLayout(layout);
- QCustomPlot* plot = new QCustomPlot();
- table->setMaximumWidth(480);
- layout->addWidget(plot);
- this->setCentralWidget(widget);
- ui->mainToolBar->addWidget(ui->btnRec);
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::openSession(QString path)
- {
- QFileInfo file(path);
- if(file.exists() and file.isFile() and path.endsWith(".csv"))
- {
- model= new TableModel(path);
- table->setModel(model);
- QString basename = file.fileName().replace(".csv","");
- QString dirname = file.dir().path()+"/"+basename;
- QFileInfo dir(dirname);
- if(!dir.exists())
- {
- file.dir().mkdir(basename);
- basedir = dirname;
- }
- else if(dir.isFile())
- {
- QMessageBox msgBox;
- msgBox.setText("File Exists");
- msgBox.exec();
- return;
- }
- else if(dir.isDir()){
- //load dir contents into dirmodel
- basedir = dirname;
- }
- }
- else {
- QMessageBox msgBox;
- msgBox.setText("Not a valid CSV file");
- msgBox.exec();
- }
- }
- // FIX crash here
- void MainWindow::on_btnRec_clicked()
- {
- if(model==nullptr) return;
- //return if config data missig
- TableItem* item = model->getDataAtIndex(currentIndex);
- //FIXME recording path
- float length = QVariant(item->len).toFloat();
- activeRec = basedir+"/"+item->wav+".flac";
- rec->recStart(activeRec,length);
- this->statusBar()->showMessage("Recording "+item->wav+".wav",length*1000);
- }
- void MainWindow::recFinished()
- {
- QString result;
- float v = rec->getMaxVolume();
- if(v>0)
- {
- checkRecording();
- float db = 20 * log10(v);
- QString vol;
- vol.sprintf("%+06.2f", db);
- TableItem* item = model->getDataAtIndex(currentIndex);
- item->dec = vol;
- currentIndex++;
- model->selectIndex(currentIndex);
- model->update();
- }
- else
- {
- QTextStream(&result) << "silence";
- model->update();
- }
- // this->statusBar()->showMessage(result,60*1000);
- // TODO store in table
- }
- void MainWindow::on_actionQuit_triggered()
- {
- this->close();
- }
- void MainWindow::on_actionOpen_Directory_triggered()
- {
- QString fileName = QFileDialog::getOpenFileName(this,tr("Open VoiceBank"), "", "");
- qDebug() << fileName;
- //FIXME -- rec dir different from reclist
- openSession(fileName);
- }
- void MainWindow::checkRecording()
- {
- qDebug() << "checkRecording" << activeRec;
- //maybe use a python script for this task, left and right blank at least 100 ms, optional check of pitch
- }
|