/* ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com ** ** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ** ** Any non-GPL usage of this software or parts of this software is strictly ** forbidden. ** ** Commercial non-GPL licensing of this software is possible. ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. ** ** $Id$ **/ #ifdef MAIN_DEC #ifndef __IC_PREDICT_H__ #define __IC_PREDICT_H__ #ifdef __cplusplus extern "C" { #endif #define ALPHA REAL_CONST(0.90625) #define A REAL_CONST(0.953125) void pns_reset_pred_state(ic_stream *ics, pred_state *state); void reset_all_predictors(pred_state *state, uint16_t frame_len); void ic_prediction(ic_stream *ics, real_t *spec, pred_state *state, uint16_t frame_len, uint8_t sf_index); ALIGN static const real_t mnt_table[128] = { COEF_CONST(0.9531250000), COEF_CONST(0.9453125000), COEF_CONST(0.9375000000), COEF_CONST(0.9296875000), COEF_CONST(0.9257812500), COEF_CONST(0.9179687500), COEF_CONST(0.9101562500), COEF_CONST(0.9023437500), COEF_CONST(0.8984375000), COEF_CONST(0.8906250000), COEF_CONST(0.8828125000), COEF_CONST(0.8789062500), COEF_CONST(0.8710937500), COEF_CONST(0.8671875000), COEF_CONST(0.8593750000), COEF_CONST(0.8515625000), COEF_CONST(0.8476562500), COEF_CONST(0.8398437500), COEF_CONST(0.8359375000), COEF_CONST(0.8281250000), COEF_CONST(0.8242187500), COEF_CONST(0.8203125000), COEF_CONST(0.8125000000), COEF_CONST(0.8085937500), COEF_CONST(0.8007812500), COEF_CONST(0.7968750000), COEF_CONST(0.7929687500), COEF_CONST(0.7851562500), COEF_CONST(0.7812500000), COEF_CONST(0.7773437500), COEF_CONST(0.7734375000), COEF_CONST(0.7656250000), COEF_CONST(0.7617187500), COEF_CONST(0.7578125000), COEF_CONST(0.7539062500), COEF_CONST(0.7500000000), COEF_CONST(0.7421875000), COEF_CONST(0.7382812500), COEF_CONST(0.7343750000), COEF_CONST(0.7304687500), COEF_CONST(0.7265625000), COEF_CONST(0.7226562500), COEF_CONST(0.7187500000), COEF_CONST(0.7148437500), COEF_CONST(0.7109375000), COEF_CONST(0.7070312500), COEF_CONST(0.6992187500), COEF_CONST(0.6953125000), COEF_CONST(0.6914062500), COEF_CONST(0.6875000000), COEF_CONST(0.6835937500), COEF_CONST(0.6796875000), COEF_CONST(0.6796875000), COEF_CONST(0.6757812500), COEF_CONST(0.6718750000), COEF_CONST(0.6679687500), COEF_CONST(0.6640625000), COEF_CONST(0.6601562500), COEF_CONST(0.6562500000), COEF_CONST(0.6523437500), COEF_CONST(0.6484375000), COEF_CONST(0.6445312500), COEF_CONST(0.6406250000), COEF_CONST(0.6406250000), COEF_CONST(0.6367187500), COEF_CONST(0.6328125000), COEF_CONST(0.6289062500), COEF_CONST(0.6250000000), COEF_CONST(0.6210937500), COEF_CONST(0.6210937500), COEF_CONST(0.6171875000), COEF_CONST(0.6132812500), COEF_CONST(0.6093750000), COEF_CONST(0.6054687500), COEF_CONST(0.6054687500), COEF_CONST(0.6015625000), COEF_CONST(0.5976562500), COEF_CONST(0.5937500000), COEF_CONST(0.5937500000), COEF_CONST(0.5898437500), COEF_CONST(0.5859375000), COEF_CONST(0.5820312500), COEF_CONST(0.5820312500), COEF_CONST(0.5781250000), COEF_CONST(0.5742187500), COEF_CONST(0.5742187500), COEF_CONST(0.5703125000), COEF_CONST(0.5664062500), COEF_CONST(0.5664062500), COEF_CONST(0.5625000000), COEF_CONST(0.5585937500), COEF_CONST(0.5585937500), COEF_CONST(0.5546875000), COEF_CONST(0.5507812500), COEF_CONST(0.5507812500), COEF_CONST(0.5468750000), COEF_CONST(0.5429687500), COEF_CONST(0.5429687500), COEF_CONST(0.5390625000), COEF_CONST(0.5390625000), COEF_CONST(0.5351562500), COEF_CONST(0.5312500000), COEF_CONST(0.5312500000), COEF_CONST(0.5273437500), COEF_CONST(0.5273437500), COEF_CONST(0.5234375000), COEF_CONST(0.5195312500), COEF_CONST(0.5195312500), COEF_CONST(0.5156250000), COEF_CONST(0.5156250000), COEF_CONST(0.5117187500), COEF_CONST(0.5117187500), COEF_CONST(0.5078125000), COEF_CONST(0.5078125000), COEF_CONST(0.5039062500), COEF_CONST(0.5039062500), COEF_CONST(0.5000000000), COEF_CONST(0.4980468750), COEF_CONST(0.4960937500), COEF_CONST(0.4941406250), COEF_CONST(0.4921875000), COEF_CONST(0.4902343750), COEF_CONST(0.4882812500), COEF_CONST(0.4863281250), COEF_CONST(0.4843750000), COEF_CONST(0.4824218750), COEF_CONST(0.4804687500), COEF_CONST(0.4785156250) }; ALIGN static const real_t exp_table[128] = { COEF_CONST(0.50000000000000000000000000000000000000000000000000), COEF_CONST(0.25000000000000000000000000000000000000000000000000), COEF_CONST(0.12500000000000000000000000000000000000000000000000), COEF_CONST(0.06250000000000000000000000000000000000000000000000), COEF_CONST(0.03125000000000000000000000000000000000000000000000), COEF_CONST(0.01562500000000000000000000000000000000000000000000), COEF_CONST(0.00781250000000000000000000000000000000000000000000), COEF_CONST(0.00390625000000000000000000000000000000000000000000), COEF_CONST(0.00195312500000000000000000000000000000000000000000), COEF_CONST(0.00097656250000000000000000000000000000000000000000), COEF_CONST(0.00048828125000000000000000000000000000000000000000), COEF_CONST(0.00024414062500000000000000000000000000000000000000), COEF_CONST(0.00012207031250000000000000000000000000000000000000), COEF_CONST(0.00006103515625000000000000000000000000000000000000), COEF_CONST(0.00003051757812500000000000000000000000000000000000), COEF_CONST(0.00001525878906250000000000000000000000000000000000), COEF_CONST(0.00000762939453125000000000000000000000000000000000), COEF_CONST(0.00000381469726562500000000000000000000000000000000), COEF_CONST(0.00000190734863281250000000000000000000000000000000), COEF_CONST(0.00000095367431640625000000000000000000000000000000), COEF_CONST(0.00000047683715820312500000000000000000000000000000), COEF_CONST(0.00000023841857910156250000000000000000000000000000), COEF_CONST(0.00000011920928955078125000000000000000000000000000), COEF_CONST(0.00000005960464477539062500000000000000000000000000), COEF_CONST(0.00000002980232238769531300000000000000000000000000), COEF_CONST(0.00000001490116119384765600000000000000000000000000), COEF_CONST(0.00000000745058059692382810000000000000000000000000), COEF_CONST(0.00000000372529029846191410000000000000000000000000), COEF_CONST(0.00000000186264514923095700000000000000000000000000), COEF_CONST(0.00000000093132257461547852000000000000000000000000), COEF_CONST(0.00000000046566128730773926000000000000000000000000), COEF_CONST(0.00000000023283064365386963000000000000000000000000), COEF_CONST(0.00000000011641532182693481000000000000000000000000), COEF_CONST(0.00000000005820766091346740700000000000000000000000), COEF_CONST(0.00000000002910383045673370400000000000000000000000), COEF_CONST(0.00000000001455191522836685200000000000000000000000), COEF_CONST(0.00000000000727595761418342590000000000000000000000), COEF_CONST(0.00000000000363797880709171300000000000000000000000), COEF_CONST(0.00000000000181898940354585650000000000000000000000), COEF_CONST(0.00000000000090949470177292824000000000000000000000), COEF_CONST(0.00000000000045474735088646412000000000000000000000), COEF_CONST(0.00000000000022737367544323206000000000000000000000), COEF_CONST(0.00000000000011368683772161603000000000000000000000), COEF_CONST(0.00000000000005684341886080801500000000000000000000), COEF_CONST(0.00000000000002842170943040400700000000000000000000), COEF_CONST(0.00000000000001421085471520200400000000000000000000), COEF_CONST(0.00000000000000710542735760100190000000000000000000), COEF_CONST(0.00000000000000355271367880050090000000000000000000), COEF_CONST(0.00000000000000177635683940025050000000000000000000), COEF_CONST(0.00000000000000088817841970012523000000000000000000), COEF_CONST(0.00000000000000044408920985006262000000000000000000), COEF_CONST(0.00000000000000022204460492503131000000000000000000), COEF_CONST(0.00000000000000011102230246251565000000000000000000), COEF_CONST(0.00000000000000005551115123125782700000000000000000), COEF_CONST(0.00000000000000002775557561562891400000000000000000), COEF_CONST(0.00000000000000001387778780781445700000000000000000), COEF_CONST(0.00000000000000000693889390390722840000000000000000), COEF_CONST(0.00000000000000000346944695195361420000000000000000), COEF_CONST(0.00000000000000000173472347597680710000000000000000), COEF_CONST(0.00000000000000000086736173798840355000000000000000), COEF_CONST(0.00000000000000000043368086899420177000000000000000), COEF_CONST(0.00000000000000000021684043449710089000000000000000), COEF_CONST(0.00000000000000000010842021724855044000000000000000), COEF_CONST(0.00000000000000000005421010862427522200000000000000), COEF_CONST(0.00000000000000000002710505431213761100000000000000), COEF_CONST(0.00000000000000000001355252715606880500000000000000), COEF_CONST(0.00000000000000000000677626357803440270000000000000), COEF_CONST(0.00000000000000000000338813178901720140000000000000), COEF_CONST(0.00000000000000000000169406589450860070000000000000), COEF_CONST(0.00000000000000000000084703294725430034000000000000), COEF_CONST(0.00000000000000000000042351647362715017000000000000), COEF_CONST(0.00000000000000000000021175823681357508000000000000), COEF_CONST(0.00000000000000000000010587911840678754000000000000), COEF_CONST(0.00000000000000000000005293955920339377100000000000), COEF_CONST(0.00000000000000000000002646977960169688600000000000), COEF_CONST(0.00000000000000000000001323488980084844300000000000), COEF_CONST(0.00000000000000000000000661744490042422140000000000), COEF_CONST(0.00000000000000000000000330872245021211070000000000), COEF_CONST(0.00000000000000000000000165436122510605530000000000), COEF_CONST(0.00000000000000000000000082718061255302767000000000), COEF_CONST(0.00000000000000000000000041359030627651384000000000), COEF_CONST(0.00000000000000000000000020679515313825692000000000), COEF_CONST(0.00000000000000000000000010339757656912846000000000), COEF_CONST(0.00000000000000000000000005169878828456423000000000), COEF_CONST(0.00000000000000000000000002584939414228211500000000), COEF_CONST(0.00000000000000000000000001292469707114105700000000), COEF_CONST(0.00000000000000000000000000646234853557052870000000), COEF_CONST(0.00000000000000000000000000323117426778526440000000), COEF_CONST(0.00000000000000000000000000161558713389263220000000), COEF_CONST(0.00000000000000000000000000080779356694631609000000), COEF_CONST(0.00000000000000000000000000040389678347315804000000), COEF_CONST(0.00000000000000000000000000020194839173657902000000), COEF_CONST(0.00000000000000000000000000010097419586828951000000), COEF_CONST(0.00000000000000000000000000005048709793414475600000), COEF_CONST(0.00000000000000000000000000002524354896707237800000), COEF_CONST(0.00000000000000000000000000001262177448353618900000), COEF_CONST(0.00000000000000000000000000000631088724176809440000), COEF_CONST(0.00000000000000000000000000000315544362088404720000), COEF_CONST(0.00000000000000000000000000000157772181044202360000), COEF_CONST(0.00000000000000000000000000000078886090522101181000), COEF_CONST(0.00000000000000000000000000000039443045261050590000), COEF_CONST(0.00000000000000000000000000000019721522630525295000), COEF_CONST(0.00000000000000000000000000000009860761315262647600), COEF_CONST(0.00000000000000000000000000000004930380657631323800), COEF_CONST(0.00000000000000000000000000000002465190328815661900), COEF_CONST(0.00000000000000000000000000000001232595164407830900), COEF_CONST(0.00000000000000000000000000000000616297582203915470), COEF_CONST(0.00000000000000000000000000000000308148791101957740), COEF_CONST(0.00000000000000000000000000000000154074395550978870), COEF_CONST(0.00000000000000000000000000000000077037197775489434), COEF_CONST(0.00000000000000000000000000000000038518598887744717), COEF_CONST(0.00000000000000000000000000000000019259299443872359), COEF_CONST(0.00000000000000000000000000000000009629649721936179), COEF_CONST(0.00000000000000000000000000000000004814824860968090), COEF_CONST(0.00000000000000000000000000000000002407412430484045), COEF_CONST(0.00000000000000000000000000000000001203706215242022), COEF_CONST(0.00000000000000000000000000000000000601853107621011), COEF_CONST(0.00000000000000000000000000000000000300926553810506), COEF_CONST(0.00000000000000000000000000000000000150463276905253), COEF_CONST(0.00000000000000000000000000000000000075231638452626), COEF_CONST(0.00000000000000000000000000000000000037615819226313), COEF_CONST(0.00000000000000000000000000000000000018807909613157), COEF_CONST(0.00000000000000000000000000000000000009403954806578), COEF_CONST(0.00000000000000000000000000000000000004701977403289), COEF_CONST(0.00000000000000000000000000000000000002350988701645), COEF_CONST(0.00000000000000000000000000000000000001175494350822), COEF_CONST(0.0 /* 0000000000000000000000000000000000000587747175411 "floating point underflow" */), COEF_CONST(0.0) }; #ifdef __cplusplus } #endif #endif #endif n334'>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 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2009 Wincent Balin
 *
 * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "plugin.h"
