Skip to content

Commit

Permalink
Merge pull request #244 from lookit/feature/215-customize-lookawayTone
Browse files Browse the repository at this point in the history
switch lookawayTone to be relative to standard user-provided baseDir,…
  • Loading branch information
Kim Scott committed Apr 14, 2021
2 parents c33a489 + 5991af1 commit 3b0680f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Infant-controlled version of the :ref:`exp-lookit-images-audio` frame. This work

- end the trial by pressing the ``endTrialKey`` key
- hold down the ``lookawayKey`` (or the mouse button) to indicate that the child is not looking; the trial will automatically end
after the lookaway criterion is met. If the 'lookawayTone' is not 'none' a noise is played while the child is looking
after the lookaway criterion is met. If a 'lookawayTone' is provided, a noise is played while the child is looking
away to help the parent know the looking coding is working.

You can disable either of these behaviors by setting the corresponding key to ``''``.
Expand Down Expand Up @@ -67,7 +67,10 @@ than 2 s total, as coded by the parent holding down the P key, it will proceed.
"position": "fill"
}
],
"baseDir": "https://www.mit.edu/~kimscott/placeholderstimuli/",
"audioTypes": ["ogg", "mp3"],
"autoProceed": true,
"doRecording": true,
"durationSeconds": 30,
Expand Down
2 changes: 1 addition & 1 deletion app/components/exp-lookit-video-infant-control/doc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Infant-controlled version of the :ref:`exp-lookit-video` frame. This works the s

- end the trial by pressing the ``endTrialKey`` key
- hold down the ``lookawayKey`` (or the mouse button) to indicate that the child is not looking; the trial will automatically end
after the lookaway criterion is met. If the 'lookawayTone' is not 'none' a noise is played while the child is looking
after the lookaway criterion is met. If a 'lookawayTone' is provided, a noise is played while the child is looking
away to help the parent know the looking coding is working.

You can disable either of these behaviors by setting the corresponding key to ``''``.
Expand Down
38 changes: 20 additions & 18 deletions app/mixins/infant-controlled-timing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Ember from 'ember';
import {audioAssetOptions} from "./expand-assets";
import {mergeObjectOfArrays} from "../utils/replace-values";

let {
$
Expand Down Expand Up @@ -115,17 +117,9 @@ var infantControlledTimingMixin = Ember.Mixin.create({
default: 'q'
},

/**
Type of audio to play during parent-coded lookaways - 'tone' (A 220), 'noise' (pink noise), or 'none'. These
tones are available at https://www.mit.edu/~kimscott/placeholderstimuli/ if you want to use them in
instructions.
@property {string} lookawayTone
@default 'noise'
*/
lookawayTone: {
type: 'string',
enum: ['tone', 'noise', 'none'],
default: 'noise',
anyOf: audioAssetOptions,
default: '',
description: 'Type of audio to play during parent-coded lookaways'
},

Expand Down Expand Up @@ -353,6 +347,16 @@ var infantControlledTimingMixin = Ember.Mixin.create({
$(document).off('keyup.parentEndTrial');
},

// Expand lookawayTone based on baseDir if appropriate
didReceiveAttrs() {
let assets = this.get('assetsToExpand') ? this.get('assetsToExpand') : {};
let additionalAssetsToExpand = {
audio: ['lookawayTone']
};
this.set('assetsToExpand', mergeObjectOfArrays(assets, additionalAssetsToExpand));
this._super(...arguments);
},

didInsertElement() {
this.set('_isLooking', true); // Default assumption is child is looking; hold down key for lookaway.
this.set('_totalLookaway', 0);
Expand All @@ -377,15 +381,13 @@ var infantControlledTimingMixin = Ember.Mixin.create({
});

try {
let useLookawayTone = this.get('lookawayTone') !== 'none';
if (useLookawayTone) {
const baseDir = 'https://www.mit.edu/~kimscott/placeholderstimuli/';
let audioElement = $('<audio id="lookawayTone" loop></audio>');
$(`<source src='${baseDir}mp3/${this.get('lookawayTone')}.mp3' type='audio/mp3'>`).appendTo(audioElement);
$(`<source src='${baseDir}ogg/${this.get('lookawayTone')}.ogg' type='audio/ogg'>`).appendTo(audioElement);
$('#experiment-player > div > div').append(audioElement);
$('audio#lookawayTone')[0].volume = this.get('lookawayToneVolume');
let lookawayTones = this.get('lookawayTone_parsed') ? this.get('lookawayTone_parsed') : [];
let audioElement = $('<audio id="lookawayTone" loop></audio>');
for (let i = 0; i < lookawayTones.length; i++) {
$(`<source src='${lookawayTones[i].src}' type='${lookawayTones[i].type}'>`).appendTo(audioElement);
}
$('#experiment-player > div > div').append(audioElement);
$('audio#lookawayTone')[0].volume = this.get('lookawayToneVolume');
} catch (e) {
console.error(`Error setting lookaway tone: ${e}`);
}
Expand Down
6 changes: 3 additions & 3 deletions app/mixins/infant-controlled-timing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ endTrialKey [String | ``'q'``]
for this trial. You can look up the names of keys at https://keycode.info. Default is 'q'.

lookawayTone [String | ``'noise'``]
Type of audio to play during parent-coded lookaways - 'tone' (A 220), 'noise' (pink noise), or 'none'. These
tones are available at https://www.mit.edu/~kimscott/placeholderstimuli/ if you want to use them in
instructions.
Audio file to play during parent-coded lookaways play during parent-coded lookaways, e.g. tone or noise. This can
be either an array of ``{src: 'url', type: 'MIMEtype'}`` objects or a single string relative to ``baseDir/<EXT>``.
Sample tones are available at https://www.mit.edu/~kimscott/placeholderstimuli/.

lookawayToneVolume [Number | ``0.25``]
Volume of lookaway tone, as fraction of full volume (1 = full volume, 0 = silent)
Expand Down

0 comments on commit 3b0680f

Please sign in to comment.