2024.02.11

This commit is contained in:
sshlien
2024-02-11 13:59:25 -05:00
parent eac28d9489
commit b9c48dc778
3 changed files with 66 additions and 112 deletions

View File

@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define VERSION "0.87 February 09 2024 midistats"
#define VERSION "0.87 February 11 2024 midistats"
/* midistrats.c is a descendent of midi2abc.c which was becoming to
large. The object of the program is to extract statistical characterisitic
@@ -68,7 +68,7 @@ float histogram_perplexity (int *histogram, int size);
void stats_noteoff(int chan,int pitch,int vol);
void stats_eot ();
void keymatch();
void outputNoteMemory();
void outputChannelSummary();
void clearTrackNm ();
#define max(a,b) (( a > b ? a : b))
@@ -102,7 +102,6 @@ int percpatternfor;
int percpatternhist;
int pitchclassanalysis;
int nseqfor;
int pmove;
int corestats;
int chordthreshold; /* number of maximum number of pulses separating note */
int beatsPerBar = 4; /* 4/4 time */
@@ -149,7 +148,6 @@ int channel_used_in_track[17]; /* for dealing with quietTime [SS] 2023-09-06 */
int histogram[256];
unsigned char drumpat[8000];
unsigned char pseq[8000];
unsigned char maxpitch[8000];
int pseqhist[128];
int percnum;
int nseqchn;
@@ -204,6 +202,8 @@ struct notememory {int eighthUnit;
int zeroCount;
int stepCount;
int jumpCount;
int totalNotes;
int totalPitches;
} nm[17];
struct notememory tracknm;
@@ -562,12 +562,6 @@ tripletsCriterion8 = (float) pulseDistribution[8]/ (float) ncounts;
tripletsCriterion4 = (float) pulseDistribution[4]/ (float) ncounts;
if (tripletsCriterion8 > 0.10 || tripletsCriterion4 > 0.10) printf("triplets\n");
if (pulseDistribution[0]/(float) ncounts > 0.95) printf("qnotes");
/*
printf("pulseDistribution:");
for (i=0;i<resolution;i++) printf("%6.3f",(float) pulseDistribution[i]/(float) ncounts);
printf("\n");
printf("nzeros = %d npeaks = %d \n",nzeros,npeaks);
*/
}
void stats_finish()
@@ -645,7 +639,7 @@ printf("collisions = %d\n",ncollisions);
if (hasLyrics) printf("Lyrics\n");
stats_interpret_pulseCounter ();
printf("\n");
outputNoteMemory();
outputChannelSummary();
}
@@ -717,10 +711,12 @@ for (i=1;i<17;i++) {
printf("-1 0");
trkdata.quietTime[i] = 0; /* in case channel i is used in another track */
trkdata.numberOfGaps[i] = 0;
if (lasttrack > 1) printf(" %d %d %d\n",tracknm.zeroCount,tracknm.stepCount,tracknm.jumpCount);
else
printf(" %d %d %d\n",nm[i-1].zeroCount,nm[i-1].stepCount,nm[i-1].jumpCount);
printf("\n");
channel2nnotes[i] += trkdata.notecount[i] + trkdata.chordcount[i];
if (lasttrack > 1) printf("nzeros = %d nsteps = %d njumps = %d\n",tracknm.zeroCount,tracknm.stepCount,tracknm.jumpCount);
}
}
@@ -778,6 +774,8 @@ void clearNotememory () {
nm[i].zeroCount = 0;
nm[i].stepCount = 0;
nm[i].jumpCount = 0;
nm[i].totalNotes =0;
nm[i].totalPitches =0;
}
}
@@ -789,6 +787,8 @@ void clearTrackNm () {
tracknm.zeroCount = 0;
tracknm.stepCount = 0;
tracknm.jumpCount = 0;
tracknm.totalNotes = 0;
tracknm.totalPitches = 0;
}
void updateNotememory (int unit, int chn, int pitch) {
@@ -811,10 +811,8 @@ if (nm[chn].previousPitch > 0)
}
if (nm[chn].beforePitch != 0) nm[chn].previousPitch = nm[chn].beforePitch;
nm[chn].eighthUnit = unit;
/*printf("%d, %d, %d, %d, %d, %d %d\n",unit,nm[chn].beforePitch,nm[chn].previousPitch,\
deltaPitch,nm[chn].zeroCount,nm[chn].stepCount,nm[chn].jumpCount);
*/
nm[chn].totalNotes++;
nm[chn].totalPitches = nm[chn].totalPitches + pitch;
}
void updateTrackNotememory (int unit, int chn, int pitch) {
@@ -1341,99 +1339,28 @@ printf("\n");
}
void maxpitchInInterval(int chn) {
int i;
int half;
int channel;
int pitch;
int onset;
int index;
int remainder;
int noteNum;
int part;
half = division/2;
for (i = 0; i<8000; i++) maxpitch[i] = 0;
for (i = 0; i <lastEvent; i++) {
channel = midievents[i].channel;
if (channel == 9) continue; /* ignore percussion channel */
if (channel == chn || chn == -1) {
pitch = midievents[i].pitch;
onset = midievents[i].onsetTime;
index = onset/half;
if (index >= 8000) {printf("index too large in drumpattern\n");
break;
}
if (pitch > maxpitch[index]) maxpitch[index] = pitch;
}
/*printf("pitchclass = %d noteNum =%d index = %d pseq[index] %d \n",pitchclass, noteNum, index, pseq[index]); */
}
/*printf("maxpitch = \n");
for (i=0;i<100;i++) printf(" %d,",maxpitch[i]);
printf("\n");
*/
}
void pitchDifference (int chn) {
int i;
int nzeros;
int nsteps;
int njumps;
int lastmax;
int pmax;
int pdif;
nzeros = 0;
nsteps = 0;
njumps = 0;
lastmax = 0;
pdif = 0;
maxpitchInInterval(chn);
for (i = 0; i <lastEvent; i++) {
if (maxpitch[i] > 0) {
pmax = maxpitch[i];
if (lastmax > 0) {
pdif = pmax - lastmax;
if (pdif == 0) nzeros++;
else if (abs(pdif) <4) nsteps++;
else njumps++;
}
lastmax = pmax;
/*if(i<40) printf("%d %d %d %d %d %d\n",pmax,lastmax,pdif,nzeros,nsteps,njumps);
*/
}
}
printf("%d %d %d %d\n",chn+1,nzeros,nsteps,njumps);
}
void allPitchDifference() {
int i;
int nonzeros;
for (i=0;i<17;i++) {
/*printf("\n%d,%d",i,channel_active[i+1]);*/
if (i == 9) continue;
if (channel_active[i+1] == 0) continue;
pitchDifference(i);
}
printf("\n");
}
void outputNoteMemory() {
void outputChannelSummary() {
int i;
for (i=0;i<17;i++) {
if (i == 9) continue;
if ((nm[i].zeroCount + nm[i].stepCount+nm[i].jumpCount) == 0) continue;
printf("nzeros: ");
printf("nnotes: ");
for(i=0;i<16;i++) printf(" %d",nm[i].totalNotes);
printf("\nnzeros: ");
for(i=0;i<16;i++) printf(" %d",nm[i].zeroCount);
printf("\nnsteps: ");
for(i=0;i<16;i++) printf(" %d",nm[i].stepCount);
printf("\nnjumps: ");
for(i=0;i<16;i++) printf(" %d",nm[i].jumpCount);
printf("\n");
printf("\nrpats: ");
for(i=1;i<17;i++) printf(" %d",trkdata.rhythmpatterns[i]);
printf("\npavg: ");
/* avoid dividing by 0 */
for(i=0;i<16;i++) printf(" %d",nm[i].totalPitches/(1+nm[i].totalNotes));
printf("\n");
}
/* printf("pmove: %d %d %d %d\n",i+1,nm[i].zeroCount,nm[i].stepCount,nm[i].jumpCount);
}*/
}
void dualDrumPattern (int perc1, int perc2) {
@@ -1835,11 +1762,6 @@ int argc;
nseqchn = -1;
}
arg = getarg("-pmove",argc,argv);
if (arg != -1) {
pmove = 1;
stats = 0;
}
arg = getarg("-nseqtokens",argc,argv);
if (arg != -1) {
@@ -1891,7 +1813,6 @@ int argc;
printf(" -nseq\n");
printf(" -nseqfor channel\n");
printf(" -nseqtokens\n");
printf(" -pmove\n");
printf(" -ver version number\n");
printf(" -d <number> debug parameter\n");
printf(" The input filename is assumed to be any string not\n");
@@ -1950,9 +1871,6 @@ if (nseqfor) {
if (nseqdistinct) {
allDistinctNoteSeq();
}
if (pmove) {
allPitchDifference();
}
if (corestats) corestatsOutput();
if (pitchclassanalysis) {
pitchClassAnalysis();
@@ -1973,7 +1891,6 @@ int argc;
if(stats == 1) midistats(argc,argv);
if(pulseanalysis || corestats || percanalysis ||\
percpatternfor || percpattern || percpatternhist ||\
pitchclassanalysis || nseqfor || nseqdistinct ||\
pmove) loadEvents();
pitchclassanalysis || nseqfor || nseqdistinct) loadEvents();
return 0;
}