Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit 8361ab4

Browse files
committed
Merge branch 'newfx' of https://github.com/ccMSC/ckb into newfx
2 parents 2fa219f + 5ad68f3 commit 8361ab4

File tree

11 files changed

+1221
-1
lines changed

11 files changed

+1221
-1
lines changed

Diff for: ckb.pro

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@ SUBDIRS = \
88
src/ckb-gradient \
99
src/ckb-pinwheel \
1010
src/ckb-random \
11-
src/ckb-rain
11+
src/ckb-rain \
12+
src/ckb-heat
13+
14+
# Music visualizer requires Pulseaudio libraries
15+
linux {
16+
system(pkg-config --exists libpulse) {
17+
SUBDIRS += src/ckb-mviz
18+
}
19+
}

Diff for: src/ckb-heat/ckb-heat.pro

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
TEMPLATE = app
2+
TARGET = ckb-heat
3+
4+
QMAKE_CFLAGS += -std=c99
5+
QMAKE_MAC_SDK = macosx10.10
6+
7+
macx {
8+
DESTDIR = $$PWD/../../ckb.app/Contents/Resources/ckb-animations
9+
} else {
10+
DESTDIR = $$PWD/../../bin/ckb-animations
11+
}
12+
13+
CONFIG =
14+
QT =
15+
LIBS =
16+
17+
SOURCES += \
18+
main.c

Diff for: src/ckb-heat/main.c

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include "../ckb/ckb-anim.h"
2+
#include <math.h>
3+
4+
void ckb_info(){
5+
// Plugin info
6+
CKB_NAME("Heat Map");
7+
CKB_VERSION("0.2");
8+
CKB_COPYRIGHT("2015", "RULER501");
9+
CKB_LICENSE("LGPLv3");
10+
CKB_GUID("{097D69F0-70B2-48B8-AFE2-25A1CDB0D92C}");
11+
CKB_DESCRIPTION("A spot effect on pressed keys that shows usage");
12+
13+
// Effect parameters
14+
CKB_PARAM_AGRADIENT("color", "Fade color:", "", "ffffffff");
15+
CKB_PARAM_BOOL("random", "Random Brightness", 0);
16+
CKB_PARAM_LONG("ffade", "Frames to fade", "frames", 30, 10, 1000);
17+
CKB_PARAM_DOUBLE("pressestofull", "Presses to full", "keypresses", 10.f, 1.f, 100.f);
18+
19+
// Timing/input parameters
20+
CKB_KPMODE(CKB_KP_POSITION);
21+
CKB_TIMEMODE(CKB_TIME_ABSOLUTE);
22+
CKB_REPEAT(FALSE);
23+
CKB_LIVEPARAMS(TRUE);
24+
25+
// Presets
26+
CKB_PRESET_START("Single Spot");
27+
CKB_PRESET_PARAM("random", "0");
28+
CKB_PRESET_PARAM("ffade", "30");
29+
CKB_PRESET_PARAM("pressestofull", "10");
30+
CKB_PRESET_PARAM("trigger", "0");
31+
CKB_PRESET_PARAM("kptrigger", "1");
32+
CKB_PRESET_END;
33+
}
34+
35+
ckb_gradient animcolor = { 0 };
36+
int randomBright = 0;
37+
long ffade = 30;
38+
double pressestofull = 10.f;
39+
40+
typedef struct{
41+
int usages;
42+
int pressed;
43+
double timing;
44+
int x;
45+
int y;
46+
} keyanim;
47+
48+
keyanim* anims = NULL;
49+
50+
void ckb_init(ckb_runctx* context){
51+
anims = calloc(context->keycount, sizeof(keyanim));
52+
for(int i=0; i < context->keycount; i++){
53+
anims[i].x = context->keys[i].x;
54+
anims[i].y = context->keys[i].y;
55+
}
56+
}
57+
58+
void ckb_parameter(ckb_runctx* context, const char* name, const char* value){
59+
CKB_PARSE_AGRADIENT("color", &animcolor){}
60+
CKB_PARSE_BOOL("random", &randomBright){}
61+
CKB_PARSE_LONG("ffade", &ffade){}
62+
CKB_PARSE_DOUBLE("pressestofull", &pressestofull){}
63+
}
64+
65+
void anim_add(int index){
66+
anims[index].usages += ffade;
67+
anims[index].pressed = 1;
68+
anims[index].timing = 0.f;
69+
}
70+
71+
void anim_remove(int index){
72+
anims[index].pressed = 0;
73+
}
74+
75+
void ckb_keypress(ckb_runctx* context, ckb_key* key, int x, int y, int state){
76+
// Add or remove a spot on this key
77+
if(state)
78+
anim_add(key - context->keys);
79+
else
80+
anim_remove(key - context->keys);
81+
}
82+
83+
void ckb_start(ckb_runctx* context, int state){
84+
return;
85+
}
86+
87+
void ckb_time(ckb_runctx* context, double delta){
88+
unsigned int count = context->keycount;
89+
for(unsigned int i=0; i < count; i++){
90+
if(anims[i].usages && !anims[i].pressed){
91+
anims[i].timing -= delta;
92+
while(anims[i].timing < 0){
93+
anims[i].timing += 1.f/30.f;
94+
anims[i].usages--;
95+
}
96+
}
97+
}
98+
}
99+
100+
inline int max(int a, int b){
101+
return a < b ? b : a;
102+
}
103+
104+
inline int min(int a, int b){
105+
return a < b ? a : b;
106+
}
107+
108+
int ckb_frame(ckb_runctx* context){
109+
CKB_KEYCLEAR(context);
110+
// Draw spots
111+
unsigned count = context->keycount;
112+
ckb_key* keys = context->keys;
113+
unsigned int full = pressestofull*ffade;
114+
for(int i =0; i < count; i++){
115+
if(!anims[i].usages)
116+
continue;
117+
float a, r, g, b;
118+
if(randomBright)
119+
ckb_grad_color(&a, &r, &g, &b, &animcolor, ((float)(rand() % 1024))/10.f);
120+
else
121+
ckb_grad_color(&a, &r, &g, &b, &animcolor, (float)min(anims[i].usages,full)*100.f/full);
122+
ckb_alpha_blend(keys+i, a, r, g, b);
123+
}
124+
return 0;
125+
}

