Modifs OSC

This commit is contained in:
tzim 2014-12-30 16:44:26 +00:00
parent 53aedc3fcd
commit 431af46b9d
4 changed files with 587 additions and 12 deletions

View file

@ -311,6 +311,8 @@ namespace DMX2
else if(master != 100){
foreach (var c in circuits) {
int val = 0;
if(circuitTelecomande==c)
val = circuitTelecomandeVal;
foreach (var seq in sequenceurs) {
val = Math.Max (val, seq.ValeurCircuit (c));
}

View file

@ -180,6 +180,8 @@ namespace DMX2
}
}
public string Address{
get;
private set;
@ -192,6 +194,108 @@ namespace DMX2
return args;
}
}
// Construction de message
public OSCMessage(string _address){
Address=_address;
}
void AddArg (OSCArg arg)
{
if (args == null) {
args = new OSCArg[1];
} else {
OSCArg[] na = new OSCArg[args.Length+1];
args.CopyTo(na,0);
args = na;
}
args[args.Length-1] = arg;
}
public void AddString (string arg)
{
AddArg(new OSCStringArg(arg));
}
public void AddInt (int arg)
{
AddArg(new OSCIntArg(arg));
}
public void AddFloat (float arg)
{
AddArg(new OSCFloatArg(arg));
}
public byte[] Encode ()
{
int len = System.Text.ASCIIEncoding.ASCII.GetByteCount (Address) / 4+1;
string typestring = ",";
foreach (var arg in args) {
switch(arg.Type){
case OSCType.Int32:
len +=1;
typestring+="i";
break;
case OSCType.Float32:
len += 1;
typestring+="f";
break;
case OSCType.String:
len += System.Text.ASCIIEncoding.ASCII.GetByteCount (arg.GetString())/4+1;
typestring+="s";
break;
}
}
len += typestring.Length/4 +1;
byte[] res = new byte[len*4];
int pos=0;
EncodeString(res,ref pos,Address);
EncodeString(res,ref pos,typestring);
foreach (var arg in args) {
switch(arg.Type){
case OSCType.Int32:
EncodeInt(res,ref pos,arg.GetInt());
break;
case OSCType.Float32:
EncodeFloat(res,ref pos,arg.GetFloat());
break;
case OSCType.String:
EncodeString(res,ref pos,arg.GetString());
break;
}
}
return res;
}
void EncodeString (byte[] buff, ref int pos, string s)
{
pos +=
System.Text.ASCIIEncoding.ASCII.GetBytes (
s, 0, s.Length, buff, pos);
do {
buff[pos++]=0;
} while (pos%4!=0);
}
void EncodeInt (byte[] res, ref int pos, int i)
{
byte[] buff = BitConverter.GetBytes(i);
if(BitConverter.IsLittleEndian)
Array.Reverse(buff);
buff.CopyTo(res,pos);
pos+=4;
}
void EncodeFloat (byte[] res, ref int pos, float f)
{
byte[] buff = BitConverter.GetBytes(f);
if(BitConverter.IsLittleEndian)
Array.Reverse(buff);
buff.CopyTo(res,pos);
pos+=4;
}
}
@ -217,7 +321,7 @@ namespace DMX2
Console.WriteLine(msg.Address);
foreach(var arg in msg.Args)
Console.WriteLine(arg.GetString());
ProcessMessage(msg);
ProcessMessage(msg,remep);
}
} catch (SocketException ex) {
}
@ -249,16 +353,21 @@ namespace DMX2
///
/// </summary>
void ProcessMessage (OSCMessage msg)
void ProcessMessage (OSCMessage msg,IPEndPoint remep)
{
if(Conduite.Courante == null) return;
string[] toks = msg.Address.Split (new char[]{'/'},StringSplitOptions.RemoveEmptyEntries);
int arg;
switch (toks [0]) {
case "refresh":
IPEndPoint ep = new IPEndPoint(remep.Address,msg.Args[0].GetInt());
SendRefresh(ep);
break;
case "master":
arg = msg.Args[0].GetInt();
if(arg>=0 && arg<=100)
Conduite.Courante.Master = arg;
if (arg<0) arg=0;
if (arg>100)arg=100;
Conduite.Courante.Master = arg;
break;
case "masterseq":
switch(toks[1]){
@ -287,6 +396,9 @@ namespace DMX2
case "universe":
ProcessMessageUniv(msg,toks);
break;
case "circuitTel":
ProcessMessageCircuit(msg,toks);
break;
}
}
@ -316,8 +428,9 @@ namespace DMX2
break;
case "master":
arg = msg.Args[0].GetInt();
if(arg>=0 && arg<=100)
seql.Master = arg;
if (arg<0) arg=0;
if (arg>100)arg=100;
seql.Master = arg;
break;
case "circuit":
int cirId;
@ -349,8 +462,9 @@ namespace DMX2
break;
case "master":
arg = msg.Args[0].GetInt();
if(arg>=0 && arg<=100)
seqm.Master = arg;
if (arg<0) arg=0;
if (arg>100)arg=100;
seqm.Master = arg;
break;
}
}
@ -361,9 +475,9 @@ namespace DMX2
int univId;
if (!int.TryParse (toks [1], out univId))
return;
if (univId > 0 || univId >= Conduite.Courante.Patches.Count)
if (univId <= 0 || univId > Conduite.Courante.Patches.Count)
return;
UniversDMX univ = Conduite.Courante.Patches [univId];
UniversDMX univ = Conduite.Courante.Patches [univId-1];
switch (toks [2]) {
case "on":
@ -377,12 +491,83 @@ namespace DMX2
break;
case "onval":
int val = msg.Args[0].GetInt();
if(val>=0 && val<=255)
univ.AllumageForceVal = val;
if(val<0) val=0;
if(val>255) val=255;
univ.AllumageForceVal = val;
break;
}
}
void ProcessMessageCircuit (OSCMessage msg, string[] toks)
{
switch (toks [1]) {
case "on":
int cirId;
if(!int.TryParse(toks[2],out cirId))return;
if( msg.Args[0].GetInt() !=0){
if(cirId>0 && cirId <= Conduite.Courante.Circuits.Count)
{
Conduite.Courante.CircuitTelecomande =
Conduite.Courante.Circuits[cirId-1];
}
}
break;
case "off":
Conduite.Courante.CircuitTelecomande= null;
break;
case "onval":
int val = msg.Args[0].GetInt();
if(val<0) val=0;
if(val>255) val=255;
Conduite.Courante.CircuitTelecomandeVal = val;
break;
}
}
void SendRefresh (IPEndPoint ep)
{
OSCMessage msg = new OSCMessage ("/master");
msg.AddFloat (Conduite.Courante.Master);
byte[] buff = msg.Encode ();
udpCli.Send (buff, buff.Length, ep);
var id = Conduite.Courante.SequenceurMaitre.IndexLigneEnCours-1;
if (id >= 0) {
msg = new OSCMessage("/masterseq/prevstep");
msg.AddString(
string.Format("{0}. {1}", id+1,
Conduite.Courante.SequenceurMaitre.Lignes[id].Nom )
);
buff = msg.Encode();
udpCli.Send (buff, buff.Length, ep);
}
id = Conduite.Courante.SequenceurMaitre.IndexLigneaSuivre;
if (id == -1) id = Conduite.Courante.SequenceurMaitre.IndexLigneEnCours+1;
if (id >= 0 && id < Conduite.Courante.SequenceurMaitre.Lignes.Count) {
msg = new OSCMessage("/masterseq/nextstep");
msg.AddString(
string.Format("{0}. {1}", id+1,
Conduite.Courante.SequenceurMaitre.Lignes[id].Nom)
);
buff = msg.Encode();
udpCli.Send (buff, buff.Length, ep);
}
id = Conduite.Courante.SequenceurMaitre.IndexLigneEnCours;
if (id >= 0) {
msg = new OSCMessage("/masterseq/curstep");
msg.AddString(
string.Format("{0}. {1}", id+1,
Conduite.Courante.SequenceurMaitre.Lignes[id].Nom)
);
buff = msg.Encode();
udpCli.Send (buff, buff.Length, ep);
}
msg = new OSCMessage("/masterseq/time");
msg.AddFloat(((float) Conduite.Courante.SequenceurMaitre.TimeStamp.TotalMilliseconds/1000 ));
buff = msg.Encode();
udpCli.Send (buff, buff.Length, ep);
}
#region IDisposable implementation
@ -407,6 +592,7 @@ namespace DMX2
}
}
#endregion
}

