|

Overview

vj_plugin is a visualizer plugin module spec that is used in LiveBeats performance application.

This visualizer plugin will be loaded to LiveBeats with file-drop, and automatically new visual effect plane is added.

plugin file is a .js file and the filename should start with 'vj_'. In this file, the function should be defined that has same name as filename (except extension).
For example, if the plugin name is "test", filename is "vj_test.js" and the function "vj_test()" should be defined.

LiveBeats is here : LiveBeats

Sample code


//-- vj_simplewave.js --
vj_simplewave=function(param) {
	this.w=param.w;
	this.h=param.h;
	this.n=param.n;
	this.wavedat=param.wavedat;
	this.freqdat=param.freqdat;
	this.elem=document.createElement("canvas");
	this.elem.width=this.w;
	this.elem.height=this.h;
	this.ctx=this.elem.getContext("2d");
	this.ctx.lineJoin="round";
	this.anim=function(timestamp) {
		this.ctx.strokeStyle=this.param.col.value;
		this.ctx.lineWidth=this.param.line.value;
		this.ctx.clearRect(0,0,this.w,this.h);
		this.ctx.beginPath();
		this.ctx.moveTo(0,this.h/2-(this.wavedat[0]-128)*this.h/512);
		for(var i=1;i<this.n;i+=2) {
			var x=this.w*i/this.n;
			var y=this.h/2-(this.wavedat[i]-128)*this.h/512;
			this.ctx.lineTo(x,y);
		}
		this.ctx.stroke();
	};
	this.param={
	"line":{"value":3,"type":"double","min":1,"max":10},
	"col":{"value":"#f00","type":"string"},
	};
}

Plugin Behavior:

Host app pass a object to fuction that include environment. The invokation will be following:


	new vj_simplewave({"w":1024,"h":768,"wavedat":wavdat,"freqdat":freqdat})

Arguments are:
"w"Horizontal resolution. Plugin should make DOM-element with this resolution.
"h"Vertical resolution. Plugin should make DOM-element width this resolution.
"wavedat"Uint8Array of wave-data. The value 128 indicate center, and the range is 0-255. This is match to Web Audio API AnalyserNode's getByteTimeDomationData().
"freqdat"Uint8Array of spectrum data. The value is appropreately scaled to the range 0-255. This is match to Web Audio data AnalyserNode's getByteFrequencyData().

Function properties

this.elem Drawing DOM-element, e.g. canvas. Plugin should newly make element that has the size "w"/"h" and store to "this.elem". Host app will appropriately place this element to view area.
this.anim Animation function. Host app will invoke this function periodically with current-time argument. Because this invocation is not so accurate time managed, plugin should manage the animation speed if needed. This invocation is assumed with requestAnimationFrame().
this.param The list of controllable parameters. Host app will change these parameters for dynamic visual effects. For example, LiveBeats can do parameter change by command input. Each param has sub-properties. "type" is a parameter type that means "double" for contiguous value, "int" for integer value and "string" for string. "value" is a initial value, "min" is typical minimum value and "max" is typical max value. Additionally even these properties are plugin specific, host app may add more properties that can make effect by CSS. For example LiveBeats adds "a":alpha, "w":width, "h":height, "x":x-pos, "y":y-pos, "z":zoom factor, "blur":blur effect and "rot":rotation.

概要

vj_pluginLiveBeatsパフォーマンスアプリで使用される、ビジュアライザープラグインです。

このビジュアライザープラグインはLiveBeatsにドロップする事で読み込まれ、新しい映像効果を付加する事ができるようになります。 ファイル名は"vj_"で始まります。内容はJavascriptのファイルで拡張子は".js"です。 ファイル内ではプラグイン名を付けた関数定義を行います。 例えばプラグイン名を"test"とした場合、ファイル名は"vj_test.js"となり、そのファイル内で関数"vj_test()"を定義します。

LiveBeatsはこちらを参照してください。LiveBeats

サンプルコード


//-- vj_simplewave.js --
vj_simplewave=function(param) {
	this.w=param.w;
	this.h=param.h;
	this.n=param.n;
	this.wavedat=param.wavedat;
	this.freqdat=param.freqdat;
	this.elem=document.createElement("canvas");
	this.elem.width=this.w;
	this.elem.height=this.h;
	this.ctx=this.elem.getContext("2d");
	this.ctx.lineJoin="round";
	this.anim=function(timestamp) {
		this.ctx.strokeStyle=this.param.col.value;
		this.ctx.lineWidth=this.param.line.value;
		this.ctx.clearRect(0,0,this.w,this.h);
		this.ctx.beginPath();
		this.ctx.moveTo(0,this.h/2-(this.wavedat[0]-128)*this.h/512);
		for(var i=1;i<this.n;i+=2) {
			var x=this.w*i/this.n;
			var y=this.h/2-(this.wavedat[i]-128)*this.h/512;
			this.ctx.lineTo(x,y);
		}
		this.ctx.stroke();
	};
	this.param={
	"line":{"value":3,"type":"double","min":1,"max":10},
	"col":{"value":"#f00","type":"string"},
	};
}

プラグインの動作

関数の引数として動作環境に関する幾つかのパラメータをまとめたオブジェクトが渡されます。ホストアプリは以下のような形でプラグインの呼び出しを行います。


	new vj_simplewave({"w":1024,"h":768,"wavedat":wavdat,"freqdat":freqdat})

引数の内容は以下の通りです。
"w"横方向の解像度。プラグインはこの解像度のDOMエレメントを作成します。
"h"縦方向の解像度。プラグインはこの解像度のDOMエレメントを作成します。
"wavedat"波形データが入ったUint8Array配列。波形は128を中心として0-255の範囲の値で格納される。これはWeb Audio APIのAnalyserNodeのgetByteTimeDomainData()で取得できる形式に一致します。
"freqdat"スペクトラムデータが入ったUint8Array配列。スペクトラムデータは適宜スケーリングされ、0-255の範囲の値で格納される。これはWeb Audio APIのAnalyserNodeのgetByteFrequencyData()で取得できる形式に一致します。

プラグインで定義する必要があるもの

this.elem描画の対象とするDOMエレメントです。プラグインは初期化時に"w","h"で指定された大きさのCanvas等のエレメントを作成し、this.elemに格納します。ホストアプリはこのエレメントを適宜表示領域に貼り付けます。
this.anim描画関数です。ホストアプリは現在時刻を引数として、この関数を定期的に呼び出します。ただし、呼び出しのタイミングはついては正確な時間管理はされていませんので、一定の速度でアニメーションを行う場合などは引数の現在時刻をもとにプラグイン側で制御します。この呼び出しは、requestAnimationFrame()によるものを想定しています。
this.param操作可能なパラメータのリストです。ホストアプリでの何らかの操作により、これらのパラメータを変化させる事ができます(LiveBeatsでは、コマンドの入力で設定します)。"type"はパラメータの型で連続変化が可能な"double"、整数値の"int"、文字列の"string"のいずれかになり、初期値を"value"、典型的な最小値を"min"、最大値を"max"とします。なお、ここにリストされているものはプラグインに固有のパラメータですが、ホストアプリ側でDOMエレメントに対してCSSレベルで操作可能なパラメータを全てのプラグインに共通のパラメータとして追加するかも知れません。LiveBeatsでは、"a":アルファ、"w":幅、"h":高さ、"x":x位置、"y":y位置、"z":ズーム、"blur":ブラー効果、"rot":回転を共通パラメータとして追加します。