Migrate from GitHub to SourceForge with this tool. Check out all of SourceForge's recent improvements.
Close

Snowmix Tutorials - Scenes

Peter Maersk-Moller

Snowmix Tutorials - Scenes

From Snowmix version 0.4.4, the Snowmix Library scenes.slib is supported. The Snowmix library scenes.slib offers advanced functions for creating simple as well as complex layouts and offers methods for switching between the layouts. This tutorial is an example of how to use the library.

Setting Up Scenes

Initial Setup

Setting up Scenes for Snowmix is intended to take place in the ini file or in files included by the ini files. Before setting up Scenes for Snowmix, the ini file must define a few things. This is shown below:

# Specify that Snowmix version major number must be 4 and and least minor number 4
require version 0.4.4

# Listen on port 9999 for command control connections
system control port 9999

# Set system Geometry to WIDTH HEIGHT
system geometry 1280 720 ARGB

# Set system frame rate to N or NN.NN
system frame rate 24

# Set output control socket
system socket /tmp/mixer1

# Change default settings for maxplaces BEFORE any of the shape, text etc. commands
maxplaces shapes 90
maxplaces shapes 170
maxplaces shapeplaces 64
maxplaces shapeplaces 128
maxplaces strings 180
maxplaces texts 180

# PreShow and Show must end with a loop statement
command create PreShow
  loop
command end
overlay pre PreShow
command create Show
  loop
command end
overlay finish Show

First we define that this ini file require the major verion number of Snowmix to be 0.4 and the minor number to be at least x.x.4. Then we define the port to be used incoming control connections. Then we set the video mixer geometry and frame rate and then we set the control socket for outputting control messages for shared memory as used by the GStreamer element shmsink. After that we change some default sizes for maxplaces values. We do this because default settings for these values may be to low, when the start defining layouts in Scenes as the library will auto allocate shapes, text etc. Last but not least, we define the two command macros PreShow and Show and specify these to be run at frame rate using the commands overlay pre and *overlay finish. You can read about these commands in the Reserved Commands Overview. It is important that the two command macros ends with a loop statement.

Including Libraries

After the initial setup in the ini file, it is now time to include the relevant Snowmix Libraries as shown below in the listed order. The order is important.

# Load libraries
include ../slib/system.slib
include ../slib/scenes.slib
include ../slib/feeds.slib
include ../slib/images.slib
include ../slib/basic-shapes.slib
include ../slib/clocks2.slib
include ../slib/texts.slib
message Snowmix Libraries Loaded

The first library to include is the system.slib. This defines functions used by the the other libraries to be included.

The second library to be included is the scenes.slib. This defines the functions used to setup and control advanced layout of Scenes.

The third library to be included is the feeds.slib. This defines functions that can be used to assist in defining and setting up video feeds.

The fourth library to be included is the images.slib. This defines functions that can be used to assist in loading images.

The fifth library to be included is the basic-shapes.slib. This defines basic shapes used by the scenes.slib.

The sixth library to be included is the clocks2.slib. This defines functions that can be used for defining a basic timer/counter or a clock. This library is not strictly necessary.

The seventh library to be included is the texts.slib. This defines functions that can be used to determine display size of texts among other things.

The message line just prints a message on stdout and it is now time to setup feeds, load images and possible setup some texts before the configuration os Scenes.

For setting up the feeds, we will use the FeedCreate, FeedDeadImage and FeedPAR defined in the feeds.slib. When this library is included, a feed with feed ID 0 is created with the geometry defined for the system geometry.

tcl eval FeedCreate "Feed #1" 1 1280 720 /tmp/feed1-control-pipe
tcl eval FeedCreate "Feed #2" 2 1280 720 /tmp/feed2-control-pipe
tcl eval FeedCreate "Feed #3" 3  704 576 /tmp/feed3-control-pipe
tcl eval FeedPAR 3 12 11
tcl eval FeedDeadImage 1 100 ../frames/dead-1280x720.bgra
tcl eval FeedDeadImage 2 100 ../frames/dead-1280x720.bgra
tcl eval FeedDeadImage 3 100 ../frames/dead-704x576.bgra

Now we will load some background images we will use for background for one of the Scenes we intend to create.

