diff --git a/DMX-2.0/Conduite.cs b/DMX-2.0/Conduite.cs index e0f10d4..b97ed75 100644 --- a/DMX-2.0/Conduite.cs +++ b/DMX-2.0/Conduite.cs @@ -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)); } diff --git a/DMX-2.0/OSCServer.cs b/DMX-2.0/OSCServer.cs index eabfaae..951f82f 100644 --- a/DMX-2.0/OSCServer.cs +++ b/DMX-2.0/OSCServer.cs @@ -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 /// /// - 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 } diff --git a/DMX-2.0/SequenceurSon.cs b/DMX-2.0/SequenceurSon.cs index dc02201..246e6c5 100644 --- a/DMX-2.0/SequenceurSon.cs +++ b/DMX-2.0/SequenceurSon.cs @@ -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; diff --git a/loupiottes.js b/loupiottes.js new file mode 100644 index 0000000..e344f26 --- /dev/null +++ b/loupiottes.js @@ -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