UI_playQueue.c File Reference


Detailed Description

This module provides play queue management rountines.

REVISION

Definition in file UI_playQueue.c.

#include "../SYSTEM/sys_hardware.h"
#include "../SYSTEM/sys_main.h"
#include "../SYSTEM/sys_clock.h"
#include "../SYSTEM/rtc_inc.h"
#include "playQ.h"
#include "ui_assert.h"

Include dependency graph for UI_playQueue.c:

Include dependency graph

Go to the source code of this file.

Functions

st_PLAYQUI_setupPlayQ (DB_ID id, DB_FIELDIDX fldIdx, DB_ENTRY entry, USHORT actvItem)
 Function sets up the play queue.
void UI_playQshutdown (void)
 Function shuts down the play queue and closes all opened handles if any.
BOOL UI_playQreset (int mode)
 Function resets the play queue if queue was generated out of Mymix.
st_PLAYQGBLUI_getPlayQGbl (void)
 Function fetches play queue global controls.
st_PLAYQUI_playQnext (void)
 Function advances the play queue.
st_PLAYQUI_playQprevious (void)
 Function moves the play queue backward.
st_PLAYQUI_playQcurrent (void)
 Function returns current active queue pointer.
FileUI_getCurrentAudioFileFromPlayQ (void)
 Function returns current audio file pointer from play queue.
void UI_setCurrentAudioFileInPlayQ (void)
 Function sets the current active audio file pointer in play queue.
FileUI_getNextAudioFileFromPlayQ (int setCacheFile)
 Function returns next audio file pointer from play queue.


Function Documentation

File* UI_getNextAudioFileFromPlayQ int  setCacheFile  ) 
 

Function returns next audio file pointer from play queue.

Parameters:
setCacheFile If non-zero, reset the cache file, otherwise seek next track only.

Definition at line 613 of file UI_playQueue.c.

References AF_NULL, st_PLAYQ::file, and st_PLAYQ::format.

Referenced by AUDIO_getCacheTrackFile().

00614 {
00615     st_PLAYQ * q = _playQnext(qCache);
00616     
00617     if(setCacheFile)
00618     {
00619         qCache = (q)? q:qCache; 
00620         if(AF_NULL != qCache->format) return &qCache->file;
00621     }
00622     
00623     return NULL;
00624 }

st_PLAYQGBL* UI_getPlayQGbl void   ) 
 

Function fetches play queue global controls.

Returns:
Play queue global data pointer.

Definition at line 419 of file UI_playQueue.c.

00420 {
00421     return &qGbl;
00422 }

st_PLAYQ* UI_playQcurrent void   ) 
 

Function returns current active queue pointer.

Returns:
Current play queue.

Definition at line 580 of file UI_playQueue.c.

Referenced by UI_PSF_play().

00581 {
00582     return qActv;
00583 }

st_PLAYQ* UI_playQnext void   ) 
 

Function advances the play queue.

Returns:
Play queue after being advanced.

Definition at line 432 of file UI_playQueue.c.

References AF_NULL, st_PLAYQGBL::flag, st_PLAYQ::format, st_PLAYQGBL::playCounter, st_SYSPARAM::repeat, and st_PLAYQGBL::totalTracks.

00433 {
00434     if(0 == qGbl.totalTracks) return NULL;
00435     
00436     if(qGbl.playCounter == qGbl.totalTracks)
00437     {
00438         qGbl.playCounter = 1;
00439         if(sysParam.repeat == 1) return NULL;
00440         else if(!(qGbl.flag&F_PLAYQGBL_TRACKVALID)) return NULL;
00441     }
00442     qActv = _playQnext(qActv);  
00443     qGbl.playCounter++;
00444     if(qActv)
00445     {
00446         if(AF_NULL != qActv->format) qGbl.flag |= F_PLAYQGBL_TRACKVALID;
00447     }
00448     return qActv;   
00449 }

st_PLAYQ* UI_playQprevious void   ) 
 

Function moves the play queue backward.

Returns:
Play queue after being moved.

Definition at line 459 of file UI_playQueue.c.

References st_PLAYQ::actvTrack, st_PLAYQ::album, st_PLAYQ::artist, DB_queryNext(), st_PLAYQ::duration, FAT_bfopen(), FAT_fclose(), st_PLAYQ::file, st_PLAYQGBL::flag, st_PLAYQ::fname, st_PLAYQ::format, st_PLAYQ::genre, st_PLAYQ::mdb, st_PLAYQGBL::playCounter, st_PLAYQ::prev, rb, st_SYSPARAM::repeat, st_PLAYQ::size, st_PLAYQ::title, st_PLAYQGBL::totalTracks, st_PLAYQGBL::trackStep, and UI_m3uGet().

