comparison main/MainWindow.cpp @ 185:f3191ab6d564

* Add MIDI file export (closes FR#1643721)
author Chris Cannam
date Thu, 04 Oct 2007 11:52:38 +0000
parents ebd906049fb6
children 26397b84e6a2
comparison
equal deleted inserted replaced
184:ebd906049fb6 185:f3191ab6d564
21 21
22 #include "view/Pane.h" 22 #include "view/Pane.h"
23 #include "view/PaneStack.h" 23 #include "view/PaneStack.h"
24 #include "data/model/WaveFileModel.h" 24 #include "data/model/WaveFileModel.h"
25 #include "data/model/SparseOneDimensionalModel.h" 25 #include "data/model/SparseOneDimensionalModel.h"
26 #include "data/model/NoteModel.h"
26 #include "view/ViewManager.h" 27 #include "view/ViewManager.h"
27 #include "base/Preferences.h" 28 #include "base/Preferences.h"
28 #include "layer/WaveformLayer.h" 29 #include "layer/WaveformLayer.h"
29 #include "layer/TimeRulerLayer.h" 30 #include "layer/TimeRulerLayer.h"
30 #include "layer/TimeInstantLayer.h" 31 #include "layer/TimeInstantLayer.h"
49 #include "audioio/PlaySpeedRangeMapper.h" 50 #include "audioio/PlaySpeedRangeMapper.h"
50 #include "data/fileio/DataFileReaderFactory.h" 51 #include "data/fileio/DataFileReaderFactory.h"
51 #include "data/fileio/PlaylistFileReader.h" 52 #include "data/fileio/PlaylistFileReader.h"
52 #include "data/fileio/WavFileWriter.h" 53 #include "data/fileio/WavFileWriter.h"
53 #include "data/fileio/CSVFileWriter.h" 54 #include "data/fileio/CSVFileWriter.h"
55 #include "data/fileio/MIDIFileWriter.h"
54 #include "data/fileio/BZipFileDevice.h" 56 #include "data/fileio/BZipFileDevice.h"
55 #include "data/fileio/RemoteFile.h" 57 #include "data/fileio/RemoteFile.h"
56 #include "data/fft/FFTDataServer.h" 58 #include "data/fft/FFTDataServer.h"
57 #include "base/RecentFiles.h" 59 #include "base/RecentFiles.h"
58 #include "transform/TransformFactory.h" 60 #include "transform/TransformFactory.h"
372 return ff->getOpenFileName(type, m_sessionFile); 374 return ff->getOpenFileName(type, m_sessionFile);
373 case FileFinder::AudioFile: 375 case FileFinder::AudioFile:
374 return ff->getOpenFileName(type, m_audioFile); 376 return ff->getOpenFileName(type, m_audioFile);
375 case FileFinder::LayerFile: 377 case FileFinder::LayerFile:
376 return ff->getOpenFileName(type, m_sessionFile); 378 return ff->getOpenFileName(type, m_sessionFile);
379 case FileFinder::LayerFileNoMidi:
380 return ff->getOpenFileName(type, m_sessionFile);
377 case FileFinder::SessionOrAudioFile: 381 case FileFinder::SessionOrAudioFile:
378 return ff->getOpenFileName(type, m_sessionFile); 382 return ff->getOpenFileName(type, m_sessionFile);
379 case FileFinder::ImageFile: 383 case FileFinder::ImageFile:
380 return ff->getOpenFileName(type, m_sessionFile); 384 return ff->getOpenFileName(type, m_sessionFile);
381 case FileFinder::AnyFile: 385 case FileFinder::AnyFile:
399 case FileFinder::SessionFile: 403 case FileFinder::SessionFile:
400 return ff->getSaveFileName(type, m_sessionFile); 404 return ff->getSaveFileName(type, m_sessionFile);
401 case FileFinder::AudioFile: 405 case FileFinder::AudioFile:
402 return ff->getSaveFileName(type, m_audioFile); 406 return ff->getSaveFileName(type, m_audioFile);
403 case FileFinder::LayerFile: 407 case FileFinder::LayerFile:
408 return ff->getSaveFileName(type, m_sessionFile);
409 case FileFinder::LayerFileNoMidi:
404 return ff->getSaveFileName(type, m_sessionFile); 410 return ff->getSaveFileName(type, m_sessionFile);
405 case FileFinder::SessionOrAudioFile: 411 case FileFinder::SessionOrAudioFile:
406 return ff->getSaveFileName(type, m_sessionFile); 412 return ff->getSaveFileName(type, m_sessionFile);
407 case FileFinder::ImageFile: 413 case FileFinder::ImageFile:
408 return ff->getSaveFileName(type, m_sessionFile); 414 return ff->getSaveFileName(type, m_sessionFile);
2602 if (!layer) return; 2608 if (!layer) return;
2603 2609
2604 Model *model = layer->getModel(); 2610 Model *model = layer->getModel();
2605 if (!model) return; 2611 if (!model) return;
2606 2612
2607 QString path = getSaveFileName(FileFinder::LayerFile); 2613 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
2614
2615 if (dynamic_cast<NoteModel *>(model)) type = FileFinder::LayerFile;
2616
2617 QString path = getSaveFileName(type);
2608 2618
2609 if (path == "") return; 2619 if (path == "") return;
2610 2620
2611 if (QFileInfo(path).suffix() == "") path += ".svl"; 2621 if (QFileInfo(path).suffix() == "") path += ".svl";
2612 2622
2623 QString suffix = QFileInfo(path).suffix().toLower();
2624
2613 QString error; 2625 QString error;
2614 2626
2615 if (path.endsWith(".xml") || path.endsWith(".svl")) { 2627 if (suffix == "xml" || suffix == "svl") {
2616 2628
2617 QFile file(path); 2629 QFile file(path);
2618 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { 2630 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
2619 error = tr("Failed to open file %1 for writing").arg(path); 2631 error = tr("Failed to open file %1 for writing").arg(path);
2620 } else { 2632 } else {
2633 2645
2634 out << " </display>\n" 2646 out << " </display>\n"
2635 << "</sv>\n"; 2647 << "</sv>\n";
2636 } 2648 }
2637 2649
2650 } else if (suffix == "mid" || suffix == "midi") {
2651
2652 NoteModel *nm = dynamic_cast<NoteModel *>(model);
2653
2654 if (!nm) {
2655 error = tr("Can't export non-note layers to MIDI");
2656 } else {
2657 MIDIFileWriter writer(path, nm);
2658 writer.write();
2659 if (!writer.isOK()) {
2660 error = writer.getError();
2661 }
2662 }
2663
2638 } else { 2664 } else {
2639 2665
2640 CSVFileWriter writer(path, model, 2666 CSVFileWriter writer(path, model,
2641 (path.endsWith(".csv") ? "," : "\t")); 2667 ((suffix == "csv") ? "," : "\t"));
2642 writer.write(); 2668 writer.write();
2643 2669
2644 if (!writer.isOK()) { 2670 if (!writer.isOK()) {
2645 error = writer.getError(); 2671 error = writer.getError();
2646 } 2672 }