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

Pull from 1 category and build a playlist

From SpacialAudio

Jump to: navigation, search

This script will pull music from 1 category folder of your choice,
based on rules and build a play list of a certain duration with and intro and exit for the show, then load the playlist to the top of the queue fade the current song and start playing the list.

The script has only been tested for a 1 hour show and 30 minutes.
on a 1.4 gig with 192 megs of memory and on an 850 with 256 megs of memory.

Be sure to give it plenty of time to work before the show should run.
There are no implied warranties or claims. This script is as is.
Feel free to modify or what ever.
1. Make sure the category you are pulling from has enough songs for the rules
2. Make sure the to category exists.
3. Be sure the intro and exit files are in SAM in the Promos or some place that won't give them a type S
4. You may have to play with your rules some to get it to pull the way you want.
5. I have tried to prevent duplicate artists but don't be surprised if some show up (tags , inconsistent artist names etc.)
If you get access memory problem.
Check to make sure that all the category folders involved exist


Link was broken, content retrieved from archive.org from Jan 13th, 2008:

{*******************************************************
 selects from more  1 category to fill a playlist
till duration is satisfied
cat2p.pal
***********************************************
Make sure the CategoryToPullFrom has songs in it
********************************************************}
PAL.loop := true   ;

const CategoryToPullFrom : String = 'Tracks' ;
const ShowDuration       : integer = 3600000; // 3600000 ms = 1 hour in milli seconds
const ShowIntrofile      : string = 'C:\Program Files\SpacialAudio\SAM2\Sound\promos\bbintro.wma' ;
const ShowExitfile       : string = 'C:\Program Files\SpacialAudio\SAM2\Sound\promos\bbexit.wma' ;
const PlaylistFile       : string = 'C:\Program Files\SpacialAudio\SAM2\Sound\promos\jzhshow.m3u' ;
const ShowTitle          : string = '# Jazz Hour';

var D, D2              : TDataSet;
var SonginfoT          : TSongInfo;
var ShowQueue          : TStringList;
var HoldArtist         : string;
var totalduration      : integer ;
var catID              : integer ;
var idofsong           : integer ;
var songcount          : integer ;
var x                  : integer;
var logicswitch        : integer;
var durationinminutes  : integer;
var Artist             : string;
var ExistingArtist     : boolean;

function ActivePlayer:TPlayer; forward;
totalduration := 0 ;
songcount := 0;
ExistingArtist := false ;
HoldArtist := ''  ;
ShowQueue := TStringList.Create;

   //   add show intro and get exit duration
      D2 :=Query('SELECT duration from songlist where filename = :fname',[ShowIntroFile],True);
      totalduration := totalduration + D2['duration'];
      ShowQueue.Add(ShowTitle);
      ShowQueue.Add(ShowIntroFile);
      D2 :=Query('SELECT duration from songlist where filename = :fname',[ShowExitFile],True);
      totalduration := totalduration + D2['duration'];
      writeln ('adding intro ' + ShowIntroFile + ' duration = ' + inttostr(D2['duration']));
      D2.free ;

   //Start PAL to make playlist from CategoryToPullFrom.
   while (totalduration <= ShowDuration) do
   begin
      {****************************************************
       here are 2 different ways to choose the songs you can add more.
       the randomInt is 0 based so if you want 3 different sets of logic 
       you use 3 but the numbers returned start at 0 so for 3 you get 0,1,2.
       Make sure the category you are pulling from has songs in it.
      ***************************************************}
      logicswitch := RandomInt(2);
      case logicswitch of
         0 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smRandom,EnforceRules);
         1 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smLemmingLogic,EnforceRules);
      end;
      Artist  :=  Trim(SonginfoT['artist']) ;
      writeln('artist from choose = ' + Artist);
      D2 := Query('SELECT songid  FROM categorylist WHERE (songid = :sid) and (categoryID = :cid )', [ SonginfoT['songID'],catID], True);
      If D2.EOF then // if it doesn't find the song continue
      begin
         //see it artists has already been put in 
        x := Pos(Artist, HoldArtist);
        if x > 0 then
            ExistingArtist := True   
         else
            ExistingArtist := False;  
         if not ExistingArtist then
         begin
            ExistingArtist := False ;
            totalduration := totalduration + SonginfoT['duration'];
            if totalduration <= ShowDuration then
            begin
               writeln ('Adding ' + SonginfoT['artist'] + ', ' + SonginfoT['title'] );
               HoldArtist := HoldArtist + Artist + '';
               ShowQueue.add (SonginfoT['filename']);
               songcount := songcount + 1;
            end;
         end;
      end; 
      D2.Free        
   end;
   ShowQueue.Add(ShowExitFile);
   durationinminutes := (totalduration / 1000) /60;
   Writeln ( inttostr(songcount) + ' Songs were added for a total of ' + 
      'approximatly ' + inttostr(durationinminutes) + ' minutes');
   ShowQueue.SaveToFile(PlaylistFile);
   //free up the TStringLists
   ShowQueue.Destroy;
//wait for 8pm to queup the show
PAL.WaitForTime(T['23:29:59']);
Queue.AddList(Playlistfile,ipTop);
//wait 5 seconds for the queue to load
Pal.WaitForTime(T['+00:00:05'])   ;
{***************************************************
fade whatever is playing and start the show
if you don't want to fade out and just wait for 
the current song to finish then comment out the next line
and the forward declare near the top of the script
*******************************************************}
ActivePlayer.FadeToNext; 
//wait for next day
PAL.WaitForTime(T['23:59:59']);

//function that is called to fade current and start next in queue
function ActivePlayer:TPlayer;
begin
if DeckA.Status = psPlaying then
Result := DeckA
else
Result := DeckB;
end;
Personal tools