Maki Reference
From ScWiki
Contents |
[edit] What is a MAKI script?
MAKI stands for Make A Killer Interface. It is the scripting language for modern Winamp skins. Scripting is used to produce the animations you see in the skin or to add some functionality. MAKI scripts are event based. In other word, your functions are used to define behaviors when an event occurs. If you don't define action for that event, the default behavior will be used and the default behavior is defined by Winamp. Scripts are used to override an existing behavior. For example, when you click on the PL button, the playlist container appears. You can override that functionality so that the Media Library also appears.
[edit] MAKI Syntax and example script
The syntax of MAKI scripts is based on C programming language. Here is an example script:
#include "C:/Scripting/std.mi"
Global Button MyButton; // This is a comment for button definition
System.onScriptLoaded()
{
string str = "YourButtonId";
MyButton = getObject(str);
}
MyButton.onLeftClick()
{
MessageBox("The button was pressed.", "Title of the message", 0, "");
}
The first line is to include standard definitions file. There are definitions of externally implemented classes and functions/events. The second line defines a global variable of the Button type (the Button type or class was defined in standard definitions file before). The next two blocks are the events with some action(s).
[edit] Events and functions
Technically, there are no differences beetween them. The events are really functions that called externally. The main difference is a way of calling. For example, there are external function (event) onEqBandChanged and the function ShowEqState. Both can be used like thisSystem.onEqBandChanged(int band, int newvalue)
{
dosomething(band,newvalue);
}
ShowEqState(int band, int newvalue)
{
dosomething(band,newvalue);
}But the event onEqBandChanged is defined as external and will be called by the platform while ShowEqState function is called internally in the script.
[edit] Basic variable types
- Boolean
- A 2-states boolean variable - 0 (FALSE) and 1 (TRUE), used for logic expressions.
- Int
- An integer number, can be positive or negative or 0.
- Double
- A real number with floating point.
- String
- Any text.
[edit] Classes
MAKI scripts support classes. They can be defined as internal:Class <Parent Class> <Derived class>;or as external:
extern class @{00000000-0000-0000-0000-000000000000}@ <Parent Class> <Derived class>;The {xxx} sequence is a link to external implementation.
Example of definition:
''Class Button NewButton;''
This would create a class called NewButton, with all the features of the Button class and a variable can then be assigned to this type in exactly the same way as they can with the predefined classes (Button is a predefined class here).
Usage example:
''NewButton Button1;''
A defined (derived) class takes all the attributes of its parent class. New attributes for the whole class can be added, in a simular was to defining the purpose of a single object. Say for example, the class NewButton needs to perform some action when releasing the Left Mouse Button.
''NewButton.onLeftButtonUp(int x, int y)''
''{''
:'' New features here''
''}''
[edit] Button
- extern Button.onActivate(int activated);
- extern Button.onLeftClick();
- extern Button.onRightClick();
- extern Button.setActivated(Boolean onoff);
- extern Button.setActivatedNoCallback(Boolean onoff);
- extern Boolean Button.getActivated();
- extern Button.leftClick();
- extern Button.rightClick();
[edit] Slider
- extern Slider.onSetPosition(int newpos);
- extern Slider.onPostedPosition(int newpos);
- extern Slider.onSetFinalPosition(int pos);
- extern Slider.setPosition(int pos);
- extern Int Slider.getPosition();
- extern Slider.lock();
- extern Slider.unlock();
[edit] Timer
- extern Timer.onTimer();
- extern Timer.setDelay(int millisec);
- extern Int Timer.getDelay();
- extern Timer.start();
- extern Timer.stop();
- extern Timer.isRunning();
- extern Int Timer.getSkipped();
[edit] List
[edit] Overview
This object is an array to store numbers or strings (there's no array for other variables - at version 5.56) You can store a value at the end of the array and take any of the items by its position. Position is a value from 0 to (number of items - 1) No changes are possible in the middle. You can only remove any item.
When using lists watch carefully for positions. Using incorrect positions will result in crushing.
Being a maki object with no xml representations, it requires to be created to be used:
List yourList = new List;
[edit] Functions
- List.addItem(string or int); //Adding an item to the end of the list
- List.removeItem(int pos); // Removing any item from the list by its index (position)
- string or int List.enumItem(int pos); //Getting the item from list by its position
- Int List.findItem(string or int value); // Getting the index of an item with the value
- Int List.findItem2(string or int value, int startItem); // Same as previous, but the search begins from "startItem" position.
// Previous two functions may not work (v 5.56)
- Int List.getNumItems(); //Getting total number of items in the list
- List.removeAll(); //Removing all items from the list (though the list - with no items - is left)
[edit] Example
SpectrumList.removeAll(); // Clearing List
for ( int i = 0; i < PrevValList.getNumItems(); i++ ) // Making a loop, based on Number of Items
{
BarValue = 0;
If (PrevValList.eNumItem(i) > BarValue) //Checking values in the List
BarValue = (PrevValList.eNumItem(i) * 4/5) //Getting values from the List
SpectrumList.addItem(BarValue); //Adding values to the list
}
[edit] BitList
[edit] Overview
This is an array for boolean values only. Unlike Lists the only information you can store is bits, but you can change any of them and add new ones. Its main parameters are size (number of bits to store) and position from 0 to (Size - 1). Bitlists allow the user to use the other indexes (positions), but they will always return "false" value.
Being a maki object with no xml representations, it requires to be created to be used:
BitList yourList = new BitList;
[edit] Functions
- boolean BitList.getItem(int n); //Getting item by position
- BitList.setItem(int n, boolean val); //Setting the item value (n - position, val - bit value)
- BitList.setSize(int s); //Setting BitList size (number of required bits)
- int BitList.getSize(); //Getting the size of the BitList
[edit] Example
BitList myBitList = new BitList; //Creating BitList
myBitList.setSize(2); //First for on/off, second for type(1-st or 2-nd)
// Setting bits according to i value
if (i == 0)
{
myBitList.setItem(0,true); //on
myBitList.setItem(1,false); //1-st type
}
if (i == 1)
{
myBitList.setItem(0,true); //on
myBitList.setItem(1,true); //2-nd type
}
if (i == 2)
myBitList.setItem(0,false); //off
if (myBitList.getItem(0) & !myBitList.getItem(1)) // check if 1-st bit is true (on) and 2-nd - false (1-st type)
{
// Process the 1-st type work
}
[edit] Equilizer
- extern System.onEqBandChanged(int band, int newvalue);
- extern System.onEqPreampChanged(int newvalue);
- extern System.onEqChanged(int newstatus);
- extern System.setEqBand(int band, Int value);
- extern System.setEqPreamp(Int value);
- extern System.setEq(int onoff);
- extern Int System.getEqBand(int band);
- extern int System.getEqPreamp();
- extern int System.getEq();
[edit] String
- extern String System.strmid(String str, Int start, Int len);
- extern String System.Strleft(string str, int nchars);
- extern string System.strright(string str, int nchars);
- extern int System.strsearch(string str, string substr);
- extern int System.strlen(string str);
- extern string System.strupper(string str);
- extern string System.strlower(string str);
- extern string System.getToken(string str, string separator, int tokennum);
[edit] Maths
- extern double System.sin(double value);
- extern double System.cos(double value);
- extern double System.tan(double value);
- extern double System.asin(double value);
- extern double System.acos(double value);
- extern double System.atan(double value);
- extern double System.atan2(double y, double x);
- extern double System.pow(double value, double pvalue);
- extern double System.sqr(double value);
- extern double System.sqrt(double value);
- extern int System.random(int max);
- extern double System.log10(double value);
- extern double System.ln(double value);
[edit] Saving
- extern System.setPrivateString(string section, string item, string value);
- extern System.setPrivateInt(string section, string item, int value);
- extern String System.getPrivateString(String section, String item, String defvalue);
- extern Int System.getPrivateInt(String section, String item, Int defvalue);
- extern System.setPublicString(String item, String value);
- extern System.setPublicInt(String item, Int value);
- extern String System.getPublicString(String item, String defvalue);
- extern Int System.getPublicInt(String item, Int defvalue);
[edit] Step-By-Step Tutorials
[edit] Scripts
to be continued...
