def triads_interruption(
					inst1, 
					inst2, 
					chords, 
					voice_manager, 
					chord_indices, 
					chord_lengths, 
					play_loud_chord = True):

	my_id = VoiceId(triads_interruption.__name__, 0)

	did_play = False

	while not did_play:

		can_play = voice_manager.request_permission(my_id)

		if can_play:

			if (play_loud_chord 
				and not (triads.__name__ in voice_manager.previous_voices) 
				and not (voice_manager.previous_voices[1] == octaves.__name__)):
				inst1.play_chord([p.midi_number for p in chords[chord_indices[0]].pitches if p.overtone_class in [1, 3, 5]], 
												0.8, 0.125, "staccato")		
				scamp.wait(1.0)

			i = -1

			while i < len(chord_indices) - 1:

				i += 1
				selected_chord_index = chord_indices[i]
				current_chord = chords[selected_chord_index]

				length = Utilities.quantize(chord_lengths[i % len(chord_lengths)], 0.125)

				midi = [p.midi_number + 24 - 1 for p in current_chord.pitches if p.overtone_class in [3, 5]]
				midi.extend([p.midi_number + 36 - 1 for p in current_chord.pitches if p.overtone_class in [1]])

				inst2.play_chord(midi, 0.7, 0.125, "staccato")		
				length -= 0.125

				scamp.wait(Utilities.quantize(length, 0.125))

			voice_manager.leave_queue(my_id)

			did_play = True

		else:

			scamp.wait(0.1)
def field_octaves(inst,
                  chords,
                  phrase_lengths,
                  voice_manager,
                  length_multiplier_manager,
                  pedal_up,
                  pedal_down,
                  chord_index_seed=0,
                  phrase_length_index_seed=0):

    my_id = VoiceId(field_octaves.__name__, threading.current_thread().ident)

    chord_index_iterator = 1

    chord_index = chord_index_seed - chord_index_iterator
    phrase_length_index = phrase_length_index_seed - 1

    q = 0

    while q < 5:

        can_play = voice_manager.request_permission(my_id)

        if can_play:

            q += 1

            chord_index += chord_index_iterator
            current_chord = chords[chord_index % len(chords)]

            phrase_length_index += 1
            mult = length_multiplier_manager.get_length_multiplier(
                field_octaves.__name__).get_value()
            phrase_length = phrase_lengths[phrase_length_index %
                                           len(phrase_lengths)] * mult

            p = [p for p in current_chord.pitches if p.overtone_class == 27][0]
            pedal_up.play_note(0, 0.0, 0.001)
            scamp.wait(0.125)
            pedal_down.play_note(0, 0.0, 0.001)
            inst.play_chord([
                p.midi_number, p.midi_number - 24, p.midi_number - 36,
                p.midi_number + 12
            ], 0.4, 0.125, "staccato")
            phrase_length -= 0.125

            voice_manager.leave_queue(my_id)

            if voice_manager.should_try_play:
                scamp.wait(Utilities.quantize(phrase_length, 0.125))

        else:

            scamp.wait(1 / 16)
Beispiel #3
0
    def _get_dequeue_time(self):

        if len(self._dequeue_times) == 0:
            raise IndexError("No dequeue times have been set")

        with self._lock:
            self._dequeue_iterator = (self._dequeue_iterator + 1) % len(
                self._dequeue_times)
            time = self._dequeue_times[self._dequeue_iterator]
            if self.time_quantization_value is not None:
                time = Utilities.quantize(time, self.time_quantization_value)
            return time
def field_triads(inst,
                 chords,
                 phrase_lengths,
                 voice_manager,
                 length_multiplier_manager,
                 chord_index_seed=0,
                 phrase_length_index_seed=0):

    my_id = VoiceId(field_triads.__name__, threading.current_thread().ident)

    chord_index_iterator = 1

    chord_index = chord_index_seed - chord_index_iterator
    phrase_length_index = phrase_length_index_seed - 1

    q = 0

    while q < 5:

        can_play = voice_manager.request_permission(my_id)

        if can_play:

            q += 1

            chord_index += chord_index_iterator
            current_chord = chords[chord_index % len(chords)]

            phrase_length_index += 1
            mult = length_multiplier_manager.get_length_multiplier(
                field_triads.__name__).get_value()
            phrase_length = phrase_lengths[phrase_length_index %
                                           len(phrase_lengths)] * mult

            inst.play_chord([
                p.midi_number for p in current_chord.pitches
                if p.overtone_class in [1, 3, 5]
            ], 0.2, 0.125, "staccato")
            phrase_length -= 0.125

            voice_manager.leave_queue(my_id)

            if voice_manager.should_try_play:
                scamp.wait(Utilities.quantize(phrase_length, 0.125))

        else:

            scamp.wait(1 / 16)
