####################################################################### mapper -- X11/OpenGL stimulus program for Mac OS X and Linux ####################################################################### Mapper (X11/OpenGL application) -- Summer 2022 ========================================================== Linux black screen FIXED on CentOS7/Ubuntu18.04 (sorry!) ========================================================== Written by Martin Sereno (msereno@sdsu.edu or msereno@ucsd.edu), 2001-present, at UCSD, UCL/Birkbeck, and SDSU. Original C/IrixGL code for polar/eccen checkerboard, low-contrast moving vs. stationary rings, and coherent vs. incoherent flow fields by Anders Dale (1996). Coherent polar dot wedge on dot background by Don Hagler. This program generates a large number of different phase-encoded and block design stimuli for fMRI mapping, including visual, auditory, somatomotor, and linguistic stimuli. It records time-stamped keyboard responses (keys 0-9). On Mac, it reads and produces TTL pulses (1-32 bits, via USB-DIO-32 ACCES TTL<->USB box attached to a USB port using includes loader/driver (libusb port in progress). Finally, it can read ASCII scenario files for completely arbitrary experimental designs (see below). Most text-displaying options can read/display UTF-8 (multi-byte) characters (e.g., Chinese). The main program (a standalone binary, 'mapper') requires at minimum, a single initial numerical argument indicating the stimulus type: use: mapper -stimtype [opts...] N.B.: On Mac, this is designed to work from an xterm in XQuartz.app "Full-screen mode" (esc kills stim). To kill mapper accidentally started from Terminal in rootless mode unkillable by esc, click around to make the mouse re-appear, open an xterm or a Terminal, and then do 'killall mapper'. Several Mac programs (e.g., Safari) can cause XQuartz to flip back to the Mac screen from fullscreen X11 to 'helpfully' interrupt you with some important news. Simply close down other running programs before starting mapper. Tested on: MacOS 10.6 - 10.15 CentOS 5.9 - 7.6 Ubuntu 12.04 - 20.04 Recent fixes (Mar-May 2022): Mac: added fxload (USB) in case AccesLoader fails Ubuntu: no longer need to install jpeg lib CentOS 7: fixed black screen no stim display Ubuntu 18.04/20.04: fixed mmap doesn't start Ubuntu/CentOS: if motion jerky, first do: export __GL_SYNC_TO_VBLANK=0 ================================================================== Basic self-unpacking distribution, mmap ================================================================== A basic set of stimuli can be run using the all-in-one self-unpacking binary, mmap, which is included in: SelfUnpackMappingLinux64.zip SelfUnpackMappingMac.zip After unzipping the Linux or Mac version, here is a quick example summary of how to use it to run the V6 localizer stimulus: cd ./mmap rotdil32 F1 # start F2 # reset to wait Esc # kill The stimuli all run forever until you hit Esc. See the included README.txt file for more details on how to change parameters. On Ubuntu/CentOS, if the motion stimuli don't seem to move smoothly, try the following (bash) shell command before running mmap: export __GL_SYNC_TO_VBLANK=0 ================================================================== Install full binary distribution ================================================================== The binary package can be installed anywhere. Compiled and tested on Mac OS X (10.6 to 10.15 -- ppc, i386, x86_64, and arm64 w/Rosetta2), and Linux (RedHat 9 to Fedora 30, CentOS 4 to 7, Ubuntu 12 to 18 -- i386 and x86_64). The mapper program uses external *.ttf or *.ttc font files (several are included if system ttf's are not in their usual locations). It requires that the standard X utility, xdpyinfo, be on the users's path (for determining screen dimensions). ### install, run mapper in user's home directory (tarfiles in /tmp) [download mapper-YYMMDD.tgz to ~/Downloads] cd ~ tar xvfz ~/Downloads/mapper-YYMMDD.tgz cd mapper source MapperEnv.sh (or source MapperEnv.csh) allscripts (or mapper w/args, or included script, e.g., pol1) ### install additional 0.5G lib images, sounds (into installation above) cd ~/mapper/lib tar xvfz /tmp/libsndimg.tgz ### Mac: you must un-quarantine the new mapper directory! sudo xattr -r -d com.apple.quarantine ~/mapper ================================================================== Path/environment setup script ================================================================== The mapper program (./bin//mapper) can be run directly from the command line without any changes to path or environment. To run the mapper script tk interface, allscripts, first set up the environment by source'ing the environment setup script, MapperEnv.csh or MapperEnv.sh (see examples below). This puts proper architecture mapper binary and $MAPPER_DIR/lib/scripts on your path, and sets up environment to run included X11 tcl/tk -- useful esp. on Mac because native Mac OS X tk: (1) is not X11, (2) so won't work in X11 fullscreen, (3) so can't get rid of menubar. To run MapperEnv.sh (or MapperEnv.csh), cd to directory it is in, and type "source MapperEnv.sh" (or "source MapperEnv.csh"). OK to anywhere afterward. Here is how to make alias to do this: In sh/bash: alias ma='pushd ; source MapperEnv.sh; popd' or in csh/tcsh: alias ma "pushd ; source MapperEnv.csh; popd" The alias method is non-invasive since it only affects the current shell (as opposed to sourcing the MapperEnv script in .bashrc or .cshrc, which would affect every new shell). If mapper cannot find one of the shared libraries it requires, you will get a message like this: Darwin dyld: Library not loaded: ... ..dylib Referenced from: /Users//mapper/bin/Darwin-ppc/./mapper Reason: image not found Trace/BPT trap Linux mapper: error while loading shared libraries: lib.so.: cannot open shared object file: No such file or directory To avoid this, several key libraries are statically compiled. On Mac OS X 10.8+, after setting up paths, since DYLD_LIBRARY_PATH has been set (for X11 tcl/tk), you may get a harmless error that DYLD_LIBRARY_PATH will be ignored for a setuid program. Note that mapper is *not* a setuid program. MapperEnv.sh (or MapperEnv.csh) and allscripts work in sh/bash (or csh/tcsh). If the environment setup scripts somehow fail or you don't want to use them, simply put the appropriate architecture mapper binary and the scripts dir on your $path (or $PATH). ================================================================== Documentation and right-click pop-up help ================================================================== The most compact documentation is the (overly) long usage message from: mapper There are over 300 command line options. To get a minimal helpfile: mapper > help.txt To search for a particular option: mapper | grep All stimtypes (over 100, listed at top of usage message) should work without any additional options. For example: mapper -stimtype 10 To print out the default values for every option for a given stimtype: mapper -stimtype -printdefs To search for the default value of a particular option, type: mapper -stimtype -printdefs | grep To get a help pop-up window for a particular stimulus num, use: helpstim Starting allscripts from the command line puts up a mapper runner window with about 300 buttons, each of which runs one of the scripts in $MAPPER_DIR/lib/scripts (see below for how to configure which allscripts buttons appear). You get the same help pop-up's just mentioned above upon right-clicking a script button in allscripts (see below). There are about 500 mapper scripts in $MAPPER_DIR/lib/scripts that illustrate the relevant options for each stimtype. There is also a NOTES.txt file in lib/scripts and code update details in UPDATES.txt in $MAPPER_DIR. To interactively fiddle with mapper options, open allscripts, then middle-click a button to get a panel of editable parameters (with a "testrun mapper" button at the top). A text editor is also started so that the same script can be edited to save modified parameters. For clarity, all scripts have one option per back-slashed line. Be sure to avoid inserting any extra invisible spaces after a backslash when editing, which will disable the line-continuation effect of the backslash! Some printed default values for a stimtype may not be relevant (change -> no effect). If -logfile is specified (auto-turned on for many scripts), a logfile with a date-and-time filename is written into the directory, ./logs, containing the complete command line used to start mapper, and then time-stamped stimulus events and key responses (0-9 keys). ================================================================== Using arbitrary scenario files ================================================================== For arbitrary block design experiments, use stimtype 60, which reads an extended version of Hillyard/Kutas VVSP format text scenario files (see mapper usage for syntax) to position, scale, and display text (including character strings in UTF8 fonts accessed via decimal or hex codepoints), tiffs and colored rectangles, play sounds, emit TTL byte codes or single TTL bits (via ACCES USB<->TTL box on Mac), and to log stimulus and keypress events, and TTL responses (on Mac). Images are preloaded into memory (repeated images with same filename use no additional memory) for exact timing (within one video frame for reasonable numbers of simultaneous images and text strings per individual video frame). 8G of RAM can hold over 25,000 unique 320x240 color images. See below for more details. ================================================================== File name conventions ================================================================== User-created experiment-specific image, sound, and word files can be accessed from anywhere, but most conveniently from user-created subdirectories of: $MAPPER_DIR/lib/imagefiles $MAPPER_DIR/lib/soundfiles $MAPPER_DIR/lib/wordfiles For example, a user could create a new directory: $MAPPER_DIR/lib/imagefiles/expt3 and place a set of tiff images inside of it. To make mapper use these images, then simply use the option: -tiffdir expt3 To use tiffs from a directory in a different/arbitrary location, specify an explicit full path (starting with a '/') or an explicit relative path (starting with a '.'), for example: -tiffdir /Users/marty/expt3 # full (absolute) path -tiffdir ./expt3 # or: curr directory (where mapper runs) Many stimtypes load and use all tiffs found in the specified -tiffdir. However, sometimes it is necessary to refer to an individual image file (e.g., in an rgb= line in stimtype 60). In this case, a bare filename (e.g., image1.tiff) will refer to a file in the current -tiffdir. But a full path (starting with a '/') or an explicit relative path (starting with a '.') can also be used, which will override -tiffdir (or make it unncessary). The same filename rules apply to -sndfiledir and soundfiles, and -worddir and wordfiles. ================================================================== Modifying which buttons/scripts "allscripts" shows ================================================================== By default, allscripts shows a large number of script buttons (over 300). To change which script buttons appear (e.g., to omit buttons, or to add new ones), pass allscripts an ASCII file (e.g., mybuttons.txt) containing rows of buttons to show: allscripts mybuttons.txt The first line must start with "# allscripts button config". The following lines should contain space- or tab-separated script names for each row of buttons in the interface. For example, to show three rows of buttons, two per row, use a file like this: # allscripts button config ecc1 ecc2 pol1 pol2 rotdil32 rotdil32b To add bold titles for each row, end the first entry in a row with a colon: # allscripts button config eccen: ecc1 ecc2 polar: pol1 pol2 flow: rotdil32 rotdil32b or use an initial "" to get an indented, title-less row: # allscripts button config map: ecc1 ecc2 "" pol1 pol2 flow: rotdil32 rotdil32b To make this the default, edit the (long) $scriptsets variable in allscripts, which specifies each line of widgets. The giant default config is saved in allscripts.defconfig ================================================================== Mac OS X specifics ================================================================== This program requires X11. Since X11.app no longer ships with Mac OS X starting from version 10.7, download XQuartz.app and do a default install (tested on XQuartz.app 2.7.3 to 2.7.8 on Mac OS X 10.4 to 10.12). Makefile now looks in /opt/X11 for include, lib. For final stimulus presentation, run the mapper program from an xterm window in full screen mode (X11->preferences->Output, click fullscreen). This removes the menu bar, and running from xterm makes it easier to kill than when running from Terminal. The command for toggling between fullscreen X11 and the Mac desktop (cmd-option-A) is worth writing down. Fullscreen fails in 10.5.1 to 10.5.6 (menu bar won't go away; see instructions below for how to install OS X 10.4 X11.app to fix this). The precompiled Mac mapper x86_64 binaries work from 10.6 up. Soundfiles are played using afplay. On 10.4, this needs to be compiled with XCode and put into $MAPPER_DIR/bin/Darwin-i386. In 10.5 and up, it will be present as /usr/bin/afplay. To make quick-and-dirty soundfiles on the Mac, select text in TextEdit, do shift-cmd-R (equals: TextEdit->Services->Add to iTunes as Spoken), and then drag-drop m4a's out of iTunes into lib/soundfiles/. Mac mapper has compiled-in support for TTL I/O through USB via a USB-DIO-32 ACCES TTL<->USB box (see ./AccesUSB dir): http://www.accesio.com/go.cgi?p=../usb/usb-dio-32.html This requires using the -loadaccesdev option or running AccesLoader once (pre-compiled binaries and source are included) before using the USB-DIO-32 box. Included scripts ('run' or 'loadUSB', automatically called when using the script runner, 'allscripts') test if the Acces loader needs to be run and run it only if needed. ACCES provides some Linux support, but that is not yet included here. In the future, unified Darwin/Linux ACCES support should be provided via libusb (TODO). An alternate USB method of starting a stim is option -fivekeytrigger This will cause a USB keyboard '5' keypress to start the stimulus. After the stimulus has started, any additional '5' keypress will be logged as a response (N.B.: subject must not press '5' before start :-} ). Starting with Mac OS X 10.11, the environment variable DYLD_LIBRARY_PATH is no longer passed to subshells. To get allscripts to use X11 tk (instead of native Mac tk), allscripts is started with: #! /bin/sh # next line not seen by tcl upon reentry by exec \ DYLD_LIBRARY_PATH=$MAPPER_LIBRARY_PATH exec wish8.5 $0 -- ${1+"$@"} This requires that MAPPER_LIBRARY_PATH is defined -- usu. done by MapperEnv.{c}sh. ================================================================== Linux specifics ================================================================== Linux OpenGL performance will likely be inadequate in a virtual machine or with the xorg nv driver (use nvidia driver from nvidia.com). Also, many stims need working wait-for-top-of-frame function, which must be enabled in Linux Nvidia and ATi drivers as follows: Nvidia glx: setenv __GL_SYNC_TO_VBLANK 1 # 0 better on CentOS7! ATi fglrx: xorg.conf: Option "Capabilities" "0x00000000" # user must do Soundfiles are played with "play" (sox). To use a different program, use -sndprog . It will be called as: & To use Mac-created *.m4a soundfiles on Linux, first convert to aiff (or wav) in iTunes: 1) iTunes -> Preferences -> ImportSettings -> AIFF Encoder 2) ctrl-click m4a in iTunes -> Create AIFF version 3) [put back your original encoder!] 4) drag-drop *.aif's it out of iTunes ================================================================== Compile source distribution ================================================================== If you want to re-compile (e.g., to modify) mapper, the local external libraries (libtiff, freetype, ftgl, all statically linked) and X11 tcl/tk/tix 8.5 (used by the script runner, allscripts) also need to be recompiled once. The source for everything is included in mappersrc-YYMMDD.tgz. Use the sh (or csh) script, mk0 (or mk0.csh) as follows. ### compile all required libraries, then mapper tar xvfz /tmp/mappersrc-YYMMDD.tgz cd mappersrc ./mk0 onearch ### edit mapper, recompile/re-link just mapper vi mapper.c [see instructions for add stimtype at top of mapper.c] ./mk0 mapper ### run recompiled mapper from the source distribution: source MapperEnv.csh (or source MapperEnv.sh) allscripts (or "mapper -s [opts ...]", or