diff --git a/CHANGELOG.md b/CHANGELOG.md index 90d4b789..4df3afeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - bug fixes - bottom horizontal scrollbar not responding on small screens +- widgets + - `logScale` can be set to a number to use a logarithm base different from the default ## 0.45.5 diff --git a/src/client/app/widgets/pads/multixy.js b/src/client/app/widgets/pads/multixy.js index 2830ff01..14249c3a 100644 --- a/src/client/app/widgets/pads/multixy.js +++ b/src/client/app/widgets/pads/multixy.js @@ -38,8 +38,8 @@ module.exports = class MultiXy extends Pad { pips: {type: 'boolean', value: true, help: 'Set to `false` to hide the scale'}, rangeX: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the x axis'}, rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'}, - logScaleX: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (log10)'}, - logScaleY: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (log10)'} + logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'}, + logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'} }, [], { diff --git a/src/client/app/widgets/pads/xy.js b/src/client/app/widgets/pads/xy.js index 8a403273..7488f60b 100644 --- a/src/client/app/widgets/pads/xy.js +++ b/src/client/app/widgets/pads/xy.js @@ -29,8 +29,8 @@ module.exports = class Xy extends Pad { pips: {type: 'boolean', value: true, help: 'Set to `false` to hide the scale'}, rangeX: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the x axis'}, rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'}, - logScaleX: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (log10)'}, - logScaleY: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (log10)'}, + logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'}, + logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'}, input: {type: 'boolean', value: true, help: 'Set to false to hide the built-in input widget'}, doubleTap: {type: 'boolean|string', value: false, help: [ 'Set to `true` to make the fader reset to its default value when receiving a double tap.', diff --git a/src/client/app/widgets/plots/eq.js b/src/client/app/widgets/plots/eq.js index 876314b0..787ece70 100644 --- a/src/client/app/widgets/plots/eq.js +++ b/src/client/app/widgets/plots/eq.js @@ -20,7 +20,7 @@ module.exports = class Eq extends _plots_base { resolution: {type: 'number', value: 128, help: 'Defines the number of points used to compute the frequency response'}, rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'}, origin: {type: 'number|boolean', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it'}, - logScaleX: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (log10)'}, + logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'}, smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'}, }, ['target', 'precision', 'bypass'], { diff --git a/src/client/app/widgets/plots/led.js b/src/client/app/widgets/plots/led.js index 3b0b6540..b22eba36 100644 --- a/src/client/app/widgets/plots/led.js +++ b/src/client/app/widgets/plots/led.js @@ -11,7 +11,7 @@ module.exports = class Led extends Widget { _led:'led', range: {type: 'object', value: {min:0,max:1}, help: 'Value to led intensity mapping range'}, - logScale: {type: 'boolean', value: false, help: 'Set to `true` to use a logarithmic mapping scale)'}, + logScale: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale (base 10). Set to a `number` to define the logarithm\'s base.'}, }, ['target', 'precision', 'bypass'], {}) diff --git a/src/client/app/widgets/plots/plot.js b/src/client/app/widgets/plots/plot.js index 1c324f1b..cc62baf0 100644 --- a/src/client/app/widgets/plots/plot.js +++ b/src/client/app/widgets/plots/plot.js @@ -17,8 +17,8 @@ module.exports = class Plot extends _plots_base { rangeX: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the x axis'}, rangeY: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'}, - logScaleX: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (log10)'}, - logScaleY: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (log10)'}, + logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'}, + logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'}, origin: {type: 'number', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it.'}, dots: {type: 'boolean', value: true, help: ''}, bars: {type: 'boolean', value: false, help: 'Set to `true` to use draw bars instead (disables `logScaleX` and forces `x axis` even spacing)'}, diff --git a/src/client/app/widgets/plots/visualizer.js b/src/client/app/widgets/plots/visualizer.js index 51724e7b..a3bef5fe 100644 --- a/src/client/app/widgets/plots/visualizer.js +++ b/src/client/app/widgets/plots/visualizer.js @@ -18,7 +18,7 @@ module.exports = class Visualizer extends _plots_base { duration: {type: 'number', value: 1, help: 'Defines visualization duration in seconds'}, range: {type: 'object', value: {min:0,max:1}, help: 'Defines the min and max values for the y axis'}, origin: {type: 'number', value: 'auto', help: 'Defines the y axis origin. Set to `false` to disable it'}, - logScale: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale for the y axis'}, + logScale: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'}, smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'}, pips:{type: 'boolean', value: true, help: 'Set to `false` to hide the scale'}, diff --git a/src/client/app/widgets/sliders/fader.js b/src/client/app/widgets/sliders/fader.js index d41464c1..39cf37ee 100644 --- a/src/client/app/widgets/sliders/fader.js +++ b/src/client/app/widgets/sliders/fader.js @@ -40,7 +40,7 @@ module.exports = class Fader extends Slider { '- `number`: define a number of evenly spaced steps', '- `array`: use arbitrary values', ]}, - logScale: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale'}, + logScale: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale (base 10). Set to a `number` to define the logarithm\'s base.'}, unit: {type: 'string', value: '', help: 'Unit will be appended to the displayed widget\'s value (it doesn\'t affect osc messages)'}, origin: {type: 'number', value: 'auto', help: 'Defines the starting point\'s value of the fader\'s gauge'}, diff --git a/src/client/app/widgets/sliders/knob.js b/src/client/app/widgets/sliders/knob.js index a2ac7711..a885431f 100644 --- a/src/client/app/widgets/sliders/knob.js +++ b/src/client/app/widgets/sliders/knob.js @@ -31,7 +31,7 @@ module.exports = class Knob extends Slider { '- `number`: define a number of evenly spaced steps', '- `array`: use arbitrary values', ]}, - logScale: {type: 'boolean', value: false, help: 'Set to `true` to use logarithmic scale'}, + logScale: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale (base 10). Set to a `number` to define the logarithm\'s base.'}, unit: {type: 'string', value: '', help: 'Unit will be appended to the displayed widget\'s value (it doesn\'t affect osc messages)'}, origin: {type: 'number', value: 'auto', help: 'Defines the starting point\'s value of the knob\'s gauge'}, diff --git a/src/client/app/widgets/utils.js b/src/client/app/widgets/utils.js index 07c8b0b8..1b101c49 100644 --- a/src/client/app/widgets/utils.js +++ b/src/client/app/widgets/utils.js @@ -12,19 +12,29 @@ module.exports = { // map a value from a scale to another input and output must be range arrays mapToScale: function(value,rangeIn,rangeOut,precision,log,revertlog) { + // clip in value = module.exports.clip(value,[rangeIn[0],rangeIn[1]]) - value = log ? - revertlog ? - (Math.pow(10,((value-rangeIn[0])/(rangeIn[1]-rangeIn[0])))/9-1/9) * (rangeOut[1]-rangeOut[0]) + rangeOut[0] - :Math.log10(((value-rangeIn[0])/(rangeIn[1]-rangeIn[0]))*9+1) * (rangeOut[1]-rangeOut[0]) + rangeOut[0] - :((value-rangeIn[0])/(rangeIn[1]-rangeIn[0])) * (rangeOut[1]-rangeOut[0]) + rangeOut[0] + // normalize + value = (value - rangeIn[0]) / (rangeIn[1] - rangeIn[0]) - value = Math.max(Math.min(rangeOut[0],rangeOut[1]),Math.min(value,Math.max(rangeOut[0],rangeOut[1]))) + // log scale + if (log) { + if (log === true) log = 10 + value = revertlog ? + Math.pow(log, value) / (log - 1) - 1 / (log - 1) : + Math.log(value * (log - 1) + 1) / Math.log(log) + } + // scale out + value = value * (rangeOut[1] - rangeOut[0]) + rangeOut[0] + + // clip out + value = module.exports.clip(value,[rangeOut[0],rangeOut[1]]) + + // precision if (precision !== false) value = parseFloat(value.toFixed(precision)) - return value },