Beispiel #5
0
    [3, 2, 7, 6, 6, 4, 5, 3, 3, 7, 6, 9, 10, 8, 3],
    [7, 0, 8, 9, 6, 6, 2, 1, 8, 7, 5, 7,
     5], [11, 4, 8, 8, 7, 9, 8, 2, 2, 7, 5], [7, 0, 8, 5, 4, 6, 4, 9],
    [3, 4, 7, 5, 9, 7, 7, 7], [0, 3, 7, 4, 5, 6], [3, 2, 7, 6, 9, 10]
]
interruption_chord_lengths = [[0.25, 0.5, 0.25, 0.5, 0.25]] * 6
interruption_chord_lengths.extend([[0.25, 0.5, 0.25, 0.25, 0.25]] * 2)
i = -1

for beats, indices, lengths in zip(pre_interruption_waits,
                                   interruption_chord_indices,
                                   interruption_chord_lengths):

    i += 1

    s.wait(Utilities.quantize(beats, 0.125))

    vm1.enter_vip_mode(triads_interruption.__name__)
    # print("--> " + str(i) + ": " + str(indices))
    triads_interruption(
        inst1=pianoteq_triads,
        inst2=pianoteq_triads_detuned,
        chords=chords,
        voice_manager=vm1,
        chord_indices=indices,
        chord_lengths=[Utilities.quantize(l, 0.125) for l in lengths])
    vm1.exit_vip_mode()

    update_length_multipliers(lmm)

    if i == 1:
def field_slow_arpeggios(inst1,
                         inst2,
                         chords,
                         phrase_lengths,
                         voice_manager,
                         length_multiplier_manager,
                         pitch_index_seed=0,
                         phrase_length_index_seed=0):

    my_id = VoiceId(field_slow_arpeggios.__name__,
                    threading.current_thread().ident)

    chord_index_iterator = -1

    pitch_index_iterator = 5  # NB!

    pitch_index = pitch_index_seed - pitch_index_iterator
    phrase_length_index = phrase_length_index_seed - 1

    q = 0

    while q < 6:

        can_play = voice_manager.request_permission(my_id)

        if can_play:

            chord_index_iterator += 1
            chord = chords[chord_index_iterator % len(chords)]

            q += 1

            pitches = []

            for _ in range(0, 7):
                pitch_index += pitch_index_iterator
                # if pitch_index % len(chord.pitches) == 0:
                # 	pitch_index += pitch_index_iterator
                pitches.append(chord.pitches[pitch_index % len(chord.pitches)])
            if q == 6:
                pitches.extend(
                    [p for p in chord.pitches if p.overtone_class == 3])
                pitches.extend(
                    [p for p in chord.pitches if p.overtone_class == 1])
                # pitches.extend([p for p in chord.pitches if p.overtone_class == 7])
                # pitches.extend([p for p in chord.pitches if p.overtone_class == 11])

            phrase_length_index += 1
            mult = length_multiplier_manager.get_length_multiplier(
                field_slow_arpeggios.__name__).get_value()
            phrase_length = phrase_lengths[phrase_length_index %
                                           len(phrase_lengths)] * mult

            note_lengths = [0.6, 0.6]
            for _ in range(0, (len(pitches) - 2)):
                note_lengths.append(0.4)

            for p, l in zip(pitches, note_lengths):
                # 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 27
                midi = p.midi_number
                if p.overtone_class in [1, 3, 5, 9, 15, 17, 19, 27]:
                    inst1.play_note(midi, 0.2, Utilities.quantize(l, 0.125))
                elif p.overtone_class in [7, 11, 13, 21]:
                    inst2.play_note(midi, 0.2, Utilities.quantize(l, 0.125))
                elif p.overtone_class in [13]:
                    inst2.play_note(midi + 1, 0.2,
                                    Utilities.quantize(l, 0.125))
                phrase_length -= Utilities.quantize(l, 0.125)

            voice_manager.leave_queue(my_id)

            if voice_manager.should_try_play:
                scamp.wait(Utilities.quantize(phrase_length, 0.125))

        else:

            scamp.wait(1 / 16)
def field_true_arpeggios(inst,
                         chords,
                         phrase_lengths,
                         voice_manager,
                         length_multiplier_manager,
                         tempo_factor,
                         chord_index_seed=0,
                         phrase_length_index_seed=0):

    my_id = VoiceId(field_true_arpeggios.__name__,
                    threading.current_thread().ident)

    chord_index_iterator = 1

    chord_index = chord_index_seed - chord_index_iterator
    phrase_length_index = phrase_length_index_seed - 1

    reversable_indices = [7, 8, 1, 10]
    jitterable_indices = [7, 2, 1, 5, 8]

    q = 0

    while q < 6:

        can_play = voice_manager.request_permission(my_id)

        if can_play:

            q += 1
            current_chord = chords[0]

            phrase_length_index += 1
            mult = length_multiplier_manager.get_length_multiplier(
                field_true_arpeggios.__name__).get_value()
            phrase_length = phrase_lengths[phrase_length_index %
                                           len(phrase_lengths)] * mult

            midi = [
                p.midi_number for p in current_chord.pitches
                if (p.is_harmonic_tone and p.midi_number >= 67
                    and p.overtone_class not in [27])
            ][-(8 - q):]

            # print(len(midi))

            if (chord_index % len(chords) in reversable_indices):
                midi = sorted(midi, reverse=True)

            jitter_count = 0

            for i in range(0, len(midi)):

                properties = ["staccato"]
                if i == 0:
                    properties.append("text: " +
                                      str(chord_index % len(chords)))
                inst.play_note(midi[i],
                               0.2,
                               Utilities.quantize(0.125 * tempo_factor, 0.125),
                               properties=properties)
                phrase_length -= 0.125 * tempo_factor

                if i == 3 and chord_index % len(chords) in jitterable_indices:
                    inst.play_note(
                        midi[i - 1], 0.2,
                        Utilities.quantize(0.125 * tempo_factor, 0.125),
                        "staccato")
                    phrase_length -= 0.125 * tempo_factor
                    inst.play_note(
                        midi[i], 0.2,
                        Utilities.quantize(0.125 * tempo_factor, 0.125),
                        "staccato")
                    phrase_length -= 0.125 * tempo_factor

                    inst.play_note(
                        midi[i - 1], 0.2,
                        Utilities.quantize(0.125 * tempo_factor, 0.125),
                        "staccato")
                    phrase_length -= 0.125 * tempo_factor
                    inst.play_note(
                        midi[i], 0.2,
                        Utilities.quantize(0.125 * tempo_factor, 0.125),
                        "staccato")
                    phrase_length -= Utilities.quantize(
                        0.125 * tempo_factor, 0.125)

                    jitter_count += 1

            scamp.wait(1.25)
            inst.play_note(midi[-1], 0.2, 0.125)

            voice_manager.leave_queue(my_id)

            if voice_manager.should_try_play:
                scamp.wait(Utilities.quantize(phrase_length, 0.125))

        else:

            scamp.wait(1 / 16)
def field_repeated_chords(inst1,
                          inst2,
                          chords,
                          phrase_lengths,
                          voice_manager,
                          length_multiplier_manager,
                          pitch_index_seed=0,
                          phrase_length_index_seed=0):

    my_id = VoiceId(field_repeated_chords.__name__,
                    threading.current_thread().ident)

    chord_index_iterator = -1

    pitch_index_iterator = 7

    pitch_index = pitch_index_seed - pitch_index_iterator
    phrase_length_index = phrase_length_index_seed - 1

    q = 0

    while q < 5:

        can_play = voice_manager.request_permission(my_id)

        if can_play:

            q += 1

            chord_index_iterator += 1
            chord = chords[chord_index_iterator % len(chords)]

            pitches = []
            for i in range(0, 2):
                pitch_index += pitch_index_iterator
                if i == 1:
                    pitch_index += 4
                pitches.append(chord.pitches[pitch_index % len(chord.pitches)])

            phrase_length_index += 1
            mult = length_multiplier_manager.get_length_multiplier(
                field_repeated_chords.__name__).get_value()
            phrase_length = phrase_lengths[phrase_length_index %
                                           len(phrase_lengths)] * mult

            note_lengths = [5, 0.25]
            dynamics = [0.3, 0.1]

            for l, d in zip(note_lengths, dynamics):
                for p in pitches:
                    # 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 27
                    if p.overtone_class in [1, 3, 5, 9, 15, 17, 19, 27]:
                        inst1.play_note(p.midi_number,
                                        d,
                                        Utilities.quantize(l, 0.125),
                                        blocking=False)
                    elif p.overtone_class in [7, 11, 13, 21]:
                        inst2.play_note(p.midi_number,
                                        d,
                                        Utilities.quantize(l, 0.125),
                                        blocking=False)
                    elif p.overtone_class in [13]:
                        inst2.play_note(p.midi_number + 1,
                                        d,
                                        Utilities.quantize(l, 0.125),
                                        blocking=False)
                scamp.wait(Utilities.quantize(l, 0.125))
                phrase_length -= Utilities.quantize(l, 0.125)

            voice_manager.leave_queue(my_id)

            if voice_manager.should_try_play:
                scamp.wait(Utilities.quantize(phrase_length, 0.125))

        else:

            scamp.wait(1 / 16)
