Skip to content

Commit

Permalink
Fixing links and finished plugin-audio-response-button
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhang03 committed Jun 13, 2024
1 parent 5c0fabb commit 485f1c4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-animation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type Info = typeof info;
* The participant is free to respond at any point during the animation, and the time of the response is recorded.
*
* @author Josh de Leeuw
* @see {@link https://www.jspsych.org/latest/plugins/jspsych-animation/ animation plugin documentation on jspsych.org}
* @see {@link https://www.jspsych.org/latest/plugins/animation/ animation plugin documentation on jspsych.org}
*/
class AnimationPlugin implements JsPsychPlugin<Info> {
static info = info;
Expand Down
97 changes: 62 additions & 35 deletions packages/plugin-audio-button-response/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,106 +1,133 @@
import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";

import { version } from "../package.json";

const info = <const>{
name: "audio-button-response",
version: version,
parameters: {
/** The audio to be played. */
/** Path to audio file to be played. */
stimulus: {
type: ParameterType.AUDIO,
pretty_name: "Stimulus",
default: undefined,
},
/** Array containing the label(s) for the button(s). */
/** Labels for the buttons. Each different string in the array will generate a different button. */
choices: {
type: ParameterType.STRING,
pretty_name: "Choices",
default: undefined,
array: true,
},
/**
* A function that, given a choice and its index, returns the HTML string of that choice's
* button.
* A function that generates the HTML for each button in the `choices` array. The function gets the string
* and index of the item in the `choices` array and should return valid HTML. If you want to use different
* markup for each button, you can do that by using a conditional on either parameter. The default parameter
* returns a button element with the text label of the choice.
*/
button_html: {
type: ParameterType.FUNCTION,
pretty_name: "Button HTML",
default: function (choice: string, choice_index: number) {
return `<button class="jspsych-btn">${choice}</button>`;
},
},
/** Any content here will be displayed below the stimulus. */
/** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention
* is that it can be used to provide a reminder about the action the participant is supposed to take
* (e.g., which key to press). */
prompt: {
type: ParameterType.HTML_STRING,
pretty_name: "Prompt",
default: null,
},
/** The maximum duration to wait for a response. */
/** How long to wait for the participant to make a response before ending the trial in milliseconds. If the
* participant fails to make a response before this timer is reached, the participant'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 */
trial_duration: {
type: ParameterType.INT,
pretty_name: "Trial duration",
default: null,
},
/** The CSS layout for the buttons. Options: 'flex' or 'grid'. */
/** Setting to `'grid'` will make the container element have the CSS property `display: grid` and enable the
* use of `grid_rows` and `grid_columns`. Setting to `'flex'` will make the container element have the CSS
* property `display: flex`. You can customize how the buttons are laid out by adding inline CSS in the `button_html` parameter.
*/
button_layout: {
type: ParameterType.STRING,
pretty_name: "Button layout",
default: "grid",
},
/** The number of grid rows when `button_layout` is "grid".
* Setting to `null` will infer the number of rows based on the
* number of columns and buttons.
/** The number of rows in the button grid. Only applicable when `button_layout` is set to `'grid'`. If null, the
* number of rows will be determined automatically based on the number of buttons and the number of columns.
*/
grid_rows: {
type: ParameterType.INT,
pretty_name: "Grid rows",
default: 1,
},
/** The number of grid columns when `button_layout` is "grid".
* Setting to `null` (default value) will infer the number of columns
* based on the number of rows and buttons. */
/** The number of columns in the button grid. Only applicable when `button_layout` is set to `'grid'`.
* If null, the number of columns will be determined automatically based on the number of buttons and the
* number of rows.
*/
grid_columns: {
type: ParameterType.INT,
pretty_name: "Grid columns",
default: null,
},
/** If true, the trial will end when user makes a response. */
/** If true, then the trial will end whenever the participant 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 `trial_duration` is reached. You can set this parameter to `false` to force
* the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete. */
response_ends_trial: {
type: ParameterType.BOOL,
pretty_name: "Response ends trial",
default: true,
},
/** If true, then the trial will end as soon as the audio file finishes playing. */
/** If true, then the trial will end as soon as the audio file finishes playing. */
trial_ends_after_audio: {
type: ParameterType.BOOL,
pretty_name: "Trial ends after audio",
default: false,
},
/**
* If true, then responses are allowed while the audio is playing.
* If false, then the audio must finish playing before a response is accepted.
* If true, then responses are allowed while the audio is playing. If false, then the audio must finish
* playing before the button choices are enabled and a response is accepted. Once the audio has played
* all the way through, the buttons are enabled and a response is allowed (including while the audio is
* being re-played via on-screen playback controls).
*/
response_allowed_while_playing: {
type: ParameterType.BOOL,
pretty_name: "Response allowed while playing",
default: true,
},
/** The delay of enabling button */
/** How long the button will delay enabling in milliseconds. If `response_allowed_while_playing` is `true`,
* the timer will start immediately. If it is `false`, the timer will start at the end of the audio. */
enable_button_after: {
type: ParameterType.INT,
pretty_name: "Enable button after",
default: 0,
},
},
data: {
/** The response time in milliseconds for the participant to make a response. The time is measured from
* when the stimulus first began playing until the participant's response.*/
rt: {
type: ParameterType.INT,
},
/** Indicates which button the participant pressed. The first button in the `choices` array is 0, the second is 1, and so on. */
response: {
type: ParameterType.INT,
},
},
};

type Info = typeof info;

/**
* **audio-button-response**
*
* jsPsych plugin for playing an audio file and getting a button response
*
* 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 can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if
* you are using timeline variables or another dynamic method to specify the audio stimulus, you will need
* to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.
* The trial can end when the participant responds, when the audio file has finished playing, or if the participant
* has failed to respond within a fixed length of time. You can also prevent a button response from being made before the
* audio has finished playing.
*
* @author Kristin Diep
* @see {@link https://www.jspsych.org/plugins/jspsych-audio-button-response/ audio-button-response plugin documentation on jspsych.org}
* @see {@link https://www.jspsych.org/latest/plugins/audio-button-response/ audio-button-response plugin documentation on jspsych.org}
*/
class AudioButtonResponsePlugin implements JsPsychPlugin<Info> {
static info = info;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-html-keyboard-response/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type Info = typeof info;
* The trial can be ended automatically if the participant has failed to respond within a fixed length of time.
*
* @author Josh de Leeuw
* @see {@link https://www.jspsych.org/latest/plugins/jspsych-html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}
* @see {@link https://www.jspsych.org/latest/plugins/html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}
*/
class HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {
static info = info;
Expand Down

0 comments on commit 485f1c4

Please sign in to comment.