mirror of
https://github.com/sshlien/abcmidi.git
synced 2025-12-13 06:01:01 +00:00
Compare commits
9 Commits
2023.08.22
...
2023.11.17
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f470c694ac | ||
|
|
633e8d8848 | ||
|
|
d93cb473dc | ||
|
|
b24803bf86 | ||
|
|
4e0266179b | ||
|
|
2bf0052eb8 | ||
|
|
1394cd96c5 | ||
|
|
8a2ec3a898 | ||
|
|
48c443fabd |
32
doc/CHANGES
32
doc/CHANGES
@@ -15103,4 +15103,36 @@ stats_noteon(). In function, output_track_summary(), suppressed
|
|||||||
notemeanpitch for percussion channel.
|
notemeanpitch for percussion channel.
|
||||||
|
|
||||||
|
|
||||||
|
October 25 2023
|
||||||
|
|
||||||
|
Midistats returns track activity (note on/off) for every track.
|
||||||
|
|
||||||
|
|
||||||
|
November 1 2023
|
||||||
|
|
||||||
|
Midistats returns the control volume settings for every track,
|
||||||
|
identifies midi files whose note timings are not quantized.
|
||||||
|
|
||||||
|
|
||||||
|
November 2 2023
|
||||||
|
|
||||||
|
abc2midi bug: In the following example, not all notes are
|
||||||
|
tied correctly.
|
||||||
|
|
||||||
|
X:1
|
||||||
|
T: tied note
|
||||||
|
M: 2/4
|
||||||
|
L: 1/4
|
||||||
|
K: C
|
||||||
|
D2-|:D2 |[1CD-:|[2CD|
|
||||||
|
|
||||||
|
No fix is available.
|
||||||
|
|
||||||
|
|
||||||
|
November 8 2023
|
||||||
|
|
||||||
|
midistats: extended the size of arrays (midievents and pulsecounter) to
|
||||||
|
handle certain midi files. The function stats_interpret_pulseCounter()
|
||||||
|
can detect midi files containing triplets and nonquantized notes.
|
||||||
|
|
||||||
|
midicopy: extended to handle midi files with up to 150 tracks.
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ track which distinguishes the MIDI files. This is attempted
|
|||||||
in the program midistats. Here is a short description.
|
in the program midistats. Here is a short description.
|
||||||
|
|
||||||
-corestats
|
-corestats
|
||||||
Produces a line with 3 numbers separated by tabs. eg
|
Produces a line with 5 numbers separated by tabs. eg
|
||||||
384 8349 448
|
1 8 384 4057 375
|
||||||
It returns the number of divisions per quarter note beat (ppqn),
|
It returns the number of tracks, the number of channels, the
|
||||||
|
number of divisions per quarter note beat (ppqn),
|
||||||
the number of note onsets in the midi file, and the maximum
|
the number of note onsets in the midi file, and the maximum
|
||||||
number of quarter note beats in midi file.
|
number of quarter note beats in midi file.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.TH MIDISTATS 1 "9 December 2022"
|
.TH MIDISTATS 1 "17 November 2023"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
\fBmidistats\fP \- program to summarize the statistical properties of a midi file
|
\fBmidistats\fP \- program to summarize the statistical properties of a midi file
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
@@ -36,7 +36,14 @@ the sum of the MIDI pitches for all the notes,
|
|||||||
the sum of the note durations in MIDI pulse units,
|
the sum of the note durations in MIDI pulse units,
|
||||||
the number of control parameter messages,
|
the number of control parameter messages,
|
||||||
the number of pressure messages.
|
the number of pressure messages.
|
||||||
and the number of distinct rhythm patterns for each channel
|
the number of distinct rhythm patterns for each channel
|
||||||
|
the number of pulses the channel was inactive
|
||||||
|
the minimum pitch value
|
||||||
|
the maximum pitch value
|
||||||
|
the minimum note length in pulses
|
||||||
|
the maximum note length in pulses
|
||||||
|
the number of gaps in the channel
|
||||||
|
the entropy of the pitch class histogram for that channel
|
||||||
.PP
|
.PP
|
||||||
After processing all the individual tracks, the following information
|
After processing all the individual tracks, the following information
|
||||||
applies to the entire midi file.
|
applies to the entire midi file.
|
||||||
@@ -70,9 +77,9 @@ that occur in the midi file.
|
|||||||
pitchact is a similar histogram but is weighted by the length of
|
pitchact is a similar histogram but is weighted by the length of
|
||||||
the notes.
|
the notes.
|
||||||
.PP
|
.PP
|
||||||
quietTime is used to compute the track/channel spread in midiexplorer.
|
chnact returns the amount of note activity in each channel.
|
||||||
It is computed by summing up all the midi pulses which occur
|
.PP
|
||||||
in gaps greater than 8 beats.
|
trkact returns the number of notes in each track.
|
||||||
.PP
|
.PP
|
||||||
totalrhythmpatterns is the total number of bar rhythm patterns for
|
totalrhythmpatterns is the total number of bar rhythm patterns for
|
||||||
all channels except the percussion channel.
|
all channels except the percussion channel.
|
||||||
@@ -89,6 +96,14 @@ runs through a collection of midi files, you can build a database
|
|||||||
of percussion descriptors. Some more details are given in the
|
of percussion descriptors. Some more details are given in the
|
||||||
file drums.txt which comes with this documentation.
|
file drums.txt which comes with this documentation.
|
||||||
|
|
||||||
|
.SH OPTIONS
|
||||||
|
.TP
|
||||||
|
.B -corestats
|
||||||
|
.TP
|
||||||
|
.B -pulseanalysis
|
||||||
|
.TP
|
||||||
|
.B etc. (See drums.txt in doc folder.)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ abc2midi version 4.84 January 06 2023
|
|||||||
abc2abc version 2.20 February 07 2023
|
abc2abc version 2.20 February 07 2023
|
||||||
yaps version 1.92 January 06 2023
|
yaps version 1.92 January 06 2023
|
||||||
abcmatch version 1.82 June 14 2022
|
abcmatch version 1.82 June 14 2022
|
||||||
midicopy version 1.38 May 06 2022
|
midicopy version 1.39 November 08 2022
|
||||||
midistats version 0.71 August 222023
|
midistats version 0.80 November 17 2023
|
||||||
|
|
||||||
24th January 2002
|
24th January 2002
|
||||||
Copyright James Allwright
|
Copyright James Allwright
|
||||||
|
|||||||
11
midicopy.c
11
midicopy.c
@@ -52,7 +52,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define VERSION "1.38 May 05 2022 midicopy"
|
#define VERSION "1.39 November 07 2023 midicopy"
|
||||||
#include "midicopy.h"
|
#include "midicopy.h"
|
||||||
#define NULLFUNC 0
|
#define NULLFUNC 0
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
@@ -96,8 +96,9 @@ long max_currtime = 0;
|
|||||||
long Mf_currcopytime = 0L; /* time of last copied event */
|
long Mf_currcopytime = 0L; /* time of last copied event */
|
||||||
char *trackdata = NULL;
|
char *trackdata = NULL;
|
||||||
long trackdata_length, trackdata_size;
|
long trackdata_length, trackdata_size;
|
||||||
char *trackstr[64]; /* [SS] 2017-10-20 2019-07-05*/
|
/* char *trackstr[64]; [SS] 2017-10-20 2019-07-05*/
|
||||||
int trackstr_length[64]; /* [SS] 2017-10-20 2019-07-05*/
|
char *trackstr[150]; /* [SS] 2023-11-07 */
|
||||||
|
int trackstr_length[150]; /* [SS] 2017-10-20 2019-07-05* 2023-11-07*/
|
||||||
int trkid = 0;
|
int trkid = 0;
|
||||||
int activetrack;
|
int activetrack;
|
||||||
int nochanmsg = 1;
|
int nochanmsg = 1;
|
||||||
@@ -1290,7 +1291,7 @@ build_new_midi_file (format, ntracks, division, fp)
|
|||||||
|
|
||||||
get_tempo_info_from_track_1 ();
|
get_tempo_info_from_track_1 ();
|
||||||
|
|
||||||
if (ntracks > 63) {printf("too many tracks\n"); exit(1); }
|
if (ntracks > 149) {printf("too many tracks\n"); exit(1); }
|
||||||
|
|
||||||
/* The rest of the file is a series of tracks */
|
/* The rest of the file is a series of tracks */
|
||||||
for (i = 0; i < ntracks; i++)
|
for (i = 0; i < ntracks; i++)
|
||||||
@@ -1836,7 +1837,7 @@ main (int argc, char *argv[])
|
|||||||
printf ("-ver version information\n");
|
printf ("-ver version information\n");
|
||||||
printf ("-trks n1,n2,..(starting from 1)\n");
|
printf ("-trks n1,n2,..(starting from 1)\n");
|
||||||
printf ("-xtrks n1,n2,.. (tracks to exclude)\n"); /* [SS] 2013-10-27 */
|
printf ("-xtrks n1,n2,.. (tracks to exclude)\n"); /* [SS] 2013-10-27 */
|
||||||
printf ("-xchns n1,n2,.. (tracks to exclude)\n"); /* [SS] 2017-12-06 */
|
printf ("-xchns n1,n2,.. (channels to exclude)\n"); /* [SS] 2022-11-12 */
|
||||||
printf ("-chns n1,n2,..(starting from 1)\n");
|
printf ("-chns n1,n2,..(starting from 1)\n");
|
||||||
printf ("-from n (in midi ticks)\n");
|
printf ("-from n (in midi ticks)\n");
|
||||||
printf ("-to n (in midi ticks)\n");
|
printf ("-to n (in midi ticks)\n");
|
||||||
|
|||||||
201
midistats.c
201
midistats.c
@@ -18,7 +18,7 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define VERSION "0.71 August 22 2023 midistats"
|
#define VERSION "0.80 November 17 2023 midistats"
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
/* Microsoft Visual C++ Version 6.0 or higher */
|
/* Microsoft Visual C++ Version 6.0 or higher */
|
||||||
@@ -49,10 +49,11 @@ extern char* strchr();
|
|||||||
#include "midifile.h"
|
#include "midifile.h"
|
||||||
void initfuncs();
|
void initfuncs();
|
||||||
void stats_finish();
|
void stats_finish();
|
||||||
float histogram_entropy (int *histogram, int size);
|
float histogram_perplexity (int *histogram, int size);
|
||||||
void stats_noteoff(int chan,int pitch,int vol);
|
void stats_noteoff(int chan,int pitch,int vol);
|
||||||
void stats_eot ();
|
void stats_eot ();
|
||||||
|
#define max(a,b) (( a > b ? a : b))
|
||||||
|
#define min(a,b) (( a < b ? a : b))
|
||||||
|
|
||||||
/* Global variables and structures */
|
/* Global variables and structures */
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ static FILE *F;
|
|||||||
static FILE *outhandle; /* for producing the abc file */
|
static FILE *outhandle; /* for producing the abc file */
|
||||||
|
|
||||||
int tracknum=0; /* track number */
|
int tracknum=0; /* track number */
|
||||||
|
int lasttrack = 0; /* lasttrack */
|
||||||
int division; /* pulses per quarter note defined in MIDI header */
|
int division; /* pulses per quarter note defined in MIDI header */
|
||||||
int quietLimit; /* minimum number of pulses with no activity */
|
int quietLimit; /* minimum number of pulses with no activity */
|
||||||
long tempo = 500000; /* the default tempo is 120 quarter notes/minute */
|
long tempo = 500000; /* the default tempo is 120 quarter notes/minute */
|
||||||
@@ -85,13 +87,14 @@ int divisionsPerBar;
|
|||||||
int unitDivision;
|
int unitDivision;
|
||||||
int maximumPulse;
|
int maximumPulse;
|
||||||
int lastBeat;
|
int lastBeat;
|
||||||
|
int hasLyrics = 0;
|
||||||
|
|
||||||
|
|
||||||
struct eventstruc {int onsetTime;
|
struct eventstruc {int onsetTime;
|
||||||
unsigned char channel;
|
unsigned char channel;
|
||||||
unsigned char pitch;
|
unsigned char pitch;
|
||||||
unsigned char velocity;
|
unsigned char velocity;
|
||||||
;} midievents[40000];
|
;} midievents[50000];
|
||||||
|
|
||||||
int lastEvent = 0;
|
int lastEvent = 0;
|
||||||
|
|
||||||
@@ -114,8 +117,10 @@ int trackcount = 0;
|
|||||||
|
|
||||||
int notechan[2048],notechanvol[2048]; /*for linking on and off midi
|
int notechan[2048],notechanvol[2048]; /*for linking on and off midi
|
||||||
channel commands */
|
channel commands */
|
||||||
int last_tick[17]; /* for getting last pulse number in MIDI file */
|
int lastTick[2048]; /* for getting last pulse number for chan (0-15) and pitch (0-127) in MIDI file */
|
||||||
int last_on_tick[17]; /* for detecting chords [SS] 2019-08-02 */
|
int last_on_tick[17]; /* for detecting chords [SS] 2019-08-02 */
|
||||||
|
int channel_active[17]; /* for dealing with chords [SS] 2023-08-30 */
|
||||||
|
int channel_used_in_track[17]; /* for dealing with quietTime [SS] 2023-09-06 */
|
||||||
|
|
||||||
int histogram[256];
|
int histogram[256];
|
||||||
unsigned char drumpat[8000];
|
unsigned char drumpat[8000];
|
||||||
@@ -131,7 +136,11 @@ struct trkstat {
|
|||||||
int notecount[17];
|
int notecount[17];
|
||||||
int chordcount[17];
|
int chordcount[17];
|
||||||
int notemeanpitch[17];
|
int notemeanpitch[17];
|
||||||
|
int notepitchmin[17];
|
||||||
|
int notepitchmax[17];
|
||||||
int notelength[17];
|
int notelength[17];
|
||||||
|
int notelengthmin[17];
|
||||||
|
int notelengthmax[17];
|
||||||
int pitchbend[17];
|
int pitchbend[17];
|
||||||
int pressure[17];
|
int pressure[17];
|
||||||
int cntlparam[17];
|
int cntlparam[17];
|
||||||
@@ -141,6 +150,9 @@ struct trkstat {
|
|||||||
int lastNoteOff[17];
|
int lastNoteOff[17];
|
||||||
int quietTime[17];
|
int quietTime[17];
|
||||||
int rhythmpatterns[17];
|
int rhythmpatterns[17];
|
||||||
|
int numberOfGaps[17];
|
||||||
|
int chanvol[17];
|
||||||
|
float pitchEntropy[17];
|
||||||
} trkdata;
|
} trkdata;
|
||||||
|
|
||||||
/* The trkstat references the individual channels in the midi file.
|
/* The trkstat references the individual channels in the midi file.
|
||||||
@@ -162,8 +174,10 @@ int pitchhistogram[12]; /* pitch distribution for non drum notes */
|
|||||||
int channel2prog[17]; /* maps channel to program */
|
int channel2prog[17]; /* maps channel to program */
|
||||||
int channel2nnotes[17]; /*maps channel to note count */
|
int channel2nnotes[17]; /*maps channel to note count */
|
||||||
int chnactivity[17]; /* [SS] 2018-02-02 */
|
int chnactivity[17]; /* [SS] 2018-02-02 */
|
||||||
|
int trkactivity[40]; /* [SS] 2023-10-25 */
|
||||||
int progactivity[128]; /* [SS] 2018-02-02 */
|
int progactivity[128]; /* [SS] 2018-02-02 */
|
||||||
int pitchclass_activity[12]; /* [SS] 2018-02-02 */
|
int pitchclass_activity[12]; /* [SS] 2018-02-02 */
|
||||||
|
int chanpitchhistogram[204]; /* [SS] 2023-09-13 */
|
||||||
|
|
||||||
|
|
||||||
/* [SS] 2017-11-01 */
|
/* [SS] 2017-11-01 */
|
||||||
@@ -186,7 +200,7 @@ static int progmapper[] = {
|
|||||||
16, 16, 16, 16, 16, 16, 16, 16
|
16, 16, 16, 16, 16, 16, 16, 16
|
||||||
};
|
};
|
||||||
|
|
||||||
int pulseCounter[480];
|
int pulseCounter[1024];
|
||||||
int pulseDistribution[24];
|
int pulseDistribution[24];
|
||||||
|
|
||||||
struct barPattern {
|
struct barPattern {
|
||||||
@@ -407,6 +421,7 @@ void stats_header (int format, int ntrks, int ldivision)
|
|||||||
quietLimit = ldivision*8;
|
quietLimit = ldivision*8;
|
||||||
divisionsPerBar = division*beatsPerBar;
|
divisionsPerBar = division*beatsPerBar;
|
||||||
unitDivision = divisionsPerBar/24;
|
unitDivision = divisionsPerBar/24;
|
||||||
|
lasttrack = ntrks; /* [SS] 2023-10-25 */
|
||||||
printf("ntrks %d\n",ntrks);
|
printf("ntrks %d\n",ntrks);
|
||||||
printf("ppqn %d\n",ldivision);
|
printf("ppqn %d\n",ldivision);
|
||||||
chordthreshold = ldivision/16; /* [SS] 2018-01-21 */
|
chordthreshold = ldivision/16; /* [SS] 2018-01-21 */
|
||||||
@@ -419,6 +434,8 @@ void stats_header (int format, int ntrks, int ldivision)
|
|||||||
trkdata.cntlparam[i] = 0; /* [SS] 2022-03-04 */
|
trkdata.cntlparam[i] = 0; /* [SS] 2022-03-04 */
|
||||||
trkdata.pressure[i] = 0; /* [SS] 2022-03-04 */
|
trkdata.pressure[i] = 0; /* [SS] 2022-03-04 */
|
||||||
trkdata.quietTime[i] = 0; /* [SS] 2022-08-22 */
|
trkdata.quietTime[i] = 0; /* [SS] 2022-08-22 */
|
||||||
|
trkdata.numberOfGaps[i] = 0; /* [SS] 2023-09-07 */
|
||||||
|
trkdata.chanvol[i] = 0; /* [SS] 2023-10-30 */
|
||||||
progcolor[i] = 0;
|
progcolor[i] = 0;
|
||||||
channel2prog[i] = 0; /* [SS] 2023-06-25-8/
|
channel2prog[i] = 0; /* [SS] 2023-06-25-8/
|
||||||
channel2nnotes[i] = 0;
|
channel2nnotes[i] = 0;
|
||||||
@@ -428,6 +445,7 @@ void stats_header (int format, int ntrks, int ldivision)
|
|||||||
for (i=0;i<12;i++) pitchhistogram[i] = 0; /* [SS] 2017-11-01 */
|
for (i=0;i<12;i++) pitchhistogram[i] = 0; /* [SS] 2017-11-01 */
|
||||||
for (i=0;i<12;i++) pitchclass_activity[i] = 0; /* [SS] 2018-02-02 */
|
for (i=0;i<12;i++) pitchclass_activity[i] = 0; /* [SS] 2018-02-02 */
|
||||||
for (i=0;i<128;i++) progactivity[i] = 0; /* [SS] 2018-02-02 */
|
for (i=0;i<128;i++) progactivity[i] = 0; /* [SS] 2018-02-02 */
|
||||||
|
for (i=0;i<40;i++) trkactivity[i]=0; /* [SS] 2023-10-25 */
|
||||||
}
|
}
|
||||||
|
|
||||||
void determine_progcolor ()
|
void determine_progcolor ()
|
||||||
@@ -454,6 +472,47 @@ int i;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* [SS] 2023-10-30 */
|
||||||
|
void stats_interpret_pulseCounter () {
|
||||||
|
int i,j;
|
||||||
|
int maxcount,ncounts;
|
||||||
|
int maxloc;
|
||||||
|
float threshold,peak;
|
||||||
|
int decimate;
|
||||||
|
float tripletsCriterion8,tripletsCriterion4;
|
||||||
|
int resolution = 12;
|
||||||
|
int nzeros;
|
||||||
|
threshold = 10.0/(float) division;
|
||||||
|
maxcount = 0;
|
||||||
|
ncounts = 0;
|
||||||
|
for (i=0;i<division;i++) {
|
||||||
|
ncounts = ncounts + pulseCounter[i];
|
||||||
|
if (pulseCounter[i] > maxcount) {
|
||||||
|
maxloc = i;
|
||||||
|
maxcount = pulseCounter[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < resolution; i++) pulseDistribution[i] = 0;
|
||||||
|
decimate = division/resolution;
|
||||||
|
for (i = 0; i < division; i++) {
|
||||||
|
j = i/decimate;
|
||||||
|
pulseDistribution[j] += pulseCounter[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* count zeros */
|
||||||
|
nzeros = 0;
|
||||||
|
for (i=0;i<resolution;i++) if(pulseDistribution[i] == 0) nzeros++;
|
||||||
|
if (nzeros > 7 && pulseDistribution[resolution-1] == 0) printf("clean_quantization");
|
||||||
|
if (pulseDistribution[resolution-1] > 0.05) printf("dithered_quantization\n");
|
||||||
|
|
||||||
|
peak = (float) maxcount/ (float) ncounts;
|
||||||
|
if (peak < threshold) printf("unquantized\n");
|
||||||
|
tripletsCriterion8 = (float) pulseDistribution[8]/ (float) ncounts;
|
||||||
|
tripletsCriterion4 = (float) pulseDistribution[4]/ (float) ncounts;
|
||||||
|
/*printf("tripletsCriterion = %f\n",tripletsCriterion);*/
|
||||||
|
if (tripletsCriterion8 > 0.10 || tripletsCriterion4 > 0.10) printf("triplets\n");
|
||||||
|
if (pulseDistribution[0]/(float) ncounts > 0.95) printf("qnotes");
|
||||||
|
}
|
||||||
|
|
||||||
void stats_finish()
|
void stats_finish()
|
||||||
{
|
{
|
||||||
@@ -511,38 +570,39 @@ if (npulses > 0)
|
|||||||
for (i=0;i<12;i++) printf("%5.2f ",pitchclass_activity[i]/(double) npulses);
|
for (i=0;i<12;i++) printf("%5.2f ",pitchclass_activity[i]/(double) npulses);
|
||||||
else
|
else
|
||||||
for (i=0;i<12;i++) printf("%5.2f ",(double) pitchclass_activity[i]);
|
for (i=0;i<12;i++) printf("%5.2f ",(double) pitchclass_activity[i]);
|
||||||
|
printf("\nchanvol "); /* [SS] 2023-10-30 */
|
||||||
|
for (i=1;i<17;i++) printf("%4d ",trkdata.chanvol[i]);
|
||||||
printf("\nchnact "); /* [SS] 2018-02-08 */
|
printf("\nchnact "); /* [SS] 2018-02-08 */
|
||||||
if (npulses > 0)
|
if (npulses > 0)
|
||||||
for (i=1;i<17;i++) printf("%5.2f ",chnactivity[i]/(double) trkdata.npulses[0]);
|
for (i=1;i<17;i++) printf("%5.3f ",chnactivity[i]/(double) trkdata.npulses[0]);
|
||||||
else
|
else
|
||||||
for (i=0;i<17;i++) printf("%5.2f ",(double) chnactivity[i]);
|
for (i=0;i<17;i++) printf("%5.3f ",(double) chnactivity[i]);
|
||||||
printf("\nquietTime ");
|
printf("\ntrkact ");
|
||||||
for (i=1;i<17;i++) {
|
lasttrack++;
|
||||||
delta = trkdata.npulses[0] - trkdata.quietTime[i];
|
for (i=0;i<lasttrack;i++) printf("% 5d",trkactivity[i]);
|
||||||
if (trkdata.quietTime[i] < quietLimit) delta = 0;
|
printf("\npitchentropy %f\n",histogram_perplexity(pitchclass_activity,12));
|
||||||
delta = delta / (double) trkdata.npulses[0];
|
|
||||||
/* printf (" %5.3f ", delta); */
|
|
||||||
printf (" %d ", trkdata.quietTime[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\npitchentropy %f\n",histogram_entropy(pitchclass_activity,12));
|
|
||||||
printf("totalrhythmpatterns =%d\n",nrpatterns);
|
printf("totalrhythmpatterns =%d\n",nrpatterns);
|
||||||
printf("collisions = %d\n",ncollisions);
|
printf("collisions = %d\n",ncollisions);
|
||||||
|
if (hasLyrics) printf("Lyrics\n");
|
||||||
|
stats_interpret_pulseCounter ();
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float histogram_entropy (int *histogram, int size)
|
float histogram_perplexity (int *histogram, int size)
|
||||||
{
|
{
|
||||||
|
/* The perplexity is 2 to the power of the entropy */
|
||||||
int i;
|
int i;
|
||||||
int total;
|
int total;
|
||||||
float entropy;
|
float entropy;
|
||||||
float e,p;
|
float e,p;
|
||||||
total = 0;
|
total = 0;
|
||||||
entropy = 0.0;
|
entropy = 0.0;
|
||||||
|
//printf("\nhistogram_entropy of:");
|
||||||
for (i=0;i<size;i++) {
|
for (i=0;i<size;i++) {
|
||||||
total += histogram[i];
|
total += histogram[i];
|
||||||
|
//printf(" %d",histogram[i]);
|
||||||
}
|
}
|
||||||
for (i=0;i<size;i++) {
|
for (i=0;i<size;i++) {
|
||||||
if (histogram[i] < 1) continue;
|
if (histogram[i] < 1) continue;
|
||||||
@@ -550,7 +610,8 @@ float histogram_entropy (int *histogram, int size)
|
|||||||
e = p*log(p);
|
e = p*log(p);
|
||||||
entropy = entropy + e;
|
entropy = entropy + e;
|
||||||
}
|
}
|
||||||
return -entropy/log(2.0);
|
//printf("\n");
|
||||||
|
return pow(2.0,-entropy/log(2.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -589,8 +650,13 @@ for (i=1;i<17;i++) {
|
|||||||
else
|
else
|
||||||
printf("-1 0 ");
|
printf("-1 0 ");
|
||||||
printf("%d %d ",trkdata.cntlparam[i],trkdata.pressure[i]); /* [SS] 2022-03-04 */
|
printf("%d %d ",trkdata.cntlparam[i],trkdata.pressure[i]); /* [SS] 2022-03-04 */
|
||||||
printf("%d %d",trkdata.quietTime[i],trkdata.rhythmpatterns[i]);
|
printf("%d %d ",trkdata.quietTime[i],trkdata.rhythmpatterns[i]);
|
||||||
trkdata.quietTime[i] = 0;
|
if (i != 10) {printf("%d %d %d %d %d",trkdata.notepitchmin[i], trkdata.notepitchmax[i] ,trkdata.notelengthmin[i], trkdata.notelengthmax[i], trkdata.numberOfGaps[i]);
|
||||||
|
printf(" %f",trkdata.pitchEntropy[i]);
|
||||||
|
} else
|
||||||
|
printf("-1 0");
|
||||||
|
trkdata.quietTime[i] = 0; /* in case channel i is used in another track */
|
||||||
|
trkdata.numberOfGaps[i] = 0;
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
channel2nnotes[i] += trkdata.notecount[i] + trkdata.chordcount[i];
|
channel2nnotes[i] += trkdata.notecount[i] + trkdata.chordcount[i];
|
||||||
@@ -607,19 +673,35 @@ void stats_trackstart()
|
|||||||
for (i=0;i<17;i++) {
|
for (i=0;i<17;i++) {
|
||||||
trkdata.notecount[i] = 0;
|
trkdata.notecount[i] = 0;
|
||||||
trkdata.notemeanpitch[i] = 0;
|
trkdata.notemeanpitch[i] = 0;
|
||||||
|
trkdata.notepitchmin[i] = 128;
|
||||||
|
trkdata.notepitchmax[i] = 0;
|
||||||
trkdata.notelength[i] = 0;
|
trkdata.notelength[i] = 0;
|
||||||
|
trkdata.notelengthmin[i] = 10000;
|
||||||
|
trkdata.notelengthmax[i] = 0;
|
||||||
trkdata.chordcount[i] = 0;
|
trkdata.chordcount[i] = 0;
|
||||||
trkdata.cntlparam[i] = 0;
|
trkdata.cntlparam[i] = 0;
|
||||||
last_tick[i] = -1;
|
|
||||||
last_on_tick[i] = -1;
|
last_on_tick[i] = -1;
|
||||||
|
channel_active[i] = 0;
|
||||||
}
|
}
|
||||||
printf("trk %d \n",tracknum);
|
printf("trk %d \n",tracknum);
|
||||||
|
|
||||||
|
for (i=0;i<2048;i++) lastTick[i] = -1;
|
||||||
|
for (i=0;i<17;i++) channel_used_in_track[i] = 0; /* [SS] 2023-09-06 */
|
||||||
|
for (i=0;i<204;i++) chanpitchhistogram[i] = 0; /* [SS] 2023-09-13 */
|
||||||
}
|
}
|
||||||
|
|
||||||
void stats_trackend()
|
void stats_trackend()
|
||||||
{
|
{
|
||||||
trkdata.npulses[tracknum] = Mf_currtime;
|
int chan;
|
||||||
|
int i;
|
||||||
|
float entropy;
|
||||||
if (trkdata.npulses[0] < Mf_currtime) trkdata.npulses[0] = Mf_currtime;
|
if (trkdata.npulses[0] < Mf_currtime) trkdata.npulses[0] = Mf_currtime;
|
||||||
|
for (chan = 1; chan < 17; chan++) /* [SS] 2023-09-06 */
|
||||||
|
if (channel_used_in_track[chan] > 0) trkdata.quietTime[chan] += (trkdata.npulses[0] - trkdata.lastNoteOff[chan]);
|
||||||
|
for (chan=0;chan<16;chan++) { /* 2023-09-13 */
|
||||||
|
if (chan == 9 || channel_used_in_track[chan+1] == 0) continue;
|
||||||
|
trkdata.pitchEntropy[chan+1] = histogram_perplexity(chanpitchhistogram +chan*12,11);
|
||||||
|
}
|
||||||
output_track_summary();
|
output_track_summary();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,7 +714,11 @@ int chan, pitch, vol;
|
|||||||
int barnum;
|
int barnum;
|
||||||
int unit;
|
int unit;
|
||||||
int dithermargin; /* [SS] 2023-08-22 */
|
int dithermargin; /* [SS] 2023-08-22 */
|
||||||
|
int cpitch; /* [SS] 2023-09-13 */
|
||||||
|
int pulsePosition;
|
||||||
|
|
||||||
|
cpitch = pitch % 12;
|
||||||
|
channel_used_in_track[chan+1]++; /* [SS] 2023-09-06 */
|
||||||
dithermargin = unitDivision/2 - 1;
|
dithermargin = unitDivision/2 - 1;
|
||||||
if (vol == 0) {
|
if (vol == 0) {
|
||||||
/* treat as noteoff */
|
/* treat as noteoff */
|
||||||
@@ -640,18 +726,26 @@ int chan, pitch, vol;
|
|||||||
trkdata.lastNoteOff[chan+1] = Mf_currtime; /* [SS] 2022.08.22 */
|
trkdata.lastNoteOff[chan+1] = Mf_currtime; /* [SS] 2022.08.22 */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
pulsePosition = Mf_currtime % division;
|
||||||
|
pulseCounter[pulsePosition]++;
|
||||||
|
if (pulsePosition >= 1023) {printf("pulsePosition = %d too large\n",pulsePosition);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
trkdata.notemeanpitch[chan+1] += pitch;
|
trkdata.notemeanpitch[chan+1] += pitch;
|
||||||
|
trkdata.notepitchmax[chan+1] = max(trkdata.notepitchmax[chan+1],pitch);
|
||||||
|
trkdata.notepitchmin[chan+1] = min(trkdata.notepitchmin[chan+1],pitch);
|
||||||
if (trkdata.lastNoteOff[chan+1] >= 0) {
|
if (trkdata.lastNoteOff[chan+1] >= 0) {
|
||||||
delta = Mf_currtime - trkdata.lastNoteOff[chan+1];
|
delta = Mf_currtime - trkdata.lastNoteOff[chan+1];
|
||||||
trkdata.lastNoteOff[chan+1] = -1; /* in case of chord */
|
|
||||||
if (delta > quietLimit) {
|
if (delta > quietLimit) {
|
||||||
trkdata.quietTime[chan+1] += delta;
|
trkdata.quietTime[chan+1] += delta;
|
||||||
|
trkdata.numberOfGaps[chan+1]++;
|
||||||
|
trkdata.lastNoteOff[chan+1] = -1; /* in case of chord */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abs(Mf_currtime - last_on_tick[chan+1]) < chordthreshold) trkdata.chordcount[chan+1]++;
|
if (abs(Mf_currtime - last_on_tick[chan+1]) < chordthreshold) trkdata.chordcount[chan+1]++;
|
||||||
else trkdata.notecount[chan+1]++; /* [SS] 2019-08-02 */
|
else trkdata.notecount[chan+1]++; /* [SS] 2019-08-02 */
|
||||||
last_tick[chan+1] = Mf_currtime;
|
lastTick[chan*128 + pitch] = Mf_currtime;
|
||||||
last_on_tick[chan+1] = Mf_currtime; /* [SS] 2019-08-02 */
|
last_on_tick[chan+1] = Mf_currtime; /* [SS] 2019-08-02 */
|
||||||
/* last_on_tick not updated by stats_noteoff */
|
/* last_on_tick not updated by stats_noteoff */
|
||||||
|
|
||||||
@@ -669,6 +763,7 @@ int chan, pitch, vol;
|
|||||||
unit = ((Mf_currtime+dithermargin) % divisionsPerBar)/unitDivision;
|
unit = ((Mf_currtime+dithermargin) % divisionsPerBar)/unitDivision;
|
||||||
//printf("unit = %d pattern = %d \n",unit,barChn[chan].rhythmPattern);
|
//printf("unit = %d pattern = %d \n",unit,barChn[chan].rhythmPattern);
|
||||||
barChn[chan].rhythmPattern = barChn[chan].rhythmPattern |= (1UL << unit);
|
barChn[chan].rhythmPattern = barChn[chan].rhythmPattern |= (1UL << unit);
|
||||||
|
chanpitchhistogram[chan*12+cpitch]++; /* [SS] 2023-09-13 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -679,6 +774,8 @@ int chan, pitch, vol;
|
|||||||
else drumhistogram[pitch]++;
|
else drumhistogram[pitch]++;
|
||||||
}
|
}
|
||||||
else pitchhistogram[pitch % 12]++; /* [SS] 2017-11-01 */
|
else pitchhistogram[pitch % 12]++; /* [SS] 2017-11-01 */
|
||||||
|
|
||||||
|
channel_active[chan+1]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -691,17 +788,28 @@ void stats_noteoff(int chan,int pitch,int vol)
|
|||||||
int length;
|
int length;
|
||||||
int program;
|
int program;
|
||||||
/* ignore if there was no noteon */
|
/* ignore if there was no noteon */
|
||||||
if (last_tick[chan+1] == -1) return;
|
if (lastTick[chan*128+pitch] == -1) return;
|
||||||
length = Mf_currtime - last_tick[chan+1];
|
length = Mf_currtime - lastTick[chan*128+pitch];
|
||||||
trkdata.notelength[chan+1] += length;
|
trkdata.notelength[chan+1] += length;
|
||||||
|
trkdata.notelengthmax[chan+1] = max(trkdata.notelengthmax[chan+1],length);
|
||||||
|
trkdata.notelengthmin[chan+1] = min(trkdata.notelengthmin[chan+1],length);
|
||||||
|
//if (length < 3) printf("chan = %d lasttick = %d currtime = %ld\n",chan,lastTick[chan*128+pitch],Mf_currtime);
|
||||||
trkdata.lastNoteOff[chan+1] = Mf_currtime; /* [SS] 2022.08.22 */
|
trkdata.lastNoteOff[chan+1] = Mf_currtime; /* [SS] 2022.08.22 */
|
||||||
chnactivity[chan+1] += length;
|
chnactivity[chan+1] += length;
|
||||||
|
trkactivity[tracknum]++;
|
||||||
if (chan == 9) return; /* drum channel */
|
if (chan == 9) return; /* drum channel */
|
||||||
pitchclass_activity[pitch % 12] += length;
|
pitchclass_activity[pitch % 12] += length;
|
||||||
program = trkdata.program[chan+1];
|
program = trkdata.program[chan+1];
|
||||||
progactivity[program] += length;
|
progactivity[program] += length;
|
||||||
|
channel_active[chan+1]--;
|
||||||
/* [SS] 2018-04-18 */
|
/* [SS] 2018-04-18 */
|
||||||
if(Mf_currtime > last_tick[chan+1]) last_tick[chan+1] = Mf_currtime;
|
if(Mf_currtime > lastTick[chan*128+pitch] && channel_active[chan+1] == 0)
|
||||||
|
lastTick[chan*128+pitch] = Mf_currtime; /* [SS] 2023.08.30 handle chords */
|
||||||
|
|
||||||
|
if (length > 4800) {
|
||||||
|
lastTick[chan*128+pitch] = Mf_currtime; /* handle stuck note [SS] 2023.08.30 */
|
||||||
|
channel_active[chan+1] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -743,11 +851,16 @@ if (trkdata.program[chan+1] != 0) {
|
|||||||
void stats_parameter(chan,control,value)
|
void stats_parameter(chan,control,value)
|
||||||
int chan, control, value;
|
int chan, control, value;
|
||||||
{
|
{
|
||||||
/*if (control == 7) {
|
int chan1;
|
||||||
printf("cntrlvolume %d %d \n",chan+1,value);
|
chan1 = chan+1;
|
||||||
}
|
/* There may be many volume commands for the same channel. Only
|
||||||
|
record the first one.
|
||||||
*/
|
*/
|
||||||
trkdata.cntlparam[chan+1]++;
|
if (control == 7 && trkdata.chanvol[chan1] == 0) {
|
||||||
|
/*printf("cntrlvolume %d %d \n",chan+1,value);*/
|
||||||
|
trkdata.chanvol[chan1] = value; /* [SS] 2023-10-30 */
|
||||||
|
}
|
||||||
|
trkdata.cntlparam[chan1]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -757,6 +870,7 @@ int type, leng;
|
|||||||
char *mess;
|
char *mess;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
if (type == 5) hasLyrics = 1; /* [SS] 2023-10-30 */
|
||||||
if (type != 3) return;
|
if (type != 3) return;
|
||||||
printf("metatext %d ",type);
|
printf("metatext %d ",type);
|
||||||
for (i=0;i<leng;i++) printf("%c",mess[i]);
|
for (i=0;i<leng;i++) printf("%c",mess[i]);
|
||||||
@@ -819,9 +933,10 @@ midievents[lastEvent].channel = chan;
|
|||||||
midievents[lastEvent].pitch = pitch;
|
midievents[lastEvent].pitch = pitch;
|
||||||
midievents[lastEvent].velocity = vol;
|
midievents[lastEvent].velocity = vol;
|
||||||
lastEvent++;
|
lastEvent++;
|
||||||
if (lastEvent > 39999) {printf("ran out of space in midievents structure\n");
|
if (lastEvent > 49999) {printf("ran out of space in midievents structure\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
channel_active[chan+1]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void record_noteoff(int chan,int pitch,int vol)
|
void record_noteoff(int chan,int pitch,int vol)
|
||||||
@@ -843,12 +958,16 @@ int int_compare_events(const void *a, const void *b) {
|
|||||||
|
|
||||||
void load_header (int format, int ntrks, int ldivision)
|
void load_header (int format, int ntrks, int ldivision)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
division = ldivision;
|
division = ldivision;
|
||||||
|
lasttrack = ntrks;
|
||||||
|
for (i=0;i<17;i++) channel_active[i] = 0; /* for counting number of channels*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void initfunc_for_stats()
|
void initfunc_for_stats()
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
Mf_error = stats_error; /* [SS] 2017-11-19 */
|
Mf_error = stats_error; /* [SS] 2017-11-19 */
|
||||||
Mf_header = stats_header;
|
Mf_header = stats_header;
|
||||||
Mf_trackstart = stats_trackstart;
|
Mf_trackstart = stats_trackstart;
|
||||||
@@ -871,6 +990,7 @@ void initfunc_for_stats()
|
|||||||
Mf_seqspecific = no_op3;
|
Mf_seqspecific = no_op3;
|
||||||
Mf_text = stats_metatext;
|
Mf_text = stats_metatext;
|
||||||
Mf_arbitrary = no_op2;
|
Mf_arbitrary = no_op2;
|
||||||
|
for (i = 0; i< 1023; i++) pulseCounter[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -922,16 +1042,16 @@ int pulsePosition;
|
|||||||
int decimate;
|
int decimate;
|
||||||
float fraction;
|
float fraction;
|
||||||
int resolution = 12;
|
int resolution = 12;
|
||||||
for (i = 0; i< 480; i++) pulseCounter[i] = 0;
|
for (i = 0; i< 1023; i++) pulseCounter[i] = 0;
|
||||||
for (i = 0; i < lastEvent; i++) {
|
for (i = 0; i < lastEvent; i++) {
|
||||||
pulsePosition = midievents[i].onsetTime % division;
|
pulsePosition = midievents[i].onsetTime % division;
|
||||||
pulseCounter[pulsePosition]++;
|
pulseCounter[pulsePosition]++;
|
||||||
if (pulsePosition >= 480) {printf("pulsePosition = %d too large\n",pulsePosition);
|
if (pulsePosition >= 1023) {printf("pulsePosition = %d too large\n",pulsePosition);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < resolution; i++) pulseDistribution[i] = 0;
|
for (i = 0; i < resolution; i++) pulseDistribution[i] = 0;
|
||||||
/*for (i = 0; i < 480; i++) printf(" %d",pulseCounter[i]);
|
/*for (i = 0; i < 1023; i++) printf(" %d",pulseCounter[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
*/
|
*/
|
||||||
decimate = division/resolution;
|
decimate = division/resolution;
|
||||||
@@ -1113,7 +1233,12 @@ printf("\n");
|
|||||||
|
|
||||||
|
|
||||||
void corestatsOutput() {
|
void corestatsOutput() {
|
||||||
printf("%d\t%d\t%d\n", division,lastEvent,lastBeat);
|
int i;
|
||||||
|
int nchannels;
|
||||||
|
nchannels = 0;
|
||||||
|
for (i=1;i<17;i++)
|
||||||
|
if (channel_active[i] > 0) nchannels++;
|
||||||
|
printf("%d\t%d\t%d\t%d\t%d\n",lasttrack,nchannels, division,lastEvent,lastBeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user