Template control application in Python

I’m a novice programmer :wink:
I’m writing a simple template control application in Python.
Everything works very well, only I have one problem.
How to check if the template started the animation, stopped the animation or finished the animation?
My application needs to know what state the server and template are in.
(I use amcp-pylib for connection to server)

I only receive responses of this type from the server:
<SuccessResponse(data=[''], code=202, code_description='CG')>

and no information about the current status of the template.
I’m testing my application with a template made in loopic (https://www.loopic.io)

Usually that is done by an operator seeing it. The AMCP protocol does not automatically give feedback about the status of the template. You can try with INFO commands using pooling, but that is only a workaround.

Why? If we understand your use case better, we could help you better.

I tried to use INFO. The information returned is not enough.

OK, I’ll try to explain step by step what my application does and what the problem is:

  1. Using the application, I upload the template with the CG_ADD… command
  2. I select a line of text to be sent in the interface
  3. (one press “IN/OUT” BUTTON in the interface) With the CG_UPDATE command I send the text and CG_PLAY start the animation. The animation starts with the uploaded text and stops after expanding .
  4. (one press of the “IN/OUT” BUTTON in the interface) Using the same CG_UPDATE and CG_PLAY sequences, I run the closing sequence of the animation (one press of the “IN/OUT” BUTTON in the interface).

In this case, everything is OK.

The problem is when the user changes the selected line of text between point 3 and 4. Then the animation will expand with one text and collapse with another. This is unacceptable.
Once I knew what status the animation was in I could use the CG_UPDATE and CG_PLAY comments once and CG_NEXT to close the animation and the text content would not change.

The way I handle scenarios like this is to design the template to be a html page that connects back to the control software over websockets. That way you can do whatever communication you desire, and bypass AMCP entirely.
With this flow it is often possible to design multiple templates into a single html page that you run once, and fully control over the websocket connection.


In your precise scenario, it shouldn’t be hard to make a copy of what was sent in step 3, so that when they click in/out in 4, you can reuse what was last sent instead of what is currently selected.


It was discussed/suggested to allow html templates to add to the INFO XML or possibly osc info, a while back, but noone has implemented it. It would be fairly straightforward to implement that if someone with C++ experience was willing to, or for it to be sponsored. But live sending data back over AMCP is a much larger task which will need some thought on design, architecture, and backwards compatibility.

In my case, it’s probably the easiest. I also thought about bypassing this problem at the html template level. Unfortunately, as I wrote, I am a novice programmer :wink:
For now, I’m using a template I made at https://www.loopic.io
I’ve already tried to copy the data from the entered text layer to another, but unfortunately I fail :sleepy:

I see two problems here: First it seems you use CG PLAY for brining in AND taking out the template. The normal workflow uses a CG STOP command to take the template out. The second problem lies in the way you do your steps. The normal workflow is like this:

  1. Select a line of text to be sent and use the CG ADD command to load the template. You also send the data to the template using this command. So you use only one CG ADD for template loading and data setting. You can also play the template by setting AutoPlay to true. In case of AutoPlay = false this is done with a button called “Load” or “Prepare”. In case of AutoPlay = true this is done with the “Play” or “Start” button (or what you want to call it).
  2. In case of AutoPlay = false you need a button to play the template using CG PLAY.
  3. When you want to get rid of the template to click on a button called “Stop” or “Out” etc. that sends the CG STOP command.

So dependent on your preference (read AutoPlay true or false) you end up with either 3 or 2 buttons: For AutoPlay = false: “Load”, “Play” and “Stop”, for AutoPlay = true only “Play” and “Stop”.

In this case you never send a CG UPDATE command, that can mess things up.

I sometimes add a separate button for CG UPDATE called “Update” or the like to intentionally change content. But that does not always make sense. In case of a lower third for instance it’s better to take it out, the moment you see the typo, correct it and bring it back in instead of changing it on the fly.

Problems so far have been solved :slight_smile:
Completion of writing the application is getting closer.
But the next one is ahead of me :wink:
I’m trying to create a functionality that will monitor whether the server is up or down.
From what I read in various places, I found out that I should probably use OSC for this.
Unfortunately, I don’t know how to write it. I don’t understand how OSC communicates with the CasparCG server. Maybe someone can advise me on how to go about it. There are various ready-made python libraries that support OSC. But I don’t really know if I should use OSC server or client to check CasparCG status.

I am trying to use this solution:
https://github.com/attwad/python-os
https://python-osc.readthedocs.io/en/latest/index.html

I suspect that your final solution for server monitoring will use a combination of AMCP protocol and OSC status. The server emits status data about the server operation to connected clients plus any address/port provided in the casparcg.config predefined clients in the OSC segment. The OSC status data structure differs between server branches, so the format is very different between server 2.1.12_NRK and 2.3.3_LTS.

To use the OSC data from the server your client only has to listen for the OSC data from the server, it does not need to send an OSC messages to the server. Each OSC message normally has three segments - the addresss which is a bit like a url without the protocol header, the list of data parameter types in the message, and the data values associated with the message. The first two segments are multiples of 32 bits/4 bytes long, adding null characters if the actual data is less than a multiple of 4 bytes. Multiple messages may be wrapped into a single transmission using an OSC bundle. The server status data uses the bundle wrapper even if the bundle includes just a single message. Most OSC libraries manage the packing and unpacking of the message elements. When a clip is loaded to a channel the status data includes the name of the file, the frame rate, and the amplitudes of the audio tracks.

When examining any OSC messaging system I find the free Wireshark application (available here) a vital tool. Wireshark can be a steep learning curve for new users but its ability to show all network traffic is so useful. You have to enable the OSC filter support, but Wireshark does have display filters for OSC messages, and you can list just the OSC packets to simplify the user data displays.

There is also an AMCP message and response that you may find useful. I know this works in both the server 2.1.12_NRK and server 2.3.3_LTS. If you send ping (or PING) from the client to the server, the server responds with a simple PONG message. Note there is no status code returned with the PONG text.

There are a few notes about OSC data in CasparCG server and client (OSC can be used to trigger the SVT client actions) in my Introduction to CasparCG document available from github (here). Appendix B describes the structure of the OSC messages, and shows the OSC message as shown in Wireshark.

Andy.

P.S. I think there is a ‘c’ missing off the end of the github link (ie should be osc).