ge150-linux 0.3.0__py3-none-any.whl
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.
- ge150/__init__.py +6 -0
- ge150/__main__.py +7 -0
- ge150/cli.py +257 -0
- ge150/cli_ai.py +71 -0
- ge150/cli_edit.py +457 -0
- ge150/cli_hw.py +66 -0
- ge150/cli_settings.py +120 -0
- ge150/cli_t3k.py +104 -0
- ge150/data/__init__.py +0 -0
- ge150/data/chevron-down.svg +1 -0
- ge150/data/effects.json +195 -0
- ge150/data/ge150.svg +22 -0
- ge150/data/gear.json +147 -0
- ge150/formats/__init__.py +1 -0
- ge150/formats/amp_nr.py +70 -0
- ge150/formats/mbf.py +185 -0
- ge150/formats/mo_json.py +157 -0
- ge150/formats/wav_ir.py +160 -0
- ge150/mcp_server/__init__.py +1 -0
- ge150/mcp_server/bridge.py +187 -0
- ge150/mcp_server/install.py +40 -0
- ge150/mcp_server/server.py +245 -0
- ge150/mcp_server/tools.py +494 -0
- ge150/model/__init__.py +1 -0
- ge150/model/catalog.py +118 -0
- ge150/model/device_state.py +214 -0
- ge150/model/gear.py +107 -0
- ge150/model/preset.py +158 -0
- ge150/model/settings.py +145 -0
- ge150/protocol/__init__.py +1 -0
- ge150/protocol/crc.py +28 -0
- ge150/protocol/framing.py +154 -0
- ge150/protocol/messages.py +262 -0
- ge150/protocol/opcodes.py +121 -0
- ge150/protocol/session.py +323 -0
- ge150/services/__init__.py +1 -0
- ge150/services/ai_permissions.py +76 -0
- ge150/services/auto_backup.py +63 -0
- ge150/services/backup.py +111 -0
- ge150/services/bulk_edit.py +276 -0
- ge150/services/chat_history.py +147 -0
- ge150/services/editor.py +303 -0
- ge150/services/guitars.py +255 -0
- ge150/services/hw_check.py +329 -0
- ge150/services/reader.py +126 -0
- ge150/services/tone3000.py +474 -0
- ge150/services/tone_agent.py +246 -0
- ge150/services/tone_ai.py +467 -0
- ge150/sim/__init__.py +1 -0
- ge150/sim/fake_device.py +250 -0
- ge150/sim/sim_transport.py +63 -0
- ge150/ui/__init__.py +1 -0
- ge150/ui/ab_compare.py +105 -0
- ge150/ui/about_dialog.py +246 -0
- ge150/ui/ai_chat.py +682 -0
- ge150/ui/ai_host.py +104 -0
- ge150/ui/ai_options.py +136 -0
- ge150/ui/ai_panel.py +23 -0
- ge150/ui/ai_permissions_dialog.py +161 -0
- ge150/ui/amp_art.py +549 -0
- ge150/ui/app.py +76 -0
- ge150/ui/art_spec.py +298 -0
- ge150/ui/assistant_page.py +360 -0
- ge150/ui/bridge.py +34 -0
- ge150/ui/bulk_form.py +416 -0
- ge150/ui/bulk_review.py +352 -0
- ge150/ui/chain_view.py +474 -0
- ge150/ui/chat_history.py +222 -0
- ge150/ui/dialogs.py +221 -0
- ge150/ui/gear_art.py +515 -0
- ge150/ui/gear_view.py +134 -0
- ge150/ui/guitar_dialog.py +397 -0
- ge150/ui/icons.py +63 -0
- ge150/ui/knob.py +211 -0
- ge150/ui/main_window.py +537 -0
- ge150/ui/markdown.py +55 -0
- ge150/ui/mic_view.py +392 -0
- ge150/ui/model_gallery.py +199 -0
- ge150/ui/module_editor.py +303 -0
- ge150/ui/preset_list.py +133 -0
- ge150/ui/settings_dialog.py +149 -0
- ge150/ui/theme.py +319 -0
- ge150/ui/tone3000_loader.py +102 -0
- ge150/ui/tone3000_page.py +325 -0
- ge150/ui/tone_detail.py +151 -0
- ge150/ui/worker.py +84 -0
- ge150/ui/working.py +117 -0
- ge150/usb/__init__.py +19 -0
- ge150/usb/device_ids.py +28 -0
- ge150/usb/hidraw_transport.py +122 -0
- ge150/usb/transport.py +33 -0
- ge150/usb/usb_transport.py +83 -0
- ge150_linux-0.3.0.dist-info/METADATA +252 -0
- ge150_linux-0.3.0.dist-info/RECORD +98 -0
- ge150_linux-0.3.0.dist-info/WHEEL +5 -0
- ge150_linux-0.3.0.dist-info/entry_points.txt +4 -0
- ge150_linux-0.3.0.dist-info/licenses/LICENSE +21 -0
- ge150_linux-0.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
"""The GE150 as a set of tools for AI clients (transport-agnostic, see ``server.py``).
|
|
2
|
+
|
|
3
|
+
Rules (docs/plan-ia-tone3000.md §3.2, §10): reads are free; changes go to the edit
|
|
4
|
+
buffer only (live, reversible with ``undo``). Writing the pedal's memory (saving a preset,
|
|
5
|
+
storing an IR) needs ``confirm``: the GE150 editor asks the user in a dialog; without the
|
|
6
|
+
editor it is refused. Nothing resets, restores or flashes the pedal. Every method returns
|
|
7
|
+
plain JSON-able data.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import threading
|
|
13
|
+
from collections.abc import Callable, Mapping
|
|
14
|
+
from typing import Any, TypeVar
|
|
15
|
+
|
|
16
|
+
from ge150.model.gear import MODULE_TAGS, describe, gear_for
|
|
17
|
+
from ge150.model.preset import EXP_KEYS, EXP_OFFSET, MODULES, PRESET_COUNT
|
|
18
|
+
from ge150.services import ai_permissions, tone_ai
|
|
19
|
+
from ge150.services.editor import Editor
|
|
20
|
+
|
|
21
|
+
Confirm = Callable[[str], bool]
|
|
22
|
+
#: (question, the 10 slots as list_user_irs shows them) -> chosen slot 1..10, or 0 = cancel.
|
|
23
|
+
PickSlot = Callable[[str, list[dict[str, Any]]], int]
|
|
24
|
+
#: (planned edits of stored presets, summary) -> shown to the user for review.
|
|
25
|
+
OnProposal = Callable[[list[Any], str], None]
|
|
26
|
+
|
|
27
|
+
T = TypeVar("T")
|
|
28
|
+
|
|
29
|
+
INSTRUCTIONS = """Controls a MOOER GE150 guitar multi-effects pedal connected to this computer.
|
|
30
|
+
Signal chain (fixed order): FX -> DS -> AMP -> CAB -> NS -> EQ -> MOD -> DELAY -> REVERB.
|
|
31
|
+
Workflow: read get_current_patch, look up models with get_catalog(module), then change the
|
|
32
|
+
sound with set_module or apply_patch: they change the LOADED preset (get_current_patch
|
|
33
|
+
says which), never another one. Changes are LIVE in the edit buffer and are NOT saved:
|
|
34
|
+
the user saves it (Save in the GE150 editor, or save_preset if they ask you to). Use undo
|
|
35
|
+
to go back. To change several STORED presets (e.g. "every Av83 preset"), read them with
|
|
36
|
+
get_presets(query) and call propose_preset_edits once with a change per preset (the user
|
|
37
|
+
reviews and applies them in the editor): never loop select_preset + save_preset. It also
|
|
38
|
+
renames stored presets (name) and moves or reorders them (copy_from). Use
|
|
39
|
+
only model and parameter names from get_catalog; values outside a range are clamped and
|
|
40
|
+
reported. save_preset and the TONE3000 IR tools write the pedal's memory: they
|
|
41
|
+
only work with the GE150 editor open, which asks the user to confirm each time. TONE3000
|
|
42
|
+
(www.tone3000.com) hosts cabinet IRs made by users: load_tone3000_ir picks the slot itself
|
|
43
|
+
(slot 0) and selects the IR in the CAB module; always tell the user the author and licence
|
|
44
|
+
of an IR you load."""
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ToolError(Exception):
|
|
48
|
+
"""A request the pedal cannot honour (the message is shown to the AI)."""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _module_index(module: str) -> int:
|
|
52
|
+
key = module.strip().upper()
|
|
53
|
+
aliases = {"COMP": "FX", "OD": "DS", "DIST": "DS", "DLY": "DELAY", "REV": "REVERB",
|
|
54
|
+
"GATE": "NS", "NOISE": "NS"}
|
|
55
|
+
key = aliases.get(key, key)
|
|
56
|
+
if key not in MODULE_TAGS:
|
|
57
|
+
raise ToolError(f"unknown module {module!r}; use one of {', '.join(MODULE_TAGS)}")
|
|
58
|
+
return MODULE_TAGS.index(key)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class PedalTools:
|
|
62
|
+
"""Thread-safe facade over an :class:`Editor` (one lock for every pedal access)."""
|
|
63
|
+
|
|
64
|
+
def __init__(self, editor: Editor, lock: threading.Lock | None = None,
|
|
65
|
+
confirm: Confirm | None = None, tone3000: Any = None,
|
|
66
|
+
pick_ir_slot: PickSlot | None = None,
|
|
67
|
+
on_proposal: OnProposal | None = None) -> None:
|
|
68
|
+
self.editor = editor
|
|
69
|
+
self.lock = lock or threading.Lock()
|
|
70
|
+
self.confirm = confirm
|
|
71
|
+
self.pick_ir_slot = pick_ir_slot
|
|
72
|
+
self.on_proposal = on_proposal
|
|
73
|
+
self.history: list[list[int]] = []
|
|
74
|
+
self._tone3000 = tone3000
|
|
75
|
+
|
|
76
|
+
def _ask(self, question: str) -> None:
|
|
77
|
+
"""Ask the user (never while holding the pedal lock)."""
|
|
78
|
+
if self.confirm is None:
|
|
79
|
+
raise ToolError("writing the pedal's memory needs the GE150 editor open (it asks "
|
|
80
|
+
"the user to confirm); ask the user to open it or to do it there")
|
|
81
|
+
if not self.confirm(question):
|
|
82
|
+
raise ToolError("the user declined")
|
|
83
|
+
|
|
84
|
+
def _locked(self, fn: Callable[[], T]) -> T:
|
|
85
|
+
with self.lock:
|
|
86
|
+
if self.editor.state.edit is None:
|
|
87
|
+
raise ToolError("the pedal has not been read yet")
|
|
88
|
+
return fn()
|
|
89
|
+
|
|
90
|
+
# --- reading ----------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
def get_catalog(self, module: str = "") -> dict[str, Any]:
|
|
93
|
+
if not module:
|
|
94
|
+
return {"modules": [
|
|
95
|
+
{"module": tag, "name": info.name,
|
|
96
|
+
"models": len([m for m in info.models if not m.hidden])}
|
|
97
|
+
for tag, info in zip(MODULE_TAGS, self.editor.catalog, strict=True)]}
|
|
98
|
+
index = _module_index(module)
|
|
99
|
+
info = self.editor.catalog[index]
|
|
100
|
+
names = self.editor.state.user_names
|
|
101
|
+
models = []
|
|
102
|
+
for model in info.models:
|
|
103
|
+
if model.hidden:
|
|
104
|
+
continue
|
|
105
|
+
label = model.name
|
|
106
|
+
if model.user_slot: # what to pass back as "model": its name on the pedal
|
|
107
|
+
label = self.editor.model_display(index, model.number - 1)
|
|
108
|
+
entry: dict[str, Any] = {"model": label, "number": model.number}
|
|
109
|
+
gear = gear_for(index, model.number)
|
|
110
|
+
if gear.name:
|
|
111
|
+
entry["based_on" if not gear.generic else "kind"] = gear.name
|
|
112
|
+
if model.user_slot:
|
|
113
|
+
bank = (names.ir if MODULE_TAGS[index] == "CAB" else names.nr) if names else []
|
|
114
|
+
slot = model.number - (27 if MODULE_TAGS[index] == "CAB" else 56)
|
|
115
|
+
entry["user_slot"] = bank[slot] if 0 <= slot < len(bank) else "?"
|
|
116
|
+
entry["params"] = [_param_info(p) for p in model.params]
|
|
117
|
+
models.append(entry)
|
|
118
|
+
return {"module": MODULE_TAGS[index], "name": info.name, "models": models}
|
|
119
|
+
|
|
120
|
+
def get_current_patch(self) -> dict[str, Any]:
|
|
121
|
+
return self._locked(self._patch)
|
|
122
|
+
|
|
123
|
+
def _patch(self) -> dict[str, Any]:
|
|
124
|
+
state = self.editor.state
|
|
125
|
+
stored = state.presets.get(state.current_slot or 0)
|
|
126
|
+
edit = state.edit
|
|
127
|
+
modules = []
|
|
128
|
+
for index in range(len(MODULES)):
|
|
129
|
+
block = self.editor.module(index)
|
|
130
|
+
model = self.editor.catalog[index].model_for_type(block.type)
|
|
131
|
+
entry: dict[str, Any] = {"module": MODULE_TAGS[index], "on": block.switch,
|
|
132
|
+
"model": self.editor.model_display(index, block.type)}
|
|
133
|
+
if model is not None:
|
|
134
|
+
gear = gear_for(index, model.number)
|
|
135
|
+
entry["based_on"] = describe(gear, False)
|
|
136
|
+
entry["params"] = {p.name: p.format(block.words[p.word]) for p in model.params}
|
|
137
|
+
modules.append(entry)
|
|
138
|
+
exp = {key: edit.words[EXP_OFFSET + i] for i, key in enumerate(EXP_KEYS)} if edit else {}
|
|
139
|
+
return {"slot": state.current_slot, "name": stored.name if stored else "",
|
|
140
|
+
"unsaved_changes": state.dirty, "modules": modules, "expression_pedal": exp}
|
|
141
|
+
|
|
142
|
+
def list_presets(self, query: str = "") -> dict[str, Any]:
|
|
143
|
+
needle = query.strip().lower()
|
|
144
|
+
presets = [{"slot": slot, "name": preset.name}
|
|
145
|
+
for slot, preset in sorted(self.editor.state.presets.items())
|
|
146
|
+
if needle in preset.name.lower()]
|
|
147
|
+
return {"current": self.editor.state.current_slot, "presets": presets}
|
|
148
|
+
|
|
149
|
+
def get_preset(self, slot: int) -> dict[str, Any]:
|
|
150
|
+
preset = self.editor.state.presets.get(slot)
|
|
151
|
+
if preset is None:
|
|
152
|
+
raise ToolError(f"preset {slot} not loaded (1..{PRESET_COUNT})")
|
|
153
|
+
modules = []
|
|
154
|
+
for index in range(len(MODULES)):
|
|
155
|
+
block = preset.module(index)
|
|
156
|
+
model = self.editor.catalog[index].model_for_type(block.type)
|
|
157
|
+
modules.append({"module": MODULE_TAGS[index], "on": block.switch,
|
|
158
|
+
"model": self.editor.model_display(index, block.type),
|
|
159
|
+
"params": {p.name: p.format(block.words[p.word])
|
|
160
|
+
for p in (model.params if model else ())}})
|
|
161
|
+
return {"slot": slot, "name": preset.name, "modules": modules}
|
|
162
|
+
|
|
163
|
+
def get_presets(self, query: str) -> dict[str, Any]:
|
|
164
|
+
"""Every stored preset whose name contains ``query``, decoded (one call)."""
|
|
165
|
+
found = self.list_presets(query)["presets"]
|
|
166
|
+
if not found:
|
|
167
|
+
raise ToolError(f"no preset name contains {query!r}")
|
|
168
|
+
return {"presets": [self.get_preset(p["slot"]) for p in found[:40]],
|
|
169
|
+
**({"note": f"first 40 of {len(found)}"} if len(found) > 40 else {})}
|
|
170
|
+
|
|
171
|
+
def list_user_irs(self) -> dict[str, Any]:
|
|
172
|
+
from ge150.services.tone3000 import IrSources
|
|
173
|
+
|
|
174
|
+
names = self.editor.state.user_names
|
|
175
|
+
if names is None:
|
|
176
|
+
return {"ir": []}
|
|
177
|
+
# The NR (AMP 56-65) slots are left out: hidden like in the official editor.
|
|
178
|
+
sources, users = IrSources().matching(names.ir), self._ir_users()
|
|
179
|
+
return {"ir": [_ir_entry(i, n, sources, users) for i, n in enumerate(names.ir)]}
|
|
180
|
+
|
|
181
|
+
def _ir_users(self) -> dict[int, list[int]]:
|
|
182
|
+
"""User IR slot (1..10) -> the stored presets whose CAB uses it."""
|
|
183
|
+
cab = MODULE_TAGS.index("CAB")
|
|
184
|
+
users: dict[int, list[int]] = {}
|
|
185
|
+
for model in self.editor.catalog[cab].models:
|
|
186
|
+
if model.user_slot and (slots := self.editor.presets_using(cab, model.number - 1)):
|
|
187
|
+
users[model.number - 26] = slots
|
|
188
|
+
return users
|
|
189
|
+
|
|
190
|
+
def get_guitar(self) -> dict[str, Any]:
|
|
191
|
+
from dataclasses import asdict
|
|
192
|
+
|
|
193
|
+
from ge150.services.guitars import GuitarStore
|
|
194
|
+
|
|
195
|
+
guitar = GuitarStore().current
|
|
196
|
+
if guitar is None:
|
|
197
|
+
return {"guitar": None, "note": "the user has not chosen a guitar in the editor"}
|
|
198
|
+
data = {k: v for k, v in asdict(guitar).items() if v and k not in ("id", "serial")}
|
|
199
|
+
return {"guitar": data}
|
|
200
|
+
|
|
201
|
+
def get_settings(self) -> dict[str, Any]:
|
|
202
|
+
result: dict[str, Any] = {}
|
|
203
|
+
system, rhythm = self.editor.system_values(), self.editor.rhythm_values()
|
|
204
|
+
if system is not None:
|
|
205
|
+
result["system"] = dict(system.describe())
|
|
206
|
+
if rhythm is not None:
|
|
207
|
+
result["rhythm"] = dict(rhythm.describe())
|
|
208
|
+
return result
|
|
209
|
+
|
|
210
|
+
# --- live changes -----------------------------------------------------------------
|
|
211
|
+
|
|
212
|
+
def set_module(self, module: str, on: bool | None = None, model: str = "",
|
|
213
|
+
params: Mapping[str, str | float] | None = None) -> dict[str, Any]:
|
|
214
|
+
index = _module_index(module)
|
|
215
|
+
current = self.editor.module(index)
|
|
216
|
+
entry = {"module": MODULE_TAGS[index],
|
|
217
|
+
"on": current.switch if on is None else on, "model": model,
|
|
218
|
+
"params": [{"name": k, "value": str(v)} for k, v in (params or {}).items()]}
|
|
219
|
+
return self.apply_patch([entry])
|
|
220
|
+
|
|
221
|
+
def apply_patch(self, modules: list[dict[str, Any]], name: str = "") -> dict[str, Any]:
|
|
222
|
+
def run() -> dict[str, Any]:
|
|
223
|
+
proposal = tone_ai.parse_proposal(
|
|
224
|
+
{"name": name, "explanation": "", "modules": modules}, self.editor)
|
|
225
|
+
edit = self.editor.state.edit
|
|
226
|
+
if edit is not None:
|
|
227
|
+
self.history.append(list(edit.words))
|
|
228
|
+
tone_ai.apply_proposal(self.editor, proposal)
|
|
229
|
+
return {"applied": proposal.describe(self.editor.catalog),
|
|
230
|
+
"warnings": proposal.warnings,
|
|
231
|
+
"note": "live only, not saved yet"}
|
|
232
|
+
|
|
233
|
+
try:
|
|
234
|
+
return self._locked(run)
|
|
235
|
+
except tone_ai.ToneAIError as exc:
|
|
236
|
+
raise ToolError(str(exc)) from exc
|
|
237
|
+
|
|
238
|
+
def undo(self) -> dict[str, Any]:
|
|
239
|
+
def run() -> dict[str, Any]:
|
|
240
|
+
if not self.history:
|
|
241
|
+
return {"undone": False, "reason": "nothing to undo"}
|
|
242
|
+
tone_ai.restore_words(self.editor, self.history.pop())
|
|
243
|
+
return {"undone": True, "remaining": len(self.history)}
|
|
244
|
+
|
|
245
|
+
return self._locked(run)
|
|
246
|
+
|
|
247
|
+
def select_preset(self, slot: int, discard_changes: bool = False) -> dict[str, Any]:
|
|
248
|
+
def run() -> dict[str, Any]:
|
|
249
|
+
if not 1 <= slot <= PRESET_COUNT:
|
|
250
|
+
raise ToolError(f"slot must be 1..{PRESET_COUNT}")
|
|
251
|
+
if self.editor.state.dirty and not discard_changes:
|
|
252
|
+
raise ToolError("the current preset has unsaved changes: ask the user whether "
|
|
253
|
+
"to discard them, then call again with discard_changes=true")
|
|
254
|
+
self.editor.select(slot)
|
|
255
|
+
self.history.clear()
|
|
256
|
+
return self._patch()
|
|
257
|
+
|
|
258
|
+
return self._locked(run)
|
|
259
|
+
|
|
260
|
+
# --- writing the pedal's memory (confirmed by the user) ---------------------------------
|
|
261
|
+
|
|
262
|
+
def save_preset(self, slot: int = 0, name: str = "") -> dict[str, Any]:
|
|
263
|
+
state = self.editor.state
|
|
264
|
+
target = slot or state.current_slot or 0
|
|
265
|
+
if not 1 <= target <= PRESET_COUNT:
|
|
266
|
+
raise ToolError(f"slot must be 1..{PRESET_COUNT}")
|
|
267
|
+
old = state.presets.get(target)
|
|
268
|
+
label = name or (old.name if old else "")
|
|
269
|
+
self._ask(f"¿Guardar el sonido actual en el preset {target} «{label}»?\n"
|
|
270
|
+
f"Reemplaza «{old.name if old else '?'}».")
|
|
271
|
+
|
|
272
|
+
def run() -> dict[str, Any]:
|
|
273
|
+
try:
|
|
274
|
+
preset = self.editor.save(target, name or None)
|
|
275
|
+
except Exception as exc: # EditorError: invalid name...
|
|
276
|
+
raise ToolError(str(exc)) from exc
|
|
277
|
+
self.history.clear()
|
|
278
|
+
return {"saved": True, "slot": target, "name": preset.name}
|
|
279
|
+
|
|
280
|
+
return self._locked(run)
|
|
281
|
+
|
|
282
|
+
def propose_preset_edits(self, edits: list[dict[str, Any]],
|
|
283
|
+
summary: str = "") -> dict[str, Any]:
|
|
284
|
+
"""Plan changes to stored presets; the user reviews and applies them in the editor."""
|
|
285
|
+
from ge150.services import bulk_edit
|
|
286
|
+
|
|
287
|
+
if self.on_proposal is None:
|
|
288
|
+
raise ToolError("changing stored presets needs the GE150 editor open (the user "
|
|
289
|
+
"reviews the changes there); ask the user to open it")
|
|
290
|
+
planned = self._locked(lambda: bulk_edit.plan_edits(self.editor, edits))
|
|
291
|
+
if not any(e.changed and not e.blocked for e in planned):
|
|
292
|
+
return {"proposed": False, "presets": bulk_edit.describe(self.editor, planned),
|
|
293
|
+
"reason": "nothing would change"}
|
|
294
|
+
self.on_proposal(planned, summary)
|
|
295
|
+
return {"proposed": True, "presets": bulk_edit.describe(self.editor, planned),
|
|
296
|
+
"note": "NOT written yet: the user reviews them in the Asistente tab and "
|
|
297
|
+
"applies (or discards) them"}
|
|
298
|
+
|
|
299
|
+
# --- TONE3000 cabinet IRs ---------------------------------------------------------
|
|
300
|
+
|
|
301
|
+
@property
|
|
302
|
+
def tone3000(self) -> Any:
|
|
303
|
+
if self._tone3000 is None:
|
|
304
|
+
from ge150.services.tone3000 import Tone3000Client
|
|
305
|
+
|
|
306
|
+
self._tone3000 = Tone3000Client()
|
|
307
|
+
return self._tone3000
|
|
308
|
+
|
|
309
|
+
def _t3k(self, fn: Callable[[], T]) -> T:
|
|
310
|
+
from ge150.services.tone3000 import Tone3000Error
|
|
311
|
+
|
|
312
|
+
client = self.tone3000
|
|
313
|
+
store = getattr(client, "store", None)
|
|
314
|
+
if store is not None: # the editor may have signed in (or out) since the last call
|
|
315
|
+
client.creds = store.load()
|
|
316
|
+
if not client.creds.signed_in:
|
|
317
|
+
raise ToolError("not signed in to TONE3000: ask the user to press «Conectar "
|
|
318
|
+
"cuenta» in the TONE3000 tab of the GE150 editor (or to run "
|
|
319
|
+
"'ge150ctl t3k-login')")
|
|
320
|
+
try:
|
|
321
|
+
return fn()
|
|
322
|
+
except Tone3000Error as exc:
|
|
323
|
+
raise ToolError(str(exc)) from exc
|
|
324
|
+
|
|
325
|
+
def tone3000_search(self, query: str) -> dict[str, Any]:
|
|
326
|
+
tones = self._t3k(lambda: self.tone3000.search(query))
|
|
327
|
+
return {"note": "TONE3000 limits searches: search few times, with precise words",
|
|
328
|
+
"tones": [{"tone_id": t.id, "title": t.title, "author": t.author,
|
|
329
|
+
"license": t.license, "gear": t.gear, "url": t.page_url,
|
|
330
|
+
"description": t.description[:200]} for t in tones]}
|
|
331
|
+
|
|
332
|
+
def tone3000_get(self, tone_id: int) -> dict[str, Any]:
|
|
333
|
+
tone = self._t3k(lambda: self.tone3000.tone(tone_id))
|
|
334
|
+
models = self._t3k(lambda: self.tone3000.models(tone_id))
|
|
335
|
+
return {"tone_id": tone.id, "title": tone.title, "author": tone.author,
|
|
336
|
+
"license": tone.license, "format": tone.format, "url": tone.page_url,
|
|
337
|
+
"description": tone.description[:500],
|
|
338
|
+
"files": [{"model_id": m.id, "name": m.name} for m in models]}
|
|
339
|
+
|
|
340
|
+
def load_tone3000_ir(self, slot: int = 0, tone_id: int = 0, model_id: int = 0,
|
|
341
|
+
name: str = "", use: bool = True) -> dict[str, Any]:
|
|
342
|
+
"""Download a TONE3000 IR (or let the user pick one in the browser when
|
|
343
|
+
``tone_id`` is 0), store it in user IR slot ``slot`` (1..10; 0 = a free one, or the
|
|
344
|
+
one already holding this IR) and, with ``use``, select it in the CAB module."""
|
|
345
|
+
from ge150.formats import wav_ir
|
|
346
|
+
from ge150.protocol import messages as msg
|
|
347
|
+
from ge150.protocol.opcodes import Op
|
|
348
|
+
from ge150.services.tone3000 import IrSources
|
|
349
|
+
|
|
350
|
+
if not 0 <= slot <= 10:
|
|
351
|
+
raise ToolError("IR slot must be 1..10 (models CAB 27..36), or 0 for a free one")
|
|
352
|
+
chosen = tone_id or self._t3k(self.tone3000.select_tone)
|
|
353
|
+
download = self._t3k(lambda: self.tone3000.download(chosen, model_id or None))
|
|
354
|
+
tone = download.tone
|
|
355
|
+
try:
|
|
356
|
+
payload = wav_ir.load_ir_file(download.path)
|
|
357
|
+
except ValueError as exc:
|
|
358
|
+
raise ToolError(f"cannot use this IR: {exc}") from exc
|
|
359
|
+
label = (name or tone.title)[: msg.USER_NAME_LEN]
|
|
360
|
+
names = self.editor.state.user_names
|
|
361
|
+
bank = list(names.ir) if names else [""] * 10
|
|
362
|
+
sources = IrSources().matching(bank)
|
|
363
|
+
what = (f"la IR de TONE3000 «{tone.title} / {download.model.name}»\nde {tone.author} "
|
|
364
|
+
f"(licencia {tone.license})")
|
|
365
|
+
result = {"slot": 0, "model": "", "name": label, "tone": tone.title,
|
|
366
|
+
"file": download.model.name, "author": tone.author,
|
|
367
|
+
"license": tone.license, "url": tone.page_url}
|
|
368
|
+
if not slot and (loaded := _slot_holding(sources, tone.id, download.model.name)):
|
|
369
|
+
result.update(stored=False, slot=loaded, name=bank[loaded - 1],
|
|
370
|
+
note="this IR was already on the pedal")
|
|
371
|
+
else:
|
|
372
|
+
if not slot:
|
|
373
|
+
slot = next((i + 1 for i, n in enumerate(bank) if msg.is_empty_slot_name(n)), 0)
|
|
374
|
+
if slot:
|
|
375
|
+
old = bank[slot - 1]
|
|
376
|
+
replaces = "" if msg.is_empty_slot_name(old) else f"\nReemplaza «{old}»."
|
|
377
|
+
self._ask(f"¿Guardar {what} en la ranura {slot} (CAB {26 + slot}) como "
|
|
378
|
+
f"«{label}»?{replaces}")
|
|
379
|
+
else:
|
|
380
|
+
slot = self._pick_slot(f"Las 10 ranuras de IR están ocupadas. ¿Cuál reemplazo "
|
|
381
|
+
f"por «{tone.title} / {download.model.name}» de "
|
|
382
|
+
f"{tone.author} (licencia {tone.license})?",
|
|
383
|
+
[_ir_entry(i, n, sources, self._ir_users())
|
|
384
|
+
for i, n in enumerate(bank)])
|
|
385
|
+
|
|
386
|
+
def store() -> None:
|
|
387
|
+
self.editor.upload_user_slot(Op.USER_IR, slot - 1, label, payload)
|
|
388
|
+
|
|
389
|
+
self._locked(store)
|
|
390
|
+
IrSources().record(slot, download, label)
|
|
391
|
+
result.update(stored=True, slot=slot)
|
|
392
|
+
result["model"] = f"CAB {26 + result['slot']}"
|
|
393
|
+
if use:
|
|
394
|
+
self.apply_patch([{"module": "CAB", "on": True, "model": result["model"]}])
|
|
395
|
+
result["selected"] = True
|
|
396
|
+
result["note"] = (f"{result.get('note', 'stored')}; selected in the CAB module "
|
|
397
|
+
"(live; undo reverts the selection, not the stored IR)")
|
|
398
|
+
return result
|
|
399
|
+
|
|
400
|
+
def _pick_slot(self, question: str, slots: list[dict[str, Any]]) -> int:
|
|
401
|
+
"""Ask the user which user IR slot to overwrite (1..10)."""
|
|
402
|
+
if self.pick_ir_slot is None:
|
|
403
|
+
raise ToolError("all 10 user IR slots are in use: show the user list_user_irs, ask "
|
|
404
|
+
"which one to overwrite and call again with that slot")
|
|
405
|
+
picked = self.pick_ir_slot(question, slots)
|
|
406
|
+
if not picked:
|
|
407
|
+
raise ToolError("the user declined")
|
|
408
|
+
return int(picked)
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def _slot_holding(sources: dict[str, dict[str, Any]], tone_id: int, file: str) -> int:
|
|
412
|
+
"""The user IR slot that already holds this TONE3000 file (0 = none)."""
|
|
413
|
+
for slot, source in sources.items():
|
|
414
|
+
if source.get("tone_id") == tone_id and source.get("model") == file:
|
|
415
|
+
return int(slot)
|
|
416
|
+
return 0
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def _ir_entry(index: int, name: str, sources: dict[str, dict[str, Any]],
|
|
420
|
+
users: dict[int, list[int]]) -> dict[str, Any]:
|
|
421
|
+
entry: dict[str, Any] = {"slot": index + 1, "model": f"CAB {27 + index}", "name": name,
|
|
422
|
+
"used_by_presets": users.get(index + 1, [])}
|
|
423
|
+
source = sources.get(str(index + 1))
|
|
424
|
+
if source:
|
|
425
|
+
entry["tone3000"] = {k: source.get(k) for k in
|
|
426
|
+
("title", "model", "author", "license", "url")}
|
|
427
|
+
entry["tone3000"]["description"] = str(source.get("description") or "")[:300]
|
|
428
|
+
return entry
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def _param_info(param: Any) -> dict[str, Any]:
|
|
432
|
+
if param.kind == "enum":
|
|
433
|
+
return {"name": param.name, "options": list(param.options)}
|
|
434
|
+
if param.kind == "number":
|
|
435
|
+
info: dict[str, Any] = {"name": param.name, "min": param.min, "max": param.max}
|
|
436
|
+
if param.step != 1:
|
|
437
|
+
info["step"] = param.step
|
|
438
|
+
if param.unit:
|
|
439
|
+
info["unit"] = param.unit
|
|
440
|
+
return info
|
|
441
|
+
return {"name": param.name}
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
#: Permissions (``services/ai_permissions.py``) each tool needs; reading needs none.
|
|
445
|
+
TOOL_PERMISSIONS: dict[str, tuple[str, ...]] = {
|
|
446
|
+
"set_module": ("live",), "apply_patch": ("live",), "undo": ("live",),
|
|
447
|
+
"select_preset": ("live",), "save_preset": ("save",),
|
|
448
|
+
"tone3000_search": ("tone3000",), "tone3000_get": ("tone3000",),
|
|
449
|
+
"load_tone3000_ir": ("tone3000", "load_ir")}
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
def required_permissions(tool: str, edits: Any = None) -> list[str]:
|
|
453
|
+
"""What a call needs; ``propose_preset_edits`` depends on what its ``edits`` change."""
|
|
454
|
+
keys = list(TOOL_PERMISSIONS.get(tool, ()))
|
|
455
|
+
if tool == "propose_preset_edits":
|
|
456
|
+
for edit in edits if isinstance(edits, list) else []:
|
|
457
|
+
if not isinstance(edit, Mapping):
|
|
458
|
+
continue
|
|
459
|
+
for field, key in (("modules", "edit_presets"), ("name", "rename"),
|
|
460
|
+
("copy_from", "move")):
|
|
461
|
+
if edit.get(field) and key not in keys:
|
|
462
|
+
keys.append(key)
|
|
463
|
+
return keys
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
class GuardedTools:
|
|
467
|
+
"""The tools as the AI sees them: every call first checks the user's permissions
|
|
468
|
+
(read again each time, so a change applies at once). The GUI's own buttons use the
|
|
469
|
+
plain :class:`PedalTools`."""
|
|
470
|
+
|
|
471
|
+
def __init__(self, tools: Any,
|
|
472
|
+
permissions: Callable[[], ai_permissions.Permissions] = ai_permissions.load
|
|
473
|
+
) -> None:
|
|
474
|
+
self.tools = tools
|
|
475
|
+
self.permissions = permissions
|
|
476
|
+
|
|
477
|
+
def check(self, tool: str, edits: Any = None) -> None:
|
|
478
|
+
denied = self.permissions().missing(required_permissions(tool, edits))
|
|
479
|
+
if denied:
|
|
480
|
+
names = ", ".join(f"«{d}»" for d in denied)
|
|
481
|
+
raise ToolError(f"the user turned off {names} in the assistant's permissions "
|
|
482
|
+
"(gear button of the chat): do not try it again; tell the user "
|
|
483
|
+
"it is off and that they can turn it on there")
|
|
484
|
+
|
|
485
|
+
def __getattr__(self, name: str) -> Any:
|
|
486
|
+
target = getattr(self.tools, name)
|
|
487
|
+
if name.startswith("_") or not callable(target):
|
|
488
|
+
return target
|
|
489
|
+
|
|
490
|
+
def call(*args: Any, **kwargs: Any) -> Any:
|
|
491
|
+
self.check(name, kwargs.get("edits", args[0] if args else None))
|
|
492
|
+
return target(*args, **kwargs)
|
|
493
|
+
|
|
494
|
+
return call
|
ge150/model/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Device data model: preset layout, effect catalogue and device state."""
|
ge150/model/catalog.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Effect catalogue loaded from ``data/effects.json`` (generated by tools/build_catalog.py).
|
|
2
|
+
|
|
3
|
+
Raw value encoding [V], fitted to 200 real presets and confirmed on the pedal's screen
|
|
4
|
+
(PITCH raw 65 shows -5.5; plan.md §2.7):
|
|
5
|
+
``raw = round((value - min(min, 0)) / step)``. Negative ranges are shifted (EQ 0 dB = 16,
|
|
6
|
+
PITCH 0.0 = 120, DETUNE 0.0 = 200) and positive ranges are stored as-is (delay TIME
|
|
7
|
+
40..2500 ms is stored in ms). Enums store the option index.
|
|
8
|
+
Each parameter also knows its ``word`` (index inside the module block).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from functools import cache
|
|
16
|
+
from importlib import resources
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from ge150.model.preset import MODULES
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class Param:
|
|
24
|
+
name: str
|
|
25
|
+
kind: str # "number" | "enum" | "raw"
|
|
26
|
+
min: float = 0
|
|
27
|
+
max: float = 0
|
|
28
|
+
step: float = 1
|
|
29
|
+
decimals: int = 0
|
|
30
|
+
unit: str = ""
|
|
31
|
+
options: tuple[str, ...] = ()
|
|
32
|
+
word: int = 2
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def offset(self) -> float:
|
|
36
|
+
return min(self.min, 0)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def raw_max(self) -> int:
|
|
40
|
+
if self.kind == "enum":
|
|
41
|
+
return len(self.options) - 1
|
|
42
|
+
return round((self.max - self.offset) / self.step)
|
|
43
|
+
|
|
44
|
+
def to_raw(self, value: float | str) -> int:
|
|
45
|
+
if self.kind == "enum":
|
|
46
|
+
index = self.options.index(value) if isinstance(value, str) else int(value)
|
|
47
|
+
if not 0 <= index < len(self.options):
|
|
48
|
+
raise ValueError(f"{self.name}: option index out of range")
|
|
49
|
+
return index
|
|
50
|
+
number = float(value)
|
|
51
|
+
if not self.min <= number <= self.max:
|
|
52
|
+
raise ValueError(f"{self.name}: {number} outside {self.min}..{self.max}")
|
|
53
|
+
return round((number - self.offset) / self.step)
|
|
54
|
+
|
|
55
|
+
def from_raw(self, raw: int) -> float | str:
|
|
56
|
+
if self.kind == "enum":
|
|
57
|
+
return self.options[raw] if 0 <= raw < len(self.options) else f"?{raw}"
|
|
58
|
+
value = self.offset + raw * self.step
|
|
59
|
+
return round(value, self.decimals) if self.decimals else round(value)
|
|
60
|
+
|
|
61
|
+
def format(self, raw: int) -> str:
|
|
62
|
+
value = self.from_raw(raw)
|
|
63
|
+
if isinstance(value, str):
|
|
64
|
+
return value
|
|
65
|
+
text = f"{value:.{self.decimals}f}"
|
|
66
|
+
return f"{text} {self.unit}".strip()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@dataclass(frozen=True)
|
|
70
|
+
class Model:
|
|
71
|
+
number: int # as shown by the pedal ("01:CRY WAH" -> 1)
|
|
72
|
+
name: str
|
|
73
|
+
params: tuple[Param, ...]
|
|
74
|
+
user_slot: bool = False
|
|
75
|
+
hidden: bool = False
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def label(self) -> str:
|
|
79
|
+
return f"{self.number:02d}:{self.name}"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass(frozen=True)
|
|
83
|
+
class ModuleInfo:
|
|
84
|
+
index: int
|
|
85
|
+
name: str
|
|
86
|
+
models: tuple[Model, ...]
|
|
87
|
+
|
|
88
|
+
def model_for_type(self, type_word: int) -> Model | None:
|
|
89
|
+
"""Model for a TYPE word. TYPE is 0-based (number - 1), verified on 200 presets."""
|
|
90
|
+
if 0 <= type_word < len(self.models):
|
|
91
|
+
return self.models[type_word]
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _param(data: dict[str, Any]) -> Param:
|
|
96
|
+
if data["kind"] == "enum":
|
|
97
|
+
return Param(data["name"], "enum", options=tuple(data["options"]), word=data["word"])
|
|
98
|
+
if data["kind"] == "number":
|
|
99
|
+
return Param(data["name"], "number", data["min"], data["max"], data["step"],
|
|
100
|
+
data["decimals"], data.get("unit", ""), word=data["word"])
|
|
101
|
+
return Param(data["name"], "raw", word=data["word"])
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@cache
|
|
105
|
+
def load_catalog() -> tuple[ModuleInfo, ...]:
|
|
106
|
+
text = resources.files("ge150.data").joinpath("effects.json").read_text()
|
|
107
|
+
raw = json.loads(text)
|
|
108
|
+
modules = []
|
|
109
|
+
for m in raw["modules"]:
|
|
110
|
+
models = tuple(
|
|
111
|
+
Model(x["number"], x["name"], tuple(_param(p) for p in x["params"]),
|
|
112
|
+
x.get("user_slot", False), x.get("hidden_in_vendor_ui", False))
|
|
113
|
+
for x in m["models"]
|
|
114
|
+
)
|
|
115
|
+
modules.append(ModuleInfo(m["index"], m["name"], models))
|
|
116
|
+
if [m.name for m in modules] != [layout.name for layout in MODULES]:
|
|
117
|
+
raise ValueError("effects.json module order does not match the preset layout")
|
|
118
|
+
return tuple(modules)
|