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 <time.h>
#include <stdio.h>
+ Include dependency graph for main.c:

Go to the source code of this file.

Data Structures

struct  keyAnim
 

Macros

#define NONE   -1.f
 
#define HOLD   -2.f
 

Functions

void ckb_info ()
 
void ckb_init (ckb_runctx *context)
 
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 ckb_start (ckb_runctx *context, int state)
 
void ckb_time (ckb_runctx *context, double delta)
 
int ckb_frame (ckb_runctx *context)
 

Variables

ckb_gradient animcolor = { 0 }
 
int kphold = 0
 
int kprelease = 0
 
int randomize = 0
 
struct keyAnimanim
 

Data Structure Documentation

struct keyAnim

Definition at line 47 of file main.c.

+ Collaboration diagram for keyAnim:
Data Fields
ckb_gradient gradient
float target

Macro Definition Documentation

#define HOLD   -2.f

Definition at line 45 of file main.c.

Referenced by ckb_frame(), and ckb_keypress().

#define NONE   -1.f

Definition at line 44 of file main.c.

Referenced by ckb_init(), ckb_keypress(), and ckb_start().

Function Documentation

int ckb_frame ( ckb_runctx context)

Definition at line 137 of file main.c.

References ckb_key::a, animcolor, ckb_key::b, ckb_grad_color(), ckb_key::g, keyAnim::gradient, HOLD, ckb_runctx::keycount, ckb_runctx::keys, phase, ckb_key::r, randomize, and keyAnim::target.

137  {
138  // Draw key colors
139  unsigned count = context->keycount;
140  for(unsigned i = 0; i < count; i++){
141  float phase = anim[i].target;
142 
143  if(phase == HOLD)
144  phase = 0.f;
145  else if(phase < 0.f)
146  phase = 1.f;
147  ckb_key* key = context->keys + i;
148  float a, r, g, b;
149  ckb_gradient thisGradient;
150  if (randomize) {
151  thisGradient = anim[i].gradient;
152  } else {
153  thisGradient = animcolor;
154  }
155  ckb_grad_color(&a, &r, &g, &b, &thisGradient, phase * 100.);
156  key->a = a;
157  key->r = r;
158  key->g = g;
159  key->b = b;
160  }
161  return 0;
162 }
unsigned char g
Definition: ckb-anim.h:134
ckb_gradient gradient
Definition: main.c:49
ckb_gradient animcolor
Definition: main.c:52
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
int randomize
Definition: main.c:53
float target
Definition: main.c:48
ckb_key * keys
Definition: ckb-anim.h:140
#define HOLD
Definition: main.c:45
void ckb_grad_color(float *a, float *r, float *g, float *b, const ckb_gradient *grad, float pos)
Definition: ckb-anim.h:254
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

void ckb_info ( )

Definition at line 5 of file main.c.

References CKB_COPYRIGHT, CKB_DESCRIPTION, CKB_GUID, CKB_KP_NAME, CKB_KPMODE, CKB_LICENSE, CKB_LIVEPARAMS, CKB_NAME, CKB_PARAM_AGRADIENT, CKB_PARAM_BOOL, CKB_PRESET_END, CKB_PRESET_PARAM, CKB_PRESET_START, CKB_TIME_DURATION, CKB_TIMEMODE, CKB_VERSION, and TRUE.

Referenced by main(), and quitWithLock().

