|
本帖最后由 zhengxb 于 2018-12-6 09:53 编辑
/********************************************************************************************************************
1.设置通道音量大小,静音,延时控制等
2.读取通道音量小大,静音状态
3.按钮,拉条,联动控制等
4.多通道合并控制
5.设置最大,最小,初使音量值
6.拉条显示,百分比显示,按钮反馈等。
7.设置控件对应通道
8.灵活替换控制代码
9.灵活修改控制方法
*********************************************************************************************************************
**********************************************以下为音频处理器参数设置参考*******************************************
*********************************************************************************************************************
********************************************************************************************************************/
创建设备方法(端口,波特率,检验位,数据位,停止位,控制命令回调方法,数据接收回调方法)
var dev_Volume = new _AUDIO('MOD',9600,N,8,1,volCommand,volReceive);
MOD为模版接口,根据向导生成指定的接口,可是COM1-COM8,NET1-NETX
9600,N,8,1为根据串口指令生成,使用网控制控制时,补齐位数,也需要填写,值任意
volCommand为控制命令的回调方法,用于填写不同品牌设备的控制命令
volReceive为数据接收回调方法,用于设备数据返回接收。
默认音量设置
dev_Volume.setLevelInit([0,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10]);
第1位为程序座标0,不起作用,从第2位即为程序对应的通道1.
最大音量
dev_Volume.setLevelMax([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
第1位为程序座标0,不起作用,从第2位即为程序对应的通道1.
最小音量
dev_Volume.setLevelMini([0,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50]);
第1位为程序座标0,不起作用,从第2位即为程序对应的通道1.
默认静音
dev_Volume.setMuteInit([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
第1位为程序座标0,不起作用,从第2位即为程序对应的通道1.第一次值程序有效,其它的会从中控读取上一次设置值
合并控制
dev_Volume.setCombine(1,2,3);
控制通道1时同时控制通道2,3,当有些音频控制需要同时控制时,可使用音频合并方法。
关联按钮初使化
dev_Volume.setInit('barVolume','txtVolume','btnVolumeMute',24);
最后做按钮关联控制,将拉条显示,百分比显示,静音反馈及总输入输出通道合并。
如初使化最大音量,最小音量,初使音量,初使静音与_AUDIO默认一致,可不设置。
控制命令:
根据控制命令,定义输入输出模块对应的通道名称,对应控制模块号从BIAMP软件查看
var aLevelName = ['','Out_Name_1_01','Out_Name_1_02', 'Out_Name_1_03', 'Out_Name_1_04', 'Out_Name_1_05', 'Out_Name_1_06', 'Out_Name_1_07', 'Out_Name_1_08'];
var aMuteName = ['','Out_Name_1_01','Out_Name_1_02', 'Out_Name_1_03', 'Out_Name_1_04', 'Out_Name_1_05', 'Out_Name_1_06', 'Out_Name_1_07', 'Out_Name_1_08']
function volCommand(vCMD,vChannel)
{
switch(vCMD)
{
//音量控制
case 'value':
return "SET 1 FDRLVL "+aLevelName[vChannel]+" 1 "+dev_Volume.level[vChannel]+"\x0D";
break;
//静音
case 'mute':
return "SET 1 FDRMUTE "+aMuteName[vChannel]+" 1 "+dev_Volume.mute[vChannel]+"\x0D"
break;
}
}
volCommand为前面定义的回调方法,vCMD为返加类型参数,返加value为音量控制,返回mute为静音控制。vChannel为控制通道。
返回数据:
function volReceive(vData)
{
sendLog("volReceive:",vData);
}
volReceive为前面定义的返回数据回调方法,vData为返回的数据,根据数据执行所需要的控制。
音量控制:
dev_Volume.volup(vSelect)
通道音量加,vSelect代表通道号
dev_Volume.voldown(vSelect)
通道音量减,vSelect代表通道号
dev_Volume.setLevel(vSelect,vLevel)
通道音量设置,vSelect代表通道号,vLevel代表音量值,根据最大和小最音量的取值范围;用于直接控制音量静音,如模式调用。
dev_Volume.delayLevel(vSec,SvSelect,vLevel)
延时通道音量设置,vSec为延时时间,单位为秒,vSelect代表通道号,vLevel代表音量值,根据最大和小最音量的取值范围;用于直接控制音量
静音,如模式调用,同一台设备多条指令同时发送间隔。
静音控制:
dev_Volume.volmute(vSelect)
通道静音,vSelect代表通道号
dev_Volume.setMute(vSelect,vValue)
通道静音,vSelect代表通道号,vValue代表静音值0或1;用于直接控制音量静音,如模式调用。
dev_Volume.delayMute(vSec,SvSelect,vValue)
延时通道静音,vSec为延时时间,单位为秒,vSelect代表通道号,vValue代表静音值0或1;用于直接控制音量静音,如模式调用,同一台设备多
条指令同时发送间隔。
关联控制:
dev_Volume.setCombine(vSelect,n1,n2...);
通道关联与取消,如:dev_Volume.setCombine(1,2,3);将2,3通道关联至1通道,控制1通道时,同时会控制通道2,3; 如需取消通道1与其它通道
的关联,则代码为dev_Volume.setCombine(1);
获取状态:
dev_Volume.getStatus();
获取所控制通道状态,并同步到触摸屏,当软件退出重新打开时,可调用此方法,同步触摸屏与中控的数据,保持数据的一致性。
dev_Volume.getLevel(vSelect);
获取指定通道音量,vSelect为指定通道,返回最小与最大音量值区间。
dev_Volume.getMute(vSelect);
获取指定通道静音值,vSelect为指定通道,返回0,1;
端口发码:
dev_Volume.setBaud(9600,N,8,1);
设置对应接口的波特率真
dev_Volume.sendCodeString(“xxxx“);
发送接口命令
dev_Volume.delayCodeString(“xxxx“);
延时发送接口命令
dev_Volume.sendCodeName(“xxxx“);
调用数据库名称
dev_Volume.delayCodeName(“xxxx“);
延时调用数据库名称
端口发码的主要目的是使用dev_Volume代替原有的sendCodeString(COM1,xxxxx)增加程序的可读性。
原型修改:
如果对于_AUDIO原型方法,需要修改或者需要增加,可使用如下方法:
修改方法:
delete dev_Volume.volup;
_AUDIO.prototype.volup = function(vSelect)
{
this.level[vSelect] = getSystemInt(this.barname+vSelect, this.level[vSelect]);
if(this.level[vSelect]<this.valueMax[vSelect])
{
this.level[vSelect] = this.level[vSelect]+2;
}
else
{
this.level[vSelect] = this.valueMax[vSelect];
}
sendCodeString(this.port,this.getCMD('value',vSelect));
this.setStatus(vSelect);
this.setCombineLevel(vSelect);
return this.level[vSelect];
}
在查看原型方法时存在,音量加volup是每次加1,如果根据情况需要每次加2,那么可以删除原来的方法并重新构造,修改里面的相关参数,如上所示。
注:删除原型方法会使用所有调用原型的方法都改变,如果一个项目存在两台音频处理器,都同时调用_AUDIO两个方法都会跟着改变。
如果一台需要改变,另一台不需要,则可使用直接增加方法2的方式,如下所示:
增加方法:
_AUDIO.prototype.volup2 = function(vSelect)
{
this.level[vSelect] = getSystemInt(this.barname+vSelect, this.level[vSelect]);
if(this.level[vSelect]<this.valueMax[vSelect])
{
this.level[vSelect] = this.level[vSelect]+2;
}
else
{
this.level[vSelect] = this.valueMax[vSelect];
}
sendCodeString(this.port,this.getCMD('value',vSelect));
this.setStatus(vSelect);
this.setCombineLevel(vSelect);
return this.level[vSelect];
}
*******************************************************************************************************************/
附 _AUDIO原型方法,已封装在system.dat文件中,可直接调用。
function _AUDIO(vPort,vB,vN,vD,vS,getCMD,fnGetData)
{
this.modPrj = _SUBPROJECT_;
this.getCMD = getCMD;
this.callButton = function(btnName)
{
CallObject(this.modPrj,btnName);
}
this.max = 24;
this.startValue = new Array(-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10,-10);
this.startMute = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
this.valueMax = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
this.valueMini = new Array(-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65,-65);
this.level = new Array();
this.mute = new Array();
this.combine = new Array(new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0),new Array(0));
this.barname = 'VOL2_Bar_CH';
this.txtname = 'VOL2_T_CH';
this.mutename = 'VOL2_B_MUTE_CH';
this.imagemuteon = new Array()
this.imagemuteoff = new Array()
this.imageon = "ImageOnStates.png";
this.imageoff = "ImageOffStates.png";
this.port = vPort
if(vPort.indexOf('MOD')!=-1)
{
this.port = GetCurrentIOName();
}
if(this.port.indexOf('COM')!=-1)
{
setComBaud(this.port,vB,vN,vD,vS);
}
this.setBaud = function(vsB,vsN,vsD,vsS)
{
setComBaud(this.port,vsB,vsN,vsD,vsS)
}
this.sendCodeString = function(vString)
{
sendCodeString(this.port,vString);
}
this.delayCodeString = function(vSec,vString)
{
delayCodeString(vSec,this.port,vString);
}
this.sendCodeName = function(vString)
{
sendCodeName(this.port,vString);
}
this.delayCodeName = function(vSec,vString)
{
delayCodeName(vSec,this.port,vString);
}
this.setLevelInit = function(aLevel)
{
for(var i=1;i<=this.max;i++)
{
this.startValue = aLevel;
}
}
this.setMuteInit = function(aMute)
{
for(var i=1;i<=this.max;i++)
{
this.startMute = aMute;
}
}
this.setLevelMax = function(aLevel)
{
for(var i=1;i<=this.max;i++)
{
this.valueMax = aLevel;
}
}
this.setLevelMini = function(aLevel)
{
for(var i=1;i<=this.max;i++)
{
this.valueMini = aLevel;
}
}
this.setCombine = function(v1)
{
if(arguments.length==1)
{
this.combine[v1]=new Array();
}else if(arguments.length>=2)
{
for(var i =1;i<arguments.length;i++)
{
this.combine[v1][i-1] = arguments;
}
}
}
for(var i=1;i<=this.max;i++)
{
this.mute = this.startMute;
this.level = this.startValue;
if(FindGUIObject(this.mutename+i)!=null)
{
this.imagemuteon=getImageOn(this.mutename+i)
this.imagemuteoff=getImage(this.mutename+i);
}
else
{
this.imagemuteon = this.imageon;
this.imagemuteoff = this.imageoff;
}
}
this.setInit = function(vbar,vtxt,vmute,vmax)
{
this.max = vmax;
this.barname = vbar;
this.txtname = vtxt;
this.mutename = vmute;
for (var i=1;i<=this.max;i++)
{
if(FindGUIObject(this.mutename+i)!=null)
{
this.imagemuteon=getImageOn(this.mutename+i)
this.imagemuteoff=getImage(this.mutename+i);
}
}
for (var i=1;i<=this.max;i++)
{
this.mute = this.startMute;
this.mute = getSystemInt(this.mutename+i,this.mute);
this.level = this.startValue;
this.level = getSystemInt(this.barname+i,this.level);
setSystemInt(this.barname+i,this.level); //将值保存在中控主机
setSystemInt(this.mutename+i,this.mute); //将值保存在中控主机
setButtonText(this.txtname+i,''+ Math.round((this.level-this.valueMini)/(this.valueMax-this.valueMini)*100)+'%');
setBarLevel(this.barname+i,Math.round((this.level-this.valueMini)/(this.valueMax-this.valueMini)*100));
if(this.mute==1)
{
setButtonImage(this.mutename+i,this.imagemuteon);
}
else
{
setButtonImage(this.mutename+i,this.imagemuteoff);
}
}
}
this.volup = function(vSelect)
{
this.level[vSelect] = getSystemInt(this.barname+vSelect, this.level[vSelect]);
if(this.level[vSelect]<this.valueMax[vSelect])
{
this.level[vSelect] = this.level[vSelect] + 1;
}
else
{
this.level[vSelect] = this.valueMax[vSelect];
}
sendCodeString(this.port,this.getCMD('value',vSelect));
this.setStatus(vSelect);
this.setCombineLevel(vSelect);
return this.level[vSelect];
}
this.voldown = function(vSelect)
{
this.level[vSelect] = getSystemInt(this.barname+vSelect, this.level[vSelect]);
if(this.level[vSelect]>this.valueMini[vSelect])
{
this.level[vSelect] = this.level[vSelect] - 1;
}
else
{
this.level[vSelect] = this.valueMini[vSelect];
}
sendCodeString(this.port,this.getCMD('value',vSelect));
this.setStatus(vSelect);
this.setCombineLevel(vSelect);
return this.level[vSelect];
}
this.setCombineLevel = function(vSelect)
{
if(this.combine[vSelect][0]!==0){
for(var i=0;i<this.combine[vSelect].length;i++)
{
this.level[this.combine[vSelect]] = this.level[vSelect];
delayCodeString(0.2*(i+1),this.port,this.getCMD('value',this.combine[vSelect]));
this.setStatus(this.combine[vSelect]);
}
}
}
this.delayCombineLevel = function(vSec,vSelect)
{
if(this.combine[vSelect][0]!==0){
for(var i=0;i<this.combine[vSelect].length;i++)
{
this.level[this.combine[vSelect]] = this.level[vSelect];
delayCodeString(vSec+0.2*(i+1),this.port,this.getCMD('value',this.combine[vSelect]));
this.setStatus(this.combine[vSelect]);
}
}
}
this.setStatus = function(vSelect)
{
setSystemInt(this.barname+vSelect,this.level[vSelect]);
setButtonText(this.txtname+vSelect,''+ Math.round((this.level[vSelect]-this.valueMini[vSelect])/(this.valueMax[vSelect]-this.valueMini[vSelect])*100)+'%');
setBarLevel(this.barname+vSelect,Math.round((this.level[vSelect]-this.valueMini[vSelect])/(this.valueMax[vSelect]-this.valueMini[vSelect])*100));
}
this.volmute = function(vSelect)
{
this.mute[vSelect] = getSystemInt(this.mutename+vSelect,this.mute[vSelect]);
if(this.mute[vSelect] == 0)
{
this.mute[vSelect] = 1;
setButtonImage(this.mutename+vSelect,this.imagemuteon[vSelect]);
}
else
{
this.mute[vSelect] = 0;
setButtonImage(this.mutename+vSelect,this.imagemuteoff[vSelect]);
}
setSystemInt(this.mutename+vSelect,this.mute[vSelect]);
sendCodeString(this.port,this.getCMD('mute',vSelect));
this.setCombineMute(vSelect);
return this.mute[vSelect];
}
this.setCombineMute = function(vSelect)
{
if(this.combine[vSelect][0]!==0){
for(var i=0;i<this.combine[vSelect].length;i++)
{
this.mute[this.combine[vSelect]] = this.mute[vSelect];
delayCodeString(0.2*(i+1),this.port,this.getCMD('mute',this.combine[vSelect]));
if(this.mute[this.combine[vSelect]] == 1)
{
setButtonImage(this.mutename+this.combine[vSelect],this.imagemuteon[this.combine[vSelect]]);
}
else
{
setButtonImage(this.mutename+this.combine[vSelect],this.imagemuteoff[this.combine[vSelect]]);
}
}
}
}
this.delayCombineMute = function(vSec,vSelect)
{
if(this.combine[vSelect][0]!==0){
for(var i=0;i<this.combine[vSelect].length;i++)
{
this.mute[this.combine[vSelect]] = this.mute[vSelect];
delayCodeString(vSec+0.2*(i+1),this.port,this.getCMD('mute',this.combine[vSelect]));
if(this.mute[this.combine[vSelect]] == 1)
{
setButtonImage(this.mutename+this.combine[vSelect],this.imagemuteon[this.combine[vSelect]]);
}
else
{
setButtonImage(this.mutename+this.combine[vSelect],this.imagemuteoff[this.combine[vSelect]]);
}
}
}
}
this.setMute = function(vSelect,vValue)
{
this.mute[vSelect] = vValue;
sendCodeString(this.port,this.getCMD('mute',vSelect));
setSystemInt(this.mutename+vSelect,this.mute[vSelect]);
if(this.mute[vSelect] == 1)
{
setButtonImage(this.mutename+vSelect,this.imagemuteon[vSelect]);
}
else
{
setButtonImage(this.mutename+vSelect,this.imagemuteoff[vSelect]);
}
this.setCombineMute(vSelect);
return this.mute[vSelect];
}
this.delayMute = function(vSec,vSelect,vValue)
{
this.mute[vSelect] = vValue;
delayCodeString(vSec,this.port,this.getCMD('mute',vSelect));
setSystemInt(this.mutename+vSelect,this.mute[vSelect]);
if(this.mute[vSelect] == 1)
{
setButtonImage(this.mutename+vSelect,this.imagemuteon[vSelect]);
}
else
{
setButtonImage(this.mutename+vSelect,this.imagemuteoff[vSelect]);
}
this.delayCombineMute(vSec,vSelect);
return this.mute[vSelect];
}
this.setBarCtrl = function(vSelect)
{
this.level[vSelect] =Math.round(getBarLevel(this.barname+vSelect)/100*(this.valueMax[vSelect]-this.valueMini[vSelect]))+this.valueMini[vSelect];
sendCodeString(this.port,this.getCMD('value',vSelect));
this.setStatus(vSelect);
this.setCombineLevel(vSelect);
return this.level[vSelect];
}
this.delayBarCtrl = function(vSec,vSelect)
{
this.level[vSelect] =Math.round(getBarLevel(this.barname+vSelect)/100*(this.valueMax[vSelect]-this.valueMini[vSelect]))+this.valueMini[vSelect];
delayCodeString(this.port,this.getCMD('value',vSelect));
this.setStatus(vSelect);
this.delayCombineLevel(vSelect);
return this.level[vSelect];
}
this.setLevel = function(vSelect,vLevel)
{
this.level[vSelect] = parseInt(vLevel);
sendCodeString(this.port,this.getCMD('value',vSelect));
this.setStatus(vSelect);
this.setCombineLevel(vSelect);
}
this.delayLevel = function(vSec,vSelect,vLevel)
{
this.level[vSelect] = parseInt(vLevel);
delayCodeString(vSec,this.port,this.getCMD('value',vSelect));
this.setStatus(vSelect);
this.delayCombineLevel(vSec,vSelect);
}
this.getStatus = function()
{
for(var i = 1;i<=this.max;i++)
{
this.level = getSystemInt(this.barname+i,this.level);
this.mute = getSystemInt(this.mutename+i,this.mute);
setButtonText(this.txtname+i,''+ Math.round((this.level-this.valueMini)/(this.valueMax-this.valueMini)*100)+'%');
setBarLevel(this.barname+i,Math.round((this.level-this.valueMini)/(this.valueMax-this.valueMini)*100));
if(this.mute==0)
{
setButtonImage(this.mutename+i,this.imagemuteoff);
}
else
{
setButtonImage(this.mutename+i,this.imagemuteon);
}
}
}
this.getLevel = function(vSelect)
{
this.level = getSystemInt(this.barname+vSelect,this.level[vSelect]);
return this.level;
}
this.getMute = function(vSelect)
{
this.mute = getSystemInt(this.mutename+vSelect,this.mute[vSelect]);
return this.mute;
}
this.getRev = function(vData)
{
fnGetData(vData);
}
if(arguments.length>=7)
{
setStringReceive(this.port,this.getRev);
}
}
|
|