Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lingot-gui-gauge.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ gboolean lingot_gui_gauge_redraw(GtkWidget *w, cairo_t *cr, lingot_main_frame_t*

const double normalized_error = frame->gauge_pos / frame->conf.gauge_range;
const double angle = 2.0 * normalized_error * overtureAngle;

cairo_set_line_width(cr, gaugeStroke);
cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
lingot_gui_mainframe_cairo_set_source_argb(cr, gauge_gaugeShadowColor);
Expand Down
34 changes: 31 additions & 3 deletions src/lingot-gui-mainframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void lingot_gui_mainframe_callback_hide(GtkWidget* w, const lingot_main_frame_t*
ui_settings.win_width = win_width;
ui_settings.win_height = win_height;
ui_settings.spectrum_visible = gtk_check_menu_item_get_active(frame->view_spectrum_item);

ui_settings.gauge_visible = gtk_check_menu_item_get_active(frame->view_gauge_item);

ui_settings.horizontal_paned_pos = gtk_paned_get_position(frame->horizontal_paned);
Expand Down Expand Up @@ -162,6 +163,17 @@ void lingot_gui_mainframe_callback_view_spectrum(GtkWidget* w, lingot_main_frame
gtk_widget_set_visible(frame->spectrum_frame, visible);
}


void lingot_gui_mainframe_callback_view_deviation(GtkWidget* w, lingot_main_frame_t* frame) {
(void)w; // Unused parameter.
gboolean on = gtk_check_menu_item_get_active(frame->view_deviation_item);
if (on) {
gtk_widget_set_visible(frame->gauge_frame, 1);
} else {
gtk_widget_set_visible(frame->gauge_frame, 0);
}
}

void lingot_gui_mainframe_update_gauge_area_tooltip(lingot_main_frame_t* frame) {
gtk_widget_set_tooltip_text(frame->gauge_area,
gtk_check_menu_item_get_active(frame->view_gauge_item) ?
Expand All @@ -172,14 +184,18 @@ void lingot_gui_mainframe_update_gauge_area_tooltip(lingot_main_frame_t* frame)
void lingot_gui_mainframe_callback_view_gauge(GtkWidget* w, lingot_main_frame_t* frame) {
(void)w; // Unused parameter.
gboolean on = gtk_check_menu_item_get_active(frame->view_gauge_item);
gtk_check_menu_item_set_active(frame->view_strobe_disc_item, !on);
if (on) {
gtk_check_menu_item_set_active(frame->view_strobe_disc_item, 0);
}
lingot_gui_mainframe_update_gauge_area_tooltip(frame);
}

void lingot_gui_mainframe_callback_view_strobe_disc(GtkWidget* w, lingot_main_frame_t* frame) {
(void)w; // Unused parameter.
gboolean on = gtk_check_menu_item_get_active(frame->view_strobe_disc_item);
gtk_check_menu_item_set_active(frame->view_gauge_item, !on);
if (on) {
gtk_check_menu_item_set_active(frame->view_gauge_item, 0);
}
lingot_gui_mainframe_update_gauge_area_tooltip(frame);
}

Expand Down Expand Up @@ -409,9 +425,10 @@ gboolean lingot_gui_gauge_strobe_disc_redraw(GtkWidget *w, cairo_t *cr, lingot_m
// lingot_gui_mainframe_callback_show(w, frame);
if (gtk_check_menu_item_get_active(frame->view_gauge_item)) {
lingot_gui_gauge_redraw(w, cr, frame);
} else{
} else if (gtk_check_menu_item_get_active(frame->view_strobe_disc_item)){
lingot_gui_strobe_disc_redraw(w, cr, frame);
}

return FALSE;
}

Expand Down Expand Up @@ -514,8 +531,11 @@ lingot_main_frame_t* lingot_gui_mainframe_create() {
frame->error_label = GTK_LABEL(gtk_builder_get_object(builder, "error_label"));

frame->spectrum_frame = GTK_WIDGET(gtk_builder_get_object(builder, "spectrum_frame"));
frame->gauge_frame = GTK_WIDGET(gtk_builder_get_object(builder, "gauge_frame"));

frame->view_spectrum_item = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(builder, "spectrum_item"));
frame->view_gauge_item = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(builder, "gauge_item"));
frame->view_deviation_item = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(builder, "deviation_item"));
frame->view_strobe_disc_item = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(builder, "strobe_disc_item"));
frame->labelsbox = GTK_WIDGET(gtk_builder_get_object(builder, "labelsbox"));
frame->horizontal_paned = GTK_PANED(gtk_builder_get_object(builder, "horizontal_paned"));
Expand All @@ -532,12 +552,18 @@ lingot_main_frame_t* lingot_gui_mainframe_create() {
g_signal_connect(frame->view_spectrum_item,
"activate", G_CALLBACK(lingot_gui_mainframe_callback_view_spectrum),
frame);
g_signal_connect(frame->view_spectrum_item,
"activate", G_CALLBACK(lingot_gui_mainframe_callback_view_deviation),
frame);
g_signal_connect(frame->view_gauge_item,
"activate", G_CALLBACK(lingot_gui_mainframe_callback_view_gauge),
frame);
g_signal_connect(frame->view_strobe_disc_item,
"activate", G_CALLBACK(lingot_gui_mainframe_callback_view_strobe_disc),
frame);
g_signal_connect(frame->view_deviation_item,
"activate", G_CALLBACK(lingot_gui_mainframe_callback_view_deviation),
frame);
g_signal_connect(gtk_builder_get_object(builder, "open_config_item"),
"activate", G_CALLBACK(lingot_gui_mainframe_callback_open_config),
frame);
Expand All @@ -563,6 +589,8 @@ lingot_main_frame_t* lingot_gui_mainframe_create() {

gtk_check_menu_item_set_active(frame->view_spectrum_item, ui_settings.spectrum_visible);
gtk_check_menu_item_set_active(frame->view_gauge_item, ui_settings.gauge_visible);
gtk_check_menu_item_set_active(frame->view_deviation_item, ui_settings.deviation_visible);


if (ui_settings.win_width > 0) {
gtk_window_resize(frame->win, ui_settings.win_width, ui_settings.win_height);
Expand Down
8 changes: 8 additions & 0 deletions src/lingot-gui-mainframe.glade
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@
<property name="can-focus">False</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="deviation_item">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Show Deviation</property>
<property name="active">True</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="spectrum_item">
<property name="visible">True</property>
Expand Down
2 changes: 2 additions & 0 deletions src/lingot-gui-mainframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ typedef struct _lingot_main_frame_t {
GtkCheckMenuItem* view_spectrum_item;
GtkCheckMenuItem* view_gauge_item;
GtkCheckMenuItem* view_strobe_disc_item;
GtkCheckMenuItem* view_deviation_item;
GtkWidget* gauge_frame;
GtkWidget* spectrum_frame;

GtkWidget* labelsbox;
Expand Down
67 changes: 52 additions & 15 deletions src/lingot-gui-spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,24 @@ static LINGOT_FLT lingot_gui_spectrum_get_in_bounds(LINGOT_FLT value, LINGOT_FLT
return value - min;
}

static void lingot_gui_spectrum_redraw_background(cairo_t *cr, lingot_main_frame_t *frame) {
static void lingot_gui_spectrum_redraw_background(cairo_t *cr, lingot_main_frame_t *frame, LINGOT_FLT spectrum_margin_percent) {

// graph doesn't display current or closest tone line on min and max, so add margins
LINGOT_FLT spectrum_frequency_margin = (frame->conf.max_frequency-frame->conf.min_frequency) *
spectrum_margin_percent;
LINGOT_FLT spectrum_max_frequency = frame->conf.max_frequency + spectrum_frequency_margin;

LINGOT_FLT spectrum_min_frequency;
if (frame->conf.min_frequency - spectrum_frequency_margin < 0) {
spectrum_min_frequency = 0;
} else {
spectrum_min_frequency = frame->conf.min_frequency - spectrum_frequency_margin;
}

LINGOT_FLT spectrum_width = spectrum_max_frequency - spectrum_min_frequency; //Hz
//defines graph zoom level
LINGOT_FLT spectrum_scaling_factor = spectrum_width / (0.5 * frame->conf.sample_rate
/ frame->conf.oversampling);

const LINGOT_FLT font_size = 8 + spectrum_size_y / 30;

Expand Down Expand Up @@ -122,27 +139,27 @@ static void lingot_gui_spectrum_redraw_background(cairo_t *cr, lingot_main_frame
cairo_rel_line_to(cr, spectrum_inner_x, 0);
cairo_stroke(cr);

// choose scale factor
const LINGOT_FLT spectrum_max_frequency = 0.5 * frame->conf.sample_rate
/ frame->conf.oversampling;
const LINGOT_FLT spectrum_inner_max = 0.5 * frame->conf.sample_rate
/ frame->conf.oversampling * spectrum_scaling_factor;

// scale factors (in KHz) to draw the grid. We will choose the smaller
// factor that respects the minimum_grid_width
static const double scales[] = { 0.01, 0.05, 0.1, 0.2, 0.5, 1, 2, 4, 11, 22, -1.0 };

int i;
for (i = 0; scales[i + 1] > 0.0; i++) {
if ((1e3 * scales[i] * spectrum_inner_x / spectrum_max_frequency)
if ((1e3 * scales[i] * spectrum_inner_x / spectrum_inner_max)
> minimum_grid_width)
break;
}

LINGOT_FLT scale = scales[i];
LINGOT_FLT grid_width = 1e3 * scales[i] * spectrum_inner_x
/ spectrum_max_frequency;
/ spectrum_inner_max;

LINGOT_FLT freq = 0.0;
LINGOT_FLT freq = spectrum_min_frequency/1000;
LINGOT_FLT x;

for (x = 0.0; x <= spectrum_inner_x; x += grid_width) {
cairo_move_to(cr, spectrum_left_margin + x, spectrum_top_margin);
cairo_rel_line_to(cr, 0, spectrum_inner_y + 3); // TODO: proportion
Expand Down Expand Up @@ -208,6 +225,23 @@ static void lingot_gui_spectrum_redraw_background(cairo_t *cr, lingot_main_frame

gboolean lingot_gui_spectrum_redraw(GtkWidget *w, cairo_t *cr, lingot_main_frame_t* frame) {

// graph doesn't display current or closest tone line on min and max, so add margins
LINGOT_FLT spectrum_margin_percent = 0.05;
LINGOT_FLT spectrum_frequency_margin = (frame->conf.max_frequency-frame->conf.min_frequency) *
spectrum_margin_percent;
LINGOT_FLT spectrum_max_frequency = frame->conf.max_frequency + spectrum_frequency_margin;
LINGOT_FLT spectrum_min_frequency;
if (frame->conf.min_frequency - spectrum_frequency_margin < 0) {
spectrum_min_frequency = 0;
} else {
spectrum_min_frequency = frame->conf.min_frequency - spectrum_frequency_margin;
}

LINGOT_FLT spectrum_width = spectrum_max_frequency - spectrum_min_frequency; //Hz
//defines graph zoom level
LINGOT_FLT spectrum_scaling_factor = spectrum_width / (0.5 * frame->conf.sample_rate
/ frame->conf.oversampling);

unsigned int i;

GtkAllocation req;
Expand All @@ -217,7 +251,7 @@ gboolean lingot_gui_spectrum_redraw(GtkWidget *w, cairo_t *cr, lingot_main_frame
spectrum_size_y = req.height;
}

lingot_gui_spectrum_redraw_background(cr, frame);
lingot_gui_spectrum_redraw_background(cr, frame, spectrum_margin_percent);

// spectrum drawing.
if (lingot_core_thread_is_running(&frame->core)) {
Expand All @@ -228,8 +262,9 @@ gboolean lingot_gui_spectrum_redraw(GtkWidget *w, cairo_t *cr, lingot_main_frame
LINGOT_FLT x;
LINGOT_FLT y = -1;

const unsigned int min_index = 0;
const unsigned int max_index = frame->conf.fft_size / 2;

const unsigned int max_index = frame->conf.fft_size /2 * spectrum_scaling_factor;
const unsigned int min_index = max_index/spectrum_width * spectrum_min_frequency;

LINGOT_FLT index_density = spectrum_inner_x / max_index;
// TODO: step
Expand Down Expand Up @@ -265,13 +300,14 @@ gboolean lingot_gui_spectrum_redraw(GtkWidget *w, cairo_t *cr, lingot_main_frame
spectrum_min_db, spectrum_max_db);
LINGOT_FLT ym1 = y;

//draw curve
for (i = index_step; i < max_index - 1; i += index_step) {

x = index_density * i;
ym1 = y;
y = yp1;
yp1 = -spectrum_db_density
* lingot_gui_spectrum_get_in_bounds(spd[i + 1],
* lingot_gui_spectrum_get_in_bounds(spd[i + min_index + 1],
spectrum_min_db, spectrum_max_db);
LINGOT_FLT dydx = (yp1 - ym1) / (2 * index_density);
static const LINGOT_FLT dx = 0.4;
Expand Down Expand Up @@ -309,8 +345,9 @@ gboolean lingot_gui_spectrum_redraw(GtkWidget *w, cairo_t *cr, lingot_main_frame
cairo_set_line_width(cr, 1.0);

// index of closest sample to fundamental frequency.
x = index_density * target_freq * frame->conf.fft_size
* frame->conf.oversampling / frame->conf.sample_rate;
x = (index_density * (target_freq - spectrum_min_frequency)* frame->conf.fft_size
* frame->conf.oversampling / frame->conf.sample_rate);

cairo_move_to(cr, x, 0);
cairo_rel_line_to(cr, 0.0, -spectrum_inner_y);
cairo_stroke(cr);
Expand All @@ -324,8 +361,8 @@ gboolean lingot_gui_spectrum_redraw(GtkWidget *w, cairo_t *cr, lingot_main_frame
cairo_set_line_width(cr, 2.0);

// index of closest sample to fundamental frequency.
x = index_density * freq * frame->conf.fft_size
* frame->conf.oversampling / frame->conf.sample_rate;
x = (index_density * (freq - spectrum_min_frequency) * frame->conf.fft_size
* frame->conf.oversampling / frame->conf.sample_rate) ;
cairo_move_to(cr, x, 0);
cairo_rel_line_to(cr, 0.0, -spectrum_inner_y);
cairo_stroke(cr);
Expand Down
1 change: 1 addition & 0 deletions src/lingot-io-ui-settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ typedef struct {
// visible / invisible widgets
int spectrum_visible;
int gauge_visible;
int deviation_visible;

// position and size of main window
int win_width;
Expand Down