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

Scheduling a regular show, to play in sequence

From SpacialAudio

Jump to: navigation, search

Comments:

         This script is designed to play a series of episodes, in this case
         Chicken Man. Numbers 1 to 97. Each episode is preceeded by the
         chickenman intro, and followed by chickenman outro. At various times
         there are chickenman promos played in the current music stream.
         
         The important point being the ability to sequence each show so that
         even in the event of a power outage - of any duration - the script
         will ensure that the correct show in the sequence is played. It will
         not simply restart from show number 1. Nor will it play random
         epsiodes - which at the least would be confusing to the listener!
         

The script relies on a number of static things being in place:

      1. The episodes are loaded into the songlist in strict order so that
         their IDs are in strict order. This means that it is unlikely that
         you can add episodes at a later date. When PAL has decent substring
         handling, then this script can be changed to use the file_name_num,
         not the ID. Unless I think of something meantime. So with shows like
         Elberts storylines, this will not work as shows are added at
         different times, and thus will end up with non sequential IDs.
      2. The script relies on a table being added to SAMDB, in my case called
         'chickenman' with one field called 'chickenID' that is the same
         structure as the ID field in songlist. That is, mediumint(9).

You may download the script here. http://spacialnet.com/knowledge/attachment.php?attId=61 (retrieved from archive.org)



{ Comments:
          This script is designed to play a series of episodes, in this case
          Chicken Man. Numbers 1 to 97. Each episode is preceeded by the
          chickenman intro, nad followed by chickenman outro. At various times
          there are chickenman promos played in the current music stream.
          
          The important point being the ability to sequence each show so that
          even in the event of a power outage - of any duration - the script
          will ensure that the correct show in the sequence is played. It will
          not simply restart from show number 1. Nor will it play random
          epsiodes - which at the least would be confusing to the listener!
          
     The script relies on a number of static things being in place:
       1. The episodes are loaded into the songlist in strict order so that
          their IDs are in strict order. This means that it is unlikely that
          you can add episodes at a later date. When PAL has decent substring
          handling, then this script can be changed to use the file_name_num,
          not the ID. Unless I think of something meantime. So with shows like
          Elberts storylines, this will not work as shows are added at
          different times, and thus will end up with non sequential IDs.
       2. The script relies on a table being added to SAMDB, in my case called
          'chickenman' with one field called 'chickenID' that is the same
          structure as the ID field in songlist. That is, mediumint(9).
          
       Notes: If you run this script multiple times in setting it up, keep
              in mind, that if it gets to the point where it has loaded the
              current show into the queue, it will assume that it is played,
              and increment the chickenID and store it ready for the next day.
            When you are ready to 'go live' then go into the SAMDB, open
            the chickenman table and reset the chickenID to the
            chickenID of the first show.

            When you prepare your mp3/wma whatever files, make sure you have
            valid IDv3 tags on them. If the 'duration' field of the tag is
            empty - the show wont play.
            
            
  Naturally, where ever I have 'chickenman' as a name, you should change that
  to suit your situation.
          

 Copyright: Dodgey Brothers. Australia. (c) 2000-3000
   Code by: Robert Chalmers. robert.chalmers@bigpond.com (Australia)
        In the Lord I trust. http://www.users.bigpond.com/robert.chalmers
}

PAL.Loop := True;               // Make sure it keeps running
// Variables
var mytime : DateTime;

var I : integer = 500;       // iterations through loop
var J : integer;
var k : integer = 0;             // set to 0 to start

var D : TDataSet;               // Holds the data set (structure) returned from
                                // the Query
var E : DateTime = Queue.ETA;  // How long is the queue in seconds?
var F : Boolean;          // Boolean. On/Off  (bit)
var S : integer;          // Holds the numerical chickenID from the table
var V : String;           // Holds the filename string and any other strings.
var W : String;           // Holds chickenman intro fully qualified filename
var X : String;           // Holds chickenman outro fully qualified filename

var FirstID : integer;    //  The ID of the first program in the series,
var LastID : integer;     //  and the ID of the last program in the series.
                          // I've ensured that the programs were loaded into
                          // SAM in strict order, so their IDs are in the
                          // correct order in the songlist. So long as they
                          // don't ever change - !!! this script will work.

W       := 'G:\StationMusic\Chicken Man Episodes\chickenman_open.mp3';
X       := 'G:\StationMusic\Chicken Man Episodes\chickenman_close.mp3';

FirstID := 3509;          // first ephisode ID
LastID  := 3606;          // last ephisode  ID

// chickenID numbers run from 3509 to 3630. These are the IDs from the songlist.

