Skip to content

Instantly share code, notes, and snippets.

@lvanderlinden
Created September 5, 2012 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvanderlinden/3636560 to your computer and use it in GitHub Desktop.
Save lvanderlinden/3636560 to your computer and use it in GitHub Desktop.
# Generated by OpenSesame 0.26 (Earnest Einstein)
# Wed Sep 5 15:28:04 2012 (posix)
#
# Copyright Sebastiaan Mathot (2010-2011)
# <http://www.cogsci.nl>
#
set foreground "black"
set subject_parity "even"
set description "A template containing a practice and an experimental phase"
set title "Example with random sound and fixed picture"
set sampler_backend "legacy"
set coordinates "relative"
set height "768"
set mouse_backend "legacy"
set width "1024"
set compensation "0"
set keyboard_backend "legacy"
set background "white"
set subject_nr "0"
set canvas_backend "legacy"
set start "experiment"
set synth_backend "legacy"
define inline_script select_sound_file_and_remove_it
set _run ""
___prepare__
"""
DESCRIPTION:
Here the last item from the randomized list is selected
without replacement.
"""
# You can select and remove the last item from a list
# by using pop(), like so:
selected_file = block_list_sound_files.pop()
# Next, you need to 'set' the selected sound file such
# that you can retrieve it in the interface (i.e. use it
# in the sampler and logger item).
# You can do this by using the built-in OpenSesame method
# experiment.self.set():
self.experiment.set("random_sound", selected_file)
# After doing this, you can simply type [random_sound] in
# the sound file box in the the sampler item to play the
# randomly selected sound.
__end__
set description "Executes Python code"
define inline_script randomize_sound_list
set _run ""
___prepare__
"""
DESCRIPTION:
Shuffle the list of sound files.
Note that we do the randomization here (in the block sequence) rather than in the
experiment sequence for two reasons:
- All used sound files are going to be removed from the list. So, after
one block of 63 trials the list will be empty. Therefore, we need to
define a list of sound files at the beginning of every new block.
- It is assumed that you want to 're-randomize' the order of the list
for every separate block, instead of using the same random order across
blocks.
"""
# Start by making a copy of the previously defined list_sound_files,
# such that you can change the copied list (i.e. by shuffling and removing
# items) without affecting the original list:
block_list_sound_files = main_list_sound_files[:]
# Next, you want to shuffle the list such that the order
# of sound files is random.
# For this you need the Python module random, which you first
# have to import as follows:
import random
# By calling the random function shuffle() you can randomize
# the content of the list, like so:
random.shuffle(block_list_sound_files)
# And finally, make the new list global:
global block_list_sound_files
__end__
set description "Executes Python code"
define loop block_loop
set repeat "1"
set description "A single block of trials"
set skip "0"
set offset "no"
set item "trial_sequence"
set column_order "picture"
set cycles "6"
set order "sequential"
setcycle 0 picture "object1.jpg"
setcycle 1 picture "object2.jpg"
setcycle 2 picture "object3.jpg"
setcycle 3 picture "object4.jpg"
setcycle 4 picture "object5.jpg"
setcycle 5 picture "object6.jpg"
run trial_sequence
define loop experimental_loop
set repeat "1"
set description "A loop containing one or more experimental blocks"
set item "block_sequence"
set column_order "practice"
set cycles "1"
set order "random"
setcycle 0 practice "no"
run block_sequence
define sequence experiment
set flush_keyboard "yes"
set description "The main sequence of the experiment"
run define_sound_list "always"
run experimental_loop "always"
define sequence trial_sequence
set flush_keyboard "yes"
set description "A single trial"
run select_sound_file_and_remove_it "always"
run sketchpad "always"
run sampler "always"
run logger "always"
define inline_script define_sound_list
set _run ""
___prepare__
"""
DESCRIPTION:
Make a list containing the names of all 63 sound files and make this list
global, such that you can retrieve it in subsequent inline scripts.
(Note that in this example only 6 pictures and 6 sound files are used.)
"""
# Start by defining a list that contains all sound files, like so:
# (if the lines in your script become too long to be readable, you can
# use line breaks by using '\').
main_list_sound_files = ['sound1.ogg', \
'sound2.ogg','sound3.ogg','sound4.ogg', \
'sound5.ogg', 'sound6.ogg']
# Next, make the list global such that it can also be used outside the
# current inline script:
global main_list_sound_files
__end__
set description "Executes Python code"
define sampler sampler
set volume "1"
set description "Plays a sound file in .wav or .ogg format"
set sample "[random_sound]"
set pitch "1"
set duration "sound"
set stop_after "0"
set pan "0"
set fade_in "0"
define logger logger
set description "Logs experimental data"
define sketchpad sketchpad
set duration "2000"
set description "Displays stimuli"
set start_response_interval "no"
draw image 0 0 "[picture]" scale=1 center=1 show_if="always"
define sequence block_sequence
set flush_keyboard "yes"
set description "A sequence containing a single block of trials followed by feedback to the participant"
run randomize_sound_list "always"
run block_loop "always"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment