Date:2013-02-01 16:29:24 (6 years 4 months ago)
Author:Werner Almesberger
Commit:aa1106e120d2f84bb251e24817ba49ef5a16be49
Message:ubb-la/gui.c: Shift+Left/Right jumps "intelligently" to next change on any channel

Files: ubb-la/README (1 diff)
ubb-la/gui.c (4 diffs)

Change Details

ubb-la/README
8282
8383In the GUI, the following keys are available:
8484
85  Left/Right Pan the waveform left/right
85  Left/Right Pan the waveform left/right. With Shift, jump to the
86        next change on any channel in the specified direction.
8687  Up/Down Zoom in/out
8788  Space Set the user origin (upward-facing green triangle)
8889        at the current position and display the time to
ubb-la/gui.c
485485}
486486
487487
488static int smart_pos(const uint8_t *buf, int skip, int nibbles,
489    int pos, int dir)
490{
491    uint8_t ref;
492
493    if (dir < 0) {
494        if (!pos)
495            return pos;
496        ref = get_sample(buf, skip+pos-1);
497    } else {
498        ref = get_sample(buf, skip+pos);
499    }
500    do {
501        pos += dir;
502        if (pos < 0 || pos == nibbles-skip)
503            return pos-dir;
504    } while (get_sample(buf, skip+pos) == ref);
505    if (dir < 0)
506        pos++;
507    return pos;
508}
509
510
488511void gui(const uint8_t *buf, int skip, int nibbles, double freq)
489512{
490513    SDL_Event event;
491514    int pos = (skip+nibbles) >> 1;
492515    int zoom; /* < 0: zoom out; 0: 1 pixel = 1 sample; > 1: zoom in */
493516    int min_zoom = 0;
494    int i;
517    int i, shift;
495518
496519    while (XWIDTH < (nibbles-skip) >> -min_zoom)
497520        min_zoom--;
...... 
515538            SDL_WaitEvent(&event);
516539            switch (event.type) {
517540            case SDL_KEYDOWN:
541                shift = event.key.keysym.mod & KMOD_SHIFT;
518542                switch (event.key.keysym.sym) {
519543                case SDLK_UP:
520544                    if (zoom < MAX_ZOOM)
...... 
525549                        zoom--;
526550                    break;
527551                case SDLK_LEFT:
528                    pos -= pos_step(zoom);
529                    if (pos < 0)
530                        pos = 0;
552                    if (shift) {
553                        pos = smart_pos(buf,
554                            skip, nibbles, pos, -1);
555                    } else {
556                        pos -= pos_step(zoom);
557                        if (pos < 0)
558                            pos = 0;
559                    }
531560                    break;
532561                case SDLK_RIGHT:
533                    pos += pos_step(zoom);
534                    if (pos > nibbles-skip-1)
535                        pos = nibbles-skip-1;
562                    if (shift) {
563                        pos = smart_pos(buf,
564                            skip, nibbles, pos, 1);
565                    } else {
566                        pos += pos_step(zoom);
567                        if (pos > nibbles-skip-1)
568                            pos = nibbles-skip-1;
569                    }
536570                    break;
537571                case SDLK_SPACE:
538572                    if (pos == user_ref)
...... 
543577                case SDLK_RETURN:
544578                case SDLK_q:
545579                    return;
580                case SDLK_LSHIFT:
581                case SDLK_RSHIFT:
582                    continue;
546583                default:
547584                    printf("%x\n", event.key.keysym.sym);
548585                    continue;

Archive Download the corresponding diff file

Branches:
master



interactive