-
Notifications
You must be signed in to change notification settings - Fork 15
/
store.c
5997 lines (5468 loc) · 160 KB
/
store.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
/*
* abc2midi - program to convert abc files to MIDI files.
* Copyright (C) 1999 James Allwright
* e-mail: [email protected]
*
* 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
*
*/
/* store.c
* This file handles all event_X() calls from parseabc.c and stores them
* in various arrays and data structures. The midi is then generated by
* calling mfwrite() which in turn uses the routine writetrack().
* This file is part of abc2midi.
*
* James Allwright
*
* Macintosh Port 30th July 1996
* Wil Macaulay ([email protected])
Table of Contents
struct voicecontext
struct notestruct
struct voicecontext* newvoice()
struct voicecontext* getvoicecontext()
void meter_voice_update()
void dump_voicecontexts()
void dump_trackdescriptor()
void setup_trackstructure()
void clearvoicecontexts()
int getchordnumbers()
void addchordname()
void setup_chordnames()
void event_init()
void event_text()
void event_x_reserved()
void event_abbreviation()
void event_acciaccatura()
int locate_voice()
void sync_voice()
int search_backwards_for_last_bar_line ()
void event_start_extended_overlay()
void event_stop_extended_overlay()
void event_split_voice()
void recurse_back_to_original_voice()
void recurse_back_and_change_bar()
void complete_all_split_voices()
void event_tex()
void event_fatal_error()
void event_error()
void event_warning()
int autoextend()
int textextend()
void addfeature()
void replacefeature()
void insertfeature()
void removefeature()
void removefeatures()
void event_linebreak()
void event_startmusicline()
void event_endmusicline()
void textfeature()
void event_comment()
void parse_mididefs()
char * expand_midix()
void event_specific()
void event_specific_in_header()
void event_startinline()
void event_closeinline()
void extract_filename()
void extract_field()
void event_words()
void append_words()
void appendfield()
void checkbreak()
void char_out()
void read_spec()
void event_part()
void event_voice()
void event_length()
void tempounits()
int get_tempo_from_name()
void event_tempo()
void event_timesig()
void event_octave()
void event_info_key()
void stack_broken()
void restore_broken()
void event_graceon()
void event_graceoff()
void event_playonrep()
void event_sluron()
void event_sluroff()
void event_tie()
void event_space()
void event_lineend()
void event_broken()
void event_tuple()
void event_chord()
void lenmul()
void brokenadjust()
void marknotestart()
void marknoteend()
void marknote()
void event_rest()
void event_mrest()
void event_chordon()
void event_chordoff()
void event_finger()
int pitchof()
int barepitch()
int pitchof_b()
int p48tc53()
void convert_to_comma53()
void doroll()
void doroll_setup()
void doroll_output()
void dotrill()
void dotrill_setup()
void dotrill_output()
void dump_notestruct()
void free_notestructs()
void makecut()
void makeharproll()
void makeharproll3()
void doornament()
void hornp()
void event_note()
void event_microtone()
void event_normal_tone()
void event_handle_gchord()
void event_handle_instruction()
void setmap()
void altermap()
void copymap()
int mputc()
void addfract()
void nondestructive_readstr()
void dotie()
void fix_enclosed_note_lengths()
int patchup_chordtie()
void tiefix()
void applygrace()
void applygrace_orig()
void applygrace_new()
void dograce()
void zerobar()
void event_bar()
void placeendrep()
void placestartrep()
void fixreps()
void beat_modifier()
void apply_bf_stress_factors()
void startfile()
void headerprocess()
void event_key()
void scan_for_missing_repeats()
void add_missing_repeats()
void convert_tnote_to_note()
void expand_ornaments()
void fix_part_start()
void finishfile()
void event_blankline()
void event_refno()
void event_eof()
int main()
*/
#define VERSION "3.88 January 08 2016 abc2midi"
/* enables reading V: indication in header */
#define XTEN1 1
/* for Microsoft Visual C++ 6.0 and higher */
#ifdef _MSC_VER
#define ANSILIBS
#define strcasecmp stricmp
#define _CRT_SECURE_NO_WARNINGS
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "abc.h"
#include "parseabc.h"
#include "parser2.h"
#include "midifile.h"
#include "genmidi.h"
#include <stdio.h>
#include <math.h>
#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
/*int snprintf(char *str, size_t size, const char *format, ...);*/
int load_stress_parameters(char *);
#define MAXLINE 500
#define INITTEXTS 20
#define INITWORDS 20
#define MAXCHANS 16
/* global variables grouped roughly by function */
FILE *fp;
/*#define MAKAM*/
#ifdef MAKAM
FILE *fc53; /* for debugging */
#endif
programname fileprogram = ABC2MIDI;
extern int oldchordconvention; /* for handling +..+ chords */
/* 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 ratio_a, ratio_b;
int velocitychange = 15;
int chordstart=0;
int propagate_accidentals = 2; /* [SS] 2015-08-18 */
/* microtonal support and scale temperament */
int active_pitchbend;
extern struct fraction setmicrotone; /* [SS] 2014-01-07 */
extern int microtone;
int temperament = 0;
#define SEMISIZE 4096
int octave_size = 12*SEMISIZE;
int fifth_size = 7*SEMISIZE; /* default to 12-edo */
int sharp_size = SEMISIZE; /* [HL] 2015-05-15] */
int started_parsing=0;
int v1index= -1;
int ignore_fermata = 0; /* [SS] 2010-01-06 */
int ignore_gracenotes = 0; /* [SS] 2010-01-08 */
int separate_tracks_for_words = 0; /* [SS] 2010-02-02 */
int bodystarted =0;
int harpmode=0; /* [JS] 2011-04-29 */
int easyabcmode = 1; /* [SS] 2011-07-18 */
int barflymode = 1; /* [SS] 2011-08-19 */
char rhythmdesignator[32]; /* [SS] 2011-08-19 */
int retuning = 0; /* [SS] 2012-04-01 */
int bend = 8192; /* [SS] 2012-04-01 */
int comma53 = 0; /* [SS] 2014-01-12 */
int silent = 0; /* [SS] 2014-10-16 */
int no_more_free_channels; /* [SS] 2015-03-23 */
void init_p48toc53 (); /* [SS] 2014-01-12 */
void convert_to_comma53 (char acc, int *midipitch, int* midibend);
void recurse_back_to_original_voice (); /* [SS] 2014-03-26 */
struct voicecontext {
/* not to be confused with struct voice defined in struct.h and
used only by yaps.
*/
/* maps of accidentals for each stave line */
char basemap[7], workmap[7][10];
int basemul[7], workmul[7][10];
struct fraction basemic[7],workmic[7][10];
int keyset; /* flag to indicate whether key signature set */
int default_length;
int active_meter_num; /* [SS] 2012-11-08 */
int active_meter_denom; /* [SS] 2012-11-08 */
int voiceno; /* voice number referenced by V: command. To avoid
conflicts with split voices, all split voices
begin from 32. */
int indexno; /* voice index number in the feat array. It just
increments by one and depends on the order the
voices are created -- including split voices.
*/
int topvoiceno,topindexno; /* links to original voice in the split */
int hasgchords;
int haswords;
int hasdrums;
int hasdrone;
int inslur;
int ingrace;
int octaveshift;
int lastbarloc; /* position of last bar line parsed */
int tosplitno,fromsplitno; /* links to split voices and source voice*/
int last_resync_point;
/* 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; /* for handling broken rhythms*/
/* broken rhythm handling */
int brokentype, brokenmult, brokenpending;
int broken_stack[7];
int midichannel; /* [SS] 2015-03-24 */
struct voicecontext* next;
int drumchannel;
};
struct voicecontext global;
struct voicecontext* v;
struct voicecontext* head;
struct voicecontext* vaddr[64]; /* address of all voices (by v->indexno) */
/* vaddr is only a convenience for debugging */
/* [SS] 2012-06-30 */
/* structure for expanding a note into a TRILL, ROLL, or ORNAMENT */
struct notestruct {
int note;
int index;
int notetype;
int pitch;
int pitchup;
int bendup;
int benddown;
int pitchdown;
int default_length;
};
struct notestruct* noteaddr[1000];
int notesdefined = 1;
struct trackstruct trackdescriptor[40]; /* trackstruct defined in genmidi.h*/
int dependent_voice[64]; /* flag to indicate type of voice */
int voicecount;
int numsplits=0;
int splitdepth = 0;
/* storage structure for strings */
int maxtexts = INITTEXTS;
char** atext;
int ntexts = 0;
/* Named guitar chords */
char chordname[MAXCHORDNAMES][8];
/* int chordnotes[MAXCHORDNAMES][6]; */
int chordnotes[MAXCHORDNAMES][10]; /* [SS] 2012-01-29 */
int chordlen[MAXCHORDNAMES];
int chordsnamed = 0;
/* general purpose storage structure */
int maxnotes;
int *pitch, *num, *denom;
int *bentpitch; /* needed for handling microtones */
featuretype *feature;
int *stressvelocity; /* [SS] 2011-08-17 for Phil's stress model*/
int *pitchline; /* introduced for handling ties */
int *decotype; /* [SS] 2012-06-29 for handling ROLLS, TRILLS, etc. */
int *charloc; /* [SS] 2014-12-25 for storing character position in abc tune */
int notes;
int verbose = 0;
int titlenames = 0;
int got_titlename;
int namelimit;
int xmatch;
int sf, mi;
int gchordvoice, wordvoice, drumvoice, dronevoice;
/* [SS] 2016-01-02 ratio_standard changed to 0 */
int ratio_standard = 0; /* flag corresponding to -RS parameter */
/* when ratio_standard != -1 the ratio for a>b is 3:1 instead of 2:1 */
int quiet = -1; /* if not -1 many common warnings and error messages */
/* are suppressed. */
int fermata_fixed = 0; /* flag on how to process fermata */
int apply_fermata_to_chord = 0; /* [SS] 2012-03-26 */
/* Part handling */
struct vstring part;
extern int parts, partno, partlabel;
extern int part_start[26], part_count[26];
int voicesused;
/* Tempo handling (Q: field) */
int time_num, time_denom;
int mtime_num, mtime_denom;
long tempo;
int tempo_num, tempo_denom;
int relative_tempo, Qtempo;
extern int division;
extern int div_factor;
int default_tempo = 120; /* quarter notes per minutes */
/* for get_tempo_from_name [SS] 2010-12-07 */
char *temponame[19] = {"larghissimo" , "adagissimo", "lentissimo",
"largo", "adagio", "lento", "larghetto", "adagietto", "andante",
"andantino", "moderato", "allegretto", "allegro", "vivace",
"vivo", "presto", "allegrissimo", "vivacissimo", "prestissimo"};
int temporate[19] = {40, 44, 48,
56, 59, 62, 66, 76, 88,
96, 104, 112, 120, 168,
180, 192, 208, 220, 240};
/* output file generation */
int userfilename = 0;
char *outname = NULL;
char *outbase = NULL;
int check;
int nofnop; /* for suppressing dynamics (ff, pp etc) */
int nocom; /* for suppressing comments in MIDI file */
int ntracks;
/* bar length checking */
extern int bar_num, bar_denom;
int barchecking;
/* generating MIDI output */
int middle_c;
extern int channel_in_use[MAXCHANS + 3]; /* 2015-03-16 formerly channels[] */
extern int additive;
int gfact_num, gfact_denom, gfact_method; /* for handling grace notes */
/* karaoke handling */
int karaoke, wcount;
char** words;
int maxwords = INITWORDS;
extern int decorators_passback[DECSIZE]; /* a kludge for passing
information from the event_handle_instruction to parsenote
in parseabc.c */
extern int inchordflag; /* [SS] 2012-03-30 */
/* for reseting decorators_passback in parseabc.c */
/* time signature after header processed */
int header_time_num,header_time_denom;
int dummydecorator[DECSIZE]; /* used in event_chord */
extern char* featname[];
char *csmfilename = NULL; /* [SS] 2013-04-10 */
/* [SS] 2015-06-01 */
#define MAXMIDICMD 200
char midicmdname[MAXMIDICMD][32];
char *midicmd[MAXMIDICMD];
int nmidicmd = 0;
void addfract(int *xnum, int *xdenom, int a, int b);
static void zerobar();
static void addfeature(int f,int p,int n,int d);
static void replacefeature(int f, int p, int n, int d, int loc);
void insertfeature(int f, int p, int n, int d, int loc);
static void textfeature(int type, char *s);
extern long writetrack();
void init_drum_map();
static void fix_enclosed_note_lengths(int from, int end);
static int patchup_chordtie(int chordstart,int chordend);
static void copymap(struct voicecontext* v);
void init_stresspat();
void beat_modifier(int);
void readstressfile (char * filename);
int parse_stress_params();
void calculate_stress_parameters();
extern int inbody; /* from parseabc.c [SS] 2009-12-18 */
extern int lineposition; /* from parseabc.c [SS] 2011-07-18 */
extern int beatmodel; /* from genmidi.c [SS] 2011-08-26 */
int stressmodel;
extern int nullputc();
void dumpfeat (int from, int to); /* defined in genmidi.c */
char * concatenatestring(char * s1,char * s2); /* defined in parseabc.c */
void read_custom_stress_file (char *filename); /* defined in stresspat.c */
static struct voicecontext* newvoice(n)
/* allocate and initialize the data for a new voice */
int n;
{
struct voicecontext *s;
int i,j;
s = (struct voicecontext*) checkmalloc(sizeof(struct voicecontext));
voicecount = voicecount + 1;
s->voiceno = n;
s->indexno = voicecount;
s->topvoiceno = n;
s->topindexno = voicecount;
s->default_length = global.default_length;
s->active_meter_num = time_num; /* [SS] 2012-11-08 */
s->active_meter_denom = time_denom; /* [SS] 2012-11-08 */
mtime_num = time_num; /* [SS] 2012-11-08 */
mtime_denom = time_denom; /* [SS] 2012-11-08 */
s->hasgchords = 0;
s->haswords = 0;
s->hasdrums = 0;
s->hasdrone = 0;
s->inslur = 0;
s->ingrace = 0;
s->inchord = 0;
s->chordcount = 0;
s->lastbarloc = -1;
s->laststart = -1;
s->lastend = -1;
s->thisstart = -1;
s->thisend = -1;
s->brokenpending = -1;
s->tosplitno = -1;
s->fromsplitno = -1;
s->last_resync_point=0;
s->next = NULL;
for (i=0; i<7; i++) {
s->basemap[i] = global.basemap[i];
s->basemul[i] = global.basemul[i];
s->basemic[i].num = global.basemic[i].num; /* [SS] 2014-01-08 */
s->basemic[i].denom = global.basemic[i].denom;
for (j=0;j<10;j++) {
s->workmap[i][j] = global.workmap[i][j];
s->workmul[i][j] = global.workmul[i][j];
s->workmic[i][j].num = global.workmic[i][j].num; /* [SS] 2014-01-26 */
s->workmic[i][j].denom = global.workmic[i][j].denom;
};
}
s->keyset = global.keyset;
s->octaveshift = global.octaveshift;
s->drumchannel = 0;
s->midichannel = -1; /* [SS] 2015-03-24 */
if (voicecount < 0 || voicecount >63)
printf("illegal voicecount = %d\n",voicecount); /* [SS] 2012-11-25 */
vaddr[voicecount] = s;
return(s);
}
static struct voicecontext* getvoicecontext(n)
/* find the data structure for a given voice number */
int n;
{
struct voicecontext *p;
struct voicecontext *q;
int i,j;
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;
};
/* check that key signature mapping is set if global
* key signature set. */
if (p->keyset == 0 && global.keyset)
{
p->keyset = 1;
for (i=0; i<7; i++) {
p->basemap[i] = global.basemap[i];
p->basemul[i] = global.basemul[i];
for (j=0;j<10;j++) {
p->workmap[i][j] = global.workmap[i][j];
p->workmul[i][j] = global.workmul[i][j];
}
};
}
mtime_num = p->active_meter_num; /* [SS] 2012-11-08 */
mtime_denom = p->active_meter_denom; /* [SS] 2012-11-08 */
return(p);
}
/* [SS] 2015-03-11 */
void meter_voice_update (int n,int m)
/* for all defined voices update p->active_meter_num and
p->active_meter_denom
*/
{
struct voicecontext *p;
p = head;
while (p != NULL) {
p->active_meter_num = n;
p->active_meter_denom = m;
p = p->next;
}
}
void dump_voicecontexts() {
/* called while debugging */
struct voicecontext *p;
struct voicecontext *q;
p = head;
printf("dump_voicecontexts()\n");
while (p != NULL) {
printf("num %d index %d gchords %d words %d drums %d drone %d tosplit %d fromsplit %d\n",
p->voiceno,p->indexno,p->hasgchords,p->haswords,p->hasdrums,p->hasdrone,p->tosplitno,p->fromsplitno);
q = p->next;
p = q;
};
}
void dump_trackdescriptor() {
int i;
for (i=0;i<ntracks;i++) {
printf("%d %d %d\n",i,trackdescriptor[i].tracktype,trackdescriptor[i].voicenum);
}
}
void setup_trackstructure () {
struct voicecontext *p;
struct voicecontext *q;
trackdescriptor[0].tracktype=NOTES;
trackdescriptor[0].voicenum=1;
trackdescriptor[0].midichannel = -1;
p = head;
ntracks = 1;
while (p != NULL) {
if (verbose) {
printf("num %d index %d gchords %d words %d drums %d drone %d tosplit %d fromsplit %d\n",
p->voiceno,p->indexno,p->hasgchords,p->haswords,p->hasdrums,p->hasdrone,p->tosplitno,p->fromsplitno);}
if (ntracks > 39) event_fatal_error("Too many tracks"); /* [SS] 2015-03-26 */
trackdescriptor[ntracks].tracktype = NOTES;
trackdescriptor[ntracks].voicenum = p->indexno;
trackdescriptor[ntracks].midichannel = p->midichannel;
if (p->haswords) {
if (!separate_tracks_for_words) {
trackdescriptor[ntracks].tracktype = NOTEWORDS;
trackdescriptor[ntracks].voicenum = p->indexno;
} else {
ntracks++;
trackdescriptor[ntracks].tracktype = WORDS;
trackdescriptor[ntracks].voicenum = trackdescriptor[ntracks-1].voicenum;
}
}
if (p->hasgchords) {
ntracks++;
trackdescriptor[ntracks].tracktype = GCHORDS;
trackdescriptor[ntracks].voicenum = p->indexno;
}
if (p->hasdrums) {
ntracks++;
trackdescriptor[ntracks].tracktype = DRUMS;
trackdescriptor[ntracks].voicenum = p->indexno;
};
if (p->hasdrone) {
ntracks++;
trackdescriptor[ntracks].tracktype = DRONE;
trackdescriptor[ntracks].voicenum = p->indexno;
};
ntracks++;
q = p->next;
p = q;
}
/* does the tune need any gchord, drum, drone or word track */
if ((voicesused == 0) && (!karaoke) && (gchordvoice == 0) &&
(drumvoice == 0) && (dronevoice==0)) {
ntracks = 1;
}
/*dump_trackdescriptor();*/
}
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;
}
static int getchordnumber(s)
/* looks through list of known chords for chord name given in s */
char *s;
{
int i;
int chordnumber;
chordnumber = 0;
i = 1;
while ((i <= chordsnamed) && (chordnumber == 0)) {
if (strcmp(s, chordname[i]) == 0) {
chordnumber = i;
} else {
i = i + 1;
};
};
return(chordnumber);
}
static void addchordname(s, len, notes)
/* adds chord name and note set to list of known chords */
char *s;
int notes[];
int len;
{
int i, j, done;
if (strlen(s) > 7) {
event_error("Chord name cannot exceed 7 characters");
return;
};
if (len > 10) {
event_error("Named chord cannot have more than 10 notes");
return;
};
i = 0;
done = 0;
while ((i<chordsnamed) && (!done)) {
if (strcmp(s, chordname[i]) == 0) {
/* change chord */
chordlen[i] = len;
for (j=0; j<len; j++) {
chordnotes[i][j] = notes[j];
};
done = 1;
} else {
i = i + 1;
};
};
if (!done) {
if (chordsnamed >= MAXCHORDNAMES-1) {
event_error("Too many Guitar Chord Names used");
} else {
chordsnamed = chordsnamed + 1;
strcpy(chordname[chordsnamed], s);
chordlen[chordsnamed] = len;
for (j=0; j<len; j++) {
chordnotes[chordsnamed][j] = notes[j];
};
};
};
}
static void setup_chordnames()
/* set up named guitar chords */
{
static int list_Maj[3] = {0, 4, 7};
static int list_m[3] = {0, 3, 7};
static int list_7[4] = {0, 4, 7, 10};
static int list_m7[4] = {0, 3, 7, 10};
static int list_m7b5[4] = {0, 3, 6, 10};
static int list_maj7[4] = {0, 4, 7, 11};
static int list_M7[4] = {0, 4, 7, 11};
static int list_6[4] = {0, 4, 7, 9};
static int list_m6[4] = {0, 3, 7, 9};
static int list_aug[3] = {0, 4, 8};
static int list_plus[3] = {0, 4, 8};
static int list_aug7[4] = {0, 4, 8, 10};
static int list_dim[3] = {0, 3, 6};
static int list_dim7[4] = {0, 3, 6, 9};
static int list_9[5] = {0, 4, 7, 10, 2};
static int list_m9[5] = {0, 3, 7, 10, 2};
static int list_maj9[5] = {0, 4, 7, 11, 2};
static int list_M9[5] = {0, 4, 7, 11, 2};
static int list_11[6] = {0, 4, 7, 10, 2, 5};
static int list_dim9[5] = {0, 3, 6, 9, 13}; /* [SS] 2016-02-08 */
static int list_sus[3] = {0, 5, 7};
static int list_sus4[3] = {0, 4, 7}; /* [SS] 2015-07-08 */
static int list_sus9[3] = {0, 2, 7};
static int list_7sus4[4] = {0, 5, 7, 10};
static int list_7sus9[4] = {0, 2, 7, 10};
static int list_5[2] = {0, 7};
addchordname("", 3, list_Maj);
addchordname("m", 3, list_m);
addchordname("7", 4, list_7);
addchordname("m7", 4, list_m7);
addchordname("m7b5", 4, list_m7b5);
addchordname("maj7", 4, list_maj7);
addchordname("M7", 4, list_M7);
addchordname("6", 4, list_6);
addchordname("m6", 4, list_m6);
addchordname("aug", 3, list_aug);
addchordname("+", 3, list_plus);
addchordname("aug7", 4, list_aug7);
addchordname("dim", 3, list_dim);
addchordname("dim7", 4, list_dim7);
addchordname("9", 5, list_9);
addchordname("m9", 5, list_m9);
addchordname("maj9", 5, list_maj9);
addchordname("M9", 5, list_M9);
addchordname("11", 6, list_11);
addchordname("dim9", 5, list_dim9);
addchordname("sus", 3, list_sus);
addchordname("sus4", 3, list_sus4); /* [SS] 2015-07-08 */
addchordname("sus9", 3, list_sus9);
addchordname("sus2", 3, list_sus9); /* [SS] 2015-07-08 */
addchordname("7sus2", 4, list_7sus9); /* [SS] 2015-07-08 */
addchordname("7sus4", 4, list_7sus4);
addchordname("7sus9", 4, list_7sus9);
addchordname("5", 2, list_5);
}
void event_init(argc, argv, filename)
/* this routine is called first by parseabc.c */
int argc;
char* argv[];
char **filename;
{
int j;
int arg,m,n;
float afreq,semitone_shift; /* [SS] 2012-04-01 */
double log10();
/* look for code checking option */
if (getarg("-c", argc, argv) != -1) {
check = 1;
} else {
check = 0;
};
/* look for filename-from-tune-titles option */
namelimit = 252;
titlenames = 0;
if (getarg("-t", argc, argv) != -1) {
titlenames = 1;
namelimit = 8;
};
/* look for verbose option */
arg = getarg("-v", argc, argv);
if (arg != -1) { /* [SS] 2011-08-26 */
if (argc > arg) {
n = sscanf(argv[arg],"%d",&m);
if (n > 0) verbose = m; }
else verbose = 1; /* arg != -1 but arg == argc */
} else { /* arg = -1 */
verbose = 0;
};
if (getarg("-ver",argc, argv) != -1) {
printf("abc2midi %s\n",VERSION);
exit(0);
}
/* look for "no forte no piano" option */
if (getarg("-NFNP", argc, argv) != -1) {
nofnop = 1;
} else {
nofnop = 0;
}
if (getarg("-NFER",argc, argv) != -1) {
ignore_fermata = 1;
} else {
ignore_fermata = 0;
}
if (getarg("-NGRA",argc, argv) != -1) {
ignore_gracenotes = 1;
} else {
ignore_gracenotes = 0;
}
if (getarg("-NCOM", argc, argv) != -1) {
nocom = 1;
} else {
nocom = 0;
}
if (getarg("-STFW",argc,argv) != -1) {
separate_tracks_for_words = 1;
} else {
separate_tracks_for_words = 0;
}
if (getarg("-HARP",argc,argv) != -1) { /* [JS] 2011-04-29 */
harpmode = 1;
} else {
harpmode = 0;
}
if (getarg("-EA",argc,argv) != -1) { /* [SS] 2011-07-18 */
easyabcmode = 1;
} else {
easyabcmode = 0;
}
arg = getarg("-BF",argc,argv);
if (arg != -1) { /* [SS] 2011-08-26 */
barflymode = 1;
if (argc > arg) {
n = sscanf(argv[arg],"%d",&m);
if (n > 0) stressmodel = m;
} else stressmodel = 2;
} else {
barflymode = 0;
stressmodel = 0;
}
arg = getarg("-TT",argc,argv); /* [SS] 2012-04-01 */
if (arg != -1) {
n =0;
if (argc > arg) {
n = sscanf(argv[arg],"%f",&afreq);
}
if (n < 1) {printf("expecting float between 415.30 and 466.16 after -TT\n");
} else {
retuning = 1;
semitone_shift = (float) (12.0 * log10(afreq/440.0f)/log10(2.0f)); /* [SS] 2015-10-08 extra parentheses */
printf("afreq = %f semitone_shift = %f\n",afreq,semitone_shift);
if (semitone_shift >= 1.001) {printf("frequency %f must be less than 466.16\n",afreq);
retuning = 0;
}
if (semitone_shift <= -1.015) {printf("frequency %f must be greater than 415.0\n",afreq);
retuning = 0;
}
if (retuning) {bend = (int) (8192.0 * semitone_shift) + 8192;
if (bend > 16383) bend=16383;
if (bend < 0) bend = 0;
printf("bend = %d\n",bend);
}
}
}
if (getarg("-OCC",argc,argv) != -1) oldchordconvention=1;
if (getarg("-silent",argc,argv) != -1) silent = 1; /* [SS] 2014-10-16 */
maxnotes = 500;
/* allocate space for notes */
pitch = checkmalloc(maxnotes*sizeof(int));
num = checkmalloc(maxnotes*sizeof(int));
denom = checkmalloc(maxnotes*sizeof(int));
stressvelocity = checkmalloc(maxnotes*sizeof(int)); /* [SS] 2011-08-17 */
bentpitch = checkmalloc(maxnotes*sizeof(int));
decotype = checkmalloc(maxnotes*sizeof(int)); /* [SS] 2012-06-29 */
feature = (featuretype*) checkmalloc(maxnotes*sizeof(featuretype));
pitchline = checkmalloc(maxnotes*sizeof(int));
charloc = checkmalloc(maxnotes*sizeof(int)); /* [SS] 2014-12-25 */
for (j=0; j<maxnotes; j++) /* [SS] 2012-11-25 */
bentpitch[j] = decotype[j] = 0; /* [SS] 2012-11-25 */
for (j=0;j<DECSIZE;j++) dummydecorator[j] = 0;
/* and for text */
atext = (char**) checkmalloc(maxtexts*sizeof(char*));
words = (char**) checkmalloc(maxwords*sizeof(char*));
if ((getarg("-h", argc, argv) != -1) || (argc < 2)) {
printf("abc2midi version %s\n",VERSION);
printf("Usage : abc2midi <abc file> [reference number] [-c] [-v] ");
printf("[-o filename]\n");
printf(" [-t] [-n <value>] [-CS] [-NFNP] [-NCOM] [-NFER] [-NGRA] [-HARP]\n");
printf(" [reference number] selects a tune\n");
printf(" -c selects checking only\n");
printf(" -v selects verbose option\n");