@jspsych/plugin-audio-slider-response 1.1.2 → 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-slider-response\",\n parameters: {\n /** The audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n pretty_name: \"Stimulus\",\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n pretty_name: \"Min slider\",\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n pretty_name: \"Max slider\",\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n pretty_name: \"Slider starting value\",\n default: 50,\n },\n /** Sets the step of the slider */\n step: {\n type: ParameterType.INT,\n pretty_name: \"Step\",\n default: 1,\n },\n /** Array containing the labels for the slider. Labels will be displayed at equidistant locations along the slider. */\n labels: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Labels\",\n default: [],\n array: true,\n },\n /** Width of the slider in pixels. */\n slider_width: {\n type: ParameterType.INT,\n pretty_name: \"Slider width\",\n default: null,\n },\n /** Label of the button to advance. */\n button_label: {\n type: ParameterType.STRING,\n pretty_name: \"Button label\",\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant will have to move the slider before continuing. */\n require_movement: {\n type: ParameterType.BOOL,\n pretty_name: \"Require movement\",\n default: false,\n },\n /** Any content here will be displayed below the slider. */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: null,\n },\n /** How long to show the trial. */\n trial_duration: {\n type: ParameterType.INT,\n pretty_name: \"Trial duration\",\n default: null,\n },\n /** If true, 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 /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before a response is accepted. */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n pretty_name: \"Response allowed while playing\",\n default: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **audio-slider-response**\n *\n * jsPsych plugin for playing audio and getting a slider response\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/plugins/jspsych-audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin 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 // half of the thumb width value from jspsych.css, used to adjust the label positions\n var half_thumb_width = 7.5;\n\n // setup stimulus\n var context = this.jsPsych.pluginAPI.audioContext();\n\n // record webaudio context start time\n var startTime;\n\n // for storing data related to response\n var response;\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 slider after audio ends if necessary\n if (!trial.response_allowed_while_playing && !trial.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (trial.slider_width !== null) {\n html += trial.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n trial.slider_start +\n '\" min=\"' +\n trial.min +\n '\" max=\"' +\n trial.max +\n '\" step=\"' +\n trial.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!trial.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < trial.labels.length; j++) {\n var label_width_perc = 100 / (trial.labels.length - 1);\n var percent_of_range = j * (100 / (trial.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html += '<span style=\"text-align: center; font-size: 80%;\">' + trial.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (trial.prompt !== null) {\n html += trial.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (trial.require_movement || !trial.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n trial.button_label +\n \"</button>\";\n\n display_element.innerHTML = html;\n\n response = {\n rt: null,\n response: null,\n };\n\n if (!trial.response_allowed_while_playing) {\n display_element.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n display_element.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n\n if (trial.require_movement) {\n const enable_button = () => {\n display_element.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n display_element\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n display_element\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n display_element\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n display_element\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\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.rt = rt;\n response.response = display_element.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (trial.response_ends_trial) {\n end_trial();\n } else {\n display_element.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n startTime = performance.now();\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 trial_duration 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 enable slider after audio ends\n function enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!trial.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\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_slider);\n\n // save data\n var trialdata = {\n rt: response.rt,\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: response.response,\n };\n\n display_element.innerHTML = \"\";\n\n // next trial\n this.jsPsych.finishTrial(trialdata);\n\n trial_complete();\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 slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\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 const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":["ParameterType"],"m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OAAO,CAAC,CAAC;AAC/C,aAAA;AAAM,iBAAA;AACL,gBAAA,OAAO,EAAE,CAAC;AACX,aAAA;AACH,SAAC,CAAC,CAAC;KACJ;;AA/SM,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-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\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\n * the 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, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\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 response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\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 /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then 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, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => 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 // record webaudio context start time\n this.startTime;\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\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 this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\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.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n this.startTime = performance.now();\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\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_slider);\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\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 slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\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 const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\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,GAAK,EAAA;AAAA,MACH,MAAMA,qBAAc,CAA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,MAAM;AACf,UAAK,IAAA,CAAA,OAAA,CAAQ,SAAU,CAAA,WAAA,CAAY,EAAE,CAAA,CAAA;AACrC,UAAA,EAAA,CAAG,gBAAgB,IAAK,CAAA,QAAA,CAAA;AAAA,SAC1B,EAAG,IAAK,CAAA,EAAA,GAAK,CAAC,CAAA,CAAA;AAEd,QAAK,IAAA,CAAA,OAAA,CAAQ,UAAU,WAAY,CAAA,eAAA,CAAgB,cAAc,QAAQ,CAAA,EAAG,KAAK,EAAE,CAAA,CAAA;AAAA,OACrF;AAAA,KACF,CAAA;AAEA,IAAK,IAAA,CAAA,KAAA,CAAM,eAAiB,EAAA,KAAA,EAAO,MAAM;AACvC,MAAc,aAAA,EAAA,CAAA;AAEd,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;AAnSM,yBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,203 +1,268 @@
1
- import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
2
- declare const info: {
3
- readonly name: "audio-slider-response";
4
- readonly parameters: {
5
- /** The audio file to be played. */
6
- readonly stimulus: {
7
- readonly type: ParameterType.AUDIO;
8
- readonly pretty_name: "Stimulus";
9
- readonly default: any;
10
- };
11
- /** Sets the minimum value of the slider. */
12
- readonly min: {
13
- readonly type: ParameterType.INT;
14
- readonly pretty_name: "Min slider";
15
- readonly default: 0;
16
- };
17
- /** Sets the maximum value of the slider */
18
- readonly max: {
19
- readonly type: ParameterType.INT;
20
- readonly pretty_name: "Max slider";
21
- readonly default: 100;
22
- };
23
- /** Sets the starting value of the slider */
24
- readonly slider_start: {
25
- readonly type: ParameterType.INT;
26
- readonly pretty_name: "Slider starting value";
27
- readonly default: 50;
28
- };
29
- /** Sets the step of the slider */
30
- readonly step: {
31
- readonly type: ParameterType.INT;
32
- readonly pretty_name: "Step";
33
- readonly default: 1;
34
- };
35
- /** Array containing the labels for the slider. Labels will be displayed at equidistant locations along the slider. */
36
- readonly labels: {
37
- readonly type: ParameterType.HTML_STRING;
38
- readonly pretty_name: "Labels";
39
- readonly default: readonly [];
40
- readonly array: true;
41
- };
42
- /** Width of the slider in pixels. */
43
- readonly slider_width: {
44
- readonly type: ParameterType.INT;
45
- readonly pretty_name: "Slider width";
46
- readonly default: any;
47
- };
48
- /** Label of the button to advance. */
49
- readonly button_label: {
50
- readonly type: ParameterType.STRING;
51
- readonly pretty_name: "Button label";
52
- readonly default: "Continue";
53
- readonly array: false;
54
- };
55
- /** If true, the participant will have to move the slider before continuing. */
56
- readonly require_movement: {
57
- readonly type: ParameterType.BOOL;
58
- readonly pretty_name: "Require movement";
59
- readonly default: false;
60
- };
61
- /** Any content here will be displayed below the slider. */
62
- readonly prompt: {
63
- readonly type: ParameterType.HTML_STRING;
64
- readonly pretty_name: "Prompt";
65
- readonly default: any;
66
- };
67
- /** How long to show the trial. */
68
- readonly trial_duration: {
69
- readonly type: ParameterType.INT;
70
- readonly pretty_name: "Trial duration";
71
- readonly default: any;
72
- };
73
- /** If true, trial will end when user makes a response. */
74
- readonly response_ends_trial: {
75
- readonly type: ParameterType.BOOL;
76
- readonly pretty_name: "Response ends trial";
77
- readonly default: true;
78
- };
79
- /** If true, then the trial will end as soon as the audio file finishes playing. */
80
- readonly trial_ends_after_audio: {
81
- readonly type: ParameterType.BOOL;
82
- readonly pretty_name: "Trial ends after audio";
83
- readonly default: false;
84
- };
85
- /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before a response is accepted. */
86
- readonly response_allowed_while_playing: {
87
- readonly type: ParameterType.BOOL;
88
- readonly pretty_name: "Response allowed while playing";
89
- readonly default: true;
90
- };
91
- };
92
- };
93
- declare type Info = typeof info;
94
- /**
95
- * **audio-slider-response**
96
- *
97
- * jsPsych plugin for playing audio and getting a slider response
98
- *
99
- * @author Josh de Leeuw
100
- * @see {@link https://www.jspsych.org/plugins/jspsych-audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}
101
- */
102
- declare class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
103
- private jsPsych;
104
- static info: {
105
- readonly name: "audio-slider-response";
106
- readonly parameters: {
107
- /** The audio file to be played. */
108
- readonly stimulus: {
109
- readonly type: ParameterType.AUDIO;
110
- readonly pretty_name: "Stimulus";
111
- readonly default: any;
112
- };
113
- /** Sets the minimum value of the slider. */
114
- readonly min: {
115
- readonly type: ParameterType.INT;
116
- readonly pretty_name: "Min slider";
117
- readonly default: 0;
118
- };
119
- /** Sets the maximum value of the slider */
120
- readonly max: {
121
- readonly type: ParameterType.INT;
122
- readonly pretty_name: "Max slider";
123
- readonly default: 100;
124
- };
125
- /** Sets the starting value of the slider */
126
- readonly slider_start: {
127
- readonly type: ParameterType.INT;
128
- readonly pretty_name: "Slider starting value";
129
- readonly default: 50;
130
- };
131
- /** Sets the step of the slider */
132
- readonly step: {
133
- readonly type: ParameterType.INT;
134
- readonly pretty_name: "Step";
135
- readonly default: 1;
136
- };
137
- /** Array containing the labels for the slider. Labels will be displayed at equidistant locations along the slider. */
138
- readonly labels: {
139
- readonly type: ParameterType.HTML_STRING;
140
- readonly pretty_name: "Labels";
141
- readonly default: readonly [];
142
- readonly array: true;
143
- };
144
- /** Width of the slider in pixels. */
145
- readonly slider_width: {
146
- readonly type: ParameterType.INT;
147
- readonly pretty_name: "Slider width";
148
- readonly default: any;
149
- };
150
- /** Label of the button to advance. */
151
- readonly button_label: {
152
- readonly type: ParameterType.STRING;
153
- readonly pretty_name: "Button label";
154
- readonly default: "Continue";
155
- readonly array: false;
156
- };
157
- /** If true, the participant will have to move the slider before continuing. */
158
- readonly require_movement: {
159
- readonly type: ParameterType.BOOL;
160
- readonly pretty_name: "Require movement";
161
- readonly default: false;
162
- };
163
- /** Any content here will be displayed below the slider. */
164
- readonly prompt: {
165
- readonly type: ParameterType.HTML_STRING;
166
- readonly pretty_name: "Prompt";
167
- readonly default: any;
168
- };
169
- /** How long to show the trial. */
170
- readonly trial_duration: {
171
- readonly type: ParameterType.INT;
172
- readonly pretty_name: "Trial duration";
173
- readonly default: any;
174
- };
175
- /** If true, trial will end when user makes a response. */
176
- readonly response_ends_trial: {
177
- readonly type: ParameterType.BOOL;
178
- readonly pretty_name: "Response ends trial";
179
- readonly default: true;
180
- };
181
- /** If true, then the trial will end as soon as the audio file finishes playing. */
182
- readonly trial_ends_after_audio: {
183
- readonly type: ParameterType.BOOL;
184
- readonly pretty_name: "Trial ends after audio";
185
- readonly default: false;
186
- };
187
- /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before a response is accepted. */
188
- readonly response_allowed_while_playing: {
189
- readonly type: ParameterType.BOOL;
190
- readonly pretty_name: "Response allowed while playing";
191
- readonly default: true;
192
- };
193
- };
194
- };
195
- private audio;
196
- constructor(jsPsych: JsPsych);
197
- trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void): Promise<unknown>;
198
- simulate(trial: TrialType<Info>, simulation_mode: any, simulation_options: any, load_callback: () => void): void;
199
- private create_simulation_data;
200
- private simulate_data_only;
201
- private simulate_visual;
202
- }
203
- export default AudioSliderResponsePlugin;
1
+ import { JsPsychPlugin, ParameterType, JsPsych, TrialType } from 'jspsych';
2
+
3
+ declare const info: {
4
+ readonly name: "audio-slider-response";
5
+ readonly version: string;
6
+ readonly parameters: {
7
+ /** Audio file to be played. */
8
+ readonly stimulus: {
9
+ readonly type: ParameterType.AUDIO;
10
+ readonly default: any;
11
+ };
12
+ /** Sets the minimum value of the slider. */
13
+ readonly min: {
14
+ readonly type: ParameterType.INT;
15
+ readonly default: 0;
16
+ };
17
+ /** Sets the maximum value of the slider */
18
+ readonly max: {
19
+ readonly type: ParameterType.INT;
20
+ readonly default: 100;
21
+ };
22
+ /** Sets the starting value of the slider */
23
+ readonly slider_start: {
24
+ readonly type: ParameterType.INT;
25
+ readonly default: 50;
26
+ };
27
+ /** Sets the step of the slider. This is the smallest amount by which the slider can change. */
28
+ readonly step: {
29
+ readonly type: ParameterType.INT;
30
+ readonly default: 1;
31
+ };
32
+ /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the
33
+ * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the
34
+ * other two will be at 33% and 67% of the slider width.
35
+ */
36
+ readonly labels: {
37
+ readonly type: ParameterType.HTML_STRING;
38
+ readonly default: readonly [];
39
+ readonly array: true;
40
+ };
41
+ /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */
42
+ readonly slider_width: {
43
+ readonly type: ParameterType.INT;
44
+ readonly default: any;
45
+ };
46
+ /** Label of the button to end the trial. */
47
+ readonly button_label: {
48
+ readonly type: ParameterType.STRING;
49
+ readonly default: "Continue";
50
+ readonly array: false;
51
+ };
52
+ /** If true, the participant must move the slider before clicking the continue button. */
53
+ readonly require_movement: {
54
+ readonly type: ParameterType.BOOL;
55
+ readonly default: false;
56
+ };
57
+ /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is
58
+ * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
59
+ */
60
+ readonly prompt: {
61
+ readonly type: ParameterType.HTML_STRING;
62
+ readonly default: any;
63
+ };
64
+ /** How long to wait for the participant to make a response before ending the trial in milliseconds. If
65
+ * the participant fails to make a response before this timer is reached, the participant's response will be
66
+ * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial
67
+ * will wait for a response indefinitely.
68
+ */
69
+ readonly trial_duration: {
70
+ readonly type: ParameterType.INT;
71
+ readonly default: any;
72
+ };
73
+ /** If true, then the trial will end whenever the participant makes a response (assuming they make their response
74
+ * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the
75
+ * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to
76
+ * the stimulus for a fixed amount of time, even if they respond before the time is complete.
77
+ */
78
+ readonly response_ends_trial: {
79
+ readonly type: ParameterType.BOOL;
80
+ readonly default: true;
81
+ };
82
+ /** If true, then the trial will end as soon as the audio file finishes playing. */
83
+ readonly trial_ends_after_audio: {
84
+ readonly type: ParameterType.BOOL;
85
+ readonly default: false;
86
+ };
87
+ /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before
88
+ * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,
89
+ * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).
90
+ */
91
+ readonly response_allowed_while_playing: {
92
+ readonly type: ParameterType.BOOL;
93
+ readonly default: true;
94
+ };
95
+ };
96
+ readonly data: {
97
+ /** The numeric value of the slider. */
98
+ readonly response: {
99
+ readonly type: ParameterType.INT;
100
+ };
101
+ /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first
102
+ * began playing until the participant's response.
103
+ */
104
+ readonly rt: {
105
+ readonly type: ParameterType.INT;
106
+ };
107
+ /** The path of the audio file that was played. */
108
+ readonly stimulus: {
109
+ readonly type: ParameterType.STRING;
110
+ };
111
+ /** The starting value of the slider. */
112
+ readonly slider_start: {
113
+ readonly type: ParameterType.INT;
114
+ };
115
+ };
116
+ };
117
+ type Info = typeof info;
118
+ /**
119
+ * This plugin plays an audio file and allows the participant to respond by dragging a slider.
120
+ *
121
+ * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the
122
+ * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of
123
+ * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.
124
+ *
125
+ * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using
126
+ * timeline variables or another dynamic method to specify the audio stimulus, then you will need
127
+ * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.
128
+ *
129
+ * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.
130
+ * @author Josh de Leeuw
131
+ * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}
132
+ */
133
+ declare class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
134
+ private jsPsych;
135
+ static info: {
136
+ readonly name: "audio-slider-response";
137
+ readonly version: string;
138
+ readonly parameters: {
139
+ /** Audio file to be played. */
140
+ readonly stimulus: {
141
+ readonly type: ParameterType.AUDIO;
142
+ readonly default: any;
143
+ };
144
+ /** Sets the minimum value of the slider. */
145
+ readonly min: {
146
+ readonly type: ParameterType.INT;
147
+ readonly default: 0;
148
+ };
149
+ /** Sets the maximum value of the slider */
150
+ readonly max: {
151
+ readonly type: ParameterType.INT;
152
+ readonly default: 100;
153
+ };
154
+ /** Sets the starting value of the slider */
155
+ readonly slider_start: {
156
+ readonly type: ParameterType.INT;
157
+ readonly default: 50;
158
+ };
159
+ /** Sets the step of the slider. This is the smallest amount by which the slider can change. */
160
+ readonly step: {
161
+ readonly type: ParameterType.INT;
162
+ readonly default: 1;
163
+ };
164
+ /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the
165
+ * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the
166
+ * other two will be at 33% and 67% of the slider width.
167
+ */
168
+ readonly labels: {
169
+ readonly type: ParameterType.HTML_STRING;
170
+ readonly default: readonly [];
171
+ readonly array: true;
172
+ };
173
+ /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */
174
+ readonly slider_width: {
175
+ readonly type: ParameterType.INT;
176
+ readonly default: any;
177
+ };
178
+ /** Label of the button to end the trial. */
179
+ readonly button_label: {
180
+ readonly type: ParameterType.STRING;
181
+ readonly default: "Continue";
182
+ readonly array: false;
183
+ };
184
+ /** If true, the participant must move the slider before clicking the continue button. */
185
+ readonly require_movement: {
186
+ readonly type: ParameterType.BOOL;
187
+ readonly default: false;
188
+ };
189
+ /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is
190
+ * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
191
+ */
192
+ readonly prompt: {
193
+ readonly type: ParameterType.HTML_STRING;
194
+ readonly default: any;
195
+ };
196
+ /** How long to wait for the participant to make a response before ending the trial in milliseconds. If
197
+ * the participant fails to make a response before this timer is reached, the participant's response will be
198
+ * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial
199
+ * will wait for a response indefinitely.
200
+ */
201
+ readonly trial_duration: {
202
+ readonly type: ParameterType.INT;
203
+ readonly default: any;
204
+ };
205
+ /** If true, then the trial will end whenever the participant makes a response (assuming they make their response
206
+ * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the
207
+ * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to
208
+ * the stimulus for a fixed amount of time, even if they respond before the time is complete.
209
+ */
210
+ readonly response_ends_trial: {
211
+ readonly type: ParameterType.BOOL;
212
+ readonly default: true;
213
+ };
214
+ /** If true, then the trial will end as soon as the audio file finishes playing. */
215
+ readonly trial_ends_after_audio: {
216
+ readonly type: ParameterType.BOOL;
217
+ readonly default: false;
218
+ };
219
+ /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before
220
+ * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,
221
+ * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).
222
+ */
223
+ readonly response_allowed_while_playing: {
224
+ readonly type: ParameterType.BOOL;
225
+ readonly default: true;
226
+ };
227
+ };
228
+ readonly data: {
229
+ /** The numeric value of the slider. */
230
+ readonly response: {
231
+ readonly type: ParameterType.INT;
232
+ };
233
+ /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first
234
+ * began playing until the participant's response.
235
+ */
236
+ readonly rt: {
237
+ readonly type: ParameterType.INT;
238
+ };
239
+ /** The path of the audio file that was played. */
240
+ readonly stimulus: {
241
+ readonly type: ParameterType.STRING;
242
+ };
243
+ /** The starting value of the slider. */
244
+ readonly slider_start: {
245
+ readonly type: ParameterType.INT;
246
+ };
247
+ };
248
+ };
249
+ private audio;
250
+ private context;
251
+ private params;
252
+ private display;
253
+ private response;
254
+ private startTime;
255
+ private half_thumb_width;
256
+ private trial_complete;
257
+ constructor(jsPsych: JsPsych);
258
+ trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void): Promise<unknown>;
259
+ private enable_slider;
260
+ private setupTrial;
261
+ private end_trial;
262
+ simulate(trial: TrialType<Info>, simulation_mode: any, simulation_options: any, load_callback: () => void): void;
263
+ private create_simulation_data;
264
+ private simulate_data_only;
265
+ private simulate_visual;
266
+ }
267
+
268
+ export { AudioSliderResponsePlugin as default };