5  {
6  // Plugin info
7  CKB_NAME("Gradient");
8  CKB_VERSION("0.9");
9  CKB_COPYRIGHT("2014-2016", "MSC");
10  CKB_LICENSE("GPLv2");
11  CKB_GUID("{54DD2975-E192-457D-BCFC-D912A24E33B4}");
12  CKB_DESCRIPTION("A transition from one color to another.");
13 
14  // Effect parameters
15  CKB_PARAM_AGRADIENT("color", "Color:", "", "ffffffff");
16  CKB_PARAM_BOOL("kphold", "Freeze until key is released", TRUE);
17  CKB_PARAM_BOOL("randomize", "Randomly select from gradient", 0);
18 
19  // Timing/input parameters
23 
24  // Presets
25  CKB_PRESET_START("Fade in");
26  CKB_PRESET_PARAM("color", "ff000000");
27  CKB_PRESET_PARAM("duration", "1.0");
28  CKB_PRESET_PARAM("stop", "0");
29  CKB_PRESET_PARAM("kpstop", "0");
31 
32  CKB_PRESET_START("Rainbow");
33  CKB_PRESET_PARAM("color", "0:ffff0000 17:ffffff00 33:ff00ff00 50:ff00ffff 67:ff0000ff 83:ffff00ff 100:ffff0000");
34  CKB_PRESET_PARAM("duration", "2.0");
36 
37  CKB_PRESET_START("Type lighting");
38  CKB_PRESET_PARAM("duration", "1.0");
39  CKB_PRESET_PARAM("trigger", "0");
40  CKB_PRESET_PARAM("kptrigger", "1");
42 }
#define CKB_PRESET_END
Definition: ckb-anim.h:87
#define CKB_VERSION(version)
Definition: ckb-anim.h:64
#define CKB_KP_NAME
Definition: ckb-anim.h:91
#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_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_PARAM_AGRADIENT(name, prefix, postfix, default)
Definition: ckb-anim.h:80
#define CKB_LIVEPARAMS(enable)
Definition: ckb-anim.h:104
#define CKB_TIME_DURATION
Definition: ckb-anim.h:95
#define CKB_PRESET_PARAM(name, value)
Definition: ckb-anim.h:86
#define CKB_PARAM_BOOL(name, text, default)
Definition: ckb-anim.h:76

+ Here is the caller graph for this function:

void ckb_init ( ckb_runctx context)

Definition at line 57 of file main.c.

References ckb_runctx::keycount, and NONE.

57  {
58  // Initialize all keys to 100% (animation over)
59 
60  srand((unsigned)time(NULL));
61  unsigned count = context->keycount;
62  anim = malloc(count * sizeof *anim);
63  for(unsigned i = 0; i < count; i++) {
64  anim[i].target = NONE;
65  }
66 }
unsigned keycount
Definition: ckb-anim.h:141
#define NONE
Definition: main.c:44
float target
Definition: main.c:48
struct keyAnim * anim
Definition: main.c:55
void ckb_keypress ( ckb_runctx context,
ckb_key key,
int  x,
int  y,
int  state 
)

Definition at line 75 of file main.c.

References ckb_gradient::a, ckb_gradient::b, ckb_grad_color(), ckb_gradient::g, keyAnim::gradient, HOLD, ckb_runctx::keys, kphold, kprelease, NONE, ckb_gradient::ptcount, ckb_gradient::pts, ckb_gradient::r, randomize, and keyAnim::target.

