From 13c93c3d74e7908f6ada1dcda3bbb3d8bf341452 Mon Sep 17 00:00:00 2001 From: sshlien Date: Sun, 9 Jun 2024 08:52:14 -0400 Subject: [PATCH] 2024.06.09 --- VERSION | 2 +- doc/readme.txt | 2 +- midifile.c | 6 +++++- midistats.c | 23 ++++++++++++++++------- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/VERSION b/VERSION index 1c67ef6..1382145 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -June 03 2024 +June 06 2024 diff --git a/doc/readme.txt b/doc/readme.txt index 039670b..c90c711 100644 --- a/doc/readme.txt +++ b/doc/readme.txt @@ -6,7 +6,7 @@ abc2abc version 2.22 April 30 2024 yaps version 1.94 April 30 2024 abcmatch version 1.83 February 19 2024 midicopy version 1.39 November 08 2022 -midistats version 0.92 June 03 2024 +midistats version 0.93 June 06 2024 24th January 2002 Copyright James Allwright diff --git a/midifile.c b/midifile.c index 3747ecf..bfed68d 100644 --- a/midifile.c +++ b/midifile.c @@ -415,8 +415,12 @@ int type; m = msg(); switch ( type ) { case 0x00: - if ( Mf_seqnum ) + if ( Mf_seqnum ) { + if (leng < 1) {printf("Error: zero length meta seqnumber\n"); + exit(1); + } (*Mf_seqnum)(to16bit(m[0],m[1])); + } break; case 0x01: /* Text event */ case 0x02: /* Copyright notice */ diff --git a/midistats.c b/midistats.c index 1544348..c764a6f 100644 --- a/midistats.c +++ b/midistats.c @@ -17,7 +17,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#define VERSION "0.92 June 03 2024 midistats" +#define VERSION "0.93 June 07 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 @@ -245,7 +245,7 @@ static int progmapper[] = { 16, 16, 16, 16, 16, 16, 16, 16 }; -int pulseCounter[1024]; +int pulseCounter[2048]; int pulseDistribution[24]; struct barPattern { @@ -463,6 +463,14 @@ void stats_header (int format, int ntrks, int ldivision) { int i; division = ldivision; + if(division < 12) { + printf("Error: division (PPQN) is too small\n"); + exit(1); + } + if(ntrks > 40) { + printf("Error: too many tracks = %d\n",ntrks); + exit(1); + } halfdivision = ldivision/2; quietLimit = ldivision*8; divisionsPerBar = division*beatsPerBar; @@ -532,6 +540,7 @@ threshold = 10.0/(float) division; maxcount = 0; ncounts = 0; npeaks = 0; +if (division > 2047) return; /* PPQN is too large for pulseCounter */ for (i=0;i maxcount) { @@ -903,10 +912,10 @@ int chan, pitch, vol; return; } pulsePosition = Mf_currtime % division; - pulseCounter[pulsePosition]++; - if (pulsePosition >= 1023) {printf("pulsePosition = %d too large\n",pulsePosition); + if (pulsePosition >= 2047) {printf("Error: pulsePosition = %d too large\n",pulsePosition); exit(1); } + pulseCounter[pulsePosition]++; 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); @@ -1183,7 +1192,7 @@ void initfunc_for_stats() Mf_seqspecific = no_op3; Mf_text = stats_metatext; Mf_arbitrary = no_op2; - for (i = 0; i< 1023; i++) pulseCounter[i] = 0; + for (i = 0; i< 2047; i++) pulseCounter[i] = 0; } @@ -1235,11 +1244,11 @@ int pulsePosition; int decimate; float fraction; int resolution = 12; -for (i = 0; i< 1023; i++) pulseCounter[i] = 0; +for (i = 0; i< 2047; i++) pulseCounter[i] = 0; for (i = 0; i < lastEvent; i++) { pulsePosition = midievents[i].onsetTime % division; pulseCounter[pulsePosition]++; - if (pulsePosition >= 1023) {printf("pulsePosition = %d too large\n",pulsePosition); + if (pulsePosition > 2047) {printf("pulsePosition = %d too large\n",pulsePosition); exit(1); } }