Update of /cvsroot/pure-data/externals/frankenstein
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14706
Modified Files:
Makefile common.c
Added Files:
rhythms_memory.c rhythms_memory.sln rhythms_memory.vcproj
test-rhythms_memory.pd
Log Message:
first version of rhythms_memory
--- NEW FILE: rhythms_memory.sln ---
Microsoft Visual Studio Solution File, Format Version 7.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rhythms_memory", "rhythms_memory.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
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal
--- NEW FILE: test-rhythms_memory.pd ---
#N canvas 0 0 641 458 12;
#X obj 134 262 rhythms_memory;
#X msg 126 212 measure;
#X msg 317 224 0;
#X obj 168 69 metro 500;
#X obj 130 107 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X obj 168 46 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
;
#X obj 169 92 int 0;
#X obj 220 93 + 1;
#X obj 169 115 % 4;
#X floatatom 196 152 5 0 0 0 - - -;
#X obj 127 155 sel 0;
#X obj 125 185 bang;
#X obj 317 189 bng 30 250 50 0 empty empty empty 0 -6 0 8 -258699 -1
-1;
#X obj 133 285 unpack f f f f f;
#X floatatom 131 312 5 0 0 1 is_this_a_new_rhythm - -;
#X floatatom 160 330 5 0 0 1 id - -;
#X floatatom 193 348 5 0 0 1 subid - -;
#X floatatom 225 368 5 0 0 1 root_closeness - -;
#X floatatom 257 391 5 0 0 1 sub_closeness - -;
#X connect 0 0 13 0;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
#X connect 3 0 4 0;
#X connect 3 0 6 0;
#X connect 5 0 3 0;
#X connect 6 0 7 0;
#X connect 6 0 8 0;
#X connect 7 0 6 1;
#X connect 8 0 9 0;
#X connect 8 0 10 0;
#X connect 10 0 11 0;
#X connect 11 0 1 0;
#X connect 12 0 2 0;
#X connect 13 0 14 0;
#X connect 13 1 15 0;
#X connect 13 2 16 0;
#X connect 13 3 17 0;
#X connect 13 4 18 0;
Index: Makefile
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/Makefile,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Makefile 6 Dec 2005 12:08:28 -0000 1.6
--- Makefile 7 Dec 2005 00:20:01 -0000 1.7
***************
*** 2,12 ****
#VC="C:\Programmi\Microsoft Visual Studio .NET\Vc7"
VC="C:\Programmi\Microsoft Visual Studio .NET\Vc7"
! #PDPATH="H:\PureData\pd-0.38-3.msw\pd"
! PDPATH="C:\Documents and Settings\Davide\Documenti\personali\pd-0.38-3.msw\pd"
current: pd_nt distclean
! pd_nt: chord_melo.dll chords_memory.dll harmonizer.dll GArhythm.dll ritmo1.dll test.dll
.SUFFIXES: .dll
--- 2,12 ----
#VC="C:\Programmi\Microsoft Visual Studio .NET\Vc7"
VC="C:\Programmi\Microsoft Visual Studio .NET\Vc7"
! PDPATH="H:\PureData\pd-0.38-3.msw\pd"
! #PDPATH="C:\Documents and Settings\Davide\Documenti\personali\pd-0.38-3.msw\pd"
current: pd_nt distclean
! pd_nt: chord_melo.dll chords_memory.dll harmonizer.dll GArhythm.dll ritmo1.dll rhythms_memory.dll
.SUFFIXES: .dll
--- NEW FILE: rhythms_memory.vcproj ---
<?xml version="1.0" encoding = "Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.00"
Name="rhythms_memory"
ProjectGUID="{DBC75D2A-816A-4C0A-8FE7-2016518D2D19}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""H:\PureData\pd-0.38-3.msw\pd\src""
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/export:rhythms_memory_setup /dll"
AdditionalDependencies="pd.lib"
OutputFile="$(OutDir)/rhythms_memory.dll"
LinkIncremental="2"
AdditionalLibraryDirectories=""H:\PureData\pd-0.38-3.msw\pd\bin""
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/frankenstein.pdb"
SubSystem="0"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OmitFramePointers="TRUE"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/frankenstein.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
</Configurations>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
<File
RelativePath="common.c">
</File>
<File
RelativePath="rhythms_memory.c">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc">
<File
RelativePath="common.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
Index: common.c
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/common.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** common.c 6 Dec 2005 12:08:28 -0000 1.11
--- common.c 7 Dec 2005 00:20:01 -0000 1.12
***************
*** 207,210 ****
--- 207,212 ----
(*this_rep)->id = id; // the main id
(*this_rep)->last_sub_id = 0; // the sub id
+ (*this_rep)->next = 0;
+ (*this_rep)->max_weight = 0;
}
***************
*** 289,292 ****
--- 291,295 ----
// a new champion!
this_rep->max_weight = this_rep->transitions[i].weight;
+ post("DEBUG: max_weight=%i", this_rep->max_weight);
}
last = i;
***************
*** 378,381 ****
--- 381,385 ----
float best_closeness, curr_closeness;
int sub_ok, sub_no;
+ int count_strong;
t_rhythm_memory_element *possible_rhythms;
***************
*** 411,431 ****
// look all the representation's rhythm
// looking for strong beats corrispondance
for (i=0; i<max_i; i++)
{
- if (this_weight_float > min_to_be_main_rhythm_beat)
- {
this_weight_int = this_rep->transitions[i].weight;
this_weight_float = (float) (((float) this_weight_int) / ((float) this_rep->max_weight));
! // this is a main rhythm beat
! if (src_rhythm_array[i]>0)
! {
! // both playing
! strong_ok++;
! } else
{
! // strong beat miss
! strong_no++;
! }
! }
}
--- 415,440 ----
// look all the representation's rhythm
// looking for strong beats corrispondance
+ count_strong = 0;
for (i=0; i<max_i; i++)
{
this_weight_int = this_rep->transitions[i].weight;
this_weight_float = (float) (((float) this_weight_int) / ((float) this_rep->max_weight));
! post("DEBUG: transition %i this_weight_float=%f", i, this_weight_float);
! if (this_weight_float > min_to_be_main_rhythm_beat)
{
! // this is a main rhythm beat
! if (src_rhythm_array[i]>0)
! {
! // both playing
! strong_ok++;
! post("DEBUG: beat %i, both playing", i);
! } else
! {
! // strong beat miss
! strong_no++;
! post("DEBUG: beat %i, src not playing", i);
! }
! count_strong++;
! }
}
***************
*** 441,450 ****
// close to 0 = no corrispondance
// close to 1 = corrispondance
! if (strong_no==0)
{
! strong_ratio = 1;
} else
{
! strong_ratio = (float) ( ((float) strong_ok) / ((float)strong_no) );
}
// for each rhythm in the list
--- 450,461 ----
// close to 0 = no corrispondance
// close to 1 = corrispondance
! if (count_strong==0)
{
! strong_ratio = 0;
} else
{
! strong_ratio = (float) ( ( ((float) strong_ok) / ((float)count_strong) ) -
! ( ((float) strong_no) / ((float)count_strong) )) ;
! post("DEBUG: strong_ratio=%f", strong_ratio);
}
// for each rhythm in the list
***************
*** 528,531 ****
--- 539,543 ----
best_subid = curr_subid;
}
+ this_rep = this_rep->next;
}
***************
*** 548,559 ****
void rhythm_memory_free(t_rhythm_memory_representation *rep_list)
{
! t_rhythm_memory_representation *curr, *next;
! next = rep_list;
! while (next)
{
! curr = next;
! next = curr->next;
free_memory_representations(curr);
}
}
// evaluate this rhythm and add it to the memory if is new
--- 560,572 ----
void rhythm_memory_free(t_rhythm_memory_representation *rep_list)
{
! t_rhythm_memory_representation *curr, *nextRep;
! nextRep = rep_list;
! while (nextRep)
{
! curr = nextRep;
! nextRep = curr->next;
free_memory_representations(curr);
}
+
}
// evaluate this rhythm and add it to the memory if is new
***************
*** 590,594 ****
if (root_closeness_found>=min_to_be_same_rhythm)
{
! // is close enough to be considered a subrhythm
*new_rhythm = 0;
*id = id_found;
--- 603,608 ----
if (root_closeness_found>=min_to_be_same_rhythm)
{
! // is close enough to be considered a rhythm
! post("DEBUG: rhythm found");
*new_rhythm = 0;
*id = id_found;
***************
*** 597,600 ****
--- 611,615 ----
{
// this is a known subrhythm
+ post("DEBUG: sub-rhythm found");
*sub_id = sub_id_found;
*sub_closeness = sub_closeness_found;
--- NEW FILE: rhythms_memory.c ---
/*
just a dummy rhythms_memory patch
*/
#include "m_pd.h"
#include "common.h"
#include <time.h>
#include <math.h>
#include <stdlib.h>
static t_class *rhythms_memory_class;
typedef struct event event;
typedef struct event
{
unsigned short int voice;
double when;
event *next;
};
typedef struct _rhythms_memory
{
t_object x_obj; // myself
t_outlet *l_out;
t_rhythm_event *curr_seq;
int seq_initialized;
t_rhythm_memory_representation *rhythms_memory;
double measure_start_time;
double measure_length;
event *events;
} t_rhythms_memory;
void rhythms_memory_free(t_rhythms_memory *x)
{
if (x->curr_seq)
freeBeats(x->curr_seq);
if (x->rhythms_memory)
rhythm_memory_free(x->rhythms_memory);
}
void start_measure(t_rhythms_memory *x)
{
// I call the pd functions to get a representation
// of this very moment
x->measure_start_time = clock_getlogicaltime();
}
void add_event(t_rhythms_memory *x, unsigned short int voice)
{
event *newEvent, *currEvent, *lastEvent;
double when;
when = clock_gettimesince(x->measure_start_time);
newEvent = (event *) malloc(sizeof(event));
newEvent->when = when;
newEvent->voice = voice;
newEvent->next = 0;
currEvent = x->events;
if (currEvent)
{
// this is not the first event
while(currEvent)
{
lastEvent = currEvent;
currEvent = currEvent->next;
}
lastEvent->next = newEvent;
} else
{
// this is the first event
x->events = newEvent;
}
post("event added");
}
void end_measure(t_rhythms_memory *x)
{
float fduration;
event *currEvent, *lastEvent;
unsigned short int is_it_a_new_rhythm;
unsigned short int id, subid;
float root_closeness, sub_closeness;
int counter;
t_atom *lista;
// I call the pd functions to get a representation
// of this very moment
x->measure_length = clock_gettimesince(x->measure_start_time);
// now that i know the exact length of the current measure
// i can process the rhythm in the current measure
// and evaluate it
currEvent = x->events;
// this is not the first event
// now I translate events in rhythm
counter = 0;
while(currEvent)
{
fduration = currEvent->when / x->measure_length;
if (x->seq_initialized)
{
concatenateBeat(x->curr_seq, currEvent->voice, fduration, 1);
} else
{
setFirstBeat(&(x->curr_seq), currEvent->voice, fduration, 1);
x->seq_initialized = 1;
}
currEvent = currEvent->next;
counter++;
}
// delete events after having evaluated them
currEvent = x->events;
// this is not the first event
while(currEvent)
{
lastEvent = currEvent;
currEvent = currEvent->next;
free(lastEvent);
}
x->events = 0;
x->seq_initialized = 0;
// now I evaluate this rhythm with the memory
rhythm_memory_evaluate(x->rhythms_memory, x->curr_seq, &is_it_a_new_rhythm,
&id, &subid, &root_closeness, &sub_closeness);
// tell out the answer
// allocate space for the list
lista = (t_atom *) malloc(sizeof(t_atom) * 5);
SETFLOAT(lista, (float) is_it_a_new_rhythm);
SETFLOAT(lista+1, (float) id);
SETFLOAT(lista+2, (float) subid);
SETFLOAT(lista+3, (float) root_closeness);
SETFLOAT(lista+4, (float) sub_closeness);
outlet_anything(x->l_out,
gensym("list") ,
5,
lista);
free(lista);
freeBeats(x->curr_seq);
x->seq_initialized = 0;
x->curr_seq = 0;
// also start the new measure!
start_measure(x);
}
static void rhythms_memory_bang(t_rhythms_memory *x) {
// generate a random value
float rnd;
t_rhythm_event *events;
t_duration dur;
rnd = rand()/((double)RAND_MAX + 1);
dur = float2duration(rnd);
post("random value=%f duration.numerator=%i duration.denominator=%i", rnd, dur.numerator, dur.denominator);
if (x->seq_initialized)
{
concatenateBeat(x->curr_seq, 0, rnd, 1);
} else
{
setFirstBeat(&(x->curr_seq), 0, rnd, 1);
x->seq_initialized = 1;
}
// print the sequence
events = x->curr_seq;
while(events)
{
post("event: numerator=%i, denominator=%i", events->duration.numerator, events->duration.denominator);
events=events->next;
}
}
void *rhythms_memory_new(t_symbol *s, int argc, t_atom *argv)
{
int i;
time_t a;
t_rhythms_memory *x = (t_rhythms_memory *)pd_new(rhythms_memory_class);
x->l_out = outlet_new(&x->x_obj, "list");
x->seq_initialized = 0;
rhythm_memory_create(&(x->rhythms_memory));
start_measure(x);
return (x);
}
void rhythms_memory_setup(void)
{
rhythms_memory_class = class_new(gensym("rhythms_memory"), (t_newmethod)rhythms_memory_new,
(t_method)rhythms_memory_free, sizeof(t_rhythms_memory), CLASS_DEFAULT, A_GIMME, 0);
class_addbang(rhythms_memory_class, (t_method)rhythms_memory_bang);
class_addmethod(rhythms_memory_class, (t_method)end_measure, gensym("measure"), 0);
class_doaddfloat(rhythms_memory_class, (t_method)add_event);
}