Diff for: src/ckb-mviz/COPYING

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Copyright (c) 2003-2010 Mark Borgerding
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10+
11+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Diff for: src/ckb-mviz/_kiss_fft_guts.h

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
Copyright (c) 2003-2010, Mark Borgerding
3+
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10+
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11+
12+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13+
*/
14+
15+
/* kiss_fft.h
16+
defines kiss_fft_scalar as either short or a float type
17+
and defines
18+
typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
19+
#include "kiss_fft.h"
20+
#include <limits.h>
21+
22+
#define MAXFACTORS 32
23+
/* e.g. an fft of length 128 has 4 factors
24+
as far as kissfft is concerned
25+
4*4*4*2
26+
*/
27+
28+
struct kiss_fft_state{
29+
int nfft;
30+
int inverse;
31+
int factors[2*MAXFACTORS];
32+
kiss_fft_cpx twiddles[1];
33+
};
34+
35+
/*
36+
Explanation of macros dealing with complex math:
37+
38+
C_MUL(m,a,b) : m = a*b
39+
C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise
40+
C_SUB( res, a,b) : res = a - b
41+
C_SUBFROM( res , a) : res -= a
42+
C_ADDTO( res , a) : res += a
43+
* */
44+
#ifdef FIXED_POINT
45+
#if (FIXED_POINT==32)
46+
# define FRACBITS 31
47+
# define SAMPPROD int64_t
48+
#define SAMP_MAX 2147483647
49+
#else
50+
# define FRACBITS 15
51+
# define SAMPPROD int32_t
52+
#define SAMP_MAX 32767
53+
#endif
54+
55+
#define SAMP_MIN -SAMP_MAX
56+
57+
#if defined(CHECK_OVERFLOW)
58+
# define CHECK_OVERFLOW_OP(a,op,b) \
59+
if ( (SAMPPROD)(a) op (SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a) op (SAMPPROD)(b) < SAMP_MIN ) { \
60+
fprintf(stderr,"WARNING:overflow @ " __FILE__ "(%d): (%d " #op" %d) = %ld\n",__LINE__,(a),(b),(SAMPPROD)(a) op (SAMPPROD)(b) ); }
61+
#endif
62+
63+
64+
# define smul(a,b) ( (SAMPPROD)(a)*(b) )
65+
# define sround( x ) (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
66+
67+
# define S_MUL(a,b) sround( smul(a,b) )
68+
69+
# define C_MUL(m,a,b) \
70+
do{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \
71+
(m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0)
72+
73+
# define DIVSCALAR(x,k) \
74+
(x) = sround( smul( x, SAMP_MAX/k ) )
75+
76+
# define C_FIXDIV(c,div) \
77+
do { DIVSCALAR( (c).r , div); \
78+
DIVSCALAR( (c).i , div); }while (0)
79+
80+
# define C_MULBYSCALAR( c, s ) \
81+
do{ (c).r = sround( smul( (c).r , s ) ) ;\
82+
(c).i = sround( smul( (c).i , s ) ) ; }while(0)
83+
84+
#else /* not FIXED_POINT*/
85+
86+
# define S_MUL(a,b) ( (a)*(b) )
87+
#define C_MUL(m,a,b) \
88+
do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
89+
(m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
90+
# define C_FIXDIV(c,div) /* NOOP */
91+
# define C_MULBYSCALAR( c, s ) \
92+
do{ (c).r *= (s);\
93+
(c).i *= (s); }while(0)
94+
#endif
95+
96+
#ifndef CHECK_OVERFLOW_OP
97+
# define CHECK_OVERFLOW_OP(a,op,b) /* noop */
98+
#endif
99+
100+
#define C_ADD( res, a,b)\
101+
do { \
102+
CHECK_OVERFLOW_OP((a).r,+,(b).r)\
103+
CHECK_OVERFLOW_OP((a).i,+,(b).i)\
104+
(res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \
105+
}while(0)
106+
#define C_SUB( res, a,b)\
107+
do { \
108+
CHECK_OVERFLOW_OP((a).r,-,(b).r)\
109+
CHECK_OVERFLOW_OP((a).i,-,(b).i)\
110+
(res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \
111+
}while(0)
112+
#define C_ADDTO( res , a)\
113+
do { \
114+
CHECK_OVERFLOW_OP((res).r,+,(a).r)\
115+
CHECK_OVERFLOW_OP((res).i,+,(a).i)\
116+
(res).r += (a).r; (res).i += (a).i;\
117+
}while(0)
118+
119+
#define C_SUBFROM( res , a)\
120+
do {\
121+
CHECK_OVERFLOW_OP((res).r,-,(a).r)\
122+
CHECK_OVERFLOW_OP((res).i,-,(a).i)\
123+
(res).r -= (a).r; (res).i -= (a).i; \
124+
}while(0)
125+
126+
127+
#ifdef FIXED_POINT
128+
# define KISS_FFT_COS(phase) floor(.5+SAMP_MAX * cos (phase))
129+
# define KISS_FFT_SIN(phase) floor(.5+SAMP_MAX * sin (phase))
130+
# define HALF_OF(x) ((x)>>1)
131+
#elif defined(USE_SIMD)
132+
# define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) )
133+
# define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) )
134+
# define HALF_OF(x) ((x)*_mm_set1_ps(.5))
135+
#else
136+
# define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase)
137+
# define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase)
138+
# define HALF_OF(x) ((x)*.5)
139+
#endif
140+
141+
#define kf_cexp(x,phase) \
142+
do{ \
143+
(x)->r = KISS_FFT_COS(phase);\
144+
(x)->i = KISS_FFT_SIN(phase);\
145+
}while(0)
146+
147+
148+
/* a debugging function */
149+
#define pcpx(c)\
150+
fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) )
151+
152+
153+
#ifdef KISS_FFT_USE_ALLOCA
154+
// define this to allow use of alloca instead of malloc for temporary buffers
155+
// Temporary buffers are used in two case:
156+
// 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5
157+
// 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform.
158+
#include <alloca.h>
159+
#define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes)
160+
#define KISS_FFT_TMP_FREE(ptr)
161+
#else
162+
#define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes)
163+
#define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr)
164+
#endif

Diff for: src/ckb-mviz/ckb-mviz.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
TEMPLATE = app
2+
TARGET = ckb-mviz
3+
4+
QMAKE_CFLAGS += -std=c99
5+
QMAKE_MAC_SDK = macosx10.10
6+
QMAKE_LFLAGS += -lpulse-simple
7+
8+
macx {
9+
DESTDIR = $$PWD/../../ckb.app/Contents/Resources/ckb-animations
10+
} else {
11+
DESTDIR = $$PWD/../../bin/ckb-animations
12+
}
13+
14+
CONFIG = debug
15+
QT =
16+
LIBS =
17+
18+
SOURCES += \
19+
main.c \
20+
kiss_fft.c \
21+
kiss_fftr.c

0 commit comments

Comments
 (0)