dechatter 0.1.0 → 0.2.0

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/package.json CHANGED
@@ -1,39 +1,40 @@
1
- {
2
- "name": "dechatter",
3
- "version": "0.1.0",
4
- "description": "CNCjs custom widget that finds chatter-free milling speeds, widths and depths from test cuts heard through the microphone.",
5
- "keywords": [
6
- "cncjs",
7
- "cnc",
8
- "chatter",
9
- "milling",
10
- "stability-lobes",
11
- "grbl",
12
- "widget"
13
- ],
14
- "license": "MIT",
15
- "author": "Pedro Paulo Vezza Campos <pedro@vezza.com.br>",
16
- "homepage": "https://github.com/pedropaulovc/dechatter#readme",
17
- "bugs": {
18
- "url": "https://github.com/pedropaulovc/dechatter/issues"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/pedropaulovc/dechatter.git"
23
- },
24
- "exports": {
25
- "./index.html": "./web/index.html",
26
- "./package.json": "./package.json"
27
- },
28
- "files": [
29
- "web",
30
- "THIRD_PARTY_NOTICES.md"
31
- ],
32
- "publishConfig": {
33
- "access": "public"
34
- },
35
- "scripts": {
36
- "build": "node .github/build_widget.mjs",
37
- "prepack": "npm run build"
38
- }
39
- }
1
+ {
2
+ "name": "dechatter",
3
+ "version": "0.2.0",
4
+ "description": "CNCjs custom widget that finds chatter-free milling speeds, widths and depths from test cuts heard through the microphone.",
5
+ "keywords": [
6
+ "cncjs",
7
+ "cnc",
8
+ "chatter",
9
+ "milling",
10
+ "stability-lobes",
11
+ "grbl",
12
+ "widget"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "Pedro Paulo Vezza Campos <pedro@vezza.com.br>",
16
+ "homepage": "https://github.com/pedropaulovc/dechatter#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/pedropaulovc/dechatter/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/pedropaulovc/dechatter.git"
23
+ },
24
+ "exports": {
25
+ "./index.html": "./web/index.html",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "web",
30
+ "CHANGELOG.md",
31
+ "THIRD_PARTY_NOTICES.md"
32
+ ],
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "scripts": {
37
+ "build": "node .github/build_widget.mjs",
38
+ "prepack": "npm run build"
39
+ }
40
+ }
package/web/dechatter.zip CHANGED
Binary file
package/web/engine.js CHANGED
@@ -1,92 +1,92 @@
1
- // Web worker: dechatter's Python running in Pyodide. Sessions live in a filesystem that is
2
- // persisted to IndexedDB, so they survive reloads and browser restarts.
3
-
4
- import { loadPyodide } from './pyodide/pyodide.js';
5
-
6
- const ROOT = '/sessions';
7
- // Calls that change files; the filesystem is flushed to IndexedDB after each of them.
8
- const WRITES = new Set(['create', 'save_setup', 'plan', 'record_stop', 'analyze', 'set_verdict', 'import_zip']);
9
-
10
- let pyodide;
11
- let call;
12
-
13
- // cncjs serves .wasm as application/octet-stream, which streaming compilation refuses.
14
- // Relabel those responses; the bytes still stream straight through.
15
- const plainFetch = self.fetch.bind(self);
16
- self.fetch = async (input, init) => {
17
- const response = await plainFetch(input, init);
18
- const url = typeof input === 'string' ? input : (input.url ?? String(input));
19
- if (!response.ok || !url.split('?')[0].endsWith('.wasm')) {
20
- return response;
21
- }
22
- return new Response(response.body, { status: response.status, headers: { 'Content-Type': 'application/wasm' } });
23
- };
24
-
25
- function sync(populate) {
26
- return new Promise((resolve, reject) => {
27
- pyodide.FS.syncfs(populate, (err) => (err ? reject(err) : resolve()));
28
- });
29
- }
30
-
31
- async function boot() {
32
- postMessage({ boot: 'Loading Python' });
33
- pyodide = await loadPyodide({ indexURL: new URL('./pyodide/', import.meta.url).href });
34
- postMessage({ boot: 'Loading numpy and scipy' });
35
- await pyodide.loadPackage(['numpy', 'scipy']);
36
- const source = await fetch(new URL('./dechatter.zip', import.meta.url));
37
- if (!source.ok) {
38
- throw new Error(`cannot load dechatter.zip: ${source.status}`);
39
- }
40
- pyodide.unpackArchive(await source.arrayBuffer(), 'zip');
41
- pyodide.FS.mkdirTree(ROOT);
42
- pyodide.FS.mount(pyodide.FS.filesystems.IDBFS, {}, ROOT);
43
- await sync(true);
44
- call = pyodide.runPython(`
45
- import logging
46
- from pathlib import Path
47
- from dechatter import browser
48
-
49
- logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s")
50
- _sessions = browser.Sessions(Path("${ROOT}"))
51
-
52
- def _call(method, *args):
53
- return browser.call(_sessions, method, *args)
54
-
55
- _call
56
- `);
57
- }
58
-
59
- async function handle({ method, args }) {
60
- const converted = args.map((arg) => (ArrayBuffer.isView(arg) ? pyodide.toPy(arg) : arg));
61
- const result = call(method, ...converted);
62
- for (const arg of converted) {
63
- arg?.destroy?.();
64
- }
65
- if (typeof result !== 'string') {
66
- const bytes = result.toJs();
67
- result.destroy();
68
- return { ok: bytes };
69
- }
70
- const reply = JSON.parse(result);
71
- if ('ok' in reply && WRITES.has(method)) {
72
- await sync(false);
73
- }
74
- return reply;
75
- }
76
-
77
- const ready = boot().then(
78
- () => postMessage({ boot: null }),
79
- (err) => {
80
- postMessage({ boot: null, fatal: `dechatter could not start: ${err.message ?? err}` });
81
- throw err;
82
- },
83
- );
84
-
85
- onmessage = async ({ data }) => {
86
- try {
87
- await ready;
88
- postMessage({ id: data.id, ...(await handle(data)) });
89
- } catch (err) {
90
- postMessage({ id: data.id, error: `${err.message ?? err}` });
91
- }
92
- };
1
+ // Web worker: dechatter's Python running in Pyodide. Sessions live in a filesystem that is
2
+ // persisted to IndexedDB, so they survive reloads and browser restarts.
3
+
4
+ import { loadPyodide } from './pyodide/pyodide.js';
5
+
6
+ const ROOT = '/sessions';
7
+ // Calls that change files; the filesystem is flushed to IndexedDB after each of them.
8
+ const WRITES = new Set(['create', 'save_setup', 'plan', 'plan_sweep', 'record_stop', 'analyze', 'set_verdict', 'import_zip']);
9
+
10
+ let pyodide;
11
+ let call;
12
+
13
+ // cncjs serves .wasm as application/octet-stream, which streaming compilation refuses.
14
+ // Relabel those responses; the bytes still stream straight through.
15
+ const plainFetch = self.fetch.bind(self);
16
+ self.fetch = async (input, init) => {
17
+ const response = await plainFetch(input, init);
18
+ const url = typeof input === 'string' ? input : (input.url ?? String(input));
19
+ if (!response.ok || !url.split('?')[0].endsWith('.wasm')) {
20
+ return response;
21
+ }
22
+ return new Response(response.body, { status: response.status, headers: { 'Content-Type': 'application/wasm' } });
23
+ };
24
+
25
+ function sync(populate) {
26
+ return new Promise((resolve, reject) => {
27
+ pyodide.FS.syncfs(populate, (err) => (err ? reject(err) : resolve()));
28
+ });
29
+ }
30
+
31
+ async function boot() {
32
+ postMessage({ boot: 'Loading Python' });
33
+ pyodide = await loadPyodide({ indexURL: new URL('./pyodide/', import.meta.url).href });
34
+ postMessage({ boot: 'Loading numpy and scipy' });
35
+ await pyodide.loadPackage(['numpy', 'scipy']);
36
+ const source = await fetch(new URL('./dechatter.zip', import.meta.url));
37
+ if (!source.ok) {
38
+ throw new Error(`cannot load dechatter.zip: ${source.status}`);
39
+ }
40
+ pyodide.unpackArchive(await source.arrayBuffer(), 'zip');
41
+ pyodide.FS.mkdirTree(ROOT);
42
+ pyodide.FS.mount(pyodide.FS.filesystems.IDBFS, {}, ROOT);
43
+ await sync(true);
44
+ call = pyodide.runPython(`
45
+ import logging
46
+ from pathlib import Path
47
+ from dechatter import browser
48
+
49
+ logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s")
50
+ _sessions = browser.Sessions(Path("${ROOT}"))
51
+
52
+ def _call(method, *args):
53
+ return browser.call(_sessions, method, *args)
54
+
55
+ _call
56
+ `);
57
+ }
58
+
59
+ async function handle({ method, args }) {
60
+ const converted = args.map((arg) => (ArrayBuffer.isView(arg) ? pyodide.toPy(arg) : arg));
61
+ const result = call(method, ...converted);
62
+ for (const arg of converted) {
63
+ arg?.destroy?.();
64
+ }
65
+ if (typeof result !== 'string') {
66
+ const bytes = result.toJs();
67
+ result.destroy();
68
+ return { ok: bytes };
69
+ }
70
+ const reply = JSON.parse(result);
71
+ if ('ok' in reply && WRITES.has(method)) {
72
+ await sync(false);
73
+ }
74
+ return reply;
75
+ }
76
+
77
+ const ready = boot().then(
78
+ () => postMessage({ boot: null }),
79
+ (err) => {
80
+ postMessage({ boot: null, fatal: `dechatter could not start: ${err.message ?? err}` });
81
+ throw err;
82
+ },
83
+ );
84
+
85
+ onmessage = async ({ data }) => {
86
+ try {
87
+ await ready;
88
+ postMessage({ id: data.id, ...(await handle(data)) });
89
+ } catch (err) {
90
+ postMessage({ id: data.id, error: `${err.message ?? err}` });
91
+ }
92
+ };
package/web/index.html CHANGED
@@ -1,81 +1,81 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>dechatter</title>
7
- <link rel="stylesheet" href="widget.css">
8
- </head>
9
- <body>
10
- <p id="error" class="error" hidden></p>
11
- <p id="boot" class="muted">Starting.</p>
12
-
13
- <div id="main" hidden>
14
- <header>
15
- <select id="sessions" aria-label="Session"></select>
16
- <button id="new-session">New</button>
17
- <button id="edit-setup" disabled>Setup</button>
18
- <button id="export" disabled>Export</button>
19
- <button id="import">Import</button>
20
- <input id="import-file" type="file" accept=".zip" hidden>
21
- <div id="summary" class="muted"></div>
22
- </header>
23
-
24
- <dl id="links">
25
- <dt>cncjs</dt>
26
- <dd id="cncjs">connecting</dd>
27
- <dt>Microphone</dt>
28
- <dd>
29
- <button id="enable-mic" hidden>Enable microphone</button>
30
- <select id="device" aria-label="Microphone" hidden></select>
31
- <meter id="level" min="-100" max="0" low="-70" high="-6" optimum="-30" value="-100" hidden></meter>
32
- <span id="level-db" class="muted"></span>
33
- </dd>
34
- </dl>
35
- <p id="mic-warning" class="error" hidden></p>
36
-
37
- <section id="setup" hidden>
38
- <h2 id="setup-title"></h2>
39
- <p id="setup-hint" class="muted"></p>
40
- <form id="setup-form"></form>
41
- <p class="wizard-buttons">
42
- <button id="setup-back" type="button">Back</button>
43
- <button id="setup-next" class="primary" type="submit" form="setup-form">Next</button>
44
- <button id="cancel-setup" type="button">Cancel</button>
45
- <span id="units" class="muted"></span>
46
- <button id="follow-machine" type="button" hidden>Use mm instead</button>
47
- </p>
48
- </section>
49
-
50
- <section id="step" hidden></section>
51
-
52
- <section id="round" hidden>
53
- <h2 id="round-title"></h2>
54
- <table>
55
- <thead>
56
- <tr><th>#</th><th>rpm</th><th>width</th><th>feed</th><th>P</th><th>result</th></tr>
57
- </thead>
58
- <tbody id="passes"></tbody>
59
- </table>
60
- </section>
61
-
62
- <section id="map-section" hidden>
63
- <h2 id="map-title">Stability map</h2>
64
- <canvas id="map" width="320" height="180"></canvas>
65
- <p class="muted legend">
66
- Green is likely stable, red likely chatter. Dots are stable cuts, crosses chatter.
67
- </p>
68
- </section>
69
-
70
- <section id="best-section" hidden>
71
- <h2>Best stable cuts</h2>
72
- <table>
73
- <thead><tr><th>rpm</th><th>width</th><th>depth</th><th>feed</th><th>cm³/min</th></tr></thead>
74
- <tbody id="best"></tbody>
75
- </table>
76
- </section>
77
- </div>
78
-
79
- <script type="module" src="widget.js"></script>
80
- </body>
81
- </html>
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>dechatter</title>
7
+ <link rel="stylesheet" href="widget.css">
8
+ </head>
9
+ <body>
10
+ <p id="error" class="error" hidden></p>
11
+ <p id="boot" class="muted">Starting.</p>
12
+
13
+ <div id="main" hidden>
14
+ <header>
15
+ <select id="sessions" aria-label="Session"></select>
16
+ <button id="new-session">New</button>
17
+ <button id="edit-setup" disabled>Setup</button>
18
+ <button id="export" disabled>Export</button>
19
+ <button id="import">Import</button>
20
+ <input id="import-file" type="file" accept=".zip" hidden>
21
+ <div id="summary" class="muted"></div>
22
+ </header>
23
+
24
+ <dl id="links">
25
+ <dt>cncjs</dt>
26
+ <dd id="cncjs">connecting</dd>
27
+ <dt>Microphone</dt>
28
+ <dd>
29
+ <button id="enable-mic" hidden>Enable microphone</button>
30
+ <select id="device" aria-label="Microphone" hidden></select>
31
+ <meter id="level" min="-100" max="0" low="-70" high="-6" optimum="-30" value="-100" hidden></meter>
32
+ <span id="level-db" class="muted"></span>
33
+ </dd>
34
+ </dl>
35
+ <p id="mic-warning" class="error" hidden></p>
36
+
37
+ <section id="setup" hidden>
38
+ <h2 id="setup-title"></h2>
39
+ <p id="setup-hint" class="muted"></p>
40
+ <form id="setup-form"></form>
41
+ <p class="wizard-buttons">
42
+ <button id="setup-back" type="button">Back</button>
43
+ <button id="setup-next" class="primary" type="submit" form="setup-form">Next</button>
44
+ <button id="cancel-setup" type="button">Cancel</button>
45
+ <span id="units" class="muted"></span>
46
+ </p>
47
+ </section>
48
+
49
+ <section id="step" hidden></section>
50
+
51
+ <section id="round" hidden>
52
+ <h2 id="round-title"></h2>
53
+ <table>
54
+ <thead>
55
+ <tr><th>#</th><th>rpm</th><th>width</th><th>feed</th><th>P</th><th>result</th></tr>
56
+ </thead>
57
+ <tbody id="passes"></tbody>
58
+ </table>
59
+ </section>
60
+
61
+ <section id="map-section" hidden>
62
+ <h2 id="map-title">Stability map</h2>
63
+ <canvas id="map" width="320" height="180"></canvas>
64
+ <p class="muted legend">
65
+ Green is likely stable, red likely chatter. Dots are stable cuts, crosses chatter.
66
+ </p>
67
+ </section>
68
+
69
+ <section id="best-section" hidden>
70
+ <h2>Best stable cuts <button id="download-report" type="button">Download report</button></h2>
71
+ <table>
72
+ <thead><tr><th>rpm</th><th>width</th><th>depth</th><th>feed</th><th>cm³/min</th></tr></thead>
73
+ <tbody id="best"></tbody>
74
+ </table>
75
+ <p id="sweep-result" class="muted legend" hidden></p>
76
+ </section>
77
+ </div>
78
+
79
+ <script type="module" src="widget.js"></script>
80
+ </body>
81
+ </html>
@@ -1,34 +1,34 @@
1
- // Audio thread: hand the microphone's samples to the page in blocks, mixed down to mono.
2
-
3
- const BLOCK = 4096;
4
-
5
- class Capture extends AudioWorkletProcessor {
6
- constructor() {
7
- super();
8
- this.block = new Float32Array(BLOCK);
9
- this.filled = 0;
10
- }
11
-
12
- process(inputs) {
13
- const channels = inputs[0];
14
- if (!channels.length) {
15
- return true;
16
- }
17
- const frames = channels[0].length;
18
- for (let i = 0; i < frames; i += 1) {
19
- let sum = 0;
20
- for (const channel of channels) {
21
- sum += channel[i];
22
- }
23
- this.block[this.filled] = sum / channels.length;
24
- this.filled += 1;
25
- if (this.filled === BLOCK) {
26
- this.port.postMessage(this.block.slice());
27
- this.filled = 0;
28
- }
29
- }
30
- return true;
31
- }
32
- }
33
-
34
- registerProcessor('capture', Capture);
1
+ // Audio thread: hand the microphone's samples to the page in blocks, mixed down to mono.
2
+
3
+ const BLOCK = 4096;
4
+
5
+ class Capture extends AudioWorkletProcessor {
6
+ constructor() {
7
+ super();
8
+ this.block = new Float32Array(BLOCK);
9
+ this.filled = 0;
10
+ }
11
+
12
+ process(inputs) {
13
+ const channels = inputs[0];
14
+ if (!channels.length) {
15
+ return true;
16
+ }
17
+ const frames = channels[0].length;
18
+ for (let i = 0; i < frames; i += 1) {
19
+ let sum = 0;
20
+ for (const channel of channels) {
21
+ sum += channel[i];
22
+ }
23
+ this.block[this.filled] = sum / channels.length;
24
+ this.filled += 1;
25
+ if (this.filled === BLOCK) {
26
+ this.port.postMessage(this.block.slice());
27
+ this.filled = 0;
28
+ }
29
+ }
30
+ return true;
31
+ }
32
+ }
33
+
34
+ registerProcessor('capture', Capture);