We are in the process of migrating the Spacial Wiki content to our new Help Center at spacial.com.
Please visit the Help Center for latest Tips and Tricks, Documentation and Troubleshooting.

Write Some More

From SpacialAudio

Jump to: navigation, search

Here are a few more scripts that people do ask for
Repeat Songs in Queue/History    Play songs at a Certain Time songs are on local machine

Return to Write Some PAL

Repeat Songs in Queue / History List

If you want to load a set of songs in the queue and then repeat them with out saving a Playlist file (.m3u) and having a Script or the Event Scheduler to reload it when the queue only has a few songs. Then here is a way.

This script declares 2 variables. One of type TSongInfo and one of type TDataSet.
It also does a LockExecution and Unlock. That stops SAM from doing anything but the code between the lock and unlock. This way the script runs fast as opposed to one line a second.
note: In program execution terms that is very slow - but for PAL this works perfect 99% of the time. But there are moments where you need that instant execution. Luckily PAL makes this easy with the PAL.LockExecution

In this script the LockExecution is used only when the SQL statement is executed.

1. Declare Variables
2. Set the PAL.Loop Equal to True
3. Wait for 1 song to play
4. Lock so execution only takes a couple of seconds instead of many.
5. Execute the Query.
The Query looks for a song in the HistoryList Table/Dataset in the Database. The results are sorted by the date played and in descending order.The oldest will be on top of the list.
6. Check to see if any records were found (IsEmpty method)
7. If the list is NOT empty Add a file to the Bottom of the queue
8. Free up the memory used by the query
9. If the list is empty the it goes to the Unlock line.
10. Unlock the execution and return to the normal 1 line a second execution speed.
11. Return to the top and start over.

{This script will rotate the songs in the queue,
i.e. the songs in the queue will loop over and over again

var Song : TSongInfo;
var Q    : TDataSet;

PAL.Loop := True;

 Q := Query('SELECT filename FROM historylist ORDER BY date_played DESC',[],True);
 if not Q.IsEmpty then

Return to Write Some PAL    Top

Play Songs At Certain Times

Files are on the local machine

This is an example script for people that run pre-recorded shows (such as The Canvas Prog Hour, or Heavycore). This example loads the top of the queue at 7:58pm on Wednesday.

There are 4 parts in this case. To get them in order they are loaded to the top of the queue in reverse order.
This way they are in the proper play order.

NOTE: you can also use this:
start_time := T['19:58:00'];

Instead of this:
start_time := date + EncodeTime(19,58,00,0);

1. Set the Loop so it will continually loop waiting for Wednesday
2. Declare 3 variables. One for the current time (Now),one for the Show start time and one for the Show End Time.
3. Initialize the start_time and the end_time variables.
4. Check to see if it is Wednesday
5. If it is Wednesday then check if the mytime is Greater than or Equal to start_time and mytime is <= to end_time.

In other words if Its Wednesday and the time is equal to the start_time and less than the end_time, load the     files. 

6. Load a station Id to Top of Queue so it plays before the Show.
7. Wait 1 minutes (PAL.WaitForTime(T['+00:01:00']);)
8. Loop back through.

When it loops back to the Top it will still be Wednesday, but the time will have passed so it will not load the files.
The script will continue to loop until the next Wednesday and load the files again.

PAL.Loop := True;
var mytime : DateTime = now;
var start_time, end_time : DateTime;

start_time := date + EncodeTime(19,58,00,0);
end_time := date + EncodeTime(19,58,30,0);

 if DayOfWeek(Now) = Wednessday then

       if( mytime >= start_time) and (mytime <= end_time) Then
                 WriteLn('Canvas Prog Hour!');

        Queue.AddFile('E:\canvas\cphpart4.mp3',ipTop); //load 
        cat['Station IDs (All)'].QueueTop(smRandom,NoRules);
        cat['Station IDs (All)'].QueueTop(smRandom,NoRules);
        cat['Station IDs (All)'].QueueTop(smRandom,NoRules);
        cat['Station IDs (All)'].QueueTop(smRandom,NoRules);


Personal tools