Recording is not happening with osc commands/run_file

osc_send ‘localhost’,51235, ‘/start-recording’,‘myGUID’
use_bpm 120
use_synth :piano

in_thread do
run_file ‘C:\songs\trackOne.rb’
#sleep 1

in_thread do
run_file ‘C:\songs\trackTwo.rb’
#sleep 1

osc_send ‘localhost’,51235, ‘/stop-recording’,‘myGUID’
sleep 0.5
osc_send ‘localhost’,51235, ‘/save-recording’,‘myGUID’,‘C:\Users\vinodv\Desktop\a.mp3’

The above code writes a a.mp3 file of size 256 kB. No sound is there in the file.

If the code is

100.times do
play :c4
sleep 1
Then the sound is recorded in the a.mp3 file.

Hmm you may be saving it as an .mp3 file but SP produces .wav files. Try saving it as a wav. You can always convert it using Audacity afterwards.
For a start rename your .mp3 as a .wav and see if it plays OK.

That also (.wav file) I tried. But no sound in .wav file.
Is there a problem with run_file/eval_file commands while recording?

The start recording and the stop recording will be sent at the same time, since there is no sleep in between them. You need to make it wait until the tracks have finished playing before sending the stop recording command.

1 Like

(Or sync on a cue event - one of those two :slightly_smiling_face: )

1 Like

I have modified with cue on a sync. still the recording is not happening.

Now recording is happening with sleep 72 between /stop and /save recording.

Remember the difference between run_file and eval_file - one runs the contents in a separate thread, so loops or threads which wrap run_file need to have sleeps or syncs in them in order to wait for the external file to finish executing - whereas eval_file runs the external file ‘in-place’ in the same thread - so any sleeps or syncs in the external file still affect the wrapping loop or thread.

Btw, your last example used cue and sync, but without those cue and sync commands there, it would most likely have behaved exactly the same, since all they did in this case was to start track one, and immediately start track two - which would have been exactly the same without the cue and sync there.
It’s not immediately clear in your last example whether you want each track to play simultaneously, or one after the other - but going with the code there, if you’re wanting them to start together, I assume also that you want the cue to happen after all the external files have finished running, so that you could tell Sonic Pi it’s ok to stop recording. So, you’d figure out which of the two external files was the longer running one, and place cue :tick at the end of it (or, if you end up using eval_file, placing the cue :tick just after the call to eval_file) - and then, just before the stop recording command, place sync :tick - to tell Sonic Pi to wait for that event before stopping the recording.

Hopefully that explains things a little - have a go rewriting it to use sync and cue in that manner if you like - I certainly think it’s easier than keeping track of sleep times :grinning_face_with_smiling_eyes: