buttons seems to work clic/osc_send/osc_receive/save_load/
This commit is contained in:
parent
5def76b11b
commit
93259e9c60
3 changed files with 124 additions and 135 deletions
|
|
@ -17,8 +17,8 @@ document.title = 'INIT'
|
|||
|
||||
init = function() {
|
||||
|
||||
__faders__ = [];
|
||||
__buttons__ = [];
|
||||
__faders__ = {};
|
||||
__buttons__ = {};
|
||||
|
||||
parsetabs(TABS,false,false)
|
||||
|
||||
|
|
@ -76,8 +76,10 @@ function parsetabs(TABS,parent,sub) {
|
|||
var $widget = $('\
|
||||
<div class="widget">\
|
||||
<div class="title" '+color+'>'+title+'</div>\
|
||||
<div class="button-wrapper"><div class="button"></div></div>\
|
||||
<input value="'+dv+'"></input>\
|
||||
<div class="button-wrapper">\
|
||||
<div class="button" widgetId="'+widgetId+'" path="'+widgetData.path+'"></div>\
|
||||
</div>\
|
||||
<input disabled value="'+dv+'"></input>\
|
||||
</div>\
|
||||
');
|
||||
|
||||
|
|
@ -85,38 +87,43 @@ function parsetabs(TABS,parent,sub) {
|
|||
$widget.button = $widget.find('.button')
|
||||
|
||||
$widget.button
|
||||
.on('on',function(){
|
||||
.on('on',function(e,send){
|
||||
$(this).addClass('on');
|
||||
var t = widgetData.target?widgetData.target:defaultTarget,
|
||||
p = widgetData.path,
|
||||
a = widgetData.args?widgetData.args.on:1;
|
||||
sendOsc([t,p,a]);
|
||||
if (send) sendOsc([t,p,a]);
|
||||
$widget.input.val(a)
|
||||
})
|
||||
.on('off',function(){
|
||||
.on('off',function(e,send){
|
||||
$(this).removeClass('on');
|
||||
var t = widgetData.target?widgetData.target:defaultTarget,
|
||||
p = widgetData.path,
|
||||
a = widgetData.args?widgetData.args.off:0;
|
||||
sendOsc([t,p,a]);
|
||||
if (send) sendOsc([t,p,a]);
|
||||
$widget.input.val(a)
|
||||
})
|
||||
|
||||
.click(function(){
|
||||
switch($(this).hasClass('on')){
|
||||
case true:
|
||||
$(this).trigger('off')
|
||||
break
|
||||
case false:
|
||||
$(this).trigger('on')
|
||||
break
|
||||
var x = $widget.button.val()?'off':'on'
|
||||
$(this).trigger(x,true)
|
||||
});
|
||||
|
||||
$widget.button.val = function(v,send) {
|
||||
var send = send==undefined?true:false;
|
||||
if (v== undefined) {return $(this).hasClass('on')?1:0;}
|
||||
else {
|
||||
if (widgetData.args!=undefined) {
|
||||
if (v==widgetData.args.on) {$widget.button.trigger('on',send)}
|
||||
if (v==widgetData.args.off) {$widget.button.trigger('off',send)}
|
||||
} else {
|
||||
if (v==1) {$widget.button.trigger('on',send)}
|
||||
if (v==0) {$widget.button.trigger('off',send)}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
__buttons__[widgetId] = $widget.button
|
||||
|
||||
|
||||
__buttons__.push($widget)
|
||||
|
||||
|
||||
break
|
||||
|
||||
|
||||
|
|
@ -128,11 +135,12 @@ function parsetabs(TABS,parent,sub) {
|
|||
<div class="widget">\
|
||||
<div class="title" '+color+'>'+title+'</div>\
|
||||
<div class="fader-wrapper">\
|
||||
<div class="fader locked" path="'+widgetData.path+'" name="'+widgetId+'"></div>\
|
||||
<div class="fader locked" path="'+widgetData.path+'" widgetId="'+widgetId+'"></div>\
|
||||
</div>\
|
||||
<input value="0"></input>\
|
||||
</div>\
|
||||
');
|
||||
|
||||
$widget.fader = $widget.find('.fader')
|
||||
|
||||
var range = (widgetData.range=='db'||!widgetData.range)?{'min': -70,'20%': -40,'45%': -20,'60%': -10,'max': 6}:widgetData.range;
|
||||
|
|
@ -161,7 +169,7 @@ function parsetabs(TABS,parent,sub) {
|
|||
var pips = pips();
|
||||
|
||||
|
||||
$widget.find('.fader')
|
||||
$widget.fader
|
||||
.noUiSlider({
|
||||
orientation:'vertical',
|
||||
direction: "rtl",
|
||||
|
|
@ -180,7 +188,7 @@ function parsetabs(TABS,parent,sub) {
|
|||
})
|
||||
.Link('lower').to($widget.find('input'))
|
||||
.on('slide',function(){
|
||||
if ($(this).hasClass('locked')) return;
|
||||
if ($widget.fader.hasClass('locked')) return;
|
||||
var t = widgetData.target?widgetData.target:defaultTarget,
|
||||
p = widgetData.path,
|
||||
a = widgetData.args,
|
||||
|
|
@ -190,7 +198,7 @@ function parsetabs(TABS,parent,sub) {
|
|||
sendOsc([t,p,a,v]);
|
||||
})
|
||||
.on('set',function(){
|
||||
if ($(this).hasClass('locked')) return;
|
||||
if ($widget.fader.hasClass('locked')) return;
|
||||
var t = widgetData.target?widgetData.target:defaultTarget,
|
||||
p = widgetData.path,
|
||||
a = widgetData.args,
|
||||
|
|
@ -200,10 +208,15 @@ function parsetabs(TABS,parent,sub) {
|
|||
|
||||
sendOsc([t,p,a,v]);
|
||||
});
|
||||
// store reference for state saving/loading
|
||||
__faders__.push($widget)
|
||||
|
||||
|
||||
break
|
||||
// store reference for state saving/loading
|
||||
if (__faders__[widgetId]!=undefined) {
|
||||
|
||||
}
|
||||
__faders__[widgetId] = $widget.fader
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
$tabContent.append($widget);
|
||||
|
|
@ -217,10 +230,9 @@ function parsetabs(TABS,parent,sub) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
// Synchronize faders that share the same name
|
||||
// Synchronize faders that share the same widgetId
|
||||
$(".fader").each(function(){
|
||||
$(".fader[name='"+$(this).attr('name')+"']").not(this).Link('lower').to($(this), crossUpdate);
|
||||
$(".fader[widgetId='"+$(this).attr('widgetId')+"']").not(this).Link('lower').to($(this), crossUpdate);
|
||||
}).removeClass('locked');
|
||||
function crossUpdate ( value, handle, slider ) {
|
||||
$(this).val( value );
|
||||
|
|
@ -314,8 +326,11 @@ function sendOsc(argsPack){
|
|||
|
||||
function saveState() {
|
||||
data = []
|
||||
$.each(__faders__,function(i,strip) {
|
||||
data.push('strip:'+strip.fader.attr('name')+':'+strip.fader.val())
|
||||
$.each(__faders__,function(i,fader) {
|
||||
data.push('fader:'+i+':'+fader.val())
|
||||
})
|
||||
$.each(__buttons__,function(i,button) {
|
||||
data.push('button:'+i+':'+button.val())
|
||||
})
|
||||
document.title = 'Save,'+data.join(';')
|
||||
}
|
||||
|
|
@ -331,8 +346,12 @@ loadPreset = function(preset){
|
|||
$.each(preset.split(';'),function(i,d) {
|
||||
var data = d.split(':')
|
||||
setTimeout(function(){
|
||||
if (data[0] == 'strip') {
|
||||
$('.fader[name="'+data[1]+'"]').val(data[2]).trigger('set')
|
||||
if (data[0] == 'fader') {
|
||||
__faders__[data[1]].val(data[2]).trigger('set')
|
||||
|
||||
}
|
||||
if (data[0] == 'button') {
|
||||
__buttons__[data[1]].val(data[2])
|
||||
|
||||
}
|
||||
},i)
|
||||
|
|
@ -342,7 +361,11 @@ loadPreset = function(preset){
|
|||
|
||||
receiveOsc = function(argsPack){
|
||||
argsPack = argsPack.split(',')
|
||||
$('.fader[path="'+argsPack[0]+'"]').addClass('locked').val(argsPack.pop()).removeClass('locked')
|
||||
var id = $('[path="'+argsPack[0]+'"]').attr('widgetId');
|
||||
$('[path="'+argsPack[0]+'"]').addClass('locked');
|
||||
if (__faders__[id]!=undefined) __faders__[id].val(argsPack.pop())
|
||||
if (__buttons__[id]!=undefined) __buttons__[id].val(argsPack.pop(),false)
|
||||
$('[path="'+argsPack[0]+'"]').removeClass('locked');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue