diff --git a/lib-dev/css/style.scss b/lib-dev/css/style.scss index c9594ce4..214df9f9 100644 --- a/lib-dev/css/style.scss +++ b/lib-dev/css/style.scss @@ -1,7 +1,7 @@ ///////////// $color-text:rgba(white,.9); -$color-text-fade:transparentize($color-text,.5); +$color-text-fade:transparentize($color-text,.4); $color-title:rgba(white,.05); @@ -245,11 +245,21 @@ a { width:100%; -webkit-mask: linear-gradient(to left, rgba(0, 0, 0, 0), #000000 10px) no-repeat; } + color:$color-text-fade; &.on { background:#282c34; border:1px solid $color-border; border-bottom-color:$color-fg; - + color:$color-text; + &:before { + content:""; + position: absolute; + top:0; + left:0; + right:0; + bottom:0; + background:linear-gradient(rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)) + } &:after { content:""; position:absolute; @@ -257,7 +267,7 @@ a { left:0; right:0; height:4px; - background:linear-gradient(rgba($color-accent,0.25),rgba($color-accent,0)) + background:linear-gradient(rgba($color-accent,0.5),rgba($color-accent,0)) } } } @@ -275,31 +285,47 @@ a { top:$nav-height - 4px; right:0; bottom:0; - padding:5px; + padding:10px 5px 5px; border-top:1px solid $color-border; .tab { - height:100%; + //height:100%; font-size:0; - position:relative; + //position:relative; overflow: auto; } .content { border:1px solid $color-border; top:$nav-height - 9px; + } } .tab { - display:none; + display:block; + height:0px; + width: 0px; + overflow: hidden; &.on { - display: block; + height:100%; + width:auto; } } +.test.tab.on { + display:flex;width:100%; + flex-wrap: wrap; + flex-direction:column; + //justify-content: stretch; + > .widget { + height:33.33%; + padding-bottom:10px; + //flex: 1 + } +} // WIDGETS @@ -311,14 +337,12 @@ a { font-size:13px; // box-shadow: 0 0 0 1px $color-border; padding-top:35px; + padding-bottom: 8px; vertical-align:top; overflow: hidden; margin-right: 10px; .title { - border-bottom:1px solid $color-border; - border-left:0; - border-right:0; - background:$color-title; + padding:10px 10px; position:absolute; top:0px; @@ -328,6 +352,8 @@ a { overflow:hidden; height:35px; border-radius:2px 2px 0 0 ; + background:linear-gradient(#3a3f4b, #353b45); + box-shadow: 0 0 0 1px $color-bg inset; } input { width:100%; @@ -362,14 +388,15 @@ $button-size:20px; .button-wrapper { height:100%; overflow:hidden; + padding-left: 10px; .button { width:100%; height:100%; position:relative; outline:1px solid $color-bg; outline-offset: -10px; - background: $color-title; - border: 10px solid $color-fg; + background:linear-gradient(#3a3f4b, #353b45); + box-shadow: 0 0 0 1px $color-bg inset; &:after{ content:""; position:absolute; @@ -380,7 +407,6 @@ $button-size:20px; border-radius:$button-size; background:$color-bg; } - &.on:after { background:$color-accent; box-shadow:0 0 0 4px rgba(255,255,255,0.1); @@ -416,7 +442,7 @@ width:400px; } .stack .widget { - height:70px; + //height:70px; width:100%; display:block; padding:0; @@ -435,25 +461,34 @@ width:400px; padding:20px 20px; float:right; width:70%; + height:70px; } .stack .button-wrapper { float:right; width:70%; + height:70px; } .stack .widget .title { width:30%; - height:50%; + height:35px; //border-right:1px solid $color-border; } -.stack .widget input { +.stack .fader-wrapper-outer input, .stack .button-wrapper input { width:30%; - height:50%; + height:35px; left:0; right:auto; border-top:0; //border-right:1px solid $color-border; } +.stack .xy-wrapper { + float:right; + width:70%; + height:300px; + padding-top:0; +} + /* STRIP (vertical fader) */ .fader-wrapper-outer { @@ -465,10 +500,11 @@ width:400px; input { position:absolute; bottom:0; + box-shadow: 0 0 1px 0 $color-border inset; } } .fader-wrapper { - padding:20px 15px; + padding:20px 15px 20px 20px ; overflow:hidden; height:100%; width:95px; @@ -483,14 +519,27 @@ width:400px; .xy-wrapper { width:400px; - padding: 10px; - height:100%; + padding: 10px 10px 140px; + height:540px; overflow: hidden; + .value { + margin-top:30px; + width:100%; + } + input { + width:50%; + float:left; + padding-left: 20px; + position: relative; + left:0px; + right:0px; + box-shadow: 0 0 1px 0 $color-border inset; + } } .xy { position:relative; width:100%; - height: 400px; + height: 100%; border:1px solid $color-border; background: $color-bg; overflow: hidden; @@ -542,25 +591,10 @@ width:400px; } - .rgb-wrapper { - .value { - margin-top:30px; - width:100%; - } + input { width:33.33%; - float:left; - padding-left: 20px; - position: relative; - left:0px; - right:0px; - &.r:after { - content:"Rzd"; - display:block; - position: absolute;; - left:0; - } } } diff --git a/lib-dev/js/demo.js b/lib-dev/js/demo.js index d1bf4740..b94382cf 100644 --- a/lib-dev/js/demo.js +++ b/lib-dev/js/demo.js @@ -22,13 +22,18 @@ TABS = { type:'stack', widgets:{ - xBasses: { + Drums: { title:'BassesXXX', range:'db', target:nmPorts['MainMix']+' 127.0.0.1:125', path:'/test2', }, - + xypad_test: { + title:'XY Pad', + type:'rgb', + target:nmPorts['MainMix'], + path:'/pad' + }, xGuitars: { title:'Guitars', range:'db', @@ -65,7 +70,12 @@ TABS = { title:'MainMix', widgets:{ - + xypad_test: { + title:'XY Pad', + type:'rgb', + target:nmPorts['MainMix'], + path:'/pad' + }, Drums: { title:'Drums', range:'db', diff --git a/lib-dev/js/oschtmlgui.js b/lib-dev/js/oschtmlgui.js index 144dbd78..47893057 100644 --- a/lib-dev/js/oschtmlgui.js +++ b/lib-dev/js/oschtmlgui.js @@ -43,15 +43,10 @@ function parsetabs(TABS,parent,sub){ var $tabContent = $(document.createElement('div')).addClass('tab').attr('id',id); - if (tabData.tabs) { - parsetabs(tabData.tabs,parent=$tabContent,sub=true); - } else { - parsewidgets(tabData.widgets,$tabContent) - } $content.append($tabContent); @@ -65,21 +60,24 @@ function parsewidgets(widgets,parent) { var color = widgetData.color?'style="background-color:'+widgetData.color+'"':''; var title = widgetData.title || widgetId; - + var type = widgetData.type || 'fader' widgetData.path = widgetData.path || '/' + widgetId var $widget = $('\ -
\ +
\
'+title+'
\
\ '); - var type = widgetData.type || 'fader' + var widgetInner = createWidget[type](widgetData,parent) widgetInner.type = widgetData.type || 'fader' $widget.append(widgetInner) - __widgets__[widgetId] = widgetInner + if (__widgets__[widgetId]==undefined) { + __widgets__[widgetId] = [] + } + __widgets__[widgetId].push(widgetInner) parent.append($widget); @@ -151,7 +149,10 @@ createWidget.xy = function(widgetData) {
\
\
\ -
\ +
\ + \ + \ +
\
\ '); $widget.xy = $widget.find('.xy') @@ -161,11 +162,13 @@ createWidget.xy = function(widgetData) { containment:'parent' }); + $widget.xy.value = {x:$widget.find('.x'),y:$widget.find('.y')} + $widget.xy.on('drag',function(e, data){ var v = $widget.getValue(); $widget.sendValue(v); - $widget.find('.val').text(v) + $widget.showValue(v) }) widgetData.range = widgetData.range || {x:{min:0,max:1},y:{min:0,max:1}} @@ -181,9 +184,9 @@ createWidget.xy = function(widgetData) { var x = (v[0]-widgetData.range.x.min)/(widgetData.range.x.max-widgetData.range.x.min)*$widget.xy.innerWidth(), y = $widget.xy.innerHeight()-(v[1]-widgetData.range.y.min)/(widgetData.range.y.max-widgetData.range.y.min)*$widget.xy.innerHeight() $widget.xy.handle.css({'top':y+'px','left':x+'px'}) - $widget.find('.val').text($widget.getValue()) - if (send) $widget.xy.sendValue(v); + $widget.showValue(v) + if (send) $widget.sendValue(v); } $widget.sendValue = function(v) { var t = widgetData.target?widgetData.target:defaultTarget, @@ -191,6 +194,10 @@ createWidget.xy = function(widgetData) { sendOsc([t,p,v]); } + $widget.showValue = function(v) { + $widget.xy.value.x.val(v[0]) + $widget.xy.value.y.val(v[1]) + } return $widget; } @@ -198,26 +205,26 @@ createWidget.xy = function(widgetData) { var hsbToRgb = function (hsb) { - var rgb = {}; - var h = hsb.h; - var s = hsb.s*255/100; - var v = hsb.b*255/100; - if(s == 0) { - rgb.r = rgb.g = rgb.b = v; - } else { - var t1 = v; - var t2 = (255-s)*v/255; - var t3 = (t1-t2)*(h%60)/60; - if(h==360) h = 0; - if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3} - else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3} - else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3} - else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3} - else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3} - else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3} - else {rgb.r=0; rgb.g=0; rgb.b=0} - } - return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)}; + var rgb = {}; + var h = hsb.h; + var s = hsb.s*255/100; + var v = hsb.b*255/100; + if(s == 0) { + rgb.r = rgb.g = rgb.b = v; + } else { + var t1 = v; + var t2 = (255-s)*v/255; + var t3 = (t1-t2)*(h%60)/60; + if(h==360) h = 0; + if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3} + else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3} + else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3} + else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3} + else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3} + else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3} + else {rgb.r=0; rgb.g=0; rgb.b=0} + } + return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)}; }; var rgbToHsb = function (rgb) { var hsb = {h: 0, s: 0, b: 0}; @@ -237,6 +244,37 @@ var rgbToHsb = function (rgb) { hsb.b *= 100/255; return hsb; }; + + +// map a value from a scale to another input and output must be range arrays +var mapToScale = function(value,rangeIn,rangeOut) { + + var reverse = false; + if (rangeIn[0]>rangeIn[1]) { + reverse = true; + rangeIn = [rangeIn[1],rangeIn[0]] + } + + var value = Math.max(rangeIn[0],Math.min(parseFloat(value),rangeIn[1])) + + + value = (value/rangeIn[1]-rangeIn[0]) * (rangeOut[1]-rangeOut[0]) + rangeOut[0] + + if (reverse) value = Math.abs(rangeOut[1] - value) + + value = Math.max(rangeOut[0],Math.min(value,rangeOut[1])) + + value = Math.round(value) + return value + +} + + + + + + + createWidget.rgb = function(widgetData) { var $widget = $('\
\ @@ -267,20 +305,33 @@ createWidget.rgb = function(widgetData) { $widget.xy.value = {r:$widget.find('input.r'),g:$widget.find('input.g'),b:$widget.find('input.b')} + $widget.xy.hue.on('drag',function(e, data){ var h = parseFloat($widget.xy.hue.css('left'))/$widget.xy.innerWidth()*360, rgb = hsbToRgb({h:h,s:100,b:100}), v = $widget.getValue(); - console.log(h) + $widget.xy.css('background-color','rgb('+rgb.r+','+rgb.g+','+rgb.b+')') $widget.sendValue(v); $widget.showValue(v); + + $widget.trigger('sync') }) $widget.xy.saturation.on('drag',function(e, data){ var v = $widget.getValue(); $widget.sendValue(v); $widget.showValue(v); + + $widget.trigger('sync') + + }) + $widget.xy.saturation.on('stop',function(e, data){ + var v = $widget.getValue(); + $widget.sendValue(v); + $widget.showValue(v); + + //$widget.trigger('sync') }) @@ -289,16 +340,13 @@ createWidget.rgb = function(widgetData) { $widget.getValue = function() { - var s = parseFloat($widget.xy.saturation.css('left'))/$widget.xy.innerWidth(), - s = widgetData.range.x.min + s *(widgetData.range.x.max - widgetData.range.x.min), - l = 1 - (parseFloat($widget.xy.saturation.css('top'))/$widget.xy.innerHeight()), - l = widgetData.range.y.min + l *(widgetData.range.y.max - widgetData.range.y.min), - h = parseFloat($widget.xy.hue.css('left'))/$widget.xy.innerWidth()*360, + var s = mapToScale($widget.xy.saturation.css('left'),[0,$widget.xy.innerWidth()],[0,100]), + l = mapToScale($widget.xy.saturation.css('top'),[$widget.xy.innerHeight(),0],[0,100]), + h = mapToScale($widget.xy.hue.css('left'),[0,$widget.xy.innerWidth()],[0,360]), rgb = hsbToRgb({h:h,s:s,b:l}) - return [rgb.r,rgb.g,rgb.b] } - $widget.setValue = function(v,send) { + $widget.setValue = function(v,send,sync) { if (v[1]==undefined && v[2]==undefined) var v = [v,v,v] if (v[2]==undefined) var v = [v[0],v[1],v[1]] @@ -309,18 +357,21 @@ createWidget.rgb = function(widgetData) { var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]}) - var s = (hsb.s-widgetData.range.x.min)/(widgetData.range.x.max-widgetData.range.x.min)*$widget.xy.innerWidth(), - l = $widget.xy.innerHeight()-(hsb.b-widgetData.range.y.min)/(widgetData.range.y.max-widgetData.range.y.min)*$widget.xy.innerHeight() - h = hsb.h/360*$widget.xy.innerWidth() + var left = mapToScale(hsb.s,[0,100],[0,$widget.xy.innerWidth()]), + top = mapToScale(hsb.b,[100,0],[0,$widget.xy.innerHeight()]), + leftHue = mapToScale(hsb.h,[0,360],[0,$widget.xy.innerWidth()]) + $widget.xy.saturation.css({'top':top+'px','left':left+'px'}) + $widget.xy.hue.css({'left':leftHue+'px'}) - $widget.xy.saturation.css({'top':l+'px','left':s+'px'}) - $widget.xy.hue.css({'left':h+'px'}) - var rgb = hsbToRgb({h:h,s:100,b:100}) + var rgb = hsbToRgb({h:hsb.h,s:100,b:100}) $widget.xy.css('background-color','rgb('+rgb.r+','+rgb.g+','+rgb.b+')') $widget.showValue(v); + + + if (sync) $widget.trigger('sync'); if (send) $widget.sendValue(v); } $widget.sendValue = function(v) { @@ -339,17 +390,17 @@ createWidget.rgb = function(widgetData) { $widget.xy.value.r.change(function(){ if (!0<=$(this).val()<=255) {$(this).val(Math.min(255,Math.max(0,$(this).val())))} var v = $widget.getValue() - $widget.setValue([$(this).val(),v[1],v[2]],true) + $widget.setValue([$(this).val(),v[1],v[2]],true,true) }) $widget.xy.value.g.change(function(){ if (!0<=$(this).val()<=255) {$(this).val(Math.min(255,Math.max(0,$(this).val())))} var v = $widget.getValue() - $widget.setValue([v[0],$(this).val(),v[2]],true) + $widget.setValue([v[0],$(this).val(),v[2]],true,true) }) $widget.xy.value.b.change(function(){ if (!0<=$(this).val()<=255) {$(this).val(Math.min(255,Math.max(0,$(this).val())))} var v = $widget.getValue() - $widget.setValue([v[0],v[1],$(this).val()],true) + $widget.setValue([v[0],v[1],$(this).val()],true,true) }) @@ -420,20 +471,28 @@ createWidget.fader = function(widgetData,parent) { }) .Link('lower').to($widget.find('input')) .on('slide',function(){ - if (!$widget.lock) {$widget.sendValue()} + + if (!$widget.lock) { + $widget.sendValue(); + } }) .on('set',function(){ - if (!$widget.lock) {$widget.sendValue()} + if (!$widget.lock) { + $widget.sendValue(); + $widget.trigger('sync') + } }); $widget.getValue = function(v,send){ return $widget.fader.val(); } - $widget.setValue = function(v,send){ + $widget.setValue = function(v,send,sync){ if (!send) {$widget.lock=true} $widget.fader.val(v); + if (sync) $widget.trigger('sync') $widget.lock=false; + } $widget.sendValue = function(){ var t = widgetData.target?widgetData.target:defaultTarget, @@ -452,34 +511,37 @@ createWidget.fader = function(widgetData,parent) { - - parsetabs(TABS,false,false) +// Widget Synchronization : widget that share the same id will update each other +// without sending any extra osc message (they must be of the same type as well) +$.each(__widgets__,function(i,widget) { + if (widget.length>1) { + var script =''; + for (j in widget) { + // Oh dear this looks hacky + // I didn't manage to cross-bind all widgets together the usual way + // ( getValue() always returns the last element's value, maybe a scope problem) - - - - - - - - - -// Synchronize faders that share the same widgetId -$(".fader").each(function(){ - $(".fader[widgetId='"+$(this).attr('widgetId')+"']").not(this).Link('lower').to($(this), crossUpdate); -}).removeClass('locked'); -function crossUpdate ( value, handle, slider ) { - $(this).val( value ); -} - - + script += ' \n\ + widget['+j+'].on(\'sync\',function(){ \n\ + var v = widget['+j+'].getValue() \n\ + for (k=0;k