Compare commits
No commits in common. "aff60df9da0aacbe6a0e5fc10cf4f18d1277f2de" and "50c9a7a6ffabf01de5a2373b0fbd1f15b9b01bd7" have entirely different histories.
aff60df9da
...
50c9a7a6ff
13
Makefile
13
Makefile
@ -1,6 +1,6 @@
|
||||
|
||||
CXXFLAGS := -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L -Wno-narrowing -march=native -flto -Wall -fvisibility=hidden -fPIC -msse4 -I./ -I/usr/local/include/sail -L/usr/local/lib `pkg-config --cflags pango opus libv4l2` '-Wl,-rpath,$$ORIGIN' -Wno-multichar
|
||||
LDFLAGS := -lwebm -lpng -lvpx -lsail -lsail-manip `pkg-config --libs pango opus libv4l2` -lportaudio -lXtst -lrtmp -lfdk-aac -leebie -lscreen_capture_lite_shared
|
||||
CXXFLAGS := -D_POSIX_C_SOURCE=200809L -Wno-narrowing -march=native -flto -Wall -fvisibility=hidden -fPIC -msse4 -I./ -I/usr/local/include/sail `pkg-config --cflags pango opus libv4l2` '-Wl,-rpath,$$ORIGIN' -Wno-multichar
|
||||
LDFLAGS := -lwebm -lpng -lvpx -lsail -lsail-manip `pkg-config --libs pango opus libv4l2` -lportaudio -lXtst -lrtmp -lfdk-aac
|
||||
|
||||
ifneq ($(RELEASE),0)
|
||||
CXXFLAGS := $(CXXFLAGS) -O0 -gdwarf-2 -DMTR_ENABLED
|
||||
@ -10,12 +10,12 @@ endif
|
||||
|
||||
all:
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o node.o hi/node.c $(LDFLAGS)
|
||||
$(CXX) $(CXXFLAGS) -std=c++17 -shared -c -o window.o hi/window.cpp $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o window.o hi/window.c $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o microphone.o hi/microphone.c $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o mode.o hi/mode.c $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o img.o hi/img.c $(LDFLAGS)
|
||||
$(CXX) $(CXXFLAGS) -std=c++17 -shared -c -o webmdec.o hi/webmdec.cpp $(LDFLAGS)
|
||||
$(CXX) $(CXXFLAGS) -std=c++17 -shared -c -o webmenc.o hi/webmenc.cpp $(LDFLAGS)
|
||||
$(CXX) $(CXXFLAGS) -std=c++11 -shared -c -o webmdec.o hi/webmdec.cpp $(LDFLAGS)
|
||||
$(CXX) $(CXXFLAGS) -std=c++11 -shared -c -o webmenc.o hi/webmenc.cpp $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o vpxenc.o hi/vpxenc.c $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o opus.o hi/opus.c $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o webcam.o hi/webcam.c $(LDFLAGS)
|
||||
@ -25,7 +25,6 @@ all:
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o rtmp.o hi/rtmp.c $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o aaclc.o hi/aaclc.c $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o mkv.o hi/mkv.c $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -std=c99 -shared -c -o serialize.o hi/serialize.c $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -shared -o libcutihi.so -shared node.o webmdec.o webmenc.o window.o microphone.o mode.o img.o opus.o webcam.o scale.o minitrace.o h264enc.o rtmp.o aaclc.o vpxenc.o mkv.o serialize.o $(LDFLAGS)
|
||||
$(CC) $(CXXFLAGS) -shared -o libcutihi.so -shared node.o webmdec.o webmenc.o window.o microphone.o mode.o img.o opus.o webcam.o scale.o minitrace.o h264enc.o rtmp.o aaclc.o vpxenc.o mkv.o $(LDFLAGS)
|
||||
|
||||
$(CXX) $(CXXFLAGS) -std=c++11 `wx-config --cflags base,adv,core,aui` -o cuticle ui/main.cpp ui/frame.cpp ui/textctrl.cpp ui/timeline.cpp -L./ -lcutihi $(LDFLAGS) `wx-config --libs base,adv,core,aui`
|
||||
|
1
hi/bs.h
1
hi/bs.h
@ -85,7 +85,6 @@ static inline CHiBSFrames *CHi_BS_Grow(CHiBSFrames *bsfs, size_t num) {
|
||||
size_t oldsz = sizeof(*bsfs) + sizeof(CHiBSFrame) * bsfs->count;
|
||||
size_t newsz = sizeof(*bsfs) + sizeof(CHiBSFrame) * (bsfs->count + num);
|
||||
CHiBSFrames *ret = (CHiBSFrames*) realloc(bsfs, newsz);
|
||||
ret->count += num;
|
||||
memset((uint8_t*) ret + oldsz, 0, newsz - oldsz);
|
||||
return ret;
|
||||
}
|
||||
|
3
hi/img.c
3
hi/img.c
@ -2,7 +2,6 @@
|
||||
|
||||
#include<mm_malloc.h>
|
||||
#include<string.h>
|
||||
#include<assert.h>
|
||||
|
||||
CUTIVIS CHiImage* CHi_Image_New(uint8_t bpc, uint8_t channels, uint16_t stride, uint16_t width, uint16_t height, void *data) {
|
||||
CHiImage *img = malloc(sizeof(*img));
|
||||
@ -15,8 +14,6 @@ CUTIVIS CHiImage* CHi_Image_New(uint8_t bpc, uint8_t channels, uint16_t stride,
|
||||
else img->data16 = _mm_malloc(bpc * stride * height, 16);
|
||||
img->owned = !data;
|
||||
|
||||
assert(stride % 16 == 0);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ static int microphone_perform(CHiPubNode *pubn) {
|
||||
size_t width = roundf(CHi_Time_GetDelta(pubn->ng) * 48000.f);
|
||||
do {
|
||||
}while((node->paBufferWriteIdx - node->paBufferReadIdx + pabufsize) % pabufsize < width); // Wait until available
|
||||
CHiImage *ret = CHi_Image_New(2, 1, (2 * width + 15) & ~15, width, 1, NULL);
|
||||
CHiImage *ret = CHi_Image_New(2, 1, 2 * width, width, 1, NULL);
|
||||
if(node->paBufferReadIdx + width >= pabufsize) {
|
||||
memcpy(ret->data16, node->paBuffer + node->paBufferReadIdx, sizeof(*node->paBuffer) * (pabufsize - node->paBufferReadIdx));
|
||||
memcpy(ret->data16 + pabufsize - node->paBufferReadIdx, node->paBuffer, sizeof(*node->paBuffer) * (width - pabufsize + node->paBufferReadIdx));
|
||||
|
9
hi/mkv.c
9
hi/mkv.c
@ -294,14 +294,14 @@ static int muxmkv_perform(CHiPubNode *pubn) {
|
||||
|
||||
struct Internal *this = (void*) pubn;
|
||||
|
||||
if(pubn->sinks[0].linked.to) {
|
||||
if(pubn->sinks[0].data.linked.to) {
|
||||
CHiBSFrames *vp9bs = CHi_Crawl(&pubn->sinks[0])->data.bitstream;
|
||||
if(vp9bs) {
|
||||
this->videoBacklog = CHi_BS_Combine(this->videoBacklog, vp9bs);
|
||||
}
|
||||
}
|
||||
|
||||
if(pubn->sinks[1].linked.to) {
|
||||
if(pubn->sinks[1].data.linked.to) {
|
||||
CHiBSFrames *opus = CHi_Crawl(&pubn->sinks[1])->data.bitstream;
|
||||
if(opus) {
|
||||
this->audioBacklog = CHi_BS_Combine(this->audioBacklog, opus);
|
||||
@ -550,12 +550,12 @@ static int muxmkv_start(CHiPubNode *pubn) {
|
||||
|
||||
int trackNum = 1;
|
||||
|
||||
if(pubn->sinks[0].linked.to) {
|
||||
if(pubn->sinks[0].data.linked.to) {
|
||||
this->videoBacklog = CHi_BS_Empty();
|
||||
this->videoTrack = trackNum++;
|
||||
}
|
||||
|
||||
if(pubn->sinks[1].linked.to) {
|
||||
if(pubn->sinks[1].data.linked.to) {
|
||||
this->audioBacklog = CHi_BS_Empty();
|
||||
this->audioTrack = trackNum++;
|
||||
}
|
||||
@ -563,7 +563,6 @@ static int muxmkv_start(CHiPubNode *pubn) {
|
||||
this->fd = fopen(CHi_Crawl(&pubn->sinks[CUTIHI_MUXWEBM_IN_FILENAME])->data.text, "wb");
|
||||
|
||||
if(!this->fd) {
|
||||
CHi_AddError(pubn, "invalid file", CUTIHI_MUXWEBM_IN_FILENAME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
513
hi/node.c
513
hi/node.c
@ -19,7 +19,55 @@
|
||||
|
||||
#include"linearity.h"
|
||||
|
||||
#include"node_internal.h"
|
||||
static size_t bisect(const void *key, const void *base, size_t nmemb, size_t size, ssize_t(*compar)(const void*, const void*)) {
|
||||
size_t low = 0, high = nmemb;
|
||||
|
||||
while(low < high) {
|
||||
size_t middle = (low + high) / 2;
|
||||
if(compar((const void*) ((uintptr_t) base + size * middle), key) < 0) {
|
||||
low = middle + 1;
|
||||
} else {
|
||||
high = middle;
|
||||
}
|
||||
}
|
||||
|
||||
return low;
|
||||
}
|
||||
|
||||
static ssize_t float_compar(const void *A, const void *B) {
|
||||
float a = *(float*) A;
|
||||
float b = *(float*) B;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
static int adjacencycmp(const void *a, const void *b) {
|
||||
size_t v = (uintptr_t) ((CHiAdjacency*) a)[0] - (uintptr_t) ((CHiAdjacency*) b)[0];
|
||||
return v ? v : (uintptr_t) ((CHiAdjacency*) a)[1] - (uintptr_t) ((CHiAdjacency*) b)[1];
|
||||
}
|
||||
|
||||
static void adjacency_add(CHiPubNode *source, CHiPubNode *sink) {
|
||||
CHiNodeGraph *ng = source->ng;
|
||||
|
||||
if(ng->adjacencyCount == ng->adjacencyCapacity) {
|
||||
ng->adjacencies = realloc(ng->adjacencies, sizeof(CHiAdjacency) * (ng->adjacencyCapacity *= 2));
|
||||
}
|
||||
|
||||
ng->adjacencies[ng->adjacencyCount][0] = source;
|
||||
ng->adjacencies[ng->adjacencyCount][1] = sink;
|
||||
ng->adjacencyCount++;
|
||||
|
||||
qsort(ng->adjacencies, ng->adjacencyCount, sizeof(CHiAdjacency), adjacencycmp);
|
||||
}
|
||||
|
||||
static void adjacency_remove(CHiPubNode *source, CHiPubNode *sink) {
|
||||
CHiNodeGraph *ng = source->ng;
|
||||
|
||||
CHiAdjacency *adj = bsearch(&(CHiAdjacency) {source, sink}, ng->adjacencies, ng->adjacencyCount, sizeof(CHiAdjacency), adjacencycmp);
|
||||
if(adj) {
|
||||
memmove(adj, adj + 1, sizeof(CHiAdjacency) * (ng->adjacencyCount - (adj - ng->adjacencies) - 1));
|
||||
ng->adjacencyCount--;
|
||||
}
|
||||
}
|
||||
|
||||
CUTIVIS CHiNodeGraph *CHi_NewNodeGraph() {
|
||||
static int inited = 0;
|
||||
@ -77,9 +125,9 @@ CUTIVIS CHiNodeGraph *CHi_NodeGraphReset(CHiNodeGraph *ng) {
|
||||
}
|
||||
|
||||
CUTIVIS CHiValue *CHi_Crawl(CHiValue *v) {
|
||||
while(v->linked.to || v->type == CUTIHI_VAL_KEYED) {
|
||||
if(v->linked.to) {
|
||||
v = &v->linked.to->sources[v->linked.idx];
|
||||
while(v->type == CUTIHI_VAL_LINKED || v->type == CUTIHI_VAL_KEYED) {
|
||||
if(v->type == CUTIHI_VAL_LINKED) {
|
||||
v = &v->data.linked.to->sources[v->data.linked.idx];
|
||||
} else if(v->type == CUTIHI_VAL_KEYED) {
|
||||
v = &v->data.keyed->current;
|
||||
}
|
||||
@ -115,8 +163,8 @@ static int dfs_visit(size_t *resultCount, CHiPubNode ***result, CHiPubNode *n) {
|
||||
n->_dfsmark = 1;
|
||||
|
||||
for(size_t s = 0; s < n->sinkCount; s++) {
|
||||
if(n->sinks[s].linked.to) {
|
||||
if(!dfs_visit(resultCount, result, n->sinks[s].linked.to)) {
|
||||
if(n->sinks[s].type == CUTIHI_VAL_LINKED) {
|
||||
if(!dfs_visit(resultCount, result, n->sinks[s].data.linked.to)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -161,34 +209,28 @@ CUTIVIS int CHi_ConfigureSink(CHiPubNode *n, size_t i, CHiValue v) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(v.linked.to && n == v.linked.to) return 0;
|
||||
if(v.type == CUTIHI_VAL_LINKED && n == v.data.linked.to) return 0;
|
||||
|
||||
CHiValue old = n->sinks[i];
|
||||
|
||||
if(old.linked.to) {
|
||||
adjacency_remove(old.linked.to, n);
|
||||
}
|
||||
|
||||
if(v.linked.to) {
|
||||
// Overwrite only the link-related things to keep the old values in case the link is removed
|
||||
n->sinks[i].linked = v.linked;
|
||||
} else {
|
||||
n->sinks[i] = v;
|
||||
if(old.type == CUTIHI_VAL_LINKED) {
|
||||
adjacency_remove(old.data.linked.to, n);
|
||||
}
|
||||
|
||||
// Check if viable
|
||||
n->sinks[i] = v;
|
||||
if(n->ng && !topological_sort(n->ng)) {
|
||||
n->sinks[i] = old;
|
||||
|
||||
if(old.linked.to) {
|
||||
adjacency_add(old.linked.to, n);
|
||||
if(old.type == CUTIHI_VAL_LINKED) {
|
||||
adjacency_add(old.data.linked.to, n);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(v.linked.to) {
|
||||
adjacency_add(v.linked.to, n);
|
||||
if(v.type == CUTIHI_VAL_LINKED) {
|
||||
adjacency_add(v.data.linked.to, n);
|
||||
}
|
||||
|
||||
CHi_MakeDirty(n->ng, n);
|
||||
@ -309,6 +351,22 @@ CUTIVIS void CHi_SetDuration(CHiNodeGraph *ng, float d) {
|
||||
ng->duration = d;
|
||||
}
|
||||
|
||||
CUTIVIS int CHi_Hysteresis(CHiPubNode *root) {
|
||||
if(root->ng->compilationStatus != CUTIHI_COMP_READY) return 0;
|
||||
|
||||
for(size_t s = 0; s < root->sinkCount; s++) {
|
||||
if(root->sinks[s].type == CUTIHI_VAL_LINKED) {
|
||||
CHi_Hysteresis(root->sinks[s].data.linked.to);
|
||||
}
|
||||
}
|
||||
|
||||
//if(!root->clean) {
|
||||
root->Perform(root);
|
||||
//}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool error_changes(CHiPubNode *n) {
|
||||
for(int e = 0; e < CUTIHI_MAX_ERRORS; e++) {
|
||||
if(n->errors.active[e] != n->errors.activeLast[e]) {
|
||||
@ -326,7 +384,9 @@ static void save_errors(CHiPubNode *n) {
|
||||
}
|
||||
}
|
||||
|
||||
CUTIVIS int CHi_Hysteresis(CHiNodeGraph *ng) {
|
||||
static void perform_step(CHiNodeGraph *ng) {
|
||||
pthread_mutex_lock(&ng->mut);
|
||||
|
||||
for(size_t nIdx = 0; nIdx < ng->count; nIdx++) {
|
||||
save_errors(ng->nodes[nIdx]);
|
||||
}
|
||||
@ -334,8 +394,6 @@ CUTIVIS int CHi_Hysteresis(CHiNodeGraph *ng) {
|
||||
for(size_t nIdx = 0; nIdx < ng->count; nIdx++) {
|
||||
CHiPubNode *n = ng->nodes[nIdx];
|
||||
|
||||
// The existence of n->Start implies the node has external side-effects and should not be executed
|
||||
if(ng->compilationStatus == CUTIHI_COMP_RUNNING || n->Start == NULL) {
|
||||
n->Perform(n);
|
||||
|
||||
if(error_changes(n)) {
|
||||
@ -343,15 +401,6 @@ CUTIVIS int CHi_Hysteresis(CHiNodeGraph *ng) {
|
||||
ng->eventOnError(ng, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void perform_step(CHiNodeGraph *ng) {
|
||||
pthread_mutex_lock(&ng->mut);
|
||||
|
||||
CHi_Hysteresis(ng);
|
||||
|
||||
if(ng->eventOnFrameComplete) {
|
||||
ng->eventOnFrameComplete(ng);
|
||||
@ -534,7 +583,9 @@ static int image_perform(CHiPubNode *node) {
|
||||
}
|
||||
|
||||
if(node->sinks[CUTIHI_IMAGE_IN_FILE].type != CUTIHI_VAL_TEXT) {
|
||||
CHi_AddError(node, "invalid type", 0);
|
||||
node->errors.active[0] = true;
|
||||
strncpy(node->errors.code[0], "invalid type", CUTIHI_ERR_SIZE);
|
||||
node->errors.sink[0] = CUTIHI_IMAGE_IN_FILE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -547,7 +598,9 @@ static int image_perform(CHiPubNode *node) {
|
||||
if(!internal->cacheImg) {
|
||||
struct sail_image *simg;
|
||||
if(sail_load_from_file(fn, &simg) != SAIL_OK) {
|
||||
CHi_AddError(node, "invalid file", 0);
|
||||
node->errors.active[0] = true;
|
||||
strncpy(node->errors.code[0], "invalid file", CUTIHI_ERR_SIZE);
|
||||
node->errors.sink[0] = CUTIHI_IMAGE_IN_FILE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -570,9 +623,6 @@ static int image_perform(CHiPubNode *node) {
|
||||
}
|
||||
|
||||
sail_destroy_image(cimg);
|
||||
|
||||
free(internal->cachePath);
|
||||
internal->cachePath = strdup(fn);
|
||||
}
|
||||
|
||||
if(CHi_Node_Active(node)) {
|
||||
@ -662,15 +712,13 @@ static int constantsample_perform(CHiPubNode *node) {
|
||||
size_t w = sz->data.vec4[0] < 1 ? 1 : sz->data.vec4[0];
|
||||
size_t h = sz->data.vec4[1] < 1 ? 1 : sz->data.vec4[1];
|
||||
|
||||
CHiImage *img = CHi_Image_New(2, 4, 8 * ((w + 1) & ~1), w, h, NULL);
|
||||
CHiImage *img = CHi_Image_New(2, 4, 8 * w, w, h, NULL);
|
||||
if(CHi_Node_Active(node)) {
|
||||
for(size_t y = 0; y < h; y++) {
|
||||
for(size_t x = 0; x < w; x++) {
|
||||
img->data16[y * img->stride / 2 + x * 4 + 0] = sink->data.vec4[2] * 65535;
|
||||
img->data16[y * img->stride / 2 + x * 4 + 1] = sink->data.vec4[1] * 65535;
|
||||
img->data16[y * img->stride / 2 + x * 4 + 2] = sink->data.vec4[0] * 65535;
|
||||
img->data16[y * img->stride / 2 + x * 4 + 3] = 65535;
|
||||
}
|
||||
for(size_t i = 0; i < w * h; i++) {
|
||||
img->data16[i * 4 + 0] = sink->data.vec4[2] * 65535;
|
||||
img->data16[i * 4 + 1] = sink->data.vec4[1] * 65535;
|
||||
img->data16[i * 4 + 2] = sink->data.vec4[0] * 65535;
|
||||
img->data16[i * 4 + 3] = 65535;
|
||||
}
|
||||
}
|
||||
node->sources->data.sample = img;
|
||||
@ -716,7 +764,9 @@ static int modulate_perform(CHiPubNode *node) {
|
||||
}
|
||||
|
||||
if(imgsrc->type != CUTIHI_VAL_SAMPLE) {
|
||||
CHi_AddError(node, "invalid type", 0);
|
||||
node->errors.active[0] = true;
|
||||
strncpy(node->errors.code[0], "invalid type", CUTIHI_ERR_SIZE);
|
||||
node->errors.sink[0] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -725,15 +775,11 @@ static int modulate_perform(CHiPubNode *node) {
|
||||
|
||||
if(!CHi_Node_Active(node)) {
|
||||
node->sources->data.sample = NULL;
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
|
||||
CHiImage *src = imgsrc->data.sample;
|
||||
|
||||
if(!src) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
assert(src->stride % 16 == 0);
|
||||
|
||||
CHiImage *dst = CHi_Image_New(2, 4, src->stride, src->width, src->height, NULL);
|
||||
@ -871,6 +917,49 @@ CUTIVIS CHiPubNode *CHi_Modulate() {
|
||||
return n;
|
||||
}
|
||||
|
||||
static void update_keyed_values(CHiNodeGraph *ng) {
|
||||
for(size_t kfsIdx = 0; kfsIdx < ng->keyframesList.count; kfsIdx++) {
|
||||
CHiKeyframes *kfs = ng->keyframesList.keyframes[kfsIdx];
|
||||
|
||||
kfs->current.type = kfs->type;
|
||||
|
||||
float now = ng->time;
|
||||
|
||||
size_t idx = bisect(&now, kfs->times, kfs->count, sizeof(now), float_compar);
|
||||
|
||||
if(idx == 0) {
|
||||
kfs->current.data = kfs->values[idx];
|
||||
|
||||
if(kfs->current.type == CUTIHI_VAL_VEC4 && kfs->extrapolationMode == CUTIHI_EXTRAPOLATION_CONSTANT) {
|
||||
kfs->current.data.vec4[0] += (now - kfs->times[0]) * kfs->extrapolationParameter[0];
|
||||
kfs->current.data.vec4[1] += (now - kfs->times[0]) * kfs->extrapolationParameter[1];
|
||||
kfs->current.data.vec4[2] += (now - kfs->times[0]) * kfs->extrapolationParameter[2];
|
||||
kfs->current.data.vec4[3] += (now - kfs->times[0]) * kfs->extrapolationParameter[3];
|
||||
}
|
||||
} else if(idx == kfs->count) {
|
||||
kfs->current.data = kfs->values[idx - 1];
|
||||
|
||||
if(kfs->current.type == CUTIHI_VAL_VEC4 && kfs->extrapolationMode == CUTIHI_EXTRAPOLATION_CONSTANT) {
|
||||
kfs->current.data.vec4[0] += (now - kfs->times[kfs->count - 1]) * kfs->extrapolationParameter[0];
|
||||
kfs->current.data.vec4[1] += (now - kfs->times[kfs->count - 1]) * kfs->extrapolationParameter[1];
|
||||
kfs->current.data.vec4[2] += (now - kfs->times[kfs->count - 1]) * kfs->extrapolationParameter[2];
|
||||
kfs->current.data.vec4[3] += (now - kfs->times[kfs->count - 1]) * kfs->extrapolationParameter[3];
|
||||
}
|
||||
} else {
|
||||
if(kfs->type == CUTIHI_VAL_VEC4) {
|
||||
float alpha = (now - kfs->times[idx - 1]) / (kfs->times[idx] - kfs->times[idx - 1]);
|
||||
|
||||
kfs->current.data.vec4[0] = kfs->values[idx - 1].vec4[0] + (kfs->values[idx].vec4[0] - kfs->values[idx - 1].vec4[0]) * alpha;
|
||||
kfs->current.data.vec4[1] = kfs->values[idx - 1].vec4[1] + (kfs->values[idx].vec4[1] - kfs->values[idx - 1].vec4[1]) * alpha;
|
||||
kfs->current.data.vec4[2] = kfs->values[idx - 1].vec4[2] + (kfs->values[idx].vec4[2] - kfs->values[idx - 1].vec4[2]) * alpha;
|
||||
kfs->current.data.vec4[3] = kfs->values[idx - 1].vec4[3] + (kfs->values[idx].vec4[3] - kfs->values[idx - 1].vec4[3]) * alpha;
|
||||
} else {
|
||||
kfs->current.data = kfs->values[idx - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int time_perform(CHiPubNode *node) {
|
||||
node->sources->type = CUTIHI_VAL_VEC4;
|
||||
node->sources->data.vec4[0] = node->ng->time;
|
||||
@ -1211,55 +1300,281 @@ CUTIVIS CHiPubNode *CHi_ChromaKey() {
|
||||
return n;
|
||||
}
|
||||
|
||||
static void save_chival(CHiNodeGraph *ng, CHiSaveWriter writer, CHiValType type, CHiValueRaw data, void *ud) {
|
||||
if(type == CUTIHI_VAL_TEXT) {
|
||||
size_t len = strlen(data.text);
|
||||
writer(ud, &(uint32_t) {len}, sizeof(uint32_t));
|
||||
writer(ud, data.text, len);
|
||||
} else if(type == CUTIHI_VAL_VEC4) {
|
||||
writer(ud, data.vec4, sizeof(data.vec4));
|
||||
} else if(type == CUTIHI_VAL_LINKED) {
|
||||
size_t index;
|
||||
for(index = 0; index < ng->count; index++) {
|
||||
if(ng->nodes[index] == data.linked.to) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(index < ng->count);
|
||||
|
||||
writer(ud, &(uint64_t) {index}, sizeof(uint64_t));
|
||||
writer(ud, &(uint16_t) {data.linked.idx}, sizeof(uint16_t));
|
||||
} else if(type == CUTIHI_VAL_KEYED) {
|
||||
size_t index;
|
||||
for(index = 0; index < ng->keyframesList.count; index++) {
|
||||
if(ng->keyframesList.keyframes[index] == data.keyed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(index < ng->count);
|
||||
|
||||
writer(ud, &(uint64_t) {index}, sizeof(uint64_t));
|
||||
}
|
||||
}
|
||||
|
||||
static void load_chival(CHiNodeGraph *ng, CHiLoadReader reader, CHiValType type, CHiValueRaw *data, void *ud) {
|
||||
if(type == CUTIHI_VAL_TEXT) {
|
||||
uint32_t len;
|
||||
reader(ud, &len, sizeof(len));
|
||||
|
||||
data->text = malloc(len + 1);
|
||||
|
||||
reader(ud, data->text, len);
|
||||
|
||||
data->text[len] = 0;
|
||||
} else if(type == CUTIHI_VAL_VEC4) {
|
||||
reader(ud, data->vec4, sizeof(data->vec4));
|
||||
} else if(type == CUTIHI_VAL_LINKED) {
|
||||
uint64_t index;
|
||||
reader(ud, &index, sizeof(index));
|
||||
|
||||
data->linked.to = ng->nodes[index];
|
||||
|
||||
uint16_t idx;
|
||||
reader(ud, &idx, sizeof(idx));
|
||||
|
||||
data->linked.idx = idx;
|
||||
} else if(type == CUTIHI_VAL_KEYED) {
|
||||
uint64_t index;
|
||||
reader(ud, &index, sizeof(index));
|
||||
|
||||
data->keyed = ng->keyframesList.keyframes[index];
|
||||
}
|
||||
}
|
||||
|
||||
CUTIVIS int CHi_NodeGraphSave(CHiNodeGraph *ng, CHiSaveWriter writer, void *ud) {
|
||||
writer(ud, "\x71\x74\xCE\xA0", 4);
|
||||
|
||||
writer(ud, &(float) {ng->duration}, sizeof(float));
|
||||
writer(ud, &(float) {ng->time}, sizeof(float));
|
||||
|
||||
writer(ud, &(uint64_t) {ng->keyframesList.count}, sizeof(uint64_t));
|
||||
|
||||
for(size_t i = 0; i < ng->keyframesList.count; i++) {
|
||||
CHiKeyframes *kfs = ng->keyframesList.keyframes[i];
|
||||
|
||||
writer(ud, &(uint16_t) {kfs->type}, sizeof(uint16_t));
|
||||
|
||||
writer(ud, &(uint64_t) {kfs->count}, sizeof(uint64_t));
|
||||
|
||||
writer(ud, kfs->times, sizeof(*kfs->times) * kfs->count);
|
||||
|
||||
for(size_t k = 0; k < kfs->count; k++) {
|
||||
save_chival(ng, writer, kfs->type, kfs->values[k], ud);
|
||||
}
|
||||
|
||||
writer(ud, &(uint16_t) {kfs->extrapolationMode}, sizeof(uint16_t));
|
||||
writer(ud, kfs->extrapolationParameter, sizeof(kfs->extrapolationParameter));
|
||||
}
|
||||
|
||||
writer(ud, &(uint64_t) {ng->count}, sizeof(uint64_t));
|
||||
|
||||
for(size_t i = 0; i < ng->count; i++) {
|
||||
CHiPubNode *node = ng->nodes[i];
|
||||
|
||||
writer(ud, &(uint64_t) {node->type}, sizeof(uint64_t));
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < ng->count; i++) {
|
||||
CHiPubNode *node = ng->nodes[i];
|
||||
|
||||
if(node->Save) {
|
||||
node->Save(node, ud, writer);
|
||||
}
|
||||
|
||||
writer(ud, &(uint16_t) {node->sinkCount}, sizeof(uint16_t));
|
||||
|
||||
for(size_t sink = 0; sink < node->sinkCount; sink++) {
|
||||
writer(ud, &(uint16_t) {node->sinks[sink].type}, sizeof(uint16_t));
|
||||
|
||||
save_chival(ng, writer, node->sinks[sink].type, node->sinks[sink].data, ud);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CUTIVIS int CHi_NodeGraphLoad(CHiNodeGraph *ng, CHiLoadReader reader, void *ud) {
|
||||
{
|
||||
char magic[4];
|
||||
reader(ud, magic, sizeof(magic));
|
||||
if(memcmp(magic, "\x71\x74\xCE\xA0", 4)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
CHi_NodeGraphReset(ng);
|
||||
|
||||
reader(ud, &ng->duration, sizeof(float));
|
||||
reader(ud, &ng->time, sizeof(float));
|
||||
|
||||
{
|
||||
uint64_t count;
|
||||
reader(ud, &count, sizeof(count));
|
||||
ng->keyframesList.count = count;
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < ng->keyframesList.count; i++) {
|
||||
CHiKeyframes *kfs = ng->keyframesList.keyframes[i] = calloc(1, sizeof(*kfs));
|
||||
|
||||
{
|
||||
uint16_t type;
|
||||
reader(ud, &type, sizeof(type));
|
||||
kfs->type = type;
|
||||
}
|
||||
|
||||
{
|
||||
uint64_t count;
|
||||
reader(ud, &count, sizeof(count));
|
||||
kfs->count = count;
|
||||
}
|
||||
|
||||
kfs->times = calloc(kfs->count, sizeof(*kfs->times));
|
||||
|
||||
reader(ud, kfs->times, kfs->count * sizeof(*kfs->times));
|
||||
|
||||
for(size_t k = 0; k < kfs->count; k++) {
|
||||
load_chival(ng, reader, kfs->type, &kfs->values[k], ud);
|
||||
}
|
||||
|
||||
{
|
||||
uint16_t extrap;
|
||||
reader(ud, &extrap, sizeof(extrap));
|
||||
kfs->extrapolationMode = extrap;
|
||||
}
|
||||
|
||||
reader(ud, kfs->extrapolationParameter, sizeof(kfs->extrapolationParameter));
|
||||
}
|
||||
|
||||
{
|
||||
uint64_t count;
|
||||
reader(ud, &count, sizeof(count));
|
||||
ng->count = count;
|
||||
}
|
||||
|
||||
ng->capacity = ng->count < 8 ? 8 : ng->count;
|
||||
|
||||
ng->nodes = calloc(ng->capacity, sizeof(*ng->nodes));
|
||||
|
||||
for(size_t i = 0; i < ng->count; i++) {
|
||||
uint64_t type;
|
||||
|
||||
reader(ud, &type, sizeof(type));
|
||||
|
||||
CHiPubNode *n = NULL;
|
||||
|
||||
if(type == CUTIHI_T('CPre','view')) {
|
||||
n = CHi_Preview();
|
||||
} else if(type == CUTIHI_T('CMix','er ')) {
|
||||
n = CHi_Mixer();
|
||||
} else if(type == CUTIHI_T('CTex','t ')) {
|
||||
n = CHi_Text();
|
||||
} else if(type == CUTIHI_T('CTim','e ')) {
|
||||
n = CHi_Time();
|
||||
} else if(type == CUTIHI_T('CMod','ulat')) {
|
||||
n = CHi_Modulate();
|
||||
} else if(type == CUTIHI_T('CCns','tCol')) {
|
||||
n = CHi_ConstantSample();
|
||||
} else if(type == CUTIHI_T('CEmb','ed ')) {
|
||||
n = CHi_Embed();
|
||||
} else if(type == CUTIHI_T('CIma','ge ')) {
|
||||
n = CHi_Image();
|
||||
} else if(type == CUTIHI_T('CWin','dow ')) {
|
||||
n = CHi_Window();
|
||||
} else if(type == CUTIHI_T('CInA','udio')) {
|
||||
n = CHi_Microphone();
|
||||
} else if(type == CUTIHI_T('CExp','Wave')) {
|
||||
n = CHi_ExportWav();
|
||||
} else if(type == CUTIHI_T('CMov','ie ')) {
|
||||
n = CHi_Movie();
|
||||
} else if(type == CUTIHI_T('CEnc','GVP8')) {
|
||||
n = CHi_EncodeVP8();
|
||||
} else if(type == CUTIHI_T('CEnc','GVP9')) {
|
||||
n = CHi_EncodeVP9();
|
||||
} else if(type == CUTIHI_T('CExp','Webm')) {
|
||||
n = CHi_MuxWebm();
|
||||
} else if(type == CUTIHI_T('CKey','hook')) {
|
||||
n = CHi_Keyhook();
|
||||
} else if(type == CUTIHI_T('CKey','hook')) {
|
||||
n = CHi_Keyhook();
|
||||
} else if(type == CUTIHI_T('CEnc','Opus')) {
|
||||
n = CHi_EncodeOpus();
|
||||
} else if(type == CUTIHI_T('CWeb','Cam ')) {
|
||||
n = CHi_Camera();
|
||||
} else if(type == CUTIHI_T('CCmp','nScl')) {
|
||||
n = CHi_ComponentScale();
|
||||
} else if(type == CUTIHI_T('CEnc','H264')) {
|
||||
n = CHi_EncodeH264();
|
||||
} else if(type == CUTIHI_T('CStr','RTMP')) {
|
||||
n = CHi_StreamRTMP();
|
||||
} else if(type == CUTIHI_T('CEnc','AACL')) {
|
||||
n = CHi_EncodeAAC();
|
||||
} else if(type == CUTIHI_T('CExp','Mkv ')) {
|
||||
n = CHi_MuxMatroska();
|
||||
}
|
||||
|
||||
n->ng = ng;
|
||||
|
||||
if(!n) {
|
||||
CHi_NodeGraphReset(ng);
|
||||
puts("Error: Unknown node type!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ng->nodes[i] = n;
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < ng->count; i++) {
|
||||
CHiPubNode *n = ng->nodes[i];
|
||||
|
||||
{
|
||||
uint16_t u16;
|
||||
reader(ud, &u16, sizeof(u16));
|
||||
n->sinkCount = u16;
|
||||
}
|
||||
|
||||
n->sinks = calloc(n->sinkCount, sizeof(*n->sinks));
|
||||
|
||||
for(size_t s = 0; s < n->sinkCount; s++) {
|
||||
{
|
||||
uint16_t u16;
|
||||
reader(ud, &u16, sizeof(u16));
|
||||
n->sinks[s].type = u16;
|
||||
}
|
||||
|
||||
load_chival(ng, reader, n->sinks[s].type, &n->sinks[s].data, ud);
|
||||
|
||||
if(n->sinks[s].type == CUTIHI_VAL_LINKED) {
|
||||
adjacency_add(n->sinks[s].data.linked.to, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_keyed_values(ng);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CUTIVIS bool CHi_Node_Active(CHiPubNode *pubn) {
|
||||
float now = CHi_Time_Get(pubn->ng);
|
||||
return pubn->lifespan.start <= now && (pubn->lifespan.end == 0 || now < pubn->lifespan.end);
|
||||
}
|
||||
|
||||
CUTIVIS void CHi_Node_Destroy(CHiPubNode *pubn) {
|
||||
for(size_t ni = 0; ni < pubn->ng->count; ni++) {
|
||||
for(size_t si = 0; si < pubn->ng->nodes[ni]->sinkCount; si++) {
|
||||
if(pubn->ng->nodes[ni]->sinks[si].linked.to == pubn) {
|
||||
adjacency_remove(pubn, pubn->ng->nodes[ni]);
|
||||
|
||||
pubn->ng->nodes[ni]->sinks[si].linked.to = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(size_t si = 0; si < pubn->sinkCount; si++) {
|
||||
if(pubn->sinks[si].linked.to) {
|
||||
adjacency_remove(pubn->sinks[si].linked.to, pubn);
|
||||
}
|
||||
}
|
||||
|
||||
size_t ni;
|
||||
for(ni = 0; ni < pubn->ng->count; ni++) {
|
||||
if(pubn->ng->nodes[ni] == pubn) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(ni < pubn->ng->count);
|
||||
|
||||
if(pubn->Destroy) {
|
||||
pubn->Destroy(pubn);
|
||||
} else {
|
||||
free(pubn);
|
||||
}
|
||||
|
||||
memmove(&pubn->ng->nodes[ni], &pubn->ng->nodes[ni + 1], sizeof(*pubn->ng->nodes) * (pubn->ng->count - ni - 1));
|
||||
|
||||
pubn->ng->count--;
|
||||
}
|
||||
|
||||
CUTIVIS void CHi_AddError(CHiPubNode *node, const char *err, size_t sink) {
|
||||
for(size_t i = 0; i < CUTIHI_MAX_ERRORS; i++) {
|
||||
if(!node->errors.active[i]) {
|
||||
node->errors.active[i] = true;
|
||||
strncpy(node->errors.code[i], "invalid type", CUTIHI_ERR_SIZE);
|
||||
node->errors.sink[i] = sink;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
34
hi/node.h
34
hi/node.h
@ -21,18 +21,12 @@ extern "C" {
|
||||
#define CUTIHI_T(a, b) ((((uint64_t) b) << 32) | a
|
||||
#endif
|
||||
|
||||
struct EBMLWriter;
|
||||
struct CHiPubNode;
|
||||
|
||||
typedef size_t(*CHiSaveWriter)(void *ud, const void *data, size_t len);
|
||||
typedef void(*CHiSaveCustomNodeData)(void *ud, struct EBMLWriter*, struct CHiPubNode*);
|
||||
|
||||
typedef size_t(*CHiLoadReader)(void *ud, void *data, size_t len);
|
||||
typedef void(*CHiLoadCustomNodeData)(void *ud, uint64_t nodeIdx, uint64_t elId, const void *buf, size_t length);
|
||||
|
||||
typedef enum {
|
||||
CUTIHI_VAL_NONE = 0,
|
||||
// CUTIHI_VAL_LINKED = 1,
|
||||
CUTIHI_VAL_LINKED = 1,
|
||||
CUTIHI_VAL_KEYED = 2,
|
||||
CUTIHI_VAL_SAMPLE = 3,
|
||||
CUTIHI_VAL_TEXT = 4,
|
||||
@ -53,6 +47,10 @@ struct CHiPubNode;
|
||||
struct CHiKeyframes;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
struct CHiPubNode *to;
|
||||
uint8_t idx;
|
||||
} linked;
|
||||
struct CHiImage *sample;
|
||||
char *text;
|
||||
float vec4[4];
|
||||
@ -63,10 +61,6 @@ typedef union {
|
||||
|
||||
typedef struct {
|
||||
CHiValType type;
|
||||
struct {
|
||||
struct CHiPubNode *to;
|
||||
uint8_t idx;
|
||||
} linked;
|
||||
CHiValueRaw data;
|
||||
} CHiValue;
|
||||
|
||||
@ -173,8 +167,8 @@ typedef struct CHiNodeGraph {
|
||||
|
||||
CUTIVIS CHiNodeGraph *CHi_NewNodeGraph();
|
||||
CUTIVIS CHiNodeGraph *CHi_NodeGraphReset(CHiNodeGraph *ng);
|
||||
CUTIVIS int CHi_NodeGraphSave(CHiNodeGraph *ng, CHiSaveWriter, CHiSaveCustomNodeData, void *ud);
|
||||
CUTIVIS int CHi_NodeGraphLoad(CHiNodeGraph *ng, CHiLoadReader, CHiLoadCustomNodeData, void *ud);
|
||||
CUTIVIS int CHi_NodeGraphSave(CHiNodeGraph *ng, CHiSaveWriter writer, void *ud);
|
||||
CUTIVIS int CHi_NodeGraphLoad(CHiNodeGraph *ng, CHiLoadReader reader, void *ud);
|
||||
|
||||
CUTIVIS void CHi_RegisterNode(CHiNodeGraph*, CHiPubNode*);
|
||||
CUTIVIS void CHi_MakeDirty(CHiNodeGraph*, CHiPubNode*);
|
||||
@ -187,7 +181,7 @@ CUTIVIS size_t CHi_GetClosestKeyframe(CHiNodeGraph *ng, CHiKeyframes *kfs, float
|
||||
CUTIVIS void CHi_SetExtrapolationMode(CHiNodeGraph *ng, CHiPubNode *n, size_t sinkIdx, CHiExtrapolationMode mode, float* params);
|
||||
CUTIVIS void CHi_DeleteKeyframe(CHiNodeGraph *ng, CHiKeyframes *kfs, size_t idx);
|
||||
|
||||
CUTIVIS int CHi_Hysteresis(CHiNodeGraph*);
|
||||
CUTIVIS int CHi_Hysteresis(CHiPubNode*);
|
||||
|
||||
CUTIVIS void CHi_SetDuration(CHiNodeGraph *ng, float);
|
||||
CUTIVIS void CHi_BeginCompilation(CHiNodeGraph *ng);
|
||||
@ -246,10 +240,10 @@ CUTIVIS int CHi_MuxWebm_Stop(CHiPubNode*);
|
||||
#define CUTIHI_WINDOW_OUT_SAMPLE 1
|
||||
CUTIVIS CHiPubNode *CHi_Window();
|
||||
|
||||
CUTIVIS size_t CHi_Window_GetList(void **buf);
|
||||
CUTIVIS const char *CHi_Window_GetName(void *buf, size_t i);
|
||||
CUTIVIS size_t CHi_Window_GetHandle(void *buf, size_t i);
|
||||
CUTIVIS void CHi_Window_FreeList(void *buf);
|
||||
CUTIVIS size_t CHi_Window_GetSourceCount();
|
||||
CUTIVIS const char *CHi_Window_GetSourceName(size_t);
|
||||
CUTIVIS uintptr_t CHi_Window_GetSourceData(size_t);
|
||||
CUTIVIS size_t CHi_Window_GetNextSource(size_t);
|
||||
|
||||
#define CUTIHI_MICROPHONE_IN_NAME 0
|
||||
#define CUTIHI_MICROPHONE_OUT_AUDIO 1
|
||||
@ -289,10 +283,6 @@ CUTIVIS CHiValue *CHi_Crawl(CHiValue*);
|
||||
|
||||
CUTIVIS bool CHi_Node_Active(CHiPubNode*);
|
||||
|
||||
CUTIVIS void CHi_Node_Destroy(CHiPubNode*);
|
||||
|
||||
CUTIVIS void CHi_AddError(CHiPubNode*, const char *err, size_t sink);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,96 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include"node.h"
|
||||
|
||||
static inline size_t bisect(const void *key, const void *base, size_t nmemb, size_t size, ssize_t(*compar)(const void*, const void*)) {
|
||||
size_t low = 0, high = nmemb;
|
||||
|
||||
while(low < high) {
|
||||
size_t middle = (low + high) / 2;
|
||||
if(compar((const void*) ((uintptr_t) base + size * middle), key) < 0) {
|
||||
low = middle + 1;
|
||||
} else {
|
||||
high = middle;
|
||||
}
|
||||
}
|
||||
|
||||
return low;
|
||||
}
|
||||
|
||||
static inline ssize_t float_compar(const void *A, const void *B) {
|
||||
float a = *(float*) A;
|
||||
float b = *(float*) B;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
static inline int adjacencycmp(const void *a, const void *b) {
|
||||
size_t v = (uintptr_t) ((CHiAdjacency*) a)[0] - (uintptr_t) ((CHiAdjacency*) b)[0];
|
||||
return v ? v : (uintptr_t) ((CHiAdjacency*) a)[1] - (uintptr_t) ((CHiAdjacency*) b)[1];
|
||||
}
|
||||
|
||||
static inline void adjacency_add(CHiPubNode *source, CHiPubNode *sink) {
|
||||
CHiNodeGraph *ng = source->ng;
|
||||
|
||||
if(ng->adjacencyCount == ng->adjacencyCapacity) {
|
||||
ng->adjacencies = realloc(ng->adjacencies, sizeof(CHiAdjacency) * (ng->adjacencyCapacity *= 2));
|
||||
}
|
||||
|
||||
ng->adjacencies[ng->adjacencyCount][0] = source;
|
||||
ng->adjacencies[ng->adjacencyCount][1] = sink;
|
||||
ng->adjacencyCount++;
|
||||
|
||||
qsort(ng->adjacencies, ng->adjacencyCount, sizeof(CHiAdjacency), adjacencycmp);
|
||||
}
|
||||
|
||||
static inline void adjacency_remove(CHiPubNode *source, CHiPubNode *sink) {
|
||||
CHiNodeGraph *ng = source->ng;
|
||||
|
||||
CHiAdjacency *adj = bsearch(&(CHiAdjacency) {source, sink}, ng->adjacencies, ng->adjacencyCount, sizeof(CHiAdjacency), adjacencycmp);
|
||||
if(adj) {
|
||||
memmove(adj, adj + 1, sizeof(CHiAdjacency) * (ng->adjacencyCount - (adj - ng->adjacencies) - 1));
|
||||
ng->adjacencyCount--;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void update_keyed_values(CHiNodeGraph *ng) {
|
||||
for(size_t kfsIdx = 0; kfsIdx < ng->keyframesList.count; kfsIdx++) {
|
||||
CHiKeyframes *kfs = ng->keyframesList.keyframes[kfsIdx];
|
||||
|
||||
kfs->current.type = kfs->type;
|
||||
|
||||
float now = ng->time;
|
||||
|
||||
size_t idx = bisect(&now, kfs->times, kfs->count, sizeof(now), float_compar);
|
||||
|
||||
if(idx == 0) {
|
||||
kfs->current.data = kfs->values[idx];
|
||||
|
||||
if(kfs->current.type == CUTIHI_VAL_VEC4 && kfs->extrapolationMode == CUTIHI_EXTRAPOLATION_CONSTANT) {
|
||||
kfs->current.data.vec4[0] += (now - kfs->times[0]) * kfs->extrapolationParameter[0];
|
||||
kfs->current.data.vec4[1] += (now - kfs->times[0]) * kfs->extrapolationParameter[1];
|
||||
kfs->current.data.vec4[2] += (now - kfs->times[0]) * kfs->extrapolationParameter[2];
|
||||
kfs->current.data.vec4[3] += (now - kfs->times[0]) * kfs->extrapolationParameter[3];
|
||||
}
|
||||
} else if(idx == kfs->count) {
|
||||
kfs->current.data = kfs->values[idx - 1];
|
||||
|
||||
if(kfs->current.type == CUTIHI_VAL_VEC4 && kfs->extrapolationMode == CUTIHI_EXTRAPOLATION_CONSTANT) {
|
||||
kfs->current.data.vec4[0] += (now - kfs->times[kfs->count - 1]) * kfs->extrapolationParameter[0];
|
||||
kfs->current.data.vec4[1] += (now - kfs->times[kfs->count - 1]) * kfs->extrapolationParameter[1];
|
||||
kfs->current.data.vec4[2] += (now - kfs->times[kfs->count - 1]) * kfs->extrapolationParameter[2];
|
||||
kfs->current.data.vec4[3] += (now - kfs->times[kfs->count - 1]) * kfs->extrapolationParameter[3];
|
||||
}
|
||||
} else {
|
||||
if(kfs->type == CUTIHI_VAL_VEC4) {
|
||||
float alpha = (now - kfs->times[idx - 1]) / (kfs->times[idx] - kfs->times[idx - 1]);
|
||||
|
||||
kfs->current.data.vec4[0] = kfs->values[idx - 1].vec4[0] + (kfs->values[idx].vec4[0] - kfs->values[idx - 1].vec4[0]) * alpha;
|
||||
kfs->current.data.vec4[1] = kfs->values[idx - 1].vec4[1] + (kfs->values[idx].vec4[1] - kfs->values[idx - 1].vec4[1]) * alpha;
|
||||
kfs->current.data.vec4[2] = kfs->values[idx - 1].vec4[2] + (kfs->values[idx].vec4[2] - kfs->values[idx - 1].vec4[2]) * alpha;
|
||||
kfs->current.data.vec4[3] = kfs->values[idx - 1].vec4[3] + (kfs->values[idx].vec4[3] - kfs->values[idx - 1].vec4[3]) * alpha;
|
||||
} else {
|
||||
kfs->current.data = kfs->values[idx - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
382
hi/serialize.c
382
hi/serialize.c
@ -1,382 +0,0 @@
|
||||
#include"node.h"
|
||||
|
||||
#include<eebie/writer.h>
|
||||
#include<eebie/reader.h>
|
||||
#include<assert.h>
|
||||
#include<stdio.h>
|
||||
#include"node_internal.h"
|
||||
#include<endian.h>
|
||||
|
||||
#define ID_PROJECT 0x10000000
|
||||
#define ID_DURATION 0x4000
|
||||
#define ID_TIME 0x4001
|
||||
#define ID_KEYFRAMES 0x200000
|
||||
#define ID_CHIVAL 0x80
|
||||
#define ID_CHIVAL_TYPE 0x81
|
||||
#define ID_LINK 0x82
|
||||
#define ID_DATA 0x83
|
||||
#define ID_EXTRAPOLATION_MODE 0x4002
|
||||
#define ID_EXTRAPOLATION_PARAM 0x4003
|
||||
#define ID_NODE 0x84
|
||||
#define ID_NODE_TYPE 0x85
|
||||
#define ID_LIFESPAN_START 0x4004
|
||||
#define ID_LIFESPAN_END 0x4005
|
||||
|
||||
static void put_chival(CHiNodeGraph *ng, EBMLWriter *ebml, CHiValue val) {
|
||||
ebml_writer_push(ebml, ID_CHIVAL);
|
||||
ebml_writer_put(ebml, ID_CHIVAL_TYPE, EBML_UNSIGNED_INTEGER, (EBMLPrimitive) {.uInt = val.type});
|
||||
|
||||
if(val.linked.to) {
|
||||
size_t index;
|
||||
for(index = 0; index < ng->count; index++) {
|
||||
if(ng->nodes[index] == val.linked.to) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(index < ng->count);
|
||||
|
||||
ebml_writer_put(ebml, ID_LINK, EBML_UNSIGNED_INTEGER, (EBMLPrimitive) {.uInt = (index << 16) | (val.linked.idx)});
|
||||
}
|
||||
|
||||
if(val.type == CUTIHI_VAL_TEXT) {
|
||||
ebml_writer_put(ebml, ID_DATA, EBML_BINARY, (EBMLPrimitive) {.binary = {.ptr = val.data.text, .length = strlen(val.data.text)}});
|
||||
} else if(val.type == CUTIHI_VAL_VEC4) {
|
||||
ebml_writer_put(ebml, ID_DATA, EBML_BINARY, (EBMLPrimitive) {.binary = {.ptr = val.data.vec4, .length = sizeof(val.data.vec4)}});
|
||||
} else if(val.type == CUTIHI_VAL_KEYED) {
|
||||
size_t index;
|
||||
for(index = 0; index < ng->keyframesList.count; index++) {
|
||||
if(ng->keyframesList.keyframes[index] == val.data.keyed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(index < ng->count);
|
||||
|
||||
ebml_writer_put(ebml, ID_DATA, EBML_UNSIGNED_INTEGER, (EBMLPrimitive) {.uInt = index});
|
||||
}
|
||||
ebml_writer_pop(ebml);
|
||||
}
|
||||
|
||||
static size_t ebml_write_callback(EBMLWriter *ebml, const void *buf, size_t length) {
|
||||
CHiSaveWriter writer = ((void**) ebml->ud)[0];
|
||||
void *ud = ((void**) ebml->ud)[1];
|
||||
return writer(ud, buf, length);
|
||||
}
|
||||
static void *ebml_alloc_callback(EBMLWriter *ebml, void *buf, size_t length) {
|
||||
return realloc(buf, length);
|
||||
}
|
||||
|
||||
CUTIVIS int CHi_NodeGraphSave(CHiNodeGraph *ng, CHiSaveWriter writer, CHiSaveCustomNodeData customNodeData, void *ud) {
|
||||
EBMLWriter ebml;
|
||||
ebml_writer_init(&ebml);
|
||||
|
||||
void *ebmlud[2] = {writer, ud};
|
||||
|
||||
ebml.ud = ebmlud;
|
||||
ebml.eventWrite = ebml_write_callback;
|
||||
ebml.eventAlloc = ebml_alloc_callback;
|
||||
|
||||
ebml_writer_push(&ebml, 0x1A45DFA3);
|
||||
ebml_writer_put(&ebml, 0x4286, EBML_UNSIGNED_INTEGER, (EBMLPrimitive) {.uInt = 1});
|
||||
ebml_writer_put(&ebml, 0x4282, EBML_STRING, (EBMLPrimitive) {.string = "cuticle"});
|
||||
ebml_writer_pop(&ebml);
|
||||
|
||||
ebml_writer_push(&ebml, ID_PROJECT);
|
||||
if(ng->duration != -1) {
|
||||
ebml_writer_put(&ebml, ID_DURATION, EBML_FLOAT4, (EBMLPrimitive) {.flt4 = ng->duration});
|
||||
}
|
||||
ebml_writer_put(&ebml, ID_TIME, EBML_FLOAT4, (EBMLPrimitive) {.flt4 = ng->time});
|
||||
|
||||
for(size_t i = 0; i < ng->keyframesList.count; i++) {
|
||||
CHiKeyframes *kfs = ng->keyframesList.keyframes[i];
|
||||
|
||||
ebml_writer_push(&ebml, ID_KEYFRAMES);
|
||||
//ebml_writer_put(&ebml, ID_CHIVAL_TYPE, EBML_UNSIGNED_INTEGER, (EBMLPrimitive) {.uInt = kfs->type});
|
||||
|
||||
for(size_t k = 0; k < kfs->count; k++) {
|
||||
ebml_writer_put(&ebml, ID_TIME, EBML_FLOAT4, (EBMLPrimitive) {.flt4 = kfs->times[k]});
|
||||
put_chival(ng, &ebml, (CHiValue) {.type = kfs->type, .linked = {}, .data = kfs->values[k]});
|
||||
}
|
||||
|
||||
ebml_writer_put(&ebml, ID_EXTRAPOLATION_MODE, EBML_UNSIGNED_INTEGER, (EBMLPrimitive) {.uInt = kfs->extrapolationMode});
|
||||
ebml_writer_put(&ebml, ID_EXTRAPOLATION_PARAM, EBML_BINARY, (EBMLPrimitive) {.binary = {.ptr = &kfs->extrapolationParameter, sizeof(kfs->extrapolationParameter)}});
|
||||
ebml_writer_pop(&ebml);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < ng->count; i++) {
|
||||
CHiPubNode *node = ng->nodes[i];
|
||||
|
||||
ebml_writer_push(&ebml, ID_NODE);
|
||||
ebml_writer_put(&ebml, ID_NODE_TYPE, EBML_BINARY, (EBMLPrimitive) {.binary = {.ptr = &node->type, sizeof(node->type)}});
|
||||
|
||||
if(node->lifespan.start != 0) {
|
||||
ebml_writer_put(&ebml, ID_LIFESPAN_START, EBML_FLOAT4, (EBMLPrimitive) {.flt4 = node->lifespan.start});
|
||||
}
|
||||
if(node->lifespan.end != 0) {
|
||||
ebml_writer_put(&ebml, ID_LIFESPAN_END, EBML_FLOAT4, (EBMLPrimitive) {.flt4 = node->lifespan.end});
|
||||
}
|
||||
|
||||
for(size_t sink = 0; sink < node->sinkCount; sink++) {
|
||||
put_chival(ng, &ebml, node->sinks[sink]);
|
||||
}
|
||||
|
||||
if(customNodeData) {
|
||||
customNodeData(ud, &ebml, node);
|
||||
}
|
||||
ebml_writer_pop(&ebml);
|
||||
}
|
||||
ebml_writer_pop(&ebml);
|
||||
|
||||
while(!ebml_writer_flush(&ebml));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct LoadState {
|
||||
uint8_t *accum;
|
||||
size_t accumSize;
|
||||
|
||||
CHiNodeGraph *ng;
|
||||
|
||||
void *ud;
|
||||
CHiLoadCustomNodeData customNodeData;
|
||||
|
||||
// Filled in by callbacks
|
||||
CHiValue activeVal;
|
||||
|
||||
// Filled in by callbacks
|
||||
size_t activeNodeNextSinkIdx;
|
||||
CHiPubNode *activeNode;
|
||||
};
|
||||
|
||||
static EBMLElementType ebml_enter_callback(EBMLReader *ebml, uint64_t id, uint64_t length) {
|
||||
struct LoadState *state = ebml->ud;
|
||||
|
||||
if(id == ID_KEYFRAMES) {
|
||||
state->ng->keyframesList.keyframes = realloc(state->ng->keyframesList.keyframes, sizeof(*state->ng->keyframesList.keyframes) * (++state->ng->keyframesList.count));
|
||||
state->ng->keyframesList.keyframes[state->ng->keyframesList.count - 1] = calloc(1, sizeof(CHiKeyframes));
|
||||
} else if(id == ID_CHIVAL) {
|
||||
memset(&state->activeVal, 0, sizeof(state->activeVal));
|
||||
}
|
||||
|
||||
return (id == ID_PROJECT || id == ID_KEYFRAMES || id == ID_CHIVAL || id == ID_NODE || id == 0x5000) ? EBML_TREE : EBML_BINARY;
|
||||
}
|
||||
|
||||
static void ebml_data_callback(EBMLReader *ebml, const uint8_t *data, size_t length) {
|
||||
struct LoadState *state = ebml->ud;
|
||||
|
||||
state->accum = realloc(state->accum, state->accumSize + length);
|
||||
memcpy(state->accum + state->accumSize, data, length);
|
||||
state->accumSize += length;
|
||||
}
|
||||
|
||||
static void ebml_exit_callback(EBMLReader *ebml) {
|
||||
struct LoadState *state = ebml->ud;
|
||||
|
||||
uint64_t parent = ebml->currentDepth >= 2 ? ebml->idStack[ebml->currentDepth - 2] : 0;
|
||||
uint64_t id = ebml->idStack[ebml->currentDepth - 1];
|
||||
|
||||
if(id == ID_NODE) {
|
||||
state->activeNode = NULL;
|
||||
} else if(parent == 0x5000 && state->customNodeData) {
|
||||
assert(state->activeNode == state->ng->nodes[state->ng->count - 1]);
|
||||
|
||||
state->customNodeData(state->ud, state->ng->count - 1, id, state->accum, state->accumSize);
|
||||
} else if(parent == ID_NODE) {
|
||||
if(id == ID_NODE_TYPE) {
|
||||
assert(state->accumSize <= 8);
|
||||
|
||||
uint64_t type = 0;
|
||||
memcpy((char*) &type + sizeof(type) - state->accumSize, state->accum, state->accumSize);
|
||||
|
||||
CHiPubNode *n = NULL;
|
||||
|
||||
if(type == CUTIHI_T('CPre','view')) {
|
||||
n = CHi_Preview();
|
||||
} else if(type == CUTIHI_T('CMix','er ')) {
|
||||
n = CHi_Mixer();
|
||||
} else if(type == CUTIHI_T('CTex','t ')) {
|
||||
n = CHi_Text();
|
||||
} else if(type == CUTIHI_T('CTim','e ')) {
|
||||
n = CHi_Time();
|
||||
} else if(type == CUTIHI_T('CMod','ulat')) {
|
||||
n = CHi_Modulate();
|
||||
} else if(type == CUTIHI_T('CCns','tCol')) {
|
||||
n = CHi_ConstantSample();
|
||||
} else if(type == CUTIHI_T('CEmb','ed ')) {
|
||||
n = CHi_Embed();
|
||||
} else if(type == CUTIHI_T('CIma','ge ')) {
|
||||
n = CHi_Image();
|
||||
} else if(type == CUTIHI_T('CWin','dow ')) {
|
||||
n = CHi_Window();
|
||||
} else if(type == CUTIHI_T('CInA','udio')) {
|
||||
n = CHi_Microphone();
|
||||
} else if(type == CUTIHI_T('CExp','Wave')) {
|
||||
n = CHi_ExportWav();
|
||||
} else if(type == CUTIHI_T('CMov','ie ')) {
|
||||
n = CHi_Movie();
|
||||
} else if(type == CUTIHI_T('CEnc','GVP8')) {
|
||||
n = CHi_EncodeVP8();
|
||||
} else if(type == CUTIHI_T('CEnc','GVP9')) {
|
||||
n = CHi_EncodeVP9();
|
||||
} else if(type == CUTIHI_T('CExp','Webm')) {
|
||||
n = CHi_MuxWebm();
|
||||
} else if(type == CUTIHI_T('CKey','hook')) {
|
||||
n = CHi_Keyhook();
|
||||
} else if(type == CUTIHI_T('CKey','hook')) {
|
||||
n = CHi_Keyhook();
|
||||
} else if(type == CUTIHI_T('CEnc','Opus')) {
|
||||
n = CHi_EncodeOpus();
|
||||
} else if(type == CUTIHI_T('CWeb','Cam ')) {
|
||||
n = CHi_Camera();
|
||||
} else if(type == CUTIHI_T('CCmp','nScl')) {
|
||||
n = CHi_ComponentScale();
|
||||
} else if(type == CUTIHI_T('CEnc','H264')) {
|
||||
n = CHi_EncodeH264();
|
||||
} else if(type == CUTIHI_T('CStr','RTMP')) {
|
||||
n = CHi_StreamRTMP();
|
||||
} else if(type == CUTIHI_T('CEnc','AACL')) {
|
||||
n = CHi_EncodeAAC();
|
||||
} else if(type == CUTIHI_T('CExp','Mkv ')) {
|
||||
n = CHi_MuxMatroska();
|
||||
}
|
||||
|
||||
n->ng = state->ng;
|
||||
|
||||
if(!n) {
|
||||
CHi_NodeGraphReset(state->ng);
|
||||
assert(0 && "Unknown node type.");
|
||||
}
|
||||
|
||||
state->ng->nodes = realloc(state->ng->nodes, sizeof(*state->ng->nodes) * (++state->ng->count));
|
||||
state->ng->nodes[state->ng->count - 1] = n;
|
||||
|
||||
state->activeNodeNextSinkIdx = 0;
|
||||
state->activeNode = n;
|
||||
} else if(id == ID_LIFESPAN_START) {
|
||||
state->activeNode->lifespan.start = *(float*) state->accum;
|
||||
} else if(id == ID_LIFESPAN_END) {
|
||||
state->activeNode->lifespan.end = *(float*) state->accum;
|
||||
} else if(id == ID_CHIVAL) {
|
||||
if(state->activeNodeNextSinkIdx >= state->activeNode->sinkCount) {
|
||||
state->activeNode->sinks = realloc(state->activeNode->sinks, sizeof(*state->activeNode->sinks) * (state->activeNode->sinkCount = (state->activeNodeNextSinkIdx + 1)));
|
||||
}
|
||||
state->activeNode->sinks[state->activeNodeNextSinkIdx++] = state->activeVal;
|
||||
}
|
||||
} else if(parent == ID_CHIVAL) {
|
||||
if(id == ID_CHIVAL_TYPE) {
|
||||
state->activeVal.type = *(uint8_t*) state->accum;
|
||||
} else if(id == ID_LINK) {
|
||||
assert(state->accumSize <= 8);
|
||||
|
||||
uint64_t data = 0;
|
||||
memcpy((char*) &data + sizeof(data) - state->accumSize, state->accum, state->accumSize);
|
||||
data = htobe64(data);
|
||||
|
||||
uint16_t srcIdx = data & 0xFFFF;
|
||||
uint64_t nodeIdx = data >> 16;
|
||||
|
||||
// linked.to is supposed to be a pointer but not all nodes are
|
||||
// available at this stage, so we'll fix it up after the EBML
|
||||
// parsing finishes
|
||||
state->activeVal.linked.to = (void*) (nodeIdx + 1);
|
||||
state->activeVal.linked.idx = srcIdx;
|
||||
} else if(id == ID_DATA) {
|
||||
if(state->activeVal.type == CUTIHI_VAL_TEXT) {
|
||||
state->activeVal.data.text = calloc(1, state->accumSize + 1);
|
||||
memcpy(state->activeVal.data.text, state->accum, state->accumSize);
|
||||
} else if(state->activeVal.type == CUTIHI_VAL_VEC4) {
|
||||
assert(state->accumSize <= 16 && state->accumSize % 4 == 0);
|
||||
|
||||
memcpy(state->activeVal.data.vec4, state->accum, state->accumSize);
|
||||
} else if(state->activeVal.type == CUTIHI_VAL_KEYED) {
|
||||
assert(state->accumSize <= 8);
|
||||
|
||||
uint64_t idx = 0;
|
||||
memcpy((char*) &idx + sizeof(idx) - state->accumSize, state->accum, state->accumSize);
|
||||
idx = htobe64(idx);
|
||||
|
||||
// keyed is supposed to be a pointer but keyframes may not
|
||||
// be available at this stage, so we'll fix it up after the
|
||||
// EBML parsing finishes
|
||||
state->activeVal.data.keyed = (void*) idx;
|
||||
} else {
|
||||
assert(0 && "Cannot load CHiValue data.");
|
||||
}
|
||||
}
|
||||
} else if(parent == ID_KEYFRAMES) {
|
||||
CHiKeyframes *kfs = state->ng->keyframesList.keyframes[state->ng->keyframesList.count - 1];
|
||||
if(id == ID_TIME) {
|
||||
kfs->times = realloc(kfs->times, sizeof(*kfs->times) * (++kfs->count));
|
||||
kfs->values = realloc(kfs->values, sizeof(*kfs->values) * kfs->count);
|
||||
|
||||
kfs->times[kfs->count - 1] = *(float*) state->accum;
|
||||
} else if(id == ID_CHIVAL) {
|
||||
assert(state->activeVal.linked.to == NULL);
|
||||
|
||||
kfs->values[kfs->count - 1] = state->activeVal.data;
|
||||
} else if(id == ID_EXTRAPOLATION_MODE) {
|
||||
kfs->extrapolationMode = *(uint8_t*) state->accum;
|
||||
} else if(id == ID_EXTRAPOLATION_PARAM) {
|
||||
assert(state->accumSize == 16);
|
||||
|
||||
memcpy(&kfs->extrapolationParameter, state->accum, 16);
|
||||
}
|
||||
}
|
||||
|
||||
state->accumSize = 0;
|
||||
}
|
||||
|
||||
CUTIVIS int CHi_NodeGraphLoad(CHiNodeGraph *ng, CHiLoadReader reader, CHiLoadCustomNodeData customNodeData, void *ud) {
|
||||
CHi_NodeGraphReset(ng);
|
||||
|
||||
ng->time = 0;
|
||||
ng->duration = -1;
|
||||
|
||||
EBMLReader ebml;
|
||||
ebml_reader_init(&ebml);
|
||||
|
||||
struct LoadState state = {.ng = ng, .ud = ud, .customNodeData = customNodeData};
|
||||
ebml.ud = &state;
|
||||
|
||||
ebml.eventEnterElement = ebml_enter_callback;
|
||||
ebml.eventDataChunk = ebml_data_callback;
|
||||
ebml.eventExitElement = ebml_exit_callback;
|
||||
|
||||
size_t i = 0;
|
||||
uint8_t buf[4096];
|
||||
while(1) {
|
||||
size_t readBytes = reader(ud, buf + i, sizeof(buf) - i);
|
||||
|
||||
i += readBytes;
|
||||
|
||||
size_t fedBytes = ebml_reader_feed(&ebml, buf, i);
|
||||
|
||||
memmove(buf, buf + fedBytes, sizeof(buf) - fedBytes);
|
||||
|
||||
i -= fedBytes;
|
||||
|
||||
if(readBytes == 0 && fedBytes == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Fix-up links/adjacencies
|
||||
for(size_t i = 0; i < ng->count; i++) {
|
||||
CHiPubNode *n = ng->nodes[i];
|
||||
for(size_t s = 0; s < n->sinkCount; s++) {
|
||||
if(n->sinks[s].linked.to) {
|
||||
n->sinks[s].linked.to = ng->nodes[(uintptr_t) n->sinks[s].linked.to - 1];
|
||||
|
||||
adjacency_add(n->sinks[s].linked.to, n);
|
||||
}
|
||||
|
||||
if(n->sinks[s].type == CUTIHI_VAL_KEYED) {
|
||||
n->sinks[s].data.keyed = ng->keyframesList.keyframes[(uintptr_t) n->sinks[s].data.keyed];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_keyed_values(ng);
|
||||
|
||||
return 0;
|
||||
}
|
13
hi/vpxenc.c
13
hi/vpxenc.c
@ -125,23 +125,24 @@ static int encodevpx_start(CHiPubNode *pubn) {
|
||||
vpx_codec_enc_config_default(node->iface, &node->cfg, 0);
|
||||
node->cfg.g_w = firstFrame->width;
|
||||
node->cfg.g_h = firstFrame->height;
|
||||
node->cfg.g_profile = 0;
|
||||
node->cfg.g_profile = 2;
|
||||
node->cfg.g_timebase.num = 1;
|
||||
node->cfg.g_timebase.den = 30;
|
||||
node->cfg.g_lag_in_frames = 0;
|
||||
node->cfg.g_threads = 4;
|
||||
node->cfg.kf_mode = VPX_KF_AUTO;
|
||||
node->cfg.kf_max_dist = 300;
|
||||
node->cfg.rc_end_usage = VPX_VBR;
|
||||
node->cfg.rc_target_bitrate = 2000;
|
||||
node->cfg.rc_min_quantizer = 0;
|
||||
node->cfg.rc_end_usage = VPX_CBR;
|
||||
node->cfg.rc_target_bitrate = 3000;
|
||||
node->cfg.rc_min_quantizer = 24;
|
||||
node->cfg.rc_max_quantizer = 32;
|
||||
node->cfg.rc_undershoot_pct = 95;
|
||||
|
||||
vpx_codec_enc_init(&node->codec, node->iface, &node->cfg, 0);
|
||||
vpx_codec_control(&node->codec, VP8E_SET_CPUUSED, 4);
|
||||
vpx_codec_control(&node->codec, VP8E_SET_CPUUSED, 9);
|
||||
//vpx_codec_control(&node->codec, VP9E_SET_SVC, 1);
|
||||
vpx_codec_control(&node->codec, VP9E_SET_ROW_MT, 1);
|
||||
vpx_codec_control(&node->codec, VP9E_SET_TILE_COLUMNS, 2);
|
||||
//vpx_codec_control(&node->codec, VP9E_SET_TILE_COLUMNS, 3);
|
||||
vpx_codec_control(&node->codec, VP9E_SET_TILE_ROWS, 1);
|
||||
vpx_codec_control(&node->codec, VP9E_SET_NOISE_SENSITIVITY, 0);
|
||||
vpx_codec_control(&node->codec, VP9E_SET_TUNE_CONTENT, VP9E_CONTENT_SCREEN);
|
||||
|
@ -43,7 +43,7 @@ static int muxwebm_perform(CHiPubNode *pubn) {
|
||||
|
||||
CHiMuxWebmNode *alln = (CHiMuxWebmNode*) pubn;
|
||||
|
||||
if(pubn->sinks[1].linked.to) {
|
||||
if(pubn->sinks[1].data.linked.to) {
|
||||
CHiBSFrames *opus = CHi_Crawl(&pubn->sinks[1])->data.bitstream;
|
||||
for(size_t i = 0; i < opus->count; i++) {
|
||||
alln->audioBacklog.push(opus->data[i]);
|
||||
@ -57,7 +57,7 @@ static int muxwebm_perform(CHiPubNode *pubn) {
|
||||
}
|
||||
}
|
||||
|
||||
while(pubn->sinks[1].linked.to && alln->audioBacklog.size() > 0 && alln->videoBacklog.size() > 0 && alln->audioBacklog.front().timestamp <= alln->videoBacklog.front().timestamp) {
|
||||
while(pubn->sinks[1].data.linked.to && alln->audioBacklog.size() > 0 && alln->videoBacklog.size() > 0 && alln->audioBacklog.front().timestamp <= alln->videoBacklog.front().timestamp) {
|
||||
Frame frame;
|
||||
frame.Init((const uint8_t*) alln->audioBacklog.front().ptr, alln->audioBacklog.front().sz);
|
||||
frame.set_track_number(alln->audioTrack);
|
||||
@ -68,7 +68,7 @@ static int muxwebm_perform(CHiPubNode *pubn) {
|
||||
alln->audioBacklog.pop();
|
||||
}
|
||||
|
||||
if(pubn->sinks[1].linked.to == NULL || (alln->audioBacklog.size() > 0 && alln->videoBacklog.size() > 0 && alln->audioBacklog.front().timestamp >= alln->videoBacklog.front().timestamp)) {
|
||||
if(pubn->sinks[1].data.linked.to == NULL || (alln->audioBacklog.size() > 0 && alln->videoBacklog.size() > 0 && alln->audioBacklog.front().timestamp >= alln->videoBacklog.front().timestamp)) {
|
||||
Frame frame;
|
||||
if(!frame.Init((const uint8_t*) alln->videoBacklog.front().ptr, alln->videoBacklog.front().sz)) puts("INIT FAIL");
|
||||
frame.set_track_number(alln->videoTrack);
|
||||
@ -122,7 +122,7 @@ CUTIVIS int CHi_MuxWebm_Start(CHiPubNode *pubn) {
|
||||
alln->seg.GetSegmentInfo()->set_writing_app("Cuticle");
|
||||
|
||||
/* Hack into first frame to get resolution */
|
||||
CHiPubNode *evp9 = pubn->sinks[0].linked.to;
|
||||
CHiPubNode *evp9 = pubn->sinks[0].data.linked.to;
|
||||
CHiImage *firstFrame = (CHiImage*) CHi_Crawl(&evp9->sinks[0])->data.sample;
|
||||
|
||||
alln->videoTrack = alln->seg.AddVideoTrack(firstFrame->width, firstFrame->height, 0);
|
||||
@ -137,7 +137,7 @@ CUTIVIS int CHi_MuxWebm_Start(CHiPubNode *pubn) {
|
||||
track->SetColour(colourspace);
|
||||
alln->seg.CuesTrack(alln->videoTrack);
|
||||
|
||||
if(pubn->sinks[1].linked.to) {
|
||||
if(pubn->sinks[1].data.linked.to) {
|
||||
struct __attribute__((packed)) {
|
||||
uint32_t magic1;
|
||||
uint32_t magic2;
|
||||
|
218
hi/window.c
218
hi/window.c
@ -0,0 +1,218 @@
|
||||
#include"node.h"
|
||||
|
||||
#include<stdlib.h>
|
||||
|
||||
#include<X11/Xlib.h>
|
||||
#include<X11/Xutil.h>
|
||||
#include<sys/ipc.h>
|
||||
#include<sys/shm.h>
|
||||
#include<X11/extensions/XShm.h>
|
||||
#include<tmmintrin.h>
|
||||
#include<smmintrin.h>
|
||||
|
||||
#include<time.h>
|
||||
|
||||
#include<string.h>
|
||||
|
||||
#include"img.h"
|
||||
|
||||
#include"linearity.h"
|
||||
|
||||
#include"minitrace.h"
|
||||
|
||||
static Display *d;
|
||||
static Window root;
|
||||
|
||||
static int find_window(Display *d, Window *w, const char *contains) {
|
||||
if(contains) {
|
||||
int found = 0;
|
||||
Atom atom = XInternAtom(d, "_NET_CLIENT_LIST", 1);
|
||||
Atom actualType;
|
||||
int format;
|
||||
unsigned long numItems, bytesAfter;
|
||||
|
||||
Window *list;
|
||||
XTextProperty windowName;
|
||||
|
||||
int status = XGetWindowProperty(d, root, atom, 0L, ~0L, 0, AnyPropertyType, &actualType, &format, &numItems, &bytesAfter, (unsigned char**) &list);
|
||||
|
||||
if(status >= Success) {
|
||||
for(int i = 0; i < numItems; i++) {
|
||||
status = XGetWMName(d, list[i], &windowName);
|
||||
if(status >= Success) {
|
||||
if(windowName.value && strstr(windowName.value, contains)) {
|
||||
*w = list[i];
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XFree(list);
|
||||
|
||||
return found;
|
||||
} else {
|
||||
*w = root;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
CHiPubNode pub;
|
||||
|
||||
Window xcache;
|
||||
XImage *ximg;
|
||||
XShmSegmentInfo shminfo;
|
||||
|
||||
CHiImage *vcache;
|
||||
} CHiWindowNode;
|
||||
|
||||
static int window_perform(CHiPubNode *n) {
|
||||
CHiWindowNode *w = (CHiWindowNode*) n;
|
||||
|
||||
MTR_BEGIN("CHi", "window_perform");
|
||||
|
||||
Window toshoot;
|
||||
if(!find_window(d, &toshoot, CHi_Crawl(&n->sinks[0])->data.text)) return 0;
|
||||
|
||||
size_t stride;
|
||||
if(!w->xcache || w->xcache != toshoot) {
|
||||
w->xcache = toshoot;
|
||||
|
||||
XWindowAttributes attrs;
|
||||
XGetWindowAttributes(d, toshoot, &attrs);
|
||||
|
||||
w->ximg = XShmCreateImage(d, attrs.visual, 32, ZPixmap, NULL, &w->shminfo, attrs.width, attrs.height);
|
||||
stride = ((w->ximg->bytes_per_line + 15) & ~15);
|
||||
w->shminfo.shmid = shmget(IPC_PRIVATE, stride * w->ximg->height, IPC_CREAT | 0777);
|
||||
w->shminfo.shmaddr = w->ximg->data = shmat(w->shminfo.shmid, 0, 0);
|
||||
w->shminfo.readOnly = False;
|
||||
XShmAttach(d, &w->shminfo);
|
||||
|
||||
w->vcache = CHi_Image_New(2, 4, 8 * attrs.width, attrs.width, attrs.height, NULL);
|
||||
} else {
|
||||
stride = ((w->ximg->bytes_per_line + 15) & ~15);
|
||||
}
|
||||
|
||||
XWindowAttributes toshootattrs;
|
||||
XGetWindowAttributes(d, w->xcache, &toshootattrs);
|
||||
|
||||
XShmGetImage(d, w->xcache, w->ximg, 0, 0, AllPlanes);
|
||||
|
||||
// Turn u8 image to u16
|
||||
#pragma omp parallel for
|
||||
for(size_t y = 0; y < w->vcache->height; y++) {
|
||||
for(size_t x = 0; x < w->vcache->width; x += 2) {
|
||||
__m128i c = _mm_loadu_si128((__m128i*) ((uintptr_t) w->ximg->data + y * w->ximg->bytes_per_line + x * 4));
|
||||
c = _mm_shuffle_epi8(c, _mm_set_epi8(7, -128, 6, -128, 5, -128, 4, -128, 3, -128, 2, -128, 1, -128, 0, -128));
|
||||
c = apply_gamma_epi16(c, _mm_set_ps(1, 2.2f, 2.2f, 2.2f));
|
||||
_mm_storeu_si128((__m128i*) ((uintptr_t) w->vcache->data16 + y * w->vcache->stride + x * 8), c);
|
||||
}
|
||||
}
|
||||
|
||||
n->sources[0].type = CUTIHI_VAL_SAMPLE;
|
||||
n->sources[0].data.sample = w->vcache;
|
||||
|
||||
MTR_END("CHi", "window_perform");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void window_destroy(CHiPubNode *pubn) {
|
||||
CHiWindowNode *n = (void*) pubn;
|
||||
|
||||
if(n->vcache) {
|
||||
XShmDetach(d, &n->shminfo);
|
||||
shmdt(n->shminfo.shmaddr);
|
||||
XDestroyImage(n->ximg);
|
||||
}
|
||||
|
||||
free(pubn);
|
||||
}
|
||||
|
||||
CUTIVIS CHiPubNode *CHi_Window() {
|
||||
if(!d) {
|
||||
d = XOpenDisplay(NULL);
|
||||
root = RootWindow(d, DefaultScreen(d));
|
||||
}
|
||||
|
||||
CHiWindowNode *n = calloc(1, sizeof(*n));
|
||||
n->pub.type = CUTIHI_T('CWin','dow ');
|
||||
n->pub.Start = n->pub.Stop = NULL;
|
||||
n->pub.Perform = window_perform;
|
||||
n->pub.Destroy = window_destroy;
|
||||
n->pub.sinkCount = 1;
|
||||
n->pub.sinks = calloc(sizeof(*n->pub.sinks), 1);
|
||||
n->pub.sourceCount = 1;
|
||||
n->pub.sources = calloc(sizeof(*n->pub.sources), 1);
|
||||
|
||||
n->xcache = 0;
|
||||
n->vcache = NULL;
|
||||
|
||||
return &n->pub;
|
||||
}
|
||||
|
||||
// All of the following are ews
|
||||
|
||||
CUTIVIS size_t CHi_Window_GetSourceCount() {
|
||||
Atom atom = XInternAtom(d, "_NET_CLIENT_LIST", 1);
|
||||
Atom actualType;
|
||||
int format;
|
||||
unsigned long numItems, bytesAfter;
|
||||
|
||||
Window *list;
|
||||
|
||||
int status = XGetWindowProperty(d, root, atom, 0L, ~0L, 0, AnyPropertyType, &actualType, &format, &numItems, &bytesAfter, (unsigned char**) &list);
|
||||
|
||||
//XFree(list);
|
||||
|
||||
return status >= Success ? numItems : 0;
|
||||
}
|
||||
|
||||
CUTIVIS const char *CHi_Window_GetSourceName(size_t idx) {
|
||||
int found = 0;
|
||||
Atom atom = XInternAtom(d, "_NET_CLIENT_LIST", 1);
|
||||
Atom actualType;
|
||||
int format;
|
||||
unsigned long numItems, bytesAfter;
|
||||
|
||||
Window *list;
|
||||
XTextProperty windowName;
|
||||
|
||||
int status = XGetWindowProperty(d, root, atom, 0L, ~0L, 0, AnyPropertyType, &actualType, &format, &numItems, &bytesAfter, (unsigned char**) &list);
|
||||
|
||||
if(status >= Success) {
|
||||
//XFree(list);
|
||||
|
||||
status = XGetWMName(d, list[idx], &windowName);
|
||||
if(status >= Success) {
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return found ? strdup(windowName.value ? windowName.value : "") : NULL;
|
||||
}
|
||||
|
||||
CUTIVIS uintptr_t CHi_Window_GetSourceData(size_t idx) {
|
||||
Atom atom = XInternAtom(d, "_NET_CLIENT_LIST", 1);
|
||||
Atom actualType;
|
||||
int format;
|
||||
unsigned long numItems, bytesAfter;
|
||||
|
||||
Window *list;
|
||||
|
||||
int status = XGetWindowProperty(d, root, atom, 0L, ~0L, 0, AnyPropertyType, &actualType, &format, &numItems, &bytesAfter, (unsigned char**) &list);
|
||||
|
||||
if(status >= Success) {
|
||||
Window ret = list[idx];
|
||||
//XFree(list);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CUTIVIS size_t CHi_Window_GetNextSource(size_t i) {
|
||||
return i + 1;
|
||||
}
|
130
hi/window.cpp
130
hi/window.cpp
@ -1,130 +0,0 @@
|
||||
#include"node.h"
|
||||
|
||||
#include<stdlib.h>
|
||||
|
||||
#include<ScreenCapture.h>
|
||||
#include<mutex>
|
||||
|
||||
#include<tmmintrin.h>
|
||||
#include<smmintrin.h>
|
||||
|
||||
#include<time.h>
|
||||
|
||||
#include<string.h>
|
||||
|
||||
#include"img.h"
|
||||
|
||||
#include"linearity.h"
|
||||
|
||||
#include"minitrace.h"
|
||||
|
||||
typedef struct {
|
||||
CHiPubNode pub;
|
||||
|
||||
char* lastWindowString;
|
||||
std::shared_ptr<SL::Screen_Capture::IScreenCaptureManager> config;
|
||||
|
||||
std::mutex mut;
|
||||
std::vector<CHiImage*> images;
|
||||
} CHiWindowNode;
|
||||
|
||||
static int window_perform(CHiPubNode *n) {
|
||||
CHiWindowNode *w = (CHiWindowNode*) n;
|
||||
|
||||
MTR_BEGIN("CHi", "window_perform");
|
||||
|
||||
const char *expectedTitle = CHi_Crawl(&w->pub.sinks[0])->data.text;
|
||||
|
||||
if(w->lastWindowString == nullptr || strcmp(w->lastWindowString, expectedTitle)) {
|
||||
if(w->lastWindowString) {
|
||||
free(w->lastWindowString);
|
||||
}
|
||||
w->lastWindowString = strdup(expectedTitle);
|
||||
|
||||
w->config = SL::Screen_Capture::CreateCaptureConfiguration([=](){
|
||||
for(SL::Screen_Capture::Window& window : SL::Screen_Capture::GetWindows()) {
|
||||
if(!strcmp(window.Name, w->lastWindowString)) {
|
||||
return std::vector<SL::Screen_Capture::Window>{window};
|
||||
}
|
||||
}
|
||||
return std::vector<SL::Screen_Capture::Window>{};
|
||||
})->onNewFrame([=](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Window& window){
|
||||
CHiImage *new_image = CHi_Image_New(2, 4, (window.Size.x * 8 + 15) & ~15, window.Size.x, window.Size.y, nullptr);
|
||||
memset(new_image->data8, 0, new_image->stride * new_image->height);
|
||||
|
||||
#pragma omp parallel for
|
||||
for(size_t y = 0; y < new_image->height; y++) {
|
||||
uint8_t buf[16] = {};
|
||||
for(size_t x = 0; x < new_image->width; x += 2) {
|
||||
memcpy(buf, &img.Data[y * new_image->width + x], 8);
|
||||
|
||||
__m128i c = _mm_loadu_si128((__m128i*) buf);
|
||||
c = _mm_shuffle_epi8(c, _mm_set_epi8(7, -128, 6, -128, 5, -128, 4, -128, 3, -128, 2, -128, 1, -128, 0, -128));
|
||||
c = apply_gamma_epi16(c, _mm_set_ps(1, 2.2f, 2.2f, 2.2f));
|
||||
_mm_store_si128((__m128i*) ((uintptr_t) new_image->data8 + y * new_image->stride + x * 8), c);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock{w->mut};
|
||||
while(w->images.size() > 0) {
|
||||
CHi_Image_Free(w->images.front());
|
||||
w->images.erase(w->images.begin());
|
||||
}
|
||||
w->images.push_back(new_image);
|
||||
})->start_capturing();
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock{w->mut};
|
||||
if(w->images.size() > 0) {
|
||||
if(n->sources[0].data.sample) {
|
||||
CHi_Image_Free(n->sources[0].data.sample);
|
||||
}
|
||||
|
||||
n->sources[0].type = CUTIHI_VAL_SAMPLE;
|
||||
n->sources[0].data.sample = w->images.front();
|
||||
|
||||
w->images.erase(w->images.begin());
|
||||
}
|
||||
|
||||
MTR_END("CHi", "window_perform");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void window_destroy(CHiPubNode *pubn) {
|
||||
CHiWindowNode *n = (CHiWindowNode*) pubn;
|
||||
delete n;
|
||||
}
|
||||
|
||||
CUTIVIS CHiPubNode *CHi_Window() {
|
||||
auto *n = new CHiWindowNode();
|
||||
n->pub.type = CUTIHI_T('CWin','dow ');
|
||||
n->pub.Start = n->pub.Stop = NULL;
|
||||
n->pub.Perform = window_perform;
|
||||
n->pub.Destroy = window_destroy;
|
||||
n->pub.sinkCount = 1;
|
||||
n->pub.sinks = (CHiValue*) calloc(sizeof(*n->pub.sinks), 1);
|
||||
n->pub.sourceCount = 1;
|
||||
n->pub.sources = (CHiValue*) calloc(sizeof(*n->pub.sources), 1);
|
||||
|
||||
return &n->pub;
|
||||
}
|
||||
|
||||
CUTIVIS size_t CHi_Window_GetList(void **buf) {
|
||||
auto vec = SL::Screen_Capture::GetWindows();
|
||||
|
||||
*buf = calloc(vec.size(), sizeof(vec[0]));
|
||||
memcpy(*buf, &vec[0], sizeof(vec[0]) * vec.size());
|
||||
|
||||
return vec.size();
|
||||
}
|
||||
|
||||
CUTIVIS const char *CHi_Window_GetName(void *buf, size_t i) {
|
||||
return ((SL::Screen_Capture::Window*) buf)[i].Name;
|
||||
}
|
||||
CUTIVIS size_t CHi_Window_GetHandle(void *buf, size_t i) {
|
||||
return ((SL::Screen_Capture::Window*) buf)[i].Handle;
|
||||
}
|
||||
CUTIVIS void CHi_Window_FreeList(void *buf) {
|
||||
free(buf);
|
||||
}
|
283
ui/frame.cpp
283
ui/frame.cpp
@ -22,26 +22,13 @@
|
||||
#include"timeline.h"
|
||||
#include<functional>
|
||||
#include<algorithm>
|
||||
#include<eebie/writer.h>
|
||||
|
||||
#define SSE_MATHFUN_WITH_CODE
|
||||
#include<hi/kumb.h>
|
||||
|
||||
#include<hi/linearity.h>
|
||||
|
||||
extern Frame *globaldis;
|
||||
|
||||
// The Preview node is actually a NOOP
|
||||
// Must inject our own function when either loading or creating projects
|
||||
static int INJECTED_PREVIEW_FUNC(CHiPubNode *preview) {
|
||||
CHiValue *val = CHi_Crawl(&preview->sinks[0]);
|
||||
|
||||
if(val->type == CUTIHI_VAL_SAMPLE && val->data.sample) {
|
||||
globaldis->viewer->SetImage(val->data.sample);
|
||||
}
|
||||
|
||||
return 1;
|
||||
};
|
||||
static Frame *globaldis;
|
||||
|
||||
std::string node_name_from_id(uint64_t id) {
|
||||
static std::unordered_map<uint64_t, std::string> NODE_ID_NAMES = {
|
||||
@ -99,9 +86,10 @@ static void ShapeGrNode(GrNode *gn) {
|
||||
gn->sources = {{"Audio", GrNode::Port::Type::SAMPLE}};
|
||||
|
||||
int numSinks = gn->logical->sinkCount;
|
||||
if(gn->logical->sinks[numSinks - 1].type == CUTIHI_VAL_NONE) {
|
||||
numSinks++;
|
||||
while(numSinks > 0 && gn->logical->sinks[numSinks - 1].type == CUTIHI_VAL_NONE) {
|
||||
numSinks--;
|
||||
}
|
||||
numSinks++;
|
||||
|
||||
gn->sinks.clear();
|
||||
for(int s = 0; s < numSinks; s++) {
|
||||
@ -236,40 +224,76 @@ Frame::Frame() : wxFrame(NULL, wxID_ANY, "Cuticle", wxDefaultPosition, {wxSystem
|
||||
wxFileDialog save{this, "Save", "", "", "Cuticle Project (*.ctc)|*.ctc", wxFD_SAVE | wxFD_OVERWRITE_PROMPT};
|
||||
|
||||
if(save.ShowModal() == wxID_OK) {
|
||||
struct UD {
|
||||
FILE *f;
|
||||
Frame *frame;
|
||||
} ud;
|
||||
FILE *f = fopen(save.GetPath().mb_str(), "wb");
|
||||
|
||||
wxString path = save.GetPath();
|
||||
if(!path.EndsWith(".ctc")) {
|
||||
path += ".ctc";
|
||||
}
|
||||
CHi_NodeGraphSave(graph->backendNG, +[](void *ud, const void *data, size_t len){
|
||||
auto f = (FILE*) ud;
|
||||
|
||||
ud.f = fopen(path.mb_str(), "wb");
|
||||
ud.frame = this;
|
||||
return fwrite(data, 1, len, f);
|
||||
}, f);
|
||||
|
||||
CHi_NodeGraphSave(graph->backendNG, +[](void *udPtr, const void *data, size_t len){
|
||||
auto &ud = *(UD*) udPtr;
|
||||
return fwrite(data, 1, len, ud.f);
|
||||
}, +[](void *udPtr, EBMLWriter *ebml, CHiPubNode *node){
|
||||
auto &ud = *(UD*) udPtr;
|
||||
|
||||
GrNode *gn = ud.frame->graph->get_graphical(node);
|
||||
for(size_t n = 0; n < graph->backendNG->count; n++) {
|
||||
GrNode *gn = graph->get_graphical(graph->backendNG->nodes[n]);
|
||||
|
||||
int32_t pos[2] = {gn->GetPosition().x, gn->GetPosition().y};
|
||||
ebml_writer_push(ebml, 0x5000);
|
||||
ebml_writer_put(ebml, 0x5001, EBML_BINARY, (EBMLPrimitive) {.binary = {.ptr = (uint8_t*) &pos, sizeof(pos)}});
|
||||
ebml_writer_pop(ebml);
|
||||
}, &ud);
|
||||
fwrite(pos, sizeof(pos), 1, f);
|
||||
}
|
||||
|
||||
fclose(ud.f);
|
||||
fclose(f);
|
||||
}
|
||||
} else if(ev.GetId() == wxID_OPEN) {
|
||||
wxFileDialog load{this, "Load", "", "", "Cuticle Project (*.ctc)|*.ctc", wxFD_OPEN | wxFD_FILE_MUST_EXIST};
|
||||
|
||||
if(load.ShowModal() == wxID_OK) {
|
||||
LoadProject(load.GetPath().utf8_string());
|
||||
FILE *f = fopen(load.GetPath().mb_str(), "rb");
|
||||
|
||||
if(CHi_NodeGraphLoad(graph->backendNG, +[](void *ud, void *data, size_t len){
|
||||
auto f = (FILE*) ud;
|
||||
|
||||
return fread(data, 1, len, f);
|
||||
}, f) == 0) {
|
||||
|
||||
for(GrNode *gnode : graph->gnodes) {
|
||||
gnode->Destroy();
|
||||
}
|
||||
|
||||
graph->gnodes.clear();
|
||||
graph->links.clear();
|
||||
|
||||
for(size_t n = 0; n < graph->backendNG->count; n++) {
|
||||
GrNode *gnode = new GrNode(graph);
|
||||
|
||||
int32_t pos[2];
|
||||
fread(pos, sizeof(pos), 1, f);
|
||||
|
||||
gnode->SetPosition({pos[0], pos[1]});
|
||||
|
||||
gnode->logical = graph->backendNG->nodes[n];
|
||||
|
||||
ShapeGrNode(gnode);
|
||||
|
||||
graph->gnodes.push_back(gnode);
|
||||
}
|
||||
|
||||
for(size_t n = 0; n < graph->backendNG->count; n++) {
|
||||
CHiPubNode *node = graph->backendNG->nodes[n];
|
||||
|
||||
for(size_t s = 0; s < node->sinkCount; s++) {
|
||||
if(node->sinks[s].type == CUTIHI_VAL_LINKED) {
|
||||
graph->links.push_back(NodeGraph::Link{graph->gnodes[n], s, *std::find_if(graph->gnodes.begin(), graph->gnodes.end(), [=](GrNode *gn){ return gn->logical == node->sinks[s].data.linked.to; }), node->sinks[s].data.linked.idx});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toolbar.duration->SetSeconds(std::max(0.f, graph->backendNG->duration));
|
||||
|
||||
if(graph->backendNG->duration <= 0) {
|
||||
toolbar.durationEnable->SetValue(false);
|
||||
toolbar.duration->Enable(false);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -323,86 +347,6 @@ Frame::Frame() : wxFrame(NULL, wxID_ANY, "Cuticle", wxDefaultPosition, {wxSystem
|
||||
tlba->AddControl(toolbar.duration);
|
||||
tlba->AddControl(toolbar.btnPerform);
|
||||
|
||||
tlba->Realize();
|
||||
|
||||
aui.SetFlags(wxAUI_MGR_LIVE_RESIZE | wxAUI_MGR_DEFAULT);
|
||||
aui.Update();
|
||||
|
||||
Centre();
|
||||
|
||||
LoadProject("");
|
||||
graph->CreatePreviewNode();
|
||||
}
|
||||
|
||||
Frame::~Frame() {
|
||||
aui.UnInit();
|
||||
}
|
||||
|
||||
void Frame::LoadProject(std::string filename) {
|
||||
struct UD {
|
||||
FILE *f;
|
||||
Frame *frame;
|
||||
std::unordered_map<uint64_t, wxPoint> nodePositions;
|
||||
} ud = {};
|
||||
|
||||
if(filename != "") {
|
||||
ud.f = fopen(filename.c_str(), "rb");
|
||||
}
|
||||
ud.frame = this;
|
||||
|
||||
if(filename == "" || CHi_NodeGraphLoad(graph->backendNG, +[](void *udPtr, void *data, size_t len){
|
||||
auto &ud = *(UD*) udPtr;
|
||||
return fread(data, 1, len, ud.f);
|
||||
}, +[](void *udPtr, uint64_t nodeIdx, uint64_t elId, const void *data, size_t len){
|
||||
auto &ud = *(UD*) udPtr;
|
||||
if(elId == 0x5001) {
|
||||
auto pos = (const int32_t*) data;
|
||||
ud.nodePositions.emplace(nodeIdx, wxPoint{pos[0], pos[1]});
|
||||
}
|
||||
}, &ud) == 0) {
|
||||
|
||||
for(GrNode *gnode : graph->gnodes) {
|
||||
gnode->Destroy();
|
||||
}
|
||||
|
||||
graph->gnodes.clear();
|
||||
graph->links.clear();
|
||||
|
||||
for(size_t n = 0; n < graph->backendNG->count; n++) {
|
||||
GrNode *gnode = new GrNode(graph);
|
||||
|
||||
gnode->SetPosition(ud.nodePositions[n]);
|
||||
|
||||
gnode->logical = graph->backendNG->nodes[n];
|
||||
|
||||
ShapeGrNode(gnode);
|
||||
|
||||
if(gnode->logical->type == CUTIHI_T('CPre', 'view')) {
|
||||
gnode->logical->Perform = INJECTED_PREVIEW_FUNC;
|
||||
}
|
||||
|
||||
graph->gnodes.push_back(gnode);
|
||||
}
|
||||
|
||||
for(size_t n = 0; n < graph->backendNG->count; n++) {
|
||||
CHiPubNode *node = graph->backendNG->nodes[n];
|
||||
|
||||
for(size_t s = 0; s < node->sinkCount; s++) {
|
||||
if(node->sinks[s].linked.to) {
|
||||
graph->links.push_back(NodeGraph::Link{graph->gnodes[n], s, *std::find_if(graph->gnodes.begin(), graph->gnodes.end(), [=](GrNode *gn){ return gn->logical == node->sinks[s].linked.to; }), node->sinks[s].linked.idx});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toolbar.duration->SetSeconds(std::max(0.f, graph->backendNG->duration));
|
||||
|
||||
if(graph->backendNG->duration <= 0) {
|
||||
toolbar.durationEnable->SetValue(false);
|
||||
toolbar.duration->Enable(false);
|
||||
}
|
||||
|
||||
timeline->ResetRows();
|
||||
|
||||
graph->backendNG->eventOnStopComplete = +[](CHiNodeGraph *ng){
|
||||
wxTheApp->CallAfter([ng](){
|
||||
wxButton *btn = ((Frame*) ng->ud)->toolbar.btnPerform;
|
||||
@ -423,14 +367,19 @@ void Frame::LoadProject(std::string filename) {
|
||||
gn->Refresh();
|
||||
});
|
||||
};
|
||||
|
||||
tlba->Realize();
|
||||
|
||||
aui.SetFlags(wxAUI_MGR_LIVE_RESIZE | wxAUI_MGR_DEFAULT);
|
||||
aui.Update();
|
||||
|
||||
Centre();
|
||||
|
||||
graph->CreatePreviewNode();
|
||||
}
|
||||
|
||||
if(ud.f) {
|
||||
fclose(ud.f);
|
||||
}
|
||||
|
||||
// Force everything in the graph to be computed so the preview immediately shows up
|
||||
CHi_Hysteresis(graph->backendNG);
|
||||
Frame::~Frame() {
|
||||
aui.UnInit();
|
||||
}
|
||||
|
||||
bool GrNode::MouseOverPort(wxPoint point, bool &source, int &i) {
|
||||
@ -451,7 +400,7 @@ void GrNode::MakeKeyframe(int sinkIdx) {
|
||||
|
||||
CHi_MakeKeyframe(ng->backendNG, this->logical, sinkIdx);
|
||||
|
||||
globaldis->timeline->ResetRows();
|
||||
((Frame*) ng->GetParent())->timeline->Refresh();
|
||||
}
|
||||
|
||||
static bool has_errors(CHiPubNode *pn) {
|
||||
@ -639,7 +588,7 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
if(dlg.ShowModal() == wxID_OK) {
|
||||
pthread_mutex_lock(&this->logical->ng->mut);
|
||||
|
||||
CHiValue newv = {};
|
||||
CHiValue newv;
|
||||
newv.type = CUTIHI_VAL_VEC4;
|
||||
newv.data.vec4[0] = dlg.GetColourData().GetColour().Red() / 255.f;
|
||||
newv.data.vec4[1] = dlg.GetColourData().GetColour().Green() / 255.f;
|
||||
@ -655,7 +604,7 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
if(dlg.ShowModal() == wxID_OK) {
|
||||
pthread_mutex_lock(&this->logical->ng->mut);
|
||||
|
||||
CHiValue newv = {};
|
||||
CHiValue newv;
|
||||
newv.type = CUTIHI_VAL_TEXT;
|
||||
newv.data.text = strdup(dlg.GetPath().utf8_str());
|
||||
CHi_ConfigureSink(this->logical, p, newv);
|
||||
@ -668,7 +617,7 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
if(dlg.ShowModal() == wxID_OK) {
|
||||
pthread_mutex_lock(&this->logical->ng->mut);
|
||||
|
||||
CHiValue newv = {};
|
||||
CHiValue newv;
|
||||
newv.type = CUTIHI_VAL_TEXT;
|
||||
newv.data.text = strdup(dlg.GetPath().utf8_str());
|
||||
CHi_ConfigureSink(this->logical, p, newv);
|
||||
@ -716,7 +665,7 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
ctrl->Bind(wxEVT_KILL_FOCUS, [=](wxFocusEvent &ev){
|
||||
pthread_mutex_lock(&this->logical->ng->mut);
|
||||
|
||||
CHiValue newv = {};
|
||||
CHiValue newv;
|
||||
newv.type = CUTIHI_VAL_TEXT;
|
||||
char *c = (char*) malloc(ctrl->GetValue().Len() + 1);
|
||||
memcpy(c, ctrl->GetValue().c_str(), ctrl->GetValue().Len() + 1);
|
||||
@ -731,7 +680,7 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
if(ev.GetKeyCode() == WXK_RETURN) {
|
||||
pthread_mutex_lock(&this->logical->ng->mut);
|
||||
|
||||
CHiValue newv = {};
|
||||
CHiValue newv;
|
||||
newv.type = CUTIHI_VAL_TEXT;
|
||||
char *c = (char*) malloc(ctrl->GetValue().Len() + 1);
|
||||
memcpy(c, ctrl->GetValue().c_str(), ctrl->GetValue().Len() + 1);
|
||||
@ -755,7 +704,7 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
if(dlg.ShowModal() == wxID_OK) {
|
||||
pthread_mutex_lock(&this->logical->ng->mut);
|
||||
|
||||
CHiValue newv = {};
|
||||
CHiValue newv;
|
||||
newv.type = CUTIHI_VAL_TEXT;
|
||||
newv.data.text = strdup(CHi_Microphone_GetSourceName((size_t) (uintptr_t) dlg.GetSelectionData()));
|
||||
CHi_ConfigureSink(this->logical, p, newv);
|
||||
@ -767,10 +716,8 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
std::vector<const char*> choicesOrig;
|
||||
std::vector<wxString> choices;
|
||||
|
||||
void *wbuf;
|
||||
size_t windowCount = CHi_Window_GetList(&wbuf);
|
||||
for(size_t i = 0; i < windowCount; i++) {
|
||||
const char *name = CHi_Window_GetName(wbuf, i);
|
||||
for(size_t i = CHi_Window_GetNextSource(-1); i < CHi_Window_GetSourceCount(); i = CHi_Window_GetNextSource(i)) {
|
||||
auto name = CHi_Window_GetSourceName(i);
|
||||
|
||||
choicesOrig.push_back(name);
|
||||
choices.push_back(wxString::FromUTF8(name));
|
||||
@ -780,7 +727,7 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
if(dlg.ShowModal() == wxID_OK) {
|
||||
pthread_mutex_lock(&this->logical->ng->mut);
|
||||
|
||||
CHiValue newv = {};
|
||||
CHiValue newv;
|
||||
newv.type = CUTIHI_VAL_TEXT;
|
||||
newv.data.text = strdup(choicesOrig[dlg.GetSelection()]);
|
||||
CHi_ConfigureSink(this->logical, p, newv);
|
||||
@ -788,8 +735,6 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
|
||||
pthread_mutex_unlock(&this->logical->ng->mut);
|
||||
}
|
||||
|
||||
CHi_Window_FreeList(wbuf);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -825,7 +770,7 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
if(!isSource) {
|
||||
pthread_mutex_lock(&daNode->ng->mut);
|
||||
|
||||
CHiValue val = {};
|
||||
CHiValue val;
|
||||
val.type = CUTIHI_VAL_NONE;
|
||||
CHi_ConfigureSink(daNode, daPortIdx, val);
|
||||
|
||||
@ -834,10 +779,6 @@ GrNode::GrNode(NodeGraph *parent) : wxPanel(parent, wxID_ANY, {0, 0}, {175, 80})
|
||||
|
||||
parent->Dirtify(this);
|
||||
parent->Refresh();
|
||||
} else {
|
||||
auto ng = (NodeGraph*) GetParent();
|
||||
|
||||
ng->DestroyNode(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -875,7 +816,7 @@ ImageViewer::ImageViewer(Frame *f) : wxPanel(f, wxID_ANY) {
|
||||
Bind(wxEVT_PAINT, [this](wxPaintEvent &ev){
|
||||
if(bm.IsOk()) {
|
||||
wxPaintDC dc(this);
|
||||
dc.DrawBitmap(bm, pos + (GetSize() - bm.GetSize()) / 2);
|
||||
dc.DrawBitmap(bm, pos);
|
||||
}
|
||||
});
|
||||
Bind(wxEVT_MIDDLE_DOWN, [this](wxMouseEvent &ev){
|
||||
@ -915,19 +856,8 @@ __attribute__((optimize("O3"))) static uint8_t *bgra64torgb24(uint8_t *orig, siz
|
||||
|
||||
__m128i z[8] = {};
|
||||
for(int zi = 0; zi < 8; zi++) {
|
||||
// Alpha-blend with checkered background.
|
||||
__m128i bottom = (((x + zi) / 4 ^ y / 4) & 1)
|
||||
? _mm_set_epi16(0xFFFF, 0x8000, 0x8000, 0x8000, 0xFFFF, 0x8000, 0x8000, 0x8000)
|
||||
: _mm_set_epi16(0xFFFF, 0x4000, 0x4000, 0x4000, 0xFFFF, 0x4000, 0x4000, 0x4000);
|
||||
|
||||
__m128i top = _mm_loadu_si128((__m128i*) temp + zi);
|
||||
|
||||
__m128i alpha = _mm_shuffle_epi8(top, _mm_set_epi8(15, 14, 15, 14, 15, 14, 15, 14, 7, 6, 7, 6, 7, 6, 7, 6));
|
||||
__m128i invAlpha = _mm_sub_epi16(_mm_set1_epi16(0xFFFF), alpha);
|
||||
|
||||
__m128i result = _mm_add_epi16(_mm_mulhi_epu16(top, alpha), _mm_mulhi_epu16(bottom, invAlpha));
|
||||
|
||||
z[zi] = apply_gamma_epi16(result, _mm_set_ps(1, 1 / 2.2f, 1 / 2.2f, 1 / 2.2f));
|
||||
z[zi] = _mm_loadu_si128((__m128i*) temp + zi);
|
||||
z[zi] = apply_gamma_epi16(z[zi], _mm_set_ps(1, 1 / 2.2f, 1 / 2.2f, 1 / 2.2f));
|
||||
}
|
||||
|
||||
__m128i a = _mm_shuffle_epi8(z[0], _mm_set_epi8(-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, 9, 11, 13, 1, 3, 5));
|
||||
@ -1118,7 +1048,7 @@ NodeGraph::NodeGraph(Frame *f) : wxPanel(f, wxID_ANY) {
|
||||
|
||||
after();
|
||||
|
||||
globaldis->timeline->ResetRows();
|
||||
((Frame*) GetParent())->timeline->ResetRows();
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&backendNG->mut);
|
||||
@ -1184,16 +1114,17 @@ NodeGraph::~NodeGraph() {
|
||||
void NodeGraph::Alinken(Link l) {
|
||||
pthread_mutex_lock(&backendNG->mut);
|
||||
|
||||
CHiValue newv = {};
|
||||
newv.linked.to = l.output->logical;
|
||||
newv.linked.idx = l.o;
|
||||
CHiValue newv;
|
||||
newv.type = CUTIHI_VAL_LINKED;
|
||||
newv.data.linked.to = l.output->logical;
|
||||
newv.data.linked.idx = l.o;
|
||||
|
||||
int err = CHi_ConfigureSink(l.input->logical, l.i, newv);
|
||||
|
||||
pthread_mutex_unlock(&backendNG->mut);
|
||||
|
||||
if(!err) {
|
||||
globaldis->stba->SetStatusText("Uh oh! Hur-hur, there's a WAACKY cycle! Can't do, sorry friend.");
|
||||
((Frame*) GetParent())->stba->SetStatusText("Uh oh! Hur-hur, there's a WAACKY cycle! Can't do, sorry friend.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1230,7 +1161,7 @@ void NodeGraph::Dirtify(GrNode *g) {
|
||||
}
|
||||
}*/
|
||||
|
||||
CHi_Hysteresis(backendNG);
|
||||
CHi_Hysteresis(gnodes[0]->logical);
|
||||
}
|
||||
|
||||
bool operator==(const NodeGraph::Link &l, const NodeGraph::Link &r) {
|
||||
@ -1266,23 +1197,17 @@ void NodeGraph::CreatePreviewNode() {
|
||||
|
||||
v->SetPosition(wxPoint{GetSize().x - v->GetSize().x - 8, 8});
|
||||
|
||||
v->logical->Perform = INJECTED_PREVIEW_FUNC;
|
||||
// The Preview node is actually a NOOP
|
||||
// Must inject our own function in Perform
|
||||
v->logical->Perform = +[](CHiPubNode *preview){
|
||||
CHiValue *val = CHi_Crawl(&preview->sinks[0]);
|
||||
|
||||
if(val->type == CUTIHI_VAL_SAMPLE && val->data.sample) {
|
||||
globaldis->viewer->SetImage(val->data.sample);
|
||||
}
|
||||
|
||||
void NodeGraph::DestroyNode(GrNode *gn) {
|
||||
for(auto it = links.begin(); it != links.end();) {
|
||||
if(it->input == gn || it->output == gn) {
|
||||
it = links.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
gnodes.erase(std::find(gnodes.begin(), gnodes.end(), gn));
|
||||
|
||||
wxTheApp->CallAfter([=](){
|
||||
gn->Destroy();
|
||||
});
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
|
||||
GrNode *NodeGraph::get_graphical(CHiPubNode *n) {
|
||||
|
@ -43,8 +43,6 @@ struct Frame : wxFrame {
|
||||
|
||||
Frame();
|
||||
virtual ~Frame();
|
||||
|
||||
void LoadProject(std::string filename);
|
||||
};
|
||||
|
||||
struct GrNode : wxPanel {
|
||||
@ -138,8 +136,6 @@ struct NodeGraph : wxPanel {
|
||||
|
||||
void CreatePreviewNode();
|
||||
|
||||
void DestroyNode(GrNode*);
|
||||
|
||||
GrNode *get_graphical(CHiPubNode*);
|
||||
};
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
#include"frame.h"
|
||||
|
||||
Frame *globaldis;
|
||||
|
||||
struct App : wxApp {
|
||||
virtual bool OnInit() {
|
||||
(new Frame())->Show(true);
|
||||
|
@ -10,8 +10,6 @@
|
||||
|
||||
#include"frame.h"
|
||||
|
||||
extern Frame *globaldis;
|
||||
|
||||
static wxBitmap bmpKf;
|
||||
static wxBitmap bmpKfExtrap;
|
||||
|
||||
@ -40,7 +38,7 @@ bool Timeline::MouseOverKF(wxPoint p, CHiKeyframes* &kfs, size_t &kfIdxRet) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto f = globaldis;
|
||||
auto f = (Frame*) GetParent();
|
||||
|
||||
kfs = row->kfs;
|
||||
|
||||
@ -61,7 +59,7 @@ bool Timeline::MouseOverKF(wxPoint p, CHiKeyframes* &kfs, size_t &kfIdxRet) {
|
||||
void Timeline::ResetRows() {
|
||||
rows.clear();
|
||||
|
||||
auto frame = globaldis;
|
||||
auto frame = (Frame*) GetParent();
|
||||
|
||||
auto kfsList = &frame->graph->backendNG->keyframesList;
|
||||
|
||||
@ -94,15 +92,13 @@ void Timeline::ResetRows() {
|
||||
|
||||
y += row.h;
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
float Timeline::SnapTime(float t) {
|
||||
float minDist = FLT_MAX;
|
||||
float newT = t;
|
||||
|
||||
auto f = globaldis;
|
||||
auto f = (Frame*) GetParent();
|
||||
|
||||
std::vector<float> times;
|
||||
for(Timeline::Row &row : rows) {
|
||||
@ -153,7 +149,7 @@ Timeline::Timeline(struct Frame *parent) : wxPanel(parent, wxID_ANY) {
|
||||
Bind(wxEVT_LEFT_DOWN, [=](wxMouseEvent &ev){
|
||||
Timeline::Row *row = GetRow(ev.GetPosition().y);
|
||||
|
||||
auto f = globaldis;
|
||||
auto f = (Frame*) GetParent();
|
||||
|
||||
float t = (ev.GetX() + camX - ZERO_TIME_BASE) / (float) scale;
|
||||
if(ev.ControlDown()) {
|
||||
@ -200,14 +196,14 @@ Timeline::Timeline(struct Frame *parent) : wxPanel(parent, wxID_ANY) {
|
||||
t = SnapTime(t);
|
||||
}
|
||||
|
||||
row->gn->logical->lifespan.end = t < 0 ? 0 : t;
|
||||
row->gn->logical->lifespan.end = t;
|
||||
|
||||
Refresh();
|
||||
}
|
||||
});
|
||||
|
||||
Bind(wxEVT_MOTION, [=](wxMouseEvent &ev){
|
||||
auto f = globaldis;
|
||||
auto f = (Frame*) GetParent();
|
||||
|
||||
if(HasCapture()) {
|
||||
if(captureMode == Timeline::CaptureMode::CAM) {
|
||||
@ -323,7 +319,7 @@ Timeline::Timeline(struct Frame *parent) : wxPanel(parent, wxID_ANY) {
|
||||
|
||||
menu.Bind(wxEVT_MENU, [=](wxCommandEvent &ev){
|
||||
if(ev.GetId() == idDel) {
|
||||
auto f = globaldis;
|
||||
auto f = (Frame*) GetParent();
|
||||
|
||||
CHi_DeleteKeyframe(f->graph->backendNG, kfs, kfIdx);
|
||||
|
||||
@ -341,7 +337,7 @@ Timeline::Timeline(struct Frame *parent) : wxPanel(parent, wxID_ANY) {
|
||||
}
|
||||
|
||||
void Timeline::Paint(wxPaintEvent &ev) {
|
||||
auto frame = globaldis;
|
||||
auto frame = (Frame*) GetParent();
|
||||
|
||||
wxPaintDC dc{this};
|
||||
|
||||
@ -409,10 +405,6 @@ void Timeline::Paint(wxPaintEvent &ev) {
|
||||
|
||||
if(end == 0) {
|
||||
end = gn->logical->ng->duration;
|
||||
if(end == -1) {
|
||||
// Hack :)
|
||||
end = 3600 * 10;
|
||||
}
|
||||
}
|
||||
|
||||
start *= scale;
|
||||
|
Loading…
Reference in New Issue
Block a user