Bulk Convert SampleMaps to WaveTables
-
@d-healey Yeah so close now, I moved it out of the for loop which solved the size problem, but now all of the wavetables are the same
So i think it has to do with making
renderAllWaveTables
reset each time or something -
@iamlamprey What does
renderAllWaveTables
do? -
@d-healey i think it's the actual conversion part, the rest is just writing the result to a file
void SampleMapToWavetableConverter::renderAllWavetablesFromSingleWavetables(double& progress) { using Data = ResynthesisHelpers::SimpleNoteConversionData; for (int i = 0; i < 128; i++) { Array<Data> conversionData; for (auto s : sampleMap) { int loKey = s.getProperty(SampleIds::LoKey, -1); int hiKey = s.getProperty(SampleIds::HiKey, -1); int root = s.getProperty(SampleIds::Root, -1); if (i >= loKey && i <= hiKey) { auto thisFreq = MidiMessage::getMidiNoteInHertz(i); auto rootFreq = MidiMessage::getMidiNoteInHertz(root); auto fName = s.getProperty(SampleIds::FileName).toString(); if (fName.isEmpty()) s.getChild(0).getProperty(SampleIds::FileName).toString(); PoolReference r(chain->getMainController(), fName, FileHandlerBase::Samples); Data data; data.sampleFile = r.getFile(); data.rootRatio = thisFreq / rootFreq; data.noteNumber = i; data.veloRange.setStart((int)s.getProperty(SampleIds::LoVel, 0)); data.veloRange.setEnd((int)s.getProperty(SampleIds::HiVel, 127) + 1); conversionData.insert(-1, data); } } progress = (double)i / 128.0; if (conversionData.isEmpty()) continue; struct DataSorter { int compareElements(Data& first, Data& second) { if (first.veloRange.getStart() < second.veloRange.getStart()) return -1; if (first.veloRange.getStart() > second.veloRange.getStart()) return 1; return 0; } }; DataSorter sorter; conversionData.sort(sorter); auto output = ResynthesisHelpers::loadAndResampleAudioFilesForVelocity(conversionData, sampleRate); storeData(i, output.getWritePointer(0), leftValueTree, output.getNumSamples(), conversionData.size()); if (output.getNumChannels() == 2) { storeData(i, output.getWritePointer(1), rightValueTree, output.getNumSamples(), conversionData.size()); } } }
-
@iamlamprey I think you might need to wait for some Christoph input
-
@d-healey all good, ill keep noodling in the meantime :) cheers
-
Edit
Okay I think a better way to do it is to iterate through the sampleMap ComboBox at the top of the window, since the conversion process already works on the combobox's currently selected item:
void bulkConvertSampleMapsToWavetables() { auto sampleComboBox = getComboBoxComponent("samplemap"); int loopLength = sampleComboBox->getNumItems(); for (int i = 0; i < loopLength; i++) { sampleComboBox->setSelectedItemIndex(i); if (currentMode == FFTResynthesis) converter->renderAllWavetablesFromHarmonicMaps(getProgressCounter()); else converter->renderAllWavetablesFromSingleWavetables(getProgressCounter()); if (threadShouldExit()) return; auto leftTree = converter->getValueTree(true); auto fileL = currentlyLoadedMap + ".hwt"; auto tfl = GET_PROJECT_HANDLER(chain).getSubDirectory(ProjectHandler::SubDirectories::AudioFiles).getChildFile(fileL); PresetHandler::writeValueTreeAsFile(leftTree, tfl.getFullPathName()); }
Here you can see it iterating through the combobox properly, but each consecutive wavetable is larger still...
Is there a JUCE method for control.changed() ? I can't seem to find it
Edit: okay added
sendNotification
and tried bothsetSelectedItemIndex
andsetSelectedId
and still get the same issue -
Hmm okay so I think the
renderAllWavetablesFromSingleWavetables
is going to keep "stacking" the files as long as the window is open, since manually clicking the confirmation dialog also closes the window...Also if I load one of these "stacked" wavetables and hit a note, HISE crashes
I just need the
renderAllWavetablesFromSingleWavetables
to reset in between loop iterations and everything should work, I just have no idea how to do that -
WOOOH okay so I can clear the ValueTree (and fix the size-stacking issue) by calling...
converter->getValueTree(true).removeAllChildren(nullptr);
...at the end of each Loop iteration. I also think I had to change the comboBox notification to async for it to update properly (it was re-exporting the same wavetable under different names).
sampleComboBox->setSelectedItemIndex(i, sendNotificationAsync);
For some other weird reason I had to delete the whole HISE build folder and recompile, VS kept saying it was Up-To-Date despite me changing lines of code.
Anyway here's the "finished" function:
void bulkConvertSampleMapsToWavetables() { auto sampleComboBox = getComboBoxComponent("samplemap"); int loopLength = sampleComboBox->getNumItems(); for (int i = 0; i < loopLength; i++) { sampleComboBox->setSelectedItemIndex(i, sendNotificationAsync); if (currentMode == FFTResynthesis) converter->renderAllWavetablesFromHarmonicMaps(getProgressCounter()); else converter->renderAllWavetablesFromSingleWavetables(getProgressCounter()); if (threadShouldExit()) return; auto tree = converter->getValueTree(true); auto file = sampleComboBox->getItemText(i) + ".hwt"; auto tf = GET_PROJECT_HANDLER(chain).getSubDirectory(ProjectHandler::SubDirectories::AudioFiles).getChildFile(file); PresetHandler::writeValueTreeAsFile(tree, tf.getFullPathName()); converter->getValueTree(true).removeAllChildren(nullptr); } }
There's still some clunkiness to it, mainly the bulkConvert button not being a switch/togglable thing. IDK how to do any of the github push stuff so this is about as far as I'm gonna take it
-
Anyway here's the "finished" function:
Well done!
I had to delete the whole HISE build folder and recompile, VS kept saying...
Sometimes intermediate files get left behind between builds. You can clean the solution folder from within VS too.
IDK how to do any of the github push stuff
Time to learn
-