-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkaraoke-display.c
534 lines (469 loc) · 15.7 KB
/
karaoke-display.c
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
/*
* Karaoke plugin to VDR (C++)
*
* This code 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 code 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
*/
#include <stdlib.h>
#include <getopt.h>
#include <strings.h>
#include <typeinfo>
#include <vdr/menuitems.h>
#include <vdr/status.h>
#include <vdr/plugin.h>
#include <vdr/osd.h>
#include <vdr/interface.h>
#include <vdr/skins.h>
#include <vdr/menu.h>
#include "karaoke.h"
#include "setup.h"
#include "syllable.h"
#include "ultrastarsong.h"
#define POSYFINPARTITION (13.5)
#define POSYDEBPARTITION (POSYFINPARTITION-5.5)
extern cUltraStarSong mySong;
int cptTimeOut = 0;
int Refreshthread = 0;
int stopThread = 0;
#define clrPartition 0xFF808080 // a Grey
#define clrNoteEmpty 0xFFbfbfbf // Grey
#define clrNoteEmptyLight 0xFFe3e3e3 // GreyLight
#define clrNoteEmptyShadow 0xFF878787 // GreyDark
#define clrNoteFill 0xFF65c9fF // Blue
#define clrNoteFillLight 0xFFb5eeff // BlueLight
#define clrNoteFillShadow 0xFF458eb7 // BLueDark
#define clrTextEmpty 0xffcecece // Grey
#define clrTextFill 0xff7373e7 // Violet
#define clrTextBack 0xff000000 // Black
#define clrProgressEmpty 0xFFbfbfbf // another Grey
#define clrProgressFill 0xFF000000 // Black
#define ELLIPSERAD 7
static void DrawNote( cOsd * osd, int x1, int y1, int x2, int y2,
int fillPercent )
{
/*
* osd->DrawRectangle(x1,y2,x2,y1,clrNoteEmpty); // Note back x2 = x1 +
* (fillPercent*(x2-x1))/100; osd->DrawRectangle(x1,y1,x2,y2,clrNoteFill);
* // Note Fill
*/
/*
* Background note
*/
if( x2 - x1 > 2 * ELLIPSERAD )
{
osd->DrawEllipse( x1, y2, x1 + ELLIPSERAD, y1, clrNoteEmpty, 7 ); // begin
// chord
osd->DrawEllipse( x2 - ELLIPSERAD, y2, x2, y1, clrNoteEmpty, 5 ); // end
// chord
osd->DrawRectangle( x1 + ELLIPSERAD, y2, x2 - ELLIPSERAD, y1, clrNoteEmpty ); // central
// rectangle
osd->DrawRectangle( x1 + ELLIPSERAD, y2, x2 - ELLIPSERAD, y2 + 1, clrNoteEmptyLight ); // central
// rectangle
// light
osd->DrawRectangle( x1 + ELLIPSERAD, y1 - 1, x2 - ELLIPSERAD, y1, clrNoteEmptyShadow ); // central
// rectangle
// shadow
}
else
{
osd->DrawRectangle( x1, y2, x2, y1, clrNoteEmpty ); // only a rectangle
}
/*
* Compute fill position
*/
x2 = x1 + ( fillPercent * ( x2 - x1 ) ) / 100;
/*
* Fill the Note
*/
if( x2 - x1 > 2 * ELLIPSERAD )
{
osd->DrawEllipse( x1, y2, x1 + ELLIPSERAD, y1, clrNoteFill, 7 ); // begin
// chord
osd->DrawEllipse( x2 - ELLIPSERAD, y2, x2, y1, clrNoteFill, 5 ); // end
// chord
osd->DrawRectangle( x1 + ELLIPSERAD, y2, x2 - ELLIPSERAD, y1, clrNoteFill ); // central
// rectangle
osd->DrawRectangle( x1 + ELLIPSERAD, y2, x2 - ELLIPSERAD, y2 + 1, clrNoteFillLight ); // central
// rectangle
// light
osd->DrawRectangle( x1 + ELLIPSERAD, y1 - 1, x2 - ELLIPSERAD, y1, clrNoteFillShadow ); // central
// rectangle
// shadow
}
else
{
if( x1 != x2 )
{
osd->DrawRectangle( x1, y2, x2, y1, clrNoteFill ); // only a rectangle
}
}
}
void *refreshThread( void *ptr )
{
cKaraokeControl *theControl = ( cKaraokeControl * ) ptr;
int index, total;
int x0, x1, y0, y5;
int xnd, xnf, i, xtextCenter;
int xnb, yn, hn;
char oneLineBack[200];
char oneLineFront[200];
char lineTwo[200];
int status, xd, xf;
int nsent;
float timeSong, timeMpg;
const cFont *font;
int fw, fh;
int finThread = 0;
int noteMin = 1000, noteMax = 0;
int octave, octaveBase;
cSyllable oneSyll;
int tabNote[30];
int tabDur[30];
int tabStart[30];
int tabStatus[30];
int nbNote;
int offsetNote, tnoteMax, tnoteMin;
printf( "[karaoke] Begin Thread\n" );
font = cFont::GetFont( fontOsd );
fw = font->Width( ' ' );
fh = font->Height( );
x0 = 0;
x1 = Setup.OSDWidth;
y0 = 0;
y5 = Setup.OSDHeight;
// 736x576
int LastIndex = index, delta = 0, cpt = 0;
float pasT = 10;
float tim = 0;
theControl->osd =
cOsdProvider::NewOsd( Setup.OSDLeft + KaraokeSetup.OSDoffsetx,
Setup.OSDTop + KaraokeSetup.OSDoffsety );
if( !theControl->osd )
{
printf( "[karaoke] Fin Thread(%d,%d) error NewOsd \n", finThread,
cptTimeOut );
Refreshthread = 0;
theControl->visible = 0;
return ( 0 );
}
// playlist , symbols , track-titel , progress
tArea Area[] = {
{0, 1 * fh, x1 - 1, 2 * fh, 2}
, // Notes
{0, POSYDEBPARTITION * fh, x1 - 1, POSYFINPARTITION * fh, 4}
, // Partition
{0, 14 * fh, x1 - 1, 16 * fh, 2}
, // Lyrics
};
eOsdError result =
theControl->osd->CanHandleAreas( Area, sizeof( Area ) / sizeof( tArea ) );
if( result == oeOk )
{
theControl->osd->SetAreas( Area, sizeof( Area ) / sizeof( tArea ) );
theControl->osd->DrawRectangle( 0, 0 * fh, x1 - 1, 16 * fh, clrTransparent ); // Info
}
else
{
const char *errormsg = NULL;
switch ( result )
{
case oeTooManyAreas:
errormsg = "Too many OSD areas";
break;
case oeTooManyColors:
errormsg = "Too many colors";
break;
case oeBppNotSupported:
errormsg = "Depth not supported";
break;
case oeAreasOverlap:
errormsg = "Areas are overlapped";
break;
case oeWrongAlignment:
errormsg = "Areas not correctly aligned";
break;
case oeOutOfMemory:
errormsg = "OSD memory overflow";
break;
case oeUnknown:
errormsg = "Unknown OSD error";
break;
default:
break;
}
esyslog( "[vdr-karaoke] ERROR! OSD open failed! Can't handle areas (%d)-%s\n",
result, errormsg );
printf( "[karaoke] Fin Thread(%d,%d) Error SetAreas \n", finThread,
cptTimeOut );
Refreshthread = 0;
theControl->visible = 0;
return ( 0 );
}
printf( "[karaoke] Thread loop\n" );
while( finThread == 0 && stopThread == 0 )
{
if( theControl->player != NULL )
{
theControl->player->GetIndex( index, total );
if( LastIndex != index )
{
// printf("- %f\n" , (index-LastIndex)/
// (float)theControl->framesPerSecond);
pasT =
1000 * ( float ) ( ( index - LastIndex ) /
( float ) theControl->framesPerSecond );
if( cpt != 0 )
{
pasT /= cpt;
}
else
pasT = 10;
LastIndex = index;
delta = 0;
cpt = 0;
}
else
{
cpt++;
delta += pasT;
}
timeMpg = index;
timeMpg /= ( float ) theControl->framesPerSecond;
timeSong = timeMpg + ( delta / 1000.f );
if( timeSong > tim )
tim = timeSong;
mySong.SetCurrentTime( tim ); // Set song Time
/*
* -- prepare data to display --
*/
oneLineBack[0] = 0;
oneLineFront[0] = 0;
nbNote = 0;
nsent = mySong.GetNextSyllable( oneSyll, &status );
tabNote[nbNote] = oneSyll.m_note;
tabDur[nbNote] = oneSyll.m_duration;
tabStart[nbNote] = oneSyll.m_start;
tabStatus[nbNote] = status;
nbNote++;
if( oneSyll.m_note < noteMin )
noteMin = oneSyll.m_note;
if( oneSyll.m_note > noteMax )
noteMax = oneSyll.m_note;
/*
* Get line one
*/
strcpy( oneLineBack, oneSyll.Get() );
if( status == 100 )
strcpy( oneLineFront, oneSyll.Get() );
while( nsent == mySong.GetNextSyllable( oneSyll, &status ) )
{
tabNote[nbNote] = oneSyll.m_note;
tabDur[nbNote] = oneSyll.m_duration;
tabStart[nbNote] = oneSyll.m_start;
tabStatus[nbNote] = status;
nbNote++;
if( oneSyll.m_note < noteMin )
noteMin = oneSyll.m_note;
if( oneSyll.m_note > noteMax )
noteMax = oneSyll.m_note;
strcat( oneLineBack, oneSyll.Get() );
if( status == 100 )
strcat( oneLineFront, oneSyll.Get() );
}
/*
* Get line two
*/
lineTwo[0] = 0;
nsent = mySong.GetNextSyllable( oneSyll, &status );
strcpy( lineTwo, oneSyll.Get() );
while( nsent == mySong.GetNextSyllable( oneSyll, &status ) )
{
strcat( lineTwo, oneSyll.Get() );
}
octaveBase = noteMin / 12; // octave de base
/*
* Adjust les notes
*/
for( i = 0; i < nbNote; i++ )
{
tabNote[i] = tabNote[i] - octaveBase * 12;
octave = tabNote[i] / 12;
switch ( tabNote[i] % 12 )
{
case 0:
tabNote[i] = 0;
break; // do -
case 1:
tabNote[i] = 1;
break; // do#
case 2:
tabNote[i] = 2;
break; // re -
case 3:
tabNote[i] = 3;
break; // re#
case 4:
tabNote[i] = 4;
break; // mi -
case 5:
tabNote[i] = 6;
break; // fa -
case 6:
tabNote[i] = 7;
break; // fa#
case 7:
tabNote[i] = 8;
break; // sol -
case 8:
tabNote[i] = 9;
break; // sol#
case 9:
tabNote[i] = 10;
break; // la -
case 10:
tabNote[i] = 11;
break; // la#
case 11:
tabNote[i] = 12;
break; // si -
}
tabNote[i] += octave * 14;
}
// 19 ligne max
tnoteMin = 1000;
tnoteMax = 0;
offsetNote = 0;
for( i = 0; i < nbNote; i++ )
{
if( tabNote[i] < tnoteMin )
tnoteMin = tabNote[i];
if( tabNote[i] > tnoteMax )
tnoteMax = tabNote[i];
}
if( tnoteMax > 19 )
{
offsetNote = tnoteMax - 19;
}
if( tnoteMin - offsetNote < 0 )
{
offsetNote /= 2;
}
/*
* -- Draw Lyrics --
*/
theControl->osd->DrawRectangle( 0, 14 * fh, x1 - 1, 16 * fh, clrGray50 ); // Erase lyrics area
font = cFont::GetFont( fontOsd );
/*
* lyric line one
*/
xtextCenter = ( ( x1 - 1 ) - 0 ) / 2 - font->Width( oneLineBack ) / 2;
theControl->osd->DrawText( 1 + xtextCenter, 14 * fh, oneLineBack,
clrTextBack, clrTransparent, font );
theControl->osd->DrawText( xtextCenter, 14 * fh, oneLineBack,
clrTextEmpty, clrTransparent, font );
theControl->osd->DrawText( xtextCenter, 14 * fh, oneLineFront,
clrTextFill, clrTransparent, font );
/*
* lyric line two
*/
xtextCenter = ( ( x1 - 1 ) - 0 ) / 2 - font->Width( lineTwo ) / 2;
theControl->osd->DrawText( 1 + xtextCenter, 15 * fh, lineTwo,
clrTextBack, clrTransparent, font );
theControl->osd->DrawText( xtextCenter, 15 * fh, lineTwo, clrTextEmpty,
clrTransparent, font );
// sprintf(oneLineFront,"dbg:%4.3f %3d %3d %3d
// %3d",tim,cptTimeOut,index,total,nbNote);
// sprintf(oneLineFront,"dbg:%3d",nbNote);
// theControl->osd->DrawText( 1*fw , 13*fh , oneLineFront, clrTextEmpty
// ,clrTransparent, font);
/*
* -- Draw partition --
*/
theControl->osd->DrawRectangle( 0, POSYDEBPARTITION * fh, x1 - 1, POSYFINPARTITION * fh, clrGray50 ); // Erase notes area
xnd = ( int ) ( ( x1 - 1 - 0 ) * 0.03f );
xnf = ( int ) ( ( x1 - 1 - 0 ) * 0.97f );
xnb = ( tabStart[nbNote - 1] + tabDur[nbNote - 1] ) - tabStart[0];
/*
* Grille de Partition
*/
hn = ( POSYFINPARTITION * fh - POSYDEBPARTITION * fh ) / 20;
for( i = 0; i < 20; i += 2 )
{
yn = POSYFINPARTITION * fh - ( i * hn );
yn -= hn;
theControl->osd->DrawRectangle( xnd, yn, xnf, yn + 1, clrPartition ); //
}
/*
* les notes
*/
if( xnb > 0 )
{
for( i = 0; i < nbNote; i++ )
{
xd = xnd + ( ( xnf - xnd ) * ( tabStart[i] - tabStart[0] ) / xnb );
xf =
xnd +
( ( xnf - xnd ) * ( ( tabStart[i] + tabDur[i] ) -
tabStart[0] ) / xnb );
yn = POSYFINPARTITION * fh - ( ( tabNote[i] - offsetNote ) * hn );
DrawNote( theControl->osd, xd, yn, xf, yn - 2 * hn, tabStatus[i] ); // Draw note
}
}
/*
* -- Header --
*/
/*
* Time
*/
// theControl->osd->DrawRectangle(1*fw , 1*fh, 6*fw , 2*fh,
// clrTransparent); // Erase Time area
sprintf( oneLineFront, "%02d:%02d", ( int ) ( timeMpg / 60 ),
( int ) ( ( ( int ) timeMpg ) % 60 ) );
font = cFont::GetFont( fontSml );
theControl->osd->DrawText( 1 * fw, 1 * fh, oneLineFront,
clrProgressEmpty, clrGray50, font );
/*
* Progress bar
*/
theControl->osd->DrawRectangle( 13 * fw, 1 * fh + ( fh / 4 ), 43 * fw,
1 * fh + ( 3 * fh / 4 ),
clrProgressEmpty );
if( total != 0 )
{
theControl->osd->DrawRectangle( 2 + 13 * fw, 1 * fh + ( fh / 4 ) + 2,
13 * fw +
fw * ( ( 30 * index ) / total ),
1 * fh + ( 3 * fh / 4 ) - 2,
clrProgressFill );
}
/*
* flush osd
*/
theControl->osd->Flush( );
}
usleep( 10000 );
cptTimeOut++;
if( cptTimeOut > 150 )
finThread = 1;
if( cOsd::IsOpen( ) == 0 )
finThread = 1;
if( theControl->osd == NULL )
finThread = 1;
}
printf( "[karaoke] Fin Thread(%d,%d)\n", finThread, cptTimeOut );
Refreshthread = 0;
theControl->visible = 0;
return ( NULL );
}