@grame/faust-ui 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -184,7 +184,8 @@ declare abstract class AbstractItem<T extends FaustUIItemStyle> extends Abstract
184
184
  */
185
185
  constructor(props?: FaustUIItemProps<T>);
186
186
  /**
187
- * Get a nearest valid number
187
+ * Get a nearest valid number. An entry of a menu or a radio is valid as
188
+ * written, even off the step grid: the C++ GUIs send it unchanged.
188
189
  */
189
190
  toValidNumber(value: number): number;
190
191
  /**
@@ -399,6 +400,8 @@ export interface FaustUIRadioStyle extends FaustUIItemStyle {
399
400
  bordercolor?: string;
400
401
  labelcolor?: string;
401
402
  textcolor?: string;
403
+ /** "horizontal" for a radio made from an hslider, "vertical" otherwise. */
404
+ direction?: "horizontal" | "vertical";
402
405
  }
403
406
  declare class Radio extends AbstractItem<FaustUIRadioStyle> {
404
407
  static get defaultProps(): FaustUIItemProps<FaustUIRadioStyle>;
@@ -510,6 +513,7 @@ declare abstract class AbstractItem$1 implements IItem {
510
513
  type: FaustUIInputType | FaustUIOutputType;
511
514
  label: string;
512
515
  address: string;
516
+ shortname: string;
513
517
  url: string;
514
518
  index: number;
515
519
  init: number;
package/dist/index.js CHANGED
@@ -701,12 +701,18 @@ ___CSS_LOADER_EXPORT___.push([module.id, `.faust-ui-component.faust-ui-component
701
701
  padding: 2px 4px;
702
702
  width: calc(100% - 8px);
703
703
  overflow: auto;
704
+ display: flex;
705
+ flex-direction: column;
706
+ }
707
+ .faust-ui-component.faust-ui-component-radio > .faust-ui-component-radio-group.faust-ui-component-radio-group-horizontal {
708
+ flex-direction: row;
709
+ justify-content: space-around;
704
710
  }
705
711
  .faust-ui-component.faust-ui-component-radio > .faust-ui-component-radio-group > div {
706
712
  text-overflow: ellipsis;
707
713
  white-space: nowrap;
708
714
  overflow: hidden;
709
- }`, "",{"version":3,"sources":["webpack://./src/components/Radio.scss"],"names":[],"mappings":"AAAA;EACI,mBAAA;AACJ;AAAI;EACI,cAAA;EACA,gBAAA;AAER;AAAI;EACI,cAAA;EACA,mBAAA;EACA,iBAAA;EACA,kBAAA;EACA,gBAAA;EACA,uBAAA;EACA,cAAA;AAER;AADQ;EACI,uBAAA;EACA,mBAAA;EACA,gBAAA;AAGZ","sourcesContent":[".faust-ui-component.faust-ui-component-radio {\n align-items: center;\n & > .faust-ui-component-label {\n flex: 0 0 auto;\n margin-top: auto;\n }\n & > .faust-ui-component-radio-group {\n flex: 0 1 auto;\n margin-bottom: auto;\n border-width: 1px;\n border-radius: 4px;\n padding: 2px 4px;\n width: calc(100% - 8px);\n overflow: auto;\n & > div {\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n }\n }\n}"],"sourceRoot":""}]);
715
+ }`, "",{"version":3,"sources":["webpack://./src/components/Radio.scss"],"names":[],"mappings":"AAAA;EACI,mBAAA;AACJ;AAAI;EACI,cAAA;EACA,gBAAA;AAER;AAAI;EACI,cAAA;EACA,mBAAA;EACA,iBAAA;EACA,kBAAA;EACA,gBAAA;EACA,uBAAA;EACA,cAAA;EACA,aAAA;EACA,sBAAA;AAER;AADQ;EACI,mBAAA;EACA,6BAAA;AAGZ;AADQ;EACI,uBAAA;EACA,mBAAA;EACA,gBAAA;AAGZ","sourcesContent":[".faust-ui-component.faust-ui-component-radio {\n align-items: center;\n & > .faust-ui-component-label {\n flex: 0 0 auto;\n margin-top: auto;\n }\n & > .faust-ui-component-radio-group {\n flex: 0 1 auto;\n margin-bottom: auto;\n border-width: 1px;\n border-radius: 4px;\n padding: 2px 4px;\n width: calc(100% - 8px);\n overflow: auto;\n display: flex;\n flex-direction: column;\n &.faust-ui-component-radio-group-horizontal {\n flex-direction: row;\n justify-content: space-around;\n }\n & > div {\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n }\n }\n}"],"sourceRoot":""}]);
710
716
  // Exports
711
717
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___);
712
718
 
@@ -1492,10 +1498,12 @@ const _AbstractItem = class _AbstractItem extends _AbstractComponent__WEBPACK_IM
1492
1498
  if (this.state.emitter) this.state.emitter.register(this.state.address, this);
1493
1499
  }
1494
1500
  /**
1495
- * Get a nearest valid number
1501
+ * Get a nearest valid number. An entry of a menu or a radio is valid as
1502
+ * written, even off the step grid: the C++ GUIs send it unchanged.
1496
1503
  */
1497
1504
  toValidNumber(value) {
1498
- const { min, max, step } = this.state;
1505
+ const { min, max, step, enums } = this.state;
1506
+ if (enums && Object.values(enums).includes(value)) return value;
1499
1507
  if (typeof min !== "number" || typeof max !== "number") return value;
1500
1508
  const v = Math.min(max, Math.max(min, value));
1501
1509
  if (!step) return v;
@@ -1651,7 +1659,7 @@ const _AbstractItem = class _AbstractItem extends _AbstractComponent__WEBPACK_IM
1651
1659
  static getDistance(state) {
1652
1660
  const { type, max, min, value, enums, scale } = state;
1653
1661
  if (type === "enum") return value / (_AbstractItem.enumSteps(enums) || 1);
1654
- const v = scale === "exp" ? (0,_utils__WEBPACK_IMPORTED_MODULE_1__.normLog)(value, min, max) : scale === "log" ? (0,_utils__WEBPACK_IMPORTED_MODULE_1__.normExp)(value, min, max) : value;
1662
+ const v = scale === "exp" ? (0,_utils__WEBPACK_IMPORTED_MODULE_1__.iNormExp)(value, min, max) : scale === "log" ? (0,_utils__WEBPACK_IMPORTED_MODULE_1__.iNormLog)(value, min, max) : value;
1655
1663
  return (0,_utils__WEBPACK_IMPORTED_MODULE_1__.normalize)(v, min, max);
1656
1664
  }
1657
1665
  /**
@@ -1844,6 +1852,25 @@ __webpack_require__.r(__webpack_exports__);
1844
1852
  /* harmony import */ var _VBargraph__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./VBargraph */ "./src/components/VBargraph.ts");
1845
1853
  /* harmony import */ var _layout_Layout__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../layout/Layout */ "./src/layout/Layout.ts");
1846
1854
  /* harmony import */ var _Group_scss__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./Group.scss */ "./src/components/Group.scss");
1855
+ var __defProp = Object.defineProperty;
1856
+ var __defProps = Object.defineProperties;
1857
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1858
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1859
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1860
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1861
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1862
+ var __spreadValues = (a, b) => {
1863
+ for (var prop in b || (b = {}))
1864
+ if (__hasOwnProp.call(b, prop))
1865
+ __defNormalProp(a, prop, b[prop]);
1866
+ if (__getOwnPropSymbols)
1867
+ for (var prop of __getOwnPropSymbols(b)) {
1868
+ if (__propIsEnum.call(b, prop))
1869
+ __defNormalProp(a, prop, b[prop]);
1870
+ }
1871
+ return a;
1872
+ };
1873
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1847
1874
 
1848
1875
 
1849
1876
 
@@ -1992,7 +2019,7 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
1992
2019
  if (type === "soundfile") return new _Soundfile__WEBPACK_IMPORTED_MODULE_4__["default"](props);
1993
2020
  if (type === "knob") return new _Knob__WEBPACK_IMPORTED_MODULE_7__["default"](props);
1994
2021
  if (type === "menu") return new _Menu__WEBPACK_IMPORTED_MODULE_8__["default"](props);
1995
- if (type === "radio") return new _Radio__WEBPACK_IMPORTED_MODULE_9__["default"](props);
2022
+ if (type === "radio") return new _Radio__WEBPACK_IMPORTED_MODULE_9__["default"](__spreadProps(__spreadValues({}, props), { style: __spreadProps(__spreadValues({}, props.style), { direction: ioItem.type === "hslider" ? "horizontal" : "vertical" }) }));
1996
2023
  if (type === "hslider") return new _HSlider__WEBPACK_IMPORTED_MODULE_1__["default"](props);
1997
2024
  if (type === "vslider") return new _VSlider__WEBPACK_IMPORTED_MODULE_2__["default"](props);
1998
2025
  if (type === "hbargraph") return new _HBargraph__WEBPACK_IMPORTED_MODULE_12__["default"](props);
@@ -3005,8 +3032,10 @@ class Radio extends _AbstractItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
3005
3032
  }
3006
3033
  };
3007
3034
  this.setStyle = () => {
3008
- const { height, width, grid, fontsize, textcolor, bgcolor, bordercolor } = this.state.style;
3009
- const fontSize = Math.min(height * grid * 0.1, width * grid * 0.1);
3035
+ const { height, width, grid, fontsize, textcolor, bgcolor, bordercolor, direction } = this.state.style;
3036
+ const horizontal = direction === "horizontal";
3037
+ const fontSize = horizontal ? Math.min(height * grid * 0.25, width * grid * 0.1) : Math.min(height * grid * 0.1, width * grid * 0.1);
3038
+ this.group.classList.toggle("faust-ui-component-radio-group-horizontal", horizontal);
3010
3039
  this.group.style.backgroundColor = bgcolor;
3011
3040
  this.group.style.borderColor = bordercolor;
3012
3041
  this.group.style.color = textcolor;
@@ -3023,7 +3052,8 @@ class Radio extends _AbstractItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
3023
3052
  bgcolor: "rgba(255, 255, 255, 0.25)",
3024
3053
  bordercolor: "rgba(80, 80, 80, 0)",
3025
3054
  labelcolor: "rgba(226, 222, 255, 0.5)",
3026
- textcolor: "rgba(18, 18, 18, 1)"
3055
+ textcolor: "rgba(18, 18, 18, 1)",
3056
+ direction: "vertical"
3027
3057
  })
3028
3058
  });
3029
3059
  }
@@ -3606,8 +3636,21 @@ const iNormLog = (vIn, min, max) => {
3606
3636
  const normalized = normalize(vLog, logMin, logMax);
3607
3637
  return denormalize(normalized, min, max);
3608
3638
  };
3609
- const normExp = iNormLog;
3610
- const iNormExp = normLog;
3639
+ const cappedExp = (x) => Math.min(Number.MAX_VALUE, Math.exp(x));
3640
+ const normExp = (x, min, max) => {
3641
+ const eMin = cappedExp(min);
3642
+ const eMax = cappedExp(max);
3643
+ if (!(eMax > eMin)) return Math.max(min, Math.min(max, x));
3644
+ const v = Math.log(denormalize(normalize(x, min, max), eMin, eMax));
3645
+ return Math.max(min, Math.min(max, v));
3646
+ };
3647
+ const iNormExp = (vIn, min, max) => {
3648
+ const eMin = cappedExp(min);
3649
+ const eMax = cappedExp(max);
3650
+ const v = Math.max(min, Math.min(max, vIn));
3651
+ if (!(eMax > eMin)) return v;
3652
+ return denormalize(normalize(cappedExp(v), eMin, eMax), min, max);
3653
+ };
3611
3654
  const roundedRect = (ctx, x, y, width, height, radius) => {
3612
3655
  const radii = [0, 0, 0, 0];
3613
3656
  if (typeof radius === "number") radii.fill(radius);
@@ -4256,13 +4299,23 @@ __webpack_require__.r(__webpack_exports__);
4256
4299
  class Radio extends _AbstractInputItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
4257
4300
  constructor() {
4258
4301
  super(...arguments);
4259
- this.layout = {
4260
- type: "radio",
4261
- width: 2,
4262
- height: 2,
4263
- // TODO: vradio and hradio
4264
- sizing: "both"
4265
- };
4302
+ /**
4303
+ * A radio menu takes the orientation of its slider, as the Faust manual
4304
+ * states: an `hslider` lays its buttons out in a row, one grid unit per
4305
+ * entry, a `vslider` or an `nentry` in a column.
4306
+ */
4307
+ this.layout = this.type === "hslider" ? { type: "radio", width: Math.max(2, Radio.countEntries(this.meta)), height: 1, sizing: "horizontal" } : { type: "radio", width: 2, height: 2, sizing: "both" };
4308
+ }
4309
+ /**
4310
+ * Number of entries in the `radio{...}` style meta.
4311
+ */
4312
+ static countEntries(meta = []) {
4313
+ var _a;
4314
+ const style = ((_a = meta.find((m) => {
4315
+ var _a2;
4316
+ return (_a2 = m.style) == null ? void 0 : _a2.startsWith("radio");
4317
+ })) == null ? void 0 : _a.style) || "";
4318
+ return (style.match(/'[^']*'\s*:/g) || []).length;
4266
4319
  }
4267
4320
  }
4268
4321