This is a page from the Morphyre Pro Online Manual. You can return to the Contents Page, or go to the Morphyre Pro Homepage.
Morphyre uses a cut-down Javascript interpreter called TinyJS to control which scenes are shown and how.
Some functions have been defined to allow the JavaScript to interface with Morphyre:
function getScenes()
function getSceneInfo(sceneNum, keyName) given a scene number finds the value of that scene's key
function getScene(sceneNum) given a scene number returns an object containing info about that scene
function findSceneId(sceneId) finds a scene with the given id
function getRandomScene(type, theme) get a random scene of the given type ("scene", "fade", etc) that contains one or more of a csv list in theme in <Styles>
function reloadVisible() reload any scenes currently in the renderScene list
function reloadXML(filename) reload the given XML file
function addArchive(filename) Add a morpharch file to the filesystem and add any scenes that are in it
function removeArchive(filename) Remove a morpharch file from the filesystem (and all scenes that are in it)
function loadScenes(xml) add scenes, given the XML for them as a string
function removeScene(sceneId) remove a scene, given its id
function renderSceneInitialise(id) queue the given scene to be initialised
function renderScenesInitialised() are all render scenes that were asked for initialised?
function renderSceneInsert(id, pos) insert *before* the position, -1 puts at the end
function renderSceneRemove(id)
function renderSceneRemoveAll()
function renderScenes()
function renderSceneAt(idx)
function renderSceneFind(id)
function renderSceneSet(idx, key, value)
function renderSceneGet(idx, key)
function print(text)
function printOSD(text)
function screenshot()
function exit()
function disconnect() if running from the network, make sure we disconnect after sending the contents of our buffers
function compareVersion(a,b) compare versions a and b, -1 if a<b, 1 if a>b 0 if a==b
function setTweak(num,val) Set one of morphyre's floating point tweak values. See scene interface.h
function getTweak(num) Get one of morphyre's floating point tweak values. See scene interface.h
function restartUpdater() Restart Morphyre's updater again
function getMonitorPosition(monitor) Return a rect with the monitor's position (monitor is an int starting from 0. -1 for the entire screen - or return undefined
function setWindowPosition(x,y,width,height,border) Set the window to a certain position, border=0,1 for whether window has a border
function getVideoDevices() returns an array of Video devices. Each element guaranteed to have a .filename field (if pro)
function Thread.sleep(millis) wait for the given number of milliseconds
function crc(str, seed) return the CRC of the given string, using the supplied seed (normal seed is 0)
function loadSettings() Load the settings file
function saveSettings() Save the settings file
function fileLoad(filename) Load the given file into a string and return it, or return 'undefined'. Only works on Morphyre dir
function setSoundBPM(bpm) If using 'fake' sound input, set the Beats per Minute to the value given.
On startup, the javascript file settings.js is loaded, followed by data/utils.js, then all the javascript files beginning with a number in the data directory are loaded in numerical order. These contain several useful functions, and there is some documentation in the files.
In addition, there are a few standard JavaScript methods:
Morphyre Pro also contains a web server. By default this is at port 8888. It accepts HTTP requests, but can also act as a simple telnet server (executing JavaScript) if the first command sent isn't GET. The Morphyre UI uses the telnet mode, however there is also a simple AJAX web interface (http://localhost:8888) which is served out of the webroot folder.
Any JavaScript errors are reported to the console, which is available either via Menu->Console in the Morphyre UI, when you run Morphyre without the UI, or saved to log.txt when LOG is set to 1 in settings.js.
Text (html/jsp/js) that is served out of the webroot folder is scanned for jsp-style tags, and as the page is sent from Morphyre the javascript in these tags is executed in Morphyre itself. If the tags contain an equals, the result is output along with the rest of the file. Hence both of the following work:
One plus two is <%= 1+2 %>
<% myvariable = 1+2; %> One plus two is <%= myvariable %>
The file common.js contains some useful utility functions (including sendCommand, which sends a command to Morphyre via AJAX). For instance if you wish to change scene when a file is loaded from the website, you can insert the following:
<% changeScene(getNewScene(), getNewFade()); %>
Or, you can send the command from javascript:
<script>
function tellMorphyre() {
sendCommand("changeScene(getNewScene(), getNewFade())");
}
</script>
<img src="myimage.png" onclick="tellMorphyre()"/>
Among the useful commands available is loadScenes, which can be given XML from one of the scene's XML files (including the SceneList tag) - note that as it takes a string, this string must be properly escaped. Note that the scene IDs must not clash with scene IDs that are already loaded or the given scene will not be loaded. Once the scene is loaded it will not be automatically freed, so you must call removeScene(sceneId) after you're done with it.
for example:
loadScenes("<SceneList><Scene id=\"bigfoot_templ_flat_image1390812797\"><Filename>bin/bigfoot.pur3s</Filename><Data><Type>scene</Type><SceneId>bigfoot</SceneId><SchemeId>templ_flat_image1390812797</SchemeId><BgColour>0xFFFFFFFF</BgColour><BgTexture>juliapink.png</BgTexture><BgType>BG_FLAT</BgType><FgTexture></FgTexture><FgType>FG_ENVMAP_BG_SOLID</FgType><MaskColour>0xFF000000</MaskColour><MidTexture></MidTexture><MidType>MD_WARP</MidType><Styles></Styles><Weight>0</Weight></Data></Scene></SceneList>");
changeScene("bigfoot_templ_flat_image1390812797",getRandomScene("fade",""));