2 * MP3/MPlayer plugin to VDR (C++)
4 * (C) 2001-2007 Stefan Huelswitt <s.huelswitt@gmx.de>
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.
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.
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
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>
38 #include "setup-mp3.h"
41 #include "player-mp3.h"
43 #include "menu-async.h"
53 const char *sourcesSub=0;
54 cFileSources MP3Sources;
56 static const char *plugin_name=0;
58 // --- cMenuSetupMP3 --------------------------------------------------------
60 class cMenuSetupMP3 : public cMenuSetupPage {
64 const char *cddb[3], *disp[2], *scan[3], *bgr[3];
65 const char *aout[AUDIOOUTMODES];
66 int amode, amodes[AUDIOOUTMODES];
68 virtual void Store(void);
73 cMenuSetupMP3::cMenuSetupMP3(void)
75 static const char allowed[] = { "abcdefghijklmnopqrstuvwxyz0123456789-_" };
77 aout[numModes]=trVDR("DVB"); amodes[numModes]=AUDIOOUTMODE_DVB; numModes++;
79 aout[numModes]=tr("OSS"); amodes[numModes]=AUDIOOUTMODE_OSS; numModes++;
83 for(int i=0; i<numModes; i++)
84 if(amodes[i]==data.AudioOutMode) { amode=i; break; }
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));
95 Add(new cMenuEditIntItem( tr("Setup.MP3$Display mode"), &data.DisplayMode, 1, 3));
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));
125 void cMenuSetupMP3::Store(void)
127 data.AudioOutMode=amodes[amode];
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 );
152 SetupStore("HideMainMenu", MP3Setup.HideMainMenu );
153 SetupStore("KeepSelect", MP3Setup.KeepSelect );
154 SetupStore("TitleArtistOrder", MP3Setup.TitleArtistOrder);
157 // --- cAsyncStatus ------------------------------------------------------------
159 cAsyncStatus asyncStatus;
161 cAsyncStatus::cAsyncStatus(void)
167 cAsyncStatus::~cAsyncStatus()
172 void cAsyncStatus::Set(const char *Text)
176 text=Text ? strdup(Text) : 0;
181 const char *cAsyncStatus::Begin(void)
187 void cAsyncStatus::Finish(void)
193 // --- --------------------------------------------------------------------
195 static const char *TitleArtist(const char *title, const char *artist)
197 static char buf[256]; // clearly not multi-thread save!
199 if(artist && artist[0]) {
200 if(MP3Setup.TitleArtistOrder) fmt="%2$s - %1$s";
204 snprintf(buf,sizeof(buf),fmt,title,artist);
208 // --- cMP3Control --------------------------------------------------------
210 #if APIVERSNUM >= 10307
211 #define clrBackground clrGray50
212 #define eDvbColor int
216 #define MAXROWS MAXOSDHEIGHT
217 #define INLINE inline
220 class cMP3Control : public cControl {
222 #if APIVERSNUM >= 10307
225 cSkinDisplayReplay *disp;
227 bool statusInterfaceOpen;
229 int bw, bh, bwc, fw, fh;
232 bool visible, shown, bigwin, statusActive;
233 time_t timeoutShow, greentime, oktime;
234 int lastkeytime, number;
237 cMP3PlayInfo *lastMode;
238 time_t fliptime, listtime;
239 int hashlist[MAXROWS];
240 int flip, flipint, top, rows;
241 int lastIndex, lastTotal, lastTop;
244 bool jumpactive, jumphide, jumpsecs;
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);
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);
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);
269 cMP3Control::cMP3Control(void)
270 :cControl(player=new cMP3Player)
272 visible=shown=bigwin=selecting=jumpactive=jumphide=statusActive=false;
273 timeoutShow=greentime=oktime=0;
274 lastkeytime=number=0;
276 framesPerSecond=SecondsToFrames(1);
277 #if APIVERSNUM >= 10307
279 font=cFont::GetFont(fontOsd);
281 statusInterfaceOpen=false;
283 #if APIVERSNUM >= 10338
284 cStatus::MsgReplaying(this,"MP3",0,true);
286 cStatus::MsgReplaying(this,"MP3");
290 cMP3Control::~cMP3Control()
297 void cMP3Control::Stop(void)
299 #if APIVERSNUM >= 10338
300 cStatus::MsgReplaying(this,0,0,false);
302 cStatus::MsgReplaying(this,0);
304 delete player; player=0;
306 mgr->Flush(); //XXX remove later
309 bool cMP3Control::SetPlayList(cPlayList *plist)
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
322 cControl::Launch(new cMP3Control);
329 void cMP3Control::ShowTimed(int Seconds)
333 timeoutShow=(Seconds>0) ? time(0)+Seconds : 0;
337 void cMP3Control::Hide(void)
342 #if APIVERSNUM >= 10307
348 visible=bigwin=false;
349 #if APIVERSNUM >= 10500
350 SetNeedsFastResponse(false);
352 needsFastResponse=false;
357 void cMP3Control::ShowStatus(bool force)
359 if((asyncStatus.Changed() || (force && !statusActive)) && !jumpactive) {
360 const char *text=asyncStatus.Begin();
362 #if APIVERSNUM >= 10307
363 if(MP3Setup.ReplayDisplay || !osd) {
364 if(statusActive) Skins.Message(mtStatus,0);
365 Skins.Message(mtStatus,text);
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);
373 if(!Interface->IsOpen()) {
374 Interface->Open(0,-1);
375 statusInterfaceOpen=true;
377 Interface->Status(text);
384 asyncStatus.Finish();
388 void cMP3Control::HideStatus(void)
391 #if APIVERSNUM >= 10307
392 if(MP3Setup.ReplayDisplay || !osd)
393 Skins.Message(mtStatus,0);
395 osd->RestoreRegion();
399 if(statusInterfaceOpen) {
401 statusInterfaceOpen=false;
404 Interface->Status(0);
412 #define CTAB 11 // some tabbing values for the progress display
415 void cMP3Control::Write(int x, int y, int w, const char *text, eDvbColor fg, eDvbColor bg)
417 #if APIVERSNUM >= 10307
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))
426 if(w>0) Fill(x,y,w,1,bg);
427 Interface->Write(x,y,text,fg,bg);
431 void cMP3Control::Fill(int x, int y, int w, int h, eDvbColor fg)
433 #if APIVERSNUM >= 10307
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))
442 Interface->Fill(x,y,w,h,fg);
446 void cMP3Control::Flush(void)
448 #if APIVERSNUM >= 10307
449 if(MP3Setup.ReplayDisplay) Skins.Flush();
450 else if(osd) osd->Flush();
456 void cMP3Control::ShowProgress(bool open, bool bigWin)
460 if(player->GetIndex(index,total) && total>=0) {
461 if(!visible && open) {
463 #if APIVERSNUM >= 10307
464 if(MP3Setup.ReplayDisplay) {
465 disp=Skins.Current()->DisplayReplay(false);
471 fw=font->Width(' ')*2;
478 rows=(bh-bp-fh/3)/fh;
483 bt=Setup.OSDHeight-bh;
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);
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));
496 tArea Areas[] = { { 0,0,bw-1,bh-1,4 } };
497 osd->SetAreas(Areas,sizeof(Areas)/sizeof(tArea));
499 osd->DrawRectangle(0,0,bw-1,bh-1,clrGray50);
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);
514 #if APIVERSNUM >= 10500
515 SetNeedsFastResponse(true);
517 needsFastResponse=true;
519 fliptime=listtime=0; flipint=0; flip=-1; top=lastTop=-1; lastIndex=lastTotal=-1;
520 delete lastMode; lastMode=0;
523 cMP3PlayInfo *mode=new cMP3PlayInfo;
524 bool valid=mgr->Info(-1,mode);
525 bool changed=(!lastMode || mode->Hash!=lastMode->Hash);
527 if(changed) { d(printf("mp3-ctrl: mode change detected\n")) }
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);
536 cStatus::MsgReplaying(this,buf);
541 if(visible) { // refresh the OSD progress display
544 #if APIVERSNUM >= 10307
545 if(MP3Setup.ReplayDisplay) {
547 if(total>0) disp->SetProgress(index,total);
548 disp->SetCurrent(IndexToHMSF(index));
549 disp->SetTotal(IndexToHMSF(total));
552 if(GetReplayMode(Play,Forward,Speed))
553 disp->SetMode(Play, Forward, Speed);
559 if(!selecting && changed && !statusActive) {
560 snprintf(buf,sizeof(buf),"(%d/%d)",mode->Num,mode->MaxNum);
561 Write(0,-2,CTAB,buf);
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);
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);
576 index/=framesPerSecond; total/=framesPerSecond;
577 if(index!=lastIndex || total!=lastTotal) {
579 #if APIVERSNUM >= 10307
580 cProgressBar ProgressBar(bw-(CTAB+CTAB2)*fw,fh,index,total);
581 osd->DrawBitmap(CTAB*fw,bh-fh,ProgressBar);
583 cProgressBar ProgressBar((bw-CTAB-CTAB2)*fw,fh,index,total);
584 Interface->SetBitmap(CTAB*fw,(abs(bh)-1)*fh,ProgressBar);
587 snprintf(buf,sizeof(buf),total?"%02d:%02d/%02d:%02d":"%02d:%02d",index/60,index%60,total/60,total%60);
591 #if APIVERSNUM >= 10307
597 if(MP3Setup.ReplayDisplay && (!lastMode || mode->Loop!=lastMode->Loop || mode->Shuffle!=lastMode->Shuffle))
599 if(!valid || changed) {
600 fliptime=time(0); flip=0;
603 else if(time(0)>fliptime+flipint) {
605 flip++; if(flip>=MP3Setup.DisplayMode) flip=0;
615 snprintf(buf,sizeof(buf),"%s",TitleArtist(mode->Title,mode->Artist));
620 snprintf(buf,sizeof(buf),mode->Year>0?"from: %s (%d)":"from: %s",mode->Album,mode->Year);
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);
629 snprintf(buf,sizeof(buf),"%.1f kHz, %d kbps, %s",mode->SampleFreq/1000.0,mode->Bitrate/1000,mode->SMode);
634 #if APIVERSNUM >= 10307
635 if(MP3Setup.ReplayDisplay) {
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);
648 else { d(printf("mp3-ctrl: display info skip due to status active\n")) }
649 #if APIVERSNUM >= 10307
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;
663 for(int i=0 ; i<rows && i<MAXROWS && num<=mode->MaxNum ; i++,num++) {
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');
674 Write(0,i,5,buf,fg,bg);
675 Write(5,i,bwc-5,s,fg,bg);
678 Write(0,i,bwc,buf,fg,bg);
683 listtime=time(0); lastTop=top;
690 lastIndex=index; lastTotal=total;
691 delete lastMode; lastMode=mode;
695 void cMP3Control::DisplayInfo(const char *s)
697 if(s) Write(CTAB,-2,bwc-CTAB,s);
698 else Fill(CTAB,-2,bwc-CTAB,1,clrBackground);
701 void cMP3Control::JumpDisplay(void)
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) {
714 #if APIVERSNUM >= 10307
719 void cMP3Control::JumpProcess(eKeys Key)
721 int n=Key-k0, d=jumpsecs?1:60;
724 if(jumpmm*10+n <= lastTotal/d) jumpmm=jumpmm*10+n;
739 player->SkipSeconds(jumpmm*d * ((Key==kLeft || Key==kFastRew) ? -1:1));
748 #if APIVERSNUM >= 10307
749 else if(MP3Setup.ReplayDisplay) disp->SetJump(0);
754 void cMP3Control::Jump(void)
756 jumpmm=0; jumphide=jumpsecs=false;
758 ShowTimed(); if(!visible) return;
762 jumpactive=true; fliptime=0; flip=-1;
765 eOSState cMP3Control::ProcessKey(eKeys Key)
767 if(!player->Active()) return osEnd;
769 if(timeoutShow && time(0)>timeoutShow) Hide();
771 #if APIVERSNUM >= 10307
772 ShowStatus(Key==kNone && !Skins.IsOpen());
774 ShowStatus(Key==kNone && !Interface->IsOpen());
777 if(jumpactive && Key!=kNone) { JumpProcess(Key); return osContinue; }
782 #if APIVERSNUM >= 10347
786 mgr->Next(); player->Play();
790 #if APIVERSNUM >= 10347
794 if(!player->PrevCheck()) mgr->Prev();
800 if(top>0) { top-=rows; if(top<1) top=1; }
805 case kFastRew|k_Repeat:
806 if(!player->IsStream()) player->SkipSeconds(-JUMPSIZE);
809 case kRight|k_Repeat:
816 case kFastFwd|k_Repeat:
817 if(!player->IsStream()) player->SkipSeconds(JUMPSIZE);
820 if(!player->IsStream()) Jump();
824 if(time(0)>greentime) {
825 if(lastMode->Loop || (!lastMode->Loop && !lastMode->Shuffle)) mgr->ToggleLoop();
826 if(lastMode->Shuffle) mgr->ToggleShuffle();
829 if(!lastMode->Loop) mgr->ToggleLoop();
830 else if(!lastMode->Shuffle) mgr->ToggleShuffle();
831 else mgr->ToggleLoop();
833 greentime=time(0)+MULTI_TIMEOUT;
841 if(!player->IsStream()) player->Pause();
850 #if APIVERSNUM >= 10332
851 cRemote::CallPlugin(plugin_name);
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();
864 #if APIVERSNUM >= 10307
865 if(MP3Setup.ReplayDisplay) {
866 snprintf(buf,sizeof(buf),"%s%d-/%d",trVDR("Jump: "),number,lastMode->MaxNum);
871 snprintf(buf,sizeof(buf),"(%d-/%d)",number,lastMode->MaxNum);
872 Write(0,-2,CTAB,buf);
873 #if APIVERSNUM >= 10307
879 number=0; lastkeytime=0;
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);
892 if(time(0)>oktime || MP3Setup.ReplayDisplay) {
893 visible ? Hide() : ShowTimed();
896 if(visible && !bigwin) { Hide(); ShowProgress(true,true); }
897 else { Hide(); ShowTimed(); }
899 oktime=time(0)+MULTI_TIMEOUT;
908 // --- cMenuID3Info ------------------------------------------------------------
910 class cMenuID3Info : public cOsdMenu {
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);
916 cMenuID3Info(cSong *song);
917 cMenuID3Info(cSongInfo *si, const char *name);
918 virtual eOSState ProcessKey(eKeys Key);
921 cMenuID3Info::cMenuID3Info(cSong *song)
922 :cOsdMenu(tr("ID3 information"),12)
924 Build(song->Info(),song->Name());
927 cMenuID3Info::cMenuID3Info(cSongInfo *si, const char *name)
928 :cOsdMenu(tr("ID3 information"),12)
933 void cMenuID3Info::Build(cSongInfo *si, const char *name)
936 Item(tr("Filename"),name);
937 if(si->HasInfo() && si->Total>0) {
939 asprintf(&buf,"%02d:%02d",si->Total/60,si->Total%60);
940 Item(tr("Length"),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);
954 cOsdItem *cMenuID3Info::Item(const char *name, const char *format, const float num)
959 asprintf(&buf,format?format:"%.f",num);
963 else item=Item(name,"");
967 cOsdItem *cMenuID3Info::Item(const char *name, const char *text)
970 asprintf(&buf,"%s:\t%s",name,text?text:"");
971 cOsdItem *item = new cOsdItem(buf,osBack);
972 #if APIVERSNUM >= 10307
973 item->SetSelectable(false);
975 item->SetColor(clrWhite, clrBackground);
978 Add(item); return item;
981 eOSState cMenuID3Info::ProcessKey(eKeys Key)
983 eOSState state = cOsdMenu::ProcessKey(Key);
985 if(state==osUnknown) {
990 case kBlue: return osContinue;
991 case kMenu: return osEnd;
998 // --- cMenuInstantBrowse -------------------------------------------------------
1000 class cMenuInstantBrowse : public cMenuBrowse {
1002 const char *selecttext, *alltext;
1003 virtual void SetButtons(void);
1004 virtual eOSState ID3Info(void);
1006 cMenuInstantBrowse(cFileSource *Source, const char *Selecttext, const char *Alltext);
1007 virtual eOSState ProcessKey(eKeys Key);
1010 cMenuInstantBrowse::cMenuInstantBrowse(cFileSource *Source, const char *Selecttext, const char *Alltext)
1011 :cMenuBrowse(Source,true,true,tr("Directory browser"),excl_br)
1013 selecttext=Selecttext; alltext=Alltext;
1017 void cMenuInstantBrowse::SetButtons(void)
1019 SetHelp(selecttext, currentdir?tr("Parent"):0, currentdir?0:alltext, tr("ID3 info"));
1023 eOSState cMenuInstantBrowse::ID3Info(void)
1025 cFileObj *item=CurrentItem();
1026 if(item && item->Type()==otFile) {
1027 cSong *song=new cSong(item);
1029 if(song && (si=song->Info())) {
1030 AddSubMenu(new cMenuID3Info(si,item->Path()));
1037 eOSState cMenuInstantBrowse::ProcessKey(eKeys Key)
1039 eOSState state=cOsdMenu::ProcessKey(Key);
1040 if(state==osUnknown) {
1042 case kYellow: lastselect=new cFileObj(source,0,0,otBase);
1047 if(state==osUnknown) state=cMenuBrowse::ProcessStdKey(Key,state);
1051 // --- cMenuPlayListItem -------------------------------------------------------
1053 class cMenuPlayListItem : public cOsdItem {
1058 cMenuPlayListItem(cSong *Song, bool showid3);
1059 cSong *Song(void) { return song; }
1060 virtual void Set(void);
1061 void Set(bool showid3);
1064 cMenuPlayListItem::cMenuPlayListItem(cSong *Song, bool showid3)
1070 void cMenuPlayListItem::Set(bool showid3)
1076 void cMenuPlayListItem::Set(void)
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));
1084 asprintf(&buffer, "%d.\t<%s>",song->Index()+1,song->Name());
1085 SetText(buffer,false);
1088 // --- cMenuPlayList ------------------------------------------------------
1090 class cMenuPlayList : public cOsdMenu {
1092 cPlayList *playlist;
1093 bool browsing, showid3;
1095 void Refresh(bool all = false);
1097 virtual void Move(int From, int To);
1098 eOSState Remove(void);
1099 eOSState ShowID3(void);
1100 eOSState ID3Info(void);
1102 cMenuPlayList(cPlayList *Playlist);
1103 virtual eOSState ProcessKey(eKeys Key);
1106 cMenuPlayList::cMenuPlayList(cPlayList *Playlist)
1107 :cOsdMenu(tr("Playlist editor"),4)
1109 browsing=showid3=false;
1111 if(MP3Setup.EditorMode) showid3=true;
1113 cSong *mp3 = playlist->First();
1115 cOsdMenu::Add(new cMenuPlayListItem(mp3,showid3));
1116 mp3 = playlist->cList<cSong>::Next(mp3);
1118 Buttons(); Display();
1121 void cMenuPlayList::Buttons(void)
1123 SetHelp(tr("Add"), showid3?tr("Filenames"):tr("ID3 names"), tr("Remove"), trVDR(BUTTON"Mark"));
1126 void cMenuPlayList::Refresh(bool all)
1128 cMenuPlayListItem *cur=(cMenuPlayListItem *)((all || Count()<2) ? First() : Get(Current()));
1131 cur=(cMenuPlayListItem *)Next(cur);
1135 void cMenuPlayList::Add(void)
1137 cFileObj *item=cMenuInstantBrowse::GetSelected();
1139 Status(tr("Scanning directory..."));
1140 cInstantPlayList *newpl=new cInstantPlayList(item);
1142 if(newpl->Count()) {
1143 if(newpl->Count()==1 || Interface->Confirm(tr("Add recursivly?"))) {
1144 cSong *mp3=newpl->First();
1146 cSong *n=new cSong(mp3);
1148 cMenuPlayListItem *current=(cMenuPlayListItem *)Get(Current());
1149 playlist->Add(n,current->Song());
1150 cOsdMenu::Add(new cMenuPlayListItem(n,showid3),true,current);
1154 cOsdMenu::Add(new cMenuPlayListItem(n,showid3),true);
1156 mp3=newpl->cList<cSong>::Next(mp3);
1159 Refresh(); Display();
1162 else Error(tr("Empty directory!"));
1164 else Error(tr("Error scanning directory!"));
1170 void cMenuPlayList::Move(int From, int To)
1172 playlist->Move(From,To); playlist->Save();
1173 cOsdMenu::Move(From,To);
1174 Refresh(true); Display();
1177 eOSState cMenuPlayList::ShowID3(void)
1180 Buttons(); Refresh(true); Display();
1184 eOSState cMenuPlayList::ID3Info(void)
1187 cMenuPlayListItem *current = (cMenuPlayListItem *)Get(Current());
1188 AddSubMenu(new cMenuID3Info(current->Song()));
1193 eOSState cMenuPlayList::Remove(void)
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();
1206 eOSState cMenuPlayList::ProcessKey(eKeys Key)
1208 eOSState state = cOsdMenu::ProcessKey(Key);
1210 if(browsing && !HasSubMenu() && state==osContinue) { Add(); browsing=false; }
1212 if(state==osUnknown) {
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;
1227 // --- cPlaylistRename --------------------------------------------------------
1229 class cPlaylistRename : public cOsdMenu {
1231 static char *newname;
1232 const char *oldname;
1235 cPlaylistRename(const char *Oldname);
1236 virtual eOSState ProcessKey(eKeys Key);
1237 static const char *GetNewname(void) { return newname; }
1240 char *cPlaylistRename::newname = NULL;
1242 cPlaylistRename::cPlaylistRename(const char *Oldname)
1243 :cOsdMenu(tr("Rename playlist"), 15)
1245 free(newname); newname=0;
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);
1254 old->SetColor(clrWhite, clrBackground);
1260 Add(new cMenuEditStrItem( tr("New name"), data, sizeof(data)-1, tr(FileNameChars)),true);
1263 eOSState cPlaylistRename::ProcessKey(eKeys Key)
1265 eOSState state = cOsdMenu::ProcessKey(Key);
1267 if (state == osUnknown) {
1269 case kOk: if(data[0] && strcmp(data,oldname)) newname=strdup(data);
1274 case kBlue: return osContinue;
1281 // --- cMenuMP3Item -----------------------------------------------------
1283 class cMenuMP3Item : public cOsdItem {
1285 cPlayList *playlist;
1286 virtual void Set(void);
1288 cMenuMP3Item(cPlayList *PlayList);
1289 cPlayList *List(void) { return playlist; }
1292 cMenuMP3Item::cMenuMP3Item(cPlayList *PlayList)
1298 void cMenuMP3Item::Set(void)
1301 asprintf(&buffer," %s",playlist->BaseName());
1302 SetText(buffer,false);
1305 // --- cMenuMP3 --------------------------------------------------------
1307 class cMenuMP3 : public cOsdMenu {
1310 bool renaming, sourcing, instanting;
1312 eOSState Play(void);
1313 eOSState Edit(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);
1324 virtual eOSState ProcessKey(eKeys Key);
1327 cMenuMP3::cMenuMP3(void)
1328 :cOsdMenu(tr("MP3"))
1330 renaming=sourcing=instanting=false;
1331 lists=new cPlayLists;
1332 ScanLists(); SetButtons(1);
1333 if(MP3Setup.MenuMode) Instant(false);
1336 cMenuMP3::~cMenuMP3(void)
1341 eOSState cMenuMP3::SetButtons(int num)
1345 SetHelp(trVDR(BUTTON"Edit"), tr("Source"), tr("Browse"), ">>");
1348 SetHelp("<<", trVDR(BUTTON"New"), trVDR(BUTTON"Delete"), tr("Rename"));
1351 buttonnum=num; Display();
1355 void cMenuMP3::ScanLists(void)
1358 Status(tr("Scanning playlists..."));
1359 bool res=lists->Load(MP3Sources.GetSource());
1362 cPlayList *plist=lists->First();
1364 Add(new cMenuMP3Item(plist));
1365 plist=lists->Next(plist);
1368 else Error(tr("Error scanning playlists!"));
1371 eOSState cMenuMP3::Delete(void)
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()) {
1379 cOsdMenu::Del(Current());
1382 else Error(tr("Error deleting playlist!"));
1388 eOSState cMenuMP3::New(void)
1390 cPlayList *plist=new cPlayList(MP3Sources.GetSource(),0,0);
1394 if(i) sprintf(name,"%s%d",tr("unnamed"),i++);
1395 else { strcpy(name,tr("unnamed")); i++; }
1396 } while(plist->TestName(name));
1398 if(plist->Create(name)) {
1400 Add(new cMenuMP3Item(plist), true);
1402 isyslog("MP3: playlist %s added", plist->Name());
1403 return AddSubMenu(new cMenuPlayList(plist));
1405 Error(tr("Error creating playlist!"));
1410 eOSState cMenuMP3::Rename(bool second)
1412 if(HasSubMenu() || Count() == 0) return osContinue;
1414 cPlayList *plist = ((cMenuMP3Item *)Get(Current()))->List();
1417 return AddSubMenu(new cPlaylistRename(plist->BaseName()));
1420 const char *newname=cPlaylistRename::GetNewname();
1422 if(plist->Rename(newname)) {
1424 DisplayCurrent(true);
1426 else Error(tr("Error renaming playlist!"));
1431 eOSState cMenuMP3::Edit(void)
1433 if(HasSubMenu() || Count() == 0) return osContinue;
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));
1441 else Error(tr("Can't edit a WinAmp playlist!"));
1445 eOSState cMenuMP3::Play(void)
1447 if(HasSubMenu() || Count() == 0) return osContinue;
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; }
1459 Error(tr("Error loading playlist!"));
1463 eOSState cMenuMP3::Source(bool second)
1465 if(HasSubMenu()) return osContinue;
1469 return AddSubMenu(new cMenuSource(&MP3Sources,tr("MP3 source")));
1472 cFileSource *src=cMenuSource::GetSelected();
1474 MP3Sources.SetSource(src);
1481 eOSState cMenuMP3::Instant(bool second)
1483 if(HasSubMenu()) return osContinue;
1487 return AddSubMenu(new cMenuInstantBrowse(MP3Sources.GetSource(),trVDR(BUTTON"Play"),tr("Play all")));
1490 cFileObj *item=cMenuInstantBrowse::GetSelected();
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); }
1502 Error(tr("Error building playlist!"));
1507 eOSState cMenuMP3::ProcessKey(eKeys Key)
1509 eOSState state = cOsdMenu::ProcessKey(Key);
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);
1517 if(state == osUnknown) {
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;
1531 // --- PropagateImage ----------------------------------------------------------
1533 void PropagateImage(const char *image)
1535 cPlugin *graphtft=cPluginManager::GetPlugin("graphtft");
1536 if(graphtft) graphtft->SetupParse("CoverImage",image ? image:"");
1539 // --- cPluginMP3 --------------------------------------------------------------
1541 static const char *DESCRIPTION = trNOOP("A versatile audio player");
1542 static const char *MAINMENUENTRY = "MP3";
1544 class cPluginMp3 : public cPlugin {
1546 #if APIVERSNUM >= 10330
1547 bool ExternalPlay(const char *path, bool test);
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);
1559 virtual bool Start(void);
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);
1575 cPluginMp3::cPluginMp3(void)
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!
1582 cPluginMp3::~cPluginMp3()
1584 InfoCache.Shutdown();
1588 const char *cPluginMp3::CommandLineHelp(void)
1590 static char *help_str=0;
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"
1595 " -n CMD, --network=CMD execute CMD before & after network access\n"
1597 " -C DIR, --cache=DIR store ID3 cache file in DIR\n"
1599 " -B DIR, --cddb=DIR search CDDB files in DIR\n"
1601 " -D DEV, --dsp=DEV device for OSS output\n"
1603 " -i CMD, --iconv=CMD use CMD to convert background images\n"
1605 " -c DIR, --icache=DIR cache converted images in DIR\n"
1607 " -S SUB, --sources=SUB search sources config in SUB subdirectory\n"
1611 netscript ? netscript:"none",
1612 cachedir ? cachedir:"video dir",
1625 sourcesSub ? sourcesSub:"empty"
1630 bool cPluginMp3::ProcessArgs(int argc, char *argv[])
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' },
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) {
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;
1655 cddbpath=optarg; break;
1657 fprintf(stderr, "mp3: libsndfile support has not been compiled in!\n"); return false;
1661 dspdevice=optarg; break;
1663 fprintf(stderr, "mp3: OSS output has not been compiled in!\n"); return false;
1665 default: return false;
1671 #if APIVERSNUM >= 10131
1672 bool cPluginMp3::Initialize(void)
1674 bool cPluginMp3::Start(void)
1677 if(!CheckVDRVersion(1,1,29,"mp3")) return false;
1679 #if APIVERSNUM < 10507
1682 i18n_name="vdr-mp3";
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");
1691 #if APIVERSNUM < 10507
1692 RegisterI18n(Phrases);
1694 mgr=new cPlayManager;
1696 esyslog("ERROR: creating playmanager failed");
1697 fprintf(stderr,"Creating playmanager failed\n");
1700 d(printf("mp3: using %s\n",mad_version))
1701 d(printf("mp3: compiled with %s\n",MAD_VERSION))
1705 void cPluginMp3::Housekeeping(void)
1710 const char *cPluginMp3::MainMenuEntry(void)
1712 return MP3Setup.HideMainMenu ? 0 : tr(MAINMENUENTRY);
1715 cOsdObject *cPluginMp3::MainMenuAction(void)
1717 return new cMenuMP3;
1720 cMenuSetupPage *cPluginMp3::SetupMenu(void)
1722 return new cMenuSetupMP3;
1725 bool cPluginMp3::SetupParse(const char *Name, const char *Value)
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);
1748 if(MP3Setup.AudioOutMode==AUDIOOUTMODE_OSS) {
1749 esyslog("WARNING: AudioOutMode OSS not supported, falling back to DVB");
1750 MP3Setup.AudioOutMode=AUDIOOUTMODE_DVB;
1754 #if APIVERSNUM >= 10307
1755 else if (!strcasecmp(Name, "ReplayDisplay")) MP3Setup.ReplayDisplay = atoi(Value);
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);
1764 #if APIVERSNUM >= 10330
1766 bool cPluginMp3::ExternalPlay(const char *path, bool test)
1768 char real[PATH_MAX+1];
1769 if(realpath(path,real)) {
1770 cFileSource *src=MP3Sources.FindSource(real);
1772 cFileObj *item=new cFileObj(src,0,0,otFile);
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);
1784 else dsyslog("MP3 service: error building playlist");
1787 else dsyslog("MP3 service: cannot play '%s'",path);
1789 else dsyslog("MP3 service: GuessType() failed for '%s'",path);
1793 else dsyslog("MP3 service: cannot find source for '%s', real '%s'",path,real);
1795 else if(errno!=ENOENT && errno!=ENOTDIR)
1796 esyslog("ERROR: realpath: %s: %s",path,strerror(errno));
1800 bool cPluginMp3::Service(const char *Id, void *Data)
1802 if(!strcasecmp(Id,"MP3-Play-v1")) {
1804 struct MPlayerServiceData *msd=(struct MPlayerServiceData *)Data;
1805 msd->result=ExternalPlay(msd->data.filename,false);
1809 else if(!strcasecmp(Id,"MP3-Test-v1")) {
1811 struct MPlayerServiceData *msd=(struct MPlayerServiceData *)Data;
1812 msd->result=ExternalPlay(msd->data.filename,true);
1819 #if APIVERSNUM >= 10331
1821 const char **cPluginMp3::SVDRPHelpPages(void)
1823 static const char *HelpPages[] = {
1825 " Triggers playback of file 'filename'.",
1827 " Tests is playback of file 'filename' is possible.",
1829 " Returns filename of song currently being replayed.",
1835 cString cPluginMp3::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
1837 if(!strcasecmp(Command,"PLAY")) {
1839 if(ExternalPlay(Option,false)) return "Playback triggered";
1840 else { ReplyCode=550; return "Playback failed"; }
1842 else { ReplyCode=501; return "Missing filename"; }
1844 else if(!strcasecmp(Command,"TEST")) {
1846 if(ExternalPlay(Option,true)) return "Playback possible";
1847 else { ReplyCode=550; return "Playback not possible"; }
1849 else { ReplyCode=501; return "Missing filename"; }
1851 else if(!strcasecmp(Command,"CURR")) {
1852 cControl *control=cControl::Control();
1853 if(control && typeid(*control)==typeid(cMP3Control)) {
1855 if(mgr->Info(-1,&mode)) return mode.Filename;
1856 else return "<unknown>";
1858 else { ReplyCode=550; return "No running playback"; }
1866 VDRPLUGINCREATOR(cPluginMp3); // Don't touch this!