Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 1902:dc275d7d9aa6 import-audio-data
Toward loading audio from CSV files
author | Chris Cannam |
---|---|
date | Thu, 28 Jun 2018 14:53:38 +0100 |
parents | e5229958a10c |
children | 2160976df436 |
comparison
equal
deleted
inserted
replaced
1900:a3cd06d89a45 | 1902:dc275d7d9aa6 |
---|---|
585 action->setStatusTip(tr("Export selection as an audio file")); | 585 action->setStatusTip(tr("Export selection as an audio file")); |
586 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio())); | 586 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio())); |
587 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); | 587 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); |
588 menu->addAction(action); | 588 menu->addAction(action); |
589 | 589 |
590 menu->addSeparator(); | |
591 | |
592 action = new QAction(tr("Import Audio Data..."), this); | |
593 action->setStatusTip(tr("Import audio sample values from a CSV data file")); | |
594 connect(action, SIGNAL(triggered()), this, SLOT(importAudioData())); | |
595 menu->addAction(action); | |
596 | |
590 action = new QAction(tr("Export Audio Data..."), this); | 597 action = new QAction(tr("Export Audio Data..."), this); |
591 action->setStatusTip(tr("Export audio from selection into a data file")); | 598 action->setStatusTip(tr("Export audio from selection into a CSV data file")); |
592 connect(action, SIGNAL(triggered()), this, SLOT(exportAudioData())); | 599 connect(action, SIGNAL(triggered()), this, SLOT(exportAudioData())); |
593 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); | 600 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); |
594 menu->addAction(action); | 601 menu->addAction(action); |
595 | 602 |
596 menu->addSeparator(); | 603 menu->addSeparator(); |
2874 emit activity(tr("Export audio to \"%1\"").arg(path)); | 2881 emit activity(tr("Export audio to \"%1\"").arg(path)); |
2875 m_recentFiles.addFile(path); | 2882 m_recentFiles.addFile(path); |
2876 } | 2883 } |
2877 } else { | 2884 } else { |
2878 QMessageBox::critical(this, tr("Failed to write file"), error); | 2885 QMessageBox::critical(this, tr("Failed to write file"), error); |
2886 } | |
2887 } | |
2888 | |
2889 void | |
2890 MainWindow::importAudioData() | |
2891 { | |
2892 QString path = getOpenFileName(FileFinder::CSVFile); | |
2893 if (path == "") return; | |
2894 | |
2895 sv_samplerate_t rate = 44100; //!!! | |
2896 | |
2897 CSVFormat format(path); | |
2898 format.setModelType(CSVFormat::WaveFileModel); | |
2899 format.setSampleRate(rate); | |
2900 format.setTimingType(CSVFormat::ImplicitTiming); | |
2901 format.setTimeUnits(CSVFormat::TimeAudioFrames); | |
2902 | |
2903 FileOpenStatus status = FileOpenSucceeded; | |
2904 | |
2905 WaveFileModel *model = qobject_cast<WaveFileModel *> | |
2906 (DataFileReaderFactory::loadCSV | |
2907 (path, format, | |
2908 getMainModel() ? getMainModel()->getSampleRate() : rate)); | |
2909 | |
2910 if (!model || !model->isOK()) { | |
2911 | |
2912 delete model; | |
2913 status = FileOpenFailed; | |
2914 | |
2915 } else { | |
2916 | |
2917 status = addOpenedAudioModel(path, | |
2918 model, | |
2919 CreateAdditionalModel, | |
2920 getDefaultSessionTemplate(), | |
2921 false); | |
2922 } | |
2923 | |
2924 if (status == FileOpenFailed) { | |
2925 emit hideSplash(); | |
2926 QMessageBox::critical(this, tr("Failed to open file"), | |
2927 tr("<b>File open failed</b><p>Audio data file %1 could not be opened.").arg(path)); | |
2879 } | 2928 } |
2880 } | 2929 } |
2881 | 2930 |
2882 void | 2931 void |
2883 MainWindow::importLayer() | 2932 MainWindow::importLayer() |