image load 1 ../images/CS/CS_TV_720p_3screen-up_background.png
image name 1 CS Background Logo Right
image load 2 ../images/CS/CS_TV_720p_2screen-up_background.png
image name 2 CS Background Logo Left
tcl eval ImageUpdateList

First we load two images and give them a name. Then we tell the Tcl Interpreter to update its internal info on the sizes of the images loaded using the function ImageUpdateList from the images.slib. We need to do this every time we load images.

Now we want to add a rolling text in the bottom of one of the Scenes we later intend to create. This is done her:

text string 1 This is an example of a rolling text placed in the bottom of one of the Scenes. The text can be turned on and off using either snowcub.tcl or a command from the Scenes library.
text font 5 Eurostile Normal 19
text place 1 1 5 0 -10 1 1 1 1 se
text place align 1 left bottom
text place backgr 1 2000 2000 10 10 0 0 0 0.75
text place repeat move 1 -2 0 -3500 0

Text string 2 is a text to be placed above the rolling text in the left side:

text string 2 Snowmix Video Mixer
text font 6 Eurostile Bold 19
text place 2 2 6 15 -57 1 1 1 1 sw
text place align 2 left bottom
text place backgr 2 15 80 10 10 0 0 0 0.27
text place clipabs 2 0 500 334 200

We will now create a couple of Scenes and specify a layout for them. When the Scenes Library was loaded, it created Scene 0 and Scene 1. Scene 0 is a Scene with no background image and no frames. When cutting or fading to Scene 0 you effectively cut or fade to black. Scene 1 has a single Frame filling the entire Scene*. This is effectively a full screen that can be filled with a feed or an image or another FrameType. Alle Scenes are by default filling the entire mixer geometry defined for the system. We will now create additional two new Scenes shown below:

tcl eval set scene(setactivesilent) 1
tcl eval SceneCreate "Fullscreen with PiP" 2
tcl eval SceneAddFrame 2 1 0 0 1280 720
tcl eval SceneAddFrame 2 2 940 20 320 180
tcl eval SceneSetFrameSource 2 1 feed 1 1 1
tcl eval SceneSetFrameSource 2 1 feed 2 0 1
tcl eval SceneSetFrameSource 2 2 feed 3 1 1
tcl eval SceneSetFrameSource 2 2 feed 2 0 1

First we tell the Scenes Library that we want it to be silent when activating Scenes. Without it, Snowcub.tcl will not work. Then we create Scene 2 with the name "Fullscreen with PiP". Then we add two Frames to Scene 2. Frame 1 is a fullscreen Frame and Frame 2 is a picture in picture Frame placed near the upper right corner. The order the Frames are created is the defualt order the Frames will be overlayed, when the Scene is activated. Then we set the front source for Frame 1 to Feed 1 and the back source is set to Feed 2. And then we set the front source for Frame 2 to Feed 2 and the back source is set to Feed 2. All sources are activated.

Now we create Scene 3, add a background image and add 3 Frames and add the placed text 1 and 2.

tcl eval SceneCreate "1 Large 2 Smaller" 3
tcl eval SceneSetBackground 3 1
tcl eval SceneAddFrame 3 1 408 40 832 468
tcl eval SceneAddFrame 3 2 40 98 346 194
tcl eval SceneAddFrame 3 3 40 314 346 194
tcl eval SceneAddOverlayText 3 1 2
tcl eval SceneSetFrameSource 3 1 feed 1 1 1
tcl eval SceneSetFrameSource 3 1 feed 2 0 1
tcl eval SceneSetFrameSource 3 2 feed 3 1 1
tcl eval SceneSetFrameSource 3 2 feed 2 0 1
tcl eval SceneSetFrameSource 3 3 feed 2 1 1
tcl eval SceneSetFrameSource 3 3 feed 1 0 1

The order of adding frames and adding overlay text determines the default order of overlaying frames and text when the Scene i activated.

Last but not least we activate an arbitrary Scene and subsequently deactivate all other Scenes:

tcl eval SceneSetState 2 1

In this example it is Scene 2 that is activated.

When Snowmix is running, it is suggested to start up snowcub.tcl and take a look at the Scene pane to see how much can be controlled from Snowcub.

That is about it. The full configuration is listed below for your convenience.

