Hello SCAMPsters!
Short time user, even shorter-time reader.
I’ve been getting this annoying error when trying to reproduce some of Marc’s video material in my own way. I ran the Cooking with Scamp code locally, so I don’t think that it’s an issue with Python and so assume it’s my code.
Trying to auto-insert some barlines but keep getting IndexError: list out of range.
The full error is:
Traceback (most recent call last):
File “/Users/vin/Dropbox/Composition/2022/SCAMP/WB7/brains.py”, line 133, in
s.stop_transcribing().to_score(bar_line_locations=bar_lines, simplicity_preference=1.0, max_divisor=14).show()
File “/Users/vin/Library/Python/3.7/lib/python/site-packages/scamp/performance.py”, line 1097, in to_score
simplicity_preference=simplicity_preference, title=title, composer=composer
File “/Users/vin/Library/Python/3.7/lib/python/site-packages/scamp/score.py”, line 924, in from_performance
max_divisor_indigestibility=max_divisor_indigestibility, simplicity_preference=simplicity_preference
File “/Users/vin/Library/Python/3.7/lib/python/site-packages/scamp/quantization.py”, line 557, in from_attributes
simplicity_preference=simplicity_preference, loop=loop)
File “/Users/vin/Library/Python/3.7/lib/python/site-packages/scamp/quantization.py”, line 606, in from_time_signature_list
simplicity_preference=simplicity_preference)
File “/Users/vin/Library/Python/3.7/lib/python/site-packages/scamp/quantization.py”, line 398, in from_time_signature
return cls(beat_schemes, time_signature)
File “/Users/vin/Library/Python/3.7/lib/python/site-packages/scamp/quantization.py”, line 345, in init
self.beat_groupings = self._generate_default_beat_groupings()
File “/Users/vin/Library/Python/3.7/lib/python/site-packages/scamp/quantization.py”, line 402, in _generate_default_beat_groupings
last_beat_length = self.beat_schemes[0].length
IndexError: list index out of range
%Run ScampCooking.py
from scamp import *
import random
s = Session(tempo=130)
oboe = s.new_part("oboe")
bar_lines = []
duration_list = []
pitch_list = []
pitch_base_list = [60, 59, 60, 59, 55, 54, 69, 59]
interval_list = [0, 2, 3, 5, 7, 8, 9, 10]
interval_mult = [1, 2, 3, -2]
def round_multiple(number, multiple):
return multiple * round(number / multiple)
def construct_parent_list(tuplet_size, output_size, duration_size):
for i in range(output_size):
rhythm_sub_list = []
pitch_sub_list = []
sub_tuplet = round(random.random() * tuplet_size)
for i in range(sub_tuplet):
sub_duration_size = round_multiple(random.random() * duration_size, 0.25)
sub_pitch = random.choice(pitch_base_list) + random.choice(interval_list) * random.choice(interval_mult)
rhythm_sub_list.append(sub_duration_size)
pitch_sub_list.append(sub_pitch)
duration_list.append(rhythm_sub_list)
pitch_list.append(pitch_sub_list)
for f in duration_list:
if f == []:
f = None
def oboe_voice():
for z in pitch_base_list:
random_index = round(random.random() * len(duration_list)-1)
rhythm_pattern = duration_list[random_index]
pitch_pattern = pitch_list[random_index]
print(rhythm_pattern)
bar_lines.append(s.time()) # Trying to do THIS part.
for x, y in zip(rhythm_pattern, pitch_pattern):
test_num = random.random()
if test_num < 0.5:
if x != 0.0:
oboe.play_note(y, random.uniform(0.5, 1.0), x)
else:
s.wait(random.choice(rhythm_pattern))
elif test_num < 0.8:
if x != 0.0:
oboe.play_note([y, y+random.choice(interval_list) * random.choice(interval_mult)], random.uniform(0.5, 1.0), x)
else:
s.wait(random.choice(rhythm_pattern))
else:
if x != 0.0:
oboe.play_note(y, random.uniform(0.5, 1.0), x, "staccato")
s.wait(random.choice(rhythm_pattern))
else:
s.wait(random.choice(rhythm_pattern))
construct_parent_list(7, 10, 1.3)
s.start_transcribing()
while s.time() <= 4:
oboe_voice()
s.stop_transcribing().to_score(bar_line_locations=bar_lines, simplicity_preference=1.0, max_divisor=14).show()