mp3.c
author nathan
Sat, 29 Dec 2007 14:56:02 +0100
branchtrunk
changeset 9 dc75c2890a31
parent 7 f5e05e2022f1
child 12 911ced691838
permissions -rw-r--r--
generate plugin version from hg identify
     1 /*
     2  * MP3/MPlayer plugin to VDR (C++)
     3  *
     4  * (C) 2001-2007 Stefan Huelswitt <s.huelswitt@gmx.de>
     5  *
     6  * This code is free software; you can redistribute it and/or
     7  * modify it under the terms of the GNU General Public License
     8  * as published by the Free Software Foundation; either version 2
     9  * of the License, or (at your option) any later version.
    10  *
    11  * This code is distributed in the hope that it will be useful,
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  * GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License
    17  * along with this program; if not, write to the Free Software
    18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    19  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
    20  */
    21 
    22 #include <stdlib.h>
    23 #include <getopt.h>
    24 #include <strings.h>
    25 #include <typeinfo>
    26 
    27 #include "common.h"
    28 
    29 #include <vdr/menuitems.h>
    30 #include <vdr/status.h>
    31 #include <vdr/plugin.h>
    32 #if APIVERSNUM >= 10307
    33 #include <vdr/interface.h>
    34 #include <vdr/skins.h>
    35 #endif
    36 
    37 #include "setup.h"
    38 #include "setup-mp3.h"
    39 #include "data-mp3.h"
    40 #include "data-src.h"
    41 #include "player-mp3.h"
    42 #include "menu.h"
    43 #include "menu-async.h"
    44 #include "decoder.h"
    45 #include "i18n.h"
    46 #include "version.h"
    47 #include "service.h"
    48 
    49 #ifdef DEBUG
    50 #include <mad.h>
    51 #endif
    52 
    53 const char *sourcesSub=0;
    54 cFileSources MP3Sources;
    55 
    56 static const char *plugin_name=0;
    57 
    58 // --- cMenuSetupMP3 --------------------------------------------------------
    59 
    60 class cMenuSetupMP3 : public cMenuSetupPage {
    61 private:
    62   cMP3Setup data;
    63   //
    64   const char *cddb[3], *disp[2], *scan[3], *bgr[3];
    65   const char *aout[AUDIOOUTMODES];
    66   int amode, amodes[AUDIOOUTMODES];
    67 protected:
    68   virtual void Store(void);
    69 public:
    70   cMenuSetupMP3(void);
    71   };
    72 
    73 cMenuSetupMP3::cMenuSetupMP3(void)
    74 {
    75   static const char allowed[] = { "abcdefghijklmnopqrstuvwxyz0123456789-_" };
    76   int numModes=0;
    77   aout[numModes]=trVDR("DVB"); amodes[numModes]=AUDIOOUTMODE_DVB; numModes++;
    78 #ifdef WITH_OSS
    79   aout[numModes]=tr("OSS"); amodes[numModes]=AUDIOOUTMODE_OSS; numModes++;
    80 #endif
    81   data=MP3Setup;
    82   amode=0;
    83   for(int i=0; i<numModes; i++)
    84     if(amodes[i]==data.AudioOutMode) { amode=i; break; }
    85 
    86   SetSection(tr("MP3"));
    87   Add(new cMenuEditStraItem(tr("Setup.MP3$Audio output mode"),     &amode,numModes,aout));
    88   Add(new cMenuEditBoolItem(tr("Setup.MP3$Audio mode"),            &data.AudioMode, tr("Round"), tr("Dither")));
    89   Add(new cMenuEditBoolItem(tr("Setup.MP3$Use 48kHz mode only"),   &data.Only48kHz));
    90 #if APIVERSNUM >= 10307
    91   disp[0]=tr("classic");
    92   disp[1]=tr("via skin");
    93   Add(new cMenuEditStraItem(tr("Setup.MP3$Replay display"),        &data.ReplayDisplay, 2, disp));
    94 #endif
    95   Add(new cMenuEditIntItem( tr("Setup.MP3$Display mode"),          &data.DisplayMode, 1, 3));
    96   bgr[0]=tr("Black");
    97   bgr[1]=tr("Live");
    98   bgr[2]=tr("Images");
    99   Add(new cMenuEditStraItem(tr("Setup.MP3$Background mode"),       &data.BackgrMode, 3, bgr));
   100   Add(new cMenuEditBoolItem(tr("Setup.MP3$Initial loop mode"),     &data.InitLoopMode));
   101   Add(new cMenuEditBoolItem(tr("Setup.MP3$Initial shuffle mode"),  &data.InitShuffleMode));
   102   Add(new cMenuEditBoolItem(tr("Setup.MP3$Abort player at end of list"),&data.AbortAtEOL));
   103   scan[0]=tr("disabled");
   104   scan[1]=tr("ID3 only");
   105   scan[2]=tr("ID3 & Level");
   106   Add(new cMenuEditStraItem(tr("Setup.MP3$Background scan"),       &data.BgrScan, 3, scan));
   107   Add(new cMenuEditBoolItem(tr("Setup.MP3$Editor display mode"),   &data.EditorMode, tr("Filenames"), tr("ID3 names")));
   108   Add(new cMenuEditBoolItem(tr("Setup.MP3$Mainmenu mode"),         &data.MenuMode, tr("Playlists"), tr("Browser")));
   109   Add(new cMenuEditBoolItem(tr("Setup.MP3$Keep selection menu"),   &data.KeepSelect));
   110   Add(new cMenuEditBoolItem(tr("Setup.MP3$Title/Artist order"),    &data.TitleArtistOrder, tr("Normal"), tr("Reversed")));
   111   Add(new cMenuEditBoolItem(tr("Hide mainmenu entry"),             &data.HideMainMenu));
   112   Add(new cMenuEditIntItem( tr("Setup.MP3$Normalizer level"),      &data.TargetLevel, 0, MAX_TARGET_LEVEL));
   113   Add(new cMenuEditIntItem( tr("Setup.MP3$Limiter level"),         &data.LimiterLevel, MIN_LIMITER_LEVEL, 100));
   114   Add(new cMenuEditBoolItem(tr("Setup.MP3$Use HTTP proxy"),        &data.UseProxy));
   115   Add(new cMenuEditStrItem( tr("Setup.MP3$HTTP proxy host"),       data.ProxyHost,MAX_HOSTNAME,allowed));
   116   Add(new cMenuEditIntItem( tr("Setup.MP3$HTTP proxy port"),       &data.ProxyPort,1,65535));
   117   cddb[0]=tr("disabled");
   118   cddb[1]=tr("local only");
   119   cddb[2]=tr("local&remote");
   120   Add(new cMenuEditStraItem(tr("Setup.MP3$CDDB for CD-Audio"),     &data.UseCddb,3,cddb));
   121   Add(new cMenuEditStrItem( tr("Setup.MP3$CDDB server"),           data.CddbHost,MAX_HOSTNAME,allowed));
   122   Add(new cMenuEditIntItem( tr("Setup.MP3$CDDB port"),             &data.CddbPort,1,65535));
   123 }
   124 
   125 void cMenuSetupMP3::Store(void)
   126 {
   127   data.AudioOutMode=amodes[amode];
   128 
   129   MP3Setup=data;
   130   SetupStore("InitLoopMode",     MP3Setup.InitLoopMode   );
   131   SetupStore("InitShuffleMode",  MP3Setup.InitShuffleMode);
   132   SetupStore("AudioMode",        MP3Setup.AudioMode      );
   133   SetupStore("AudioOutMode",     MP3Setup.AudioOutMode   );
   134   SetupStore("BgrScan",          MP3Setup.BgrScan        );
   135   SetupStore("EditorMode",       MP3Setup.EditorMode     );
   136   SetupStore("DisplayMode",      MP3Setup.DisplayMode    );
   137   SetupStore("BackgrMode",       MP3Setup.BackgrMode     );
   138   SetupStore("MenuMode",         MP3Setup.MenuMode       );
   139   SetupStore("TargetLevel",      MP3Setup.TargetLevel    );
   140   SetupStore("LimiterLevel",     MP3Setup.LimiterLevel   );
   141   SetupStore("Only48kHz",        MP3Setup.Only48kHz      );
   142   SetupStore("UseProxy",         MP3Setup.UseProxy       );
   143   SetupStore("ProxyHost",        MP3Setup.ProxyHost      );
   144   SetupStore("ProxyPort",        MP3Setup.ProxyPort      );
   145   SetupStore("UseCddb",          MP3Setup.UseCddb        );
   146   SetupStore("CddbHost",         MP3Setup.CddbHost       );
   147   SetupStore("CddbPort",         MP3Setup.CddbPort       );
   148   SetupStore("AbortAtEOL",       MP3Setup.AbortAtEOL     );
   149 #if APIVERSNUM >= 10307
   150   SetupStore("ReplayDisplay",    MP3Setup.ReplayDisplay  );
   151 #endif
   152   SetupStore("HideMainMenu",     MP3Setup.HideMainMenu   );
   153   SetupStore("KeepSelect",       MP3Setup.KeepSelect     );
   154   SetupStore("TitleArtistOrder", MP3Setup.TitleArtistOrder);
   155 }
   156 
   157 // --- cAsyncStatus ------------------------------------------------------------
   158 
   159 cAsyncStatus asyncStatus;
   160 
   161 cAsyncStatus::cAsyncStatus(void)
   162 {
   163   text=0;
   164   changed=false;
   165 }
   166 
   167 cAsyncStatus::~cAsyncStatus()
   168 {
   169   free((void *)text);
   170 }
   171 
   172 void cAsyncStatus::Set(const char *Text)
   173 {
   174   Lock();
   175   free((void *)text);
   176   text=Text ? strdup(Text) : 0;
   177   changed=true;
   178   Unlock();
   179 }
   180 
   181 const char *cAsyncStatus::Begin(void)
   182 {
   183   Lock();
   184   return text;
   185 }
   186 
   187 void cAsyncStatus::Finish(void)
   188 {
   189   changed=false;
   190   Unlock();
   191 }
   192 
   193 // --- --------------------------------------------------------------------
   194 
   195 static const char *TitleArtist(const char *title, const char *artist)
   196 {
   197   static char buf[256]; // clearly not multi-thread save!
   198   const char *fmt;
   199   if(artist && artist[0]) {
   200     if(MP3Setup.TitleArtistOrder) fmt="%2$s - %1$s";
   201     else  fmt="%s - %s";
   202     }
   203   else fmt="%s";
   204   snprintf(buf,sizeof(buf),fmt,title,artist);
   205   return buf;
   206 }
   207 
   208 // --- cMP3Control --------------------------------------------------------
   209 
   210 #if APIVERSNUM >= 10307
   211 #define clrBackground clrGray50
   212 #define eDvbColor int
   213 #define MAXROWS 120
   214 #define INLINE
   215 #else
   216 #define MAXROWS MAXOSDHEIGHT
   217 #define INLINE inline
   218 #endif
   219 
   220 class cMP3Control : public cControl {
   221 private:
   222 #if APIVERSNUM >= 10307
   223   cOsd *osd;
   224   const cFont *font;
   225   cSkinDisplayReplay *disp;
   226 #else
   227   bool statusInterfaceOpen;
   228 #endif
   229   int bw, bh, bwc, fw, fh;
   230   //
   231   cMP3Player *player;
   232   bool visible, shown, bigwin, statusActive;
   233   time_t timeoutShow, greentime, oktime;
   234   int lastkeytime, number;
   235   bool selecting;
   236   //
   237   cMP3PlayInfo *lastMode;
   238   time_t fliptime, listtime;
   239   int hashlist[MAXROWS];
   240   int flip, flipint, top, rows;
   241   int lastIndex, lastTotal, lastTop;
   242   int framesPerSecond;
   243   //
   244   bool jumpactive, jumphide, jumpsecs;
   245   int jumpmm;
   246   //
   247   void ShowTimed(int Seconds=0);
   248   void ShowProgress(bool open=false, bool bigWin=false);
   249   void ShowStatus(bool force);
   250   void HideStatus(void);
   251   void DisplayInfo(const char *s=0);
   252   void JumpDisplay(void);
   253   void JumpProcess(eKeys Key);
   254   void Jump(void);
   255   void Stop(void);
   256   INLINE void Write(int x, int y, int w, const char *text, eDvbColor fg=clrWhite, eDvbColor bg=clrBackground);
   257   INLINE void Fill(int x, int y, int w, int h, eDvbColor fg);
   258   inline void Flush(void);
   259 public:
   260   cMP3Control(void);
   261   virtual ~cMP3Control();
   262   virtual eOSState ProcessKey(eKeys Key);
   263   virtual void Show(void) { ShowTimed(); }
   264   virtual void Hide(void);
   265   bool Visible(void) { return visible; }
   266   static bool SetPlayList(cPlayList *plist);
   267   };
   268 
   269 cMP3Control::cMP3Control(void)
   270 :cControl(player=new cMP3Player)
   271 {
   272   visible=shown=bigwin=selecting=jumpactive=jumphide=statusActive=false;
   273   timeoutShow=greentime=oktime=0;
   274   lastkeytime=number=0;
   275   lastMode=0;
   276   framesPerSecond=SecondsToFrames(1);
   277 #if APIVERSNUM >= 10307
   278   osd=0; disp=0;
   279   font=cFont::GetFont(fontOsd);
   280 #else
   281   statusInterfaceOpen=false;
   282 #endif
   283 #if APIVERSNUM >= 10338
   284   cStatus::MsgReplaying(this,"MP3",0,true);
   285 #else
   286   cStatus::MsgReplaying(this,"MP3");
   287 #endif
   288 }
   289 
   290 cMP3Control::~cMP3Control()
   291 {
   292   delete lastMode;
   293   Hide();
   294   Stop();
   295 }
   296 
   297 void cMP3Control::Stop(void)
   298 {
   299 #if APIVERSNUM >= 10338
   300   cStatus::MsgReplaying(this,0,0,false);
   301 #else
   302   cStatus::MsgReplaying(this,0);
   303 #endif
   304   delete player; player=0;
   305   mgr->Halt();
   306   mgr->Flush(); //XXX remove later
   307 }
   308 
   309 bool cMP3Control::SetPlayList(cPlayList *plist)
   310 {
   311   bool res;
   312   cControl *control=cControl::Control();
   313   // is there a running MP3 player?
   314   if(control && typeid(*control)==typeid(cMP3Control)) {
   315     // add songs to running playlist
   316     mgr->Add(plist);
   317     res=true;
   318     }
   319   else {
   320     mgr->Flush();
   321     mgr->Add(plist);
   322     cControl::Launch(new cMP3Control);
   323     res=false;
   324     }
   325   delete plist;
   326   return res;
   327 }
   328 
   329 void cMP3Control::ShowTimed(int Seconds)
   330 {
   331   if(!visible) {
   332     ShowProgress(true);
   333     timeoutShow=(Seconds>0) ? time(0)+Seconds : 0;
   334     }
   335 }
   336 
   337 void cMP3Control::Hide(void)
   338 {
   339   HideStatus();
   340   timeoutShow=0;
   341   if(visible) {
   342 #if APIVERSNUM >= 10307
   343     delete osd; osd=0;
   344     delete disp; disp=0;
   345 #else
   346     Interface->Close();
   347 #endif
   348     visible=bigwin=false;
   349 #if APIVERSNUM >= 10500
   350     SetNeedsFastResponse(false);
   351 #else
   352     needsFastResponse=false;
   353 #endif
   354     }
   355 }
   356 
   357 void cMP3Control::ShowStatus(bool force)
   358 {
   359   if((asyncStatus.Changed() || (force && !statusActive)) && !jumpactive) {
   360     const char *text=asyncStatus.Begin();
   361     if(text) {
   362 #if APIVERSNUM >= 10307
   363       if(MP3Setup.ReplayDisplay || !osd) {
   364         if(statusActive) Skins.Message(mtStatus,0);
   365         Skins.Message(mtStatus,text);
   366         }
   367       else {
   368         if(!statusActive) osd->SaveRegion(0,bh-2*fh,bw-1,bh-fh-1);
   369         osd->DrawText(0,bh-2*fh,text,clrBlack,clrCyan,font,bw,fh,taCenter);
   370         osd->Flush();
   371         }
   372 #else
   373       if(!Interface->IsOpen()) {
   374         Interface->Open(0,-1);
   375         statusInterfaceOpen=true;
   376         }
   377       Interface->Status(text);
   378       Interface->Flush();
   379 #endif
   380       statusActive=true;
   381       }
   382     else
   383       HideStatus();
   384     asyncStatus.Finish();
   385     }
   386 }
   387 
   388 void cMP3Control::HideStatus(void)
   389 {
   390   if(statusActive) {
   391 #if APIVERSNUM >= 10307
   392     if(MP3Setup.ReplayDisplay || !osd)
   393       Skins.Message(mtStatus,0);
   394     else {
   395       osd->RestoreRegion();
   396       osd->Flush();
   397       }
   398 #else
   399     if(statusInterfaceOpen) {
   400       Interface->Close();
   401       statusInterfaceOpen=false;
   402       }
   403     else {
   404       Interface->Status(0);
   405       Interface->Flush();
   406       }
   407 #endif
   408     }
   409   statusActive=false;
   410 }
   411 
   412 #define CTAB    11 // some tabbing values for the progress display
   413 #define CTAB2   5
   414 
   415 void cMP3Control::Write(int x, int y, int w, const char *text, eDvbColor fg, eDvbColor bg)
   416 {
   417 #if APIVERSNUM >= 10307
   418   if(osd) {
   419     //d(printf("write x=%d y=%d w=%d ->",x,y,w))
   420     x*=fw; if(x<0) x+=bw;
   421     y*=fh; if(y<0) y+=bh;
   422     osd->DrawText(x,y,text,fg,bg,font,w*fw);
   423     //d(printf(" x=%d y=%d w=%d\n",x,y,w*fw))
   424     }
   425 #else
   426   if(w>0) Fill(x,y,w,1,bg);
   427   Interface->Write(x,y,text,fg,bg);
   428 #endif
   429 }
   430 
   431 void cMP3Control::Fill(int x, int y, int w, int h, eDvbColor fg)
   432 {
   433 #if APIVERSNUM >= 10307
   434   if(osd) {
   435     //d(printf("fill x=%d y=%d w=%d h=%d ->",x,y,w,h))
   436     x*=fw; if(x<0) x+=bw;
   437     y*=fh; if(y<0) y+=bh;
   438     osd->DrawRectangle(x,y,x+w*fw-1,y+h*fh-1,fg);
   439     //d(printf(" x=%d y=%d x2=%d y2=%d\n",x,y,x+h*fh-1,y+w*fw-1))
   440     }
   441 #else
   442   Interface->Fill(x,y,w,h,fg);
   443 #endif
   444 }
   445 
   446 void cMP3Control::Flush(void)
   447 {
   448 #if APIVERSNUM >= 10307
   449   if(MP3Setup.ReplayDisplay) Skins.Flush();
   450   else if(osd) osd->Flush();
   451 #else
   452   Interface->Flush();
   453 #endif
   454 }
   455 
   456 void cMP3Control::ShowProgress(bool open, bool bigWin)
   457 {
   458   int index, total;
   459 
   460   if(player->GetIndex(index,total) && total>=0) {
   461     if(!visible && open) {
   462       HideStatus();
   463 #if APIVERSNUM >= 10307
   464       if(MP3Setup.ReplayDisplay) {
   465         disp=Skins.Current()->DisplayReplay(false);
   466         if(!disp) return;
   467         bigWin=false;
   468         }
   469       else {
   470         int bt, bp;
   471         fw=font->Width(' ')*2;
   472         fh=font->Height();
   473         if(bigWin) {
   474           bw=Setup.OSDWidth;
   475           bh=Setup.OSDHeight;
   476           bt=0;
   477           bp=2*fh;
   478           rows=(bh-bp-fh/3)/fh;
   479           }
   480         else {
   481           bw=Setup.OSDWidth;
   482           bh=bp=2*fh;
   483           bt=Setup.OSDHeight-bh;
   484           rows=0;
   485           }
   486         bwc=bw/fw+1;
   487         //d(printf("mp3: bw=%d bh=%d bt=%d bp=%d bwc=%d rows=%d fw=%d fh=%d\n",
   488         //  bw,bh,bt,bp,bwc,rows,fw,fh))
   489         osd=cOsdProvider::NewOsd(Setup.OSDLeft,Setup.OSDTop+bt);
   490         if(!osd) return;
   491         if(bigWin) {
   492           tArea Areas[] = { { 0,0,bw-1,bh-bp-1,2 }, { 0,bh-bp,bw-1,bh-1,4 } };
   493           osd->SetAreas(Areas,sizeof(Areas)/sizeof(tArea));
   494           }
   495         else {
   496           tArea Areas[] = { { 0,0,bw-1,bh-1,4 } };
   497           osd->SetAreas(Areas,sizeof(Areas)/sizeof(tArea));
   498           }
   499         osd->DrawRectangle(0,0,bw-1,bh-1,clrGray50);
   500         osd->Flush();
   501         }
   502 #else
   503       fw=cOsd::CellWidth();
   504       fh=cOsd::LineHeight();
   505       bh=bigWin ? Setup.OSDheight : -2;
   506       bw=bwc=Setup.OSDwidth;
   507       rows=Setup.OSDheight-3;
   508       Interface->Open(bw,bh);
   509       Interface->Clear();
   510 #endif
   511       ShowStatus(true);
   512       bigwin=bigWin;
   513       visible=true;
   514 #if APIVERSNUM >= 10500
   515       SetNeedsFastResponse(true);
   516 #else
   517       needsFastResponse=true;
   518 #endif
   519       fliptime=listtime=0; flipint=0; flip=-1; top=lastTop=-1; lastIndex=lastTotal=-1;
   520       delete lastMode; lastMode=0;
   521       }
   522 
   523     cMP3PlayInfo *mode=new cMP3PlayInfo;
   524     bool valid=mgr->Info(-1,mode);
   525     bool changed=(!lastMode || mode->Hash!=lastMode->Hash);
   526     char buf[256];
   527     if(changed) { d(printf("mp3-ctrl: mode change detected\n")) }
   528 
   529     if(valid) { // send progress to status monitor
   530       if(changed || mode->Loop!=lastMode->Loop || mode->Shuffle!=lastMode->Shuffle) {
   531         snprintf(buf,sizeof(buf),"[%c%c] (%d/%d) %s",
   532                   mode->Loop?'L':'.',mode->Shuffle?'S':'.',mode->Num,mode->MaxNum,TitleArtist(mode->Title,mode->Artist));
   533 #if APIVERSNUM >= 10338
   534         cStatus::MsgReplaying(this,buf,mode->Filename[0]?mode->Filename:0,true);
   535 #else
   536         cStatus::MsgReplaying(this,buf);
   537 #endif
   538         }
   539       }
   540 
   541     if(visible) { // refresh the OSD progress display
   542       bool flush=false;
   543 
   544 #if APIVERSNUM >= 10307
   545       if(MP3Setup.ReplayDisplay) {
   546         if(!statusActive) {
   547           if(total>0) disp->SetProgress(index,total);
   548           disp->SetCurrent(IndexToHMSF(index));
   549           disp->SetTotal(IndexToHMSF(total));
   550           bool Play, Forward;
   551           int Speed;
   552           if(GetReplayMode(Play,Forward,Speed)) 
   553             disp->SetMode(Play, Forward, Speed);
   554           flush=true;
   555           }
   556         }
   557       else {
   558 #endif
   559         if(!selecting && changed && !statusActive) {
   560           snprintf(buf,sizeof(buf),"(%d/%d)",mode->Num,mode->MaxNum);
   561           Write(0,-2,CTAB,buf);
   562           flush=true;
   563           }
   564 
   565         if(!lastMode || mode->Loop!=lastMode->Loop) {
   566           if(mode->Loop) Write(-4,-1,0,"L",clrBlack,clrYellow);
   567           else Fill(-4,-1,2,1,clrBackground);
   568           flush=true;
   569           }
   570         if(!lastMode || mode->Shuffle!=lastMode->Shuffle) {
   571           if(mode->Shuffle) Write(-2,-1,0,"S",clrWhite,clrRed);
   572           else Fill(-2,-1,2,1,clrBackground);
   573           flush=true;
   574           }
   575 
   576         index/=framesPerSecond; total/=framesPerSecond;
   577         if(index!=lastIndex || total!=lastTotal) {
   578           if(total>0) {
   579 #if APIVERSNUM >= 10307
   580             cProgressBar ProgressBar(bw-(CTAB+CTAB2)*fw,fh,index,total);
   581             osd->DrawBitmap(CTAB*fw,bh-fh,ProgressBar);
   582 #else
   583             cProgressBar ProgressBar((bw-CTAB-CTAB2)*fw,fh,index,total);
   584             Interface->SetBitmap(CTAB*fw,(abs(bh)-1)*fh,ProgressBar);
   585 #endif
   586             }
   587           snprintf(buf,sizeof(buf),total?"%02d:%02d/%02d:%02d":"%02d:%02d",index/60,index%60,total/60,total%60);
   588           Write(0,-1,11,buf);
   589           flush=true;
   590           }
   591 #if APIVERSNUM >= 10307
   592         }
   593 #endif
   594 
   595       if(!jumpactive) {
   596         bool doflip=false;
   597         if(MP3Setup.ReplayDisplay && (!lastMode || mode->Loop!=lastMode->Loop || mode->Shuffle!=lastMode->Shuffle))
   598           doflip=true;
   599         if(!valid || changed) {
   600           fliptime=time(0); flip=0;
   601 	  doflip=true;
   602 	  }
   603         else if(time(0)>fliptime+flipint) {
   604 	  fliptime=time(0);
   605 	  flip++; if(flip>=MP3Setup.DisplayMode) flip=0;
   606           doflip=true;
   607 	  }
   608         if(doflip) {
   609           buf[0]=0;
   610           switch(flip) {
   611 	    default:
   612 	      flip=0;
   613 	      // fall through
   614 	    case 0:
   615 	      snprintf(buf,sizeof(buf),"%s",TitleArtist(mode->Title,mode->Artist));
   616 	      flipint=6;
   617 	      break;
   618 	    case 1:
   619               if(mode->Album[0]) {
   620       	        snprintf(buf,sizeof(buf),mode->Year>0?"from: %s (%d)":"from: %s",mode->Album,mode->Year);
   621 	        flipint=4;
   622 	        }
   623               else fliptime=0;
   624               break;
   625 	    case 2:
   626               if(mode->MaxBitrate>0)
   627                 snprintf(buf,sizeof(buf),"%.1f kHz, %d-%d kbps, %s",mode->SampleFreq/1000.0,mode->Bitrate/1000,mode->MaxBitrate/1000,mode->SMode);
   628               else
   629                 snprintf(buf,sizeof(buf),"%.1f kHz, %d kbps, %s",mode->SampleFreq/1000.0,mode->Bitrate/1000,mode->SMode);
   630 	      flipint=3;
   631 	      break;
   632 	    }
   633           if(buf[0]) {
   634 #if APIVERSNUM >= 10307
   635             if(MP3Setup.ReplayDisplay) {
   636               char buf2[256];
   637               snprintf(buf2,sizeof(buf2),"[%c%c] (%d/%d) %s",
   638                        mode->Loop?'L':'.',mode->Shuffle?'S':'.',mode->Num,mode->MaxNum,buf);
   639               disp->SetTitle(buf2);
   640               flush=true;
   641               }
   642             else {
   643 #endif
   644               if(!statusActive) {
   645                 DisplayInfo(buf);
   646                 flush=true;
   647                 }
   648               else { d(printf("mp3-ctrl: display info skip due to status active\n")) }
   649 #if APIVERSNUM >= 10307
   650               }
   651 #endif
   652             }
   653           }
   654         }
   655 
   656       if(bigwin) {
   657         bool all=(top!=lastTop || changed);
   658         if(all || time(0)>listtime+2) {
   659           int num=(top>0 && mode->Num==lastMode->Num) ? top : mode->Num - rows/2;
   660           if(num+rows>mode->MaxNum) num=mode->MaxNum-rows+1;
   661           if(num<1) num=1;
   662           top=num;
   663           for(int i=0 ; i<rows && i<MAXROWS && num<=mode->MaxNum ; i++,num++) {
   664             cMP3PlayInfo pi;
   665             mgr->Info(num,&pi); if(!pi.Title[0]) break;
   666             snprintf(buf,sizeof(buf),"%d.\t%s",num,TitleArtist(pi.Title,pi.Artist));
   667             eDvbColor fg=clrWhite, bg=clrBackground;
   668             int hash=MakeHash(buf);
   669             if(num==mode->Num) { fg=clrBlack; bg=clrCyan; hash=(hash^77) + 23; }
   670             if(all || hash!=hashlist[i]) {
   671               char *s=rindex(buf,'\t');
   672               if(s) {
   673                 *s++=0;
   674                 Write(0,i,5,buf,fg,bg);
   675                 Write(5,i,bwc-5,s,fg,bg);
   676                 }
   677               else
   678                 Write(0,i,bwc,buf,fg,bg);
   679               flush=true;
   680               hashlist[i]=hash;
   681               }
   682             }
   683           listtime=time(0); lastTop=top;
   684           }
   685         }
   686 
   687       if(flush) Flush();
   688       }
   689 
   690     lastIndex=index; lastTotal=total;
   691     delete lastMode; lastMode=mode;
   692     }
   693 }
   694 
   695 void cMP3Control::DisplayInfo(const char *s)
   696 {
   697   if(s) Write(CTAB,-2,bwc-CTAB,s);
   698   else Fill(CTAB,-2,bwc-CTAB,1,clrBackground);
   699 }
   700 
   701 void cMP3Control::JumpDisplay(void)
   702 {
   703   char buf[64];
   704   const char *j=trVDR("Jump: "), u=jumpsecs?'s':'m';
   705   if(!jumpmm) sprintf(buf,"%s- %c",  j,u);
   706   else        sprintf(buf,"%s%d- %c",j,jumpmm,u);
   707 #if APIVERSNUM >= 10307
   708   if(MP3Setup.ReplayDisplay) {
   709     disp->SetJump(buf);
   710     }
   711   else {
   712 #endif
   713     DisplayInfo(buf);
   714 #if APIVERSNUM >= 10307
   715     }
   716 #endif
   717 }
   718 
   719 void cMP3Control::JumpProcess(eKeys Key)
   720 {
   721  int n=Key-k0, d=jumpsecs?1:60;
   722   switch (Key) {
   723     case k0 ... k9:
   724       if(jumpmm*10+n <= lastTotal/d) jumpmm=jumpmm*10+n;
   725       JumpDisplay();
   726       break;
   727     case kBlue:
   728       jumpsecs=!jumpsecs;
   729       JumpDisplay();
   730       break;
   731     case kPlay:
   732     case kUp:
   733       jumpmm-=lastIndex/d;
   734       // fall through
   735     case kFastRew:
   736     case kFastFwd:
   737     case kLeft:
   738     case kRight:
   739       player->SkipSeconds(jumpmm*d * ((Key==kLeft || Key==kFastRew) ? -1:1));
   740       // fall through
   741     default:
   742       jumpactive=false;
   743       break;
   744     }
   745 
   746   if(!jumpactive) {
   747     if(jumphide) Hide();
   748 #if APIVERSNUM >= 10307
   749     else if(MP3Setup.ReplayDisplay) disp->SetJump(0);
   750 #endif
   751     }
   752 }
   753 
   754 void cMP3Control::Jump(void)
   755 {
   756   jumpmm=0; jumphide=jumpsecs=false;
   757   if(!visible) {
   758     ShowTimed(); if(!visible) return;
   759     jumphide=true;
   760     }
   761   JumpDisplay();
   762   jumpactive=true; fliptime=0; flip=-1;
   763 }
   764 
   765 eOSState cMP3Control::ProcessKey(eKeys Key)
   766 {
   767   if(!player->Active()) return osEnd;
   768 
   769   if(timeoutShow && time(0)>timeoutShow) Hide();
   770   ShowProgress();
   771 #if APIVERSNUM >= 10307
   772   ShowStatus(Key==kNone && !Skins.IsOpen());
   773 #else
   774   ShowStatus(Key==kNone && !Interface->IsOpen());
   775 #endif
   776 
   777   if(jumpactive && Key!=kNone) { JumpProcess(Key); return osContinue; }
   778 
   779   switch(Key) {
   780     case kUp:
   781     case kUp|k_Repeat:
   782 #if APIVERSNUM >= 10347
   783     case kNext:
   784     case kNext|k_Repeat:    
   785 #endif
   786       mgr->Next(); player->Play();
   787       break;
   788     case kDown:
   789     case kDown|k_Repeat:
   790 #if APIVERSNUM >= 10347
   791     case kPrev:
   792     case kPrev|k_Repeat:
   793 #endif
   794       if(!player->PrevCheck()) mgr->Prev();
   795       player->Play();
   796       break;
   797     case kLeft:
   798     case kLeft|k_Repeat:
   799       if(bigwin) {
   800         if(top>0) { top-=rows; if(top<1) top=1; }
   801         break;
   802         }
   803       // fall through
   804     case kFastRew:
   805     case kFastRew|k_Repeat:
   806       if(!player->IsStream()) player->SkipSeconds(-JUMPSIZE);
   807       break;
   808     case kRight:
   809     case kRight|k_Repeat:
   810       if(bigwin) {
   811         if(top>0) top+=rows;
   812         break;
   813         }
   814       // fall through
   815     case kFastFwd:
   816     case kFastFwd|k_Repeat:
   817       if(!player->IsStream()) player->SkipSeconds(JUMPSIZE);
   818       break;
   819     case kRed:
   820       if(!player->IsStream()) Jump();
   821       break;
   822     case kGreen:
   823       if(lastMode) {
   824         if(time(0)>greentime) {
   825           if(lastMode->Loop || (!lastMode->Loop && !lastMode->Shuffle)) mgr->ToggleLoop();
   826           if(lastMode->Shuffle) mgr->ToggleShuffle();
   827           }
   828         else {
   829           if(!lastMode->Loop) mgr->ToggleLoop();
   830           else if(!lastMode->Shuffle) mgr->ToggleShuffle();
   831           else mgr->ToggleLoop();
   832           }
   833         greentime=time(0)+MULTI_TIMEOUT;
   834         }
   835       break;
   836     case kPlay:
   837       player->Play();
   838       break;
   839     case kPause:
   840     case kYellow:
   841       if(!player->IsStream()) player->Pause();
   842       break;
   843     case kStop:
   844     case kBlue:
   845       Hide();
   846       Stop();
   847       return osEnd;
   848     case kBack:
   849       Hide();
   850 #if APIVERSNUM >= 10332
   851       cRemote::CallPlugin(plugin_name);
   852       return osBack;
   853 #else
   854       return osEnd;
   855 #endif
   856 
   857     case k0 ... k9:
   858       number=number*10+Key-k0;
   859       if(lastMode && number>0 && number<=lastMode->MaxNum) {
   860         if(!visible) ShowTimed(SELECTHIDE_TIMEOUT);
   861         else if(timeoutShow>0) timeoutShow=time(0)+SELECTHIDE_TIMEOUT;
   862         selecting=true; lastkeytime=time_ms();
   863         char buf[32];
   864 #if APIVERSNUM >= 10307
   865         if(MP3Setup.ReplayDisplay) {
   866           snprintf(buf,sizeof(buf),"%s%d-/%d",trVDR("Jump: "),number,lastMode->MaxNum);
   867           disp->SetJump(buf);
   868           }
   869         else {
   870 #endif
   871           snprintf(buf,sizeof(buf),"(%d-/%d)",number,lastMode->MaxNum);
   872           Write(0,-2,CTAB,buf);
   873 #if APIVERSNUM >= 10307
   874           }
   875 #endif
   876         Flush();
   877         break;
   878         }
   879       number=0; lastkeytime=0;
   880       // fall through
   881     case kNone:
   882       if(selecting && time_ms()-lastkeytime>SELECT_TIMEOUT) {
   883         if(number>0) { mgr->Goto(number); player->Play();  }
   884         if(lastMode) lastMode->Hash=-1;
   885         number=0; selecting=false;
   886 #if APIVERSNUM >= 10307
   887         if(MP3Setup.ReplayDisplay && disp) disp->SetJump(0);
   888 #endif
   889         }
   890       break;
   891     case kOk:
   892       if(time(0)>oktime || MP3Setup.ReplayDisplay) {
   893         visible ? Hide() : ShowTimed();
   894         }
   895       else {
   896         if(visible && !bigwin) { Hide(); ShowProgress(true,true); }
   897         else { Hide(); ShowTimed(); }
   898         }
   899       oktime=time(0)+MULTI_TIMEOUT;
   900       ShowStatus(true);
   901       break;
   902     default:
   903       return osUnknown;
   904     }
   905   return osContinue;
   906 }
   907 
   908 // --- cMenuID3Info ------------------------------------------------------------
   909 
   910 class cMenuID3Info : public cOsdMenu {
   911 private:
   912   cOsdItem *Item(const char *name, const char *text);
   913   cOsdItem *Item(const char *name, const char *format, const float num);
   914   void Build(cSongInfo *info, const char *name);
   915 public:
   916   cMenuID3Info(cSong *song);
   917   cMenuID3Info(cSongInfo *si, const char *name);
   918   virtual eOSState ProcessKey(eKeys Key);
   919   };
   920 
   921 cMenuID3Info::cMenuID3Info(cSong *song)
   922 :cOsdMenu(tr("ID3 information"),12)
   923 {
   924   Build(song->Info(),song->Name());
   925 }
   926 
   927 cMenuID3Info::cMenuID3Info(cSongInfo *si, const char *name)
   928 :cOsdMenu(tr("ID3 information"),12)
   929 {
   930   Build(si,name);
   931 }
   932 
   933 void cMenuID3Info::Build(cSongInfo *si, const char *name)
   934 {
   935   if(si) {
   936     Item(tr("Filename"),name);
   937     if(si->HasInfo() && si->Total>0) {
   938       char *buf=0;
   939       asprintf(&buf,"%02d:%02d",si->Total/60,si->Total%60);
   940       Item(tr("Length"),buf);
   941       free(buf);
   942       Item(tr("Title"),si->Title);
   943       Item(tr("Artist"),si->Artist);
   944       Item(tr("Album"),si->Album);
   945       Item(tr("Year"),0,(float)si->Year);
   946       Item(tr("Samplerate"),"%.1f kHz",si->SampleFreq/1000.0);
   947       Item(tr("Bitrate"),"%.f kbit/s",si->Bitrate/1000.0);
   948       Item(trVDR("Channels"),0,(float)si->Channels);
   949       }
   950     Display();
   951     }
   952 }
   953 
   954 cOsdItem *cMenuID3Info::Item(const char *name, const char *format, const float num)
   955 {
   956   cOsdItem *item;
   957   if(num>=0.0) {
   958     char *buf=0;
   959     asprintf(&buf,format?format:"%.f",num);
   960     item=Item(name,buf);
   961     free(buf);
   962     }
   963   else item=Item(name,"");
   964   return item;
   965 }
   966 
   967 cOsdItem *cMenuID3Info::Item(const char *name, const char *text)
   968 {
   969   char *buf=0;
   970   asprintf(&buf,"%s:\t%s",name,text?text:"");
   971   cOsdItem *item = new cOsdItem(buf,osBack);
   972 #if APIVERSNUM >= 10307
   973   item->SetSelectable(false);
   974 #else
   975   item->SetColor(clrWhite, clrBackground);
   976 #endif
   977   free(buf);
   978   Add(item); return item;
   979 }
   980 
   981 eOSState cMenuID3Info::ProcessKey(eKeys Key)
   982 {
   983   eOSState state = cOsdMenu::ProcessKey(Key);
   984 
   985   if(state==osUnknown) {
   986      switch(Key) {
   987        case kRed:
   988        case kGreen:
   989        case kYellow:
   990        case kBlue:   return osContinue;
   991        case kMenu:   return osEnd;
   992        default: break;
   993        }
   994      }
   995   return state;
   996 }
   997 
   998 // --- cMenuInstantBrowse -------------------------------------------------------
   999 
  1000 class cMenuInstantBrowse : public cMenuBrowse {
  1001 private:
  1002   const char *selecttext, *alltext;
  1003   virtual void SetButtons(void);
  1004   virtual eOSState ID3Info(void);
  1005 public:
  1006   cMenuInstantBrowse(cFileSource *Source, const char *Selecttext, const char *Alltext);
  1007   virtual eOSState ProcessKey(eKeys Key);
  1008   };
  1009 
  1010 cMenuInstantBrowse::cMenuInstantBrowse(cFileSource *Source, const char *Selecttext, const char *Alltext)
  1011 :cMenuBrowse(Source,true,true,tr("Directory browser"),excl_br)
  1012 {
  1013   selecttext=Selecttext; alltext=Alltext;
  1014   SetButtons();
  1015 }
  1016 
  1017 void cMenuInstantBrowse::SetButtons(void)
  1018 {
  1019   SetHelp(selecttext, currentdir?tr("Parent"):0, currentdir?0:alltext, tr("ID3 info"));
  1020   Display();
  1021 }
  1022 
  1023 eOSState cMenuInstantBrowse::ID3Info(void)
  1024 {
  1025   cFileObj *item=CurrentItem();
  1026   if(item && item->Type()==otFile) {
  1027     cSong *song=new cSong(item);
  1028     cSongInfo *si;
  1029     if(song && (si=song->Info())) {
  1030       AddSubMenu(new cMenuID3Info(si,item->Path()));
  1031       }
  1032     delete song;
  1033     }
  1034   return osContinue;
  1035 }
  1036 
  1037 eOSState cMenuInstantBrowse::ProcessKey(eKeys Key)
  1038 {
  1039   eOSState state=cOsdMenu::ProcessKey(Key);
  1040   if(state==osUnknown) {
  1041      switch (Key) {
  1042        case kYellow: lastselect=new cFileObj(source,0,0,otBase);
  1043                      return osBack;
  1044        default: break;
  1045        }
  1046      }
  1047   if(state==osUnknown) state=cMenuBrowse::ProcessStdKey(Key,state);
  1048   return state;
  1049 }
  1050 
  1051 // --- cMenuPlayListItem -------------------------------------------------------
  1052 
  1053 class cMenuPlayListItem : public cOsdItem {
  1054   private:
  1055   bool showID3;
  1056   cSong *song;
  1057 public:
  1058   cMenuPlayListItem(cSong *Song, bool showid3);
  1059   cSong *Song(void) { return song; }
  1060   virtual void Set(void);
  1061   void Set(bool showid3);
  1062   };
  1063 
  1064 cMenuPlayListItem::cMenuPlayListItem(cSong *Song, bool showid3)
  1065 {
  1066   song=Song;
  1067   Set(showid3);
  1068 }
  1069 
  1070 void cMenuPlayListItem::Set(bool showid3)
  1071 {
  1072   showID3=showid3;
  1073   Set();
  1074 }
  1075 
  1076 void cMenuPlayListItem::Set(void)
  1077 {
  1078   char *buffer=0;
  1079   cSongInfo *si=song->Info(false);
  1080   if(showID3 && !si) si=song->Info();
  1081   if(showID3 && si && si->Title)
  1082     asprintf(&buffer, "%d.\t%s",song->Index()+1,TitleArtist(si->Title,si->Artist));
  1083   else
  1084     asprintf(&buffer, "%d.\t<%s>",song->Index()+1,song->Name());
  1085   SetText(buffer,false);
  1086 }
  1087 
  1088 // --- cMenuPlayList ------------------------------------------------------
  1089 
  1090 class cMenuPlayList : public cOsdMenu {
  1091 private:
  1092   cPlayList *playlist;
  1093   bool browsing, showid3;
  1094   void Buttons(void);
  1095   void Refresh(bool all = false);
  1096   void Add(void);
  1097   virtual void Move(int From, int To);
  1098   eOSState Remove(void);
  1099   eOSState ShowID3(void);
  1100   eOSState ID3Info(void);
  1101 public:
  1102   cMenuPlayList(cPlayList *Playlist);
  1103   virtual eOSState ProcessKey(eKeys Key);
  1104   };
  1105 
  1106 cMenuPlayList::cMenuPlayList(cPlayList *Playlist)
  1107 :cOsdMenu(tr("Playlist editor"),4)
  1108 {
  1109   browsing=showid3=false;
  1110   playlist=Playlist;
  1111   if(MP3Setup.EditorMode) showid3=true;
  1112 
  1113   cSong *mp3 = playlist->First();
  1114   while(mp3) {
  1115     cOsdMenu::Add(new cMenuPlayListItem(mp3,showid3));
  1116     mp3 = playlist->cList<cSong>::Next(mp3);
  1117     }
  1118   Buttons(); Display();
  1119 }
  1120 
  1121 void cMenuPlayList::Buttons(void)
  1122 {
  1123   SetHelp(tr("Add"), showid3?tr("Filenames"):tr("ID3 names"), tr("Remove"), trVDR(BUTTON"Mark"));
  1124 }
  1125 
  1126 void cMenuPlayList::Refresh(bool all)
  1127 {
  1128   cMenuPlayListItem *cur=(cMenuPlayListItem *)((all || Count()<2) ? First() : Get(Current()));
  1129   while(cur) {
  1130     cur->Set(showid3);
  1131     cur=(cMenuPlayListItem *)Next(cur);
  1132     }
  1133 }
  1134 
  1135 void cMenuPlayList::Add(void)
  1136 {
  1137   cFileObj *item=cMenuInstantBrowse::GetSelected();
  1138   if(item) {
  1139     Status(tr("Scanning directory..."));
  1140     cInstantPlayList *newpl=new cInstantPlayList(item);
  1141     if(newpl->Load()) {
  1142       if(newpl->Count()) {
  1143         if(newpl->Count()==1 || Interface->Confirm(tr("Add recursivly?"))) {
  1144           cSong *mp3=newpl->First();
  1145           while(mp3) {
  1146             cSong *n=new cSong(mp3);
  1147             if(Count()>0) {
  1148               cMenuPlayListItem *current=(cMenuPlayListItem *)Get(Current());
  1149               playlist->Add(n,current->Song());
  1150               cOsdMenu::Add(new cMenuPlayListItem(n,showid3),true,current);
  1151               }
  1152             else {
  1153               playlist->Add(n);
  1154               cOsdMenu::Add(new cMenuPlayListItem(n,showid3),true);
  1155               }
  1156             mp3=newpl->cList<cSong>::Next(mp3);
  1157             }
  1158           playlist->Save();
  1159           Refresh(); Display();
  1160           }
  1161         }
  1162       else Error(tr("Empty directory!"));
  1163       }
  1164     else Error(tr("Error scanning directory!"));
  1165     delete newpl;
  1166     Status(0);
  1167     }
  1168 }
  1169 
  1170 void cMenuPlayList::Move(int From, int To)
  1171 {
  1172   playlist->Move(From,To); playlist->Save();
  1173   cOsdMenu::Move(From,To);
  1174   Refresh(true); Display();
  1175 }
  1176 
  1177 eOSState cMenuPlayList::ShowID3(void)
  1178 {
  1179   showid3=!showid3;
  1180   Buttons(); Refresh(true); Display();
  1181   return osContinue;
  1182 }
  1183 
  1184 eOSState cMenuPlayList::ID3Info(void)
  1185 {
  1186   if(Count()>0) {
  1187     cMenuPlayListItem *current = (cMenuPlayListItem *)Get(Current());
  1188     AddSubMenu(new cMenuID3Info(current->Song()));
  1189     }
  1190   return osContinue;
  1191 }
  1192 
  1193 eOSState cMenuPlayList::Remove(void)
  1194 {
  1195   if(Count()>0) {
  1196     cMenuPlayListItem *current = (cMenuPlayListItem *)Get(Current());
  1197     if(Interface->Confirm(tr("Remove entry?"))) {
  1198       playlist->Del(current->Song()); playlist->Save();
  1199       cOsdMenu::Del(Current());
  1200       Refresh(); Display();
  1201       }
  1202     }
  1203   return osContinue;
  1204 }
  1205 
  1206 eOSState cMenuPlayList::ProcessKey(eKeys Key)
  1207 {
  1208   eOSState state = cOsdMenu::ProcessKey(Key);
  1209 
  1210   if(browsing && !HasSubMenu() && state==osContinue) { Add(); browsing=false; }
  1211 
  1212   if(state==osUnknown) {
  1213      switch(Key) {
  1214        case kOk:     return ID3Info();
  1215        case kRed:    browsing=true;
  1216                      return AddSubMenu(new cMenuInstantBrowse(MP3Sources.GetSource(),tr("Add"),tr("Add all")));
  1217        case kGreen:  return ShowID3();
  1218        case kYellow: return Remove();
  1219        case kBlue:   Mark(); return osContinue;
  1220        case kMenu:   return osEnd;
  1221        default: break;
  1222        }
  1223      }
  1224   return state;
  1225 }
  1226 
  1227 // --- cPlaylistRename --------------------------------------------------------
  1228 
  1229 class cPlaylistRename : public cOsdMenu {
  1230 private:
  1231   static char *newname;
  1232   const char *oldname;
  1233   char data[64];
  1234 public:
  1235   cPlaylistRename(const char *Oldname);
  1236   virtual eOSState ProcessKey(eKeys Key);
  1237   static const char *GetNewname(void) { return newname; }
  1238   };
  1239 
  1240 char *cPlaylistRename::newname = NULL;
  1241 
  1242 cPlaylistRename::cPlaylistRename(const char *Oldname)
  1243 :cOsdMenu(tr("Rename playlist"), 15)
  1244 {
  1245   free(newname); newname=0;
  1246 
  1247   oldname=Oldname;
  1248   char *buf=NULL;
  1249   asprintf(&buf,"%s\t%s",tr("Old name:"),oldname);
  1250   cOsdItem *old = new cOsdItem(buf,osContinue);
  1251 #if APIVERSNUM >= 10307
  1252   old->SetSelectable(false);
  1253 #else
  1254   old->SetColor(clrWhite, clrBackground);
  1255 #endif
  1256   Add(old);
  1257   free(buf);
  1258 
  1259   data[0]=0;
  1260   Add(new cMenuEditStrItem( tr("New name"), data, sizeof(data)-1, tr(FileNameChars)),true);
  1261 }
  1262 
  1263 eOSState cPlaylistRename::ProcessKey(eKeys Key)
  1264 {
  1265   eOSState state = cOsdMenu::ProcessKey(Key);
  1266 
  1267   if (state == osUnknown) {
  1268      switch (Key) {
  1269        case kOk:     if(data[0] && strcmp(data,oldname)) newname=strdup(data);
  1270                      return osBack;
  1271        case kRed:
  1272        case kGreen:
  1273        case kYellow:
  1274        case kBlue:   return osContinue;
  1275        default: break;
  1276        }
  1277      }
  1278   return state;
  1279 }
  1280 
  1281 // --- cMenuMP3Item -----------------------------------------------------
  1282 
  1283 class cMenuMP3Item : public cOsdItem {
  1284   private:
  1285   cPlayList *playlist;
  1286   virtual void Set(void);
  1287 public:
  1288   cMenuMP3Item(cPlayList *PlayList);
  1289   cPlayList *List(void) { return playlist; }
  1290   };
  1291 
  1292 cMenuMP3Item::cMenuMP3Item(cPlayList *PlayList)
  1293 {
  1294   playlist=PlayList;
  1295   Set();
  1296 }
  1297 
  1298 void cMenuMP3Item::Set(void)
  1299 {
  1300   char *buffer=0;
  1301   asprintf(&buffer," %s",playlist->BaseName());
  1302   SetText(buffer,false);
  1303 }
  1304 
  1305 // --- cMenuMP3 --------------------------------------------------------
  1306 
  1307 class cMenuMP3 : public cOsdMenu {
  1308 private:
  1309   cPlayLists *lists;
  1310   bool renaming, sourcing, instanting;
  1311   int buttonnum;
  1312   eOSState Play(void);
  1313   eOSState Edit(void);
  1314   eOSState New(void);
  1315   eOSState Delete(void);
  1316   eOSState Rename(bool second);
  1317   eOSState Source(bool second);
  1318   eOSState Instant(bool second);
  1319   void ScanLists(void);
  1320   eOSState SetButtons(int num);
  1321 public:
  1322   cMenuMP3(void);
  1323   ~cMenuMP3(void);
  1324   virtual eOSState ProcessKey(eKeys Key);
  1325   };
  1326 
  1327 cMenuMP3::cMenuMP3(void)
  1328 :cOsdMenu(tr("MP3"))
  1329 {
  1330   renaming=sourcing=instanting=false;
  1331   lists=new cPlayLists;
  1332   ScanLists(); SetButtons(1);
  1333   if(MP3Setup.MenuMode) Instant(false);
  1334 }
  1335 
  1336 cMenuMP3::~cMenuMP3(void)
  1337 {
  1338   delete lists;
  1339 }
  1340 
  1341 eOSState cMenuMP3::SetButtons(int num)
  1342 {
  1343   switch(num) {
  1344     case 1:
  1345       SetHelp(trVDR(BUTTON"Edit"), tr("Source"), tr("Browse"), ">>");
  1346       break;
  1347     case 2:
  1348       SetHelp("<<", trVDR(BUTTON"New"), trVDR(BUTTON"Delete"), tr("Rename"));
  1349       break;
  1350     }
  1351   buttonnum=num; Display();
  1352   return osContinue;
  1353 }
  1354 
  1355 void cMenuMP3::ScanLists(void)
  1356 {
  1357   Clear();
  1358   Status(tr("Scanning playlists..."));
  1359   bool res=lists->Load(MP3Sources.GetSource());
  1360   Status(0);
  1361   if(res) {
  1362     cPlayList *plist=lists->First();
  1363     while(plist) {
  1364       Add(new cMenuMP3Item(plist));
  1365       plist=lists->Next(plist);
  1366       }
  1367     }
  1368   else Error(tr("Error scanning playlists!"));
  1369 }
  1370 
  1371 eOSState cMenuMP3::Delete(void)
  1372 {
  1373   if(Count()>0) {
  1374     if(Interface->Confirm(tr("Delete playlist?")) &&
  1375        Interface->Confirm(tr("Are you sure?")) ) {
  1376       cPlayList *plist = ((cMenuMP3Item *)Get(Current()))->List();
  1377       if(plist->Delete()) {
  1378         lists->Del(plist);
  1379         cOsdMenu::Del(Current());
  1380         Display();
  1381         }
  1382       else Error(tr("Error deleting playlist!"));
  1383       }
  1384     }
  1385   return osContinue;
  1386 }
  1387 
  1388 eOSState cMenuMP3::New(void)
  1389 {
  1390   cPlayList *plist=new cPlayList(MP3Sources.GetSource(),0,0);
  1391   char name[32];
  1392   int i=0;
  1393   do {
  1394     if(i) sprintf(name,"%s%d",tr("unnamed"),i++);
  1395     else { strcpy(name,tr("unnamed")); i++; }
  1396     } while(plist->TestName(name));
  1397 
  1398   if(plist->Create(name)) {
  1399     lists->Add(plist);
  1400     Add(new cMenuMP3Item(plist), true);
  1401 
  1402     isyslog("MP3: playlist %s added", plist->Name());
  1403     return AddSubMenu(new cMenuPlayList(plist));
  1404     }
  1405   Error(tr("Error creating playlist!"));
  1406   delete plist;
  1407   return osContinue;
  1408 }
  1409 
  1410 eOSState cMenuMP3::Rename(bool second)
  1411 {
  1412   if(HasSubMenu() || Count() == 0) return osContinue;
  1413 
  1414   cPlayList *plist = ((cMenuMP3Item *)Get(Current()))->List();
  1415   if(!second) {
  1416     renaming=true;
  1417     return AddSubMenu(new cPlaylistRename(plist->BaseName()));
  1418     }
  1419   renaming=false;
  1420   const char *newname=cPlaylistRename::GetNewname();
  1421   if(newname) {
  1422     if(plist->Rename(newname)) {
  1423       RefreshCurrent();
  1424       DisplayCurrent(true);
  1425       }
  1426     else Error(tr("Error renaming playlist!"));
  1427     }
  1428   return osContinue;
  1429 }
  1430 
  1431 eOSState cMenuMP3::Edit(void)
  1432 {
  1433   if(HasSubMenu() || Count() == 0) return osContinue;
  1434 
  1435   cPlayList *plist = ((cMenuMP3Item *)Get(Current()))->List();
  1436   if(!plist->Load()) Error(tr("Error loading playlist!"));
  1437   else if(!plist->IsWinAmp()) {
  1438     isyslog("MP3: editing playlist %s", plist->Name());
  1439     return AddSubMenu(new cMenuPlayList(plist));
  1440     }
  1441   else Error(tr("Can't edit a WinAmp playlist!"));
  1442   return osContinue;
  1443 }
  1444 
  1445 eOSState cMenuMP3::Play(void)
  1446 {
  1447   if(HasSubMenu() || Count() == 0) return osContinue;
  1448 
  1449   Status(tr("Loading playlist..."));
  1450   cPlayList *newpl=new cPlayList(((cMenuMP3Item *)Get(Current()))->List());
  1451   if(newpl->Load() && newpl->Count()) {
  1452     isyslog("mp3: playback started with playlist %s", newpl->Name());
  1453     cMP3Control::SetPlayList(newpl);
  1454     if(MP3Setup.KeepSelect) { Status(0); return osContinue; }
  1455     return osEnd;
  1456     }
  1457   Status(0);
  1458   delete newpl;
  1459   Error(tr("Error loading playlist!"));
  1460   return osContinue;
  1461 }
  1462 
  1463 eOSState cMenuMP3::Source(bool second)
  1464 {
  1465   if(HasSubMenu()) return osContinue;
  1466 
  1467   if(!second) {
  1468     sourcing=true;
  1469     return AddSubMenu(new cMenuSource(&MP3Sources,tr("MP3 source")));
  1470     }
  1471   sourcing=false;
  1472   cFileSource *src=cMenuSource::GetSelected();
  1473   if(src) {
  1474     MP3Sources.SetSource(src);
  1475     ScanLists();
  1476     Display();
  1477     }
  1478   return osContinue;
  1479 }
  1480 
  1481 eOSState cMenuMP3::Instant(bool second)
  1482 {
  1483   if(HasSubMenu()) return osContinue;
  1484 
  1485   if(!second) {
  1486     instanting=true;
  1487     return AddSubMenu(new cMenuInstantBrowse(MP3Sources.GetSource(),trVDR(BUTTON"Play"),tr("Play all")));
  1488     }
  1489   instanting=false;
  1490   cFileObj *item=cMenuInstantBrowse::GetSelected();
  1491   if(item) {
  1492     Status(tr("Building playlist..."));
  1493     cInstantPlayList *newpl = new cInstantPlayList(item);
  1494     if(newpl->Load() && newpl->Count()) {
  1495       isyslog("mp3: playback started with instant playlist %s", newpl->Name());
  1496       cMP3Control::SetPlayList(newpl);
  1497       if(MP3Setup.KeepSelect) { Status(0); return Instant(false); }
  1498       return osEnd;
  1499       }
  1500     Status(0);
  1501     delete newpl;
  1502     Error(tr("Error building playlist!"));
  1503     }
  1504   return osContinue;
  1505 }
  1506 
  1507 eOSState cMenuMP3::ProcessKey(eKeys Key)
  1508 {
  1509   eOSState state = cOsdMenu::ProcessKey(Key);
  1510 
  1511   if(!HasSubMenu() && state==osContinue) { // eval the return value from submenus
  1512     if(renaming) return Rename(true);
  1513     if(sourcing) return Source(true);
  1514     if(instanting) return Instant(true);
  1515     }
  1516 
  1517   if(state == osUnknown) {
  1518     switch(Key) {
  1519       case kOk:     return Play();
  1520       case kRed:    return (buttonnum==1 ? Edit() : SetButtons(1)); 
  1521       case kGreen:  return (buttonnum==1 ? Source(false) : New());
  1522       case kYellow: return (buttonnum==1 ? Instant(false) : Delete());
  1523       case kBlue:   return (buttonnum==1 ? SetButtons(2) : Rename(false));
  1524       case kMenu:   return osEnd;
  1525       default:      break;
  1526       }
  1527     }
  1528   return state;
  1529 }
  1530 
  1531 // --- PropagateImage ----------------------------------------------------------
  1532 
  1533 void PropagateImage(const char *image)
  1534 {
  1535   cPlugin *graphtft=cPluginManager::GetPlugin("graphtft");
  1536   if(graphtft) graphtft->SetupParse("CoverImage",image ? image:"");
  1537 }
  1538 
  1539 // --- cPluginMP3 --------------------------------------------------------------
  1540 
  1541 static const char *DESCRIPTION    = trNOOP("A versatile audio player");
  1542 static const char *MAINMENUENTRY  = "MP3";
  1543 
  1544 class cPluginMp3 : public cPlugin {
  1545 private:
  1546 #if APIVERSNUM >= 10330
  1547   bool ExternalPlay(const char *path, bool test);
  1548 #endif
  1549 public:
  1550   cPluginMp3(void);
  1551   virtual ~cPluginMp3();
  1552   virtual const char *Version(void) { return PluginVersion; }
  1553   virtual const char *Description(void) { return tr(DESCRIPTION); }
  1554   virtual const char *CommandLineHelp(void);
  1555   virtual bool ProcessArgs(int argc, char *argv[]);
  1556 #if APIVERSNUM >= 10131
  1557   virtual bool Initialize(void);
  1558 #else
  1559   virtual bool Start(void);
  1560 #endif
  1561   virtual void Housekeeping(void);
  1562   virtual const char *MainMenuEntry(void);
  1563   virtual cOsdObject *MainMenuAction(void);
  1564   virtual cMenuSetupPage *SetupMenu(void);
  1565   virtual bool SetupParse(const char *Name, const char *Value);
  1566 #if APIVERSNUM >= 10330
  1567   virtual bool Service(const char *Id, void *Data);
  1568 #if APIVERSNUM >= 10331
  1569   virtual const char **SVDRPHelpPages(void);
  1570   virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
  1571 #endif
  1572 #endif
  1573   };
  1574 
  1575 cPluginMp3::cPluginMp3(void)
  1576 {
  1577   // Initialize any member varaiables here.
  1578   // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
  1579   // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
  1580 }
  1581 
  1582 cPluginMp3::~cPluginMp3()
  1583 {
  1584   InfoCache.Shutdown();
  1585   delete mgr;
  1586 }
  1587 
  1588 const char *cPluginMp3::CommandLineHelp(void)
  1589 {
  1590   static char *help_str=0;
  1591   
  1592   free(help_str);    //                                     for easier orientation, this is column 80|
  1593   asprintf(&help_str,"  -m CMD,   --mount=CMD    use CMD to mount/unmount/eject mp3 sources\n"
  1594                      "                           (default: %s)\n"
  1595                      "  -n CMD,   --network=CMD  execute CMD before & after network access\n"
  1596                      "                           (default: %s)\n"
  1597                      "  -C DIR,   --cache=DIR    store ID3 cache file in DIR\n"
  1598                      "                           (default: %s)\n"
  1599                      "  -B DIR,   --cddb=DIR     search CDDB files in DIR\n"
  1600                      "                           (default: %s)\n"
  1601                      "  -D DEV,   --dsp=DEV      device for OSS output\n"
  1602                      "                           (default: %s)\n"
  1603                      "  -i CMD,   --iconv=CMD    use CMD to convert background images\n"
  1604                      "                           (default: %s)\n"
  1605                      "  -c DIR,   --icache=DIR   cache converted images in DIR\n"
  1606                      "                           (default: %s)\n"
  1607                      "  -S SUB,   --sources=SUB  search sources config in SUB subdirectory\n"
  1608                      "                           (default: %s)\n",
  1609                      
  1610                      mountscript,
  1611                      netscript ? netscript:"none",
  1612                      cachedir ? cachedir:"video dir",
  1613 #ifdef HAVE_SNDFILE
  1614                      cddbpath,
  1615 #else
  1616                      "none",
  1617 #endif
  1618 #ifdef WITH_OSS
  1619                      dspdevice,
  1620 #else
  1621                      "none",
  1622 #endif
  1623                      imageconv,
  1624                      imagecache,
  1625                      sourcesSub ? sourcesSub:"empty"
  1626                      );
  1627   return help_str;
  1628 }
  1629 
  1630 bool cPluginMp3::ProcessArgs(int argc, char *argv[])
  1631 {
  1632   static struct option long_options[] = {
  1633       { "mount",    required_argument, NULL, 'm' },
  1634       { "network",  required_argument, NULL, 'n' },
  1635       { "cddb",     required_argument, NULL, 'B' },
  1636       { "dsp",      required_argument, NULL, 'D' },
  1637       { "cache",    required_argument, NULL, 'C' },
  1638       { "icache",   required_argument, NULL, 'c' },
  1639       { "iconv",    required_argument, NULL, 'i' },
  1640       { "sources",  required_argument, NULL, 'S' },
  1641       { NULL }
  1642     };
  1643 
  1644   int c, option_index = 0;
  1645   while((c=getopt_long(argc,argv,"c:i:m:n:B:C:D:S:",long_options,&option_index))!=-1) {
  1646     switch (c) {
  1647       case 'i': imageconv=optarg; break;
  1648       case 'c': imagecache=optarg; break;
  1649       case 'm': mountscript=optarg; break;
  1650       case 'n': netscript=optarg; break;
  1651       case 'C': cachedir=optarg; break;
  1652       case 'S': sourcesSub=optarg; break;
  1653       case 'B':
  1654 #ifdef HAVE_SNDFILE
  1655                 cddbpath=optarg; break;
  1656 #else
  1657                 fprintf(stderr, "mp3: libsndfile support has not been compiled in!\n"); return false;
  1658 #endif
  1659       case 'D':
  1660 #ifdef WITH_OSS
  1661                 dspdevice=optarg; break;
  1662 #else
  1663                 fprintf(stderr, "mp3: OSS output has not been compiled in!\n"); return false;
  1664 #endif
  1665       default:  return false;
  1666       }
  1667     }
  1668   return true;
  1669 }
  1670 
  1671 #if APIVERSNUM >= 10131
  1672 bool cPluginMp3::Initialize(void)
  1673 #else
  1674 bool cPluginMp3::Start(void)
  1675 #endif
  1676 {
  1677   if(!CheckVDRVersion(1,1,29,"mp3")) return false;
  1678   plugin_name="mp3";
  1679 #if APIVERSNUM < 10507
  1680   i18n_name="mp3";
  1681 #else
  1682   i18n_name="vdr-mp3";
  1683 #endif
  1684   MP3Sources.Load(AddDirectory(ConfigDirectory(sourcesSub),"mp3sources.conf"));
  1685   if(MP3Sources.Count()<1) {
  1686      esyslog("ERROR: you should have defined at least one source in mp3sources.conf");
  1687      fprintf(stderr,"No source(s) defined in mp3sources.conf\n");
  1688      return false;
  1689      }
  1690   InfoCache.Load();
  1691 #if APIVERSNUM < 10507
  1692   RegisterI18n(Phrases);
  1693 #endif
  1694   mgr=new cPlayManager;
  1695   if(!mgr) {
  1696     esyslog("ERROR: creating playmanager failed");
  1697     fprintf(stderr,"Creating playmanager failed\n");
  1698     return false;
  1699     }
  1700   d(printf("mp3: using %s\n",mad_version))
  1701   d(printf("mp3: compiled with %s\n",MAD_VERSION))
  1702   return true;
  1703 }
  1704 
  1705 void cPluginMp3::Housekeeping(void)
  1706 {
  1707   InfoCache.Save();
  1708 }
  1709 
  1710 const char *cPluginMp3::MainMenuEntry(void)
  1711 {
  1712   return MP3Setup.HideMainMenu ? 0 : tr(MAINMENUENTRY);
  1713 }
  1714 
  1715 cOsdObject *cPluginMp3::MainMenuAction(void)
  1716 {
  1717   return new cMenuMP3;
  1718 }
  1719 
  1720 cMenuSetupPage *cPluginMp3::SetupMenu(void)
  1721 {
  1722   return new cMenuSetupMP3;
  1723 }
  1724 
  1725 bool cPluginMp3::SetupParse(const char *Name, const char *Value)
  1726 {
  1727   if      (!strcasecmp(Name, "InitLoopMode"))     MP3Setup.InitLoopMode    = atoi(Value);
  1728   else if (!strcasecmp(Name, "InitShuffleMode"))  MP3Setup.InitShuffleMode = atoi(Value);
  1729   else if (!strcasecmp(Name, "AudioMode"))        MP3Setup.AudioMode       = atoi(Value);
  1730   else if (!strcasecmp(Name, "BgrScan"))          MP3Setup.BgrScan         = atoi(Value);
  1731   else if (!strcasecmp(Name, "EditorMode"))       MP3Setup.EditorMode      = atoi(Value);
  1732   else if (!strcasecmp(Name, "DisplayMode"))      MP3Setup.DisplayMode     = atoi(Value);
  1733   else if (!strcasecmp(Name, "BackgrMode"))       MP3Setup.BackgrMode      = atoi(Value);
  1734   else if (!strcasecmp(Name, "MenuMode"))         MP3Setup.MenuMode        = atoi(Value);
  1735   else if (!strcasecmp(Name, "TargetLevel"))      MP3Setup.TargetLevel     = atoi(Value);
  1736   else if (!strcasecmp(Name, "LimiterLevel"))     MP3Setup.LimiterLevel    = atoi(Value);
  1737   else if (!strcasecmp(Name, "Only48kHz"))        MP3Setup.Only48kHz       = atoi(Value);
  1738   else if (!strcasecmp(Name, "UseProxy"))         MP3Setup.UseProxy        = atoi(Value);
  1739   else if (!strcasecmp(Name, "ProxyHost"))        strn0cpy(MP3Setup.ProxyHost,Value,MAX_HOSTNAME);
  1740   else if (!strcasecmp(Name, "ProxyPort"))        MP3Setup.ProxyPort       = atoi(Value);
  1741   else if (!strcasecmp(Name, "UseCddb"))          MP3Setup.UseCddb         = atoi(Value);
  1742   else if (!strcasecmp(Name, "CddbHost"))         strn0cpy(MP3Setup.CddbHost,Value,MAX_HOSTNAME);
  1743   else if (!strcasecmp(Name, "CddbPort"))         MP3Setup.CddbPort        = atoi(Value);
  1744   else if (!strcasecmp(Name, "AbortAtEOL"))       MP3Setup.AbortAtEOL      = atoi(Value);
  1745   else if (!strcasecmp(Name, "AudioOutMode")) {
  1746     MP3Setup.AudioOutMode = atoi(Value);
  1747 #ifndef WITH_OSS
  1748     if(MP3Setup.AudioOutMode==AUDIOOUTMODE_OSS) {
  1749       esyslog("WARNING: AudioOutMode OSS not supported, falling back to DVB");
  1750       MP3Setup.AudioOutMode=AUDIOOUTMODE_DVB;
  1751       }
  1752 #endif
  1753     }
  1754 #if APIVERSNUM >= 10307
  1755   else if (!strcasecmp(Name, "ReplayDisplay"))      MP3Setup.ReplayDisplay = atoi(Value);
  1756 #endif
  1757   else if (!strcasecmp(Name, "HideMainMenu"))       MP3Setup.HideMainMenu  = atoi(Value);
  1758   else if (!strcasecmp(Name, "KeepSelect"))         MP3Setup.KeepSelect    = atoi(Value);
  1759   else if (!strcasecmp(Name, "TitleArtistOrder"))   MP3Setup.TitleArtistOrder = atoi(Value);
  1760   else return false;
  1761   return true;
  1762 }
  1763 
  1764 #if APIVERSNUM >= 10330
  1765 
  1766 bool cPluginMp3::ExternalPlay(const char *path, bool test)
  1767 {
  1768   char real[PATH_MAX+1];
  1769   if(realpath(path,real)) {
  1770     cFileSource *src=MP3Sources.FindSource(real);
  1771     if(src) {
  1772       cFileObj *item=new cFileObj(src,0,0,otFile);
  1773       if(item) {
  1774         item->SplitAndSet(real);
  1775         if(item->GuessType()) {
  1776           if(item->Exists()) {
  1777             cInstantPlayList *pl=new cInstantPlayList(item);
  1778             if(pl && pl->Load() && pl->Count()) {
  1779               if(!test) cMP3Control::SetPlayList(pl);
  1780               else delete pl;
  1781               delete item;
  1782               return true;
  1783               }
  1784             else dsyslog("MP3 service: error building playlist");
  1785             delete pl;
  1786             }
  1787           else dsyslog("MP3 service: cannot play '%s'",path);
  1788           }
  1789         else dsyslog("MP3 service: GuessType() failed for '%s'",path);
  1790         delete item;
  1791         }
  1792       }
  1793     else dsyslog("MP3 service: cannot find source for '%s', real '%s'",path,real);
  1794     }
  1795   else if(errno!=ENOENT && errno!=ENOTDIR)
  1796     esyslog("ERROR: realpath: %s: %s",path,strerror(errno));
  1797   return false;
  1798 }
  1799 
  1800 bool cPluginMp3::Service(const char *Id, void *Data)
  1801 {
  1802   if(!strcasecmp(Id,"MP3-Play-v1")) {
  1803     if(Data) {
  1804       struct MPlayerServiceData *msd=(struct MPlayerServiceData *)Data;
  1805       msd->result=ExternalPlay(msd->data.filename,false);
  1806       }
  1807     return true;
  1808     }
  1809   else if(!strcasecmp(Id,"MP3-Test-v1")) {
  1810     if(Data) {
  1811       struct MPlayerServiceData *msd=(struct MPlayerServiceData *)Data;
  1812       msd->result=ExternalPlay(msd->data.filename,true);
  1813       }
  1814     return true;
  1815     }
  1816   return false;
  1817 }
  1818 
  1819 #if APIVERSNUM >= 10331
  1820 
  1821 const char **cPluginMp3::SVDRPHelpPages(void)
  1822 {
  1823   static const char *HelpPages[] = {
  1824     "PLAY <filename>\n"
  1825     "    Triggers playback of file 'filename'.",
  1826     "TEST <filename>\n"
  1827     "    Tests is playback of file 'filename' is possible.",
  1828     "CURR\n"
  1829     "    Returns filename of song currently being replayed.",
  1830     NULL
  1831     };
  1832   return HelpPages;
  1833 }
  1834 
  1835 cString cPluginMp3::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
  1836 {
  1837   if(!strcasecmp(Command,"PLAY")) {
  1838     if(*Option) {
  1839       if(ExternalPlay(Option,false)) return "Playback triggered";
  1840       else { ReplyCode=550; return "Playback failed"; }
  1841       }
  1842     else { ReplyCode=501; return "Missing filename"; }
  1843     }
  1844   else if(!strcasecmp(Command,"TEST")) {
  1845     if(*Option) {
  1846       if(ExternalPlay(Option,true)) return "Playback possible";
  1847       else { ReplyCode=550; return "Playback not possible"; }
  1848       }
  1849     else { ReplyCode=501; return "Missing filename"; }
  1850     }
  1851   else if(!strcasecmp(Command,"CURR")) {
  1852     cControl *control=cControl::Control();
  1853     if(control && typeid(*control)==typeid(cMP3Control)) {
  1854       cMP3PlayInfo mode;
  1855       if(mgr->Info(-1,&mode)) return mode.Filename;
  1856       else return "<unknown>";
  1857       }
  1858     else { ReplyCode=550; return "No running playback"; }
  1859     }
  1860   return NULL;
  1861 }
  1862 
  1863 #endif // 1.3.31
  1864 #endif // 1.3.30
  1865 
  1866 VDRPLUGINCREATOR(cPluginMp3); // Don't touch this!