00460 {
00461     unsigned short  actvTrack;
00462     USHORT          record[DB_MAXRECLEN];
00463     USHORT *        pD = &record[0];
00464     File *          fp;
00465     
00466     if( (0 == qGbl.totalTracks) || 
00467         ((qGbl.totalTracks == 1)&&((qActv->size ==0)||(sysParam.repeat == 1))) )
00468     {
00469         return NULL;
00470     }
00471     
00472     if(sysParam.repeat == 2)
00473     {
00474         if(qActv->format != AF_NULL) return qActv;
00475         else return NULL;
00476     }
00477     
00478     if(qGbl.playCounter>1) qGbl.playCounter--;
00479     
00480     actvTrack = (qGbl.totalTracks+qActv->actvTrack-qGbl.trackStep)%qGbl.totalTracks;
00481     actvTrack = (actvTrack==0)? qGbl.totalTracks:actvTrack;
00482     
00483     if(qActv != qHead)
00484     {
00485         // Track is queued already.
00486         qActv = qActv->prev;
00487         return qActv;
00488     }
00489     
00490     else
00491     {
00492         if(qTail->actvTrack == actvTrack)
00493         {
00494             // At head, and track is queued already, in which case 
00495             // the queue is big enough to hold all tracks.
00496             qActv = qTail; 
00497             return qActv;
00498         }
00499         
00500         // Queue track now.
00501         qActv = qActv->prev;
00502         qHead = qActv;
00503         
00504         if(qActv == qTail)
00505         {
00506             // Queue rollover.
00507             qTail = qTail->prev;
00508         }
00509         
00510         qActv->actvTrack = actvTrack;
00511     }
00512     
00513     DB_LOCK(SYS_FOREVER);
00514     
00515     qActv->format = AF_NULL;
00516     if(qGbl.flag & F_PLAYQGBL_FROMPLAYQ)
00517     {
00518         #ifdef M3U_SUPPORT
00519         if(SYS_isHDDpresent())
00520         {
00521             qActv->fname[0] = 'C';
00522             qActv->fname[1] = ':';
00523         }
00524         else
00525         {
00526             qActv->fname[0] = 'D';
00527             qActv->fname[1] = ':';
00528         }
00529 
00530         if(TRUE == UI_m3uGet(0, actvTrack,
00531                                 qActv->fname+2,
00532                                 qActv->artist,
00533                                 qActv->title,
00534                                 qActv->album,
00535                                 qActv->genre,
00536                                 &qActv->duration,
00537                                 &qActv->size ) )
00538         {
00539             qActv->format = _getMediaType(qActv->fname);
00540                 
00541             fp = FAT_bfopen(qActv->fname, rb, &qActv->file);
00542             if(fp) FAT_fclose(fp);
00543             else qActv->format = AF_NULL;
00544         }
00545         #endif
00546     }
00547     else
00548     {
00549         if(TRUE == DB_queryNext(dbHdl, actvTrack, (DB_DATA *)record))
00550         {
00551             qActv->mdb = ((ULONG)(*pD)<<16)|*(pD+1);
00552             if(TRUE == _interpretRecord(pInfo, (DB_DATA*)(pD+2), qActv))
00553             {
00554                 qActv->format = _getMediaType(qActv->fname);
00555                 //UI_assert(qActv->format!=AF_NULL, UI_PLAYQUEUE3);
00556                 
00557                 fp = FAT_bfopen(qActv->fname, rb, &qActv->file);
00558                 //UI_assert(fp!=NULL, UI_PLAYQUEUE1);
00559                 if(fp) FAT_fclose(fp);
00560                 else qActv->format = AF_NULL;
00561             }
00562         }
00563     }
00564     
00565     //if(SYS_isHDDpresent()) HDD_setPowerMode(HDD_STANDBY_IMMEDIATE, 0);
00566     //if(SYS_isHDDpresent()) HDD_setPowerMode(HDD_SLEEP, 0);
00567     if(SYS_isHDDpresent()) HDD_setPowerMode(HDD_POWEROFF, 0);
00568     DB_UNLOCK();
00569     return qActv;           
00570 }

Here is the call graph for this function:

BOOL UI_playQreset int  mode  ) 
 

Function resets the play queue if queue was generated out of Mymix.

Parameters:
mode Reset mode, 0: record added, 1: record removed, DONTCARE: shuffle mode change.
Returns:
TRUE if queue is not empty, otherwise FALSE.

Definition at line 344 of file UI_playQueue.c.

References st_PLAYQ::actvTrack, st_DBNAV::audio, DB_queryClose(), DB_queryFirst(), st_PLAYQGBL::flag, st_PLAYQGBL::playCounter, st_PLAYQGBL::playlist, st_SYSPARAM::repeat, st_SYSPARAM::shuffle, st_PLAYQGBL::totalTracks, st_PLAYQGBL::trackStep, and UI_m3uEntryNum().

Referenced by UI_PSF_play().

00345 {
00346     if( 0x1234 == mode )
00347     {
00348         #ifdef M3U_SUPPORT
00349         // Reset the current active track to be the first track in queue.
00350         qActv->actvTrack = 1; 
00351         
00352         qGbl.playlist[0]  = 0;
00353         qGbl.playCounter  = 1;
00354         
00355         UI_setPlaySource(PLAY_FROM_PLAYQ);
00356         qGbl.flag = F_PLAYQGBL_FROMPLAYQ|F_PLAYQGBL_TRACKVALID;
00357         qGbl.totalTracks = UI_m3uEntryNum(0);
00358         #endif
00359     }
00360     else if( mode != DONTCARE )
00361     {
00362         if(qGbl.flag & F_PLAYQGBL_FROMPLAYLIST)
00363         {
00364             char mymix[8];
00365             GEN_readXstr((ULONG)mymixRecord, (USHORT*)mymix, 8);        
00366             if(strcmp(qGbl.playlist, mymix+1) == 0) 
00367             {   
00368                 if(0==mode)
00369                 {
00370                     qGbl.totalTracks++;
00371                 }
00372                 else if(1==mode)
00373                 {
00374                     if(1>=qGbl.totalTracks) return FALSE;
00375                     qGbl.totalTracks--;
00376                 }
00377                 
00378                 // Reopen DB query controls.
00379                 DB_queryClose(dbHdl);
00380                 dbHdl = DB_queryFirst(DBnav.audio, 1, 1, 1, NULL);
00381             }
00382         }
00383         else if( qGbl.flag & F_PLAYQGBL_FROMPLAYQ )
00384         {
00385             #ifdef M3U_SUPPORT
00386             if(0==mode)
00387             {
00388                 qGbl.totalTracks++;
00389             }
00390             else if(1==mode)
00391             {
00392                 if(1>=qGbl.totalTracks) return FALSE;
00393                 qGbl.totalTracks--;
00394             }
00395             else return FALSE;
00396             #endif  
00397         }
00398     }
00399     
00400     _qInit(qActv);
00401     
00402     if( (2 != sysParam.repeat)&&(2 == sysParam.shuffle) )
00403     {
00404         qGbl.trackStep =  _initRandomMode(qGbl.totalTracks);
00405     }
00406     else qGbl.trackStep = 1;
00407     
00408     return TRUE;
00409 }

Here is the call graph for this function:

st_PLAYQ* UI_setupPlayQ DB_ID  id,
DB_FIELDIDX  fldIdx,
DB_ENTRY  entry,
USHORT  actvItem
 

Function sets up the play queue.

Parameters:
id DB ID.
fldIdx DB field index.
entry DB field entry.
actvItem Root entry.
Returns:
Queue pointer if queue is not empty, otherwise NULL.

Definition at line 95 of file UI_playQueue.c.

References st_PLAYQ::actvTrack, AF_NULL, st_PLAYQ::album, st_PLAYQ::artist, st_DBNAV::audio, Audio, DB_childID(), DB_getField(), DB_info(), DB_queryClose(), DB_queryFirst(), DB_queryNext(), st_AUDIO::duration, st_PLAYQ::duration, st_DBNAV::failedhisi, FAT_bfopen(), FAT_fclose(), st_PLAYQ::file, st_PLAYQGBL::flag, st_UI::fname, st_PLAYQ::fname, st_PLAYQ::format, st_PLAYQ::genre, st_DBNAV::idedhisi, st_PLAYQ::mdb, st_DBINFO::numOfPAIent, st_DBINFO::numOfSAIent, st_UI::path, st_PLAYQGBL::playCounter, st_PLAYQGBL::playlist, st_SYSPARAM::randomPattern, rb, st_PLAYQ::recordings, st_SYSPARAM::repeat, st_SYSPARAM::shuffle, st_PLAYQ::size, st_PLAYQ::title, st_PLAYQGBL::totalTracks, st_PLAYQGBL::trackStep, UI_m3uClear(), UI_m3uEntryNum(), and UI_m3uGet().

00096 {
00097     USHORT          itemNum;
00098     USHORT          record[DB_MAXRECLEN];
00099     USHORT *        pD = &record[0];
00100     File *          fp;
00101     BOOL            bTrackFound = TRUE;
00102     
00103     _qInit(NULL);
00104     qGbl.totalTracks  = 0;
00105     qGbl.flag         = 0;
00106     qGbl.playlist[0]  = 0;
00107     qGbl.playCounter  = 1;
00108     
00109     if(DB_INVALID_ID == id)
00110     { // Start of none-DB support.
00111         qGbl.totalTracks     = 1;
00112         qActv->actvTrack = 1;
00113         strcpy(qActv->fname, Ui.path);
00114         qActv->artist[0] = 0;
00115         strcpy(qActv->title, Ui.fname);
00116         qActv->album[0]      = 0;
00117         qActv->genre[0]      = 0;
00118         //qActv->playlist[0]   = 0;
00119         qActv->recordings[0] = 0;
00120         qActv->duration      = Audio.duration;
00121         qActv->size          = 0; // don't care.
00122     } // End of none-DB support.
00123     else    
00124     {
00125         DB_LOCK(SYS_FOREVER);
00126         // Check DB to fill up the queue.
00127 
00128         if(id == DBnav.audio)
00129         { // Start of Audio DB support. 
00130             UI_setPlaySource(PLAY_FROM_AUDIODB);
00131             
00132             #ifdef M3U_SUPPORT
00133             // Clear queue.
00134             if(UI_m3uEntryNum(0)) UI_m3uClear(0);
00135             #endif
00136             
00137             if( -1 == fldIdx ) fldIdx = 0;
00138 
00139             DB_queryClose(dbHdl);
00140             dbHdl = DB_queryFirst(id, fldIdx, entry, 1, NULL);
00141             if(dbHdl == DB_INVALID_HDL) QRET(NULL);
00142             
00143             pInfo = DB_info(dbHdl);
00144             
00145             if(fldIdx)
00146             {
00147                 itemNum = pInfo->numOfPAIent;
00148             }
00149             else
00150             {
00151                 itemNum = pInfo->numOfSAIent;
00152             }
00153             
00154             if(itemNum <= 1) 
00155             {
00156                 DB_queryClose(dbHdl);
00157                 QRET(NULL);
00158             }
00159             
00160             qGbl.totalTracks = itemNum-1;   
00161             
00162             if(DONTCARE == actvItem)
00163             {
00164                 if( (2 == sysParam.shuffle)&&(qGbl.totalTracks > 1) )
00165                 {
00166                     do
00167                     {
00168                         actvItem = rand()%qGbl.totalTracks;
00169                     } while(actvItem == 0);
00170                 }
00171                 else actvItem = 1;
00172             }           
00173             qActv->actvTrack = actvItem;
00174         
00175             bTrackFound = FALSE;
00176             if(TRUE == DB_queryNext(dbHdl, actvItem, (DB_DATA *)record))
00177             {   
00178                 qActv->mdb = ((ULONG)(*pD)<<16)|*(pD+1);
00179                 if(TRUE == _interpretRecord(pInfo, (DB_DATA*)(pD+2), qActv))
00180                 { 
00181                     // Hard coded to detect playlist access.
00182 //DeepB
00183 // BAAAAD QUEUE BEHAVIOUR !!!
00184 // The playlists ARE NOT the only fldIdx here.
00185 #ifdef USE_DATABASE_HACKS
00186                     if(fldIdx == 1) 
00187                     {
00188                         DB_HDL hdl;
00189                         USHORT record[DB_MAXRECLEN];
00190                         
00191                         qGbl.flag |= F_PLAYQGBL_FROMPLAYLIST;
00192                         hdl = DB_queryFirst(DB_childID(DBnav.audio, 1), 0, 0, entry, record);
00193                         if(DB_INVALID_HDL != hdl)
00194                         {
00195                             DB_getField(record+2,0,(DB_DATA*)qGbl.playlist,&DB_qinfo[hdl]);
00196                             DB_queryClose(hdl);
00197                         }
00198                     }   
00199 #endif
00200                     bTrackFound = TRUE;     
00201                 }
00202             }
00203         } // End of Audio DB support.
00204         else if(0x1234 == id)
00205         { // Start of play queue support.
00206             #ifdef M3U_SUPPORT
00207             UI_setPlaySource(PLAY_FROM_PLAYQ);
00208             itemNum = UI_m3uEntryNum(0);
00209             if(itemNum < 1) 
00210             {
00211                 QRET(NULL);
00212             }
00213             
00214             qGbl.totalTracks = itemNum; 
00215             qActv->actvTrack   = actvItem;
00216             bTrackFound = FALSE;
00217             if(SYS_isHDDpresent())
00218             {
00219                 qActv->fname[0] = 'C';
00220                 qActv->fname[1] = ':';
00221             }
00222             else
00223             {
00224                 qActv->fname[0] = 'D';
00225                 qActv->fname[1] = ':';
00226             }
00227             if(TRUE == UI_m3uGet(0, actvItem,
00228                                     qActv->fname+2,
00229                                     qActv->artist,
00230                                     qActv->title,
00231                                     qActv->album,
00232                                     qActv->genre,
00233                                     &qActv->duration,
00234                                     &qActv->size ) )
00235             
00236                     bTrackFound = TRUE;
00237             else    bTrackFound = FALSE;
00238             qGbl.flag |= F_PLAYQGBL_FROMPLAYQ;
00239             #endif
00240         } // End of play queue support.
00241         else
00242         { // Start of HiSi DB support.
00243             if(id == DBnav.failedhisi)
00244             {
00245                 UI_setPlaySource(PLAY_FROM_FAILEDHISI);
00246             }
00247             else if(id == DBnav.idedhisi)
00248             {
00249                 UI_setPlaySource(PLAY_FROM_IDEDHISI);
00250             }
00251             else
00252             {
00253                 UI_setPlaySource(PLAY_FROM_UNIDEDHISI);
00254             }
00255             
00256             fldIdx = 0;
00257             DB_queryClose(dbHdl);
00258             dbHdl = DB_queryFirst(id, fldIdx, entry, actvItem, NULL);
00259             if(dbHdl == DB_INVALID_HDL) QRET(NULL);
00260             pInfo = DB_info(dbHdl);
00261 
00262             itemNum = pInfo->numOfSAIent;
00263             
00264             if(itemNum <= 1) 
00265             {
00266                 DB_queryClose(dbHdl);
00267                 QRET(NULL);
00268             }
00269             
00270             qGbl.totalTracks = itemNum-1;   
00271             qActv->actvTrack   = actvItem;
00272         
00273             bTrackFound = FALSE;
00274             if(TRUE == DB_queryNext(dbHdl, actvItem, (DB_DATA *)record))
00275             {
00276                 qActv->mdb = ((ULONG)(*pD)<<16)|*(pD+1);
00277                 if(TRUE == _interpretRecord(pInfo, (DB_DATA*)(pD+2), qActv))
00278                 {
00279                     bTrackFound = TRUE;
00280                 }
00281             }
00282         } // End of HiSi DB support.
00283         
00284         DB_UNLOCK();
00285     }
00286     
00287     if(TRUE == bTrackFound)
00288     {
00289         qActv->format = _getMediaType(qActv->fname);
00290         //UI_assert(qActv->format!=AF_NULL, UI_PLAYQUEUE3);
00291         
00292         fp = FAT_bfopen(qActv->fname, rb, &qActv->file);
00293         //UI_assert(fp!=NULL, UI_PLAYQUEUE);
00294         if(fp) FAT_fclose(fp);
00295         else qActv->format = AF_NULL;
00296     }
00297     else qActv->format = AF_NULL;
00298     
00299     //if(SYS_isHDDpresent()) HDD_setPowerMode(HDD_STANDBY_IMMEDIATE, 0);
00300     //if(SYS_isHDDpresent()) HDD_setPowerMode(HDD_SLEEP, 0);
00301     if(SYS_isHDDpresent()) HDD_setPowerMode(HDD_POWEROFF, 0);   
00302     
00303     if( (2 != sysParam.repeat)&&(2 == sysParam.shuffle) )
00304     {
00305         if( (SYS_isUseSavedRandomPattern())&&
00306             (sysParam.randomPattern < qGbl.totalTracks)&&
00307             (sysParam.randomPattern > 0)&&
00308             (qGbl.totalTracks%sysParam.randomPattern) )
00309         {   
00310             qGbl.trackStep = sysParam.randomPattern;
00311         }
00312         else qGbl.trackStep =  _initRandomMode(qGbl.totalTracks);
00313     }
00314     else qGbl.trackStep = 1;
00315     
00316     if(AF_NULL != qActv->format) qGbl.flag |= F_PLAYQGBL_TRACKVALID;
00317     return qActv;
00318 }

Here is the call graph for this function:


Generated on Wed Jan 19 01:13:31 2005 for neuros-firmware by  doxygen 1.3.9.1