Loading files
// AUTO-GENERATED by scripts/gen_amy_js_api.py — do not edit by hand.
// Source: amy/__init__.py
(function() {
"use strict";
var AMY_KW_MAP = {
osc: {wire: "v", type: "I"},
wave: {wire: "w", type: "I"},
note: {wire: "n", type: "F"},
vel: {wire: "l", type: "F"},
amp: {wire: "a", type: "C"},
freq: {wire: "f", type: "C"},
duty: {wire: "d", type: "C"},
feedback: {wire: "b", type: "F"},
time: {wire: "t", type: "I"},
reset: {wire: "S", type: "I"},
phase: {wire: "P", type: "F"},
pan: {wire: "Q", type: "C"},
client: {wire: "g", type: "I"},
volume: {wire: "V", type: "F"},
pitch_bend: {wire: "s", type: "F"},
filter_freq: {wire: "F", type: "C"},
resonance: {wire: "R", type: "F"},
bp0: {wire: "A", type: "L"},
bp1: {wire: "B", type: "L"},
eg0: {wire: "A", type: "L"},
eg1: {wire: "B", type: "L"},
eg0_type: {wire: "T", type: "I"},
eg1_type: {wire: "X", type: "I"},
debug: {wire: "D", type: "I"},
chained_osc: {wire: "c", type: "I"},
mod_source: {wire: "L", type: "I"},
eq: {wire: "x", type: "L"},
filter_type: {wire: "G", type: "I"},
ratio: {wire: "I", type: "F"},
latency_ms: {wire: "N", type: "I"},
algo_source: {wire: "O", type: "L"},
load_sample: {wire: "z", type: "L"},
transfer_file: {wire: "zT", type: "L"},
disk_sample: {wire: "zF", type: "L"},
algorithm: {wire: "o", type: "I"},
chorus: {wire: "k", type: "L"},
reverb: {wire: "h", type: "L"},
echo: {wire: "M", type: "L"},
patch: {wire: "K", type: "I"},
voices: {wire: "r", type: "L"},
external_channel: {wire: "W", type: "I"},
portamento: {wire: "m", type: "I"},
sequence: {wire: "H", type: "L"},
tempo: {wire: "j", type: "F"},
synth: {wire: "i", type: "I"},
pedal: {wire: "ip", type: "I"},
synth_flags: {wire: "if", type: "I"},
num_voices: {wire: "iv", type: "I"},
oscs_per_voice: {wire: "in", type: "I"},
to_synth: {wire: "it", type: "I"},
grab_midi_notes: {wire: "im", type: "I"},
synth_delay: {wire: "id", type: "I"},
preset: {wire: "p", type: "I"},
num_partials: {wire: "p", type: "I"},
start_sample: {wire: "zS", type: "L"},
stop_sample: {wire: "zO", type: "I"},
midi_cc: {wire: "ic", type: "L"},
patch_string: {wire: "u", type: "S"}
};
var AMY_KW_PRIORITY = {
osc: 0,
wave: 1,
note: 2,
vel: 3,
amp: 4,
freq: 5,
duty: 6,
feedback: 7,
time: 8,
reset: 9,
phase: 10,
pan: 11,
client: 12,
volume: 13,
pitch_bend: 14,
filter_freq: 15,
resonance: 16,
bp0: 17,
bp1: 18,
eg0: 19,
eg1: 20,
eg0_type: 21,
eg1_type: 22,
debug: 23,
chained_osc: 24,
mod_source: 25,
eq: 26,
filter_type: 27,
ratio: 28,
latency_ms: 29,
algo_source: 30,
load_sample: 31,
transfer_file: 32,
disk_sample: 33,
algorithm: 34,
chorus: 35,
reverb: 36,
echo: 37,
patch: 38,
voices: 39,
external_channel: 40,
portamento: 41,
sequence: 42,
tempo: 43,
synth: 44,
pedal: 45,
synth_flags: 46,
num_voices: 47,
oscs_per_voice: 48,
to_synth: 49,
grab_midi_notes: 50,
synth_delay: 51,
preset: 52,
num_partials: 53,
start_sample: 54,
stop_sample: 55,
midi_cc: 56,
patch_string: 57
};
var AMY_COEF_FIELDS = ["const", "note", "vel", "eg0", "eg1", "mod", "bend", "ext0", "ext1"];
// --- type handlers (mirror Python's str_of_int, trunc, parse_list_or_comma_string, parse_ctrl_coefs) ---
function _str_of_int(arg) {
return String(Math.trunc(Number(arg)));
}
function _trunc(number) {
if (typeof number === "string") {
if (number.trim() === "") return "";
number = parseFloat(number);
}
if (typeof number === "number") {
var s = number.toFixed(6);
s = s.replace(/0+$/, "");
s = s.replace(/\.$/, "");
return s;
}
return String(number);
}
function _parse_list(obj) {
if (Array.isArray(obj)) {
return obj.map(function(v) { return v == null ? "" : String(v); }).join(",");
}
return String(obj);
}
function _trim_trailing(arr) {
var end = arr.length;
while (end > 0 && arr[end - 1] == null) end--;
return arr.slice(0, end);
}
function _parse_ctrl_coefs(coefs) {
if (typeof coefs === "string") {
return coefs.split(",").map(function(x) { return _trunc(x); }).join(",");
}
if (typeof coefs === "number") {
return _trunc(coefs);
}
if (!Array.isArray(coefs) && typeof coefs === "object" && coefs !== null) {
var list = new Array(AMY_COEF_FIELDS.length).fill(null);
for (var key in coefs) {
if (!coefs.hasOwnProperty(key)) continue;
var idx = AMY_COEF_FIELDS.indexOf(key);
if (idx < 0) throw new Error("Unknown ctrl_coef field: " + key + ". Valid: " + AMY_COEF_FIELDS.join(", "));
list[idx] = coefs[key];
}
coefs = list;
}
if (!Array.isArray(coefs)) {
return String(coefs);
}
coefs = _trim_trailing(coefs);
return coefs.map(function(v) { return v == null ? "" : _trunc(v); }).join(",");
}
var _ARG_HANDLERS = {
I: _str_of_int,
F: _trunc,
S: String,
L: _parse_list,
C: _parse_ctrl_coefs
};
/**
* Build an AMY wire code string from named parameters.
*
* amy_message({osc: 0, wave: 1, freq: 440}) => "v0w1f440Z"
* amy_message({synth: 1, patch: 257, num_voices: 6}) => "K257i1iv6Z"
*
* Control coefficient params (amp, freq, duty, pan, filter_freq) accept:
* - A number: freq: 440
* - An array: freq: [440, 1, null, null, null, null, 1]
* - An object: freq: {const: 440, bend: 1}
*/
function amy_message(params) {
if (!params || typeof params !== "object") {
throw new Error("amy_message requires an object of parameters");
}
var keys = [];
for (var key in params) {
if (!params.hasOwnProperty(key)) continue;
if (!(key in AMY_KW_MAP)) {
throw new Error("Unknown AMY parameter: " + key);
}
var arg = params[key];
if (arg == null) {
if (key !== "time" && key !== "sequence") {
throw new Error("Null value for AMY parameter: " + key);
}
continue;
}
keys.push(key);
}
keys.sort(function(a, b) {
return (AMY_KW_PRIORITY[a] || 0) - (AMY_KW_PRIORITY[b] || 0);
});
var m = "";
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
var mapping = AMY_KW_MAP[k];
var handler = _ARG_HANDLERS[mapping.type];
m += mapping.wire + handler(params[k]);
}
return m + "Z";
}
/**
* Build and send an AMY wire code message.
* Equivalent to Python's amy.send().
*/
function amy_send(params, log) {
var msg = amy_message(params);
if (log && typeof amy_add_log_message === "function") {
amy_add_log_message(msg);
} else if (typeof amy_add_message === "function") {
amy_add_message(msg);
} else {
console.warn("amy_send: no AMY message handler found (is amy.js loaded?)");
}
return msg;
}
// Constants from amy/constants.py (mirrors amy.SINE, amy.FILTER_LPF, etc.)
var AMY = {
MAX_FILENAME_LEN: 127,
AMY_BLOCK_SIZE: 256,
BLOCK_SIZE_BITS: 8,
AMY_SAMPLE_RATE: 44100,
PCM_AMY_SAMPLE_RATE: 22050,
AMY_TRANSFER_TYPE_NONE: 0,
AMY_TRANSFER_TYPE_AUDIO: 1,
AMY_TRANSFER_TYPE_FILE: 2,
AMY_TRANSFER_TYPE_SAMPLE: 3,
AMY_PCM_TYPE_ROM: 0,
AMY_PCM_TYPE_FILE: 1,
AMY_PCM_TYPE_MEMORY: 2,
PCM_FILE_BUFFER_MULT: 8,
AMY_BUS_OUTPUT: 1,
AMY_BUS_AUDIO_IN: 2,
AMY_MAX_CORES: 2,
AMY_MAX_CHANNELS: 2,
AMY_NCHANS: 2,
AMY_CORES: 1,
AMY_MIDI_CHANNEL_DRUMS: 10,
MALLOC_CAP_DEFAULT: 0,
CHORUS_DEFAULT_LFO_FREQ: 0.5,
CHORUS_DEFAULT_MOD_DEPTH: 0.5,
CHORUS_DEFAULT_LEVEL: 0,
CHORUS_DEFAULT_MAX_DELAY: 320,
EQ_CENTER_LOW: 800.0,
EQ_CENTER_MED: 2500.0,
EQ_CENTER_HIGH: 7000.0,
REVERB_DEFAULT_LEVEL: 0,
REVERB_DEFAULT_LIVENESS: 0.85,
REVERB_DEFAULT_DAMPING: 0.5,
REVERB_DEFAULT_XOVER_HZ: 3000.0,
ECHO_DEFAULT_LEVEL: 0,
ECHO_DEFAULT_DELAY_MS: 500.0,
ECHO_DEFAULT_MAX_DELAY_MS: 743.0,
ECHO_DEFAULT_FEEDBACK: 0,
ECHO_DEFAULT_FILTER_COEF: 0,
AMY_SEQUENCER_PPQ: 48,
DELAY_LINE_LEN: 512,
CLIP_D: 0.1,
MAX_VOLUME: 11.0,
AMP_THRESH: 0.001,
AMP_THRESH_PLUS: 0.0011,
SAMPLE_MAX: 32767,
MAX_ALGO_OPS: 6,
DEFAULT_NUM_BREAKPOINTS: 8,
MAX_BREAKPOINTS: 24,
MAX_BREAKPOINT_SETS: 2,
THREAD_USLEEP: 500,
AMY_BYTES_PER_SAMPLE: 2,
MAX_VOICES_PER_INSTRUMENT: 32,
FILT_NUM_DELAYS: 4,
ZERO_HZ_LOG_VAL: -99.0,
ZERO_LOGFREQ_IN_HZ: 440.0,
ZERO_MIDI_NOTE: 69,
MIN_FILTER_LOGFREQ: -2.75,
NUM_COMBO_COEFS: 9,
MAX_MESSAGE_LEN: 1024,
MAX_PARAM_LEN: 256,
FILTER_NONE: 0,
FILTER_LPF: 1,
FILTER_BPF: 2,
FILTER_HPF: 3,
FILTER_LPF24: 4,
SINE: 0,
PULSE: 1,
SAW_DOWN: 2,
SAW_UP: 3,
TRIANGLE: 4,
NOISE: 5,
KS: 6,
PCM: 7,
ALGO: 8,
PARTIAL: 9,
BYO_PARTIALS: 10,
INTERP_PARTIALS: 11,
AUDIO_IN0: 12,
AUDIO_IN1: 13,
AUDIO_EXT0: 14,
AUDIO_EXT1: 15,
AMY_MIDI: 16,
PCM_LEFT: 17,
PCM_RIGHT: 18,
PCM_MIX: 7,
WAVETABLE: 19,
SILENT: 20,
CUSTOM: 21,
WAVE_OFF: 22,
SYNTH_OFF: 0,
SYNTH_AUDIBLE: 1,
SYNTH_INAUDIBLE: 2,
SYNTH_IS_MOD_SOURCE: 3,
SYNTH_IS_ALGO_SOURCE: 4,
EVENT_EMPTY: 0,
EVENT_SCHEDULED: 1,
EVENT_TRANSFER_DATA: 2,
EVENT_SEQUENCE: 3,
NOTE_SOURCE_MIDI: 2,
ENVELOPE_NORMAL: 0,
ENVELOPE_LINEAR: 1,
ENVELOPE_DX7: 2,
ENVELOPE_TRUE_EXPONENTIAL: 3,
SEQUENCE_TICK: 0,
SEQUENCE_PERIOD: 1,
SEQUENCE_TAG: 2,
RESET_SEQUENCER: 4096,
RESET_ALL_OSCS: 8192,
RESET_TIMEBASE: 16384,
RESET_AMY: 32768,
RESET_EVENTS: 65536,
RESET_ALL_NOTES: 131072,
RESET_SYNTHS: 262144,
RESET_PATCH: 524288,
RESET_QUEUE: 1048576,
AMY_OK: 0,
AMY_AUDIO_IS_NONE: 0,
AMY_AUDIO_IS_I2S: 1,
AMY_AUDIO_IS_USB_GADGET: 2,
AMY_AUDIO_IS_MINIAUDIO: 4,
AMY_MIDI_IS_NONE: 0,
AMY_MIDI_IS_UART: 1,
AMY_MIDI_IS_USB_GADGET: 2,
AMY_MIDI_IS_MACOS: 4,
AMY_MIDI_IS_WEBMIDI: 8,
AMYBOARD_LRC: 2,
AMYBOARD_BCLK: 8,
AMYBOARD_DOUT: 6,
AMYBOARD_DIN: 9,
AMYBOARD_MCLK: 3,
AMYBOARD_MIDI_OUT_TYPE_A: 14,
AMYBOARD_MIDI_OUT_TYPE_B: 15,
AMYBOARD_MIDI_IN: 21
};
if (typeof globalThis !== "undefined") {
globalThis.amy_message = amy_message;
globalThis.amy_send = amy_send;
globalThis.AMY = AMY;
globalThis.AMY_KW_MAP = AMY_KW_MAP;
globalThis.AMY_COEF_FIELDS = AMY_COEF_FIELDS;
}
})();
87586a3acThis file is pinned to the selected release. Download the original to open it in your design tool.