@jspsych/plugin-audio-slider-response 1.1.3 → 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.
- package/dist/index.browser.js +357 -351
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +2 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +288 -336
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +118 -53
- package/dist/index.js +288 -336
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.spec.ts +131 -1
- package/src/index.ts +252 -232
package/src/index.ts
CHANGED
|
@@ -1,347 +1,367 @@
|
|
|
1
|
+
import autoBind from "auto-bind";
|
|
1
2
|
import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
|
|
2
3
|
|
|
4
|
+
import { AudioPlayerInterface } from "../../jspsych/src/modules/plugin-api/AudioPlayer";
|
|
5
|
+
import { version } from "../package.json";
|
|
6
|
+
|
|
3
7
|
const info = <const>{
|
|
4
8
|
name: "audio-slider-response",
|
|
9
|
+
version: version,
|
|
5
10
|
parameters: {
|
|
6
|
-
/**
|
|
11
|
+
/** Audio file to be played. */
|
|
7
12
|
stimulus: {
|
|
8
13
|
type: ParameterType.AUDIO,
|
|
9
|
-
pretty_name: "Stimulus",
|
|
10
14
|
default: undefined,
|
|
11
15
|
},
|
|
12
16
|
/** Sets the minimum value of the slider. */
|
|
13
17
|
min: {
|
|
14
18
|
type: ParameterType.INT,
|
|
15
|
-
pretty_name: "Min slider",
|
|
16
19
|
default: 0,
|
|
17
20
|
},
|
|
18
21
|
/** Sets the maximum value of the slider */
|
|
19
22
|
max: {
|
|
20
23
|
type: ParameterType.INT,
|
|
21
|
-
pretty_name: "Max slider",
|
|
22
24
|
default: 100,
|
|
23
25
|
},
|
|
24
26
|
/** Sets the starting value of the slider */
|
|
25
27
|
slider_start: {
|
|
26
28
|
type: ParameterType.INT,
|
|
27
|
-
pretty_name: "Slider starting value",
|
|
28
29
|
default: 50,
|
|
29
30
|
},
|
|
30
|
-
/** Sets the step of the slider */
|
|
31
|
+
/** Sets the step of the slider. This is the smallest amount by which the slider can change. */
|
|
31
32
|
step: {
|
|
32
33
|
type: ParameterType.INT,
|
|
33
|
-
pretty_name: "Step",
|
|
34
34
|
default: 1,
|
|
35
35
|
},
|
|
36
|
-
/**
|
|
36
|
+
/** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the
|
|
37
|
+
* slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the
|
|
38
|
+
* other two will be at 33% and 67% of the slider width.
|
|
39
|
+
*/
|
|
37
40
|
labels: {
|
|
38
41
|
type: ParameterType.HTML_STRING,
|
|
39
|
-
pretty_name: "Labels",
|
|
40
42
|
default: [],
|
|
41
43
|
array: true,
|
|
42
44
|
},
|
|
43
|
-
/**
|
|
45
|
+
/** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */
|
|
44
46
|
slider_width: {
|
|
45
47
|
type: ParameterType.INT,
|
|
46
|
-
pretty_name: "Slider width",
|
|
47
48
|
default: null,
|
|
48
49
|
},
|
|
49
|
-
/** Label of the button to
|
|
50
|
+
/** Label of the button to end the trial. */
|
|
50
51
|
button_label: {
|
|
51
52
|
type: ParameterType.STRING,
|
|
52
|
-
pretty_name: "Button label",
|
|
53
53
|
default: "Continue",
|
|
54
54
|
array: false,
|
|
55
55
|
},
|
|
56
|
-
/** If true, the participant
|
|
56
|
+
/** If true, the participant must move the slider before clicking the continue button. */
|
|
57
57
|
require_movement: {
|
|
58
58
|
type: ParameterType.BOOL,
|
|
59
|
-
pretty_name: "Require movement",
|
|
60
59
|
default: false,
|
|
61
60
|
},
|
|
62
|
-
/** Any content here will be displayed below the
|
|
61
|
+
/** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is
|
|
62
|
+
* that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
|
|
63
|
+
*/
|
|
63
64
|
prompt: {
|
|
64
65
|
type: ParameterType.HTML_STRING,
|
|
65
|
-
pretty_name: "Prompt",
|
|
66
66
|
default: null,
|
|
67
67
|
},
|
|
68
|
-
/** How long to
|
|
68
|
+
/** How long to wait for the participant to make a response before ending the trial in milliseconds. If
|
|
69
|
+
* the participant fails to make a response before this timer is reached, the participant's response will be
|
|
70
|
+
* recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial
|
|
71
|
+
* will wait for a response indefinitely.
|
|
72
|
+
*/
|
|
69
73
|
trial_duration: {
|
|
70
74
|
type: ParameterType.INT,
|
|
71
|
-
pretty_name: "Trial duration",
|
|
72
75
|
default: null,
|
|
73
76
|
},
|
|
74
|
-
/** If true, trial will end
|
|
77
|
+
/** If true, then the trial will end whenever the participant makes a response (assuming they make their response
|
|
78
|
+
* before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the
|
|
79
|
+
* value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to
|
|
80
|
+
* the stimulus for a fixed amount of time, even if they respond before the time is complete.
|
|
81
|
+
*/
|
|
75
82
|
response_ends_trial: {
|
|
76
83
|
type: ParameterType.BOOL,
|
|
77
|
-
pretty_name: "Response ends trial",
|
|
78
84
|
default: true,
|
|
79
85
|
},
|
|
80
86
|
/** If true, then the trial will end as soon as the audio file finishes playing. */
|
|
81
87
|
trial_ends_after_audio: {
|
|
82
88
|
type: ParameterType.BOOL,
|
|
83
|
-
pretty_name: "Trial ends after audio",
|
|
84
89
|
default: false,
|
|
85
90
|
},
|
|
86
|
-
/** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before
|
|
91
|
+
/** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before
|
|
92
|
+
* the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,
|
|
93
|
+
* the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).
|
|
94
|
+
*/
|
|
87
95
|
response_allowed_while_playing: {
|
|
88
96
|
type: ParameterType.BOOL,
|
|
89
|
-
pretty_name: "Response allowed while playing",
|
|
90
97
|
default: true,
|
|
91
98
|
},
|
|
92
99
|
},
|
|
100
|
+
data: {
|
|
101
|
+
/** The numeric value of the slider. */
|
|
102
|
+
response: {
|
|
103
|
+
type: ParameterType.INT,
|
|
104
|
+
},
|
|
105
|
+
/** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first
|
|
106
|
+
* began playing until the participant's response.
|
|
107
|
+
*/
|
|
108
|
+
rt: {
|
|
109
|
+
type: ParameterType.INT,
|
|
110
|
+
},
|
|
111
|
+
/** The path of the audio file that was played. */
|
|
112
|
+
stimulus: {
|
|
113
|
+
type: ParameterType.STRING,
|
|
114
|
+
},
|
|
115
|
+
/** The starting value of the slider. */
|
|
116
|
+
slider_start: {
|
|
117
|
+
type: ParameterType.INT,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
93
120
|
};
|
|
94
121
|
|
|
95
122
|
type Info = typeof info;
|
|
96
123
|
|
|
97
124
|
/**
|
|
98
|
-
*
|
|
125
|
+
* This plugin plays an audio file and allows the participant to respond by dragging a slider.
|
|
126
|
+
*
|
|
127
|
+
* If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the
|
|
128
|
+
* playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of
|
|
129
|
+
* response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.
|
|
99
130
|
*
|
|
100
|
-
* jsPsych
|
|
131
|
+
* Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using
|
|
132
|
+
* timeline variables or another dynamic method to specify the audio stimulus, then you will need
|
|
133
|
+
* to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.
|
|
101
134
|
*
|
|
135
|
+
* 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.
|
|
102
136
|
* @author Josh de Leeuw
|
|
103
|
-
* @see {@link https://www.jspsych.org/plugins/
|
|
137
|
+
* @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}
|
|
104
138
|
*/
|
|
105
139
|
class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|
106
140
|
static info = info;
|
|
107
|
-
private audio;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
141
|
+
private audio: AudioPlayerInterface;
|
|
142
|
+
private context: AudioContext;
|
|
143
|
+
private params: TrialType<Info>;
|
|
144
|
+
private display: HTMLElement;
|
|
145
|
+
private response: { rt: number; response: number } = { rt: null, response: null };
|
|
146
|
+
private startTime: number;
|
|
147
|
+
private half_thumb_width: number;
|
|
148
|
+
private trial_complete: (trial_data: {
|
|
149
|
+
rt: number;
|
|
150
|
+
slider_start: number;
|
|
151
|
+
response: number;
|
|
152
|
+
}) => void;
|
|
153
|
+
|
|
154
|
+
constructor(private jsPsych: JsPsych) {
|
|
155
|
+
autoBind(this);
|
|
156
|
+
}
|
|
114
157
|
|
|
158
|
+
async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {
|
|
159
|
+
// record webaudio context start time
|
|
160
|
+
this.startTime;
|
|
161
|
+
this.params = trial;
|
|
162
|
+
this.display = display_element;
|
|
163
|
+
// for storing data related to response
|
|
164
|
+
this.response;
|
|
115
165
|
// half of the thumb width value from jspsych.css, used to adjust the label positions
|
|
116
|
-
|
|
166
|
+
this.half_thumb_width = 7.5;
|
|
167
|
+
// hold the .resolve() function from the Promise that ends the trial
|
|
168
|
+
this.trial_complete;
|
|
117
169
|
|
|
118
170
|
// setup stimulus
|
|
119
|
-
|
|
171
|
+
this.context = this.jsPsych.pluginAPI.audioContext();
|
|
120
172
|
|
|
121
|
-
//
|
|
122
|
-
|
|
173
|
+
// load audio file
|
|
174
|
+
this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);
|
|
123
175
|
|
|
124
|
-
|
|
125
|
-
var response;
|
|
176
|
+
this.setupTrial();
|
|
126
177
|
|
|
127
|
-
|
|
128
|
-
this.jsPsych.pluginAPI
|
|
129
|
-
.getAudioBuffer(trial.stimulus)
|
|
130
|
-
.then((buffer) => {
|
|
131
|
-
if (context !== null) {
|
|
132
|
-
this.audio = context.createBufferSource();
|
|
133
|
-
this.audio.buffer = buffer;
|
|
134
|
-
this.audio.connect(context.destination);
|
|
135
|
-
} else {
|
|
136
|
-
this.audio = buffer;
|
|
137
|
-
this.audio.currentTime = 0;
|
|
138
|
-
}
|
|
139
|
-
setupTrial();
|
|
140
|
-
})
|
|
141
|
-
.catch((err) => {
|
|
142
|
-
console.error(
|
|
143
|
-
`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`
|
|
144
|
-
);
|
|
145
|
-
console.error(err);
|
|
146
|
-
});
|
|
178
|
+
on_load();
|
|
147
179
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
180
|
+
return new Promise((resolve) => {
|
|
181
|
+
this.trial_complete = resolve;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
153
184
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
185
|
+
// to enable slider after audio ends
|
|
186
|
+
private enable_slider() {
|
|
187
|
+
document.querySelector<HTMLInputElement>("#jspsych-audio-slider-response-response").disabled =
|
|
188
|
+
false;
|
|
189
|
+
if (!this.params.require_movement) {
|
|
190
|
+
document.querySelector<HTMLButtonElement>("#jspsych-audio-slider-response-next").disabled =
|
|
191
|
+
false;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private setupTrial = () => {
|
|
196
|
+
// set up end event if trial needs it
|
|
197
|
+
if (this.params.trial_ends_after_audio) {
|
|
198
|
+
this.audio.addEventListener("ended", this.end_trial);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// enable slider after audio ends if necessary
|
|
202
|
+
if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {
|
|
203
|
+
this.audio.addEventListener("ended", this.enable_slider);
|
|
204
|
+
}
|
|
158
205
|
|
|
159
|
-
|
|
206
|
+
var html = '<div id="jspsych-audio-slider-response-wrapper" style="margin: 100px 0px;">';
|
|
207
|
+
html +=
|
|
208
|
+
'<div class="jspsych-audio-slider-response-container" style="position:relative; margin: 0 auto 3em auto; width:';
|
|
209
|
+
if (this.params.slider_width !== null) {
|
|
210
|
+
html += this.params.slider_width + "px;";
|
|
211
|
+
} else {
|
|
212
|
+
html += "auto;";
|
|
213
|
+
}
|
|
214
|
+
html += '">';
|
|
215
|
+
html +=
|
|
216
|
+
'<input type="range" class="jspsych-slider" value="' +
|
|
217
|
+
this.params.slider_start +
|
|
218
|
+
'" min="' +
|
|
219
|
+
this.params.min +
|
|
220
|
+
'" max="' +
|
|
221
|
+
this.params.max +
|
|
222
|
+
'" step="' +
|
|
223
|
+
this.params.step +
|
|
224
|
+
'" id="jspsych-audio-slider-response-response"';
|
|
225
|
+
if (!this.params.response_allowed_while_playing) {
|
|
226
|
+
html += " disabled";
|
|
227
|
+
}
|
|
228
|
+
html += "></input><div>";
|
|
229
|
+
for (var j = 0; j < this.params.labels.length; j++) {
|
|
230
|
+
var label_width_perc = 100 / (this.params.labels.length - 1);
|
|
231
|
+
var percent_of_range = j * (100 / (this.params.labels.length - 1));
|
|
232
|
+
var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;
|
|
233
|
+
var offset = (percent_dist_from_center * this.half_thumb_width) / 100;
|
|
160
234
|
html +=
|
|
161
|
-
'<div
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
235
|
+
'<div style="border: 1px solid transparent; display: inline-block; position: absolute; ' +
|
|
236
|
+
"left:calc(" +
|
|
237
|
+
percent_of_range +
|
|
238
|
+
"% - (" +
|
|
239
|
+
label_width_perc +
|
|
240
|
+
"% / 2) - " +
|
|
241
|
+
offset +
|
|
242
|
+
"px); text-align: center; width: " +
|
|
243
|
+
label_width_perc +
|
|
244
|
+
'%;">';
|
|
168
245
|
html +=
|
|
169
|
-
'<
|
|
170
|
-
trial.slider_start +
|
|
171
|
-
'" min="' +
|
|
172
|
-
trial.min +
|
|
173
|
-
'" max="' +
|
|
174
|
-
trial.max +
|
|
175
|
-
'" step="' +
|
|
176
|
-
trial.step +
|
|
177
|
-
'" id="jspsych-audio-slider-response-response"';
|
|
178
|
-
if (!trial.response_allowed_while_playing) {
|
|
179
|
-
html += " disabled";
|
|
180
|
-
}
|
|
181
|
-
html += "></input><div>";
|
|
182
|
-
for (var j = 0; j < trial.labels.length; j++) {
|
|
183
|
-
var label_width_perc = 100 / (trial.labels.length - 1);
|
|
184
|
-
var percent_of_range = j * (100 / (trial.labels.length - 1));
|
|
185
|
-
var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;
|
|
186
|
-
var offset = (percent_dist_from_center * half_thumb_width) / 100;
|
|
187
|
-
html +=
|
|
188
|
-
'<div style="border: 1px solid transparent; display: inline-block; position: absolute; ' +
|
|
189
|
-
"left:calc(" +
|
|
190
|
-
percent_of_range +
|
|
191
|
-
"% - (" +
|
|
192
|
-
label_width_perc +
|
|
193
|
-
"% / 2) - " +
|
|
194
|
-
offset +
|
|
195
|
-
"px); text-align: center; width: " +
|
|
196
|
-
label_width_perc +
|
|
197
|
-
'%;">';
|
|
198
|
-
html += '<span style="text-align: center; font-size: 80%;">' + trial.labels[j] + "</span>";
|
|
199
|
-
html += "</div>";
|
|
200
|
-
}
|
|
201
|
-
html += "</div>";
|
|
246
|
+
'<span style="text-align: center; font-size: 80%;">' + this.params.labels[j] + "</span>";
|
|
202
247
|
html += "</div>";
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
248
|
+
}
|
|
249
|
+
html += "</div>";
|
|
250
|
+
html += "</div>";
|
|
251
|
+
html += "</div>";
|
|
208
252
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
next_disabled_attribute = "disabled";
|
|
213
|
-
}
|
|
214
|
-
html +=
|
|
215
|
-
'<button id="jspsych-audio-slider-response-next" class="jspsych-btn" ' +
|
|
216
|
-
next_disabled_attribute +
|
|
217
|
-
">" +
|
|
218
|
-
trial.button_label +
|
|
219
|
-
"</button>";
|
|
253
|
+
if (this.params.prompt !== null) {
|
|
254
|
+
html += this.params.prompt;
|
|
255
|
+
}
|
|
220
256
|
|
|
221
|
-
|
|
257
|
+
// add submit button
|
|
258
|
+
var next_disabled_attribute = "";
|
|
259
|
+
if (this.params.require_movement || !this.params.response_allowed_while_playing) {
|
|
260
|
+
next_disabled_attribute = "disabled";
|
|
261
|
+
}
|
|
262
|
+
html +=
|
|
263
|
+
'<button id="jspsych-audio-slider-response-next" class="jspsych-btn" ' +
|
|
264
|
+
next_disabled_attribute +
|
|
265
|
+
">" +
|
|
266
|
+
this.params.button_label +
|
|
267
|
+
"</button>";
|
|
268
|
+
|
|
269
|
+
this.display.innerHTML = html;
|
|
270
|
+
|
|
271
|
+
this.response = {
|
|
272
|
+
rt: null,
|
|
273
|
+
response: null,
|
|
274
|
+
};
|
|
222
275
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
response
|
|
226
|
-
|
|
276
|
+
if (!this.params.response_allowed_while_playing) {
|
|
277
|
+
this.display.querySelector<HTMLInputElement>(
|
|
278
|
+
"#jspsych-audio-slider-response-response"
|
|
279
|
+
).disabled = true;
|
|
280
|
+
this.display.querySelector<HTMLInputElement>("#jspsych-audio-slider-response-next").disabled =
|
|
281
|
+
true;
|
|
282
|
+
}
|
|
227
283
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
).disabled = true;
|
|
232
|
-
display_element.querySelector<HTMLInputElement>(
|
|
284
|
+
if (this.params.require_movement) {
|
|
285
|
+
const enable_button = () => {
|
|
286
|
+
this.display.querySelector<HTMLInputElement>(
|
|
233
287
|
"#jspsych-audio-slider-response-next"
|
|
234
|
-
).disabled =
|
|
235
|
-
}
|
|
288
|
+
).disabled = false;
|
|
289
|
+
};
|
|
236
290
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
"#jspsych-audio-slider-response-next"
|
|
241
|
-
).disabled = false;
|
|
242
|
-
};
|
|
291
|
+
this.display
|
|
292
|
+
.querySelector("#jspsych-audio-slider-response-response")
|
|
293
|
+
.addEventListener("mousedown", enable_button);
|
|
243
294
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
295
|
+
this.display
|
|
296
|
+
.querySelector("#jspsych-audio-slider-response-response")
|
|
297
|
+
.addEventListener("touchstart", enable_button);
|
|
247
298
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
299
|
+
this.display
|
|
300
|
+
.querySelector("#jspsych-audio-slider-response-response")
|
|
301
|
+
.addEventListener("change", enable_button);
|
|
302
|
+
}
|
|
251
303
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
304
|
+
this.display
|
|
305
|
+
.querySelector("#jspsych-audio-slider-response-next")
|
|
306
|
+
.addEventListener("click", () => {
|
|
307
|
+
// measure response time
|
|
308
|
+
var endTime = performance.now();
|
|
309
|
+
var rt = Math.round(endTime - this.startTime);
|
|
310
|
+
if (this.context !== null) {
|
|
311
|
+
endTime = this.context.currentTime;
|
|
312
|
+
rt = Math.round((endTime - this.startTime) * 1000);
|
|
313
|
+
}
|
|
314
|
+
this.response.rt = rt;
|
|
315
|
+
this.response.response = this.display.querySelector<HTMLInputElement>(
|
|
316
|
+
"#jspsych-audio-slider-response-response"
|
|
317
|
+
).valueAsNumber;
|
|
256
318
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
rt = Math.round((endTime - startTime) * 1000);
|
|
266
|
-
}
|
|
267
|
-
response.rt = rt;
|
|
268
|
-
response.response = display_element.querySelector<HTMLInputElement>(
|
|
269
|
-
"#jspsych-audio-slider-response-response"
|
|
270
|
-
).valueAsNumber;
|
|
271
|
-
|
|
272
|
-
if (trial.response_ends_trial) {
|
|
273
|
-
end_trial();
|
|
274
|
-
} else {
|
|
275
|
-
display_element.querySelector<HTMLInputElement>(
|
|
276
|
-
"#jspsych-audio-slider-response-next"
|
|
277
|
-
).disabled = true;
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
startTime = performance.now();
|
|
282
|
-
// start audio
|
|
283
|
-
if (context !== null) {
|
|
284
|
-
startTime = context.currentTime;
|
|
285
|
-
this.audio.start(startTime);
|
|
286
|
-
} else {
|
|
287
|
-
this.audio.play();
|
|
288
|
-
}
|
|
319
|
+
if (this.params.response_ends_trial) {
|
|
320
|
+
this.end_trial();
|
|
321
|
+
} else {
|
|
322
|
+
this.display.querySelector<HTMLInputElement>(
|
|
323
|
+
"#jspsych-audio-slider-response-next"
|
|
324
|
+
).disabled = true;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
289
327
|
|
|
290
|
-
|
|
291
|
-
if (trial.trial_duration !== null) {
|
|
292
|
-
this.jsPsych.pluginAPI.setTimeout(() => {
|
|
293
|
-
end_trial();
|
|
294
|
-
}, trial.trial_duration);
|
|
295
|
-
}
|
|
328
|
+
this.startTime = performance.now();
|
|
296
329
|
|
|
297
|
-
|
|
298
|
-
|
|
330
|
+
// start audio
|
|
331
|
+
this.audio.play();
|
|
299
332
|
|
|
300
|
-
//
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
document.querySelector<HTMLButtonElement>("#jspsych-audio-slider-response-next").disabled =
|
|
306
|
-
false;
|
|
307
|
-
}
|
|
333
|
+
// end trial if trial_duration is set
|
|
334
|
+
if (this.params.trial_duration !== null) {
|
|
335
|
+
this.jsPsych.pluginAPI.setTimeout(() => {
|
|
336
|
+
this.end_trial();
|
|
337
|
+
}, this.params.trial_duration);
|
|
308
338
|
}
|
|
339
|
+
};
|
|
309
340
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
341
|
+
private end_trial = () => {
|
|
342
|
+
// kill any remaining setTimeout handlers
|
|
343
|
+
this.jsPsych.pluginAPI.clearAllTimeouts();
|
|
313
344
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (context !== null) {
|
|
317
|
-
this.audio.stop();
|
|
318
|
-
} else {
|
|
319
|
-
this.audio.pause();
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
this.audio.removeEventListener("ended", end_trial);
|
|
323
|
-
this.audio.removeEventListener("ended", enable_slider);
|
|
324
|
-
|
|
325
|
-
// save data
|
|
326
|
-
var trialdata = {
|
|
327
|
-
rt: response.rt,
|
|
328
|
-
stimulus: trial.stimulus,
|
|
329
|
-
slider_start: trial.slider_start,
|
|
330
|
-
response: response.response,
|
|
331
|
-
};
|
|
345
|
+
// stop the audio file if it is playing
|
|
346
|
+
this.audio.stop();
|
|
332
347
|
|
|
333
|
-
|
|
348
|
+
// remove end event listeners if they exist
|
|
349
|
+
this.audio.removeEventListener("ended", this.end_trial);
|
|
350
|
+
this.audio.removeEventListener("ended", this.enable_slider);
|
|
334
351
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
352
|
+
// save data
|
|
353
|
+
var trialdata = {
|
|
354
|
+
rt: this.response.rt,
|
|
355
|
+
stimulus: this.params.stimulus,
|
|
356
|
+
slider_start: this.params.slider_start,
|
|
357
|
+
response: this.response.response,
|
|
339
358
|
};
|
|
340
359
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
360
|
+
this.display.innerHTML = "";
|
|
361
|
+
|
|
362
|
+
// next trial
|
|
363
|
+
this.trial_complete(trialdata);
|
|
364
|
+
};
|
|
345
365
|
|
|
346
366
|
simulate(
|
|
347
367
|
trial: TrialType<Info>,
|