From ad2fef3fa0a2f4d5a2a9fb57ba939dc4affda006 Mon Sep 17 00:00:00 2001 From: niels Date: Mon, 30 Nov 2015 20:48:55 +0100 Subject: [PATCH] fix distortion fx, honor fade_method in auto fader, fix crash on failed generator loading, fix typo (issue #32) --- .../veejay-server/libsample/sampleadm.c | 3 +- .../veejay-server/libsample/sampleadm.h | 2 +- .../veejay-server/libstream/vj-tag.c | 9 +- .../veejay-server/libstream/vj-tag.h | 2 +- .../veejay-server/libvje/effects/distort.c | 135 ++++++++---------- .../veejay-server/libvje/effects/distort.h | 4 +- .../veejay-server/libvje/vj-effect.c | 1 - .../veejay-server/veejay/vj-event.c | 4 +- .../veejay-server/veejay/vj-perform.c | 4 +- 9 files changed, 78 insertions(+), 86 deletions(-) diff --git a/veejay-current/veejay-server/libsample/sampleadm.c b/veejay-current/veejay-server/libsample/sampleadm.c index 1e9c70c1..0b238e29 100644 --- a/veejay-current/veejay-server/libsample/sampleadm.c +++ b/veejay-current/veejay-server/libsample/sampleadm.c @@ -781,10 +781,11 @@ int sample_set_fader_val(int s1, float val) { return 1; } -int sample_apply_fader_inc(int s1) { +int sample_apply_fader_inc(int s1, int method) { sample_info *si = sample_get(s1); if(!si) return -1; si->fader_val += si->fader_inc; + si->fade_method = method; if(si->fader_val > 255.0 ) si->fader_val = 255.0; if(si->fader_val < 0.0 ) si->fader_val = 0.0; return (int) (si->fader_val+0.5); diff --git a/veejay-current/veejay-server/libsample/sampleadm.h b/veejay-current/veejay-server/libsample/sampleadm.h index c4e90ea1..ffc621e7 100644 --- a/veejay-current/veejay-server/libsample/sampleadm.h +++ b/veejay-current/veejay-server/libsample/sampleadm.h @@ -306,7 +306,7 @@ extern int sample_set_loop_dec(int s1, int active); extern int sample_apply_loop_dec(int s1, double fps); extern int sample_set_manual_fader(int s1, int value, int method ); -extern int sample_apply_fader_inc(int s1); +extern int sample_apply_fader_inc(int s1, int method); extern int sample_set_fader_active(int s1, int nframes, int direction); extern int sample_set_fader_val(int s1, float val); extern int sample_get_fader_active(int s1); diff --git a/veejay-current/veejay-server/libstream/vj-tag.c b/veejay-current/veejay-server/libstream/vj-tag.c index 46416bba..34d5c31e 100644 --- a/veejay-current/veejay-server/libstream/vj-tag.c +++ b/veejay-current/veejay-server/libstream/vj-tag.c @@ -1061,6 +1061,12 @@ int vj_tag_new(int type, char *filename, int stream_nr, editlist * el, int pix_f vj_shm_set_id( extra ); tag->generator = plug_activate(channel); + if( tag->generator == NULL ) { + veejay_msg(0, "Unable to load selected generator"); + free(tag->source_name); + free(tag); + return -1; + } int vj_plug_id = 500 + channel; vevo_property_set(tag->generator, "HOST_id",VEVO_ATOM_TYPE_INT, 1, &vj_plug_id ); @@ -1510,10 +1516,11 @@ int vj_tag_get_fader_direction(int t1) { return (tag->fader_direction); } -int vj_tag_apply_fader_inc(int t1) { +int vj_tag_apply_fader_inc(int t1, int fade_method) { vj_tag *tag = vj_tag_get(t1); if(!tag) return -1; tag->fader_val += tag->fader_inc; + tag->fade_method = fade_method; if(tag->fader_val > 255.0 ) tag->fader_val = 255.0; if(tag->fader_val < 0.0) tag->fader_val = 0.0; if(tag->fader_direction) return tag->fader_val; diff --git a/veejay-current/veejay-server/libstream/vj-tag.h b/veejay-current/veejay-server/libstream/vj-tag.h index 6a251e24..eb71fc8f 100644 --- a/veejay-current/veejay-server/libstream/vj-tag.h +++ b/veejay-current/veejay-server/libstream/vj-tag.h @@ -285,7 +285,7 @@ int vj_tag_set_fader_active(int t1, int nframes, int direction); int vj_tag_set_fade_to_tag(int t1, int t2); int vj_tag_set_fade_to_sample(int t1, int s1); int vj_tag_set_fader_val(int t1, float val); -int vj_tag_apply_fader_inc(int t1); +int vj_tag_apply_fader_inc(int t1, int method); int vj_tag_get_fader_active(int t1); float vj_tag_get_fader_val(int t1, int *method); float vj_tag_get_fader_inc(int t1); diff --git a/veejay-current/veejay-server/libvje/effects/distort.c b/veejay-current/veejay-server/libvje/effects/distort.c index 7f5359a7..0d6973f4 100644 --- a/veejay-current/veejay-server/libvje/effects/distort.c +++ b/veejay-current/veejay-server/libvje/effects/distort.c @@ -27,7 +27,7 @@ #include "distort.h" #include "widthmirror.h" -static int *plasma_table = NULL; +static int plasma_table[512]; static int plasma_pos1 = 0; static int plasma_pos2 = 0; @@ -36,10 +36,9 @@ vj_effect *distortion_init(int width, int height) vj_effect *ve = (vj_effect *) vj_calloc(sizeof(vj_effect)); int i; float rad; - plasma_table = (int *) vj_calloc(sizeof(int) * 512); for (i = 0; i < 512; i++) { - rad = ((float) i * 0.703125) * 0.0174532; - plasma_table[i] = sin(rad) * (1024); + rad = ((float) i * 0.703125f) * 0.0174532f; + plasma_table[i] = sin(rad) * (1024); } ve->num_params = 2; @@ -53,23 +52,13 @@ vj_effect *distortion_init(int width, int height) ve->limits[0][1] = 0; ve->limits[1][1] = 8; ve->description = "Distortion"; - ve->sub_format = 0; + ve->sub_format = -1; ve->extra_frame = 0; ve->has_user = 0; ve->param_description = vje_build_param_list( ve->num_params, "Inc 1" , "Inc2" ); return ve; } -void distortion_free() { - if(plasma_table) free(plasma_table); -} - -void distortion_destroy() -{ - if(plasma_table) - free( plasma_table ); -} - /* the distortion effect comes originally from the demo effects collection, it is the plasma effect */ @@ -84,83 +73,81 @@ void distortion_apply(VJFrame *frame, int width, int height, uint8_t *Y = frame->data[0]; uint8_t *Cb = frame->data[1]; uint8_t *Cr = frame->data[2]; - const int uv_width = frame->uv_width; - const int uv_height = frame->uv_height; + int uv_width = frame->uv_width; + int uv_height = frame->uv_height; unsigned int yi; + if( frame->ssm ) { + uv_width = width; + uv_height = height; + } uint8_t p, cb, cr; for (i = 0; i < height; ++i) { - tpos1 = plasma_pos1 + inc_val1; - tpos2 = plasma_pos2 + inc_val2; + tpos1 = plasma_pos1 + inc_val1; + tpos2 = plasma_pos2 + inc_val2; - tpos3 &= z; - tpos4 &= z; + tpos3 &= z; + tpos4 &= z; - for (j = 0; j < width; ++j) { - tpos1 &= z; - tpos2 &= z; - x = plasma_table[tpos1] + plasma_table[tpos2] + - plasma_table[tpos3] + plasma_table[tpos4]; - - index = 128 + (x >> 4); - - /* image = index */ - Y[(i * width) + j] = Y[index]; - - tpos1 += inc_val1; - tpos2 += inc_val2; - } - tpos4 += 3; - tpos3 += 1; + for (j = 0; j < width; ++j) { + tpos1 &= z; + tpos2 &= z; + x = plasma_table[tpos1] + plasma_table[tpos2] + + plasma_table[tpos3] + plasma_table[tpos4]; + + index = (x >> 4); + + Y[(i * width) + j] = Y[index]; + + tpos1 += inc_val1; + tpos2 += inc_val2; + } + tpos4 += 3; + tpos3 += 1; } - - for (i = 0; i < uv_height; ++i) { - tpos1 = plasma_pos1 + inc_val1; - tpos2 = plasma_pos2 + inc_val2; + tpos1 = plasma_pos1 + inc_val1; + tpos2 = plasma_pos2 + inc_val2; - tpos3 &= z; - tpos4 &= z; + tpos3 &= z; + tpos4 &= z; - for (j = 0; j < uv_width; ++j) { - tpos1 &= z; - tpos2 &= z; - x = plasma_table[tpos1] + plasma_table[tpos2] + - plasma_table[tpos3] + plasma_table[tpos4]; + for (j = 0; j < uv_width; ++j) { + tpos1 &= z; + tpos2 &= z; + x = plasma_table[tpos1] + plasma_table[tpos2] + + plasma_table[tpos3] + plasma_table[tpos4]; - index = 128 + (x >> 4); - - /* image = index */ - Cb[(j * uv_width) + i] = Cb[index]; - Cr[(j * uv_width) + i] = Cr[index]; - tpos1 += inc_val1; - tpos2 += inc_val2; - } - tpos4 += 3; - tpos3 += 1; + index = (x >> 4); + + Cb[(j * uv_width) + i] = Cb[index]; + Cr[(j * uv_width) + i] = Cr[index]; + tpos1 += inc_val1; + tpos2 += inc_val2; + } + tpos4 += 3; + tpos3 += 1; } plasma_pos1 += 9; plasma_pos2 += 8; for (y = 0; y < height; y++) { - yi = y * width; - for (x = 0; x < width; x++) { - p =Y[yi + x]; - Y[yi + (width - x - 1)] = p; - } + yi = y * width; + for (x = 0; x < width; x++) { + p =Y[yi + x]; + Y[yi + (width - x - 1)] = p; + } + } + for (y = 0; y < uv_height; y++) { + yi = y * uv_width; + for (x = 0; x < uv_width; x++) { + cb = Cb[yi + x]; + cr = Cr[yi + x]; + Cb[yi + uv_width - x - 1] = cb; + Cr[yi + uv_width - x - 1] = cr; + } } - for (y = 0; y < uv_height; y++) { - yi = y * uv_width; - for (x = 0; x < uv_width; x++) { - cb = Cb[yi + x]; - cr = Cr[yi + x]; - Cb[yi + uv_width - x - 1] = cb; - Cr[yi + uv_width - x - 1] = cr; - } - } - } -void distort_free(){} diff --git a/veejay-current/veejay-server/libvje/effects/distort.h b/veejay-current/veejay-server/libvje/effects/distort.h index 4278366a..3f38b2f1 100644 --- a/veejay-current/veejay-server/libvje/effects/distort.h +++ b/veejay-current/veejay-server/libvje/effects/distort.h @@ -25,8 +25,6 @@ #include vj_effect *distortion_init(int w, int h); -void distortion_apply( VJFrame *frame, int width, int height, int n, - int type); +void distortion_apply( VJFrame *frame, int width, int height, int n,int type); void distort_free(); -void distortion_destroy(); #endif diff --git a/veejay-current/veejay-server/libvje/vj-effect.c b/veejay-current/veejay-server/libvje/vj-effect.c index 42face44..ccfdd6ef 100644 --- a/veejay-current/veejay-server/libvje/vj-effect.c +++ b/veejay-current/veejay-server/libvje/vj-effect.c @@ -727,7 +727,6 @@ void vj_effect_shutdown() { //texmap_destroy(); // contourextract_destroy(); rotozoom_destroy(); - distortion_destroy(); plug_sys_free(); } diff --git a/veejay-current/veejay-server/veejay/vj-event.c b/veejay-current/veejay-server/veejay/vj-event.c index b04555a9..9f2480ab 100644 --- a/veejay-current/veejay-server/veejay/vj-event.c +++ b/veejay-current/veejay-server/veejay/vj-event.c @@ -4927,14 +4927,14 @@ void vj_event_chain_disable(void *ptr, const char format[], va_list ap) if(SAMPLE_PLAYING(v) ) { sample_set_effect_status(v->uc->sample_id, 0); - veejay_msg(VEEJAY_MSG_INFO, "Effect chain on Sample %d is disabled",v->uc->sample_id); + veejay_msg(VEEJAY_MSG_INFO, "Effect chain on sample %d is disabled",v->uc->sample_id); } else { if(STREAM_PLAYING(v) ) { vj_tag_set_effect_status(v->uc->sample_id, 0); - veejay_msg(VEEJAY_MSG_INFO, "Effect chain on Stream %d is enabled",v->uc->sample_id); + veejay_msg(VEEJAY_MSG_INFO, "Effect chain on stream %d is enabled",v->uc->sample_id); } else p_invalid_mode(); diff --git a/veejay-current/veejay-server/veejay/vj-perform.c b/veejay-current/veejay-server/veejay/vj-perform.c index bab93043..9a2338c5 100644 --- a/veejay-current/veejay-server/veejay/vj-perform.c +++ b/veejay-current/veejay-server/veejay/vj-perform.c @@ -3031,7 +3031,7 @@ static int vj_perform_post_chain_sample(veejay_t *info, VJFrame *frame) if(mode == 2 ) // manual fade opacity = (int) sample_get_fader_val(info->uc->sample_id, &fade_method); else // fade in/fade out - opacity = (int) sample_apply_fader_inc(info->uc->sample_id); + opacity = (int) sample_apply_fader_inc(info->uc->sample_id, &fade_method); if(mode != 2) { @@ -3103,7 +3103,7 @@ static int vj_perform_post_chain_tag(veejay_t *info, VJFrame *frame) if(mode == 2) opacity = (int) vj_tag_get_fader_val(info->uc->sample_id, &fade_method); else - opacity = (int) vj_tag_apply_fader_inc(info->uc->sample_id); + opacity = (int) vj_tag_apply_fader_inc(info->uc->sample_id, &fade_method); if( opacity == 0 ) { if( pvar_.follow_fade ) {