class LoadSound : public ThreadWithProgressWindow
{
public:
LoadSound(EightAudioProcessor &processor) : ThreadWithProgressWindow("Loading...", true, false) {}
void run(EightAudioProcessor &processor)
{
processor.clearSamplerSounds();
}
};
void EightAudioProcessorEditor::loadFile()
{
LoadSound loadSoundThread(processor);
if (loadSoundThread.runThread())
{
// thread finished normally..
}
else
{
// user pressed the cancel button..
}
}
Found out that I can pass the editor
to the Thread Constructor:
class LoadSound : public ThreadWithProgressWindow
{
public:
EightAudioProcessorEditor& edi;
LoadSound(EightAudioProcessorEditor& editor) : ThreadWithProgressWindow("Loading...", true, false)
{
editor.processor.clearSamplerSounds();
edi = editor;
}
...
void EightAudioProcessorEditor::loadFile()
{
LoadSound loadSoundThread(*this);
if (loadSoundThread.runThread())
{
// thread finished normally..
}
else
{
// user pressed the cancel button..
}
}
But I cannot assign it to a public Variable inside the Thread Class.
Could fix it with:
class LoadSound : public ThreadWithProgressWindow
{
public:
EightAudioProcessorEditor* editor;
LoadSound(EightAudioProcessorEditor* editorInstance) : ThreadWithProgressWindow("Loading...", true, false)
{
editor = editorInstance;
}
void run()
{
editor->processor.clearSamplerSounds();
...
void EightAudioProcessorEditor::loadFile()
{
LoadSound loadSoundThread(this);
if (loadSoundThread.runThread())
{
// thread finished normally..
}
else
{
// user pressed the cancel button..
}
}
I know that’s a terrible way. Even with this hacky “Solution” the UI doesn’t update.
Edit
The Calculation of the Percentage Value was not correct. Instead of:
setProgress((1 / (6 * 127)) * percentageIdx);
I need to use:
setProgress((1. / (6 * 127)) * percentageIdx); // <<< Force to be `double`