Skip to content

Commit

Permalink
- add DSP network C++ code creation stage at plugin export
Browse files Browse the repository at this point in the history
- fix hardcoded FX modules being loaded without a valid DLL
  • Loading branch information
christoph-hart committed Jan 24, 2025
1 parent b83c841 commit 77f08ee
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 89 deletions.
11 changes: 3 additions & 8 deletions hi_backend/backend/CompileExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ CompileExporter::ErrorCodes CompileExporter::exportInternal(TargetTypes type, Bu

setProgress(0.3);

if (rawMode || (alreadyExported && data.getSetting(HiseSettings::Compiler::RebuildPoolFiles)))
if (rawMode || !alreadyExported || data.getSetting(HiseSettings::Compiler::RebuildPoolFiles))
{
iof.deleteFile();
sof.deleteFile();
Expand Down Expand Up @@ -694,11 +694,6 @@ CompileExporter::ErrorCodes CompileExporter::exportInternal(TargetTypes type, Bu
alreadyExported = true;
}

if (!alreadyExported)
{
handler.exportAllPoolsToTemporaryDirectory(chainToExport, nullptr);
}

setProgress(0.4);

File imageOutputFile, sampleOutputFile, samplemapFile, midiFile;
Expand Down Expand Up @@ -733,7 +728,7 @@ CompileExporter::ErrorCodes CompileExporter::exportInternal(TargetTypes type, Bu
else
return ErrorCodes::CorruptedPoolFiles;
}
else if (PresetHandler::showYesNoWindow("Copy Audio files to app data directory?",
else if (manager != nullptr || PresetHandler::showYesNoWindow("Copy Audio files to app data directory?",
"Do you want to copy the audio pool file to your project's app data directory?"))
{
sampleOutputFile = projectFolder.getChildFile(sof.getFileName());
Expand All @@ -749,7 +744,7 @@ CompileExporter::ErrorCodes CompileExporter::exportInternal(TargetTypes type, Bu
else
return ErrorCodes::CorruptedPoolFiles;
}
else if (PresetHandler::showYesNoWindow("Copy Image files to app data directory?",
else if (manager != nullptr || PresetHandler::showYesNoWindow("Copy Image files to app data directory?",
"Do you want to copy the image pool file to your project's app data directory?"))
{
imageOutputFile = projectFolder.getChildFile(iof.getFileName());
Expand Down
2 changes: 1 addition & 1 deletion hi_backend/backend/ProjectDllTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const unsigned char projectDllTemplate_jucer_lines[] =
" alwaysGenerateDebugSymbols = \"0\" optimisation = \"2\"\r\n"
" linkTimeOptimisation = \"0\" useRuntimeLibDLL=\"0\"/>\r\n"
" <CONFIGURATION isDebug=\"0\" name=\"Release\" targetName=\"%RELEASE_DLL_NAME%\" headerPath =\"%FAUST_HEADER_PATH%\" binaryPath=\"dll\"\r\n"
" alwaysGenerateDebugSymbols=\"1\" useRuntimeLibDLL=\"0\"/>\r\n"
" alwaysGenerateDebugSymbols=\"1\" linkTimeOptimisation = \"0\" useRuntimeLibDLL=\"0\"/>\r\n"

" </CONFIGURATIONS>\r\n"
" <MODULEPATHS>\r\n"
Expand Down
29 changes: 27 additions & 2 deletions hi_backend/backend/dialog_library/dialog_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct ScriptReplaceHelpers
struct SaveData
{
Array<float> parameters;
Array<Identifier> parameterIds;
String id;
String effect;
bool bypassed;
Expand All @@ -117,7 +118,10 @@ struct ScriptReplaceHelpers
bypassed = p->isBypassed();

for(int i = 0; i < p->getNumParameters(); i++)
{
parameters.add(p->getAttribute(i));
parameterIds.add(p->getIdentifierForParameterIndex(i));
}

if(auto rp = dynamic_cast<RoutableProcessor*>(p))
routing = rp->getMatrix().exportAsValueTree();
Expand Down Expand Up @@ -154,10 +158,13 @@ struct ScriptReplaceHelpers
rp->getMatrix().restoreFromValueTree(routing);

if(auto s = dynamic_cast<HardcodedSwappableEffect*>(p))
{
s->setEffect(effect, false);
s->preallocateUnloadedParameters(parameterIds);
}

for(int i = 0; i < parameters.size(); i++)
p->setAttribute(i, parameters[i], sendNotificationAsync);
p->setAttribute(i, parameters[i], dontSendNotification);

if(auto eh = dynamic_cast<ExternalDataHolder*>(p))
{
Expand Down Expand Up @@ -1080,9 +1087,18 @@ CompileProjectDialog::CompileProjectDialog(BackendRootWindow* bpe_):

dialog->setFinishCallback([this]()
{
//dynamic_cast<DspNetworkCompileExporter*>(compileExporter.get())->threadFinished();
dllCompiler = nullptr;
findParentComponentOfClass<ModalBaseWindow>()->clearModalComponent();
});

auto dllManager = bpe->getBackendProcessor()->dllManager;

if(!dllManager->isDllLoaded() && dllManager->hasFilesToCompile())
{
dllCompiler = new DspNetworkCompileExporter(bpe, bpe->getBackendProcessor(), true);
dllCompiler->setAdditionalLogFunction(BIND_MEMBER_FUNCTION_1(NetworkCompiler::logMessage));
dynamic_cast<DspNetworkCompileExporter*>(dllCompiler.get())->managerToUse = this;
}
}

CompileProjectDialog::~CompileProjectDialog()
Expand Down Expand Up @@ -1200,6 +1216,13 @@ var CompileProjectDialog::onInit(const var::NativeFunctionArgs& args)

var CompileProjectDialog::compileTask(const var::NativeFunctionArgs& args)
{



if(dllCompiler != nullptr)
dllCompiler->run();


CompileExporter ep(bpe->getBackendProcessor()->getMainSynthChain());

auto modulesToReplace = ScriptReplaceHelpers::getListOfAllConvertableScriptModules(bpe->getBackendProcessor());
Expand All @@ -1220,6 +1243,8 @@ var CompileProjectDialog::compileTask(const var::NativeFunctionArgs& args)

auto flags = getBuildFlag();

ChildProcessManager::ScopedLogger sl(*this);

if(IS_FLAG(isStandalone))
ok = ep.exportMainSynthChainAsStandaloneApp((CompileExporter::BuildOption)flags);
if(IS_FLAG(isInstrument))
Expand Down
28 changes: 27 additions & 1 deletion hi_backend/backend/dialog_library/dialog_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ class ChildProcessManager: public AsyncUpdater
{
public:

struct ScopedLogger: public juce::Logger
{
ScopedLogger(ChildProcessManager& cm_):
cm(cm_),
prevLogger(Logger::getCurrentLogger())
{
Logger::setCurrentLogger(this);
}

~ScopedLogger()
{
Logger::setCurrentLogger(prevLogger);
}

Logger* prevLogger;

void logMessage(const String& message) override
{
cm.logMessage(message);
}

ChildProcessManager& cm;
};

ChildProcessManager()
{
log.setDisableUndo(true);
Expand Down Expand Up @@ -469,7 +493,9 @@ struct CompileProjectDialog: public EncodedDialogBase,

setElementProperty("OutputFile", mpid::Text, content);
}


ScopedPointer<DialogWindowWithBackgroundThread> dllCompiler;

var onInit(const var::NativeFunctionArgs& args);
var compileTask(const var::NativeFunctionArgs& args);
var onExportType(const var::NativeFunctionArgs& args);
Expand Down
41 changes: 24 additions & 17 deletions hi_backend/snex_workbench/WorkbenchProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,34 @@ struct IncludeSorter
};
};

DspNetworkCompileExporter::DspNetworkCompileExporter(Component* e, BackendProcessor* bp) :
DspNetworkCompileExporter::DspNetworkCompileExporter(Component* e, BackendProcessor* bp, bool skipCompilation_) :
DialogWindowWithBackgroundThread("Compile DSP networks"),
ControlledObject(bp),
CompileExporter(bp->getMainSynthChain()),
editor(e)
editor(e),
skipCompilation(skipCompilation_)
{
addComboBox("build", { "Debug", "CI", "Release" }, "Build Configuration");

#if !JUCE_DEBUG
getComboBoxComponent("build")->setText("Release", dontSendNotification);
#endif
if (getNetwork() == nullptr)

if(!skipCompilation)
{
raw::Builder builder(bp);
MainController::ScopedBadBabysitter sb(bp);
if (getNetwork() == nullptr)
{
raw::Builder builder(bp);
MainController::ScopedBadBabysitter sb(bp);

auto jmp = builder.create<JavascriptMasterEffect>(bp->getMainSynthChain(), raw::IDs::Chains::FX);
jmp->getOrCreate("internal_dsp");
auto jmp = builder.create<JavascriptMasterEffect>(bp->getMainSynthChain(), raw::IDs::Chains::FX);
jmp->getOrCreate("internal_dsp");
}
}

if (auto n = getNetwork())
n->createAllNodesOnce();

auto customProperties = bp->dllManager->getSubFolder(getMainController(), BackendDllManager::FolderSubType::ThirdParty).getChildFile("node_properties.json");

if (customProperties.existsAsFile())
Expand Down Expand Up @@ -283,10 +287,10 @@ void DspNetworkCompileExporter::run()
{
auto n = getNetwork();

if(managerToUse != nullptr)
if(managerToUse != nullptr && !skipCompilation)
managerToUse->setProgress(0.25);

if (n == nullptr)
if (n == nullptr && !skipCompilation)
{
ok = (ErrorCodes)(int)DspNetworkErrorCodes::NoNetwork;
errorMessage << "You need at least one active network for the export process. \n";
Expand Down Expand Up @@ -684,17 +688,20 @@ void DspNetworkCompileExporter::run()

configurationName = getComboBoxComponent("build")->getText();

if(managerToUse != nullptr)
managerToUse->setProgress(0.5);
if(!skipCompilation)
{
if(managerToUse != nullptr)
managerToUse->setProgress(0.5);

#if JUCE_LINUX
ok = ErrorCodes::OK;
ok = ErrorCodes::OK;
#else
ok = compileSolution(o, CompileExporter::TargetTypes::numTargetTypes, managerToUse);
ok = compileSolution(o, CompileExporter::TargetTypes::numTargetTypes, managerToUse);
#endif

if(managerToUse != nullptr)
managerToUse->setProgress(1.0);
if(managerToUse != nullptr)
managerToUse->setProgress(1.0);
}
}

void DspNetworkCompileExporter::threadFinished()
Expand Down
4 changes: 3 additions & 1 deletion hi_backend/snex_workbench/WorkbenchProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class DspNetworkCompileExporter : public hise::DialogWindowWithBackgroundThread,
UninitialisedProperties
};

DspNetworkCompileExporter(Component* editor, BackendProcessor* bp);
DspNetworkCompileExporter(Component* editor, BackendProcessor* bp, bool skipCompilation_=false);

void run() override;

Expand All @@ -122,6 +122,8 @@ class DspNetworkCompileExporter : public hise::DialogWindowWithBackgroundThread,
StringArray nodesToCompile;
StringArray cppFilesToCompile;

bool skipCompilation = false;

private:

enum CppFileLocationType
Expand Down
2 changes: 1 addition & 1 deletion hi_core/hi_core/MainController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ void MainController::prepareToPlay(double sampleRate_, int samplesPerBlock)
if (logger == nullptr)
{
logger = new ConsoleLogger(getMainSynthChain());
Logger::setCurrentLogger(logger);
//Logger::setCurrentLogger(logger);
}

#endif
Expand Down
6 changes: 3 additions & 3 deletions hi_core/hi_core/PresetHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3103,8 +3103,8 @@ void FileHandlerBase::exportAllPoolsToTemporaryDirectory(ModulatorSynthChain* ch

ScopedPointer<Logger> outputLogger = new ConsoleLogger(chain);

if(!CompileExporter::isExportingFromCommandLine())
Logger::setCurrentLogger(outputLogger);
//if(!CompileExporter::isExportingFromCommandLine())
//Logger::setCurrentLogger(outputLogger);

auto* progress = logData != nullptr ? &logData->progress : nullptr;

Expand Down Expand Up @@ -3137,7 +3137,7 @@ void FileHandlerBase::exportAllPoolsToTemporaryDirectory(ModulatorSynthChain* ch
if (logData != nullptr) logData->logFunction("Export MIDI files");
chain->getMainController()->getCurrentMidiFilePool()->getDataProvider()->writePool(new FileOutputStream(midiOutputFile), progress);

Logger::setCurrentLogger(previousLogger);
//Logger::setCurrentLogger(previousLogger);

outputLogger = nullptr;
#else
Expand Down
Loading

0 comments on commit 77f08ee

Please sign in to comment.