mirror of
https://github.com/sshlien/abcmidi.git
synced 2025-12-06 15:05:07 +00:00
Compare commits
3 Commits
2023.05.30
...
2023.08.31
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48c443fabd | ||
|
|
3f405a1aba | ||
|
|
5534c8935d |
18
doc/CHANGES
18
doc/CHANGES
@@ -15085,4 +15085,22 @@ More functions for the percussion track was added to midistats.c to
|
||||
support some future analysis.
|
||||
|
||||
|
||||
June 25 2023
|
||||
Midistats runs incorrectly if the midi file has no program channel
|
||||
commands. When a program channel command is missing, the program should
|
||||
be the acoutic piano (0) by default.
|
||||
|
||||
If more than one channel with the same program color, they should be
|
||||
added together.
|
||||
|
||||
|
||||
August 22 2023
|
||||
|
||||
Midistats improved the calculation of the number of rhythm patterns
|
||||
in a channel (barChn[chan].rhythmPattern) by allowing for dithering
|
||||
of note onset. Introduced dithermargin variable in function
|
||||
stats_noteon(). In function, output_track_summary(), suppressed
|
||||
notemeanpitch for percussion channel.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,10 @@ the sum of the note durations in MIDI pulse units,
|
||||
the number of control parameter messages,
|
||||
the number of pressure messages.
|
||||
and the number of distinct rhythm patterns for each channel
|
||||
the minimum pitch value
|
||||
the maximum pitch value
|
||||
the minimum note length in pulses
|
||||
the maximum note length in pulses
|
||||
.PP
|
||||
After processing all the individual tracks, the following information
|
||||
applies to the entire midi file.
|
||||
|
||||
@@ -6,20 +6,18 @@ abc2abc version 2.20 February 07 2023
|
||||
yaps version 1.92 January 06 2023
|
||||
abcmatch version 1.82 June 14 2022
|
||||
midicopy version 1.38 May 06 2022
|
||||
midistats version 0.59 February 08 2023
|
||||
midistats version 0.72 August 31 2023
|
||||
|
||||
24th January 2002
|
||||
|
||||
Copyright James Allwright
|
||||
J.R.Allwright@westminster.ac.uk
|
||||
jamesallwright@yahoo.co.uk
|
||||
University of Westminster,
|
||||
London, UK
|
||||
|
||||
October 2021
|
||||
|
||||
Seymour Shlien
|
||||
Ottawa, Canada
|
||||
August 2023
|
||||
Copyright Seymour Shlien
|
||||
fy733@ncf.ca
|
||||
Ottawa, Canada
|
||||
|
||||
This is free software. You may copy and re-distribute it under the terms of
|
||||
the GNU General Public License version 2 or later, which is available from
|
||||
|
||||
62
midistats.c
62
midistats.c
@@ -18,7 +18,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#define VERSION "0.69 May 27 2023 midistats"
|
||||
#define VERSION "0.72 August 31 2023 midistats"
|
||||
|
||||
#include <limits.h>
|
||||
/* Microsoft Visual C++ Version 6.0 or higher */
|
||||
@@ -52,7 +52,8 @@ void stats_finish();
|
||||
float histogram_entropy (int *histogram, int size);
|
||||
void stats_noteoff(int chan,int pitch,int vol);
|
||||
void stats_eot ();
|
||||
|
||||
#define max(a,b) (( a > b ? a : b))
|
||||
#define min(a,b) (( a < b ? a : b))
|
||||
|
||||
/* Global variables and structures */
|
||||
|
||||
@@ -114,8 +115,9 @@ int trackcount = 0;
|
||||
|
||||
int notechan[2048],notechanvol[2048]; /*for linking on and off midi
|
||||
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 channel_active[17]; /* for dealing with chords [SS] 2023-08-30 */
|
||||
|
||||
int histogram[256];
|
||||
unsigned char drumpat[8000];
|
||||
@@ -131,7 +133,11 @@ struct trkstat {
|
||||
int notecount[17];
|
||||
int chordcount[17];
|
||||
int notemeanpitch[17];
|
||||
int notepitchmin[17];
|
||||
int notepitchmax[17];
|
||||
int notelength[17];
|
||||
int notelengthmin[17];
|
||||
int notelengthmax[17];
|
||||
int pitchbend[17];
|
||||
int pressure[17];
|
||||
int cntlparam[17];
|
||||
@@ -420,7 +426,7 @@ void stats_header (int format, int ntrks, int ldivision)
|
||||
trkdata.pressure[i] = 0; /* [SS] 2022-03-04 */
|
||||
trkdata.quietTime[i] = 0; /* [SS] 2022-08-22 */
|
||||
progcolor[i] = 0;
|
||||
channel2prog[i] = -1;
|
||||
channel2prog[i] = 0; /* [SS] 2023-06-25-8/
|
||||
channel2nnotes[i] = 0;
|
||||
chnactivity[i] = 0; /* [SS] 2018-02-02 */
|
||||
}
|
||||
@@ -483,7 +489,7 @@ if (nprogs > 0) output_progs_data();
|
||||
else {
|
||||
for (i=0;i<17;i++)
|
||||
if(chnactivity[i] > 0)
|
||||
progactivity[channel2prog[i]] = chnactivity[i];
|
||||
progactivity[channel2prog[i]] += chnactivity[i]; /* [SS] 2023-06-25 */
|
||||
output_progs_data();
|
||||
}
|
||||
|
||||
@@ -584,9 +590,15 @@ for (i=1;i<17;i++) {
|
||||
printf("trkinfo ");
|
||||
printf("%d %d ",i,trkdata.program[i]); /* channel number and program*/
|
||||
printf("%d %d ",trkdata.notecount[i],trkdata.chordcount[i]);
|
||||
printf("%d %d ",trkdata.notemeanpitch[i], trkdata.notelength[i]);
|
||||
/* [SS] 2023-08-22 */
|
||||
if (i != 10) printf("%d %d ",trkdata.notemeanpitch[i], trkdata.notelength[i]);
|
||||
else
|
||||
printf("-1 0 ");
|
||||
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]);
|
||||
if (i != 10) printf("%d %d %d %d",trkdata.notepitchmin[i], trkdata.notepitchmax[i] ,trkdata.notelengthmin[i], trkdata.notelengthmax[i]);
|
||||
else
|
||||
printf("-1 0");
|
||||
trkdata.quietTime[i] = 0;
|
||||
printf("\n");
|
||||
|
||||
@@ -604,13 +616,19 @@ void stats_trackstart()
|
||||
for (i=0;i<17;i++) {
|
||||
trkdata.notecount[i] = 0;
|
||||
trkdata.notemeanpitch[i] = 0;
|
||||
trkdata.notepitchmin[i] = 128;
|
||||
trkdata.notepitchmax[i] = 0;
|
||||
trkdata.notelength[i] = 0;
|
||||
trkdata.notelengthmin[i] = 10000;
|
||||
trkdata.notelengthmax[i] = 0;
|
||||
trkdata.chordcount[i] = 0;
|
||||
trkdata.cntlparam[i] = 0;
|
||||
last_tick[i] = -1;
|
||||
last_on_tick[i] = -1;
|
||||
channel_active[i] = 0;
|
||||
}
|
||||
printf("trk %d \n",tracknum);
|
||||
|
||||
for (i=0;i<2048;i++) lastTick[i] = -1;
|
||||
}
|
||||
|
||||
void stats_trackend()
|
||||
@@ -628,7 +646,9 @@ int chan, pitch, vol;
|
||||
int delta;
|
||||
int barnum;
|
||||
int unit;
|
||||
int dithermargin; /* [SS] 2023-08-22 */
|
||||
|
||||
dithermargin = unitDivision/2 - 1;
|
||||
if (vol == 0) {
|
||||
/* treat as noteoff */
|
||||
stats_noteoff(chan,pitch,vol);
|
||||
@@ -636,6 +656,8 @@ int chan, pitch, vol;
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
delta = Mf_currtime - trkdata.lastNoteOff[chan+1];
|
||||
trkdata.lastNoteOff[chan+1] = -1; /* in case of chord */
|
||||
@@ -646,7 +668,7 @@ int chan, pitch, vol;
|
||||
|
||||
if (abs(Mf_currtime - last_on_tick[chan+1]) < chordthreshold) trkdata.chordcount[chan+1]++;
|
||||
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 not updated by stats_noteoff */
|
||||
|
||||
@@ -661,7 +683,7 @@ int chan, pitch, vol;
|
||||
barChn[chan].rhythmPattern = 0;
|
||||
barChn[chan].activeBarNumber = barnum;
|
||||
}
|
||||
unit = (Mf_currtime % divisionsPerBar)/unitDivision;
|
||||
unit = ((Mf_currtime+dithermargin) % divisionsPerBar)/unitDivision;
|
||||
//printf("unit = %d pattern = %d \n",unit,barChn[chan].rhythmPattern);
|
||||
barChn[chan].rhythmPattern = barChn[chan].rhythmPattern |= (1UL << unit);
|
||||
}
|
||||
@@ -674,6 +696,8 @@ int chan, pitch, vol;
|
||||
else drumhistogram[pitch]++;
|
||||
}
|
||||
else pitchhistogram[pitch % 12]++; /* [SS] 2017-11-01 */
|
||||
|
||||
channel_active[chan+1]++;
|
||||
}
|
||||
|
||||
|
||||
@@ -686,17 +710,27 @@ void stats_noteoff(int chan,int pitch,int vol)
|
||||
int length;
|
||||
int program;
|
||||
/* ignore if there was no noteon */
|
||||
if (last_tick[chan+1] == -1) return;
|
||||
length = Mf_currtime - last_tick[chan+1];
|
||||
if (lastTick[chan*128+pitch] == -1) return;
|
||||
length = Mf_currtime - lastTick[chan*128+pitch];
|
||||
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 */
|
||||
chnactivity[chan+1] += length;
|
||||
if (chan == 9) return; /* drum channel */
|
||||
pitchclass_activity[pitch % 12] += length;
|
||||
program = trkdata.program[chan+1];
|
||||
progactivity[program] += length;
|
||||
channel_active[chan+1]--;
|
||||
/* [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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -730,7 +764,7 @@ if (trkdata.program[chan+1] != 0) {
|
||||
printf("program %d %d\n",chan+1,program);
|
||||
trkdata.program[chan+1] = program;
|
||||
}
|
||||
if (channel2prog[chan+1]== -1) channel2prog[chan+1] = program;
|
||||
if (channel2prog[chan+1]== 0) channel2prog[chan+1] = program; /* [SS] 2023-06-25*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user