Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 1987:fbf8ce45fcad import-audio-data
Use CSV format dialog for importing audio data, + some text changes
author | Chris Cannam |
---|---|
date | Thu, 06 Sep 2018 12:35:11 +0100 |
parents | bb9cf19e0b67 |
children | 0088a8f452ff |
comparison
equal
deleted
inserted
replaced
1986:bb9cf19e0b67 | 1987:fbf8ce45fcad |
---|---|
57 #include "widgets/TransformFinder.h" | 57 #include "widgets/TransformFinder.h" |
58 #include "widgets/LabelCounterInputDialog.h" | 58 #include "widgets/LabelCounterInputDialog.h" |
59 #include "widgets/ActivityLog.h" | 59 #include "widgets/ActivityLog.h" |
60 #include "widgets/UnitConverter.h" | 60 #include "widgets/UnitConverter.h" |
61 #include "widgets/ProgressDialog.h" | 61 #include "widgets/ProgressDialog.h" |
62 #include "widgets/CSVFormatDialog.h" | |
62 #include "audio/AudioCallbackPlaySource.h" | 63 #include "audio/AudioCallbackPlaySource.h" |
63 #include "audio/AudioCallbackRecordTarget.h" | 64 #include "audio/AudioCallbackRecordTarget.h" |
64 #include "audio/PlaySpeedRangeMapper.h" | 65 #include "audio/PlaySpeedRangeMapper.h" |
65 #include "data/fileio/DataFileReaderFactory.h" | 66 #include "data/fileio/DataFileReaderFactory.h" |
66 #include "data/fileio/PlaylistFileReader.h" | 67 #include "data/fileio/PlaylistFileReader.h" |
604 m_keyReference->registerShortcut(action); | 605 m_keyReference->registerShortcut(action); |
605 menu->addAction(action); | 606 menu->addAction(action); |
606 | 607 |
607 menu->addSeparator(); | 608 menu->addSeparator(); |
608 | 609 |
609 action = new QAction(tr("Import Audio Data from CSV..."), this); | 610 action = new QAction(tr("Import Audio from Data File..."), this); |
610 action->setStatusTip(tr("Import audio sample values from a CSV data file")); | 611 action->setStatusTip(tr("Import audio sample values from a CSV data file")); |
611 connect(action, SIGNAL(triggered()), this, SLOT(importAudioData())); | 612 connect(action, SIGNAL(triggered()), this, SLOT(importAudioData())); |
612 menu->addAction(action); | 613 menu->addAction(action); |
613 | 614 |
614 action = new QAction(tr("Export Audio Data to CSV..."), this); | 615 action = new QAction(tr("Export Audio to Data File..."), this); |
615 action->setStatusTip(tr("Export audio from selection into a CSV data file")); | 616 action->setStatusTip(tr("Export audio from selection into a CSV data file")); |
616 connect(action, SIGNAL(triggered()), this, SLOT(exportAudioData())); | 617 connect(action, SIGNAL(triggered()), this, SLOT(exportAudioData())); |
617 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); | 618 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); |
618 menu->addAction(action); | 619 menu->addAction(action); |
619 | 620 |
2896 format.setModelType(CSVFormat::WaveFileModel); | 2897 format.setModelType(CSVFormat::WaveFileModel); |
2897 format.setSampleRate(rate); | 2898 format.setSampleRate(rate); |
2898 format.setTimingType(CSVFormat::ImplicitTiming); | 2899 format.setTimingType(CSVFormat::ImplicitTiming); |
2899 format.setTimeUnits(CSVFormat::TimeAudioFrames); | 2900 format.setTimeUnits(CSVFormat::TimeAudioFrames); |
2900 for (int i = 0; i < format.getColumnCount(); ++i) { | 2901 for (int i = 0; i < format.getColumnCount(); ++i) { |
2901 if (format.getColumnQualities()[i] & CSVFormat::ColumnNumeric) { | 2902 if (format.isColumnNumeric(CSVFormat::ColumnNumeric)) { |
2902 format.setColumnPurpose(i, CSVFormat::ColumnValue); | 2903 format.setColumnPurpose(i, CSVFormat::ColumnValue); |
2903 } | 2904 } |
2904 } | 2905 } |
2905 | 2906 |
2907 { | |
2908 CSVFormatDialog *dialog = new CSVFormatDialog(this, format); | |
2909 if (dialog->exec() != QDialog::Accepted) { | |
2910 delete dialog; | |
2911 return; | |
2912 } | |
2913 format = dialog->getFormat(); | |
2914 delete dialog; | |
2915 } | |
2916 | |
2906 FileOpenStatus status = FileOpenSucceeded; | 2917 FileOpenStatus status = FileOpenSucceeded; |
2907 | 2918 |
2908 ProgressDialog *dialog = new ProgressDialog(tr("Importing audio data..."), | 2919 ProgressDialog *progress = new ProgressDialog |
2909 true, 0, this, | 2920 (tr("Importing audio data..."), true, 0, this, Qt::ApplicationModal); |
2910 Qt::ApplicationModal); | |
2911 | 2921 |
2912 WaveFileModel *model = qobject_cast<WaveFileModel *> | 2922 WaveFileModel *model = qobject_cast<WaveFileModel *> |
2913 (DataFileReaderFactory::loadCSV | 2923 (DataFileReaderFactory::loadCSV |
2914 (path, format, | 2924 (path, format, |
2915 getMainModel() ? getMainModel()->getSampleRate() : rate, | 2925 getMainModel() ? getMainModel()->getSampleRate() : rate, |
2916 dialog)); | 2926 progress)); |
2917 | 2927 |
2918 if (dialog->wasCancelled()) { | 2928 if (progress->wasCancelled()) { |
2919 | 2929 |
2920 delete model; | 2930 delete model; |
2921 status = FileOpenCancelled; | 2931 status = FileOpenCancelled; |
2922 | 2932 |
2923 } else if (!model || !model->isOK()) { | 2933 } else if (!model || !model->isOK()) { |
2932 CreateAdditionalModel, | 2942 CreateAdditionalModel, |
2933 getDefaultSessionTemplate(), | 2943 getDefaultSessionTemplate(), |
2934 false); | 2944 false); |
2935 } | 2945 } |
2936 | 2946 |
2937 delete dialog; | 2947 delete progress; |
2938 | 2948 |
2939 if (status == FileOpenFailed) { | 2949 if (status == FileOpenFailed) { |
2940 emit hideSplash(); | 2950 emit hideSplash(); |
2941 QMessageBox::critical(this, tr("Failed to open file"), | 2951 QMessageBox::critical(this, tr("Failed to open file"), |
2942 tr("<b>File open failed</b><p>Audio data file %1 could not be opened.").arg(path)); | 2952 tr("<b>File open failed</b><p>Audio data file %1 could not be opened.").arg(path)); |