Skip to content

Commit

Permalink
- added Settings API class
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Apr 11, 2021
1 parent 30a8140 commit c61759f
Show file tree
Hide file tree
Showing 6 changed files with 2,519 additions and 2,410 deletions.
1 change: 1 addition & 0 deletions hi_scripting/scripting/ScriptProcessorModules.cpp
Expand Up @@ -186,6 +186,7 @@ void JavascriptMidiProcessor::registerApiClasses()
scriptEngine->registerNativeObject("Content", getScriptingContent());
scriptEngine->registerApiClass(currentMidiMessage);
scriptEngine->registerApiClass(engineObject);
scriptEngine->registerApiClass(new ScriptingApi::Settings(this));

This comment has been minimized.

Copy link
@christoph-hart

christoph-hart Apr 11, 2021

Author Collaborator

Add the api class here. This makes it available in all script MIDI processors. If you want it to be available on the other module types, add it there too.

scriptEngine->registerApiClass(new ScriptingApi::FileSystem(this));
scriptEngine->registerApiClass(serverObject = new ScriptingApi::Server(this));
scriptEngine->registerApiClass(new ScriptingApi::Console(this));
Expand Down
56 changes: 56 additions & 0 deletions hi_scripting/scripting/api/ScriptingApi.cpp
Expand Up @@ -1271,13 +1271,15 @@ String ScriptingApi::Engine::getPreloadMessage()

var ScriptingApi::Engine::getZoomLevel() const
{
logSettingWarning("getZoomLevel");

This comment has been minimized.

Copy link
@christoph-hart

christoph-hart Apr 11, 2021

Author Collaborator

This will make the transition more clear and nudge the people into the new class...

auto gm = dynamic_cast<const GlobalSettingManager*>(getScriptProcessor()->getMainController_());

return gm->getGlobalScaleFactor();
}

void ScriptingApi::Engine::setZoomLevel(double newLevel)
{
logSettingWarning("setZoomLevel");
newLevel = jlimit(0.25, 2.0, newLevel);

auto gm = dynamic_cast<GlobalSettingManager*>(getScriptProcessor()->getMainController_());
Expand All @@ -1286,6 +1288,8 @@ void ScriptingApi::Engine::setZoomLevel(double newLevel)

void ScriptingApi::Engine::setDiskMode(int mode)
{
logSettingWarning("setDiskMode");

auto mc = dynamic_cast<MainController*>(getScriptProcessor()->getMainController_());

AudioProcessorDriver* driver = dynamic_cast<AudioProcessorDriver*>(mc);
Expand Down Expand Up @@ -1608,6 +1612,45 @@ void ScriptingApi::Engine::saveUserPreset(var presetName)
}
}

struct ScriptingApi::Settings::Wrapper
{
API_METHOD_WRAPPER_0(Settings, getZoomLevel);
API_VOID_METHOD_WRAPPER_1(Settings, setZoomLevel);
API_VOID_METHOD_WRAPPER_1(Settings, setDiskMode);
};

ScriptingApi::Settings::Settings(ProcessorWithScriptingContent* s) :
ScriptingObject(s),
ApiClass(0)

This comment has been minimized.

Copy link
@christoph-hart

christoph-hart Apr 11, 2021

Author Collaborator

0 is the number of constants that you can add with addConstant. I can't think of a constant for this class though...

{
// Gonna save you some typing...
mc = dynamic_cast<MainController*>(getScriptProcessor()->getMainController_());
gm = dynamic_cast<GlobalSettingManager*>(mc);
driver = dynamic_cast<AudioProcessorDriver*>(mc);

ADD_API_METHOD_0(getZoomLevel);
ADD_API_METHOD_1(setZoomLevel);
ADD_API_METHOD_1(setDiskMode);
}


double ScriptingApi::Settings::getZoomLevel() const
{
return gm->getGlobalScaleFactor();
}

void ScriptingApi::Settings::setZoomLevel(double newLevel)
{
newLevel = jlimit(0.25, 2.0, newLevel);
gm->setGlobalScaleFactor(newLevel, sendNotificationAsync);
}

void ScriptingApi::Settings::setDiskMode(int mode)
{
driver->diskMode = mode;
mc->getSampleManager().setDiskMode((MainController::SampleManager::DiskMode)mode);
}

struct DynamicArrayComparator
{
DynamicArrayComparator(HiseJavascriptEngine* engine_, var sortFunction_, var arrayToSort_):
Expand Down Expand Up @@ -2049,6 +2092,17 @@ String ScriptingApi::Engine::getSystemTime(bool includeDividerCharacters)
return Time::getCurrentTime().toISO8601(includeDividerCharacters);
};

void ScriptingApi::Engine::logSettingWarning(const String& methodName) const
{
auto p = dynamic_cast<const Processor*>(getScriptProcessor());

auto unconst = const_cast<Processor*>(p);

String s;
s << "Engine." << methodName << "() is deprecated. Use Settings." << methodName << "() instead.";
debugToConsole(unconst, s);
}

// ====================================================================================================== Sampler functions

struct ScriptingApi::Sampler::Wrapper
Expand Down Expand Up @@ -4871,4 +4925,6 @@ void ScriptingApi::Server::setServerCallback(var callback)





} // namespace hise
35 changes: 35 additions & 0 deletions hi_scripting/scripting/api/ScriptingApi.h
Expand Up @@ -494,13 +494,48 @@ class ScriptingApi

// ============================================================================================================

/** This warning will show up in the console so people can migrate in the next years... */
void logSettingWarning(const String& methodName) const;

struct Wrapper;

ScriptBaseMidiProcessor* parentMidiProcessor;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Engine);
};

/** This class takes over a few of the Engine methods in order to break down this gigantomanic object. */
class Settings : public ApiClass,

This comment has been minimized.

Copy link
@christoph-hart

christoph-hart Apr 11, 2021

Author Collaborator

The class must be derived by ApiClass and ScriptingObject

public ScriptingObject
{
public:

Settings(ProcessorWithScriptingContent* s);;

Identifier getObjectName() const override { RETURN_STATIC_IDENTIFIER("Settings"); }

// ================================================================================================== API Calls

/** Returns the UI Zoom factor. */
double getZoomLevel() const;

/** Changes the UI zoom (1.0 = 100%). */
void setZoomLevel(double newLevel);

/** Sets the Streaming Mode (0 -> Fast-SSD, 1 -> Slow-HDD) */
void setDiskMode(int mode);

// ============================================================================================================

private:

GlobalSettingManager* gm;
AudioProcessorDriver* driver;
MainController* mc;

struct Wrapper;

This comment has been minimized.

Copy link
@christoph-hart

christoph-hart Apr 11, 2021

Author Collaborator

This opaque internal class will hold the glue code (defined in the .cpp file)

};

/** All scripting functions for sampler specific functionality. */
class Sampler : public ConstScriptingObject
{
Expand Down

0 comments on commit c61759f

Please sign in to comment.