#include "pdbox.h"

#include "lib/xlcd.h"

/* Button colors. */
#define BTNCOLOR_DARK (LCD_DARKGRAY)
#define BTNCOLOR_LIGHT (LCD_LIGHTGRAY)

/* Variables in the main code. */
extern char* filename;
extern bool quit;

/* Screen multiplier. */
static float screen_multiplier;

/* Back- and foreground colors. */
static unsigned bgcolor;
static unsigned fgcolor;

/* Displacement of the slanted corner in the contour of the number widget. */
static int number_corner;

/* Button flags. */
static bool play_on;
static bool previous_on;
static bool next_on;
static bool menu_on;
static bool action_on;

/* Pause flag. */
static bool paused;


/* Draw circle using midpoint circle algorithm.
   Adapted from http://en.wikipedia.org/wiki/Midpoint_circle_algorithm. */
void drawcircle(int x, int y, int r)
{
    int f = 1 - r;
    int ddfx = 1;
    int ddfy = -2 * r;
    int xp = 0;
    int yp = r;

    /* Draw outer points. */
    rb->lcd_drawpixel(x, y + r);
    rb->lcd_drawpixel(x, y + r);
    rb->lcd_drawpixel(x + r, y);
    rb->lcd_drawpixel(x - r, y);

    /* Calculate coordinates of points in one octant. */
    while(xp < yp)
    {
        /* ddfx == 2 * xp + 1;
           ddfy == -2 * yp;
           f == xp*xp + yp*yp - r*r + 2*xp - yp + 1; */
        if(f >= 0)
        {
            yp--;
            ddfy += 2;
            f += ddfy;
        }

        xp++;
        ddfx += 2;
        f += ddfx;

        /* Draw pixels in all octants. */
        rb->lcd_drawpixel(x + xp, y + yp);
        rb->lcd_drawpixel(x + xp, y - yp);
        rb->lcd_drawpixel(x - xp, y + yp);
        rb->lcd_drawpixel(x - xp, y - yp);
        rb->lcd_drawpixel(x + yp, y + xp);
        rb->lcd_drawpixel(x + yp, y - xp);
        rb->lcd_drawpixel(x - yp, y + xp);
        rb->lcd_drawpixel(x - yp, y - xp);
    }
}

