User:Eufalesio/How to build edos in DAWs: Difference between revisions
No edit summary |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 23: | Line 23: | ||
* Disadvantages: Only possible with 12n edos. Edos above 72 or 84 may become unwieldy or RAM-intensive, due to the abundance of many instrument instances. | * Disadvantages: Only possible with 12n edos. Edos above 72 or 84 may become unwieldy or RAM-intensive, due to the abundance of many instrument instances. | ||
Good edos: [[24edo|24]], [[72edo|72]], [[84edo|84]] - Reasoning: Efficient approximations of JI / 24edo is an entry-level microtonal edo, great [[2.3.11 subgroup| | Good edos: [[24edo|24]], [[72edo|72]], [[84edo|84]] - Reasoning: Efficient approximations of JI / 24edo is an entry-level microtonal edo, great [[2.3.11 subgroup|ila]] tuning. | ||
== Edos >12 == | == Edos >12 == | ||
| Line 43: | Line 43: | ||
* Advantages: Allows use of very fine-grained edos, 10.<u>3</u> octave range, practical to compose in. | * Advantages: Allows use of very fine-grained edos, 10.<u>3</u> octave range, practical to compose in. | ||
* Disadvantages: Harder to set up, less transposing-friendly because of wolf intervals. | * Disadvantages: Harder to set up, less transposing-friendly because of wolf intervals. Not usable live. | ||
Good edos: [[41edo|41]], [[53edo|53]], [[94edo|94]], [[130edo|130]], [[159edo|159]] - Reasoning: Astounding fifths and/or Great 13-limit approximations. | Good edos: [[41edo|41]], [[53edo|53]], [[94edo|94]], [[130edo|130]], [[159edo|159]] - Reasoning: Astounding fifths and/or Great 13-limit approximations. | ||
94edo is my favorite here, because it combines two top-tier edos into one great jack-of-all trades 23-odd-limit tuning. 159edo, [[Dawson Berry|Aura]]'s favorite, is also a top-tier edo, making an ''astonishingly good'' | 94edo is my favorite here, because it combines two top-tier edos into one great jack-of-all trades 23-odd-limit tuning. 159edo, [[Dawson Berry|Aura]]'s favorite, is also a top-tier edo, making an ''astonishingly good'' ila tuning, and/or an overall a very good jack-of-all trades tuning, both of them with a graspable gamut. | ||
=== Preset-scale deviations - MIDI and articulations === | === Preset-scale deviations - MIDI and articulations === | ||
| Line 55: | Line 55: | ||
* Advantages: Near total freedom of pitch and tuning options, allows use of extremely fine edos, 10.<u>3</u> octave range, practical to compose in. | * Advantages: Near total freedom of pitch and tuning options, allows use of extremely fine edos, 10.<u>3</u> octave range, practical to compose in. | ||
* Disadvantages: | * Disadvantages: Non-transposing friendly. Requires MPE or else instrument must be monophonic. Hard to setup, very technical, prone to error, number of articulations x deviations must not exceed 255. | ||
Good edos: [[217edo|217]], [[270edo|270]], [[311edo|311 | Good edos: [[217edo|217]], [[270edo|270]], [[311edo|311]] - Reasoning: High-prime-limit support / Unbeatably accurate yazalathana. | ||
Excessive edos: Anything beyond 311. Highly recommend you use superfine 12n edos for these ones. I don't go here. | |||
==== About edo usage and JI approximations (my experience) ==== | ==== About edo usage and JI approximations (my experience) ==== | ||
[[Septischismic]] is my temperament of temperaments, which supports {{Edos|12e, 41, 53, 94, 217, 270, 311}}, and of those my best choices are undoubtedly 94edo and 270edo. They have respectively, very good and extremely good 13-limit, and are even, so I can split the [[Pythagorean comma|poma]] in halves for easier navigation if I want to. | |||
I aim for 13-limit JI, and if you also aim for that, then these tunings are the best for you. Check the [[User:Eufalesio/Ultimate|Ultimate]] article for more info. Note, I don't care about essential tempering, VAOs, MOSes beyond the theoretical, or structural exploiting. I just don't want pain. | |||
If you still want to go even finer than that... then try 612edo and 2460; S-tier 12n edos, so you get transposing-friendly hyperfine microtonality. But, since their step sizes are smaller than the melodic JND, you can't tell notes edosteps apart. You are likely wasting your time here, however. | |||
If you STILL want to go finer... you are surely wasting your time. Just use [[JI]] scales and forget about edos and temperaments altogether. Remember when I said you could ''theoretically'' compose in these insane edos? That's because PB resolution is going to be your main bottleneck. The other one is your paranoia. | |||
===== Vibe-coded Javascript script (V8) ===== | |||
I highly suggest you read the code. Claude does a wayyy better job at explaining things than I do.<syntaxhighlight lang="javascript" line="1">// =========================================================================== | |||
// EDO RETUNER V8 — generalized EDO retuner with polyphonic micro-deviation | |||
// =========================================================================== | |||
// | |||
// WHAT IT DOES | |||
// ------------ | |||
// Maps the 12 keyboard degrees to their nearest approximations in any EDO | |||
// (circle-of-fifths "scale bend"), then adds two independent deviations: | |||
// | |||
// 1. MIDI-channel deviation : input channel N -> (N - zeroCh) increments | |||
// 2. Articulation deviation : Articulation CC# -> (value - 64) increments | |||
// | |||
// Each increment is worth either: | |||
// - a number of EDO steps ........ "MIDIchDev" / "ArtiDev" boxes, or | |||
// - an exact cent value .......... "...cents" boxes (float, 4 decimals). | |||
// If a cents box is 0 the EDO-step box is used; if non-zero, the cents | |||
// value wins (independent per deviation type). | |||
// | |||
// FIFTH SIZE: the 12-degree scale bend is generated by stacking fifths. | |||
// By default the fifth is the EDO's best approximation of 3/2. Override it | |||
// with either box (chain: cents box wins, then steps box, then auto): | |||
// - "Fifth (EDOsteps, 0=auto)" .... fifth as a number of EDO steps | |||
// - "Fifth cents (0=steps)" ....... fifth as an exact cent value, e.g. | |||
// 696.5784 for 1/4-comma meantone (this frees the 12 base degrees from | |||
// the EDO grid entirely; step-based deviations still move in EDO steps). | |||
// | |||
// Every distinct tuning gets its own output channel from the pool; the | |||
// pitch-bend is always sent BEFORE the note. | |||
// | |||
// IMPORTANT: "PB range (± cents)" must match the synth's pitch-bend range | |||
// (200 = ±2 semitones standard, 4800 = ±48 for most MPE synths). A mismatch | |||
// is the #1 cause of "this plugin detunes wrong". | |||
// | |||
// | |||
// NOTE ON THE CENTS BOXES: the parameter value has 0.0001-cent resolution | |||
// (double-click the value and type it in). Logic's on-screen display may | |||
// round to fewer decimals, but the exact value is used internally and traced | |||
// to the console (with 4 decimals) whenever you change it. | |||
// | |||
// =========================================================================== | |||
var NeedsTimingInfo = true; | |||
// --------------------------------------------------------------------------- | |||
// State | |||
// --------------------------------------------------------------------------- | |||
// Output pool | |||
var memberStart = 1, memberEnd = 16; | |||
If | // If your controller sends the articulation CC on member channels themselves, | ||
// set this to false (V7 behaviour kept). | |||
var mpeMasterCCFeedsMembers = true; | |||
== | // Tuning parameters | ||
var EDO = 311; | |||
// | var STEP_CENTS = 1200.0 / 311; | ||
var fifthStepsOvr = 0; // fifth override in EDO steps (0 = auto best fifth) | |||
var fifthCentsOvr = 0; // fifth override in cents (0 = use steps box / auto) | |||
var rootKeyPC = 0; | |||
// | var refMidiNote = 69; | ||
var refHz = 440.0; | |||
/ | var ch1Mode = 0; // 0 Normal, 1 ScaleBendOnly, 2 Bypass, 3 Nullify | ||
var zeroCh = 8; // channel at which channel-deviation = 0 | |||
// | var pbRangeCents = 200; // synth pitch-bend range in ± cents | ||
// | // Deviation settings | ||
var | var midiChDevSteps = 2; // EDO steps per input-channel increment | ||
var | var midiChDevCents = 0; // cents per input-channel increment (0 = use steps) | ||
var | var artiDevSteps = 1; // EDO steps per articulation-CC unit (value-64) | ||
var | var artiDevCents = 0; // cents per articulation-CC unit (0 = use steps) | ||
var | // Behaviour | ||
var | var artiCC = 27; // articulation CC# (avoid 64 and the panic CC) | ||
var offsetScopeGlobal = | var releaseHoldMs = 300; | ||
var swallowCC = true; | var panicCCNumber = 83; | ||
var panicThreshold = 63; | |||
var offsetScopeGlobal = false; // false = Per-Channel, true = Global-Last | |||
var swallowCC = true; // swallow the articulation CC | |||
var pbInPass = false; // pass incoming pitch-bend through (default: swallow) | |||
var otherCCToAll = false; // forward other CCs to all pool channels | |||
var noteDelayMs = 2; | |||
var debug = false; | var debug = false; | ||
// | // Scale-bend | ||
var | var scaleBendEnabled = true; | ||
var gSteps = 0; | |||
var scaleBend = Array(12).fill(0.0); | |||
var masterOffsetCents = 0.0; | |||
var FIFTH_OFFSETS = [0, -5, 2, -3, 4, -1, 6, 1, -4, 3, -2, 5]; | |||
// | // Articulation-CC capture (units = ccValue - 64) | ||
var globalMicro = 0; | var globalMicro = 0; | ||
var | var masterMicro = 0; // last CC received on ch 1 | ||
var microPerInCh = Array(17).fill(0); | |||
var microTouched = Array(17).fill(false); | |||
var sustainDown = false; | |||
// Monotonic clock (ms). Advanced every process block; never freezes. | |||
var nowMs = 0; | |||
// | // Per-output-channel state | ||
var | var chAssignedPk = Array(17).fill(""); // tuning key owning the channel | ||
var | var chActive = Array(17).fill(0); // held + sustained note count | ||
var | var chReleaseUntil = Array(17).fill(0); // tail-guard deadline (ms) | ||
var | var chLastPB = Array(17).fill(999999); | ||
var chTune = Array(17).fill(null); // {pitch, steps, extraCents} | |||
var pkToCh = {}; // tuning key -> channel | |||
var rrNext = 1; | |||
// Active notes: "inCh:pitch" -> stack of {outCh, inCh, pitch, sustained} | |||
var noteStacks = {}; | |||
// --------------------------------------------------------------------------- | |||
// UI | |||
// --------------------------------------------------------------------------- | |||
var PluginParameters = [ | var PluginParameters = [ | ||
// EDO | /* 0*/ { name:"EDO", type:"lin", minValue:1, maxValue:65535, numberOfSteps:65534, defaultValue:311 }, | ||
{ name:" | /* 1*/ { name:"Fifth (EDOsteps, 0=auto)", type:"lin", minValue:0, maxValue:65535, numberOfSteps:65535, defaultValue:0 }, | ||
/* 2*/ { name:"Fifth cents (0=steps)", type:"lin", minValue:0, maxValue:1200, numberOfSteps:12000000, defaultValue:0 }, | |||
/* 3*/ { name:"Root key (PC)", type:"menu", valueStrings:["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"], defaultValue:0 }, | |||
/* 4*/ { name:"Reference MIDI note", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:69 }, | |||
/* 5*/ { name:"Reference Hz", type:"float", minValue:1, maxValue:20000, numberOfSteps:19999, defaultValue:440 }, | |||
/* 6*/ { name:"Ch 1 treatment", type:"menu", valueStrings:["Normal","ScaleBendOnly","Bypass (12edo)","Nullify"], defaultValue:0 }, | |||
/* 7*/ { name:"Channel at which step=0 (n)", type:"lin", minValue:1, maxValue:16, numberOfSteps:15, defaultValue:8 }, | |||
/* 8*/ { name:"PB range (± cents)", type:"float", minValue:1, maxValue:4800, numberOfSteps:4799, defaultValue:200 }, | |||
/* 9*/ { name:"Articulation CC#", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:27 }, | |||
/*10*/ { name:"MIDIchDev (EDOsteps per ch)", type:"lin", minValue:0, maxValue:63, numberOfSteps:63, defaultValue:2 }, | |||
/*11*/ { name:"MIDIchDev cents (0=steps)", type:"lin", minValue:-100, maxValue:100, numberOfSteps:2000000, defaultValue:0 }, | |||
/*12*/ { name:"ArtiDev (EDOsteps per CCstep)", type:"lin", minValue:0, maxValue:63, numberOfSteps:63, defaultValue:1 }, | |||
/*13*/ { name:"ArtiDev cents (0=steps)", type:"lin", minValue:-100, maxValue:100, numberOfSteps:2000000, defaultValue:0 }, | |||
/*14*/ { name:"Release Hold (ms)", type:"lin", minValue:0, maxValue:20000, numberOfSteps:20000, defaultValue:300 }, | |||
/*15*/ { name:"Panic CC#", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:83 }, | |||
/*16*/ { name:"Panic thresh (>)", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:63 }, | |||
/*17*/ { name:"PANIC (kill all)", type:"menu", valueStrings:["Off","TRIGGER"], defaultValue:0 }, | |||
/*18*/ { name:"Offset scope", type:"menu", valueStrings:["Per-Channel","Global-Last"], defaultValue:0 }, | |||
/*19*/ { name:"Swallow Arti CC", type:"menu", valueStrings:["No","Yes"], defaultValue:1 }, | |||
/*20*/ { name:"Incoming PitchBend", type:"menu", valueStrings:["Swallow","Pass"], defaultValue:0 }, | |||
/*21*/ { name:"Other CCs", type:"menu", valueStrings:["Pass unchanged","To all out ch"], defaultValue:0 }, | |||
/*22*/ { name:"NoteOn Delay (ms)", type:"lin", minValue:0, maxValue:10, numberOfSteps:10, defaultValue:2 }, | |||
/*23*/ { name:"Debug Trace", type:"menu", valueStrings:["Off","On"], defaultValue:0 }, | |||
/*24*/ { name:"Output ch start", type:"lin", minValue:1, maxValue:16, numberOfSteps:15, defaultValue:1 }, | |||
/*25*/ { name:"Output ch end", type:"lin", minValue:1, maxValue:16, numberOfSteps:15, defaultValue:16 }, | |||
/*26*/ { name:"Scale-bend or 12EDO", type:"menu", valueStrings:["On","Off"], defaultValue:0 } | |||
]; | |||
// Snap to exactly 4 decimals; kill float fuzz around zero. | |||
function snap4(v){ | |||
v = Math.round(v * 1e4) / 1e4; | |||
return (v > -5e-5 && v < 5e-5) ? 0 : v; | |||
} | |||
function ParameterChanged(p, v){ | |||
switch (p){ | |||
case 0: EDO = Math.max(1, Math.min(65535, Math.floor(v))); | |||
STEP_CENTS = 1200.0 / EDO; rebuildAndRetune(); break; | |||
case 1: fifthStepsOvr = Math.max(0, Math.min(65535, Math.floor(v))); | |||
rebuildAndRetune(); break; | |||
case 2: fifthCentsOvr = snap4(v); | |||
Trace("Fifth cents = " + fifthCentsOvr.toFixed(4) + | |||
(fifthCentsOvr === 0 ? " (using steps/auto)" : "")); | |||
rebuildAndRetune(); break; | |||
case 3: rootKeyPC = (v|0) % 12; rebuildAndRetune(); break; | |||
case 4: refMidiNote = Math.max(0, Math.min(127, v|0)); rebuildAndRetune(); break; | |||
case 5: refHz = Math.max(1.0, v); rebuildAndRetune(); break; | |||
case 6: ch1Mode = (v|0) & 3; break; | |||
case 7: zeroCh = Math.max(1, Math.min(16, v|0)); break; | |||
case 8: pbRangeCents = Math.max(1, v); rebuildAndRetune(); break; | |||
case 9: artiCC = Math.floor(v); break; | |||
case 10: midiChDevSteps = Math.max(0, Math.min(63, Math.floor(v))); break; | |||
case 11: midiChDevCents = snap4(v); | |||
Trace("MIDIchDev cents = " + midiChDevCents.toFixed(4) + | |||
(midiChDevCents === 0 ? " (using EDO steps)" : "")); break; | |||
case 12: artiDevSteps = Math.max(0, Math.min(63, Math.floor(v))); break; | |||
case 13: artiDevCents = snap4(v); | |||
Trace("ArtiDev cents = " + artiDevCents.toFixed(4) + | |||
(artiDevCents === 0 ? " (using EDO steps)" : "")); break; | |||
case 14: releaseHoldMs = Math.max(0, Math.min(20000, Math.floor(v))); break; | |||
case 15: panicCCNumber = Math.max(0, Math.min(127, v|0)); break; | |||
case 16: panicThreshold = Math.max(0, Math.min(127, v|0)); break; | |||
case 17: if ((v|0) === 1){ | |||
panicAll(); | |||
if (typeof SetParameter === "function") SetParameter(17, 0); | |||
} break; | |||
case 18: offsetScopeGlobal = (v|0) === 1; break; | |||
case 19: swallowCC = (v|0) === 1; break; | |||
case 20: pbInPass = (v|0) === 1; break; | |||
case 21: otherCCToAll = (v|0) === 1; break; | |||
case 22: noteDelayMs = Math.max(0, Math.min(10, v|0)); break; | |||
case 23: debug = (v|0) === 1; break; | |||
case 24: setOutputPool(v|0, memberEnd); allocatorReset(); rebuildAndRetune(); break; | |||
case 25: setOutputPool(memberStart, v|0); allocatorReset(); rebuildAndRetune(); break; | |||
case 26: scaleBendEnabled = ((v|0) === 0); rebuildAndRetune(); break; | |||
} | |||
} | |||
// --------------------------------------------------------------------------- | |||
// Helpers | |||
// --------------------------------------------------------------------------- | |||
function T(s){ | |||
if (!debug) return; | |||
s = String(s); | |||
if (s.length > 120) s = s.slice(0, 120); | |||
Trace(s); | |||
} | |||
function safeCh(ch){ ch = (ch|0) || 1; return ch < 1 ? 1 : (ch > 16 ? 16 : ch); } | |||
function mod(a, m){ var r = a % m; return r < 0 ? r + m : r; } | |||
function log2(x){ return Math.log(x) / Math.log(2.0); } | |||
function degreeForPitch(pitch){ return mod((pitch|0) - rootKeyPC, 12); } | |||
function setOutputPool(a, b){ | |||
a = safeCh(a); b = safeCh(b); | |||
if (a > b){ var t = a; a = b; b = t; } | |||
memberStart = a; memberEnd = b; | |||
if (rrNext < memberStart || rrNext > memberEnd) rrNext = memberStart; | |||
T("Pool " + memberStart + ".." + memberEnd); | |||
} | |||
function nextCh(ch){ | |||
ch++; return (ch > memberEnd || ch < memberStart) ? memberStart : ch; | |||
} | |||
function centsToPB(c){ | |||
var v = (c / pbRangeCents) * 8191.0; | |||
if (v > 8191) v = 8191; else if (v < -8192) v = -8192; | |||
return Math.round(v); | |||
} | |||
function sendPB(ch, value){ | |||
var pb = new PitchBend(); | |||
pb.channel = safeCh(ch); pb.value = value; | |||
pb.send(); | |||
chLastPB[ch] = value; | |||
} | |||
function sendCC(ch, num, val){ | |||
var cc = new ControlChange(); | |||
cc.channel = safeCh(ch); cc.number = num|0; cc.value = val|0; | |||
cc.send(); | |||
} | |||
// All forwarded notes share the same delay so on/off ordering is preserved. | |||
function sendNote(ev){ | |||
if (noteDelayMs > 0) ev.sendAfterMilliseconds(noteDelayMs); else ev.send(); | |||
} | |||
function sendNoteOff(ch, pitch, vel){ | |||
var off = new NoteOff(); | |||
off.channel = safeCh(ch); off.pitch = pitch & 0x7F; off.velocity = (vel|0) || 64; | |||
sendNote(off); | |||
} | |||
// --------------------------------------------------------------------------- | |||
// Scale bend | |||
// --------------------------------------------------------------------------- | |||
// | function rebuildScale(){ | ||
STEP_CENTS = 1200.0 / EDO; | |||
gSteps = Math.round(EDO * (log2(3.0) - 1.0)); // best fifth in this EDO | |||
// Fifth resolution chain: cents box wins, then steps box, then auto. | |||
var fifthCents; | |||
if (fifthCentsOvr !== 0) fifthCents = fifthCentsOvr; | |||
else if (fifthStepsOvr > 0) fifthCents = fifthStepsOvr * STEP_CENTS; | |||
else fifthCents = gSteps * STEP_CENTS; | |||
var rawBend = Array(12); | |||
for (var i = 0; i < 12; i++){ | |||
rawBend[i] = mod(FIFTH_OFFSETS[i] * fifthCents, 1200.0) - i * 100.0; | |||
} | |||
var stdHz = 440.0 * Math.pow(2.0, (refMidiNote - 69) / 12.0); | |||
masterOffsetCents = 1200.0 * log2(refHz / stdHz); | |||
var anchor = rawBend[mod((refMidiNote|0) - rootKeyPC, 12)]; | |||
for (var k = 0; k < 12; k++) scaleBend[k] = rawBend[k] - anchor; | |||
T("Scale EDO=" + EDO + " fifth=" + fifthCents.toFixed(4) + "c"); | |||
} | |||
function tuningCents(pitch, steps, extraCents){ | |||
var sb = scaleBendEnabled ? scaleBend[degreeForPitch(pitch)] : 0.0; | |||
return masterOffsetCents + sb + steps * STEP_CENTS + extraCents; | |||
} | |||
function | // Retune channels that still own a tuning (held notes AND release tails). | ||
function rebuildAndRetune(){ | |||
rebuildScale(); | |||
for (var ch = memberStart; ch <= memberEnd; ch++){ | |||
var | var tn = chTune[ch]; | ||
if ( | if (chAssignedPk[ch] && tn){ | ||
var pb = centsToPB(tuningCents(tn.pitch, tn.steps, tn.extraCents)); | |||
if (chLastPB[ch] !== pb) sendPB(ch, pb); | |||
} | |||
} | } | ||
} | |||
// --------------------------------------------------------------------------- | |||
// Allocator — always succeeds, never sends CC120 | |||
// --------------------------------------------------------------------------- | |||
function claim(ch, pk){ | |||
if ( | var old = chAssignedPk[ch]; | ||
if (old && old !== pk && pkToCh[old] === ch) delete pkToCh[old]; | |||
chAssignedPk[ch] = pk; | |||
pkToCh[pk] = ch; | |||
} | |||
// Kick every note off a channel with targeted NoteOffs (last-resort steal). | |||
function stealChannel(ch){ | |||
var pedal = sustainDown; | |||
if (pedal) sendCC(ch, 64, 0); // lift sustain so the NoteOffs bite | |||
for (var sk in noteStacks){ | |||
var stack = noteStacks[sk]; | |||
for (var i = stack.length - 1; i >= 0; i--){ | |||
if (stack[i].outCh === ch){ | |||
sendNoteOff(ch, stack[i].pitch, 64); | |||
stack.splice(i, 1); | |||
} | |||
} | |||
if (stack.length === 0) delete noteStacks[sk]; | |||
} | } | ||
if (pedal) sendCC(ch, 64, 127); | |||
chActive[ch] = 0; | |||
chReleaseUntil[ch] = nowMs; | |||
T("STEAL ch" + ch); | |||
} | } | ||
function allocChannel(pk){ | |||
function | var hit = pkToCh[pk]; | ||
if (hit) return hit; // same tuning -> same channel | |||
var span = memberEnd - memberStart + 1, ch, i; | |||
// 1. idle channel past its release tail | |||
// | ch = rrNext; | ||
for (i = 0; i < span; i++){ | |||
if (chActive[ch] === 0 && nowMs >= chReleaseUntil[ch]){ | |||
claim(ch, pk); rrNext = nextCh(ch); return ch; | |||
} | |||
ch = nextCh(ch); | |||
} | |||
// 2. idle channel still in its tail — take the oldest (tail gets bent, | |||
// which beats refusing to play or killing sound) | |||
var best = 0, bestT = Infinity; | |||
for (ch = memberStart; ch <= memberEnd; ch++){ | |||
if (chActive[ch] === 0 && chReleaseUntil[ch] < bestT){ | |||
bestT = chReleaseUntil[ch]; best = ch; | |||
} | |||
} | |||
if (best){ claim(best, pk); rrNext = nextCh(best); return best; } | |||
// 3. every channel is sounding: steal round-robin with clean NoteOffs | |||
ch = rrNext; | |||
stealChannel(ch); | |||
claim(ch, pk); | |||
rrNext = nextCh(ch); | |||
return ch; | |||
} | } | ||
// | // --------------------------------------------------------------------------- | ||
// Reset / panic | |||
// --------------------------------------------------------------------------- | |||
function clearTracking(){ | |||
pkToCh = {}; noteStacks = {}; rrNext = memberStart; | |||
for (var ch = 1; ch <= 16; ch++){ | |||
var | chAssignedPk[ch] = ""; chActive[ch] = 0; | ||
chReleaseUntil[ch] = nowMs; chLastPB[ch] = 0; chTune[ch] = null; | |||
} | |||
} | |||
function allocatorReset(){ | |||
for (var ch = 1; ch <= 16; ch++){ sendCC(ch, 123, 0); sendPB(ch, 0); } | |||
clearTracking(); | |||
T("ALLOC RESET"); | |||
} | |||
function panicAll(){ | |||
for (var ch = 1; ch <= 16; ch++){ | |||
sendCC(ch, 120, 0); sendCC(ch, 123, 0); sendPB(ch, 0); | |||
} | |||
clearTracking(); | |||
globalMicro = 0; masterMicro = 0; sustainDown = false; | |||
for (var i = 1; i <= 16; i++){ microPerInCh[i] = 0; microTouched[i] = false; } | |||
T("PANIC ALL"); | |||
} | } | ||
function noteEnded(ch){ | |||
chActive[ch] = Math.max(0, chActive[ch] - 1); | |||
if (chActive[ch] === 0) chReleaseUntil[ch] = nowMs + releaseHoldMs; | |||
} | |||
function | function flushSustained(){ | ||
var | for (var sk in noteStacks){ | ||
var stack = noteStacks[sk]; | |||
for (var i = stack.length - 1; i >= 0; i--){ | |||
if (stack[i].sustained){ | |||
noteEnded(stack[i].outCh); | |||
stack.splice(i, 1); | |||
} | |||
} | |||
if (stack.length === 0) delete noteStacks[sk]; | |||
} | |||
T("SustainUp: flushed"); | |||
} | } | ||
function | // --------------------------------------------------------------------------- | ||
var | // Clock + idle housekeeping (runs every process block, even when stopped) | ||
// --------------------------------------------------------------------------- | |||
function ProcessMIDI(){ | |||
var t = (typeof GetTimingInfo === "function") ? GetTimingInfo() : null; | |||
var adv = 0; | |||
if (t && t.tempo > 0 && t.blockEndBeat > t.blockStartBeat) | |||
adv = (t.blockEndBeat - t.blockStartBeat) * 60000.0 / t.tempo; | |||
if (!(adv > 0) || adv > 1000) adv = 5.8; // stopped/cycle-jump fallback (~256 frames @ 44.1k) | |||
nowMs += adv; | |||
// Re-center idle channels whose tail has died, and release their tuning. | |||
for (var ch = memberStart; ch <= memberEnd; ch++){ | |||
if (chActive[ch] === 0 && nowMs >= chReleaseUntil[ch]){ | |||
if (chAssignedPk[ch]){ | |||
if (pkToCh[chAssignedPk[ch]] === ch) delete pkToCh[chAssignedPk[ch]]; | |||
chAssignedPk[ch] = ""; chTune[ch] = null; | |||
} | |||
if (chLastPB[ch] !== 0) sendPB(ch, 0); | |||
} | |||
} | |||
} | } | ||
// --------------------------------------------------------------------------- | |||
// Note handling | |||
// --------------------------------------------------------------------------- | |||
function | function handleNoteOn(e){ | ||
var inCh = safeCh(e.channel); | |||
if ( | if (inCh === 1){ | ||
if (ch1Mode === 3) return; // Nullify | |||
if (ch1Mode === 2){ e.send(); return; } // Bypass (12edo) | |||
} | } | ||
var | var pitch = e.pitch | 0; | ||
if ( | // Micro units captured at the exact moment the note arrives | ||
var micro; | |||
if (offsetScopeGlobal){ | |||
micro = globalMicro; | |||
} else { | |||
micro = microPerInCh[inCh] || 0; | |||
if (inCh !== 1 && mpeMasterCCFeedsMembers && !microTouched[inCh]) | |||
micro = masterMicro; // MPE master-channel fallback | |||
} | |||
var steps = 0, extraCents = 0; | |||
if (!(inCh === 1 && ch1Mode === 1)){ // ScaleBendOnly zeroes offsets | |||
if (midiChDevCents !== 0) extraCents += (inCh - zeroCh) * midiChDevCents; | |||
else steps += (inCh - zeroCh) * midiChDevSteps; | |||
if (artiDevCents !== 0) extraCents += micro * artiDevCents; | |||
else steps += micro * artiDevSteps; | |||
} | } | ||
var pk = inCh + ":" + pitch + ":" + steps + ":" + extraCents.toFixed(4); | |||
var tgt = allocChannel(pk); | |||
var cents = tuningCents(pitch, steps, extraCents); | |||
var pb = centsToPB(cents); | |||
chTune[tgt] = { pitch: pitch, steps: steps, extraCents: extraCents }; | |||
T("NOTE in=" + inCh + " out=" + tgt + " p=" + pitch + " micro=" + micro + | |||
" cents=" + cents.toFixed(3) + " pb=" + pb); | |||
sendPB(tgt, pb); // always — never trust caches | |||
var on = new NoteOn(e); | |||
on.channel = tgt; | |||
sendNote(on); | |||
chActive[tgt]++; | |||
var sk = inCh + ":" + pitch; | |||
if (!noteStacks[sk]) noteStacks[sk] = []; | |||
noteStacks[sk].push({ outCh: tgt, inCh: inCh, pitch: pitch, sustained: false }); | |||
} | } | ||
function handleNoteOff(e){ | |||
function | var inCh = safeCh(e.channel), pitch = e.pitch | 0; | ||
var sk = inCh + ":" + pitch; | |||
var stack = noteStacks[sk]; | |||
if ( | if (stack && stack.length){ | ||
// most recent entry that hasn't been released yet | |||
var idx = -1; | |||
for (var i = stack.length - 1; i >= 0; i--){ | |||
if (!stack[i].sustained){ idx = i; break; } | |||
if ( | } | ||
if ( | if (idx < 0){ // duplicate release while pedal down | ||
sendNoteOff(stack[stack.length - 1].outCh, pitch, e.velocity); | |||
return; | |||
} | |||
var ent = stack[idx]; | |||
sendNoteOff(ent.outCh, pitch, e.velocity); | |||
if (sustainDown){ | |||
ent.sustained = true; // synth holds it via its own CC64 | |||
return; | |||
} | |||
stack.splice(idx, 1); | |||
if (stack.length === 0) delete noteStacks[sk]; | |||
noteEnded(ent.outCh); | |||
return; | return; | ||
} | } | ||
if ( | if (inCh === 1){ | ||
if (ch1Mode === 3) return; | |||
if (ch1Mode === 2){ e.send(); return; } | |||
var | } | ||
e.send(); | |||
} | |||
// --------------------------------------------------------------------------- | |||
// Main event entry | |||
// --------------------------------------------------------------------------- | |||
function HandleMIDI(e){ | |||
if (e instanceof ControlChange){ | |||
var num = e.number | 0, val = e.value | 0; | |||
// Panic CC has priority over everything (incl. an artiCC set to the same #) | |||
if (num === panicCCNumber){ | |||
if (val > panicThreshold){ allocatorReset(); return; } | |||
e.send(); return; | |||
} | |||
var | if (num === 64){ // sustain -> every pool channel | ||
var was = sustainDown; | |||
sustainDown = (val >= 64); | |||
for (var ch = memberStart; ch <= memberEnd; ch++) sendCC(ch, 64, val); | |||
if (was && !sustainDown) flushSustained(); | |||
return; | |||
} | |||
if ( | if (num === artiCC){ // capture only, no live retune | ||
var inCh = safeCh(e.channel); | |||
var micro = val - 64; // -64 .. +63 units | |||
microPerInCh[inCh] = micro; | |||
microTouched[inCh] = true; | |||
if (inCh === 1) masterMicro = micro; | |||
if (offsetScopeGlobal) globalMicro = micro; | |||
T("CC" + artiCC + " ch" + inCh + " m=" + micro); | |||
if (!swallowCC) e.send(); | |||
return; | |||
} | } | ||
if (otherCCToAll){ | |||
for (var c2 = memberStart; c2 <= memberEnd; c2++){ | |||
var cp = new ControlChange(e); cp.channel = c2; cp.send(); | |||
} | |||
return; | |||
} | |||
e.send(); return; | |||
} | |||
if (e instanceof NoteOn){ | |||
if ((e.velocity | 0) === 0){ handleNoteOff(new NoteOff(e)); return; } | |||
handleNoteOn(e); return; | |||
} | |||
if (e instanceof NoteOff){ handleNoteOff(e); return; } | |||
// Incoming pitch-bend would fight the per-channel tuning: swallow by default. | |||
if (e instanceof PitchBend){ | |||
if (pbInPass) e.send(); | |||
return; | return; | ||
} | } | ||
if (e instanceof | // Route pressure to the channel(s) actually playing that input's notes. | ||
var | if (e instanceof ChannelPressure){ | ||
var src = safeCh(e.channel), sent = {}; | |||
for (var | for (var sk in noteStacks){ | ||
var | var st = noteStacks[sk]; | ||
if ( | for (var j = 0; j < st.length; j++){ | ||
if (st[j].inCh === src && !sent[st[j].outCh]){ | |||
sent[st[j].outCh] = 1; | |||
var cpr = new ChannelPressure(e); cpr.channel = st[j].outCh; cpr.send(); | |||
} | |||
} | |||
} | } | ||
return; | |||
var | } | ||
if ( | if (e instanceof PolyPressure){ | ||
var ps = noteStacks[safeCh(e.channel) + ":" + (e.pitch | 0)]; | |||
if (ps && ps.length){ | |||
var pp = new PolyPressure(e); pp.channel = ps[ps.length - 1].outCh; pp.send(); | |||
} | } | ||
return; | return; | ||
| Line 275: | Line 657: | ||
} | } | ||
// Called by Logic on bypass toggle / transport changes. | |||
function Reset(){ | function Reset(){ | ||
panicAll(); | |||
rebuildAndRetune(); | |||
} | |||
} | |||
// init | |||
rebuildScale(); | |||
allocatorReset(); | |||
</syntaxhighlight> | |||
==== Parameters: ==== | |||
* EDO: Obviously, the edo you'll be working with. | * EDO: Obviously, the edo you'll be working with. | ||
* Fifth (EDOsteps, 0=auto): If you want to use non-patent val fifths, or your custom fifths. 0 is for patent val fifth. | |||
* Fifth cents (0=steps): Any value that is not 0 will force this number of cents to be your fifth. | |||
* Root key: modes of 5L 7s 6|5 (built from the best fifth), transposing from C | |||
* Reference MIDI note, reference Hz: Reference pitch at NOTE = FREQUENCY. Default 69 = 440, but you can make it anything. | |||
* Channel 1 treatment: | |||
** Normal: CH1 acts normally as one midiCH deviation step. | |||
** ScaleBendOnly: CH1 Matches the 5L 7s of the tuning, but ignores midiCH and microdeviations. | |||
** Bypass (12edo): CH1 notes ignore the script completely. | |||
** Nullify: CH1 notes are killed. | |||
* Channel at which step=0 (n): from 3 to 9. The midpoint of your edostep deviations. Channel 1 is not used here. If you choose 5, then your edosteps will be 2:-3, 3:-2, 4:-1, 5:0, 6:+1, 7:+2, 8:+3, so the amount of deviations you have at your disposal is 2n+1. Note that no matter the input channel (the one in your piano roll), it will be sent as Channel 1, or allocated to another channel for MPE. | * Channel at which step=0 (n): from 3 to 9. The midpoint of your edostep deviations. Channel 1 is not used here. If you choose 5, then your edosteps will be 2:-3, 3:-2, 4:-1, 5:0, 6:+1, 7:+2, 8:+3, so the amount of deviations you have at your disposal is 2n+1. Note that no matter the input channel (the one in your piano roll), it will be sent as Channel 1, or allocated to another channel for MPE. | ||
* PB range (± cents): The range of your plugin's PB. Recommend values like 200 or 1200. For MPE, it is often 4800, but if you're using very fine grained edos, you might want to bring this down to get more resolution. | * PB range (± cents): The range of your plugin's PB. Recommend values like 200 or 1200. For MPE, it is often 4800, but if you're using very fine grained edos, you might want to bring this down to get more resolution. | ||
* Articulation CC#: The CC at which articulations will be sent, you can change it if it causes conflicts with your plugin, but then you need to change all the articulation set's CC. Default 27, Not recommended to change it. | * Articulation CC#: The CC at which articulations will be sent, you can change it if it causes conflicts with your plugin, but then you need to change all the articulation set's CC. Default 27, Not recommended to change it. | ||
* | * MidiChDev: The number of edosteps added for each going up one MidiCh. | ||
* Offset scope: I don't know what this | * MidiChDev cents (0=steps): Any value that is not 0 will force this number of cents to be your MidiChDev alteration. | ||
* Swallow CC | * ArtiDev (EDOsteps per CCstep): Number of edosteps that each artidev adds (see below) | ||
* | * ArtiDev cents (0=steps): Any value that is not 0 will force this number of cents to be your ArtiDev alteration. | ||
* Release Hold (ms): The duration that the MPE allocator holds each output channel's pitch after NoteOff messages. Recommended it be long for sounds with a long tail. | |||
* Panic CC#: Default 83. Exceeding {Panic Threshold} in this will kill all MIDI events, you can use this if the script behaves erratically. | |||
* Panic thresh (>): CC# above higher than 63 will kill all notes once. Button-style, holding at 127 doesn't kill continuously. | |||
* PANIC (kill all): Kill all notes yourself, now. | |||
* Offset scope: I don't know exactly what this does. | |||
* Swallow Arti CC: Ignore CC27 (Y/N) | |||
* Incoming pitch bend: Ignore PB (Y/N) | |||
* NoteOn Delay (ms): Set higher than 0 if the notes aren't being detuned correctly. Obviously, don't set it too high. Default 2. | * NoteOn Delay (ms): Set higher than 0 if the notes aren't being detuned correctly. Obviously, don't set it too high. Default 2. | ||
* Debug Trace: If something is not working, check this box to see debugging output in the Scripter. | * Debug Trace: If something is not working, check this box to see debugging output in the Scripter. | ||
* Output Ch start: For the Midi allocator to send MPE. | |||
* Output Ch end: The difference between this and the above is your pitch-class polyphony. | |||
* Scale-bend or 12edo: Keep this on. I forgot to delete this. | |||
===== .plist Articulation set ===== | ===== .plist Articulation set (alternate) ===== | ||
<syntaxhighlight lang="xml" line="1"> | <syntaxhighlight lang="xml" line="1"> | ||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
| Line 306: | Line 707: | ||
<key>Articulations</key> | <key>Articulations</key> | ||
<array> | <array> | ||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>1</integer> | |||
<key>ID</key> | |||
<integer>1001</integer> | |||
<key>Name</key> | |||
<string>0</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>64</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>2</integer> | |||
<key>ID</key> | |||
<integer>1002</integer> | |||
<key>Name</key> | |||
<string>+1</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>65</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>3</integer> | |||
<key>ID</key> | |||
<integer>1003</integer> | |||
<key>Name</key> | |||
<string>-1</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>63</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>4</integer> | |||
<key>ID</key> | |||
<integer>1004</integer> | |||
<key>Name</key> | |||
<string>+2</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>66</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>5</integer> | |||
<key>ID</key> | |||
<integer>1005</integer> | |||
<key>Name</key> | |||
<string>-2</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>62</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>6</integer> | |||
<key>ID</key> | |||
<integer>1006</integer> | |||
<key>Name</key> | |||
<string>+3</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>67</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>7</integer> | |||
<key>ID</key> | |||
<integer>1007</integer> | |||
<key>Name</key> | |||
<string>-3</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>61</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>8</integer> | |||
<key>ID</key> | |||
<integer>1008</integer> | |||
<key>Name</key> | |||
<string>+4</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>68</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>9</integer> | |||
<key>ID</key> | |||
<integer>1009</integer> | |||
<key>Name</key> | |||
<string>-4</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>60</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>10</integer> | |||
<key>ID</key> | |||
<integer>1010</integer> | |||
<key>Name</key> | |||
<string>+5</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>69</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>11</integer> | |||
<key>ID</key> | |||
<integer>1011</integer> | |||
<key>Name</key> | |||
<string>-5</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>59</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>12</integer> | |||
<key>ID</key> | |||
<integer>1012</integer> | |||
<key>Name</key> | |||
<string>+6</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>70</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>13</integer> | |||
<key>ID</key> | |||
<integer>1013</integer> | |||
<key>Name</key> | |||
<string>-6</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>58</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>14</integer> | |||
<key>ID</key> | |||
<integer>1014</integer> | |||
<key>Name</key> | |||
<string>+7</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
<integer>71</integer> | |||
</dict> | |||
</array> | |||
</dict> | |||
<dict> | |||
<key>ArticulationID</key> | |||
<integer>15</integer> | |||
<key>ID</key> | |||
<integer>1015</integer> | |||
<key>Name</key> | |||
<string>-7</string> | |||
<key>Output</key> | |||
<array> | |||
<dict> | |||
<key>MB1</key> | |||
<integer>27</integer> | |||
<key>Status</key> | |||
<string>Controller</string> | |||
<key>ValueLow</key> | |||
</array> | </array> | ||
<key>Name</key> | <key>Name</key> | ||
| Line 441: | Line 3,146: | ||
</dict> | </dict> | ||
</plist> | </plist> | ||
</syntaxhighlight> | </syntaxhighlight> | ||