# Specify that Snowmix version major number must be 4 and and least minor number 4
require version 0.4.4

# Listen on port 9999 for command control connections
system control port 9999

# Set system Geometry to WIDTH HEIGHT
system geometry 1280 720 ARGB

# Set system frame rate to N or NN.NN
system frame rate 24

# Set output control socket
system socket /tmp/mixer1

# Change default settings for maxplaces BEFORE any of the shape, text etc. commands
maxplaces shapes 90
maxplaces shapes 170
maxplaces shapeplaces 64
maxplaces shapeplaces 128
maxplaces strings 180
maxplaces texts 180
# PreShow and Show must end with a loop statement
command create PreShow
  loop
command end
overlay pre PreShow
command create Show
  loop
command end
overlay finish Show

# Load libraries
include ../slib/system.slib
include ../slib/scenes.slib
include ../slib/feeds.slib
include ../slib/images.slib
include ../slib/basic-shapes.slib
include ../slib/clocks2.slib
include ../slib/texts.slib
message Snowmix Libraries Loaded
tcl eval FeedCreate "Feed #1" 1 1280 720 /tmp/feed1-control-pipe
tcl eval FeedCreate "Feed #2" 2 1280 720 /tmp/feed2-control-pipe
tcl eval FeedCreate "Feed #3" 3  704 576 /tmp/feed3-control-pipe
tcl eval FeedPAR 3 12 11
tcl eval FeedDeadImage 1 100 ../frames/dead-1280x720.bgra
tcl eval FeedDeadImage 2 100 ../frames/dead-1280x720.bgra
tcl eval FeedDeadImage 3 100 ../frames/dead-704x576.bgra
image load 1 ../images/CS/CS_TV_720p_3screen-up_background.png
image name 1 CS Background Logo Right
image load 2 ../images/CS/CS_TV_720p_2screen-up_background.png
image name 2 CS Background Logo Left
tcl eval ImageUpdateList
text font 4 Eurostile Bold 16
text font 5 Eurostile Normal 19
text place 1 1 5 0 -10 1 1 1 1 se
text place align 1 left bottom
text place backgr 1 2000 2000 10 10 0 0 0 0.75
text place repeat move 1 -2 0 -3500 0
text string 2 Snowmix Video Mixer
text font 6 Eurostile Bold 19
text place 2 2 6 15 -57 1 1 1 1 sw
text place align 2 left bottom
text place backgr 2 15 80 10 10 0 0 0 0.27
text place clipabs 2 0 500 334 200
tcl eval set scene(setactivesilent) 1
tcl eval SceneCreate "Fullscreen with PiP" 2
tcl eval SceneAddFrame 2 1 0 0 1280 720
tcl eval SceneAddFrame 2 2 940 20 320 180
tcl eval SceneSetFrameSource 2 1 feed 1 1 1
tcl eval SceneSetFrameSource 2 1 feed 2 0 1
tcl eval SceneSetFrameSource 2 2 feed 3 1 1
tcl eval SceneSetFrameSource 2 2 feed 2 0 1
tcl eval SceneCreate "1 Large 2 Smaller" 3
tcl eval SceneSetBackground 3 1
tcl eval SceneAddFrame 3 1 408 40 832 468
tcl eval SceneAddFrame 3 2 40 98 346 194
tcl eval SceneAddFrame 3 3 40 314 346 194
tcl eval SceneAddOverlayText 3 1 2
tcl eval SceneSetFrameSource 3 1 feed 1 1 1
tcl eval SceneSetFrameSource 3 1 feed 2 0 1
tcl eval SceneSetFrameSource 3 2 feed 3 1 1
tcl eval SceneSetFrameSource 3 2 feed 2 0 1
tcl eval SceneSetFrameSource 3 3 feed 2 1 1
tcl eval SceneSetFrameSource 3 3 feed 1 0 1
tcl eval SceneSetState 2 1

Related

Wiki: Reserved Commands
Wiki: Snowmix Libraries - Basic Shapes
Wiki: Snowmix Libraries - Feeds
Wiki: Snowmix Libraries - Images
Wiki: Snowmix Libraries - Scenes
Wiki: Snowmix Libraries - System
Wiki: Snowmix Libraries - Texts
Wiki: Snowmix Libraries