SCAMP For Airports (Writing Ambient Music with Python and Scamp)

i made a little video that i think it may be cool to share here
really beginner stuff, but with cool results

2 Likes

Hello Pedro

I meticulously typed in your script for ambient Airport.py (see video). When playing, I get syntax errors. Can you scan my py file (below): where is it wrong?
I also have a question why you are under “while True” random.choice (durs) twice. Shouldn’t the last random.choice in the line be: wait_time?
where does the sound come from? from a connected synth (not mentioned in the script) or through the computer sound?
FYI: I am using Python on iMac MacOs 14.14.6.
Thanks
Paul

script:

from scamp import *
import random

s= Session()
inst = s.new_part(“synth str”)

def play_ambient(inst, pitch, dur, wait_time):
wait(wait_time)
inst.play_note(pitch,[0,2,0,8,0,3], dur)

pitches = [36,48,51,55,58,60,63,67,70,72,75]
durs = [3 + (0,5 * x) for x in range(10)]

while True:
s.fork(play_ambient, args= [inst, random.choice(pitches), random.choice(durs), random.choice(durs)]
s.fork(play_ambient, args= [inst, random.choice(pitches), random.choice(durs), random.choice(durs)]
s.fork(play_ambient, args= [inst, random.choice(pitches), random.choice(durs), random.choice(durs)]
s.fork(play_ambient, args= [inst, random.choice(pitches), random.choice(durs), random.choice(durs)]
s.fork(play_ambient, args= [inst, random.choice(pitches), random.choice(durs), random.choice(durs)]
s.fork(play_ambient, args= [inst, random.choice(pitches), random.choice(durs), random.choice(durs)]
wait_for_children_to_finish()

the problem is here: it should be 0.5 and not 0,5

as for the random.choice(durs), the functionplay_ambient takes four arguments: the instrument, a pitch, a duration and a wait time
i’m choosing a duration at random with random.choice(durs) AND i’m choosing the wait_time at random, choosing from the same list of durations

and the sound is the default soundfount on my computer
for a list of your available sounds, do:

from scamp import *
s.print_default_soundfont_presets()

Thanks for sharing this Pedro, and for making these videos!

Thanks Pedro.
0.5 OK
“SyntaxError: invalid syntax” at line 16
s.fork(play_ambient, args= [inst, random.choice(pitches), random.choice(durs), random.choice(durs)]

Note: in your videopresentation you typed two time durs after ‘random.choice’. The error stays while changing the last (durs) by (wait_time).

Thanks for your effort.

Paul

Paul, you’re missing the last closing parenthesis on the line you posted.

s.fork(play_ambient, args= [inst, random.choice(pitches), random.choice(durs), random.choice(durs)])

Yes, you should use (durs), because that’s the list of durations. I’m picking a wait time from the available durations, that’s why there are two calls of random.choice(durs).
The syntax error is indeed the missing parenthesis at the end of the line.

Hello Pedro, Great. It works now. I can start to change some subtile values. etc. and to adjust the script into my aspiration. Many thanks for this help.
How I can connect the script to my MIDI keyboard f.e. Roland Go:Keys in stead of the computer sound?
Is it possible?

Thanks in advance.
Paul