Heya.
Here's a quick stab at it.
First thing, how to save clips? There are a few ways to do this, the one I find the easiest to understand is using selectMany.
Let's first create a subject (publishSubject) for your camera stream and I will simulate an Arduino using keyPresses. Essentially, clicking A and S will output a true or a false, respectively (FakeArduino -> TriggerState).
Now, how do we use this information to save clips?
We listen to TriggerState and look for a rising edge (false->true transition). We do this by simply looking for true values with a condition. For each rising edge, we trigger the "SelectMany (saveclip)". Inside we immediately subscribe to the camera stream (SubscribeWhen). And save the data until a falling edge (true-> false transition, Condition that only lets "false" pass) and use it to close the branch using "TakeUntil". This should take care of saving clips. How do we name them?
We load a full csv (CsvReader), convert it to a list that we can index, and send it to a behaviorSubject to use later. We can index these lists using the "index" node. To keep track of this index, I will add a second variable "currentFileIndex". All there is left to do is to grab an element from this row on each rising edge. To do that, we will take the current index (withLatestFrom * currentFileIndex) and index the list with it. (also we need to increment currentFileIndex by one. Add(1) -> MulticastSubject). Finally, we use the indexed string to name the video file. Make sure the number of trials is, at most, the number of rows in your csvFile. Otherwise, the workflow will crash. I did some quick tests and it seems to be working as intended but let me know if something does not behave as expected or if I was not clear in any of the steps.
Cheers,
Bruno