aboutsummaryrefslogtreecommitdiff
path: root/harmonizer.c
diff options
context:
space:
mode:
authorDavide Morelli <morellid@users.sourceforge.net>2005-12-08 16:31:11 +0000
committerDavide Morelli <morellid@users.sourceforge.net>2005-12-08 16:31:11 +0000
commitac33aae33bcd8e334755dfa6a725ffbb51a84931 (patch)
treee98f57ef0c71970871c6335bfddf34048d8315f4 /harmonizer.c
parentfe91359682b9d76eb3c2a4bb8fb7b4d2f00bfcb9 (diff)
fixing things
svn path=/trunk/externals/frankenstein/; revision=4171
Diffstat (limited to 'harmonizer.c')
-rwxr-xr-xharmonizer.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/harmonizer.c b/harmonizer.c
index 7277723..a270df9 100755
--- a/harmonizer.c
+++ b/harmonizer.c
@@ -263,7 +263,7 @@ void harmonizer_init_pop(t_harmonizer *x)
{
// i go up
rnd = rand()/((double)RAND_MAX + 1);
- steps = rnd * 5; // how many step (good notes) will I ignore?
+ steps = rnd * 5; // how many steps (good notes) will I ignore?
note = insertpoint + steps;
if (note >= POSSIBLE_NOTES)
note = POSSIBLE_NOTES-1;
@@ -272,7 +272,7 @@ void harmonizer_init_pop(t_harmonizer *x)
{
// i go down
rnd = rand()/((double)RAND_MAX + 1);
- steps = rnd * 5; // how many step (good notes) will I ignore?
+ steps = rnd * 5; // how many steps (good notes) will I ignore?
note = insertpoint - steps;
if (note < 0)
note = 0;
@@ -295,6 +295,8 @@ void harmonizer_free(t_harmonizer *x)
int fitness(t_harmonizer *x, int *candidate)
{
int i, j, tmp, res, last, avgHI, avgLOW;
+ short int chord_notes[4];
+ short int chord_notes_ok[4];
short int transitions[VOICES];
short int directions[VOICES];
// intervals between voices
@@ -434,6 +436,41 @@ int fitness(t_harmonizer *x, int *candidate)
// TODO: too many near limits?
// TODO: is a complete chord?
+ // does this voicing have all 5 notes?
+ // first build a table for comparision
+ for (i=0; i<4; i++)
+ {
+ chord_notes[i] = (x->target_notes[i]) % 12;
+ chord_notes_ok[i] = 0;
+ }
+ for (i=0; i<VOICES; i++)
+ {
+ tmp = notes[i] % 12;
+ for (j=0; j<4; j++)
+ {
+ if (chord_notes[j] == tmp)
+ chord_notes_ok[j]++;
+ }
+ }
+ // now in chord_notes_ok i have the number of times each note is present
+ if (chord_notes_ok[0] == 0)
+ {
+ // no fundamental! this is bad!!
+ res -= 5;
+ }
+ if ((chord_notes_ok[0] != 0) &&
+ (chord_notes_ok[2] != 0) &&
+ (chord_notes_ok[3] != 0) &&
+ (chord_notes_ok[4] != 0))
+ {
+ // complete chord! this is good
+ res += 5;
+ }
+ for (j=0; j<4; j++)
+ {
+ res -= 2^chord_notes_ok[j];
+ }
+ res += 2*VOICES;
// penalize too many basses
tmp = 0;
@@ -451,6 +488,7 @@ int fitness(t_harmonizer *x, int *candidate)
case 4: res -= 30; break;
}
+
if (DEBUG_VERBOSE)
post("fitness is %i", res);