Save capture files to user documents directory

This commit is contained in:
xenakios 2018-11-08 22:18:50 +02:00
parent 06ded7d011
commit 0d230ac974

View File

@ -486,9 +486,14 @@ void PaulstretchpluginAudioProcessor::saveCaptureBuffer()
if (inchans < 1) if (inchans < 1)
return; return;
Uuid uid; Uuid uid;
String outfn = "C:\\Users\\Teemu\\AppData\\Roaming\\PaulXStretch\\audio_captures\\" + uid.toString() + ".wav";
WavAudioFormat wavformat; WavAudioFormat wavformat;
String outfn = File::getSpecialLocation(File::SpecialLocationType::userDocumentsDirectory).getFullPathName() + "/paulxstretchaudiocaptures/" +
uid.toString() + ".wav";
Logger::writeToLog("Attempting to save capture to file " + outfn);
File outfile(outfn); File outfile(outfn);
outfile.create();
if (outfile.existsAsFile())
{
auto outstream = outfile.createOutputStream(); auto outstream = outfile.createOutputStream();
auto writer = unique_from_raw(wavformat.createWriterFor(outstream, getSampleRateChecked(), auto writer = unique_from_raw(wavformat.createWriterFor(outstream, getSampleRateChecked(),
inchans, 32, {}, 0)); inchans, 32, {}, 0));
@ -497,7 +502,7 @@ void PaulstretchpluginAudioProcessor::saveCaptureBuffer()
auto sourcebuffer = getStretchSource()->getSourceAudioBuffer(); auto sourcebuffer = getStretchSource()->getSourceAudioBuffer();
jassert(sourcebuffer->getNumChannels() == inchans); jassert(sourcebuffer->getNumChannels() == inchans);
jassert(sourcebuffer->getNumSamples() > 0); jassert(sourcebuffer->getNumSamples() > 0);
Logger::writeToLog("Saving capture to file " + outfn);
writer->writeFromAudioSampleBuffer(*sourcebuffer, 0, sourcebuffer->getNumSamples()); writer->writeFromAudioSampleBuffer(*sourcebuffer, 0, sourcebuffer->getNumSamples());
m_current_file = outfile; m_current_file = outfile;
} }
@ -506,6 +511,9 @@ void PaulstretchpluginAudioProcessor::saveCaptureBuffer()
Logger::writeToLog("Could not create wav writer"); Logger::writeToLog("Could not create wav writer");
delete outstream; delete outstream;
} }
}
else
Logger::writeToLog("Could not create output file");
}; };
std::thread th(task); std::thread th(task);
th.detach(); th.detach();