ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
main.c File Reference
#include "../ckb/ckb-anim.h"
#include <math.h>
#include <stdlib.h>
#include <time.h>
+ Include dependency graph for main.c:

Go to the source code of this file.

Data Structures

struct  rgb
 

Functions

void ckb_info ()
 
void ckb_parameter (ckb_runctx *context, const char *name, const char *value)
 
void ckb_keypress (ckb_runctx *context, ckb_key *key, int x, int y, int state)
 
void newtarget (rgb *data, unsigned count)
 
void ckb_init (ckb_runctx *context)
 
void ckb_start (ckb_runctx *context, int state)
 
void ckb_time (ckb_runctx *context, double delta)
 
int ckb_frame (ckb_runctx *context)
 

Variables

int fadein = 0
 
int useopacity = 0
 
rgbcurrent = 0
 
rgbtarget = 0
 
double phase = -1.
 

Data Structure Documentation

struct rgb

Definition at line 42 of file main.c.

+ Collaboration diagram for rgb:
Data Fields
unsigned char a
unsigned char b
unsigned char g
unsigned char r

Function Documentation

int ckb_frame ( ckb_runctx context)

Definition at line 109 of file main.c.

References ckb_key::a, ckb_key::b, CKB_KEYCLEAR, ckb_key::g, ckb_runctx::keycount, ckb_runctx::keys, phase, and ckb_key::r.

109  {
110  if(phase < 0.){
111  CKB_KEYCLEAR(context);
112  return 0;
113  }
114  ckb_key* keys = context->keys;
115  unsigned count = context->keycount;
116  for(unsigned i = 0; i < count; i++){
117  // Color each key according to the position between the last color set and the new color set
118  ckb_key* key = keys + i;
119  key->a = round(current[i].a * (1. - phase) + target[i].a * phase);
120  key->r = round(current[i].r * (1. - phase) + target[i].r * phase);
121  key->g = round(current[i].g * (1. - phase) + target[i].g * phase);
122  key->b = round(current[i].b * (1. - phase) + target[i].b * phase);
123  }
124  return 0;
125 }
rgb * current
Definition: main.c:46
unsigned char g
Definition: ckb-anim.h:134
rgb * target
Definition: main.c:47
unsigned char b
Definition: ckb-anim.h:134
unsigned char r
Definition: ckb-anim.h:134
unsigned char a
Definition: ckb-anim.h:134
Definition: keymap.h:49
double phase
Definition: main.c:48
unsigned keycount
Definition: ckb-anim.h:141
#define CKB_KEYCLEAR(context)
Definition: ckb-anim.h:148
ckb_key * keys
Definition: ckb-anim.h:140
void ckb_info ( )

Definition at line 6 of file main.c.

References CKB_COPYRIGHT, CKB_DESCRIPTION, CKB_GUID, CKB_KP_NONE, CKB_KPMODE, CKB_LICENSE, CKB_LIVEPARAMS, CKB_NAME, CKB_PARAM_BOOL, CKB_PRESET_END, CKB_PRESET_PARAM, CKB_PRESET_START, CKB_REPEAT, CKB_TIME_DURATION, CKB_TIMEMODE, CKB_VERSION, FALSE, and TRUE.

6  {
7  // Plugin info
8  CKB_NAME("Random");
9  CKB_VERSION("0.9");
10  CKB_COPYRIGHT("2014-2016", "MSC");
11  CKB_LICENSE("GPLv2");
12  CKB_GUID("{22418DA4-A181-4B93-A4D3-03682BA283D2}");
13  CKB_DESCRIPTION("An effect that changes key colors randomly.");
14 
15  // Effect parameters
16  CKB_PARAM_BOOL("fade", "Fade in", 0);
17  CKB_PARAM_BOOL("useopacity", "Randomize opacity", 0);
18 
19  // Timing/input parameters
24 
25  // Presets
26  CKB_PRESET_START("Default");
27  CKB_PRESET_PARAM("duration", "1.");
29 }
#define CKB_PRESET_END
Definition: ckb-anim.h:87
#define FALSE
Definition: ckb-anim.h:49
#define CKB_VERSION(version)
Definition: ckb-anim.h:64
#define CKB_TIMEMODE(mode)
Definition: ckb-anim.h:97
#define TRUE
Definition: ckb-anim.h:46
#define CKB_GUID(guid)
Definition: ckb-anim.h:60
#define CKB_NAME(name)
Definition: ckb-anim.h:62
#define CKB_KP_NONE
Definition: ckb-anim.h:90
#define CKB_LICENSE(license)
Definition: ckb-anim.h:68
#define CKB_COPYRIGHT(year, author)
Definition: ckb-anim.h:66
#define CKB_DESCRIPTION(description)
Definition: ckb-anim.h:70
#define CKB_PRESET_START(name)
Definition: ckb-anim.h:85
#define CKB_KPMODE(mode)
Definition: ckb-anim.h:93
#define CKB_LIVEPARAMS(enable)
Definition: ckb-anim.h:104
#define CKB_TIME_DURATION
Definition: ckb-anim.h:95
#define CKB_REPEAT(enable)
Definition: ckb-anim.h:99
#define CKB_PRESET_PARAM(name, value)
Definition: ckb-anim.h:86
#define CKB_PARAM_BOOL(name, text, default)
Definition: ckb-anim.h:76
void ckb_init ( ckb_runctx context)

