mirror of
https://github.com/sshlien/abcmidi.git
synced 2025-12-06 15:05:07 +00:00
Compare commits
5 Commits
2022.02.08
...
2023.03.15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e49858809a | ||
|
|
821240720d | ||
|
|
1f835036e2 | ||
|
|
a410e191d0 | ||
|
|
a29dc35927 |
82
doc/drums.txt
Executable file
82
doc/drums.txt
Executable file
@@ -0,0 +1,82 @@
|
|||||||
|
Advamced Percussion Analysis
|
||||||
|
in the Midistats Program
|
||||||
|
|
||||||
|
This is an addendum to the midistats.1 file.
|
||||||
|
|
||||||
|
The MIDI file devotes channel 9 to the percussion instruments
|
||||||
|
and over 60 percussion instruments are defined in the MIDI
|
||||||
|
standard. Though there is a lot of diversity in the percussion
|
||||||
|
track, for most MIDI files only the first 10 or so percussion
|
||||||
|
instruments are important in defining the character of the track. The
|
||||||
|
program Midiexplorer has various tools for exposing the percussion
|
||||||
|
channel which are described in the documentation. The goal
|
||||||
|
here is to find the essential characteristics of the percussion
|
||||||
|
track which distinguishes the MIDI files. This is attempted
|
||||||
|
in the program midistats. Here is a short description.
|
||||||
|
|
||||||
|
-corestats
|
||||||
|
Produces a line with 3 numbers separated by tabs. eg
|
||||||
|
384 8349 448
|
||||||
|
It returns the number of divisions per quarter note beat (ppqn),
|
||||||
|
the number of note onsets in the midi file, and the maximum
|
||||||
|
number of quarter note beats in midi file.
|
||||||
|
|
||||||
|
-pulseanalysis
|
||||||
|
Counts the number of note onsets as a function of its onset time
|
||||||
|
relative to a beat, grouping them into 12 intervals and returns
|
||||||
|
the result as a discrete probability density function. Generally,
|
||||||
|
the distribution consists of a couple of peaks corresponding
|
||||||
|
to quarter notes or eigth notes. If the distribution is flat,
|
||||||
|
it indicates that the times of the note occurrences have not been
|
||||||
|
quantized into beats and fractions. Here is a sample output.
|
||||||
|
0.3496,0.0000,0.0000,0.1602,0.0000,0.0002,0.2983,0.0000,0.0000,0.1914,0.0002,0.0001
|
||||||
|
|
||||||
|
-panal
|
||||||
|
Counts the number of note onsets for each percussion instrument. The first
|
||||||
|
number is the code (pitch) of the instrument, the second number is the
|
||||||
|
number of occurrences. eg.
|
||||||
|
35 337 37 16 38 432 39 208 40 231 42 1088 46 384 49 42 54 1104 57 5 70 1040 85 16
|
||||||
|
|
||||||
|
-ppatfor n
|
||||||
|
where n is the code number of the percussion instrument. Each beat
|
||||||
|
is represented by a 4 bit number where the position of the on-bit
|
||||||
|
indicates the time in the beat when the drum onset occurs. Thus
|
||||||
|
0 indicates that there was no note onset in that beat, 1 indicates
|
||||||
|
a note onset in the beginning of the beat, 4 indicates a note onset
|
||||||
|
in the middle of the beat, and etc. The function returns a string
|
||||||
|
of numbers ranging from 0 to 7 indicating the presence of note onsets
|
||||||
|
for the selected percussion instrument for the sequence of beats
|
||||||
|
in the midi file. Here is a truncated sample of the output.
|
||||||
|
|
||||||
|
0 0 0 0 0 0 0 0 1 0 0 4 1 0 0 4 1 0 0 4 1 0 0 4 1 0 0 4 1 0 0 4 1 4 4 0
|
||||||
|
1 0 0 0 1 0 5 0 1 0 5 0 1 0 5 0 1 0 5 0 1 0 5 0 1 0 5 0 1 0 5 0 1 0 0 0
|
||||||
|
1 0 5 0 1 0 5 0 1 etc.
|
||||||
|
|
||||||
|
One can see a repeating 4 beat pattern.
|
||||||
|
|
||||||
|
-ppat
|
||||||
|
midistats attempts to find two percussion instruments in the midi file
|
||||||
|
which come closest to acting as the bass drum and snare drum.
|
||||||
|
If it is unsuccessful, it returns a message of its failue. Otherwise,
|
||||||
|
encodes the position of these drum onsets in a 8 bit byte for each
|
||||||
|
quarter note beat in the midi file. The lower (right) 4 bits encode the
|
||||||
|
bass drum and the higher (left) 4 bits encode the snare drum in the
|
||||||
|
same manner as described above for -ppatfor.
|
||||||
|
0 0 0 0 0 0 0 0 0 0 33 145 33 145 33 145 33 145 33 145 33 145 33 145 33 145
|
||||||
|
33 145 33 145 33 145 33 145 33 145 33 145 33 145 33 145 33 145 33 145 33 145
|
||||||
|
33 145 33 145 33 145 33 145 33 145 33 and etc.
|
||||||
|
|
||||||
|
-ppathist
|
||||||
|
computes and displays the histogram of the values that would appear
|
||||||
|
when running the -ppat. eg.
|
||||||
|
bass 35 337
|
||||||
|
snare 38 432
|
||||||
|
1 (0.1) 64 32 (2.0) 8 33 (2.1) 136 144 (9.0) 8 145 (9.1) 136
|
||||||
|
|
||||||
|
The bass percussion code, the number of onsets, and the snare
|
||||||
|
percussion code and the number of onsets are given in the
|
||||||
|
first two lines. In the next line the number of occurrences of
|
||||||
|
each value in the -ppat listing is given. The number in parentheses
|
||||||
|
splits the two 4-bit values with a period. Thus 33 = (2*16 + 1).
|
||||||
|
|
||||||
|
|
||||||
@@ -80,6 +80,17 @@ all channels except the percussion channel.
|
|||||||
collisions. Midistats counts the bar rhythm patterns using a hashing
|
collisions. Midistats counts the bar rhythm patterns using a hashing
|
||||||
function. Presently collisions are ignored so occasionally two
|
function. Presently collisions are ignored so occasionally two
|
||||||
distinct rhythm patterns are counted as one.
|
distinct rhythm patterns are counted as one.
|
||||||
|
.SH Advance Percussion Analysis Tools
|
||||||
|
.PP
|
||||||
|
A number of experimental tools for analyzing the percussion channel
|
||||||
|
(track) were introduced into midistats and are accessible through
|
||||||
|
the runtime arguments. When these tools are used in a script which
|
||||||
|
runs through a collection of midi files, you can build a database
|
||||||
|
of percussion descriptors. Some more details are given in the
|
||||||
|
file drums.txt which comes with this documentation.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Seymour Shlien <fy733@ncf.ca>
|
Seymour Shlien <fy733@ncf.ca>
|
||||||
|
|
||||||
|
|||||||
371
midistats.c
371
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.59 February 08 2023 midistats"
|
#define VERSION "0.67 March 14 2023 midistats"
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
/* Microsoft Visual C++ Version 6.0 or higher */
|
/* Microsoft Visual C++ Version 6.0 or higher */
|
||||||
@@ -72,17 +72,39 @@ int trackno;
|
|||||||
int maintrack;
|
int maintrack;
|
||||||
int format; /* MIDI file type */
|
int format; /* MIDI file type */
|
||||||
int debug;
|
int debug;
|
||||||
|
int pulseanalysis;
|
||||||
|
int percanalysis;
|
||||||
|
int percpattern;
|
||||||
|
int percpatternfor;
|
||||||
|
int percpatternhist;
|
||||||
|
int corestats;
|
||||||
int chordthreshold; /* number of maximum number of pulses separating note */
|
int chordthreshold; /* number of maximum number of pulses separating note */
|
||||||
int beatsPerBar = 4; /* 4/4 time */
|
int beatsPerBar = 4; /* 4/4 time */
|
||||||
int divisionsPerBar;
|
int divisionsPerBar;
|
||||||
int unitDivision;
|
int unitDivision;
|
||||||
|
int maximumPulse;
|
||||||
|
int lastBeat;
|
||||||
|
|
||||||
|
|
||||||
|
struct eventstruc {int onsetTime;
|
||||||
|
unsigned char channel;
|
||||||
|
unsigned char pitch;
|
||||||
|
unsigned char velocity;
|
||||||
|
;} midievents[40000];
|
||||||
|
|
||||||
|
int lastEvent = 0;
|
||||||
|
|
||||||
|
|
||||||
int tempocount=0; /* number of tempo indications in MIDI file */
|
int tempocount=0; /* number of tempo indications in MIDI file */
|
||||||
|
|
||||||
int stats = 0; /* flag - gather and print statistics */
|
int stats = 0; /* flag - gather and print statistics */
|
||||||
|
|
||||||
|
int pulseanalysis = 0;
|
||||||
|
int percanalysis = 0;
|
||||||
|
int percpattern = 0;
|
||||||
|
int percpatternfor = 0;
|
||||||
|
int percpatternhist = 0;
|
||||||
|
int corestats = 0;
|
||||||
|
|
||||||
|
|
||||||
/* can cope with up to 64 track MIDI files */
|
/* can cope with up to 64 track MIDI files */
|
||||||
@@ -93,6 +115,9 @@ int notechan[2048],notechanvol[2048]; /*for linking on and off midi
|
|||||||
int last_tick[17]; /* for getting last pulse number in MIDI file */
|
int last_tick[17]; /* for getting last pulse number 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 histogram[256];
|
||||||
|
unsigned char drumpat[8000];
|
||||||
|
int percnum;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -130,7 +155,7 @@ struct trkstat {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int progcolor[17]; /* used by stats_program */
|
int progcolor[17]; /* used by stats_program */
|
||||||
int drumhistogram[82]; /* counts drum noteons */
|
int drumhistogram[100]; /* counts drum noteons */
|
||||||
int pitchhistogram[12]; /* pitch distribution for non drum notes */
|
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 */
|
||||||
@@ -159,6 +184,8 @@ static int progmapper[] = {
|
|||||||
16, 16, 16, 16, 16, 16, 16, 16
|
16, 16, 16, 16, 16, 16, 16, 16
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int pulseCounter[480];
|
||||||
|
int pulseDistribution[24];
|
||||||
|
|
||||||
struct barPattern {
|
struct barPattern {
|
||||||
int activeBarNumber;
|
int activeBarNumber;
|
||||||
@@ -395,7 +422,7 @@ void stats_header (int format, int ntrks, int ldivision)
|
|||||||
channel2nnotes[i] = 0;
|
channel2nnotes[i] = 0;
|
||||||
chnactivity[i] = 0; /* [SS] 2018-02-02 */
|
chnactivity[i] = 0; /* [SS] 2018-02-02 */
|
||||||
}
|
}
|
||||||
for (i=0;i<82;i++) drumhistogram[i] = 0;
|
for (i=0;i<100;i++) drumhistogram[i] = 0;
|
||||||
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 */
|
||||||
@@ -467,11 +494,11 @@ else
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
printf("drums ");
|
printf("drums ");
|
||||||
for (i=35;i<82;i++) {
|
for (i=35;i<100;i++) {
|
||||||
if (drumhistogram[i] > 0) printf("%d ",i);
|
if (drumhistogram[i] > 0) printf("%d ",i);
|
||||||
}
|
}
|
||||||
printf("\ndrumhits ");
|
printf("\ndrumhits ");
|
||||||
for (i=35;i<82;i++) {
|
for (i=35;i<100;i++) {
|
||||||
if (drumhistogram[i] > 0) printf("%d ",drumhistogram[i]);
|
if (drumhistogram[i] > 0) printf("%d ",drumhistogram[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -640,7 +667,7 @@ int chan, pitch, vol;
|
|||||||
|
|
||||||
|
|
||||||
if (chan == 9) {
|
if (chan == 9) {
|
||||||
if (pitch < 0 || pitch > 81)
|
if (pitch < 0 || pitch > 100)
|
||||||
printf("****illegal drum value %d\n",pitch);
|
printf("****illegal drum value %d\n",pitch);
|
||||||
else drumhistogram[pitch]++;
|
else drumhistogram[pitch]++;
|
||||||
}
|
}
|
||||||
@@ -776,7 +803,41 @@ int nn, dd, cc, bb;
|
|||||||
printf("timesig %d/%d %6.2f\n",nn,denom,beatnumber);
|
printf("timesig %d/%d %6.2f\n",nn,denom,beatnumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void record_noteon(int chan,int pitch,int vol)
|
||||||
|
{
|
||||||
|
if (maximumPulse < Mf_currtime) maximumPulse = Mf_currtime;
|
||||||
|
if (vol < 1) return; /* noteoff ? */
|
||||||
|
midievents[lastEvent].onsetTime = Mf_currtime;
|
||||||
|
midievents[lastEvent].channel = chan;
|
||||||
|
midievents[lastEvent].pitch = pitch;
|
||||||
|
midievents[lastEvent].velocity = vol;
|
||||||
|
lastEvent++;
|
||||||
|
if (lastEvent > 39999) {printf("ran out of space in midievents structure\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void record_noteoff(int chan,int pitch,int vol)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void record_trackend()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int int_compare_events(const void *a, const void *b) {
|
||||||
|
struct eventstruc *ia = (struct eventstruc *)a;
|
||||||
|
struct eventstruc *ib = (struct eventstruc *)b;
|
||||||
|
if (ib->onsetTime > ia->onsetTime)
|
||||||
|
return -1;
|
||||||
|
else if (ia ->onsetTime > ib->onsetTime)
|
||||||
|
return 1;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_header (int format, int ntrks, int ldivision)
|
||||||
|
{
|
||||||
|
division = ldivision;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void initfunc_for_stats()
|
void initfunc_for_stats()
|
||||||
@@ -806,6 +867,224 @@ void initfunc_for_stats()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void initfunc_for_loadNoteEvents()
|
||||||
|
{
|
||||||
|
Mf_error = error;
|
||||||
|
Mf_header = load_header;
|
||||||
|
Mf_trackstart = no_op0;
|
||||||
|
Mf_trackend = record_trackend;
|
||||||
|
Mf_noteon = record_noteon;
|
||||||
|
Mf_noteoff = record_noteoff;
|
||||||
|
Mf_pressure = no_op3;
|
||||||
|
Mf_parameter = no_op3;
|
||||||
|
Mf_pitchbend = no_op3;
|
||||||
|
Mf_program = no_op0;
|
||||||
|
Mf_chanpressure = no_op3;
|
||||||
|
Mf_sysex = no_op2;
|
||||||
|
Mf_metamisc = no_op3;
|
||||||
|
Mf_seqnum = no_op1;
|
||||||
|
Mf_eot = no_op0;
|
||||||
|
Mf_timesig = no_op4;
|
||||||
|
Mf_smpte = no_op5;
|
||||||
|
Mf_tempo = no_op1;
|
||||||
|
Mf_keysig = no_op2;
|
||||||
|
Mf_seqspecific = no_op3;
|
||||||
|
Mf_text = no_op3;
|
||||||
|
Mf_arbitrary = no_op2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dumpMidievents (int from , int to)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = from; i < to; i++) {
|
||||||
|
printf("%5d %d %d %d\n",midievents[i].onsetTime, midievents[i].channel,
|
||||||
|
midievents[i].pitch, midievents[i].velocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_finish()
|
||||||
|
{
|
||||||
|
qsort(midievents,lastEvent,sizeof(struct eventstruc),int_compare_events);
|
||||||
|
/*dumpMidievents(0,50);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void pulseHistogram() {
|
||||||
|
int i,j;
|
||||||
|
int pulsePosition;
|
||||||
|
int decimate;
|
||||||
|
float fraction;
|
||||||
|
int resolution = 12;
|
||||||
|
for (i = 0; i< 480; i++) pulseCounter[i] = 0;
|
||||||
|
for (i = 0; i < lastEvent; i++) {
|
||||||
|
pulsePosition = midievents[i].onsetTime % division;
|
||||||
|
pulseCounter[pulsePosition]++;
|
||||||
|
if (pulsePosition >= 480) {printf("pulsePosition = %d too large\n",pulsePosition);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < resolution; i++) pulseDistribution[i] = 0;
|
||||||
|
/*for (i = 0; i < 480; i++) printf(" %d",pulseCounter[i]);
|
||||||
|
printf("\n");
|
||||||
|
*/
|
||||||
|
decimate = division/resolution;
|
||||||
|
for (i = 0; i < division; i++) {
|
||||||
|
j = i/decimate;
|
||||||
|
pulseDistribution[j] += pulseCounter[i];
|
||||||
|
}
|
||||||
|
for (i = 0; i < resolution; i++)
|
||||||
|
{fraction = (float) pulseDistribution[i] / (float) lastEvent;
|
||||||
|
if (i == 0)
|
||||||
|
printf("%6.4f",fraction);
|
||||||
|
else
|
||||||
|
printf(",%6.4f",fraction);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void drumanalysis () {
|
||||||
|
int i;
|
||||||
|
int channel;
|
||||||
|
int pitch;
|
||||||
|
for (i=0;i<100;i++) drumhistogram[i] = 0;
|
||||||
|
for (i = 0; i < lastEvent; i++) {
|
||||||
|
channel = midievents[i].channel;
|
||||||
|
if (channel != 9) continue;
|
||||||
|
pitch = midievents[i].pitch;
|
||||||
|
if (pitch < 0 || pitch > 100) {
|
||||||
|
printf("illegal percussion instrument %d\n",pitch);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
drumhistogram[pitch]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drumpattern (int perc) {
|
||||||
|
int i;
|
||||||
|
int channel;
|
||||||
|
int pitch;
|
||||||
|
int onset;
|
||||||
|
int index;
|
||||||
|
int quarter;
|
||||||
|
int remainder;
|
||||||
|
int part;
|
||||||
|
quarter = division/4;
|
||||||
|
for (i = 0; i<8000; i++) drumpat[i] = 0;
|
||||||
|
for (i = 0; i <lastEvent; i++) {
|
||||||
|
channel = midievents[i].channel;
|
||||||
|
if (channel != 9) continue;
|
||||||
|
pitch = midievents[i].pitch;
|
||||||
|
if (pitch != perc) continue;
|
||||||
|
onset = midievents[i].onsetTime;
|
||||||
|
index = onset/division;
|
||||||
|
remainder = onset % division;
|
||||||
|
part = remainder/quarter;
|
||||||
|
if (index >= 8000) {printf("index too large in drumpattern\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
drumpat[index] = drumpat[index] |= 1 << part;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dualDrumPattern (int perc1, int perc2) {
|
||||||
|
int i;
|
||||||
|
int channel;
|
||||||
|
int pitch;
|
||||||
|
int onset;
|
||||||
|
int index;
|
||||||
|
int quarter;
|
||||||
|
int remainder;
|
||||||
|
int part;
|
||||||
|
quarter = division/4;
|
||||||
|
for (i = 0; i<8000; i++) drumpat[i] = 0;
|
||||||
|
for (i = 0; i <lastEvent; i++) {
|
||||||
|
channel = midievents[i].channel;
|
||||||
|
if (channel != 9) continue;
|
||||||
|
pitch = midievents[i].pitch;
|
||||||
|
if (pitch != perc1 && pitch != perc2) continue;
|
||||||
|
onset = midievents[i].onsetTime;
|
||||||
|
index = onset/division;
|
||||||
|
if (index >= 8000) {printf("index too large in drumpattern\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
remainder = onset % division;
|
||||||
|
part = remainder/quarter;
|
||||||
|
if (pitch == perc1) drumpat[index] = drumpat[index] |= 1 << part;
|
||||||
|
else drumpat[index] = drumpat[index] |= 16 * (1 << part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_perc_pattern (int i) {
|
||||||
|
int left,right;
|
||||||
|
left = i/16;
|
||||||
|
right = i % 16;
|
||||||
|
printf(" (%d.%d)",left,right);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void drumPatternHistogram () {
|
||||||
|
int i;
|
||||||
|
for (i=0;i<256;i++) {
|
||||||
|
histogram[i] = 0;
|
||||||
|
}
|
||||||
|
for (i=0;i<lastBeat;i++) {
|
||||||
|
histogram[drumpat[i]]++;
|
||||||
|
}
|
||||||
|
for (i=1;i<256;i++) {
|
||||||
|
if (histogram[i] > 0) {
|
||||||
|
printf(" %d",i);
|
||||||
|
output_perc_pattern(i);
|
||||||
|
printf(" %d ", histogram[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void output_drumpat () {
|
||||||
|
int i;
|
||||||
|
for (i=0;i<lastBeat;i++) printf("%d ",drumpat[i]);
|
||||||
|
/*for (i=0;i<lastBeat;i++) output_perc_pattern(drumpat[i]);*/
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void percsummary () {
|
||||||
|
int i;
|
||||||
|
int bassindex,snareindex;
|
||||||
|
int bassmax,snaremax;
|
||||||
|
int bassdrum[] = {35,36,41,45};
|
||||||
|
int snaredrum[] = {37,38,39,40};
|
||||||
|
bassmax = 0;
|
||||||
|
snaremax = 0;
|
||||||
|
for (i=0;i<4;i++) {
|
||||||
|
if(drumhistogram[bassdrum[i]] > bassmax) {
|
||||||
|
bassindex = bassdrum[i];
|
||||||
|
bassmax = drumhistogram[bassindex];
|
||||||
|
}
|
||||||
|
if(drumhistogram[snaredrum[i]] > snaremax) {
|
||||||
|
snareindex = snaredrum[i];
|
||||||
|
snaremax = drumhistogram[snareindex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bassmax && snaremax) {
|
||||||
|
printf("bass %d %d\n",bassindex,bassmax);
|
||||||
|
printf("snare %d %d\n",snareindex,snaremax);
|
||||||
|
} else {
|
||||||
|
printf("missing bass or snare\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dualDrumPattern(bassindex,snareindex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void corestatsOutput() {
|
||||||
|
printf("%d\t%d\t%d\n", division,lastEvent,lastBeat);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int readnum(num)
|
int readnum(num)
|
||||||
/* read a number from a string */
|
/* read a number from a string */
|
||||||
/* used for processing command line */
|
/* used for processing command line */
|
||||||
@@ -910,8 +1189,45 @@ int argc;
|
|||||||
if ((arg != -1) && (arg <argc)) {
|
if ((arg != -1) && (arg <argc)) {
|
||||||
debug = readnum(argv[arg]);
|
debug = readnum(argv[arg]);
|
||||||
}
|
}
|
||||||
|
arg = getarg("-pulseanalysis",argc,argv);
|
||||||
|
if (arg != -1) {
|
||||||
|
pulseanalysis = 1;
|
||||||
|
stats = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
arg = getarg("-corestats",argc,argv);
|
||||||
|
if (arg != -1) {
|
||||||
|
corestats = 1;
|
||||||
|
stats = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
arg = getarg("-panal",argc,argv);
|
||||||
|
if (arg != -1) {
|
||||||
|
percanalysis = 1;
|
||||||
|
stats = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
arg = getarg("-ppat",argc,argv);
|
||||||
|
if (arg != -1) {
|
||||||
|
percpattern = 1;
|
||||||
|
stats = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
arg = getarg("-ppatfor",argc,argv);
|
||||||
|
if (arg != -1) {
|
||||||
|
percpatternfor = 1;
|
||||||
|
stats = 0;
|
||||||
|
if (arg != -1 && arg <argc) {
|
||||||
|
percnum = readnum(argv[arg]);
|
||||||
|
printf("percnum = %d\n",percnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arg = getarg("-ppathist",argc,argv);
|
||||||
|
if (arg != -1) {
|
||||||
|
percpatternhist = 1;
|
||||||
|
stats = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
arg = getarg("-o",argc,argv);
|
arg = getarg("-o",argc,argv);
|
||||||
@@ -934,10 +1250,16 @@ int argc;
|
|||||||
else {
|
else {
|
||||||
printf("midistats version %s\n usage :\n",VERSION);
|
printf("midistats version %s\n usage :\n",VERSION);
|
||||||
printf("midistats filename <options>\n");
|
printf("midistats filename <options>\n");
|
||||||
|
printf(" -corestats\n");
|
||||||
|
printf(" -pulseanalysis\n");
|
||||||
|
printf(" -panal\n");
|
||||||
|
printf(" -ppat\n");
|
||||||
|
printf(" -ppatfor\n");
|
||||||
|
printf(" -ppathist\n");
|
||||||
printf(" -ver version number\n");
|
printf(" -ver version number\n");
|
||||||
printf(" -d <number> debug parameter\n");
|
printf(" -d <number> debug parameter\n");
|
||||||
printf(" The input filename is assumed to be any string not\n");
|
printf(" The input filename is assumed to be any string not\n");
|
||||||
printf(" beginning with a - (hyphen). It may be placed anywhere.\n");
|
printf(" beginning with a - (hyphen).\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
};
|
};
|
||||||
return arg;
|
return arg;
|
||||||
@@ -955,6 +1277,39 @@ mfread();
|
|||||||
stats_finish();
|
stats_finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loadEvents() {
|
||||||
|
int i;
|
||||||
|
initfunc_for_loadNoteEvents();
|
||||||
|
Mf_getc = filegetc;
|
||||||
|
maximumPulse = 0;
|
||||||
|
mfread();
|
||||||
|
lastBeat = maximumPulse/division;
|
||||||
|
load_finish();
|
||||||
|
if (pulseanalysis) pulseHistogram();
|
||||||
|
if (percanalysis) {
|
||||||
|
drumanalysis();
|
||||||
|
for (i = 0; i< 100; i++) {
|
||||||
|
if (drumhistogram[i] > 0) printf("%d %d\t",i,drumhistogram[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
if (percpattern) {
|
||||||
|
drumanalysis();
|
||||||
|
percsummary();
|
||||||
|
output_drumpat();
|
||||||
|
}
|
||||||
|
if (percpatternfor) {
|
||||||
|
drumpattern(percnum);
|
||||||
|
output_drumpat();
|
||||||
|
}
|
||||||
|
if (percpatternhist) {
|
||||||
|
drumanalysis();
|
||||||
|
percsummary();
|
||||||
|
drumPatternHistogram();
|
||||||
|
}
|
||||||
|
if (corestats) corestatsOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(argc,argv)
|
int main(argc,argv)
|
||||||
@@ -966,5 +1321,7 @@ int argc;
|
|||||||
|
|
||||||
arg = process_command_line_arguments(argc,argv);
|
arg = process_command_line_arguments(argc,argv);
|
||||||
if(stats == 1) midistats(argc,argv);
|
if(stats == 1) midistats(argc,argv);
|
||||||
|
if(pulseanalysis || corestats || percanalysis ||\
|
||||||
|
percpatternfor || percpattern || percpatternhist) loadEvents();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user