Skip to content

Commit 5e23a0a

Browse files
committed
BF: Get current loop for mic during run rather than in boilerplate
1 parent d7049ad commit 5e23a0a

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

psychopy/experiment/components/microphone/__init__.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,6 @@ def writeRoutineEndCode(self, buff):
399399
def writeRoutineEndCodeJS(self, buff):
400400
inits = getInitVals(self.params)
401401
inits['routine'] = self.parentName
402-
if len(self.exp.flow._loopList):
403-
inits['loop'] = self.exp.flow._loopList[-1].params['name']
404-
inits['filename'] = f"'recording_{inits['name']}_{inits['loop']}_' + {inits['loop']}.thisN"
405-
else:
406-
inits['loop'] = ""
407-
inits['filename'] = f"'recording_{inits['name']}'"
408402
if inits['transcribeBackend'].val in allTranscribers:
409403
inits['transcribeBackend'].val = allTranscribers[self.params['transcribeBackend'].val]
410404
# Warn user if their transcriber won't work online
@@ -418,20 +412,22 @@ def writeRoutineEndCodeJS(self, buff):
418412
code = (
419413
"// stop the microphone (make the audio data ready for upload)\n"
420414
"await %(name)s.stop();\n"
415+
"// construct a filename for this recording\n"
416+
"thisFilename = 'recording_%(name)s_' + psychoJS.experiment.currentLoop.name + '_' + psychoJS.experiment.currentLoop.thisN\n"
421417
"// get the recording\n"
422418
"%(name)s.lastClip = await %(name)s.getRecording({\n"
423419
)
424420
buff.writeIndentedLines(code % inits)
425421
buff.setIndentLevel(1, relative=True)
426422
code = (
427-
"tag: %(filename)s + util.MonotonicClock.getDateStr(),\n"
423+
"tag: thisFilename + '_' + util.MonotonicClock.getDateStr(),\n"
428424
"flush: false\n"
429425
)
430426
buff.writeIndentedLines(code % inits)
431427
buff.setIndentLevel(-1, relative=True)
432428
code = (
433429
"});\n"
434-
"psychoJS.experiment.addData('%(name)s.clip', %(filename)s);\n"
430+
"psychoJS.experiment.addData('%(name)s.clip', thisFilename);\n"
435431
"// start the asynchronous upload to the server\n"
436432
"%(name)s.lastClip.upload();\n"
437433
)

0 commit comments

Comments
 (0)