Filename generation via OSC message

447 views
Skip to first unread message

hinz....@googlemail.com

unread,
Sep 7, 2020, 9:08:27 AM9/7/20
to Bonsai Users
Hi Gonçalo,

I am trying to control an experiment through Matlab and record a video with Bonsai through a minimal workflow. Currently I am renaming the video files manually after every experiment, however I would like to automatically rename it through an OSC message from Matlab. I attached the faulty workflow, which throws the error: 'The specified connection name has no matching configuration'. 

I can see that the general idea works, since if I visualize the string value it shows the correct message (Filename), however it doesn't initialize if I connect the string value  to the externalized FileName property of the Videowriter.

Thanks for your help !

Best,
Julian

hinz....@googlemail.com

unread,
Sep 7, 2020, 9:19:32 AM9/7/20
to Bonsai Users
It seems like I can't attach the workflow so I attached a photo of it.Workflow.bmp

Bruno Cruz

unread,
Sep 8, 2020, 7:15:55 AM9/8/20
to Bonsai Users
Hey,
Do you really need to use OSC? If you just want to start a new workflow each time from matlab I have attached a couple of functions I wrote. Just "externalize property" in the workflow (right click on a node) and give it a unique name (e.g. VideoPath). These variables will be used to call bonsai with specific settings using the CLI.

The function takes as inputs:
workflowPath -  just the path of the workflow you want to use
addOptArray - cell array with settings. For instance if you want to see the path this variable would be : {'VideoPath', 'C:\.....'}. More settings can be set, jsut add them in pairs
bonsaiExePath - path to bonsai (the function tries to find it automatically but it might fail)
external - whether you want to run the command in matlab (which makes it "busy") or if you want to just launch an external window.

Cheers,
B
runBonsaiWorkflow.m
bonsaiPath.m

hinz....@googlemail.com

unread,
Sep 9, 2020, 5:46:38 AM9/9/20
to Bonsai Users
Hi Bruno,

Yes, indeed I do not need to send the filename via OSC ! After minimal tweaking your script worked like a charm, thanks heaps :) One question that came tomy mind yesterday, was how you deal with stopping the Bonsai recording and closing the program ?
 When I tried the standard: !taskkill -f -im Bonsai64.exe , Bonsai closed as expected, however the videos were unfortunately not saved because I didn't stop the recording, but just crashed the program. Did you find an automatic solution to this ?

Best,
Julian

bruno...@neuro.fchampalimaud.org

unread,
Sep 9, 2020, 5:55:17 AM9/9/20
to Bonsai Users
From my experience it is not worth it, never found an easy solution. taskkill doesnt work because the default behavior is to kill the application without giving a chance to normally close it. If you give it a chance to close you still need to click on the confirmation dialog. Alternatively I tried something whereby i wrote a small macro that matlab would call and would click "stop" on bonsai and close everything but it failed more often than it worked tbh ahah.
At th end of the day, it was just not worth it, and I always ended up closing everything manually :P.
If you do find an easy solution let me know, i'd love to upgrade the code!
Cheers
B

Vincent Prevosto

unread,
Sep 9, 2020, 9:48:47 AM9/9/20
to Bonsai Users
Hi,
If instead of a live video flow, the input came from a file, the Bonsai workflow would terminate properly after the last frame (I think that relates to the difference between hot and cold observables). So, in Julian's case, maybe the solution is to stop the the video flux broadcast with a TakeUntil operator? (Maybe adding a PublishSubject expression in the mix? ). I haven't tested that, but the point is to find a way to make the workflow stop running by itself. 
Best,
Vincent

Gonçalo Lopes

unread,
Sep 9, 2020, 9:17:06 PM9/9/20
to Vincent Prevosto, Bonsai Users
Yes, as Vincent suggested, having the workflow finish by itself would be the safest way to prevent video loss. This unfortunately requires some kind of external control over the Bonsai workflow, which you can do through OSC, but there are 2 more "unconventional" ways which might work through MATLAB (although any of them requires investigation):

 1. pipe a text input through standard in: Bonsai supports reading lines from the "console" standard input using the ReadLine source. If you had a way to pipe a standard input stream from matlab into the process you create, then you could write a line into the stream and use that event to stop Bonsai. Of course, this would also be a direct line of communication to pass in all kinds of other data. Incidentally WriteLine would have the same effect going the other way if you found a way to redirect the standard output.


  2. call Bonsai direct from MATLAB: incidentally the previous link also points out the interesting fact that MATLAB can just call a .NET library and/or applications directly. This means you would be able to simply instantiate a Bonsai workflow straight in MATLAB and simply pass the config data and potentially even call inputs/functions directly without having to spawn a subprocess.

These are just food for thought for possible things, there is definitely room to have a more seamless integration between Bonsai and MATLAB but would require a bit of work.

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/22085ab4-6f34-48f2-9ee3-c7130392429bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages