Skip to Content
It is currently September 24th, 2018, 11:04 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 9:37 am 
Offline
Experienced User
Experienced User

Joined: January 31st, 2004, 10:28 pm
Posts: 252
Location: Carrboro, North Carolina
What's the best way to discover the TDataSet for the last item in queue. EG: I want to add a promo to the QueueBottom iff the last item in queue is of songtype = "S" so as not to play a promo after songs only, not after other Ps or Is or Js, etc...

Song := Queue.NextInQueue; works well to discover the first item in queue... but how to discover the last item?

Thanks,
K

_________________
-Keith (Lumper5) - Deeper Into Music
Celebrating more than 10 years streaming (as of Oct 2010)
Visit http://www.deeperintomusic.net | Facebook: Become a "fan" | Twitter: Follow the leader


Top
 Profile  
Reply with quote  
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 9:52 am 
Offline
Alumni
Alumni

Joined: October 14th, 2006, 9:38 am
Posts: 5986
Location: Deep in the heart of the PRNJ
Query the queuelist, examine the last item in the data set.

q.v. TDataSet in the Help files.

_________________
- Stan Olochwoszcz
A proud licensed SAM user since 2002

Raritan Bay Radio


Top
 Profile  
Reply with quote  
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 11:50 am 
Offline
Experienced User
Experienced User

Joined: January 31st, 2004, 10:28 pm
Posts: 252
Location: Carrboro, North Carolina
Problem is that queuelist doesn't store songtype.

_________________
-Keith (Lumper5) - Deeper Into Music
Celebrating more than 10 years streaming (as of Oct 2010)
Visit http://www.deeperintomusic.net | Facebook: Become a "fan" | Twitter: Follow the leader


Top
 Profile  
Reply with quote  
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 12:08 pm 
Offline
Junior User
Junior User

Joined: October 4th, 2008, 12:35 pm
Posts: 39
Location: Kaufbeuren, Germany
You might want to use something like the code snippet below. Just bear in mind that the function »SongList« only returns the fields ID, songID, sortID, requestID, artist, title, and duration in the TDataSet returned.

Code:
PAL.LockExecution;
var Q, QInfo: TDataSet;

if (not Queue.IsEmpty) then
begin
  // Queue not empty, get last song in Queue
  Q := Queue.SongList;
  Q.Last;

  if (not Q.EOF) then
  begin
    // need to get extra info that is not in »queuelist« table, so read »songlist« table
    QInfo := Query('SELECT * FROM songlist WHERE songID = :id',[Q['songID']], True); // r/o query
    QInfo.First;
    // you should now have all songlist info in »QInfo['…']«
    if (QInfo['songtype'] = 'S') then
    begin
      // add promo to Queue Bottom
    end;
  end;

  Q.Free;
  QInfo.Free;
end;

PAL.UnlockExecution;

Untested, but I guess it should work.

_________________
Moonbase: The Problem Solver
I will not give any support for unlicensed or pirated software.


Top
 Profile  
Reply with quote  
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 12:24 pm 
Offline
Experienced User
Experienced User

Joined: January 31st, 2004, 10:28 pm
Posts: 252
Location: Carrboro, North Carolina
Thanks - that was the right idea. A small tweak and it worked great. Seems odd that queuelist wouldn't store a little more info like songtype, but so it goes. Thanks for the helps.

_________________
-Keith (Lumper5) - Deeper Into Music
Celebrating more than 10 years streaming (as of Oct 2010)
Visit http://www.deeperintomusic.net | Facebook: Become a "fan" | Twitter: Follow the leader


Top
 Profile  
Reply with quote  
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 1:13 pm 
Offline
Alumni
Alumni

Joined: March 11th, 2003, 1:34 pm
Posts: 9959
Location: Maui, HI
This could also be done without the outer check:
Code:
PAL.LockExecution;

var QInfo : TDataSet = Query( 'select sl.songinfo from songlist sl, queuelist ql where sl.id = ql.songid order by ql.id desc limit 1', [], True);
if ( QInfo[ 'songtype' ] = 'S' ) then
begin
  // add promo to Queue Bottom
end;

QInfo.Free;
PAL.UnlockExecution;


SQL validated on MySQL; salt to taste for other dialects

_________________
- Steve Kunitzer
- SVS (Spacial Volunteer Support) / Forum Administrator

Image
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 1:18 pm 
Offline
Alumni
Alumni

Joined: October 14th, 2006, 9:38 am
Posts: 5986
Location: Deep in the heart of the PRNJ
Thanks, Moonbase. Tweaked it a bit and this does work:
Code:
//PAL.LockExecution;
var Q, QInfo: TDataSet;
var SI : String;

if (not Queue.IsEmpty) then
  begin
     Q := Queue.SongList;
     Q.Last;
  end;
  WriteLn(Q['SongID']);
  WriteLn(Q['title']);
  SI := Q['songID'];
  WriteLn(SI);
  //Get additional info about song
    QInfo := Query('SELECT * FROM songlist WHERE ID = :ID',[Q['songID']], True);
    WriteLn(QInfo['ID']);
    WriteLn(QInfo['title']);
    WriteLn(QInfo['songtype']);
    // You should now have all songlist info in »QInfo['…']«
    //Put a jingle in the queue
    if (QInfo['songtype'] = 'S') then
    begin
      CAT['Jingles (All)'].QueueBottom(smLemmingLogic,NoRules);
    end;


  Q.Free;
  QInfo.Free;
//end;

//PAL.UnlockExecution;

@lumper
Throw out the obvious check lines, tweak accordingly, you should be good to go.

_________________
- Stan Olochwoszcz
A proud licensed SAM user since 2002

Raritan Bay Radio


Top
 Profile  
Reply with quote  
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 1:23 pm 
Offline
Alumni
Alumni

Joined: October 14th, 2006, 9:38 am
Posts: 5986
Location: Deep in the heart of the PRNJ
Or you could do it Steve's way. :lol:

_________________
- Stan Olochwoszcz
A proud licensed SAM user since 2002

Raritan Bay Radio


Top
 Profile  
Reply with quote  
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 2:09 pm 
Offline
Junior User
Junior User

Joined: October 4th, 2008, 12:35 pm
Posts: 39
Location: Kaufbeuren, Germany
Steve, my PAL hero :)
Always a way to optimize things. Great code.

_________________
Moonbase: The Problem Solver
I will not give any support for unlicensed or pirated software.


Top
 Profile  
Reply with quote  
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 2:20 pm 
Offline
Experienced User
Experienced User

Joined: January 31st, 2004, 10:28 pm
Posts: 252
Location: Carrboro, North Carolina
Here's what worked for me... based on Steve's code:

QInfo := Query( 'select songtype from songlist AS sl, queuelist AS ql where sl.id = ql.songid order by ql.id desc limit 1', [], True);

while NOT (QInfo['songtype'] = 'S')

wait
else
add to QueueBottom

_________________
-Keith (Lumper5) - Deeper Into Music
Celebrating more than 10 years streaming (as of Oct 2010)
Visit http://www.deeperintomusic.net | Facebook: Become a "fan" | Twitter: Follow the leader


Top
 Profile  
Reply with quote  
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 6:49 pm 
Offline
Alumni
Alumni

Joined: March 11th, 2003, 1:34 pm
Posts: 9959
Location: Maui, HI
Both return a TDataSet but one has the option to return the songtype field while the other does not.
As we say in Hawaii: if can, can; if no can, no can.

_________________
- Steve Kunitzer
- SVS (Spacial Volunteer Support) / Forum Administrator

Image
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group