Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to get expansion properties directly from info.hxi #699

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions hi_core/hi_core/ExpansionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,24 @@ juce::File ExpansionHandler::getExpansionTargetFolder(const File& resourceFile)
return File();
}

var ExpansionHandler::getPropertiesFromHxi(const File& hxiFile)
{
FileInputStream fis(hxiFile);
auto hxiData = ValueTree::readFromStream(fis);

auto hxiTree = hxiData.getChildWithName(ExpansionIds::ExpansionInfo);

auto obj = new DynamicObject();

for (int i = 0; i < hxiTree.getNumProperties(); ++i)
{
Identifier propertyName = hxiTree.getPropertyName(i);
obj->setProperty(propertyName, hxiTree.getProperty(propertyName).toString());
}

return obj;
}

PooledAudioFile ExpansionHandler::loadAudioFileReference(const PoolReference& sampleId)
{
AudioSampleBufferPool* pool = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions hi_core/hi_core/ExpansionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ class ExpansionHandler: public hlac::HlacArchiver::Listener,

void removeListener(Listener* l);

var getPropertiesFromHxi(const File& hxiFile);

bool installFromResourceFile(const File& f, const File& sampleDirectoryToUse);

File getExpansionTargetFolder(const File& resourceFile);
Expand Down
22 changes: 21 additions & 1 deletion hi_scripting/scripting/api/ScriptExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,8 @@ struct ScriptExpansionHandler::Wrapper
API_METHOD_WRAPPER_1(ScriptExpansionHandler, encodeWithCredentials);
API_METHOD_WRAPPER_0(ScriptExpansionHandler, refreshExpansions);
API_VOID_METHOD_WRAPPER_1(ScriptExpansionHandler, setAllowedExpansionTypes);
API_METHOD_WRAPPER_2(ScriptExpansionHandler, installExpansionFromPackage);
API_METHOD_WRAPPER_1(ScriptExpansionHandler, getPropertiesFromHxi);
API_METHOD_WRAPPER_2(ScriptExpansionHandler, installExpansionFromPackage);
API_METHOD_WRAPPER_1(ScriptExpansionHandler, getExpansionForInstallPackage);
};

Expand All @@ -980,6 +981,7 @@ ScriptExpansionHandler::ScriptExpansionHandler(JavascriptProcessor* jp_) :
ADD_API_METHOD_1(setInstallFullDynamics);
ADD_API_METHOD_1(encodeWithCredentials);
ADD_API_METHOD_0(refreshExpansions);
ADD_API_METHOD_1(getPropertiesFromHxi);
ADD_API_METHOD_2(installExpansionFromPackage);
ADD_API_METHOD_1(setAllowedExpansionTypes);
ADD_API_METHOD_0(getCurrentExpansion);
Expand Down Expand Up @@ -1136,6 +1138,24 @@ bool ScriptExpansionHandler::encodeWithCredentials(var hxiFile)
}
}

var ScriptExpansionHandler::getPropertiesFromHxi(var hxiFile)
{
if (auto f = dynamic_cast<ScriptingObjects::ScriptFile*>(hxiFile.getObject()))
{
if (!f->f.existsAsFile())
reportScriptError(f->toString(0) + " doesn't exist");

auto result = getMainController()->getExpansionHandler().getPropertiesFromHxi(f->f);

return var(result);
}
else
{
reportScriptError("argument is not a file");
return var();
}
}

bool ScriptExpansionHandler::installExpansionFromPackage(var packageFile, var sampleDirectory)
{
if (auto f = dynamic_cast<ScriptingObjects::ScriptFile*>(packageFile.getObject()))
Expand Down
3 changes: 3 additions & 0 deletions hi_scripting/scripting/api/ScriptExpansion.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ class ScriptExpansionHandler : public ConstScriptingObject,
/** Encrypts the given hxi file. */
bool encodeWithCredentials(var hxiFile);

/** Get the Expansion properties directly from an info.hxi file */
var getPropertiesFromHxi(var hxiFile);

/** Decompresses the samples and installs the .hxi / .hxp file. */
bool installExpansionFromPackage(var packageFile, var sampleDirectory);

Expand Down