From 0fcacc1c3329e905228ceb80903f69561a7db732 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 15 Apr 2014 09:55:45 +0200 Subject: New selections model. --- dgedit/audioextractor.cc | 69 +++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 51 deletions(-) (limited to 'dgedit/audioextractor.cc') diff --git a/dgedit/audioextractor.cc b/dgedit/audioextractor.cc index 8395b7f..5e37312 100644 --- a/dgedit/audioextractor.cc +++ b/dgedit/audioextractor.cc @@ -37,13 +37,12 @@ typedef struct { float *data; } audiodata_t; -AudioExtractor::AudioExtractor(QObject *parent) - : QObject(parent) +AudioExtractor::AudioExtractor(Selections &s, QObject *parent) + : QObject(parent), selections(s) { } -void AudioExtractor::exportSelections(Selections selections, - Levels levels) +void AudioExtractor::exportSelections() { // Open all input audio files: audiodata_t audiodata[audiofiles.size()]; @@ -67,9 +66,10 @@ void AudioExtractor::exportSelections(Selections selections, } idx = 0; - QMap::iterator si = selections.begin(); - while(si != selections.end()) { - Selection &sel = *si; + QVector sels = selections.ids(); + QVector::iterator si = sels.begin(); + while(si != sels.end()) { + Selection sel = selections.get(*si); size_t offset = sel.from; size_t size = sel.to - sel.from; size_t fadein = sel.fadein; @@ -161,19 +161,23 @@ void AudioExtractor::exportSelections(Selections selections, QDomElement samples = doc.createElement("samples"); instrument.appendChild(samples); + { // Do the adding to the xml file one sample at the time. int index = 0; - QMap::iterator i = selections.begin(); - while(i != selections.end()) { + QVector::iterator si = sels.begin(); + while(si != sels.end()) { index++; - i->name = prefix + "-" + QString::number(index); + Selection i = selections.get(*si); + i.name = prefix + "-" + QString::number(index); QDomElement sample = doc.createElement("sample"); - sample.setAttribute("name", i->name); - sample.setAttribute("power", QString::number(i->energy)); + sample.setAttribute("name", i.name); + sample.setAttribute("power", QString::number(i.energy)); samples.appendChild(sample); + selections.update(*si, i); + int channelnum = 1; // Filechannel numbers are 1-based. AudioFileList::iterator j = audiofiles.begin(); while(j != audiofiles.end()) { @@ -191,47 +195,10 @@ void AudioExtractor::exportSelections(Selections selections, j++; } - i++; + si++; } - - QDomElement velocities = doc.createElement("velocities"); - instrument.appendChild(velocities); - - Levels::iterator k = levels.begin(); - while(k != levels.end()) { - - Levels::iterator nxt = k; - nxt++; - float next; - if(nxt == levels.end()) next = 1.0; - else next = nxt->velocity; - - - QDomElement velocity = doc.createElement("velocity"); - velocity.setAttribute("lower", k->velocity); - velocity.setAttribute("upper", next); - velocities.appendChild(velocity); - - QMap::iterator i = k->selections.begin(); - while(i != k->selections.end()) { - - QMap::iterator j = selections.begin(); - while(j != selections.end()) { - if(i->from == j->from && i->to == j->to) { - QDomElement sampleref = doc.createElement("sampleref"); - sampleref.setAttribute("name", j->name); - sampleref.setAttribute("probability", - 1.0 / (double)k->selections.size()); - velocity.appendChild(sampleref); - } - j++; - } - i++; - } - - k++; } - + QFile xmlfile(exportpath + "/" + prefix + "/" + prefix + ".xml"); xmlfile.open(QIODevice::WriteOnly); xmlfile.write(doc.toByteArray()); -- cgit v1.2.3