C#Macro Button

13 posts / 0 new
Last post
Offline

Location

Columbus,
United States
Joined: 25/02/2016
Posts: 7
C#Macro Button

i posted something similar to this on the BMD forum

i am trying to make an app that 

Connects to my switcher 

Has one button that will call a macro. 

 

actually i want more than that. But that is the part that i cannot figure out. at this point. 

i am having trouble with the callback. i have connected to the switcher 

and have set up a class and have the IBMDSwitcherMacroControl parented in. 

set up processes for the function i though i needed. (probably did that wrong)

and i hit my button and it crashes.

no error no compile error just a crash. 

i did not see any loops that i stepped in to. 

 

any advice would be helpful. 

Point me to an example or any thing.

 

Thanks John.

 

imorrish's picture
Offline

Location

Wellington
New Zealand
Joined: 05/01/2015
Posts: 80
Reply on BMD

Reply on BMD forum

https://forum.blackmagicdesign.com/viewtopic.php?f=12&t=45033

 

Offline

Location

Columbus,
United States
Joined: 25/02/2016
Posts: 7
the real problim

well ya

looked in to this i guess i just don’t have the c# skills just yet.

not sure why BMD interface has to be so much more complicated then most of the others  out there, at least the ones i have worked with. 

i can talk to my Barco Gear with TCP or UDP commands. 

not sure why i cant do that here. 

i know there are pi and Arduino works arounds to do that. 

i was just trying to keep the parts in the system that could fail to a min. 

i might have to go that way it looks. 

or use Justmacros to act as a web gui (reading about that now). 

the real problem that i am trying to solve:

i have a set up that relies on the super source a lot. 

all the looks are set up in the Super source via macros,

and we will change boxes live on air.  

inadvertently some one changes a DSK fill by mistake or reroute something.  i even set my DSK cut to a NHL hockey game once....(why was there a hockey game in the switcher?)

all i was doing was changing a macro and hit the wrong button.

my dsk was on air.  it sucked, got caught ...

i have a windows surface tablet on an arm next to the 2 ME controller.  the problem there is no matter what rez i set the surface pro to, the BMD app never gets large enough to use.  

so make my own app right. 

Sounds easy enough... not for some one that only know she basic c#  it seams. 

Offline

Location

Columbus,
United States
Joined: 25/02/2016
Posts: 7
programming.... the need to solve puzzles.

am i thinking abiout this wrong. 

1) set up a callback 

2) send request to switcher for indexes of macros. 

3) watch callback for changes.

may be i dont get the prosess correctly

 

JohnBengston's picture
Offline

Location

London
United Kingdom
Joined: 14/01/2012
Posts: 2144
Start by checking your crash

Start by checking your crash isn't the result of the project with the wrong threading model appled.

https://forum.blackmagicdesign.com/viewtopic.php?f=12&t=36252&p=232922&hilit=c%23+thread#p232693

If that doesn't improve things for you then read this:

https://forum.blackmagicdesign.com/viewtopic.php?f=12&t=41964

It goes through all the steps necessary to implement an AUX Changed callback in C#., Every single part of the SDK/API works in exactly the same way, and it's pretty standard COM stuff.

Where they differ from the industry standards is in th\t they like to re-use Interface names, giving old-interfaces new names, they have even been known to change interface definitions without generating new GUIDs. This is covered towards the end of the topic, as there was a fairly major change to the main Switcher Input interface around 6.6.

It would help others help you, if you chose to post what code you have or a subset of it which can be loaded and tested by others.

