diff options
author | Alessio Treglia <alessio@debian.org> | 2011-03-24 09:13:51 +0100 |
---|---|---|
committer | Alessio Treglia <alessio@debian.org> | 2011-03-24 09:13:51 +0100 |
commit | e5328e59987b90c4e98959510b810510e384650d (patch) | |
tree | 0f140b79d942c4654701d8fb4cfe2f1dd904f9f0 /snd-marks.c | |
parent | 36cf8384e5699cda3f1ca607753fe4d4a8515b01 (diff) |
Imported Upstream version 12.0
Diffstat (limited to 'snd-marks.c')
-rw-r--r-- | snd-marks.c | 308 |
1 files changed, 134 insertions, 174 deletions
diff --git a/snd-marks.c b/snd-marks.c index ba9f3ab..a2b4b97 100644 --- a/snd-marks.c +++ b/snd-marks.c @@ -261,11 +261,11 @@ void marks_off(chan_info *cp) } -static void show_mark(chan_info *cp, axis_info *ap, mark *mp, bool show); +static void show_mark(chan_info *cp, mark *mp, bool show); static XEN draw_mark_hook; -static void draw_mark_1(chan_info *cp, axis_info *ap, mark *mp, bool show) +static void draw_mark_1(chan_info *cp, mark *mp, bool show) { /* fields are samp and name */ if (!(cp->graph_time_p)) return; @@ -281,20 +281,20 @@ static void draw_mark_1(chan_info *cp, axis_info *ap, mark *mp, bool show) return; } } - show_mark(cp, ap, mp, show); + show_mark(cp, mp, show); } -static void draw_mark(chan_info *cp, axis_info *ap, mark *mp) +static void draw_mark(chan_info *cp, mark *mp) { - if (!(mp->visible)) draw_mark_1(cp, ap, mp, true); + if (!(mp->visible)) draw_mark_1(cp, mp, true); } -static void erase_mark(chan_info *cp, axis_info *ap, mark *mp) +static void erase_mark(chan_info *cp, mark *mp) { #if (!USE_GTK) - if (mp->visible) draw_mark_1(cp, ap, mp, false); + if (mp->visible) draw_mark_1(cp, mp, false); #endif } @@ -328,7 +328,7 @@ static mark *hit_mark_1(chan_info *cp, mark *mp, void *m) } -#define MARK_PLAY_ARROW_SIZE 10 +#define HIT_SLOP 4 static mark *hit_mark_triangle_1(chan_info *cp, mark *mp, void *m) { @@ -343,11 +343,11 @@ static mark *hit_mark_triangle_1(chan_info *cp, mark *mp, void *m) if (mp->samp > ap->hisamp) return(md->all_done); /* grf_x clips so we can be confused by off-screen marks */ mx = grf_x((double)(mp->samp) / (double)SND_SRATE(cp->sound), cp->axis); - if (mx > md->x) return(md->all_done); - if ((mx + MARK_PLAY_ARROW_SIZE) < md->x) return(NULL); - y = md->y - ap->y_axis_y0 - MARK_PLAY_ARROW_SIZE; + if (mx > (md->x + HIT_SLOP)) return(md->all_done); + if ((mx + play_arrow_size(ss) + HIT_SLOP) < md->x) return(NULL); + y = md->y - ap->y_axis_y0 - play_arrow_size(ss); if (y < 0) y = -y; - if ((mx + MARK_PLAY_ARROW_SIZE - y) >= md->x) return(mp); + if ((mx + play_arrow_size(ss) - y + HIT_SLOP) >= md->x) return(mp); /* the last is assuming the triangle shape for hit detection */ return(NULL); } @@ -361,7 +361,7 @@ mark *hit_mark_triangle(chan_info *cp, int x, int y) ap = cp->axis; /* first check that we're in the bottom portion of the graph where the mark triangles are */ if ((y >= ap->y_axis_y0) && - (y <= (ap->y_axis_y0 + 2 * MARK_PLAY_ARROW_SIZE))) + (y <= (ap->y_axis_y0 + 2 * play_arrow_size(ss)))) { mark *mp; mdata *md; @@ -442,7 +442,7 @@ static bool move_mark_1(chan_info *cp, mark *mp, int x) } else { - erase_mark(cp, ap, mp); + erase_mark(cp, mp); nx = x; if (watching_mouse) { @@ -481,34 +481,6 @@ static void sort_marks(chan_info *cp) } -static void show_mark_triangle(chan_info *cp, int x); -static int prev_cx = -1; - -mus_long_t move_play_mark(chan_info *cp, mus_long_t *mc, int cx) -{ - /* mc = mouse loc sampwise return samps updating mc */ - mus_long_t cur_mc; - axis_info *ap; - ap = cp->axis; - if (prev_cx > 0) show_mark_triangle(cp, prev_cx); - prev_cx = cx; - show_mark_triangle(cp, cx); - cur_mc = (*mc); - (*mc) = (mus_long_t)(ungrf_x(ap, cx) * SND_SRATE(cp->sound)); - return((*mc) - cur_mc); -} - - -void finish_moving_play_mark(chan_info *cp) -{ - snd_info *sp; - sp = cp->sound; - show_mark_triangle(cp, prev_cx); - prev_cx = -1; - sp->speed_control = 1.0; -} - - typedef enum {MARK_ADD, MARK_DELETE, MARK_MOVE, MARKS_DELETE, MARK_RELEASE} mark_hook_reason_t; static void run_mark_hook(chan_info *cp, int id, mark_hook_reason_t reason) @@ -521,7 +493,9 @@ static void run_mark_hook(chan_info *cp, int id, mark_hook_reason_t reason) C_TO_XEN_INT(cp->chan), C_TO_XEN_INT((int)reason)), S_mark_hook); - run_watchers(); + + if (XEN_HOOKED(ss->effects_hook)) + run_hook(ss->effects_hook, XEN_EMPTY_LIST, S_effects_hook); } @@ -609,7 +583,7 @@ bool delete_mark_samp(mus_long_t samp, chan_info *cp) axis_info *ap; int id = -1; ap = cp->axis; - if ((mp->samp >= ap->losamp) && (mp->samp <= ap->hisamp)) erase_mark(cp, ap, mp); + if ((mp->samp >= ap->losamp) && (mp->samp <= ap->hisamp)) erase_mark(cp, mp); id = mp->id; free_mark(mp); mps[i] = NULL; @@ -653,7 +627,7 @@ static bool delete_mark_id(int id, chan_info *cp) { axis_info *ap; ap = cp->axis; - if ((mp->samp >= ap->losamp) && (mp->samp <= ap->hisamp)) erase_mark(cp, ap, mp); + if ((mp->samp >= ap->losamp) && (mp->samp <= ap->hisamp)) erase_mark(cp, mp); free_mark(mp); mps[i] = NULL; if (i < edm) @@ -695,7 +669,7 @@ static void delete_marks(chan_info *cp) { axis_info *ap; ap = cp->axis; - if ((mp->samp >= ap->losamp) && (mp->samp <= ap->hisamp)) erase_mark(cp, ap, mp); + if ((mp->samp >= ap->losamp) && (mp->samp <= ap->hisamp)) erase_mark(cp, mp); free_mark(mp); mps[i] = NULL; } @@ -888,7 +862,7 @@ static mark *display_channel_marks_1(chan_info *cp, mark *mp, void *m) if ((mp->samp >= ap->losamp) && (mp->samp <= ap->hisamp) && (mp != moving_mark)) - draw_mark(cp, ap, mp); + draw_mark(cp, mp); return(NULL); } @@ -1283,7 +1257,7 @@ static mark_context *make_mark_context(chan_info *cp) mark_context *g; g = (mark_context *)calloc(1, sizeof(mark_context)); g->graph = channel_graph(cp); - g->color = ss->sgx->mark_color; + g->color = ss->mark_color; return(g); } @@ -1309,7 +1283,7 @@ static void initialize_md_context(int size, chan_info **cps) mark_context *ms; mark_movers[i] = make_mark_context(cps[i]); ms = mark_movers[i]; - ms->lastpj = make_graph(cps[i]); + ms->lastpj = make_dragged_marks_graph(cps[i]); mark_save_graph(ms, ms->lastpj); } } @@ -1329,7 +1303,45 @@ static void finalize_md_context(int size) } -mark *hit_mark(chan_info *cp, int x, int y, int key_state) +void set_mark_control(chan_info *cp, mark *mp, int key_state) +{ + mark_control_clicked = (key_state & snd_ControlMask); + + if (mark_control_clicked) + { + mark_initial_sample = mp->samp; + if (mark_sd) + { + if ((mark_sd->mark_ctr > 1) && + (mark_sd->marks[0] != mp)) + { + mark *tm; + int loc = 1; + mus_long_t ts; + chan_info *tc; + for (loc = 1; loc < mark_sd->mark_ctr; loc++) + if (mark_sd->marks[loc] == mp) break; + if (loc < mark_sd->mark_ctr) + { + tm = mark_sd->marks[0]; + ts = mark_sd->initial_samples[0]; + tc = mark_sd->chans[0]; + mark_sd->marks[0] = mark_sd->marks[loc]; + mark_sd->initial_samples[0] = mark_sd->initial_samples[loc]; + mark_sd->chans[0] = mark_sd->chans[loc]; + mark_sd->marks[loc] = tm; + mark_sd->initial_samples[loc] = ts; + mark_sd->chans[loc] = tc; + } + } + initialize_md_context(mark_sd->mark_ctr, mark_sd->chans); + } + else initialize_md_context(1, &cp); + } +} + + +mark *hit_mark(chan_info *cp, int x, int y) { ed_list *ed; ed = cp->edits[cp->edit_ctr]; @@ -1337,12 +1349,14 @@ mark *hit_mark(chan_info *cp, int x, int y, int key_state) { axis_info *ap; ap = cp->axis; + /* first check that we're in the top portion of the graph where the mark tabs are */ if ((y >= ap->y_axis_y1) && (y <= (ap->y_axis_y1 + mark_tag_height(ss) + 10))) /* + 10 for named marks -- checked again later */ { mark *mp; mdata *md; + md = (mdata *)calloc(1, sizeof(mdata)); md->x = x; md->y = y; @@ -1350,45 +1364,14 @@ mark *hit_mark(chan_info *cp, int x, int y, int key_state) mp = map_over_marks(cp, hit_mark_1, (void *)md, READ_FORWARD); if (mp == (mark *)1) mp = NULL; free(md); + if (mp) { - mark_control_clicked = (key_state & snd_ControlMask); if (mp->sync != 0) { if (mark_sd) mark_sd = free_syncdata(mark_sd); mark_sd = gather_syncd_marks(mp->sync); } - if (mark_control_clicked) - { - mark_initial_sample = mp->samp; - if (mark_sd) - { - if ((mark_sd->mark_ctr > 1) && - (mark_sd->marks[0] != mp)) - { - mark *tm; - int loc = 1; - mus_long_t ts; - chan_info *tc; - for (loc = 1; loc < mark_sd->mark_ctr; loc++) - if (mark_sd->marks[loc] == mp) break; - if (loc < mark_sd->mark_ctr) - { - tm = mark_sd->marks[0]; - ts = mark_sd->initial_samples[0]; - tc = mark_sd->chans[0]; - mark_sd->marks[0] = mark_sd->marks[loc]; - mark_sd->initial_samples[0] = mark_sd->initial_samples[loc]; - mark_sd->chans[0] = mark_sd->chans[loc]; - mark_sd->marks[loc] = tm; - mark_sd->initial_samples[loc] = ts; - mark_sd->chans[loc] = tc; - } - } - initialize_md_context(mark_sd->mark_ctr, mark_sd->chans); - } - else initialize_md_context(1, &cp); - } } return(mp); } @@ -1426,21 +1409,26 @@ static void mark_save_graph(mark_context *ms, int j) static void erase_and_draw_grf_points(mark_context *ms, chan_info *cp, int nj) { - chan_context *cx; graphics_context *ax; point_t *points; + chan_info *draw_cp; #if USE_MOTIF GC draw_gc, undraw_gc; #else gc_t *draw_gc, *undraw_gc; #endif + points = get_grf_points(); - cx = cp->tcgx; - if (!cx) cx = cp->cgx; - ax = cx->ax; - undraw_gc = erase_GC(cp); - draw_gc = copy_GC(cp); - if (cp->time_graph_style == GRAPH_LINES) + draw_cp = channel_to_chan(cp); + ax = draw_cp->ax; + +#if USE_GTK + ss->cr = MAKE_CAIRO(ax->wn); +#endif + + undraw_gc = erase_GC(draw_cp); + draw_gc = copy_GC(draw_cp); + if (draw_cp->time_graph_style == GRAPH_LINES) { ax->gc = undraw_gc; draw_lines(ax, ms->p0, ms->lastpj); @@ -1450,33 +1438,44 @@ static void erase_and_draw_grf_points(mark_context *ms, chan_info *cp, int nj) else { ax->gc = undraw_gc; - draw_points(ax, ms->p0, ms->lastpj, cp->dot_size); + draw_points(ax, ms->p0, ms->lastpj, draw_cp->dot_size); ax->gc = draw_gc; - draw_points(ax, points, nj, cp->dot_size); + draw_points(ax, points, nj, draw_cp->dot_size); } backup_erase_grf_points(ms, nj); ax->gc = draw_gc; + +#if USE_GTK + FREE_CAIRO(ss->cr); + ss->cr = NULL; +#endif } static void erase_and_draw_both_grf_points(mark_context *ms, chan_info *cp, int nj) { - chan_context *cx; graphics_context *ax; point_t *points, *points1; + chan_info *draw_cp; #if USE_MOTIF GC draw_gc, undraw_gc; #else gc_t *draw_gc, *undraw_gc; #endif + points = get_grf_points(); points1 = get_grf_points1(); - cx = cp->tcgx; - if (!cx) cx = cp->cgx; - ax = cx->ax; - undraw_gc = erase_GC(cp); - draw_gc = copy_GC(cp); - if (cp->time_graph_style == GRAPH_LINES) + + draw_cp = channel_to_chan(cp); + ax = draw_cp->ax; + +#if USE_GTK + ss->cr = MAKE_CAIRO(ax->wn); +#endif + + undraw_gc = erase_GC(draw_cp); + draw_gc = copy_GC(draw_cp); + if (draw_cp->time_graph_style == GRAPH_LINES) { ax->gc = undraw_gc; draw_lines(ax, ms->p0, ms->lastpj); @@ -1488,14 +1487,19 @@ static void erase_and_draw_both_grf_points(mark_context *ms, chan_info *cp, int else { ax->gc = undraw_gc; - draw_points(ax, ms->p0, ms->lastpj, cp->dot_size); - draw_points(ax, ms->p1, ms->lastpj, cp->dot_size); + draw_points(ax, ms->p0, ms->lastpj, draw_cp->dot_size); + draw_points(ax, ms->p1, ms->lastpj, draw_cp->dot_size); ax->gc = draw_gc; - draw_points(ax, points, nj, cp->dot_size); - draw_points(ax, points1, nj, cp->dot_size); + draw_points(ax, points, nj, draw_cp->dot_size); + draw_points(ax, points1, nj, draw_cp->dot_size); } backup_erase_grf_points(ms, nj); ax->gc = draw_gc; + +#if USE_GTK + FREE_CAIRO(ss->cr); + ss->cr = NULL; +#endif } #else static void mark_save_graph(mark_context *ms, int j) {} @@ -1527,7 +1531,7 @@ static bool move_syncd_mark(chan_info *cp, mark *m, int x) ap = ncp->axis; if ((mp->samp >= ap->losamp) && (mp->samp <= ap->hisamp)) - erase_mark(ncp, ap, mp); + erase_mark(ncp, mp); mp->samp += diff; if (mp->samp < 0) mp->samp = 0; samps = CURRENT_SAMPLES(ncp); @@ -1536,7 +1540,7 @@ static bool move_syncd_mark(chan_info *cp, mark *m, int x) make_mark_graph(ncp, mark_sd->initial_samples[i], mp->samp, i); if ((mp->samp >= ap->losamp) && (mp->samp <= ap->hisamp)) - draw_mark(ncp, ap, mp); + draw_mark(ncp, mp); } } } @@ -1554,7 +1558,7 @@ static void move_axis_to_track_mark(chan_info *cp) if (moving_mark->sync) redraw = move_syncd_mark(cp, moving_mark, last_mouse_x); else redraw = move_mark_1(cp, moving_mark, last_mouse_x); - if (redraw) draw_mark(cp, cp->axis, moving_mark); + if (redraw) draw_mark(cp, moving_mark); } } #endif @@ -1564,15 +1568,19 @@ void move_mark(chan_info *cp, mark *mp, int x) /* from mouse drag callback in sn { bool redraw; last_mouse_x = x; + if (mp->sync) redraw = move_syncd_mark(cp, mp, x); else redraw = move_mark_1(cp, mp, x); + if (mark_control_clicked) make_mark_graph(cp, mark_initial_sample, mp->samp, 0); + #if (!USE_GTK) - if (redraw) draw_mark(cp, cp->axis, mp); + if (redraw) draw_mark(cp, mp); #else - if (redraw) display_channel_time_data(cp); + if ((redraw) && (!mark_control_clicked)) + display_channel_time_data(cp); #endif } @@ -1872,9 +1880,10 @@ static void make_mark_graph(chan_info *cp, mus_long_t initial_sample, mus_long_t /* -------------------------------- display mark -------------------------------- */ -static void show_mark(chan_info *cp, axis_info *ap, mark *mp, bool show) +static void show_mark(chan_info *cp, mark *mp, bool show) { int len, top, cx, y0, y1; + axis_info *ap; graphics_context *ax; #if USE_MOTIF @@ -1883,6 +1892,7 @@ static void show_mark(chan_info *cp, axis_info *ap, mark *mp, bool show) #define STRING_Y_OFFSET -6 #endif + ap = cp->axis; top = ap->y_axis_y1; y1 = top; y0 = ap->y_axis_y0; @@ -1890,11 +1900,15 @@ static void show_mark(chan_info *cp, axis_info *ap, mark *mp, bool show) cx = grf_x((double)(mp->samp) / (double)SND_SRATE(cp->sound), ap); ax = mark_tag_context(cp); +#if USE_GTK + ss->cr = MAKE_CAIRO(ax->wn); +#endif + if (mp->name) { #if USE_MOTIF - ax->current_font = ss->sgx->peaks_fontstruct->fid; - XSetFont(ax->dp, ax->gc, ss->sgx->peaks_fontstruct->fid); + ax->current_font = ss->peaks_fontstruct->fid; + XSetFont(ax->dp, ax->gc, ss->peaks_fontstruct->fid); #else ax->current_font = PEAKS_FONT(ss); #endif @@ -1906,33 +1920,24 @@ static void show_mark(chan_info *cp, axis_info *ap, mark *mp, bool show) cx - mark_tag_width(ss), top, 2 * mark_tag_width(ss), mark_tag_height(ss)); draw_line(ax, cx, top + 4, cx, y0); - fill_polygon(ax, 4, - cx, y0, - cx + MARK_PLAY_ARROW_SIZE, y0 + MARK_PLAY_ARROW_SIZE, - cx, y0 + 2 * MARK_PLAY_ARROW_SIZE, - cx, y0); + + if (mp->samp != CURSOR(cp)) + fill_polygon(ax, 4, + cx, y0, + cx + play_arrow_size(ss), y0 + play_arrow_size(ss), + cx, y0 + 2 * play_arrow_size(ss), + cx, y0); mp->visible = show; #if USE_GTK + FREE_CAIRO(ss->cr); + ss->cr = NULL; copy_context(cp); #endif } - -static void show_mark_triangle(chan_info *cp, int x) -{ - int y0; - y0 = ((axis_info *)(cp->axis))->y_axis_y0; - draw_polygon(mark_tag_context(cp), 4, - x, y0, - x + MARK_PLAY_ARROW_SIZE, y0 + MARK_PLAY_ARROW_SIZE, - x, y0 + 2 * MARK_PLAY_ARROW_SIZE, - x, y0); -} - #else /* no gui */ -static void show_mark(chan_info *cp, axis_info *ap, mark *mp, bool show) {} -static void show_mark_triangle(chan_info *cp, int x) {} +static void show_mark(chan_info *cp, mark *mp, bool show) {} #endif @@ -2109,41 +2114,6 @@ static XEN snd_no_such_mark_error(const char *caller, XEN id) } -#if MUS_DEBUGGING && HAVE_SCHEME -/* too hard to do this via mouse events in snd-test, so do it by hand here */ -static XEN g_test_control_drag_mark(XEN snd, XEN chn, XEN mid) -{ - int x, y; - mus_long_t cx; - chan_info *cp; - mark *m = NULL, *m1 = NULL; - cp = get_cp(snd, chn, "test-C-mark"); - if (!cp) return(XEN_FALSE); - m = find_mark_from_id(XEN_MARK_TO_C_INT(mid), NULL, AT_CURRENT_EDIT_POSITION); - if (m == NULL) - return(snd_no_such_mark_error("test-C-mark", mid)); - y = cp->axis->y_axis_y1; - if (m->name) y += 10; - x = grf_x((double)(m->samp) / (double)SND_SRATE(cp->sound), cp->axis); - m1 = hit_mark(cp, x, y + 1, snd_ControlMask); - if (m != m1) - { - fprintf(stderr, "ah rats! "); - abort(); - } - move_mark(cp, m, x - 50); - finish_moving_mark(cp, m); - x = grf_x((double)(m->samp) / (double)SND_SRATE(cp->sound), cp->axis); - y = cp->axis->y_axis_y0 + 2; - hit_mark_triangle(cp, x, y); - cx = m->samp + 50; - move_play_mark(cp, &cx, x + 50); - finish_moving_play_mark(cp); - return(mid); -} -#endif - - typedef enum {MARK_SAMPLE, MARK_NAME, MARK_SYNC, MARK_HOME} mark_field_t; static XEN mark_get(XEN n, mark_field_t fld, XEN pos_n, const char *caller) @@ -2906,9 +2876,6 @@ XEN_NARGIFY_1(g_mark_properties_w, g_mark_properties) XEN_NARGIFY_2(g_set_mark_properties_w, g_set_mark_properties) XEN_NARGIFY_2(g_mark_property_w, g_mark_property) XEN_NARGIFY_3(g_set_mark_property_w, g_set_mark_property) -#if MUS_DEBUGGING && HAVE_SCHEME - XEN_NARGIFY_3(g_test_control_drag_mark_w, g_test_control_drag_mark) -#endif #else #define g_mark_sample_w g_mark_sample #define g_set_mark_sample_w g_set_mark_sample @@ -2937,9 +2904,6 @@ XEN_NARGIFY_3(g_set_mark_property_w, g_set_mark_property) #define g_set_mark_properties_w g_set_mark_properties #define g_mark_property_w g_mark_property #define g_set_mark_property_w g_set_mark_property -#if MUS_DEBUGGING && HAVE_SCHEME - #define g_test_control_drag_mark_w g_test_control_drag_mark -#endif #endif void g_init_marks(void) @@ -2992,9 +2956,5 @@ void g_init_marks(void) If the hook returns " PROC_TRUE ", the mark is not drawn." draw_mark_hook = XEN_DEFINE_HOOK(S_draw_mark_hook, 1, H_draw_mark_hook); /* arg = mark-id */ - -#if MUS_DEBUGGING && HAVE_SCHEME - XEN_DEFINE_PROCEDURE("internal-test-control-drag-mark", g_test_control_drag_mark_w, 3, 0, 0, "internal testing func"); -#endif } |