Follow

PAL Script - New Commands Included With 2017.8

We would like to provide you with a quick overview of a number of new PAL commands which will be available with version 2017.8 and beyond.

PAL.Log(Message,LogType);

Log messages to event log. This is a great way to keep a DJ in the loop on what is happening inside the PAL script. This way the DJ does not need to keep open the PAL IDE to see messages in output window, but rather just keep an eye on the event lot.

Example usage:

PAL.Log('This is my normal notice message', ltNotice);
PAL.Log('Example warning message', ltWarning);

DATA_PATH and PROGRAM_PATH

If you go to

SAM --> Tools --> Jump to --> Data Path
or
SAM --> Tools --> Jump to --> Program Path

The first is the working directory where SAM stores all its configuration data, temporary files and any other content SAM needs to read/write.

The second is the installation directory where the SAM Broadcaster executable lives.

Now we have two constants in PAL which represent these values.

PROGRAM_PATH
DATA_PATH

Example usage:

WriteLn(PROGRAM_PATH);

WriteLn(DATA_PATH);

ExecuteCmd(cmd,[arg1,arg2,…])

You can now execute external commands with PAL scripting.

Example usage:

//Open EventLog file in NotePad (Assumes Notepad is found in your standard search path)
ExecuteCmd('notepad.exe',[DATA_PATH+'EventLog.log']);

//Signal SAM to close itself
ExecuteCmd(PROGRAM_PATH+'SAMBC.exe',['/SHUTDOWN']);

Note: See how we used the new DATA_PATH and PROGRAM_PATH variables here?

Studio operations

A new object, Studio, allows you to set various aspects of your SAM studio environment.

Example usage:

//Change Virtual DJ mode
Studio.DJMode := djAuto;
WriteLn(IntToStr(Studio.DJMode));
PAL.WaitForTime('+00:00:05');

Studio.DJMode := djQueue;
WriteLn(IntToStr(Studio.DJMode));
PAL.WaitForTime('+00:00:05');

Studio.DJMode := djManual;
WriteLn(IntToStr(Studio.DJMode));
PAL.WaitForTime('+00:00:05');

//Mute / Unmute studio
Studio.Muted := True;
PAL.WaitForTime('+00:00:05');
Studio.Muted := False;
PAL.WaitForTime('+00:00:05');

//Change Auto-Recovery settings
Studio.DJMode := djAuto; //Auto-recovery disabled with djManual
Studio.AutoRecoveryEnabled := False;
WriteLn(IntToStr(Studio.MaxIdleTime));
Studio.MaxIdleTime := 6;
WriteLn(IntToStr(Studio.UserResponseTime));
Studio.UserResponseTime := 9;
PAL.WaitForTime('+00:00:05');
Studio.AutoRecoveryEnabled := True;
PAL.WaitForTime('+00:00:30');
Studio.AutoRecoveryEnabled := False;

THttpClient

SAM is now much better able to communicate with various APIs via the new THttpClient.

Example usage:

var httpClient : THttpClient;
var headers : TStrings = TStringList.Create;
var T : Integer;
var url : string = 'http://myserver.com/myapi/';
httpClient := THttpClient.Create(url);

//Customize headers
httpClient.AddHeader('User-Agent: sambc/2017.8'); //Override default User-Agent
httpClient.AddHeader('X-CUSTOM-HEADER: My custom header code'); //Add custom header

//HTTP Basic Auth support
httpClient.Username := 'myusername';
httpClient.Password := 'pass123';

//If set, will save data to file instead of storing result in 'httpClient.ResponseData'
httpClient.Filename := DATA_PATH+'URL-TO-FILE.txt';

//Choose VERB to use + Data type to sent
//Note: httpClient is SINGLE USE only. Create new instance for each web request.
httpClient.Get;
//httpClient.Head;
//httpClient.Delete;
//httpClient.Post('My Post Data','text/text');
//httpClient.Put('My Put Data','text/text');
//httpClient.PostFile(DATA_PATH+'EventLog.log','text/text');
//httpClient.PutFile(DATA_PATH+'EventLog.log','text/text');

//Requests happen in background - so make sure to wait for it to complete!
while not httpClient.ResponseReady do
  Pal.WaitForTime('+00:00:01');
 
//Print out response data
PAL.LockExecution;
  WriteLn('Code='+IntToStr(httpClient.ResponseCode));
  WriteLn('Response='+httpClient.ResponseData);
  WriteLn('Headers=>');
  httpClient.ReadResponseHeaders(headers);
  for T := 0 to headers.count-1 do
     WriteLn(headers[T]);
PAL.UnLockExecution;

//Cleanup
httpClient.Free;
headers.Free;

PAL Scripting Reference Guide

As always, please refer to updated PAL scripting reference guide for more details.

SAM --> Help --> PAL Scripting Reference

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

Comments