frac32 stretch
int32 root
int32 chord
int32 invert
int32 spread
int32 key
int32 scale
int32 temper
frac32 n1
frac32 n2
frac32 n3
frac32 n4
objref scale
int32_t out;
int key;
int scale;
int32_t STR;
int32_t temper;
int32_t N[4];
int P[4];
int i;
int32_t scalar(int NT) {
int32_t pitch = NT + 64;
int32_t octave = pitch / 7;
int semitone = pitch - octave * 7;
int32_t note = (attr_scale.note[semitone + scale] + octave * 12) - 112 + key
<< 21;
int mn = (note + (1 << 20) >> 21) + 8;
int32_t stretch = mn / 12;
stretch = stretch * (STR >> 9);
int oct = mn / 12 * 12;
oct = mn < 0 ? oct - 12 : oct;
mn = mn - oct;
int tmpr = temper;
tmpr = tmpr - tmpr / 137 * 137;
tmpr += tmpr < 0 ? 137 : 0;
tmpr = tmpr * 12;
return out = attr_scale.TMPR[mn + tmpr] + note + stretch;
};
int S[26][4] = {{2, 2, 2, 2}, {3, 2, 1, 2}, {3, 2, 2, 1}, {2, 3, 2, 1},
{2, 3, 1, 2}, {2, 1, 3, 2}, {2, 1, 2, 3}, {1, 2, 2, 3},
{1, 2, 3, 2}, {1, 3, 2, 2}, {3, 1, 2, 2}, {2, 2, 1, 3},
{2, 2, 3, 1}, {1, 3, 3, 1}, {1, 3, 1, 3}, {3, 1, 1, 3},
{3, 1, 3, 1}, {2, 1, 4, 1}, {2, 4, 1, 1}, {4, 2, 1, 1},
{4, 1, 2, 1}, {4, 1, 1, 2}, {1, 4, 1, 2}, {1, 1, 4, 2},
{1, 1, 2, 4}, {1, 2, 1, 4}};
int32_t T[26][3] = {
{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}, {0, 1, 1}, {1, 0, 1}, {1, 1, 0},
{0, 1, 2}, {1, 0, 2}, {1, 2, 0}, {2, 1, 0}, {1, 1, 1}, {1, 1, 2}, {1, 2, 1},
{2, 1, 1}, {1, 2, 2}, {2, 1, 2}, {2, 2, 1}, {2, 2, 2}, {1, 2, 3}, {1, 3, 2},
{2, 3, 1}, {3, 2, 1}, {3, 1, 2}, {2, 1, 3}, {2, 2, 3},
};
N[0] = 0;
N[1] = 0;
N[2] = 0;
N[3] = 0;
scale = inlet_scale;
scale = scale - scale / 46 * 46;
scale = scale < 0 ? scale + 46 : scale;
scale = scale * 7;
int chord = inlet_chord;
chord = chord - chord / 26 * 26;
chord = chord < 0 ? chord + 26 : chord;
int spread = inlet_spread;
spread = spread - spread / 26 * 26;
spread = spread < 0 ? spread + 26 : spread;
P[0] = inlet_root;
P[1] = P[0] + S[chord][0] + T[spread][0] * 3.5;
P[2] = P[1] + S[chord][1] + T[spread][1] * 3.5;
P[3] = P[2] + S[chord][2] + T[spread][2] * 3.5;
if (inlet_invert > 0) {
for (i = 0; i < inlet_invert; i++) {
int a = i & 3;
P[a] += 7;
}
}
if (inlet_invert < 0) {
for (i = 0; i < (-inlet_invert); i++) {
int a = 3 - (i & 3);
P[a] -= 7;
}
}
key = (inlet_key)*7 - 4;
key = key - (key / 12) * 12;
key = key < 0 ? key + 12 : key;
temper = inlet_temper;
STR = inlet_stretch;
N[0] = scalar(P[0]);
N[1] = scalar(P[1]);
N[2] = scalar(P[2]);
N[3] = scalar(P[3]);
outlet_n1 = N[0];
outlet_n2 = N[1];
outlet_n3 = N[2];
outlet_n4 = N[3];