Note that this Wiki is a work in progress, items may not be updated or may disappear entirely as the pages are updated.

PAL: Custom request handling example

From SpacialAudio

Jump to: navigation, search

This example script demonstrates how to handle requests with a custom PAL script:

Setting up SAM:

Go to SAM->Config->Request policy Make sure to select the "Leave request in list" option


The script:

{ PAL script to manually handle requests to play within a
 category based rotation logic system }
PAL.Loop := True;
{-->Insert first songs into queue}
CAT['Jingles (All)'].QueueBottom(smLemmingLogic,NoRules);
CAT['Power hit'].QueueBottom(smWeighted,EnforceRules);
CAT['Heavy Rotation'].QueueBottom(smWeighted,EnforceRules);
CAT['Jingles (All)'].QueueBottom(smLemmingLogic,NoRules);
{-->Insert next request + Jingle if request was found}
var AQuery : TDataSet;
var Song   : TSongInfo;
  AQuery := Query('SELECT songlist.*, requestlist.ID as requestID '
    +' FROM songlist,requestlist '
    +' WHERE (requestlist.ETA<:now) AND (requestlist.status=new) AND (songlist.ID=requestlist.songID) '
    + 'ORDER BY requestlist.ETA ASC '
    +' LIMIT 1 ',[Now],True);
 if not(AQuery.BOF and AQuery.EOF) then
   begin
     {A cool idea would be to insert a jingle here
      that says "The next song is by request" or something simular}
     {For example: Queue.AddFile('c:\.mp3',ipBottom);}
     {Copy the needed information from the dataset}
     Song := TSongInfo.Create();
     Song['ID']         := AQuery['ID'];
     Song['filename']  := AQuery['filename'];
     Song['artist']     := AQuery['artist'];
     Song['title']      := AQuery['title'];
     Song['duration']  := AQuery['duration'];
     Song['requestID'] := AQuery['requestID'];
     {Add request to queue}
     Queue.Add(Song,ipBottom);
     WriteLn('Request handled: '+Song['artist']+' - '+Song['title']);
     {Change status of request}
     ExecSQL('UPDATE requestlist SET status=:status WHERE (songID = :songID) AND ((status=new) OR (status=pending)) ',['pending',song['ID']]);
     {Insert Jingle after request}
     CAT['Jingles (All)'].QueueBottom(smLRP,NoRules);
   end
  else
    WriteLn('No request found');
{-->Insert final category}
CAT['Rare rotation'].QueueBottom(smWeighted,EnforceRules);
{Wait for songs in queue to play}
while (Queue.Count > 1) do
PAL.WaitForPlayCount(1);
Personal tools