# HG changeset patch # User Chris Cannam # Date 1578497487 0 # Node ID cd1e8c731095328da09ebc0fe25b396be2b3fc9c # Parent 2915cc467ebf7d978d12571ff1c4548cd3163a5d Permit exporting selected regions only diff -r 2915cc467ebf -r cd1e8c731095 framework/MainWindowBase.cpp --- a/framework/MainWindowBase.cpp Wed Jan 08 15:29:35 2020 +0000 +++ b/framework/MainWindowBase.cpp Wed Jan 08 15:31:27 2020 +0000 @@ -62,6 +62,8 @@ #include "rdf/RDFImporter.h" #include "rdf/RDFExporter.h" +#include "transform/ModelTransformerFactory.h" + #include "base/RecentFiles.h" #include "base/XmlExportable.h" @@ -2804,8 +2806,14 @@ bool MainWindowBase::exportLayerTo(Layer *layer, View *fromView, + MultiSelection *selectionsToWrite, QString path, QString &error) { + //!!! should we pull out the whole export logic into another + // class? then we can more reasonably query it for things like + // "can we export this layer type to this file format? can we + // export selections, or only the whole layer?" + if (QFileInfo(path).suffix() == "") path += ".svl"; QString suffix = QFileInfo(path).suffix().toLower(); @@ -2818,6 +2826,8 @@ if (suffix == "xml" || suffix == "svl") { + //!!! +selection + QFile file(path); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { error = tr("Failed to open file %1 for writing").arg(path); @@ -2846,16 +2856,37 @@ if (!nm) { error = tr("Can't export non-note layers to MIDI"); - } else { + } else if (!selectionsToWrite) { MIDIFileWriter writer(path, nm.get(), nm->getSampleRate()); writer.write(); if (!writer.isOK()) { error = writer.getError(); } + } else { + NoteModel temporary(nm->getSampleRate(), + nm->getResolution(), + nm->getValueMinimum(), + nm->getValueMaximum(), + false); + temporary.setScaleUnits(nm->getScaleUnits()); + for (const auto &s: selectionsToWrite->getSelections()) { + EventVector ev(nm->getEventsStartingWithin + (s.getStartFrame(), s.getDuration())); + for (const auto &e: ev) { + temporary.add(e); + } + } + MIDIFileWriter writer(path, &temporary, temporary.getSampleRate()); + writer.write(); + if (!writer.isOK()) { + error = writer.getError(); + } } } else if (suffix == "ttl" || suffix == "n3") { + //!!! +selection + if (!RDFExporter::canExportModel(model.get())) { error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)"); } else { @@ -2875,7 +2906,12 @@ CSVFileWriter writer(path, model.get(), &dialog, ((suffix == "csv") ? "," : "\t")); - writer.write(); + + if (selectionsToWrite) { + writer.writeSelection(*selectionsToWrite); + } else { + writer.write(); + } if (!writer.isOK()) { error = writer.getError(); diff -r 2915cc467ebf -r cd1e8c731095 framework/MainWindowBase.h --- a/framework/MainWindowBase.h Wed Jan 08 15:29:35 2020 +0000 +++ b/framework/MainWindowBase.h Wed Jan 08 15:31:27 2020 +0000 @@ -166,6 +166,7 @@ virtual bool saveSessionTemplate(QString path); virtual bool exportLayerTo(Layer *layer, View *fromView, + MultiSelection *selectionsToWrite, // or null QString toPath, QString &error); void cueOSCScript(QString filename);