diff --git a/src/zlfo_ui.c b/src/zlfo_ui.c index 5283547..0a63279 100644 --- a/src/zlfo_ui.c +++ b/src/zlfo_ui.c @@ -1012,108 +1012,14 @@ add_bot_buttons ( self->app, (ZtkWidget *) control, 2); } +/** + * Draws the graphs in curve mode. + */ static void -mid_region_bg_draw_cb ( - ZtkWidget * widget, - cairo_t * cr, - ZLfoUi * self) +draw_graph_curves ( + ZLfoUi * self, + cairo_t * cr) { - /* set background */ - zlfo_ui_theme_set_cr_color (cr, selected_bg); - cairo_rectangle ( - cr, widget->rect.x, widget->rect.y, - widget->rect.width, widget->rect.height); - cairo_fill (cr); - - /* draw grid */ - for (int i = 0; i < 9; i++) - { - if ((i % 4) == 0) - { - zlfo_ui_theme_set_cr_color ( - cr, grid_strong); - } - else - { - zlfo_ui_theme_set_cr_color ( - cr, grid); - } - cairo_move_to ( - cr, - widget->rect.x + GRID_HPADDING + - i * GRID_SPACE, - widget->rect.y + GRID_YSTART_OFFSET); - cairo_line_to ( - cr, - widget->rect.x + GRID_HPADDING + - i * GRID_SPACE, - widget->rect.y + GRID_YEND_OFFSET); - cairo_stroke (cr); - } - zlfo_ui_theme_set_cr_color ( - cr, grid_strong); - cairo_move_to ( - cr, - GRID_XSTART_GLOBAL, - widget->rect.y + 105); - cairo_line_to ( - cr, - GRID_XEND_GLOBAL, - widget->rect.y + 105); - cairo_stroke (cr); - -/*#if 0*/ - /* draw current position */ - double total_space = GRID_WIDTH; - double current_offset = - (double) self->common.current_sample / - (double) self->common.period_size; -#if 0 - ztk_message ( - "current_sample %ld, period size %ld", - self->current_sample, self->period_size); -#endif - cairo_move_to ( - cr, - widget->rect.x + GRID_HPADDING + - current_offset * total_space, - widget->rect.y + 46); - cairo_line_to ( - cr, - widget->rect.x + GRID_HPADDING + - current_offset * total_space, - widget->rect.y + 164); - cairo_stroke (cr); -/*#endif*/ - - float sync_rate_float = - sync_rate_to_float ( - self->sync_rate, - self->sync_rate_type); - - /** - * Effective frequency. - * - * This is either the free-running frequency, - * or the frequency corresponding to the current - * sync rate. - */ - float effective_freq = - get_effective_freq ( - self->freerun, self->freq, - &self->common.host_pos, sync_rate_float); - - recalc_vars ( - self->freerun, - &self->common.sine_multiplier, - &self->common.saw_multiplier, - &self->common.period_size, - &self->common.current_sample, - &self->common.host_pos, effective_freq, - sync_rate_float, - (float) self->common.samplerate); - - /* draw other visible waves in the back */ double max_range = MAX (self->range_max, self->range_min); double min_range = @@ -1123,8 +1029,12 @@ mid_region_bg_draw_cb ( cairo_set_source_rgba ( cr, zlfo_ui_theme.line.red, zlfo_ui_theme.line.green, - zlfo_ui_theme.line.blue, 0.3); - cairo_set_line_width (cr, 3); + zlfo_ui_theme.line.blue, 1); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_width (cr, 6); + double prev_draw_sine, + prev_draw_triangle, + prev_draw_saw, prev_draw_square; for (int i = 0; i < GRID_WIDTH; i++) { /* from 0 to GRID_WIDTH */ @@ -1191,18 +1101,22 @@ mid_region_bg_draw_cb ( * in cairo */ \ draw_val = GRID_HEIGHT - draw_val; \ \ - /* draw line */ \ - cairo_move_to ( \ - cr, \ - widget->rect.x + GRID_HPADDING + i, \ - widget->rect.y + GRID_YSTART_OFFSET + \ - draw_val); \ - cairo_line_to ( \ - cr, \ - widget->rect.x + GRID_HPADDING + i + 1, \ - widget->rect.y + GRID_YSTART_OFFSET + \ - draw_val + 1); \ - cairo_stroke (cr) + if (i != 0) \ + { \ + /* draw line */ \ + cairo_move_to ( \ + cr, \ + GRID_XSTART_GLOBAL + i - 1, \ + GRID_YSTART_GLOBAL + \ + prev_draw_##val); \ + cairo_line_to ( \ + cr, \ + GRID_XSTART_GLOBAL + i, \ + GRID_YSTART_GLOBAL + \ + draw_val); \ + cairo_stroke (cr); \ + } \ + prev_draw_##val = draw_val /* calculate sine */ double sine = @@ -1274,6 +1188,117 @@ mid_region_bg_draw_cb ( } } +static void +mid_region_bg_draw_cb ( + ZtkWidget * widget, + cairo_t * cr, + ZLfoUi * self) +{ + /* set background */ + zlfo_ui_theme_set_cr_color (cr, selected_bg); + cairo_rectangle ( + cr, widget->rect.x, widget->rect.y, + widget->rect.width, widget->rect.height); + cairo_fill (cr); + + /* draw grid */ + for (int i = 0; i < 9; i++) + { + if ((i % 4) == 0) + { + zlfo_ui_theme_set_cr_color ( + cr, grid_strong); + } + else + { + zlfo_ui_theme_set_cr_color ( + cr, grid); + } + cairo_move_to ( + cr, + widget->rect.x + GRID_HPADDING + + i * GRID_SPACE, + widget->rect.y + GRID_YSTART_OFFSET); + cairo_line_to ( + cr, + widget->rect.x + GRID_HPADDING + + i * GRID_SPACE, + widget->rect.y + GRID_YEND_OFFSET); + cairo_stroke (cr); + } + zlfo_ui_theme_set_cr_color ( + cr, grid_strong); + cairo_move_to ( + cr, + GRID_XSTART_GLOBAL, + widget->rect.y + 105); + cairo_line_to ( + cr, + GRID_XEND_GLOBAL, + widget->rect.y + 105); + cairo_stroke (cr); + +/*#if 0*/ + /* draw current position */ + double total_space = GRID_WIDTH; + double current_offset = + (double) self->common.current_sample / + (double) self->common.period_size; +#if 0 + ztk_message ( + "current_sample %ld, period size %ld", + self->current_sample, self->period_size); +#endif + cairo_move_to ( + cr, + widget->rect.x + GRID_HPADDING + + current_offset * total_space, + widget->rect.y + 46); + cairo_line_to ( + cr, + widget->rect.x + GRID_HPADDING + + current_offset * total_space, + widget->rect.y + 164); + cairo_stroke (cr); +/*#endif*/ + + float sync_rate_float = + sync_rate_to_float ( + self->sync_rate, + self->sync_rate_type); + + /** + * Effective frequency. + * + * This is either the free-running frequency, + * or the frequency corresponding to the current + * sync rate. + */ + float effective_freq = + get_effective_freq ( + self->freerun, self->freq, + &self->common.host_pos, sync_rate_float); + + recalc_vars ( + self->freerun, + &self->common.sine_multiplier, + &self->common.saw_multiplier, + &self->common.period_size, + &self->common.current_sample, + &self->common.host_pos, effective_freq, + sync_rate_float, + (float) self->common.samplerate); + + /* draw other visible waves in the back */ + if (self->step_mode) + { + } + else + { + draw_graph_curves (self, cr); + } +} + static void mid_region_bg_update_cb ( ZtkWidget * w, @@ -1875,13 +1900,13 @@ add_grid_controls ( case GRID_BTN_HMIRROR: rect.x = start + padding + width + padding + - 68; + 69; rect.width = 40; break; case GRID_BTN_VMIRROR: rect.x = start + padding + width + padding + - 110; + 111; rect.width = 40; break; default: