New upstream version 20171215
Ross Gammon
6 years ago
12521 | 12521 | w: line and call preparse_words(). |
12522 | 12522 | |
12523 | 12523 | |
12524 | November 01 2017 November 08 2017 November 10 2017 | |
12524 | November 01 2017 November 08 2017 November 10 2017 November 19 2017 | |
12525 | 12525 | |
12526 | 12526 | Midi2abc: minor enhancement for -stats function. |
12527 | 12527 | |
12528 | ||
12529 | November 27 2017 | |
12530 | Midicopy: introducing new options -focusontracks n1,n2,... and | |
12531 | -focusonchannel n1,n2.... This attenuates the velocity values of the | |
12532 | notes in all tracks (channels) except except n1,n2,... by the | |
12533 | attenuation (default 70) units. The attenuation can be specified | |
12534 | by -attenuation n. | |
12535 | ||
12536 | December 06 2017 | |
12537 | Midicopy: added an option -xchns to exclude specific channels. | |
12538 | ||
12539 | ||
12540 | December 10 2017 | |
12541 | Abc2midi: abc2midi now implements the command | |
12542 | %%abc-include per.abc | |
12543 | where per.abc is typically a header file which defines various | |
12544 | global parameters. For example, the file could remap the channel | |
12545 | pitches to particular percussion instruments using the %%MIDI drummap | |
12546 | command. | |
12547 | ||
12548 | Implementation: in genmidi.c the function parse_drummap() is no longer | |
12549 | static so it can be called in store.c. In store.c, the command | |
12550 | %%MIDI drummap is recoginized in the function event_specific_in_header(). | |
12551 | The function init_drummap, is no longer activated in the function | |
12552 | finishfile(), but only once in the main() function. This means that, | |
12553 | the %%MIDI drummap command will apply to all the tunes in the file, | |
12554 | irrespective of whether it is in the header (global) area. Finally, | |
12555 | parsefile() in parseabc.c has been extended to recognize the | |
12556 | abc-include file. All the contents of this include file are parsed | |
12557 | as if the lines were included in the open abc file, except that the | |
12558 | line counters do not count the lines in the include file. The | |
12559 | extension to parseabc.c also impacts abc2abc, yaps, and abcmatch. | |
12560 | ||
12561 | December 15 2017 | |
12562 | Midicopy: added -nobends option. | |
12563 | ||
12564 |
3 | 3 | .SH SYNOPSIS |
4 | 4 | \fBmidicopy\fP [\fB-ver\fP] [\fB-trks\fP \fIn1,n2,..\fP]\ |
5 | 5 | [\fB-xtrks\fP \fIn1,n2,..\fP]\ |
6 | [\fB-xchns\fP \fIn1,n2,..\fP]\ | |
6 | 7 | [\fB-chans\fP \fIn1,n2,...\fP]\ |
7 | 8 | [\fB-from\fP \fIn (in midi ticks)\fP] [\fB-to\fP \fIn (in midi ticks)\fP]\ |
8 | 9 | [\fB-fromsec %f\fP \fIn (in seconds)\fP] [\fB-tosec\fP \fIn (in seconds)\fP]\ |
9 | [\fB-frombeat %f\fP \fIn (in beats)\fP] [\fB-tosec\fP \fIn (in beats)\fP]\ | |
10 | [\fB-frombeat %f\fP \fIn (in beats)\fP] [\fB-tobeat\fP \fIn (in beats)\fP]\ | |
10 | 11 | [\fB-replace\fP \fItrk,loc,val\fP] [\fB-tempo %n\fP] [\fB-speed %f\fP]\ |
11 | 12 | [\fB-drumfocus\fP \fIn \fIm\fP] [\fB-mutenodrum [%d]\fP]\ |
12 | 13 | [\fB-setdrumloudness\fP \fIn \fIm\fP]\ |
14 | [\fB-focusontrack\fP \fIn1,n2,... (from 1)\fP]\ | |
15 | [\fB-focusonchannel\fP \fIn1,n2,... (from 1)\fP]\ | |
16 | [\fB-attenuation\fP \fIn\fP]\ | |
17 | [\fB-nobends\fP]\ | |
13 | 18 | \fIinput.mid output.mid\fP |
14 | 19 | .SH "DESCRIPTION" |
15 | 20 | .PP |
37 | 42 | .B -xtrks n1,n2, etc |
38 | 43 | Lists the tracks to exclude from copying. All other tracks are copied. |
39 | 44 | This option does not work in combination with \-trks. |
45 | .TP | |
46 | .B -xchns n1,n2, etc | |
47 | Lists the channels to exclude from copying. All other channels are copied. | |
48 | This option does not work in combination with \-chns. | |
40 | 49 | .TP |
41 | 50 | .B -chns n |
42 | 51 | Like above, it specifies the MIDI channels to be copied. By default |
103 | 112 | where n is between 35 to 81 inclusive and m is the loudness between |
104 | 113 | 0 and 127. The loudness of all instances of drum n are changed |
105 | 114 | to m. |
115 | .TP | |
116 | .B -focusontrack n1,n2,... | |
117 | The velocities of notes in all tracks except n are attenuated. | |
118 | .TP | |
119 | .B -focusonchannel n1,n2,... | |
120 | The velocities of notes in all channels except n are attenuated. | |
121 | .TP | |
122 | .B -attenuation n | |
123 | Specifies the amount the note velocities are reduced by either | |
124 | -focusontracks or -focusonchannels. Current default is 70. | |
125 | .TP | |
126 | .B -nobends | |
127 | Suppresses all channel pitchbend commands. | |
106 | 128 | |
107 | 129 | .SH EXAMPLE |
108 | 130 | .B midicopy.exe -trks 1,5 -from 2669 -to 8634 uzicko.mid fragment.mid |
115 | 137 | .SH AUTHOR |
116 | 138 | This manual page was written by Seymour Shlien. |
117 | 139 | .SH VERSION |
118 | This man page describes midicopy version 1.20 from October 28 2013. | |
140 | This man page describes midicopy version 1.30 from December 15 2017. |
0 | 0 | abcMIDI : abc <-> MIDI conversion utilities |
1 | 1 | |
2 | midi2abc version 3.14 November 10 2017 | |
3 | abc2midi version 4.00 October 23 2017 | |
2 | midi2abc version 3.16 November 26 2017 | |
3 | abc2midi version 4.01 December 10 2017 | |
4 | 4 | abc2abc version 1.97 October 11 2017 |
5 | yaps version 1.69 October 23 2017 | |
5 | yaps version 1.70 November 17 2017 | |
6 | 6 | abcmatch version 1.71 April 19 2017 |
7 | midicopy version 1.26 October 22 2017 | |
7 | midicopy version 1.30 December 15 2017 | |
8 | 8 | |
9 | 9 | 24th January 2002 |
10 | 10 | |
418 | 418 | midicopy copies selected tracks, channels, time interval of the input midi file.options: |
419 | 419 | -ver version information |
420 | 420 | -trks n1,n2,..(starting from 1) |
421 | -xtrks n1,n2,... (tracks to exclude) | |
422 | -xchns n1,n2,... (channels to exclude) | |
421 | 423 | -chns n1,n2,..(starting from 1) |
422 | 424 | -from n (in midi ticks) |
423 | 425 | -to n (in midi ticks) |
426 | -fromsec %f (in seconds) | |
427 | -tosec %f (in seconds) | |
428 | -frombeat %f | |
429 | -tobeat %f | |
424 | 430 | -replace trk,loc,val |
431 | -tempo n (in quarter notes/min) | |
432 | -speed %f (between 0.1 and 10.0) | |
433 | -drumfocus n (35 - 81) m (0 - 127) | |
434 | -mutenodrum [level] | |
435 | -setdrumloudness n (35-81) m (0 -127) | |
436 | -focusontrack n1,n2,... | |
437 | -focusonchannel n1,n2,... | |
438 | -attenuation n | |
439 | ||
425 | 440 | |
426 | 441 | midicopy.exe -ver |
427 | 442 | |
428 | 443 | will print out something like |
429 | 1.00 July 11 2004 | |
444 | 1.29 December 06 2017 | |
430 | 445 | |
431 | 446 | |
432 | 447 | midicopy.exe input.mid output.mid |
444 | 459 | |
445 | 460 | If you include the -to command followed by a midi pulse number, the |
446 | 461 | midi file is truncated beyond that point, so that when you play the file |
447 | it will stop at this point. | |
448 | ||
449 | If you have selected a time interval using the -from or -to parameters | |
450 | (or both), then the program will print out the estimated duration of | |
451 | the output midi file. | |
462 | it will stop at this point. You can also specify the window using beats | |
463 | with the options -frombeats and -tobeats. The program will print out | |
464 | the estimated duration of the output midi file. | |
452 | 465 | |
453 | 466 | All the tracks will be copied unless you specify them in the list following |
454 | 467 | keyword -trks. You start counting tracks from 1. |
455 | 468 | |
456 | 469 | Similarly, all channels will be copied unless you specify them following |
457 | 470 | keyword -chns. You start counting channels from 1. |
471 | ||
472 | The -xchns and -xtrk options will exclude the indicated channels or | |
473 | tracks from the output midi file. The -xchns does not work together | |
474 | with -chns and neither does -xtrks work with -trks. (Use one or the | |
475 | other.) | |
458 | 476 | |
459 | 477 | The option -replace allows you to overwrite a specific byte given its |
460 | 478 | track number and offset loc, by the byte whose value is val. This is |
462 | 480 | is replaced in the output file. If you use the -replace option, all |
463 | 481 | other options like -from, -to, -chns etc. are ignored. |
464 | 482 | |
483 | The embedded tempo commands can be replaced using | |
484 | -tempo n | |
485 | in units beats/minute. | |
486 | ||
487 | -speed f | |
488 | where f is a decimal number between 0.1 and 10.0 will multiply | |
489 | the current tempo by this factor. | |
490 | ||
491 | -drumfocus will accentuate the specified drum (35 to 81) to level | |
492 | m (0 to 127). | |
493 | ||
494 | -focusontracks will attenuate all tracks except those specified. | |
495 | ||
496 | -focusonchannels will attenuate all channels except those specified. | |
497 | ||
498 | -attenuation specifies the amount to reduce the note velocities | |
499 | for the focus options. | |
465 | 500 | |
466 | 501 | ------------------------------------------------------------------------- |
467 | 502 | abcmatch.exe - see abcmatch.txt |
1161 | 1161 | event_error("Internal error: beam with 0 notes"); |
1162 | 1162 | showtune(&thetune); |
1163 | 1163 | return; |
1164 | exit(0); | |
1164 | /* exit(0); [SS] 2017-11-17 */ | |
1165 | 1165 | }; |
1166 | 1166 | if (beamset[0]->type != NOTE) { |
1167 | 1167 | event_error("Internal error: beam does not start with NOTE"); |
63 | 63 | } |
64 | 64 | |
65 | 65 | void setbeat(); |
66 | static void parse_drummap(char **s); | |
66 | void parse_drummap(char **s); /* [SS] 2017-12-10 no more static */ | |
67 | 67 | |
68 | 68 | /* global variables grouped roughly by function */ |
69 | 69 | |
2518 | 2518 | drum_map[i] = i; |
2519 | 2519 | } |
2520 | 2520 | |
2521 | static void parse_drummap(char **s) | |
2521 | void parse_drummap(char **s) | |
2522 | 2522 | /* parse abc note and advance character pointer */ |
2523 | 2523 | /* code stolen from parseabc.c and simplified */ |
2524 | /* [SS] 2017-12-10 no more 'static voice parse_drummap' */ | |
2524 | 2525 | { |
2525 | 2526 | int mult; |
2526 | 2527 | char accidental, note; |
130 | 130 | } |
131 | 131 | |
132 | 132 | |
133 | void txt_pitchbend(chan,msb,lsb) | |
133 | /* [SS] 2017-11-16 submitted by Jonathan Hough (msb,lsb interchanged) */ | |
134 | void txt_pitchbend(chan,lsb,msb) | |
134 | 135 | int chan, msb, lsb; |
135 | 136 | { |
136 | 137 | prtime(); |
137 | printf("Pitchbend, chan=%d msb=%d lsb=%d\n",chan+1,msb,lsb); | |
138 | printf("Pitchbend, chan=%d lsb=%d msb=%d\n",chan+1,msb,lsb); | |
138 | 139 | } |
139 | 140 | |
140 | 141 | void txt_program(chan,program) |
45 | 45 | * based on public domain 'midifilelib' package. |
46 | 46 | */ |
47 | 47 | |
48 | #define VERSION "3.14 November 10 2017" | |
48 | #define VERSION "3.16 November 23 2017" | |
49 | 49 | #define SPLITCODE |
50 | 50 | |
51 | 51 | /* Microsoft Visual C++ Version 6.0 or higher */ |
78 | 78 | #define MIDDLE 72 |
79 | 79 | void initfuncs(); |
80 | 80 | void setupkey(int); |
81 | void stats_finish(); | |
81 | 82 | int testtrack(int trackno, int barbeats, int anacrusis); |
82 | 83 | int open_note(int chan, int pitch, int vol); |
83 | 84 | int close_note(int chan, int pitch, int *initvol); |
104 | 105 | int symbol[256]; /*translation tables for MIDI pitch to abc note */ |
105 | 106 | int key[12]; |
106 | 107 | int sharps; |
107 | int trackno, maintrack; | |
108 | int trackno; | |
109 | int maintrack; | |
108 | 110 | int format; /* MIDI file type */ |
109 | 111 | |
110 | 112 | int karaoke, inkaraoke; |
488 | 490 | return(f); |
489 | 491 | } |
490 | 492 | |
491 | ||
492 | 493 | void error(s) |
493 | 494 | char *s; |
494 | 495 | { |
495 | 496 | fprintf(stderr,"Error: %s\n",s); |
497 | } | |
498 | ||
499 | ||
500 | /* [SS] 2017-11-19 */ | |
501 | void stats_error(s) | |
502 | char *s; | |
503 | { | |
504 | fprintf(stderr,"Error: %s\n",s); | |
505 | fprintf(stderr,"activetrack %d\n",tracknum); | |
506 | stats_finish(); | |
496 | 507 | } |
497 | 508 | |
498 | 509 | |
989 | 1000 | int p; |
990 | 1001 | |
991 | 1002 | for (i=1;i<17;i++) { |
1003 | /* skip drum channel 10 */ | |
1004 | if (i == 10) continue; | |
992 | 1005 | if (channel2nnotes[i] > 0) { |
993 | 1006 | p = channel2prog[i]; |
1007 | if (p == -1) p =0; /* missing program for channel */ | |
994 | 1008 | if (p >=0 && p < 128) |
995 | progcolor[progmapper[channel2prog[i]]] += channel2nnotes[i]; | |
1009 | progcolor[progmapper[p]] += channel2nnotes[i]; | |
996 | 1010 | } |
997 | 1011 | } |
998 | 1012 | |
1499 | 1513 | |
1500 | 1514 | void initfunc_for_stats() |
1501 | 1515 | { |
1502 | Mf_error = error; | |
1516 | Mf_error = stats_error; /* [SS] 2017-11-19 */ | |
1503 | 1517 | Mf_header = stats_header; |
1504 | 1518 | Mf_trackstart = stats_trackstart; |
1505 | 1519 | Mf_trackend = stats_trackend; |
48 | 48 | |
49 | 49 | |
50 | 50 | |
51 | #define VERSION "1.26 October 22 2017" | |
51 | #define VERSION "1.30 December 15 2017" | |
52 | 52 | #include "midicopy.h" |
53 | 53 | #define NULLFUNC 0 |
54 | 54 | #define NULL 0 |
106 | 106 | int mutenodrum = 0; /* [SS] 2013-09-15 */ |
107 | 107 | int chosen_drum = 0; /* [SS] 2013-10-01 */ |
108 | 108 | int drumvelocity = 0; /* [SS] 2013-10-01 */ |
109 | int attenuation = 70; /* [SS] 2017-11-27 */ | |
110 | int nobends = 0; /* [SS] 2017-12-15 */ | |
109 | 111 | |
110 | 112 | long Mf_numbyteswritten = 0L; |
111 | 113 | long readvarinum (); |
132 | 134 | int notechan[2048]; /* keeps track of running voices */ |
133 | 135 | int tocopy[32]; /* tracks to copy */ |
134 | 136 | int ctocopy[16]; /* channels to copy */ |
137 | int tfocus[32]; /* track focus 2017-11 27*/ | |
138 | int cfocus[16]; /* channel focus 2017-11-27*/ | |
135 | 139 | int chnflag = 0; /* flag indicating not all channels selected */ |
136 | 140 | int verbatim = 1; /* flag for verbatim transfer */ |
137 | 141 | int haschannel[17]; /* for determining which channels are in use */ |
142 | int hastempo[32]; /* indicates whether tempo command in track */ | |
138 | 143 | |
139 | 144 | FILE *F_in, *fp; |
140 | 145 | int format, ntrks, division; |
945 | 950 | copy_metaeot (); |
946 | 951 | break; |
947 | 952 | case 0x51: /* Set tempo */ |
953 | hastempo[activetrack] = 1; /* [SS] 2017-12-14 */ | |
948 | 954 | if (newtempo > 0) /* [SS] 2013-09-04 */ |
949 | 955 | mf_write_tempo (newtempo); |
950 | 956 | else if (newspeed) |
1010 | 1016 | c2 = nondrumlevel; /*[SS] 2013-09-15 */ |
1011 | 1017 | if (chan == 9 && chosen_drum != 0 && c1 == chosen_drum) |
1012 | 1018 | c2 = drumvelocity; /* [SS] 2013-10-01 */ |
1019 | if (cfocus[chan] == 1) { /* [SS] 2017-11-27 */ | |
1020 | c2 = c2 - attenuation; | |
1021 | if (c2 <0) c2 = 0; | |
1022 | } | |
1023 | if (tfocus[activetrack] == 1) { /* [SS] 2017-11-27 */ | |
1024 | c2 = c2 - attenuation; | |
1025 | if (c2 <0) c2 = 0; | |
1026 | } | |
1013 | 1027 | copy_noteon (chan, c1, c2); |
1014 | 1028 | break; |
1015 | 1029 | case 0xa0: |
1019 | 1033 | copy_parameter (chan, c1, c2); |
1020 | 1034 | break; |
1021 | 1035 | case 0xe0: |
1022 | copy_pitchbend (chan, c1, c2); | |
1036 | if (nobends == 0) | |
1037 | copy_pitchbend (chan, c1, c2); | |
1023 | 1038 | break; |
1024 | 1039 | case 0xc0: |
1025 | 1040 | copy_program (chan, c1); |
1272 | 1287 | if (tocopy[i] == 1) |
1273 | 1288 | /*list_channels_in_use(i); */ |
1274 | 1289 | /* [SS] 2017-10-19] don't copy redundant tracks */ |
1290 | /* [SS] 2017-12-24 but make sure tracks with tempo is copied */ | |
1275 | 1291 | for (j=0;j<16;j++) { |
1276 | if(ctocopy[j] == 1 && haschannel[j] == 1) { | |
1292 | if((ctocopy[j] == 1 && haschannel[j] == 1) || hastempo[i]) { | |
1277 | 1293 | /* printf("writing track %d\n",i); */ |
1278 | 1294 | mf_write_track_chunk (i, fp); |
1279 | 1295 | break; /* only write the track once */ |
1740 | 1756 | int trk[16], mtrks; |
1741 | 1757 | int chn[16], chns; |
1742 | 1758 | int xtrks; /* [SS] 2013-10-28 */ |
1759 | int xchns; /* [SS] 2017-12-06 */ | |
1743 | 1760 | int i; |
1744 | 1761 | int byteloc, trknum; |
1745 | 1762 | int repflag; |
1753 | 1770 | tocopy[i] = 1; |
1754 | 1771 | for (i = 0; i < 16; i++) |
1755 | 1772 | ctocopy[i] = 1; |
1773 | for (i=0;i<32;i++) tfocus[i] = 0; /* [SS] 2017-11-27 */ | |
1774 | for (i=0;i<16;i++) cfocus[i] = 0; /* [SS] 2017-11-27 */ | |
1775 | for (i=0;i<32;i++) hastempo[i] = 0; /* [SS] 2017-12-14 */ | |
1756 | 1776 | mtrks = 0; |
1757 | 1777 | xtrks = 0; |
1758 | 1778 | chns = 0; |
1779 | xchns = 0; | |
1759 | 1780 | start_tick = -1; |
1760 | 1781 | end_tick = -1; |
1761 | 1782 | start_seconds = -1.0; |
1779 | 1800 | printf ("options:\n"); |
1780 | 1801 | printf ("-ver version information\n"); |
1781 | 1802 | printf ("-trks n1,n2,..(starting from 1)\n"); |
1782 | printf ("-xtrks n1,n2, (tracks to exclude)\n"); /* [SS] 2013-10-27 */ | |
1803 | printf ("-xtrks n1,n2,.. (tracks to exclude)\n"); /* [SS] 2013-10-27 */ | |
1804 | printf ("-xchns n1,n2,.. (tracks to exclude)\n"); /* [SS] 2017-12-06 */ | |
1783 | 1805 | printf ("-chns n1,n2,..(starting from 1)\n"); |
1784 | 1806 | printf ("-from n (in midi ticks)\n"); |
1785 | 1807 | printf ("-to n (in midi ticks)\n"); |
1793 | 1815 | printf ("-drumfocus n (35 - 81) m (0 - 127)\n"); /* [SS] 2013-09-07 */ |
1794 | 1816 | printf ("-mutenodrum [level] \n"); /* [SS] 2013-09-15 */ |
1795 | 1817 | printf ("-setdrumloudness n (35-81) m (0 -127)\n"); /* [SS] 2013-10-01 */ |
1818 | printf ("-focusontracks n1,n2,... \n"); /* [SS] 2017-11-27 */ | |
1819 | printf ("-focusonchannels n1,n2,...\n"); /* [SS] 2017-11-27 */ | |
1820 | printf ("-attenuation n\n"); /* [SS] 2017-11-27 */ | |
1821 | printf ("-nobends\n"); /* [SS] 2017-11-27 */ | |
1796 | 1822 | exit (1); |
1797 | 1823 | } |
1798 | 1824 | |
1803 | 1829 | */ |
1804 | 1830 | arg = getarg ("-trks", argc, argv); |
1805 | 1831 | if (arg >= 0) |
1806 | mtrks = sscanf (argv[arg], "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", | |
1832 | mtrks = sscanf (argv[arg], "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", | |
1807 | 1833 | &trk[0], &trk[1], &trk[2], &trk[3], &trk[4], |
1808 | 1834 | &trk[5], &trk[6], &trk[7], &trk[8], &trk[9], &trk[10], |
1809 | &trk[11]); | |
1835 | &trk[11],&trk[12],&trk[13]); | |
1810 | 1836 | if (mtrks > 0) |
1811 | 1837 | { |
1812 | 1838 | /* printf("%d tracks specified\n", mtrks); */ |
1833 | 1859 | tocopy[trk[i] - 1] = 0; |
1834 | 1860 | } |
1835 | 1861 | |
1862 | arg = getarg("-xchns",argc,argv); /* [SS] 2017-12-06 */ | |
1863 | if (arg >= 0) | |
1864 | xchns = sscanf (argv[arg], "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", | |
1865 | &chn[0], &chn[1], &chn[2], &chn[3], &chn[4], &chn[5], | |
1866 | &chn[6], &chn[7], &chn[8], &chn[9], &chn[10], &chn[11], | |
1867 | &chn[12],&chn[13]); | |
1868 | if (xchns > 0) | |
1869 | { | |
1870 | for (i = 0; i < 16; i++) | |
1871 | ctocopy[i] = 1; | |
1872 | for (i = 0; i < xchns; i++) | |
1873 | if (chn[i] > 0 && chn[i] < 17) | |
1874 | ctocopy[chn[i] - 1] = 0; | |
1875 | chnflag = 1; | |
1876 | verbatim = 0; | |
1877 | } | |
1878 | ||
1836 | 1879 | arg = getarg ("-chns", argc, argv); |
1837 | 1880 | if (arg >= 0) |
1838 | chns = sscanf (argv[arg], "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", | |
1881 | chns = sscanf (argv[arg], "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", | |
1839 | 1882 | &chn[0], &chn[1], &chn[2], &chn[3], &chn[4], &chn[5], |
1840 | &chn[6], &chn[7], &chn[8], &chn[9], &chn[10], &chn[11]); | |
1883 | &chn[6], &chn[7], &chn[8], &chn[9], &chn[10], &chn[11], | |
1884 | &chn[12],&chn[13]); | |
1841 | 1885 | if (chns > 0) |
1842 | 1886 | { |
1843 | 1887 | for (i = 0; i < 16; i++) |
1848 | 1892 | chnflag = 1; |
1849 | 1893 | verbatim = 0; |
1850 | 1894 | } |
1895 | ||
1851 | 1896 | arg = getarg ("-from", argc, argv); |
1852 | 1897 | if (arg >= 0) |
1853 | 1898 | { |
1967 | 2012 | } |
1968 | 2013 | } |
1969 | 2014 | |
2015 | /* [SS] 2017-11-27 */ | |
2016 | mtrks = 0; | |
2017 | arg = getarg("-focusontracks",argc,argv); | |
2018 | if (arg >= 0) | |
2019 | { | |
2020 | verbatim = 0; | |
2021 | mtrks = sscanf (argv[arg], "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", | |
2022 | &trk[0], &trk[1], &trk[2], &trk[3], &trk[4], | |
2023 | &trk[5], &trk[6], &trk[7], &trk[8], &trk[9], &trk[10], | |
2024 | &trk[11]); | |
2025 | if (mtrks > 0) | |
2026 | { | |
2027 | /* printf("%d tracks specified\n", mtrks); */ | |
2028 | for (i = 0; i < 32; i++) | |
2029 | tfocus[i] = 1; /* attenuation flag */ | |
2030 | for (i = 0; i < mtrks; i++) { | |
2031 | if (trk[i] < 32 && trk[i] >= 0) | |
2032 | tfocus[trk[i]-1] = 0; /* track numbers start from 1*/ | |
2033 | } | |
2034 | } | |
2035 | } | |
2036 | ||
2037 | /* [SS] 2017-11-27 */ | |
2038 | arg = getarg("-focusonchannels",argc,argv); | |
2039 | if (arg >=0) { | |
2040 | chns = sscanf (argv[arg], "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", | |
2041 | &chn[0], &chn[1], &chn[2], &chn[3], &chn[4], &chn[5], | |
2042 | &chn[6], &chn[7], &chn[8], &chn[9], &chn[10], &chn[11]); | |
2043 | if (chns > 0) | |
2044 | { | |
2045 | verbatim = 0; | |
2046 | for (i = 0; i < 16; i++) | |
2047 | cfocus[i] = 1; /* attenuation flag */ | |
2048 | for (i = 0; i < chns; i++) | |
2049 | if (chn[i] > 0 && chn[i] < 17) | |
2050 | cfocus[chn[i] - 1] = 0; /* channel numbers start from 1 */ | |
2051 | } | |
2052 | } | |
2053 | ||
2054 | arg = getarg("-attenuation",argc,argv); | |
2055 | if (arg >= 0) | |
2056 | sscanf (argv[arg], "%d", &attenuation); | |
2057 | ||
2058 | arg = getarg("-nobends",argc,argv); | |
2059 | if (arg >=0) nobends=1; | |
1970 | 2060 | |
1971 | 2061 | |
1972 | 2062 | repflag = getarg ("-replace", argc, argv); |
1767 | 1767 | char *p; |
1768 | 1768 | int success; |
1769 | 1769 | |
1770 | success = sscanf (s, "%%abc-version %s", &abcversion); /* [SS] 2014-08-11 */ | |
1770 | success = sscanf (s, "%%%%abc-version %3s", abcversion); /* [SS] 2014-08-11 */ | |
1771 | 1771 | if (*s == '%') |
1772 | 1772 | { |
1773 | 1773 | p = s + 1; |
1779 | 1779 | event_comment (s); |
1780 | 1780 | }; |
1781 | 1781 | } |
1782 | ||
1783 | /* [SS] 2017-12-10 */ | |
1784 | FILE * parse_abc_include (s) | |
1785 | char *s; | |
1786 | { | |
1787 | char includefilename[80]; | |
1788 | FILE *includehandle; | |
1789 | int success; | |
1790 | success = sscanf (s, "%%%%abc-include %80s", includefilename); /* [SS] 2014-08-11 */ | |
1791 | if (success == 1) { | |
1792 | /* printf("opening include file %s\n",includefilename); */ | |
1793 | includehandle = fopen(includefilename,"r"); | |
1794 | if (includehandle == NULL) | |
1795 | { | |
1796 | printf ("Failed to open include file %s\n", includefilename); | |
1797 | }; | |
1798 | return includehandle; | |
1799 | } | |
1800 | return NULL; | |
1801 | } | |
1802 | ||
1782 | 1803 | |
1783 | 1804 | void |
1784 | 1805 | parse_tempo (place) |
2734 | 2755 | handle_abc2midi_parser (line); /* [SS] 2017-04-12 */ |
2735 | 2756 | if (ignore_line == 1) return; /* [SS] 2017-04-12 */ |
2736 | 2757 | |
2737 | /*printf("%d parsing : %s\n", lineno, line); */ | |
2758 | /*printf("%d parsing : %s\n", lineno, line);*/ | |
2738 | 2759 | strncpy (inputline, line, sizeof inputline); /* [SS] 2011-06-07 [PHDM] 2012-11-27 */ |
2739 | 2760 | |
2740 | 2761 | p = line; |
2832 | 2853 | parsefile (name) |
2833 | 2854 | char *name; |
2834 | 2855 | /* top-level routine for parsing file */ |
2856 | /* [SS] 2017-12-10 In order to allow including the directive | |
2857 | "%%abc-include includefile.abc" to insert the includedfile.abc, | |
2858 | we switch the file handle fp to link to the includefile.abc and switch | |
2859 | back to the original file handle when we reach the end of file | |
2860 | of includefile.abc. Thus we keep track of the original handle | |
2861 | using fp_last. | |
2862 | */ | |
2835 | 2863 | { |
2836 | 2864 | FILE *fp; |
2865 | FILE *fp_last,*fp_include; /* [SS] 2017-12-10 */ | |
2837 | 2866 | int reading; |
2838 | 2867 | int fileline; |
2868 | int last_position; | |
2839 | 2869 | struct vstring line; |
2840 | 2870 | /* char line[MAXLINE]; */ |
2841 | 2871 | int t; |
2842 | 2872 | int lastch, done_eol; |
2873 | int err; | |
2874 | ||
2875 | fp_last = NULL; /* [SS] 2017-12-10 */ | |
2843 | 2876 | |
2844 | 2877 | /* printf("parsefile called %s\n", name); */ |
2845 | 2878 | /* The following code permits abc2midi to read abc from stdin */ |
2879 | 2912 | if (parsing) |
2880 | 2913 | event_linebreak (); |
2881 | 2914 | }; |
2915 | if (fp_last != NULL) { /* [SS] 2017-12-10 */ | |
2916 | fclose(fp); | |
2917 | fp = fp_last; | |
2918 | err = fseek(fp,last_position,SEEK_SET); | |
2919 | /*printf("fseek return err = %d\n",err);*/ | |
2920 | reading = 1; | |
2921 | fp_last = NULL; | |
2922 | } | |
2882 | 2923 | } |
2883 | 2924 | else |
2884 | 2925 | { |
2899 | 2940 | } |
2900 | 2941 | else |
2901 | 2942 | { |
2902 | /* reached end of line */ | |
2903 | parseline (line.st); | |
2904 | clearvstring (&line); | |
2905 | fileline = fileline + 1; | |
2906 | lineno = fileline; | |
2907 | if (parsing) | |
2908 | event_linebreak (); | |
2909 | done_eol = 1; | |
2943 | /* reached end of line */ | |
2944 | fp_include = parse_abc_include (line.st);/* [SS] 2017-12-10 */ | |
2945 | if (fp_include == NULL) { | |
2946 | parseline (line.st); | |
2947 | clearvstring (&line); | |
2948 | if (fp_last == NULL) { | |
2949 | fileline = fileline + 1; | |
2950 | lineno = fileline; | |
2951 | } | |
2952 | if (parsing) | |
2953 | event_linebreak (); | |
2954 | done_eol = 1; | |
2955 | } else { | |
2956 | if (fp_last == NULL) { | |
2957 | last_position = ftell(fp); | |
2958 | /*printf("last position = %d\n",last_position);*/ | |
2959 | fp_last = fp; | |
2960 | fp = fp_include; | |
2961 | if (parsing) | |
2962 | event_linebreak (); | |
2963 | done_eol = 1; | |
2964 | clearvstring (&line); | |
2965 | } else { | |
2966 | event_error ("Not allowed to recurse include file"); | |
2967 | } | |
2968 | } | |
2910 | 2969 | }; |
2911 | 2970 | }; |
2912 | 2971 | lastch = t; |
183 | 183 | |
184 | 184 | */ |
185 | 185 | |
186 | #define VERSION "4.00 October 23 2017 abc2midi" | |
186 | #define VERSION "4.01 December 10 2017 abc2midi" | |
187 | 187 | |
188 | 188 | /* enables reading V: indication in header */ |
189 | 189 | #define XTEN1 1 |
288 | 288 | void init_p48toc53 (); /* [SS] 2014-01-12 */ |
289 | 289 | void convert_to_comma53 (char acc, int *midipitch, int* midibend); |
290 | 290 | void recurse_back_to_original_voice (); /* [SS] 2014-03-26 */ |
291 | void parse_drummap(char **s); /* [SS] 2017-12-10 */ | |
291 | 292 | |
292 | 293 | |
293 | 294 | struct voicecontext { |
2515 | 2516 | velocitychange = readnump(&p); |
2516 | 2517 | done = 1; |
2517 | 2518 | } |
2519 | ||
2520 | if (strcmp(command,"drummap") == 0) { /* [SS] 2017-12-10 */ | |
2521 | skipspace(&p); | |
2522 | parse_drummap(&p); | |
2523 | done = 1; | |
2524 | } | |
2525 | ||
2518 | 2526 | |
2519 | 2527 | if (done == 0) { |
2520 | 2528 | event_warning("cannot handle this MIDI directive in file header"); |
5827 | 5835 | /* dump_voicecontexts(); for debugging*/ |
5828 | 5836 | setup_trackstructure(); |
5829 | 5837 | clearvoicecontexts(); |
5830 | init_drum_map(); | |
5838 | /* init_drum_map(); [SS] 2017-12-10 moved to main() */ | |
5831 | 5839 | if (!pastheader) { |
5832 | 5840 | event_error("No valid K: field found at start of tune"); |
5833 | 5841 | } else { |
6007 | 6015 | /* printf("argc = %d\n", argc); */ |
6008 | 6016 | } else { |
6009 | 6017 | init_abbreviations(); |
6018 | init_drum_map(); /* [SS] 2017-12-10 */ | |
6010 | 6019 | if (!silent) printf("%s\n",VERSION); /* [SS] 2015-07-15 */ |
6011 | 6020 | parsefile(filename); |
6012 | 6021 | free_abbreviations(); |