summaryrefslogtreecommitdiff
path: root/snd-genv.c
diff options
context:
space:
mode:
authorAlessio Treglia <alessio@debian.org>2010-09-22 11:13:01 +0200
committerAlessio Treglia <alessio@debian.org>2010-09-22 11:13:01 +0200
commit21c0acaad1b1fa3d17c911ff7e4ad05d63310195 (patch)
tree78c71c4b3e27b7e107e5023c67123a3cacc018de /snd-genv.c
parent6d99b2e313fc5878ab1ac115460f0e85595825a0 (diff)
Imported Upstream version 11.9
Diffstat (limited to 'snd-genv.c')
-rw-r--r--snd-genv.c181
1 files changed, 80 insertions, 101 deletions
diff --git a/snd-genv.c b/snd-genv.c
index db11f93..621ffc0 100644
--- a/snd-genv.c
+++ b/snd-genv.c
@@ -5,11 +5,11 @@
static GtkWidget *enved_dialog = NULL;
static GtkWidget *applyB, *apply2B, *cancelB, *drawer, *showB, *saveB, *resetB, *firB = NULL;
-static GtkWidget *revertB, *undoB, *redoB, *printB, *brktxtL, *brkpixL, *graphB, *fltB, *ampB, *srcB, *rbrow, *clipB, *deleteB;
+static GtkWidget *revertB, *undoB, *redoB, *printB, *brktxtL, *graphB, *fltB, *ampB, *srcB, *rbrow, *clipB, *deleteB;
static GtkWidget *nameL, *textL, *dBB, *orderL;
static GtkWidget *expB, *linB, *lerow, *baseScale, *baseLabel, *baseValue, *selectionB, *selrow, *revrow, *unrow, *saverow;
static GtkObject *baseAdj, *orderAdj;
-static gc_t *gc, *rgc, *ggc, *hgc;
+static gc_t *gc, *rgc, *ggc;
static slist *env_list = NULL;
static const char *env_names[3] = {N_("amp env:"), N_("flt env:"), N_("src env:")};
@@ -31,70 +31,46 @@ static bool FIR_p = true;
static bool old_clip_p = false;
static bool ignore_button_release = false;
-static axis_context *pix_ax = NULL;
+static cairo_t *enved_cr = NULL;
-static void fixup_axis_context(axis_context *ax, GtkWidget *w, gc_t *gc)
+static void fixup_graphics_context(graphics_context *ax, GtkWidget *w, gc_t *gc)
{
ax->wn = WIDGET_TO_WINDOW(w);
ax->w = w;
if (gc) ax->gc = gc;
+ ax->cr = enved_cr;
ax->current_font = AXIS_NUMBERS_FONT(ss);
}
-axis_info *enved_make_axis(const char *name, axis_context *ax,
+axis_info *enved_make_axis(const char *name, graphics_context *ax,
int ex0, int ey0, int width, int height,
mus_float_t xmin, mus_float_t xmax, mus_float_t ymin, mus_float_t ymax,
printing_t printing)
{
- /* conjure up minimal context for axis drawer in snd-axis.c */
- if (!axis)
- {
- axis = (axis_info *)calloc(1, sizeof(axis_info));
- axis->ax = (axis_context *)calloc(1, sizeof(axis_context));
- fixup_axis_context(axis->ax, drawer, ax->gc);
- }
- if (!gray_ap)
- {
- gray_ap = (axis_info *)calloc(1, sizeof(axis_info));
- gray_ap->ax = (axis_context *)calloc(1, sizeof(axis_context));
- gray_ap->graph_active = true;
- fixup_axis_context(gray_ap->ax, drawer, ggc);
- }
-#if USE_CAIRO
- axis->ax->cr = gdk_cairo_create(WIDGET_TO_WINDOW(drawer));
-#endif
init_env_axes(axis, name, ex0, ey0, width, height, xmin, xmax, ymin, ymax, printing);
-#if USE_CAIRO
- cairo_destroy(axis->ax->cr);
-#endif
return(axis);
}
static void display_env(env *e, const char *name, gc_t *cur_gc, int x0, int y0, int width, int height, bool dots, printing_t printing)
{
- axis_context *ax = NULL;
- ax = (axis_context *)calloc(1, sizeof(axis_context));
- ax->wn = WIDGET_TO_WINDOW(drawer);
- ax->w = drawer;
- ax->gc = cur_gc;
-#if USE_CAIRO
- ax->cr = gdk_cairo_create(WIDGET_TO_WINDOW(drawer));
-#endif
- ss->enved->with_dots = dots;
- env_editor_display_env(ss->enved, e, ax, name, x0, y0, width, height, printing);
-#if USE_CAIRO
- cairo_destroy(ax->cr);
-#endif
- free(ax);
+ if ((axis) && (enved_cr))
+ {
+ ss->enved->with_dots = dots;
+ axis->ax->gc = cur_gc;
+ env_editor_display_env(ss->enved, e, axis->ax, name, x0, y0, width, height, printing);
+ }
}
void display_enved_env_with_selection(env *e, const char *name, int x0, int y0, int width, int height, bool dots, printing_t printing)
{
+ cairo_push_group(enved_cr);
display_env(e, name, (selected_env == e) ? rgc : gc, x0, y0, width, height, dots, printing);
+ cairo_pop_group_to_source(enved_cr);
+ cairo_paint(enved_cr);
}
@@ -272,7 +248,7 @@ static void env_redisplay_1(printing_t printing)
{
if (enved_dialog_is_active())
{
- gdk_window_clear(WIDGET_TO_WINDOW(drawer));
+ /* gdk_window_clear(WIDGET_TO_WINDOW(drawer)); */ /* this cause flicker */
if (showing_all_envs)
view_envs(env_window_width, env_window_height, printing);
else
@@ -280,22 +256,44 @@ static void env_redisplay_1(printing_t printing)
char *name = NULL;
name = (char *)gtk_entry_get_text(GTK_ENTRY(textL));
if (!name) name = _("noname");
- if ((enved_wave_p(ss)) &&
- (active_channel) &&
- (!(active_channel->squelch_update)))
+
+ if ((axis) && (gray_ap))
{
-#if USE_CAIRO
- gray_ap->ax->cr = gdk_cairo_create(WIDGET_TO_WINDOW(drawer));
-#endif
- if ((enved_target(ss) == ENVED_SPECTRUM) && (active_env) && (FIR_p) && (printing == NOT_PRINTING))
- display_frequency_response(active_env, axis, gray_ap->ax, enved_filter_order(ss), enved_in_dB(ss));
- enved_show_background_waveform(axis, gray_ap, apply_to_selection, (enved_target(ss) == ENVED_SPECTRUM), printing);
-#if USE_CAIRO
- cairo_destroy(gray_ap->ax->cr);
-#endif
+ enved_cr = gdk_cairo_create(WIDGET_TO_WINDOW(drawer));
+
+ /* we have to create a new cairo_t each time, or the envelope is messed
+ * up after an expose event. I find this note in gdk/gdkcairo.c:
+ *
+ * "Note that due to double-buffering, Cairo contexts created
+ * in a GTK+ expose event handler cannot be cached and reused
+ * between different expose events."
+ */
+
+ axis->ax->cr = enved_cr;
+ gray_ap->ax->cr = enved_cr;
+ cairo_push_group(enved_cr);
+
+ /* erase previous */
+ cairo_set_source_rgb(enved_cr, gc->bg_color->red, gc->bg_color->green, gc->bg_color->blue);
+ cairo_rectangle(enved_cr, axis->graph_x0, axis->y_offset, axis->width, axis->height);
+ cairo_fill(enved_cr);
+
+ if ((enved_wave_p(ss)) &&
+ (active_channel) &&
+ (!(active_channel->squelch_update)))
+ {
+ if ((enved_target(ss) == ENVED_SPECTRUM) && (active_env) && (FIR_p) && (printing == NOT_PRINTING))
+ display_frequency_response(active_env, axis, gray_ap->ax, enved_filter_order(ss), enved_in_dB(ss));
+ enved_show_background_waveform(axis, gray_ap, apply_to_selection, (enved_target(ss) == ENVED_SPECTRUM), printing);
+ }
+
+ display_env(active_env, name, gc, 0, 0, env_window_width, env_window_height, true, printing);
+ name = NULL;
+
+ cairo_pop_group_to_source(enved_cr);
+ cairo_paint(enved_cr);
+ cairo_destroy(enved_cr);
}
- display_env(active_env, name, gc, 0, 0, env_window_width, env_window_height, true, printing);
- name = NULL;
}
}
}
@@ -354,7 +352,8 @@ static void errors_to_genv_text(const char *msg, void *data)
static void text_field_activated(GtkWidget *w, gpointer context)
-{ /* might be breakpoints to load or an envelope name (<cr> in enved text field) */
+{
+ /* might be breakpoints to load or an envelope name (<cr> in enved text field) */
char *str = NULL;
str = (char *)gtk_entry_get_text(GTK_ENTRY(w));
if ((str) && (*str))
@@ -476,8 +475,6 @@ static void select_or_edit_env(int pos)
static void clear_point_label(void)
{
- if (pix_ax)
- fill_rectangle(pix_ax, 0, 4, 24, 24);
set_button_label(brktxtL, BLANK_LABEL);
}
@@ -493,20 +490,13 @@ static void enved_display_point_label(mus_float_t x, mus_float_t y)
}
-static gboolean brkpixL_expose(GtkWidget *w, GdkEventExpose *ev, gpointer data)
-{
- if (pix_ax)
- fill_rectangle(pix_ax, 0, 4, 24, 24);
- return(false);
-}
-
-
static gboolean drawer_button_motion(GtkWidget *w, GdkEventMotion *ev, gpointer data)
{
int evx, evy;
GdkModifierType state;
oclock_t motion_time = 0;
ignore_button_release = false;
+
if (BUTTON1_PRESSED(EVENT_STATE(ev)))
{
if (EVENT_IS_HINT(ev))
@@ -520,6 +510,7 @@ static gboolean drawer_button_motion(GtkWidget *w, GdkEventMotion *ev, gpointer
}
}
else return(false);
+
if (!showing_all_envs)
{
mus_float_t x, y;
@@ -527,6 +518,7 @@ static gboolean drawer_button_motion(GtkWidget *w, GdkEventMotion *ev, gpointer
enved_display_point_label(x, y);
env_redisplay();
}
+
return(false);
}
@@ -535,6 +527,7 @@ static gboolean drawer_button_press(GtkWidget *w, GdkEventButton *ev, gpointer d
{
ss->enved->down_time = EVENT_TIME(ev);
ss->enved->env_dragged = false;
+
if (showing_all_envs)
{
int pos;
@@ -809,17 +802,23 @@ static void make_base_label(mus_float_t bval)
{
char *sfs, *buf;
int i, len, scale_len;
+
len = (int)(enved_power(ss) * 4);
if (len < 32) len = 32;
+
sfs = (char *)calloc(len, sizeof(char));
mus_snprintf(sfs, len, "%.3f", bval);
+
scale_len = (int)(enved_power(ss) + 3);
if (scale_len < 32) scale_len = 32;
buf = (char *)calloc(scale_len, sizeof(char));
+
for (i = 0; i < scale_len - 1; i++) buf[i] = sfs[i];
gtk_label_set_text(GTK_LABEL(baseValue), buf);
+
free(sfs);
free(buf);
+
in_set_enved_base(bval);
if ((active_env) && (!(showing_all_envs)))
{
@@ -932,24 +931,20 @@ GtkWidget *create_envelope_editor(void)
gc_set_background(ggc, ss->sgx->white);
gc_set_foreground(ggc, ss->sgx->enved_waveform_color);
- hgc = gc_new(MAIN_WINDOW(ss)); /* progress pix next to break point label */
- gc_set_background(hgc, ss->sgx->basic_color);
- gc_set_foreground(hgc, ss->sgx->basic_color);
-
helpB = gtk_button_new_from_stock(GTK_STOCK_HELP);
- gtk_widget_set_name(helpB, "help_button");
+ gtk_widget_set_name(helpB, "dialog_button");
cancelB = sg_button_new_from_stock_with_label("Go Away", GTK_STOCK_QUIT);
- gtk_widget_set_name(cancelB, "quit_button");
+ gtk_widget_set_name(cancelB, "dialog_button");
applyB = gtk_button_new_from_stock(GTK_STOCK_APPLY);
- gtk_widget_set_name(applyB, "doit_button");
+ gtk_widget_set_name(applyB, "dialog_button");
apply2B = sg_button_new_from_stock_with_label(_("Undo&Apply"), GTK_STOCK_UNDO);
- gtk_widget_set_name(apply2B, "doit_again_button");
+ gtk_widget_set_name(apply2B, "dialog_button");
resetB = sg_button_new_from_stock_with_label(_("Reset"), GTK_STOCK_REFRESH);
- gtk_widget_set_name(resetB, "reset_button");
+ gtk_widget_set_name(resetB, "dialog_button");
gtk_box_pack_start(GTK_BOX(DIALOG_ACTION_AREA(enved_dialog)), applyB, false, true, 10);
gtk_box_pack_start(GTK_BOX(DIALOG_ACTION_AREA(enved_dialog)), apply2B, false, true, 10);
@@ -1114,20 +1109,8 @@ GtkWidget *create_envelope_editor(void)
textL = snd_entry_new(toprow, WITH_WHITE_BACKGROUND);
SG_SIGNAL_CONNECT(textL, "activate", text_field_activated, NULL);
- brkpixL = gtk_drawing_area_new();
- widget_modify_bg(brkpixL, GTK_STATE_NORMAL, ss->sgx->basic_color);
- gtk_widget_set_events(brkpixL, GDK_EXPOSURE_MASK);
- gtk_widget_set_size_request(brkpixL, 16, 16);
- gtk_box_pack_start(GTK_BOX(toprow), brkpixL, false, false, 0);
- gtk_widget_show(brkpixL);
- SG_SIGNAL_CONNECT(brkpixL, "expose_event", brkpixL_expose, NULL);
-
-#if 0
- brktxtL = snd_gtk_highlight_label_new(BLANK_LABEL); /* not NULL! gtk only creates the label child if not null */
-#else
brktxtL = gtk_button_new_with_label(BLANK_LABEL);
gtk_button_set_relief(GTK_BUTTON(brktxtL), GTK_RELIEF_NONE);
-#endif
gtk_box_pack_start(GTK_BOX(toprow), brktxtL, false, false, 6);
gtk_widget_show(brktxtL);
@@ -1179,12 +1162,14 @@ GtkWidget *create_envelope_editor(void)
gtk_widget_show(mainform);
gtk_widget_show(enved_dialog);
- pix_ax = (axis_context *)calloc(1, sizeof(axis_context));
- pix_ax->wn = GDK_DRAWABLE(WIDGET_TO_WINDOW(brkpixL));
- pix_ax->gc = hgc;
-#if USE_CAIRO
- pix_ax->cr = gdk_cairo_create(WIDGET_TO_WINDOW(brkpixL));
-#endif
+ axis = (axis_info *)calloc(1, sizeof(axis_info));
+ axis->ax = (graphics_context *)calloc(1, sizeof(graphics_context));
+ fixup_graphics_context(axis->ax, drawer, gc);
+
+ gray_ap = (axis_info *)calloc(1, sizeof(axis_info));
+ gray_ap->ax = (graphics_context *)calloc(1, sizeof(graphics_context));
+ gray_ap->graph_active = true;
+ fixup_graphics_context(gray_ap->ax, drawer, ggc);
SG_SIGNAL_CONNECT(drawer, "expose_event", drawer_expose, NULL);
SG_SIGNAL_CONNECT(drawer, "configure_event", drawer_resize, NULL);
@@ -1216,18 +1201,12 @@ GtkWidget *create_envelope_editor(void)
add_selection_watcher(enved_selection_watcher, NULL);
}
else raise_dialog(enved_dialog);
- active_channel = current_channel();
- return(enved_dialog);
-}
+ active_channel = current_channel();
+ env_redisplay();
-#if USE_CAIRO
-GdkDrawable *enved_pix_wn(void);
-GdkDrawable *enved_pix_wn(void)
-{
- return(GDK_DRAWABLE(WIDGET_TO_WINDOW(brkpixL)));
+ return(enved_dialog);
}
-#endif
void set_enved_clip_p(bool val)