diff --git a/README.md b/README.md index fae61f9..bc32eed 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,17 @@ Some plugins developed at dBSPLab for jsPsych 6. Mostly they concern audio prese Three versions of jsPsych are supported: 6.1, 6.2 and 6.3. We use branches to maintain the different versions. + +## Plugins + +We've implemented some generic methods for audio testing with jsPsych: + +* A plugin to do alternative forced choice with sounds: [jspsych-audio-sequence-button-response](docs/jspsych-audio-sequence-button-response.md). +* A plugin to do extend `audio-keyboard-response`: [jspsych-audio-keyboard-response-wait](docs/jspsych-audio-keyboard-response-wait.md). +* A plugin to display a Coordinate Response Measure interface: [jspsych-crm](docs/jspsych-crm.md). +* A plugin to do display a loading spinner while waiting for a (possible async) function to complete: [jspsych-waitfor-function](docs/jspsych-waitfor-function.md). + +## Tools + +* A function that generates timelines for adaptive testing using a nAFC interface: [jspsych-nafc-adaptive](docs/jspsych-nafc-adaptive.md). +* In `js/tools.js`, some globally useful functions are available. diff --git a/docs/jspsych-audio-keyboard-response-wait.md b/docs/jspsych-audio-keyboard-response-wait.md new file mode 100644 index 0000000..6230304 --- /dev/null +++ b/docs/jspsych-audio-keyboard-response-wait.md @@ -0,0 +1,50 @@ +# jspsych-audio-keyboard-response-wait + +This plugin is similar to [jspsych-audio-keyboard-response](https://www.jspsych.org/plugins/jspsych-audio-keyboard-response/), but allows more control on when the trial stops. + +This plugin plays audio files and records responses generated with the keyboard. + +If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio. + +Audio files are automatically preloaded by jsPsych. However, if you are using timeline variables or another dynamic method to specify the audio stimulus you will need to [manually preload](https://www.jspsych.org/overview/media-preloading/#manual-preloading) the audio. + +The trial can end when the subject responds, when the audio file has finished playing, or if the subject has failed to respond within a fixed length of time. In addition, the trial can end after the subject has responded *and* the audio file has finished playing if you want to make sure the subject always hears the stimulus completely. Once the subject pressed a key, following key presses are not registered anymore. It is possible to dim the interface to signify this to the participant. + +## Parameters + +Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable. + +Parameter | Type | Default Value | Description +----------------|-------------------|---------------|------------ +stimulus | string (audio) | undefined | The audio to be played. +choices | array of keycodes | ALL_KEYS | The keys the subject is allowed to press to respond to the stimulus. +prompt | string | null | This string can contain HTML markup. The intention is that it can be used to provide a reminder about the action the subject is supposed to take. +trial_duration | numeric | null | How long to wait for the subject to make a response before ending the trial, in milliseconds. If the subject fails to make a response before this timer is reached, the subject's response will be recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial will wait for a response indefinitely. +response_ends_trial | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until another condition ends the trial (either `trial_duration` or `trials_ends_after_audio`, but see `wait_for_audio`). +trial_ends_after_audio | boolean | false | If true, then the trial will end as soon as the audio file finishes playing. +wait_for_audio | boolean | false | If `response_ends_trial` is true, this will still wait for the audio to end before ending the trial. +dim_content_after_response | boolean | false | Will dim the content once the response has been given (a key has been pressed). +## Data Generated + +In addition to the [default data collected by all plugins](overview#data-collected-by-plugins), this plugin collects the following data for each trial. + +Name | Type | Value +-----|------|------ +key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response. +rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response. +stimulus | string | Path to the audio file that played during the trial. + +## Example + +#### Plays a sound, and keeps playing until the end of the sound even if a response was given + +```javascript +var trial = { + type: 'audio-keyboard-response-wait', + stimulus: 'sound/tone.mp3', + choices: ['e', 'i'], + prompt: "
Is the pitch high or low? Press 'e' for low and 'i' for high.
", + response_ends_trial: true. + wait_for_audio: true +}; +``` diff --git a/docs/jspsych-audio-sequence-button-response.md b/docs/jspsych-audio-sequence-button-response.md new file mode 100644 index 0000000..7690171 --- /dev/null +++ b/docs/jspsych-audio-sequence-button-response.md @@ -0,0 +1,82 @@ +# jspsych-audio-sequence-button-response + +This plugin plays a sequence of audio files, highlighting answer buttons as they are played. + +This plugin is based on [jspsych-audio-button-response](https://www.jspsych.org/plugins/jspsych-audio-button-response/). + +Audio files are automatically preloaded by jsPsych. However, if you are using timeline variables or another dynamic method to specify the audio stimulus you will need to manually preload the audio. + +The trial can end when the subject responds, when the audio file has finished playing, or if the subject has failed to respond within a fixed length of time. + +Note that the buttons are disabled during playing so the subject cannot press any button during that time. + +## Parameters + +Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable. + +Parameter | Type | Default Value | Description +----------------|------------------|---------------|------------ +stimuli | array of strings | undefined | An array listing the path (url) to the audio files to be played. +choices | array of strings | [] | Labels for the buttons. Each different string in the array will generate a different button. It is not absolutely mandatory, but it is probably a good idea to have this being the same length as `stimuli`. +button_html | HTML string | `''` | A template of HTML for generating the button elements. You can override this to create customized buttons of various kinds. The string `%choice%` will be changed to the corresponding element of the `choices` array. You may also specify an array of strings, if you need different HTML to render for each button. If you do specify an array, the `choices` array and this array must have the same length. The HTML from position 0 in the `button_html` array will be used to create the button for element 0 in the `choices` array, and so on. +prompt | string | null | This string can contain HTML markup. Any content here will be displayed below or above the stimulus (see `prompt_position`). The intention is that it can be used to provide a reminder about the action the subject is supposed to take. +prompt_position | string | `'bottom'` | The position of the prompt: `'bottom'` or `'above'`. +isi | numeric | 0 | Inter-stimulus-interval: The delay in between stimulus presentation (in ms). +trial_duration | numeric | null | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the subject's response will be recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial will wait for a response indefinitely. +margin_vertical | string | `'0px'` | Vertical margin of the button(s). +margin_horizontal | string | `'8px'` | Horizontal margin of the button(s). +response_ends_trial | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete. +trial_ends_after_audio | boolean | false | If true, then the trial will end as soon as the audio file finishes playing. +visual_feedback | boolean | false | If true, provides feedback after the subject gave their answer. If this is set to true, `i_correct` has to be also specified. +i_correct | numeric | null | The index of the choice that corresponds to the correct answer (for feedback, otherwise it is optional). + +## Data Generated + +In addition to the [default data collected by all plugins](https://www.jspsych.org/plugins/overview/#data-collected-by-plugins), this plugin collects the following data for each trial. + +Name | Type | Value +-----|------|------ +rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response. +stimuli | array of strings | The list of stimuli that was passed as parameter (just for convenience). +button_pressed | numeric | Indicates which button the subject pressed. The first button in the `choices` array is 0, the second is 1, and so on. + +## Styling elements + +### IDs + +id | Description +-------------------------------------------|------------------------------------ +`jspsych-audio-sequence-button-response-#` | Where `#` is the index of the choice. This is the div that is wrapping each response button (not the button itself). + + +### CSS Classes + +Class | Description +-------------------------------------------|------------------------------------ +jspsych-audio-button-response-btngroup | The `` that contains the prompt. +highlighted | The button inside the `
Which one is different from the two others?
" +}; +``` diff --git a/docs/jspsych-crm.md b/docs/jspsych-crm.md new file mode 100644 index 0000000..2b63f26 --- /dev/null +++ b/docs/jspsych-crm.md @@ -0,0 +1,84 @@ +# jspsych-crm + +This plugin displays an interface for the Coordinate Response Measure [(Bolia _et al._, 2000)](https://doi.org/10.1121/1.428288). The interface is a grid where +each row corresponds to a color and each column corresponds to a number. The participants hear a sound and then can click on one of the cells to give their response. + +The trial can end when the subject responds, when the audio file has finished playing, or if the subject has failed to respond within a fixed length of time. + +Note that the buttons are disabled during playing so the subject cannot press any button during that time. + +## Parameters + +Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable. + +Parameter | Type | Default Value | Description +----------------|------------------|---------------|------------ +stimulus | string | undefined | The path (url) to the audio file to play. +colors | array of strings | undefined | Labels for the rows. +numbers | array | undefined | Labels for the columns (can be strings or plain numbers). +prompt | string | null | This string can contain HTML markup. Any content here will be displayed above the response grid. The intention is that it can be used to provide a reminder about the action the subject is supposed to take. +trial_duration | numeric | null | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the subject's response will be recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial will wait for a response indefinitely. +response_ends_trial | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `trial_duration` parameter). +trial_ends_after_audio | boolean | false | If true, then the trial will end as soon as the audio file finishes playing. +visual_feedback | boolean | false | If true, provides feedback after the subject gave their answer. Visual feedback automatically ends the trial. +correct | object | undefined | An object containing the correct color and number (used to calculate the score and to provide feedback). +color_values | object | null | An object with keys corresponding to the `colors`, and containing a valid CSS color description. If left to `null`, some default colors are used (see below). +text_color_values | object | 'auto' | Same as `color_values` but for the text color of the cells. `'auto'` (the default) means that the text color is either black or white depending on the computed luminance of the background. + +Default color values: + +```javascript +color_values = { + red: "#ff3333", + blue: "#6b6bff", + green: "#80ee59", + yellow: "#ffe534", + pink: "#ff57df", + purple: "#a522ff", + brown: "#7a5630", + black: "#22222", + white: "#fcfcfc", + grey: "#8c8c8c", + gray: "#8c8c8c" +}; +``` + +## Data Generated + +In addition to the [default data collected by all plugins](https://www.jspsych.org/plugins/overview/#data-collected-by-plugins), this plugin collects the following data for each trial. + +Name | Type | Value +---------|----------|------ +rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response. +stimulus | string | The stimulus that was passed as parameter (just for convenience). +response_color | string | Indicate which color was selected by the participant. `null` if not response was given. +response_number | string | Indicate which number was selected by the participant. `null` if not response was given. +correct_color | string | Indicate which color was the correct one (from `trial.correct`). +correct_number | string | Indicate which number was the correct one (from `trial.correct`). + +## Styling elements + +### IDs + +id | Description +---------------------------------|------------------------------------ +`jspsych-crm-buttons-container` | The `