Definition at line 61 of file main.c.

References ckb_runctx::keycount.

61  {
62  unsigned count = context->keycount;
63  current = malloc(count * sizeof(rgb));
64  target = malloc(count * sizeof(rgb));
65  srand(time(NULL));
66 }
rgb * current
Definition: main.c:46
rgb * target
Definition: main.c:47
unsigned keycount
Definition: ckb-anim.h:141
Definition: main.c:42
void ckb_keypress ( ckb_runctx context,
ckb_key key,
int  x,
int  y,
int  state 
)

Definition at line 38 of file main.c.

38  {
39  // Unused
40 }
void ckb_parameter ( ckb_runctx context,
const char *  name,
const char *  value 
)

Definition at line 33 of file main.c.

References CKB_PARSE_BOOL, fadein, and useopacity.

33  {
34  CKB_PARSE_BOOL("fade", &fadein) {}
35  CKB_PARSE_BOOL("useopacity", &useopacity) {}
36 }
int useopacity
Definition: main.c:31
int fadein
Definition: main.c:31
#define CKB_PARSE_BOOL(param_name, value_ptr)
Definition: ckb-anim.h:117
void ckb_start ( ckb_runctx context,
int  state 
)

Definition at line 68 of file main.c.

References rgb::a, ckb_key::a, rgb::b, ckb_key::b, fadein, rgb::g, ckb_key::g, ckb_runctx::keycount, ckb_runctx::keys, newtarget(), phase, rgb::r, and ckb_key::r.

68  {
69  if(state == 0){
70  // Stop animation
71  phase = -1.;
72  return;
73  }
74  // Start animation
75  phase = 0.;
76  ckb_key* keys = context->keys;
77  unsigned count = context->keycount;
78  // Randomize starting colors and pick a random target
79  newtarget(current, count);
80  // Over the course of the animation, the keys fade between the current pattern and the target pattern
81  newtarget(target, count);
82  // Set all keys to current
83  for(unsigned i = 0; i < count; i++){
84  ckb_key* key = keys + i;
85  if(fadein)
86  current[i].a = 0;
87  key->a = current[i].a;
88  key->r = current[i].r;
89  key->g = current[i].g;
90  key->b = current[i].b;
91  }
92 }
unsigned char b
Definition: main.c:43
rgb * current
Definition: main.c:46
unsigned char r
Definition: main.c:43
unsigned char g
Definition: ckb-anim.h:134
rgb * target
Definition: main.c:47
unsigned char b
Definition: ckb-anim.h:134
unsigned char r
Definition: ckb-anim.h:134
unsigned char a
Definition: ckb-anim.h:134
Definition: keymap.h:49
int fadein
Definition: main.c:31
double phase
Definition: main.c:48
unsigned keycount
Definition: ckb-anim.h:141
void newtarget(rgb *data, unsigned count)
Definition: main.c:51
unsigned char a
Definition: main.c:43
ckb_key * keys
Definition: ckb-anim.h:140
unsigned char g
Definition: main.c:43

+ Here is the call graph for this function:

void ckb_time ( ckb_runctx context,
double  delta 
)

Definition at line 94 of file main.c.

References current, ckb_runctx::keycount, newtarget(), phase, and target.

94  {
95  if(phase < 0.)
96  return;
97  // Advance animation
98  phase += delta;
99  if(phase > 1.){
100  // If the animation is complete, pick a new target pattern and start again
101  phase -= 1.;
102  rgb* temp = target;
103  target = current;
104  current = temp;
105  newtarget(target, context->keycount);
106  }
107 }
rgb * current
Definition: main.c:46
rgb * target
Definition: main.c:47
double phase
Definition: main.c:48
unsigned keycount
Definition: ckb-anim.h:141
Definition: main.c:42
void newtarget(rgb *data, unsigned count)
Definition: main.c:51

+ Here is the call graph for this function:

void newtarget ( rgb data,
unsigned  count 
)

Definition at line 51 of file main.c.

References rgb::a, rgb::b, rgb::g, rgb::r, and useopacity.

Referenced by ckb_start(), and ckb_time().

51  {
52  for(unsigned i = 0; i < count; i++){
53  rgb* key = data + i;
54  key->a = useopacity ? rand() % 256 : 255;
55  key->r = rand() % 256;
56  key->g = rand() % 256;
57  key->b = rand() % 256;
58  }
59 }
unsigned char b
Definition: main.c:43
unsigned char r
Definition: main.c:43
int useopacity
Definition: main.c:31
Definition: keymap.h:49
Definition: main.c:42
unsigned char a
Definition: main.c:43
unsigned char g
Definition: main.c:43

+ Here is the caller graph for this function:

Variable Documentation

int fadein = 0

Definition at line 31 of file main.c.

Referenced by ckb_parameter(), and ckb_start().

double phase = -1.

Definition at line 48 of file main.c.

Referenced by ckb_frame(), ckb_start(), ckb_time(), kiss_fft_alloc(), and kiss_fftr_alloc().

rgb* target = 0

Definition at line 47 of file main.c.

Referenced by ckb_time().

int useopacity = 0

Definition at line 31 of file main.c.

Referenced by ckb_parameter(), and newtarget().