File: menucontrol.c

package info (click to toggle)
vdr-plugin-vcd 0.9-22
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 496 kB
  • ctags: 598
  • sloc: ansic: 3,014; makefile: 63; sh: 27
file content (433 lines) | stat: -rw-r--r-- 11,451 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/*
 * menucontrol.c: Menu control of VCD replay
 *
 * VCD Player plugin for VDR (the Video Disk Recorder)
 * Copyright (C) 2002  Thomas Heiligenmann  <thomas@heiligenmann.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
 *
 */


#include <stdio.h>
#include <typeinfo>

#include <vdr/interface.h>
#include <vdr/status.h>
#include <vdr/i18n.h>
#include "menu.h"
#include "functions.h"
#include "setup.h"
#include "menucontrol.h"


#define MODETIMEOUT       3 // seconds


// --- cMenuSpiControl -------------------------------------------------------

int cMenuSpiControl::spi = 0;
cVcd *cMenuSpiControl::vcd = 0;

cMenuSpiControl::cMenuSpiControl(void)
: cVcdViewerControl(spi, vcd)
{
  displayReplay = NULL;
  visible = modeOnly = false;
}

cMenuSpiControl::~cMenuSpiControl()
{
  cStatus::MsgReplaying(this, NULL, NULL, true);
  Stop();
}

void cMenuSpiControl::SetItem(int Spi, cVcd *Vcd)
{
  cControl *control = cControl::Control();
  if (control && typeid(*control)==typeid(cMenuVcdControl))
     static_cast<cMenuVcdControl*>(control)->Stop();
  if (control && typeid(*control)==typeid(cMenuSpiControl)
        && strcmp(Vcd->DeviceName(),static_cast<cMenuSpiControl*>(control)->DeviceName())==0) {
     static_cast<cMenuSpiControl*>(control)->GotoItem(Spi);
     return;
  }

  spi = Spi;
  vcd = Vcd;
  cControl::Launch(new cMenuSpiControl);
}

void cMenuSpiControl::Hide(void)
{
  if (visible) {
     delete displayReplay;
#if APIVERSNUM >= 10500
     SetNeedsFastResponse(false);
#else
     needsFastResponse = false;
#endif
     visible = false;
     modeOnly = false;
  }
}

eOSState cMenuSpiControl::ProcessKey(eKeys Key)
{
  if (!Active())
     return osEnd;
  switch (Key) {
     // Positioning:
     case k4:       SkipItems(-1); break;
     case k5:       ToggleStillRes(); break;
     case k6:       SkipItems(1); break;
     case kBlue:    Hide();
                    Stop();
                    vcd->Close();
                    return osEnd;
     default: {
        switch (Key) {
           // Editing: (?)
           default: {
              switch (Key) {
                 // Menu control:
                 case kOk:   break;
                 case kBack: Hide();
                             Stop();
                             vcd->Close();
                             return osEnd;
                 default:    return osUnknown;
              }
           }
        }
     }
  }
  return osContinue;
}


// --- cMenuVcdControl ------------------------------------------------------

int cMenuVcdControl::track = 0;
cVcd *cMenuVcdControl::vcd = 0;
char *cMenuVcdControl::title = 0;

cMenuVcdControl::cMenuVcdControl(void)
: cVcdPlayerControl(track, vcd)
{
  displayReplay = NULL;
  visible = modeOnly = shown = displayFrames = false;
  lastCurrent = lastTotal = -1;
  lastPlay = lastForward = false;
  lastSpeed = -1;
  timeoutShow = 0;
  timeSearchActive = false;
  cStatus::MsgReplaying(this, "VCD", NULL, true);
}

cMenuVcdControl::~cMenuVcdControl()
{
  Hide();
  cStatus::MsgReplaying(this, NULL, NULL, false);
  Stop();
}

void cMenuVcdControl::SetTrack(int Track, cVcd *Vcd)
{
  cControl *control = cControl::Control();
  if (control && typeid(*control)==typeid(cMenuSpiControl))
     static_cast<cMenuSpiControl*>(control)->Stop();
  if (control && typeid(*control)==typeid(cMenuVcdControl) &&
        strcmp(Vcd->DeviceName(),static_cast<cMenuVcdControl*>(control)->DeviceName())==0) {
     static_cast<cMenuVcdControl*>(control)->GotoTrack(Track);
     return;
  }

  free(title);
  track = Track;
  vcd = Vcd;
  title = NULL;
  cControl::Launch(new cMenuVcdControl);
}

