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.
spacial.com/help-center

PAL script to generate advanced playlists

From SpacialAudio

(Difference between revisions)
Jump to: navigation, search
(New page: It took me about a week .... I wanted to build a music library or database and then be able to automatically create playlists from it, in a very advanced manner, like a radio station forma...)
Current revision (13:13, 1 February 2010) (view source)
 
Line 1: Line 1:
-
It took me about a week .... I wanted to build a music library or database and then be able to automatically create playlists from it, in a very advanced manner, like a radio station format. The first you can do with a lot of software, the second turned out to be the big problem. But with SAM broadcaster with mySQL as database and the PAL (actually a king of Java) programming language you can do both.  
+
It took me about a week .... I wanted to build a music library or database and then be able to automatically create playlists from it, in a very advanced manner, like a radio station format. The first you can do with a lot of software, the second turned out to be the big problem. But with SAM broadcaster with mySQL as database and the PAL (actually a modified version of the Pascal / Delphi programming language) programming language you can do both.  
Underneath you find a PAL script that you can easily modify and that allows you to create very advanced playlists.  
Underneath you find a PAL script that you can easily modify and that allows you to create very advanced playlists.  

Current revision

It took me about a week .... I wanted to build a music library or database and then be able to automatically create playlists from it, in a very advanced manner, like a radio station format. The first you can do with a lot of software, the second turned out to be the big problem. But with SAM broadcaster with mySQL as database and the PAL (actually a modified version of the Pascal / Delphi programming language) programming language you can do both.

Underneath you find a PAL script that you can easily modify and that allows you to create very advanced playlists.

First it creates so called songlists (2 in this simple example) which can be created by applying and combining criteria concerning artist, album, genre, rating, actually everything that is recorded in the data base in an and/or fashion. Also the length of these songlists can be specified (limited).

Secondly the script builds a playlist by drawing from these songlists randomly (in this example, but you can very easily specify the picking order yourself) until they are exhausted, while looking for the next songlist if the previous one is exhausted.

With these two steps you can actually exploit all the possibilities of the database to create playlist automatically, meating any format. And that was what I wanted. You might want this too .... Here is the script:

// PAL script to create songlists based on general 
// criteria and draw randomly from them 
// to build an advanced playlist 
// GvW 6-9-2005 
// Declare variables for songlists generation 
var theSongChooser1, theSongChooser2 : TDataSet; 
var theArtist1, theArtist2 : String; 
var theAlbum1, theAlbum2 : String; 
var theGenre1, theGenre2 : String; 
var duration, ls, sc1, sc2 : Integer; 
// Repeat the program endlessly if necessary 
// PAL.Loop := True; 
// Define the variables for the selection criteria 
theAlbum1 := 'TwentySomething'; 
theAlbum2 := 'Fearless'; 
theArtist1 := 'Jamie Cullum'; 
theArtist2 := 'Kane'; 
theGenre1 := 'Pop'; 
theGenre2 := 'Rock'; 
// Write info to screen 
WriteLn('PAL scipts that draws randomly from specified'); 
WriteLn('songlists to build an advanced playlist'); 
WriteLn(); 
// Create the songlists to draw from 
theSongChooser1 := Query('select *' + ' from songlist' + 
' where artist != ' + QuotedStr(theArtist1) + 
' and album != ' + QuotedStr(theAlbum1) + 
' and songtype = S' + 
' order by rand() limit 6',[],True); 
theSongChooser2 := Query('select *' + ' from songlist' + 
' where artist = ' + QuotedStr(theArtist2) + 
' and album = ' + QuotedStr(theAlbum2) + 
' or album = ' + QuotedStr(theAlbum1) + 
' and songtype = S' + 
' order by rand() limit 7',[],True); 
// Draw randomly from the songlists above until they are exhausted 
// Initialization 
theSongChooser1.First; theSongChooser2.First; duration := 0; 
ls := 0; sc1 := 0; sc2 :=0; 
// Loop 
while (sc1 = 0) or (sc2 = 0) do 
begin 
// Detect whether songlists are exhausted 
if theSongChooser1.EOF then sc1 := 1; 
if theSongChooser2.EOF then sc2 := 1; 
// Draw appropriate random integer to select the songlist or continue 
// the selection from the last songlist 
if (ls = -1) then ls := 0 else ls := RandomInt(2); 
// Draw from songlist 1 if not exhausted 
if (ls = 0) and (sc1 = 0) then 
begin 
WriteLn(theSongChooser1['title'] + ' *from* ' + theSongChooser1['album']); 
Queue.AddFile(theSongChooser1['filename'], ipBottom); 
duration := duration + theSongChooser1['duration']; 
theSongChooser1.Next; 
end 
// Increase the random number by 1 if this songlist is exhausted 
else if (ls = 0) and (sc1 = 1) then 
begin 
ls := ls+1; 
end; 
// Draw from songlist 2 if not exhausted 
if (ls = 1) and (sc2 = 0) then 
begin 
WriteLn(theSongChooser2['title'] + ' *from* ' + theSongChooser2['album']); 
Queue.AddFile(theSongChooser2['filename'], ipBottom); 
duration := duration + theSongChooser2['duration']; 
theSongChooser2.Next; 
end 
// Set the random number to -1 to signal continuation on top 
else if (ls = 1) and (sc2 = 1) then 
begin 
ls := -1; 
end; 
// Draw from songlist .. if not exhausted etc. 
end; 
// Wait for one or more songs to play before repeating the script if necessary 
// PAL.WaitForPlayCount(1); 
//*** PAL script end ***
Personal tools