# Arvo Part Tintinnabuli and if/else problems

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;
)
``````

Iâ€™m not sure if there are logic errors in the code, but there are definitely syntax errors.

else: SC language is not C. Thereâ€™s no â€śelseâ€ť keyword.

Semicolons after control structures: SC language is not C. You canâ€™t omit `;` between expressions.

Negation: `-something` is not allowed. `something.neg`.

Pseq needs an array: `Pseq(aPattern, inf)` is not valid. `Pseq([aPattern], inf)` is OK, as is `Pn(aPattern, inf)`.

``````(
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 = Pn(m_voice.collect({ |m_note|
var t_candidates;

if (t_position == 1) {
t_candidates = [0, 4, 7] - m_note % 12;
} {
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;
} {
if (t_voice_type == 2) {
t_candidates.maxItem.neg;
} {
if (m_note % 2 == 0) {
t_candidates.minItem;
} {
t_candidates.maxItem.neg;
}
}
}
}), 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;
)
``````

hjh

1 Like

Well it runs! Itâ€™s not yet doing what I would like it to do musically, but thatâ€™s a great start :). Thank you! x