Skip to content

Commit

Permalink
BF: Get current loop for mic during run rather than in boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
TEParsons committed Apr 21, 2022
1 parent d7049ad commit 5e23a0a
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions psychopy/experiment/components/microphone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,6 @@ def writeRoutineEndCode(self, buff):
def writeRoutineEndCodeJS(self, buff):
inits = getInitVals(self.params)
inits['routine'] = self.parentName
if len(self.exp.flow._loopList):
inits['loop'] = self.exp.flow._loopList[-1].params['name']
inits['filename'] = f"'recording_{inits['name']}_{inits['loop']}_' + {inits['loop']}.thisN"
else:
inits['loop'] = ""
inits['filename'] = f"'recording_{inits['name']}'"
if inits['transcribeBackend'].val in allTranscribers:
inits['transcribeBackend'].val = allTranscribers[self.params['transcribeBackend'].val]
# Warn user if their transcriber won't work online
Expand All @@ -418,20 +412,22 @@ def writeRoutineEndCodeJS(self, buff):
code = (
"// stop the microphone (make the audio data ready for upload)\n"
"await %(name)s.stop();\n"
"// construct a filename for this recording\n"
"thisFilename = 'recording_%(name)s_' + psychoJS.experiment.currentLoop.name + '_' + psychoJS.experiment.currentLoop.thisN\n"
"// get the recording\n"
"%(name)s.lastClip = await %(name)s.getRecording({\n"
)
buff.writeIndentedLines(code % inits)
buff.setIndentLevel(1, relative=True)
code = (
"tag: %(filename)s + util.MonotonicClock.getDateStr(),\n"
"tag: thisFilename + '_' + util.MonotonicClock.getDateStr(),\n"
"flush: false\n"
)
buff.writeIndentedLines(code % inits)
buff.setIndentLevel(-1, relative=True)
code = (
"});\n"
"psychoJS.experiment.addData('%(name)s.clip', %(filename)s);\n"
"psychoJS.experiment.addData('%(name)s.clip', thisFilename);\n"
"// start the asynchronous upload to the server\n"
"%(name)s.lastClip.upload();\n"
)
Expand Down

0 comments on commit 5e23a0a

Please sign in to comment.