duskfm 0.1.0__tar.gz
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.
- duskfm-0.1.0/LICENSE +21 -0
- duskfm-0.1.0/PKG-INFO +102 -0
- duskfm-0.1.0/README.md +76 -0
- duskfm-0.1.0/duskfm/__init__.py +3 -0
- duskfm-0.1.0/duskfm/__main__.py +3 -0
- duskfm-0.1.0/duskfm/cli.py +200 -0
- duskfm-0.1.0/duskfm/compose.py +313 -0
- duskfm-0.1.0/duskfm/engine.py +104 -0
- duskfm-0.1.0/duskfm/fx.py +186 -0
- duskfm-0.1.0/duskfm/player.py +127 -0
- duskfm-0.1.0/duskfm/synth.py +205 -0
- duskfm-0.1.0/pyproject.toml +39 -0
- duskfm-0.1.0/tests/test_duskfm.py +97 -0
duskfm-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Frank Lynam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
duskfm-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: duskfm
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Endless, never-repeating music from lo-fi to synthwave, synthesized on the spot: no samples, nothing recorded.
|
|
5
|
+
Keywords: lofi,lo-fi,synthwave,chillwave,generative,music,focus,ambient,synthesizer
|
|
6
|
+
Author: Frank Lynam
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Sound Synthesis
|
|
17
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Players
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: numpy>=1.22
|
|
20
|
+
Requires-Dist: scipy>=1.8
|
|
21
|
+
Requires-Dist: sounddevice>=0.4 ; extra == "sounddevice"
|
|
22
|
+
Project-URL: Homepage, https://github.com/frank-lynam/duskfm
|
|
23
|
+
Project-URL: Issues, https://github.com/frank-lynam/duskfm/issues
|
|
24
|
+
Provides-Extra: sounddevice
|
|
25
|
+
|
|
26
|
+
# duskfm
|
|
27
|
+
|
|
28
|
+
Endless music from lo-fi to synthwave, made on the spot: never the same twice, all day long.
|
|
29
|
+
|
|
30
|
+
Every sound is synthesized as it plays: an FM electric piano, detuned pads, a polysynth, bass, a drum kit made of
|
|
31
|
+
sweeps and noise, tape wobble, vinyl dust. No samples and nothing recorded, so the package is a few files of Python.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install duskfm
|
|
35
|
+
duskfm # lo-fi
|
|
36
|
+
duskfm synthwave # or: lofi, chillhop, chillwave, synthwave, nightdrive, ambient
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## One dial from lo-fi to synthwave
|
|
40
|
+
|
|
41
|
+
`--style` runs from 0 (lo-fi) to 1 (synthwave), and everything blends along it:
|
|
42
|
+
|
|
43
|
+
| | lo-fi (0) | chillwave (0.5) | synthwave (1) |
|
|
44
|
+
|---|---|---|---|
|
|
45
|
+
| tempo | 72–84, swung | ~85–97 | 94–110, straight |
|
|
46
|
+
| harmony | jazzy 7ths and 9ths (ii–V–I) | dreamy maj9 and sus | minor: i–VI–III–VII |
|
|
47
|
+
| keys | FM electric piano | piano, pads, a glassy bell | polysynth, arpeggios, a lead |
|
|
48
|
+
| drums | dusty boom-bap, lazy | soft kick, rim, shaker | punchy, 80s gated snare |
|
|
49
|
+
| texture | crackle, tape wobble, dark | haze, chorus | bright, wide, big reverb |
|
|
50
|
+
|
|
51
|
+
`--energy` runs from 0 (ambient: no drums, sparse) to 1 (driving). `--drift` lets both wander slowly on their own,
|
|
52
|
+
so a long session moves through moods. The presets are points on the two dials (`duskfm --help` lists them).
|
|
53
|
+
|
|
54
|
+
It composes as it goes: chord progressions voiced smoothly from one to the next, melodies grown from short motifs and
|
|
55
|
+
varied each time, sections that thin out and build back, a new key and tempo every few minutes. `--seed` replays
|
|
56
|
+
a session you liked (the seed is shown when you quit).
|
|
57
|
+
|
|
58
|
+
## While it plays
|
|
59
|
+
|
|
60
|
+
| key | |
|
|
61
|
+
|---|---|
|
|
62
|
+
| ← → | style: toward lo-fi, toward synthwave |
|
|
63
|
+
| ↑ ↓ | energy |
|
|
64
|
+
| + − | volume |
|
|
65
|
+
| ] [ | boost (3 dB a press) |
|
|
66
|
+
| r | rain: off, light, heavy |
|
|
67
|
+
| d | drift on or off |
|
|
68
|
+
| n | on to the next section |
|
|
69
|
+
| 1–6 | the presets |
|
|
70
|
+
| space | pause |
|
|
71
|
+
| q | quit (it fades out) |
|
|
72
|
+
|
|
73
|
+
## Loud enough to drown out the room
|
|
74
|
+
|
|
75
|
+
- `--volume` (0–100) is the ordinary level.
|
|
76
|
+
- `--boost DB` (up to 18) is the maximizer behind it: the music is compressed and driven into a soft limiter, so it
|
|
77
|
+
gets much louder without ever clipping. Your speakers' own limit still applies; this gets more out of it.
|
|
78
|
+
- `--rain` adds a soft rain bed shaped to the frequencies speech lives in. Lo-fi is mellow and dark, which is
|
|
79
|
+
lovely and also poor at covering voices; a little rain covers chatter better than a lot more volume, and spares
|
|
80
|
+
your ears. A whole day at high volume is hard on hearing: reach for the rain first.
|
|
81
|
+
|
|
82
|
+
## Playing it
|
|
83
|
+
|
|
84
|
+
On Linux it plays through `paplay` (PulseAudio, or PipeWire's pulse layer), `pw-cat` or `aplay`, whichever is
|
|
85
|
+
there: nothing else to install. Over remote desktop (xrdp), sound comes through when the session has xrdp's
|
|
86
|
+
PulseAudio or PipeWire module; if `paplay` works there, duskfm does. Elsewhere, `pip install "duskfm[sounddevice]"`
|
|
87
|
+
uses PortAudio.
|
|
88
|
+
|
|
89
|
+
No sound where you are? Make a file and play it anywhere:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
duskfm chillwave --render 3h -o afternoon.wav
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`--minutes 90` plays for a while and then fades out.
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
`python3 tests/test_duskfm.py`: every preset renders clean audio at a steady level, a seed replays exactly, nothing
|
|
100
|
+
loops, boost gets louder without clipping, and the player and command line work (no sound card needed). A GitHub
|
|
101
|
+
release `vX.Y.Z` matching `__version__` publishes to PyPI.
|
|
102
|
+
|
duskfm-0.1.0/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# duskfm
|
|
2
|
+
|
|
3
|
+
Endless music from lo-fi to synthwave, made on the spot: never the same twice, all day long.
|
|
4
|
+
|
|
5
|
+
Every sound is synthesized as it plays: an FM electric piano, detuned pads, a polysynth, bass, a drum kit made of
|
|
6
|
+
sweeps and noise, tape wobble, vinyl dust. No samples and nothing recorded, so the package is a few files of Python.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install duskfm
|
|
10
|
+
duskfm # lo-fi
|
|
11
|
+
duskfm synthwave # or: lofi, chillhop, chillwave, synthwave, nightdrive, ambient
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## One dial from lo-fi to synthwave
|
|
15
|
+
|
|
16
|
+
`--style` runs from 0 (lo-fi) to 1 (synthwave), and everything blends along it:
|
|
17
|
+
|
|
18
|
+
| | lo-fi (0) | chillwave (0.5) | synthwave (1) |
|
|
19
|
+
|---|---|---|---|
|
|
20
|
+
| tempo | 72–84, swung | ~85–97 | 94–110, straight |
|
|
21
|
+
| harmony | jazzy 7ths and 9ths (ii–V–I) | dreamy maj9 and sus | minor: i–VI–III–VII |
|
|
22
|
+
| keys | FM electric piano | piano, pads, a glassy bell | polysynth, arpeggios, a lead |
|
|
23
|
+
| drums | dusty boom-bap, lazy | soft kick, rim, shaker | punchy, 80s gated snare |
|
|
24
|
+
| texture | crackle, tape wobble, dark | haze, chorus | bright, wide, big reverb |
|
|
25
|
+
|
|
26
|
+
`--energy` runs from 0 (ambient: no drums, sparse) to 1 (driving). `--drift` lets both wander slowly on their own,
|
|
27
|
+
so a long session moves through moods. The presets are points on the two dials (`duskfm --help` lists them).
|
|
28
|
+
|
|
29
|
+
It composes as it goes: chord progressions voiced smoothly from one to the next, melodies grown from short motifs and
|
|
30
|
+
varied each time, sections that thin out and build back, a new key and tempo every few minutes. `--seed` replays
|
|
31
|
+
a session you liked (the seed is shown when you quit).
|
|
32
|
+
|
|
33
|
+
## While it plays
|
|
34
|
+
|
|
35
|
+
| key | |
|
|
36
|
+
|---|---|
|
|
37
|
+
| ← → | style: toward lo-fi, toward synthwave |
|
|
38
|
+
| ↑ ↓ | energy |
|
|
39
|
+
| + − | volume |
|
|
40
|
+
| ] [ | boost (3 dB a press) |
|
|
41
|
+
| r | rain: off, light, heavy |
|
|
42
|
+
| d | drift on or off |
|
|
43
|
+
| n | on to the next section |
|
|
44
|
+
| 1–6 | the presets |
|
|
45
|
+
| space | pause |
|
|
46
|
+
| q | quit (it fades out) |
|
|
47
|
+
|
|
48
|
+
## Loud enough to drown out the room
|
|
49
|
+
|
|
50
|
+
- `--volume` (0–100) is the ordinary level.
|
|
51
|
+
- `--boost DB` (up to 18) is the maximizer behind it: the music is compressed and driven into a soft limiter, so it
|
|
52
|
+
gets much louder without ever clipping. Your speakers' own limit still applies; this gets more out of it.
|
|
53
|
+
- `--rain` adds a soft rain bed shaped to the frequencies speech lives in. Lo-fi is mellow and dark, which is
|
|
54
|
+
lovely and also poor at covering voices; a little rain covers chatter better than a lot more volume, and spares
|
|
55
|
+
your ears. A whole day at high volume is hard on hearing: reach for the rain first.
|
|
56
|
+
|
|
57
|
+
## Playing it
|
|
58
|
+
|
|
59
|
+
On Linux it plays through `paplay` (PulseAudio, or PipeWire's pulse layer), `pw-cat` or `aplay`, whichever is
|
|
60
|
+
there: nothing else to install. Over remote desktop (xrdp), sound comes through when the session has xrdp's
|
|
61
|
+
PulseAudio or PipeWire module; if `paplay` works there, duskfm does. Elsewhere, `pip install "duskfm[sounddevice]"`
|
|
62
|
+
uses PortAudio.
|
|
63
|
+
|
|
64
|
+
No sound where you are? Make a file and play it anywhere:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
duskfm chillwave --render 3h -o afternoon.wav
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`--minutes 90` plays for a while and then fades out.
|
|
71
|
+
|
|
72
|
+
## Development
|
|
73
|
+
|
|
74
|
+
`python3 tests/test_duskfm.py`: every preset renders clean audio at a steady level, a seed replays exactly, nothing
|
|
75
|
+
loops, boost gets louder without clipping, and the player and command line work (no sound card needed). A GitHub
|
|
76
|
+
release `vX.Y.Z` matching `__version__` publishes to PyPI.
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""duskfm: endless, never-repeating music from lo-fi to synthwave, made on the spot.
|
|
2
|
+
|
|
3
|
+
duskfm lo-fi
|
|
4
|
+
duskfm synthwave a preset: lofi, chillhop, chillwave, synthwave, nightdrive, ambient
|
|
5
|
+
duskfm --style 0.3 --energy 0.6 --drift
|
|
6
|
+
duskfm --boost 9 --rain 0.5 louder than the volume alone goes; a rain bed that covers voices
|
|
7
|
+
duskfm --render 2h -o work.wav to a file instead (e.g. to play somewhere without Python)
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
import select
|
|
15
|
+
import shutil
|
|
16
|
+
import sys
|
|
17
|
+
import time
|
|
18
|
+
import wave
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
from . import __version__
|
|
23
|
+
from .compose import PRESETS, Composer, style_name
|
|
24
|
+
from .engine import Engine
|
|
25
|
+
from .player import Player, backends
|
|
26
|
+
from .synth import SR
|
|
27
|
+
|
|
28
|
+
KEYS_HELP = ("keys: ←/→ style (lo-fi ↔ synthwave) ↑/↓ energy +/- volume ]/[ boost r rain d drift n next "
|
|
29
|
+
"1-6 presets space pause q quit")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def duration(text: str) -> float:
|
|
33
|
+
"""'90m', '2h', '1h30m', '45s', '30' (minutes) -> seconds."""
|
|
34
|
+
if re.fullmatch(r"\d+(\.\d+)?", text):
|
|
35
|
+
return float(text) * 60
|
|
36
|
+
parts = re.findall(r"(\d+(?:\.\d+)?)\s*([hms])", text.lower())
|
|
37
|
+
if not parts or "".join(a + b for a, b in parts) != re.sub(r"\s", "", text.lower()):
|
|
38
|
+
raise argparse.ArgumentTypeError(f"not a length: {text!r} (try 90m, 2h, 1h30m)")
|
|
39
|
+
return sum(float(n) * {"h": 3600, "m": 60, "s": 1}[u] for n, u in parts)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def unit(text: str) -> float:
|
|
43
|
+
v = float(text)
|
|
44
|
+
if not 0 <= v <= 1:
|
|
45
|
+
raise argparse.ArgumentTypeError("between 0 and 1")
|
|
46
|
+
return v
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def parse(argv):
|
|
50
|
+
p = argparse.ArgumentParser(prog="duskfm", description=__doc__.split("\n")[0],
|
|
51
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
52
|
+
epilog="presets: " + ", ".join(f"{k} (style {s}, energy {e})" for k, (s, e) in PRESETS.items())
|
|
53
|
+
+ "\n\n" + KEYS_HELP)
|
|
54
|
+
p.add_argument("preset", nargs="?", choices=list(PRESETS), help="where to start (default lofi)")
|
|
55
|
+
p.add_argument("--style", type=unit, help="0 lo-fi .. 0.5 chillwave .. 1 synthwave")
|
|
56
|
+
p.add_argument("--energy", type=unit, help="0 ambient (no drums) .. 1 driving")
|
|
57
|
+
p.add_argument("--drift", action="store_true", help="let the style and energy wander slowly on their own")
|
|
58
|
+
p.add_argument("--volume", type=float, default=80, help="0-100 (default 80)")
|
|
59
|
+
p.add_argument("--boost", type=float, default=0, help="dB of extra loudness, 0-18: compressed and limited, "
|
|
60
|
+
"so it gets louder without clipping (default 0)")
|
|
61
|
+
p.add_argument("--rain", type=unit, default=0, help="a rain bed shaped to cover voices, 0-1 (default 0)")
|
|
62
|
+
p.add_argument("--seed", type=int, help="replay a session (it's shown when you quit)")
|
|
63
|
+
p.add_argument("--minutes", type=duration, metavar="LENGTH", help="play this long, then fade out (e.g. 90m, 2h)")
|
|
64
|
+
p.add_argument("--backend", help="paplay, pw-cat, aplay or sounddevice (default: the first that's here)")
|
|
65
|
+
p.add_argument("--render", type=duration, metavar="LENGTH", help="write LENGTH of music to a WAV file instead")
|
|
66
|
+
p.add_argument("-o", "--output", default="duskfm.wav", help="the file for --render (default duskfm.wav)")
|
|
67
|
+
p.add_argument("--version", action="version", version=f"duskfm {__version__}")
|
|
68
|
+
a = p.parse_args(argv)
|
|
69
|
+
s, e = PRESETS[a.preset or "lofi"]
|
|
70
|
+
a.style = s if a.style is None else a.style
|
|
71
|
+
a.energy = e if a.energy is None else a.energy
|
|
72
|
+
a.boost = max(0.0, min(18.0, a.boost))
|
|
73
|
+
a.volume = max(0.0, min(100.0, a.volume))
|
|
74
|
+
return a
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def render_file(a) -> int:
|
|
78
|
+
comp = Composer(seed=a.seed, style=a.style, energy=a.energy, drift=a.drift)
|
|
79
|
+
eng = Engine(comp, rain=a.rain, boost=a.boost)
|
|
80
|
+
total, done, fade = int(a.render * SR), 0, int(min(10, a.render / 4) * SR)
|
|
81
|
+
with wave.open(a.output, "wb") as w:
|
|
82
|
+
w.setnchannels(2)
|
|
83
|
+
w.setsampwidth(2)
|
|
84
|
+
w.setframerate(SR)
|
|
85
|
+
while done < total:
|
|
86
|
+
block = eng.render_bar()[: total - done] * (a.volume / 100)
|
|
87
|
+
k = np.clip((total - done - np.arange(len(block))) / fade, 0, 1) # fade out at the end
|
|
88
|
+
w.writeframes((np.clip(block * k[:, None], -1, 1) * 32767).astype("<i2").tobytes())
|
|
89
|
+
done += len(block)
|
|
90
|
+
print(f"\r{a.output}: {done / SR / 60:5.1f} of {total / SR / 60:.1f} min {eng.label} ", end="", flush=True)
|
|
91
|
+
print(f"\ndone (seed {comp.seed})")
|
|
92
|
+
return 0
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class Keys:
|
|
96
|
+
"""Single keypresses from the terminal, without Enter (and without echoing them)."""
|
|
97
|
+
|
|
98
|
+
def __init__(self):
|
|
99
|
+
import termios
|
|
100
|
+
import tty
|
|
101
|
+
self.fd = sys.stdin.fileno()
|
|
102
|
+
self.old = termios.tcgetattr(self.fd)
|
|
103
|
+
tty.setcbreak(self.fd)
|
|
104
|
+
|
|
105
|
+
def read(self, timeout: float) -> str | None:
|
|
106
|
+
if not select.select([sys.stdin], [], [], timeout)[0]:
|
|
107
|
+
return None
|
|
108
|
+
ch = os.read(self.fd, 1).decode(errors="ignore")
|
|
109
|
+
if ch == "\x1b" and select.select([sys.stdin], [], [], 0.02)[0]:
|
|
110
|
+
ch += os.read(self.fd, 2).decode(errors="ignore")
|
|
111
|
+
return ch
|
|
112
|
+
|
|
113
|
+
def close(self):
|
|
114
|
+
import termios
|
|
115
|
+
termios.tcsetattr(self.fd, termios.TCSADRAIN, self.old)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def meter(v: float) -> str:
|
|
119
|
+
n = round(v * 8)
|
|
120
|
+
return "▮" * n + "▯" * (8 - n)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def play(a) -> int:
|
|
124
|
+
comp = Composer(seed=a.seed, style=a.style, energy=a.energy, drift=a.drift)
|
|
125
|
+
eng = Engine(comp, rain=a.rain, boost=a.boost)
|
|
126
|
+
player = Player(eng.render_bar, backend=a.backend)
|
|
127
|
+
player.volume = a.volume / 100
|
|
128
|
+
player.start()
|
|
129
|
+
interactive = sys.stdin.isatty() and sys.stdout.isatty()
|
|
130
|
+
keys = Keys() if interactive else None
|
|
131
|
+
started, rain_levels = time.time(), [0.0, 0.35, 0.7]
|
|
132
|
+
print(f"duskfm {__version__} · playing through {player.backend}" + (f"\n{KEYS_HELP}" if interactive else ""))
|
|
133
|
+
try:
|
|
134
|
+
while not player.stopping.is_set():
|
|
135
|
+
if a.minutes and time.time() - started > a.minutes and not player.fade:
|
|
136
|
+
player.fade_out(30)
|
|
137
|
+
k = keys.read(0.25) if keys else (time.sleep(0.5) or None)
|
|
138
|
+
if k in ("q", "Q", "\x03"):
|
|
139
|
+
player.fade_out(1.5)
|
|
140
|
+
elif k == "\x1b[C":
|
|
141
|
+
comp.style = min(1.0, comp.style + 0.1)
|
|
142
|
+
elif k == "\x1b[D":
|
|
143
|
+
comp.style = max(0.0, comp.style - 0.1)
|
|
144
|
+
elif k == "\x1b[A":
|
|
145
|
+
comp.energy = min(1.0, comp.energy + 0.1)
|
|
146
|
+
elif k == "\x1b[B":
|
|
147
|
+
comp.energy = max(0.0, comp.energy - 0.1)
|
|
148
|
+
elif k in ("+", "="):
|
|
149
|
+
player.volume = min(1.0, player.volume + 0.05)
|
|
150
|
+
elif k in ("-", "_"):
|
|
151
|
+
player.volume = max(0.0, player.volume - 0.05)
|
|
152
|
+
elif k == "]":
|
|
153
|
+
eng.boost = min(18.0, eng.boost + 3)
|
|
154
|
+
elif k == "[":
|
|
155
|
+
eng.boost = max(0.0, eng.boost - 3)
|
|
156
|
+
elif k == "r":
|
|
157
|
+
eng.rain = rain_levels[(rain_levels.index(min(rain_levels, key=lambda v: abs(v - eng.rain))) + 1) % 3]
|
|
158
|
+
elif k == "d":
|
|
159
|
+
comp.drift = not comp.drift
|
|
160
|
+
elif k == "n":
|
|
161
|
+
comp.skip = True
|
|
162
|
+
elif k == " ":
|
|
163
|
+
player.paused = not player.paused
|
|
164
|
+
elif k and k in "123456":
|
|
165
|
+
comp.style, comp.energy = list(PRESETS.values())[int(k) - 1]
|
|
166
|
+
comp.skip = True
|
|
167
|
+
if interactive:
|
|
168
|
+
status = (f"\r\x1b[2K{'❚❚ paused · ' if player.paused else ''}{eng.label or 'tuning in…'} "
|
|
169
|
+
f"style {meter(comp.style)} energy {meter(comp.energy)} vol {round(player.volume * 100)}%"
|
|
170
|
+
f" boost +{eng.boost:g} dB rain {'off' if not eng.rain else f'{eng.rain:g}'}"
|
|
171
|
+
f"{' drift' if comp.drift else ''}")
|
|
172
|
+
cols = shutil.get_terminal_size((100, 24)).columns or 100
|
|
173
|
+
print(status[: cols + 4], end="", flush=True) # +4: the line-clearing code isn't seen
|
|
174
|
+
except KeyboardInterrupt:
|
|
175
|
+
pass
|
|
176
|
+
finally:
|
|
177
|
+
player.stop()
|
|
178
|
+
if keys:
|
|
179
|
+
keys.close()
|
|
180
|
+
print(f"\n{'error: ' + str(player.error) if player.error else 'goodnight'} (seed {comp.seed}: duskfm --seed {comp.seed} "
|
|
181
|
+
f"--style {comp.style:.2f} --energy {comp.energy:.2f} replays it)")
|
|
182
|
+
return 1 if player.error else 0
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def main(argv=None) -> int:
|
|
186
|
+
a = parse(sys.argv[1:] if argv is None else argv)
|
|
187
|
+
if a.render:
|
|
188
|
+
return render_file(a)
|
|
189
|
+
try:
|
|
190
|
+
return play(a)
|
|
191
|
+
except RuntimeError as e:
|
|
192
|
+
print(f"duskfm: {e}", file=sys.stderr)
|
|
193
|
+
return 1
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def cli():
|
|
197
|
+
sys.exit(main())
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
__all__ = ["main", "cli", "backends", "style_name"]
|