Page 1 of 1

Effective use of OSC file reload

Posted: Sat Jan 06, 2024 6:15 am
by SelfDrivingCarp
I use Magic for visuals during a DJ live stream. I've written some custom software that connects to chat and provides commands for interaction. One allows channel moderators to give a shoutout to someone. I've set up an overlay scene with a bunch of fields mapped to OSC addresses. The software will write the subject's name to a text file then send OSC messages to Magic to animate the overlay fading in, moving, and fading out. Everything works perfectly except for the file reload; sometimes it doesn't work.

Here's the sequence:
- Write the new text file, flush, and close
- Wait 0.25 seconds
- Send 1.0 to the text file reload control
- Wait 0.25 seconds
- Send 0.0 to the text file reload control
- Wait 5.0 sec
- ...a bunch of other OSC messages and waits.

The rest of the OSC-driven animation is smooth. It's not obvious that there are any OSC messages getting dropped. I understand that loading the file is asynchronous, but I'd expect it to be done after 5 seconds or so that it would be done. Is there a way I can make this reliable?

Re: Effective use of OSC file reload

Posted: Mon Jan 08, 2024 9:37 pm
by Magic
Have you tried increasing the delay, say from .25 to 1?

Re: Effective use of OSC file reload

Posted: Tue Jan 09, 2024 4:59 pm
by Sadler
If it is a race or blocking condition making it unreliable then perhaps working around it would be better. For example, continually re-loading the text file from the text file node using an oscillator. At the very least, it might help you debug/diagnose.

Re: Effective use of OSC file reload

Posted: Thu Jan 11, 2024 3:21 am
by SelfDrivingCarp
Magic wrote: Mon Jan 08, 2024 9:37 pm Have you tried increasing the delay, say from .25 to 1?
I've tried changing all the 250ms sleeps to a full second and I still get the same behavior. Sometimes it doesn't reload at all. The rest of the OSC events are delivered, showing the animation. If I disable the Reload binding to OSC and click reload manually it works as expected.

Re: Effective use of OSC file reload

Posted: Thu Jan 11, 2024 3:37 am
by SelfDrivingCarp
Sadler wrote: Tue Jan 09, 2024 4:59 pm If it is a race or blocking condition making it unreliable then perhaps working around it would be better. For example, continually re-loading the text file from the text file node using an oscillator. At the very least, it might help you debug/diagnose.
Cool idea for a diagnostic! So I set reload to a sine oscillator. I then ran a bash loop that would go to sleep for 0.8 seconds and then write the current time with seconds to the text file, repeating indefinitely. The magic window showed a update to the text in time ranges varying from 3 to 11 seconds, at least for the couple of minutes that I watched it.

This is a case where just being able to send an OSC string to the Text (not TextFile) module would be great. I understand that currently Magic only does OSC floats.

Re: Effective use of OSC file reload

Posted: Thu Jan 11, 2024 11:48 am
by Sadler
I ran this batch file:

Code: Select all

:a
echo %time% > time.txt
timeout /t 1 /nobreak
goto a
And used the triangle oscillator set to 2.0.

While the batch file executed, Magic updated the text once per second.

Re: Effective use of OSC file reload

Posted: Thu Jan 11, 2024 5:50 pm
by Magic
I would be surprised if this is some kind of issue in Magic. Are you sure your text file is actually being written to, saved, and closed properly?

Re: Effective use of OSC file reload

Posted: Fri Jan 12, 2024 4:33 am
by SelfDrivingCarp
Seems likely that it's something in my program. I did Sadler's batch file and got the desired result: the Text module reloads about every second.

The bash loop I did was in WSL as I'm a lot handier with the Linux command line than the Windows one. Quite possible there's IO shenanigans between the two environments.

I made a minimal test program in Go and Magic was doing the reloads about every second:

Code: Select all

func main() {
	client := osc.NewClient("localhost", 8765)
	for {
		time.Sleep(time.Second)
		timestamp := time.Now().Format(time.RFC3339)
		if err := os.WriteFile(filePath, []byte(timestamp), 0600); err != nil {
			fmt.Printf("writing file: %s", err)
			break
		}
		fmt.Println("wrote ", timestamp)

		msg := osc.NewMessage("/osc/overlay/message/reload")
		msg.Append(1.0)
		if err := client.Send(msg); err != nil {
			fmt.Printf("error sending 1: %s", err)
			break
		}
		time.Sleep(time.Second / 4)
		msg = osc.NewMessage("/osc/overlay/message/reload")
		msg.Append(0.0)
		if err := client.Send(msg); err != nil {
			fmt.Printf("error sending 0: %s", err)
			break
		}
	}
}
I appreciate the sanity-checking.

Re: Effective use of OSC file reload

Posted: Fri Jan 12, 2024 5:13 am
by SelfDrivingCarp
I spoke too soon.

My original program works reliably when the scene I'm showing is the Overlay scene.

I have a "Selector" scene which has a bunch of other scenes going into an InputSelector; viewers can use chat commands to change scenes. That scene places the Overlay scene over the InputSelector going into the Magic node. The Overlay passes through a Transparency node before the Magic node. Using OSC, I power off the transparency node so that I can arrange things in the Overlay scene, then fade the overlay in. When I'm viewing this Selector scene, the TextFile reload doesn't happen.

I've attached a minimal magic file that reproduces the issue.
repro.png
repro.png (50.87 KiB) Viewed 4193 times
When the power is turned off on the Transparency node, the Triangle Oscillator on the TextFile node stops. This seems to happen with OSC events as well. My guess is that, as an optimization, nodes upstream of the powered-off node aren't getting displayed they also aren't getting events.

Re: Effective use of OSC file reload

Posted: Fri Jan 12, 2024 5:32 am
by SelfDrivingCarp
I've worked around this by changing the order of animation events. Now I set the Transparency to 1.0 so nothing from the Overlay shows, then power on the Transparency node, then send the file reload messages and start the fade in.

This is working reliably. Thanks for helping me figure out the issue!

Re: Effective use of OSC file reload

Posted: Fri Jan 12, 2024 5:17 pm
by Magic
Yes, that's correct. If an upstream module is powered off, the downstream modules don't get OSC commands.