Linked Questions

Popular Questions

I am using EarSketch for a assignment at school, a tool that allows you to program music in Python (even if you are not familiar with EarSketch please any input is appreciated, as it seems that my issue is mostly with Python and not with EarSketch, but EarSketch could be part of it which is why I mention it.) In order to complete the assignment I must feature at least one function that helps me automate the process of making a ringtone. So far my code looks like so: https://earsketch.gatech.edu/earsketch2/?sharing=WAo1CdSaae72pppDkc40Hw

In the event that the link doesn't work or something, here is a code block:

from earsketch import *

init()
setTempo(120)

starts = 7

tracklist = []
track_number = int(0)

tracklist.append("gorp") # 0

tracklist.append(COMMON_LOVE_DRUMBEAT_1) # 1
tracklist.append(HIPHOP_DUSTYGROOVEPART_001) # 2
tracklist.append(AK_UNDOG_PERC_HATS_1) # 3

tracklist.append(AK_UNDOG_PAD_1) # 4
tracklist.append(AK_UNDOG_PAD_1) # 5

tracklist.append(ELECTRO_ANALOGUE_PHASERBASS_003) # 6
tracklist.append(ELECTRO_ANALOGUE_PHASERBASS_001) # 7
tracklist.append(ELECTRO_ANALOGUE_PHASERBASS_002) # 8

def parallel_tracks(sounds = [], sounds_length = [], sound_offsets = []):
    sound_num = 0
    
    points = []
    points.append("gorp")
    
    for measure in range(1, starts):
        for i in range(1, len(sounds)):
            sound_num += 1
            points.append(measure + sound_offsets[sound_num])
            points.append(points[sound_num - 1] + sound_offsets[sound_nums])
            fitMedia(sounds[sound_num], sound_num, points[sound_num - 1], points[sound_num])
        
          

parallel_tracks(tracklist[4], 4, 0)

finish()

What I was trying to do was write a function that makes multiple audio clips play at the same time for a specified length and offset each. The way I am currently trying to approach this is using a custom function called parallel_tracks() with the parameters sounds[], sounds_length[], and sound_offsets[]. So far I am trying to make it so that for each sound[] entry two entries for a new list called points[] are created, one odd and one even, with the odd one being the start number that goes in the third parameter of fitMedia(sound, track, **start**, end) (this is one of the ways music is created in EarSketch) and is hopefully equal to measure (a variable representing the current measure of the song) plus sound_offsets[*whichever sound[] is currently being fit*] (so while processing sound[1] sound_offsets = [1] and that corresponds to a value such as 1 or -3, thus allowing me to offset a sound by whatever value.) The even point created afterward is the end parameter of the fitMedia() function (so fitMedia(sound, track, start, **end**)), and should be equal to the even points[] entry plus sounds_length[] (sounds_length[] matches up with the current entry number of sounds[] as well.) What should happen is that every fitMedia() function should use the two points in tandem with sounds[] and a variable tracking which track to place the sound on to fill out all four fields, the problem is of course on line 33 and with the general structure, but I will focus on line 33's error for now and see where that gets me.

I have tried multiple designs but have encountered this same or similar error (I don't remember what errors specifically I just remember this one and that there might have been other kinds of errors; I did not save my previous versions so I could not check and see.) The error came up while using a variable that would increment to track which sound was currently being processed and which track the sounds should be placed on, then of course this same value would be used on the other two lists. Then I would loop this process for each number in a variable called starts (starts is how many times any given sound with a length of one would start; if a sound has a length of say, four, and an offset of zero, then the sound would play starting on the first measure and end on the fifth measure, then if starts was seven like it is in the script the sound would play again immediately after and end after measure 7 since 1 + 4 + 4 is 9, thus the sound would end on measure 9) until the last sound with length 1 starts on measure 7.

Then there is the error, all I really know is that apparently one of the two lists on line 33 is technically a integer for whatever reason? I saw a few other forum threads talking about the same error but they were all using SQL of some sort aside from one, which was using python to create some kind of renderer called a turtle renderer? Anyways, they had the same error as I had in a more applicable context, and someone proposed a solution that didn't seem particularly applicable to my situation but could serve as a lead (*Why does line 34 return: TypeError: 'int' does not support indexing) They seemed to have accidently overwritten their list variable with a integer variable in a for loop, so someone proposed replacing it, but other than that possible thread I didn't find anything useful; all that I could fine were the aforementioned SQL stuffs. Looking at it there doesn't seem to be a problem at first glance? I have tried many different methods I am trying to (mostly ones not involving using this crummy points system and instead just slotting an equation right into the different fields of fitMedia() but I tried this points system in the hopes I wouldn't get the error; the issue remained and it went from afflicting the fitMedia() to the points system which comes first.

tl;dr, I am getting a really strange error involving loops and lists, I think there might be a better way to do what I am doing but this error has been a recurring and seemingly unsolvable issue for me.

Related Questions