-
Notifications
You must be signed in to change notification settings - Fork 15
/
matchsup.c
2015 lines (1788 loc) · 45.1 KB
/
matchsup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
matchsup.c (abcmatch support functions)
Seymour Shlien
* originally store.c
* abc2midi - program to convert abc files to MIDI files.
* Copyright (C) 1999 James Allwright
* e-mail: [email protected]
store.c was adapted for the purpose of analyzing the contents
of abc tunes. The code is much the same except many functions
related to the generation of midi files has been trimmed off.
In particular: links to the code in genmidi.c and queue.c are gone.
All the gchord stuff is removed. There are options to suppress
all warning and error messages. Certain variables are no longer
extern's (parts, partno, bar_num, global_transpose etc.).
Output file generation stuff is gone. A new variable xrefno is
added to pass the reference number to abcmatch. Event_init has
been moved to the main program abcmatch.c and maxnotes has
been raised to 3000 since there seems to be a problem with
the autoextend procedure. Some DEBUG statements were
added to addfeature - (they can probably be removed). Support
for text features and comments are gone. All the karaoke stuff
is gone. Tempo stuff, slurs, grace notes, decorations, hornpipe
indications are all ignored. Event_note was changed to ignore
trills and rolls. When a [chord] is included, only the highest
note is extracted from the chord. For debugging, a new function
print_feature_list was introduced.etc.
Essentially for comparing abc files, we want to ignore repeats,
grace notes, staccato indications and midi indications. We are
only interested in comparing the tunes. The main output
which is used is the feature[],pitch,num[],denom[] list which
is used by abcmatch to create a new representation of the abc
file.
Some abc files with interleaved voices will not be treated
propertly with this program. In general parts, repeats and
voice indications are ignored.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
#define XTEN1 1
#include "abc.h"
#include "parseabc.h"
#include "parser2.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef WIN32
#include <string.h> /* [gjg] 2012-02-01 Visual C++ 2010 Express compatability */
#endif
#ifdef __MWERKS__
#define __MACINTOSH__ 1
#endif /* __MWERKS__ */
#ifdef __MACINTOSH__
int setOutFileCreator(char *fileName,unsigned long theType,
unsigned long theCreator);
#endif /* __MACINTOSH__ */
/* define USE_INDEX if your C libraries have index() instead of strchr() */
#ifdef USE_INDEX
#define strchr index
#endif
#ifdef ANSILIBS
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#else
extern char* strchr();
extern void reduce();
#endif
#define MAXLINE 500
#define INITTEXTS 20
#define INITWORDS 20
#define MAXCHANS 16
/*#define DEBUG*/
/* global variables grouped roughly by function */
FILE *fp;
programname fileprogram = ABCMATCH;
/* parsing stage */
int tuplecount, tfact_num, tfact_denom, tnote_num, tnote_denom;
int specialtuple;
int gracenotes;
int headerpartlabel;
int dotune, pastheader;
int hornpipe, last_num, last_denom;
int timesigset;
int retain_accidentals;
int ratio_a, ratio_b;
int foundtitle; /* flag for capturing on the first title */
struct voicecontext {
/* maps of accidentals for each stave line */
char basemap[7], workmap[7];
int basemul[7], workmul[7];
int default_length;
int voiceno;
int indexno;
int hasgchords;
int haswords;
int inslur;
int ingrace;
int octaveshift;
/* chord handling */
int inchord, chordcount;
int chord_num, chord_denom;
/* details of last 2 notes/chords to apply length-modifiers to */
int laststart, lastend, thisstart, thisend;
/* broken rythm handling */
int brokentype, brokenmult, brokenpending;
int broken_stack[7];
struct voicecontext* next;
};
struct voicecontext global;
struct voicecontext* v;
struct voicecontext* head;
int voicecount;
/* storage structure for strings */
int maxtexts = INITTEXTS;
char** atext;
int ntexts = 0;
int note_unit_length=8;
/* general purpose storage structure */
int maxnotes;
int *pitch, *num, *denom;
featuretype *feature;
int *pitchline;
int notes;
int verbose = 0;
int nowarn=1;
int noerror=1;
int xmatch;
int sf, mi;
/* Part handling */
struct vstring part;
int parts, partno, partlabel;
int part_start[26], part_count[26];
int voicesused;
/* Tempo handling (Q: field) */
int time_num, time_denom;
long tempo;
int tempo_num, tempo_denom;
int relative_tempo, Qtempo;
extern int division;
extern int div_factor;
/* output file generation */
int check;
int ntracks;
/* bar length checking */
int bar_num, bar_denom;
int barchecking;
int beat;
/* generating MIDI output */
int middle_c;
extern int channels[MAXCHANS + 3];
int global_transpose;
int additive;
int gfact_num, gfact_denom;
/* karaoke handling */
int karaoke, wcount;
char** words;
int maxwords = INITWORDS;
int xrefno;
extern int intune; /* signals to parsetune that tune is finished */
extern char titlename[48]; /* stores title of tune */
extern char keysignature[16];
/* Many of these functions have been retained in order to link with parseabc.
As I have been forced to also modifiy parseabc, now called abcparse, these
functions can also be removed eventually.
*/
char *featname[] = {
"SINGLE_BAR", "DOUBLE_BAR", "BAR_REP", "REP_BAR",
"PLAY_ON_REP", "REP1", "REP2", "BAR1",
"REP_BAR2", "DOUBLE_REP", "THICK_THIN", "THIN_THICK",
"PART", "TEMPO", "TIME", "KEY",
"REST", "TUPLE", "NOTE", "NONOTE",
"OLDTIE", "TEXT", "SLUR_ON", "SLUR_OFF",
"TIE", "CLOSE_TIE", "TITLE", "CHANNEL",
"TRANSPOSE", "RTRANSPOSE", "GTRANSPOSE", "GRACEON",
"GRACEOFF", "SETGRACE", "SETC", "SETTRIM", "GCHORD",
"GCHORDON", "GCHORDOFF", "VOICE", "CHORDON",
"CHORDOFF", "CHORDOFFEX", "DRUMON", "DRUMOFF",
"DRONEON", "DRONEOFF", "SLUR_TIE", "TNOTE",
"LT", "GT", "DYNAMIC", "LINENUM",
"MUSICLINE", "MUSICSTOP", "WORDLINE", "WORDSTOP",
"INSTRUCTION", "NOBEAM", "CHORDNOTE", "CLEF",
"PRINTLINE", "NEWPAGE", "LEFT_TEXT", "CENTRE_TEXT",
"VSKIP", "COPYRIGHT", "COMPOSER", "ARPEGGIO",
"SPLITVOICE", "META", "PEDAL_ON", "PEDAL_OFF", "EFFECT"
};
void event_info (place)
char * place;
{
}
void event_gchord (chord)
char * chord;
{
}
void event_slur (t)
int t;
{
}
void event_instruction (s)
char *s;
{
}
void event_reserved (p)
char p;
{
}
int bar_num, bar_denom, barno, barsize;
int b_num,b_denom;
void reduce(a, b)
/* elimate common factors in fraction a/b */
int *a, *b;
{
int sign;
int t, n, m;
if (*a < 0) {
sign = -1;
*a = -*a;
} else {
sign = 1;
};
/* find HCF using Euclid's algorithm */
if (*a > *b) {
n = *a;
m = *b;
} else {
n = *b;
m = *a;
};
while (m != 0) {
t = n % m;
n = m;
m = t;
};
*a = (*a/n)*sign;
*b = *b/n;
}
void addunits(a, b)
/* add a/b to the count of units in the bar */
int a, b;
{
bar_num = bar_num*(b*b_denom) + (a*b_num)*bar_denom;
bar_denom = bar_denom * (b*b_denom);
reduce(&bar_num, &bar_denom);
}
void set_meter(n, m)
/* set up variables associated with meter */
int n, m;
{
/* set up barsize */
barsize = n;
if (barsize % 3 == 0) {
beat = 3;
} else {
if (barsize % 2 == 0) {
beat = 2;
} else {
beat = barsize;
};
};
/* correction factor to make sure we count in the right units */
if (m > 4) {
b_num = m/4;
b_denom = 1;
} else {
b_num = 1;
b_denom = 4/m;
};
}
int dummydecorator[DECSIZE]; /* used in event_chord */
static struct voicecontext* newvoice(n)
/* allocate and initialize the data for a new voice */
int n;
{
struct voicecontext *s;
int i;
s = (struct voicecontext*) checkmalloc(sizeof(struct voicecontext));
voicecount = voicecount + 1;
s->voiceno = n;
s->indexno = voicecount;
s->default_length = global.default_length;
s->hasgchords = 0;
s->haswords = 0;
s->inslur = 0;
s->ingrace = 0;
s->inchord = 0;
s->chordcount = 0;
s->laststart = -1;
s->lastend = -1;
s->thisstart = -1;
s->thisend = -1;
s->brokenpending = -1;
s->next = NULL;
for (i=0; i<7; i++) {
s->basemap[i] = global.basemap[i];
s->basemul[i] = global.basemul[i];
s->workmap[i] = global.workmap[i];
s->workmul[i] = global.workmul[i];
};
s->octaveshift = global.octaveshift;
return(s);
}
static struct voicecontext* getvoicecontext(n)
/* find the data structure for a given voice number */
int n;
{
struct voicecontext *p;
struct voicecontext *q;
p = head;
q = NULL;
while ((p != NULL) && (p->voiceno != n)) {
q = p;
p = p->next;
};
if (p == NULL) {
p = newvoice(n);
if (q != NULL) {
q->next = p;
};
};
if (head == NULL) {
head = p;
};
return(p);
}
static void clearvoicecontexts()
/* free up all the memory allocated to voices */
{
struct voicecontext *p;
struct voicecontext *q;
p = head;
while (p != NULL) {
q = p->next;
free(p);
p = q;
};
head = NULL;
}
void event_text(s)
/* text found in abc file */
char *s;
{
}
void event_specific (package, s)
char *package, *s;
{
}
void event_x_reserved(p)
/* reserved character H-Z found in abc file */
char p;
{
}
void event_abbreviation(symbol, string, container)
/* abbreviation encountered - this is handled within the parser */
char symbol;
char *string;
char container;
{
}
void event_acciaccatura()
{
/* does nothing here but outputs a / in abc2abc */
return;
}
/* [SS] 2015-03-23 */
void event_start_extended_overlay()
{
event_error("extended overlay not implemented in abcmatch");
}
void event_stop_extended_overlay()
{
event_error("extended overlay not implemented in abcmatch");
}
void event_split_voice()
{
}
void event_tex(s)
/* TeX command found - ignore it */
char *s;
{
}
void event_fatal_error(s)
/* print error message and halt */
char *s;
{
event_error(s);
exit(1);
}
void event_error(s)
/* generic error handler */
char *s;
{
if (noerror) return;
#ifdef NOFTELL
extern int nullpass;
if (nullpass != 1) {
printf("Error in line %d : %s\n", lineno, s);
};
#else
printf("Error in line %d : %s\n", lineno, s);
#endif
}
void event_warning(s)
/* generic warning handler - for flagging possible errors */
char *s;
{
if (nowarn) return;
#ifdef NOFTELL
extern int nullpass;
if (nullpass != 1) {
printf("Warning in line %d : %s\n", lineno, s);
};
#else
printf("Warning in line %d : %s\n", lineno, s);
#endif
}
static int autoextend(maxnotes)
/* increase the number of abc elements the program can cope with */
int maxnotes;
{
int newlimit;
int *ptr;
featuretype *fptr;
int i;
if (verbose) {
event_warning("Extending note capacity");
};
newlimit = maxnotes*2;
fptr = (featuretype*) checkmalloc(newlimit*sizeof(featuretype));
for(i=0;i<maxnotes;i++){
fptr[i] = feature[i];
};
free(feature);
feature = fptr;
ptr = checkmalloc(newlimit*sizeof(int));
for(i=0;i<maxnotes;i++){
ptr[i] = pitch[i];
};
free(pitch);
pitch = ptr;
ptr = checkmalloc(newlimit*sizeof(int));
for(i=0;i<maxnotes;i++){
ptr[i] = pitchline[i];
};
free(pitchline);
pitchline = ptr;
ptr = checkmalloc(newlimit*sizeof(int));
for(i=0;i<maxnotes;i++){
ptr[i] = num[i];
};
free(num);
num = ptr;
ptr = checkmalloc(newlimit*sizeof(int));
for(i=0;i<maxnotes;i++){
ptr[i] = denom[i];
};
free(denom);
denom = ptr;
return(newlimit);
}
static void addfeature(f, p, n, d)
/* place feature in internal table */
int f, p, n, d;
{
feature[notes] = f;
pitch[notes] = p;
num[notes] = n;
denom[notes] = d;
if ((f == NOTE) || (f == REST) || (f == CHORDOFF)) {
reduce(&num[notes], &denom[notes]);
};
#ifdef DEBUG
if ((f == NOTE) || (f == REST)) {
float fract = (float) num[notes]/ (float) denom[notes]; /* [gjg] 2012-02-01 */
int length = fract * 12.0 +0.1; /* [gjg] 2012-02-01 */
printf("%2d %2d %2d %2d\n",pitch[notes],num[notes],denom[notes],length);
}
if (f == TIME) printf("time signature = %d/%d\n",n,d);
#endif
notes = notes + 1;
if (notes >= maxnotes) {
maxnotes = autoextend(maxnotes);
};
}
void event_linebreak()
/* reached end of line in abc */
{
addfeature(LINENUM, lineno, 0, 0);
}
void event_startmusicline()
/* starting to parse line of abc music */
{
addfeature(MUSICLINE, 0, 0, 0);
}
void event_endmusicline(endchar)
/* finished parsing line of abc music */
char endchar;
{
addfeature(MUSICSTOP, 0, 0, 0);
}
static void textfeature(type, s)
/* called while parsing abc - stores an item which requires an */
/* associared string */
int type;
char* s;
{
}
void event_comment(s)
/* comment found in abc */
char *s;
{
}
void event_startinline()
/* start of in-line field in abc music line */
{
}
void event_closeinline()
/* end of in-line field in abc music line */
{
}
void event_field(k, f)
/* Handles R: T: and any other field not handled elsewhere */
char k;
char *f;
{
if (dotune) {
switch (k) {
case 'R':
{
char* p;
p = f;
skipspace(&p);
/******** if ((strncmp(p, "Hornpipe", 8) == 0) ||
(strncmp(p, "hornpipe", 8) == 0)) {
hornpipe = 1;
};
********/
};
break;
case 'T':
if (foundtitle == 0) strncpy(titlename,f,46);
foundtitle = 1; /* [SS] 2014-01-01 */
break;
default:
{
};
};
};
}
void event_words(p, continuation)
/* handles a w: field in the abc */
char* p;
int continuation;
{
}
/* [SS] 2014-08-16 */
void appendfield (morewords)
char *morewords;
{
printf("appendfield not implemented here\n");
}
static void checkbreak()
/* check that we are in not in chord, grace notes or tuple */
/* called at voice change */
{
if (tuplecount != 0) {
event_error("Previous voice has an unfinished tuple");
tuplecount = 0;
};
if (v->inchord != 0) {
event_error("Previous voice has incomplete chord");
event_chordoff(1,1);
};
if (v->ingrace != 0) {
event_error("Previous voice has unfinished grace notes");
v->ingrace = 0;
};
}
static void read_spec(spec, part)
/* converts a P: field to a list of part labels */
/* e.g. P:A(AB)3(CD)2 becomes P:AABABABCDCD */
/* A '+' indicates 'additive' behaviour (a part may include repeats). */
/* A '-' indicates 'non-additive' behaviour (repeat marks in the music */
/* are ignored and only repeats implied by the part order statement */
/* are played). */
char spec[];
struct vstring* part;
{
}
void event_part(s)
/* handles a P: field in the abc */
char* s;
{
char* p;
if (dotune) {
p = s;
skipspace(&p);
if (pastheader) {
if (((int)*p < 'A') || ((int)*p > 'Z')) {
event_error("Part must be one of A-Z");
return;
};
if ((headerpartlabel == 1) && (part.st[0] == *p)) {
/* P: field in header is not a label */
headerpartlabel = 0;
/* remove speculative part label */
feature[part_start[(int)*p - (int)'A']] = NONOTE;
} else {
if (part_start[(int)*p - (int)'A'] != -1) {
event_error("Part defined more than once");
};
};
part_start[(int)*p - (int)'A'] = notes;
addfeature(PART, (int)*p, 0, 0);
checkbreak();
v = getvoicecontext(1);
} else {
parts = 0;
read_spec(p, &part);
if (parts == 1) {
/* might be a label not a specificaton */
headerpartlabel = 1;
};
};
};
}
void event_octave(int, int);
void event_voice(n, s, vp)
/* handles a V: field in the abc */
int n;
char *s;
struct voice_params *vp;
{
if (pastheader || XTEN1) {
voicesused = 1;
if (pastheader) checkbreak();
v = getvoicecontext(n);
addfeature(VOICE, v->indexno, 0, 0);
if (vp->gotoctave) {
event_octave(vp->octave,1);
};
if (vp->gottranspose) {
addfeature(TRANSPOSE, vp->transpose, 0, 0);
};
} else {
event_warning("V: in header ignored");
};
}
void event_length(n)
/* handles an L: field in the abc */
int n;
{
note_unit_length = 8;
if (pastheader) {
v->default_length = n;
} else {
global.default_length = n;
};
}
static void tempounits(t_num, t_denom)
/* interprets Q: once default length is known */
int *t_num, *t_denom;
{
}
void event_tempo(n, a, b, rel, pre, post)
/* handles a Q: field e.g. Q: a/b = n or Q: Ca/b = n */
/* strings before and after are ignored */
int n;
int a, b, rel;
char *pre;
char *post;
{
}
void event_timesig(n, m, dochecking)
/* handles an M: field M:n/m */
int n, m, dochecking;
{
if (dotune) {
if (pastheader) {
addfeature(TIME, dochecking, n, m);
} else {
time_num = n;
time_denom = m;
timesigset = 1;
barchecking = dochecking;
};
};
}
void event_octave(num, local)
/* used internally by other routines when octave=N is encountered */
/* in I: or K: fields */
int num;
{
if (dotune) {
if (pastheader || local) {
v->octaveshift = num;
} else {
global.octaveshift = num;
};
};
}
void event_info_key(key, value)
char* key;
char* value;
{
int num;
if (strcmp(key, "octave")==0) {
num = readsnumf(value);
event_octave(num,0);
};
}
static void stack_broken(v)
struct voicecontext* v;
{
v->broken_stack[0] = v->laststart;
v->broken_stack[1] = v->lastend;
v->broken_stack[2] = v->thisstart;
v->broken_stack[3] = v->thisend;
v->broken_stack[4] = v->brokentype;
v->broken_stack[5] = v->brokenmult;
v->broken_stack[6] = v->brokenpending;
v->laststart = -1;
v->lastend = -1;
v->thisstart = -1;
v->thisend = -1;
v->brokenpending = -1;
}
static void restore_broken(v)
struct voicecontext* v;
{
if (v->brokenpending != -1) {
event_error("Unresolved broken rhythm in grace notes");
};
v->laststart = v->broken_stack[0];
v->lastend = v->broken_stack[1];
v->thisstart = v->broken_stack[2];
v->thisend = v->broken_stack[3];
v->brokentype = v->broken_stack[4];
v->brokenmult = v->broken_stack[5];
v->brokenpending = v->broken_stack[6];
}
void event_graceon()
/* a { in the abc */
{
if (gracenotes) {
event_error("Nested grace notes not allowed");
} else {
if (v->inchord) {
event_error("Grace notes not allowed in chord");
} else {
gracenotes = 1;
addfeature(GRACEON, 0, 0, 0);
v->ingrace = 1;
stack_broken(v);
};
};
}
void event_graceoff()
/* a } in the abc */
{
if (!gracenotes) {
event_error("} without matching {");
} else {
gracenotes = 0;
addfeature(GRACEOFF, 0, 0, 0);
v->ingrace = 0;
restore_broken(v);
};
}
void event_rep1()
/* [1 in the abc */
{
addfeature(PLAY_ON_REP, 0, 0, 1);
/*
if ((notes == 0) || (feature[notes-1] != SINGLE_BAR)) {
event_error("[1 must follow a single bar");
} else {
feature[notes-1] = BAR1;
};
*/
}
void event_rep2()
/* [2 in the abc */
{
addfeature(PLAY_ON_REP, 0, 0, 2);
/*
if ((notes == 0) || (feature[notes-1] != REP_BAR)) {
event_error("[2 must follow a :| ");
} else {
feature[notes-1] = REP_BAR2;
};
*/
}
void event_playonrep(s)
char* s;
/* [X in the abc, where X is a list of numbers */
{
int num, converted;
char seps[2];
converted = sscanf(s, "%d%1[,-]", &num, seps);
if (converted == 0) {
event_error("corrupted variant ending");
} else {
if ((converted == 1) && (num != 0)) {
addfeature(PLAY_ON_REP, 0, 0, num);
} else {
textfeature(PLAY_ON_REP, s);
};
};
}
static void slurtotie()
/* converts a pair of identical slurred notes to tied notes */
{
}
void event_sluron(t)
/* called when ( is encountered in the abc */
int t;
{
if (t == 1) {
addfeature(SLUR_ON, 0, 0, 0);
v->inslur = 1;
};
}
void event_sluroff(t)
/* called when ) is encountered */
int t;
{
if (t == 0) {
slurtotie();
addfeature(SLUR_OFF, 0, 0, 0);
v->inslur = 0;
};
}
void event_tie()
/* a tie - has been encountered in the abc */
{
addfeature(TIE, 0, 0, 0);
}
void event_space()
/* space character in the abc is ignored by abc2midi */
{
/* ignore */
/* printf("Space event\n"); */
}
void event_lineend(ch, n)
/* called when \ or ! or * or ** is encountered at the end of a line */
char ch;
int n;
{
/* ignore */
}
void event_broken(type, mult)
/* handles > >> >>> < << <<< in the abc */
int type, mult;