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