10000 Fix #2302 - Updated Polyscript to its latest · pyscript/pyscript@cac9edc · GitHub
[go: up one dir, main page]

Skip to content

Commit cac9edc

Browse files
committed
Fix #2302 - Updated Polyscript to its latest
1 parent 55031f2 commit cac9edc

14 files changed

+929
-16
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ repos:
4747
rev: "v3.0.0-alpha.6"
4848
hooks:
4949
- id: prettier
50-
exclude: core/test|core/dist|core/types|core/src/stdlib/pyscript.js|pyscript\.sw/|core/src/3rd-party
50+
exclude: core/tests/*|core/dist|core/types|core/src/stdlib/pyscript.js|pyscript\.sw/|core/src/3rd-party
5151
args: [--tab-width, "4"]

core/package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pyscript/core",
3-
"version": "0.6.33",
3+
"version": "0.6.35",
44
"type": "module",
55
"description": "PyScript",
66
"module": "./index.js",
@@ -66,7 +66,7 @@
6666
"@webreflection/idb-map": "^0.3.2",
6767
"add-promise-listener": "^0.1.3",
6868
"basic-devtools": "^0.1.6",
69-
"polyscript": "^0.16.15",
69+
"polyscript": "^0.16.17",
7070
"sabayon": "^0.6.6",
7171
"sticky-module": "^0.1.1",
7272
"to-json-callback": "^0.1.1",

core/tests/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
a:hover { opacity: 1; }
1515
</style>
1616
</head>
17-
<body><ul><li><strong><span>javascript</span></strong><ul><li><a href="./javascript/async-listener.html">async-listener<small>.html</small></a></li><li><a href="./javascript/config-url.html">config-url<small>.html</small></a></li><li><a href="./javascript/config_type.html">config_type<small>.html</small></a></li><li><strong><a href="./javascript/fetch/index.html">fetch</a></strong></li><li><a href="./javascript/ffi.html">ffi<small>.html</small></a></li><li><a href="./javascript/hooks.html">hooks<small>.html</small></a></li><li><strong><a href="./javascript/issue-2093/index.html">issue-2093</a></strong></li><li><a href="./javascript/js-storage.html">js-storage<small>.html</small></a></li><li><a href="./javascript/js_modules.html">js_modules<small>.html</small></a></li><li><strong><a href="./javascript/loader/index.html">loader</a></strong></li><li><a href="./javascript/mpy-error.html">mpy-error<small>.html</small></a></li><li><a href="./javascript/mpy-no-error.html">mpy-no-error<small>.html</small></a></li><li><a href="./javascript/mpy.html">mpy<small>.html</small></a></li><li><a href="./javascript/py-terminal-main.html">py-terminal-main<small>.html</small></a></li><li><a href="./javascript/py-terminal-worker.html">py-terminal-worker<small>.html</small></a></li><li><a href="./javascript/py-terminal.html">py-terminal<small>.html</small></a></li><li><a href="./javascript/py-terminals.html">py-terminals<small>.html</small></a></li><li><strong><a href="./javascript/pyodide-cache/index.html">pyodide-cache</a></strong></li><li><strong><a href="./javascript/pyodide-lockfile/index.html">pyodide-lockfile</a></strong></li><li><a href="./javascript/storage.html">storage<small>.html</small></a></li><li><strong><span>workers</span></strong><ul><li><strong><a href="./javascript/workers/create_named/index.html">create_named</a></strong></li><li><strong><a href="./javascript/workers/mpy/index.html">mpy</a></strong></li><li><strong><a href="./javascript/workers/py/index.html">py</a></strong></li></ul></li></ul></li><li><strong><a href="./manual/index.html">manual</a></strong><ul><li><a href="./manual/all-done.html">all-done<small>.html</small></a></li><li><a href="./manual/async.html">async<small>.html</small></a></li><li><a href="./manual/camera.html">camera<small>.html</small></a></li><li><a href="./manual/click.html">click<small>.html</small></a></li><li><a href="./manual/code-a-part.html">code-a-part<small>.html</small></a></li><li><a href="./manual/combo.html">combo<small>.html</small></a></li><li><a href="./manual/config.html">config<small>.html</small></a></li><li><a href="./manual/create-element.html">create-element<small>.html</small></a></li><li><a href="./manual/dialog.html">dialog<small>.html</small></a></li><li><a href="./manual/display.html">display<small>.html</small></a></li><li><strong><a href="./manual/donkey/index.html">donkey</a></strong></li><li><a href="./manual/emoji.html">emoji<small>.html</small></a></li><li><a href="./manual/error.html">error<small>.html</small></a></li><li><strong><a href="./manual/fs/index.html">fs</a></strong></li><li><strong><a href="./manual/game/index.html">game</a></strong></li><li><a href="./manual/html-decode.html">html-decode<small>.html</small></a></li><li><a href="./manual/input.html">input<small>.html</small></a></li><li><a href="./manual/interpreter.html">interpreter<small>.html</small></a></li><li><strong><a href="./manual/issue-2228/index.html">issue-2228</a></strong></li><li><strong><a href="./manual/issue-2246/index.html">issue-2246</a></strong></li><li><strong><a href="./manual/issue-7015/index.html">issue-7015</a></strong></li><li><a href="./manual/multi.html">multi<small>.html</small></a></li><li><a href="./manual/multiple-editors.html">multiple-editors<small>.html</small></a></li><li><a href="./manual/no-error.html">no-error<small>.html</small></a></li><li><strong><a href="./manual/no_sab/index.html">no_sab</a></strong></li><li><strong><a href="./manual/piratical/index.html">piratical</a></strong></li><li><a href="./manual/py-editor.html">py-editor<small>.html</small></a></li><li><a href="./manual/py-editor-failure.html">py-editor-failure<small>.html</small></a></li><li><strong><a href="./manual/py-terminals/index.html">py-terminals</a></strong><ul><li><a href="./manual/py-terminals/no-repl.html">no-repl<small>.html</small></a></li><li><a href="./manual/py-terminals/repl.html">repl<small>.html</small></a></li></ul></li><li><a href="./manual/py_modules.html">py_modules<small>.html</small></a></li><li><strong><a href="./manual/service-worker/index.html">service-worker</a></strong></li><li><a href="./manual/split-config.html">split-config<small>.html</small></a></li><li><a href="./manual/submit.html">submit<small>.html</small></a></li< 10BC0 /span>><li><a href="./manual/target.html">target<small>.html</small></a></li><li><a href="./manual/test_display_HTML.html">test_display_HTML<small>.html</small></a></li><li><a href="./manual/test_when.html">test_when<small>.html</small></a></li><li><a href="./manual/worker.html">worker<small>.html</small></a></li></ul></li><li><strong><a href="./python/index.html">python</a></strong></li></ul></body>
17+
<body><ul><li><strong><span>javascript</span></strong><ul><li><a href="./javascript/async-listener.html">async-listener<small>.html</small></a></li><li><a href="./javascript/config-url.html">config-url<small>.html</small></a></li><li><a href="./javascript/config_type.html">config_type<small>.html</small></a></li><li><strong><a href="./javascript/fetch/index.html">fetch</a></strong></li><li><a href="./javascript/ffi.html">ffi<small>.html</small></a></li><li><a href="./javascript/hooks.html">hooks<small>.html</small></a></li><li><strong><a href="./javascript/issue-2093/index.html">issue-2093</a></strong></li><li><a href="./javascript/js-storage.html">js-storage<small>.html</small></a></li><li><a href="./javascript/js_modules.html">js_modules<small>.html</small></a></li><li><strong><a href="./javascript/loader/index.html">loader</a></strong></li><li><a href="./javascript/mpy-error.html">mpy-error<small>.html</small></a></li><li><a href="./javascript/mpy-no-error.html">mpy-no-error<small>.html</small></a></li><li><a href="./javascript/mpy.html">mpy<small>.html</small></a></li><li><a href="./javascript/py-terminal-main.html">py-terminal-main<small>.html</small></a></li><li><a href="./javascript/py-terminal-worker.html">py-terminal-worker<small>.html</small></a></li><li><a href="./javascript/py-terminal.html">py-terminal<small>.html</small></a></li><li><a href="./javascript/py-terminals.html">py-terminals<small>.html</small></a></li><li><strong><a href="./javascript/pyodide-cache/index.html">pyodide-cache</a></strong></li><li><strong><a href="./javascript/pyodide-lockfile/index.html">pyodide-lockfile</a></strong></li><li><a href="./javascript/storage.html">storage<small>.html</small></a></li><li><strong><span>workers</span></strong><ul><li><strong><a href="./javascript/workers/create_named/index.html">create_named</a></strong></li><li><strong><a href="./javascript/workers/mpy/index.html">mpy</a></strong></li><li><strong><a href="./javascript/workers/py/index.html">py</a></strong></li></ul></li></ul></li><li><strong><a href="./manual/index.html">manual</a></strong><ul><li><a href="./manual/all-done.html">all-done<small>.html</small></a></li><li><a href="./manual/async.html">async<small>.html</small></a></li><li><a href="./manual/camera.html">camera<small>.html</small></a></li><li><a href="./manual/click.html">click<small>.html</small></a></li><li><a href="./manual/code-a-part.html">code-a-part<small>.html</small></a></li><li><a href="./manual/combo.html">combo<small>.html</small></a></li><li><a href="./manual/config.html">config<small>.html</small></a></li><li><a href="./manual/create-element.html">create-element<small>.html</small></a></li><li><a href="./manual/dialog.html">dialog<small>.html</small></a></li><li><a href="./manual/display.html">display<small>.html</small></a></li><li><strong><a href="./manual/donkey/index.html">donkey</a></strong></li><li><a href="./manual/emoji.html">emoji<small>.html</small></a></li><li><a href="./manual/error.html">error<small>.html</small></a></li><li><strong><a href="./manual/fs/index.html">fs</a></strong></li><li><strong><a href="./manual/game/index.html">game</a></strong></li><li><a href="./manual/html-decode.html">html-decode<small>.html</small></a></li><li><a href="./manual/input.html">input<small>.html</small></a></li><li><a href="./manual/interpreter.html">interpreter<small>.html</small></a></li><li><strong><a href="./manual/issue-2228/index.html">issue-2228</a></strong></li><li><strong><a href="./manual/issue-2246/index.html">issue-2246</a></strong></li><li><strong><a href="./manual/issue-2302/index.html">issue-2302</a></strong></li><li><strong><a href="./manual/issue-7015/index.html">issue-7015</a></strong></li><li><a href="./manual/multi.html">multi<small>.html</small></a></li><li><a href="./manual/multiple-editors.html">multiple-editors<small>.html</small></a></li><li><a href="./manual/no-error.html">no-error<small>.html</small></a></li><li><strong><a href="./manual/no_sab/index.html">no_sab</a></strong></li><li><strong><a href="./manual/piratical/index.html">piratical</a></strong></li><li><a href="./manual/py-editor.html">py-editor<small>.html</small></a></li><li><a href="./manual/py-editor-failure.html">py-editor-failure<small>.html</small></a></li><li><strong><a href="./manual/py-terminals/index.html">py-terminals</a></strong><ul><li><a href="./manual/py-terminals/no-repl.html">no-repl<small>.html</small></a></li><li><a href="./manual/py-terminals/repl.html">repl<small>.html</small></a></li></ul></li><li><a href="./manual/py_modules.html">py_modules<small>.html</small></a></li><li><strong><a href="./manual/service-worker/index.html">service-worker</a></strong></li><li><a href="./manual/split-config.html">split-config<small>.html</small></a></li><li><a href="./manual/submit.html">submit<small>.html</small></a></li><li><a href="./manual/target.html">target<small>.html</small></a></li><li><a href="./manual/test_display_HTML.html">test_display_HTML<small>.html</small></a></li><li><a href="./manual/test_when.html">test_when<small>.html</small></a></li><li><a href="./manual/worker.html">worker<small>.html</small></a></li></ul></li><li><strong><a href="./python/index.html">python</a></strong></li></ul></body>
1818
</html>
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pyscript import config
2+
3+
MICROPYTHON = config["type"] == "mpy"
4+
5+
if MICROPYTHON:
6+
def new(obj, *args, **kwargs):
7+
return obj.new(*args, kwargs) if kwargs else obj.new(*args)
8+
def call(obj, *args, **kwargs):
9+
return obj(*args, kwargs) if kwargs else obj(*args)
10+
else:
11+
def new(obj, *args, **kwargs):
12+
return obj.new(*args, **kwargs)
13+
def call(obj, *args, **kwargs):
14+
return obj(*args, **kwargs)
15+
16+
if not MICROPYTHON:
17+
import pyodide_js
18+
pyodide_js.setDebug(True)
19+
20+
from pyscript.ffi import to_js, create_proxy
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Genuary</title>
5+
6+
<!-- Recommended meta tags -->
7+
<meta charset="UTF-8">
8+
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
9+
10+
<!-- PyScript CSS -->
11+
<link rel="stylesheet" href="../../../dist/core.css">
12+
13+
<style>
14+
body {
15+
margin: 0;
16+
overflow: hidden;
17+
background-color: #4a315e;
18+
color: white;
19+
font-family: Inconsolata, Consolas, Monaco, Courier New;
20+
}
21+
22+
.gutter {
23+
background-color: #eee;
24+
background-repeat: no-repeat;
25+
background-position: 50%;
26+
}
27+
28+
.gutter.gutter-vertical {
29+
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAFAQMAAABo7865AAAABlBMVEVHcEzMzMzyAv2sAAAAAXRSTlMAQObYZgAAABBJREFUeF5jOAMEEAIEEFwAn3kMwcB6I2AAAAAASUVORK5CYII=');
30+
cursor: row-resize;
31+
}
32+
33+
py-terminal {
34+
max-height: 7em;
35+
max-width: calc(100vw - 90px);
36+
}
37+
38+
#pyterm {
39+
background-color: #191a1a;
40+
}
41+
42+
#pyterm,
43+
#threejs {
44+
position: relative;
45+
overflow: hidden;
46+
}
47+
</style>
48+
49+
<!-- This script tag bootstraps PyScript -->
50+
<script type="importmap">
51+
{
52+
"imports": {
53+
"three": "https://cdn.jsdelivr.net/npm/three@v0.173.0/build/three.module.js"
54+
}
55+
}
56+
</script>
57+
<script type="module" src="../../../dist/core.js"></script>
58+
<script src="https://cdnjs.cloudflare.com/ajax/libs/split.js/1.6.5/split.min.js"></script>
59+
</head>
60+
<body>
61+
<div id="stats"></div>
62+
<div id="stats-off"></div>
63+
<div class="split">
64+
<div id="pyterm"></div>
65+
<div id="threejs"></div>
66+
</div>
67+
<script type="py" src="./main.py" config="./pyscript.toml" async terminal></script>
68+
</body>
69+
</html>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from dataclasses import dataclass, field
2+
import sys
3+
4+
@dataclass
5+
class BeatSync:
6+
fft_res: int = field()
7+
8+
on_beat: bool = False
9+
beat: int = -1
10+
since_last_beat: float = sys.maxsize
11+
12+
_prev: int = 0
13+
_count: int = 0
14+
_bins: list[int] = field(default_factory=list)
15+
_last_detection: float = -1.0
16+
_threshold: int = 50
17+
_diff: int = 40
18+
_cooldown: float = 0.2
19+
20+
_highest: int = 0
21+
22+
def __post_init__(self):
23+
self._bins = [int(13/16*self.fft_res/2)+17, int(13/16*self.fft_res/2)+18]
24+
25+
def reset(self):
26+
self.beat = -1
27+
self._prev = 0
28+
self._count = 0
29+
self._last_detection = -1.0
30+
self.since_last_beat = sys.maxsize
31+
# print('bs reset')
32+
33+
def update(self, data, running_time):
34+
self._count += 1
35+
self.since_last_beat = running_time - self._last_detection
36+
d = sum(data[bin] for bin in self._bins)
37+
if d < self._threshold:
38+
self.on_beat = False
39+
elif d - self._prev < self._diff:
40+
self.on_beat = False
41+
elif self.since_last_beat < self._cooldown:
42+
self.on_beat = False
43+
else:
44+
self._last_detection = running_time
45+
self.since_last_beat = 0
46+
self.on_beat = True
47+
self.beat += 1
48+
self._prev = d
49+
50+
@dataclass
51+
class FreqIntensity:
52+
freq: float = field()
53+
fft_res: int = field()
54+
55+
intensity: float = 0.0
56+
intensity_slew: float = 0.0
57+
scale_min: float = 0.0
58+
scale_max: float = 350
59+
max: float = 0.0
60+
_sample_rate: int = 48000
61+
_bin_indexes: list[int] = field(default_factory=list)
62+
_harmonics: int = 8
63+
_slew_factor: float = 0.8
64+
65+
def __post_init__(self):
66+
self._bin_indexes = [
67+
round((harmonic+1) * self.freq / self._sample_rate * self.fft_res / 2)
68+
for harmonic in range(self._harmonics)
69+
]
70+
print(self._bin_indexes)
71+
72+
def update(self, data):
73+
intensity = 0.0
74+
for bin in range(self._harmonics):
75+
intensity += data[self._bin_indexes[bin]]/(bin+1)
76+
self.intensity = intensity
77+
self.intensity_slew = self._slew_factor * self.intensity_slew + (1 - self._slew_factor) * intensity
78+
self.max = max(intensity, self.max)
79+
80+
@property
81+
def intensity_scaled(self):
82+
raw = max(0, min(1.0, (self.intensity_slew - self.scale_min)/(self.scale_max - self.scale_min)))
83+
return raw * raw

0 commit comments

Comments
 (0)
0