// Check if it's the right day/time to play the show.
F := false;        // Switch off. Not actually used in this script. yet!
               // Make sure it keeps running

  while k <= 97 do
    begin
    
// This next bit could be more compact, but I use this (Thanks Steve) because
// it clearly defines what and when I want things to happen.
// For example, if you only want a show on Monday - at a time - simply change it
// here to what you want. Set the time(s) to play, set the day(s) to play

// Make sure that a promo plays up to an hour before the actual show. Depends on
// your queue size. Mine keeps four tracks in it. The longest is 26 minutes.
// Uh Oh, don't touch that dial, coming up in the next hour.....

if (now >= T['14:29:00']) and (now <= T['14:30:00']) and
((DayOfWeek(Now) = Monday) or
(DayOfWeek(Now) = Tuesday) or
(DayOfWeek(Now) = Wednesday) or
(DayOfWeek(Now) = Thursday) or
(DayOfWeek(Now) = Friday)) then
        begin
        cat['Chicken Man Promos'].QueueBottom(smRandom,NoRules);
        WriteLn('Waiting a moment!');
        // Gakkk. Wait at least a minute - or you queue will fill with promos.
        PAL.WaitForTime(T['+00:02:00']);
        end;

    
if (now >= T['15:29:00']) and (now <= T['15:30:00']) and
((DayOfWeek(Now) = Monday) or
(DayOfWeek(Now) = Tuesday) or
(DayOfWeek(Now) = Wednesday) or
(DayOfWeek(Now) = Thursday) or
(DayOfWeek(Now) = Friday)) then
    begin                             // don't forget, this has an end;

// Get the correct chickenID from the chickenman table. Remember, this MUST be
// set initially with the first track ID that will be used.
// The table 'chickenman' has one field called 'chickenID'. Same structure as
// the ID field in songlist.
// ok, get the show that is slotted to play.
D := Query('SELECT chickenID FROM chickenman',[], True);
     // check it
     WriteLn(D['chickenID']);

S := D['chickenID'];
     // check it
     WriteLn(S);
     // go to songlist and pull the filename with ID = S
D := Query('SELECT filename FROM songlist WHERE songlist.ID = :S',[S], True);
     // stuff it into a variable. ( less typing later on :-)   )
V := D['filename'];
     // check we have the filename
     WriteLn(V);
     
      // Load it into Queue Top ready to play.
      WriteLn('Load Chickenman');
      Queue.Clear();
      Queue.AddFile(W,ipTop);      // add chickenman_open
      Queue.AddFile(V,ipBottom);   // load the episode
      Queue.AddFile(X,ipBottom);   // load chickenman close below it
        k := k + 1;
        writeln(k);
         E := Queue.ETA;
         WriteLn('Do not pass Go...');
         WriteLn(E);
         PAL.WaitForTime(E);
         { or if you like, this one. It's just to give the timer enough
           time to get past 'time to load a file' - otherwise it just loops.
           Uncomment the lines, and comment the 4 above. }
         //WriteLn('Wait for 2 tracks');
         //PAL.WaitForPlayCount(2);

         
      // If you have like 4 songs normally queued, this will then requeue them.
     // Ok, we have todays show loaded at queue top. increment the chickenID,
     // uh oh. Is this the last show in the sequence?
     // If it is, better be carefull to avoid the increment.
     // If it is the last one, Reset the chickenID to the first one.
          if S = LastID then
             S := FirstID
          else     // if it's not the last one, just increment as usual
             begin
             S := ( S+1 );
             // check it
             WriteLn(S);
             // stuff it into the chickenman table's 'chickenID'
             ExecSQL('UPDATE chickenman SET chickenID = :S',[S]);
             // pull it back and check it.
             D := Query('SELECT chickenID FROM chickenman',[], True);
             // check it
             WriteLn(IntToStr(D['chickenID']) + ', ' + 'Next to play' );
             end;

   // wait for another day.....

   end;     // From the first begin, under the 'check what day it is...'

         // ok, while waiting for next day, plug the show
             J := J + 1;
             writeln(J);
             if J = I then
             begin
             cat['Chicken Man Promos'].QueueBottom(smRandom,NoRules);
             J := 0;
             end;

          if (now >= T['15:29:00']) and (now <= T['15:30:00']) and
             ((DayOfWeek(Now) = Saturday) or
             (DayOfWeek(Now) = Sunday)) then
             begin
             cat['Chicken Man Promos'].QueueBottom(smRandom,NoRules);
         WriteLn('Waiting a moment!');
        // Gakkk. Wait at least a minute - or you queue will fill with promos.
        PAL.WaitForTime(T['+00:02:00']);

             end;
end;

Personal tools