But Yeah, you are thinking about it wrong. Sequence is:

  • Query (or cast in C#) IBMDSwitcher, for a IBMDSwitcherMacroPool
  • Create an object which exposes IBMDSwitcherMacroPoolCallback, which is just one function "Notify"
  • Query (or cast in C#) IBMDSwitcher, for a IBMDSwitcherMacroControl
  • Create an object which exposes IBMDSwitcherMacroControlCallback which is again one function "Notify"
  • Use the IBMDSwitcherMacroPool.AddCallback()  and IBMDSwitcherMacroControl.AddCallback() passing your objects.
  • Call IBMDSwitcherMacroPool.GetMaxCount to find out the maximum number of macros supportted on a mixer model. i.e. a 2ME supports more than a 1ME.
  • Now Loop around from 0 to Max Macros calling IsValid for every slot. Just becuase you find an invalid macro at an address, doesn't mean there won't be a valid one later, so keep track of what macros are valid and which ones aren't.
  • For every Valid Macro Slot position, call IBMDSwitcherMacroPool.GetName() and IBMDSwitcherMacroPool.GetDescription(), hold in your list of valid macros
  • When a user runs a macros your object implementing IBMDSwitcherMacroControlCallback.Notify() will fire passing bmdSwitcherMacroControlEventTypeRunStatusChanged.
  • Synchronise the event handler code with your main appliction thread.
  • Call IBMDSwitcherMacroControl.GetRunStatus() which will give you the index of the macro which is running, whether Loop is enabled on the current macro, and most importantly one of 3 status flags "IDLE" (nothing is now running), "RUNNING" (you can match the index from GetRunStatus to your list and determine which macro is running) or "WaitingForUser" (means the running Macro is in USERWAIT state).
  • Act accordingly based on GetRunStatus which you need to call from your main thread, as a result of have the notify triggered in your callback object from whatever thread the API is using, safest to always synchronise it, or maintain an internal stack of events triggered by the callback objects and process them in a subthread of your own.

Obviously........ it is far easier in Just Macros:

one line:

ATEMMixerSetNameMatchingEnabled(1, "TRUE")

Then create macros in JustMacros that have the same name as you have defined on the ATEM. When a BMD Macro runs on the desk, the JM macro will be running within 5 milliseconds (on a resonable PC) of the user operting the button on the mixer surface, certainly well within a frame.

Or to enumerate them and get their "Macro Numbers", 3 lines separated over 9 for readability.
for i = 1, ATEMMixerMacrosGetMaxCount( 1 ) do
    if ATEMMixerMacrosGetIsValid( 1, i ) == true then
       VSLog( "   " .. LPad( i, 3 ) ..
              "   " .. RPad( tostring( ATEMMixerMacrosGetIsValid( 1, i ) ), 7 )           ..
              "   " .. RPad( tostring( ATEMMixerMacrosGetHasUnsupportedOps( 1, i ) ), 7 ) ..
              "   " .. RPad(           ATEMMixerMacrosGetName( 1, i ), 45 ) ..
              "   " );
    end;
end;
 
And to run it's just one line of code so to run macro 10 on mixer 1 it would be:
 
ATEMMixerMacrosRun( 1, 10 )

Offline

Location

Columbus,
United States
Joined: 25/02/2016
Posts: 7
Thank you.

Thank you for your help. 

i have never undertaken any thing using COM
befor.  ( Not True i did satart a project with the Project Cars SDK once, it was a great idea) 

i get lost every time i read about implemting COM in c#

"Obviously........ it is far easier in Just Macros:" 

Yep it is.  and that is what we have been testing out.

but i started this project and i realy want to understand how it works.

not just for this but for other things as well.   

i find it better to have a project, it helps me learn.

And i cant Let this computer beat me again.... im sure you understand...... 

 

 

JohnBengston's picture
Offline

Location

London
United Kingdom
Joined: 14/01/2012
Posts: 2144
.net and COM are strange

.net and COM are strange bedfellows most definately - but "it kinda works", even when all you want to do is dereference a pointer to an interface e.g. the BMD ATEM iterators in C# are a very weird affair. I think it's do to with reference counting on COM interfaces, but I too get bored at this level of geek-ish-ness, and I started out programming in Assembler on 8086s and CP/M.

I've spent huge amounts of time over many years writing bespoke automation software for big broadcasters, but the truth is there is just no way for small production entities (the likes of which make up the majority of BMD ATEM customers) to justify this kind of expense in man-hours. Even big broadcasters mostly look for off-the-shelf solutions these days (cost cutting).

Hence JM.......

If I have read this topic correctly, it started out as a problem with high res screens and the BMD app not scaling - that's a long running complaint, although originally it was it wouldn't scale small enough for low-res displays - funny!

Keep your eye on this topic:

http://www.atemuser.com/forums/atem-vision-mixers/blackmagic-atems/just-macros/html-gui#comment-14355

The topic will end having implement the basics of the BMD app in a Browser window, which will scale fine for you.

 

imorrish's picture
Offline

Location

Wellington
New Zealand
Joined: 05/01/2015
Posts: 80
Well there is no way I can

Well there is no way I can write 10K lines of C# in a day ;-) At my rate it will be a year to even get close to the ATEM functionality you have in JM.

But I did make progress today with one function

add-type -path 'C:\Users\imorrish\Documents\GitHub\atemlib\SwitcherLib\bin\Debug\SwitcherLib.dll'
$atem = New-Object SwitcherLib.Switcher("192.168.1.8")
$atem.Connect()

$i=0; do {$macro = $atem.GetMacro($i)
            If($macro[2] -eq 'true'){
                "Title: $($macro[0]), Description: $($macro[1])"}
            $i +=1}
        until($i -eq $atem.GetMacroCount()-1)

 

JohnBengston's picture
Offline

Location

London
United Kingdom
Joined: 14/01/2012
Posts: 2144
It won't be a year mate, a

It won't be a year mate, a lot of that 30K lines of the initial build was copy-pasting and then changing IID_s and tweaking Notify handlers, don't get me wrong, those 3 days were each 18-19 hours long, and I looked like a zombie at the end of it!! Addiction..... it's a real problem for me.... but I guess a coding addiction is better than drugs or alcohol.

It's a very interesting project you are doing with PowerShell, in JustMacros we have a command line utility called JM.exe, which I dump into my windows directory (to put on the path) on any machine I need to recall automation actions from.

http://www.atemuser.com/forums/atem-vision-mixers/blackmagic-atems/just-macros/launching-script-command-line

Then I can put into a shell script a command like

JM localhost 39812 ATEMMixerMECut(1,1)

where param1 is the host name of the JustMacros machine, param2 is the remote access port JM is using and the rest is a Lua script, so when I type the above line into a command prompt, the instant I hit enter the CUT occurs on the mixer. I only need one JustMacros on the network, and put the JM.exe on any machine that need to execute automation from.

This has the advantage of not connecting and disconnecting to the ATEM for each batch file, as the ATEM doesn't like connect / disconnecting, not least because when a connection occurs it sends all configuration data down to the client - a fair amount of data. Using JustMacros as a gateway means it maintains the connection, allowing JM.exe (batch file commands) to JUST do the work, and not worry about the plumbing.

So in the case of running a BMD macro it would be equally simple

JM localhost 39812 ATEMMixerMacrosRun(1,10)

Where this solution fails is in passing data back to the batch file, i.e. basically...... I didn't bother with that, as I tend to put the logic in the Lua.

Anyway, great to see other cool generic projects on the ATEMUser forum, give me a shout if you get stuck with anything, and once again, good luck with your project, I think it'll be really useful for lots of guys when finished.

imorrish's picture
Offline

Location

Wellington
New Zealand
Joined: 05/01/2015
Posts: 80
PowerShell Script to control ATEM

Making slow progress. I only get about an hour per evening on this. Have most MixerEffectBlock functions working (but with a TVS I havn't bothered doing DVE or Stinger yet). Just completed Color Generator control.

See video

Script is as simple as
#Color Inputs
$ColorGen= $atem.GetColorInputs()
$ColorGen1 = $ColorGen[0]
$ColorGen2 = $ColorGen[1]
for ($i=1; $i -le 360; $i++)
{
    $ColorGen1.Hue =$i
    start-sleep -Milliseconds 50
    if($i -eq 359){$i=1}
}

imorrish's picture
Offline

Location

Wellington
New Zealand
Joined: 05/01/2015
Posts: 80
Oh, and that 30K lines

is very tedious as I found with Wipe and DVE properties  (OK, slightly addictive) but I'm still at the experimentation stage of what is the best approach to provide a consistant interface so have been rewriting much of it several times...

Moving on to Audio next. Events and Multiple ME support I'm putting off for a "Pro" version :-)

Offline

Location

San Francisco,
United States
Joined: 24/02/2017
Posts: 1
Web developer, a programmer

Web developer, a programmer who specializes in, or is specifically engaged in, the development of World Wide Web applications. Video game developer, a person or business involved in video game development, the process of designing and creating games

 

 

thos-berlin's picture
Offline

Location

berlin
Germany
Joined: 19/06/2012
Posts: 469
albertpinto43: "Web developer, a programmer" is a spam-post

The post abve ist spam....

Thomas  S e e w a l d - thos-berlin (amateur)