def field_grace_notes(inst1,
                      inst2,
                      chords,
                      phrase_lengths,
                      voice_manager,
                      length_multiplier_manager,
                      pitch_index_seed=0,
                      phrase_length_index_seed=0):

    my_id = VoiceId(field_grace_notes.__name__,
                    threading.current_thread().ident)

    chord_index_iterator = -1

    pitch_index_iterator = 7  # NB!

    repeatable_indices = [7, 9, 4, 6, 3, 10]

    pitch_index = pitch_index_seed - pitch_index_iterator
    phrase_length_index = phrase_length_index_seed - 1

    q = 0

    while q < 6:

        can_play = voice_manager.request_permission(my_id)

        chord_index_iterator += 1
        chord = chords[chord_index_iterator % len(chords)]

        if can_play:

            q += 1

            pitches = []
            pitch_reserves = []
            for i in range(0, 2):
                pitch_index += pitch_index_iterator
                pitches.append(chord.pitches[pitch_index % len(chord.pitches)])
                if (pitch_index % len(chord.pitches) in repeatable_indices):
                    pitch_reserves.append(chord.pitches[pitch_index %
                                                        len(chord.pitches)])
                # print(pitch_index % len(chord.pitches))
            pitches.extend(pitch_reserves)

            note_lengths = [0.25, 1.25, 0.25]

            phrase_length_index += 1
            mult = length_multiplier_manager.get_length_multiplier(
                field_grace_notes.__name__).get_value()
            phrase_length = phrase_lengths[phrase_length_index %
                                           len(phrase_lengths)] * mult

            for p, l in zip(pitches, note_lengths):
                # 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 27
                if p.overtone_class in [1, 3, 5, 9, 15, 17, 19, 27]:
                    inst1.play_note(p.midi_number, 0.2,
                                    Utilities.quantize(l, 0.125))
                elif p.overtone_class in [7, 11, 13, 21]:
                    inst2.play_note(p.midi_number, 0.2,
                                    Utilities.quantize(l, 0.125))
                elif p.overtone_class in [13]:
                    inst2.play_note(p.midi_number + 1, 0.2,
                                    Utilities.quantize(l, 0.125))
                phrase_length -= Utilities.quantize(l, 0.125)

            voice_manager.leave_queue(my_id)

            if voice_manager.should_try_play:
                scamp.wait(Utilities.quantize(phrase_length, 0.125))

        else:

            scamp.wait(1 / 16)
def grace_notes(
			inst, 
			chords, 
			phrase_lengths, 
			voice_manager, 
			length_multiplier_manager, 
			chord_index_seed = 0, 
			phrase_length_index_seed = 0):

	my_id = VoiceId(grace_notes.__name__, threading.current_thread().ident)

	chord_index_iterator = 1

	chord_index = chord_index_seed - chord_index_iterator
	phrase_length_index = phrase_length_index_seed - 1

	reversable_indices = [2, 5, 7, 11]
	jitterable_indices = [1, 2, 4, 6, 7, 11]
	repeatable_indices = [3, 5, 8, 9, 10]

	while voice_manager.should_try_play:

			can_play = voice_manager.request_permission(my_id)

			if can_play:

				chord_index += chord_index_iterator
				current_chord = chords[chord_index % len(chords)]
				# print("playing grace notes " + str(chord_index % len(chords)))

				phrase_length_index += 1
				mult = length_multiplier_manager.get_length_multiplier(grace_notes.__name__).get_value()
				phrase_length = phrase_lengths[phrase_length_index % len(phrase_lengths)] * mult

				midi = [p.midi_number for p in current_chord.pitches if p.overtone_class in [19, 21]]

				if (chord_index % len(chords) in reversable_indices):
					midi = sorted(midi, reverse = True)

				should_jitter = chord_index % len(chords) in jitterable_indices
				should_repeat = chord_index % len(chords) in repeatable_indices

				if should_jitter or should_repeat:
					for i in range(0, len(midi)):
						if i == 0:
							inst.play_note(midi[i], 0.4, 0.125, properties = ["staccato", "text: " + str(chord_index % len(chords))])
							phrase_length -= 0.125
						elif i == 1 and should_jitter:
							inst.play_note(midi[i], 0.4, 0.875)
							phrase_length -= 0.875
							inst.play_note(midi[i - 1], 0.4, 0.125, "staccato")
							phrase_length -= 0.125
						elif i == 1 and should_repeat: 
							inst.play_note(midi[i], 0.4, 0.875)
							phrase_length -= 0.875
							inst.play_note(midi[i], 0.4, 0.125, "staccato")
							phrase_length -= 0.125

				else:
					for i in range(0, len(midi)):
						properties = ["staccato"]
						if i == 0:
							properties.append("text: " + str(chord_index % len(chords)))
						inst.play_note(midi[i], 0.4, 0.125, properties = properties)
						phrase_length -= 0.125

				voice_manager.leave_queue(my_id)

				if voice_manager.should_try_play:
					scamp.wait(Utilities.quantize(phrase_length, 0.125))

			else:

				scamp.wait(0.1)