I am clearly getting something horribly wrong :). Help?
The T-voice can remain above, or below the M-voice, or can alternate between above and below the M-voice:
i.) The T-voice that is located above the M-voice is called “superior.”
ii.) The T-voice that that is located below the M-voice is called “inferior.”
iii.) The T-voice that alternates between above and below M-voice is called “alternating.”
The T-voice can also follow one of two positions, which is determined by the distance between the M-voice and the T-voice pairs:
A.) The M-voice with the nearest T-triad is called “first position.”
B.) The M-voice with the second nearest T-triad is called “second position.”
This code is meant to generate a T-voice based on the Melody (M-voice) example, adapting the T-voice notes automatically to the melody. It is meant to easily switch between T-voice combinations (i, ii, and iii) and positions (A and B).
(
MIDIClient.init;
MIDIIn.connectAll;
m = MIDIOut.newByName("PolyBrute", "MIDI");
)
(
var m_voice, t_voice, t_voice_type, t_position;
// Melody (M-voice) example
m_voice = Pseq([0, 2, 4, 5, 7, 9, 11, 12], inf);
// T-voice types: 1 (superior), 2 (inferior), 3 (alternating)
t_voice_type = 1;
// T-voice position: 1 (first position), 2 (second position)
t_position = 1;
t_voice = Pseq(m_voice.collect({ |m_note|
var t_candidates;
if (t_position == 1) {
t_candidates = [0, 4, 7] - m_note % 12;
} else {
t_candidates = [0, 4, 7] - (m_note + 7) % 12;
}
t_candidates = t_candidates.collect(_.abs); // Take the absolute value of the elements
if (t_voice_type == 1) {
t_candidates.minItem;
} else {
if (t_voice_type == 2) {
-t_candidates.maxItem;
} else {
if (m_note % 2 == 0) {
t_candidates.minItem;
} else {
-t_candidates.maxItem;
}
}
}
}), inf);
a = Pbind(
\type, \midi,
\midiout, m,
\chan, 0,
\degree, m_voice,
\scale, Scale.major,
\octave, 5,
\dur, 0.5,
\amp, 0.8
);
b = Pbind(
\type, \midi,
\midiout, m,
\chan, 0,
\degree, t_voice,
\scale, Scale.major,
\octave, 4,
\dur, 0.5,
\amp, 0.6
);
Ppar([a, b]).play;
)