/* Fill circle. */
void fillcircle(int x, int y, int r)
{
    int f = 1 - r;
    int ddfx = 1;
    int ddfy = -2 * r;
    int xp = 0;
    int yp = r;

    /* Draw outer points. */
    rb->lcd_drawpixel(x, y + r);
    rb->lcd_drawpixel(x, y + r);
    rb->lcd_drawpixel(x + r, y);
    rb->lcd_drawpixel(x - r, y);

    /* Calculate coordinates of points in one octant. */
    while(xp < yp)
    {
        /* ddfx == 2 * xp + 1;
           ddfy == -2 * yp;
           f == xp*xp + yp*yp - r*r + 2*xp - yp + 1; */
        if(f >= 0)
        {
            yp--;
            ddfy += 2;
            f += ddfy;
        }

        xp++;
        ddfx += 2;
        f += ddfx;

        /* Fill circle with horizontal lines. */
        rb->lcd_hline(x - xp, x + xp, y - yp);
        rb->lcd_hline(x - xp, x + xp, y + yp);
        rb->lcd_hline(x - yp, x + yp, y - xp);
        rb->lcd_hline(x - yp, x + yp, y + xp);
    }

    /* Draw last horizontal line (central one). */
    rb->lcd_hline(x - r, x + r, y);
}

