CasparCG

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bern333
Posts: 25
Joined: Tue Aug 02, 2016 11:03 am

CasparCG

Post by bern333 » Tue Aug 02, 2016 11:45 am

I've hunted the forum and the web, and keep finding the same questions asked but never answered properly, so please could someone who knows, post for all of us who have endlessly searched and failed......

I've build a lower thirds CasparCG client in LiveCode. I need to get two lines of text to appear over my Flash template. I can do this in the supplied CasparCG client, now I want to do it in my client.

I need to do an CG ADD command with added xml eg -

CG 1 ADD 0 "demo/test" 1 "<templateData><componentData id=\"f0\">
<data id=\"text\" value=\"Niklas P Andersson\">
</data> </componentData><componentData id=\"f1\">
<data id=\"text\" value=\"developer\">
</data></componentData><componentData id=\"f2\">
<data id=\"text\" value=\"Providing an example\"></data> </componentData></templateData>"

That's the example from the CasparCG documentation.

Livecode seems be happy if you remove " and replace with & quote &, but falls over when you get to the forward slashes - </componentData></templateData> . Escaping the escape codes doesn't work as Livecode keeps \/ in the string, and CasparCG doesn't like that.


Please - a simple tutorial for us idiots rather than references to other posts or projects would help me, and, as it turns out, lots of other people

Thank you

Bernard Newnham

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: CasparCG

Post by Klaus » Tue Aug 02, 2016 12:48 pm

Hi Bernard,

1. welcome to the forum! :D
2. Sorry, but what exactly is your question?


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: CasparCG

Post by jacque » Tue Aug 02, 2016 7:55 pm

This looks like a mostly-escaped string that you can use intact except for a some minor escaping additions. Use the LC "format" function:

Code: Select all

  put format("CG 1 ADD 0 \"demo/test\" 1 \"<templateData><componentData id=\"f0\"><data id=\"text\" value=\"Niklas P Andersson\"></data> </componentData><componentData id=\"f1\"><data id=\"text\" value=\"developer\"></data></componentData><componentData id=\"f2\"><data id=\"text\" value=\"Providing an example\"></data> </componentData></templateData>") into tCode 
I had to add escape characters to the quotes around "demo test" and the start and end of the XML, as well as add quotes at the front and end of the entire string. Note this is only one single line, so ignore line wrap. The resulting string is:
CG 1 ADD 0 "demo/test" 1 "<templateData><componentData id="f0"><data id="text" value="Niklas P Andersson"></data> </componentData><componentData id="f1"><data id="text" value="developer"></data></componentData><componentData id="f2"><data id="text" value="Providing an example"></data> </componentData></templateData>
After you get the string into the tCode variable, send the variable.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: CasparCG

Post by Klaus » Tue Aug 02, 2016 8:20 pm

AHA! :D


Your message contains 7 characters. The minimum number of characters you need to enter is 10.

bern333
Posts: 25
Joined: Tue Aug 02, 2016 11:03 am

Re: CasparCG

Post by bern333 » Tue Aug 02, 2016 8:39 pm

1. welcome to the forum! :D
2. Sorry, but what exactly is your question?
1. Thank you
2 The string in the original post is what one has to send to CasparCG in order to do the job required. It contains lots of slashes - the forward ones are xml and the backward ones are escapes for Caspar. Livecode doesn't seem to like these too much, especially the forward slashes. I've tried various versions of & quote & but mostly I get to </data> and it refuses to play.

I've looked extensively at this forum and others and this seems to be a common Livecode problem, and not just with CasparCG.

Lots of people trying to do this job are tv people like me with some programming knowledge but not actually programmers, and as far as I can see are generally like me trying to do a charity job for someone. All over the place these people are asking pretty much the same question.

...and thank you Jacque. That's the first time I've seen format - and the first time Livecode hasn't thrown a fit at the string. A great leap forward!! Not that it works at the CasparCG end, but that's probably my fault for writing the command wrongly.

Hooray (I think) - days of really annoying research may be complete, and the result is here for others to reference.

Thank you

B

bern333
Posts: 25
Joined: Tue Aug 02, 2016 11:03 am

Re: CasparCG

Post by bern333 » Wed Aug 03, 2016 9:11 am

Sadly that didn't work. The string has to arrive at CasparCG with the escapes intact.

