mirror of
https://github.com/sshlien/abcmidi.git
synced 2025-12-13 06:01:01 +00:00
Compare commits
3 Commits
2023.02.07
...
2023.02.20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a410e191d0 | ||
|
|
a29dc35927 | ||
|
|
5202b73bac |
@@ -15074,3 +15074,8 @@ abc2abc: in toabc.c, James Allwright has introduced a new option -c
|
||||
which replaces /2 with /. He also fixed the -h output in
|
||||
event_init() so that all options are listed.
|
||||
|
||||
|
||||
February 08 2023
|
||||
midi2abc, mftext, midistats: modified midifile.c so that it indicates where
|
||||
it encounters an unexpected byte in the input midi file.
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
abcMIDI : abc <-> MIDI conversion utilities
|
||||
|
||||
midi2abc version 3.58 December 09 2022
|
||||
midi2abc version 3.59 February 08 2023
|
||||
abc2midi version 4.84 January 06 2023
|
||||
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.58 December 09 2022
|
||||
midistats version 0.59 February 08 2023
|
||||
|
||||
24th January 2002
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
* based on public domain 'midifilelib' package.
|
||||
*/
|
||||
|
||||
#define VERSION "3.58 December 09 2022 midi2abc"
|
||||
#define VERSION "3.59 February 08 2023 midi2abc"
|
||||
|
||||
#include <limits.h>
|
||||
/* Microsoft Visual C++ Version 6.0 or higher */
|
||||
|
||||
@@ -198,6 +198,7 @@ char *s;
|
||||
int c;
|
||||
|
||||
while ( n++<4 && (c=(*Mf_getc)()) != EOF ) {
|
||||
Mf_bytesread++; /* [SS] 2023-02-08 */
|
||||
if ( c != *p++ ) {
|
||||
char buff[32];
|
||||
(void) strcpy(buff,"expecting ");
|
||||
@@ -229,7 +230,7 @@ readheader() /* read a header chunk */
|
||||
return;
|
||||
|
||||
Mf_toberead = read32bit();
|
||||
Mf_bytesread = 0;
|
||||
/* Mf_bytesread = 0; [SS] 2023-01-08 */
|
||||
format = read16bit();
|
||||
ntrks = read16bit();
|
||||
division = read16bit();
|
||||
@@ -281,7 +282,7 @@ readtrack() /* read a track chunk */
|
||||
|
||||
Mf_toberead = read32bit();
|
||||
Mf_currtime = 0;
|
||||
Mf_bytesread =0;
|
||||
/* Mf_bytesread =0; [SS] 2022.02.08 */
|
||||
|
||||
if ( Mf_trackstart )
|
||||
(*Mf_trackstart)();
|
||||
@@ -397,9 +398,9 @@ static void
|
||||
badbyte(c)
|
||||
int c;
|
||||
{
|
||||
char buff[32];
|
||||
char buff[96]; /* [SS] 2022.02.08 */
|
||||
|
||||
(void) sprintf(buff,"unexpected byte: 0x%02x",c);
|
||||
(void) sprintf(buff,"unexpected byte: 0x%02x at byte %ld (0x%lX)",c,Mf_bytesread,Mf_bytesread);
|
||||
mferror(buff);
|
||||
}
|
||||
|
||||
|
||||
151
midistats.c
151
midistats.c
@@ -18,7 +18,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#define VERSION "0.58 December 08 2022 midistats"
|
||||
#define VERSION "0.60 February 20 2023 midistats"
|
||||
|
||||
#include <limits.h>
|
||||
/* Microsoft Visual C++ Version 6.0 or higher */
|
||||
@@ -72,17 +72,29 @@ int trackno;
|
||||
int maintrack;
|
||||
int format; /* MIDI file type */
|
||||
int debug;
|
||||
int pulseanalysis;
|
||||
int corestats;
|
||||
int chordthreshold; /* number of maximum number of pulses separating note */
|
||||
int beatsPerBar = 4; /* 4/4 time */
|
||||
int divisionsPerBar;
|
||||
int unitDivision;
|
||||
|
||||
|
||||
struct eventstruc {int onsetTime;
|
||||
unsigned char channel;
|
||||
unsigned char pitch;
|
||||
unsigned char velocity;
|
||||
;} midievents[20000];
|
||||
|
||||
int lastEvent = 0;
|
||||
|
||||
|
||||
int tempocount=0; /* number of tempo indications in MIDI file */
|
||||
|
||||
int stats = 0; /* flag - gather and print statistics */
|
||||
|
||||
int pulseanalysis = 0;
|
||||
int corestats = 0;
|
||||
|
||||
|
||||
/* can cope with up to 64 track MIDI files */
|
||||
@@ -159,6 +171,8 @@ static int progmapper[] = {
|
||||
16, 16, 16, 16, 16, 16, 16, 16
|
||||
};
|
||||
|
||||
int pulseCounter[480];
|
||||
int pulseDistribution[24];
|
||||
|
||||
struct barPattern {
|
||||
int activeBarNumber;
|
||||
@@ -776,7 +790,40 @@ int nn, dd, cc, bb;
|
||||
printf("timesig %d/%d %6.2f\n",nn,denom,beatnumber);
|
||||
}
|
||||
|
||||
void record_noteon(int chan,int pitch,int vol)
|
||||
{
|
||||
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 > 19999) {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()
|
||||
@@ -806,6 +853,84 @@ 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;
|
||||
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 < 24; i++) pulseDistribution[i] = 0;
|
||||
/*for (i = 0; i < 480; i++) printf(" %d",pulseCounter[i]);
|
||||
printf("\n");
|
||||
*/
|
||||
decimate = division/24;
|
||||
for (i = 0; i < division; i++) {
|
||||
j = i/decimate;
|
||||
pulseDistribution[j] += pulseCounter[i];
|
||||
}
|
||||
for (i = 0; i < 24; i++)
|
||||
{fraction = (float) pulseDistribution[i] / (float) lastEvent;
|
||||
printf(" %8.4f",fraction);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
}
|
||||
|
||||
void corestatsOutput() {
|
||||
printf("%d\t%d\n", division,lastEvent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int readnum(num)
|
||||
/* read a number from a string */
|
||||
/* used for processing command line */
|
||||
@@ -910,9 +1035,17 @@ int argc;
|
||||
if ((arg != -1) && (arg <argc)) {
|
||||
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("-o",argc,argv);
|
||||
if ((arg != -1) && (arg < argc)) {
|
||||
@@ -934,6 +1067,8 @@ int argc;
|
||||
else {
|
||||
printf("midistats version %s\n usage :\n",VERSION);
|
||||
printf("midistats filename <options>\n");
|
||||
printf(" -corestats\n");
|
||||
printf(" -pulseanalysis\n");
|
||||
printf(" -ver version number\n");
|
||||
printf(" -d <number> debug parameter\n");
|
||||
printf(" The input filename is assumed to be any string not\n");
|
||||
@@ -955,6 +1090,15 @@ mfread();
|
||||
stats_finish();
|
||||
}
|
||||
|
||||
void loadEvents() {
|
||||
initfunc_for_loadNoteEvents();
|
||||
Mf_getc = filegetc;
|
||||
mfread();
|
||||
load_finish();
|
||||
if (pulseanalysis) pulseHistogram();
|
||||
if (corestats) corestatsOutput();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(argc,argv)
|
||||
@@ -966,5 +1110,6 @@ int argc;
|
||||
|
||||
arg = process_command_line_arguments(argc,argv);
|
||||
if(stats == 1) midistats(argc,argv);
|
||||
if(pulseanalysis || corestats) loadEvents();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user