# Hello from London + question on iteration

Hello! I’m Chris from south-west London, retired software developer, keen musician (keyboard, oboe: classical, jazz, rock). I found SPi via a recent episode of the Cool Tools podcast. Hoping to teach it to my 5 grandkids when they’re old enough.

Spi now running on a Win7 workstation; failed to get it to work on my Chromebook, though I would love to sort this out. Also have a RPi 3 Model B on my shelf which I will dust off.

A coding question: Can I retrieve the number of elements in a list? For example, to audition all the synths I’ve written…

``````loop do
use_synth synth_names[tick]
print look, synth_names[look]
play 60
sleep 1
end
``````

…which works, but repeats ad infinitum. I’d like to do the equivalent of the javascriptesque pseudo-code…

``````for (let index = 0; index < synth_names.length; ++index) {
use_synth synth_names[index];
print look, synth_names[look];
play 60;
sleep 1;
}
``````

HI there and welcome to in-thread

Here is one possible solution. It will repeat indefinitely until you press stop

``````live_loop :synthNames do
n=tick%synth_names.length #n will increment with each tick, and start again when all the synths have played
use_synth synth_names.look #picks the next synth name
puts n, synth_names.look #prints n and synth name
play 60
sleep 1
end
``````

EDIT
the number of synths available is synth_names.length

Ah, that’s more like what I’m after, thanks Robin.

Hi, alternatively, if you wanted to stop after playing all the synths, you could do it this way:

``````define :audition_synths do
num_of_synths = synth_names.length

num_of_synths.times do
use_synth synth_names.tick
play 60
sleep 1
end
end

audition_synths``````

By the way Chris, glad to see some fellow retired guys finding the time now to play with stuff that isn’t work. Seems like you got the answers you were looking for and I hope your grandkids have have some fun with Sonic.pi.

Cheers from across the pond here in Philadelphia

There’s quite a few of us around. I’m well past 70. Cut my teeth on Nascom 2 trs80 apple II etc. Also grand children into using computers.

1 Like

That makes me happy to no end! I’m just 62 and coming up on my well-deserved retirement from public service. I’ve been into the tech world for just about forever. Literally since the days of my Timex/Sinclair 1000. I’ve been saying to everyone that will tolerate my pontificating that retired people are itching, and I mean it, to have fun with stuff they couldn’t dive into while work called. At the rate I’m going, I’ll have to install a second mains line into the house just to power it all!

I started out in the '70s with an EMS Synthi A, after turning up unannounced at Peter Zinovieff’s house in Putney with iirc £300 cash to buy it. It was versatile, albeit with no temperature compensation on the oscillators, at least on the early version I had. Eventually someone stole it - I note from Wikipedia it would be quite valuable now!

You could do a lot with the Synthi and a TEAC reel-to-reel recorder. I even got to play with the Synthi 100 at Cardiff University one summer - amazing. Anyway, loving SPi…

1 Like