Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 724:cd1e8c731095 spectrogram-export
Permit exporting selected regions only
author | Chris Cannam |
---|---|
date | Wed, 08 Jan 2020 15:31:27 +0000 |
parents | b06b18c15fd4 |
children | 16f6737fa557 |
comparison
equal
deleted
inserted
replaced
723:2915cc467ebf | 724:cd1e8c731095 |
---|---|
59 #include "data/fileio/BZipFileDevice.h" | 59 #include "data/fileio/BZipFileDevice.h" |
60 #include "data/fileio/FileSource.h" | 60 #include "data/fileio/FileSource.h" |
61 #include "data/fileio/AudioFileReaderFactory.h" | 61 #include "data/fileio/AudioFileReaderFactory.h" |
62 #include "rdf/RDFImporter.h" | 62 #include "rdf/RDFImporter.h" |
63 #include "rdf/RDFExporter.h" | 63 #include "rdf/RDFExporter.h" |
64 | |
65 #include "transform/ModelTransformerFactory.h" | |
64 | 66 |
65 #include "base/RecentFiles.h" | 67 #include "base/RecentFiles.h" |
66 | 68 |
67 #include "base/XmlExportable.h" | 69 #include "base/XmlExportable.h" |
68 #include "base/Profiler.h" | 70 #include "base/Profiler.h" |
2802 } | 2804 } |
2803 } | 2805 } |
2804 | 2806 |
2805 bool | 2807 bool |
2806 MainWindowBase::exportLayerTo(Layer *layer, View *fromView, | 2808 MainWindowBase::exportLayerTo(Layer *layer, View *fromView, |
2809 MultiSelection *selectionsToWrite, | |
2807 QString path, QString &error) | 2810 QString path, QString &error) |
2808 { | 2811 { |
2812 //!!! should we pull out the whole export logic into another | |
2813 // class? then we can more reasonably query it for things like | |
2814 // "can we export this layer type to this file format? can we | |
2815 // export selections, or only the whole layer?" | |
2816 | |
2809 if (QFileInfo(path).suffix() == "") path += ".svl"; | 2817 if (QFileInfo(path).suffix() == "") path += ".svl"; |
2810 | 2818 |
2811 QString suffix = QFileInfo(path).suffix().toLower(); | 2819 QString suffix = QFileInfo(path).suffix().toLower(); |
2812 | 2820 |
2813 auto model = ModelById::get(layer->getExportModel(fromView)); | 2821 auto model = ModelById::get(layer->getExportModel(fromView)); |
2816 return false; | 2824 return false; |
2817 } | 2825 } |
2818 | 2826 |
2819 if (suffix == "xml" || suffix == "svl") { | 2827 if (suffix == "xml" || suffix == "svl") { |
2820 | 2828 |
2829 //!!! +selection | |
2830 | |
2821 QFile file(path); | 2831 QFile file(path); |
2822 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { | 2832 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { |
2823 error = tr("Failed to open file %1 for writing").arg(path); | 2833 error = tr("Failed to open file %1 for writing").arg(path); |
2824 } else { | 2834 } else { |
2825 QTextStream out(&file); | 2835 QTextStream out(&file); |
2844 | 2854 |
2845 auto nm = ModelById::getAs<NoteModel>(layer->getModel()); | 2855 auto nm = ModelById::getAs<NoteModel>(layer->getModel()); |
2846 | 2856 |
2847 if (!nm) { | 2857 if (!nm) { |
2848 error = tr("Can't export non-note layers to MIDI"); | 2858 error = tr("Can't export non-note layers to MIDI"); |
2849 } else { | 2859 } else if (!selectionsToWrite) { |
2850 MIDIFileWriter writer(path, nm.get(), nm->getSampleRate()); | 2860 MIDIFileWriter writer(path, nm.get(), nm->getSampleRate()); |
2851 writer.write(); | 2861 writer.write(); |
2852 if (!writer.isOK()) { | 2862 if (!writer.isOK()) { |
2853 error = writer.getError(); | 2863 error = writer.getError(); |
2854 } | 2864 } |
2865 } else { | |
2866 NoteModel temporary(nm->getSampleRate(), | |
2867 nm->getResolution(), | |
2868 nm->getValueMinimum(), | |
2869 nm->getValueMaximum(), | |
2870 false); | |
2871 temporary.setScaleUnits(nm->getScaleUnits()); | |
2872 for (const auto &s: selectionsToWrite->getSelections()) { | |
2873 EventVector ev(nm->getEventsStartingWithin | |
2874 (s.getStartFrame(), s.getDuration())); | |
2875 for (const auto &e: ev) { | |
2876 temporary.add(e); | |
2877 } | |
2878 } | |
2879 MIDIFileWriter writer(path, &temporary, temporary.getSampleRate()); | |
2880 writer.write(); | |
2881 if (!writer.isOK()) { | |
2882 error = writer.getError(); | |
2883 } | |
2855 } | 2884 } |
2856 | 2885 |
2857 } else if (suffix == "ttl" || suffix == "n3") { | 2886 } else if (suffix == "ttl" || suffix == "n3") { |
2887 | |
2888 //!!! +selection | |
2858 | 2889 |
2859 if (!RDFExporter::canExportModel(model.get())) { | 2890 if (!RDFExporter::canExportModel(model.get())) { |
2860 error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)"); | 2891 error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)"); |
2861 } else { | 2892 } else { |
2862 RDFExporter exporter(path, model.get()); | 2893 RDFExporter exporter(path, model.get()); |
2873 Qt::ApplicationModal | 2904 Qt::ApplicationModal |
2874 }; | 2905 }; |
2875 | 2906 |
2876 CSVFileWriter writer(path, model.get(), &dialog, | 2907 CSVFileWriter writer(path, model.get(), &dialog, |
2877 ((suffix == "csv") ? "," : "\t")); | 2908 ((suffix == "csv") ? "," : "\t")); |
2878 writer.write(); | 2909 |
2910 if (selectionsToWrite) { | |
2911 writer.writeSelection(*selectionsToWrite); | |
2912 } else { | |
2913 writer.write(); | |
2914 } | |
2879 | 2915 |
2880 if (!writer.isOK()) { | 2916 if (!writer.isOK()) { |
2881 error = writer.getError(); | 2917 error = writer.getError(); |
2882 if (error == "") { | 2918 if (error == "") { |
2883 error = tr("Failed to export layer for an unknown reason"); | 2919 error = tr("Failed to export layer for an unknown reason"); |