Files
app/tools/country_tones.py
Claude 71c649bce1 README as a landing page; D-Modem-RE is now D-Modem; CI skips doc-only changes
The README, titled for Android only, now introduces the app on Android
and iOS with a short feature list, a quick start, the suite's
repositories and the licence. Its sections move to docs/: the modem's
lines, fax, adapters and phone lines, the app screen by screen, building,
the iOS app and the source layout.

D-Modem-RE becomes D-Modem in comments, docs, workflows and the
generator's header, as in brand's naming guide; the build info line says
'D-Modem core <commit>' for the submodule's commit. Identifiers and the
external/d-modem-re path keep their names.

The Android and Apple workflows no longer run for a change to Markdown,
docs/ or COPYING alone (tag pushes still run).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRSqjp9Pn2KBr9N9LAn
2026-11-05 10:46:04 +00:00

73 lines
2.7 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright (C) 2026 Neo-Desktop
"""The countries' tones for the apps' shared Kotlin, from D-Modem's
table (external/d-modem-re/dsp/tones.cpp: the ITU's list of national
networks' tones, after E.180): each country's ringing, dial, busy and
congestion tones, and the table's other names of them.
tools/country_tones.py > shared/src/commonMain/kotlin/org/dmodem/app/tones/CountryTonesTable.kt
CountryTonesTest checks the Kotlin against tones.cpp when the submodule
is there.
"""
import os
import re
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
SRC = os.path.join(HERE, "..", "external", "d-modem-re", "dsp", "tones.cpp")
TONE = r"\{\s*(-?\d+),\s*(-?\d+),\s*([\d.]+)f,\s*(\d+),\s*\{([^}]*)\}\s*\}"
COUNTRY = re.compile(
r'\{\s*"([A-Z0-9_]+)",\s*' + TONE + r",\s*(\d+),\s*" + TONE + r",\s*" + TONE + r",\s*" + TONE + r"\s*\}",
re.S,
)
ALIAS = re.compile(r'\{\s*"([A-Z0-9_]+)",\s*"([A-Z0-9_]+)"\s*\}')
def tone(g, i):
"""the Kotlin Tone() of the tone at i in the match g: its frequencies, modulation and cadence (its first n values)"""
f1, f2, mod, n, cad = g[i:i + 5]
vals = [v.strip().rstrip("f") for v in cad.split(",") if v.strip()][: int(n)]
m = float(mod)
cadence = ", ".join(f"{float(v)}f" for v in vals)
return f"Tone({f1}, {f2}, {m}f, floatArrayOf({cadence}))"
def main():
"""tones.cpp's countries and aliases as CountryTonesTable.kt, to stdout"""
text = open(SRC).read()
countries_part, _, aliases_part = text.partition("const Alias ALIASES[]")
countries = COUNTRY.findall(countries_part)
aliases = ALIAS.findall(aliases_part)
out = sys.stdout
out.write("""// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2026 Neo-Desktop
//
// Generated by tools/country_tones.py from D-Modem's dsp/tones.cpp
// (the ITU's list of the tones of national networks, Annex to ITU
// Operational Bulletin No. 955, after E.180). Don't edit: run it again.
package org.dmodem.app.tones
internal object CountryTonesTable {
val countries: List<CountryTones> = listOf(
""")
for c in countries:
name = c[0]
ringing = tone(c, 1)
ring_hz = c[6]
dial = tone(c, 7)
busy = tone(c, 12)
congestion = tone(c, 17)
out.write(f' CountryTones(\n "{name}",\n {ringing}, {ring_hz},\n'
f" {dial},\n {busy},\n {congestion},\n ),\n")
out.write(" )\n\n val aliases: Map<String, String> = mapOf(\n")
for a, n in aliases:
out.write(f' "{a}" to "{n}",\n')
out.write(" )\n}\n")
print(f"{len(countries)} countries, {len(aliases)} aliases", file=sys.stderr)
main()