+
+function mosaic_code_update()
+{
+
+ var code = document.getElementById( 'mosaic_code' );
+ code.value =
+"##################################\n"+
+"## HTTP interface mosaic wizard ##\n"+
+"##################################\n"+
+"\n"+
+"# Comment the following line if you don't want to reset your VLM configuration\n"+
+"del all\n"+
+"\n"+
+"# Background options\n"+
+"new bg broadcast enabled\n"+
+"setup bg input " + sanitize_input( value( 'mosaic_bg_input' ) ) + "\n";
+ if( value( 'mosaic_output' ) )
+ {
+ code.value +=
+"setup bg output " + value( 'mosaic_output' )+ "\n";
+ }
+ var o = /.*transcode.*/;
+ if(! o.test( value( 'mosaic_output' ) ) )
+ {
+ code.value +=
+"setup bg option sub-filter=mosaic\n"+
+"setup bg output #bridge-in{offset=100}:display\n";
+ }
+ code.value+=
+"\n"+
+"# Mosaic options\n"+
+"setup bg option mosaic-alpha=" + mosaic_alpha + "\n"+
+"setup bg option mosaic-height=" + mosaic_height + "\n"+
+"setup bg option mosaic-width=" + mosaic_width + "\n"+
+"setup bg option mosaic-align=" + mosaic_align + "\n"+
+"setup bg option mosaic-xoffset=" + mosaic_xoffset + "\n"+
+"setup bg option mosaic-yoffset=" + mosaic_yoffset + "\n"+
+"setup bg option mosaic-vborder=" + mosaic_vborder + "\n"+
+"setup bg option mosaic-hborder=" + mosaic_hborder + "\n"+
+"setup bg option mosaic-position=" + mosaic_position + "\n"+
+"setup bg option mosaic-rows=" + mosaic_rows + "\n"+
+"setup bg option mosaic-cols=" + mosaic_cols + "\n"+
+"setup bg option mosaic-order=";
+ for( y = 0; y < mosaic_rows; y++ )
+ {
+ for( x = 0; x < mosaic_cols; x++ )
+ {
+ var id = x+'_'+y;
+ if( cells[id] )
+ code.value += cells[id];
+ else
+ code.value += '_';
+ if( y != mosaic_rows - 1 || x != mosaic_cols - 1 )
+ code.value += ',';
+ }
+ }
+ code.value += "\n"+
+"setup bg option mosaic-delay=" + mosaic_delay + "\n"+
+"setup bg option mosaic-keep-picture\n"+
+"\n"+
+"# Input options\n";
+ var x, y;
+ for( y = 0; y < mosaic_rows; y++ )
+ {
+ for( x = 0; x < mosaic_cols; x++ )
+ {
+ var id = x+'_'+y;
+ if( cells[id] )
+ {
+ var s = cells[id];
+ code.value +=
+"new " + s + " broadcast enabled\n"+
+"setup " + s + " input " + sanitize_input( streams[s] ) + "\n"+
+"setup " + s + " output #duplicate{dst=mosaic-bridge{id=" + s + ",width="+cell_width+",height="+cell_height+"},select=video,dst=bridge-out{id="+(y*mosaic_cols+x)+"},select=audio}\n"+
+"\n";
+ }
+ }
+ }
+ code.value +=
+"# Launch everything\n"+
+"control bg play\n";
+ for( y = 0; y < mosaic_rows; y++ )
+ {
+ for( x = 0; x < mosaic_cols; x++ )
+ {
+ var id = x+'_'+y;
+ if( cells[id] )
+ {
+ var s = cells[id];
+ code.value +=
+"control " + s + " play\n";
+ }
+ }
+ }
+ code.value +=
+"\n"+
+"# end of mosaic batch\n";
+}
+
+function mosaic_batch( batch )
+{
+ var i;
+ var commands = batch.split( '\n' );
+ for( i = 0; i < commands.length; i++ )
+ {
+ mosaic_cmd( commands[i] );
+ }
+}
+
+function mosaic_cmd( cmd )
+{
+ loadXMLDoc( 'requests/vlm_cmd.xml?command='+cmd.replace(/\#/g, '%23'), parse_mosaic_cmd );
+}
+
+function parse_mosaic_cmd()
+{
+ /* TODO */
+}
+
+function mosaic_stop()
+{
+ var cmd;
+ cmd = "control bg stop\n";
+ var x,y;
+ for( y = 0; y < mosaic_rows; y++ )
+ {
+ for( x = 0; x < mosaic_cols; x++ )
+ {
+ var id = x+'_'+y;
+ if( cells[id] )
+ {
+ var s = cells[id];
+ cmd += "control " + s + " stop\n";
+ }
+ }
+ }
+ mosaic_batch( cmd );
+}
+
+function mosaic_feedback( msg, ok )
+{
+ var f = document.getElementById( "mosaic_feedback" );
+ while( f.hasChildNodes() )
+ f.removeChild( f.firstChild );
+
+ f.style.fontWeight = "bold";
+ if( ok )
+ f.style.color = "#0f0";
+ else
+ f.style.color = "#f00";
+
+ var t = document.createTextNode( ( ok ? "Info: " : "Error: " ) + msg );
+ f.appendChild( t );
+
+}