This from the CCG log when sent by the supplied CCG client (not suitable for this task otherwise I'd use it) -

Code: Select all

CG 1-20 ADD 1 "LOWER2" 1 "<templateData><componentData id=\"f0\"><data id=\"text\" value=\"bern\"/></componentData><componentData id=\"f1\"><data id=\"text\" value=\"boss\"/></componentData></templateData>"\r\n
Which works, of course.

This from Livecode using the Jacque method -

Code: Select all

CG 1-20 ADD 1 "lower2" 1 "<templateData><componentData id="f0"><data id="text" value="bern"></data> </componentData><componentData id="f1"><data id="text" value="boss"></data></componentData></templateData>\r\n
No escape codes and Flash sends a 1090 error - "XML parser failure: element is malformed"

Any ideas please?

Bernie

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: CasparCG

Post by Klaus » Wed Aug 03, 2016 11:39 am

Hi Bernie,

thanks for the explanation, but I am still unsure if you have problems to format a string
before you send it to Caspar or parsing some XML received from Caspar?

What did you script so far?
How do you create that strings?


Best

Klaus

bern333
Posts: 25
Joined: Tue Aug 02, 2016 11:03 am

Re: CasparCG

Post by bern333 » Wed Aug 03, 2016 3:14 pm

So far I have the main Livecode part of the application more or less done. The requirement is to make what are called "lower-third supers" in tv. This is the text at the bottom of the screen that gives the name and occupation of the speaker on a news programme. CasparCG is a free server/client application made by Swedish TV SVT. You run the server, and a client - either the supplied one or one you write yourself - sends commands and info. CasparCG is used all over the world because it's incredibly flexible. You'd think that what I need would be all over the place, but it isn't. When (if) this works I will publish mine for free so that anyone can do what I've been trying to do for ages.

So - the way in which supers get on and off is fixed by a Flash template loaded separately into the CasparCG server, but the actual text content is different for everyone, and is supplied by a client application.

Livecode would seem a natural for this task if it's a charity job - CasparCG is free, and so is Livecode.

I've now largely completed the front end. Users will input two fields, one for the name and one for the occupation. These are stored in SQLite till needed. Another card is the edit and output card which uses a datagrid for the various operations, though so far I haven't connected that to the actual output socket as i can't get the application to sent a correctly formatted test string..

Livecode connects to the server via a socket and sends a set pattern of command and text to make a super appear and disappear. The string you ask about comes from the example at the CasparCG wiki in the CasparCG_2.0_AMCP_Protocol Template_Data section (can't do URL). All that's required of Livecode is to add the name and occupation fields to the preset string.

What I've been trying to do for days now is to get Livecode to send exactly this -

Code: Select all

CG 1-20 ADD 1 "LOWER2" 1 "<templateData><componentData id=\"f0\"><data id=\"text\" value=\"bern\"/></componentData><componentData id=\"f1\"><data id=\"text\" value=\"boss\"/></componentData></templateData>"\r\n
The words "bern and "boss" are the texts which go on the screen, everything else is either the command - CG 1-20 ADD 1 "LOWER2" 1 - or a fixed pattern of escaped xml that Flash needs.

This exact code works because this is what the CCG supplied client sends to get the super onto the screen, and I've done it many times now in that client and in the server console. Now I need it to work in my much more user friendly Livecode client.

Everything pretty much works apart from this crucial problem which I don't seem to be able to solve. I've searched a huge amount, but only find other people asking variations on the same question and not getting an answer. So I gave up and asked here.

Bernie

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: CasparCG

Post by Klaus » Wed Aug 03, 2016 3:29 pm

Please post (parts of) the script that will build/create the string you need to send back to Caspar!

bern333
Posts: 25
Joined: Tue Aug 02, 2016 11:03 am

Re: CasparCG

Post by bern333 » Wed Aug 03, 2016 4:24 pm

I don't have any parts, just the complete string. Livecode doesn't do any more than insert the name and occupation - in this case "bern" and "boss" - into the preset string that will work in CasparCG. Livecode variables sourced from Sqlite will substitute for "bern" and "boss".

If I can make Livecode send this I can make it send any variation.

B

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: CasparCG

Post by jacque » Wed Aug 03, 2016 4:31 pm

Now that I see what you need exactly, the solution is easy. Create a custom property, or even a hidden field, that holds the template XML text. Substitute the two replacement strings with placeholders in the template text. For example, *NAME* and *OCCUPATION*.

To use it, put the template into a variable, use the replace command to replace each placeholder with the user entries in the fields, and it's done.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: CasparCG

Post by Klaus » Wed Aug 03, 2016 4:32 pm

bern333 wrote:I don't have any parts, just the complete string. Livecode doesn't do any more than insert the name and occupation - in this case "bern" and "boss" - into the preset string that will work in CasparCG. Livecode variables sourced from Sqlite will substitute for "bern" and "boss".

If I can make Livecode send this I can make it send any variation.

B
So you (more or less) only do something like this:

Code: Select all

...
replace "bern" with "something else" in tString4Caspar
replace "boss" with "something different" in tString4Caspar
...
?
Hm, sorry, then I actually don't get what your problem is? 8)

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: CasparCG

Post by Klaus » Wed Aug 03, 2016 4:37 pm

Ah, I'm getting there slowly, looks like my question was/is part of the solution. :D
Yes, what Jaques said, you can also use a (hidden) field for this!

bern333
Posts: 25
Joined: Tue Aug 02, 2016 11:03 am

Re: CasparCG

Post by bern333 » Wed Aug 03, 2016 5:22 pm

Jacque you are an amazing person. Finally, finally it works!

Thank you many times. I've been working on this for days and days and getting nowhere, with no clues out there. I'd show you a picture but this system won't let me.

Thanks again

Bernie

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: CasparCG

Post by jacque » Wed Aug 03, 2016 5:33 pm

Glad to help. You'll be able to add images and URLs to your posts after you have a certain number of posts here, ten I think. For now I'm just vicariously enjoying your eureka moment. ;-)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply