Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 659:49cf3787cf22 single-point
Add exportLayerTo (moved here from MainWindow)
author | Chris Cannam |
---|---|
date | Thu, 28 Mar 2019 14:34:00 +0000 |
parents | 94f518af106c |
children | 31ea416fea3c |
comparison
equal
deleted
inserted
replaced
658:94f518af106c | 659:49cf3787cf22 |
---|---|
52 | 52 |
53 #include "data/fileio/DataFileReaderFactory.h" | 53 #include "data/fileio/DataFileReaderFactory.h" |
54 #include "data/fileio/PlaylistFileReader.h" | 54 #include "data/fileio/PlaylistFileReader.h" |
55 #include "data/fileio/WavFileWriter.h" | 55 #include "data/fileio/WavFileWriter.h" |
56 #include "data/fileio/MIDIFileWriter.h" | 56 #include "data/fileio/MIDIFileWriter.h" |
57 #include "data/fileio/CSVFileWriter.h" | |
57 #include "data/fileio/BZipFileDevice.h" | 58 #include "data/fileio/BZipFileDevice.h" |
58 #include "data/fileio/FileSource.h" | 59 #include "data/fileio/FileSource.h" |
59 #include "data/fileio/AudioFileReaderFactory.h" | 60 #include "data/fileio/AudioFileReaderFactory.h" |
60 #include "rdf/RDFImporter.h" | 61 #include "rdf/RDFImporter.h" |
62 #include "rdf/RDFExporter.h" | |
61 | 63 |
62 #include "base/RecentFiles.h" | 64 #include "base/RecentFiles.h" |
63 | 65 |
64 #include "base/PlayParameterRepository.h" | 66 #include "base/PlayParameterRepository.h" |
65 #include "base/XmlExportable.h" | 67 #include "base/XmlExportable.h" |
2763 .arg(path).arg(f.what())); | 2765 .arg(path).arg(f.what())); |
2764 return false; | 2766 return false; |
2765 } | 2767 } |
2766 } | 2768 } |
2767 | 2769 |
2770 bool | |
2771 MainWindowBase::exportLayerTo(Layer *layer, QString path, QString &error) | |
2772 { | |
2773 if (QFileInfo(path).suffix() == "") path += ".svl"; | |
2774 | |
2775 QString suffix = QFileInfo(path).suffix().toLower(); | |
2776 | |
2777 Model *model = layer->getModel(); | |
2778 | |
2779 if (suffix == "xml" || suffix == "svl") { | |
2780 | |
2781 QFile file(path); | |
2782 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { | |
2783 error = tr("Failed to open file %1 for writing").arg(path); | |
2784 } else { | |
2785 QTextStream out(&file); | |
2786 out.setCodec(QTextCodec::codecForName("UTF-8")); | |
2787 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | |
2788 << "<!DOCTYPE sonic-visualiser>\n" | |
2789 << "<sv>\n" | |
2790 << " <data>\n"; | |
2791 | |
2792 model->toXml(out, " "); | |
2793 | |
2794 out << " </data>\n" | |
2795 << " <display>\n"; | |
2796 | |
2797 layer->toXml(out, " "); | |
2798 | |
2799 out << " </display>\n" | |
2800 << "</sv>\n"; | |
2801 } | |
2802 | |
2803 } else if (suffix == "mid" || suffix == "midi") { | |
2804 | |
2805 NoteModel *nm = dynamic_cast<NoteModel *>(model); | |
2806 | |
2807 if (!nm) { | |
2808 error = tr("Can't export non-note layers to MIDI"); | |
2809 } else { | |
2810 MIDIFileWriter writer(path, nm, nm->getSampleRate()); | |
2811 writer.write(); | |
2812 if (!writer.isOK()) { | |
2813 error = writer.getError(); | |
2814 } | |
2815 } | |
2816 | |
2817 } else if (suffix == "ttl" || suffix == "n3") { | |
2818 | |
2819 if (!RDFExporter::canExportModel(model)) { | |
2820 error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)"); | |
2821 } else { | |
2822 RDFExporter exporter(path, model); | |
2823 exporter.write(); | |
2824 if (!exporter.isOK()) { | |
2825 error = exporter.getError(); | |
2826 } | |
2827 } | |
2828 | |
2829 } else { | |
2830 | |
2831 CSVFileWriter writer(path, model, | |
2832 ((suffix == "csv") ? "," : "\t")); | |
2833 writer.write(); | |
2834 | |
2835 if (!writer.isOK()) { | |
2836 error = writer.getError(); | |
2837 } | |
2838 } | |
2839 | |
2840 return (error == ""); | |
2841 } | |
2842 | |
2768 void | 2843 void |
2769 MainWindowBase::toXml(QTextStream &out, bool asTemplate) | 2844 MainWindowBase::toXml(QTextStream &out, bool asTemplate) |
2770 { | 2845 { |
2771 QString indent(" "); | 2846 QString indent(" "); |
2772 | 2847 |