const int cMenuVcdControl::LastReplayed(void)
{
  return track;
}

void cMenuVcdControl::ShowTimed(int Seconds)
{
  if (modeOnly)
     Hide();
  if (!visible) {
     shown = ShowProgress(true);
     timeoutShow = (shown && Seconds > 0) ? time(NULL) + Seconds : 0;
  }
}

void cMenuVcdControl::Show(void)
{
  ShowTimed();
}

void cMenuVcdControl::Hide(void)
{
  if (visible) {
     delete displayReplay;
#if APIVERSNUM >= 10500
     SetNeedsFastResponse(false);
#else
     needsFastResponse = false;
#endif
     visible = false;
     modeOnly = false;
     lastPlay = lastForward = false;
     lastSpeed = -1;
     timeSearchActive = false;
  }
}

void cMenuVcdControl::ShowMode(void)
{
  if (visible || Setup.ShowReplayMode && !cOsd::IsOpen()) {
     bool Play, Forward;
     int Speed;
     if (GetReplayMode(Play, Forward, Speed) &&
           (!visible || Play != lastPlay || Forward != lastForward || Speed != lastSpeed)) {
        bool NormalPlay = (Play && Speed == -1);

        if (!visible) {
           if (NormalPlay)
              return; // no need to do indicate ">" unless there was a different mode displayed before
           visible = modeOnly = true;
           displayReplay = Skins.Current()->DisplayReplay(modeOnly);
        }

        if (modeOnly && !timeoutShow && NormalPlay)
           timeoutShow = time(NULL) + MODETIMEOUT;
        displayReplay->SetMode(Play, Forward, Speed);
        lastPlay = Play;
        lastForward = Forward;
        lastSpeed = Speed;
     }
  }
}

bool cMenuVcdControl::ShowProgress(bool Initial)
{
  int Current, Total;

  if (GetIndex(Current, Total) && Total > 0) {
     if (!visible) {
        displayReplay = Skins.Current()->DisplayReplay(modeOnly);
#if APIVERSNUM >= 10500
        SetNeedsFastResponse(false);
#else
        needsFastResponse = false;
#endif
	    visible = true;
     }
     if (Initial)
        lastCurrent = lastTotal = -1;
     if (title) 
        displayReplay->SetTitle(title);
     if (Total != lastTotal) {
        displayReplay->SetTotal(IndexToHMSF(Total));
     if (!Initial)
           displayReplay->Flush();
     }
     if (Current != lastCurrent || Total != lastTotal) {
        displayReplay->SetProgress(Current, Total);
        if (!Initial)
           displayReplay->Flush();
        displayReplay->SetCurrent(IndexToHMSF(Current, displayFrames));
        displayReplay->Flush();
        lastCurrent = Current;
     }
     lastTotal = Total;
     ShowMode();
     return true;
  }
  return false;
}

void cMenuVcdControl::TimeSearchDisplay(void)
{
  char buf[64];
  strcpy(buf, tr("Jump: "));
  int len = strlen(buf);
  char h10 = '0' + (timeSearchTime >> 24);
  char h1  = '0' + ((timeSearchTime & 0x00FF0000) >> 16);
  char m10 = '0' + ((timeSearchTime & 0x0000FF00) >> 8);
  char m1  = '0' + (timeSearchTime & 0x000000FF);
  char ch10 = timeSearchPos > 3 ? h10 : '-';
  char ch1  = timeSearchPos > 2 ? h1  : '-';
  char cm10 = timeSearchPos > 1 ? m10 : '-';
  char cm1  = timeSearchPos > 0 ? m1  : '-';
  sprintf(buf + len, "%c%c:%c%c", ch10, ch1, cm10, cm1);
  displayReplay->SetJump(buf);
}

