You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(5) |
Jul
(42) |
Aug
(91) |
Sep
(97) |
Oct
(69) |
Nov
(16) |
Dec
(32) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(74) |
Feb
(109) |
Mar
(117) |
Apr
(86) |
May
(84) |
Jun
(47) |
Jul
(30) |
Aug
(25) |
Sep
(39) |
Oct
(59) |
Nov
(42) |
Dec
(38) |
2010 |
Jan
(30) |
Feb
(43) |
Mar
(59) |
Apr
(67) |
May
(29) |
Jun
(47) |
Jul
(48) |
Aug
(22) |
Sep
(22) |
Oct
(36) |
Nov
(40) |
Dec
(3) |
2011 |
Jan
(39) |
Feb
(21) |
Mar
(36) |
Apr
(35) |
May
(8) |
Jun
|
Jul
(14) |
Aug
(4) |
Sep
(10) |
Oct
(27) |
Nov
(1) |
Dec
|
2012 |
Jan
(2) |
Feb
(2) |
Mar
|
Apr
(9) |
May
(1) |
Jun
(1) |
Jul
(7) |
Aug
|
Sep
(15) |
Oct
(1) |
Nov
(3) |
Dec
(6) |
2013 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
(2) |
Jul
|
Aug
(5) |
Sep
(15) |
Oct
|
Nov
|
Dec
(1) |
2014 |
Jan
(5) |
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
2015 |
Jan
|
Feb
(5) |
Mar
|
Apr
(4) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
(19) |
Oct
|
Nov
|
Dec
(1) |
2016 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
(6) |
Oct
|
Nov
|
Dec
(2) |
2017 |
Jan
(16) |
Feb
(8) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
(7) |
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(5) |
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(14) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2021 |
Jan
|
Feb
|
Mar
(7) |
Apr
(14) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(8) |
Nov
(3) |
Dec
|
2023 |
Jan
(1) |
Feb
|
Mar
(12) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2025 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(4) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <di...@us...> - 2008-07-22 14:55:45
|
Revision: 1832 http://ftm.svn.sourceforge.net/ftm/?rev=1832&view=rev Author: diemo Date: 2008-07-22 14:55:53 +0000 (Tue, 22 Jul 2008) Log Message: ----------- renamed tree to more precise kdtree Modified Paths: -------------- trunk/ftm/ftmlib/classes/kdtree.c trunk/ftm/ftmlib/classes/kdtree.h trunk/ftm/ftmlib/classes/kdtreebuild.c trunk/ftm/ftmlib/classes/kdtreesearch.c Modified: trunk/ftm/ftmlib/classes/kdtree.c =================================================================== --- trunk/ftm/ftmlib/classes/kdtree.c 2008-07-22 14:51:27 UTC (rev 1831) +++ trunk/ftm/ftmlib/classes/kdtree.c 2008-07-22 14:55:53 UTC (rev 1832) @@ -32,8 +32,8 @@ #define HEIGHT 3 #define MAX_FLOAT 0x7FFFFFFF -fts_symbol_t tree_symbol = 0; -fts_class_t *tree_class = 0; +fts_symbol_t kdtree_symbol = 0; +fts_class_t *kdtree_class = 0; fts_symbol_t s_mean; fts_symbol_t s_hyper; @@ -83,7 +83,7 @@ #if PROFILE -static void profile_clear (tree_t *t) +static void profile_clear (kdtree_t *t) { t->profile.v2v = 0; t->profile.v2n = 0; @@ -138,7 +138,7 @@ list of n indices in result */ #if 0 -static int tree_search (tree_t *tree, fmat_t *x, int k, int *result) +static int kdtree_search (kdtree_t *tree, fmat_t *x, int k, int *result) { fts_stack_t stack; @@ -167,7 +167,7 @@ fts_post("]%s", suffix); } -static void tree_info_display (tree_t* t) +static void kdtree_info_display (kdtree_t* t) { int i, j; fts_post("\nTree Info:\n"); @@ -186,7 +186,7 @@ } -static void tree_data_display(tree_t* t) +static void kdtree_data_display(kdtree_t* t) { int l, n, i, j; @@ -204,7 +204,7 @@ for (i = t->nodes[n].startind; i <= t->nodes[n].endind; i++) { fts_post("vec %d = ", t->dataindex[i]); - vec_post(tree_get_vector(t, i), t->ndim, + vec_post(kdtree_get_vector(t, i), t->ndim, i < t->nodes[n].endind ? ", " : ""); } fts_post(")\n"); @@ -214,7 +214,7 @@ static void -tree_getelem_function(fts_object_t *o, int ac, const fts_atom_t *at, fts_atom_t *ret) +kdtree_getelem_function(fts_object_t *o, int ac, const fts_atom_t *at, fts_atom_t *ret) { if(ac > 0 && fts_is_number(at)) { @@ -231,11 +231,11 @@ * */ -static fts_method_status_t _tree_set (fts_object_t *o, fts_symbol_t s, +static fts_method_status_t _kdtree_set (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { - tree_t *self = (tree_t *) o; + kdtree_t *self = (kdtree_t *) o; fmat_t *data = (fmat_t *) fts_get_object(at); if (self->data) @@ -245,25 +245,25 @@ self->data = data; fts_object_refer((fts_object_t *) self->data); - tree_init(self, floor(log2(fmat_get_m(data))), + kdtree_init(self, floor(log2(fmat_get_m(data))), fmat_get_m(data), fmat_get_n(data)); - /* tree_clear and rebuild: */ - /* tree_clear(self);*/ - tree_build(self); + /* kdtree_clear and rebuild: */ + /* kdtree_clear(self);*/ + kdtree_build(self); fts_set_object(ret, o); return fts_ok; } -static fts_method_status_t _tree_add (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) +static fts_method_status_t _kdtree_add (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { - tree_t *self = (tree_t *) o; + kdtree_t *self = (kdtree_t *) o; /* rebuild */ - /* tree_set(self, ac, at); - tree_build(self); + /* kdtree_set(self, ac, at); + kdtree_build(self); */ fts_set_object(ret, self); @@ -274,11 +274,11 @@ -static fts_method_status_t _tree_getknn (fts_object_t *o, fts_symbol_t s, +static fts_method_status_t _kdtree_getknn (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { - tree_t *self = (tree_t *) o; + kdtree_t *self = (kdtree_t *) o; fmat_t *x = NULL; /* search vector */ int k = 1, n; int *result; @@ -291,7 +291,7 @@ result = alloca(sizeof(int) * k); - n = tree_search_knn(self, fmat_get_ptr(x), k, result); + n = kdtree_search_knn(self, fmat_get_ptr(x), k, result); if (s == fts_s_get) /* geti: nearest index? */ { /* return one fvec */ @@ -329,11 +329,11 @@ } -static fts_method_status_t _tree_get_node (fts_object_t *o, fts_symbol_t s, +static fts_method_status_t _kdtree_get_node (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { - tree_t *t = (tree_t *) o; + kdtree_t *t = (kdtree_t *) o; int n = 0; /* node to inspect */ if (ac > 1 && fts_is_number(at + 1)) @@ -388,14 +388,14 @@ } -static fts_method_status_t _tree_print (fts_object_t *o, fts_symbol_t s, +static fts_method_status_t _kdtree_print (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { - tree_t *self = (tree_t *) o; + kdtree_t *self = (kdtree_t *) o; - tree_info_display(self); - tree_data_display(self); + kdtree_info_display(self); + kdtree_data_display(self); return fts_ok; } @@ -409,9 +409,9 @@ */ static fts_method_status_t -_tree_init(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) +_kdtree_init(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { - tree_t *self = (tree_t *) o; + kdtree_t *self = (kdtree_t *) o; /* Init */ self->ndata = 0; @@ -429,7 +429,7 @@ if (ac > 0 && fts_is_a(at, fmat_class)) { /* set data arg and build tree */ - _tree_set(o, s, ac, at, ret); + _kdtree_set(o, s, ac, at, ret); } return fts_ok; @@ -437,12 +437,12 @@ static fts_method_status_t -_tree_delete(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) +_kdtree_delete(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { - tree_t *self = (tree_t *) o; + kdtree_t *self = (kdtree_t *) o; int i; -/* todo: move to tree_clear */ +/* todo: move to kdtree_clear */ /* free nodes */ for (i = 0; i < self->nnodes; i++) { @@ -462,50 +462,50 @@ static void -_tree_instantiate(fts_class_t *cl) +_kdtree_instantiate(fts_class_t *cl) { - fts_class_init(cl, sizeof(tree_t), _tree_init, _tree_delete, "[<fmat: data>>] - vector space index tree"); + fts_class_init(cl, sizeof(kdtree_t), _kdtree_init, _kdtree_delete, "[<fmat: data>>] - vector space index tree"); /* - fts_class_set_copy_function(cl, tree_copy_function); - fts_class_set_array_function(cl, tree_array_function); - fts_class_set_dump_function(cl, tree_dump_function); + fts_class_set_copy_function(cl, kdtree_copy_function); + fts_class_set_array_function(cl, kdtree_array_function); + fts_class_set_dump_function(cl, kdtree_dump_function); */ - fts_class_set_getelem_function(cl, tree_getelem_function); + fts_class_set_getelem_function(cl, kdtree_getelem_function); - fts_class_message_varargs(cl, fts_s_print, _tree_print, "print list of entries"); + fts_class_message_varargs(cl, fts_s_print, _kdtree_print, "print list of entries"); /* - fts_class_message_void(cl, fts_s_clear, _tree_clear, "- erase all entries"); - fts_class_message_varargs(cl, fts_new_symbol("rebuild"), _tree_rebuild); - fts_class_message_varargs(cl, fts_s_remove, _tree_remove, "<any: key> ... - remove given entries"); + fts_class_message_void(cl, fts_s_clear, _kdtree_clear, "- erase all entries"); + fts_class_message_varargs(cl, fts_new_symbol("rebuild"), _kdtree_rebuild); + fts_class_message_varargs(cl, fts_s_remove, _kdtree_remove, "<any: key> ... - remove given entries"); */ - fts_class_message(cl, fts_s_set, fmat_class, _tree_set, "<fmat: data> - set data matrix(ndata, ndim)"); -/* no: fts_class_message(cl, fts_new_symbol("add"), fmat_class, _tree_add, "<fmat: vector> - add one vector"); */ + fts_class_message(cl, fts_s_set, fmat_class, _kdtree_set, "<fmat: data> - set data matrix(ndata, ndim)"); +/* no: fts_class_message(cl, fts_new_symbol("add"), fmat_class, _kdtree_add, "<fmat: vector> - add one vector"); */ - fts_class_message_varargs(cl, fts_s_get, _tree_getknn, + fts_class_message_varargs(cl, fts_s_get, _kdtree_getknn, "<fmat: x> - get frow vector of data matrix nearest to vector x"); - fts_class_message_varargs(cl, fts_new_symbol("getknn"), _tree_getknn, + fts_class_message_varargs(cl, fts_new_symbol("getknn"), _kdtree_getknn, "<fmat: x> [<int: k>] - get k nearest neighbour vectors to vector x (default k=1)"); - fts_class_message_varargs(cl, s_getknni, _tree_getknn, + fts_class_message_varargs(cl, s_getknni, _kdtree_getknn, "<fmat: x> [<int: k>] - get row indices in data matrix of k nearest neighbours to vector x (default k=1) "); /* inspection */ - fts_class_message_varargs(cl, fts_new_symbol("node"), _tree_get_node, + fts_class_message_varargs(cl, fts_new_symbol("node"), _kdtree_get_node, "<num|mean|hyper|size|start|end|profile> <int: index> - get information about a node"); } -FTS_MODULE_INIT(tree) +FTS_MODULE_INIT(kdtree) { - tree_symbol = fts_new_symbol("tree"); + kdtree_symbol = fts_new_symbol("kdtree"); s_mean = fts_new_symbol("mean"); s_hyper = fts_new_symbol("hyper"); s_vec = fts_new_symbol("vec"); s_profile = fts_new_symbol("profile"); s_getknni = fts_new_symbol("getknni"); - tree_class = fts_class_install(tree_symbol, _tree_instantiate); + kdtree_class = fts_class_install(kdtree_symbol, _kdtree_instantiate); } Modified: trunk/ftm/ftmlib/classes/kdtree.h =================================================================== --- trunk/ftm/ftmlib/classes/kdtree.h 2008-07-22 14:51:27 UTC (rev 1831) +++ trunk/ftm/ftmlib/classes/kdtree.h 2008-07-22 14:55:53 UTC (rev 1832) @@ -20,8 +20,8 @@ * */ -#ifndef _DATA_TREE_H_ -#define _DATA_TREE_H_ +#ifndef _DATA_KDTREE_H_ +#define _DATA_KDTREE_H_ #include "fts.h" @@ -59,16 +59,16 @@ } node_t; -enum tree_dmode { dmode_orthogonal, dmode_hyperplane, dmode_pca }; +enum kdtree_dmode { dmode_orthogonal, dmode_hyperplane, dmode_pca }; -typedef struct _tree +typedef struct _kdtree { fts_object_t o; - enum tree_dmode dmode; + enum kdtree_dmode dmode; int ndim; /* Dimension of vectors */ int ndata; /* Number of vectors */ - int height; /* Height of the tree */ + int height; /* Height of the kdtree */ int nnodes; /* Number of nodes (must be a power of 2) */ fmat_t *data; /* data matrix (ndata, ndim) */ @@ -83,17 +83,17 @@ int mean; int hyper; } profile; -} tree_t; +} kdtree_t; -FTS_API fts_symbol_t tree_symbol; -FTS_API fts_class_t *tree_class; +FTS_API fts_symbol_t kdtree_symbol; +FTS_API fts_class_t *kdtree_class; /* get data element via indirection order array */ -#define tree_get_element(t, i, j) fmat_get_element(t->data, t->dataindex[i], j) +#define kdtree_get_element(t, i, j) fmat_get_element(t->data, t->dataindex[i], j) /* get data vector via indirection order array */ -#define tree_get_vector(t, i) (fmat_get_ptr(t->data) + t->dataindex[i] * t->ndim) +#define kdtree_get_vector(t, i) (fmat_get_ptr(t->data) + t->dataindex[i] * t->ndim) #define fmat_get_row_ptr(f, i) (fmat_get_ptr(f) + (i) * fmat_get_n(f)) @@ -102,12 +102,12 @@ void vec_post (float *v, int n, const char *suffix); /* vector to node distance */ -float distV2N (tree_t* t, const float *x, const int node); +float distV2N (kdtree_t* t, const float *x, const int node); -void tree_build (tree_t* t); -void tree_init (tree_t* t, int h, int vect_num, int dim); +void kdtree_build (kdtree_t* t); +void kdtree_init (kdtree_t* t, int h, int vect_num, int dim); -int tree_search_knn (tree_t *t, float* x, int k, int *y); +int kdtree_search_knn (kdtree_t *t, float* x, int k, int *y); #endif Modified: trunk/ftm/ftmlib/classes/kdtreebuild.c =================================================================== --- trunk/ftm/ftmlib/classes/kdtreebuild.c 2008-07-22 14:51:27 UTC (rev 1831) +++ trunk/ftm/ftmlib/classes/kdtreebuild.c 2008-07-22 14:55:53 UTC (rev 1832) @@ -1,14 +1,14 @@ -#include "tree.h" +#include "kdtree.h" #include <stdlib.h> #include <math.h> -#define DEBUG_TREEBUILD 0 +#define DEBUG_KDTREEBUILD 0 static void -compute_mean (tree_t *t, int node) +compute_mean (kdtree_t *t, int node) { float sum; float *mean_ptr = fmat_get_ptr(t->nodes[node].mean); @@ -28,12 +28,12 @@ for (i = t->nodes[node].startind; i <= t->nodes[node].endind; i++) { - sum += tree_get_element(t, i, j); + sum += kdtree_get_element(t, i, j); } mean_ptr[j] = sum / nvector; } -#if DEBUG_TREEBUILD +#if DEBUG_KDTREEBUILD fts_post("mean vect for node %d = ", node); vec_post(mean_ptr, t->ndim, "\n"); #endif @@ -48,7 +48,7 @@ /* swap positions of vectors i and j: only in indirection array */ -static void swap (tree_t* t, int i, int j) +static void swap (kdtree_t* t, int i, int j) { int tmp; @@ -89,7 +89,7 @@ /* vector to node distance */ -float distV2N (tree_t* t, const float *x, const int node) +float distV2N (kdtree_t* t, const float *x, const int node) { #if PROFILE_BUILD t->profile.v2n++; @@ -113,7 +113,7 @@ } -static void compute_splitplane (tree_t* t, int node, int level) +static void compute_splitplane (kdtree_t* t, int node, int level) { int b; float h; @@ -135,7 +135,7 @@ t->nodes[node].splitnorm = 1; -#if DEBUG_TREEBUILD +#if DEBUG_KDTREEBUILD fts_post("Splitplane of node %i: ", node); vec_post(t->nodes[node].split, t->ndim + 1, "\n"); #endif @@ -144,13 +144,13 @@ -static void freeVect (tree_t* t, int vect_number) +static void freeVect (kdtree_t* t, int vect_number) { fmat_set_const(t->data, MAX_FLOAT); } #if 0 -void reBalance(tree_t* t) +void reBalance(kdtree_t* t) { int i = 0; int j = t->ndata - 1; @@ -174,12 +174,12 @@ t->ndata = i; t->nodes[0].endind = t->ndata - 1; - tree_build(t); + kdtree_build(t); } #endif -void tree_build (tree_t* t) +void kdtree_build (kdtree_t* t) { int l; // current level number int n; // current node number @@ -200,7 +200,7 @@ { int nstart = pow2(l) - 1; int nend = pow2(l+1) - 1; -#if DEBUG_TREEBUILD +#if DEBUG_KDTREEBUILD fts_post("\nLevel #%i nodes %d..%d\n", l, nstart, nend); #endif for (n = nstart; n < nend; n++) @@ -208,7 +208,7 @@ compute_mean(t, n); compute_splitplane(t, n, l); -#if DEBUG_TREEBUILD +#if DEBUG_KDTREEBUILD fts_post("Node #%i (%i..%i): mean = ", n, t->nodes[n].startind, t->nodes[n].endind); vec_post(fmat_get_ptr(t->nodes[n].mean), t->ndim, "\n"); @@ -218,11 +218,11 @@ while (j > i) { /* sort node vectors by distance to splitplane */ - while (distV2N(t, tree_get_vector(t, i), n) <= 0) + while (distV2N(t, kdtree_get_vector(t, i), n) <= 0) { i++; // fts_post("i=%i\n", i); } - while (distV2N(t, tree_get_vector(t, j), n) > 0) + while (distV2N(t, kdtree_get_vector(t, j), n) > 0) { j--; // fts_post("j=%i\n", j); } @@ -241,7 +241,7 @@ } -void tree_init (tree_t* t, int h, int vect_num, int dim) +void kdtree_init (kdtree_t* t, int h, int vect_num, int dim) { int i; Modified: trunk/ftm/ftmlib/classes/kdtreesearch.c =================================================================== --- trunk/ftm/ftmlib/classes/kdtreesearch.c 2008-07-22 14:51:27 UTC (rev 1831) +++ trunk/ftm/ftmlib/classes/kdtreesearch.c 2008-07-22 14:55:53 UTC (rev 1832) @@ -1,10 +1,10 @@ -#include "tree.h" +#include "kdtree.h" #include <stdlib.h> #include <math.h> -#define DEBUG_TREESEARCH 0 +#define DEBUG_KDTREESEARCH 0 static void initStack(stack* s) @@ -100,7 +100,7 @@ /* out: y[K] = index of the Kth neirest neighbour return: actual number of found neighbours */ -int tree_search_knn (tree_t *t, float* x, int k, int *y) +int kdtree_search_knn (kdtree_t *t, float* x, int k, int *y) { float *d; // vector to vector distance from vector y[k] to vector x int i; // current processed vector @@ -137,16 +137,16 @@ int istart = t->nodes[cur.node].startind; int iend = t->nodes[cur.node].endind; int i; -#ifdef DEBUG_TREESEARCH +#ifdef DEBUG_KDTREESEARCH fts_post("Leaf node p = %d\n", cur.node); #endif for (i = istart; i <= iend; i++) { - dxx = euclidianDistance(x, tree_get_vector(t, i), t->ndim); + dxx = euclidianDistance(x, kdtree_get_vector(t, i), t->ndim); -#ifdef DEBUG_TREESEARCH +#ifdef DEBUG_KDTREESEARCH fts_post("distance = %f between vector %d ", dxx, i); - vec_post(tree_get_vector(t, i), t->ndim, " and x "); + vec_post(kdtree_get_vector(t, i), t->ndim, " and x "); vec_post(x, t->ndim, "\n"); #endif #if PROFILE_SEARCH @@ -163,7 +163,7 @@ else { // branched node float d = distV2N(t, x, cur.node); -#ifdef DEBUG_TREESEARCH +#ifdef DEBUG_KDTREESEARCH fts_post("Inner node %d, d = %f\n", cur.node, d); #endif if (d < 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-22 14:51:19
|
Revision: 1831 http://ftm.svn.sourceforge.net/ftm/?rev=1831&view=rev Author: diemo Date: 2008-07-22 14:51:27 +0000 (Tue, 22 Jul 2008) Log Message: ----------- renamed tree files to more precise kdtree, removed obsolete treedefs.h Added Paths: ----------- trunk/ftm/ftmlib/classes/kdtree.c trunk/ftm/ftmlib/classes/kdtree.h trunk/ftm/ftmlib/classes/kdtreebuild.c trunk/ftm/ftmlib/classes/kdtreesearch.c Removed Paths: ------------- trunk/ftm/ftmlib/classes/tree.c trunk/ftm/ftmlib/classes/tree.h trunk/ftm/ftmlib/classes/treebuild.c trunk/ftm/ftmlib/classes/treedefs.h trunk/ftm/ftmlib/classes/treesearch.c Copied: trunk/ftm/ftmlib/classes/kdtree.c (from rev 1829, trunk/ftm/ftmlib/classes/tree.c) =================================================================== --- trunk/ftm/ftmlib/classes/kdtree.c (rev 0) +++ trunk/ftm/ftmlib/classes/kdtree.c 2008-07-22 14:51:27 UTC (rev 1831) @@ -0,0 +1,511 @@ +/* + * FTM + * Copyright (C) 1994, 1995, 1998, 1999, 2007 by IRCAM-Centre Georges Pompidou, Paris, France. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * See file COPYING.LIB for further informations on licensing terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef WIN32 +#include <malloc.h> +#else +#include <alloca.h> +#endif +#include <math.h> + +#include "fts.h" + +#define HEIGHT 3 +#define MAX_FLOAT 0x7FFFFFFF + +fts_symbol_t tree_symbol = 0; +fts_class_t *tree_class = 0; + +fts_symbol_t s_mean; +fts_symbol_t s_hyper; +fts_symbol_t s_vec; +fts_symbol_t s_profile; +fts_symbol_t s_getknni; + + +/* for the search algorithm */ +typedef struct stack_elem +{ + int node; + double dist; +} stack_elem_t; + +static void stack_push (fts_stack_t *s, int p, double d) +{ +/* doesn't work with CodeWorrior + stack_elem_t _new = { p, d }; + fts_stack_push(s, stack_elem_t, _new); + */ +} + +static int stack_pop (fts_stack_t *s, int *p, double *d) +{ + int top = fts_stack_top(s); + + if (top >= 0) + { + stack_elem_t *_tmp = ((stack_elem_t *) fts_stack_base(s)) + top; + + *p = _tmp->node; + *d = _tmp->dist; + + fts_stack_pop(s, 1); + return 1; + } + else + return 0; +} + + +int pow2 (int x) +{ + return 1 << x; +} + + +#if PROFILE +static void profile_clear (tree_t *t) +{ + t->profile.v2v = 0; + t->profile.v2n = 0; + t->profile.mean = 0; + t->profile.hyper = 0; +} +#endif + +static double +vec_dist (fmat_t *a, fmat_t *b) +{ + int m = fmat_get_m(a); + int n = fmat_get_n(a); + float *l = fmat_get_ptr(a); + float *r = fmat_get_ptr(b); + int size = m * n; + double dist = 0; + int i; + + for (i = 0; i < size; i++) + dist += (l[i] - r[i]) * (l[i] - r[i]); + + return dist; +} + + +static float +distfmatV2H(fmat_t* vect, fmat_t* hplane) +{ + //standard algebra computing + int i; + float tmp1 = 0; + float tmp2 = 0; + int m = fmat_get_m(vect); + int n = fmat_get_n(vect); + float *v = fmat_get_ptr(vect); + float *h = fmat_get_ptr(hplane); + int size = m * n; + + for(i = 0; i < size; i++) + { + tmp1 += v[i]*h[i]; + tmp2 += h[i]*h[i]; + } + + return (tmp1 + h[size])/sqrt(tmp2); +} + + +/* + @return number of vectors found n, n <= k + list of n indices in result +*/ +#if 0 +static int tree_search (tree_t *tree, fmat_t *x, int k, int *result) +{ + fts_stack_t stack; + + fts_stack_init(&stack, stack_elem_t); + + stack_push(&stack, 0, 0); + + /* one element access */ +/* fmat_get_element(x, 0, i); */ + + /* testing: */ + result[0] = 0; + return 1; +} +#endif + + +void vec_post (float *v, int n, const char *suffix) +{ + int i; + + for (i = 0; i < n; i++) + { + fts_post("%s%.1f", (i == 0 ? "[" : ", "), v[i]); + } + fts_post("]%s", suffix); +} + +static void tree_info_display (tree_t* t) +{ + int i, j; + fts_post("\nTree Info:\n"); + fts_post("ndim = %i\n", t->ndim); + fts_post("ndata = %i\n", t->ndata); + fts_post("height = %i\n", t->height); + fts_post("nnodes = %i\n", t->nnodes); + + if (t->height == 0 || t->ndata == 0) fts_post("Empty Tree\n"); + + for (i = 0; i < t->ndata; i++) + { + fts_post("raw data vec %-3i = ", i); + vec_post(fmat_get_row_ptr(t->data, i), t->ndim, "\n"); + } +} + + +static void tree_data_display(tree_t* t) +{ + int l, n, i, j; + + fts_post("\nTree Data:\n"); + if (t->height == 0 || t->ndata == 0) fts_post("Empty Tree\n"); + + for (l = 0; l < t->height; l++) + { + fts_post("Level #%i nodes %d..%d\n", l, pow2(l) - 1, pow2(l+1) - 1); + for (n = pow2(l) - 1; n < pow2(l+1) - 1; n++) + { + fts_post(" node %d size %d <%d..%d> = (", + n, t->nodes[n].endind - t->nodes[n].startind + 1, + t->nodes[n].startind, t->nodes[n].endind); + for (i = t->nodes[n].startind; i <= t->nodes[n].endind; i++) + { + fts_post("vec %d = ", t->dataindex[i]); + vec_post(tree_get_vector(t, i), t->ndim, + i < t->nodes[n].endind ? ", " : ""); + } + fts_post(")\n"); + } + } +} + + +static void +tree_getelem_function(fts_object_t *o, int ac, const fts_atom_t *at, fts_atom_t *ret) +{ + if(ac > 0 && fts_is_number(at)) + { + } +} + + + + + +/****************************************************************************** + * + * user methods + * + */ + +static fts_method_status_t _tree_set (fts_object_t *o, fts_symbol_t s, + int ac, const fts_atom_t *at, + fts_atom_t *ret) +{ + tree_t *self = (tree_t *) o; + fmat_t *data = (fmat_t *) fts_get_object(at); + + if (self->data) + fts_object_release((fts_object_t *) self->data); + + /* method only declared for fmat, so no check needed */ + self->data = data; + fts_object_refer((fts_object_t *) self->data); + + tree_init(self, floor(log2(fmat_get_m(data))), + fmat_get_m(data), fmat_get_n(data)); + + /* tree_clear and rebuild: */ + /* tree_clear(self);*/ + tree_build(self); + + fts_set_object(ret, o); + return fts_ok; +} + + +static fts_method_status_t _tree_add (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) +{ + tree_t *self = (tree_t *) o; + + /* rebuild */ + /* tree_set(self, ac, at); + tree_build(self); + */ + + fts_set_object(ret, self); + fts_object_refer(self); + + return fts_ok; +} + + + +static fts_method_status_t _tree_getknn (fts_object_t *o, fts_symbol_t s, + int ac, const fts_atom_t *at, + fts_atom_t *ret) +{ + tree_t *self = (tree_t *) o; + fmat_t *x = NULL; /* search vector */ + int k = 1, n; + int *result; + + if (ac > 0 && fts_is_a(at, fmat_class)) + x = (fmat_t *) fts_get_object(at); + + if (ac > 1 && fts_is_number(at+1)) + k = fts_get_number_int(at+1); + + result = alloca(sizeof(int) * k); + + n = tree_search_knn(self, fmat_get_ptr(x), k, result); + + if (s == fts_s_get) /* geti: nearest index? */ + { /* return one fvec */ + fvec_t *vec = fvec_create_row(self->data); + fvec_set_index(vec, result[0]); + fts_set_object(ret, vec); + } + else + { /* return n-tuple of fvec or index */ + fts_tuple_t *tup = (fts_tuple_t *) fts_object_create(fts_tuple_class, 0, NULL); + fts_atom_t *at; + int i; + + fts_tuple_set_size(tup, n); + at = fts_tuple_get_atoms(tup); + + for (i = 0; i < n; i++) + { + if (s == s_getknni) + fts_set_int(at + i, self->dataindex[result[i]]); + else /* getknn */ + { + fvec_t *vec = fvec_create_row(self->data); + fvec_set_index(vec, self->dataindex[result[i]]); + + fts_object_refer((fts_object_t *) vec); + fts_set_object(at + i, vec); + } + } + + fts_set_object(ret, tup); + } + + return fts_ok; +} + + +static fts_method_status_t _tree_get_node (fts_object_t *o, fts_symbol_t s, + int ac, const fts_atom_t *at, + fts_atom_t *ret) +{ + tree_t *t = (tree_t *) o; + int n = 0; /* node to inspect */ + + if (ac > 1 && fts_is_number(at + 1)) + { + n = fts_get_number_int(at + 1); + if (n >= t->nnodes) + n = t->nnodes - 1; + } + + if (t->nnodes > 0 && ac > 0 && fts_is_symbol(at)) + { + fts_symbol_t func = fts_get_symbol(at); + node_t *node = &t->nodes[n]; + + if (func == fts_s_num) + fts_set_int(ret, t->nnodes); + else if (func == s_mean) + fts_set_object(ret, node->mean); + else if (func == s_hyper) + fts_set_object(ret, node->split); + else if (func == fts_s_size) + fts_set_int(ret, node->endind - node->startind + 1); + else if (ac > 2 && fts_is_number(at + 2)) + { + int i = fts_get_number_int(at + 2); /* node-data vector to inspect */ + + if (func == s_vec) + { + fvec_t *vec = fvec_create_row(t->data); + + fvec_set_index(vec, t->dataindex[node->startind + i]); + fts_set_object(ret, vec); + } + else if (func == fts_s_index) + fts_set_int(ret, t->dataindex[node->startind + i]); + } + else if (func == s_profile) + { + fts_post("build profile:\n" + "vector to vector distances:\t%d\n" + "vector to node distances: \t%d\n" + "mean vector calculations: \t%d\n", + "split plane calculations: \t%d\n", + t->profile.v2v, t->profile.v2n, + t->profile.mean, t->profile.hyper); + fts_set_object(ret, t); + profile_clear(t); + } + } + + return fts_ok; +} + + +static fts_method_status_t _tree_print (fts_object_t *o, fts_symbol_t s, + int ac, const fts_atom_t *at, + fts_atom_t *ret) +{ + tree_t *self = (tree_t *) o; + + tree_info_display(self); + tree_data_display(self); + + return fts_ok; +} + + + +/********************************************************** +* +* class +* +*/ + +static fts_method_status_t +_tree_init(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) +{ + tree_t *self = (tree_t *) o; + + /* Init */ + self->ndata = 0; + self->height = 0; + self->nnodes = 0; + self->ndim = 0; + self->dataindex = NULL; + self->nodes = NULL; + self->data = fmat_create(0, 0); /* always an fmat here */ + fts_object_refer((fts_object_t *) self->data); + +#if PROFILE_BUILD + profile_clear(self); +#endif + + if (ac > 0 && fts_is_a(at, fmat_class)) + { /* set data arg and build tree */ + _tree_set(o, s, ac, at, ret); + } + + return fts_ok; +} + + +static fts_method_status_t +_tree_delete(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) +{ + tree_t *self = (tree_t *) o; + int i; + +/* todo: move to tree_clear */ + /* free nodes */ + for (i = 0; i < self->nnodes; i++) + { + fts_object_release(self->nodes[i].mean); + fts_object_release(self->nodes[i].split); + } + + /* free data */ + fts_object_release(self->data); /* release stored vectors */ + + /* free structure */ + if (self->dataindex) fts_free(self->dataindex); + if (self->nodes) fts_free(self->nodes); + + return fts_ok; +} + + +static void +_tree_instantiate(fts_class_t *cl) +{ + fts_class_init(cl, sizeof(tree_t), _tree_init, _tree_delete, "[<fmat: data>>] - vector space index tree"); + +/* + fts_class_set_copy_function(cl, tree_copy_function); + fts_class_set_array_function(cl, tree_array_function); + fts_class_set_dump_function(cl, tree_dump_function); +*/ + fts_class_set_getelem_function(cl, tree_getelem_function); + + fts_class_message_varargs(cl, fts_s_print, _tree_print, "print list of entries"); + +/* + fts_class_message_void(cl, fts_s_clear, _tree_clear, "- erase all entries"); + fts_class_message_varargs(cl, fts_new_symbol("rebuild"), _tree_rebuild); + fts_class_message_varargs(cl, fts_s_remove, _tree_remove, "<any: key> ... - remove given entries"); +*/ + + fts_class_message(cl, fts_s_set, fmat_class, _tree_set, "<fmat: data> - set data matrix(ndata, ndim)"); +/* no: fts_class_message(cl, fts_new_symbol("add"), fmat_class, _tree_add, "<fmat: vector> - add one vector"); */ + + fts_class_message_varargs(cl, fts_s_get, _tree_getknn, + "<fmat: x> - get frow vector of data matrix nearest to vector x"); + fts_class_message_varargs(cl, fts_new_symbol("getknn"), _tree_getknn, + "<fmat: x> [<int: k>] - get k nearest neighbour vectors to vector x (default k=1)"); + fts_class_message_varargs(cl, s_getknni, _tree_getknn, + "<fmat: x> [<int: k>] - get row indices in data matrix of k nearest neighbours to vector x (default k=1) "); + + /* inspection */ + fts_class_message_varargs(cl, fts_new_symbol("node"), _tree_get_node, + "<num|mean|hyper|size|start|end|profile> <int: index> - get information about a node"); + +} + + +FTS_MODULE_INIT(tree) +{ + tree_symbol = fts_new_symbol("tree"); + s_mean = fts_new_symbol("mean"); + s_hyper = fts_new_symbol("hyper"); + s_vec = fts_new_symbol("vec"); + s_profile = fts_new_symbol("profile"); + s_getknni = fts_new_symbol("getknni"); + + tree_class = fts_class_install(tree_symbol, _tree_instantiate); +} Copied: trunk/ftm/ftmlib/classes/kdtree.h (from rev 1829, trunk/ftm/ftmlib/classes/tree.h) =================================================================== --- trunk/ftm/ftmlib/classes/kdtree.h (rev 0) +++ trunk/ftm/ftmlib/classes/kdtree.h 2008-07-22 14:51:27 UTC (rev 1831) @@ -0,0 +1,113 @@ +/* + * FTM + * Copyright (C) 1994, 1995, 1998, 1999, 2007 by IRCAM-Centre Georges Pompidou, Paris, France. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * See file COPYING.LIB for further informations on licensing terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef _DATA_TREE_H_ +#define _DATA_TREE_H_ + +#include "fts.h" + + +#define PROFILE_BUILD 1 +#define PROFILE_SEARCH 1 +#define PROFILE (PROFILE_BUILD || PROFILE_SEARCH) + +#define MAX_FLOAT 0x7FFFFFFF + +#define MAX_NODES 100 + +/* stack elements for search algorithm */ +typedef struct coupleNodeDist +{ + int node; + float dist; +} couple; + +typedef struct searchStack +{ + couple c[MAX_NODES]; + int sp; +} stack; + + +typedef struct node +{ + int startind; /* index of first vector in node in dataindex array */ + int endind; /* index of last vector in node in dataindex array */ + + fmat_t *mean; /* mean vector (todo: median) */ + fmat_t *split; /* hyperplane A1*X1 + A2*X2 +...+ An*Xn + An+1 = 0 */ + float splitnorm; /* length of split vector */ +} node_t; + + +enum tree_dmode { dmode_orthogonal, dmode_hyperplane, dmode_pca }; + +typedef struct _tree +{ + fts_object_t o; + + enum tree_dmode dmode; + int ndim; /* Dimension of vectors */ + int ndata; /* Number of vectors */ + int height; /* Height of the tree */ + int nnodes; /* Number of nodes (must be a power of 2) */ + + fmat_t *data; /* data matrix (ndata, ndim) */ + int *dataindex; /* data vector indirection array (ndata) */ + node_t *nodes; /* nodes (nnodes) */ + + stack s; + + struct { + int v2v; + int v2n; + int mean; + int hyper; + } profile; +} tree_t; + + +FTS_API fts_symbol_t tree_symbol; +FTS_API fts_class_t *tree_class; + +/* get data element via indirection order array */ +#define tree_get_element(t, i, j) fmat_get_element(t->data, t->dataindex[i], j) + +/* get data vector via indirection order array */ +#define tree_get_vector(t, i) (fmat_get_ptr(t->data) + t->dataindex[i] * t->ndim) + +#define fmat_get_row_ptr(f, i) (fmat_get_ptr(f) + (i) * fmat_get_n(f)) + + +int pow2(int x); +void vec_post (float *v, int n, const char *suffix); + +/* vector to node distance */ +float distV2N (tree_t* t, const float *x, const int node); + +void tree_build (tree_t* t); +void tree_init (tree_t* t, int h, int vect_num, int dim); + +int tree_search_knn (tree_t *t, float* x, int k, int *y); + + +#endif Copied: trunk/ftm/ftmlib/classes/kdtreebuild.c (from rev 1830, trunk/ftm/ftmlib/classes/treebuild.c) =================================================================== --- trunk/ftm/ftmlib/classes/kdtreebuild.c (rev 0) +++ trunk/ftm/ftmlib/classes/kdtreebuild.c 2008-07-22 14:51:27 UTC (rev 1831) @@ -0,0 +1,277 @@ + +#include "tree.h" +#include <stdlib.h> +#include <math.h> + + +#define DEBUG_TREEBUILD 0 + + +static void +compute_mean (tree_t *t, int node) +{ + float sum; + float *mean_ptr = fmat_get_ptr(t->nodes[node].mean); +// float *data_ptr = fmat_get_ptr(t->data); + int nvector; + int i, j; + +#if PROFILE_BUILD + t->profile.mean++; +#endif + + // number of vectors from the processed node + nvector = t->nodes[node].endind - t->nodes[node].startind + 1; + for (j = 0; j < t->ndim; j++) + { + sum = 0; + + for (i = t->nodes[node].startind; i <= t->nodes[node].endind; i++) + { + sum += tree_get_element(t, i, j); + } + mean_ptr[j] = sum / nvector; + } + +#if DEBUG_TREEBUILD + fts_post("mean vect for node %d = ", node); + vec_post(mean_ptr, t->ndim, "\n"); +#endif +} + + +static int compare(float* currentVect, float* mean, int component) +{ +// fts_post("compare %f and %f\n", mean[component], currentVect[component]); + return (currentVect[component] - mean[component]); +} + + +/* swap positions of vectors i and j: only in indirection array */ +static void swap (tree_t* t, int i, int j) +{ + int tmp; + + tmp = t->dataindex[i]; + t->dataindex[i] = t->dataindex[j]; + t->dataindex[j] = tmp; +} + + +/* vector to orthogonal plane node distance */ +static float distV2orthoH (const float* vect, float* hplane, int vectDim, float norm) +{ +// standard algebra computing + int i; + float dotprod = 0; + + for (i = 0; i < vectDim; i++) + { + dotprod += vect[i] * hplane[i]; + } + return ((dotprod + hplane[vectDim]) / norm); +} + + +/* vector to general plane node distance */ +static float distV2H (const float* vect, float* plane, float* mean, int vectDim, float norm) +{ + // standard algebra computing + int i; + float dotprod = 0; + + for(i = 0; i < vectDim; i++) + { + dotprod += (vect[i] - mean[i]) * plane[i]; + } + return (dotprod / norm); +} + + +/* vector to node distance */ +float distV2N (tree_t* t, const float *x, const int node) +{ +#if PROFILE_BUILD + t->profile.v2n++; +#endif + + switch (t->dmode) + { + case dmode_orthogonal: + return distV2orthoH(x, + fmat_get_ptr(t->nodes[node].split), + t->ndim, t->nodes[node].splitnorm); + case dmode_hyperplane: + return distV2H(x, + fmat_get_ptr(t->nodes[node].split), + fmat_get_ptr(t->nodes[node].mean), + t->ndim, t->nodes[node].splitnorm); + default: + fts_post("error: unknown mode %d", t->dmode); + return 0; + } +} + + +static void compute_splitplane (tree_t* t, int node, int level) +{ + int b; + float h; + + #if PROFILE_BUILD + t->profile.hyper++; +#endif + + /* case dmode_orthogonal */ + // Level parameter gives the base vector to use + b = level % t->ndim; + h = fmat_get_element(t->nodes[node].mean, b, 0); + + // We compute an hyperplane which is orthogonal to the base vector number b + fmat_set_const(t->nodes[node].split, 0); + + fmat_set_element(t->nodes[node].split, b, 0, 1); + fmat_set_element(t->nodes[node].split, t->ndim, 0, -h); + + t->nodes[node].splitnorm = 1; + +#if DEBUG_TREEBUILD + fts_post("Splitplane of node %i: ", node); + vec_post(t->nodes[node].split, t->ndim + 1, "\n"); +#endif +} + + + + +static void freeVect (tree_t* t, int vect_number) +{ + fmat_set_const(t->data, MAX_FLOAT); +} + +#if 0 +void reBalance(tree_t* t) +{ + int i = 0; + int j = t->ndata - 1; + + /* Sort */ + while(j > i) + { + while((t->data[i][0] != MAX_FLOAT)&&(i < t->ndata)) + { + i++; + } + while((t->data[j][0] == MAX_FLOAT)&&(j >=0 )) + { + j--; + } + if(j > i) + { + swap(t, i, j); + } + } + t->ndata = i; + t->nodes[0].endind = t->ndata - 1; + + tree_build(t); +} +#endif + + +void tree_build (tree_t* t) +{ + int l; // current level number + int n; // current node number + int i, j; // loop counters + + /* Maximum length is equal to pow2(height-1) */ + if (pow2(t->height-1) > t->ndata) + { + if (t->ndata == 0) + fts_post("tree is empty! \n"); + else + fts_post("error: can't build this tree, try with a smaller height: %i > %i\n", pow2(t->height-1), t->ndata); + + return; + } + + for (l = 0; l < t->height; l++) + { + int nstart = pow2(l) - 1; + int nend = pow2(l+1) - 1; +#if DEBUG_TREEBUILD + fts_post("\nLevel #%i nodes %d..%d\n", l, nstart, nend); +#endif + for (n = nstart; n < nend; n++) + { /* for all nodes at tree level l */ + compute_mean(t, n); + compute_splitplane(t, n, l); + +#if DEBUG_TREEBUILD + fts_post("Node #%i (%i..%i): mean = ", + n, t->nodes[n].startind, t->nodes[n].endind); + vec_post(fmat_get_ptr(t->nodes[n].mean), t->ndim, "\n"); +#endif + i = t->nodes[n].startind; + j = t->nodes[n].endind; + + while (j > i) + { /* sort node vectors by distance to splitplane */ + while (distV2N(t, tree_get_vector(t, i), n) <= 0) + { + i++; // fts_post("i=%i\n", i); + } + while (distV2N(t, tree_get_vector(t, j), n) > 0) + { + j--; // fts_post("j=%i\n", j); + } + if (j > i) + { + swap(t, i, j); // fts_post("swap %i and %i\n", i ,j); + } + } + + t->nodes[2*n+1].startind = t->nodes[n].startind; // start index of left child of node n + t->nodes[2*n+1].endind = j; // end index of left child of node n + t->nodes[2*n+2].startind = i; // start index of right child of node n + t->nodes[2*n+2].endind = t->nodes[n].endind; // end index of right child of node n + } + } +} + + +void tree_init (tree_t* t, int h, int vect_num, int dim) +{ + int i; + + t->dmode = dmode_orthogonal; + t->ndim = dim; + t->ndata = vect_num; + t->height = h; + + /* init nodes */ + t->nnodes = pow2(h) - 1; + t->nodes = fts_realloc(t->nodes, t->nnodes * sizeof(node_t)); + + for (i = 0; i < t->nnodes; i++) + { + t->nodes[i].mean = fmat_create(dim, 1); + t->nodes[i].split = fmat_create(dim + 1, 1); + + fts_object_refer((fts_object_t *) t->nodes[i].mean); + fts_object_refer((fts_object_t *) t->nodes[i].split); + } + + if (t->nnodes > 0) + { /* init root node */ + t->nodes[0].startind = 0; + t->nodes[0].endind = t->ndata - 1; + } + + /* init index list */ + t->dataindex = fts_realloc(t->dataindex, t->ndata * sizeof(int)); + + for (i = 0; i < t->ndata; i++) + t->dataindex[i] = i; +} Copied: trunk/ftm/ftmlib/classes/kdtreesearch.c (from rev 1830, trunk/ftm/ftmlib/classes/treesearch.c) =================================================================== --- trunk/ftm/ftmlib/classes/kdtreesearch.c (rev 0) +++ trunk/ftm/ftmlib/classes/kdtreesearch.c 2008-07-22 14:51:27 UTC (rev 1831) @@ -0,0 +1,191 @@ + +#include "tree.h" +#include <stdlib.h> +#include <math.h> + + +#define DEBUG_TREESEARCH 0 + + +static void initStack(stack* s) +{ + s->sp = -1; +} + +static int isEmpty(stack s) +{ + if(s.sp < 0) return 1; + return 0; +} + +static void push(stack* s, couple c) +{ + s->sp++; + if(s->sp >= MAX_NODES) + fts_post("Warning: Stack capacity is attented [sp = %i]\n", s->sp); + s->c[s->sp].node = c.node; + s->c[s->sp].dist = c.dist; +} + +static couple pop(stack* s) +{ + if(s->sp < 0) + fts_post("Warning: Stack is empty, popped values may be inderteminated [sp = %i]\n", + s->sp); + couple tmp = s->c[s->sp]; + s->sp--; + return tmp; +} + + +static void displayStack(stack s) +{ + int i = s.sp; + if(s.sp < 0) fts_post("Stack is empty\n"); + else + { + fts_post("TOS (size %d) --------------\n", s.sp + 1); + while(i >= 0) + { + fts_post("stack pos %d (node %d, dist %f)\n", i, s.c[i].node, s.c[i].dist); + i--; + } + } +} + +static void displayCouple(couple c) +{ + fts_post("Couple( %i, %f)\n", c.node, c.dist); +} + +static void coupleBuild(couple* c, int n, float d) +{ + c->node = n; + c->dist = d; +} + +static float max(float a, float b) +{ + return (a > b)? a : b; +} + + +static int maxArr(float* array, int size) +{ + int index = 0; + int i; + + for(i = 1; i<size; i++) + { + if(array[index] < array[i]) index = i; + } + + return index; +} + +static float euclidianDistance(float* v1, float* v2, int dim) +{ + int i; + float sum = 0; + + for (i = 0; i < dim; i++) + { + float diff = v2[i] - v1[i]; + sum += diff * diff; + } + + return sum; +} + + +/* out: y[K] = index of the Kth neirest neighbour + return: actual number of found neighbours */ +int tree_search_knn (tree_t *t, float* x, int k, int *y) +{ + float *d; // vector to vector distance from vector y[k] to vector x + int i; // current processed vector + float dxx; // dxx = distance between 2 vectors + int kmax = 0; // index of current Kth neighbour + couple cur; // current (node, dist) couple + + if (t->ndata == 0) + return 0; + + if (k < 1) + k = 1; + + // Init distances + d = alloca(k * sizeof(float)); + for(i = 0; i < k; i++) + { + d[i] = MAX_FLOAT; + } + + // Init Search Stack + coupleBuild(&cur, 0, 0); + push(&t->s, cur); + + while (!isEmpty(t->s)) + { + displayStack(t->s); + cur = pop(&t->s); + + if (cur.dist < d[kmax]) // elimination rule + { + if (cur.node >= (pow2(t->height - 1) - 1)) + { // leaf node + int istart = t->nodes[cur.node].startind; + int iend = t->nodes[cur.node].endind; + int i; +#ifdef DEBUG_TREESEARCH + fts_post("Leaf node p = %d\n", cur.node); +#endif + for (i = istart; i <= iend; i++) + { + dxx = euclidianDistance(x, tree_get_vector(t, i), t->ndim); + +#ifdef DEBUG_TREESEARCH + fts_post("distance = %f between vector %d ", dxx, i); + vec_post(tree_get_vector(t, i), t->ndim, " and x "); + vec_post(x, t->ndim, "\n"); +#endif +#if PROFILE_SEARCH + t->profile.v2v++; +#endif + if (dxx < d[kmax]) + { + y[kmax] = i; + d[kmax] = dxx; + kmax = maxArr(d, k); + } + } + } + else + { // branched node + float d = distV2N(t, x, cur.node); +#ifdef DEBUG_TREESEARCH + fts_post("Inner node %d, d = %f\n", cur.node, d); +#endif + if (d < 0) + { + couple c1; + couple c2; + coupleBuild(&c1, 2*cur.node+2, max(cur.dist, d*d)); + coupleBuild(&c2, 2*cur.node+1, cur.dist); + push(&t->s, c1); + push(&t->s, c2); + } + else + { + couple c1; + couple c2; + coupleBuild(&c1, 2*cur.node+1, max(cur.dist, d*d)); + coupleBuild(&c2, 2*cur.node+2, cur.dist); + push(&t->s, c1); + push(&t->s, c2); + } + } + } + } + return k; /* return actual number of found neighbours */ +} Deleted: trunk/ftm/ftmlib/classes/tree.c =================================================================== --- trunk/ftm/ftmlib/classes/tree.c 2008-07-22 14:28:50 UTC (rev 1830) +++ trunk/ftm/ftmlib/classes/tree.c 2008-07-22 14:51:27 UTC (rev 1831) @@ -1,511 +0,0 @@ -/* - * FTM - * Copyright (C) 1994, 1995, 1998, 1999, 2007 by IRCAM-Centre Georges Pompidou, Paris, France. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 - * of the License, or (at your option) any later version. - * - * See file COPYING.LIB for further informations on licensing terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifdef WIN32 -#include <malloc.h> -#else -#include <alloca.h> -#endif -#include <math.h> - -#include "fts.h" - -#define HEIGHT 3 -#define MAX_FLOAT 0x7FFFFFFF - -fts_symbol_t tree_symbol = 0; -fts_class_t *tree_class = 0; - -fts_symbol_t s_mean; -fts_symbol_t s_hyper; -fts_symbol_t s_vec; -fts_symbol_t s_profile; -fts_symbol_t s_getknni; - - -/* for the search algorithm */ -typedef struct stack_elem -{ - int node; - double dist; -} stack_elem_t; - -static void stack_push (fts_stack_t *s, int p, double d) -{ -/* doesn't work with CodeWorrior - stack_elem_t _new = { p, d }; - fts_stack_push(s, stack_elem_t, _new); - */ -} - -static int stack_pop (fts_stack_t *s, int *p, double *d) -{ - int top = fts_stack_top(s); - - if (top >= 0) - { - stack_elem_t *_tmp = ((stack_elem_t *) fts_stack_base(s)) + top; - - *p = _tmp->node; - *d = _tmp->dist; - - fts_stack_pop(s, 1); - return 1; - } - else - return 0; -} - - -int pow2 (int x) -{ - return 1 << x; -} - - -#if PROFILE -static void profile_clear (tree_t *t) -{ - t->profile.v2v = 0; - t->profile.v2n = 0; - t->profile.mean = 0; - t->profile.hyper = 0; -} -#endif - -static double -vec_dist (fmat_t *a, fmat_t *b) -{ - int m = fmat_get_m(a); - int n = fmat_get_n(a); - float *l = fmat_get_ptr(a); - float *r = fmat_get_ptr(b); - int size = m * n; - double dist = 0; - int i; - - for (i = 0; i < size; i++) - dist += (l[i] - r[i]) * (l[i] - r[i]); - - return dist; -} - - -static float -distfmatV2H(fmat_t* vect, fmat_t* hplane) -{ - //standard algebra computing - int i; - float tmp1 = 0; - float tmp2 = 0; - int m = fmat_get_m(vect); - int n = fmat_get_n(vect); - float *v = fmat_get_ptr(vect); - float *h = fmat_get_ptr(hplane); - int size = m * n; - - for(i = 0; i < size; i++) - { - tmp1 += v[i]*h[i]; - tmp2 += h[i]*h[i]; - } - - return (tmp1 + h[size])/sqrt(tmp2); -} - - -/* - @return number of vectors found n, n <= k - list of n indices in result -*/ -#if 0 -static int tree_search (tree_t *tree, fmat_t *x, int k, int *result) -{ - fts_stack_t stack; - - fts_stack_init(&stack, stack_elem_t); - - stack_push(&stack, 0, 0); - - /* one element access */ -/* fmat_get_element(x, 0, i); */ - - /* testing: */ - result[0] = 0; - return 1; -} -#endif - - -void vec_post (float *v, int n, const char *suffix) -{ - int i; - - for (i = 0; i < n; i++) - { - fts_post("%s%.1f", (i == 0 ? "[" : ", "), v[i]); - } - fts_post("]%s", suffix); -} - -static void tree_info_display (tree_t* t) -{ - int i, j; - fts_post("\nTree Info:\n"); - fts_post("ndim = %i\n", t->ndim); - fts_post("ndata = %i\n", t->ndata); - fts_post("height = %i\n", t->height); - fts_post("nnodes = %i\n", t->nnodes); - - if (t->height == 0 || t->ndata == 0) fts_post("Empty Tree\n"); - - for (i = 0; i < t->ndata; i++) - { - fts_post("raw data vec %-3i = ", i); - vec_post(fmat_get_row_ptr(t->data, i), t->ndim, "\n"); - } -} - - -static void tree_data_display(tree_t* t) -{ - int l, n, i, j; - - fts_post("\nTree Data:\n"); - if (t->height == 0 || t->ndata == 0) fts_post("Empty Tree\n"); - - for (l = 0; l < t->height; l++) - { - fts_post("Level #%i nodes %d..%d\n", l, pow2(l) - 1, pow2(l+1) - 1); - for (n = pow2(l) - 1; n < pow2(l+1) - 1; n++) - { - fts_post(" node %d size %d <%d..%d> = (", - n, t->nodes[n].endind - t->nodes[n].startind + 1, - t->nodes[n].startind, t->nodes[n].endind); - for (i = t->nodes[n].startind; i <= t->nodes[n].endind; i++) - { - fts_post("vec %d = ", t->dataindex[i]); - vec_post(tree_get_vector(t, i), t->ndim, - i < t->nodes[n].endind ? ", " : ""); - } - fts_post(")\n"); - } - } -} - - -static void -tree_getelem_function(fts_object_t *o, int ac, const fts_atom_t *at, fts_atom_t *ret) -{ - if(ac > 0 && fts_is_number(at)) - { - } -} - - - - - -/****************************************************************************** - * - * user methods - * - */ - -static fts_method_status_t _tree_set (fts_object_t *o, fts_symbol_t s, - int ac, const fts_atom_t *at, - fts_atom_t *ret) -{ - tree_t *self = (tree_t *) o; - fmat_t *data = (fmat_t *) fts_get_object(at); - - if (self->data) - fts_object_release((fts_object_t *) self->data); - - /* method only declared for fmat, so no check needed */ - self->data = data; - fts_object_refer((fts_object_t *) self->data); - - tree_init(self, floor(log2(fmat_get_m(data))), - fmat_get_m(data), fmat_get_n(data)); - - /* tree_clear and rebuild: */ - /* tree_clear(self);*/ - tree_build(self); - - fts_set_object(ret, o); - return fts_ok; -} - - -static fts_method_status_t _tree_add (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) -{ - tree_t *self = (tree_t *) o; - - /* rebuild */ - /* tree_set(self, ac, at); - tree_build(self); - */ - - fts_set_object(ret, self); - fts_object_refer(self); - - return fts_ok; -} - - - -static fts_method_status_t _tree_getknn (fts_object_t *o, fts_symbol_t s, - int ac, const fts_atom_t *at, - fts_atom_t *ret) -{ - tree_t *self = (tree_t *) o; - fmat_t *x = NULL; /* search vector */ - int k = 1, n; - int *result; - - if (ac > 0 && fts_is_a(at, fmat_class)) - x = (fmat_t *) fts_get_object(at); - - if (ac > 1 && fts_is_number(at+1)) - k = fts_get_number_int(at+1); - - result = alloca(sizeof(int) * k); - - n = tree_search_knn(self, fmat_get_ptr(x), k, result); - - if (s == fts_s_get) /* geti: nearest index? */ - { /* return one fvec */ - fvec_t *vec = fvec_create_row(self->data); - fvec_set_index(vec, result[0]); - fts_set_object(ret, vec); - } - else - { /* return n-tuple of fvec or index */ - fts_tuple_t *tup = (fts_tuple_t *) fts_object_create(fts_tuple_class, 0, NULL); - fts_atom_t *at; - int i; - - fts_tuple_set_size(tup, n); - at = fts_tuple_get_atoms(tup); - - for (i = 0; i < n; i++) - { - if (s == s_getknni) - fts_set_int(at + i, self->dataindex[result[i]]); - else /* getknn */ - { - fvec_t *vec = fvec_create_row(self->data); - fvec_set_index(vec, self->dataindex[result[i]]); - - fts_object_refer((fts_object_t *) vec); - fts_set_object(at + i, vec); - } - } - - fts_set_object(ret, tup); - } - - return fts_ok; -} - - -static fts_method_status_t _tree_get_node (fts_object_t *o, fts_symbol_t s, - int ac, const fts_atom_t *at, - fts_atom_t *ret) -{ - tree_t *t = (tree_t *) o; - int n = 0; /* node to inspect */ - - if (ac > 1 && fts_is_number(at + 1)) - { - n = fts_get_number_int(at + 1); - if (n >= t->nnodes) - n = t->nnodes - 1; - } - - if (t->nnodes > 0 && ac > 0 && fts_is_symbol(at)) - { - fts_symbol_t func = fts_get_symbol(at); - node_t *node = &t->nodes[n]; - - if (func == fts_s_num) - fts_set_int(ret, t->nnodes); - else if (func == s_mean) - fts_set_object(ret, node->mean); - else if (func == s_hyper) - fts_set_object(ret, node->split); - else if (func == fts_s_size) - fts_set_int(ret, node->endind - node->startind + 1); - else if (ac > 2 && fts_is_number(at + 2)) - { - int i = fts_get_number_int(at + 2); /* node-data vector to inspect */ - - if (func == s_vec) - { - fvec_t *vec = fvec_create_row(t->data); - - fvec_set_index(vec, t->dataindex[node->startind + i]); - fts_set_object(ret, vec); - } - else if (func == fts_s_index) - fts_set_int(ret, t->dataindex[node->startind + i]); - } - else if (func == s_profile) - { - fts_post("build profile:\n" - "vector to vector distances:\t%d\n" - "vector to node distances: \t%d\n" - "mean vector calculations: \t%d\n", - "split plane calculations: \t%d\n", - t->profile.v2v, t->profile.v2n, - t->profile.mean, t->profile.hyper); - fts_set_object(ret, t); - profile_clear(t); - } - } - - return fts_ok; -} - - -static fts_method_status_t _tree_print (fts_object_t *o, fts_symbol_t s, - int ac, const fts_atom_t *at, - fts_atom_t *ret) -{ - tree_t *self = (tree_t *) o; - - tree_info_display(self); - tree_data_display(self); - - return fts_ok; -} - - - -/********************************************************** -* -* class -* -*/ - -static fts_method_status_t -_tree_init(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) -{ - tree_t *self = (tree_t *) o; - - /* Init */ - self->ndata = 0; - self->height = 0; - self->nnodes = 0; - self->ndim = 0; - self->dataindex = NULL; - self->nodes = NULL; - self->data = fmat_create(0, 0); /* always an fmat here */ - fts_object_refer((fts_object_t *) self->data); - -#if PROFILE_BUILD - profile_clear(self); -#endif - - if (ac > 0 && fts_is_a(at, fmat_class)) - { /* set data arg and build tree */ - _tree_set(o, s, ac, at, ret); - } - - return fts_ok; -} - - -static fts_method_status_t -_tree_delete(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) -{ - tree_t *self = (tree_t *) o; - int i; - -/* todo: move to tree_clear */ - /* free nodes */ - for (i = 0; i < self->nnodes; i++) - { - fts_object_release(self->nodes[i].mean); - fts_object_release(self->nodes[i].split); - } - - /* free data */ - fts_object_release(self->data); /* release stored vectors */ - - /* free structure */ - if (self->dataindex) fts_free(self->dataindex); - if (self->nodes) fts_free(self->nodes); - - return fts_ok; -} - - -static void -_tree_instantiate(fts_class_t *cl) -{ - fts_class_init(cl, sizeof(tree_t), _tree_init, _tree_delete, "[<fmat: data>>] - vector space index tree"); - -/* - fts_class_set_copy_function(cl, tree_copy_function); - fts_class_set_array_function(cl, tree_array_function); - fts_class_set_dump_function(cl, tree_dump_function); -*/ - fts_class_set_getelem_function(cl, tree_getelem_function); - - fts_class_message_varargs(cl, fts_s_print, _tree_print, "print list of entries"); - -/* - fts_class_message_void(cl, fts_s_clear, _tree_clear, "- erase all entries"); - fts_class_message_varargs(cl, fts_new_symbol("rebuild"), _tree_rebuild); - fts_class_message_varargs(cl, fts_s_remove, _tree_remove, "<any: key> ... - remove given entries"); -*/ - - fts_class_message(cl, fts_s_set, fmat_class, _tree_set, "<fmat: data> - set data matrix(ndata, ndim)"); -/* no: fts_class_message(cl, fts_new_symbol("add"), fmat_class, _tree_add, "<fmat: vector> - add one vector"); */ - - fts_class_message_varargs(cl, fts_s_get, _tree_getknn, - "<fmat: x> - get frow vector of data matrix nearest to vector x"); - fts_class_message_varargs(cl, fts_new_symbol("getknn"), _tree_getknn, - "<fmat: x> [<int: k>] - get k nearest neighbour vectors to vector x (default k=1)"); - fts_class_message_varargs(cl, s_getknni, _tree_getknn, - "<fmat: x> [<int: k>] - get row indices in data matrix of k nearest neighbours to vector x (default k=1) "); - - /* inspection */ - fts_class_message_varargs(cl, fts_new_symbol("node"), _tree_get_node, - "<num|mean|hyper|size|start|end|profile> <int: index> - get information about a node"); - -} - - -FTS_MODULE_INIT(tree) -{ - tree_symbol = fts_new_symbol("tree"); - s_mean = fts_new_symbol("mean"); - s_hyper = fts_new_symbol("hyper"); - s_vec = fts_new_symbol("vec"); - s_profile = fts_new_symbol("profile"); - s_getknni = fts_new_symbol("getknni"); - - tree_class = fts_class_install(tree_symbol, _tree_instantiate); -} Deleted: trunk/ftm/ftmlib/classes/tree.h =================================================================== --- trunk/ftm/ftmlib/classes/tree.h 2008-07-22 14:28:50 UTC (rev 1830) +++ trunk/ftm/ftmlib/classes/tree.h 2008-07-22 14:51:27 UTC (rev 1831) @@ -1,113 +0,0 @@ -/* - * FTM - * Copyright (C) 1994, 1995, 1998, 1999, 2007 by IRCAM-Centre Georges Pompidou, Paris, France. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 - * of the License, or (at your option) any later version. - * - * See file COPYING.LIB for further informations on licensing terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef _DATA_TREE_H_ -#define _DATA_TREE_H_ - -#include "fts.h" - - -#define PROFILE_BUILD 1 -#define PROFILE_SEARCH 1 -#define PROFILE (PROFILE_BUILD || PROFILE_SEARCH) - -#define MAX_FLOAT 0x7FFFFFFF - -#define MAX_NODES 100 - -/* stack elements for search algorithm */ -typedef struct coupleNodeDist -{ - int node; - float dist; -} couple; - -typedef struct searchStack -{ - couple c[MAX_NODES]; - int sp; -} stack; - - -typedef struct node -{ - int startind; /* index of first vector in node in dataindex array */ - int endind; /* index of last vector in node in dataindex array */ - - fmat_t *mean; /* mean vector (todo: median) */ - fmat_t *split; /* hyperplane A1*X1 + A2*X2 +...+ An*Xn + An+1 = 0 */ - float splitnorm; /* length of split vector */ -} node_t; - - -enum tree_dmode { dmode_orthogonal, dmode_hyperplane, dmode_pca }; - -typedef struct _tree -{ - fts_object_t o; - - enum tree_dmode dmode; - int ndim; /* Dimension of vectors */ - int ndata; /* Number of vectors */ - int height; /* Height of the tree */ - int nnodes; /* Number of nodes (must be a power of 2) */ - - fmat_t *data; /* data matrix (ndata, ndim) */ - int *dataindex; /* data vector indirection array (ndata) */ - node_t *nodes; /* nodes (nnodes) */ - - stack s; - - struct { - int v2v; - int v2n; - int mean; - int hyper; - } profile; -} tree_t; - - -FTS_API fts_symbol_t tree_symbol; -FTS_API fts_class_t *tree_class; - -/* get data element via indirection order array */ -#define tree_get_element(t, i, j) fmat_get_element(t->data, t->dataindex[i], j) - -/* get data vector via indirection order array */ -#define tree_get_vector(t, i) (fmat_get_ptr(t->data) + t->dataindex[i] * t->ndim) - -#define fmat_get_row_ptr(f, i) (fmat_get_ptr(f) + (i) * fmat_get_n(f)) - - -int pow2(int x); -void vec_post (float *v, int n, const char *suffix); - -/* vector to node distance */ -float distV2N (tree_t* t, const float *x, const int node); - -void tree_build (tree_t* t); -void tree_init (tree_t* t, int h, int vect_num, int dim); - -int tree_search_knn (tree_t *t, float* x, int k, int *y); - - -#endif Deleted: trunk/ftm/ftmlib/classes/treebuild.c =================================================================== --- trunk/ftm/ftmlib/classes/treebuild.c 2008-07-22 14:28:50 UTC (rev 1830) +++ trunk/ftm/ftmlib/classes/treebuild.c 2008-07-22 14:51:27 UTC (rev 1831) @@ -1,277 +0,0 @@ - -#include "tree.h" -#include <stdlib.h> -#include <math.h> - - -#define DEBUG_TREEBUILD 0 - - -static void -compute_mean (tree_t *t, int node) -{ - float sum; - float *mean_ptr = fmat_get_ptr(t->nodes[node].mean); -// float *data_ptr = fmat_get_ptr(t->data); - int nvector; - int i, j; - -#if PROFILE_BUILD - t->profile.mean++; -#endif - - // number of vectors from the processed node - nvector = t->nodes[node].endind - t->nodes[node].startind + 1; - for (j = 0; j < t->ndim; j++) - { - sum = 0; - - for (i = t->nodes[node].startind; i <= t->nodes[node].endind; i++) - { - sum += tree_get_element(t, i, j); - } - mean_ptr[j] = sum / nvector; - } - -#if DEBUG_TREEBUILD - fts_post("mean vect for node %d = ", node); - vec_post(mean_ptr, t->ndim, "\n"); -#endif -} - - -static int compare(float* currentVect, float* mean, int component) -{ -// fts_post("compare %f and %f\n", mean[component], currentVect[component]); - return (currentVect[component] - mean[component]); -} - - -/* swap positions of vectors i and j: only in indirection array */ -static void swap (tree_t* t, int i, int j) -{ - int tmp; - - tmp = t->dataindex[i]; - t->dataindex[i] = t->dataindex[j]; - t->dataindex[j] = tmp; -} - - -/* vector to orthogonal plane node distance */ -static float distV2orthoH (const float* vect, float* hplane, int vectDim, float norm) -{ -// standard algebra computing - int i; - float dotprod = 0; - - for (i = 0; i < vectDim; i++) - { - dotprod += vect[i] * hplane[i]; - } - return ((dotprod + hplane[vectDim]) / norm); -} - - -/* vector to general plane node distance */ -static float distV2H (const float* vect, float* plane, float* mean, int vectDim, float norm) -{ - // standard algebra computing - int i; - float dotprod = 0; - - for(i = 0; i < vectDim; i++) - { - dotprod += (vect[i] - mean[i]) * plane[i]; - } - return (dotprod / norm); -} - - -/* vector to node distance */ -float distV2N (tree_t* t, const float *x, const int node) -{ -#if PROFILE_BUILD - t->profile.v2n++; -#endif - - switch (t->dmode) - { - case dmode_orthogonal: - return distV2orthoH(x, - fmat_get_ptr(t->nodes[node].split), - t->ndim, t->nodes[node].splitnorm); - case dmode_hyperplane: - return distV2H(x, - fmat_get_ptr(t->nodes[node].split), - fmat_get_ptr(t->nodes[node].mean), - t->ndim, t->nodes[node].splitnorm); - default: - fts_post("error: unknown mode %d", t->dmode); - return 0; - } -} - - -static void compute_splitplane (tree_t* t, int node, int level) -{ - int b; - float h; - - #if PROFILE_BUILD - t->profile.hyper++; -#endif - - /* case dmode_orthogonal */ - // Level parameter gives the base vector to use - b = level % t->ndim; - h = fmat_get_element(t->nodes[node].mean, b, 0); - - // We compute an hyperplane which is orthogonal to the base vector number b - fmat_set_const(t->nodes[node].split, 0); - - fmat_set_element(t->nodes[node].split, b, 0, 1); - fmat_set_element(t->nodes[node].split, t->ndim, 0, -h); - - t->nodes[node].splitnorm = 1; - -#if DEBUG_TREEBUILD - fts_post("Splitplane of node %i: ", node); - vec_post(t->nodes[node].split, t->ndim + 1, "\n"); -#endif -} - - - - -static void freeVect (tree_t* t, int vect_number) -{ - fmat_set_const(t->data, MAX_FLOAT); -} - -#if 0 -void reBalance(tree_t* t) -{ - int i = 0; - int j = t->ndata - 1; - - /* Sort */ - while(j > i) - { - while((t->data[i][0] != MAX_FLOAT)&&(i < t->ndata)) - { - i++; - } - while((t->data[j][0] == MAX_FLOAT)&&(j >=0 )) - { - j--; - } - if(j > i) - { - swap(t, i, j); - } - } - t->ndata = i; - t->nodes[0].endind = t->ndata - 1; - - tree_build(t); -} -#endif - - -void tree_build (tree_t* t) -{ - int l; // current level number - int n; // current node number - int i, j; // loop counters - - /* Maximum length is equal to pow2(height-1) */ - if (pow2(t->height-1) > t->ndata) - { - if (t->ndata == 0) - fts_post("tree is empty! \n"); - else - fts_post("error: can't build this tree, try with a smaller height: %i > %i\n", pow2(t->height-1), t->ndata); - - return; - } - - for (l = 0; l < t->height; l++) - { - int nstart = pow2(l) - 1; - int nend = pow2(l+1) - 1; -#if DEBUG_TREEBUILD - fts_post("\nLevel #%i nodes %d..%d\n", l, nstart, nend); -#endif - for (n = nstart; n < nend; n++) - { /* for all nodes at tree level l */ - compute_mean(t, n); - compute_splitplane(t, n, l); - -#if DEBUG_TREEBUILD - fts_post("Node #%i (%i..%i): mean = ", - n, t->nodes[n].startind, t->nodes[n].endind); - vec_post(fmat_get_ptr(t->nodes[n].mean), t->ndim, "\n"); -#endif - i = t->nodes[n].startind; - j = t->nodes[n].endind; - - while (j > i) - { /* sort node vectors by distance to splitplane */ - while (distV2N(t, tree_get_vector(t, i), n) <= 0) - { - i++; // fts_post("i=%i\n", i); - } - while (distV2N(t, tree_get_vector(t, j), n) > 0) - { - j--; // fts_post("j=%i\n", j); - } - if (j > i) - { - swap(t, i, j); // fts_post("swap %i and %i\n", i ,j); - } - } - - t->nodes[2*n+1].startind = t->nodes[n].startind; // start index of left child of node n - t->nodes[2*n+1].endind = j; // end index of left child of node n - t->nodes[2*n+2].startind = i; // start index of right child of node n - t->nodes[2*n+2].endind = t->nodes[n].endind; // end index of right child of node n - } - } -} - - -void tree_init (tree_t* t, int h, int vect_num, int dim) -{ - int i; - - t->dmode = dmode_orthogonal; - t->ndim = dim; - t->ndata = vect_num; - t->height = h; - - /* init nodes */ - t->nnodes = pow2(h) - 1; - t->nodes = fts_realloc(t->nodes, t->nnodes * sizeof(node_t)); - - for (i = 0; i < t->nnodes; i++) - { - t->nodes[i].mean = fmat_create(dim, 1); - t->nodes[i].split = fmat_create(dim + 1, 1); - - fts_object_refer((fts_object_t *) t->nodes[i].mean); - fts_object_refer((fts_object_t *) t->nodes[i].split); - } - - if (t->nnodes > 0) - { /* init root node */ - t->nodes[0].startind = 0; - t->nodes[0].endind = t->ndata - 1; - } - - /* init index list */ - t->dataindex = fts_realloc(t->dataindex, t->ndata * sizeof(int)); - - for (i = 0; i < t->ndata; i++) - t->dataindex[i] = i; -} Deleted: trunk/ftm/ftmlib/classes/treedefs.h =================================================================== --- trunk/ftm/ftmlib/classes/treedefs.h 2008-07-22 14:28:50 UTC (rev 1830) +++ trunk/ftm/ftmlib/classes/treedefs.h 2008-07-22 14:51:27 UTC (rev 1831) @@ -1,112 +0,0 @@ -#include <stdio.h> - -#define MAX_DIM 10 -#define MAX_VECT 20 -#define MAX_NODES 100 - -#define MAX_FLOAT 0x7FFFFFFF - -typedef struct coupleNodeDist { - int node; - float dist; -} couple; - -typedef struct searchStack { - couple c[MAX_NODES]; - int sp; -} stack; - -typedef struct SearchTree { - int v_dim; //Dimention of vectors - int v_number; //Number of vectors - int height; //Height of the tree - int n_number; //Number of nodes (must be a power of 2) - int n_begin[MAX_NODES]; //n_begin[i] = begining index of the node i - int n_end[MAX_NODES]; //n_end[i] = ending index of the node i - float data[MAX_VECT][MAX_DIM]; //Matrix of vectors - float meanVect[MAX_NODES][MAX_DIM]; //Matrix of mean vectors - float splitPlane[MAX_NODES][MAX_DIM+1]; //Matrix of hyperplanes: A1*X1 + A2*X2 +...+ An*Xn + An+1 = 0 - stack s; //Stack of couple (node number, distance to vector) -} Tree; - - - -/* Init Tree object */ -void initTree(Tree* t, int dim, int height, int vect_num); - -/* Returns 2^x */ -int pow2(int x); - -/* Compute the "mean vector" of a vector list beetween index begin and end */ -void meanVectCompute(Tree* t, int node); - -/* Compute a "split plane" which is orthogonal to the base vectors */ -void splitPlaneCompute(Tree* t, int node, int level); - - -/* - Compare the current vector to an hyperplane in a simple way. - Returns distance. -*/ -int compare(float* currentVect, float* meanVect, int component); - -/* Return the orthogonal distance from a vector to an hyperplane */ -float distV2H(float* vect, float* hplane, int vectDim); - -/* - Compare the current vector to an hyperplane. - Returns 1 if the result is positive else return 0. - bool compare(Vector currentVect, Vector meanvect); -*/ - - -/* Standard exchange beetween two vectors of a Tree object */ -void swap(Tree* t, int i, int j); - - -/* Decomposition algorithm */ -void decompose(Tree* t); - - -/* Building the Tree */ -void buildTree(Tree* t, int dim, int component, int vnum); - -/* Mark a vector to be deleted at the next call of reBuild function */ -void freeVect(Tree* t, int vect_number); - -/* Rebuild the tree (can bee nescessary if you had free or inserted some vectors) */ -void reBalance(Tree* t); - - -/* Show informations about a tree structure */ -void tree_info_display(Tree* t); - - -/* Display a Tree structure */ -void tree_display(Tree* t); - - -/******************************* Functions used in search procedure *********************************/ - -/* Search the k nearest neighbours of a vector by using a search tree */ -int* search(Tree* t, int k, float* vector); - -/* Maximum of a */ -float max(float a, float b); - -/* returns index of the maximum value of an array */ -int maxArr(float* array, int size); - -/* returns Euclidian distance of two vectors without square root */ -float euclidianDistance(float* v1, float* v2, int dim); - -/* Methods for the stack */ -void initStack(stack* s); -int isEmpty(stack s); -void push(stack* s, couple c); -couple pop(stack* s); -void displayStack(stack s); - -/* Function used to work with couples of (node, value) */ -void displayCouple(couple c); -void coupleBuild(couple* c, int n, float d); Deleted: trunk/ftm/ftmlib/classes/treesearch.c =================================================================== --- trunk/ftm/ftmlib/classes/treesearch.c 2008-07-22 14:28:50 UTC (rev 1830) +++ trunk/ftm/ftmlib/classes/treesearch.c 2008-07-22 14:51:27 UTC (rev 1831) @@ -1,191 +0,0 @@ - -#include "tree.h" -#include <stdlib.h> -#include <math.h> - - -#define DEBUG_TREESEARCH 0 - - -static void initStack(stack* s) -{ - s->sp = -1; -} - -static int isEmpty(stack s) -{ - if(s.sp < 0) return 1; - return 0; -} - -static void push(stack* s, couple c) -{ - s->sp++; - if(s->sp >= MAX_NODES) - fts_post("Warning: Stack capacity is attented [sp = %i]\n", s->sp); - s->c[s->sp].node = c.node; - s->c[s->sp].dist = c.dist; -} - -static couple pop(stack* s) -{ - if(s->sp < 0) - fts_post("Warning: Stack is empty, popped values may be inderteminated [sp = %i]\n", - s->sp); - couple tmp = s->c[s->sp]; - s->sp--; - return tmp; -} - - -static void displayStack(stack s) -{ - int i = s.sp; - if(s.sp < 0) fts_post("Stack is empty\n"); - else - { - fts_post("TOS (size %d) --------------\n", s.sp + 1); - while(i >= 0) - { - fts_post("stack pos %d (node %d, dist %f)\n", i, s.c[i].node, s.c[i].dist); - i--; - } - } -} - -static void displayCouple(couple c) -{ - fts_post("Couple( %i, %f)\n", c.node, c.dist); -} - -static void coupleBuild(couple* c, int n, float d) -{ - c->node = n; - c->dist = d; -} - -static float max(float a, float b) -{ - return (a > b)? a : b; -} - - -static int maxArr(float* array, int size) -{ - int index = 0; - int i; - - for(i = 1; i<size; i++) - { - if(array[index] < array[i]) index = i; - } - - return index; -} - -static float euclidianDistance(float* v1, float* v2, int dim) -{ - int i; - float sum = 0; - - for (i = 0; i < dim; i++) - { - float diff = v2[i] - v1[i]; - sum += diff * diff; - } - - return sum; -} - - -/* out: y[K] = index of the Kth neirest neighbour - return: actual number of found neighbours */ -int tree_search_knn (tree_t *t, float* x, int k, int *y) -{ - float *d; // vector to vector distance from vector y[k] to vector x - int i; // current processed vector - float dxx; // dxx = distance between 2 vectors - int kmax = 0; // index of current Kth neighbour - couple cur; // current (node, dist) couple - - if (t->ndata == 0) - return 0; - - if (k < 1) - k = 1; - - // Init distances - d = alloca(k * sizeof(float)); - for(i = 0; i < k; i++) - { - d[i] = MAX_FLOAT; - } - - // Init Search Stack - coupleBuild(&cur, 0, 0); - push(&t->s, cur); - - while (!isEmpty(t->s)) - { - displayStack(t->s); - cur = pop(&t->s); - - if (cur.dist < d[kmax]) // elimination rule - { - if (cur.node >= (pow2(t->height - 1) - 1)) - { // leaf node - int istart = t->nodes[cur.node].startind; - int iend = t->nodes[cur.node].endind; - int i; -#ifdef DEBUG_TREESEARCH - fts_post("Leaf node p = %d\n", cur.node); -#endif - for (i = istart; i <= iend; i++) - { - dxx = euclidianDistance(x, tree_get_vector(t, i), t->ndim); - -#ifdef DEBUG_TREESEARCH - fts_post("distance = %f between vector %d ", dxx, i); - vec_post(tree_get_vector(t, i), t->ndim, " and x "); - vec_post(x, t->ndim, "\n"); -#endif -#if PROFILE_SEARCH - t->profile.v2v++; -#endif - if (dxx < d[kmax]) - { - y[kmax] = i; - d[kmax] = dxx; - kmax = maxArr(d, k); - } - } - } - else - { // branched node - float d = distV2N(t, x, cur.node); -#ifdef DEBUG_TREESEARCH - fts_post("Inner node %d, d = %f\n", cur.node, d); -#endif - if (d < 0) - { - couple c1; - couple c2; - coupleBuild(&c1, 2*cur.node+2, max(cur.dist, d*d)); - coupleBuild(&c2, 2*cur.node+1, cur.dist); - push(&t->s, c1); - push(&t->s, c2); - } - else - { - couple c1; - couple c2; - coupleBuild(&c1, 2*cur.node+1, max(cur.dist, d*d)); - coupleBuild(&c2, 2*cur.node+2, cur.dist); - push(&t->s, c1); - push(&t->s, c2); - } - } - } - } - return k; /* return actual number of found neighbours */ -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-22 14:28:43
|
Revision: 1830 http://ftm.svn.sourceforge.net/ftm/?rev=1830&view=rev Author: diemo Date: 2008-07-22 14:28:50 +0000 (Tue, 22 Jul 2008) Log Message: ----------- protect search algorithm from silly values conditional debug print Modified Paths: -------------- trunk/ftm/ftmlib/classes/treebuild.c trunk/ftm/ftmlib/classes/treesearch.c Modified: trunk/ftm/ftmlib/classes/treebuild.c =================================================================== --- trunk/ftm/ftmlib/classes/treebuild.c 2008-07-21 16:57:55 UTC (rev 1829) +++ trunk/ftm/ftmlib/classes/treebuild.c 2008-07-22 14:28:50 UTC (rev 1830) @@ -4,7 +4,7 @@ #include <math.h> -#define DEBUG_BUILD 0 +#define DEBUG_TREEBUILD 0 static void @@ -33,7 +33,7 @@ mean_ptr[j] = sum / nvector; } -#if DEBUG_BUILD +#if DEBUG_TREEBUILD fts_post("mean vect for node %d = ", node); vec_post(mean_ptr, t->ndim, "\n"); #endif @@ -135,7 +135,7 @@ t->nodes[node].splitnorm = 1; -#if DEBUG_BUILD +#if DEBUG_TREEBUILD fts_post("Splitplane of node %i: ", node); vec_post(t->nodes[node].split, t->ndim + 1, "\n"); #endif @@ -200,7 +200,7 @@ { int nstart = pow2(l) - 1; int nend = pow2(l+1) - 1; -#if DEBUG_BUILD +#if DEBUG_TREEBUILD fts_post("\nLevel #%i nodes %d..%d\n", l, nstart, nend); #endif for (n = nstart; n < nend; n++) @@ -208,7 +208,7 @@ compute_mean(t, n); compute_splitplane(t, n, l); -#if DEBUG_BUILD +#if DEBUG_TREEBUILD fts_post("Node #%i (%i..%i): mean = ", n, t->nodes[n].startind, t->nodes[n].endind); vec_post(fmat_get_ptr(t->nodes[n].mean), t->ndim, "\n"); Modified: trunk/ftm/ftmlib/classes/treesearch.c =================================================================== --- trunk/ftm/ftmlib/classes/treesearch.c 2008-07-21 16:57:55 UTC (rev 1829) +++ trunk/ftm/ftmlib/classes/treesearch.c 2008-07-22 14:28:50 UTC (rev 1830) @@ -3,6 +3,10 @@ #include <stdlib.h> #include <math.h> + +#define DEBUG_TREESEARCH 0 + + static void initStack(stack* s) { s->sp = -1; @@ -26,7 +30,7 @@ static couple pop(stack* s) { if(s->sp < 0) - fts_post("Warning: Stack is empty, poped values may be inderteminated [sp = %i]\n", + fts_post("Warning: Stack is empty, popped values may be inderteminated [sp = %i]\n", s->sp); couple tmp = s->c[s->sp]; s->sp--; @@ -104,6 +108,12 @@ int kmax = 0; // index of current Kth neighbour couple cur; // current (node, dist) couple + if (t->ndata == 0) + return 0; + + if (k < 1) + k = 1; + // Init distances d = alloca(k * sizeof(float)); for(i = 0; i < k; i++) @@ -127,15 +137,18 @@ int istart = t->nodes[cur.node].startind; int iend = t->nodes[cur.node].endind; int i; +#ifdef DEBUG_TREESEARCH fts_post("Leaf node p = %d\n", cur.node); - +#endif for (i = istart; i <= iend; i++) { dxx = euclidianDistance(x, tree_get_vector(t, i), t->ndim); +#ifdef DEBUG_TREESEARCH fts_post("distance = %f between vector %d ", dxx, i); vec_post(tree_get_vector(t, i), t->ndim, " and x "); vec_post(x, t->ndim, "\n"); +#endif #if PROFILE_SEARCH t->profile.v2v++; #endif @@ -150,8 +163,9 @@ else { // branched node float d = distV2N(t, x, cur.node); +#ifdef DEBUG_TREESEARCH fts_post("Inner node %d, d = %f\n", cur.node, d); - +#endif if (d < 0) { couple c1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-21 16:57:46
|
Revision: 1829 http://ftm.svn.sourceforge.net/ftm/?rev=1829&view=rev Author: diemo Date: 2008-07-21 16:57:55 +0000 (Mon, 21 Jul 2008) Log Message: ----------- finished search algorithm fixed return of nearest neighbours (via indirection) Modified Paths: -------------- trunk/ftm/ftmlib/classes/tree.c trunk/ftm/ftmlib/classes/tree.h trunk/ftm/ftmlib/classes/treebuild.c trunk/ftm/ftmlib/classes/treesearch.c Modified: trunk/ftm/ftmlib/classes/tree.c =================================================================== --- trunk/ftm/ftmlib/classes/tree.c 2008-07-21 10:11:35 UTC (rev 1828) +++ trunk/ftm/ftmlib/classes/tree.c 2008-07-21 16:57:55 UTC (rev 1829) @@ -85,9 +85,10 @@ #if PROFILE static void profile_clear (tree_t *t) { - t->profile.v2v = 0; - t->profile.v2n = 0; - t->profile.mean = 0; + t->profile.v2v = 0; + t->profile.v2n = 0; + t->profile.mean = 0; + t->profile.hyper = 0; } #endif @@ -136,7 +137,7 @@ @return number of vectors found n, n <= k list of n indices in result */ - +#if 0 static int tree_search (tree_t *tree, fmat_t *x, int k, int *result) { fts_stack_t stack; @@ -152,6 +153,7 @@ result[0] = 0; return 1; } +#endif void vec_post (float *v, int n, const char *suffix) @@ -289,7 +291,7 @@ result = alloca(sizeof(int) * k); - n = tree_search(self, x, k, result); + n = tree_search_knn(self, fmat_get_ptr(x), k, result); if (s == fts_s_get) /* geti: nearest index? */ { /* return one fvec */ @@ -309,11 +311,11 @@ for (i = 0; i < n; i++) { if (s == s_getknni) - fts_set_int(at + i, result[i]); + fts_set_int(at + i, self->dataindex[result[i]]); else /* getknn */ { fvec_t *vec = fvec_create_row(self->data); - fvec_set_index(vec, result[i]); + fvec_set_index(vec, self->dataindex[result[i]]); fts_object_refer((fts_object_t *) vec); fts_set_object(at + i, vec); @@ -374,8 +376,10 @@ "vector to vector distances:\t%d\n" "vector to node distances: \t%d\n" "mean vector calculations: \t%d\n", - t->profile.v2v, t->profile.v2n, t->profile.mean); - fts_set_int(ret, 0); + "split plane calculations: \t%d\n", + t->profile.v2v, t->profile.v2n, + t->profile.mean, t->profile.hyper); + fts_set_object(ret, t); profile_clear(t); } } @@ -423,8 +427,6 @@ profile_clear(self); #endif - fts_post("tree init is ok \n"); - if (ac > 0 && fts_is_a(at, fmat_class)) { /* set data arg and build tree */ _tree_set(o, s, ac, at, ret); Modified: trunk/ftm/ftmlib/classes/tree.h =================================================================== --- trunk/ftm/ftmlib/classes/tree.h 2008-07-21 10:11:35 UTC (rev 1828) +++ trunk/ftm/ftmlib/classes/tree.h 2008-07-21 16:57:55 UTC (rev 1829) @@ -81,6 +81,7 @@ int v2v; int v2n; int mean; + int hyper; } profile; } tree_t; @@ -106,5 +107,7 @@ void tree_build (tree_t* t); void tree_init (tree_t* t, int h, int vect_num, int dim); +int tree_search_knn (tree_t *t, float* x, int k, int *y); + #endif Modified: trunk/ftm/ftmlib/classes/treebuild.c =================================================================== --- trunk/ftm/ftmlib/classes/treebuild.c 2008-07-21 10:11:35 UTC (rev 1828) +++ trunk/ftm/ftmlib/classes/treebuild.c 2008-07-21 16:57:55 UTC (rev 1829) @@ -4,6 +4,9 @@ #include <math.h> +#define DEBUG_BUILD 0 + + static void compute_mean (tree_t *t, int node) { @@ -29,8 +32,11 @@ } mean_ptr[j] = sum / nvector; } + +#if DEBUG_BUILD fts_post("mean vect for node %d = ", node); vec_post(mean_ptr, t->ndim, "\n"); +#endif } @@ -53,7 +59,7 @@ /* vector to orthogonal plane node distance */ -static float distV2orthoH (float* vect, float* hplane, int vectDim, float norm) +static float distV2orthoH (const float* vect, float* hplane, int vectDim, float norm) { // standard algebra computing int i; @@ -68,7 +74,7 @@ /* vector to general plane node distance */ -static float distV2H (float* vect, float* plane, float* mean, int vectDim, float norm) +static float distV2H (const float* vect, float* plane, float* mean, int vectDim, float norm) { // standard algebra computing int i; @@ -112,7 +118,11 @@ int b; float h; - /* case dmode_orthogonal */ + #if PROFILE_BUILD + t->profile.hyper++; +#endif + + /* case dmode_orthogonal */ // Level parameter gives the base vector to use b = level % t->ndim; h = fmat_get_element(t->nodes[node].mean, b, 0); @@ -125,8 +135,10 @@ t->nodes[node].splitnorm = 1; +#if DEBUG_BUILD fts_post("Splitplane of node %i: ", node); vec_post(t->nodes[node].split, t->ndim + 1, "\n"); +#endif } @@ -188,16 +200,19 @@ { int nstart = pow2(l) - 1; int nend = pow2(l+1) - 1; +#if DEBUG_BUILD fts_post("\nLevel #%i nodes %d..%d\n", l, nstart, nend); - +#endif for (n = nstart; n < nend; n++) { /* for all nodes at tree level l */ compute_mean(t, n); compute_splitplane(t, n, l); + +#if DEBUG_BUILD fts_post("Node #%i (%i..%i): mean = ", n, t->nodes[n].startind, t->nodes[n].endind); vec_post(fmat_get_ptr(t->nodes[n].mean), t->ndim, "\n"); - +#endif i = t->nodes[n].startind; j = t->nodes[n].endind; Modified: trunk/ftm/ftmlib/classes/treesearch.c =================================================================== --- trunk/ftm/ftmlib/classes/treesearch.c 2008-07-21 10:11:35 UTC (rev 1828) +++ trunk/ftm/ftmlib/classes/treesearch.c 2008-07-21 16:57:55 UTC (rev 1829) @@ -18,7 +18,7 @@ { s->sp++; if(s->sp >= MAX_NODES) - printf("Warning: Stack capacity is attented [sp = %i]\n", s->sp); + fts_post("Warning: Stack capacity is attented [sp = %i]\n", s->sp); s->c[s->sp].node = c.node; s->c[s->sp].dist = c.dist; } @@ -26,7 +26,7 @@ static couple pop(stack* s) { if(s->sp < 0) -printf("Warning: Stack is empty, poped values may be inderteminated [sp = %i]\n", + fts_post("Warning: Stack is empty, poped values may be inderteminated [sp = %i]\n", s->sp); couple tmp = s->c[s->sp]; s->sp--; @@ -37,22 +37,21 @@ static void displayStack(stack s) { int i = s.sp; - if(s.sp < 0) printf("Stack is empty\n"); + if(s.sp < 0) fts_post("Stack is empty\n"); else { - printf("Top of stack\n"); + fts_post("TOS (size %d) --------------\n", s.sp + 1); while(i >= 0) { - printf("( %i, %f)\n", s.c[i].node, s.c[i].dist); + fts_post("stack pos %d (node %d, dist %f)\n", i, s.c[i].node, s.c[i].dist); i--; } - printf("Bottom of stack\n\n"); } } static void displayCouple(couple c) { - printf("Couple( %i, %f)\n", c.node, c.dist); + fts_post("Couple( %i, %f)\n", c.node, c.dist); } static void coupleBuild(couple* c, int n, float d) @@ -83,28 +82,30 @@ static float euclidianDistance(float* v1, float* v2, int dim) { int i; - float tmp = 0; - for(i = 0; i < dim; i++) + float sum = 0; + + for (i = 0; i < dim; i++) { - tmp = tmp + ((v1[i] - v2[i])*(v1[i] - v2[i])); + float diff = v2[i] - v1[i]; + sum += diff * diff; } - return tmp; + + return sum; } /* out: y[K] = index of the Kth neirest neighbour return: actual number of found neighbours */ -int tree_search (tree_t *t, int k, float* x, int *y) +int tree_search_knn (tree_t *t, float* x, int k, int *y) { - float d[k]; // vector to vector distance from vector y[k] to vector x + float *d; // vector to vector distance from vector y[k] to vector x int i; // current processed vector float dxx; // dxx = distance between 2 vectors int kmax = 0; // index of current Kth neighbour couple cur; // current (node, dist) couple - y = (int*)malloc(k*sizeof(int)); - // Init distances + d = alloca(k * sizeof(float)); for(i = 0; i < k; i++) { d[i] = MAX_FLOAT; @@ -114,37 +115,44 @@ coupleBuild(&cur, 0, 0); push(&t->s, cur); - while(!isEmpty(t->s)) + while (!isEmpty(t->s)) { displayStack(t->s); cur = pop(&t->s); - displayStack(t->s); - if(cur.dist < d[kmax]) - { // elimination rule - if(cur.node >= (pow2(t->height - 1) - 1)) - + + if (cur.dist < d[kmax]) // elimination rule + { + if (cur.node >= (pow2(t->height - 1) - 1)) { // leaf node - fts_post("Je suis une feuille: p = %i\n", cur.node); - i = t->nodes[cur.node].startind; - while(i <= t->nodes[cur.node].endind) + int istart = t->nodes[cur.node].startind; + int iend = t->nodes[cur.node].endind; + int i; + fts_post("Leaf node p = %d\n", cur.node); + + for (i = istart; i <= iend; i++) { dxx = euclidianDistance(x, tree_get_vector(t, i), t->ndim); - printf("la distance entre le vecteur %i et x est de: %f\n", i, dxx); - if(dxx < d[kmax]) + + fts_post("distance = %f between vector %d ", dxx, i); + vec_post(tree_get_vector(t, i), t->ndim, " and x "); + vec_post(x, t->ndim, "\n"); +#if PROFILE_SEARCH + t->profile.v2v++; +#endif + if (dxx < d[kmax]) { y[kmax] = i; d[kmax] = dxx; kmax = maxArr(d, k); } - i++; } } else { // branched node - float d; - fts_post("Je suis un noeud: p = %i\n", cur.node); - d = distV2N(t, x, cur.node); - if(d < 0) + float d = distV2N(t, x, cur.node); + fts_post("Inner node %d, d = %f\n", cur.node, d); + + if (d < 0) { couple c1; couple c2; @@ -155,7 +163,6 @@ } else { - fts_post("Je suis un noeud: p = %i\n", cur.node); couple c1; couple c2; coupleBuild(&c1, 2*cur.node+1, max(cur.dist, d*d)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-21 10:12:17
|
Revision: 1828 http://ftm.svn.sourceforge.net/ftm/?rev=1828&view=rev Author: diemo Date: 2008-07-21 10:11:35 +0000 (Mon, 21 Jul 2008) Log Message: ----------- fix print Modified Paths: -------------- trunk/ftm/ftmlib/classes/tree.c trunk/ftm/ftmlib/classes/tree.h trunk/ftm/ftmlib/classes/treebuild.c Modified: trunk/ftm/ftmlib/classes/tree.c =================================================================== --- trunk/ftm/ftmlib/classes/tree.c 2008-07-18 17:51:18 UTC (rev 1827) +++ trunk/ftm/ftmlib/classes/tree.c 2008-07-21 10:11:35 UTC (rev 1828) @@ -154,13 +154,13 @@ } -void vec_print (float *v, int n, const char *suffix) +void vec_post (float *v, int n, const char *suffix) { int i; for (i = 0; i < n; i++) { - fts_post("%s%.1f", (i == 0 ? "[" : ", "), v + i); + fts_post("%s%.1f", (i == 0 ? "[" : ", "), v[i]); } fts_post("]%s", suffix); } @@ -168,7 +168,7 @@ static void tree_info_display (tree_t* t) { int i, j; - fts_post("Tree Info:\n"); + fts_post("\nTree Info:\n"); fts_post("ndim = %i\n", t->ndim); fts_post("ndata = %i\n", t->ndata); fts_post("height = %i\n", t->height); @@ -179,21 +179,21 @@ for (i = 0; i < t->ndata; i++) { fts_post("raw data vec %-3i = ", i); - vec_print(fmat_get_row_ptr(t->data, i), t->ndim, "\n"); + vec_post(fmat_get_row_ptr(t->data, i), t->ndim, "\n"); } } -static void tree_display(tree_t* t) +static void tree_data_display(tree_t* t) { int l, n, i, j; - fts_post("Tree Display:\n"); + fts_post("\nTree Data:\n"); if (t->height == 0 || t->ndata == 0) fts_post("Empty Tree\n"); for (l = 0; l < t->height; l++) { - fts_post("Level #%i\n", l); + fts_post("Level #%i nodes %d..%d\n", l, pow2(l) - 1, pow2(l+1) - 1); for (n = pow2(l) - 1; n < pow2(l+1) - 1; n++) { fts_post(" node %d size %d <%d..%d> = (", @@ -202,7 +202,7 @@ for (i = t->nodes[n].startind; i <= t->nodes[n].endind; i++) { fts_post("vec %d = ", t->dataindex[i]); - vec_print(tree_get_vector(t, i), t->ndim, + vec_post(tree_get_vector(t, i), t->ndim, i < t->nodes[n].endind ? ", " : ""); } fts_post(")\n"); @@ -244,7 +244,7 @@ fts_object_refer((fts_object_t *) self->data); tree_init(self, floor(log2(fmat_get_m(data))), - fmat_get_m(data), fmat_get_n(data)); + fmat_get_m(data), fmat_get_n(data)); /* tree_clear and rebuild: */ /* tree_clear(self);*/ @@ -391,7 +391,7 @@ tree_t *self = (tree_t *) o; tree_info_display(self); - tree_display(self); + tree_data_display(self); return fts_ok; } @@ -426,15 +426,10 @@ fts_post("tree init is ok \n"); if (ac > 0 && fts_is_a(at, fmat_class)) - { + { /* set data arg and build tree */ _tree_set(o, s, ac, at, ret); } - /* build tree */ - tree_build(self); - tree_info_display(self); - tree_display(self); - return fts_ok; } Modified: trunk/ftm/ftmlib/classes/tree.h =================================================================== --- trunk/ftm/ftmlib/classes/tree.h 2008-07-18 17:51:18 UTC (rev 1827) +++ trunk/ftm/ftmlib/classes/tree.h 2008-07-21 10:11:35 UTC (rev 1828) @@ -98,7 +98,7 @@ int pow2(int x); -void vec_print (float *v, int n, const char *suffix); +void vec_post (float *v, int n, const char *suffix); /* vector to node distance */ float distV2N (tree_t* t, const float *x, const int node); Modified: trunk/ftm/ftmlib/classes/treebuild.c =================================================================== --- trunk/ftm/ftmlib/classes/treebuild.c 2008-07-18 17:51:18 UTC (rev 1827) +++ trunk/ftm/ftmlib/classes/treebuild.c 2008-07-21 10:11:35 UTC (rev 1828) @@ -30,7 +30,7 @@ mean_ptr[j] = sum / nvector; } fts_post("mean vect for node %d = ", node); - vec_print(mean_ptr, t->ndim, "\n"); + vec_post(mean_ptr, t->ndim, "\n"); } @@ -126,7 +126,7 @@ t->nodes[node].splitnorm = 1; fts_post("Splitplane of node %i: ", node); - vec_print(t->nodes[node].split, t->ndim + 1, "\n"); + vec_post(t->nodes[node].split, t->ndim + 1, "\n"); } @@ -186,38 +186,37 @@ for (l = 0; l < t->height; l++) { - fts_post("\nLevel#%i\n", l); - - for (n = pow2(l) - 1; n < pow2(l+1) - 1; n++) - { + int nstart = pow2(l) - 1; + int nend = pow2(l+1) - 1; + fts_post("\nLevel #%i nodes %d..%d\n", l, nstart, nend); + + for (n = nstart; n < nend; n++) + { /* for all nodes at tree level l */ compute_mean(t, n); compute_splitplane(t, n, l); - fts_post("Node #%i (%i..%i): mean = (%f, %f)\n", - n, t->nodes[n].startind, t->nodes[n].endind, - t->nodes[n].mean[0], t->nodes[n].mean[1]); - + fts_post("Node #%i (%i..%i): mean = ", + n, t->nodes[n].startind, t->nodes[n].endind); + vec_post(fmat_get_ptr(t->nodes[n].mean), t->ndim, "\n"); + i = t->nodes[n].startind; j = t->nodes[n].endind; while (j > i) - { + { /* sort node vectors by distance to splitplane */ while (distV2N(t, tree_get_vector(t, i), n) <= 0) { - i++; - // fts_post("i=%i\n", i); + i++; // fts_post("i=%i\n", i); } while (distV2N(t, tree_get_vector(t, j), n) > 0) { - j--; - // fts_post("j=%i\n", j); + j--; // fts_post("j=%i\n", j); } if (j > i) { - swap(t, i, j); - // fts_post("swap %i and %i\n", i ,j); + swap(t, i, j); // fts_post("swap %i and %i\n", i ,j); } } - + t->nodes[2*n+1].startind = t->nodes[n].startind; // start index of left child of node n t->nodes[2*n+1].endind = j; // end index of left child of node n t->nodes[2*n+2].startind = i; // start index of right child of node n @@ -249,10 +248,12 @@ fts_object_refer((fts_object_t *) t->nodes[i].split); } - /* init root node */ - t->nodes[0].startind = 0; - t->nodes[0].endind = t->ndata - 1; - + if (t->nnodes > 0) + { /* init root node */ + t->nodes[0].startind = 0; + t->nodes[0].endind = t->ndata - 1; + } + /* init index list */ t->dataindex = fts_realloc(t->dataindex, t->ndata * sizeof(int)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-18 17:51:10
|
Revision: 1827 http://ftm.svn.sourceforge.net/ftm/?rev=1827&view=rev Author: diemo Date: 2008-07-18 17:51:18 +0000 (Fri, 18 Jul 2008) Log Message: ----------- fix warnings Modified Paths: -------------- trunk/ftm/ftmlib/classes/tree.c trunk/ftm/ftmlib/classes/tree.h trunk/ftm/ftmlib/classes/treebuild.c trunk/ftm/ftmlib/classes/treesearch.c Modified: trunk/ftm/ftmlib/classes/tree.c =================================================================== --- trunk/ftm/ftmlib/classes/tree.c 2008-07-18 16:13:40 UTC (rev 1826) +++ trunk/ftm/ftmlib/classes/tree.c 2008-07-18 17:51:18 UTC (rev 1827) @@ -154,7 +154,16 @@ } +void vec_print (float *v, int n, const char *suffix) +{ + int i; + for (i = 0; i < n; i++) + { + fts_post("%s%.1f", (i == 0 ? "[" : ", "), v + i); + } + fts_post("]%s", suffix); +} static void tree_info_display (tree_t* t) { @@ -169,12 +178,8 @@ for (i = 0; i < t->ndata; i++) { - fts_post("raw data vec %-3i = [", i); - for (j = 0; j < t->ndim; j++) - { - fts_post("%.1f, ", fmat_get_element(t->data, i, j)); - } - fts_post("]\n"); + fts_post("raw data vec %-3i = ", i); + vec_print(fmat_get_row_ptr(t->data, i), t->ndim, "\n"); } } @@ -188,23 +193,20 @@ for (l = 0; l < t->height; l++) { - fts_post("Level #%i ", l); + fts_post("Level #%i\n", l); for (n = pow2(l) - 1; n < pow2(l+1) - 1; n++) { - fts_post("node %d<%d..%d> = (", - n, t->nodes[n].startind, t->nodes[n].endind); + fts_post(" node %d size %d <%d..%d> = (", + n, t->nodes[n].endind - t->nodes[n].startind + 1, + t->nodes[n].startind, t->nodes[n].endind); for (i = t->nodes[n].startind; i <= t->nodes[n].endind; i++) { - fts_post("vec %d = [", t->dataindex[i]); - for (j = 0; j < t->ndim; j++) - { - fts_post("%.1f, ", tree_get_element(t, i, j)); - } - fts_post("], "); + fts_post("vec %d = ", t->dataindex[i]); + vec_print(tree_get_vector(t, i), t->ndim, + i < t->nodes[n].endind ? ", " : ""); } - fts_post(") "); + fts_post(")\n"); } - fts_post("\n"); } } @@ -279,7 +281,7 @@ int k = 1, n; int *result; - if (ac && fts_is_a(at, fmat_class)) + if (ac > 0 && fts_is_a(at, fmat_class)) x = (fmat_t *) fts_get_object(at); if (ac > 1 && fts_is_number(at+1)) @@ -312,7 +314,9 @@ { fvec_t *vec = fvec_create_row(self->data); fvec_set_index(vec, result[i]); - fts_set_object(ret, vec); + + fts_object_refer((fts_object_t *) vec); + fts_set_object(at + i, vec); } } @@ -408,11 +412,12 @@ /* Init */ self->ndata = 0; self->height = 0; - self->nnodes = (int)pow(2, self->height) - 1; + self->nnodes = 0; self->ndim = 0; - self->data = NULL; self->dataindex = NULL; self->nodes = NULL; + self->data = fmat_create(0, 0); /* always an fmat here */ + fts_object_refer((fts_object_t *) self->data); #if PROFILE_BUILD profile_clear(self); @@ -449,7 +454,7 @@ } /* free data */ - if (self->data) fts_object_release(self->data); /* free stored vectors */ + fts_object_release(self->data); /* release stored vectors */ /* free structure */ if (self->dataindex) fts_free(self->dataindex); Modified: trunk/ftm/ftmlib/classes/tree.h =================================================================== --- trunk/ftm/ftmlib/classes/tree.h 2008-07-18 16:13:40 UTC (rev 1826) +++ trunk/ftm/ftmlib/classes/tree.h 2008-07-18 17:51:18 UTC (rev 1827) @@ -90,12 +90,15 @@ /* get data element via indirection order array */ #define tree_get_element(t, i, j) fmat_get_element(t->data, t->dataindex[i], j) -#define tree_get_vector(t, i) (fmat_get_ptr(t->data) + (i) * t->ndim) -#define fmat_get_row_ptr(f, i) (f->ptr + (i) * f->n) +/* get data vector via indirection order array */ +#define tree_get_vector(t, i) (fmat_get_ptr(t->data) + t->dataindex[i] * t->ndim) +#define fmat_get_row_ptr(f, i) (fmat_get_ptr(f) + (i) * fmat_get_n(f)) + int pow2(int x); +void vec_print (float *v, int n, const char *suffix); /* vector to node distance */ float distV2N (tree_t* t, const float *x, const int node); Modified: trunk/ftm/ftmlib/classes/treebuild.c =================================================================== --- trunk/ftm/ftmlib/classes/treebuild.c 2008-07-18 16:13:40 UTC (rev 1826) +++ trunk/ftm/ftmlib/classes/treebuild.c 2008-07-18 17:51:18 UTC (rev 1827) @@ -29,7 +29,8 @@ } mean_ptr[j] = sum / nvector; } - //fts_post("mean vect computed \n"); + fts_post("mean vect for node %d = ", node); + vec_print(mean_ptr, t->ndim, "\n"); } @@ -124,8 +125,8 @@ t->nodes[node].splitnorm = 1; -// fts_post("Splitplane of node %i: (%f, %f, %f)\n", node, t->split[node][0], -// t->split[node][1], t->split[node][2]); + fts_post("Splitplane of node %i: ", node); + vec_print(t->nodes[node].split, t->ndim + 1, "\n"); } @@ -185,14 +186,15 @@ for (l = 0; l < t->height; l++) { - fts_post("\n\nLevel#%i\n", l); + fts_post("\nLevel#%i\n", l); for (n = pow2(l) - 1; n < pow2(l+1) - 1; n++) { compute_mean(t, n); compute_splitplane(t, n, l); - /*fts_post("\nNode #%i (%i->%i): mean = (%f,%f)\n", n, t->nodes[n].startind, - t->nodes[n].endind, t->mean[n][0], t->mean[n][1]);*/ + fts_post("Node #%i (%i..%i): mean = (%f, %f)\n", + n, t->nodes[n].startind, t->nodes[n].endind, + t->nodes[n].mean[0], t->nodes[n].mean[1]); i = t->nodes[n].startind; j = t->nodes[n].endind; Modified: trunk/ftm/ftmlib/classes/treesearch.c =================================================================== --- trunk/ftm/ftmlib/classes/treesearch.c 2008-07-18 16:13:40 UTC (rev 1826) +++ trunk/ftm/ftmlib/classes/treesearch.c 2008-07-18 17:51:18 UTC (rev 1827) @@ -34,7 +34,7 @@ } -void displayStack(stack s) +static void displayStack(stack s) { int i = s.sp; if(s.sp < 0) printf("Stack is empty\n"); @@ -50,24 +50,24 @@ } } -void displayCouple(couple c) +static void displayCouple(couple c) { printf("Couple( %i, %f)\n", c.node, c.dist); } -void coupleBuild(couple* c, int n, float d) +static void coupleBuild(couple* c, int n, float d) { c->node = n; c->dist = d; } -float max(float a, float b) +static float max(float a, float b) { return (a > b)? a : b; } -int maxArr(float* array, int size) +static int maxArr(float* array, int size) { int index = 0; int i; @@ -80,7 +80,7 @@ return index; } -float euclidianDistance(float* v1, float* v2, int dim) +static float euclidianDistance(float* v1, float* v2, int dim) { int i; float tmp = 0; @@ -124,12 +124,12 @@ if(cur.node >= (pow2(t->height - 1) - 1)) { // leaf node - // printf("Je suis une feuille: p = %i\n", cur.node); + fts_post("Je suis une feuille: p = %i\n", cur.node); i = t->nodes[cur.node].startind; while(i <= t->nodes[cur.node].endind) { dxx = euclidianDistance(x, tree_get_vector(t, i), t->ndim); - /*printf("la distance entre le vecteur %i et x est de: %f\n", i, dxx); */ + printf("la distance entre le vecteur %i et x est de: %f\n", i, dxx); if(dxx < d[kmax]) { y[kmax] = i; @@ -142,7 +142,7 @@ else { // branched node float d; - // printf("Je suis un noeud: p = %i\n", cur.node); + fts_post("Je suis un noeud: p = %i\n", cur.node); d = distV2N(t, x, cur.node); if(d < 0) { @@ -155,7 +155,7 @@ } else { - // printf("Je suis un noeud: p = %i\n", cur.node); + fts_post("Je suis un noeud: p = %i\n", cur.node); couple c1; couple c2; coupleBuild(&c1, 2*cur.node+1, max(cur.dist, d*d)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-18 16:13:32
|
Revision: 1826 http://ftm.svn.sourceforge.net/ftm/?rev=1826&view=rev Author: diemo Date: 2008-07-18 16:13:40 +0000 (Fri, 18 Jul 2008) Log Message: ----------- include search algorithm profiling, displaying Modified Paths: -------------- trunk/ftm/ftmlib/classes/tree.c trunk/ftm/ftmlib/classes/tree.h trunk/ftm/ftmlib/classes/treebuild.c trunk/ftm/ftmlib/classes/treesearch.c Modified: trunk/ftm/ftmlib/classes/tree.c =================================================================== --- trunk/ftm/ftmlib/classes/tree.c 2008-07-18 15:51:37 UTC (rev 1825) +++ trunk/ftm/ftmlib/classes/tree.c 2008-07-18 16:13:40 UTC (rev 1826) @@ -35,7 +35,13 @@ fts_symbol_t tree_symbol = 0; fts_class_t *tree_class = 0; +fts_symbol_t s_mean; +fts_symbol_t s_hyper; +fts_symbol_t s_vec; +fts_symbol_t s_profile; +fts_symbol_t s_getknni; + /* for the search algorithm */ typedef struct stack_elem { @@ -70,6 +76,21 @@ } +int pow2 (int x) +{ + return 1 << x; +} + + +#if PROFILE +static void profile_clear (tree_t *t) +{ + t->profile.v2v = 0; + t->profile.v2n = 0; + t->profile.mean = 0; +} +#endif + static double vec_dist (fmat_t *a, fmat_t *b) { @@ -89,7 +110,7 @@ static float -distV2H(fmat_t* vect, fmat_t* hplane) +distfmatV2H(fmat_t* vect, fmat_t* hplane) { //standard algebra computing int i; @@ -134,69 +155,60 @@ -/* For debuging */ -static void -tree_info_display(tree_t* t) -{ - fts_post("\nTree Info:\n"); - fts_post("**********\n\n"); - fts_post("ndim = %i\n", t->ndim); - fts_post("ndata = %i\n", t->ndata); - fts_post("height = %i\n", t->height); - fts_post("nnodes = %i\n", t->nnodes); -} -static void -tree_display(tree_t* t) +static void tree_info_display (tree_t* t) { - int l, n, i, j; - float* data_ptr; - - fts_post("\nTree Display:\n"); - fts_post("*************\n\n"); - - if(t->height == 0 || t->ndata == 0) fts_post("Empty Tree\n"); - for(l = 0; l < t->height; l++) { - fts_post("Level #%i ", l); - for(n = (int)pow(2, l) - 1; n < (int)pow(2, l+1) - 1; n++) { - fts_post("("); - for(i = t->nodes[n].startind; i <= t->nodes[n].endind; i++) { - fts_post("["); - data_ptr = fmat_get_ptr(t->data); + int i, j; + fts_post("Tree Info:\n"); + fts_post("ndim = %i\n", t->ndim); + fts_post("ndata = %i\n", t->ndata); + fts_post("height = %i\n", t->height); + fts_post("nnodes = %i\n", t->nnodes); - if(data_ptr[0] == MAX_FLOAT) fts_post("zombi]"); - else { - for(j = 0; j < (t->ndim - 1); j++) { - fts_post("%.1f, ", data_ptr[j]); - } - fts_post("%.1f]", data_ptr[t->ndim - 1]); - } - } - fts_post(")"); - } - fts_post("\n"); + if (t->height == 0 || t->ndata == 0) fts_post("Empty Tree\n"); + + for (i = 0; i < t->ndata; i++) + { + fts_post("raw data vec %-3i = [", i); + for (j = 0; j < t->ndim; j++) + { + fts_post("%.1f, ", fmat_get_element(t->data, i, j)); } + fts_post("]\n"); + } } -static void -data_display(tree_t *t, int v) + +static void tree_display(tree_t* t) { - int j; - float* data_ptr; + int l, n, i, j; + + fts_post("Tree Display:\n"); + if (t->height == 0 || t->ndata == 0) fts_post("Empty Tree\n"); - fts_post("vector #%i[", v); - data_ptr = fmat_get_ptr(t->data) + v * t->ndim; - if(data_ptr[0] == MAX_FLOAT) fts_post("zombi]"); - else + for (l = 0; l < t->height; l++) + { + fts_post("Level #%i ", l); + for (n = pow2(l) - 1; n < pow2(l+1) - 1; n++) { - for(j = 0; j < (t->ndim - 1); j++) + fts_post("node %d<%d..%d> = (", + n, t->nodes[n].startind, t->nodes[n].endind); + for (i = t->nodes[n].startind; i <= t->nodes[n].endind; i++) + { + fts_post("vec %d = [", t->dataindex[i]); + for (j = 0; j < t->ndim; j++) { - fts_post("%.1f, ", data_ptr[j]); + fts_post("%.1f, ", tree_get_element(t, i, j)); } - fts_post("%.1f]\n", data_ptr[t->ndim - 1]); + fts_post("], "); + } + fts_post(") "); } + fts_post("\n"); + } } + static void tree_getelem_function(fts_object_t *o, int ac, const fts_atom_t *at, fts_atom_t *ret) { @@ -229,7 +241,7 @@ self->data = data; fts_object_refer((fts_object_t *) self->data); - tree_init(self, floor(log(fmat_get_m(data))), + tree_init(self, floor(log2(fmat_get_m(data))), fmat_get_m(data), fmat_get_n(data)); /* tree_clear and rebuild: */ @@ -258,9 +270,10 @@ -static fts_method_status_t _tree_getknn (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) +static fts_method_status_t _tree_getknn (fts_object_t *o, fts_symbol_t s, + int ac, const fts_atom_t *at, + fts_atom_t *ret) { -#if 0 tree_t *self = (tree_t *) o; fmat_t *x = NULL; /* search vector */ int k = 1, n; @@ -276,13 +289,14 @@ n = tree_search(self, x, k, result); - if (s == fts_s_get) - { /* return one fmat */ - fts_set_object(ret, self->data[result[0]]); - fts_object_refer(self->data[result[0]]); + if (s == fts_s_get) /* geti: nearest index? */ + { /* return one fvec */ + fvec_t *vec = fvec_create_row(self->data); + fvec_set_index(vec, result[0]); + fts_set_object(ret, vec); } else - { /* return n-tuple */ + { /* return n-tuple of fvec or index */ fts_tuple_t *tup = (fts_tuple_t *) fts_object_create(fts_tuple_class, 0, NULL); fts_atom_t *at; int i; @@ -292,18 +306,80 @@ for (i = 0; i < n; i++) { - fts_set_object(at + i, self->data[result[i]]); - fts_object_refer(self->data[result[i]]); + if (s == s_getknni) + fts_set_int(at + i, result[i]); + else /* getknn */ + { + fvec_t *vec = fvec_create_row(self->data); + fvec_set_index(vec, result[i]); + fts_set_object(ret, vec); + } } fts_set_object(ret, tup); - fts_object_refer(tup); } -#endif + return fts_ok; } +static fts_method_status_t _tree_get_node (fts_object_t *o, fts_symbol_t s, + int ac, const fts_atom_t *at, + fts_atom_t *ret) +{ + tree_t *t = (tree_t *) o; + int n = 0; /* node to inspect */ + + if (ac > 1 && fts_is_number(at + 1)) + { + n = fts_get_number_int(at + 1); + if (n >= t->nnodes) + n = t->nnodes - 1; + } + + if (t->nnodes > 0 && ac > 0 && fts_is_symbol(at)) + { + fts_symbol_t func = fts_get_symbol(at); + node_t *node = &t->nodes[n]; + + if (func == fts_s_num) + fts_set_int(ret, t->nnodes); + else if (func == s_mean) + fts_set_object(ret, node->mean); + else if (func == s_hyper) + fts_set_object(ret, node->split); + else if (func == fts_s_size) + fts_set_int(ret, node->endind - node->startind + 1); + else if (ac > 2 && fts_is_number(at + 2)) + { + int i = fts_get_number_int(at + 2); /* node-data vector to inspect */ + + if (func == s_vec) + { + fvec_t *vec = fvec_create_row(t->data); + + fvec_set_index(vec, t->dataindex[node->startind + i]); + fts_set_object(ret, vec); + } + else if (func == fts_s_index) + fts_set_int(ret, t->dataindex[node->startind + i]); + } + else if (func == s_profile) + { + fts_post("build profile:\n" + "vector to vector distances:\t%d\n" + "vector to node distances: \t%d\n" + "mean vector calculations: \t%d\n", + t->profile.v2v, t->profile.v2n, t->profile.mean); + fts_set_int(ret, 0); + profile_clear(t); + } + } + + return fts_ok; +} + + static fts_method_status_t _tree_print (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) @@ -328,8 +404,7 @@ _tree_init(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { tree_t *self = (tree_t *) o; - int i; - + /* Init */ self->ndata = 0; self->height = 0; @@ -339,6 +414,10 @@ self->dataindex = NULL; self->nodes = NULL; +#if PROFILE_BUILD + profile_clear(self); +#endif + fts_post("tree init is ok \n"); if (ac > 0 && fts_is_a(at, fmat_class)) @@ -370,16 +449,16 @@ } /* free data */ - fts_object_release(self->data); /* free stored vectors */ + if (self->data) fts_object_release(self->data); /* free stored vectors */ /* free structure */ - fts_free(self->data); - fts_free(self->dataindex); - fts_free(self->nodes); + if (self->dataindex) fts_free(self->dataindex); + if (self->nodes) fts_free(self->nodes); return fts_ok; } + static void _tree_instantiate(fts_class_t *cl) { @@ -403,13 +482,16 @@ fts_class_message(cl, fts_s_set, fmat_class, _tree_set, "<fmat: data> - set data matrix(ndata, ndim)"); /* no: fts_class_message(cl, fts_new_symbol("add"), fmat_class, _tree_add, "<fmat: vector> - add one vector"); */ - /*fts_class_message_varargs(cl, fts_s_get, _tree_getknn);*/ - fts_class_message_varargs(cl, fts_new_symbol("getknn"), _tree_getknn, "<fmat: x> [<int: k>] - get k nearest neighbours (default=1) to vector x"); -// fts_class_message_varargs(cl, fts_new_symbol("getknni"), _tree_getknni, "<fmat: x> [<int: k>] - get row indices in data matrix of k nearest neighbours (default=1) to vector x"); + fts_class_message_varargs(cl, fts_s_get, _tree_getknn, + "<fmat: x> - get frow vector of data matrix nearest to vector x"); + fts_class_message_varargs(cl, fts_new_symbol("getknn"), _tree_getknn, + "<fmat: x> [<int: k>] - get k nearest neighbour vectors to vector x (default k=1)"); + fts_class_message_varargs(cl, s_getknni, _tree_getknn, + "<fmat: x> [<int: k>] - get row indices in data matrix of k nearest neighbours to vector x (default k=1) "); /* inspection */ -// fts_class_message_varargs(cl, fts_new_symbol("node"), _tree_get_node, -// "<num|mean|hyper|size|start|end> <int: index> - get information about a node"); + fts_class_message_varargs(cl, fts_new_symbol("node"), _tree_get_node, + "<num|mean|hyper|size|start|end|profile> <int: index> - get information about a node"); } @@ -417,6 +499,11 @@ FTS_MODULE_INIT(tree) { tree_symbol = fts_new_symbol("tree"); - + s_mean = fts_new_symbol("mean"); + s_hyper = fts_new_symbol("hyper"); + s_vec = fts_new_symbol("vec"); + s_profile = fts_new_symbol("profile"); + s_getknni = fts_new_symbol("getknni"); + tree_class = fts_class_install(tree_symbol, _tree_instantiate); } Modified: trunk/ftm/ftmlib/classes/tree.h =================================================================== --- trunk/ftm/ftmlib/classes/tree.h 2008-07-18 15:51:37 UTC (rev 1825) +++ trunk/ftm/ftmlib/classes/tree.h 2008-07-18 16:13:40 UTC (rev 1826) @@ -26,8 +26,28 @@ #include "fts.h" +#define PROFILE_BUILD 1 +#define PROFILE_SEARCH 1 +#define PROFILE (PROFILE_BUILD || PROFILE_SEARCH) + #define MAX_FLOAT 0x7FFFFFFF +#define MAX_NODES 100 + +/* stack elements for search algorithm */ +typedef struct coupleNodeDist +{ + int node; + float dist; +} couple; + +typedef struct searchStack +{ + couple c[MAX_NODES]; + int sp; +} stack; + + typedef struct node { int startind; /* index of first vector in node in dataindex array */ @@ -54,32 +74,34 @@ fmat_t *data; /* data matrix (ndata, ndim) */ int *dataindex; /* data vector indirection array (ndata) */ node_t *nodes; /* nodes (nnodes) */ -} tree_t; + stack s; -/* stack elements for search algorithm */ -typedef struct coupleNodeDist -{ - int node; - float dist; -} couple; + struct { + int v2v; + int v2n; + int mean; + } profile; +} tree_t; -typedef struct searchStack -{ - couple c[100]; - int sp; -} stack; - - FTS_API fts_symbol_t tree_symbol; FTS_API fts_class_t *tree_class; /* get data element via indirection order array */ -#define tree_get_element(tree, i, j) fmat_get_element(tree->data, tree->dataindex[i], j) +#define tree_get_element(t, i, j) fmat_get_element(t->data, t->dataindex[i], j) +#define tree_get_vector(t, i) (fmat_get_ptr(t->data) + (i) * t->ndim) +#define fmat_get_row_ptr(f, i) (f->ptr + (i) * f->n) + + +int pow2(int x); + +/* vector to node distance */ +float distV2N (tree_t* t, const float *x, const int node); + void tree_build (tree_t* t); -void tree_init (tree_t* t, int h, int dim, int vect_num); +void tree_init (tree_t* t, int h, int vect_num, int dim); #endif Modified: trunk/ftm/ftmlib/classes/treebuild.c =================================================================== --- trunk/ftm/ftmlib/classes/treebuild.c 2008-07-18 15:51:37 UTC (rev 1825) +++ trunk/ftm/ftmlib/classes/treebuild.c 2008-07-18 16:13:40 UTC (rev 1826) @@ -4,12 +4,6 @@ #include <math.h> -static int pow2(int x) -{ - return 1 << x; -} - - static void compute_mean (tree_t *t, int node) { @@ -19,6 +13,10 @@ int nvector; int i, j; +#if PROFILE_BUILD + t->profile.mean++; +#endif + // number of vectors from the processed node nvector = t->nodes[node].endind - t->nodes[node].startind + 1; for (j = 0; j < t->ndim; j++) @@ -84,16 +82,20 @@ /* vector to node distance */ -static float distV2N (tree_t* t, int i, int node) +float distV2N (tree_t* t, const float *x, const int node) { +#if PROFILE_BUILD + t->profile.v2n++; +#endif + switch (t->dmode) { case dmode_orthogonal: - return distV2orthoH(fmat_get_ptr(t->data) + i * t->ndim, + return distV2orthoH(x, fmat_get_ptr(t->nodes[node].split), t->ndim, t->nodes[node].splitnorm); case dmode_hyperplane: - return distV2H(fmat_get_ptr(t->data) + i * t->ndim, + return distV2H(x, fmat_get_ptr(t->nodes[node].split), fmat_get_ptr(t->nodes[node].mean), t->ndim, t->nodes[node].splitnorm); @@ -107,7 +109,6 @@ static void compute_splitplane (tree_t* t, int node, int level) { int b; - int i; float h; /* case dmode_orthogonal */ @@ -127,56 +128,10 @@ // t->split[node][1], t->split[node][2]); } -/* Only for debugging */ -static void tree_info_display (tree_t* t) -{ - int i, j; - fts_post("\nTree Info:\n"); - fts_post("**********\n\n"); - fts_post("ndim = %i\n", t->ndim); - fts_post("ndata = %i\n", t->ndata); - fts_post("height = %i\n", t->height); - fts_post("n_number = %i\n", t->nnodes); - for(i = 0; i < t->ndata; i++) - { - fts_post("raw data #%i = [", i); - for(j = 0; j < t->ndim; j++) - { - fts_post("%.1f, ", fmat_get_element(t->data, i, j)); - } - fts_post("]\n"); - } -} -static void tree_display(tree_t* t) -{ - int l, n, i, j; - fts_post("\nTree Display:\n"); - fts_post("*************\n\n"); - - for(l = 0; l < t->height; l++) - { - fts_post("Level #%i ", l); - for(n = pow2(l) - 1; n < pow2(l+1) - 1; n++) - { - fts_post("("); - for(i = t->nodes[n].startind; i <= t->nodes[n].endind; i++) - { - fts_post("["); - for(j = 0; j < t->ndim; j++) - { - fts_post("%.1f, ", tree_get_element(t, i, j)); - } - fts_post("]"); - } - fts_post(")"); - } - fts_post("\n"); - } -} -void freeVect (tree_t* t, int vect_number) +static void freeVect (tree_t* t, int vect_number) { fmat_set_const(t->data, MAX_FLOAT); } @@ -244,12 +199,12 @@ while (j > i) { - while (distV2N(t, i, n) <= 0) + while (distV2N(t, tree_get_vector(t, i), n) <= 0) { i++; // fts_post("i=%i\n", i); } - while (distV2N(t, j, n) > 0) + while (distV2N(t, tree_get_vector(t, j), n) > 0) { j--; // fts_post("j=%i\n", j); @@ -270,10 +225,11 @@ } -void tree_init (tree_t* t, int h, int dim, int vect_num) +void tree_init (tree_t* t, int h, int vect_num, int dim) { int i; + t->dmode = dmode_orthogonal; t->ndim = dim; t->ndata = vect_num; t->height = h; Modified: trunk/ftm/ftmlib/classes/treesearch.c =================================================================== --- trunk/ftm/ftmlib/classes/treesearch.c 2008-07-18 15:51:37 UTC (rev 1825) +++ trunk/ftm/ftmlib/classes/treesearch.c 2008-07-18 16:13:40 UTC (rev 1826) @@ -1,143 +1,170 @@ -#if 0 #include "tree.h" #include <stdlib.h> #include <math.h> -void initStack(stack* s) { - s->sp = -1; +static void initStack(stack* s) +{ + s->sp = -1; } -int isEmpty(stack s) { - if(s.sp < 0) return 1; - return 0; +static int isEmpty(stack s) +{ + if(s.sp < 0) return 1; + return 0; } -void push(stack* s, couple c) { - s->sp++; - if(s->sp >= 100) printf("Warning: Stack capacity is attented [sp = %i]\n", s->sp); - s->c[s->sp].node = c.node; - s->c[s->sp].dist = c.dist; +static void push(stack* s, couple c) +{ + s->sp++; + if(s->sp >= MAX_NODES) + printf("Warning: Stack capacity is attented [sp = %i]\n", s->sp); + s->c[s->sp].node = c.node; + s->c[s->sp].dist = c.dist; } -couple pop(stack* s) { - if(s->sp < 0) printf("Warning: Stack is empty, poped values may be inderteminated [sp = %i]\n", s->sp); - couple tmp = s->c[s->sp]; - s->sp--; - return tmp; +static couple pop(stack* s) +{ + if(s->sp < 0) +printf("Warning: Stack is empty, poped values may be inderteminated [sp = %i]\n", + s->sp); + couple tmp = s->c[s->sp]; + s->sp--; + return tmp; } -void displayStack(stack s) { - int i = s.sp; - if(s.sp < 0) printf("Stack is empty\n"); - else { - printf("Top of stack\n"); - while(i >= 0) { - printf("( %i, %f)\n", s.c[i].node, s.c[i].dist); - i--; - } - printf("Bottom of stack\n\n"); +void displayStack(stack s) +{ + int i = s.sp; + if(s.sp < 0) printf("Stack is empty\n"); + else + { + printf("Top of stack\n"); + while(i >= 0) + { + printf("( %i, %f)\n", s.c[i].node, s.c[i].dist); + i--; } + printf("Bottom of stack\n\n"); + } } -void displayCouple(couple c) { - printf("Couple( %i, %f)\n", c.node, c.dist); +void displayCouple(couple c) +{ + printf("Couple( %i, %f)\n", c.node, c.dist); } -void coupleBuild(couple* c, int n, float d) { - c->node = n; - c->dist = d; +void coupleBuild(couple* c, int n, float d) +{ + c->node = n; + c->dist = d; } -float max(float a, float b) { - return (a > b)? a : b; +float max(float a, float b) +{ + return (a > b)? a : b; } -int maxArr(float* array, int size) { - int index = 0; - int i; +int maxArr(float* array, int size) +{ + int index = 0; + int i; - for(i = 1; i<size; i++) { - if(array[index] < array[i]) index = i; - } + for(i = 1; i<size; i++) + { + if(array[index] < array[i]) index = i; + } - return index; + return index; } -float euclidianDistance(float* v1, float* v2, int dim) { - int i; - float tmp = 0; - for(i = 0; i < dim; i++) { - tmp = tmp + ((v1[i] - v2[i])*(v1[i] - v2[i])); - } - return tmp; +float euclidianDistance(float* v1, float* v2, int dim) +{ + int i; + float tmp = 0; + for(i = 0; i < dim; i++) + { + tmp = tmp + ((v1[i] - v2[i])*(v1[i] - v2[i])); + } + return tmp; } -int* search(Tree* t, int k, float* x) { - float d[k]; //vector to vector distance from vector y[k] to vector x - int* y; //y[K] = index of the Kth neirest neighbour - int i; //current processed vector - float dxx; //dxx = distance between 2 vectors - int kmax = 0; //index of current Kth neighbour - y = (int*)malloc(k*sizeof(int)); - couple cur; //current (node, dist) couple + +/* out: y[K] = index of the Kth neirest neighbour + return: actual number of found neighbours */ +int tree_search (tree_t *t, int k, float* x, int *y) +{ + float d[k]; // vector to vector distance from vector y[k] to vector x + int i; // current processed vector + float dxx; // dxx = distance between 2 vectors + int kmax = 0; // index of current Kth neighbour + couple cur; // current (node, dist) couple + + y = (int*)malloc(k*sizeof(int)); - //Init distances - for(i = 0; i < k; i++) { - d[i] = MAX_FLOAT; - } + // Init distances + for(i = 0; i < k; i++) + { + d[i] = MAX_FLOAT; + } - //Init Search Stack - coupleBuild(&cur, 0, 0); - push(&t->s, cur); + // Init Search Stack + coupleBuild(&cur, 0, 0); + push(&t->s, cur); - while(!isEmpty(t->s)) { - displayStack(t->s); - cur = pop(&t->s); - displayStack(t->s); - if(cur.dist < d[kmax]) { //elimination rule - if(cur.node >= (pow2(t->height - 1) - 1)) { //leaf node - //printf("Je suis une feuille: p = %i\n", cur.node); - i = t->n_begin[cur.node]; - while(i <= t->n_end[cur.node]) { - dxx = euclidianDistance(x, t->data[i], t->v_dim); - //printf("la distance entre le vecteur %i et x est de: %f\n",i ,dxx); - if(dxx < d[kmax]) { - y[kmax] = i; - d[kmax] = dxx; - kmax = maxArr(d, k); - } - i++; - } - } - else { //branched node - float d; - //printf("Je suis un noeud: p = %i\n", cur.node); - d = distV2H(x, t->splitPlane[cur.node], t->v_dim); - if(d < 0) { - couple c1; - couple c2; - coupleBuild(&c1, 2*cur.node+2, max(cur.dist, d*d)); - coupleBuild(&c2, 2*cur.node+1, cur.dist); - push(&t->s, c1); - push(&t->s, c2); - } - else { - //printf("Je suis un noeud: p = %i\n", cur.node); - couple c1; - couple c2; - coupleBuild(&c1, 2*cur.node+1, max(cur.dist, d*d)); - coupleBuild(&c2, 2*cur.node+2, cur.dist); - push(&t->s, c1); - push(&t->s, c2); - } - } + while(!isEmpty(t->s)) + { + displayStack(t->s); + cur = pop(&t->s); + displayStack(t->s); + if(cur.dist < d[kmax]) + { // elimination rule + if(cur.node >= (pow2(t->height - 1) - 1)) + + { // leaf node + // printf("Je suis une feuille: p = %i\n", cur.node); + i = t->nodes[cur.node].startind; + while(i <= t->nodes[cur.node].endind) + { + dxx = euclidianDistance(x, tree_get_vector(t, i), t->ndim); + /*printf("la distance entre le vecteur %i et x est de: %f\n", i, dxx); */ + if(dxx < d[kmax]) + { + y[kmax] = i; + d[kmax] = dxx; + kmax = maxArr(d, k); + } + i++; } + } + else + { // branched node + float d; + // printf("Je suis un noeud: p = %i\n", cur.node); + d = distV2N(t, x, cur.node); + if(d < 0) + { + couple c1; + couple c2; + coupleBuild(&c1, 2*cur.node+2, max(cur.dist, d*d)); + coupleBuild(&c2, 2*cur.node+1, cur.dist); + push(&t->s, c1); + push(&t->s, c2); + } + else + { + // printf("Je suis un noeud: p = %i\n", cur.node); + couple c1; + couple c2; + coupleBuild(&c1, 2*cur.node+1, max(cur.dist, d*d)); + coupleBuild(&c2, 2*cur.node+2, cur.dist); + push(&t->s, c1); + push(&t->s, c2); + } + } } - return y; + } + return k; /* return actual number of found neighbours */ } - - -#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bor...@us...> - 2008-07-18 16:06:03
|
Revision: 1825 http://ftm.svn.sourceforge.net/ftm/?rev=1825&view=rev Author: borghesi Date: 2008-07-18 15:51:37 +0000 (Fri, 18 Jul 2008) Log Message: ----------- ftm.editor: minor changes Modified Paths: -------------- trunk/ftm/gui/Juce/common/BpfEditor.cpp trunk/ftm/gui/Juce/common/EditorContainer.h trunk/ftm/gui/Juce/common/EditorResizerBar.cpp trunk/ftm/gui/Juce/common/FvecEditor.cpp trunk/ftm/gui/Juce/common/InfoPanel.cpp trunk/ftm/gui/Juce/common/MarkersEditor.cpp trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp trunk/ftm/patches/max/help/ftm.editor.help Modified: trunk/ftm/gui/Juce/common/BpfEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/BpfEditor.cpp 2008-07-18 10:51:31 UTC (rev 1824) +++ trunk/ftm/gui/Juce/common/BpfEditor.cpp 2008-07-18 15:51:37 UTC (rev 1825) @@ -35,6 +35,9 @@ #define DEFWIDTH 256 // default width and height #define DEFHEIGHT 128 +#define BPF_INFO_SIZE 35 +#define float_Pi 3.14159265358979323846f + class BpfListDialog : public JUCE_EDITOR_NAMESPACE::Component { imtr_guiInterfaceBpf *bpfGui; @@ -107,6 +110,7 @@ class BpfEditor : public JUCE_EDITOR_NAMESPACE::Component, public ImtrEditor { JUCE_EDITOR_NAMESPACE::Colour backcolor, lightColour, darkerColour, forecolor, selectColor; + JUCE_EDITOR_NAMESPACE::Font *rangeFont; imtr_guiInterfaceBpf *bpfGui; void *obj; @@ -132,6 +136,8 @@ /*-------- offscreen -------*/ JUCE_EDITOR_NAMESPACE::Image *offscreen; + JUCE_EDITOR_NAMESPACE::Image *infoImage; + bool redraw_offscreen; public: @@ -145,11 +151,13 @@ //backcolor = JUCE_EDITOR_NAMESPACE::Colours::transparentWhite; backcolor = container->getBackgroundColor(); - lightColour = container->getBackgroundColor().brighter(); - darkerColour = container->getBackgroundColor().darker(); - forecolor = JUCE_EDITOR_NAMESPACE::Colours::white; - selectColor = forecolor.withAlpha(0.6f); + lightColour = container->getBackgroundColor().brighter(0.2f); + darkerColour = container->getBackgroundColor().darker(0.2f); + forecolor = JUCE_EDITOR_NAMESPACE::Colours::black; + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); + rangeFont = new JUCE_EDITOR_NAMESPACE::Font(JUCE_EDITOR_NAMESPACE::String( "Lucida Grande"), 10, JUCE_EDITOR_NAMESPACE::Font::italic); + opacity = container->getOpacity(); init_original_length(); @@ -171,6 +179,8 @@ else offscreen = NULL; + infoImage = NULL; + redraw_offscreen = true; description = JUCE_EDITOR_NAMESPACE::String("bpf"); @@ -234,7 +244,65 @@ else if(shape == steps_shape) return JUCE_EDITOR_NAMESPACE::String("steps"); else return JUCE_EDITOR_NAMESPACE::String("bpf"); } + + /////////////////////////// Info Image + void drawInfoBackground(JUCE_EDITOR_NAMESPACE::Graphics& g) + { + JUCE_EDITOR_NAMESPACE::Rectangle bounds = g.getClipBounds(); + JUCE_EDITOR_NAMESPACE::String text_min, text_max; + int text_min_width, text_max_width, text_height; + g.fillAll(backcolor); + + //////////////////////// text + g.setFont(*rangeFont); + text_min = JUCE_EDITOR_NAMESPACE::String( v_min); + text_min = container->formatDecimalString(text_min, 3); + text_min_width = rangeFont->getStringWidth(text_min)+2; + text_max = JUCE_EDITOR_NAMESPACE::String( v_max); + text_max = container->formatDecimalString(text_max, 3); + text_max_width = rangeFont->getStringWidth(text_max)+2; + text_height = (int)(rangeFont->getHeight()); + //////////////////////////////// + + if(!container->isVertical()) + { + g.setColour(forecolor); + g.drawText(text_min, bounds.getWidth()-1-text_min_width, getHeight()-text_height, text_min_width, text_height, JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); + g.drawText(text_max, bounds.getWidth()-1-text_max_width, 1, text_max_width, text_height, JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); + g.setColour(darkerColour); + g.drawLine(bounds.getWidth()-2, 0, bounds.getWidth()-2, getHeight()); + g.setColour(lightColour); + g.drawLine(bounds.getWidth()-1, 0, bounds.getWidth()-1, getHeight()); + + } + else + { + g.setColour(forecolor); + g.drawTextAsPath(text_min, JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(1, bounds.getHeight()-text_min_width-1))); + g.drawTextAsPath(text_max, JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(getWidth()-text_height, bounds.getHeight()-text_max_width-1))); + g.setColour(darkerColour); + g.drawLine(0, bounds.getHeight()-2, getWidth(), bounds.getHeight()-2); + g.setColour(lightColour); + g.drawLine(0, bounds.getHeight()-1, getWidth(), bounds.getHeight()-1); + } + } + void createAndDrawInfoBackground() + { + if(infoImage != NULL) + delete infoImage; + + if(container->isVertical()) + infoImage = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), BPF_INFO_SIZE, true); + else + infoImage = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, BPF_INFO_SIZE, getHeight(), true); + + JUCE_EDITOR_NAMESPACE::Graphics info_g (*infoImage); + drawInfoBackground(info_g); + } + + /////////////////////////////////////////// + void drawPeeksViewAsVector(JUCE_EDITOR_NAMESPACE::Graphics& g) { float x, y, value; @@ -1038,15 +1106,6 @@ g.drawLine(zero, 0, zero, height); } - /* draw borders */ - g.drawLine(0, 0, width, 0); - g.drawLine(0, 0, 0, height); - - g.setColour(darkerColour); - g.drawLine(0, height-1, width, height-1); - g.drawLine(width-1, 0, width-1, height); - - g.setColour(lightColour); /* draw points */ switch(shape) { @@ -1067,34 +1126,43 @@ container->drawVerticalRange(g, this); } + void updateBackgroundOffscreens() + { + /* destroy offscreen every redraw... just to force a real re-initialisation... */ + if(offscreen != NULL) + { + delete offscreen; + offscreen = NULL; + } + offscreen = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), getHeight(), true); + + JUCE_EDITOR_NAMESPACE::Graphics off_g (*offscreen); + paintBpf(off_g); + + createAndDrawInfoBackground(); + } + void paint (JUCE_EDITOR_NAMESPACE::Graphics& g) { if(redraw_offscreen && !selecting && !movingSelection) { - /* destroy offscreen every redraw... just to force a real re-initialisation... */ - if(offscreen != NULL) - { - delete offscreen; - offscreen = NULL; - } - offscreen = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), getHeight(), true); - - JUCE_EDITOR_NAMESPACE::Graphics off_g (*offscreen); - paintBpf(off_g); + updateBackgroundOffscreens(); redraw_offscreen = false; } + g.drawImageAt(offscreen, 0, 0, false); + g.setColour(selectColor); + /* draw selection rectangle */ if(selecting) { g.setOpacity(0.3f); - g.drawRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight(), 1); + g.fillRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight()); } else if(movingSelection) { g.setOpacity(0.3f); - g.setColour(lightColour); /* draw points */ switch(shape) @@ -1403,20 +1471,21 @@ void backgroundColorChanged(JUCE_EDITOR_NAMESPACE::Colour bcolor) { - lightColour = bcolor.brighter(); - darkerColour = bcolor.darker(); + lightColour = bcolor.brighter(0.2f); + darkerColour = bcolor.darker(0.2f); } void setBackgroundColor(JUCE_EDITOR_NAMESPACE::Colour bcolor) { backcolor = bcolor; + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); backgroundColorChanged(backcolor); } void setForegroundColor(JUCE_EDITOR_NAMESPACE::Colour fcolor) { forecolor = fcolor; - selectColor = forecolor.withAlpha(0.6f); + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); } JUCE_EDITOR_NAMESPACE::Colour getForegroundColor() @@ -2121,8 +2190,12 @@ } } - bool haveInfoPanel() {return false;} - JUCE_EDITOR_NAMESPACE::Image *getInfoImage(){return 0;} + bool haveInfoPanel() {return true;} + JUCE_EDITOR_NAMESPACE::Image *getInfoImage() + { + if(infoImage == NULL) createAndDrawInfoBackground(); + return infoImage; + } }; Modified: trunk/ftm/gui/Juce/common/EditorContainer.h =================================================================== --- trunk/ftm/gui/Juce/common/EditorContainer.h 2008-07-18 10:51:31 UTC (rev 1824) +++ trunk/ftm/gui/Juce/common/EditorContainer.h 2008-07-18 15:51:37 UTC (rev 1825) @@ -771,6 +771,8 @@ void addEditorContainerListener(EditorContainerListener *listener){containerListeners.add(listener);} void removeEditorContainerListener(EditorContainerListener *listener){containerListeners.removeValue(listener);} void notifyEditorContainerListeners(); + + JUCE_EDITOR_NAMESPACE::String formatDecimalString(JUCE_EDITOR_NAMESPACE::String, int n_digits); private: void createSuperposedMultiEditor(JUCE_EDITOR_NAMESPACE::Array <ImtrEditor *> imtreditors); @@ -780,7 +782,6 @@ void initInfoPanel(); void paint (JUCE_EDITOR_NAMESPACE::Graphics& g); void resized(); - JUCE_EDITOR_NAMESPACE::String formatDecimalString(JUCE_EDITOR_NAMESPACE::String, int n_digits); void InitContainer(); void initTabbedContainer(); Modified: trunk/ftm/gui/Juce/common/EditorResizerBar.cpp =================================================================== --- trunk/ftm/gui/Juce/common/EditorResizerBar.cpp 2008-07-18 10:51:31 UTC (rev 1824) +++ trunk/ftm/gui/Juce/common/EditorResizerBar.cpp 2008-07-18 15:51:37 UTC (rev 1825) @@ -55,6 +55,15 @@ } else g.fillAll( bgcolor.withAlpha( (isMouseOver() || isMouseButtonDown()) ? 1.0f : 0.5f)); + + int width = getWidth(); + int height = getHeight(); + g.setColour(bgcolor.brighter(0.2f)); + g.drawLine(0, 0, width, 0); + g.drawLine(0, 0, 0, height); + g.setColour(bgcolor.darker(0.2f)); + g.drawLine(width, 0, width, height); + g.drawLine(0, height-1, width, height-1); } void EditorResizerBar::mouseDown (const JUCE_EDITOR_NAMESPACE::MouseEvent&) Modified: trunk/ftm/gui/Juce/common/FvecEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/FvecEditor.cpp 2008-07-18 10:51:31 UTC (rev 1824) +++ trunk/ftm/gui/Juce/common/FvecEditor.cpp 2008-07-18 15:51:37 UTC (rev 1825) @@ -35,9 +35,13 @@ #define DEFWIDTH 256 // default width and height #define DEFHEIGHT 128 +#define FVEC_INFO_SIZE 35 +#define float_Pi 3.14159265358979323846f + class FvecEditor : public JUCE_EDITOR_NAMESPACE::Component, public ImtrEditor { JUCE_EDITOR_NAMESPACE::Colour backcolor, lightColour, darkerColour, forecolor, selectColor; + JUCE_EDITOR_NAMESPACE::Font *rangeFont; imtr_guiInterfaceFvec *fvecGui; void *obj; @@ -56,6 +60,8 @@ /*-------- offscreen -------*/ JUCE_EDITOR_NAMESPACE::Image *offscreen; + JUCE_EDITOR_NAMESPACE::Image *infoImage; + bool redraw_offscreen; public: @@ -69,11 +75,13 @@ //backcolor = JUCE_EDITOR_NAMESPACE::Colours::transparentWhite; backcolor = container->getBackgroundColor(); - lightColour = container->getBackgroundColor().brighter(); - darkerColour = container->getBackgroundColor().darker(); - forecolor = JUCE_EDITOR_NAMESPACE::Colours::white; - selectColor = forecolor.withAlpha(0.6f); + lightColour = container->getBackgroundColor().brighter(0.2f); + darkerColour = container->getBackgroundColor().darker(0.2f); + forecolor = JUCE_EDITOR_NAMESPACE::Colours::black; + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); + rangeFont = new JUCE_EDITOR_NAMESPACE::Font(JUCE_EDITOR_NAMESPACE::String( "Lucida Grande"), 10, JUCE_EDITOR_NAMESPACE::Font::italic); + opacity = container->getOpacity(); shape = lines_shape; @@ -92,6 +100,8 @@ else offscreen = NULL; + infoImage = NULL; + redraw_offscreen = true; description = JUCE_EDITOR_NAMESPACE::String("fvec"); } @@ -157,6 +167,62 @@ } } + /////////////////////////// Info Image + void drawInfoBackground(JUCE_EDITOR_NAMESPACE::Graphics& g) + { + JUCE_EDITOR_NAMESPACE::Rectangle bounds = g.getClipBounds(); + JUCE_EDITOR_NAMESPACE::String text_min, text_max; + int text_min_width, text_max_width, text_height; + + g.fillAll(backcolor); + + //////////////////////// text + g.setFont(*rangeFont); + text_min = JUCE_EDITOR_NAMESPACE::String( v_min); + text_min = container->formatDecimalString(text_min, 3); + text_min_width = rangeFont->getStringWidth(text_min)+2; + text_max = JUCE_EDITOR_NAMESPACE::String( v_max); + text_max = container->formatDecimalString(text_max, 3); + text_max_width = rangeFont->getStringWidth(text_max)+2; + text_height = (int)(rangeFont->getHeight()); + //////////////////////////////// + + if(!container->isVertical()) + { + g.setColour(forecolor); + g.drawText(text_min, bounds.getWidth()-text_min_width, bounds.getHeight()-text_height, text_min_width, text_height, JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); + g.drawText(text_max, bounds.getWidth()-text_max_width, 1, text_max_width, text_height, JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); + g.setColour(darkerColour); + g.drawLine(bounds.getWidth()-2, 0, bounds.getWidth()-2, bounds.getHeight()); + g.setColour(lightColour); + g.drawLine(bounds.getWidth()-1, 0, bounds.getWidth()-1, bounds.getHeight()); + } + else + { + g.setColour(forecolor); + g.drawTextAsPath(text_min, JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(1, bounds.getHeight()-text_min_width-1))); + g.drawTextAsPath(text_max, JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(bounds.getWidth()-text_height, bounds.getHeight()-text_max_width-1))); + g.setColour(darkerColour); + g.drawLine(0, bounds.getHeight()-2, bounds.getWidth(), bounds.getHeight()-2); + g.setColour(lightColour); + g.drawLine(0, bounds.getHeight()-1, bounds.getWidth(), bounds.getHeight()-1); + } + } + void createAndDrawInfoBackground() + { + if(infoImage != NULL) + delete infoImage; + + if(container->isVertical()) + infoImage = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), FVEC_INFO_SIZE, true); + else + infoImage = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, FVEC_INFO_SIZE, getHeight(), true); + + JUCE_EDITOR_NAMESPACE::Graphics info_g (*infoImage); + drawInfoBackground(info_g); + } + ////////////////////////////////////////////////////// + void drawZeroPeeksView(JUCE_EDITOR_NAMESPACE::Graphics& g) { int x, y, i; @@ -856,15 +922,6 @@ g.drawLine(zero, 0, zero, height); } - g.setColour(lightColour); - /* draw borders */ - g.drawLine(0, 0, width, 0); - g.drawLine(0, 0, 0, height); - - g.setColour(darkerColour); - g.drawLine(0, height-1, width, height-1); - g.drawLine(width-1, 0, width-1, height); - g.setColour(forecolor); switch(shape) @@ -886,20 +943,27 @@ container->drawVerticalRange(g, this); } + void updateBackgroundOffscreens() + { + /* destroy offscreen every redraw... just to force a real re-initialisation... */ + if(offscreen != NULL) + { + delete offscreen; + offscreen = NULL; + } + offscreen = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), getHeight(), true); + + JUCE_EDITOR_NAMESPACE::Graphics off_g (*offscreen); + paintFvec(off_g); + + createAndDrawInfoBackground(); + } + void paint (JUCE_EDITOR_NAMESPACE::Graphics& g) { if(redraw_offscreen && !selecting) { - /* destroy offscreen every redraw... just to force a real re-initialisation... */ - if(offscreen != NULL) - { - delete offscreen; - offscreen = NULL; - } - offscreen = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), getHeight(), true); - - JUCE_EDITOR_NAMESPACE::Graphics off_g (*offscreen); - paintFvec(off_g); + updateBackgroundOffscreens(); redraw_offscreen = false; } g.drawImageAt(offscreen, 0, 0, false); @@ -907,8 +971,9 @@ /* draw selection rectangle */ if(selecting) { + g.setColour(selectColor); g.setOpacity(0.3f); - g.drawRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight(), 1); + g.fillRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight()); } else if(container->doRegionSelection(this)) container->drawRegionSelection(g, this); @@ -982,20 +1047,21 @@ void backgroundColorChanged(JUCE_EDITOR_NAMESPACE::Colour bcolor) { - lightColour = bcolor.brighter(); - darkerColour = bcolor.darker(); + lightColour = bcolor.brighter(0.2f); + darkerColour = bcolor.darker(0.2f); } void setBackgroundColor(JUCE_EDITOR_NAMESPACE::Colour bcolor) { backcolor = bcolor; + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); backgroundColorChanged(backcolor); } void setForegroundColor(JUCE_EDITOR_NAMESPACE::Colour fcolor) { forecolor = fcolor; - selectColor = forecolor.withAlpha(0.6f); + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); } JUCE_EDITOR_NAMESPACE::Colour getForegroundColor() @@ -1227,8 +1293,12 @@ return ((y/dy)/container->getHZoom() - container->getHTransposition()); } } - bool haveInfoPanel() {return false;} - JUCE_EDITOR_NAMESPACE::Image *getInfoImage(){return NULL;} + bool haveInfoPanel() {return true;} + JUCE_EDITOR_NAMESPACE::Image *getInfoImage() + { + if(infoImage == NULL) createAndDrawInfoBackground(); + return infoImage; + } }; Modified: trunk/ftm/gui/Juce/common/InfoPanel.cpp =================================================================== --- trunk/ftm/gui/Juce/common/InfoPanel.cpp 2008-07-18 10:51:31 UTC (rev 1824) +++ trunk/ftm/gui/Juce/common/InfoPanel.cpp 2008-07-18 15:51:37 UTC (rev 1825) @@ -158,7 +158,7 @@ { JUCE_EDITOR_NAMESPACE::Image *img = editor->getInfoImage(); bounds = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(editor))->getBounds(); - g.drawImageWithin(img, 0, bounds.getY(), getWidth(), bounds.getHeight(), JUCE_EDITOR_NAMESPACE::RectanglePlacement::xLeft | JUCE_EDITOR_NAMESPACE::RectanglePlacement::yTop | JUCE_EDITOR_NAMESPACE::RectanglePlacement::doNotResize, false); + g.drawImageWithin(img, bounds.getX(), 0, bounds.getWidth(), getHeight(), JUCE_EDITOR_NAMESPACE::RectanglePlacement::xLeft | JUCE_EDITOR_NAMESPACE::RectanglePlacement::yTop | JUCE_EDITOR_NAMESPACE::RectanglePlacement::doNotResize, false); } } } Modified: trunk/ftm/gui/Juce/common/MarkersEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/MarkersEditor.cpp 2008-07-18 10:51:31 UTC (rev 1824) +++ trunk/ftm/gui/Juce/common/MarkersEditor.cpp 2008-07-18 15:51:37 UTC (rev 1825) @@ -40,10 +40,11 @@ #define STEPS_VIEW 2 #define float_Pi 3.14159265358979323846f +#define MARKERS_INFO_SIZE 35 class MarkersEditor : public JUCE_EDITOR_NAMESPACE::Component, public ImtrEditor { - JUCE_EDITOR_NAMESPACE::Colour backcolor, lightColour, forecolor, selectColor, labelColor; + JUCE_EDITOR_NAMESPACE::Colour backcolor, lightColor, darkerColor, forecolor, selectColor, labelColor; float opacity; imtr_guiInterfaceMarkers *markersGui; @@ -70,6 +71,7 @@ /*-------- offscreen -------*/ JUCE_EDITOR_NAMESPACE::Image *offscreen; + JUCE_EDITOR_NAMESPACE::Image *infoImage; bool redraw_offscreen; public: @@ -82,9 +84,10 @@ setFocusContainer(true); backcolor = container->getBackgroundColor(); - lightColour = container->getBackgroundColor().brighter(); - forecolor = JUCE_EDITOR_NAMESPACE::Colours::white; - selectColor = forecolor.withAlpha(0.6f); + lightColor = container->getBackgroundColor().brighter(0.2f); + darkerColor = container->getBackgroundColor().darker(0.2f); + forecolor = JUCE_EDITOR_NAMESPACE::Colours::black; + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); labelColor = forecolor.withAlpha(0.4f); opacity = container->getOpacity(); @@ -117,6 +120,8 @@ else offscreen = NULL; + infoImage = NULL; + redraw_offscreen = true; description = JUCE_EDITOR_NAMESPACE::String("markers"); @@ -536,6 +541,43 @@ }*/ } } + + /////////////////////////// Info Image + void drawInfoBackground(JUCE_EDITOR_NAMESPACE::Graphics& g) + { + JUCE_EDITOR_NAMESPACE::Rectangle bounds = g.getClipBounds(); + + g.fillAll(backcolor); + + g.setColour(darkerColor); + if(!container->isVertical()) + { + g.drawLine(bounds.getWidth()-2, 0, bounds.getWidth()-2, bounds.getHeight()); + g.setColour(lightColor); + g.drawLine(bounds.getWidth()-1, 0, bounds.getWidth()-1, bounds.getHeight()); + } + else + { + g.drawLine(0, bounds.getHeight()-2, bounds.getWidth(), bounds.getHeight()-2); + g.setColour(lightColor); + g.drawLine(0, bounds.getHeight()-1, bounds.getWidth(), bounds.getHeight()-1); + } + } + void createAndDrawInfoBackground() + { + if(infoImage != NULL) + delete infoImage; + + if(container->isVertical()) + infoImage = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), MARKERS_INFO_SIZE, true); + else + infoImage = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, MARKERS_INFO_SIZE, getHeight(), true); + + JUCE_EDITOR_NAMESPACE::Graphics info_g (*infoImage); + drawInfoBackground(info_g); + } + ////////////////////////////////////////////////////// + /********************** paint **********************/ @@ -780,30 +822,37 @@ drawMarkersAsList(g); } + void updateBackgroundOffscreens() + { + /* destroy offscreen every redraw... just to force a real re-initialisation... */ + if(offscreen != NULL) + { + delete offscreen; + offscreen = NULL; + } + offscreen = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), getHeight(), true); + + JUCE_EDITOR_NAMESPACE::Graphics off_g (*offscreen); + paintMarkers(off_g); + + createAndDrawInfoBackground(); + } + void paint (JUCE_EDITOR_NAMESPACE::Graphics& g) { if(redraw_offscreen && !selecting && !movingSelection) { - /* destroy offscreen every redraw... just to force a real re-initialisation... */ - if(offscreen != NULL) - { - delete offscreen; - offscreen = NULL; - } - offscreen = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), getHeight(), true); - - JUCE_EDITOR_NAMESPACE::Graphics off_g (*offscreen); - paintMarkers(off_g); + updateBackgroundOffscreens(); redraw_offscreen = false; } g.drawImageAt(offscreen, 0, 0, false); - g.setColour(lightColour); + g.setColour(selectColor); /* draw selection rectangle */ if(selecting) { g.setOpacity(0.3f); - g.drawRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight(), 1); + g.fillRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight()); } else if(container->doRegionSelection(this)) { @@ -811,9 +860,7 @@ } else if(movingSelection) { - g.setOpacity(0.3f); - g.setColour(lightColour); - + g.setOpacity(0.3f); markersDrawSelection(g); } } @@ -957,7 +1004,9 @@ void setBackgroundColor(JUCE_EDITOR_NAMESPACE::Colour bcolor) { backcolor = bcolor; - lightColour = backcolor.brighter(); + darkerColor = backcolor.darker(0.2f); + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); + lightColor = backcolor.brighter(0.2f); } void backgroundColorChanged(JUCE_EDITOR_NAMESPACE::Colour bcolor){ setBackgroundColor(bcolor);} @@ -965,7 +1014,7 @@ void setForegroundColor(JUCE_EDITOR_NAMESPACE::Colour fcolor) { forecolor = fcolor; - selectColor = forecolor.withAlpha(0.6f); + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); labelColor = forecolor.withAlpha(0.4f); } @@ -1238,8 +1287,12 @@ return (y/dy)/container->getHZoom() - container->getHTransposition(); } } - bool haveInfoPanel() {return false;} - JUCE_EDITOR_NAMESPACE::Image *getInfoImage(){return NULL;} + bool haveInfoPanel() {return true;} + JUCE_EDITOR_NAMESPACE::Image *getInfoImage() + { + if(infoImage == NULL) createAndDrawInfoBackground(); + return infoImage; + } }; JUCE_EDITOR_NAMESPACE::Component *createMarkersEditor(void *obj, imtr_guiInterfaceMarkers *markersGui, EditorContainer *container, ImtrEditorListener *listener) Modified: trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp 2008-07-18 10:51:31 UTC (rev 1824) +++ trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp 2008-07-18 15:51:37 UTC (rev 1825) @@ -39,10 +39,11 @@ #define LINES_VIEW 0 #define PEEKS_VIEW 1 #define STEPS_VIEW 2 +#define SPECTRO_INFO_SIZE 35 class SpectrogramEditor : public JUCE_EDITOR_NAMESPACE::Component, public ImtrEditor { - JUCE_EDITOR_NAMESPACE::Colour backcolor, lightColour, forecolor, selectColor; + JUCE_EDITOR_NAMESPACE::Colour backcolor, lightColor, darkerColor, forecolor, selectColor; imtr_guiInterfaceSpectrogram *spectroGui; void *obj; @@ -74,6 +75,7 @@ /*-------- offscreen -------*/ JUCE_EDITOR_NAMESPACE::Image *offscreen; + JUCE_EDITOR_NAMESPACE::Image *infoImage; bool redraw_offscreen; public: @@ -86,8 +88,9 @@ setFocusContainer(true); backcolor = container->getBackgroundColor(); - lightColour = backcolor.brighter().withAlpha(0.5f); - forecolor = JUCE_EDITOR_NAMESPACE::Colours::white; + lightColor = backcolor.brighter(0.2f).withAlpha(0.5f); + darkerColor = backcolor.darker(0.2f); + forecolor = JUCE_EDITOR_NAMESPACE::Colours::black; selectColor = forecolor.withAlpha(0.6f); opacity = container->getOpacity(); @@ -115,6 +118,8 @@ else offscreen = NULL; + infoImage = NULL; + redraw_offscreen = true; addMouseListener((dynamic_cast<JUCE_EDITOR_NAMESPACE::MouseListener *>(container->getCurrentTool())), false); @@ -364,6 +369,43 @@ /********************** paint **********************/ + + /////////////////////////// Info Image + void drawInfoBackground(JUCE_EDITOR_NAMESPACE::Graphics& g) + { + JUCE_EDITOR_NAMESPACE::Rectangle bounds = g.getClipBounds(); + + g.fillAll(backcolor); + + g.setColour(darkerColor); + if(!container->isVertical()) + { + g.drawLine(bounds.getWidth()-2, 0, bounds.getWidth()-2, bounds.getHeight()); + g.setColour(lightColor); + g.drawLine(bounds.getWidth()-1, 0, bounds.getWidth()-1, bounds.getHeight()); + } + else + { + g.drawLine(0, bounds.getHeight()-2, bounds.getWidth(), bounds.getHeight()-2); + g.setColour(lightColor); + g.drawLine(0, bounds.getHeight()-1, bounds.getWidth(), bounds.getHeight()-1); + } + } + void createAndDrawInfoBackground() + { + if(infoImage != NULL) + delete infoImage; + + if(container->isVertical()) + infoImage = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), SPECTRO_INFO_SIZE, true); + else + infoImage = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, SPECTRO_INFO_SIZE, getHeight(), true); + + JUCE_EDITOR_NAMESPACE::Graphics info_g (*infoImage); + drawInfoBackground(info_g); + } + /////////////////////////////////////// + void spectro_draw_monodimensional_fmat(JUCE_EDITOR_NAMESPACE::Graphics& g, int start_pix, int end_pix, int onset, int size, float *ptr) { int start_idx = (v_min > 0 && v_min < size) ? v_min : 0; @@ -595,20 +637,27 @@ } } + void updateBackgroundOffscreens() + { + /* destroy offscreen every redraw... just to force a real re-initialisation... */ + if(offscreen != NULL) + { + delete offscreen; + offscreen = NULL; + } + offscreen = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), getHeight(), true); + + JUCE_EDITOR_NAMESPACE::Graphics off_g (*offscreen); + paintSpectrogram(off_g); + + createAndDrawInfoBackground(); + } + void paint (JUCE_EDITOR_NAMESPACE::Graphics& g) { if(redraw_offscreen && !rect_selection && !cross_selection) { - /* destroy offscreen every redraw... just to force a real re-initialisation... */ - if(offscreen != NULL) - { - delete offscreen; - offscreen = NULL; - } - offscreen = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), getHeight(), true); - - JUCE_EDITOR_NAMESPACE::Graphics off_g (*offscreen); - paintSpectrogram(off_g); + updateBackgroundOffscreens(); redraw_offscreen = false; } g.drawImageAt(offscreen, 0, 0, false); @@ -704,7 +753,8 @@ void setBackgroundColor(JUCE_EDITOR_NAMESPACE::Colour bcolor) { backcolor = bcolor; - lightColour = backcolor.brighter(); + lightColor = backcolor.brighter(0.2f); + darkerColor = backcolor.darker(0.2f); } void backgroundColorChanged(JUCE_EDITOR_NAMESPACE::Colour bcolor){ setBackgroundColor(bcolor);} @@ -890,8 +940,12 @@ return (y/dy)/container->getHZoom() - container->getHTransposition(); } } - bool haveInfoPanel() {return false;} - JUCE_EDITOR_NAMESPACE::Image *getInfoImage(){return NULL;} + bool haveInfoPanel() {return true;} + JUCE_EDITOR_NAMESPACE::Image *getInfoImage() + { + if(infoImage == NULL) createAndDrawInfoBackground(); + return infoImage; + } }; JUCE_EDITOR_NAMESPACE::Component *createSpectrogramEditor(void *obj, imtr_guiInterfaceSpectrogram *spectroGui, EditorContainer *container, ImtrEditorListener *listener) Modified: trunk/ftm/patches/max/help/ftm.editor.help =================================================================== --- trunk/ftm/patches/max/help/ftm.editor.help 2008-07-18 10:51:31 UTC (rev 1824) +++ trunk/ftm/patches/max/help/ftm.editor.help 2008-07-18 15:51:37 UTC (rev 1825) @@ -1,13745 +1,14097 @@ @@ Diff output truncated at 100000 characters. @@ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-18 10:51:26
|
Revision: 1824 http://ftm.svn.sourceforge.net/ftm/?rev=1824&view=rev Author: diemo Date: 2008-07-18 10:51:31 +0000 (Fri, 18 Jul 2008) Log Message: ----------- precalc hyperplane norm start distinguishing decomposition modes Modified Paths: -------------- trunk/ftm/ftmlib/classes/tree.h trunk/ftm/ftmlib/classes/treebuild.c Modified: trunk/ftm/ftmlib/classes/tree.h =================================================================== --- trunk/ftm/ftmlib/classes/tree.h 2008-07-18 10:35:56 UTC (rev 1823) +++ trunk/ftm/ftmlib/classes/tree.h 2008-07-18 10:51:31 UTC (rev 1824) @@ -35,12 +35,13 @@ fmat_t *mean; /* mean vector (todo: median) */ fmat_t *split; /* hyperplane A1*X1 + A2*X2 +...+ An*Xn + An+1 = 0 */ + float splitnorm; /* length of split vector */ } node_t; -enum tree_dmode { mode_orthogonal, mode_hyperplane, mode_pca }; +enum tree_dmode { dmode_orthogonal, dmode_hyperplane, dmode_pca }; -typedef struct tree +typedef struct _tree { fts_object_t o; Modified: trunk/ftm/ftmlib/classes/treebuild.c =================================================================== --- trunk/ftm/ftmlib/classes/treebuild.c 2008-07-18 10:35:56 UTC (rev 1823) +++ trunk/ftm/ftmlib/classes/treebuild.c 2008-07-18 10:51:31 UTC (rev 1824) @@ -54,49 +54,49 @@ /* vector to orthogonal plane node distance */ -static float distV2orthoH (float* vect, float* hplane, int vectDim) +static float distV2orthoH (float* vect, float* hplane, int vectDim, float norm) { // standard algebra computing int i; - float tmp1 = 0; - float tmp2 = 0; - for(i = 0; i < vectDim; i++) + float dotprod = 0; + + for (i = 0; i < vectDim; i++) { - tmp1 += vect[i] * hplane[i]; - tmp2 += hplane[i] * hplane[i]; + dotprod += vect[i] * hplane[i]; } - return ((tmp1 + hplane[vectDim]) / sqrt(tmp2)); + return ((dotprod + hplane[vectDim]) / norm); } /* vector to general plane node distance */ -static float distV2orthoH (float* vect, float* plane, float* mean, int vectDim) +static float distV2H (float* vect, float* plane, float* mean, int vectDim, float norm) { // standard algebra computing int i; - float tmp1 = 0; - float tmp2 = 0; + float dotprod = 0; for(i = 0; i < vectDim; i++) { - tmp1 += (vect[i] - mean[i]) * hplane[i]; - tmp2 += hplane[i] * hplane[i]; + dotprod += (vect[i] - mean[i]) * plane[i]; } - return (tmp1 / sqrt(tmp2)); + return (dotprod / norm); } /* vector to node distance */ -static float distV2N (tree_t* t, int i, int n) +static float distV2N (tree_t* t, int i, int node) { switch (t->dmode) { - case mode_orthogonal: + case dmode_orthogonal: return distV2orthoH(fmat_get_ptr(t->data) + i * t->ndim, - fmat_get_ptr(t->nodes[i].split), t->ndim); - case mode_hyperplane: + fmat_get_ptr(t->nodes[node].split), + t->ndim, t->nodes[node].splitnorm); + case dmode_hyperplane: return distV2H(fmat_get_ptr(t->data) + i * t->ndim, - fmat_get_ptr(t->nodes[i].split), t->ndim); + fmat_get_ptr(t->nodes[node].split), + fmat_get_ptr(t->nodes[node].mean), + t->ndim, t->nodes[node].splitnorm); default: fts_post("error: unknown mode %d", t->dmode); return 0; @@ -110,6 +110,7 @@ int i; float h; + /* case dmode_orthogonal */ // Level parameter gives the base vector to use b = level % t->ndim; h = fmat_get_element(t->nodes[node].mean, b, 0); @@ -120,6 +121,8 @@ fmat_set_element(t->nodes[node].split, b, 0, 1); fmat_set_element(t->nodes[node].split, t->ndim, 0, -h); + t->nodes[node].splitnorm = 1; + // fts_post("Splitplane of node %i: (%f, %f, %f)\n", node, t->split[node][0], // t->split[node][1], t->split[node][2]); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-18 10:35:53
|
Revision: 1823 http://ftm.svn.sourceforge.net/ftm/?rev=1823&view=rev Author: diemo Date: 2008-07-18 10:35:56 +0000 (Fri, 18 Jul 2008) Log Message: ----------- compiles as ftm class Modified Paths: -------------- trunk/ftm/ftmlib/classes/tree.c trunk/ftm/ftmlib/classes/tree.h trunk/ftm/ftmlib/classes/treebuild.c trunk/ftm/ftmlib/classes/treesearch.c Modified: trunk/ftm/ftmlib/classes/tree.c =================================================================== --- trunk/ftm/ftmlib/classes/tree.c 2008-07-17 10:55:48 UTC (rev 1822) +++ trunk/ftm/ftmlib/classes/tree.c 2008-07-18 10:35:56 UTC (rev 1823) @@ -87,140 +87,30 @@ return dist; } -static void -compute_mean(tree_t *t, int node) -{ - int i, j; - float tmp; - float *mean_ptr; - float *data_ptr; - int n_nvector; - t->nodes[node].mean = fmat_create(1, t->ndim); - fts_object_refer(t->nodes[node].mean); - - mean_ptr = fmat_get_ptr(t->nodes[node].mean); - - // number of vectors from the processed node - n_nvector = t->nodes[node].endind - t->nodes[node].startind + 1; - for(j = 0; j < t->ndim; j++) - { - tmp = 0; - - for(i = t->nodes[node].startind; i <= t->nodes[node].endind; i++) - { - data_ptr = fmat_get_ptr(t->data[i]); - tmp += data_ptr[j]; - } - mean_ptr[j] = tmp / n_nvector; - } - //fts_post("mean vect computed \n"); -} - -static void -compute_splitplane(tree_t *t, int node, int level) -{ - int b; - int i; - float *split_ptr; - float *mean_ptr; - - //Level parameter gives the base vector to use - b = level % t->ndim; - - t->nodes[node].splitplane = fmat_create(1, t->ndim + 1); - fts_object_refer(t->nodes[node].splitplane); - split_ptr = fmat_get_ptr(t->nodes[node].splitplane); - mean_ptr = fmat_get_ptr(t->nodes[node].mean); - - //We compute an hyperplane which is orthogonal to the base vector number b - for(i = 0; i < t->ndim; i++) - split_ptr[i] = 0; - - split_ptr[b] = 1; - split_ptr[t->ndim] = -(mean_ptr[b]); - //fts_post("splitplane computed\n"); -} - static float distV2H(fmat_t* vect, fmat_t* hplane) { - //standard algebra computing - int i; - float tmp1 = 0; - float tmp2 = 0; - int m = fmat_get_m(vect); - int n = fmat_get_n(vect); - float *v = fmat_get_ptr(vect); + //standard algebra computing + int i; + float tmp1 = 0; + float tmp2 = 0; + int m = fmat_get_m(vect); + int n = fmat_get_n(vect); + float *v = fmat_get_ptr(vect); float *h = fmat_get_ptr(hplane); int size = m * n; - for(i = 0; i < size; i++) - { - tmp1 += v[i]*h[i]; - tmp2 += h[i]*h[i]; - } + for(i = 0; i < size; i++) + { + tmp1 += v[i]*h[i]; + tmp2 += h[i]*h[i]; + } - return (tmp1 + h[size])/sqrt(tmp2); + return (tmp1 + h[size])/sqrt(tmp2); } -static void -swap(tree_t* t, int i, int j) -{ - int tmp; - tmp = t->listind[i]; - t->listind[i] = t->listind[j]; - t->listind[j] = tmp; -} -static void -tree_build (tree_t *t) -{ - int l; //current level number - int n; //current node number - int i, j; //loop counters - - /* Maximum length is equal to pow(2, height-1) */ - if(pow(2, t->height-1) > t->ndata) - { - if(t->ndata == 0) fts_post("tree is empty! \n"); - else fts_post("can't buid this tree, try with a smaller tree height \n"); - } - - for(l = 0; l < (t->height); l++) - { - for(n = pow(2, l) - 1; n < pow(2, l+1) - 1; n++) - { - compute_mean(t, n); - compute_splitplane(t, n, l); - i = t->nodes[n].startind; - j = t->nodes[n].endind; - - while(j > i) - { - while(distV2H(t->data[i], t->nodes[n].splitplane) <= 0) - { - i++; - } - while(distV2H(t->data[j], t->nodes[n].splitplane) > 0) - { - j--; - } - if(j > i) - { - swap(t, i, j); - } - } - t->nodes[2*n+1].startind = t->nodes[n].startind; //begining index of left child of node n - t->nodes[2*n+1].endind = j; //ending index of left child of node n - t->nodes[2*n+2].startind = i; //begining index of left child of node n - t->nodes[2*n+2].endind = t->nodes[n].endind; //ending index of left child of node n - } - } - -} - - /* @return number of vectors found n, n <= k list of n indices in result @@ -272,7 +162,8 @@ fts_post("("); for(i = t->nodes[n].startind; i <= t->nodes[n].endind; i++) { fts_post("["); - data_ptr = fmat_get_ptr(t->data[i]); + data_ptr = fmat_get_ptr(t->data); + if(data_ptr[0] == MAX_FLOAT) fts_post("zombi]"); else { for(j = 0; j < (t->ndim - 1); j++) { @@ -294,7 +185,7 @@ float* data_ptr; fts_post("vector #%i[", v); - data_ptr = fmat_get_ptr(t->data[v]); + data_ptr = fmat_get_ptr(t->data) + v * t->ndim; if(data_ptr[0] == MAX_FLOAT) fts_post("zombi]"); else { @@ -314,25 +205,38 @@ } } + + + + /****************************************************************************** * * user methods * */ -static fts_method_status_t _tree_set (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) +static fts_method_status_t _tree_set (fts_object_t *o, fts_symbol_t s, + int ac, const fts_atom_t *at, + fts_atom_t *ret) { tree_t *self = (tree_t *) o; + fmat_t *data = (fmat_t *) fts_get_object(at); - /* tree_clear and rebuild: */ - /* tree_clear(self); - tree_set(self, ac, at); - tree_build(self); - */ + if (self->data) + fts_object_release((fts_object_t *) self->data); - fts_set_object(ret, self); - fts_object_refer(self); + /* method only declared for fmat, so no check needed */ + self->data = data; + fts_object_refer((fts_object_t *) self->data); + tree_init(self, floor(log(fmat_get_m(data))), + fmat_get_m(data), fmat_get_n(data)); + + /* tree_clear and rebuild: */ + /* tree_clear(self);*/ + tree_build(self); + + fts_set_object(ret, o); return fts_ok; } @@ -356,6 +260,7 @@ static fts_method_status_t _tree_getknn (fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { +#if 0 tree_t *self = (tree_t *) o; fmat_t *x = NULL; /* search vector */ int k = 1, n; @@ -394,7 +299,7 @@ fts_set_object(ret, tup); fts_object_refer(tup); } - +#endif return fts_ok; } @@ -420,55 +325,27 @@ */ static fts_method_status_t -tree_init(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) +_tree_init(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { tree_t *self = (tree_t *) o; int i; /* Init */ - self->ndata = 0; - self->height = HEIGHT; /*Function that returns an optimal tree height for a given number of data*/ - self->nnodes = (int)pow(2, self->height) - 1; - self->ndim = 0; - - /* Init index list */ - for(i = 0; i < self->ndata; i++) - self->listind[i] = i; - + self->ndata = 0; + self->height = 0; + self->nnodes = (int)pow(2, self->height) - 1; + self->ndim = 0; + self->data = NULL; + self->dataindex = NULL; + self->nodes = NULL; + fts_post("tree init is ok \n"); - /* make space for max. ac vectors */ - -/* todo: move to tree_set */ - while (ac) + if (ac > 0 && fts_is_a(at, fmat_class)) { - if (fts_is_a(at, fmat_class)) - { - fmat_t *x = (fmat_t *) fts_get_object(at); - - /* check dimensions */ - if (self->ndim == 0) - { - self->ndim = fmat_get_n(x); - fts_post("set dimension to %d\n", self->ndim); - } - else - { - } - - self->data[self->ndata++] = x; - fts_object_refer(x); - fts_post("add %d\n", self->ndata); - } - - ac--; - at++; + _tree_set(o, s, ac, at, ret); } - /* Init root node */ - self->nodes[0].startind = 0; - self->nodes[0].endind = self->ndata - 1; - /* build tree */ tree_build(self); tree_info_display(self); @@ -479,7 +356,7 @@ static fts_method_status_t -tree_delete(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) +_tree_delete(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) { tree_t *self = (tree_t *) o; int i; @@ -489,24 +366,24 @@ for (i = 0; i < self->nnodes; i++) { fts_object_release(self->nodes[i].mean); - fts_object_release(self->nodes[i].splitplane); + fts_object_release(self->nodes[i].split); } /* free data */ - for (i = 0; i < self->ndata; i++) - { - fts_object_release(self->data[i]); /* free stored vectors */ - } + fts_object_release(self->data); /* free stored vectors */ - /* todo: free structure */ + /* free structure */ + fts_free(self->data); + fts_free(self->dataindex); + fts_free(self->nodes); return fts_ok; } static void -tree_instantiate(fts_class_t *cl) +_tree_instantiate(fts_class_t *cl) { - fts_class_init(cl, sizeof(tree_t), tree_init, tree_delete, "[<sym|int: key> <any: value> ...] - treeionary"); + fts_class_init(cl, sizeof(tree_t), _tree_init, _tree_delete, "[<fmat: data>>] - vector space index tree"); /* fts_class_set_copy_function(cl, tree_copy_function); @@ -523,11 +400,17 @@ fts_class_message_varargs(cl, fts_s_remove, _tree_remove, "<any: key> ... - remove given entries"); */ - fts_class_message_varargs(cl, fts_s_set, _tree_set, "<any: key> <any: value> ... - set list of key-value pairs"); - fts_class_message(cl, fts_new_symbol("add"), fmat_class, _tree_add, ""); + fts_class_message(cl, fts_s_set, fmat_class, _tree_set, "<fmat: data> - set data matrix(ndata, ndim)"); +/* no: fts_class_message(cl, fts_new_symbol("add"), fmat_class, _tree_add, "<fmat: vector> - add one vector"); */ /*fts_class_message_varargs(cl, fts_s_get, _tree_getknn);*/ - fts_class_message_varargs(cl, fts_new_symbol("getknn"), _tree_getknn, ""); + fts_class_message_varargs(cl, fts_new_symbol("getknn"), _tree_getknn, "<fmat: x> [<int: k>] - get k nearest neighbours (default=1) to vector x"); +// fts_class_message_varargs(cl, fts_new_symbol("getknni"), _tree_getknni, "<fmat: x> [<int: k>] - get row indices in data matrix of k nearest neighbours (default=1) to vector x"); + + /* inspection */ +// fts_class_message_varargs(cl, fts_new_symbol("node"), _tree_get_node, +// "<num|mean|hyper|size|start|end> <int: index> - get information about a node"); + } @@ -535,5 +418,5 @@ { tree_symbol = fts_new_symbol("tree"); - tree_class = fts_class_install(tree_symbol, tree_instantiate); + tree_class = fts_class_install(tree_symbol, _tree_instantiate); } Modified: trunk/ftm/ftmlib/classes/tree.h =================================================================== --- trunk/ftm/ftmlib/classes/tree.h 2008-07-17 10:55:48 UTC (rev 1822) +++ trunk/ftm/ftmlib/classes/tree.h 2008-07-18 10:35:56 UTC (rev 1823) @@ -26,42 +26,59 @@ #include "fts.h" +#define MAX_FLOAT 0x7FFFFFFF -#define MAX_VECT 200 -#define MAX_NODES 400 - typedef struct node { - int startind; - int endind; + int startind; /* index of first vector in node in dataindex array */ + int endind; /* index of last vector in node in dataindex array */ - fmat_t *mean; - fmat_t *splitplane; + fmat_t *mean; /* mean vector (todo: median) */ + fmat_t *split; /* hyperplane A1*X1 + A2*X2 +...+ An*Xn + An+1 = 0 */ } node_t; +enum tree_dmode { mode_orthogonal, mode_hyperplane, mode_pca }; + typedef struct tree { fts_object_t o; - int ndim; - int ndata; - int height; + enum tree_dmode dmode; + int ndim; /* Dimension of vectors */ + int ndata; /* Number of vectors */ + int height; /* Height of the tree */ + int nnodes; /* Number of nodes (must be a power of 2) */ - fmat_t *data[MAX_VECT]; - - //Vector index list - int listind[MAX_VECT]; + fmat_t *data; /* data matrix (ndata, ndim) */ + int *dataindex; /* data vector indirection array (ndata) */ + node_t *nodes; /* nodes (nnodes) */ +} tree_t; - int nnodes; - node_t nodes[MAX_NODES]; -} tree_t; +/* stack elements for search algorithm */ +typedef struct coupleNodeDist +{ + int node; + float dist; +} couple; +typedef struct searchStack +{ + couple c[100]; + int sp; +} stack; + + FTS_API fts_symbol_t tree_symbol; FTS_API fts_class_t *tree_class; -FTS_API void tree_get(tree_t *tree, const fts_atom_t *key, fts_atom_t *atom); +/* get data element via indirection order array */ +#define tree_get_element(tree, i, j) fmat_get_element(tree->data, tree->dataindex[i], j) +void tree_build (tree_t* t); +void tree_init (tree_t* t, int h, int dim, int vect_num); + + #endif Modified: trunk/ftm/ftmlib/classes/treebuild.c =================================================================== --- trunk/ftm/ftmlib/classes/treebuild.c 2008-07-17 10:55:48 UTC (rev 1822) +++ trunk/ftm/ftmlib/classes/treebuild.c 2008-07-18 10:35:56 UTC (rev 1823) @@ -1,195 +1,300 @@ -#include "Tree.h" + +#include "tree.h" #include <stdlib.h> #include <math.h> -int pow2(int x) { - if(x == 0) return 1; - else return 2*pow2(x - 1); +static int pow2(int x) +{ + return 1 << x; } -void initTree(Tree* t, int dim, int h, int vect_num) { - t->v_dim = dim; - t->v_number = vect_num; - t->height = h; - t->n_number = pow2(h) - 1; - t->n_begin[0] = 0; //Init root node : - t->n_end[0] = t->v_number - 1; //Vectors are indexed from 0 to v_number - 1 - initStack(&t->s); //Init stack -} -void meanVectCompute(Tree* t, int node) { - int i, j; - float tmp; - int n_nvector = t->n_end[node] - t->n_begin[node] + 1; // number of vectors from the processed node - for(j = 0; j <= t->v_dim; j++) { - tmp = 0; - for(i = t->n_begin[node]; i <= t->n_end[node]; i++) { - tmp += t->data[i][j]; - } - t->meanVect[node][j] = tmp / n_nvector; +static void +compute_mean (tree_t *t, int node) +{ + float sum; + float *mean_ptr = fmat_get_ptr(t->nodes[node].mean); +// float *data_ptr = fmat_get_ptr(t->data); + int nvector; + int i, j; + + // number of vectors from the processed node + nvector = t->nodes[node].endind - t->nodes[node].startind + 1; + for (j = 0; j < t->ndim; j++) + { + sum = 0; + + for (i = t->nodes[node].startind; i <= t->nodes[node].endind; i++) + { + sum += tree_get_element(t, i, j); } + mean_ptr[j] = sum / nvector; + } + //fts_post("mean vect computed \n"); } -int compare(float* currentVect, float* meanVect, int component) { - //printf("compare %f and %f\n", meanVect[component], currentVect[component]); - return (currentVect[component] - meanVect[component]); + +static int compare(float* currentVect, float* mean, int component) +{ +// fts_post("compare %f and %f\n", mean[component], currentVect[component]); + return (currentVect[component] - mean[component]); } -void swap(Tree* t, int i, int j) { - int tmp; - int comp; - for(comp = 0; comp < t->v_dim; comp++) { - tmp = t->data[i][comp]; - t->data[i][comp] = t->data[j][comp]; - t->data[j][comp] = tmp; - } + +/* swap positions of vectors i and j: only in indirection array */ +static void swap (tree_t* t, int i, int j) +{ + int tmp; + + tmp = t->dataindex[i]; + t->dataindex[i] = t->dataindex[j]; + t->dataindex[j] = tmp; } -float distV2H(float* vect, float* hplane, int vectDim) { - //standard algebra computing - int i; - float tmp1 = 0; - float tmp2 = 0; - for(i = 0; i < vectDim; i++) { - tmp1 += vect[i]*hplane[i]; - tmp2 += hplane[i] * hplane[i]; - } - return (tmp1 + hplane[vectDim])/sqrt(tmp2); + +/* vector to orthogonal plane node distance */ +static float distV2orthoH (float* vect, float* hplane, int vectDim) +{ +// standard algebra computing + int i; + float tmp1 = 0; + float tmp2 = 0; + for(i = 0; i < vectDim; i++) + { + tmp1 += vect[i] * hplane[i]; + tmp2 += hplane[i] * hplane[i]; + } + return ((tmp1 + hplane[vectDim]) / sqrt(tmp2)); } -void splitPlaneCompute(Tree* t, int node, int level) { - int b; - int i; - //Level parameter gives the base vector to use - b = level % t->v_dim; - - //We compute an hyperplane which is orthogonal to the base vector number b - for(i = 0; i < t->v_dim; i++) { - t->splitPlane[node][i] = 0; - } - t->splitPlane[node][b] = 1; - t->splitPlane[node][t->v_dim] = -(t->meanVect[node][b]); - //printf("Splitplane of node %i: (%f, %f, %f)\n", node, t->splitPlane[node][0], t->splitPlane[node][1], t->splitPlane[node][2]); + +/* vector to general plane node distance */ +static float distV2orthoH (float* vect, float* plane, float* mean, int vectDim) +{ + // standard algebra computing + int i; + float tmp1 = 0; + float tmp2 = 0; + + for(i = 0; i < vectDim; i++) + { + tmp1 += (vect[i] - mean[i]) * hplane[i]; + tmp2 += hplane[i] * hplane[i]; + } + return (tmp1 / sqrt(tmp2)); } + +/* vector to node distance */ +static float distV2N (tree_t* t, int i, int n) +{ + switch (t->dmode) + { + case mode_orthogonal: + return distV2orthoH(fmat_get_ptr(t->data) + i * t->ndim, + fmat_get_ptr(t->nodes[i].split), t->ndim); + case mode_hyperplane: + return distV2H(fmat_get_ptr(t->data) + i * t->ndim, + fmat_get_ptr(t->nodes[i].split), t->ndim); + default: + fts_post("error: unknown mode %d", t->dmode); + return 0; + } +} + + +static void compute_splitplane (tree_t* t, int node, int level) +{ + int b; + int i; + float h; + + // Level parameter gives the base vector to use + b = level % t->ndim; + h = fmat_get_element(t->nodes[node].mean, b, 0); + + // We compute an hyperplane which is orthogonal to the base vector number b + fmat_set_const(t->nodes[node].split, 0); + + fmat_set_element(t->nodes[node].split, b, 0, 1); + fmat_set_element(t->nodes[node].split, t->ndim, 0, -h); + +// fts_post("Splitplane of node %i: (%f, %f, %f)\n", node, t->split[node][0], +// t->split[node][1], t->split[node][2]); +} + /* Only for debugging */ -void tree_info_display(Tree* t) { - int i, j; - printf("\nTree Info:\n"); - printf("**********\n\n"); - printf("v_dim = %i\n", t->v_dim); - printf("v_number = %i\n", t->v_number); - printf("height = %i\n", t->height); - printf("n_number = %i\n", t->n_number); - for(i = 0; i < t->v_number; i++) { - printf("data #%i = [", i); - for(j = 0; j < (t->v_dim - 1); j++) { - printf("%.1f, ", t->data[i][j]); - } - printf("%.1f]\n", t->data[i][t->v_dim - 1]); +static void tree_info_display (tree_t* t) +{ + int i, j; + fts_post("\nTree Info:\n"); + fts_post("**********\n\n"); + fts_post("ndim = %i\n", t->ndim); + fts_post("ndata = %i\n", t->ndata); + fts_post("height = %i\n", t->height); + fts_post("n_number = %i\n", t->nnodes); + for(i = 0; i < t->ndata; i++) + { + fts_post("raw data #%i = [", i); + for(j = 0; j < t->ndim; j++) + { + fts_post("%.1f, ", fmat_get_element(t->data, i, j)); } + fts_post("]\n"); + } } -void tree_display(Tree* t) { - int l, n, i, j; - printf("\nTree Display:\n"); - printf("*************\n\n"); +static void tree_display(tree_t* t) +{ + int l, n, i, j; + fts_post("\nTree Display:\n"); + fts_post("*************\n\n"); - for(l = 0; l < t->height; l++) { - printf("Level #%i ", l); - for(n = pow2(l) - 1; n < pow2(l+1) - 1; n++) { - printf("("); - for(i = t->n_begin[n]; i <= t->n_end[n]; i++) { - printf("["); - for(j = 0; j < (t->v_dim - 1); j++) { - printf("%.1f, ", t->data[i][j]); - } - printf("%.1f]", t->data[i][t->v_dim - 1]); - } - printf(")"); + for(l = 0; l < t->height; l++) + { + fts_post("Level #%i ", l); + for(n = pow2(l) - 1; n < pow2(l+1) - 1; n++) + { + fts_post("("); + for(i = t->nodes[n].startind; i <= t->nodes[n].endind; i++) + { + fts_post("["); + for(j = 0; j < t->ndim; j++) + { + fts_post("%.1f, ", tree_get_element(t, i, j)); } - printf("\n"); + fts_post("]"); + } + fts_post(")"); } + fts_post("\n"); + } } -void freeVect(Tree* t, int vect_number) { - t->data[vect_number][0] = MAX_FLOAT; +void freeVect (tree_t* t, int vect_number) +{ + fmat_set_const(t->data, MAX_FLOAT); } -void reBalance(Tree* t) { - int i = 0; - int j = t->v_number - 1; +#if 0 +void reBalance(tree_t* t) +{ + int i = 0; + int j = t->ndata - 1; - /* Sort */ - while(j > i) { - while((t->data[i][0] != MAX_FLOAT)&&(i < t->v_number)) { - i++; - } - while((t->data[j][0] == MAX_FLOAT)&&(j >=0 )) { - j--; - } - if(j > i) { - swap(t, i, j); - } + /* Sort */ + while(j > i) + { + while((t->data[i][0] != MAX_FLOAT)&&(i < t->ndata)) + { + i++; } - t->v_number = i; - t->n_end[0] = t->v_number - 1; - decompose(t); + while((t->data[j][0] == MAX_FLOAT)&&(j >=0 )) + { + j--; + } + if(j > i) + { + swap(t, i, j); + } + } + t->ndata = i; + t->nodes[0].endind = t->ndata - 1; + + tree_build(t); } +#endif -void decompose(Tree* t) { - int l; //current level number - int n; //current node number - int i, j; //loop counters + +void tree_build (tree_t* t) +{ + int l; // current level number + int n; // current node number + int i, j; // loop counters - /* Maximum length is equal to pow2(height-1) */ - if(pow2(t->height-1) > t->v_number) { - printf("error: can't build this tree, try with a smaller height: %i > %i\n" - ,pow2(t->height-1),t->v_number); - exit(0); - } + /* Maximum length is equal to pow2(height-1) */ + if (pow2(t->height-1) > t->ndata) + { + if (t->ndata == 0) + fts_post("tree is empty! \n"); + else + fts_post("error: can't build this tree, try with a smaller height: %i > %i\n", pow2(t->height-1), t->ndata); - for(l = 0; l < (t->height); l++) { - //printf("\n\nLevel#%i\n", l); + return; + } + + for (l = 0; l < t->height; l++) + { + fts_post("\n\nLevel#%i\n", l); - for(n = pow2(l) - 1; n < pow2(l+1) - 1; n++) { - meanVectCompute(t, n); - splitPlaneCompute(t, n, l); - /*printf("\nNode #%i (%i->%i): meanVect = (%f,%f)\n",n,t->n_begin[n],t->n_end[n], - t->meanVect[n][0], t->meanVect[n][1]);*/ + for (n = pow2(l) - 1; n < pow2(l+1) - 1; n++) + { + compute_mean(t, n); + compute_splitplane(t, n, l); + /*fts_post("\nNode #%i (%i->%i): mean = (%f,%f)\n", n, t->nodes[n].startind, + t->nodes[n].endind, t->mean[n][0], t->mean[n][1]);*/ - i = t->n_begin[n]; - j = t->n_end[n]; + i = t->nodes[n].startind; + j = t->nodes[n].endind; - while(j > i) { - while(distV2H(t->data[i], t->splitPlane[n], t->v_dim) <= 0) { - i++; - - //printf("i=%i\n", i); - } - while(distV2H(t->data[j], t->splitPlane[n], t->v_dim) > 0) { - j--; - //printf("j=%i\n", j); - } - if(j > i) { - swap(t, i, j); - //printf("swap %i and %i\n",i ,j); - } - } + while (j > i) + { + while (distV2N(t, i, n) <= 0) + { + i++; + // fts_post("i=%i\n", i); + } + while (distV2N(t, j, n) > 0) + { + j--; + // fts_post("j=%i\n", j); + } + if (j > i) + { + swap(t, i, j); + // fts_post("swap %i and %i\n", i ,j); + } + } - t->n_begin[2*n+1] = t->n_begin[n]; //begining index of left child of node n - t->n_end[2*n+1] = j; //ending index of left child of node n - t->n_begin[2*n+2] = i; //begining index of left child of node n - t->n_end[2*n+2] = t->n_end[n]; //ending index of left child of node n - } + t->nodes[2*n+1].startind = t->nodes[n].startind; // start index of left child of node n + t->nodes[2*n+1].endind = j; // end index of left child of node n + t->nodes[2*n+2].startind = i; // start index of right child of node n + t->nodes[2*n+2].endind = t->nodes[n].endind; // end index of right child of node n } + } } -void buildTree(Tree* t, int dim, int h, int vnum) { - initTree(t , dim, h, vnum); - decompose(t); -} +void tree_init (tree_t* t, int h, int dim, int vect_num) +{ + int i; + t->ndim = dim; + t->ndata = vect_num; + t->height = h; + + /* init nodes */ + t->nnodes = pow2(h) - 1; + t->nodes = fts_realloc(t->nodes, t->nnodes * sizeof(node_t)); + + for (i = 0; i < t->nnodes; i++) + { + t->nodes[i].mean = fmat_create(dim, 1); + t->nodes[i].split = fmat_create(dim + 1, 1); + + fts_object_refer((fts_object_t *) t->nodes[i].mean); + fts_object_refer((fts_object_t *) t->nodes[i].split); + } + + /* init root node */ + t->nodes[0].startind = 0; + t->nodes[0].endind = t->ndata - 1; + + /* init index list */ + t->dataindex = fts_realloc(t->dataindex, t->ndata * sizeof(int)); + + for (i = 0; i < t->ndata; i++) + t->dataindex[i] = i; +} Modified: trunk/ftm/ftmlib/classes/treesearch.c =================================================================== --- trunk/ftm/ftmlib/classes/treesearch.c 2008-07-17 10:55:48 UTC (rev 1822) +++ trunk/ftm/ftmlib/classes/treesearch.c 2008-07-18 10:35:56 UTC (rev 1823) @@ -1,4 +1,6 @@ -#include "Tree.h" +#if 0 + +#include "tree.h" #include <stdlib.h> #include <math.h> @@ -13,7 +15,7 @@ void push(stack* s, couple c) { s->sp++; - if(s->sp >= MAX_NODES) printf("Warning: Stack capacity is attented [sp = %i]\n", s->sp); + if(s->sp >= 100) printf("Warning: Stack capacity is attented [sp = %i]\n", s->sp); s->c[s->sp].node = c.node; s->c[s->sp].dist = c.dist; } @@ -138,3 +140,4 @@ } +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bor...@us...> - 2008-07-17 10:55:48
|
Revision: 1822 http://ftm.svn.sourceforge.net/ftm/?rev=1822&view=rev Author: borghesi Date: 2008-07-17 10:55:48 +0000 (Thu, 17 Jul 2008) Log Message: ----------- ftm.editor: fixed bug in InfoPanel Modified Paths: -------------- trunk/ftm/gui/Juce/common/InfoPanel.cpp Modified: trunk/ftm/gui/Juce/common/InfoPanel.cpp =================================================================== --- trunk/ftm/gui/Juce/common/InfoPanel.cpp 2008-07-17 10:44:13 UTC (rev 1821) +++ trunk/ftm/gui/Juce/common/InfoPanel.cpp 2008-07-17 10:55:48 UTC (rev 1822) @@ -124,9 +124,10 @@ { if(container->getEditorsSize() > 0) { - int ed_x, ed_w; + int ed_w; int ed_right = 0; int dscroll_x = (container->isDScrollVisible()) ? container->getDScrollSize() : 0; + int ed_x = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(container->getEditors()[0]))->getX() + dscroll_x; if(container->isTabsVisible()) //draw top rectangle { ed_x = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(container->getEditors()[0]))->getX() + dscroll_x; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-17 10:44:12
|
Revision: 1821 http://ftm.svn.sourceforge.net/ftm/?rev=1821&view=rev Author: diemo Date: 2008-07-17 10:44:13 +0000 (Thu, 17 Jul 2008) Log Message: ----------- Tree.h by Sebastien Gulluni, 8.6.2008 Added Paths: ----------- trunk/ftm/ftmlib/classes/treedefs.h Added: trunk/ftm/ftmlib/classes/treedefs.h =================================================================== --- trunk/ftm/ftmlib/classes/treedefs.h (rev 0) +++ trunk/ftm/ftmlib/classes/treedefs.h 2008-07-17 10:44:13 UTC (rev 1821) @@ -0,0 +1,112 @@ +#include <stdio.h> + +#define MAX_DIM 10 +#define MAX_VECT 20 +#define MAX_NODES 100 + +#define MAX_FLOAT 0x7FFFFFFF + +typedef struct coupleNodeDist { + int node; + float dist; +} couple; + +typedef struct searchStack { + couple c[MAX_NODES]; + int sp; +} stack; + +typedef struct SearchTree { + int v_dim; //Dimention of vectors + int v_number; //Number of vectors + int height; //Height of the tree + int n_number; //Number of nodes (must be a power of 2) + int n_begin[MAX_NODES]; //n_begin[i] = begining index of the node i + int n_end[MAX_NODES]; //n_end[i] = ending index of the node i + float data[MAX_VECT][MAX_DIM]; //Matrix of vectors + float meanVect[MAX_NODES][MAX_DIM]; //Matrix of mean vectors + float splitPlane[MAX_NODES][MAX_DIM+1]; //Matrix of hyperplanes: A1*X1 + A2*X2 +...+ An*Xn + An+1 = 0 + stack s; //Stack of couple (node number, distance to vector) +} Tree; + + + +/* Init Tree object */ +void initTree(Tree* t, int dim, int height, int vect_num); + +/* Returns 2^x */ +int pow2(int x); + +/* Compute the "mean vector" of a vector list beetween index begin and end */ +void meanVectCompute(Tree* t, int node); + +/* Compute a "split plane" which is orthogonal to the base vectors */ +void splitPlaneCompute(Tree* t, int node, int level); + + +/* + Compare the current vector to an hyperplane in a simple way. + Returns distance. +*/ +int compare(float* currentVect, float* meanVect, int component); + +/* Return the orthogonal distance from a vector to an hyperplane */ +float distV2H(float* vect, float* hplane, int vectDim); + +/* + Compare the current vector to an hyperplane. + Returns 1 if the result is positive else return 0. + bool compare(Vector currentVect, Vector meanvect); +*/ + + +/* Standard exchange beetween two vectors of a Tree object */ +void swap(Tree* t, int i, int j); + + +/* Decomposition algorithm */ +void decompose(Tree* t); + + +/* Building the Tree */ +void buildTree(Tree* t, int dim, int component, int vnum); + +/* Mark a vector to be deleted at the next call of reBuild function */ +void freeVect(Tree* t, int vect_number); + +/* Rebuild the tree (can bee nescessary if you had free or inserted some vectors) */ +void reBalance(Tree* t); + + +/* Show informations about a tree structure */ +void tree_info_display(Tree* t); + + +/* Display a Tree structure */ +void tree_display(Tree* t); + + +/******************************* Functions used in search procedure *********************************/ + +/* Search the k nearest neighbours of a vector by using a search tree */ +int* search(Tree* t, int k, float* vector); + +/* Maximum of a */ +float max(float a, float b); + +/* returns index of the maximum value of an array */ +int maxArr(float* array, int size); + +/* returns Euclidian distance of two vectors without square root */ +float euclidianDistance(float* v1, float* v2, int dim); + +/* Methods for the stack */ +void initStack(stack* s); +int isEmpty(stack s); +void push(stack* s, couple c); +couple pop(stack* s); +void displayStack(stack s); + +/* Function used to work with couples of (node, value) */ +void displayCouple(couple c); +void coupleBuild(couple* c, int n, float d); Property changes on: trunk/ftm/ftmlib/classes/treedefs.h ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-17 10:43:24
|
Revision: 1820 http://ftm.svn.sourceforge.net/ftm/?rev=1820&view=rev Author: diemo Date: 2008-07-17 10:43:28 +0000 (Thu, 17 Jul 2008) Log Message: ----------- TreeBuild.c by Sebastien Gulluni, 8.6.2008 Added Paths: ----------- trunk/ftm/ftmlib/classes/treebuild.c Added: trunk/ftm/ftmlib/classes/treebuild.c =================================================================== --- trunk/ftm/ftmlib/classes/treebuild.c (rev 0) +++ trunk/ftm/ftmlib/classes/treebuild.c 2008-07-17 10:43:28 UTC (rev 1820) @@ -0,0 +1,195 @@ +#include "Tree.h" +#include <stdlib.h> +#include <math.h> + + +int pow2(int x) { + if(x == 0) return 1; + else return 2*pow2(x - 1); +} + +void initTree(Tree* t, int dim, int h, int vect_num) { + t->v_dim = dim; + t->v_number = vect_num; + t->height = h; + t->n_number = pow2(h) - 1; + t->n_begin[0] = 0; //Init root node : + t->n_end[0] = t->v_number - 1; //Vectors are indexed from 0 to v_number - 1 + initStack(&t->s); //Init stack +} + +void meanVectCompute(Tree* t, int node) { + int i, j; + float tmp; + int n_nvector = t->n_end[node] - t->n_begin[node] + 1; // number of vectors from the processed node + for(j = 0; j <= t->v_dim; j++) { + tmp = 0; + for(i = t->n_begin[node]; i <= t->n_end[node]; i++) { + tmp += t->data[i][j]; + } + t->meanVect[node][j] = tmp / n_nvector; + } +} + +int compare(float* currentVect, float* meanVect, int component) { + //printf("compare %f and %f\n", meanVect[component], currentVect[component]); + return (currentVect[component] - meanVect[component]); +} + +void swap(Tree* t, int i, int j) { + int tmp; + int comp; + for(comp = 0; comp < t->v_dim; comp++) { + tmp = t->data[i][comp]; + t->data[i][comp] = t->data[j][comp]; + t->data[j][comp] = tmp; + } +} + +float distV2H(float* vect, float* hplane, int vectDim) { + //standard algebra computing + int i; + float tmp1 = 0; + float tmp2 = 0; + for(i = 0; i < vectDim; i++) { + tmp1 += vect[i]*hplane[i]; + tmp2 += hplane[i] * hplane[i]; + } + return (tmp1 + hplane[vectDim])/sqrt(tmp2); +} + +void splitPlaneCompute(Tree* t, int node, int level) { + int b; + int i; + //Level parameter gives the base vector to use + b = level % t->v_dim; + + //We compute an hyperplane which is orthogonal to the base vector number b + for(i = 0; i < t->v_dim; i++) { + t->splitPlane[node][i] = 0; + } + t->splitPlane[node][b] = 1; + t->splitPlane[node][t->v_dim] = -(t->meanVect[node][b]); + //printf("Splitplane of node %i: (%f, %f, %f)\n", node, t->splitPlane[node][0], t->splitPlane[node][1], t->splitPlane[node][2]); +} + +/* Only for debugging */ + +void tree_info_display(Tree* t) { + int i, j; + printf("\nTree Info:\n"); + printf("**********\n\n"); + printf("v_dim = %i\n", t->v_dim); + printf("v_number = %i\n", t->v_number); + printf("height = %i\n", t->height); + printf("n_number = %i\n", t->n_number); + for(i = 0; i < t->v_number; i++) { + printf("data #%i = [", i); + for(j = 0; j < (t->v_dim - 1); j++) { + printf("%.1f, ", t->data[i][j]); + } + printf("%.1f]\n", t->data[i][t->v_dim - 1]); + } +} + +void tree_display(Tree* t) { + int l, n, i, j; + printf("\nTree Display:\n"); + printf("*************\n\n"); + + for(l = 0; l < t->height; l++) { + printf("Level #%i ", l); + for(n = pow2(l) - 1; n < pow2(l+1) - 1; n++) { + printf("("); + for(i = t->n_begin[n]; i <= t->n_end[n]; i++) { + printf("["); + for(j = 0; j < (t->v_dim - 1); j++) { + printf("%.1f, ", t->data[i][j]); + } + printf("%.1f]", t->data[i][t->v_dim - 1]); + } + printf(")"); + } + printf("\n"); + } +} + +void freeVect(Tree* t, int vect_number) { + t->data[vect_number][0] = MAX_FLOAT; +} + +void reBalance(Tree* t) { + int i = 0; + int j = t->v_number - 1; + + /* Sort */ + while(j > i) { + while((t->data[i][0] != MAX_FLOAT)&&(i < t->v_number)) { + i++; + } + while((t->data[j][0] == MAX_FLOAT)&&(j >=0 )) { + j--; + } + if(j > i) { + swap(t, i, j); + } + } + t->v_number = i; + t->n_end[0] = t->v_number - 1; + decompose(t); +} + +void decompose(Tree* t) { + int l; //current level number + int n; //current node number + int i, j; //loop counters + + /* Maximum length is equal to pow2(height-1) */ + if(pow2(t->height-1) > t->v_number) { + printf("error: can't build this tree, try with a smaller height: %i > %i\n" + ,pow2(t->height-1),t->v_number); + exit(0); + } + + for(l = 0; l < (t->height); l++) { + //printf("\n\nLevel#%i\n", l); + + for(n = pow2(l) - 1; n < pow2(l+1) - 1; n++) { + meanVectCompute(t, n); + splitPlaneCompute(t, n, l); + /*printf("\nNode #%i (%i->%i): meanVect = (%f,%f)\n",n,t->n_begin[n],t->n_end[n], + t->meanVect[n][0], t->meanVect[n][1]);*/ + + i = t->n_begin[n]; + j = t->n_end[n]; + + while(j > i) { + while(distV2H(t->data[i], t->splitPlane[n], t->v_dim) <= 0) { + i++; + + //printf("i=%i\n", i); + } + while(distV2H(t->data[j], t->splitPlane[n], t->v_dim) > 0) { + j--; + //printf("j=%i\n", j); + } + if(j > i) { + swap(t, i, j); + //printf("swap %i and %i\n",i ,j); + } + } + + t->n_begin[2*n+1] = t->n_begin[n]; //begining index of left child of node n + t->n_end[2*n+1] = j; //ending index of left child of node n + t->n_begin[2*n+2] = i; //begining index of left child of node n + t->n_end[2*n+2] = t->n_end[n]; //ending index of left child of node n + } + } +} + +void buildTree(Tree* t, int dim, int h, int vnum) { + initTree(t , dim, h, vnum); + decompose(t); +} + + Property changes on: trunk/ftm/ftmlib/classes/treebuild.c ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2008-07-17 10:42:21
|
Revision: 1819 http://ftm.svn.sourceforge.net/ftm/?rev=1819&view=rev Author: diemo Date: 2008-07-17 10:42:19 +0000 (Thu, 17 Jul 2008) Log Message: ----------- Search.c by Sebastien Gulluni, 8.6.2008 Added Paths: ----------- trunk/ftm/ftmlib/classes/treesearch.c Added: trunk/ftm/ftmlib/classes/treesearch.c =================================================================== --- trunk/ftm/ftmlib/classes/treesearch.c (rev 0) +++ trunk/ftm/ftmlib/classes/treesearch.c 2008-07-17 10:42:19 UTC (rev 1819) @@ -0,0 +1,140 @@ +#include "Tree.h" +#include <stdlib.h> +#include <math.h> + +void initStack(stack* s) { + s->sp = -1; +} + +int isEmpty(stack s) { + if(s.sp < 0) return 1; + return 0; +} + +void push(stack* s, couple c) { + s->sp++; + if(s->sp >= MAX_NODES) printf("Warning: Stack capacity is attented [sp = %i]\n", s->sp); + s->c[s->sp].node = c.node; + s->c[s->sp].dist = c.dist; +} + +couple pop(stack* s) { + if(s->sp < 0) printf("Warning: Stack is empty, poped values may be inderteminated [sp = %i]\n", s->sp); + couple tmp = s->c[s->sp]; + s->sp--; + return tmp; +} + + +void displayStack(stack s) { + int i = s.sp; + if(s.sp < 0) printf("Stack is empty\n"); + else { + printf("Top of stack\n"); + while(i >= 0) { + printf("( %i, %f)\n", s.c[i].node, s.c[i].dist); + i--; + } + printf("Bottom of stack\n\n"); + } +} + +void displayCouple(couple c) { + printf("Couple( %i, %f)\n", c.node, c.dist); +} + +void coupleBuild(couple* c, int n, float d) { + c->node = n; + c->dist = d; +} + +float max(float a, float b) { + return (a > b)? a : b; +} + + +int maxArr(float* array, int size) { + int index = 0; + int i; + + for(i = 1; i<size; i++) { + if(array[index] < array[i]) index = i; + } + + return index; +} + +float euclidianDistance(float* v1, float* v2, int dim) { + int i; + float tmp = 0; + for(i = 0; i < dim; i++) { + tmp = tmp + ((v1[i] - v2[i])*(v1[i] - v2[i])); + } + return tmp; +} + +int* search(Tree* t, int k, float* x) { + float d[k]; //vector to vector distance from vector y[k] to vector x + int* y; //y[K] = index of the Kth neirest neighbour + int i; //current processed vector + float dxx; //dxx = distance between 2 vectors + int kmax = 0; //index of current Kth neighbour + y = (int*)malloc(k*sizeof(int)); + couple cur; //current (node, dist) couple + + //Init distances + for(i = 0; i < k; i++) { + d[i] = MAX_FLOAT; + } + + //Init Search Stack + coupleBuild(&cur, 0, 0); + push(&t->s, cur); + + while(!isEmpty(t->s)) { + displayStack(t->s); + cur = pop(&t->s); + displayStack(t->s); + if(cur.dist < d[kmax]) { //elimination rule + if(cur.node >= (pow2(t->height - 1) - 1)) { //leaf node + //printf("Je suis une feuille: p = %i\n", cur.node); + i = t->n_begin[cur.node]; + while(i <= t->n_end[cur.node]) { + dxx = euclidianDistance(x, t->data[i], t->v_dim); + //printf("la distance entre le vecteur %i et x est de: %f\n",i ,dxx); + if(dxx < d[kmax]) { + y[kmax] = i; + d[kmax] = dxx; + kmax = maxArr(d, k); + } + i++; + } + } + else { //branched node + float d; + //printf("Je suis un noeud: p = %i\n", cur.node); + d = distV2H(x, t->splitPlane[cur.node], t->v_dim); + if(d < 0) { + couple c1; + couple c2; + coupleBuild(&c1, 2*cur.node+2, max(cur.dist, d*d)); + coupleBuild(&c2, 2*cur.node+1, cur.dist); + push(&t->s, c1); + push(&t->s, c2); + } + else { + //printf("Je suis un noeud: p = %i\n", cur.node); + couple c1; + couple c2; + coupleBuild(&c1, 2*cur.node+1, max(cur.dist, d*d)); + coupleBuild(&c2, 2*cur.node+2, cur.dist); + push(&t->s, c1); + push(&t->s, c2); + } + } + } + } + return y; +} + + Property changes on: trunk/ftm/ftmlib/classes/treesearch.c ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bor...@us...> - 2008-07-17 10:28:34
|
Revision: 1818 http://ftm.svn.sourceforge.net/ftm/?rev=1818&view=rev Author: borghesi Date: 2008-07-17 10:28:27 +0000 (Thu, 17 Jul 2008) Log Message: ----------- ftm.Editor: fixed bug in table view Modified Paths: -------------- trunk/ftm/gui/Juce/common/ScoreTableView.cpp Modified: trunk/ftm/gui/Juce/common/ScoreTableView.cpp =================================================================== --- trunk/ftm/gui/Juce/common/ScoreTableView.cpp 2008-07-17 09:52:13 UTC (rev 1817) +++ trunk/ftm/gui/Juce/common/ScoreTableView.cpp 2008-07-17 10:28:27 UTC (rev 1818) @@ -245,15 +245,10 @@ owner.scoreGui->move(owner.obj, evt, row, text.getFloatValue()); break; case 2: - //owner.scoreGui->setCue(owner.obj, evt, row, text.getIntValue()); + owner.scoreGui->setPitch(owner.obj, evt, row, text.getFloatValue()); break; case 3: - int len = text.length(); - char *buff = (char *)alloca(sizeof(char) * (len+1)); - text.copyToBuffer(buff, len); - buff[len] = '\0'; - buff[len+1] = '\0'; - //owner.scoreGui->setLabel(owner.obj, evt, row, buff); + owner.scoreGui->setDuration(owner.obj, evt, row, text.getFloatValue()); break; } owner.parent->objectRefresh(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bor...@us...> - 2008-07-17 09:52:30
|
Revision: 1817 http://ftm.svn.sourceforge.net/ftm/?rev=1817&view=rev Author: borghesi Date: 2008-07-17 09:52:13 +0000 (Thu, 17 Jul 2008) Log Message: ----------- ftm.editor: finalized ScoreEditor (for testing track and mat classes implements score_gui_interface) Modified Paths: -------------- trunk/ftm/build/max/osx-macho/ftmexternals.xcodeproj/project.pbxproj trunk/ftm/ftmlib/classes/mat.c trunk/ftm/ftmlib/classes/track.c trunk/ftm/gui/Juce/common/InfoPanel.cpp trunk/ftm/gui/Juce/common/ScoreEditor.cpp Modified: trunk/ftm/build/max/osx-macho/ftmexternals.xcodeproj/project.pbxproj =================================================================== --- trunk/ftm/build/max/osx-macho/ftmexternals.xcodeproj/project.pbxproj 2008-07-15 16:41:27 UTC (rev 1816) +++ trunk/ftm/build/max/osx-macho/ftmexternals.xcodeproj/project.pbxproj 2008-07-17 09:52:13 UTC (rev 1817) @@ -115,7 +115,6 @@ 2195DE0309A24A63007DEFAF /* MaxAudioAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B1B82C806D4A733009827F3 /* MaxAudioAPI.framework */; }; 2195DE0B09A24AA6007DEFAF /* ftm.sdif.write.c in Sources */ = {isa = PBXBuildFile; fileRef = 2195DDA709A24A4A007DEFAF /* ftm.sdif.write.c */; }; 3B01D3090A790E2A00950F15 /* ftm.sqlite.c in Sources */ = {isa = PBXBuildFile; fileRef = 3B01D3080A790E2A00950F15 /* ftm.sqlite.c */; }; - 3B04C2930CABBEDC00AA02B0 /* BpfTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B04C2920CABBEDC00AA02B0 /* BpfTableView.cpp */; }; 3B145DBA0CBA86FF0013392A /* EditorContainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B145DB80CBA86FE0013392A /* EditorContainer.cpp */; }; 3B145DBB0CBA86FF0013392A /* EditorContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B145DB90CBA86FF0013392A /* EditorContainer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3B1982C40A55805600B2841E /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B1B822E06D4A70F009827F3 /* Carbon.framework */; }; @@ -193,12 +192,12 @@ 3B4E71160CC8E399006DFB5A /* MarkersTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B4E71150CC8E399006DFB5A /* MarkersTableView.cpp */; }; 3B7073BE0713F12300764C51 /* ftm.list.c in Sources */ = {isa = PBXBuildFile; fileRef = 3B7073BD0713F04500764C51 /* ftm.list.c */; }; 3B8DE0FC0E10F962000757BC /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B8DE0FB0E10F962000757BC /* AppKit.framework */; }; - 3B9C563A0D5DF07000051CD5 /* TrackScoobEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B9C56390D5DF07000051CD5 /* TrackScoobEditor.cpp */; }; 3B9D37B30E1CD6CC002ED38C /* EditorContainerListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B9D37B10E1CD6CC002ED38C /* EditorContainerListener.h */; }; 3B9D37B40E1CD6CC002ED38C /* InfoPanel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B9D37B20E1CD6CC002ED38C /* InfoPanel.cpp */; }; 3BA368CD0E0A60050011055C /* libjuce.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BDB04330D197490006AEB4A /* libjuce.a */; }; 3BA9E3B80E2513A500B88643 /* ScoreEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BA9E3B60E2513A500B88643 /* ScoreEditor.cpp */; }; 3BA9E3B90E2513A500B88643 /* ScoreTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BA9E3B70E2513A500B88643 /* ScoreTableView.cpp */; }; + 3BBD0E020E261F6D0074EE11 /* BpfTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BBD0E010E261F6D0074EE11 /* BpfTableView.cpp */; }; 3BCAC5EC0CBE5E7E00020156 /* FvecEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BCAC5EB0CBE5E7E00020156 /* FvecEditor.cpp */; }; 3BDB03F40D197463006AEB4A /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BDB03F30D197463006AEB4A /* IOKit.framework */; }; 3BDB03F50D197463006AEB4A /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BDB03F30D197463006AEB4A /* IOKit.framework */; }; @@ -216,12 +215,9 @@ 3BDF29390D06C28800436BD5 /* MarkersTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B4E71150CC8E399006DFB5A /* MarkersTableView.cpp */; }; 3BDF293B0D06C28800436BD5 /* FvecEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BCAC5EB0CBE5E7E00020156 /* FvecEditor.cpp */; }; 3BDF293C0D06C28800436BD5 /* EditorContainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B145DB80CBA86FE0013392A /* EditorContainer.cpp */; }; - 3BDF293D0D06C28800436BD5 /* BpfTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B04C2920CABBEDC00AA02B0 /* BpfTableView.cpp */; }; 3BDF293E0D06C28800436BD5 /* EditorScrollBar.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B02948C0C1FEBD500E7AB82 /* EditorScrollBar.cpp */; }; 3BDF293F0D06C28800436BD5 /* BpfEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B35E1950C05AD6D00567CE9 /* BpfEditor.cpp */; }; 3BDF29400D06C28800436BD5 /* SpectrogramEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BFB5BB10CF860BF00FB74F9 /* SpectrogramEditor.cpp */; }; - 3BDF2B870D07201800436BD5 /* InspectorContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3BDF2B860D07201800436BD5 /* InspectorContainer.h */; }; - 3BDF2B8B0D07203500436BD5 /* InspectorContainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BDF2B8A0D07203500436BD5 /* InspectorContainer.cpp */; }; 3BE10D990DC756E10023645B /* ScrollZoomTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BE10D980DC756E10023645B /* ScrollZoomTool.cpp */; }; 3BE501400D059384006C9C44 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B0897A10B8B64520058107D /* CoreAudio.framework */; }; 3BE501410D059384006C9C44 /* AGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B0682850C29369A00D78875 /* AGL.framework */; }; @@ -574,7 +570,6 @@ 3B01D3080A790E2A00950F15 /* ftm.sqlite.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = ftm.sqlite.c; sourceTree = "<group>"; }; 3B02948C0C1FEBD500E7AB82 /* EditorScrollBar.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = EditorScrollBar.cpp; sourceTree = "<group>"; }; 3B03F9840CAA96E7001C491B /* libjucedebug.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjucedebug.a; path = ../../../components/juce/bin/libjucedebug.a; sourceTree = "<group>"; }; - 3B04C2920CABBEDC00AA02B0 /* BpfTableView.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = BpfTableView.cpp; sourceTree = "<group>"; }; 3B0682850C29369A00D78875 /* AGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AGL.framework; path = /System/Library/Frameworks/AGL.framework; sourceTree = "<absolute>"; }; 3B0682DB0C2937D200D78875 /* EditorScrollBar.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = EditorScrollBar.h; sourceTree = "<group>"; }; 3B0897A10B8B64520058107D /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = /System/Library/Frameworks/CoreAudio.framework; sourceTree = "<absolute>"; }; @@ -618,11 +613,11 @@ 3B4E71150CC8E399006DFB5A /* MarkersTableView.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MarkersTableView.cpp; sourceTree = "<group>"; }; 3B7073BD0713F04500764C51 /* ftm.list.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = ftm.list.c; sourceTree = "<group>"; }; 3B8DE0FB0E10F962000757BC /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; }; - 3B9C56390D5DF07000051CD5 /* TrackScoobEditor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = TrackScoobEditor.cpp; sourceTree = "<group>"; }; 3B9D37B10E1CD6CC002ED38C /* EditorContainerListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditorContainerListener.h; sourceTree = "<group>"; }; 3B9D37B20E1CD6CC002ED38C /* InfoPanel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InfoPanel.cpp; sourceTree = "<group>"; }; 3BA9E3B60E2513A500B88643 /* ScoreEditor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScoreEditor.cpp; sourceTree = "<group>"; }; 3BA9E3B70E2513A500B88643 /* ScoreTableView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScoreTableView.cpp; sourceTree = "<group>"; }; + 3BBD0E010E261F6D0074EE11 /* BpfTableView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BpfTableView.cpp; sourceTree = "<group>"; }; 3BCAC5EB0CBE5E7E00020156 /* FvecEditor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FvecEditor.cpp; sourceTree = "<group>"; }; 3BDB03F30D197463006AEB4A /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; }; 3BDB04330D197490006AEB4A /* libjuce.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjuce.a; path = ../../../components/juce/bin/UninstalledProducts/libjuce.a; sourceTree = SOURCE_ROOT; }; @@ -632,8 +627,6 @@ 3BDD17CB0DCF11B100E6ED8C /* RegionTool.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RegionTool.cpp; sourceTree = "<group>"; }; 3BDD54C50DC5DD970047D21D /* EditorTool.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = EditorTool.h; sourceTree = "<group>"; }; 3BDD54C60DC5DD970047D21D /* EditTool.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = EditTool.cpp; sourceTree = "<group>"; }; - 3BDF2B860D07201800436BD5 /* InspectorContainer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = InspectorContainer.h; sourceTree = "<group>"; }; - 3BDF2B8A0D07203500436BD5 /* InspectorContainer.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorContainer.cpp; sourceTree = "<group>"; }; 3BE10D980DC756E10023645B /* ScrollZoomTool.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollZoomTool.cpp; sourceTree = "<group>"; }; 3BE501490D059384006C9C44 /* ftm.inspector.mxo */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ftm.inspector.mxo; sourceTree = BUILT_PRODUCTS_DIR; }; 3BE5016E0D059C5E006C9C44 /* ftm.inspector.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ftm.inspector.cpp; sourceTree = "<group>"; }; @@ -1141,6 +1134,7 @@ 3B35E1920C05AD2600567CE9 /* Juce */ = { isa = PBXGroup; children = ( + 3BBD0E010E261F6D0074EE11 /* BpfTableView.cpp */, 3B9D37B10E1CD6CC002ED38C /* EditorContainerListener.h */, 3B9D37B20E1CD6CC002ED38C /* InfoPanel.cpp */, 3BE7C48A0DEC385D00A0B7A5 /* ImtrEditor.h */, @@ -1153,7 +1147,6 @@ 3BDD54C50DC5DD970047D21D /* EditorTool.h */, 3BDD54C60DC5DD970047D21D /* EditTool.cpp */, 3B35E1950C05AD6D00567CE9 /* BpfEditor.cpp */, - 3B04C2920CABBEDC00AA02B0 /* BpfTableView.cpp */, 3B145DB80CBA86FE0013392A /* EditorContainer.cpp */, 3B145DB90CBA86FF0013392A /* EditorContainer.h */, 3BF594270DAA371D003FE0A6 /* EditorResizerBar.cpp */, @@ -1161,14 +1154,11 @@ 3B02948C0C1FEBD500E7AB82 /* EditorScrollBar.cpp */, 3B0682DB0C2937D200D78875 /* EditorScrollBar.h */, 3BCAC5EB0CBE5E7E00020156 /* FvecEditor.cpp */, - 3BDF2B8A0D07203500436BD5 /* InspectorContainer.cpp */, - 3BDF2B860D07201800436BD5 /* InspectorContainer.h */, 3B4E71150CC8E399006DFB5A /* MarkersTableView.cpp */, 3BA9E3B60E2513A500B88643 /* ScoreEditor.cpp */, 3BA9E3B70E2513A500B88643 /* ScoreTableView.cpp */, 3B40FAA50D351B7D00A25542 /* ScrollZoomListener.h */, 3BFB5BB10CF860BF00FB74F9 /* SpectrogramEditor.cpp */, - 3B9C56390D5DF07000051CD5 /* TrackScoobEditor.cpp */, ); name = Juce; path = ../../../gui/Juce/common; @@ -1343,7 +1333,6 @@ files = ( 3BDF29340D06C26800436BD5 /* EditorContainer.h in Headers */, 3BDF29370D06C26800436BD5 /* EditorScrollBar.h in Headers */, - 3BDF2B870D07201800436BD5 /* InspectorContainer.h in Headers */, 3B40FAA60D351B7D00A25542 /* ScrollZoomListener.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -3139,7 +3128,6 @@ 3B1CA7D40C467B12005F0280 /* ftm.editor.cpp in Sources */, 3B1CA7D20C467B12005F0280 /* BpfEditor.cpp in Sources */, 3B1CA7D30C467B12005F0280 /* EditorScrollBar.cpp in Sources */, - 3B04C2930CABBEDC00AA02B0 /* BpfTableView.cpp in Sources */, 3B145DBA0CBA86FF0013392A /* EditorContainer.cpp in Sources */, 3BCAC5EC0CBE5E7E00020156 /* FvecEditor.cpp in Sources */, 3B4E71160CC8E399006DFB5A /* MarkersTableView.cpp in Sources */, @@ -3153,6 +3141,7 @@ 3B9D37B40E1CD6CC002ED38C /* InfoPanel.cpp in Sources */, 3BA9E3B80E2513A500B88643 /* ScoreEditor.cpp in Sources */, 3BA9E3B90E2513A500B88643 /* ScoreTableView.cpp in Sources */, + 3BBD0E020E261F6D0074EE11 /* BpfTableView.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3172,12 +3161,9 @@ 3BDF29390D06C28800436BD5 /* MarkersTableView.cpp in Sources */, 3BDF293B0D06C28800436BD5 /* FvecEditor.cpp in Sources */, 3BDF293C0D06C28800436BD5 /* EditorContainer.cpp in Sources */, - 3BDF293D0D06C28800436BD5 /* BpfTableView.cpp in Sources */, 3BDF293E0D06C28800436BD5 /* EditorScrollBar.cpp in Sources */, 3BDF293F0D06C28800436BD5 /* BpfEditor.cpp in Sources */, 3BDF29400D06C28800436BD5 /* SpectrogramEditor.cpp in Sources */, - 3BDF2B8B0D07203500436BD5 /* InspectorContainer.cpp in Sources */, - 3B9C563A0D5DF07000051CD5 /* TrackScoobEditor.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Modified: trunk/ftm/ftmlib/classes/mat.c =================================================================== --- trunk/ftm/ftmlib/classes/mat.c 2008-07-15 16:41:27 UTC (rev 1816) +++ trunk/ftm/ftmlib/classes/mat.c 2008-07-17 09:52:13 UTC (rev 1817) @@ -29,6 +29,7 @@ fts_class_t *mat_class = NULL; static imtr_guiInterfaceMarkers *mat_gui_interface_markers = NULL; +static imtr_guiInterfaceScore *mat_gui_interface_score = NULL; static void mat_changed(mat_t *mat) @@ -402,7 +403,6 @@ { int old_m = mat_get_m(self); int old_n = mat_get_n(self); - int old_size = old_m * old_n; if(n < 1) n = 1; @@ -610,7 +610,6 @@ { int old_m = mat_get_m(self); int old_n = mat_get_n(self); - int old_size = old_m * old_n; if(n < 1) n = 1; @@ -622,7 +621,6 @@ else { int min_m = (m < old_m)? m: old_m; - int min_n = (n < old_n)? n: old_n; ma_reshape_grow_unsafe(self, m, n); ma_rearrange(self, min_m, old_n); @@ -2111,6 +2109,191 @@ return NULL; } +/************************************************************ + * + * Score Gui Interface + * + */ +static int +mat_gui_score_is_vector(void) +{ + return 1; +} + +static int +mat_gui_score_get_size(void *obj) +{ + return mat_get_m((mat_t *)obj); +} + +static double +mat_gui_score_get_duration(void *obj) +{ + int m = mat_get_m((mat_t *)obj); + int n = mat_get_n((mat_t *)obj); + if(m > 0 && n > 2) + { + fts_atom_t *time = mat_get_element( (mat_t *)obj, m-1, 0); + fts_atom_t *duration = mat_get_element( (mat_t *)obj, m-1, 2); + if(fts_is_number(time) && fts_is_number(duration)) return (fts_get_number_float(time) + fts_get_number_float(duration)); + } + return -1.0; +} +static void * +mat_gui_score_get_by_index(void *obj, int index, double *time, double *pitch, double *duration) +{ + int m = mat_get_m((mat_t *)obj); + int n = mat_get_n((mat_t *)obj); + + *time = -1.0; + *pitch = -1.0; + *duration = -1.0; + if((m > 0 && n > 2) && (index >= 0 && index < m)) + { + fts_atom_t *val; + /* time */ + val = mat_get_element( (mat_t *)obj, index, 0); + if(fts_is_number(val)) *time = fts_get_number_float(val); + /* pitch */ + val = mat_get_element( (mat_t *)obj, index, 1); + if(fts_is_number(val)) *pitch = fts_get_number_float(val); + /* duration */ + val = mat_get_element( (mat_t *)obj, index, 2); + if(fts_is_number(val)) *duration = fts_get_number_float(val); + } + return NULL; +} + +static void * +mat_gui_score_add(void *obj, double time, double pitch, double duration) +{ + int m = mat_get_m((mat_t *)obj); + float evt_time; + int i; + fts_atom_t k; + for(i = 0; i < m; i++) + { + evt_time = fts_get_number_float(mat_get_element( (mat_t *)obj, i, 0)); + if(evt_time > time) + break; + } + mat_insert_rows((mat_t *)obj, i, 1); + + fts_set_float(&k, time); + mat_set_element((mat_t *)obj, i, 0, &k); + + fts_set_float(&k, pitch); + mat_set_element((mat_t *)obj, i, 1, &k); + fts_set_float(&k, duration); + mat_set_element((mat_t *)obj, i, 2, &k); + + return NULL; +} + +static void +mat_gui_score_move(void *obj, void *evt, int index, double time) +{ + int m = mat_get_m((mat_t *)obj); + float evt_time; + int i; + fts_atom_t k; + fts_atom_t at_void; + fts_set_void(&at_void); + + for(i = 0; i < m; i++) + { + evt_time = fts_get_number_float(mat_get_element( (mat_t *)obj, i, 0)); + if(evt_time > time) + break; + } + + if(i == index) + { + fts_set_float(&k, time); + mat_set_element((mat_t *)obj, i, 0, &k); + } + else + { + int idx = (i < index) ? index+1 : index; + + // insert row and copy values + mat_insert_rows((mat_t *)obj, i, 1); + + fts_set_float(&k, time); + mat_set_element((mat_t *)obj, i, 0, &k); + + k = *(mat_get_element((mat_t *)obj, idx, 1)); + + if(fts_is_number(&k)) + mat_set_element((mat_t *)obj, i, 1, &k); + + k = *(mat_get_element((mat_t *)obj, idx, 2)); + + if(fts_is_number(&k)) + mat_set_element((mat_t *)obj, i, 2, &k); + + //remove row at old index + mat_delete_rows((mat_t *)obj, idx, 1); + } +} +static void +mat_gui_score_remove(void *obj, void *evt, int index) +{ + mat_delete_rows((mat_t *)obj, index, 1); +} +static void +mat_gui_score_set_pitch(void *obj, void *marker, int index, double pitch) +{ + int m = mat_get_m((mat_t *)obj); + int n = mat_get_n((mat_t *)obj); + + if(m > 0 && n > 2 && index >= 0 && index < m) + { + fts_atom_t k; + fts_set_float(&k, pitch); + mat_set_element((mat_t *)obj, index, 1, &k); + } +} + +static void +mat_gui_score_set_duration(void *obj, void *evt, int index, double duration) +{ + int m = mat_get_m((mat_t *)obj); + int n = mat_get_n((mat_t *)obj); + + if(m > 0 && n > 2 && index >= 0 && index < m) + { + fts_atom_t k; + fts_set_float(&k, duration); + mat_set_element((mat_t *)obj, index, 2, &k); + } +} + +static void +mat_gui_score_get_values(void *obj, void *evt, double *time, double *pitch, double *duration) +{ + *time = -1.0; + *pitch = -1.0; + *duration = -1.0; +} + +static void * +mat_gui_score_get_first(void *obj, double *time, double *pitch, double *duration) +{ + *time = -1.0; + *pitch = -1.0; + *duration = -1.0; + return NULL; +} +static void * +mat_gui_score_get_next(void *obj, void *marker, double *time, double *pitch, double *duration) +{ + *time = -1.0; + *pitch = -1.0; + *duration = -1.0; + return NULL; +} + /******************************************************************** * * class @@ -2122,7 +2305,7 @@ mat_t *self = (mat_t *) o; int m = 0; int n = 1; - int size, i; + int size; fts_safeobject_init((fts_safeobject_t *)self); @@ -2303,6 +2486,23 @@ mat_gui_interface_markers->getTime = mat_gui_markers_get_time; fts_class_gui_interface(cl, fts_s_markers, mat_gui_interface_markers); + + mat_gui_interface_score = (imtr_guiInterfaceScore *)fts_malloc(sizeof(imtr_guiInterfaceScore)); + ((imtr_guiInterface *)mat_gui_interface_score)->name = fts_symbol_name(fts_s_score); + mat_gui_interface_score->isVector = mat_gui_score_is_vector; + mat_gui_interface_score->getSize = mat_gui_score_get_size; + mat_gui_interface_score->getDuration = mat_gui_score_get_duration; + mat_gui_interface_score->move = mat_gui_score_move; + mat_gui_interface_score->setDuration = mat_gui_score_set_duration; + mat_gui_interface_score->remove = mat_gui_score_remove; + mat_gui_interface_score->add = mat_gui_score_add; + mat_gui_interface_score->getFirst = mat_gui_score_get_first; + mat_gui_interface_score->getNext = mat_gui_score_get_next; + mat_gui_interface_score->getValues = mat_gui_score_get_values; + mat_gui_interface_score->getByIndex = mat_gui_score_get_by_index; + mat_gui_interface_score->setPitch = mat_gui_score_set_pitch; + + fts_class_gui_interface(cl, fts_s_score, mat_gui_interface_score); } FTS_MODULE_INIT(mat) Modified: trunk/ftm/ftmlib/classes/track.c =================================================================== --- trunk/ftm/ftmlib/classes/track.c 2008-07-15 16:41:27 UTC (rev 1816) +++ trunk/ftm/ftmlib/classes/track.c 2008-07-17 09:52:13 UTC (rev 1817) @@ -2055,6 +2055,12 @@ } static void +track_gui_score_set_duration(void *obj, void *evt, int index, double duration) +{ + event_set_duration((event_t *)evt, duration); +} + +static void track_gui_score_remove(void *obj, void *evt, int index) { sequence_remove_event(track_get_events((track_t *)obj), (event_t *)evt); @@ -2256,6 +2262,7 @@ track_gui_interface_score->getSize = track_gui_score_get_size; track_gui_interface_score->getDuration = track_gui_score_get_duration; track_gui_interface_score->move = track_gui_score_move; + track_gui_interface_score->setDuration = track_gui_score_set_duration; track_gui_interface_score->remove = track_gui_score_remove; track_gui_interface_score->add = track_gui_score_add; track_gui_interface_score->getFirst = track_gui_score_get_first; Modified: trunk/ftm/gui/Juce/common/InfoPanel.cpp =================================================================== --- trunk/ftm/gui/Juce/common/InfoPanel.cpp 2008-07-15 16:41:27 UTC (rev 1816) +++ trunk/ftm/gui/Juce/common/InfoPanel.cpp 2008-07-17 09:52:13 UTC (rev 1817) @@ -72,7 +72,7 @@ if(editor->haveInfoPanel()) { JUCE_EDITOR_NAMESPACE::Image *img = editor->getInfoImage(); - g.drawImageAt(img, 0, ed_y, false); + g.drawImageAt(img, 0, ed_y, false); } } } Modified: trunk/ftm/gui/Juce/common/ScoreEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/ScoreEditor.cpp 2008-07-15 16:41:27 UTC (rev 1816) +++ trunk/ftm/gui/Juce/common/ScoreEditor.cpp 2008-07-17 09:52:13 UTC (rev 1817) @@ -201,13 +201,13 @@ pianorollInfoImage = NULL; redraw_offscreen = true; - description = JUCE_EDITOR_NAMESPACE::String("markers"); + description = JUCE_EDITOR_NAMESPACE::String("score"); currentToolToRestore = EditorContainer::edit_tool; scoreFont = NULL; loadScoreFont(); - + //addAndMakeVisible(mouseLabel = new ScoreMouseLabel()); /*addAndMakeVisible(mouseLabel = new JUCE_EDITOR_NAMESPACE::Label("mouse label", "1000 , 15")); mouseLabel->setEditable(false, true, true); @@ -423,40 +423,39 @@ return NULL; } - int scoreGetIndexAt(int pix) + int scoreGetIndexAt(int x, int y) { - double time, t_delta, evt_time, next_time; - double evt_pitch, evt_duration; + double evt_time, evt_pitch, evt_duration; int size = scoreGui->getSize(obj); - if(pix > 0) pix--; if(!container->isVertical()) { - time = editorGetInvX(pix); - t_delta = editorGetInvX(2)-editorGetInvX(0); + int i, evt_x, evt_nx, evt_y; + for(i = 0; i < size; i++) + { + scoreGui->getByIndex(obj, i, &evt_time, &evt_pitch, &evt_duration); + evt_x = editorGetX(evt_time); + evt_nx = editorGetX(evt_time + evt_duration); + evt_y = editorGetY(evt_pitch); + + if((x >= evt_x - 2 && x <= evt_nx + 2) && (y <= evt_y + 2 && y >= evt_y - 2)) + return i; + } } else { - time = editorGetInvY(pix); - t_delta = editorGetInvY(2)-editorGetInvY(0); + int i, evt_y, evt_ny, evt_x; + for(i = 0; i < size; i++) + { + scoreGui->getByIndex(obj, i, &evt_time, &evt_pitch, &evt_duration); + evt_y = editorGetY(evt_time); + evt_ny = editorGetY(evt_time + evt_duration); + evt_x = editorGetX(evt_pitch); + if((y >= evt_y - 2 && y <= evt_ny + 2) && (x <= evt_x + 2 && x >= evt_x - 2)) + return i; + } } - - int i; - for(i = 0; i < size; i++) - { - scoreGui->getByIndex(obj, i, &next_time, &evt_pitch, &evt_duration); - if(next_time > time) break; - evt_time = next_time; - } - - if((next_time < time + t_delta) && (next_time > time - t_delta)) - return i; - else - if(evt_time <= time + t_delta && evt_time >= time - t_delta) - return i-1; - else - return -1; } /********************** @@ -467,7 +466,7 @@ if(!selection.contains(evt)) selection.add(evt); } - void markerIndexSelect(int i) + void scoreIndexSelect(int i) { if(!indexSelection.contains(i)) indexSelection.add(i); @@ -476,15 +475,15 @@ { selection.removeValue(evt); } - void markerIndexDeselect(int i) + void scoreIndexDeselect(int i) { indexSelection.removeValue(i); } - bool markersIsSelected(void *evt) + bool scoreIsSelected(void *evt) { return selection.contains(evt); } - bool markerIndexIsSelected(int i) + bool scoreIndexIsSelected(int i) { return indexSelection.contains(i); } @@ -539,7 +538,7 @@ } } else - { + { if(dy != 0) for(i = indexSelection.size()-1; i >= 0; i--) { @@ -551,7 +550,7 @@ for(i = 0; i< indexSelection.size(); i++) { scoreGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); - pix = editorGetY(pitch) + dx; + pix = editorGetX(pitch) + dx; new_pitch = (int)editorGetInvX(pix); if(new_pitch > 127) new_pitch = 127; else if (new_pitch < 0) new_pitch = 0; @@ -683,7 +682,7 @@ } } - void markersDeleteSelection() + void scoreDeleteSelection() { if(scoreGui->isVector()) { @@ -705,37 +704,45 @@ void scoreSelectInRect(JUCE_EDITOR_NAMESPACE::Rectangle r) { + double start_time, end_time, evt_time; + double evt_pitch, evt_duration; + double maxPitch, minPitch; + if(scoreGui->isVector()) { - double start_time, end_time, evt_time; - double evt_pitch, evt_duration; int i; - + double last_time; + + int first_idx = getFirstVisibleIndex(&evt_time, &evt_pitch, &evt_duration); + int last_idx = getLastVisibleIndex(&last_time); + if(!container->isVertical()) { start_time = editorGetInvX(r.getX()); end_time = editorGetInvX( r.getX() + r.getWidth()); + maxPitch = editorGetInvY(r.getY()); + minPitch = editorGetInvY(r.getY() + r.getHeight()); } else { start_time = editorGetInvY(r.getY()); end_time = editorGetInvY( r.getY() + r.getHeight()); + minPitch = editorGetInvX(r.getX()); + maxPitch = editorGetInvX(r.getX() + r.getWidth()); } - for(i = 0; i < scoreGui->getSize(obj); i++) + for(i = first_idx; i <= last_idx; i++) { scoreGui->getByIndex(obj, i, &evt_time, &evt_pitch, &evt_duration); - if(evt_time >= start_time && evt_time <= end_time) - markerIndexSelect(i); + if((evt_time+evt_duration >= start_time && evt_time <= end_time) && + (evt_pitch >= minPitch && evt_pitch <= maxPitch)) + scoreIndexSelect(i); } } else { void *evt = NULL; void *evt_after = NULL; - double start_time, end_time, evt_time; - double evt_pitch, evt_duration; - double maxPitch, minPitch; if(!container->isVertical()) { @@ -791,8 +798,8 @@ nx = editorGetX(evt_time+evt_duration); y = editorGetY(evt_pitch); - if(markersIsSelected(evt)) - g.setColour(JUCE_EDITOR_NAMESPACE::Colours::grey); + if(scoreIsSelected(evt)) + g.setColour(selectColor); else g.setColour(forecolor); @@ -823,8 +830,8 @@ ny = editorGetY(evt_time+evt_duration); x = editorGetX(evt_pitch); - if(markersIsSelected(evt)) - g.setColour(JUCE_EDITOR_NAMESPACE::Colours::grey); + if(scoreIsSelected(evt)) + g.setColour(selectColor); else g.setColour(forecolor); @@ -850,116 +857,79 @@ void drawScoreAsVector(JUCE_EDITOR_NAMESPACE::Graphics& g) { - /*double evt_time, last_time; - int cue; - char *evt_label; + double evt_time, last_time, evt_pitch, evt_duration; int size = scoreGui->getSize(obj); - int first_idx = getFirstVisibleIndex(&evt_time, &cue, &evt_label); + int first_idx = getFirstVisibleIndex(&evt_time, &evt_pitch, &evt_duration); int last_idx = getLastVisibleIndex(&last_time); - - g.setColour(forecolor); + + scoreFont.setHeight(42.0f); + g.setFont(scoreFont); + if(!container->isVertical()) { - int i, x; - int height = getHeight(); + int i, x, nx, y; for(i = first_idx; i < size && i<=last_idx; i++) { - scoreGui->getByIndex(obj, i, &evt_time, &cue, &evt_label); + scoreGui->getByIndex(obj, i, &evt_time, &evt_pitch, &evt_duration); + x = editorGetX(evt_time); - g.drawLine(x, 0, x, height); - if(markerIndexIsSelected(i)) - { + nx = editorGetX(evt_time+evt_duration); + y = editorGetY(evt_pitch); + + if(scoreIndexIsSelected(i)) g.setColour(selectColor); - g.fillRoundedRectangle(x-1, 0, 3, height, 2); + else g.setColour(forecolor); - } - // draw event properties - JUCE_EDITOR_NAMESPACE::String text; - int ytext = 1; - int wtext = 0; + g.fillRect(x, y-1, (nx-x), 3); - if(cue >= 0) + if(shape == staves_shape) { - text = JUCE_EDITOR_NAMESPACE::String(cue); - int text_width = midiFont->getStringWidth(text)+2; - g.setFont(*midiFont); - g.drawText(text, x+2, ytext, text_width, (int)(midiFont->getHeight()), JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); - ytext+=(int)(midiFont->getHeight()); - wtext = text_width; + int alt = getAlteration(evt_pitch); + switch(alt) + { + case ALTERATION_DIESIS: + g.drawSingleLineText("B", x-8, y+4); + break; + case ALTERATION_BEMOLLE: + g.drawSingleLineText("b", x-8, y+4); + } } - - if(evt_label != 0) - { - text = JUCE_EDITOR_NAMESPACE::String(evt_label); - int text_width = midiFont->getStringWidth(text)+2; - - g.setFont(*midiFont); - g.drawText(text, x+2, ytext, midiFont->getStringWidth(text)+2, (int)(midiFont->getHeight()), JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); - if(text_width > wtext) wtext = text_width; - ytext+=(int)(midiFont->getHeight()); - } - if(wtext > 0 && markerIndexIsSelected(i))//draw rect around props - { - g.setColour(labelColor); - g.fillRect(x+1, 1, wtext+2, ytext-1); - g.setColour(forecolor); - } } } else { - int i, y; - int width = getWidth(); + int i, x, y, ny; for(i = first_idx; i < size && i<=last_idx; i++) { - scoreGui->getByIndex(obj, i, &evt_time, &cue, &evt_label); + scoreGui->getByIndex(obj, i, &evt_time, &evt_pitch, &evt_duration); + y = editorGetY(evt_time); - g.drawLine(0, y, width, y); + ny = editorGetY(evt_time+evt_duration); + x = editorGetX(evt_pitch); - if(markerIndexIsSelected(i)) - { + if(scoreIndexIsSelected(i)) g.setColour(selectColor); - g.fillRoundedRectangle(0, y-1, width, 3, 2); + else g.setColour(forecolor); - } - // draw event properties - JUCE_EDITOR_NAMESPACE::String text; - int fontH = (int)(midiFont->getHeight()); - int xtext = getWidth()-fontH-1; - int htext = 0; + g.fillRect(x-1, y, 3, (ny-y)); - if(cue >= 0) + if(shape == staves_shape) { - text = JUCE_EDITOR_NAMESPACE::String(cue); - int text_width = midiFont->getStringWidth(text)+2; - g.setFont(*midiFont); - g.drawTextAsPath(text, JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(xtext, y+1))); - xtext-=(int)(midiFont->getHeight()); - htext = text_width; + int alt = getAlteration(evt_pitch); + switch(alt) + { + case ALTERATION_DIESIS: + g.drawTextAsPath("B", JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(x-3, y-8))); + break; + case ALTERATION_BEMOLLE: + g.drawTextAsPath("b", JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(x-3, y-8))); + } } - - if(evt_label != 0) - { - text = JUCE_EDITOR_NAMESPACE::String(evt_label); - int text_width = midiFont->getStringWidth(text)+2; - - g.setFont(*midiFont); - g.drawTextAsPath(text, JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(xtext, y+1))); - - if(text_width > htext) htext = text_width; - xtext-=(int)(midiFont->getHeight()); - } - if(htext > 0 && markerIndexIsSelected(i))//draw rect around props - { - g.setColour(labelColor); - g.fillRect(xtext+fontH, y+1, fontH*2+2, htext+2); - g.setColour(forecolor); - } } - }*/ + } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1597,7 +1567,7 @@ { if(pianorollInfoImage != NULL) delete pianorollInfoImage; - + if(container->isVertical()) pianorollInfoImage = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), PIANOROLL_INFO_SIZE, true); else @@ -1713,25 +1683,26 @@ if(!container->isVertical()) { - int x; - int height = getHeight(); - + int x, nx, y; for(i = 0; i< indexSelection.size(); i++) { scoreGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); x = editorGetX(time) + moving_dx; - g.fillRoundedRectangle(x-1, 0, 3, height, 2); + nx = editorGetX(time + duration) + moving_dx; + y = editorGetY(pitch) + moving_dy; + g.drawRect(x, y-2, nx-x, 5, 2); } } else { - int y; - int width = getWidth(); + int x, y, ny; for(i = 0; i< indexSelection.size(); i++) { scoreGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); y = editorGetY(time) + moving_dy; - g.fillRoundedRectangle(0, y-1, width, 3, 2); + ny = editorGetY(time + duration) + moving_dy; + x = editorGetX(pitch) + moving_dx; + g.drawRect(x-2, y, 5, ny-y, 2); } } } @@ -1775,25 +1746,26 @@ if(!container->isVertical()) { - int x; - int height = getHeight(); - + int x, nx, y; for(i = 0; i< indexSelection.size(); i++) { scoreGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); - x = editorGetX(time) + moving_dx; - g.fillRoundedRectangle(x-1, 0, 3, height, 2); + x = editorGetX(time); + nx = editorGetX(time + duration) + moving_dx; + y = editorGetY(pitch); + g.drawRect(x, y-2, nx-x, 5, 2); } } else { - int y; - int width = getWidth(); + int x, y, ny; for(i = 0; i< indexSelection.size(); i++) { scoreGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); - y = editorGetY(time) + moving_dy; - g.fillRoundedRectangle(0, y-1, width, 3, 2); + y = editorGetY(time); + ny = editorGetY(time + duration) + moving_dy; + x = editorGetX(pitch); + g.drawRect(x-2, y, 5, ny-y, 2); } } } @@ -1838,7 +1810,7 @@ if(code == JUCE_EDITOR_NAMESPACE::KeyPress::deleteKey || code == JUCE_EDITOR_NAMESPACE::KeyPress::backspaceKey) { if(!scoreIsSelectionEmpty()) - markersDeleteSelection(); + scoreDeleteSelection(); return true; } return false; @@ -2070,24 +2042,24 @@ { if(scoreGui->isVector()) { - int index = scoreGetIndexAt((container->isVertical()) ? y : x); + int index = scoreGetIndexAt(x, y); if(index >= 0) { if(isShiftDown) { - if(markerIndexIsSelected(index)) - markerIndexDeselect(index); + if(scoreIndexIsSelected(index)) + scoreIndexDeselect(index); else { - markerIndexSelect(index); + scoreIndexSelect(index); scoreSetMovingSelection(true); } } else { - if( !markerIndexIsSelected(index)) + if( !scoreIndexIsSelected(index)) scoreDeselectAll(); - markerIndexSelect(index); + scoreIndexSelect(index); scoreSetMovingSelection(true); } @@ -2108,7 +2080,7 @@ { if(isShiftDown) { - if(markersIsSelected(evt)) + if(scoreIsSelected(evt)) scoreDeselect(evt); else { @@ -2118,7 +2090,7 @@ } else { - if( !markersIsSelected(evt)) + if( !scoreIsSelected(evt)) scoreDeselectAll(); scoreSelect(evt); @@ -2347,8 +2319,16 @@ bool haveInfoPanel() {return true;} JUCE_EDITOR_NAMESPACE::Image *getInfoImage() { - if(shape == staves_shape) return stavesInfoImage; - else return pianorollInfoImage; + if(shape == staves_shape) + { + if(stavesInfoImage == NULL) createAndDrawStavesInfoBackground(); + return stavesInfoImage; + } + else + { + if(pianorollInfoImage == NULL) createAndDrawPianorollInfoBackground(); + return pianorollInfoImage; + } } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bor...@us...> - 2008-07-15 16:41:37
|
Revision: 1816 http://ftm.svn.sourceforge.net/ftm/?rev=1816&view=rev Author: borghesi Date: 2008-07-15 09:41:27 -0700 (Tue, 15 Jul 2008) Log Message: ----------- ftm.editor: ScoreEditor, added duration resize (COMMAND+ALT+drag) Modified Paths: -------------- trunk/ftm/gui/Juce/c_gui/guiinterfaces.h trunk/ftm/gui/Juce/common/BpfEditor.cpp trunk/ftm/gui/Juce/common/EditTool.cpp trunk/ftm/gui/Juce/common/FvecEditor.cpp trunk/ftm/gui/Juce/common/ImtrEditor.h trunk/ftm/gui/Juce/common/MarkersEditor.cpp trunk/ftm/gui/Juce/common/ScoreEditor.cpp trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp trunk/ftm/gui/Juce/cpp_gui/guiinterfaces.h Modified: trunk/ftm/gui/Juce/c_gui/guiinterfaces.h =================================================================== --- trunk/ftm/gui/Juce/c_gui/guiinterfaces.h 2008-07-15 15:46:21 UTC (rev 1815) +++ trunk/ftm/gui/Juce/c_gui/guiinterfaces.h 2008-07-15 16:41:27 UTC (rev 1816) @@ -540,6 +540,16 @@ typedef void (*imtr_gui_interface_score_move_t)(void *obj, void *evt, int index, double the_time); /** + * @brief set the duration of given score event + * @param obj the score track object + * @param evt the score event + * @param index the index of the score event + * @param the_duration duration + * @ingroup guiinterfaces + */ +typedef void (*imtr_gui_interface_score_set_duration_t)(void *obj, void *evt, int index, double the_duration); + +/** * @brief set pitch to score event * @param obj the score track object * @param evt the score event @@ -591,6 +601,7 @@ imtr_gui_interface_score_get_size_t getSize; imtr_gui_interface_score_get_duration_t getDuration; imtr_gui_interface_score_move_t move; + imtr_gui_interface_score_set_duration_t setDuration; imtr_gui_interface_score_remove_t remove; imtr_gui_interface_score_get_first_t getFirst; Modified: trunk/ftm/gui/Juce/common/BpfEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/BpfEditor.cpp 2008-07-15 15:46:21 UTC (rev 1815) +++ trunk/ftm/gui/Juce/common/BpfEditor.cpp 2008-07-15 16:41:27 UTC (rev 1816) @@ -1540,6 +1540,7 @@ } objectChanged(); } + void commandAltInteraction(int x, int y, bool isShiftDown){} void startDragging(int x, int y, int w, int h, bool isShiftDown) { int pt = bpfGetPointAt(x, y); Modified: trunk/ftm/gui/Juce/common/EditTool.cpp =================================================================== --- trunk/ftm/gui/Juce/common/EditTool.cpp 2008-07-15 15:46:21 UTC (rev 1815) +++ trunk/ftm/gui/Juce/common/EditTool.cpp 2008-07-15 16:41:27 UTC (rev 1816) @@ -99,23 +99,28 @@ editor->openPopupMenu(); else if(e.mods.isCommandDown()) - editor->addToLocation(x, y, e.mods.isShiftDown()); - else - if(e.mods.isAltDown()) { - if(e.mods.isShiftDown()) /*start select_region */ + if(!e.mods.isAltDown()) + editor->addToLocation(x, y, e.mods.isShiftDown()); + else + editor->commandAltInteraction(x, y, e.mods.isShiftDown()); + } + else + if(e.mods.isAltDown()) { - if(container->isRegionSelected()) /* deselect region selection */ - container->deselectRegion(); - - container->setRegionSelection( editor->editorGetInvX(x), editor->editorGetInvX(x)); - editor->setSelectingRegion(true); + if(e.mods.isShiftDown()) /*start select_region */ + { + if(container->isRegionSelected()) /* deselect region selection */ + container->deselectRegion(); + + container->setRegionSelection( editor->editorGetInvX(x), editor->editorGetInvX(x)); + editor->setSelectingRegion(true); + } + else //open help patch + container->getImtrListener()->doAction(JUCE_EDITOR_NAMESPACE::String("help")); } - else //open help patch - container->getImtrListener()->doAction(JUCE_EDITOR_NAMESPACE::String("help")); - } - else - editor->startDragging(x, y, w, h, e.mods.isShiftDown()); + else + editor->startDragging(x, y, w, h, e.mods.isShiftDown()); e.eventComponent->repaint(); } Modified: trunk/ftm/gui/Juce/common/FvecEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/FvecEditor.cpp 2008-07-15 15:46:21 UTC (rev 1815) +++ trunk/ftm/gui/Juce/common/FvecEditor.cpp 2008-07-15 16:41:27 UTC (rev 1816) @@ -1098,7 +1098,8 @@ } } -void addToLocation(int x, int y, bool isShiftDown){} + void addToLocation(int x, int y, bool isShiftDown){} + void commandAltInteraction(int x, int y, bool isShiftDown){} void startDragging(int x, int y, int w, int h, bool isShiftDown) { selecting = true; Modified: trunk/ftm/gui/Juce/common/ImtrEditor.h =================================================================== --- trunk/ftm/gui/Juce/common/ImtrEditor.h 2008-07-15 15:46:21 UTC (rev 1815) +++ trunk/ftm/gui/Juce/common/ImtrEditor.h 2008-07-15 16:41:27 UTC (rev 1816) @@ -272,7 +272,16 @@ */ virtual void addToLocation(int x, int y, bool isShiftDown) = 0; /** - * @brief Called to set the current tool + * @brief called to special interaction responding to Command+Alt click + * @param x the x coord + * @param y the y coord + * @param isShiftDown true if the shift is down, to deal with selection + * @ingroup ImtrEditor + */ + virtual void commandAltInteraction(int x, int y, bool isShiftDown) = 0; + + /** + * @brief Called to set the current tool * @param tool the new current tool * @ingroup ImtrEditor */ Modified: trunk/ftm/gui/Juce/common/MarkersEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/MarkersEditor.cpp 2008-07-15 15:46:21 UTC (rev 1815) +++ trunk/ftm/gui/Juce/common/MarkersEditor.cpp 2008-07-15 16:41:27 UTC (rev 1816) @@ -1060,6 +1060,7 @@ markersSelect(evt); objectRefresh(); } + void commandAltInteraction(int x, int y, bool isShiftDown){} void startDragging(int x, int y, int w, int h, bool isShiftDown) { if(markersGui->isVector()) Modified: trunk/ftm/gui/Juce/common/ScoreEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/ScoreEditor.cpp 2008-07-15 15:46:21 UTC (rev 1815) +++ trunk/ftm/gui/Juce/common/ScoreEditor.cpp 2008-07-15 16:41:27 UTC (rev 1816) @@ -116,6 +116,7 @@ int moving_dx, moving_dy; bool directionChoosen; int move_direction; + bool changingDuration; JUCE_EDITOR_NAMESPACE::Component *scoreList; JUCE_EDITOR_NAMESPACE::Font *gridSubdivisionFont; @@ -616,6 +617,72 @@ } } + void scoreChangeDurationForSelection(int dpix) + { + double time, pitch, duration; + + if(dpix != 0) + { + if(scoreGui->isVector()) + { + float pix; + int i; + + if(!container->isVertical()) + { + for(i = indexSelection.size()-1; i >= 0; i--) + { + scoreGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); + pix = editorGetX(time + duration) + dpix; + duration = editorGetInvX(pix) - time; + if(duration < 1) duration = 1; + scoreGui->setDuration(obj, NULL, indexSelection[i], duration); + } + } + else + { + for(i = indexSelection.size()-1; i >= 0; i--) + { + scoreGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); + pix = editorGetY(time + duration) + dpix; + duration = editorGetInvY(pix) - time; + if(duration < 1) duration = 1; + scoreGui->move(obj, NULL, indexSelection[i], duration); + } + } + } + else + { + float pix; + int i; + double time, pitch, duration; + + if(!container->isVertical()) + { + for(i = 0; i< selection.size(); i++) + { + scoreGui->getValues(obj, selection[i], &time, &pitch, &duration); + pix = editorGetX(time + duration) + dpix; + duration = editorGetInvX(pix)-time; + if(duration < 1) duration = 1; + scoreGui->setDuration(obj, selection[i], -1, duration); + } + } + else + { + for(i = 0; i< selection.size(); i++) + { + scoreGui->getValues(obj, selection[i], &time, &pitch, &duration); + pix = editorGetY(time + duration) + dpix; + duration = editorGetInvY(pix) - time; + if(duration < 1) duration = 1; + scoreGui->setDuration(obj, selection[i], -1, duration); + } + } + } + } + } + void markersDeleteSelection() { if(scoreGui->isVector()) @@ -1614,12 +1681,11 @@ } g.drawImageAt(offscreen, 0, 0, false); - g.setColour(/*lightcolor*/selectColor); + g.setColour(selectColor); /* draw selection rectangle */ if(selecting) { g.setOpacity(0.3f); - //g.drawRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight(), 1); g.fillRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight()); } else if(container->doRegionSelection(this)) @@ -1631,7 +1697,10 @@ g.setOpacity(0.3f); g.setColour(lightcolor); - scoreDrawSelection(g); + if(changingDuration) + scoreDrawSelectedDurationChange(g); + else + scoreDrawSelection(g); } } @@ -1696,7 +1765,69 @@ } } } + + void scoreDrawSelectedDurationChange(JUCE_EDITOR_NAMESPACE::Graphics& g) + { + if(scoreGui->isVector()) + { + int i; + double time, pitch, duration; + if(!container->isVertical()) + { + int x; + int height = getHeight(); + + for(i = 0; i< indexSelection.size(); i++) + { + scoreGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); + x = editorGetX(time) + moving_dx; + g.fillRoundedRectangle(x-1, 0, 3, height, 2); + } + } + else + { + int y; + int width = getWidth(); + for(i = 0; i< indexSelection.size(); i++) + { + scoreGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); + y = editorGetY(time) + moving_dy; + g.fillRoundedRectangle(0, y-1, width, 3, 2); + } + } + } + else + { + int i; + double time, pitch, duration; + if(!container->isVertical()) + { + int x, nx, y; + for(i = 0; i< selection.size(); i++) + { + scoreGui->getValues(obj, selection[i], &time, &pitch, &duration); + x = editorGetX(time); + nx = editorGetX(time + duration) + moving_dx; + y = editorGetY(pitch); + g.drawRect(x, y-2, nx-x, 5, 2); + } + } + else + { + int x, y, ny; + for(i = 0; i< selection.size(); i++) + { + scoreGui->getValues(obj, selection[i], &time, &pitch, &duration); + y = editorGetY(time); + ny = editorGetY(time + duration) + moving_dy; + x = editorGetX(pitch); + g.drawRect(x-2, y, 5, ny-y, 2); + } + } + } + } + /****************************** Key Listener *****************************/ @@ -1930,6 +2061,11 @@ scoreSelect(evt); objectRefresh(); } + void commandAltInteraction(int x, int y, bool isShiftDown) + { + changingDuration = true; + startDragging(x, y, 0, 0, isShiftDown); + } void startDragging(int x, int y, int w, int h, bool isShiftDown) { if(scoreGui->isVector()) @@ -2025,15 +2161,28 @@ } void dragSelection(int x, int y, int dx, int dy) { - if(!directionChoosen) + if(changingDuration) { - if(abs(dy) >= abs(dx)) + if(container->isVertical()) move_direction = VERTICAL_DIR; else move_direction = HORIZONTAL_DIR; directionChoosen = true; } + else + { + if(!directionChoosen) + { + if(abs(dy) >= abs(dx)) + move_direction = VERTICAL_DIR; + else + move_direction = HORIZONTAL_DIR; + + directionChoosen = true; + } + } + if(move_direction == VERTICAL_DIR) { moving_dx = 0; @@ -2058,9 +2207,13 @@ } void endMovingSelection() { - scoreMoveSelection(moving_dx, moving_dy); + if(changingDuration) + scoreChangeDurationForSelection((container->isVertical() ? moving_dy : moving_dx)); + else + scoreMoveSelection(moving_dx, moving_dy); movingSelection = false; directionChoosen = false; + changingDuration = false; moving_dx = moving_dy = 0; objectRefresh(); } Modified: trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp 2008-07-15 15:46:21 UTC (rev 1815) +++ trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp 2008-07-15 16:41:27 UTC (rev 1816) @@ -773,6 +773,7 @@ } } void addToLocation(int x, int y, bool isShiftDown){} + void commandAltInteraction(int x, int y, bool isShiftDown){} void startDragging(int x, int y, int w, int h, bool isShiftDown) { if(isShiftDown) //rect selection Modified: trunk/ftm/gui/Juce/cpp_gui/guiinterfaces.h =================================================================== --- trunk/ftm/gui/Juce/cpp_gui/guiinterfaces.h 2008-07-15 15:46:21 UTC (rev 1815) +++ trunk/ftm/gui/Juce/cpp_gui/guiinterfaces.h 2008-07-15 16:41:27 UTC (rev 1816) @@ -133,7 +133,7 @@ virtual int isVector() = 0; virtual int getSize(void *obj) = 0; virtual double getDuration(void *obj) = 0; - + virtual void move(void *obj, void *evt, int index, double the_time) = 0; virtual void remove(void *obj, void *evt, int index) = 0; @@ -143,7 +143,9 @@ virtual void *getByIndex(void *obj, int the_index, double *time, double *pitch, double *duration) = 0; virtual void *add(void *obj, double the_time, double pitch, double duration) = 0; + virtual void setPitch(void *obj, void *evt, int index, double pitch) = 0; + virtual void setDuration(void *obj, void *evt, int index, double the_duration) = 0; }; /** @} Score gui interface */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bor...@us...> - 2008-07-15 16:03:00
|
Revision: 1815 http://ftm.svn.sourceforge.net/ftm/?rev=1815&view=rev Author: borghesi Date: 2008-07-15 08:46:21 -0700 (Tue, 15 Jul 2008) Log Message: ----------- ftm.editor: ScoreEditor minor fixes Modified Paths: -------------- trunk/ftm/gui/Juce/common/ScoreEditor.cpp Modified: trunk/ftm/gui/Juce/common/ScoreEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/ScoreEditor.cpp 2008-07-15 11:01:43 UTC (rev 1814) +++ trunk/ftm/gui/Juce/common/ScoreEditor.cpp 2008-07-15 15:46:21 UTC (rev 1815) @@ -152,9 +152,9 @@ horizontalGridLinesColor = JUCE_EDITOR_NAMESPACE::Colour(220, 220, 220); backcolor = /*JUCE_EDITOR_NAMESPACE::Colours::white*/container->getBackgroundColor(); - lightcolor = horizontalGridLinesColor; + lightcolor = /*horizontalGridLinesColor;*/backcolor.contrasting(0.15f); forecolor = JUCE_EDITOR_NAMESPACE::Colours::black; - selectColor = forecolor.withAlpha(0.6f); + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); labelColor = forecolor.withAlpha(0.4f); opacity = container->getOpacity(); @@ -389,18 +389,36 @@ void *scoreGetEventAt(int x, int y) { double evt_time, evt_pitch, evt_duration; - int evt_x, evt_nx, evt_y; void *event = scoreGui->getFirst(obj, &evt_time, &evt_pitch, &evt_duration); - while(event != NULL) + + if(!container->isVertical()) { - evt_x = editorGetX(evt_time); - evt_nx = editorGetX(evt_time + evt_duration); - evt_y = editorGetY(evt_pitch); - if((x >= evt_x - 2 && x <= evt_nx + 2) && (y <= evt_y + 2 && y >= evt_y - 2)) - return event; - - event = scoreGui->getNext(obj, event, &evt_time, &evt_pitch, &evt_duration); - } + int evt_x, evt_nx, evt_y; + while(event != NULL) + { + evt_x = editorGetX(evt_time); + evt_nx = editorGetX(evt_time + evt_duration); + evt_y = editorGetY(evt_pitch); + if((x >= evt_x - 2 && x <= evt_nx + 2) && (y <= evt_y + 2 && y >= evt_y - 2)) + return event; + + event = scoreGui->getNext(obj, event, &evt_time, &evt_pitch, &evt_duration); + } + } + else + { + int evt_y, evt_ny, evt_x; + while(event != NULL) + { + evt_y = editorGetY(evt_time); + evt_ny = editorGetY(evt_time + evt_duration); + evt_x = editorGetX(evt_pitch); + if((y >= evt_y - 2 && y <= evt_ny + 2) && (x <= evt_x + 2 && x >= evt_x - 2)) + return event; + + event = scoreGui->getNext(obj, event, &evt_time, &evt_pitch, &evt_duration); + } + } return NULL; } @@ -1275,7 +1293,7 @@ /********* Third Bass Line ***********************************************/ if(staffIsDrawable_Staves(6, maxPitch, minPitch)) { - g.setColour( horizontalGridLinesColor); + g.setColour( lightcolor); if(!container->isVertical()) { int positionY = STAVES_BOTTOM-19*LINE_STEP-transp; @@ -1596,12 +1614,13 @@ } g.drawImageAt(offscreen, 0, 0, false); - g.setColour(lightcolor); + g.setColour(/*lightcolor*/selectColor); /* draw selection rectangle */ if(selecting) { g.setOpacity(0.3f); - g.drawRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight(), 1); + //g.drawRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight(), 1); + g.fillRect(selRect.getX(), selRect.getY(), selRect.getWidth(), selRect.getHeight()); } else if(container->doRegionSelection(this)) { @@ -1798,6 +1817,7 @@ { backcolor = bcolor; lightcolor = backcolor.contrasting(0.15f); + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); updateBackgroundOffscreens(); objectRefresh(); } @@ -1808,7 +1828,7 @@ { forecolor = fcolor; //lightcolor = forecolor.brighter(0.9f); - selectColor = forecolor.withAlpha(0.6f); + selectColor = JUCE_EDITOR_NAMESPACE::Colour::contrasting(backcolor, forecolor); labelColor = forecolor.withAlpha(0.4f); updateBackgroundOffscreens(); objectRefresh(); @@ -2131,9 +2151,9 @@ temp = q*12 + getIntervallFromRest(r, rest); } else - { + { int dx = (PIANO_BOTTOM - PIANO_TOP)/127.0f; - temp = v_max - (x - PIANO_TOP)/dx; + temp = v_max - (getWidth()-PIANO_TOP-x)/dx; } if(temp < v_min) temp = v_min; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bor...@us...> - 2008-07-15 11:01:37
|
Revision: 1814 http://ftm.svn.sourceforge.net/ftm/?rev=1814&view=rev Author: borghesi Date: 2008-07-15 04:01:43 -0700 (Tue, 15 Jul 2008) Log Message: ----------- ftm.editor: fixed coord convertion in ScoreEditor when vertical Modified Paths: -------------- trunk/ftm/gui/Juce/common/InfoPanel.cpp trunk/ftm/gui/Juce/common/ScoreEditor.cpp Modified: trunk/ftm/gui/Juce/common/InfoPanel.cpp =================================================================== --- trunk/ftm/gui/Juce/common/InfoPanel.cpp 2008-07-09 16:00:37 UTC (rev 1813) +++ trunk/ftm/gui/Juce/common/InfoPanel.cpp 2008-07-15 11:01:43 UTC (rev 1814) @@ -120,7 +120,76 @@ } else { + if(container->isLayoutSuperposed()) + { + if(container->getEditorsSize() > 0) + { + int ed_x, ed_w; + int ed_right = 0; + int dscroll_x = (container->isDScrollVisible()) ? container->getDScrollSize() : 0; + if(container->isTabsVisible()) //draw top rectangle + { + ed_x = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(container->getEditors()[0]))->getX() + dscroll_x; + ed_w = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(container->getEditors()[0]))->getWidth(); + ed_right = ed_x + ed_w; + g.setColour(JUCE_EDITOR_NAMESPACE::Colours::black); + g.drawLine(ed_right, 0, ed_right, getHeight()); + g.setColour(container->getBackgroundColor().darker()); + g.drawLine(ed_right+1, 0, ed_right+1, getHeight()); + } + + ImtrEditor *editor = container->getEditors()[container->getForemost()]; + if(editor->haveInfoPanel()) + { + JUCE_EDITOR_NAMESPACE::Image *img = editor->getInfoImage(); + g.drawImageAt(img, ed_x, 0, false); + } + } + } + else //juxtaposed + { + JUCE_EDITOR_NAMESPACE::Rectangle bounds; + int i; + for(i=0; i<container->getEditorsSize(); i++) + { + ImtrEditor *editor = container->getEditors()[i]; + if(editor->haveInfoPanel()) + { + JUCE_EDITOR_NAMESPACE::Image *img = editor->getInfoImage(); + bounds = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(editor))->getBounds(); + g.drawImageWithin(img, 0, bounds.getY(), getWidth(), bounds.getHeight(), JUCE_EDITOR_NAMESPACE::RectanglePlacement::xLeft | JUCE_EDITOR_NAMESPACE::RectanglePlacement::yTop | JUCE_EDITOR_NAMESPACE::RectanglePlacement::doNotResize, false); + } + } + } + if(container->isDScrollVisible()) + { + int width = getWidth(); + int height = getHeight(); + int scroll_x = container->getDScrollSize(); + g.setColour(JUCE_EDITOR_NAMESPACE::Colours::black); + g.drawLine(scroll_x-1, 0, scroll_x-1, height-1); + g.drawLine(0, height-1, scroll_x, height-1); + g.setColour(container->getBackgroundColor().brighter(0.3f)); + g.drawLine(scroll_x-2, 0, scroll_x-2, height-2); + g.drawLine(0, height-2, scroll_x-1, height-2); + g.setColour(container->getBackgroundColor().darker()); + g.drawLine(0, 1, 0, width-1, 1); + g.drawLine(0, 0, 0, height-1); + } + /* + g.drawLine(0, height-1, width-1, height-1); + g.drawLine(0, scroll_y+1, 0, height-1); + */ + /*for(i = 0; i < container->getEditorsSize(); i++) + { + editor = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(container->getEditors()[0])); + if(editor->haveInfoPanel()) + { + Image img = editor->getInfoImage(); + g.drawImageAt(offscreen, x, y, false); + } + }*/ } } Modified: trunk/ftm/gui/Juce/common/ScoreEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/ScoreEditor.cpp 2008-07-09 16:00:37 UTC (rev 1813) +++ trunk/ftm/gui/Juce/common/ScoreEditor.cpp 2008-07-15 11:01:43 UTC (rev 1814) @@ -709,7 +709,7 @@ if(markersIsSelected(evt)) g.setColour(JUCE_EDITOR_NAMESPACE::Colours::grey); else - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::black*/forecolor); + g.setColour(forecolor); g.fillRect(x, y-1, (nx-x), 3); @@ -731,56 +731,35 @@ } else { - /*int y; - int width = getWidth(); + int y, ny, x; while(evt != NULL && evt != last) { y = editorGetY(evt_time); - g.drawLine(0, y, width, y); + ny = editorGetY(evt_time+evt_duration); + x = editorGetX(evt_pitch); if(markersIsSelected(evt)) - { - g.setColour(selectColor); - g.fillRoundedRectangle(0, y-1, width, 3, 2); + g.setColour(JUCE_EDITOR_NAMESPACE::Colours::grey); + else g.setColour(forecolor); - } - // draw event properties - JUCE_EDITOR_NAMESPACE::String text; - int fontH = (int)(midiFont->getHeight()); - int xtext = getWidth()-fontH-1; - int htext = 0; + g.fillRect(x-1, y, 3, (ny-y)); - if(cue >= 0) + if(shape == staves_shape) { - text = JUCE_EDITOR_NAMESPACE::String(cue); - int text_width = midiFont->getStringWidth(text)+2; - g.setFont(*midiFont); - g.drawTextAsPath(text, JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(xtext, y+1))); - xtext-=(int)(midiFont->getHeight()); - htext = text_width; + int alt = getAlteration(evt_pitch); + switch(alt) + { + case ALTERATION_DIESIS: + g.drawTextAsPath("B", JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(x-3, y-8))); + break; + case ALTERATION_BEMOLLE: + g.drawTextAsPath("b", JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(x-3, y-8))); + } } - if(evt_label != 0) - { - text = JUCE_EDITOR_NAMESPACE::String(evt_label); - int text_width = midiFont->getStringWidth(text)+2; - - g.setFont(*midiFont); - g.drawTextAsPath(text, JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(xtext, y+1))); - - if(text_width > htext) htext = text_width; - xtext-=(int)(midiFont->getHeight()); - } - if(htext > 0 && markersIsSelected(evt))//draw rect around props - { - g.setColour(labelColor); - g.fillRect(xtext+fontH, y+1, fontH*2+2, htext+2); - g.setColour(forecolor); - } - - evt = scoreGui->getNext(obj, evt, &evt_time, &cue, &evt_label); - }*/ + evt = scoreGui->getNext(obj, evt, &evt_time, &evt_pitch, &evt_duration); + } } } @@ -1116,101 +1095,162 @@ (p >=79 && p<=86) || (p >=103 && p<=110); } - void drawBlackStaff(JUCE_EDITOR_NAMESPACE::Graphics& g, int startLine, int startx, int width, int pixPitchTransp, int key, bool drawKey) + void drawBlackStaff(JUCE_EDITOR_NAMESPACE::Graphics& g, int startLine, int startpix, int length, int pixPitchTransp, int key, bool drawKey) { int transp = pixPitchTransp; - int positionY = STAVES_BOTTOM; - int start = STAVES_BOTTOM-startLine*LINE_STEP-transp; int i; - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::black*/forecolor); - for (i = 0; i < 5; i++) //draw horiz lines - { - positionY = start-i*LINE_STEP; - g.drawLine(startx, positionY, width, positionY); - } - if(drawKey) + g.setColour(forecolor); + if(!container->isVertical()) { - if(key == VIOLIN_KEY) //draw key + int position = STAVES_BOTTOM; + int start = STAVES_BOTTOM-startLine*LINE_STEP-transp; + for (i = 0; i < 5; i++) //draw horiz lines { - scoreFont.setHeight(70.0f); - g.setFont( scoreFont); - g.drawText("G", startx+5, positionY - 23, scoreFont.getStringWidth("G")+2, (int)(scoreFont.getHeight()), JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); + position = start-i*LINE_STEP; + g.drawLine(startpix, position, length, position); } - else + if(drawKey) { - scoreFont.setHeight(48.0f); - g.setFont( scoreFont); - g.drawText("?", startx+6, positionY-13, scoreFont.getStringWidth("?")+2, (int)(scoreFont.getHeight()), JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); + if(key == VIOLIN_KEY) //draw key + { + scoreFont.setHeight(70.0f); + g.setFont( scoreFont); + g.drawText("G", startpix+5, position - 23, scoreFont.getStringWidth("G")+2, (int)(scoreFont.getHeight()), JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); + } + else + { + scoreFont.setHeight(48.0f); + g.setFont( scoreFont); + g.drawText("?", startpix+6, position-13, scoreFont.getStringWidth("?")+2, (int)(scoreFont.getHeight()), JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); + } + g.drawLine(startpix, start, startpix, start-4*LINE_STEP); + g.setColour(lightcolor); + g.drawLine(startpix+STAVES_KEYWIDTH-1, start, startpix+STAVES_KEYWIDTH-1, start-4*LINE_STEP); } - g.drawLine(startx, start, startx, start-4*LINE_STEP); - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::grey*/lightcolor); - g.drawLine(startx+STAVES_KEYWIDTH-1, start, startx+STAVES_KEYWIDTH-1, start-4*LINE_STEP); } + else + { + int width = getWidth(); + int position = width-STAVES_BOTTOM; + int start = position+startLine*LINE_STEP+transp; + for (i = 0; i < 5; i++) //draw horiz lines + { + position = start+i*LINE_STEP; + g.drawLine(position, startpix, position, length); + } + if(drawKey) + { + if(key == VIOLIN_KEY) //draw key + { + scoreFont.setHeight(70.0f); + g.setFont( scoreFont); + g.drawTextAsPath("G", JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(position - 33, startpix+4))); + } + else + { + scoreFont.setHeight(48.0f); + g.setFont( scoreFont); + g.drawTextAsPath("?", JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(position - 25, startpix+6))); + } + g.drawLine(start, startpix, start+4*LINE_STEP, startpix); + g.setColour(lightcolor); + g.drawLine(start, startpix+STAVES_KEYWIDTH-1, start+4*LINE_STEP, startpix+STAVES_KEYWIDTH-1); + } + } } - void drawGrayStaff(JUCE_EDITOR_NAMESPACE::Graphics& g, int startLine, int startx, int width, int pixPitchTransp, bool drawKey) + void drawGrayStaff(JUCE_EDITOR_NAMESPACE::Graphics& g, int startLine, int startpix, int length, int pixPitchTransp, bool drawKey) { int transp = pixPitchTransp; - int positionY = STAVES_BOTTOM; - int start = STAVES_BOTTOM-startLine*LINE_STEP-transp; int j; - g.setColour( /*horizontalGridLinesColor*/lightcolor); - for (j = 0; j < 4; j++) - { - positionY = start-(j-1)*LINE_STEP; - g.drawLine(startx, positionY, width, positionY); - } - if(drawKey) + g.setColour( lightcolor); + if(!container->isVertical()) { - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::black*/forecolor); - g.drawLine(startx, start+LINE_STEP, startx, start-2*LINE_STEP); - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::grey*/lightcolor); - g.drawLine(startx+STAVES_KEYWIDTH-1, start+LINE_STEP, startx+STAVES_KEYWIDTH-1, start-2*LINE_STEP); - } + int position = STAVES_BOTTOM; + int start = STAVES_BOTTOM-startLine*LINE_STEP-transp; + for (j = 0; j < 4; j++) + { + position = start-(j-1)*LINE_STEP; + g.drawLine(startpix, position, length, position); + } + if(drawKey) + { + g.setColour(forecolor); + g.drawLine(startpix, start+LINE_STEP, startpix, start-2*LINE_STEP); + g.setColour(lightcolor); + g.drawLine(startpix+STAVES_KEYWIDTH-1, start+LINE_STEP, startpix+STAVES_KEYWIDTH-1, start-2*LINE_STEP); + } + } + else + { + int width = getWidth(); + int position = width-STAVES_BOTTOM; + int start = position+startLine*LINE_STEP+transp; + for (j = 0; j < 4; j++) + { + position = start+(j-1)*LINE_STEP; + g.drawLine(position, startpix, position, length); + } + if(drawKey) + { + g.setColour(forecolor); + g.drawLine(start-LINE_STEP, startpix, start+2*LINE_STEP, startpix); + g.setColour(lightcolor); + g.drawLine(start-LINE_STEP, startpix+STAVES_KEYWIDTH-1, start+2*LINE_STEP, startpix+STAVES_KEYWIDTH-1); + } + } } void drawStavesBackground(JUCE_EDITOR_NAMESPACE::Graphics& g) { int maxPitch = v_max; int minPitch = v_min; int transp = getPitchTransp(); - int width = getWidth(); + int length = (container->isVertical()) ? getHeight() : getWidth(); - g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor.withAlpha(opacity)); + g.fillAll(backcolor.withAlpha(opacity)); /********* First Bass Line ***********************************************/ if(staffIsDrawable_Staves(2, maxPitch, minPitch)) - drawGrayStaff(g, 5, 0, width, transp, false); + drawGrayStaff(g, 5, 0, length, transp, false); if(staffIsDrawable_Staves(1, maxPitch, minPitch)) - drawBlackStaff(g, 0, 0, width, transp, BASS_KEY, false); + drawBlackStaff(g, 0, 0, length, transp, BASS_KEY, false); /********* Second Bass Line **********************************************/ if(staffIsDrawable_Staves(4, maxPitch, minPitch)) - drawGrayStaff(g, 12, 0, width, transp, false); + drawGrayStaff(g, 12, 0, length, transp, false); if(staffIsDrawable_Staves(3, maxPitch, minPitch)) - drawBlackStaff(g, 7, 0, width, transp, BASS_KEY, false); + drawBlackStaff(g, 7, 0, length, transp, BASS_KEY, false); /********* Third Bass Line ***********************************************/ if(staffIsDrawable_Staves(6, maxPitch, minPitch)) { - g.setColour( /*horizontalGridLinesColor*/lightcolor); - int positionY = STAVES_BOTTOM-19*LINE_STEP-transp; - g.drawLine(0, positionY, getWidth(), positionY); + g.setColour(lightcolor); + if(!container->isVertical()) + { + int positionY = STAVES_BOTTOM-19*LINE_STEP-transp; + g.drawLine(0, positionY, getWidth(), positionY); + } + else + { + int positionX = (getWidth()-STAVES_BOTTOM)+19*LINE_STEP+transp; + g.drawLine(positionX, 0, positionX, getHeight()); + } } if(staffIsDrawable_Staves(5, maxPitch, minPitch)) - drawBlackStaff( g, 14, 0, width, transp, BASS_KEY, false); + drawBlackStaff( g, 14, 0, length, transp, BASS_KEY, false); /********* First Violin Line **********************************************/ if(staffIsDrawable_Staves(8, maxPitch, minPitch)) - drawGrayStaff( g, 25, 0, width, transp, false); + drawGrayStaff( g, 25, 0, length, transp, false); if(staffIsDrawable_Staves(7, maxPitch, minPitch)) - drawBlackStaff( g, 20, 0, width, transp, VIOLIN_KEY, false); + drawBlackStaff( g, 20, 0, length, transp, VIOLIN_KEY, false); /********* Second Violin Line *********************************************/ if(staffIsDrawable_Staves(10, maxPitch, minPitch)) - drawGrayStaff( g, 32, 0, width, transp, false); + drawGrayStaff( g, 32, 0, length, transp, false); if(staffIsDrawable_Staves(9, maxPitch, minPitch)) - drawBlackStaff( g, 27, 0, width, transp, VIOLIN_KEY, false); + drawBlackStaff( g, 27, 0, length, transp, VIOLIN_KEY, false); /********* Third Violin Line **********************************************/ if(staffIsDrawable_Staves(11, maxPitch, minPitch)) - drawBlackStaff( g, 34, 0, width, transp, VIOLIN_KEY, false); + drawBlackStaff( g, 34, 0, length, transp, VIOLIN_KEY, false); } void drawStavesInfoBackground(JUCE_EDITOR_NAMESPACE::Graphics& g) @@ -1220,7 +1260,7 @@ int transp = getPitchTransp(); int width = STAVES_INFO_SIZE; - g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor); + g.fillAll(backcolor); /********* First Bass Line ***********************************************/ if(staffIsDrawable_Staves(2, maxPitch, minPitch)) @@ -1236,13 +1276,24 @@ if(staffIsDrawable_Staves(6, maxPitch, minPitch)) { g.setColour( horizontalGridLinesColor); - int positionY = STAVES_BOTTOM-19*LINE_STEP-transp; - g.drawLine(STAVES_KEYX, positionY, getWidth(), positionY); - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::black*/forecolor); - g.drawLine(STAVES_KEYX, positionY+LINE_STEP, STAVES_KEYX, positionY-LINE_STEP); - //g.setColour(JUCE_EDITOR_NAMESPACE::Colours::grey); - g.drawLine(STAVES_KEYEND-1, positionY+LINE_STEP, STAVES_KEYEND-1, positionY-LINE_STEP); - } + if(!container->isVertical()) + { + int positionY = STAVES_BOTTOM-19*LINE_STEP-transp; + g.drawLine(STAVES_KEYX, positionY, getWidth(), positionY); + g.drawLine(STAVES_KEYEND-1, positionY+LINE_STEP, STAVES_KEYEND-1, positionY-LINE_STEP); + g.setColour(forecolor); + g.drawLine(STAVES_KEYX, positionY+LINE_STEP, STAVES_KEYX, positionY-LINE_STEP); + + } + else + { + int positionX = (getWidth()-STAVES_BOTTOM)+19*LINE_STEP+transp; + g.drawLine(positionX, STAVES_KEYX, positionX, getHeight()); + g.drawLine(positionX+LINE_STEP, STAVES_KEYEND-1, positionX-LINE_STEP, STAVES_KEYEND-1); + g.setColour(forecolor); + g.drawLine(positionX+LINE_STEP, STAVES_KEYX, positionX-LINE_STEP, STAVES_KEYX); + } + } if(staffIsDrawable_Staves(5, maxPitch, minPitch)) drawBlackStaff( g, 14, STAVES_KEYX, width, transp, BASS_KEY, true); /********* First Violin Line **********************************************/ @@ -1301,75 +1352,147 @@ void drawPianorollBackground(JUCE_EDITOR_NAMESPACE::Graphics& g) { - int width = getWidth(); - int maxPitch = v_max; - int minPitch = v_min; - int maxPitchY = editorGetY(maxPitch); - int minPitchY = editorGetY(minPitch); - int transp = /*pa.getVerticalTransp()*/0; - JUCE_EDITOR_NAMESPACE::String text; - - /********** Background ******************************************************/ - g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor.withAlpha(opacity)); - - /********** Gray Lines ******************************************************/ - int positionY; - int minGray = (minPitch/12)*12 + 3; - g.setColour(/*horizontalGridLinesColor*/lightcolor); - for(int i = minGray; i <= maxPitch; i+=3) - { - positionY = editorGetY(i); - g.drawLine(0, positionY-transp, width, positionY - transp); - } - /********** Black Lines *****************************************************/ - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::black*/forecolor); - int minBlack = minPitch/12; - int maxBlack = maxPitch/12; - - g.drawLine(0, minPitchY+1-transp, width, minPitchY+1-transp); - for(int j = minBlack+1; j <= maxBlack; j++) - { - positionY = editorGetY(j*12); - g.drawLine(0, positionY-transp, width, positionY-transp); - } - g.drawLine(0, maxPitchY-3-transp, width, maxPitchY-3-transp); + if(!container->isVertical()) + { + int width = getWidth(); + int maxPitch = v_max; + int minPitch = v_min; + int maxPitchY = editorGetY(maxPitch); + int minPitchY = editorGetY(minPitch); + + JUCE_EDITOR_NAMESPACE::String text; + /********** Background ******************************************************/ + g.fillAll(backcolor.withAlpha(opacity)); + + /********** Gray Lines ******************************************************/ + int positionY; + int minGray = (minPitch/12)*12 + 3; + g.setColour(lightcolor); + for(int i = minGray; i <= maxPitch; i+=3) + { + positionY = editorGetY(i); + g.drawLine(0, positionY, width, positionY); + } + /********** Black Lines *****************************************************/ + g.setColour(forecolor); + int minBlack = minPitch/12; + int maxBlack = maxPitch/12; + + g.drawLine(0, minPitchY+1, width, minPitchY+1); + for(int j = minBlack+1; j <= maxBlack; j++) + { + positionY = editorGetY(j*12); + g.drawLine(0, positionY, width, positionY); + } + g.drawLine(0, maxPitchY-3, width, maxPitchY-3); + } + else + { + int height = getHeight(); + int maxPitch = v_max; + int minPitch = v_min; + int maxPitchX = editorGetX(maxPitch); + int minPitchX = editorGetX(minPitch); + JUCE_EDITOR_NAMESPACE::String text; + /********** Background ******************************************************/ + g.fillAll(backcolor.withAlpha(opacity)); + + /********** Gray Lines ******************************************************/ + int positionX; + int minGray = (minPitch/12)*12 + 3; + g.setColour(lightcolor); + for(int i = minGray; i <= maxPitch; i+=3) + { + positionX = editorGetX(i); + g.drawLine(positionX, 0, positionX, height); + } + /********** Black Lines *****************************************************/ + g.setColour(forecolor); + int minBlack = minPitch/12; + int maxBlack = maxPitch/12; + + g.drawLine(minPitchX-1, 0, minPitchX-1, height); + for(int j = minBlack+1; j <= maxBlack; j++) + { + positionX = editorGetX(j*12); + g.drawLine(positionX, 0, positionX, height); + } + g.drawLine(maxPitchX+3, 0, maxPitchX+3, height); + } } void drawPianorollInfoBackground(JUCE_EDITOR_NAMESPACE::Graphics& g) { - int maxPitch = v_max; - int minPitch = v_min; - int maxPitchY = editorGetY(maxPitch); - int minPitchY = editorGetY(minPitch); - int transp = 0 /*getPitchTransp()*/; - JUCE_EDITOR_NAMESPACE::String text; - int positionY; + if(!container->isVertical()) + { + int maxPitch = v_max; + int minPitch = v_min; + int maxPitchY = editorGetY(maxPitch); + int minPitchY = editorGetY(minPitch); + JUCE_EDITOR_NAMESPACE::String text; + int positionY; - g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor); - /********** Piano Keys *********************************************************/ - for (int i = maxPitch; i >= minPitch; i--) - { - positionY = editorGetY(i)-2; - if (isAlteration(i)) + g.fillAll(backcolor); + /********** Piano Keys *********************************************************/ + for (int i = maxPitch; i >= minPitch; i--) { - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::darkgrey*/forecolor); - g.fillRect(PIANO_KEYX, positionY-transp, PIANO_SHORTKEYWIDTH, KEYHEIGHT); + positionY = editorGetY(i)-2; + if (isAlteration(i)) + { + g.setColour(forecolor); + g.fillRect(PIANO_KEYX, positionY, PIANO_SHORTKEYWIDTH, KEYHEIGHT); + } + else + { + g.setColour(backcolor); + g.fillRect(PIANO_KEYX, positionY, PIANO_KEYWIDTH, KEYHEIGHT); + } } - else + /********** lines at top and bottom of the keybord ****************************/ + g.setColour(forecolor); + g.drawLine(PIANO_KEYX, maxPitchY-3, PIANO_KEYEND, maxPitchY-3); + g.drawLine(PIANO_KEYX, minPitchY+1, PIANO_KEYEND, minPitchY+1); + + /********** the vertical line at the end of keyboard ****************************/ + g.drawLine(PIANO_KEYEND-1, maxPitchY-3, PIANO_KEYEND-1, minPitchY+2); + g.drawLine(PIANO_KEYX-1, maxPitchY-3, PIANO_KEYX-1, minPitchY+2); + } + else + { + int maxPitch = v_max; + int minPitch = v_min; + int maxPitchX = editorGetX(maxPitch); + int minPitchX = editorGetX(minPitch); + JUCE_EDITOR_NAMESPACE::String text; + int positionX; + + g.fillAll(backcolor); + /********** Piano Keys *********************************************************/ + for (int i = maxPitch; i >= minPitch; i--) { - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor); - g.fillRect(PIANO_KEYX, positionY -transp, PIANO_KEYWIDTH, KEYHEIGHT); + positionX = editorGetX(i)/*+2*/; + if (isAlteration(i)) + { + g.setColour(forecolor); + g.fillRect(positionX, PIANO_KEYX, KEYHEIGHT, PIANO_SHORTKEYWIDTH); + } + else + { + g.setColour(backcolor); + g.fillRect(positionX, PIANO_KEYX, KEYHEIGHT, PIANO_KEYWIDTH); + } } + /********** the vertical line at the end of keyboard ****************************/ + g.setColour(forecolor); + g.drawLine(maxPitchX+3, PIANO_KEYX, maxPitchX+3, PIANO_KEYEND); + g.drawLine(minPitchX-1, PIANO_KEYX, minPitchX-1, PIANO_KEYEND); + + /********** lines at top and bottom of the keybord ****************************/ + g.drawLine(maxPitchX+4, PIANO_KEYEND-1, minPitchX-1, PIANO_KEYEND-1); + g.drawLine(maxPitchX+4, PIANO_KEYX-1, minPitchX-1, PIANO_KEYX-1); } - /********** lines at top and bottom of the keybord ****************************/ - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::black*/forecolor); - g.drawLine(PIANO_KEYX, maxPitchY-3-transp, PIANO_KEYEND, maxPitchY-3-transp); - g.drawLine(PIANO_KEYX, minPitchY+1-transp, PIANO_KEYEND, minPitchY+1-transp); - - /********** the vertical line at the end of keyboard ****************************/ - g.drawLine(PIANO_KEYEND-1, maxPitchY-3-transp, PIANO_KEYEND-1, minPitchY+2-transp); - g.drawLine(PIANO_KEYX-1, maxPitchY-3-transp, PIANO_KEYX-1, minPitchY+2-transp); } + /////////////////////////////////////////////////////////////////////////////////////////////// void createAndDrawStavesInfoBackground() { @@ -1952,11 +2075,14 @@ { if(shape == staves_shape) { + int q = x/12; + int r = getRestFromIntervall((int)(x - q*12)); + return ((getWidth()-STAVES_BOTTOM)+9+(q*7+r)*4 + 3) + getPitchTransp(); } else { double dx = (PIANO_BOTTOM - PIANO_TOP)/127.0f; - return PIANO_TOP + (int)((v_max-x)*dx); + return (getWidth()-PIANO_TOP) - (int)((v_max-x)*dx); } } @@ -1979,15 +2105,8 @@ } else { - if(shape == staves_shape) - { - /*float dy = getHeight()/container->getHLength(); - return (int)((y+container->getHTransposition())*dy*container->getHZoom());*/ - } - else - { - - } + float dy = getHeight()/container->getHLength(); + return (int)((y+container->getHTransposition())*dy*container->getHZoom()); } } double editorGetInvX(float x) @@ -2000,11 +2119,29 @@ } else { - float width = getWidth(); - float dx = width/v_range; - return (x/dx + v_min); + int temp; + if(shape == staves_shape) + { + int width = getWidth(); + temp = (x -(width-STAVES_BOTTOM) -9 -getPitchTransp())/4; + + int rest = (x -(width-STAVES_BOTTOM) -9 -getPitchTransp()) - temp*4; + int q = temp/7; + int r = temp - q*7; + temp = q*12 + getIntervallFromRest(r, rest); + } + else + { + int dx = (PIANO_BOTTOM - PIANO_TOP)/127.0f; + temp = v_max - (x - PIANO_TOP)/dx; + } + + if(temp < v_min) temp = v_min; + else if(temp > v_max) temp = v_max; + return temp; } } + double editorGetInvY(float y) { if(!container->isVertical()) @@ -2012,8 +2149,8 @@ int temp; if(shape == staves_shape) { - temp = (STAVES_BOTTOM-9-y)/4 + getPitchTransp(); - int rest = (STAVES_BOTTOM-9-y) - temp*4; + temp = (STAVES_BOTTOM-9-y - getPitchTransp())/4; + int rest = (STAVES_BOTTOM-9-y - getPitchTransp()) - temp*4; int q = temp/7; int r = temp - q*7; temp = q*12 + getIntervallFromRest(r, rest); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bor...@us...> - 2008-07-09 16:00:34
|
Revision: 1813 http://ftm.svn.sourceforge.net/ftm/?rev=1813&view=rev Author: borghesi Date: 2008-07-09 09:00:37 -0700 (Wed, 09 Jul 2008) Log Message: ----------- ftm.editor: changed name of midi_gui interface to score_gui interface Modified Paths: -------------- trunk/ftm/build/max/osx-macho/ftmexternals.xcodeproj/project.pbxproj trunk/ftm/externals/max/ftm.editor.cpp trunk/ftm/ftmlib/classes/track.c trunk/ftm/ftmlib/parser.h trunk/ftm/ftmlib/predefsymbols.h trunk/ftm/gui/Juce/c_gui/guiinterfaces.h trunk/ftm/gui/Juce/common/EditorContainer.cpp trunk/ftm/gui/Juce/common/imtrjuce.h trunk/ftm/gui/Juce/cpp_gui/guiinterfaces.h Added Paths: ----------- trunk/ftm/gui/Juce/common/ScoreEditor.cpp trunk/ftm/gui/Juce/common/ScoreTableView.cpp Removed Paths: ------------- trunk/ftm/gui/Juce/common/MidiEditor.cpp trunk/ftm/gui/Juce/common/MidiTableView.cpp Modified: trunk/ftm/build/max/osx-macho/ftmexternals.xcodeproj/project.pbxproj =================================================================== --- trunk/ftm/build/max/osx-macho/ftmexternals.xcodeproj/project.pbxproj 2008-07-09 10:07:51 UTC (rev 1812) +++ trunk/ftm/build/max/osx-macho/ftmexternals.xcodeproj/project.pbxproj 2008-07-09 16:00:37 UTC (rev 1813) @@ -197,6 +197,8 @@ 3B9D37B30E1CD6CC002ED38C /* EditorContainerListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B9D37B10E1CD6CC002ED38C /* EditorContainerListener.h */; }; 3B9D37B40E1CD6CC002ED38C /* InfoPanel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3B9D37B20E1CD6CC002ED38C /* InfoPanel.cpp */; }; 3BA368CD0E0A60050011055C /* libjuce.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BDB04330D197490006AEB4A /* libjuce.a */; }; + 3BA9E3B80E2513A500B88643 /* ScoreEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BA9E3B60E2513A500B88643 /* ScoreEditor.cpp */; }; + 3BA9E3B90E2513A500B88643 /* ScoreTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BA9E3B70E2513A500B88643 /* ScoreTableView.cpp */; }; 3BCAC5EC0CBE5E7E00020156 /* FvecEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BCAC5EB0CBE5E7E00020156 /* FvecEditor.cpp */; }; 3BDB03F40D197463006AEB4A /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BDB03F30D197463006AEB4A /* IOKit.framework */; }; 3BDB03F50D197463006AEB4A /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BDB03F30D197463006AEB4A /* IOKit.framework */; }; @@ -207,8 +209,6 @@ 3BDB05960D1975EB006AEB4A /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BDB05940D1975EB006AEB4A /* OpenGL.framework */; }; 3BDD17CC0DCF11B100E6ED8C /* CursorTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BDD17CA0DCF11B100E6ED8C /* CursorTool.cpp */; }; 3BDD17CD0DCF11B100E6ED8C /* RegionTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BDD17CB0DCF11B100E6ED8C /* RegionTool.cpp */; }; - 3BDD44BF0E18E5AD00EC6BFB /* MidiEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BDD44BD0E18E5AD00EC6BFB /* MidiEditor.cpp */; }; - 3BDD44C00E18E5AD00EC6BFB /* MidiTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BDD44BE0E18E5AD00EC6BFB /* MidiTableView.cpp */; }; 3BDD54C70DC5DD970047D21D /* EditorTool.h in Headers */ = {isa = PBXBuildFile; fileRef = 3BDD54C50DC5DD970047D21D /* EditorTool.h */; }; 3BDD54C80DC5DD970047D21D /* EditTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3BDD54C60DC5DD970047D21D /* EditTool.cpp */; }; 3BDF29340D06C26800436BD5 /* EditorContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B145DB90CBA86FF0013392A /* EditorContainer.h */; }; @@ -621,6 +621,8 @@ 3B9C56390D5DF07000051CD5 /* TrackScoobEditor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = TrackScoobEditor.cpp; sourceTree = "<group>"; }; 3B9D37B10E1CD6CC002ED38C /* EditorContainerListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditorContainerListener.h; sourceTree = "<group>"; }; 3B9D37B20E1CD6CC002ED38C /* InfoPanel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InfoPanel.cpp; sourceTree = "<group>"; }; + 3BA9E3B60E2513A500B88643 /* ScoreEditor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScoreEditor.cpp; sourceTree = "<group>"; }; + 3BA9E3B70E2513A500B88643 /* ScoreTableView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScoreTableView.cpp; sourceTree = "<group>"; }; 3BCAC5EB0CBE5E7E00020156 /* FvecEditor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FvecEditor.cpp; sourceTree = "<group>"; }; 3BDB03F30D197463006AEB4A /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; }; 3BDB04330D197490006AEB4A /* libjuce.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjuce.a; path = ../../../components/juce/bin/UninstalledProducts/libjuce.a; sourceTree = SOURCE_ROOT; }; @@ -628,8 +630,6 @@ 3BDB05940D1975EB006AEB4A /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = "<absolute>"; }; 3BDD17CA0DCF11B100E6ED8C /* CursorTool.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CursorTool.cpp; sourceTree = "<group>"; }; 3BDD17CB0DCF11B100E6ED8C /* RegionTool.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RegionTool.cpp; sourceTree = "<group>"; }; - 3BDD44BD0E18E5AD00EC6BFB /* MidiEditor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MidiEditor.cpp; sourceTree = "<group>"; }; - 3BDD44BE0E18E5AD00EC6BFB /* MidiTableView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MidiTableView.cpp; sourceTree = "<group>"; }; 3BDD54C50DC5DD970047D21D /* EditorTool.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = EditorTool.h; sourceTree = "<group>"; }; 3BDD54C60DC5DD970047D21D /* EditTool.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = EditTool.cpp; sourceTree = "<group>"; }; 3BDF2B860D07201800436BD5 /* InspectorContainer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = InspectorContainer.h; sourceTree = "<group>"; }; @@ -1143,8 +1143,6 @@ children = ( 3B9D37B10E1CD6CC002ED38C /* EditorContainerListener.h */, 3B9D37B20E1CD6CC002ED38C /* InfoPanel.cpp */, - 3BDD44BD0E18E5AD00EC6BFB /* MidiEditor.cpp */, - 3BDD44BE0E18E5AD00EC6BFB /* MidiTableView.cpp */, 3BE7C48A0DEC385D00A0B7A5 /* ImtrEditor.h */, 3BE7C48B0DEC385D00A0B7A5 /* ImtrEditorListener.h */, 3BE7C48C0DEC385D00A0B7A5 /* imtrjuce.h */, @@ -1166,6 +1164,8 @@ 3BDF2B8A0D07203500436BD5 /* InspectorContainer.cpp */, 3BDF2B860D07201800436BD5 /* InspectorContainer.h */, 3B4E71150CC8E399006DFB5A /* MarkersTableView.cpp */, + 3BA9E3B60E2513A500B88643 /* ScoreEditor.cpp */, + 3BA9E3B70E2513A500B88643 /* ScoreTableView.cpp */, 3B40FAA50D351B7D00A25542 /* ScrollZoomListener.h */, 3BFB5BB10CF860BF00FB74F9 /* SpectrogramEditor.cpp */, 3B9C56390D5DF07000051CD5 /* TrackScoobEditor.cpp */, @@ -3150,9 +3150,9 @@ 3BDD17CC0DCF11B100E6ED8C /* CursorTool.cpp in Sources */, 3BDD17CD0DCF11B100E6ED8C /* RegionTool.cpp in Sources */, 3BEDC5350DE428630051B77A /* MarkersEditor.cpp in Sources */, - 3BDD44BF0E18E5AD00EC6BFB /* MidiEditor.cpp in Sources */, - 3BDD44C00E18E5AD00EC6BFB /* MidiTableView.cpp in Sources */, 3B9D37B40E1CD6CC002ED38C /* InfoPanel.cpp in Sources */, + 3BA9E3B80E2513A500B88643 /* ScoreEditor.cpp in Sources */, + 3BA9E3B90E2513A500B88643 /* ScoreTableView.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Modified: trunk/ftm/externals/max/ftm.editor.cpp =================================================================== --- trunk/ftm/externals/max/ftm.editor.cpp 2008-07-09 10:07:51 UTC (rev 1812) +++ trunk/ftm/externals/max/ftm.editor.cpp 2008-07-09 16:00:37 UTC (rev 1813) @@ -1234,7 +1234,7 @@ else if(track_type == fts_number_class) gui_interface = (imtr_guiInterface *)fts_object_get_gui_interface(obj, fts_s_bpf); else if(track_type == scoob_class) - gui_interface = (imtr_guiInterface *)fts_object_get_gui_interface(obj, fts_s_midi); + gui_interface = (imtr_guiInterface *)fts_object_get_gui_interface(obj, fts_s_score); } else if(cl == sequence_class) { Modified: trunk/ftm/ftmlib/classes/track.c =================================================================== --- trunk/ftm/ftmlib/classes/track.c 2008-07-09 10:07:51 UTC (rev 1812) +++ trunk/ftm/ftmlib/classes/track.c 2008-07-09 16:00:37 UTC (rev 1813) @@ -48,7 +48,7 @@ static fts_schema_t *tempo_sequence_schema = NULL; static imtr_guiInterfaceBpf *track_gui_interface_bpf = NULL; static imtr_guiInterfaceSpectrogram *track_gui_interface_spectro = NULL; -static imtr_guiInterfaceMidi *track_gui_interface_midi = NULL; +static imtr_guiInterfaceScore *track_gui_interface_score = NULL; fts_class_t *track_class = 0; @@ -1927,28 +1927,28 @@ /************************************************************ * - * Midi Gui Interface + * Score Gui Interface * */ static int -track_gui_midi_is_vector() +track_gui_score_is_vector() { return 0; } static int -track_gui_midi_get_size(void *obj) +track_gui_score_get_size(void *obj) { return sequence_get_size( track_get_events((track_t *)obj)); } static double -track_gui_midi_get_duration(void *obj) +track_gui_score_get_duration(void *obj) { return sequence_get_total_duration( track_get_events((track_t *)obj)); } static void * -track_gui_midi_get_first(void *obj, double *time, double *pitch, double *duration) +track_gui_score_get_first(void *obj, double *time, double *pitch, double *duration) { event_t *evt = sequence_get_first(track_get_events((track_t *)obj)); if(evt != NULL) @@ -1976,7 +1976,7 @@ } static void * -track_gui_midi_get_next(void *obj, void *evt, double *time, double *pitch, double *duration) +track_gui_score_get_next(void *obj, void *evt, double *time, double *pitch, double *duration) { event_t *event = event_get_next((event_t *)evt); if(event != NULL) @@ -2003,7 +2003,7 @@ } static void * -track_gui_midi_get_by_index(void *obj, int the_index, double *time, double *pitch, double *duration) +track_gui_score_get_by_index(void *obj, int the_index, double *time, double *pitch, double *duration) { event_t *evt = sequence_get_event_by_index( track_get_events((track_t *)obj), the_index); if(evt != NULL) @@ -2031,7 +2031,7 @@ } static void * -track_gui_midi_add(void *obj, double time, double pitch, double duration) +track_gui_score_add(void *obj, double time, double pitch, double duration) { event_t *evt = NULL; fts_atom_t a[4]; @@ -2049,19 +2049,19 @@ } static void -track_gui_midi_move(void *obj, void *evt, int index, double time) +track_gui_score_move(void *obj, void *evt, int index, double time) { sequence_move_event( track_get_events((track_t *)obj), (event_t *)evt, time); } static void -track_gui_midi_remove(void *obj, void *evt, int index) +track_gui_score_remove(void *obj, void *evt, int index) { sequence_remove_event(track_get_events((track_t *)obj), (event_t *)evt); } static void -track_gui_midi_get_values(void *obj, void *evt, double *time, double *pitch, double *duration) +track_gui_score_get_values(void *obj, void *evt, double *time, double *pitch, double *duration) { if(evt != NULL) { @@ -2084,7 +2084,7 @@ } static void -track_gui_midi_set_pitch(void *obj, void *evt, int index, double pitch) +track_gui_score_set_pitch(void *obj, void *evt, int index, double pitch) { scoob_t *scoob = (scoob_t *)fts_get_object(event_get_value((event_t *)evt)); scoob_set_pitch(scoob, pitch); @@ -2250,21 +2250,21 @@ fts_class_gui_interface(cl, fts_s_spectrogram, track_gui_interface_spectro); - track_gui_interface_midi = (imtr_guiInterfaceMidi *)fts_malloc(sizeof(imtr_guiInterfaceMidi)); - ((imtr_guiInterface *)track_gui_interface_midi)->name = fts_symbol_name(fts_s_midi); - track_gui_interface_midi->isVector = track_gui_midi_is_vector; - track_gui_interface_midi->getSize = track_gui_midi_get_size; - track_gui_interface_midi->getDuration = track_gui_midi_get_duration; - track_gui_interface_midi->move = track_gui_midi_move; - track_gui_interface_midi->remove = track_gui_midi_remove; - track_gui_interface_midi->add = track_gui_midi_add; - track_gui_interface_midi->getFirst = track_gui_midi_get_first; - track_gui_interface_midi->getNext = track_gui_midi_get_next; - track_gui_interface_midi->getValues = track_gui_midi_get_values; - track_gui_interface_midi->getByIndex = track_gui_midi_get_by_index; - track_gui_interface_midi->setPitch = track_gui_midi_set_pitch; + track_gui_interface_score = (imtr_guiInterfaceScore *)fts_malloc(sizeof(imtr_guiInterfaceScore)); + ((imtr_guiInterface *)track_gui_interface_score)->name = fts_symbol_name(fts_s_score); + track_gui_interface_score->isVector = track_gui_score_is_vector; + track_gui_interface_score->getSize = track_gui_score_get_size; + track_gui_interface_score->getDuration = track_gui_score_get_duration; + track_gui_interface_score->move = track_gui_score_move; + track_gui_interface_score->remove = track_gui_score_remove; + track_gui_interface_score->add = track_gui_score_add; + track_gui_interface_score->getFirst = track_gui_score_get_first; + track_gui_interface_score->getNext = track_gui_score_get_next; + track_gui_interface_score->getValues = track_gui_score_get_values; + track_gui_interface_score->getByIndex = track_gui_score_get_by_index; + track_gui_interface_score->setPitch = track_gui_score_set_pitch; - fts_class_gui_interface(cl, fts_s_midi, track_gui_interface_midi); + fts_class_gui_interface(cl, fts_s_score, track_gui_interface_score); } Modified: trunk/ftm/ftmlib/parser.h =================================================================== --- trunk/ftm/ftmlib/parser.h 2008-07-09 10:07:51 UTC (rev 1812) +++ trunk/ftm/ftmlib/parser.h 2008-07-09 16:00:37 UTC (rev 1813) @@ -1,52 +1,159 @@ -typedef union { +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Skeleton interface for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TK_INT = 258, + TK_FLOAT = 259, + TK_SYMBOL = 260, + TK_OPEN_PAR = 261, + TK_CLOSED_PAR = 262, + TK_OPEN_CPAR = 263, + TK_CLOSED_CPAR = 264, + TK_OPEN_SQPAR = 265, + TK_CLOSED_SQPAR = 266, + TK_TUPLE = 267, + TK_PREFIX = 268, + TK_ELEMENT = 269, + TK_ASSIGN = 270, + TK_SEND = 271, + TK_COMMA = 272, + TK_SEMI = 273, + TK_SPACE = 274, + TK_EQUAL = 275, + TK_COLON_EQUAL = 276, + TK_MINUS_EQUAL = 277, + TK_PLUS_EQUAL = 278, + TK_DIV_EQUAL = 279, + TK_TIMES_EQUAL = 280, + TK_LOGICAL_OR = 281, + TK_LOGICAL_AND = 282, + TK_NOT_EQUAL = 283, + TK_EQUAL_EQUAL = 284, + TK_SMALLER_EQUAL = 285, + TK_SMALLER = 286, + TK_GREATER_EQUAL = 287, + TK_GREATER = 288, + TK_SHIFT_RIGHT = 289, + TK_SHIFT_LEFT = 290, + TK_MINUS = 291, + TK_PLUS = 292, + TK_BIT_XOR = 293, + TK_BIT_OR = 294, + TK_BIT_AND = 295, + TK_PERCENT = 296, + TK_DIV = 297, + TK_TIMES = 298, + TK_UPLUS = 299, + TK_UMINUS = 300, + TK_LOGICAL_NOT = 301, + TK_POWER = 302, + TK_DOLLAR = 303, + TK_SECT = 304 + }; +#endif +/* Tokens. */ +#define TK_INT 258 +#define TK_FLOAT 259 +#define TK_SYMBOL 260 +#define TK_OPEN_PAR 261 +#define TK_CLOSED_PAR 262 +#define TK_OPEN_CPAR 263 +#define TK_CLOSED_CPAR 264 +#define TK_OPEN_SQPAR 265 +#define TK_CLOSED_SQPAR 266 +#define TK_TUPLE 267 +#define TK_PREFIX 268 +#define TK_ELEMENT 269 +#define TK_ASSIGN 270 +#define TK_SEND 271 +#define TK_COMMA 272 +#define TK_SEMI 273 +#define TK_SPACE 274 +#define TK_EQUAL 275 +#define TK_COLON_EQUAL 276 +#define TK_MINUS_EQUAL 277 +#define TK_PLUS_EQUAL 278 +#define TK_DIV_EQUAL 279 +#define TK_TIMES_EQUAL 280 +#define TK_LOGICAL_OR 281 +#define TK_LOGICAL_AND 282 +#define TK_NOT_EQUAL 283 +#define TK_EQUAL_EQUAL 284 +#define TK_SMALLER_EQUAL 285 +#define TK_SMALLER 286 +#define TK_GREATER_EQUAL 287 +#define TK_GREATER 288 +#define TK_SHIFT_RIGHT 289 +#define TK_SHIFT_LEFT 290 +#define TK_MINUS 291 +#define TK_PLUS 292 +#define TK_BIT_XOR 293 +#define TK_BIT_OR 294 +#define TK_BIT_AND 295 +#define TK_PERCENT 296 +#define TK_DIV 297 +#define TK_TIMES 298 +#define TK_UPLUS 299 +#define TK_UMINUS 300 +#define TK_LOGICAL_NOT 301 +#define TK_POWER 302 +#define TK_DOLLAR 303 +#define TK_SECT 304 + + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +#line 61 "/Users/borghesi/projects/ftm/build/max/osx-macho/../../../ftmlib/parser.y" +{ fts_atom_t a; fts_parsetree_t *n; -} YYSTYPE; -#define TK_INT 257 -#define TK_FLOAT 258 -#define TK_SYMBOL 259 -#define TK_OPEN_PAR 260 -#define TK_CLOSED_PAR 261 -#define TK_OPEN_CPAR 262 -#define TK_CLOSED_CPAR 263 -#define TK_OPEN_SQPAR 264 -#define TK_CLOSED_SQPAR 265 -#define TK_TUPLE 266 -#define TK_PREFIX 267 -#define TK_ELEMENT 268 -#define TK_ASSIGN 269 -#define TK_SEND 270 -#define TK_COMMA 271 -#define TK_SEMI 272 -#define TK_SPACE 273 -#define TK_EQUAL 274 -#define TK_COLON_EQUAL 275 -#define TK_PLUS_EQUAL 276 -#define TK_MINUS_EQUAL 277 -#define TK_TIMES_EQUAL 278 -#define TK_DIV_EQUAL 279 -#define TK_LOGICAL_OR 280 -#define TK_LOGICAL_AND 281 -#define TK_EQUAL_EQUAL 282 -#define TK_NOT_EQUAL 283 -#define TK_GREATER 284 -#define TK_GREATER_EQUAL 285 -#define TK_SMALLER 286 -#define TK_SMALLER_EQUAL 287 -#define TK_SHIFT_LEFT 288 -#define TK_SHIFT_RIGHT 289 -#define TK_PLUS 290 -#define TK_MINUS 291 -#define TK_TIMES 292 -#define TK_DIV 293 -#define TK_PERCENT 294 -#define TK_BIT_AND 295 -#define TK_BIT_OR 296 -#define TK_BIT_XOR 297 -#define TK_UMINUS 298 -#define TK_UPLUS 299 -#define TK_LOGICAL_NOT 300 -#define TK_POWER 301 -#define TK_DOLLAR 302 -#define TK_SECT 303 +} +/* Line 1529 of yacc.c. */ +#line 152 "y.tab.h" + YYSTYPE; +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + + Modified: trunk/ftm/ftmlib/predefsymbols.h =================================================================== --- trunk/ftm/ftmlib/predefsymbols.h 2008-07-09 10:07:51 UTC (rev 1812) +++ trunk/ftm/ftmlib/predefsymbols.h 2008-07-09 16:00:37 UTC (rev 1813) @@ -396,6 +396,7 @@ PREDEF_SYMBOL( fts_s_points, "points"); PREDEF_SYMBOL( fts_s_redraw, "redraw"); PREDEF_SYMBOL( fts_s_region, "region"); +PREDEF_SYMBOL( fts_s_score, "score"); PREDEF_SYMBOL( fts_s_scrollzoom, "scrollzoom"); PREDEF_SYMBOL( fts_s_shape, "shape"); PREDEF_SYMBOL( fts_s_spectrogram, "spectrogram"); Modified: trunk/ftm/gui/Juce/c_gui/guiinterfaces.h =================================================================== --- trunk/ftm/gui/Juce/c_gui/guiinterfaces.h 2008-07-09 10:07:51 UTC (rev 1812) +++ trunk/ftm/gui/Juce/c_gui/guiinterfaces.h 2008-07-09 16:00:37 UTC (rev 1813) @@ -470,128 +470,137 @@ /*********************************************************** * - * midi GUI interface + * score GUI interface * */ -/** @name Midi gui interface (a track of time tagged midi events) +/** @name Score gui interface (a track of time tagged events) * @{ */ /** - * @brief returns true if the midi object is implemented as a vector (acces by index), false if as a list - * @return 1 if midi track is implemented as a vector, 0 otherwise + * @brief returns true if the score object is implemented as a vector (acces by index), false if as a list + * @return 1 if score track is implemented as a vector, 0 otherwise * @ingroup guiinterfaces */ -typedef int (*imtr_gui_interface_midi_is_vector_t)(void); +typedef int (*imtr_gui_interface_score_is_vector_t)(void); /** - * @brief returns the number of midi events - * @param obj the midi track object - * @return midi track size + * @brief returns the number of score events + * @param obj the score track object + * @return score track size * @ingroup guiinterfaces */ -typedef int (*imtr_gui_interface_midi_get_size_t)(void *obj); +typedef int (*imtr_gui_interface_score_get_size_t)(void *obj); + /** - * @brief returns the midi track duration (time tag of the last midi event) - * @param obj the midi track object - * @return midi track duration + * @brief returns the score track duration (time tag of the last score event) + * @param obj the score track object + * @return score track duration * @ingroup guiinterfaces */ -typedef double (*imtr_gui_interface_midi_get_duration_t)(void *obj); +typedef double (*imtr_gui_interface_score_get_duration_t)(void *obj); + /** - * @brief returns the first midi event - * @param obj the midi track object - * @param time returns the time of the first midi event - * @param pitch returns the pitch of the first midi event - * @param duration returns the duration of the first midi event - * @return midi event at given time + * @brief returns the first score event + * @param obj the score track object + * @param time returns the time of the first score event + * @param pitch returns the pitch of the first score event + * @param duration returns the duration of the first score event + * @return score event at given time * @ingroup guiinterfaces */ -typedef void *(*imtr_gui_interface_midi_get_first_t)(void *obj, double *time, double *pitch, double *duration); +typedef void *(*imtr_gui_interface_score_get_first_t)(void *obj, double *time, double *pitch, double *duration); + /** - * @brief returns the midi event at given index - * @param obj the midi track object + * @brief returns the score event at given index + * @param obj the score track object * @param the_index index * @param time returns the time of returned event - * @return midi event at given index + * @return score event at given index * @ingroup guiinterfaces */ -typedef void *(*imtr_gui_interface_midi_get_by_index_t)(void *obj, int the_index, double *time, double *pitch, double *duration); +typedef void *(*imtr_gui_interface_score_get_by_index_t)(void *obj, int the_index, double *time, double *pitch, double *duration); + /** - * @brief add a midi event at given index - * @param obj the midi track object + * @brief add a score event at given index + * @param obj the score track object * @param the_time time - * @return the added midi event + * @return the added score event * @ingroup guiinterfaces */ -typedef void *(*imtr_gui_interface_midi_add_t)(void *obj, double the_time, double pitch, double duration); +typedef void *(*imtr_gui_interface_score_add_t)(void *obj, double the_time, double pitch, double duration); + /** - * @brief move a midi event to given time - * @param obj the midi track object - * @param evt the midi event - * @param index the index of the midi event + * @brief move a score event to given time + * @param obj the score track object + * @param evt the score event + * @param index the index of the score event * @param the_time time * @ingroup guiinterfaces */ -typedef void (*imtr_gui_interface_midi_move_t)(void *obj, void *evt, int index, double the_time); +typedef void (*imtr_gui_interface_score_move_t)(void *obj, void *evt, int index, double the_time); + /** - * @brief set pitch to midi event - * @param obj the midi track object - * @param evt the midi event - * @param index the index of the midi event + * @brief set pitch to score event + * @param obj the score track object + * @param evt the score event + * @param index the index of the score event * @param pitch the new pitch * @ingroup guiinterfaces */ -typedef void (*imtr_gui_interface_midi_set_pitch_t)(void *obj, void *evt, int index, double pitch); +typedef void (*imtr_gui_interface_score_set_pitch_t)(void *obj, void *evt, int index, double pitch); + /** - * @brief remove a midi event - * @param obj the midi track object - * @param marker the midi event to be removed - * @param index the index of the midi event to be removed + * @brief remove a score event + * @param obj the score track object + * @param marker the score event to be removed + * @param index the index of the score event to be removed * @ingroup guiinterfaces */ -typedef void (*imtr_gui_interface_midi_remove_t)(void *obj, void *evt, int index); +typedef void (*imtr_gui_interface_score_remove_t)(void *obj, void *evt, int index); + /** - * @brief returns next midi event of given midi event - * @param obj the midi track object - * @param evt the midi event - * @param the_time returns the time of next midi event - * @return returns next midi event + * @brief returns next score event of given score event + * @param obj the score track object + * @param evt the score event + * @param the_time returns the time of next score event + * @return returns next score event * @ingroup guiinterfaces */ -typedef void *(*imtr_gui_interface_midi_get_next_t)(void *obj, void *evt, double *time, double *pitch, double *duration); +typedef void *(*imtr_gui_interface_score_get_next_t)(void *obj, void *evt, double *time, double *pitch, double *duration); + /** - * @brief gets the time, ^pitch and duration of given midi event - * @param obj the midi track object - * @param evt the midi event + * @brief gets the time, pitch and duration of given score event + * @param obj the score track object + * @param evt the score event * @param time returns the time tag * @param pitch returns the pitch * @param duration returns the duration * @ingroup guiinterfaces */ -typedef void (*imtr_gui_interface_midi_get_values_t)(void *obj, void *evt, double *time, double *pitch, double *duration); +typedef void (*imtr_gui_interface_score_get_values_t)(void *obj, void *evt, double *time, double *pitch, double *duration); /** - * @brief midi gui interface + * @brief score gui interface * @ingroup guiinterfaces */ -typedef struct _imtrGuiInterfaceMidi +typedef struct _imtrGuiInterfaceScore { imtr_guiInterface head; - imtr_gui_interface_midi_is_vector_t isVector; - imtr_gui_interface_midi_get_size_t getSize; - imtr_gui_interface_midi_get_duration_t getDuration; - imtr_gui_interface_midi_move_t move; - imtr_gui_interface_midi_remove_t remove; + imtr_gui_interface_score_is_vector_t isVector; + imtr_gui_interface_score_get_size_t getSize; + imtr_gui_interface_score_get_duration_t getDuration; + imtr_gui_interface_score_move_t move; + imtr_gui_interface_score_remove_t remove; - imtr_gui_interface_midi_get_first_t getFirst; - imtr_gui_interface_midi_get_next_t getNext; - imtr_gui_interface_midi_get_values_t getValues; + imtr_gui_interface_score_get_first_t getFirst; + imtr_gui_interface_score_get_next_t getNext; + imtr_gui_interface_score_get_values_t getValues; - imtr_gui_interface_midi_get_by_index_t getByIndex; - imtr_gui_interface_midi_add_t add; - imtr_gui_interface_midi_set_pitch_t setPitch; + imtr_gui_interface_score_get_by_index_t getByIndex; + imtr_gui_interface_score_add_t add; + imtr_gui_interface_score_set_pitch_t setPitch; - } imtr_guiInterfaceMidi; -/** @} Midi gui interface */ + } imtr_guiInterfaceScore; +/** @} Score gui interface */ #endif Modified: trunk/ftm/gui/Juce/common/EditorContainer.cpp =================================================================== --- trunk/ftm/gui/Juce/common/EditorContainer.cpp 2008-07-09 10:07:51 UTC (rev 1812) +++ trunk/ftm/gui/Juce/common/EditorContainer.cpp 2008-07-09 16:00:37 UTC (rev 1813) @@ -232,7 +232,7 @@ EditorTabbedContainer::EditorTabbedContainer(const JUCE_EDITOR_NAMESPACE::TabbedButtonBar::Orientation orientation, EditorContainer *container) : JUCE_EDITOR_NAMESPACE::TabbedComponent(orientation), container(container) { - foreTabColor = container->getBackgroundColor().darker(0.2f).withAlpha(container->getOpacity()); + foreTabColor = container->getBackgroundColor().withAlpha(container->getOpacity()); } EditorTabbedContainer::~EditorTabbedContainer() @@ -276,7 +276,7 @@ void EditorTabbedContainer::opacityChanged() { - foreTabColor = container->getBackgroundColor().darker(0.2f).withAlpha(container->getOpacity()); + foreTabColor = container->getBackgroundColor().withAlpha(container->getOpacity()); container->getEditors()[getCurrentTabIndex()]->setOpacity(container->getOpacity()); } @@ -288,10 +288,10 @@ opacityChanged(); if(index >= 0) - setTabBackgroundColour(index, color/*.darker(0.2f)*/); + setTabBackgroundColour(index, color); else for(i = 0; i < getNumTabs(); i++) - setTabBackgroundColour(i, color/*.darker(0.2f)*/); + setTabBackgroundColour(i, color); setOutline( color, 0); } @@ -314,7 +314,7 @@ dscroll = NULL; infoPanel = NULL; - backcolor = JUCE_EDITOR_NAMESPACE::Colour(126, 132, 178); + backcolor = /*JUCE_EDITOR_NAMESPACE::Colour(126, 132, 178)*/JUCE_EDITOR_NAMESPACE::Colours::white; selectionColorAsBackground = true; regionSelectionColor = backcolor.brighter(); rangeFont = new JUCE_EDITOR_NAMESPACE::Font(JUCE_EDITOR_NAMESPACE::String( "Lucida Grande"), 10, JUCE_EDITOR_NAMESPACE::Font::italic); @@ -427,7 +427,7 @@ for(i = 0; i < ftmeditors.size(); i++) { tabbedContainer->addTab( JUCE_EDITOR_NAMESPACE::String(ftmeditors[i]->getDescription()), - backcolor.darker(0.2f), dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(ftmeditors[i]), true); + backcolor, dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(ftmeditors[i]), true); editors.add(ftmeditors[i]); } addAndMakeVisible(tabbedContainer); @@ -582,8 +582,8 @@ if(interface_name == JUCE_EDITOR_NAMESPACE::String("markers")) editor = createMarkersEditor((void *)obj, (imtr_guiInterfaceMarkers *)guiInterface, this, listener); else - if(interface_name == JUCE_EDITOR_NAMESPACE::String("midi")) - editor = createMidiEditor((void *)obj, (imtr_guiInterfaceMidi *)guiInterface, this, listener); + if(interface_name == JUCE_EDITOR_NAMESPACE::String("score")) + editor = createScoreEditor((void *)obj, (imtr_guiInterfaceScore *)guiInterface, this, listener); } else { @@ -936,7 +936,7 @@ editors[i]->setBackgroundColor(backcolor); if(tabbedContainer != NULL) - tabbedContainer->backgroundChanged(-1, color.darker(0.2f)); + tabbedContainer->backgroundChanged(-1, color); if(dscroll != NULL) (dynamic_cast<EditorScrollBar *>(dscroll))->setScrollbarColor(true, color); @@ -1160,7 +1160,7 @@ { removeChildComponent((dynamic_cast<Component *>(editors[i]))); tabbedContainer->addTab( JUCE_EDITOR_NAMESPACE::String(editors[i]->getDescription()), - editors[i]->getBackgroundColor().darker(0.2f), (dynamic_cast<Component *>(editors[i])), true); + editors[i]->getBackgroundColor(), (dynamic_cast<Component *>(editors[i])), true); } addAndMakeVisible(tabbedContainer); tabbedContainer->refresh(); Deleted: trunk/ftm/gui/Juce/common/MidiEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/MidiEditor.cpp 2008-07-09 10:07:51 UTC (rev 1812) +++ trunk/ftm/gui/Juce/common/MidiEditor.cpp 2008-07-09 16:00:37 UTC (rev 1813) @@ -1,2047 +0,0 @@ -/* - * IMTR EDITOR - * Copyright (C) 2004 by IRCAM-Centre Georges Pompidou, Paris, France. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 - * of the License, or (at your option) any later version. - * - * See file COPYING.LIB - for further informations on licensing terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -//#include "src/juce_WithoutMacros.h" -#ifdef DISABLE_JUCE_NAMESPACE -#define DONT_SET_USING_JUCE_NAMESPACE 1 -#endif -#include "juce.h" -#include "imtrjuce.h" -#include "ImtrEditor.h" - -#define float_Pi 3.14159265358979323846f - -#define STAVES_KEYX 7 -#define STAVES_KEYWIDTH 28 -#define KEYHEIGHT 3 -#define STAVES_KEYEND (STAVES_KEYX + STAVES_KEYWIDTH) - -#define VIOLIN_KEY 0 -#define BASS_KEY 1 - -#define LINE_STEP 8 -#define STAVES_BOTTOM 320 -#define STAVES_TOP 16 - -#define PIANO_KEYX 11 -#define PIANO_KEYWIDTH 24 -#define PIANO_SHORTKEYWIDTH 16 -#define PIANO_KEYEND (PIANO_KEYX + PIANO_KEYWIDTH) -#define PIANO_BOTTOM 399 -#define PIANO_TOP 18 - -#define GRAY_STEP 9 -#define BLACK_STEP 36 - -#define ALTERATION_DIESIS 1 -#define ALTERATION_BEMOLLE -1 -#define ALTERATION_NOTHING 0 - -#define VERTICAL_DIR 0 -#define HORIZONTAL_DIR 1 - -#define PIANOROLL_INFO_SIZE 35 -#define STAVES_INFO_SIZE 35 - -/*class MidiMouseLabel : public JUCE_EDITOR_NAMESPACE::Component -{ - JUCE_EDITOR_NAMESPACE::Font font; - JUCE_EDITOR_NAMESPACE::String text; - -public: - MidiMouseLabel() - { - font = JUCE_EDITOR_NAMESPACE::Font(JUCE_EDITOR_NAMESPACE::String( "Lucida Grande"), 11, JUCE_EDITOR_NAMESPACE::Font::italic); - text = ""; - } - ~MidiMouseLabel(){} - - void setText(JUCE_EDITOR_NAMESPACE::String txt) - { - text = txt; - } - void paint(JUCE_EDITOR_NAMESPACE::Graphics& g) - { - g.fillAll(JUCE_EDITOR_NAMESPACE::Colours::white); - g.setFont(font); - g.setColour(JUCE_EDITOR_NAMESPACE::Colours::black); - g.drawSingleLineText(text, 1, getHeight()-1); - } -};*/ - -class MidiEditor : public JUCE_EDITOR_NAMESPACE::Component, public ImtrEditor -{ - JUCE_EDITOR_NAMESPACE::Colour backcolor, lightcolor, forecolor, selectColor, labelColor; - float opacity; - - imtr_guiInterfaceMidi *midiGui; - void *obj; - - ImtrEditorListener *listener; - EditorContainer *container; - float v_range, value_range, original_length; - float v_min, v_max; - float value_min, value_max; - int view_mode; - JUCE_EDITOR_NAMESPACE::Array <void *> selection; - JUCE_EDITOR_NAMESPACE::Array <int> indexSelection; - - //JUCE_EDITOR_NAMESPACE::Label *mouseLabel; - //MidiMouseLabel *mouseLabel; - - /*---selection-----*/ - bool selecting, movingSelection, regionSelection; - JUCE_EDITOR_NAMESPACE::Rectangle selRect; - - int moving_dx, moving_dy; - bool directionChoosen; - int move_direction; - - JUCE_EDITOR_NAMESPACE::Component *midiList; - JUCE_EDITOR_NAMESPACE::Font *midiFont; - JUCE_EDITOR_NAMESPACE::Font *gridSubdivisionFont; - - EditorContainer::tool_name currentToolToRestore; - /*---shapes ----------------**/ - enum midi_shape_mode {pianoroll_shape, staves_shape}; - midi_shape_mode shape; - - /*-- range mode --------------**/ - enum midi_range_mode {whole_range, used_range}; - midi_range_mode range_mode; - - /*-------- offscreen -------*/ - JUCE_EDITOR_NAMESPACE::Image *offscreen; - JUCE_EDITOR_NAMESPACE::Image *stavesBackgroundImage; - JUCE_EDITOR_NAMESPACE::Image *pianorollBackgroundImage; - JUCE_EDITOR_NAMESPACE::Image *stavesInfoImage; - JUCE_EDITOR_NAMESPACE::Image *pianorollInfoImage; - bool redraw_offscreen; - - JUCE_EDITOR_NAMESPACE::Colour horizontalGridLinesColor; - - JUCE_EDITOR_NAMESPACE::Font scoreFont; -public: - MidiEditor(void *obj, imtr_guiInterfaceMidi *midiGui, EditorContainer *container, ImtrEditorListener *listener) : listener(listener), container(container), obj(obj), midiGui(midiGui) - { - setOpaque(false); - setInterceptsMouseClicks(true, true); - setWantsKeyboardFocus(true); - setMouseClickGrabsKeyboardFocus(true); - setFocusContainer(true); - - horizontalGridLinesColor = JUCE_EDITOR_NAMESPACE::Colour(220, 220, 220); - - backcolor = JUCE_EDITOR_NAMESPACE::Colours::white; - lightcolor = horizontalGridLinesColor; - forecolor = JUCE_EDITOR_NAMESPACE::Colours::black; - selectColor = forecolor.withAlpha(0.6f); - labelColor = forecolor.withAlpha(0.4f); - - opacity = container->getOpacity(); - - /* time range */ - original_length = midiGui->getDuration(obj); - /* values in fmat */ - value_min = -20.0f; - value_max = 20.0f; - value_range = value_max - value_min; - /* fmat index */ - v_min = 0.0f; - v_max = 127.0f; - v_range = v_max-v_min; - - selecting = false; - movingSelection = false; - regionSelection = false; - - moving_dx = moving_dy = 0; - directionChoosen = false; - move_direction = -1; - - midiList = NULL; - - midiFont = new JUCE_EDITOR_NAMESPACE::Font(JUCE_EDITOR_NAMESPACE::String( "Lucida Grande"), 10, JUCE_EDITOR_NAMESPACE::Font::italic); - gridSubdivisionFont = new JUCE_EDITOR_NAMESPACE::Font(JUCE_EDITOR_NAMESPACE::String( "Serif"), 10, JUCE_EDITOR_NAMESPACE::Font::plain); - - shape = pianoroll_shape; - - addMouseListener((dynamic_cast<JUCE_EDITOR_NAMESPACE::MouseListener *>(container->getCurrentTool())), false); - - if(getWidth()>0 && getHeight() > 0) - offscreen = new JUCE_EDITOR_NAMESPACE::Image(JUCE_EDITOR_NAMESPACE::Image::ARGB, getWidth(), getHeight(), true); - else - offscreen = NULL; - - stavesBackgroundImage = NULL; - pianorollBackgroundImage = NULL; - stavesInfoImage = NULL; - pianorollInfoImage = NULL; - - redraw_offscreen = true; - description = JUCE_EDITOR_NAMESPACE::String("markers"); - - currentToolToRestore = EditorContainer::edit_tool; - - scoreFont = NULL; - loadScoreFont(); - - //addAndMakeVisible(mouseLabel = new MidiMouseLabel()); - /*addAndMakeVisible(mouseLabel = new JUCE_EDITOR_NAMESPACE::Label("mouse label", "1000 , 15")); - mouseLabel->setEditable(false, true, true); - mouseLabel->setFont(JUCE_EDITOR_NAMESPACE::Font(JUCE_EDITOR_NAMESPACE::String( "Lucida Grande"), 11, JUCE_EDITOR_NAMESPACE::Font::italic));*/ - } - - ~MidiEditor() - { - } - - void loadScoreFont() - { - /*JUCE_EDITOR_NAMESPACE::File cwd; - cwd = JUCE_EDITOR_NAMESPACE::File::getSpecialLocation(JUCE_EDITOR_NAMESPACE::File::currentExecutableFile); - JUCE_EDITOR_NAMESPACE::String cwd_str = cwd.getFullPathName(); - - listener->postError(cwd_str);*/ - - //JUCE_EDITOR_NAMESPACE::File ttf_file = JUCE_EDITOR_NAMESPACE::File("../Resources/MusicSync.ttf"); - /*JUCE_EDITOR_NAMESPACE::File ttf_file = JUCE_EDITOR_NAMESPACE::File("/Users/borghesi/Desktop/MusiSync.ttf"); - if(ttf_file.exists()) - { - JUCE_EDITOR_NAMESPACE::FileInputStream in_stream(ttf_file); - JUCE_EDITOR_NAMESPACE::Typeface tf(in_stream); - scoreFont = JUCE_EDITOR_NAMESPACE::Font(tf); - }*/ - scoreFont = JUCE_EDITOR_NAMESPACE::Font(JUCE_EDITOR_NAMESPACE::String( "MusiSync"), 52, JUCE_EDITOR_NAMESPACE::Font::plain); - } - - /* void mouseMove(const JUCE_EDITOR_NAMESPACE::MouseEvent& e) - { - double time = editorGetInvX(e.x); - double pitch = editorGetInvY(e.y); - mouseLabel->setText(JUCE_EDITOR_NAMESPACE::String(time)+" , "+JUCE_EDITOR_NAMESPACE::String(pitch)); - mouseLabel->repaint(mouseLabel->getX(), mouseLabel->getY(), mouseLabel->getWidth(), mouseLabel->getHeight()); - }*/ - - void setShape(JUCE_EDITOR_NAMESPACE::String sp) - { - if(sp == JUCE_EDITOR_NAMESPACE::String("staves")) - shape = staves_shape; - else if(sp == JUCE_EDITOR_NAMESPACE::String("pianoroll")) - shape = pianoroll_shape; - - findPitchRange(); - updateBackgroundOffscreens(); - objectRefresh(); - } - - JUCE_EDITOR_NAMESPACE::String getShape() - { - if(shape == staves_shape) return JUCE_EDITOR_NAMESPACE::String("staves"); - else if(shape == pianoroll_shape) return JUCE_EDITOR_NAMESPACE::String("pianoroll"); - else return JUCE_EDITOR_NAMESPACE::String("staves"); - } - - /**************************** - Finding events - **************************/ - - void *getFirstVisibleEvent(double *time, double *pitch, double *duration) - { - double startVisibleTime; - double evt_time, n_time; - void *n_event = NULL; - double evt_pitch, n_pitch, evt_duration, n_duration; - - if(container->isVertical()) - startVisibleTime = editorGetInvY(0); - else - startVisibleTime = editorGetInvX(0); - - void *event = midiGui->getFirst(obj, &evt_time, &evt_pitch, &evt_duration); - - while(event != NULL) - { - n_event = midiGui->getNext(obj, event, &n_time, &n_pitch, &n_duration); - if(n_time + n_duration >= startVisibleTime) break; - event = n_event; - } - *time = evt_time; - *pitch = evt_pitch; - *duration = evt_duration; - return event; - } - - int getFirstVisibleIndex(double *time, double *pitch, double *duration) - { - double i_time, next_time; - double i_duration, next_duration; - double i_pitch, next_pitch; - - int size = midiGui->getSize(obj); - float startTime = (container->isVertical()) ? editorGetInvY(0) : editorGetInvX(0); - int i; - int first = 0; - for(i = 0; i < size-1; i++) - { - midiGui->getByIndex(obj, i, &next_time, &next_pitch, &next_duration); - if(next_time >= startTime) - { - first = i; - break; - } - else - { - i_time = next_time; - i_pitch = next_pitch; - i_duration = next_duration; - } - } - if(first > 0) - { - first--; - *time = i_time; - *pitch = i_pitch; - *duration = i_duration; - } - else - { - *time = next_time; - *pitch = next_pitch; - *duration = next_duration; - } - return first; - } - - void *getNextAfterLastVisibleEvent() - { - double endVisibleTime = (container->isVertical() ? editorGetInvY(getHeight()) : editorGetInvX(getWidth())); - double evt_time, next_time; - void *n_event = NULL; - double evt_pitch; - double evt_duration; - void *event = midiGui->getFirst(obj, &evt_time, &evt_pitch, &evt_duration); - - while(event != NULL) - { - n_event = midiGui->getNext(obj, event, &next_time, &evt_pitch, &evt_duration); - if(next_time >= endVisibleTime) break; - event = n_event; - } - return ((event != NULL) ? midiGui->getNext(obj, event, &next_time, &evt_pitch, &evt_duration) : NULL); - } - - - int getLastVisibleIndex(double *time) - { - double i_time, next_time; - double i_pitch, next_pitch; - double i_duration, next_duration; - - int size = midiGui->getSize(obj); - float endTime = (container->isVertical()) ? editorGetInvY(getHeight()) : editorGetInvX(getWidth()); - int i; - int last = size-1; - for(i = 0; i<size-1; i++) - { - midiGui->getByIndex(obj, i, &next_time, &next_pitch, &next_duration); - if(next_time > endTime) - { - last = i; - break; - } - i_time = next_time; - i_pitch = next_pitch; - i_duration = next_duration; - } - if(last < size-1) - { - last++; - *time = next_time; - } - else - *time = i_time; - - return last; - } - - void *midiGetEventAt(int x, int y) - { - double evt_time, evt_pitch, evt_duration; - int evt_x, evt_nx, evt_y; - void *event = midiGui->getFirst(obj, &evt_time, &evt_pitch, &evt_duration); - while(event != NULL) - { - evt_x = editorGetX(evt_time); - evt_nx = editorGetX(evt_time + evt_duration); - evt_y = editorGetY(evt_pitch); - if((x >= evt_x - 2 && x <= evt_nx + 2) && (y <= evt_y + 2 && y >= evt_y - 2)) - return event; - - event = midiGui->getNext(obj, event, &evt_time, &evt_pitch, &evt_duration); - } - return NULL; - } - - int midiGetIndexAt(int pix) - { - double time, t_delta, evt_time, next_time; - double evt_pitch, evt_duration; - - int size = midiGui->getSize(obj); - - if(pix > 0) pix--; - if(!container->isVertical()) - { - time = editorGetInvX(pix); - t_delta = editorGetInvX(2)-editorGetInvX(0); - } - else - { - time = editorGetInvY(pix); - t_delta = editorGetInvY(2)-editorGetInvY(0); - } - - int i; - for(i = 0; i < size; i++) - { - midiGui->getByIndex(obj, i, &next_time, &evt_pitch, &evt_duration); - if(next_time > time) break; - evt_time = next_time; - } - - if((next_time < time + t_delta) && (next_time > time - t_delta)) - return i; - else - if(evt_time <= time + t_delta && evt_time >= time - t_delta) - return i-1; - else - return -1; - } - - /********************** - selection - **********************/ - void midiSelect(void *evt) - { - if(!selection.contains(evt)) - selection.add(evt); - } - void markerIndexSelect(int i) - { - if(!indexSelection.contains(i)) - indexSelection.add(i); - } - void midiDeselect(void *evt) - { - selection.removeValue(evt); - } - void markerIndexDeselect(int i) - { - indexSelection.removeValue(i); - } - bool markersIsSelected(void *evt) - { - return selection.contains(evt); - } - bool markerIndexIsSelected(int i) - { - return indexSelection.contains(i); - } - bool midiIsSelectionEmpty() - { - if(midiGui->isVector()) - return (indexSelection.size() == 0); - else - return (selection.size() == 0); - } - void midiDeselectAll() - { - if(midiGui->isVector()) - indexSelection.clear(); - else - selection.clear(); - } - void midiSetMovingSelection(bool move) - { - movingSelection = move; - } - - void midiMoveSelection(int dx, int dy) - { - double time, pitch, duration; - int new_pitch; - if(dx != 0 || dy != 0) - { - if(midiGui->isVector()) - { - float pix; - int i; - - if(!container->isVertical()) - { - if(dx != 0) - for(i = indexSelection.size()-1; i >= 0; i--) - { - midiGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); - pix = editorGetX(time) + dx; - midiGui->move(obj, NULL, indexSelection[i], editorGetInvX(pix)); - } - else - for(i = 0; i< indexSelection.size(); i++) - { - midiGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); - pix = editorGetY(pitch) + dy; - new_pitch = (int)editorGetInvY(pix); - if(new_pitch > 127) new_pitch = 127; - else if (new_pitch < 0) new_pitch = 0; - midiGui->setPitch(obj, NULL, indexSelection[i], new_pitch); - } - } - else - { - if(dy != 0) - for(i = indexSelection.size()-1; i >= 0; i--) - { - midiGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); - pix = editorGetY(time) + dy; - midiGui->move(obj, NULL, indexSelection[i], editorGetInvY(pix)); - } - else - for(i = 0; i< indexSelection.size(); i++) - { - midiGui->getByIndex(obj, indexSelection[i], &time, &pitch, &duration); - pix = editorGetY(pitch) + dx; - new_pitch = (int)editorGetInvX(pix); - if(new_pitch > 127) new_pitch = 127; - else if (new_pitch < 0) new_pitch = 0; - midiGui->setPitch(obj, NULL, indexSelection[i], new_pitch); - } - } - } - else - { - float pix; - int i; - double time, pitch, duration; - - if(!container->isVertical()) - { - if(dx != 0) - { - for(i = 0; i< selection.size(); i++) - { - midiGui->getValues(obj, selection[i], &time, &pitch, &duration); - pix = editorGetX(time) + dx; - midiGui->move(obj, selection[i], -1, editorGetInvX(pix)); - } - } - else - { - for(i = 0; i< selection.size(); i++) - { - midiGui->getValues(obj, selection[i], &time, &pitch, &duration); - pix = editorGetY(pitch) + dy; - new_pitch = (int)editorGetInvY(pix); - if(new_pitch > 127) new_pitch = 127; - else if (new_pitch < 0) new_pitch = 0; - midiGui->setPitch(obj, selection[i], -1, new_pitch); - } - } - } - else - { - if(dy != 0) - { - for(i = 0; i< selection.size(); i++) - { - midiGui->getValues(obj, selection[i], &time, &pitch, &duration); - pix = editorGetY(time) + dy; - midiGui->move(obj, selection[i], -1, editorGetInvY(pix)); - } - } - else - { - for(i = 0; i< selection.size(); i++) - { - midiGui->getValues(obj, selection[i], &time, &pitch, &duration); - pix = editorGetX(pitch) + dx; - new_pitch = (int)editorGetInvX(pix); - if(new_pitch > 127) new_pitch = 127; - else if (new_pitch < 0) new_pitch = 0; - midiGui->setPitch(obj, selection[i], -1, new_pitch); - } - } - } - } - } - } - - void markersDeleteSelection() - { - if(midiGui->isVector()) - { - int i; - for(i = indexSelection.size()-1; i >= 0; i--) - midiGui->remove(obj, NULL, indexSelection[i]); - indexSelection.clear(); - } - else - { - int i; - for(i = 0; i< selection.size(); i++) - midiGui->remove(obj, selection[i], -1); - selection.clear(); - } - - objectRefresh(); - } - - void midiSelectInRect(JUCE_EDITOR_NAMESPACE::Rectangle r) - { - if(midiGui->isVector()) - { - double start_time, end_time, evt_time; - double evt_pitch, evt_duration; - int i; - - if(!container->isVertical()) - { - start_time = editorGetInvX(r.getX()); - end_time = editorGetInvX( r.getX() + r.getWidth()); - } - else - { - start_time = editorGetInvY(r.getY()); - end_time = editorGetInvY( r.getY() + r.getHeight()); - } - - for(i = 0; i < midiGui->getSize(obj); i++) - { - midiGui->getByIndex(obj, i, &evt_time, &evt_pitch, &evt_duration); - if(evt_time >= start_time && evt_time <= end_time) - markerIndexSelect(i); - } - } - else - { - void *evt = NULL; - void *evt_after = NULL; - double start_time, end_time, evt_time; - double evt_pitch, evt_duration; - double maxPitch, minPitch; - - if(!container->isVertical()) - { - start_time = editorGetInvX(r.getX()); - end_time = editorGetInvX( r.getX() + r.getWidth()); - maxPitch = editorGetInvY(r.getY()); - minPitch = editorGetInvY(r.getY() + r.getHeight()); - } - else - { - start_time = editorGetInvY(r.getY()); - end_time = editorGetInvY( r.getY() + r.getHeight()); - minPitch = editorGetInvX(r.getX()); - maxPitch = editorGetInvX(r.getX() + r.getWidth()); - } - - evt = getFirstVisibleEvent(&evt_time, &evt_pitch, &evt_duration); - evt_after = getNextAfterLastVisibleEvent(); - - while (evt != NULL && evt != evt_after) - { - if((evt_time+evt_duration >= start_time && evt_time <= end_time) && - (evt_pitch >= minPitch && evt_pitch <= maxPitch)) - midiSelect(evt); - evt = midiGui->getNext(obj, evt, &evt_time, &evt_pitch, &evt_duration); - } - } - } - - - /********************** - paint - **********************/ - void drawMidiAsList(JUCE_EDITOR_NAMESPACE::Graphics& g) - { - void *evt; - void *last; - double evt_time; - double evt_pitch, evt_duration; - - scoreFont.setHeight(42.0f); - g.setFont(scoreFont); - - evt = getFirstVisibleEvent(&evt_time, &evt_pitch, &evt_duration); - last = getNextAfterLastVisibleEvent(); - - if(!container->isVertical()) - { - int x, nx, y; - while(evt != NULL && evt != last) - { - x = editorGetX(evt_time); - nx = editorGetX(evt_time+evt_duration); - y = editorGetY(evt_pitch); - - if(markersIsSelected(evt)) - g.setColour(JUCE_EDITOR_NAMESPACE::Colours::grey); - else - g.setColour(/*JUCE_EDITOR_NAMESPACE::Colours::black*/forecolor); - - g.fillRect(x, y-1, (nx-x), 3); - - if(shape == staves_shape) - { - int alt = getAlteration(evt_pitch); - switch(alt) - { - case ALTERATION_DIESIS: - g.drawSingleLineText("B", x-8, y+4); - break; - case ALTERATION_BEMOLLE: - g.drawSingleLineText("b", x-8, y+4); - } - } - - evt = midiGui->getNext(obj, evt, &evt_time, &evt_pitch, &evt_duration); - } - } - else - { - /*int y; - int width = getWidth(); - while(evt != NULL && evt != last) - { - y = editorGetY(evt_time); - g.drawLine(0, y, width, y); - - if(markersIsSelected(evt)) - { - g.setColour(selectColor); - g.fillRoundedRectangle(0, y-1, width, 3, 2); - g.setColour(forecolor); - } - - // draw event properties - JUCE_EDITOR_NAMESPACE::String text; - int fontH = (int)(midiFont->getHeight()); - int xtext = getWidth()-fontH-1; - int htext = 0; - - if(cue >= 0) - { - text = JUCE_EDITOR_NAMESPACE::String(cue); - int text_width = midiFont->getStringWidth(text)+2; - g.setFont(*midiFont); - g.drawTextAsPath(text, JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(xtext, y+1))); - xtext-=(int)(midiFont->getHeight()); - htext = text_width; - } - - if(evt_label != 0) - { - text = JUCE_EDITOR_NAMESPACE::String(evt_label); - int text_width = midiFont->getStringWidth(text)+2; - - g.setFont(*midiFont); - g.drawTextAsPath(text, JUCE_EDITOR_NAMESPACE::AffineTransform::rotation(float_Pi/2).followedBy(JUCE_EDITOR_NAMESPACE::AffineTransform::translation(xtext, y+1))); - - if(text_width > htext) htext = text_width; - xtext-=(int)(midiFont->getHeight()); - } - if(htext > 0 && markersIsSelected(evt))//draw rect around props - { - g.setColour(labelColor); - g.fillRect(xtext+fontH, y+1, fontH*2+2, htext+2); - g.setColour(forecolor); - } - - evt = midiGui->getNext(obj, evt, &evt_time, &cue, &evt_label); - }*/ - } - } - - void drawMidiAsVector(JUCE_EDITOR_NAMESPACE::Graphics& g) - { - /*double evt_time, last_time; - int cue; - char *evt_label; - int size = midiGui->getSize(obj); - - int first_idx = getFirstVisibleIndex(&evt_time, &cue, &evt_label); - int last_idx = getLastVisibleIndex(&last_time); - - g.setColour(forecolor); - if(!container->isVertical()) - { - int i, x; - int height = getHeight(); - for(i = first_idx; i < size && i<=last_idx; i++) - { - midiGui->getByIndex(obj, i, &evt_time, &cue, &evt_label); - x = editorGetX(evt_time); - g.drawLine(x, 0, x, height); - if(markerIndexIsSelected(i)) - { - g.setColour(selectColor); - g.fillRoundedRectangle(x-1, 0, 3, height, 2); - g.setColour(forecolor); - } - - // draw event properties - JUCE_EDITOR_NAMESPACE::String text; - int ytext = 1; - int wtext = 0; - - if(cue >= 0) - { - text = JUCE_EDITOR_NAMESPACE::String(cue); - int text_width = midiFont->getStringWidth(text)+2; - g.setFont(*midiFont); - g.drawText(text, x+2, ytext, text_width, (int)(midiFont->getHeight()), JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); - ytext+=(int)(midiFont->getHeight()); - wtext = text_width; - } - - if(evt_label != 0) - { - text = JUCE_EDITOR_NAMESPACE::String(evt_label); - int text_width = midiFont->getStringWidth(text)+2; - - g.setFont(*midiFont); - g.drawText(text, x+2, ytext, midiFont->getStringWidth(text)+2, (int)(midiFont->getHeight()), JUCE_EDITOR_NAMESPACE::Justification::centredLeft, true); - if(text_width > wtext) wtext = text_width; - ytext+=(int)(midiFont->getHeight()); - } - if(wtext > 0 && markerIndexIsSelected(i))//draw rect around props - { - g.setColour(labelColor); - g.fillRect(x+1, 1, wtext+2, ytext-1); - g.setColour(forecolor); - } - } - } - else - { - int i, y; - int width = getWidth(); - for(i = first_idx; i < size && i<=last_idx; i++) - { - midiGui->getByIndex(obj, i, &evt_time, &cue, &evt_label); - y = editorGetY(evt_time); - g.drawLine(0, y, width, y); - - if(markerIndexIsSelected(i)) - { - g.setColour(selectColor); - g.fillRoundedRectangle(0, y-1, width, 3, 2); - g.setColour(forecolor); - } - - // draw event properties - JUCE_EDITOR_NAMESPACE::String text; - int fontH = (int)(midiFont->getHeight()); - int xtext =... [truncated message content] |
From: Norbert S. <Nor...@ir...> - 2008-07-09 10:52:17
|
Youpieee! This seems to work suddenly... I just replaced everybody's non-SourceForge addresses by everybody's SourceForge address (I had forgotten that they are automatically forwarded), so don't worry about the kicked-out-message you just received. **NOS On 9 juil. 08, at 12:07, bor...@us... wrote: > Revision: 1812 > http://ftm.svn.sourceforge.net/ftm/?rev=1812&view=rev > Author: borghesi > Date: 2008-07-09 03:07:51 -0700 (Wed, 09 Jul 2008) > > Log Message: > ----------- > ftm.editor: added InfoPanel > > Modified Paths: > -------------- > trunk/ftm/gui/Juce/common/BpfEditor.cpp > trunk/ftm/gui/Juce/common/EditorContainer.cpp > trunk/ftm/gui/Juce/common/FvecEditor.cpp > trunk/ftm/gui/Juce/common/ImtrEditor.h > trunk/ftm/gui/Juce/common/MarkersEditor.cpp > trunk/ftm/gui/Juce/common/MidiEditor.cpp > trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp > > Added Paths: > ----------- > trunk/ftm/gui/Juce/common/InfoPanel.cpp > > Modified: trunk/ftm/gui/Juce/common/BpfEditor.cpp > =================================================================== > --- trunk/ftm/gui/Juce/common/BpfEditor.cpp 2008-07-09 09:59:51 UTC > (rev 1811) > +++ trunk/ftm/gui/Juce/common/BpfEditor.cpp 2008-07-09 10:07:51 UTC > (rev 1812) > @@ -1399,6 +1399,8 @@ > container->repaint(); > } > > + void layoutChanged(){} > + > void backgroundColorChanged(JUCE_EDITOR_NAMESPACE::Colour bcolor) > { > lightColour = bcolor.brighter(); > > Modified: trunk/ftm/gui/Juce/common/EditorContainer.cpp > =================================================================== > --- trunk/ftm/gui/Juce/common/EditorContainer.cpp 2008-07-09 > 09:59:51 UTC (rev 1811) > +++ trunk/ftm/gui/Juce/common/EditorContainer.cpp 2008-07-09 > 10:07:51 UTC (rev 1812) > @@ -743,6 +743,7 @@ > bar->setBounds(position, barBounds.getY(), barBounds.getWidth(), > barBounds.getHeight()); > next->setBounds(nextBounds.getX(), nextBounds.getY(), > nextBounds.getWidth()-dpos, nextBounds.getHeight()); > } > + containerRefresh(); > repaint(); > } > > @@ -941,6 +942,7 @@ > (dynamic_cast<EditorScrollBar *>(dscroll))- > >setScrollbarColor(true, color); > > setSplitColor(true, backcolor); > + containerRefresh(); > > repaint(); > } > @@ -1142,7 +1144,8 @@ > > void > EditorContainer::setLayout(layout_type ltype, > JUCE_EDITOR_NAMESPACE::Array <float> editorSizes) > -{ > +{ > + int i; > if(layout != ltype) > { > layout = ltype; > @@ -1150,8 +1153,6 @@ > { > if(layout == superposed) > { > - int i; > - > initTabbedContainer(); > clearSplitBars(); > > @@ -1172,7 +1173,6 @@ > removeChildComponent(tabbedContainer); > tabbedContainer = NULL; > } > - int i; > for(i = 0; i < editors.size(); i++) > { > addAndMakeVisible((dynamic_cast<Component *>(editors[i]))); > @@ -1184,14 +1184,19 @@ > } > resized(); > updateCursor(); > + containerRefresh(); > } > } > - else > + else { > if(layout == juxtaposed && editorSizes.size()> 0 && > editorSizes.size() == editors.size()) > { > initJuxtaposedEditorsSizes(editorSizes); > resized(); > + containerRefresh(); > } > + } > + for(i = 0; i < editors.size(); i++) > + editors[i]->layoutChanged(); > } > > void > @@ -1204,8 +1209,6 @@ > if(tabbedContainer != NULL) > tabbedContainer->setOrientation((orientation == horizontal) ? > > JUCE_EDITOR_NAMESPACE::TabbedButtonBar::TabsAtTop : > JUCE_EDITOR_NAMESPACE::TabbedButtonBar::TabsAtRight); > - > - > resized(); > } > } > > Modified: trunk/ftm/gui/Juce/common/FvecEditor.cpp > =================================================================== > --- trunk/ftm/gui/Juce/common/FvecEditor.cpp 2008-07-09 09:59:51 UTC > (rev 1811) > +++ trunk/ftm/gui/Juce/common/FvecEditor.cpp 2008-07-09 10:07:51 UTC > (rev 1812) > @@ -978,6 +978,8 @@ > container->repaint(); > } > > +void layoutChanged(){} > + > void backgroundColorChanged(JUCE_EDITOR_NAMESPACE::Colour bcolor) > { > lightColour = bcolor.brighter(); > > Modified: trunk/ftm/gui/Juce/common/ImtrEditor.h > =================================================================== > --- trunk/ftm/gui/Juce/common/ImtrEditor.h 2008-07-09 09:59:51 UTC > (rev 1811) > +++ trunk/ftm/gui/Juce/common/ImtrEditor.h 2008-07-09 10:07:51 UTC > (rev 1812) > @@ -65,6 +65,12 @@ > * @ingroup ImtrEditor > */ > virtual void objectChanged() = 0; > + /** > + * @brief called when the layout has changed > + * @ingroup ImtrEditor > + */ > + virtual void layoutChanged() = 0; > + > /** @} Object/interface */ > > /** @name View properties > > Added: trunk/ftm/gui/Juce/common/InfoPanel.cpp > =================================================================== > --- trunk/ftm/gui/Juce/common/InfoPanel.cpp > (rev 0) > +++ trunk/ftm/gui/Juce/common/InfoPanel.cpp 2008-07-09 10:07:51 UTC > (rev 1812) > @@ -0,0 +1,140 @@ > +/* > + * IMTR EDITOR > + * Copyright (C) 2004 by IRCAM-Centre Georges Pompidou, Paris, > France. > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public License > + * as published by the Free Software Foundation; either version 2.1 > + * of the License, or (at your option) any later version. > + * > + * See file COPYING.LIB > + for further informations on licensing terms. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > License > + * along with this program; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA > 02111-1307, USA. > + * > + */ > + > +#ifdef DISABLE_JUCE_NAMESPACE > +#define DONT_SET_USING_JUCE_NAMESPACE 1 > +#endif > + > +#include "juce.h" > +#include "imtrjuce.h" > + > +#include "juce.h" > +#include "imtrjuce.h" > + > +class InfoPanel : public JUCE_EDITOR_NAMESPACE::Component, public > EditorContainerListener > +{ > + EditorContainer *container; > + > +public: > + InfoPanel(EditorContainer *container): container(container) > + { > + setOpaque(true); > + setBufferedToImage(true); > + > + container->addEditorContainerListener(this); > + } > + > + ~InfoPanel() > + { > + } > + > + void paint(JUCE_EDITOR_NAMESPACE::Graphics& g) > + { > + g.fillAll(container->getBackgroundColor()); > + > + if(!container->isVertical()) > + { > + if(container->isLayoutSuperposed()) > + { > + if(container->getEditorsSize() > 0) > + { > + int ed_y = 0; > + if(container->isTabsVisible()) //draw top rectangle > + { > + ed_y = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component > *>(container->getEditors()[0]))->getY(); > + g.setColour(JUCE_EDITOR_NAMESPACE::Colours::black); > + g.drawLine(0, ed_y-1, getWidth(), ed_y-1); > + g.setColour(container->getBackgroundColor().darker()); > + g.drawLine(0, ed_y-2, getWidth(), ed_y-2); > + } > + > + ImtrEditor *editor = container->getEditors()[container- > >getForemost()]; > + if(editor->haveInfoPanel()) > + { > + JUCE_EDITOR_NAMESPACE::Image *img = editor- > >getInfoImage(); > + g.drawImageAt(img, 0, ed_y, false); > + } > + } > + } > + else //juxtaposed > + { > + JUCE_EDITOR_NAMESPACE::Rectangle bounds; > + int i; > + for(i=0; i<container->getEditorsSize(); i++) > + { > + ImtrEditor *editor = container->getEditors()[i]; > + if(editor->haveInfoPanel()) > + { > + JUCE_EDITOR_NAMESPACE::Image *img = editor- > >getInfoImage(); > + bounds = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component > *>(editor))->getBounds(); > + g.drawImageWithin(img, 0, bounds.getY(), getWidth(), > bounds.getHeight(), JUCE_EDITOR_NAMESPACE::RectanglePlacement::xLeft > | JUCE_EDITOR_NAMESPACE::RectanglePlacement::yTop | > JUCE_EDITOR_NAMESPACE::RectanglePlacement::doNotResize, false); > + } > + } > + } > + > + if(container->isDScrollVisible()) > + { > + int width = getWidth(); > + int height = getHeight(); > + int scroll_y = getHeight() - container->getDScrollSize(); > + g.setColour(JUCE_EDITOR_NAMESPACE::Colours::black); > + g.drawLine(0, scroll_y, width-1, scroll_y); > + g.drawLine(width-1, scroll_y, width-1, height); > + g.setColour(container->getBackgroundColor().brighter(0.3f)); > + g.drawLine(0, scroll_y+1, width-2, scroll_y+1); > + g.drawLine(width-2, scroll_y+1, width-2, height-1); > + g.setColour(container->getBackgroundColor().darker()); > + g.drawLine(0, height-1, width-1, height-1); > + g.drawLine(0, scroll_y+1, 0, height-1); > + } > + > + /*for(i = 0; i < container->getEditorsSize(); i++) > + { > + editor = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component > *>(container->getEditors()[0])); > + if(editor->haveInfoPanel()) > + { > + Image img = editor->getInfoImage(); > + g.drawImageAt(offscreen, x, y, false); > + } > + }*/ > + } > + else > + { > + > + } > + > + } > + void resized() > + { > + } > + > + void containerChanged() > + { > + repaint(); > + } > +}; > + > +JUCE_EDITOR_NAMESPACE::Component *createInfoPanel(EditorContainer > *container) > +{ > + return new InfoPanel(container); > +} > \ No newline at end of file > > > Property changes on: trunk/ftm/gui/Juce/common/InfoPanel.cpp > ___________________________________________________________________ > Name: svn:executable > + * > > Modified: trunk/ftm/gui/Juce/common/MarkersEditor.cpp > =================================================================== > --- trunk/ftm/gui/Juce/common/MarkersEditor.cpp 2008-07-09 09:59:51 > UTC (rev 1811) > +++ trunk/ftm/gui/Juce/common/MarkersEditor.cpp 2008-07-09 10:07:51 > UTC (rev 1812) > @@ -952,6 +952,8 @@ > container->repaint(); > } > > + void layoutChanged(){} > + > void setBackgroundColor(JUCE_EDITOR_NAMESPACE::Colour bcolor) > { > backcolor = bcolor; > > Modified: trunk/ftm/gui/Juce/common/MidiEditor.cpp > =================================================================== > --- trunk/ftm/gui/Juce/common/MidiEditor.cpp 2008-07-09 09:59:51 UTC > (rev 1811) > +++ trunk/ftm/gui/Juce/common/MidiEditor.cpp 2008-07-09 10:07:51 UTC > (rev 1812) > @@ -1176,7 +1176,7 @@ > int transp = getPitchTransp(); > int width = getWidth(); > > - g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor); > + g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/ > backcolor.withAlpha(opacity)); > > /********* First Bass Line > ***********************************************/ > if(staffIsDrawable_Staves(2, maxPitch, minPitch)) > @@ -1309,7 +1309,7 @@ > JUCE_EDITOR_NAMESPACE::String text; > > /********** Background > ******************************************************/ > - g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor); > + g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/ > backcolor.withAlpha(opacity)); > > /********** Gray Lines > ******************************************************/ > int positionY; > @@ -1643,6 +1643,12 @@ > container->repaint(); > } > > + void layoutChanged() > + { > + updateBackgroundOffscreens(); > + objectRefresh(); > + } > + > void setRangeMode(JUCE_EDITOR_NAMESPACE::String mode) > { > if(mode == JUCE_EDITOR_NAMESPACE::String("whole")) > @@ -1667,7 +1673,7 @@ > void setBackgroundColor(JUCE_EDITOR_NAMESPACE::Colour bcolor) > { > backcolor = bcolor; > - //lightColour = backcolor.brighter(); > + lightcolor = backcolor.contrasting(0.15f); > updateBackgroundOffscreens(); > objectRefresh(); > } > @@ -1697,6 +1703,8 @@ > void setOpacity(float alpha) > { > opacity = alpha; > + updateBackgroundOffscreens(); > + objectRefresh(); > } > > void setForemost(bool isForemost) > > Modified: trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp > =================================================================== > --- trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp 2008-07-09 > 09:59:51 UTC (rev 1811) > +++ trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp 2008-07-09 > 10:07:51 UTC (rev 1812) > @@ -699,6 +699,8 @@ > container->repaint(); > } > > + void layoutChanged(){} > + > void setBackgroundColor(JUCE_EDITOR_NAMESPACE::Colour bcolor) > { > backcolor = bcolor; > > > This was sent by the SourceForge.net collaborative development > platform, the world's largest Open Source development site. > > ------------------------------------------------------------------------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source project, > along with a healthy diet, reduces your potential for chronic lameness > and boredom. Vote Now at http://www.sourceforge.net/community/cca08 > _______________________________________________ > ftm-svn mailing list > ft...@li... > https://lists.sourceforge.net/lists/listinfo/ftm-svn > |
From: <bor...@us...> - 2008-07-09 10:07:43
|
Revision: 1812 http://ftm.svn.sourceforge.net/ftm/?rev=1812&view=rev Author: borghesi Date: 2008-07-09 03:07:51 -0700 (Wed, 09 Jul 2008) Log Message: ----------- ftm.editor: added InfoPanel Modified Paths: -------------- trunk/ftm/gui/Juce/common/BpfEditor.cpp trunk/ftm/gui/Juce/common/EditorContainer.cpp trunk/ftm/gui/Juce/common/FvecEditor.cpp trunk/ftm/gui/Juce/common/ImtrEditor.h trunk/ftm/gui/Juce/common/MarkersEditor.cpp trunk/ftm/gui/Juce/common/MidiEditor.cpp trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp Added Paths: ----------- trunk/ftm/gui/Juce/common/InfoPanel.cpp Modified: trunk/ftm/gui/Juce/common/BpfEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/BpfEditor.cpp 2008-07-09 09:59:51 UTC (rev 1811) +++ trunk/ftm/gui/Juce/common/BpfEditor.cpp 2008-07-09 10:07:51 UTC (rev 1812) @@ -1399,6 +1399,8 @@ container->repaint(); } + void layoutChanged(){} + void backgroundColorChanged(JUCE_EDITOR_NAMESPACE::Colour bcolor) { lightColour = bcolor.brighter(); Modified: trunk/ftm/gui/Juce/common/EditorContainer.cpp =================================================================== --- trunk/ftm/gui/Juce/common/EditorContainer.cpp 2008-07-09 09:59:51 UTC (rev 1811) +++ trunk/ftm/gui/Juce/common/EditorContainer.cpp 2008-07-09 10:07:51 UTC (rev 1812) @@ -743,6 +743,7 @@ bar->setBounds(position, barBounds.getY(), barBounds.getWidth(), barBounds.getHeight()); next->setBounds(nextBounds.getX(), nextBounds.getY(), nextBounds.getWidth()-dpos, nextBounds.getHeight()); } + containerRefresh(); repaint(); } @@ -941,6 +942,7 @@ (dynamic_cast<EditorScrollBar *>(dscroll))->setScrollbarColor(true, color); setSplitColor(true, backcolor); + containerRefresh(); repaint(); } @@ -1142,7 +1144,8 @@ void EditorContainer::setLayout(layout_type ltype, JUCE_EDITOR_NAMESPACE::Array <float> editorSizes) -{ +{ + int i; if(layout != ltype) { layout = ltype; @@ -1150,8 +1153,6 @@ { if(layout == superposed) { - int i; - initTabbedContainer(); clearSplitBars(); @@ -1172,7 +1173,6 @@ removeChildComponent(tabbedContainer); tabbedContainer = NULL; } - int i; for(i = 0; i < editors.size(); i++) { addAndMakeVisible((dynamic_cast<Component *>(editors[i]))); @@ -1184,14 +1184,19 @@ } resized(); updateCursor(); + containerRefresh(); } } - else + else { if(layout == juxtaposed && editorSizes.size()> 0 && editorSizes.size() == editors.size()) { initJuxtaposedEditorsSizes(editorSizes); resized(); + containerRefresh(); } + } + for(i = 0; i < editors.size(); i++) + editors[i]->layoutChanged(); } void @@ -1204,8 +1209,6 @@ if(tabbedContainer != NULL) tabbedContainer->setOrientation((orientation == horizontal) ? JUCE_EDITOR_NAMESPACE::TabbedButtonBar::TabsAtTop : JUCE_EDITOR_NAMESPACE::TabbedButtonBar::TabsAtRight); - - resized(); } } Modified: trunk/ftm/gui/Juce/common/FvecEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/FvecEditor.cpp 2008-07-09 09:59:51 UTC (rev 1811) +++ trunk/ftm/gui/Juce/common/FvecEditor.cpp 2008-07-09 10:07:51 UTC (rev 1812) @@ -978,6 +978,8 @@ container->repaint(); } +void layoutChanged(){} + void backgroundColorChanged(JUCE_EDITOR_NAMESPACE::Colour bcolor) { lightColour = bcolor.brighter(); Modified: trunk/ftm/gui/Juce/common/ImtrEditor.h =================================================================== --- trunk/ftm/gui/Juce/common/ImtrEditor.h 2008-07-09 09:59:51 UTC (rev 1811) +++ trunk/ftm/gui/Juce/common/ImtrEditor.h 2008-07-09 10:07:51 UTC (rev 1812) @@ -65,6 +65,12 @@ * @ingroup ImtrEditor */ virtual void objectChanged() = 0; + /** + * @brief called when the layout has changed + * @ingroup ImtrEditor + */ + virtual void layoutChanged() = 0; + /** @} Object/interface */ /** @name View properties Added: trunk/ftm/gui/Juce/common/InfoPanel.cpp =================================================================== --- trunk/ftm/gui/Juce/common/InfoPanel.cpp (rev 0) +++ trunk/ftm/gui/Juce/common/InfoPanel.cpp 2008-07-09 10:07:51 UTC (rev 1812) @@ -0,0 +1,140 @@ +/* + * IMTR EDITOR + * Copyright (C) 2004 by IRCAM-Centre Georges Pompidou, Paris, France. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * See file COPYING.LIB + for further informations on licensing terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef DISABLE_JUCE_NAMESPACE +#define DONT_SET_USING_JUCE_NAMESPACE 1 +#endif + +#include "juce.h" +#include "imtrjuce.h" + +#include "juce.h" +#include "imtrjuce.h" + +class InfoPanel : public JUCE_EDITOR_NAMESPACE::Component, public EditorContainerListener +{ + EditorContainer *container; + +public: + InfoPanel(EditorContainer *container): container(container) + { + setOpaque(true); + setBufferedToImage(true); + + container->addEditorContainerListener(this); + } + + ~InfoPanel() + { + } + + void paint(JUCE_EDITOR_NAMESPACE::Graphics& g) + { + g.fillAll(container->getBackgroundColor()); + + if(!container->isVertical()) + { + if(container->isLayoutSuperposed()) + { + if(container->getEditorsSize() > 0) + { + int ed_y = 0; + if(container->isTabsVisible()) //draw top rectangle + { + ed_y = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(container->getEditors()[0]))->getY(); + g.setColour(JUCE_EDITOR_NAMESPACE::Colours::black); + g.drawLine(0, ed_y-1, getWidth(), ed_y-1); + g.setColour(container->getBackgroundColor().darker()); + g.drawLine(0, ed_y-2, getWidth(), ed_y-2); + } + + ImtrEditor *editor = container->getEditors()[container->getForemost()]; + if(editor->haveInfoPanel()) + { + JUCE_EDITOR_NAMESPACE::Image *img = editor->getInfoImage(); + g.drawImageAt(img, 0, ed_y, false); + } + } + } + else //juxtaposed + { + JUCE_EDITOR_NAMESPACE::Rectangle bounds; + int i; + for(i=0; i<container->getEditorsSize(); i++) + { + ImtrEditor *editor = container->getEditors()[i]; + if(editor->haveInfoPanel()) + { + JUCE_EDITOR_NAMESPACE::Image *img = editor->getInfoImage(); + bounds = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(editor))->getBounds(); + g.drawImageWithin(img, 0, bounds.getY(), getWidth(), bounds.getHeight(), JUCE_EDITOR_NAMESPACE::RectanglePlacement::xLeft | JUCE_EDITOR_NAMESPACE::RectanglePlacement::yTop | JUCE_EDITOR_NAMESPACE::RectanglePlacement::doNotResize, false); + } + } + } + + if(container->isDScrollVisible()) + { + int width = getWidth(); + int height = getHeight(); + int scroll_y = getHeight() - container->getDScrollSize(); + g.setColour(JUCE_EDITOR_NAMESPACE::Colours::black); + g.drawLine(0, scroll_y, width-1, scroll_y); + g.drawLine(width-1, scroll_y, width-1, height); + g.setColour(container->getBackgroundColor().brighter(0.3f)); + g.drawLine(0, scroll_y+1, width-2, scroll_y+1); + g.drawLine(width-2, scroll_y+1, width-2, height-1); + g.setColour(container->getBackgroundColor().darker()); + g.drawLine(0, height-1, width-1, height-1); + g.drawLine(0, scroll_y+1, 0, height-1); + } + + /*for(i = 0; i < container->getEditorsSize(); i++) + { + editor = (dynamic_cast<JUCE_EDITOR_NAMESPACE::Component *>(container->getEditors()[0])); + if(editor->haveInfoPanel()) + { + Image img = editor->getInfoImage(); + g.drawImageAt(offscreen, x, y, false); + } + }*/ + } + else + { + + } + + } + void resized() + { + } + + void containerChanged() + { + repaint(); + } +}; + +JUCE_EDITOR_NAMESPACE::Component *createInfoPanel(EditorContainer *container) +{ + return new InfoPanel(container); +} \ No newline at end of file Property changes on: trunk/ftm/gui/Juce/common/InfoPanel.cpp ___________________________________________________________________ Name: svn:executable + * Modified: trunk/ftm/gui/Juce/common/MarkersEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/MarkersEditor.cpp 2008-07-09 09:59:51 UTC (rev 1811) +++ trunk/ftm/gui/Juce/common/MarkersEditor.cpp 2008-07-09 10:07:51 UTC (rev 1812) @@ -952,6 +952,8 @@ container->repaint(); } + void layoutChanged(){} + void setBackgroundColor(JUCE_EDITOR_NAMESPACE::Colour bcolor) { backcolor = bcolor; Modified: trunk/ftm/gui/Juce/common/MidiEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/MidiEditor.cpp 2008-07-09 09:59:51 UTC (rev 1811) +++ trunk/ftm/gui/Juce/common/MidiEditor.cpp 2008-07-09 10:07:51 UTC (rev 1812) @@ -1176,7 +1176,7 @@ int transp = getPitchTransp(); int width = getWidth(); - g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor); + g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor.withAlpha(opacity)); /********* First Bass Line ***********************************************/ if(staffIsDrawable_Staves(2, maxPitch, minPitch)) @@ -1309,7 +1309,7 @@ JUCE_EDITOR_NAMESPACE::String text; /********** Background ******************************************************/ - g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor); + g.fillAll(/*JUCE_EDITOR_NAMESPACE::Colours::white*/backcolor.withAlpha(opacity)); /********** Gray Lines ******************************************************/ int positionY; @@ -1643,6 +1643,12 @@ container->repaint(); } + void layoutChanged() + { + updateBackgroundOffscreens(); + objectRefresh(); + } + void setRangeMode(JUCE_EDITOR_NAMESPACE::String mode) { if(mode == JUCE_EDITOR_NAMESPACE::String("whole")) @@ -1667,7 +1673,7 @@ void setBackgroundColor(JUCE_EDITOR_NAMESPACE::Colour bcolor) { backcolor = bcolor; - //lightColour = backcolor.brighter(); + lightcolor = backcolor.contrasting(0.15f); updateBackgroundOffscreens(); objectRefresh(); } @@ -1697,6 +1703,8 @@ void setOpacity(float alpha) { opacity = alpha; + updateBackgroundOffscreens(); + objectRefresh(); } void setForemost(bool isForemost) Modified: trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp =================================================================== --- trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp 2008-07-09 09:59:51 UTC (rev 1811) +++ trunk/ftm/gui/Juce/common/SpectrogramEditor.cpp 2008-07-09 10:07:51 UTC (rev 1812) @@ -699,6 +699,8 @@ container->repaint(); } + void layoutChanged(){} + void setBackgroundColor(JUCE_EDITOR_NAMESPACE::Colour bcolor) { backcolor = bcolor; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bor...@us...> - 2008-07-09 09:59:49
|
Revision: 1811 http://ftm.svn.sourceforge.net/ftm/?rev=1811&view=rev Author: borghesi Date: 2008-07-09 02:59:51 -0700 (Wed, 09 Jul 2008) Log Message: ----------- added midi_gui to cpp gui interfaces Modified Paths: -------------- trunk/ftm/gui/Juce/cpp_gui/guiinterfaces.h Modified: trunk/ftm/gui/Juce/cpp_gui/guiinterfaces.h =================================================================== --- trunk/ftm/gui/Juce/cpp_gui/guiinterfaces.h 2008-07-07 10:32:53 UTC (rev 1810) +++ trunk/ftm/gui/Juce/cpp_gui/guiinterfaces.h 2008-07-09 09:59:51 UTC (rev 1811) @@ -120,4 +120,31 @@ virtual double getTime(void *obj, void *marker) = 0; }; +/** + * @brief midi gui interface + * @ingroup guiinterfaces + */ +class imtr_guiInterfaceMidi: public imtr_guiInterface +{ + public: + imtr_guiInterfaceMidi(){setName("midi");} + virtual ~imtr_guiInterfaceMidi() {} + + virtual int isVector() = 0; + virtual int getSize(void *obj) = 0; + virtual double getDuration(void *obj) = 0; + + virtual void move(void *obj, void *evt, int index, double the_time) = 0; + virtual void remove(void *obj, void *evt, int index) = 0; + + virtual void *getFirst(void *obj, double *time, double *pitch, double *duration) = 0; + virtual void *getNext(void *obj, void *evt, double *time, double *pitch, double *duration) = 0; + virtual void getValues(void *obj, void *evt, double *time, double *pitch, double *duration) = 0; + + virtual void *getByIndex(void *obj, int the_index, double *time, double *pitch, double *duration) = 0; + virtual void *add(void *obj, double the_time, double pitch, double duration) = 0; + virtual void setPitch(void *obj, void *evt, int index, double pitch) = 0; +}; +/** @} Midi gui interface */ + #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: IOhannes m z. <zmo...@ie...> - 2008-07-04 08:24:21
|
Norbert Schnell wrote: > > Looks pretty much the same. Should we simply give it a little time? hmm, i still don't get email notifactions. could you file a bug-report at sourceforge (site-bugs or however it is called)? mfga.sd IOhannes |
From: Norbert S. <Nor...@ir...> - 2008-06-30 13:03:31
|
On 30 juin 08, at 13:55, IOhannes m zmoelnig wrote: > well, the svn-hook does work (as it does so on other projects), it > just seems to be configured incorrectly. > > this is how the full hook looks like for the "iem" project: > svnnotify --repos-path "$1" --revision "$2" --to "sf...@ie..." -- > subject-prefix "SF.net SVN: iem:" --subject-cx --no-first-line -- > with-diff --viewcvs-url "http://iem.svn.sourceforge.net/iem/?rev= > %s&view=rev" --user-domain "users.sourceforge.net" -l /usr/bin/ > svnlook --max-diff-length 100000Yes, the "installation process" is > absolutely straight forward. The FTM one is this: svnnotify --repos-path "$1" --revision "$2" --to "ft...@li... " --subject-prefix "SF.net SVN: ftm:" --subject-cx --no-first-line -- with-diff --viewcvs-url "http://ftm.svn.sourceforge.net/ftm/?rev= %s&view=rev" --user-domain "users.sourceforge.net" -l /usr/bin/svnlook --max-diff-length 100000 Looks pretty much the same. Should we simply give it a little time? > but then, it isn't so hard to setup... > do you have any other hooks installed? No, nothing. **NOS |