View file

@ -79,6 +79,7 @@ namespace DMX2
public int AddFile (int pos, string file)
{
lock (this) {
if(files.Contains(file)) return -1;
files.Insert (pos, file);
CommandAdd(pos);
return pos;

386
loupiottes.js Normal file
View file

@ -0,0 +1,386 @@
loadedInterfaceName = "Loupiottes2";
interfaceOrientation = "landscape";
control.sendRef = function(){
oscManager.sendOSC(["refresh","i",8080]);
window.setTimeout(control.sendRef,500);
}
control.refinit = function(){
if(control.timerinit!=true){
window.setTimeout(control.sendRef,1000);
control.timerinit=true;
}
}
control.regMode = "OFF";
control.regUniv = 0;
control.regPage = 0;
control.regPageCount=32;
control.modeFunc = function(p1){
if( control.regMode == "CIR")
{
oscManager.sendOSC(["/circuitTel/off","i",1]);
  }
if( control.regMode == "UNI")
{
oscManager.sendOSC(["/universe/"+control.regUniv+"/off","i",1]);
  }
if(p1 == "OFF"){
control.regMode = "OFF";
control.regUniv=0;
}
if(p1 == "CIR"){
control.regMode = "CIR";
control.regUniv=0;
}
if(p1 == "U+"){
control.regMode = "UNI";
control.regUniv++;
if(control.regUniv<1) control.regUniv=1;
}
if(p1 == "U-"){
control.regMode = "UNI";
control.regUniv--;
if(control.regUniv<1) control.regUniv=1;
}
if( control.regMode == "OFF")
lblMode.setValue("Mode : OFF");
if( control.regMode == "CIR")
lblMode.setValue("Mode : Circuit");
if( control.regMode == "UNI")
lblMode.setValue("Mode : Univers n°"+control.regUniv);
}
control.reglValChange = function(val){
if( control.regMode == "UNI")
{
var addr = "/universe/"+ control.regUniv + "/onval";
oscManager.sendOSC([addr,"f",val]);
}
if( control.regMode == "CIR")
{
var addr = "/circuitTel/onval";
oscManager.sendOSC([addr,"f",val]);
}
return false;
}
control.btnRegl = function(id,val)
{
if(val==0)return;
for(var i = 0;i<control.regPageCount;i++){
if(i!=id && mulButton.children[i].value !=0)
mulButton.children[i].setValue(0);
}
reglval.setValue(0);
id = id + control.regPageCount *control.regPage +1;
if( control.regMode == "UNI")
{
var addr = "/universe/"+ control.regUniv + "/on/" + (id);
oscManager.sendOSC([addr,"f",val]);
}
if( control.regMode == "CIR")
{
var addr = "/circuitTel/on/" + (id);
oscManager.sendOSC([addr,"f",val]);
}
}
control.changeRegPage = function(){
var base = control.regPage *control.regPageCount +1;
for(var i = 0;i<control.regPageCount;i++){
mulButton.children[i].label.setValue(base + i);
if(mulButton.children[i].value !=0)
mulButton.children[i].setValue(0);
}
}
control.pageUp= function(){
control.regPage++;
control.changeRegPage();
}
control.pageDown= function(){
control.regPage--;
if(control.regPage<0)control.regPage=0;
control.changeRegPage();
}
oscManager.delegate = {
processOSC : function(oscAddress, typetags, args) {
switch(oscAddress) {
case "/masterseq/curstep":
lblCurrStep.setValue(args[0]);
break;
case "/masterseq/nextstep":
lblGo.setValue("Suivant : "+args[0]);
break;
case "/masterseq/prevstep":
lblGoBack.setValue("Precedent : "+args[0]);
break;
case "/masterseq/time":
lblTime.setValue("T : "+args[0]);
break;
default:
oscManager.processOSC(oscAddress, typetags, args);
break;
}
}
}
pages = [
[
{
"name": "refreshButton", "type": "Button",
"bounds": [0,.7,.14,.15],
"mode": "momentary", "color": "#000000", "stroke": "#aaaaaa",
"ontouchstart": "interfaceManager.refreshInterface()",
"label":"Refr"
},
{
"name": "btnMainPage", "type": "Button",
"bounds": [0,.1,.14,.15],
"mode": "momentary", "color": "#000000", "stroke": "#FF0000",
"ontouchstart": "control.changePage(0)",
"label":"Main"
},
{
"name": "btnReglPage", "type": "Button",
"bounds": [0,.26,.14,.15],
"mode": "momentary", "color": "#000000", "stroke": "#aaaaaa",
"ontouchstart": "control.changePage(1)",
"label":"Reglage"
},
{
"name": "btnMastPage", "type": "Button",
"bounds": [0,.42,.14,.15],
"mode": "momentary", "color": "#000000", "stroke": "#aaaaaa",
"ontouchstart": "control.changePage(2)",
"label":"Masters"
},
{"name": "lbl2", "type": "Label",
"bounds": [0,0,.14,.1],
"value": "Pages :",
},
{
"name":"master",
"type":"Slider",
"address":"/master",
"min" : -10,
"max" : 110,
"isVertical" : true,
"x":.15, "y": 0,
"width":.1, "height":.9,
"startingValue":100
},
// --- Suivant
{
"name": "btnGo", "type": "Button", "address":"/masterseq/go",
"bounds": [.3,.56,.5,.15],
"mode": "momentary",
},
{"name": "lblGo", "type": "Label",
"bounds": [.325,.56,.45,.15],
"value": "Suivant : ", "align":"left"
},
// --- Precedent
{
"name": "btnGoBack", "type": "Button", "address":"/masterseq/goback",
"bounds": [.3,.26,.5,.15],
"mode": "momentary",
},
{"name": "lblGoBack", "type": "Label",
"bounds": [.325,.26,.45,.15],
"value": "Precedent : ", "align":"left"
},
{"name": "lblCurrStep", "type": "Label",
"size":25,
// "address":"/masterseq/curstep",
"bounds": [.325,.41,.45,.15],
"value": "Precedent : ", "align":"left"
},
{"name": "lblTime", "type": "Label",
"size":20,
"address":"/masterseq/time",
"bounds": [.74,.05,.2,.1],
"value": "0:00 s", "align":"right",
"backgroundColor": "#000022",
"oninit":"control.refinit()"
},
],
// ---------- PAGE 2 -----------
[
{
"name": "btnMainPage", "type": "Button",
"bounds": [0,.1,.14,.15],
"mode": "momentary", "color": "#000000", "stroke": "#aaaaaa",
"ontouchstart": "control.changePage(0)",
"label":"Main"
},
{
"name": "btnReglPage", "type": "Button",
"bounds": [0,.26,.14,.15],
"mode": "momentary", "color": "#000000", "stroke": "#FF0000",
"ontouchstart": "control.changePage(1)",
"label":"Reglage"
},
{
"name": "btnMastPage", "type": "Button",
"bounds": [0,.42,.14,.15],
"mode": "momentary", "color": "#000000", "stroke": "#aaaaaa",
"ontouchstart": "control.changePage(2)",
"label":"Masters"
},
{"name": "lbl2", "type": "Label",
"bounds": [0,0,.14,.1],
"value": "Pages :",
},
{
"name":"master",
"type":"Slider",
"min" : -10,
"max" : 110,
"isVertical" : true,
"x":.15, "y": 0,
"width":.08, "height":.9,
"startingValue":100,
"color":"#FF3300"
},
{
"name":"reglval",
"type":"Slider",
"isVertical" : true,
"min" : -10,
"max" : 270,
"bounds": [.25,.3,.05,.58],
"onvaluechange":"control.reglValChange(this.value)",
"color":"#FFFF00"
},
{
"name" : "mulButton",
"type" : "MultiButton",
"bounds": [.4,.3,.59,.58],
"rows" : 4, "columns" : 8,
"shouldLabel":"true",
"ontouchstart": "control.btnRegl(this.childID, this.value)",
"stroke":"#FFFFFF", "color":"#8888FF"
},
{
"name": "btnMulPlus", "type": "Button",
"bounds": [.325,.3,.05,.1],
"mode": "momentary",
"ontouchstart":"control.pageUp()",
"label":"+"
},
{
"name": "btnMulMoins", "type": "Button",
"bounds": [.325,.78,.05,.1],
"mode": "momentary",
"label":"-",
"ontouchstart":"control.pageDown()"
},
{
"name": "btnROff", "type": "Button",
"bounds": [.4,.01,.12,.15],
"mode": "momentary",
"ontouchstart": "control.modeFunc('OFF')",
"label":"OFF"
},
{
"name": "btnRUminus", "type": "Button",
"bounds": [.52,.01,.12,.15],
"mode": "momentary",
"ontouchstart": "control.modeFunc('U-')",
"label":"Univ -"
},
{
"name": "btnRUplus", "type": "Button",
"bounds": [.64,.01,.12,.15],
"mode": "momentary",
"ontouchstart": "control.modeFunc('U+')",
"label":"Univ +"
},
{
"name": "btnRCirc", "type": "Button",
"bounds": [.76,.01,.12,.15],
"mode": "momentary",
"ontouchstart": "control.modeFunc('CIR')",
"label":"Circuit"
},
{"name": "lblMode", "type": "Label",
"bounds": [.4,.18,.5,.1],
"value": "Mode : OFF",
},
],
[
{
"name": "btnMainPage", "type": "Button",
"bounds": [0,.1,.14,.15],
"mode": "momentary", "color": "#000000", "stroke": "#aaaaaa",
"ontouchstart": "control.changePage(0)",
"label":"Main"
},
{
"name": "btnReglPage", "type": "Button",
"bounds": [0,.26,.14,.15],
"mode": "momentary", "color": "#000000", "stroke": "#aaaaaa",
"ontouchstart": "control.changePage(1)",
"label":"Reglage"
},
{
"name": "btnMastPage", "type": "Button",
"bounds": [0,.42,.14,.15],
"mode": "momentary", "color": "#000000", "stroke": "#FF0000",
"ontouchstart": "control.changePage(2)",
"label":"Masters"
},
{"name": "lbl2", "type": "Label",
"bounds": [0,0,.14,.1],
"value": "Pages :",
},
]
];