#!/usr/bin/env python3 """Build the "quiet" Tascam DA-6400 Companion module (1.3.1-quiet) from the stock 1.3.0. The stock module polls the recorder every 200 ms. The recorder rejects one of those polls with an "F2 Illegal Status" reply, and the module logs a warning for every reply: about 430,000 warnings a day in Companion's log. This build logs it at most once a minute and names the commands that were just sent. Nothing else changes. On NA Ingest the stock module is in ~/Library/Application Support/companion/modules/tascam-da-6400-1.3.0 python3 make_quiet_tascam.py Writes /tascam-da-6400-1.3.1-quiet.tgz. Import it in Companion under Modules -> Import module package, then pick 1.3.1-quiet on the Tascam connection. """ import json import os import shutil import sys import tarfile import tempfile VERSION = "1.3.1-quiet" PATCHES = [ # remember the last two commands sent, so the warning can name the rejected one ("return this.socket.send(e+c),!0", "return this.spSent=[(this.spSent||[]).slice(-1)[0],e].filter(Boolean),this.socket.send(e+c),!0"), # log "Illegal Status" at most once a minute, with a count ('case n.illegalStatus:this.log("warn",`Illegal Status: Invalid Command ${t.substr(3)}`);break;', 'case n.illegalStatus:{const q=Date.now();this.spIllegal=(this.spIllegal||0)+1;' 'if(!this.spIllegalAt||q-this.spIllegalAt>6e4){this.log("warn",`Illegal Status: Invalid Command ' '${t.substr(3)} (last commands sent: ${(this.spSent||[]).join(", ")}; ${this.spIllegal} rejected ' 'since the last report - reported at most once a minute)`);this.spIllegalAt=q;this.spIllegal=0}}break;'), ] def build(src, out_dir): with tempfile.TemporaryDirectory() as tmp: dst = os.path.join(tmp, "tascam-da-6400") shutil.copytree(src, dst) main = os.path.join(dst, "main.js") code = open(main, encoding="utf-8").read() for old, new in PATCHES: if code.count(old) != 1: sys.exit("main.js does not look like the stock 1.3.0 module (patch anchor not found)") code = code.replace(old, new) open(main, "w", encoding="utf-8").write(code) for name in ("companion/manifest.json", "package.json"): path = os.path.join(dst, name) data = json.load(open(path)) data["version"] = VERSION json.dump(data, open(path, "w"), indent="\t") with open(os.path.join(dst, "companion/HELP.md"), "a") as f: f.write("\n\n## %s (Waters Church build)\n\nSame as 1.3.0, except the recorder's " "\"Illegal Status\" reply is logged at most once a minute, with the commands " "that were just sent, instead of 5 times a second.\n" % VERSION) out = os.path.join(out_dir, "tascam-da-6400-%s.tgz" % VERSION) with tarfile.open(out, "w:gz") as tar: tar.add(dst, arcname="tascam-da-6400") print(out) if __name__ == "__main__": if len(sys.argv) != 3: sys.exit(__doc__) build(sys.argv[1], sys.argv[2])