Previous topicNext topic

Effective use of OSC file reload

Questions, comments, feedback, etc.
Post Reply
SelfDrivingCarp
Posts: 8
Joined: Sat Jan 06, 2024 5:44 am

Effective use of OSC file reload

Post 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?
Magic
Site Admin
Posts: 3441
Joined: Wed Apr 09, 2014 9:28 pm

Re: Effective use of OSC file reload

Post by Magic »

Have you tried increasing the delay, say from .25 to 1?
Sadler
Posts: 1143
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: Effective use of OSC file reload

Post 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.
SelfDrivingCarp
Posts: 8
Joined: Sat Jan 06, 2024 5:44 am

Re: Effective use of OSC file reload

Post 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.
SelfDrivingCarp
Posts: 8
Joined: Sat Jan 06, 2024 5:44 am

Re: Effective use of OSC file reload

Post 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.
Sadler
Posts: 1143
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: Effective use of OSC file reload

Post 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.
Magic
Site Admin
Posts: 3441
Joined: Wed Apr 09, 2014 9:28 pm

Re: Effective use of OSC file reload

Post 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?
SelfDrivingCarp
Posts: 8
Joined: Sat Jan 06, 2024 5:44 am

Re: Effective use of OSC file reload

Post 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.
SelfDrivingCarp
Posts: 8
Joined: Sat Jan 06, 2024 5:44 am

Re: Effective use of OSC file reload

Post 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 3370 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.
Attachments
PowerInhibitsFeature.magic
(1.2 KiB) Downloaded 433 times
SelfDrivingCarp
Posts: 8
Joined: Sat Jan 06, 2024 5:44 am

Re: Effective use of OSC file reload

Post 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!
Magic
Site Admin
Posts: 3441
Joined: Wed Apr 09, 2014 9:28 pm

Re: Effective use of OSC file reload

Post by Magic »

Yes, that's correct. If an upstream module is powered off, the downstream modules don't get OSC commands.
Post Reply