gr-fosphor: Update to fosphor new 'render options' model and add zoom
Note that the d_zoom_* vars are kept as double to avoid error build-up when changing them a lot from the UI. Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
parent
affd1a3eb7
commit
351af1f7e5
|
@ -46,6 +46,13 @@ namespace gr {
|
|||
DB_PER_DIV_DOWN,
|
||||
REF_UP,
|
||||
REF_DOWN,
|
||||
ZOOM_TOGGLE,
|
||||
ZOOM_WIDTH_UP,
|
||||
ZOOM_WIDTH_DOWN,
|
||||
ZOOM_CENTER_UP,
|
||||
ZOOM_CENTER_DOWN,
|
||||
RATIO_UP,
|
||||
RATIO_DOWN,
|
||||
};
|
||||
|
||||
virtual void execute_ui_action(enum ui_action_t action) = 0;
|
||||
|
|
|
@ -74,6 +74,27 @@ QGLSurface::keyPressEvent(QKeyEvent *ke)
|
|||
case Qt::Key_Right:
|
||||
this->d_block->execute_ui_action(qt_sink_c_impl::DB_PER_DIV_UP);
|
||||
break;
|
||||
case Qt::Key_Z:
|
||||
this->d_block->execute_ui_action(qt_sink_c_impl::ZOOM_TOGGLE);
|
||||
break;
|
||||
case Qt::Key_W:
|
||||
this->d_block->execute_ui_action(qt_sink_c_impl::ZOOM_WIDTH_UP);
|
||||
break;
|
||||
case Qt::Key_S:
|
||||
this->d_block->execute_ui_action(qt_sink_c_impl::ZOOM_WIDTH_DOWN);
|
||||
break;
|
||||
case Qt::Key_D:
|
||||
this->d_block->execute_ui_action(qt_sink_c_impl::ZOOM_CENTER_UP);
|
||||
break;
|
||||
case Qt::Key_A:
|
||||
this->d_block->execute_ui_action(qt_sink_c_impl::ZOOM_CENTER_DOWN);
|
||||
break;
|
||||
case Qt::Key_Q:
|
||||
this->d_block->execute_ui_action(qt_sink_c_impl::RATIO_UP);
|
||||
break;
|
||||
case Qt::Key_E:
|
||||
this->d_block->execute_ui_action(qt_sink_c_impl::RATIO_DOWN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,15 +53,27 @@ const int base_sink_c_impl::k_db_per_div[] = {1, 2, 5, 10, 20};
|
|||
|
||||
|
||||
base_sink_c_impl::base_sink_c_impl()
|
||||
: d_db_ref(0), d_db_per_div_idx(3), d_active(false),
|
||||
: d_db_ref(0), d_db_per_div_idx(3),
|
||||
d_zoom_enabled(false), d_zoom_center(0.5), d_zoom_width(0.2),
|
||||
d_ratio(0.35f), d_active(false),
|
||||
d_frequency(), d_fft_window(gr::fft::window::WIN_BLACKMAN_hARRIS)
|
||||
{
|
||||
/* Init FIFO */
|
||||
this->d_fifo = new fifo(2 * 1024 * 1024);
|
||||
|
||||
/* Init render options */
|
||||
this->d_render_main = new fosphor_render();
|
||||
fosphor_render_defaults(this->d_render_main);
|
||||
|
||||
this->d_render_zoom = new fosphor_render();
|
||||
fosphor_render_defaults(this->d_render_zoom);
|
||||
this->d_render_zoom->options &= ~(FRO_LABEL_PWR | FRO_LABEL_TIME);
|
||||
}
|
||||
|
||||
base_sink_c_impl::~base_sink_c_impl()
|
||||
{
|
||||
delete this->d_render_zoom;
|
||||
delete this->d_render_main;
|
||||
delete this->d_fifo;
|
||||
}
|
||||
|
||||
|
@ -148,7 +160,10 @@ base_sink_c_impl::render(void)
|
|||
}
|
||||
|
||||
/* Draw */
|
||||
fosphor_draw(this->d_fosphor, this->d_width, this->d_height);
|
||||
fosphor_draw(this->d_fosphor, this->d_render_main);
|
||||
|
||||
if (this->d_zoom_enabled)
|
||||
fosphor_draw(this->d_fosphor, this->d_render_zoom);
|
||||
|
||||
/* Done, swap buffer */
|
||||
this->glctx_swap();
|
||||
|
@ -207,6 +222,43 @@ base_sink_c_impl::settings_apply(uint32_t settings)
|
|||
gr::fft::window::build(this->d_fft_window, 1024, 6.76);
|
||||
fosphor_set_fft_window(this->d_fosphor, window.data());
|
||||
}
|
||||
|
||||
if (settings & (SETTING_DIMENSIONS | SETTING_RENDER_OPTIONS))
|
||||
{
|
||||
float f;
|
||||
|
||||
if (this->d_zoom_enabled) {
|
||||
int a = (int)(this->d_width * 0.65f);
|
||||
this->d_render_main->width = a;
|
||||
this->d_render_main->options |= FRO_CHANNELS;
|
||||
this->d_render_zoom->pos_x = a - 10;
|
||||
this->d_render_zoom->width = this->d_width - a + 10;
|
||||
} else {
|
||||
this->d_render_main->width = this->d_width;
|
||||
this->d_render_main->options &= ~FRO_CHANNELS;
|
||||
}
|
||||
|
||||
this->d_render_main->height = this->d_height;
|
||||
this->d_render_zoom->height = this->d_height;
|
||||
|
||||
this->d_render_main->histo_wf_ratio = this->d_ratio;
|
||||
this->d_render_zoom->histo_wf_ratio = this->d_ratio;
|
||||
|
||||
this->d_render_main->channels[0].enabled = this->d_zoom_enabled;
|
||||
this->d_render_main->channels[0].center = (float)this->d_zoom_center;
|
||||
this->d_render_main->channels[0].width = (float)this->d_zoom_width;
|
||||
|
||||
f = (float)(this->d_zoom_center - this->d_zoom_width / 2.0);
|
||||
this->d_render_zoom->freq_start =
|
||||
f > 0.0f ? (f < 1.0f ? f : 1.0f) : 0.0f;
|
||||
|
||||
f = (float)(this->d_zoom_center + this->d_zoom_width / 2.0);
|
||||
this->d_render_zoom->freq_stop =
|
||||
f > 0.0f ? (f < 1.0f ? f : 1.0f) : 0.0f;
|
||||
|
||||
fosphor_render_refresh(this->d_render_main);
|
||||
fosphor_render_refresh(this->d_render_zoom);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -240,9 +292,46 @@ base_sink_c_impl::execute_ui_action(enum ui_action_t action)
|
|||
case REF_DOWN:
|
||||
this->d_db_ref -= k_db_per_div[this->d_db_per_div_idx];
|
||||
break;
|
||||
|
||||
case ZOOM_TOGGLE:
|
||||
this->d_zoom_enabled ^= 1;
|
||||
break;
|
||||
|
||||
case ZOOM_WIDTH_UP:
|
||||
if (this->d_zoom_enabled)
|
||||
this->d_zoom_width *= 2.0;
|
||||
break;
|
||||
|
||||
case ZOOM_WIDTH_DOWN:
|
||||
if (this->d_zoom_enabled)
|
||||
this->d_zoom_width /= 2.0;
|
||||
break;
|
||||
|
||||
case ZOOM_CENTER_UP:
|
||||
if (this->d_zoom_enabled)
|
||||
this->d_zoom_center += this->d_zoom_width / 8.0;
|
||||
break;
|
||||
|
||||
case ZOOM_CENTER_DOWN:
|
||||
if (this->d_zoom_enabled)
|
||||
this->d_zoom_center -= this->d_zoom_width / 8.0;
|
||||
break;
|
||||
|
||||
case RATIO_UP:
|
||||
if (this->d_ratio < 0.8f)
|
||||
this->d_ratio += 0.05f;
|
||||
break;
|
||||
|
||||
case RATIO_DOWN:
|
||||
if (this->d_ratio > 0.2f)
|
||||
this->d_ratio -= 0.05f;
|
||||
break;
|
||||
}
|
||||
|
||||
this->settings_mark_changed(SETTING_POWER_RANGE);
|
||||
this->settings_mark_changed(
|
||||
SETTING_POWER_RANGE |
|
||||
SETTING_RENDER_OPTIONS
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <gnuradio/fosphor/base_sink_c.h>
|
||||
|
||||
struct fosphor;
|
||||
struct fosphor_render;
|
||||
|
||||
namespace gr {
|
||||
namespace fosphor {
|
||||
|
@ -53,6 +54,8 @@ namespace gr {
|
|||
fifo *d_fifo;
|
||||
|
||||
struct fosphor *d_fosphor;
|
||||
struct fosphor_render *d_render_main;
|
||||
struct fosphor_render *d_render_zoom;
|
||||
|
||||
void render();
|
||||
|
||||
|
@ -62,6 +65,7 @@ namespace gr {
|
|||
SETTING_POWER_RANGE = (1 << 1),
|
||||
SETTING_FREQUENCY_RANGE = (1 << 2),
|
||||
SETTING_FFT_WINDOW = (1 << 3),
|
||||
SETTING_RENDER_OPTIONS = (1 << 4),
|
||||
};
|
||||
|
||||
uint32_t d_settings_changed;
|
||||
|
@ -79,6 +83,12 @@ namespace gr {
|
|||
int d_db_ref;
|
||||
int d_db_per_div_idx;
|
||||
|
||||
bool d_zoom_enabled;
|
||||
double d_zoom_center;
|
||||
double d_zoom_width;
|
||||
|
||||
float d_ratio;
|
||||
|
||||
struct {
|
||||
double center;
|
||||
double span;
|
||||
|
|
|
@ -66,19 +66,47 @@ glfw_sink_c_impl::glfw_cb_key(int key, int scancode, int action, int mods)
|
|||
break;
|
||||
|
||||
case GLFW_KEY_UP:
|
||||
this->base_sink_c_impl::execute_ui_action(REF_DOWN);
|
||||
this->execute_ui_action(REF_DOWN);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_DOWN:
|
||||
this->base_sink_c_impl::execute_ui_action(REF_UP);
|
||||
this->execute_ui_action(REF_UP);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_LEFT:
|
||||
this->base_sink_c_impl::execute_ui_action(DB_PER_DIV_DOWN);
|
||||
this->execute_ui_action(DB_PER_DIV_DOWN);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_RIGHT:
|
||||
this->base_sink_c_impl::execute_ui_action(DB_PER_DIV_UP);
|
||||
this->execute_ui_action(DB_PER_DIV_UP);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_Z:
|
||||
this->execute_ui_action(ZOOM_TOGGLE);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_W:
|
||||
this->execute_ui_action(ZOOM_WIDTH_UP);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_S:
|
||||
this->execute_ui_action(ZOOM_WIDTH_DOWN);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_D:
|
||||
this->execute_ui_action(ZOOM_CENTER_UP);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_A:
|
||||
this->execute_ui_action(ZOOM_CENTER_DOWN);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_Q:
|
||||
this->execute_ui_action(RATIO_UP);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_E:
|
||||
this->execute_ui_action(RATIO_DOWN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,15 +64,24 @@ class wx_sink_c(gr.hier_block2):
|
|||
self.sink.pycb_reshape(*evt.GetSize())
|
||||
|
||||
def _evt_key_down(self, evt):
|
||||
actions = {
|
||||
wx.WXK_UP: base_sink_c.REF_DOWN,
|
||||
wx.WXK_DOWN: base_sink_c.REF_UP,
|
||||
wx.WXK_LEFT: base_sink_c.DB_PER_DIV_DOWN,
|
||||
wx.WXK_RIGHT: base_sink_c.DB_PER_DIV_UP,
|
||||
ord('Z'): base_sink_c.ZOOM_TOGGLE,
|
||||
ord('W'): base_sink_c.ZOOM_WIDTH_UP,
|
||||
ord('S'): base_sink_c.ZOOM_WIDTH_DOWN,
|
||||
ord('D'): base_sink_c.ZOOM_CENTER_UP,
|
||||
ord('A'): base_sink_c.ZOOM_CENTER_DOWN,
|
||||
ord('Q'): base_sink_c.RATIO_UP,
|
||||
ord('E'): base_sink_c.RATIO_DOWN,
|
||||
}
|
||||
|
||||
k = evt.GetKeyCode()
|
||||
if k == wx.WXK_UP:
|
||||
self.sink.execute_ui_action(base_sink_c.REF_DOWN)
|
||||
elif k == wx.WXK_DOWN:
|
||||
self.sink.execute_ui_action(base_sink_c.REF_UP)
|
||||
elif k == wx.WXK_LEFT:
|
||||
self.sink.execute_ui_action(base_sink_c.DB_PER_DIV_DOWN)
|
||||
elif k == wx.WXK_RIGHT:
|
||||
self.sink.execute_ui_action(base_sink_c.DB_PER_DIV_UP)
|
||||
|
||||
if k in actions:
|
||||
self.sink.execute_ui_action(actions[k])
|
||||
else:
|
||||
evt.Skip()
|
||||
|
||||
|
|
Loading…
Reference in New Issue