mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-23 21:14:04 +02:00
ubb-la/gui.c: Shift+Left/Right jumps "intelligently" to next change on any channel
This commit is contained in:
parent
47e5859c5b
commit
aa1106e120
@ -82,7 +82,8 @@ command line. Example:
|
|||||||
|
|
||||||
In the GUI, the following keys are available:
|
In the GUI, the following keys are available:
|
||||||
|
|
||||||
Left/Right Pan the waveform left/right
|
Left/Right Pan the waveform left/right. With Shift, jump to the
|
||||||
|
next change on any channel in the specified direction.
|
||||||
Up/Down Zoom in/out
|
Up/Down Zoom in/out
|
||||||
Space Set the user origin (upward-facing green triangle)
|
Space Set the user origin (upward-facing green triangle)
|
||||||
at the current position and display the time to
|
at the current position and display the time to
|
||||||
|
39
ubb-la/gui.c
39
ubb-la/gui.c
@ -485,13 +485,36 @@ static int pos_step(int zoom)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int smart_pos(const uint8_t *buf, int skip, int nibbles,
|
||||||
|
int pos, int dir)
|
||||||
|
{
|
||||||
|
uint8_t ref;
|
||||||
|
|
||||||
|
if (dir < 0) {
|
||||||
|
if (!pos)
|
||||||
|
return pos;
|
||||||
|
ref = get_sample(buf, skip+pos-1);
|
||||||
|
} else {
|
||||||
|
ref = get_sample(buf, skip+pos);
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
pos += dir;
|
||||||
|
if (pos < 0 || pos == nibbles-skip)
|
||||||
|
return pos-dir;
|
||||||
|
} while (get_sample(buf, skip+pos) == ref);
|
||||||
|
if (dir < 0)
|
||||||
|
pos++;
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void gui(const uint8_t *buf, int skip, int nibbles, double freq)
|
void gui(const uint8_t *buf, int skip, int nibbles, double freq)
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
int pos = (skip+nibbles) >> 1;
|
int pos = (skip+nibbles) >> 1;
|
||||||
int zoom; /* < 0: zoom out; 0: 1 pixel = 1 sample; > 1: zoom in */
|
int zoom; /* < 0: zoom out; 0: 1 pixel = 1 sample; > 1: zoom in */
|
||||||
int min_zoom = 0;
|
int min_zoom = 0;
|
||||||
int i;
|
int i, shift;
|
||||||
|
|
||||||
while (XWIDTH < (nibbles-skip) >> -min_zoom)
|
while (XWIDTH < (nibbles-skip) >> -min_zoom)
|
||||||
min_zoom--;
|
min_zoom--;
|
||||||
@ -515,6 +538,7 @@ void gui(const uint8_t *buf, int skip, int nibbles, double freq)
|
|||||||
SDL_WaitEvent(&event);
|
SDL_WaitEvent(&event);
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
|
shift = event.key.keysym.mod & KMOD_SHIFT;
|
||||||
switch (event.key.keysym.sym) {
|
switch (event.key.keysym.sym) {
|
||||||
case SDLK_UP:
|
case SDLK_UP:
|
||||||
if (zoom < MAX_ZOOM)
|
if (zoom < MAX_ZOOM)
|
||||||
@ -525,14 +549,24 @@ void gui(const uint8_t *buf, int skip, int nibbles, double freq)
|
|||||||
zoom--;
|
zoom--;
|
||||||
break;
|
break;
|
||||||
case SDLK_LEFT:
|
case SDLK_LEFT:
|
||||||
|
if (shift) {
|
||||||
|
pos = smart_pos(buf,
|
||||||
|
skip, nibbles, pos, -1);
|
||||||
|
} else {
|
||||||
pos -= pos_step(zoom);
|
pos -= pos_step(zoom);
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
pos = 0;
|
pos = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_RIGHT:
|
case SDLK_RIGHT:
|
||||||
|
if (shift) {
|
||||||
|
pos = smart_pos(buf,
|
||||||
|
skip, nibbles, pos, 1);
|
||||||
|
} else {
|
||||||
pos += pos_step(zoom);
|
pos += pos_step(zoom);
|
||||||
if (pos > nibbles-skip-1)
|
if (pos > nibbles-skip-1)
|
||||||
pos = nibbles-skip-1;
|
pos = nibbles-skip-1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_SPACE:
|
case SDLK_SPACE:
|
||||||
if (pos == user_ref)
|
if (pos == user_ref)
|
||||||
@ -543,6 +577,9 @@ void gui(const uint8_t *buf, int skip, int nibbles, double freq)
|
|||||||
case SDLK_RETURN:
|
case SDLK_RETURN:
|
||||||
case SDLK_q:
|
case SDLK_q:
|
||||||
return;
|
return;
|
||||||
|
case SDLK_LSHIFT:
|
||||||
|
case SDLK_RSHIFT:
|
||||||
|
continue;
|
||||||
default:
|
default:
|
||||||
printf("%x\n", event.key.keysym.sym);
|
printf("%x\n", event.key.keysym.sym);
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user