int effect_update(struct razer_fx_render_node *render)
{
	float percentage = daemon_get_parameter_float(daemon_effect_get_parameter_by_index(render->effect,0));
	int x,y;
	struct razer_rgb col;
	#ifdef USE_DEBUGGING
		printf(" (Bar.%d ## %%:%f)",render->id,percentage);
	#endif

	int xmax = (int)((21.0f / 100.0f) * percentage);
	for(x=0;x<render->device->columns_num;x++)
		for(y=0;y<render->device->rows_num;y++)
		{
			float dist = 0.0f;
			if(x-xmax <= 0)
				dist = 1.0f;
			else
			{
				dist = (21.0f / (x-xmax))/21.0f;
			}
			rgb_from_hue(dist,0.3f,0.0f,&col);
			rgb_mix_into(&render->output_frame->rows[y]->column[x],&render->input_frame->rows[y]->column[x],&col,render->opacity);//*render->opacity  //&render->second_input_frame->rows[y]->column[x]
			render->output_frame->update_mask |= 1<<y;
		}
	return(1);
}
int effect2_update(struct razer_fx_render_node *render)
{
	struct razer_rgb color;
	int x,y;
	struct razer_rgb *base_color = daemon_get_parameter_rgb(daemon_get_parameter_by_index(render->effect->parameters,0));
	int count = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,1));
	int dir = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,2));
	#ifdef USE_DEBUGGING
		printf(" (breath ## breathing color: %d,%d,%d,count:%d,dir:%d)",base_color->r,base_color->g,base_color->b,count,dir);
	#endif
	for(x=0;x<22;x++)
		for(y=0;y<6;y++)
		{
			color.r = (int)((float)count*((float)base_color->r/100.0f));
			color.g = (int)((float)count*((float)base_color->g/100.0f));
			color.b = (int)((float)count*((float)base_color->b/100.0f));

			rgb_mix_into(&render->output_frame->rows[y].column[x],&render->input_frame->rows[y].column[x],&color,render->opacity);
			render->output_frame->update_mask |= 1<<y;
		}
	count+=dir;
	if(count<1 || count>99)
		dir=-dir;
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,1),count);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,2),dir);	
	return(1);
}
int effect1_update(struct razer_fx_render_node *render)
{
	struct razer_rgb color;
	//struct razer_chroma *chroma = render->daemon->chroma;
	int x,y;
	int count = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,1));
	int dir = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,2));
	for(x=0;x<22;x++)
		for(y=0;y<6;y++)
		{
			color.r = (count+x)*(255/22);
			color.g = (count-x)*(255/22);
			color.b = (count+y)*(255/22);

			/*chroma->keys->rows[y].column[x].r = (unsigned char)r;
			chroma->keys->rows[y].column[x].g = (unsigned char)g;
			chroma->keys->rows[y].column[x].b = (unsigned char)b;
			chroma->keys->update_mask |= 1<<y;*/
			/*render->output_frame->rows[y].column[x].r = (unsigned char)r;
			render->output_frame->rows[y].column[x].g = (unsigned char)g;
			render->output_frame->rows[y].column[x].b = (unsigned char)b;*/
			rgb_mix_into(&render->output_frame->rows[y].column[x],&render->input_frame->rows[y].column[x],&color,render->opacity);
			render->output_frame->update_mask |= 1<<y;
		}
	//razer_update_keys(chroma,chroma->keys);
	count+=dir;
	#ifdef USE_DEBUGGING
		printf(" (1st One ## end counter:%d,count:%d,dir:%d)",daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,0)),count,dir);
	#endif
	if(count<=0 || count>=daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,0)))
		dir=-dir;
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,1),count);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,2),dir);	
	return(1);
}
int effect6_update(struct razer_fx_render_node *render)
{
	struct razer_rgb color;
	int count = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,0));
	int dir = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,1));
	int rnd1 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,2));
	int rnd2 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,3));
	int rnd3 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,4));
	int x,y;
	for(x=0;x<22;x++)
		for(y=0;y<6;y++)
		{
			color.r = (count+x)*(255/22);
			color.g = (count-x)*(255/22);
			color.b = (count-y)*(255/6);
			rgb_mix_into(&render->output_frame->rows[y].column[x],&render->input_frame->rows[y].column[x],&color,render->opacity);
			render->output_frame->update_mask |= 1<<y;
		}
		count+=dir;
		if(count<=0 || count>=440)
		{
		dir=-dir;
		rnd1 = random();
		rnd2 = random();
		rnd3 = random();
	}
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,0),count);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,1),dir);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,2),rnd1);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,3),rnd2);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,4),rnd3);	
	return(1);
}
int effect4_update(struct razer_fx_render_node *render)
{
	struct razer_rgb color;
	int v1 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,0));
	int v1_dir = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,1));
	int v2 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,2));
	int v2_dir = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,3));
	int v3 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,4));
	int v3_dir = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,5));
	int rnd1 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,6));
	int rnd2 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,7));
	int rnd3 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,8));
	int x,y;
	#ifdef USE_DEBUGGING
		printf(" (Random ## v1:%d,v1dir:%d,v2:%d,v2dir:%d,v3:%d,v3dir:%d)",v1,v1_dir,v2,v2_dir,v3,v3_dir);
	#endif
	for(x=0;x<22;x++)
		for(y=0;y<6;y++)
		{
			color.r = (unsigned char)v1-v1*sin(y)+cos(x);
			color.g = (unsigned char)v2-v2*cos(y)-x;
			color.b = (unsigned char)v3-v3*sin(x);
			rgb_mix_into(&render->output_frame->rows[y].column[x],&render->input_frame->rows[y].column[x],&color,render->opacity);
			render->output_frame->update_mask |= 1<<y;
		}
	if((v1+v1_dir*rnd1)>=255 || (v1+v1_dir*rnd1)<=0)
	{
		v1_dir=-v1_dir;
		rnd1=(random()%3)+1;
	}
	if((v2+v2_dir*rnd2)>=255 || (v2+v2_dir*rnd2)<=0)
	{
		v2_dir=-v2_dir;
		rnd2=(random()%3)+1;
	}
	if((v3+v3_dir*rnd3)>=255 || (v3+v3_dir*rnd3)<=0)
	{
		v3_dir=-v3_dir;
		rnd3=(random()%3)+1;
	}

	v1=v1+v1_dir*rnd1;
	v2=v2+v2_dir*rnd2;
	v3=v3+v3_dir*rnd3;
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,0),v1);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,1),v1_dir);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,2),v2);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,3),v2_dir);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,4),v3);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,5),v3_dir);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,6),rnd1);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,7),rnd2);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,8),rnd3);	
	return(1);
}
int effectmix1_update(struct razer_fx_render_node *render)
{
	int x,y;
	for(x=0;x<22;x++)
		for(y=0;y<6;y++)
		{
			rgb_mix_into(&render->output_frame->rows[y].column[x],&render->input_frame->rows[y].column[x],&render->second_input_frame->rows[y].column[x],render->opacity);
			render->output_frame->update_mask |= 1<<y;
		}
	return(1);
}
void razer_mix_frames(struct razer_rgb_frame *dst_frame,struct razer_rgb_frame *src_frame,float opacity)
{
	int x,y;
	for(y=0;y<6;y++)
		for(x=0;x<22;x++)
		{
			//rgb_mix_into(&dst_frame->rows[y].column[x],&dst_frame->rows[y].column[x],&src_frame->rows[y].column[x],opacity);
			rgb_mix_into(&dst_frame->rows[y].column[x],&src_frame->rows[y].column[x],&dst_frame->rows[y].column[x],opacity);
		}
	dst_frame->update_mask = 63;
}
int effect_mix_update(struct razer_fx_render_node *render)
{
	int x,y;
	#ifdef USE_DEBUGGING
		printf(" (Mixer::Basic.%d ## opacity:%f / %d,%d)",render->id,render->opacity,render->input_frame_linked_uid,render->second_input_frame_linked_uid);
	#endif
	//render->opacity = 0.5f;
	for(x=0;x<render->device->columns_num;x++)
		for(y=0;y<render->device->rows_num;y++)
		{
			rgb_mix_into(&render->output_frame->rows[y]->column[x],&render->input_frame->rows[y]->column[x],&render->second_input_frame->rows[y]->column[x],render->opacity);
			render->output_frame->update_mask |= 1<<y;
		}
	return(1);
}
int effect_glimmer_update(struct razer_fx_render_node *render)
{
	int x,y;
	#ifdef USE_DEBUGGING
		printf(" (Mixer::Glimmer.%d ## opacity:%f / %d,%d)",render->id,render->opacity,render->input_frame_linked_uid,render->second_input_frame_linked_uid);
	#endif
	//render->opacity = 0.5f;
	for(x=0;x<render->device->columns_num;x++)
		for(y=0;y<render->device->rows_num;y++)
		{
			float pixel_opacity = render->opacity + ((((float)(random()%1000))/1000.0f)-(render->opacity*0.5f));
			//float pixel_opacity = ((((float)(random()%1000))/1000.0f));

			rgb_mix_into(&render->output_frame->rows[y]->column[x],&render->input_frame->rows[y]->column[x],&render->second_input_frame->rows[y]->column[x],pixel_opacity);
			render->output_frame->update_mask |= 1<<y;
		}
	return(1);
}
int effect3_update(struct razer_fx_render_node *render)
{
	struct razer_rgb color;
	int count = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,0));
	int dir = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,1));
	int rnd1 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,2));
	int rnd2 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,3));
	int rnd3 = daemon_get_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,4));
	int x,y;
	float s = 0.1f;
	#ifdef USE_DEBUGGING
		printf(" (Wave ## count:%d,dir:%d)",count,dir);
	#endif
	for(x=0;x<22;x++)
	{
		for(y=0;y<6;y++)
		{
			color.r = (cos((count+((rnd1%4)*90)+y)*s)+sin(count+x)*s)*255;
			color.g = (cos((count+((rnd2%4)*90)+y)*s)+sin(count+x)*s)*255;
			color.b = (cos((count+((rnd3%4)*90)+y)*s)+sin(count+x)*s)*255;
			rgb_mix_into(&render->output_frame->rows[y].column[x],&render->input_frame->rows[y].column[x],&color,render->opacity);
			render->output_frame->update_mask |= 1<<y;
		}
	}
	count+=dir;
	if(count<=0 || count>=30)
	{
		dir=-dir;
		rnd1 = random();
		rnd2 = random();
		rnd3 = random();
	}
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,0),count);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,1),dir);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,2),rnd1);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,3),rnd2);	
	daemon_set_parameter_int(daemon_get_parameter_by_index(render->effect->parameters,4),rnd3);	
	return(1);
}
int effect_update(struct razer_fx_render_node *render)
{
	float magnitude = daemon_get_parameter_float(daemon_effect_get_parameter_by_index(render->effect,1));
	int x,y;
	struct razer_rgb col;
	#ifdef USE_DEBUGGING
		printf(" (Fft.%d ## %%:%f)",render->id);
	#endif

	unsigned long samples_left=0;
	while((samples_left=wav_samples_left(effect_input_file)))
	{
		unsigned int sample = read_wav_stereo_sample(effect_input_file);
		short high = sample >> 16;
		short low = sample & 0xFFFF;
		//add sample to fft buffer
		effect_fft_in[effect_fft_samples_used][0] = (double)high * effect_fft_hamming_buffer[effect_fft_samples_used];///(double)32768;//* windowHanning(step++, N);
  		effect_fft_in[effect_fft_samples_used++][1] = 0.0f;
		//enough samples gathered?
		if(effect_fft_samples_used==effect_fft_samples)
  		{
  			printf("Computing fft, still %d samples left\n",samples_left);
			//compute fft
    		effect_fft_plan = fftw_plan_dft_1d(effect_fft_samples, effect_fft_in, effect_fft_out, FFTW_FORWARD, FFTW_ESTIMATE);
    		fftw_execute(effect_fft_plan);
    		fftw_destroy_plan(effect_fft_plan);
    		effect_fft_samples_used = 0;
 		    double tmp_magnitude = sqrt(effect_fft_out[0][0]*effect_fft_out[0][0] + effect_fft_out[0][1]*effect_fft_out[0][1]);
		    tmp_magnitude = 10./log(10.) * log(tmp_magnitude + 1e-6);
    		printf("new fft mag db:%f\n",tmp_magnitude);
    		double sum = 0.0f;
    		for(int i=0;i<effect_fft_samples/2;i++)
    		{
	 		    double tmp_bin_magnitude = sqrt(effect_fft_out[i][0]*effect_fft_out[i][0] + effect_fft_out[i][1]*effect_fft_out[i][1]);
			    tmp_bin_magnitude = 10./log(10.) * log(tmp_bin_magnitude + 1e-6);
			    sum += tmp_bin_magnitude;
    		}
    		printf("sum:%f\n",sum/(effect_fft_samples/2));
    		magnitude = (float)tmp_magnitude - 50.0f;
    		break;
  		}
	}
	if(!samples_left)
	{
		#ifdef USE_DEBUGGING
			printf("no samples left to analyze, closing input file\n");
		#endif
		close_wav(effect_input_file);
		effect_input_file = NULL;
		return(0);
	}


	//set color to avg magnitude ,transformed to 0.0-1.0 space	

	//calculate hue from magnitude
	rgb_from_hue(magnitude/96,0.3f,0.0f,&col);

	for(x=0;x<22;x++)
		for(y=0;y<6;y++)
		{
			rgb_mix_into(&render->output_frame->rows[y].column[x],&render->input_frame->rows[y].column[x],&col,render->opacity);//*render->opacity  //&render->second_input_frame->rows[y].column[x]
			render->output_frame->update_mask |= 1<<y;
		}
	daemon_set_parameter_float(daemon_effect_get_parameter_by_index(render->effect,1),magnitude);	
	return(1);
}
int effect_random_col_update(struct razer_fx_render_node *render)
{
	int length_ms = daemon_get_parameter_int(daemon_effect_get_parameter_by_index(render->effect,0));
	int par_index = daemon_get_parameter_int(daemon_effect_get_parameter_by_index(render->effect,1));
	if(par_index == -1)
		return(0);
	int randomize_now = daemon_get_parameter_int(daemon_effect_get_parameter_by_index(render->effect,2));
	struct razer_rgb *dst_color = daemon_get_parameter_rgb(daemon_effect_get_parameter_by_index(render->effect,3));
	struct razer_rgb *src_color = daemon_get_parameter_rgb(daemon_effect_get_parameter_by_index(render->effect,4));
	if(randomize_now)
	{
		struct razer_rgb *org_color = NULL;
		if(render->parent) 
		{
			org_color = daemon_get_parameter_rgb(daemon_effect_get_parameter_by_index(render->parent->effect,par_index));
		}
		if(org_color)
		{
			src_color->r = org_color->r;
			src_color->g = org_color->g;
			src_color->b = org_color->b;
		}

		dst_color->r = random() % 256;
		dst_color->g = random() % 256;
		dst_color->b = random() % 256;
		daemon_set_parameter_rgb(daemon_effect_get_parameter_by_index(render->effect,3),dst_color);	
		daemon_set_parameter_rgb(daemon_effect_get_parameter_by_index(render->effect,4),src_color);	
		randomize_now = 0;
	}
	unsigned long start = render->start_ticks;
	unsigned long end = start + length_ms;
	unsigned long ticks_left = end - render->daemon->chroma->update_ms;
	float trans = 0.0f;
	trans = (float)ticks_left / (float)length_ms;
	if(end<render->daemon->chroma->update_ms)
	{
		//#ifdef USE_DEBUGGING
		//	printf("\n(Compute::RandomCol.%d ## finished)\n",render->id);
		//#endif
		daemon_set_parameter_rgb(daemon_effect_get_parameter_by_index(render->parent->effect,par_index),dst_color);	
		randomize_now = 1;
		daemon_set_parameter_int(daemon_effect_get_parameter_by_index(render->effect,2),randomize_now);	
		return(0);
	}
	else
	{
		#ifdef USE_DEBUGGING
			printf(" (Compute::RandomCol.%d ## length_ms:%d,trans_color:%d,%d,%d,trans:%f)",render->id,length_ms,dst_color->r,dst_color->g,dst_color->b,trans);
		#endif
		if(render->parent) 
		{
			struct razer_rgb trans_color;
			//trans_color.r=dst_color->r*trans;
			rgb_mix_into(&trans_color,dst_color,src_color,trans);
			daemon_set_parameter_rgb(daemon_effect_get_parameter_by_index(render->parent->effect,par_index),&trans_color);	
		}
	}


	daemon_set_parameter_int(daemon_effect_get_parameter_by_index(render->effect,2),randomize_now);	
	return(1);
}