From be7e8a70dbbbdc3ab2b1a8311b9380db5ca15553 Mon Sep 17 00:00:00 2001 From: Davide Morelli Date: Sun, 15 Jan 2006 01:38:32 +0000 Subject: improving harmonizer, adding MSVC project files svn path=/trunk/externals/frankenstein/; revision=4404 --- GArhythm.vcproj | 130 +++++++++++++++++++++++++++++++++++++++++++++++++ chords_memory.c | 32 +------------ chords_memory.vcproj | 130 +++++++++++++++++++++++++++++++++++++++++++++++++ frankenstein.sln | 45 +++++++++++++++++ harmonizer.c | 107 ++++++++++++++++++++++++++++++++++------- harmonizer.vcproj | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 528 insertions(+), 49 deletions(-) create mode 100755 GArhythm.vcproj create mode 100755 chords_memory.vcproj create mode 100755 frankenstein.sln create mode 100755 harmonizer.vcproj diff --git a/GArhythm.vcproj b/GArhythm.vcproj new file mode 100755 index 0000000..fafd049 --- /dev/null +++ b/GArhythm.vcproj @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/chords_memory.c b/chords_memory.c index 866142e..7a39cd3 100755 --- a/chords_memory.c +++ b/chords_memory.c @@ -1094,7 +1094,7 @@ void *chords_memory_new(t_symbol *s, int argc, t_atom *argv) t_chords_memory *x = (t_chords_memory *)pd_new(chords_memory_class); x->x_outchordname = outlet_new(&x->x_obj, gensym("symbol")); x->x_outtonalityname = outlet_new(&x->x_obj, gensym("symbol")); - x->x_outchordssequence = outlet_new(&x->x_obj, &s_list); + x->x_outchordssequence = outlet_new(&x->x_obj, gensym("list")); srand(time(&a)); chords_memory_init_graph(x); x->fundamental_note = C; @@ -1115,40 +1115,10 @@ void chords_memory_free(t_chords_memory *x) // free(x->current_fundamental); } -// TEST -typedef struct _bla -{ - int value; - int index; -} bla_t; -typedef struct _bla2 -{ - bla_t array[10]; -} bla2_t; -#define BLA_COMPARATOR(e1, e2) (e1.value - e2.value) -//TEST -void chords_memory_bang(t_chords_memory *x) -{ - int i; - bla2_t test[2]; - for (i=0; i<10; i++) - { - test[1].array[i].index = i; - test[1].array[i].value = 10-i; - } -SGLIB_ARRAY_QUICK_SORT (bla_t, test[1].array, 10, BLA_COMPARATOR, SGLIB_ARRAY_ELEMENTS_EXCHANGER); - for (i=0; i<10; i++) - { - post("array[%i].value = %i, array[%i].index = %i",i, test[1].array[i].value,i, test[1].array[i].index ); - } - -} - void chords_memory_setup(void) { chords_memory_class = class_new(gensym("chords_memory"), (t_newmethod)chords_memory_new, (t_method)chords_memory_free, sizeof(t_chords_memory), CLASS_DEFAULT, A_GIMME, 0); -class_addbang(chords_memory_class, (t_method)chords_memory_bang); // file I/O class_addmethod(chords_memory_class, (t_method)chords_memory_write_to_file, gensym("write"),A_SYMBOL, 0); class_addmethod(chords_memory_class, (t_method)chords_memory_read_from_file, gensym("read"),A_SYMBOL, 0); diff --git a/chords_memory.vcproj b/chords_memory.vcproj new file mode 100755 index 0000000..d71acb5 --- /dev/null +++ b/chords_memory.vcproj @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/frankenstein.sln b/frankenstein.sln new file mode 100755 index 0000000..0542fd8 --- /dev/null +++ b/frankenstein.sln @@ -0,0 +1,45 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chords_memory", "chords_memory.vcproj", "{DBC75D2A-816A-4C0A-8FE7-2016518D2D19}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rhythms_memory", "rhythms_memory.vcproj", "{DBC75D2A-816A-4C0A-8FE7-2016518D2D19}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "themes_memory", "themes_memory.vcproj", "{DBC75D2A-816A-4C0A-8FE7-2016518D2D19}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "harmonizer", "harmonizer.vcproj", "{DBC75D2A-816A-4C0A-8FE7-2016518D2D19}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "voicing_analyzer", "voicing_analyzer.vcproj", "{DBC75D2A-816A-4C0A-8FE7-2016518D2D19}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Debug.ActiveCfg = Debug|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Debug.Build.0 = Debug|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Release.ActiveCfg = Release|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Release.Build.0 = Release|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Debug.ActiveCfg = Debug|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Debug.Build.0 = Debug|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Release.ActiveCfg = Release|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Release.Build.0 = Release|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Debug.ActiveCfg = Debug|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Debug.Build.0 = Debug|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Release.ActiveCfg = Release|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Release.Build.0 = Release|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Debug.ActiveCfg = Debug|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Debug.Build.0 = Debug|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Release.ActiveCfg = Release|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Release.Build.0 = Release|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Debug.ActiveCfg = Debug|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Debug.Build.0 = Debug|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Release.ActiveCfg = Release|Win32 + {DBC75D2A-816A-4C0A-8FE7-2016518D2D19}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/harmonizer.c b/harmonizer.c index 48880f3..c73b519 100755 --- a/harmonizer.c +++ b/harmonizer.c @@ -45,6 +45,9 @@ or at least set the importance of rules in realtime.. #define LOWER_POSSIBLE_NOTE 24 // lower note possible, it should be a C #define POSSIBLE_NOTES (NOTES_RANGE/12*4) // 4 is the max number of notes in a chord +// default values +#define DEF_WIDENESS 3 // 3 octaves +#define DEF_CENTER_NOTE 72 // central C // testing i noticed that we don't need more than 1 generation.. // this is because we create an initial population that is really good // we may not need to crossover at all! @@ -102,6 +105,14 @@ typedef struct _harmonizer chord_t target_chord; int target_notes[POSSIBLE_NOTES]; t_outlet *l_out; + + float wideness; + int center_note; + float i_like_parallelism; + float small_intervals; + //TODO +// int lower_octave; +// int notes_range; } t_harmonizer; @@ -338,8 +349,7 @@ int fitness(t_harmonizer *x, int *candidate) directions[1]==directions[2] && directions[2]==directions[3]) { - // bad! - res -= 10; + res += 10 * x->i_like_parallelism; if (DEBUG_VERBOSE) post("same direction!"); } @@ -357,7 +367,7 @@ int fitness(t_harmonizer *x, int *candidate) // bad! if (directions[i]==directions[j]) { - res -= 10; + res += 10 * x->i_like_parallelism; if (DEBUG_VERBOSE) post("hidden or parallel consonance!"); } @@ -379,7 +389,8 @@ int fitness(t_harmonizer *x, int *candidate) tmp = tmp/(VOICES-1); if (DEBUG_VERBOSE) post("average note is %i after division by (VOICES-1)", tmp); - tmp = abs((LOWER_POSSIBLE_NOTE + NOTES_RANGE)*2/3 - tmp); // how much average is far from 72 +// tmp = abs((LOWER_POSSIBLE_NOTE + NOTES_RANGE)*2/3 - tmp); // how much average is far from 72 + tmp = abs(x->center_note - tmp); // how much average is far from desired center note res += 30; res -= tmp; @@ -413,21 +424,21 @@ int fitness(t_harmonizer *x, int *candidate) if (transitions[i]==0) res += 5; if (abs(transitions[i]==1)) - res += 5; + res += 5 * x->small_intervals; if (abs(transitions[i]==2)) - res += 5; + res += 5 * x->small_intervals; if (abs(transitions[i]==3)) - res += 2; + res += 2 * x->small_intervals; if (abs(transitions[i]==4)) - res += 2; + res += 2 * x->small_intervals; if (abs(transitions[i]==5)) - res += 1; + res += 1 * x->small_intervals; if (abs(transitions[i]==6)) - res += 1; + res += 1 * x->small_intervals; if (abs(transitions[i]>11)) - res -= 2; + res -= 2 * x->small_intervals; if (abs(transitions[i]>15)) - res -= 5; + res -= 5 * x->small_intervals; } if (DEBUG_VERBOSE) @@ -435,7 +446,7 @@ int fitness(t_harmonizer *x, int *candidate) // TODO: too many near limits? - // TODO: is a complete chord? + // is a complete chord? // does this voicing have all 5 notes? // first build a table for comparision for (i=0; i<4; i++) @@ -456,7 +467,7 @@ int fitness(t_harmonizer *x, int *candidate) if (chord_notes_ok[0] == 0) { // no fundamental! this is bad!! - res -= 5; + res -= 10; } if ((chord_notes_ok[0] != 0) && (chord_notes_ok[2] != 0) && @@ -464,7 +475,7 @@ int fitness(t_harmonizer *x, int *candidate) (chord_notes_ok[4] != 0)) { // complete chord! this is good - res += 5; + res += 10; } for (j=0; j<4; j++) { @@ -635,13 +646,65 @@ void set_target(t_harmonizer *x, t_symbol *s) { post("harmonizer: set_target %s",s->s_name); } +//how any octaves should this chord be? +void set_wideness(t_harmonizer *x, t_floatarg f) +{ + if (f>=0) + x->wideness = f; +} + +// which note should the center note have ? +void set_center_note(t_harmonizer *x, t_floatarg f) +{ + if ((f>=LOWER_POSSIBLE_NOTE)&&(f<120)) + x->center_note = (int) f; +} + +// which note should the center note have ? +void set_i_like_parallelism(t_harmonizer *x, t_floatarg f) +{ + float newval = f; + if (newval<-1) + newval = -1; + if (newval>1) + newval = 1; + x->i_like_parallelism = newval; +} + +// which note should the center note have ? +void set_small_intervals(t_harmonizer *x, t_floatarg f) +{ + float newval = f; + if (newval<-1) + newval = -1; + if (newval>1) + newval = 1; + x->small_intervals = newval; +} + +void print_help(t_harmonizer *x) +{ + post(""); + post("harmonizer is an external that builds voicing"); + post("takes chords name and outputs a list of %i midi notes", VOICES); + post("available commands:"); + post("current symbol: sets the current chord name (which chordwe are in)"); + post("target symbol: sets the target chord name (which chord we want to go to)"); + post("wideness float: now many octaves wide should the next chord be? must be > than 0"); + post("set_center_note int: sets the desired center chord note, min 24 max 100"); + post("i_like_parallelism float: do I want parallelism? from -1 (I don't want them) to 1 (I like them), 0 means I don't care, default = -1"); + post("small_intervals float: do I want small intervals? from -1 (I don't want them) to 1 (I like them), 0 means I don't care, default = 1"); + post("this externalis part of the frank framework"); + post("authors: davide morelli, david casals"); + +} void *harmonizer_new(t_symbol *s, int argc, t_atom *argv) { int i; time_t a; t_harmonizer *x = (t_harmonizer *)pd_new(harmonizer_class); - x->l_out = outlet_new(&x->x_obj, &s_list); + x->l_out = outlet_new(&x->x_obj, gensym("list")); /* for (i=0; icenter_note = DEF_CENTER_NOTE; + x->wideness = DEF_WIDENESS; + x->i_like_parallelism = -1; // by default we don't like them! + x->small_intervals = 1; //by default we want small intervals return (x); } @@ -658,10 +724,15 @@ void harmonizer_setup(void) harmonizer_class = class_new(gensym("harmonizer"), (t_newmethod)harmonizer_new, (t_method)harmonizer_free, sizeof(t_harmonizer), CLASS_DEFAULT, A_GIMME, 0); class_addbang(harmonizer_class, (t_method)harmonizer_bang); + class_addmethod(harmonizer_class, (t_method)print_help, gensym("help"),0, 0); class_addmethod(harmonizer_class, (t_method)set_current, gensym("current"),A_SYMBOL, 0); class_addmethod(harmonizer_class, (t_method)set_target, gensym("target"),A_SYMBOL, 0); // class_addmethod(harmonizer_class, (t_method)harmonizer_fitness1_set, gensym("fitness1"), A_DEFFLOAT, 0); class_addlist(harmonizer_class, (t_method)set_current_voices); - + class_addmethod(harmonizer_class, (t_method)set_wideness, gensym("wideness"), A_DEFFLOAT, 0); + class_addmethod(harmonizer_class, (t_method)set_center_note, gensym("center_note"), A_DEFFLOAT, 0); + class_addmethod(harmonizer_class, (t_method)set_i_like_parallelism, gensym("i_like_parallelism"), A_DEFFLOAT, 0); + class_addmethod(harmonizer_class, (t_method)set_small_intervals, gensym("small_intervals"), A_DEFFLOAT, 0); + } diff --git a/harmonizer.vcproj b/harmonizer.vcproj new file mode 100755 index 0000000..b794426 --- /dev/null +++ b/harmonizer.vcproj @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.1