/* Initialize GUI. */
void pd_gui_init(void)
{
    /* Reset button flags. */
    play_on = false;
    previous_on = false;
    next_on = false;
    menu_on = false;
    action_on = false;

    /* Unpause Pure Data. */
    paused = false;

    /* Calculate dimension factors. */
    screen_multiplier = ((float) LCD_WIDTH) / 160.0f;
    number_corner = 5 * screen_multiplier;

    /* Get back- and foreground colors. */
    bgcolor = rb->lcd_get_background();
    fgcolor = rb->lcd_get_foreground();

    /* Clear background. */
    rb->lcd_clear_display();

    /* Draw background of appropriate color. */
    rb->lcd_set_foreground(bgcolor);
    rb->lcd_fillrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
    rb->lcd_set_foreground(fgcolor);

    /* Update display. */
    rb->lcd_update();
}

/* Load PD patch. */
unsigned int pd_gui_load_patch(struct pd_widget* wg, unsigned int max_widgets)
{
    int fd;
    char line[100];
    char* saveptr;
    unsigned int widgets = 0;

    /* Open PD patch. */
    fd = open(filename, O_RDONLY);

    /* Check for I/O error. */
    if(!fd)
    {
        /* Show error message and make plug-in quit. */
        rb->splash(HZ, "Error opening .pd file!");
        quit = true;
        return 0;
    }

    /* Read lines from PD file. */
    while(rb->read_line(fd, line, sizeof(line)) > 0)
    {
        /* Check whether we got too many widgets. */
        if(widgets >= max_widgets)
        {
            rb->splash(HZ, "Too many widgets!");
            quit = true;
            return 0;
        }

        /* Search for key strings in the line. */
        if((strstr(line, "floatatom") != NULL) &&
           (strstr(line, "pod_") != NULL))
        {
            wg->id = PD_NUMBER;

            strtok_r(line, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            wg->x = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->y = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->w = 7 * atoi(strtok_r(NULL, " ", &saveptr)) *
                                                          screen_multiplier;
            wg->h = 16 * screen_multiplier;
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strncpy(wg->name, strtok_r(NULL, " ", &saveptr), sizeof(wg->name));

            /* Reset value. */
            wg->value = 0;

            /* We got one more widget. */
            wg++;
            widgets++;
        }
        else if((strstr(line, "symbolatom") != NULL) &&
                (strstr(line, "pod_") != NULL))
        {
            wg->id = PD_SYMBOL;

            strtok_r(line, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            wg->x = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->y = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->w = 7 * atoi(strtok_r(NULL, " ", &saveptr)) *
                                                          screen_multiplier;
            wg->h = 16 * screen_multiplier;
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strncpy(wg->name, strtok_r(NULL, " ", &saveptr), sizeof(wg->name));

            /* Reset value. */
            wg->value = 0;

            /* We got one more widget. */
            wg++;
            widgets++;
        }
        else if((strstr(line, "vsl") != NULL) &&
                (strstr(line, "pod_") != NULL))
        {
            wg->id = PD_VSLIDER;

            strtok_r(line, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            wg->x = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->y = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            strtok_r(NULL, " ", &saveptr);
            wg->w = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->h = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->min = atoi(strtok_r(NULL, " ", &saveptr));
            wg->max = atoi(strtok_r(NULL, " ", &saveptr));
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strncpy(wg->name, strtok_r(NULL, " ", &saveptr), sizeof(wg->name));

            /* Reset value. */
            wg->value = 0;

            /* We got one more widget. */
            wg++;
            widgets++;
        }
        else if((strstr(line, "hsl") != NULL) &&
                (strstr(line, "pod_") != NULL))
        {
            wg->id = PD_HSLIDER;

            strtok_r(line, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            wg->x = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->y = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            strtok_r(NULL, " ", &saveptr);
            wg->w = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->h = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->min = atoi(strtok_r(NULL, " ", &saveptr));
            wg->max = atoi(strtok_r(NULL, " ", &saveptr));
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strncpy(wg->name, strtok_r(NULL, " ", &saveptr), sizeof(wg->name));

            /* Reset value. */
            wg->value = 0;

            /* We got one more widget. */
            wg++;
            widgets++;
        }
        else if((strstr(line, "vradio") != NULL) &&
                (strstr(line, "pod_") != NULL))
        {
            wg->id = PD_VRADIO;

            strtok_r(line, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            wg->x = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->y = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            strtok_r(NULL, " ", &saveptr);
            wg->w = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            wg->min = 0;
            wg->max = atoi(strtok_r(NULL, " ", &saveptr));
            wg->h = wg->w * wg->max;
            strtok_r(NULL, " ", &saveptr);
            strncpy(wg->name, strtok_r(NULL, " ", &saveptr), sizeof(wg->name));
            wg->max--;

            /* Reset value. */
            wg->value = 0;

            /* We got one more widget. */
            wg++;
            widgets++;
        }
        else if((strstr(line, "hradio") != NULL) &&
                (strstr(line, "pod_") != NULL))
        {
            wg->id = PD_HRADIO;

            strtok_r(line, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            wg->x = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->y = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            strtok_r(NULL, " ", &saveptr);
            wg->h = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            wg->min = 0;
            wg->max = atoi(strtok_r(NULL, " ", &saveptr));
            wg->w = wg->h * wg->max;
            strtok_r(NULL, " ", &saveptr);
            strncpy(wg->name, strtok_r(NULL, " ", &saveptr), sizeof(wg->name));
            wg->max--;

            /* Reset value. */
            wg->value = 0;

            /* We got one more widget. */
            wg++;
            widgets++;
        }
        else if((strstr(line, "bng") != NULL) &&
                (strstr(line, "pod_") != NULL))
        {
            wg->id = PD_BANG;

            strtok_r(line, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            wg->x = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->y = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            strtok_r(NULL, " ", &saveptr);
            wg->w = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->h = wg->w;
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            strncpy(wg->name, strtok_r(NULL, " ", &saveptr), sizeof(wg->name));
            wg->min = 0;
            wg->max = 1;

            /* Reset value. */
            wg->value = 0;

            /* Clear timeout flag. */
            wg->timeout = 0;

            /* We got one more widget. */
            wg++;
            widgets++;
        }
        else if(strstr(line, "text") != NULL)
        {
            wg->id = PD_TEXT;

            strtok_r(line, " ", &saveptr);
            strtok_r(NULL, " ", &saveptr);
            wg->x = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            wg->y = atoi(strtok_r(NULL, " ", &saveptr)) * screen_multiplier;
            strncpy(wg->name, strtok_r(NULL, " ", &saveptr), sizeof(wg->name));
            char* w = strtok_r(NULL, " ", &saveptr);
            while(w != NULL)
            {
                strcat(wg->name, w);
                strcat(wg->name, " ");
                w = strtok_r(NULL, " ", &saveptr);
            }
            /* Cut off unneeded characters (';' and '\n'). */
            int namelen = strlen(wg->name);
            if(namelen > 1)
            {
                /* Cut off '\n'. */
                wg->name[namelen-1] = '\0';
                namelen--;
                /* Cut the last semi-colon, if there is one. */
                if(wg->name[namelen-1] == ';')
                    wg->name[namelen-1] = '\0';
            }


            /* We got one more widget. */
            wg++;
            widgets++;
        }
    }

    /* Close PD patch. */
    close(fd);

    /* Return amount of loaded widgets. */
    return widgets;
}

/* Draw standard user interface. */
void pd_gui_draw_standard(void)
{
    /* Draw main circle. */
    rb->lcd_set_foreground(fgcolor);
    fillcircle(LCD_WIDTH / 2,
               LCD_HEIGHT / 2,
               2 * MIN(LCD_WIDTH, LCD_HEIGHT) / 5);

    /* Draw center circle. */
    rb->lcd_set_foreground(action_on ? BTNCOLOR_DARK : BTNCOLOR_LIGHT);
    fillcircle(LCD_WIDTH / 2,
               LCD_HEIGHT / 2,
               MIN(LCD_WIDTH, LCD_HEIGHT) / 8);

    /* Draw pressed buttons. */
    if(play_on)
        fillcircle(LCD_WIDTH / 2,
                   3 * LCD_HEIGHT / 4,
                   MIN(LCD_WIDTH, LCD_HEIGHT) / 8);

    if(previous_on)
        fillcircle(LCD_WIDTH / 3,
                   LCD_HEIGHT / 2,
                   MIN(LCD_WIDTH, LCD_HEIGHT) / 8);

    if(next_on)
        fillcircle(2 * LCD_WIDTH / 3 + 1,
                   LCD_HEIGHT / 2,
                   MIN(LCD_WIDTH, LCD_HEIGHT) / 8);

    if(menu_on)
        fillcircle(LCD_WIDTH / 2,
                   LCD_HEIGHT / 4,
                   MIN(LCD_WIDTH, LCD_HEIGHT) / 8);

    /* Restore foreground color. */
    rb->lcd_set_foreground(fgcolor);
}

/* Draw custom user interface. */
void pd_gui_draw_custom(struct pd_widget* wg, unsigned int widgets)
{
    unsigned int i;
    int j;
    int v;

    for(i = 0; i < widgets; wg++, i++)
    {
        switch(wg->id)
        {
            case PD_BANG:
                /* Clear area to (re-)draw. */
                rb->lcd_set_foreground(bgcolor);
                rb->lcd_fillrect(wg->x, wg->y, wg->w, wg->h);
                rb->lcd_set_foreground(fgcolor);
                /* Draw border (rectangle). */
                rb->lcd_drawrect(wg->x, wg->y, wg->w, wg->h);
                /* Draw button (circle), being filled depending on value. */
                if(((int) wg->value) == 0) /* Button not pressed. */
                    drawcircle(wg->x + wg->w/2,
                               wg->y + wg->w/2,
                               wg->w/2 - 1);
                else /* Button pressed. */
                    fillcircle(wg->x + wg->w/2,
                               wg->y + wg->w/2,
                               wg->w/2 - 1);
                break;

            case PD_VSLIDER:
                /* Clear area to (re-)draw. */
                rb->lcd_set_foreground(bgcolor);
                rb->lcd_fillrect(wg->x, wg->y, wg->w, wg->h);
                rb->lcd_set_foreground(fgcolor);
                /* Draw border. */
                rb->lcd_drawrect(wg->x, wg->y, wg->w, wg->h);
                /* Draw slider. */
                v = ((float) wg->h / (wg->max - wg->min)) *
                    (wg->max - wg->value);
                rb->lcd_fillrect(wg->x, wg->y + v, wg->w, 2);
                break;

            case PD_HSLIDER:
                /* Clear area to (re-)draw. */
                rb->lcd_set_foreground(bgcolor);
                rb->lcd_fillrect(wg->x, wg->y, wg->w, wg->h);
                rb->lcd_set_foreground(fgcolor);
                /* Draw border. */
                rb->lcd_drawrect(wg->x, wg->y, wg->w, wg->h);
                /* Draw slider. */
                v = ((float) wg->w / (wg->max - wg->min)) *
                    (wg->max - wg->value);
                rb->lcd_fillrect(wg->x + wg->w - v, wg->y, 2, wg->h);
                break;

            case PD_HRADIO:
                /* Clear area to (re-)draw. */
                rb->lcd_set_foreground(bgcolor);
                rb->lcd_fillrect(wg->x, wg->y, wg->w, wg->h);
                rb->lcd_set_foreground(fgcolor);
                for(j = 0; j < wg->w / wg->h; j++)
                {
                    /* Draw border. */
                    rb->lcd_drawrect(wg->x + wg->h * j, wg->y, wg->h, wg->h);
                    /* If marked, draw button. */
                    if(((int) wg->value) == j)
                        rb->lcd_fillrect(wg->x + wg->h * j + 2, wg->y + 2,
                                         wg->h - 4, wg->h - 4);
                }
                break;

            case PD_VRADIO:
                /* Clear area to (re-)draw. */
                rb->lcd_set_foreground(bgcolor);
                rb->lcd_fillrect(wg->x, wg->y, wg->w, wg->h);
                rb->lcd_set_foreground(fgcolor);
                for(j = 0; j < wg->h / wg->w; j++)
                {
                    /* Draw border. */
                    rb->lcd_drawrect(wg->x, wg->y + wg->w * j, wg->w, wg->w);
                    /* If marked, draw button. */
                    if(((int) wg->value) == j)
                        rb->lcd_fillrect(wg->x + 2, wg->y + wg->w * j + 2,
                                         wg->w - 4, wg->w - 4);
                }
                break;

            case PD_NUMBER: