MCPcopy Create free account
hub / github.com/christophhart/HISE / parseSnippetsFromString

Method parseSnippetsFromString

hi_scripting/scripting/ScriptProcessor.cpp:2081–2117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2079}
2080
2081bool JavascriptProcessor::parseSnippetsFromString(const String &x, bool clearUndoHistory /*= false*/)
2082{
2083 String codeToCut = String(x);
2084
2085 for (int i = getNumSnippets(); i > 1; i--)
2086 {
2087 SnippetDocument *s = getSnippet(i-1);
2088
2089 const String filter = "function " + s->getCallbackName().toString() + "(";
2090
2091 if (!x.contains(filter))
2092 {
2093 if(MessageManager::getInstance()->isThisTheMessageThread())
2094 {
2095 PresetHandler::showMessageWindow("Invalid script", "The script you are trying to load is not a valid HISE script file.\nThe callback " + filter + " is not defined.", PresetHandler::IconType::Error);
2096 }
2097
2098 debugError(dynamic_cast<Processor*>(this), s->getCallbackName().toString() + " could not be parsed!");
2099
2100 return false;
2101 }
2102
2103 String code = codeToCut.fromLastOccurrenceOf(filter, true, false);
2104
2105 // If this is true, we're loading the preset and don't care about multithreading
2106 auto shouldBeAsync = !clearUndoHistory;
2107
2108 s->replaceContentAsync(code, shouldBeAsync);
2109
2110 codeToCut = codeToCut.upToLastOccurrenceOf(filter, false, false);
2111
2112 }
2113
2114 getSnippet(0)->replaceContentAsync(codeToCut);
2115
2116 return true;
2117}
2118
2119
2120

Callers 1

testScriptPitchFadeMethod · 0.80

Calls 11

getSnippetFunction · 0.85
getInstanceFunction · 0.85
replaceContentAsyncMethod · 0.80
getNumSnippetsFunction · 0.70
StringClass · 0.50
toStringMethod · 0.45
getCallbackNameMethod · 0.45
containsMethod · 0.45
fromLastOccurrenceOfMethod · 0.45
upToLastOccurrenceOfMethod · 0.45

Tested by 1

testScriptPitchFadeMethod · 0.64