Arvo Part Tintinnabuli and if/else problems

I am clearly getting something horribly wrong :). Help? :slight_smile:

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! :slight_smile: It’s not yet doing what I would like it to do musically, but that’s a great start :). Thank you! x