comparison main/MainWindow.cpp @ 1995:2b83ca602ece import-audio-data

Menu wording and file-path handling fixes for recording/converting audio
author Chris Cannam
date Tue, 11 Sep 2018 14:38:21 +0100
parents 64e8701e77b4
children 6d82eecd4164
comparison
equal deleted inserted replaced
1994:692734ef4f40 1995:2b83ca602ece
30 #include "framework/Document.h" 30 #include "framework/Document.h"
31 #include "framework/TransformUserConfigurator.h" 31 #include "framework/TransformUserConfigurator.h"
32 #include "view/ViewManager.h" 32 #include "view/ViewManager.h"
33 #include "base/Preferences.h" 33 #include "base/Preferences.h"
34 #include "base/ResourceFinder.h" 34 #include "base/ResourceFinder.h"
35 #include "base/RecordDirectory.h"
35 #include "layer/WaveformLayer.h" 36 #include "layer/WaveformLayer.h"
36 #include "layer/TimeRulerLayer.h" 37 #include "layer/TimeRulerLayer.h"
37 #include "layer/TimeInstantLayer.h" 38 #include "layer/TimeInstantLayer.h"
38 #include "layer/TimeValueLayer.h" 39 #include "layer/TimeValueLayer.h"
39 #include "layer/NoteLayer.h" 40 #include "layer/NoteLayer.h"
563 menu->addAction(action); 564 menu->addAction(action);
564 toolbar->addAction(action); 565 toolbar->addAction(action);
565 566
566 menu->addSeparator(); 567 menu->addSeparator();
567 568
568 /*
569 icon = il.load("fileopenaudio");
570 action = new QAction(icon, tr("&Import Audio File..."), this);
571 action->setShortcut(tr("Ctrl+I"));
572 action->setStatusTip(tr("Import an existing audio file"));
573 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
574 m_keyReference->registerShortcut(action);
575 menu->addAction(action);
576 */
577
578 // the Replace action we made earlier 569 // the Replace action we made earlier
579 menu->addAction(raction); 570 menu->addAction(raction);
580 571
581 // the Import action we made earlier 572 // the Import action we made earlier
582 menu->addAction(iaction); 573 menu->addAction(iaction);
605 m_keyReference->registerShortcut(action); 596 m_keyReference->registerShortcut(action);
606 menu->addAction(action); 597 menu->addAction(action);
607 598
608 menu->addSeparator(); 599 menu->addSeparator();
609 600
610 action = new QAction(tr("Import Audio from Data File..."), this); 601 action = new QAction(tr("Convert Audio from Data File..."), this);
611 action->setStatusTip(tr("Import audio sample values from a CSV data file")); 602 action->setStatusTip(tr("Convert and import audio sample values from a CSV data file"));
612 connect(action, SIGNAL(triggered()), this, SLOT(importAudioData())); 603 connect(action, SIGNAL(triggered()), this, SLOT(convertAudio()));
613 menu->addAction(action); 604 menu->addAction(action);
614 605
615 action = new QAction(tr("Export Audio to Data File..."), this); 606 action = new QAction(tr("Export Audio to Data File..."), this);
616 action->setStatusTip(tr("Export audio from selection into a CSV data file")); 607 action->setStatusTip(tr("Export audio from selection into a CSV data file"));
617 connect(action, SIGNAL(triggered()), this, SLOT(exportAudioData())); 608 connect(action, SIGNAL(triggered()), this, SLOT(exportAudioData()));
632 connect(this, SIGNAL(canExportImage(bool)), action, SLOT(setEnabled(bool))); 623 connect(this, SIGNAL(canExportImage(bool)), action, SLOT(setEnabled(bool)));
633 menu->addAction(action); 624 menu->addAction(action);
634 625
635 menu->addSeparator(); 626 menu->addSeparator();
636 627
637 action = new QAction(tr("Browse Recorded Audio Folder"), this); 628 action = new QAction(tr("Browse Recorded and Converted Audio"), this);
638 action->setStatusTip(tr("Open the Recorded Audio folder in the system file browser")); 629 action->setStatusTip(tr("Open the Recorded Audio folder in the system file browser"));
639 connect(action, SIGNAL(triggered()), this, SLOT(browseRecordedAudio())); 630 connect(action, SIGNAL(triggered()), this, SLOT(browseRecordedAudio()));
640 menu->addAction(action); 631 menu->addAction(action);
641 632
642 menu->addSeparator(); 633 menu->addSeparator();
2884 QMessageBox::critical(this, tr("Failed to write file"), error); 2875 QMessageBox::critical(this, tr("Failed to write file"), error);
2885 } 2876 }
2886 } 2877 }
2887 2878
2888 void 2879 void
2889 MainWindow::importAudioData() 2880 MainWindow::convertAudio()
2890 { 2881 {
2891 QString path = getOpenFileName(FileFinder::CSVFile); 2882 QString path = getOpenFileName(FileFinder::CSVFile);
2892 if (path == "") return; 2883 if (path == "") return;
2893 2884
2894 sv_samplerate_t rate = 44100; //!!! 2885 sv_samplerate_t defaultRate = 44100;
2895 2886
2896 CSVFormat format(path); 2887 CSVFormat format(path);
2897 format.setModelType(CSVFormat::WaveFileModel); 2888 format.setModelType(CSVFormat::WaveFileModel);
2898 format.setSampleRate(rate);
2899 format.setTimingType(CSVFormat::ImplicitTiming); 2889 format.setTimingType(CSVFormat::ImplicitTiming);
2900 format.setTimeUnits(CSVFormat::TimeAudioFrames); 2890 format.setTimeUnits(CSVFormat::TimeAudioFrames);
2891 format.setSampleRate(defaultRate); // as a default for the dialog
2892
2901 for (int i = 0; i < format.getColumnCount(); ++i) { 2893 for (int i = 0; i < format.getColumnCount(); ++i) {
2902 if (format.isColumnNumeric(CSVFormat::ColumnNumeric)) { 2894 if (format.isColumnNumeric(CSVFormat::ColumnNumeric)) {
2903 format.setColumnPurpose(i, CSVFormat::ColumnValue); 2895 format.setColumnPurpose(i, CSVFormat::ColumnValue);
2904 } 2896 }
2905 } 2897 }
2920 (tr("Importing audio data..."), true, 0, this, Qt::ApplicationModal); 2912 (tr("Importing audio data..."), true, 0, this, Qt::ApplicationModal);
2921 2913
2922 WaveFileModel *model = qobject_cast<WaveFileModel *> 2914 WaveFileModel *model = qobject_cast<WaveFileModel *>
2923 (DataFileReaderFactory::loadCSV 2915 (DataFileReaderFactory::loadCSV
2924 (path, format, 2916 (path, format,
2925 getMainModel() ? getMainModel()->getSampleRate() : rate, 2917 getMainModel() ? getMainModel()->getSampleRate() : defaultRate,
2926 progress)); 2918 progress));
2927 2919
2928 if (progress->wasCancelled()) { 2920 if (progress->wasCancelled()) {
2929 2921
2930 delete model; 2922 delete model;
3242 void 3234 void
3243 MainWindow::browseRecordedAudio() 3235 MainWindow::browseRecordedAudio()
3244 { 3236 {
3245 if (!m_recordTarget) return; 3237 if (!m_recordTarget) return;
3246 3238
3247 QString path = m_recordTarget->getRecordContainerFolder(); 3239 QString path = RecordDirectory::getRecordContainerDirectory();
3248 if (path == "") path = m_recordTarget->getRecordFolder(); 3240 if (path == "") path = RecordDirectory::getRecordDirectory();
3249 if (path == "") return; 3241 if (path == "") return;
3250 3242
3251 openLocalFolder(path); 3243 openLocalFolder(path);
3252 } 3244 }
3253 3245