@grame/faustwasm 0.0.64 → 0.0.65

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/README.md CHANGED
@@ -81,6 +81,16 @@ node scripts/faust2svg.js test/mono.dsp test/out
81
81
 
82
82
  The main diagram should be in `test/out/process.svg`.
83
83
 
84
+ #### Compile a Faust DSP in a Cmajor file
85
+
86
+ For example:
87
+ ```bash
88
+ rm -rf test/out # make sure you are under the faustwasm directory.
89
+ node scripts/faust2cmajor.js test/organ.dsp test/out
90
+ ```
91
+
92
+ The Cmajor file should be in `test/out/organ.cmajor`.
93
+
84
94
  #### Generate or process audio files
85
95
 
86
96
  Options:
@@ -458,7 +458,7 @@ const _AbstractItem = class extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_
458
458
  const stateValue = newState[stateKey];
459
459
  if (stateKey === "style") {
460
460
  for (const styleKey in newState.style) {
461
- if (styleKey in this.state.style && this.state.style[styleKey] !== newState.style[styleKey]) {
461
+ if (styleKey in this.state.style) {
462
462
  this.state.style[styleKey] = newState.style[styleKey];
463
463
  shouldUpdate = true;
464
464
  }
@@ -495,13 +495,17 @@ const _AbstractItem = class extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_
495
495
  const color = this.state.style.labelcolor;
496
496
  const ctx = this.labelCtx;
497
497
  const canvas = this.labelCanvas;
498
+ const ratio = window.devicePixelRatio || 1;
498
499
  let { width, height } = this.label.getBoundingClientRect();
499
500
  if (!width || !height)
500
501
  return this;
501
502
  width = Math.floor(width);
502
503
  height = Math.floor(height);
503
- canvas.height = height;
504
- canvas.width = width;
504
+ const scaledWidth = Math.floor(width * ratio);
505
+ const scaledHeight = Math.floor(height * ratio);
506
+ canvas.width = scaledWidth;
507
+ canvas.height = scaledHeight;
508
+ ctx.scale(ratio, ratio);
505
509
  ctx.clearRect(0, 0, width, height);
506
510
  ctx.fillStyle = color;
507
511
  ctx.textBaseline = "middle";
@@ -748,7 +752,8 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
748
752
  this.children = [];
749
753
  const { style, type, items, emitter, isRoot } = this.state;
750
754
  const { grid, left, top, width, height } = style;
751
- this.label.style.height = `${grid * 0.3}px`;
755
+ if (!this.state.isRoot)
756
+ this.label.style.height = `${grid * 0.3}px`;
752
757
  this.container.style.left = `${left * grid}px`;
753
758
  this.container.style.top = `${top * grid}px`;
754
759
  this.container.style.width = `${width * grid}px`;
@@ -903,7 +908,7 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
903
908
  if (stateKey === "style") {
904
909
  for (const key2 in newState.style) {
905
910
  const styleKey = key2;
906
- if (styleKey in this.state.style && this.state.style[styleKey] !== newState.style[styleKey]) {
911
+ if (styleKey in this.state.style) {
907
912
  this.state.style[styleKey] = newState.style[styleKey];
908
913
  shouldUpdate = true;
909
914
  }
@@ -921,26 +926,34 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
921
926
  this.container = document.createElement("div");
922
927
  this.tabs = document.createElement("div");
923
928
  this.tabs.className = "faust-ui-tgroup-tabs";
924
- this.label = document.createElement("div");
925
- this.label.className = "faust-ui-group-label";
926
- this.labelCanvas = document.createElement("canvas");
927
- this.labelCtx = this.labelCanvas.getContext("2d");
929
+ if (!this.state.isRoot) {
930
+ this.label = document.createElement("div");
931
+ this.label.className = "faust-ui-group-label";
932
+ this.labelCanvas = document.createElement("canvas");
933
+ this.labelCtx = this.labelCanvas.getContext("2d");
934
+ }
928
935
  this.updateUI();
929
936
  this.children.forEach((item) => item.componentWillMount());
930
937
  return this;
931
938
  }
932
939
  paintLabel() {
940
+ if (this.state.isRoot)
941
+ return this;
933
942
  const label = this.state.label;
934
943
  const color = this.state.style.labelcolor;
935
944
  const ctx = this.labelCtx;
936
945
  const canvas = this.labelCanvas;
946
+ const ratio = window.devicePixelRatio || 1;
937
947
  let { width, height } = this.label.getBoundingClientRect();
938
948
  if (!width || !height)
939
949
  return this;
940
950
  width = Math.floor(width);
941
951
  height = Math.floor(height);
942
- canvas.height = height;
943
- canvas.width = width;
952
+ const scaledWidth = Math.floor(width * ratio);
953
+ const scaledHeight = Math.floor(height * ratio);
954
+ canvas.width = scaledWidth;
955
+ canvas.height = scaledHeight;
956
+ ctx.scale(ratio, ratio);
944
957
  ctx.clearRect(0, 0, width, height);
945
958
  ctx.fillStyle = color;
946
959
  ctx.textBaseline = "middle";
@@ -950,8 +963,10 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
950
963
  return this;
951
964
  }
952
965
  mount() {
953
- this.label.appendChild(this.labelCanvas);
954
- this.container.appendChild(this.label);
966
+ if (!this.state.isRoot) {
967
+ this.label.appendChild(this.labelCanvas);
968
+ this.container.appendChild(this.label);
969
+ }
955
970
  if (this.tabs.children.length)
956
971
  this.container.appendChild(this.tabs);
957
972
  this.children.forEach((item) => {
@@ -963,7 +978,8 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
963
978
  componentDidMount() {
964
979
  const handleResize = () => {
965
980
  const { grid, left, top, width, height } = this.state.style;
966
- this.label.style.height = `${grid * 0.3}px`;
981
+ if (!this.state.isRoot)
982
+ this.label.style.height = `${grid * 0.3}px`;
967
983
  this.container.style.width = `${width * grid}px`;
968
984
  this.container.style.height = `${height * grid}px`;
969
985
  this.container.style.left = `${left * grid}px`;
@@ -1036,11 +1052,15 @@ class HBargraph extends _VBargraph__WEBPACK_IMPORTED_MODULE_1__["default"] {
1036
1052
  const { type, max, min, enums, scale, value } = this.state;
1037
1053
  const ctx = this.ctx;
1038
1054
  const canvas = this.canvas;
1055
+ const ratio = window.devicePixelRatio || 1;
1039
1056
  let { width, height } = this.canvasDiv.getBoundingClientRect();
1040
1057
  width = Math.floor(width);
1041
1058
  height = Math.floor(height);
1042
- canvas.width = width;
1043
- canvas.height = height;
1059
+ const scaledWidth = Math.floor(width * ratio);
1060
+ const scaledHeight = Math.floor(height * ratio);
1061
+ canvas.width = scaledWidth;
1062
+ canvas.height = scaledHeight;
1063
+ ctx.scale(ratio, ratio);
1044
1064
  const drawWidth = width * 0.9;
1045
1065
  const drawHeight = barwidth || Math.min(height / 3, drawWidth * 0.05);
1046
1066
  const left = width * 0.05;
@@ -1148,11 +1168,15 @@ class HSlider extends _VSlider__WEBPACK_IMPORTED_MODULE_1__["default"] {
1148
1168
  const ctx = this.ctx;
1149
1169
  const canvas = this.canvas;
1150
1170
  const distance = this.distance;
1171
+ const ratio = window.devicePixelRatio || 1;
1151
1172
  let { width, height } = this.canvasDiv.getBoundingClientRect();
1152
1173
  width = Math.floor(width);
1153
1174
  height = Math.floor(height);
1154
- canvas.width = width;
1155
- canvas.height = height;
1175
+ const scaledWidth = Math.floor(width * ratio);
1176
+ const scaledHeight = Math.floor(height * ratio);
1177
+ canvas.width = scaledWidth;
1178
+ canvas.height = scaledHeight;
1179
+ ctx.scale(ratio, ratio);
1156
1180
  const drawWidth = width * 0.9;
1157
1181
  const drawHeight = sliderwidth || Math.min(height / 3, drawWidth * 0.05);
1158
1182
  const left = width * 0.05;
@@ -1236,11 +1260,15 @@ class Knob extends _AbstractItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
1236
1260
  const ctx = this.ctx;
1237
1261
  const canvas = this.canvas;
1238
1262
  const distance = this.distance;
1263
+ const ratio = window.devicePixelRatio || 1;
1239
1264
  let { width, height } = this.canvas.getBoundingClientRect();
1240
1265
  width = Math.floor(width);
1241
1266
  height = Math.floor(height);
1242
- canvas.width = width;
1243
- canvas.height = height;
1267
+ const scaledWidth = Math.floor(width * ratio);
1268
+ const scaledHeight = Math.floor(height * ratio);
1269
+ canvas.width = scaledWidth;
1270
+ canvas.height = scaledHeight;
1271
+ ctx.scale(ratio, ratio);
1244
1272
  const start = 5 / 8 * Math.PI;
1245
1273
  const end = 19 / 8 * Math.PI;
1246
1274
  const valPos = start + (0,_utils__WEBPACK_IMPORTED_MODULE_1__.toRad)(distance * 315);
@@ -1422,9 +1450,15 @@ class Led extends _AbstractItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
1422
1450
  const { shape, ledbgcolor, coldcolor, warmcolor, hotcolor, overloadcolor } = this.state.style;
1423
1451
  const { min, max } = this.state;
1424
1452
  const { canvas, ctx, tempCanvas, tempCtx, distance } = this;
1425
- const { width, height } = canvas.getBoundingClientRect();
1426
- canvas.width = width;
1427
- canvas.height = height;
1453
+ const ratio = window.devicePixelRatio || 1;
1454
+ let { width, height } = canvas.getBoundingClientRect();
1455
+ width = Math.floor(width);
1456
+ height = Math.floor(height);
1457
+ const scaledWidth = Math.floor(width * ratio);
1458
+ const scaledHeight = Math.floor(height * ratio);
1459
+ canvas.width = scaledWidth;
1460
+ canvas.height = scaledHeight;
1461
+ ctx.scale(ratio, ratio);
1428
1462
  const drawHeight = Math.min(height, width) * 0.75;
1429
1463
  const drawWidth = drawHeight;
1430
1464
  const left = (width - drawWidth) * 0.5;
@@ -1984,11 +2018,15 @@ class VBargraph extends _AbstractItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
1984
2018
  const { type, max, min, enums, scale, value } = this.state;
1985
2019
  const ctx = this.ctx;
1986
2020
  const canvas = this.canvas;
2021
+ const ratio = window.devicePixelRatio || 1;
1987
2022
  let { width, height } = this.canvasDiv.getBoundingClientRect();
1988
2023
  width = Math.floor(width);
1989
2024
  height = Math.floor(height);
1990
- canvas.width = width;
1991
- canvas.height = height;
2025
+ const scaledWidth = Math.floor(width * ratio);
2026
+ const scaledHeight = Math.floor(height * ratio);
2027
+ canvas.width = scaledWidth;
2028
+ canvas.height = scaledHeight;
2029
+ ctx.scale(ratio, ratio);
1992
2030
  const drawHeight = height * 0.9;
1993
2031
  const drawWidth = barwidth || Math.min(width / 3, drawHeight * 0.05);
1994
2032
  const left = (width - drawWidth) * 0.5;
@@ -2187,11 +2225,15 @@ class VSlider extends _AbstractItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
2187
2225
  const ctx = this.ctx;
2188
2226
  const canvas = this.canvas;
2189
2227
  const distance = this.distance;
2228
+ const ratio = window.devicePixelRatio || 1;
2190
2229
  let { width, height } = this.canvasDiv.getBoundingClientRect();
2191
2230
  width = Math.floor(width);
2192
2231
  height = Math.floor(height);
2193
- canvas.width = width;
2194
- canvas.height = height;
2232
+ const scaledWidth = Math.floor(width * ratio);
2233
+ const scaledHeight = Math.floor(height * ratio);
2234
+ canvas.width = scaledWidth;
2235
+ canvas.height = scaledHeight;
2236
+ ctx.scale(ratio, ratio);
2195
2237
  const drawHeight = height * 0.9;
2196
2238
  const drawWidth = sliderwidth || Math.min(width / 3, drawHeight * 0.05);
2197
2239
  const left = (width - drawWidth) * 0.5;
@@ -2487,7 +2529,7 @@ const _AbstractGroup = class {
2487
2529
  this.layout = {
2488
2530
  type: group.type,
2489
2531
  width: _AbstractGroup.padding * 2,
2490
- height: _AbstractGroup.padding * 2 + _AbstractGroup.labelHeight,
2532
+ height: _AbstractGroup.padding * 2 + (this.isRoot ? 0 : _AbstractGroup.labelHeight),
2491
2533
  sizing
2492
2534
  };
2493
2535
  }
@@ -2693,7 +2735,7 @@ class HGroup extends _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"] {
2693
2735
  this.items.forEach((item) => {
2694
2736
  item.adjust();
2695
2737
  this.layout.width += item.layout.width;
2696
- this.layout.height = Math.max(this.layout.height, item.layout.height + 2 * _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].padding + _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].labelHeight);
2738
+ this.layout.height = Math.max(this.layout.height, item.layout.height + 2 * _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].padding + (this.isRoot ? 0 : _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].labelHeight));
2697
2739
  });
2698
2740
  this.layout.width += _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].spaceBetween * (this.items.length - 1);
2699
2741
  if (this.layout.width < 1)
@@ -2714,7 +2756,7 @@ class HGroup extends _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"] {
2714
2756
  item.layout.width += dX$;
2715
2757
  }
2716
2758
  if (item.layout.sizing === "both" || item.layout.sizing === "vertical") {
2717
- dY$ = this.layout.height - 2 * _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].padding - _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].labelHeight - item.layout.height;
2759
+ dY$ = this.layout.height - 2 * _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].padding - (this.isRoot ? 0 : _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].labelHeight) - item.layout.height;
2718
2760
  item.layout.height += dY$;
2719
2761
  }
2720
2762
  item.expand(dX$, dY$);
@@ -2724,12 +2766,12 @@ class HGroup extends _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"] {
2724
2766
  offset() {
2725
2767
  const { labelHeight, padding, spaceBetween } = _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"];
2726
2768
  let $left = padding;
2727
- const $top = padding + labelHeight;
2769
+ const $top = padding + (this.isRoot ? 0 : labelHeight);
2728
2770
  const { height } = this.layout;
2729
2771
  this.items.forEach((item) => {
2730
2772
  item.layout.offsetLeft = $left;
2731
2773
  item.layout.offsetTop = $top;
2732
- item.layout.offsetTop += (height - labelHeight - item.layout.height) / 2 - padding;
2774
+ item.layout.offsetTop += (height - (this.isRoot ? 0 : labelHeight) - item.layout.height) / 2 - padding;
2733
2775
  item.layout.left = (this.layout.left || 0) + item.layout.offsetLeft;
2734
2776
  item.layout.top = (this.layout.top || 0) + item.layout.offsetTop;
2735
2777
  item.offset();
@@ -3066,7 +3108,7 @@ const _TGroup = class extends _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["defau
3066
3108
  if (item.layout.sizing === "both" || item.layout.sizing === "horizontal")
3067
3109
  dX$ = this.layout.width - 2 * _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].padding - item.layout.width;
3068
3110
  if (item.layout.sizing === "both" || item.layout.sizing === "vertical")
3069
- dY$ = this.layout.height - 2 * _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].padding - _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].labelHeight - (tabsCount ? _TGroup.tabLayout.height : 0) - item.layout.height;
3111
+ dY$ = this.layout.height - 2 * _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].padding - (this.isRoot ? 0 : _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"].labelHeight) - (tabsCount ? _TGroup.tabLayout.height : 0) - item.layout.height;
3070
3112
  item.expand(dX$, dY$);
3071
3113
  });
3072
3114
  return this;
@@ -3074,7 +3116,7 @@ const _TGroup = class extends _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["defau
3074
3116
  offset() {
3075
3117
  const { labelHeight, padding } = _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"];
3076
3118
  const $left = padding;
3077
- const $top = padding + labelHeight + _TGroup.tabLayout.height;
3119
+ const $top = padding + (this.isRoot ? 0 : labelHeight) + _TGroup.tabLayout.height;
3078
3120
  this.items.forEach((item) => {
3079
3121
  item.layout.offsetLeft = $left;
3080
3122
  item.layout.offsetTop = $top;
@@ -3170,7 +3212,7 @@ class VGroup extends _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"] {
3170
3212
  offset() {
3171
3213
  const { labelHeight, padding, spaceBetween } = _AbstractGroup__WEBPACK_IMPORTED_MODULE_0__["default"];
3172
3214
  const $left = padding;
3173
- let $top = padding + labelHeight;
3215
+ let $top = padding + (this.isRoot ? 0 : labelHeight);
3174
3216
  const { width } = this.layout;
3175
3217
  this.items.forEach((item) => {
3176
3218
  item.layout.offsetLeft = $left;