diff --git a/app/config.json b/app/config.json index bc55b4b0..a9b7fb2f 100644 --- a/app/config.json +++ b/app/config.json @@ -3,6 +3,7 @@ "sessionPath": "/home/bordun/oscwork/oschtmlgui/sessions/", "recentSessions": [ "/home/bordun/oscwork/oschtmlgui/sessions/demo.js", + "/home/bordun/oscwork/oschtmlgui/sessions/knob.js", "/home/bordun/oscwork/oschtmlgui/sessions/demo-full.js", "/home/bordun/oscwork/oschtmlgui/sessions/xy.js", "/home/bordun/oscwork/oschtmlgui/sessions/fadertest.js", diff --git a/browser/css/style.scss b/browser/css/style.scss index 9f7e31c4..80e764f2 100644 --- a/browser/css/style.scss +++ b/browser/css/style.scss @@ -863,8 +863,7 @@ a { .fader-wrapper-outer { padding-bottom:30px; overflow:hidden; - height:100%; - width:100%; + // height:100%; position: relative; input { position:absolute; @@ -987,3 +986,61 @@ a { } } + + +.knob-wrapper-outer { + padding-bottom:30px; + overflow:hidden; + width:100%; + position: relative; + input { + position:absolute; + bottom:0; + box-shadow: 0 0 1px 0 $color-border inset; + } +} +.knob-wrapper { + padding:20px 20px 20px 20px ; + overflow:hidden; + //height:100%; + width:120px; + position: relative; + + .knob { + width:100%; + padding-bottom:100%; + border-radius:100%; + position: relative; + background: $color-bg; + box-shadow: 0 0 0 2px $color-border; + &:after { + content:""; + position:absolute; + width:4px; + height:4px; + border-radius:100%; + left:50%; + margin-left:-3px; + bottom:4px; + border:1px solid $color-border; + background:$color-accent + } + } + .pip { + position:absolute; + font-size:11px; + color:#ccc; + &.min { + bottom:10px; + right:50%; + margin-right:35px; + text-align:right; + } + &.max { + bottom:10px; + left:50%; + margin-left:35px; + text-align:left; + } + } +} diff --git a/browser/js/app/widgets.js b/browser/js/app/widgets.js index 08154be8..cb5ce28c 100644 --- a/browser/js/app/widgets.js +++ b/browser/js/app/widgets.js @@ -453,7 +453,7 @@ createWidget.fader = function(widgetData,parent){ },{ relative:true }); - widgetData.range = widgetData.range || {'min':0,'100%':1} + widgetData.range = widgetData.range || {'min':0,'max':1} widgetData.range = (widgetData.range=='db')?{'min': -70,'20%': -40,'45%': -20,'60%': -10,'71%':-6,'78%':-3,'85%':0,'92%':3,'max': 6}:widgetData.range; @@ -536,3 +536,85 @@ createWidget.fader = function(widgetData,parent){ return widget } + +// get rotation plugin (@Ivo Renkema) + +$.fn.getRotation = function () { + var matrix = this.css("transform") + if(typeof matrix === 'string' && matrix !== 'none') { + var values = matrix.split('(')[1].split(')')[0].split(','); + var a = values[0]; + var b = values[1]; + var angle = Math.round(Math.atan2(b, a) * (180/Math.PI)); + } else { var angle = 0; } + if (angle<0) angle = 360+angle + return angle; +}; + + +createWidget.knob = function(widgetData,parent) { + var widget = $('\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ + \ +
\ + '), + knob = widget.find('.knob'), + input = widget.find('input'), + range = widgetData.range || {min:0,max:1} + + + widget.find('.pip.min').text(range.min) + widget.find('.pip.max').text(range.max) + + knob.css('transform','rotate(45deg)').drag('init',function(){ + offR = knob.getRotation() + }) + + knob.drag(function( ev, dd ){ + var r = clip(-dd.deltaY+offR,[45,315]) + knob.css('transform', 'rotateZ('+r+'deg)') + + var v = widget.getValue() + + widget.sendValue(v); + widget.trigger('sync') + widget.showValue(v) + + },{ relative:true }); + + + widget.getValue = function() { + return mapToScale(knob.getRotation(),[45,315],[range.min,range.max]) + } + widget.showValue = function(v) { + input.val(v) + } + widget.sendValue = function(v) { + var t = widgetData.target, + p = widgetData.path + sendOsc([t,p,v]); + } + widget.setValue = function(v,send,sync) { + var r = mapToScale(v,[range.min,range.max],[45,315]) + + knob.css('transform', 'rotateZ('+r+'deg)') + var v = widget.getValue() || v + + widget.showValue(v); + + if (sync) widget.trigger('sync'); + if (send) widget.sendValue(v); + } + input.change(function(){ + widget.setValue(input.val(),true,true) + }) + + widget.setValue(range.min) + return widget +} diff --git a/sessions/demo.js b/sessions/demo.js index af7dd697..6f4df346 100644 --- a/sessions/demo.js +++ b/sessions/demo.js @@ -19,16 +19,16 @@ TABS = { testingshits: { widgets:{ BassesXXX: { - type:'switch', + type:'knob', target:'localhost:6666', path:'/osc/path/', color:'#555522', - values:[-70,-10,0] + range:{min:-70,max:6} }, stacktest: { type:'stack', widgets:{ - switchtest: { + BassesXXX: { type:'switch', target:'localhost:6666', path:'/osc/path/',