Follow

PAL Script - Automate the Start of SAM Broadcaster

There are many ways you can start SAM Broadcaster, either manually or automatically using event scheduling software or options included with Windows, or by including SAM Broadcaster as an application registered under the Windows system startup.

This script is designed to automatically start your encoders and play a track if you did use any automation option to run SAM Broadcaster.

There is minimal error checking included within this script and as it is designed to be used only when SAM Broadcaster starts and is not designed to be used if SAM Broadcaster is already running and playing music.

You may have already configured SAM Broadcaster to use the Auto Recover options available within SAM Broadcaster however, this script can be used instead and this script can also be edited to provide additional or specific options for starting your station.  If you wish to use the standard auto recovery options, you would need to also set the encoders to start automatically whilst this script also starts your encoders.

// PAL Script to automatically start playing a track
// and start the encoders when SAM Broadcaster is started
// When the software is started
// This script starts all encoders
// and then cues and plays the first track
// This script contains minimal error checking and
// is designed to be run once when SAM Broadcaster starts

// Variables
var I : Integer; // Counter used to start encoders
var TrkCat : String; // Declare a variable to hold the track category
var Player1 : TPlayer; // Declare an instance of TPlayer for the Active Player
var Song : TSongInfo; // Declare an instance of TSongInfo for the queued track

TrkCat := 'Music (All)'; // Change this if you wish to select a track from a different category

// ********** Pause for 10 Seconds **********
PAL.WaitForTime('+00:00:10');

// ********** Start Encoders **********
for I := 0 to Encoders.Count-1 do
if not Encoders[I].Started then begin
Encoders[I].Start;
WriteLn('Started Encoder: '+InttoStr(I));
end;

// ********** Select and Cue a Track from a Designated Category **********
Player1 := IdlePlayer;
Song := Cat[TrkCat].ChooseSong(smRandom,NoRules); //select the category here
Player1.QueueSong(Song);
Player1.Play;
WriteLn('');
WriteLn('Track: '+Song['title']);
WriteLn('Artist: '+Song['artist']);

// ********** Housekeeping **********
Player1.Free;
Song.Free;

To better explain this script, we have broken this down into sections.

// PAL Script to automatically start playing a track
// and start the encoders when SAM Broadcaster is started
// When the software is started
// This script starts all encoders
// and then cues and plays the first track
// This script contains minimal error checking and
// is designed to be run once when SAM Broadcaster starts

The double forward slash is used to indicate a comment.  This section only contains a brief description of the script.

// Variables
var I : Integer; // Counter used to start encoders
var TrkCat : String; // Declare a variable to hold the track category
var Player1 : TPlayer; // Declare an instance of TPlayer for the Active Player
var Song : TSongInfo; // Declare an instance of TSongInfo for the queued track

TrkCat := 'Music (All)'; // Change this if you wish to select a track from a different category

Before we can use any variables, we have to declare them.  Using a suitable naming convention makes it easier to understand and follow the processes.  We have declared "I" as a variable of the type Integer.  Traditionally, "I" is commonly used for sections in code which are required to loop through a number of options.

TrkCat is a string and therefore can contain text in the form of words or sentences, is used to hold a designated category from which the first song is selected.  As we have declared this variable at the start of the script, we can easily change the current category "Music (All)" once to any of the available categories and this will ensure all occurrences of this will also select from the same category.

Player1 is an instance of the TPlayer class and enables us to access and manipulate one of the decks.

Song is an instance of the TSongInfo class which gives us access to track information.

// ********** Pause for 10 Seconds **********
PAL.WaitForTime('+00:00:10');

This line of code tells the script to pause for 10 seconds.  The auto recovery options wait for 5 seconds but if your computer runs a lot of applications, it might take longer than 10 seconds for the database to be running or your Internet connection to connect.  You can change the 10 to any number from 00 to 59 but remember, if for example you only want to wait five seconds, then you would set this to 05 and not just 5.

// ********** Start Encoders **********
for I := 0 to Encoders.Count-1 do
if not Encoders[I].Started then begin
Encoders[I].Start;
WriteLn('Started Encoder: '+InttoStr(I));
end;

Here we start all of the encoders which are not currently running, this is where the only error checking exists, (to identify idle encoders) and is designed to only start encoders which are not running.  It does not matter how many encoders you have, this small section of code will start each of them in turn.

// ********** Select and Cue a Track from a Designated Category **********
Player1 := IdlePlayer;
Song := Cat[TrkCat].ChooseSong(smRandom,NoRules); //select the category here
Player1.QueueSong(Song);
Player1.Play;
WriteLn('');
WriteLn('Track: '+Song['title']);
WriteLn('Artist: '+Song['artist']);

This identifies which player is the idle player and selects a track from the designated category.  This track is cued and the player started.  For a record, the track title and artist are written to the PAL script output but you could just as easily remove this or even write this information to a text file.  Recording the first track to play after a restart is a great way to identify when the software started as you would only need to search for the track title and artist.

// ********** Housekeeping **********
Player1.Free;
Song.Free;

Under housekeeping, we free up the two variables shown.  Whilst not strictly necessary, it is good practice, especially if you have multiple scripts running which may be using the same variable names.

Finally, we only need to set this script to start automatically when SAM Broadcaster starts.  This can be set by right-clicking on the script and selecting the Config option:

We simply need to check the box "Automatically start script" and click OK:

The PAL script is included with this article.

 

 

 

 

 

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments