Hi guys,
First up, when I first announced I had written one of these and was testing it I was inundated with people asking for it. Unfortunately I was having huge problems with memory leaks which I couldn't track down, and was VERY reluctant to letit go out, so HUGE, MASSIVE apologies to all those who asked me for it and I said "in a few weeks" and then never delivered. This was the reason why.
Anyway, the problem seems tohave been sorted with the release of v2.8.1, and I have had this script running now for a few weeks continuosly without the need for a reboot, so hopefully *touch wood* all is fixed, so here are the details for everybody to try out and let me know what you think.
A bit of background is required first I think. Many peope in the dance sector broadcast continuopus mixes. For legal reasons we are required to display the track name/artist for each and every track in that mix. One way to do this would be to split the mix into seperate files. However, there seems tobe no way at the moment that allows the files to be played back to back without either a gap between tracks, or the mix sounding all rubbish (not good when you are trying to showcase yourself as a DJ!!!). So, the other option is to keep the mix as one long file and change the track title, which is what I have done here!
OK, so theres a little bit of work required to set it up. first up youneed a new table in the SAM database. Here is the SQL to create it:
Code:
CREATE TABLE `track_list` (
`mix_id` mediumint(4) default NULL,
`artist` varchar(50) default NULL,
`title` varchar(50) default NULL,
`time` mediumint(7) default NULL
) TYPE=MyISAM;
As you can see, this creates a table called "track_list" with the following fields:
mix_id: this is equal tothe song_id within SAM
artist: the artist ofthe track
title: the title of the track
time: the time the track starts (in MILISECONDS!!!)
This table will need to be populated for each mix you have within SAM. The way I do it is using personalised php scripts on my website which the DJs have to submit a tracklisting before they can upload their mix to me. Theres no point me posting these up as they are personalised to my site and the way I work. However, there are many other ways such as phpmyadmin etc.
So, now you have the table created, and all your mix info is inserted you are ready to rock n roll!! Heres the PAL script, just copy/paste over to your own file and add to your script listing withing SAM:
Code:
PAL.Loop := True;
PAL.MemoryLeakWarning := True;
{declares variables}
var ds_currentid: TDataSet;
var currenttrack: TDataSet;
var currentid: Integer;
var currentmix: TDataSet;
var cur_time: integer;
var Song : TSongInfo;
var nexttrack: TDataSet;
var nexttime :String;
var temp_hour : Float;
var temp_min : Float;
var temp_sec : Float;
var str_hour : string;
var str_min : string;
var str_sec : string;
var temp_nexttime : Integer;
var A : TPlayer;
PAL.LockExecution;
A := ActivePlayer;
nexttime := '+0:00:20';
{Gets the song ID of the currently playing mix from the historylist}
ds_currentid := Query('SELECT MAX(ID) FROM historylist', [], TRUE);
currentmix := Query('SELECT * FROM historylist WHERE ID = :id ORDER BY date_played DESC LIMIT 1', [ds_currentid['max(ID)']], TRUE);
currentid := currentmix['songID'];
{Gets the cursor time for the mix playing}
cur_time := A.CurTime;
{Gets the track info from the databse - Note: the track_list table has to be created and populated}
currenttrack := Query('SELECT * FROM track_list WHERE (mix_id = :currentid) AND (time <= :time) ORDER BY time DESC LIMIT 1', [currentid, cur_time], TRUE);
{Works out length of track}
nexttrack := Query('SELECT * FROM track_list WHERE (mix_id = :currentid) AND (time > :time) ORDER BY time ASC LIMIT 1', [currentid, cur_time], TRUE);
{Checks that there is track info for the mix}
If not currenttrack.IsEmpty then
begin
Song := TSongInfo.Create;
{Creates the appropriate artist and title fields in the desired format}
Song['artist'] := currentmix['artist'] + ' - ' + currentmix['title'];
Song['title'] := '[' + currenttrack['artist'] + ' - ' + currenttrack['title'] + ']';
WriteLn(Song['artist'] + Song['title']);
{Update song information}
Encoders.SongChange(Song);
temp_nexttime := nexttrack['time'];
{works out length of track}
If nexttrack.IsEmpty then
temp_nexttime := A.duration;
end
Else
begin
WriteLn('Tracklisting for ' + currentmix['artist'] + ' - ' + currentmix['title'] + ' needs uploading' );
temp_nexttime := A.duration;
end;
{converts the time of the track from ms into the format '+hh:mm:ss'}
temp_hour := INT((temp_nexttime - cur_time)/(1000*60*60));
temp_min := INT(FRAC((temp_nexttime - cur_time)/(1000*60*60))*60);
temp_sec := INT(FRAC((FRAC((temp_nexttime - cur_time)/(1000*60*60)))*60)*60);
If (temp_hour < 10) then
str_hour := '0' + FloatToStr(temp_hour)
else
str_hour := FloatToStr(temp_hour);
If (temp_min < 10) then
str_min := '0' + FloatToStr(temp_min)
else
str_min := FloatToStr(temp_min);
If (temp_sec < 10) then
str_sec := '0' + FloatToStr(temp_sec)
else
str_sec := FloatToStr(temp_sec);
nexttime := '+' + str_hour + ':' + str_min + ':' + str_sec;
Song.Free;
ds_currentid.Free;
currentmix.Free;
nexttrack.Free;
currenttrack.Free;
Encoders.Free;
A.Free;
PAL.UnlockExecution;
{Waits either for next track or for end of mix before re-checking}
PAL.WaitForTime(nexttime);
If you have any questions then post them below and I'll do my best to answer them, and if you have any suggestions for the code etc then again, let me know.
Hope this is of use to a few of you.