void cMenuVcdControl::TimeSearchProcess(eKeys Key)
{
#define STAY_SECONDS_OFF_END 10
  int Seconds = (timeSearchTime >> 24) * 36000 + ((timeSearchTime & 0x00FF0000) >> 16) * 3600 + ((timeSearchTime & 0x0000FF00) >> 8) * 600 + (timeSearchTime & 0x000000FF) * 60;
  int Current = (lastCurrent / FRAMESPERSEC);
  int Total = (lastTotal / FRAMESPERSEC);
  switch (Key) {
    case k0 ... k9:
         if (timeSearchPos < 4) {
            timeSearchTime <<= 8;
            timeSearchTime |= Key - k0;
            timeSearchPos++;
            TimeSearchDisplay();
         }
         break;
    case kFastRew:
    case kLeft:
    case kFastFwd:
    case kRight: {
         int dir = ((Key == kRight || Key == kFastFwd) ? 1 : -1);
         if (dir > 0)
            Seconds = min(Total - Current - STAY_SECONDS_OFF_END, Seconds);
         SkipSeconds(Seconds * dir);
         timeSearchActive = false;
         }
         break;
    case kPlay:
    case kUp:
    case kPause:
    case kDown:
         Seconds = min(Total - STAY_SECONDS_OFF_END, Seconds);
         Goto(Seconds, Key == kDown || Key == kPause);
         timeSearchActive = false;
         break;
    default:
         timeSearchActive = false;
         break;
  }
  if (!timeSearchActive) {
     if (timeSearchHide)
        Hide();
     else
        displayReplay->SetJump(NULL);
     ShowMode();
  }
}

void cMenuVcdControl::TimeSearch(void)
{
  timeSearchTime = timeSearchPos = 0;
  timeSearchHide = false;
  if (modeOnly)
     Hide();
  if (!visible) {
     Show();
     if (visible)
        timeSearchHide = true;
     else
        return;
  }
  timeoutShow = 0;
  TimeSearchDisplay();
  timeSearchActive = true;
}

eOSState cMenuVcdControl::ProcessKey(eKeys Key)
{
  if (!Active())
     return osEnd;
  if (visible) {
     if (timeoutShow && time(0) > timeoutShow) {
        Hide();
        ShowMode();
        timeoutShow = 0;
     } else if (modeOnly)
        ShowMode();
     else
        shown = ShowProgress(!shown) || shown;
  }
  bool DisplayedFrames = displayFrames;
  displayFrames = false;
  if (timeSearchActive && Key != kNone) {
     TimeSearchProcess(Key);
     return osContinue;
  }
  switch (Key) {
     case k1: SkipEntries(-1); break;
     case k3: SkipEntries(1); break;
     case k4: SkipTracks(-1); break;
     case k5: SkipTracks(0); break;
     case k6: SkipTracks(1); break;
     default: break;
  }
  asprintf(&title, "VideoCD Track %02d", GetTrack());
  bool DoShowMode = true;
  switch (Key) {
     // Positioning:
     case kPlay:
     case kUp:      Play(); break;
     case kPause:
     case kDown:    Pause(); break;
     case kFastRew|k_Release:
     case kLeft|k_Release:
                    if (Setup.MultiSpeedMode) break;
     case kFastRew:
     case kLeft:    Backward(); break;
     case kFastFwd|k_Release:
     case kRight|k_Release:
                    if (Setup.MultiSpeedMode) break;
     case kFastFwd:
     case kRight:   Forward(); break;
     case kRed:     TimeSearch(); break;
     case kGreen|k_Repeat:
     case kGreen:   SkipSeconds(-60); break;
     case kYellow|k_Repeat:
     case kYellow:  SkipSeconds(60); break;
     case kStop:
     case kBlue:    Hide();
                    Stop();
                    vcd->Close();
                    return osEnd;
     default: {
        DoShowMode = false;
        switch (Key) {
           // Editing: (?)

           default: {
              displayFrames = DisplayedFrames;
              switch (Key) {
                 // Menu control:
                 case kOk:   if (visible && !modeOnly) {
                                Hide();
                                DoShowMode = true;
                             } else
                                Show();
                             break;
                 case kBack: Hide();
                             Stop();
                             vcd->Close();
                             return osEnd;
                 default:    return osUnknown;
              }
           }
        }
     }
  }
  if (DoShowMode)
     ShowMode();
  return osContinue;
}