diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 75c7332..d4f1e8f 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -274,7 +274,9 @@ void PaulstretchpluginAudioProcessorEditor::timerCallback(int id) if (processor.m_playposinfo.isPlaying) infotext += " "+String(processor.m_playposinfo.timeInSeconds,1); if (processor.m_show_technical_info) - infotext += " " + String(m_wavecomponent.m_image_init_count) + " " + String(m_wavecomponent.m_image_update_count); + infotext += " " + String(m_wavecomponent.m_image_init_count) + " " + String(m_wavecomponent.m_image_update_count)+ " "; + if (processor.m_offline_render_state >= 0 && processor.m_offline_render_state <= 100) + infotext += String(processor.m_offline_render_state)+"%"; m_info_label.setText(infotext, dontSendNotification); m_perfmeter.repaint(); } @@ -358,7 +360,8 @@ void PaulstretchpluginAudioProcessorEditor::showSettingsMenu() menu.addItem(6, "Dump preset to clipboard", true, false); #endif menu.addItem(7, "Show technical info", true, processor.m_show_technical_info); - menu.addItem(8, "Offline render...", true, false); + menu.addItem(8, "Offline render...", + processor.m_offline_render_state == 200 || processor.m_offline_render_state == -1, false); int r = menu.show(); if (r >= 200 && r < 210) { diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index c0fd391..6915e3f 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -417,8 +417,7 @@ String PaulstretchpluginAudioProcessor::offlineRender(File outputfile) int numoutchans = *getIntParameter(cpi_num_outchans); auto ss = std::make_shared(numoutchans,m_afm); int blocksize = 2048; - int64_t outlen = 10 * getSampleRateChecked(); - int64_t outcounter = 0; + ss->setAudioFile(m_current_file); ProcessParameters renderpars; updateStretchParametersFromPluginParameters(renderpars); @@ -438,9 +437,9 @@ String PaulstretchpluginAudioProcessor::offlineRender(File outputfile) ss->setPaused(getParameter(cpi_pause_enabled)); ss->setSpectrumProcessOrder(m_stretch_source->getSpectrumProcessOrder()); ss->setFFTSize(m_fft_size_to_use); - ss->prepareToPlay(blocksize, getSampleRateChecked()); - AudioBuffer renderbuffer(numoutchans, blocksize); - + ss->setMainVolume(*getFloatParameter(cpi_main_volume)); + double outsr = getSampleRateChecked(); + ss->prepareToPlay(blocksize, outsr); WavAudioFormat wavformat; FileOutputStream* outstream = outputfiletouse.createOutputStream(); if (outstream == nullptr) @@ -451,15 +450,25 @@ String PaulstretchpluginAudioProcessor::offlineRender(File outputfile) delete outstream; return "Could not create WAV writer"; } - AudioSourceChannelInfo asci(renderbuffer); - while (outcounter < outlen) + auto rendertask = [ss,writer,blocksize,numoutchans, outsr, this]() { - ss->setMainVolume(*getFloatParameter(cpi_main_volume)); - ss->getNextAudioBlock(asci); - writer->writeFromAudioSampleBuffer(renderbuffer,0,blocksize); - outcounter += blocksize; - } - delete writer; + AudioBuffer renderbuffer(numoutchans, blocksize); + int64_t outlen = 50 * outsr; + int64_t outcounter = 0; + AudioSourceChannelInfo asci(renderbuffer); + m_offline_render_state = 0; + while (outcounter < outlen) + { + ss->getNextAudioBlock(asci); + writer->writeFromAudioSampleBuffer(renderbuffer, 0, blocksize); + outcounter += blocksize; + m_offline_render_state = 100.0 / outlen * outcounter; + } + m_offline_render_state = 200; + delete writer; + }; + std::thread th(rendertask); + th.detach(); return "Rendered OK"; } diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 9f66851..8aae594 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -162,6 +162,7 @@ public: ValueTree getStateTree(bool ignoreoptions, bool ignorefile); void setStateFromTree(ValueTree tree); String offlineRender(File outputfile); + std::atomic m_offline_render_state{ -1 }; bool m_state_dirty = false; std::unique_ptr m_thumb; bool m_show_technical_info = false;