@jspsych/plugin-audio-button-response 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nconst info = <const>{\n name: \"audio-button-response\",\n parameters: {\n /** The audio to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n pretty_name: \"Stimulus\",\n default: undefined,\n },\n /** Array containing the label(s) for the button(s). */\n choices: {\n type: ParameterType.STRING,\n pretty_name: \"Choices\",\n default: undefined,\n array: true,\n },\n /** The HTML for creating button. Can create own style. Use the \"%choice%\" string to indicate where the label from the choices parameter should be inserted. */\n button_html: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Button HTML\",\n default: '<button class=\"jspsych-btn\">%choice%</button>',\n array: true,\n },\n /** Any content here will be displayed below the stimulus. */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: null,\n },\n /** The maximum duration to wait for a response. */\n trial_duration: {\n type: ParameterType.INT,\n pretty_name: \"Trial duration\",\n default: null,\n },\n /** Vertical margin of button. */\n margin_vertical: {\n type: ParameterType.STRING,\n pretty_name: \"Margin vertical\",\n default: \"0px\",\n },\n /** Horizontal margin of button. */\n margin_horizontal: {\n type: ParameterType.STRING,\n pretty_name: \"Margin horizontal\",\n default: \"8px\",\n },\n /** If true, the trial will end when user makes a response. */\n response_ends_trial: {\n type: ParameterType.BOOL,\n pretty_name: \"Response ends trial\",\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n pretty_name: \"Trial ends after audio\",\n default: false,\n },\n /**\n * If true, then responses are allowed while the audio is playing.\n * If false, then the audio must finish playing before a response is accepted.\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n pretty_name: \"Response allowed while playing\",\n default: true,\n },\n /** The delay of enabling button */\n enable_button_after: {\n type: ParameterType.INT,\n pretty_name: \"Enable button after\",\n default: 0,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **audio-button-response**\n *\n * jsPsych plugin for playing an audio file and getting a button response\n *\n * @author Kristin Diep\n * @see {@link https://www.jspsych.org/plugins/jspsych-audio-button-response/ audio-button-response plugin documentation on jspsych.org}\n */\nclass AudioButtonResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n // hold the .resolve() function from the Promise that ends the trial\n let trial_complete;\n\n // setup stimulus\n var context = this.jsPsych.pluginAPI.audioContext();\n\n // store response\n var response = {\n rt: null,\n button: null,\n };\n\n // record webaudio context start time\n var startTime;\n\n // load audio file\n this.jsPsych.pluginAPI\n .getAudioBuffer(trial.stimulus)\n .then((buffer) => {\n if (context !== null) {\n this.audio = context.createBufferSource();\n this.audio.buffer = buffer;\n this.audio.connect(context.destination);\n } else {\n this.audio = buffer;\n this.audio.currentTime = 0;\n }\n setupTrial();\n })\n .catch((err) => {\n console.error(\n `Failed to load audio file \"${trial.stimulus}\". Try checking the file path. We recommend using the preload plugin to load audio files.`\n );\n console.error(err);\n });\n\n const setupTrial = () => {\n // set up end event if trial needs it\n if (trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", end_trial);\n }\n\n // enable buttons after audio ends if necessary\n if (!trial.response_allowed_while_playing && !trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", enable_buttons);\n }\n\n //display buttons\n var buttons = [];\n if (Array.isArray(trial.button_html)) {\n if (trial.button_html.length == trial.choices.length) {\n buttons = trial.button_html;\n } else {\n console.error(\n \"Error in audio-button-response plugin. The length of the button_html array does not equal the length of the choices array\"\n );\n }\n } else {\n for (var i = 0; i < trial.choices.length; i++) {\n buttons.push(trial.button_html);\n }\n }\n\n var html = '<div id=\"jspsych-audio-button-response-btngroup\">';\n for (var i = 0; i < trial.choices.length; i++) {\n var str = buttons[i].replace(/%choice%/g, trial.choices[i]);\n html +=\n '<div class=\"jspsych-audio-button-response-button\" style=\"cursor: pointer; display: inline-block; margin:' +\n trial.margin_vertical +\n \" \" +\n trial.margin_horizontal +\n '\" id=\"jspsych-audio-button-response-button-' +\n i +\n '\" data-choice=\"' +\n i +\n '\">' +\n str +\n \"</div>\";\n }\n html += \"</div>\";\n\n //show prompt if there is one\n if (trial.prompt !== null) {\n html += trial.prompt;\n }\n\n display_element.innerHTML = html;\n\n if (trial.response_allowed_while_playing) {\n disable_buttons();\n enable_buttons();\n } else {\n disable_buttons();\n }\n\n // start time\n startTime = performance.now();\n\n // start audio\n if (context !== null) {\n startTime = context.currentTime;\n this.audio.start(startTime);\n } else {\n this.audio.play();\n }\n\n // end trial if time limit is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n end_trial();\n }, trial.trial_duration);\n }\n\n on_load();\n };\n\n // function to handle responses by the subject\n function after_response(choice) {\n // measure rt\n var endTime = performance.now();\n var rt = Math.round(endTime - startTime);\n if (context !== null) {\n endTime = context.currentTime;\n rt = Math.round((endTime - startTime) * 1000);\n }\n response.button = parseInt(choice);\n response.rt = rt;\n\n // disable all the buttons after a response\n disable_buttons();\n\n if (trial.response_ends_trial) {\n end_trial();\n }\n }\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n // remove end event listeners if they exist\n if (context !== null) {\n this.audio.stop();\n } else {\n this.audio.pause();\n }\n\n this.audio.removeEventListener(\"ended\", end_trial);\n this.audio.removeEventListener(\"ended\", enable_buttons);\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.button,\n };\n\n // clear the display\n display_element.innerHTML = \"\";\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n\n trial_complete();\n };\n\n const enable_buttons_with_delay = (delay: number) => {\n this.jsPsych.pluginAPI.setTimeout(enable_buttons_without_delay, delay);\n };\n\n function button_response(e) {\n var choice = e.currentTarget.getAttribute(\"data-choice\"); // don't use dataset for jsdom compatibility\n after_response(choice);\n }\n\n function disable_buttons() {\n var btns = document.querySelectorAll(\".jspsych-audio-button-response-button\");\n for (var i = 0; i < btns.length; i++) {\n var btn_el = btns[i].querySelector(\"button\");\n if (btn_el) {\n btn_el.disabled = true;\n }\n btns[i].removeEventListener(\"click\", button_response);\n }\n }\n\n function enable_buttons_without_delay() {\n var btns = document.querySelectorAll(\".jspsych-audio-button-response-button\");\n for (var i = 0; i < btns.length; i++) {\n var btn_el = btns[i].querySelector(\"button\");\n if (btn_el) {\n btn_el.disabled = false;\n }\n btns[i].addEventListener(\"click\", button_response);\n }\n }\n\n function enable_buttons() {\n if (trial.enable_button_after > 0) {\n enable_buttons_with_delay(trial.enable_button_after);\n } else {\n enable_buttons_without_delay();\n }\n }\n\n return new Promise((resolve) => {\n trial_complete = resolve;\n });\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt:\n this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true) +\n trial.enable_button_after,\n response: this.jsPsych.randomization.randomInt(0, trial.choices.length - 1),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(`div[data-choice=\"${data.response}\"] button`),\n data.rt\n );\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioButtonResponsePlugin;\n"],"names":["ParameterType"],"mappings":";;;;AAEA,MAAM,IAAI,GAAU;AAClB,IAAA,IAAI,EAAE,uBAAuB;AAC7B,IAAA,UAAU,EAAE;;AAEV,QAAA,QAAQ,EAAE;YACR,IAAI,EAAEA,qBAAa,CAAC,KAAK;AACzB,YAAA,WAAW,EAAE,UAAU;AACvB,YAAA,OAAO,EAAE,SAAS;AACnB,SAAA;;AAED,QAAA,OAAO,EAAE;YACP,IAAI,EAAEA,qBAAa,CAAC,MAAM;AAC1B,YAAA,WAAW,EAAE,SAAS;AACtB,YAAA,OAAO,EAAE,SAAS;AAClB,YAAA,KAAK,EAAE,IAAI;AACZ,SAAA;;AAED,QAAA,WAAW,EAAE;YACX,IAAI,EAAEA,qBAAa,CAAC,WAAW;AAC/B,YAAA,WAAW,EAAE,aAAa;AAC1B,YAAA,OAAO,EAAE,+CAA+C;AACxD,YAAA,KAAK,EAAE,IAAI;AACZ,SAAA;;AAED,QAAA,MAAM,EAAE;YACN,IAAI,EAAEA,qBAAa,CAAC,WAAW;AAC/B,YAAA,WAAW,EAAE,QAAQ;AACrB,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;;AAED,QAAA,cAAc,EAAE;YACd,IAAI,EAAEA,qBAAa,CAAC,GAAG;AACvB,YAAA,WAAW,EAAE,gBAAgB;AAC7B,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;;AAED,QAAA,eAAe,EAAE;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AAEO,IAAA,eAAe,CAAC,KAAsB,EAAE,kBAAkB,EAAE,aAAyB,EAAA;QAC3F,MAAM,IAAI,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;QAEpE,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;QAEzD,MAAM,OAAO,GAAG,MAAK;AACnB,YAAA,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE;gBACpB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAChC,eAAe,CAAC,aAAa,CAAC,oBAAoB,IAAI,CAAC,QAAQ,CAAW,SAAA,CAAA,CAAC,EAC3E,IAAI,CAAC,EAAE,CACR,CAAC;AACH,aAAA;AACH,SAAC,CAAC;QAEF,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,MAAK;AACtC,YAAA,aAAa,EAAE,CAAC;AAChB,YAAA,IAAI,CAAC,KAAK,CAAC,8BAA8B,EAAE;gBACzC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,aAAA;AAAM,iBAAA;AACL,gBAAA,OAAO,EAAE,CAAC;AACX,aAAA;AACH,SAAC,CAAC,CAAC;KACJ;;AArRM,yBAAI,CAAA,IAAA,GAAG,IAAI;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-button-response\",\n version: version,\n parameters: {\n /** Path to audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Labels for the buttons. Each different string in the array will generate a different button. */\n choices: {\n type: ParameterType.STRING,\n default: undefined,\n array: true,\n },\n /**\n * A function that generates the HTML for each button in the `choices` array. The function gets the string\n * and index of the item in the `choices` array and should return valid HTML. If you want to use different\n * markup for each button, you can do that by using a conditional on either parameter. The default parameter\n * returns a button element with the text label of the choice.\n */\n button_html: {\n type: ParameterType.FUNCTION,\n default: function (choice: string, choice_index: number) {\n return `<button class=\"jspsych-btn\">${choice}</button>`;\n },\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention\n * is that it can be used to provide a reminder about the action the participant is supposed to take\n * (e.g., which key to press). */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the\n * participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial\n * will wait for a response indefinitely */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** Setting to `'grid'` will make the container element have the CSS property `display: grid` and enable the\n * use of `grid_rows` and `grid_columns`. Setting to `'flex'` will make the container element have the CSS\n * property `display: flex`. You can customize how the buttons are laid out by adding inline CSS in the `button_html` parameter.\n */\n button_layout: {\n type: ParameterType.STRING,\n default: \"grid\",\n },\n /** The number of rows in the button grid. Only applicable when `button_layout` is set to `'grid'`. If null, the\n * number of rows will be determined automatically based on the number of buttons and the number of columns.\n */\n grid_rows: {\n type: ParameterType.INT,\n default: 1,\n },\n /** The number of columns in the button grid. Only applicable when `button_layout` is set to `'grid'`.\n * If null, the number of columns will be determined automatically based on the number of buttons and the\n * number of rows.\n */\n grid_columns: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can set this parameter to `false` to force\n * the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete. */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /**\n * If true, then responses are allowed while the audio is playing. If false, then the audio must finish\n * playing before the button choices are enabled and a response is accepted. Once the audio has played\n * all the way through, the buttons are enabled and a response is allowed (including while the audio is\n * being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** How long the button will delay enabling in milliseconds. If `response_allowed_while_playing` is `true`,\n * the timer will start immediately. If it is `false`, the timer will start at the end of the audio. */\n enable_button_after: {\n type: ParameterType.INT,\n default: 0,\n },\n },\n data: {\n /** The response time in milliseconds for the participant to make a response. The time is measured from\n * when the stimulus first began playing until the participant's response.*/\n rt: {\n type: ParameterType.INT,\n },\n /** Indicates which button the participant pressed. The first button in the `choices` array is 0, the second is 1, and so on. */\n response: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise \n * timing of the playback. The timing of responses generated is measured against the WebAudio specific clock, \n * improving the measurement of response times. If the browser does not support the WebAudio API, then the audio file is \n * played with HTML5 audio. \n\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if \n * you are using timeline variables or another dynamic method to specify the audio stimulus, you will need \n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n\n * The trial can end when the participant responds, when the audio file has finished playing, or if the participant \n * has failed to respond within a fixed length of time. You can also prevent a button response from being made before the \n * audio has finished playing.\n * \n * @author Kristin Diep\n * @see {@link https://www.jspsych.org/latest/plugins/audio-button-response/ audio-button-response plugin documentation on jspsych.org}\n */\nclass AudioButtonResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private params: TrialType<Info>;\n private buttonElements: HTMLElement[] = [];\n private display: HTMLElement;\n private response: { rt: number; button: number } = { rt: null, button: null };\n private context: AudioContext;\n private startTime: number;\n private trial_complete: (trial_data: { rt: number; stimulus: string; response: number }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n this.params = trial;\n this.display = display_element;\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n // set up end event if trial needs it\n if (trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable buttons after audio ends if necessary\n if (!trial.response_allowed_while_playing && !trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_buttons);\n }\n\n // Display buttons\n const buttonGroupElement = document.createElement(\"div\");\n buttonGroupElement.id = \"jspsych-audio-button-response-btngroup\";\n if (trial.button_layout === \"grid\") {\n buttonGroupElement.classList.add(\"jspsych-btn-group-grid\");\n if (trial.grid_rows === null && trial.grid_columns === null) {\n throw new Error(\n \"You cannot set `grid_rows` to `null` without providing a value for `grid_columns`.\"\n );\n }\n const n_cols =\n trial.grid_columns === null\n ? Math.ceil(trial.choices.length / trial.grid_rows)\n : trial.grid_columns;\n const n_rows =\n trial.grid_rows === null\n ? Math.ceil(trial.choices.length / trial.grid_columns)\n : trial.grid_rows;\n buttonGroupElement.style.gridTemplateColumns = `repeat(${n_cols}, 1fr)`;\n buttonGroupElement.style.gridTemplateRows = `repeat(${n_rows}, 1fr)`;\n } else if (trial.button_layout === \"flex\") {\n buttonGroupElement.classList.add(\"jspsych-btn-group-flex\");\n }\n\n for (const [choiceIndex, choice] of trial.choices.entries()) {\n buttonGroupElement.insertAdjacentHTML(\"beforeend\", trial.button_html(choice, choiceIndex));\n const buttonElement = buttonGroupElement.lastChild as HTMLElement;\n buttonElement.dataset.choice = choiceIndex.toString();\n buttonElement.addEventListener(\"click\", () => {\n this.after_response(choiceIndex);\n });\n this.buttonElements.push(buttonElement);\n }\n\n display_element.appendChild(buttonGroupElement);\n\n // Show prompt if there is one\n if (trial.prompt !== null) {\n display_element.insertAdjacentHTML(\"beforeend\", trial.prompt);\n }\n\n if (trial.response_allowed_while_playing) {\n if (trial.enable_button_after > 0) {\n this.disable_buttons();\n this.enable_buttons();\n }\n } else {\n this.disable_buttons();\n }\n\n // start time\n this.startTime = performance.now();\n\n // end trial if time limit is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, trial.trial_duration);\n }\n\n on_load();\n\n this.audio.play();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n private disable_buttons = () => {\n for (const button of this.buttonElements) {\n button.setAttribute(\"disabled\", \"disabled\");\n }\n };\n\n private enable_buttons_without_delay = () => {\n for (const button of this.buttonElements) {\n button.removeAttribute(\"disabled\");\n }\n };\n\n private enable_buttons_with_delay = (delay: number) => {\n this.jsPsych.pluginAPI.setTimeout(this.enable_buttons_without_delay, delay);\n };\n\n private enable_buttons() {\n if (this.params.enable_button_after > 0) {\n this.enable_buttons_with_delay(this.params.enable_button_after);\n } else {\n this.enable_buttons_without_delay();\n }\n }\n\n // function to handle responses by the subject\n private after_response = (choice) => {\n // measure rt\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.button = parseInt(choice);\n this.response.rt = rt;\n\n // disable all the buttons after a response\n this.disable_buttons();\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n }\n };\n\n // method to end trial when it is time\n private end_trial = () => {\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_buttons);\n\n // gather the data to store for the trial\n var trial_data = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n response: this.response.button,\n };\n\n // move on to the next trial\n this.trial_complete(trial_data);\n };\n\n async simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt:\n this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true) +\n trial.enable_button_after,\n response: this.jsPsych.randomization.randomInt(0, trial.choices.length - 1),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#jspsych-audio-button-response-btngroup [data-choice=\"${data.response}\"]`\n ),\n data.rt\n );\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioButtonResponsePlugin;\n"],"names":["version","ParameterType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,uBAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAEV,QAAU,EAAA;AAAA,MACR,MAAMC,qBAAc,CAAA,KAAA;AAAA,MACpB,OAAS,EAAA,KAAA,CAAA;AAAA,KACX;AAAA,IAEA,OAAS,EAAA;AAAA,MACP,MAAM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AI,IAAA,IAAA,CAAK,OAAO,IAAM,EAAA;AACpB,QAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;AAAA,UACrB,eAAgB,CAAA,aAAA;AAAA,YACd,yDAAyD,IAAK,CAAA,QAAA,CAAA,EAAA,CAAA;AAAA,WAChE;AAAA,UACA,IAAK,CAAA,EAAA;AAAA,SACP,CAAA;AAAA,OACF;AAAA,KACF,CAAA;AAEA,IAAK,IAAA,CAAA,KAAA,CAAM,eAAiB,EAAA,KAAA,EAAO,MAAM;AACvC,MAAc,aAAA,EAAA,CAAA;AACd,MAAI,IAAA,CAAC,MAAM,8BAAgC,EAAA;AACzC,QAAK,IAAA,CAAA,KAAA,CAAM,gBAAiB,CAAA,OAAA,EAAS,OAAO,CAAA,CAAA;AAAA,OACvC,MAAA;AACL,QAAQ,OAAA,EAAA,CAAA;AAAA,OACV;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAvOM,yBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,173 +1,255 @@
1
- import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
1
+ import { JsPsychPlugin, ParameterType, JsPsych, TrialType } from 'jspsych';
2
+
2
3
  declare const info: {
3
4
  readonly name: "audio-button-response";
5
+ readonly version: string;
4
6
  readonly parameters: {
5
- /** The audio to be played. */
7
+ /** Path to audio file to be played. */
6
8
  readonly stimulus: {
7
9
  readonly type: ParameterType.AUDIO;
8
- readonly pretty_name: "Stimulus";
9
10
  readonly default: any;
10
11
  };
11
- /** Array containing the label(s) for the button(s). */
12
+ /** Labels for the buttons. Each different string in the array will generate a different button. */
12
13
  readonly choices: {
13
14
  readonly type: ParameterType.STRING;
14
- readonly pretty_name: "Choices";
15
15
  readonly default: any;
16
16
  readonly array: true;
17
17
  };
18
- /** The HTML for creating button. Can create own style. Use the "%choice%" string to indicate where the label from the choices parameter should be inserted. */
18
+ /**
19
+ * A function that generates the HTML for each button in the `choices` array. The function gets the string
20
+ * and index of the item in the `choices` array and should return valid HTML. If you want to use different
21
+ * markup for each button, you can do that by using a conditional on either parameter. The default parameter
22
+ * returns a button element with the text label of the choice.
23
+ */
19
24
  readonly button_html: {
20
- readonly type: ParameterType.HTML_STRING;
21
- readonly pretty_name: "Button HTML";
22
- readonly default: "<button class=\"jspsych-btn\">%choice%</button>";
23
- readonly array: true;
25
+ readonly type: ParameterType.FUNCTION;
26
+ readonly default: (choice: string, choice_index: number) => string;
24
27
  };
25
- /** Any content here will be displayed below the stimulus. */
28
+ /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention
29
+ * is that it can be used to provide a reminder about the action the participant is supposed to take
30
+ * (e.g., which key to press). */
26
31
  readonly prompt: {
27
32
  readonly type: ParameterType.HTML_STRING;
28
- readonly pretty_name: "Prompt";
29
33
  readonly default: any;
30
34
  };
31
- /** The maximum duration to wait for a response. */
35
+ /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the
36
+ * participant fails to make a response before this timer is reached, the participant's response will be
37
+ * recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial
38
+ * will wait for a response indefinitely */
32
39
  readonly trial_duration: {
33
40
  readonly type: ParameterType.INT;
34
- readonly pretty_name: "Trial duration";
35
41
  readonly default: any;
36
42
  };
37
- /** Vertical margin of button. */
38
- readonly margin_vertical: {
43
+ /** Setting to `'grid'` will make the container element have the CSS property `display: grid` and enable the
44
+ * use of `grid_rows` and `grid_columns`. Setting to `'flex'` will make the container element have the CSS
45
+ * property `display: flex`. You can customize how the buttons are laid out by adding inline CSS in the `button_html` parameter.
46
+ */
47
+ readonly button_layout: {
39
48
  readonly type: ParameterType.STRING;
40
- readonly pretty_name: "Margin vertical";
41
- readonly default: "0px";
49
+ readonly default: "grid";
42
50
  };
43
- /** Horizontal margin of button. */
44
- readonly margin_horizontal: {
45
- readonly type: ParameterType.STRING;
46
- readonly pretty_name: "Margin horizontal";
47
- readonly default: "8px";
51
+ /** The number of rows in the button grid. Only applicable when `button_layout` is set to `'grid'`. If null, the
52
+ * number of rows will be determined automatically based on the number of buttons and the number of columns.
53
+ */
54
+ readonly grid_rows: {
55
+ readonly type: ParameterType.INT;
56
+ readonly default: 1;
57
+ };
58
+ /** The number of columns in the button grid. Only applicable when `button_layout` is set to `'grid'`.
59
+ * If null, the number of columns will be determined automatically based on the number of buttons and the
60
+ * number of rows.
61
+ */
62
+ readonly grid_columns: {
63
+ readonly type: ParameterType.INT;
64
+ readonly default: any;
48
65
  };
49
- /** If true, the trial will end when user makes a response. */
66
+ /** If true, then the trial will end whenever the participant makes a response (assuming they make their
67
+ * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will
68
+ * continue until the value for `trial_duration` is reached. You can set this parameter to `false` to force
69
+ * the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete. */
50
70
  readonly response_ends_trial: {
51
71
  readonly type: ParameterType.BOOL;
52
- readonly pretty_name: "Response ends trial";
53
72
  readonly default: true;
54
73
  };
55
- /** If true, then the trial will end as soon as the audio file finishes playing. */
74
+ /** If true, then the trial will end as soon as the audio file finishes playing. */
56
75
  readonly trial_ends_after_audio: {
57
76
  readonly type: ParameterType.BOOL;
58
- readonly pretty_name: "Trial ends after audio";
59
77
  readonly default: false;
60
78
  };
61
79
  /**
62
- * If true, then responses are allowed while the audio is playing.
63
- * If false, then the audio must finish playing before a response is accepted.
80
+ * If true, then responses are allowed while the audio is playing. If false, then the audio must finish
81
+ * playing before the button choices are enabled and a response is accepted. Once the audio has played
82
+ * all the way through, the buttons are enabled and a response is allowed (including while the audio is
83
+ * being re-played via on-screen playback controls).
64
84
  */
65
85
  readonly response_allowed_while_playing: {
66
86
  readonly type: ParameterType.BOOL;
67
- readonly pretty_name: "Response allowed while playing";
68
87
  readonly default: true;
69
88
  };
70
- /** The delay of enabling button */
89
+ /** How long the button will delay enabling in milliseconds. If `response_allowed_while_playing` is `true`,
90
+ * the timer will start immediately. If it is `false`, the timer will start at the end of the audio. */
71
91
  readonly enable_button_after: {
72
92
  readonly type: ParameterType.INT;
73
- readonly pretty_name: "Enable button after";
74
93
  readonly default: 0;
75
94
  };
76
95
  };
96
+ readonly data: {
97
+ /** The response time in milliseconds for the participant to make a response. The time is measured from
98
+ * when the stimulus first began playing until the participant's response.*/
99
+ readonly rt: {
100
+ readonly type: ParameterType.INT;
101
+ };
102
+ /** Indicates which button the participant pressed. The first button in the `choices` array is 0, the second is 1, and so on. */
103
+ readonly response: {
104
+ readonly type: ParameterType.INT;
105
+ };
106
+ };
77
107
  };
78
108
  type Info = typeof info;
79
109
  /**
80
- * **audio-button-response**
81
- *
82
- * jsPsych plugin for playing an audio file and getting a button response
110
+ * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise
111
+ * timing of the playback. The timing of responses generated is measured against the WebAudio specific clock,
112
+ * improving the measurement of response times. If the browser does not support the WebAudio API, then the audio file is
113
+ * played with HTML5 audio.
114
+
115
+ * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if
116
+ * you are using timeline variables or another dynamic method to specify the audio stimulus, you will need
117
+ * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.
118
+
119
+ * The trial can end when the participant responds, when the audio file has finished playing, or if the participant
120
+ * has failed to respond within a fixed length of time. You can also prevent a button response from being made before the
121
+ * audio has finished playing.
83
122
  *
84
123
  * @author Kristin Diep
85
- * @see {@link https://www.jspsych.org/plugins/jspsych-audio-button-response/ audio-button-response plugin documentation on jspsych.org}
124
+ * @see {@link https://www.jspsych.org/latest/plugins/audio-button-response/ audio-button-response plugin documentation on jspsych.org}
86
125
  */
87
126
  declare class AudioButtonResponsePlugin implements JsPsychPlugin<Info> {
88
127
  private jsPsych;
89
128
  static info: {
90
129
  readonly name: "audio-button-response";
130
+ readonly version: string;
91
131
  readonly parameters: {
92
- /** The audio to be played. */
132
+ /** Path to audio file to be played. */
93
133
  readonly stimulus: {
94
134
  readonly type: ParameterType.AUDIO;
95
- readonly pretty_name: "Stimulus";
96
135
  readonly default: any;
97
136
  };
98
- /** Array containing the label(s) for the button(s). */
137
+ /** Labels for the buttons. Each different string in the array will generate a different button. */
99
138
  readonly choices: {
100
139
  readonly type: ParameterType.STRING;
101
- readonly pretty_name: "Choices";
102
140
  readonly default: any;
103
141
  readonly array: true;
104
142
  };
105
- /** The HTML for creating button. Can create own style. Use the "%choice%" string to indicate where the label from the choices parameter should be inserted. */
143
+ /**
144
+ * A function that generates the HTML for each button in the `choices` array. The function gets the string
145
+ * and index of the item in the `choices` array and should return valid HTML. If you want to use different
146
+ * markup for each button, you can do that by using a conditional on either parameter. The default parameter
147
+ * returns a button element with the text label of the choice.
148
+ */
106
149
  readonly button_html: {
107
- readonly type: ParameterType.HTML_STRING;
108
- readonly pretty_name: "Button HTML";
109
- readonly default: "<button class=\"jspsych-btn\">%choice%</button>";
110
- readonly array: true;
150
+ readonly type: ParameterType.FUNCTION;
151
+ readonly default: (choice: string, choice_index: number) => string;
111
152
  };
112
- /** Any content here will be displayed below the stimulus. */
153
+ /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention
154
+ * is that it can be used to provide a reminder about the action the participant is supposed to take
155
+ * (e.g., which key to press). */
113
156
  readonly prompt: {
114
157
  readonly type: ParameterType.HTML_STRING;
115
- readonly pretty_name: "Prompt";
116
158
  readonly default: any;
117
159
  };
118
- /** The maximum duration to wait for a response. */
160
+ /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the
161
+ * participant fails to make a response before this timer is reached, the participant's response will be
162
+ * recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial
163
+ * will wait for a response indefinitely */
119
164
  readonly trial_duration: {
120
165
  readonly type: ParameterType.INT;
121
- readonly pretty_name: "Trial duration";
122
166
  readonly default: any;
123
167
  };
124
- /** Vertical margin of button. */
125
- readonly margin_vertical: {
168
+ /** Setting to `'grid'` will make the container element have the CSS property `display: grid` and enable the
169
+ * use of `grid_rows` and `grid_columns`. Setting to `'flex'` will make the container element have the CSS
170
+ * property `display: flex`. You can customize how the buttons are laid out by adding inline CSS in the `button_html` parameter.
171
+ */
172
+ readonly button_layout: {
126
173
  readonly type: ParameterType.STRING;
127
- readonly pretty_name: "Margin vertical";
128
- readonly default: "0px";
174
+ readonly default: "grid";
129
175
  };
130
- /** Horizontal margin of button. */
131
- readonly margin_horizontal: {
132
- readonly type: ParameterType.STRING;
133
- readonly pretty_name: "Margin horizontal";
134
- readonly default: "8px";
176
+ /** The number of rows in the button grid. Only applicable when `button_layout` is set to `'grid'`. If null, the
177
+ * number of rows will be determined automatically based on the number of buttons and the number of columns.
178
+ */
179
+ readonly grid_rows: {
180
+ readonly type: ParameterType.INT;
181
+ readonly default: 1;
135
182
  };
136
- /** If true, the trial will end when user makes a response. */
183
+ /** The number of columns in the button grid. Only applicable when `button_layout` is set to `'grid'`.
184
+ * If null, the number of columns will be determined automatically based on the number of buttons and the
185
+ * number of rows.
186
+ */
187
+ readonly grid_columns: {
188
+ readonly type: ParameterType.INT;
189
+ readonly default: any;
190
+ };
191
+ /** If true, then the trial will end whenever the participant makes a response (assuming they make their
192
+ * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will
193
+ * continue until the value for `trial_duration` is reached. You can set this parameter to `false` to force
194
+ * the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete. */
137
195
  readonly response_ends_trial: {
138
196
  readonly type: ParameterType.BOOL;
139
- readonly pretty_name: "Response ends trial";
140
197
  readonly default: true;
141
198
  };
142
- /** If true, then the trial will end as soon as the audio file finishes playing. */
199
+ /** If true, then the trial will end as soon as the audio file finishes playing. */
143
200
  readonly trial_ends_after_audio: {
144
201
  readonly type: ParameterType.BOOL;
145
- readonly pretty_name: "Trial ends after audio";
146
202
  readonly default: false;
147
203
  };
148
204
  /**
149
- * If true, then responses are allowed while the audio is playing.
150
- * If false, then the audio must finish playing before a response is accepted.
205
+ * If true, then responses are allowed while the audio is playing. If false, then the audio must finish
206
+ * playing before the button choices are enabled and a response is accepted. Once the audio has played
207
+ * all the way through, the buttons are enabled and a response is allowed (including while the audio is
208
+ * being re-played via on-screen playback controls).
151
209
  */
152
210
  readonly response_allowed_while_playing: {
153
211
  readonly type: ParameterType.BOOL;
154
- readonly pretty_name: "Response allowed while playing";
155
212
  readonly default: true;
156
213
  };
157
- /** The delay of enabling button */
214
+ /** How long the button will delay enabling in milliseconds. If `response_allowed_while_playing` is `true`,
215
+ * the timer will start immediately. If it is `false`, the timer will start at the end of the audio. */
158
216
  readonly enable_button_after: {
159
217
  readonly type: ParameterType.INT;
160
- readonly pretty_name: "Enable button after";
161
218
  readonly default: 0;
162
219
  };
163
220
  };
221
+ readonly data: {
222
+ /** The response time in milliseconds for the participant to make a response. The time is measured from
223
+ * when the stimulus first began playing until the participant's response.*/
224
+ readonly rt: {
225
+ readonly type: ParameterType.INT;
226
+ };
227
+ /** Indicates which button the participant pressed. The first button in the `choices` array is 0, the second is 1, and so on. */
228
+ readonly response: {
229
+ readonly type: ParameterType.INT;
230
+ };
231
+ };
164
232
  };
165
233
  private audio;
234
+ private params;
235
+ private buttonElements;
236
+ private display;
237
+ private response;
238
+ private context;
239
+ private startTime;
240
+ private trial_complete;
166
241
  constructor(jsPsych: JsPsych);
167
242
  trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void): Promise<unknown>;
168
- simulate(trial: TrialType<Info>, simulation_mode: any, simulation_options: any, load_callback: () => void): void;
243
+ private disable_buttons;
244
+ private enable_buttons_without_delay;
245
+ private enable_buttons_with_delay;
246
+ private enable_buttons;
247
+ private after_response;
248
+ private end_trial;
249
+ simulate(trial: TrialType<Info>, simulation_mode: any, simulation_options: any, load_callback: () => void): Promise<void>;
169
250
  private create_simulation_data;
170
251
  private simulate_data_only;
171
252
  private simulate_visual;
172
253
  }
173
- export default AudioButtonResponsePlugin;
254
+
255
+ export { AudioButtonResponsePlugin as default };