75  {
76  // Start or stop animation on key
77  int i = key - context->keys;
78  if(state){
79  if (randomize) {
80  float a, r, g, b;
81  float colorChoice = (float)rand()/(float)(RAND_MAX);
82  ckb_grad_color(&a, &r, &g, &b, &animcolor, colorChoice * 100.);
83  ckb_gradient newGradient = { 0 };
84  newGradient.ptcount = 2;
85  newGradient.pts[0] = 0;
86  newGradient.pts[1] = 100;
87  newGradient.a[0] = 255;
88  newGradient.b[0] = b;
89  newGradient.g[0] = g;
90  newGradient.r[0] = r;
91  newGradient.a[1] = 0;
92  newGradient.b[1] = b;
93  newGradient.g[1] = g;
94  newGradient.r[1] = r;
95 
96  anim[i].gradient = newGradient;
97  }
98 
99  if(kphold) {
100  anim[i].target = HOLD;
101  } else {
102  anim[i].target = 0.f;
103  }
104  } else {
105  if(kprelease) {
106  anim[i].target = NONE;
107  }
108  else if(kphold) {
109  anim[i].target = 0.f;
110  }
111  }
112 }
unsigned char b[100]
Definition: ckb-anim.h:162
char pts[100]
Definition: ckb-anim.h:157
ckb_gradient gradient
Definition: main.c:49
unsigned char g[100]
Definition: ckb-anim.h:161
ckb_gradient animcolor
Definition: main.c:52
unsigned char r[100]
Definition: ckb-anim.h:160
int randomize
Definition: main.c:53
unsigned char a[100]
Definition: ckb-anim.h:159
int kphold
Definition: main.c:53
#define NONE
Definition: main.c:44
float target
Definition: main.c:48
ckb_key * keys
Definition: ckb-anim.h:140
int kprelease
Definition: main.c:53
#define HOLD
Definition: main.c:45
void ckb_grad_color(float *a, float *r, float *g, float *b, const ckb_gradient *grad, float pos)
Definition: ckb-anim.h:254
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

void ckb_parameter ( ckb_runctx context,
const char *  name,
const char *  value 
)

Definition at line 68 of file main.c.

References CKB_PARSE_AGRADIENT, CKB_PARSE_BOOL, kphold, kprelease, and randomize.

68  {
69  CKB_PARSE_AGRADIENT("color", &animcolor){}
70  CKB_PARSE_BOOL("kphold", &kphold){}
71  CKB_PARSE_BOOL("kprelease", &kprelease){}
72  CKB_PARSE_BOOL("randomize", &randomize){}
73 }
ckb_gradient animcolor
Definition: main.c:52
#define CKB_PARSE_AGRADIENT(param_name, gradient_ptr)
Definition: ckb-anim.h:121
int randomize
Definition: main.c:53
int kphold
Definition: main.c:53
#define CKB_PARSE_BOOL(param_name, value_ptr)
Definition: ckb-anim.h:117
int kprelease
Definition: main.c:53
void ckb_start ( ckb_runctx context,
int  state 
)

Definition at line 114 of file main.c.

References ckb_runctx::keycount, NONE, and keyAnim::target.

114  {
115  // Start/stop all keys
116  unsigned count = context->keycount;
117  if(state) {
118  memset(anim, 0, count * sizeof *anim);
119  } else {
120  for(unsigned i = 0; i < count; i++) {
121  anim[i].target = NONE;
122  }
123  }
124 }
unsigned keycount
Definition: ckb-anim.h:141
#define NONE
Definition: main.c:44
float target
Definition: main.c:48
struct keyAnim * anim
Definition: main.c:55
void ckb_time ( ckb_runctx context,
double  delta 
)

Definition at line 126 of file main.c.

References ckb_runctx::keycount, phase, and keyAnim::target.

126  {
127  // Advance animation on each key
128  unsigned count = context->keycount;
129  for(unsigned i = 0; i < count; i++){
130  float phase = anim[i].target;
131  if(phase > 1.f || phase < 0.f)
132  continue;
133  anim[i].target = phase + delta;
134  }
135 }
double phase
Definition: main.c:48
unsigned keycount
Definition: ckb-anim.h:141
float target
Definition: main.c:48
struct keyAnim * anim
Definition: main.c:55

Variable Documentation

ckb_gradient animcolor = { 0 }

Definition at line 52 of file main.c.

Referenced by ckb_frame().

int kphold = 0

Definition at line 53 of file main.c.

Referenced by ckb_keypress(), and ckb_parameter().

int kprelease = 0

Definition at line 53 of file main.c.

Referenced by ckb_keypress(), ckb_parameter(), ckb_start(), and AnimScript::load().

int randomize = 0

Definition at line 53 of file main.c.

Referenced by ckb_frame(), ckb_keypress(), and ckb_parameter().