-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.c
5090 lines (4772 loc) · 109 KB
/
draw.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
/*
* Drawing functions.
*
* This file is part of abcm2ps.
*
* Copyright (C) 1998-2016 Jean-François Moine
* Adapted from abc2ps, Copyright (C) 1996,1997 Michael Methfessel
*
* 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.
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "abcm2ps.h"
struct BEAM { /* packages info on one beam */
struct SYMBOL *s1, *s2;
float a, b;
short nflags;
};
static char *acc_tb[] = { "", "sh", "nt", "ft", "dsh", "dft" };
/* scaling stuff */
static int scale_voice; /* staff (0) or voice(1) scaling */
static float cur_scale = 1; /* voice or staff scale */
static float cur_trans = 0; /* != 0 when scaled staff */
static float cur_staff = 1; /* current scaled staff */
static int cur_color = 0; /* current color */
static void draw_note(float x,
struct SYMBOL *s,
int fl);
static void set_tie_room(void);
/* set the voice color */
void set_v_color(int v)
{
int old_color = cur_color;
if (v < 0)
cur_color = 0;
else
cur_color = voice_tb[v].color;
if (cur_color != old_color)
a2b("%.2f %.2f %.2f setrgbcolor ",
(float) (cur_color >> 16) / 255,
(float) ((cur_color >> 8) & 0xff) / 255,
(float) (cur_color & 0xff) / 255);
}
/* output debug annotations */
static void anno_out(struct SYMBOL *s, char type)
{
if (s->linenum == 0)
return;
if (mbf[-1] != '\n')
*mbf++ = '\n';
a2b("%%A %c %d %d ", type, s->linenum, s->colnum);
putxy(s->x - s->wl - 2, staff_tb[s->staff].y + s->ymn - 2);
if (type != 'b' && type != 'e') /* if not beam */
a2b("%.1f %d", s->wl + s->wr + 4, s->ymx - s->ymn + 4);
a2b("\n");
}
/* -- up/down shift needed to get k*6 -- */
static float rnd6(float y)
{
int iy;
iy = ((int) (y + 2.999) + 12) / 6 * 6 - 12;
return iy - y;
}
/* -- compute the best vertical offset for the beams -- */
static float b_pos(int grace,
int stem,
int flags,
float b)
{
float d1, d2, shift, depth;
float top, bot;
shift = !grace ? BEAM_SHIFT : 3;
depth = !grace ? BEAM_DEPTH : 1.7;
if (stem > 0) {
bot = b - (flags - 1) * shift - depth;
if (bot > 26)
return 0;
top = b;
} else {
top = b + (flags - 1) * shift + depth;
if (top < -2)
return 0;
bot = b;
}
d1 = rnd6(top - BEAM_OFFSET);
d2 = rnd6(bot + BEAM_OFFSET);
if (d1 * d1 > d2 * d2)
return d2;
return d1;
}
/* duplicate a note for beaming continuation */
static struct SYMBOL *sym_dup(struct SYMBOL *s_orig)
{
struct SYMBOL *s;
int m;
s = (struct SYMBOL *) getarena(sizeof *s);
memcpy(s, s_orig, sizeof *s);
s->flags |= ABC_F_INVIS;
s->text = NULL;
for (m = 0; m <= s->nhd; m++)
s->u.note.notes[m].sl1 = 0;
memset(&s->u.note.dc, 0, sizeof s->u.note.dc);
s->gch = NULL;
s->ly = NULL;
return s;
}
/* -- calculate a beam -- */
/* (the staves may be defined or not) */
static int calculate_beam(struct BEAM *bm,
struct SYMBOL *s1)
{
struct SYMBOL *s, *s2;
int notes, nflags, staff, voice, two_staves, two_dir;
float x, y, ys, a, b, max_stem_err;
float sx, sy, sxx, sxy, syy, a0, stem_xoff, scale;
static float min_tb[2][6] = {
{STEM_MIN, STEM_MIN,
STEM_MIN2, STEM_MIN3, STEM_MIN4, STEM_MIN4},
{STEM_CH_MIN, STEM_CH_MIN,
STEM_CH_MIN2, STEM_CH_MIN3, STEM_CH_MIN4, STEM_CH_MIN4}
};
// /* must have one printed note head */
// if (s1->flags & ABC_F_INVIS) {
// if (!s1->next
// || (s1->next->flags & ABC_F_INVIS))
// return 0;
// }
if (!(s1->sflags & S_BEAM_ST)) { /* beam from previous music line */
s = sym_dup(s1);
s->prev = s1->prev;
if (s->prev)
s->prev->next = s;
else
voice_tb[s->voice].sym = s;
s1->prev = s;
s->next = s1;
s->ts_prev = s1->ts_prev;
// if (s->ts_prev)
s->ts_prev->ts_next = s;
s1->ts_prev = s;
s->ts_next = s1;
for (s2 = s->ts_prev; /*s2*/; s2 = s2->ts_prev) {
switch (s2->type) {
default:
continue;
case CLEF:
case KEYSIG:
case TIMESIG:
break;
}
break;
}
s->x -= 12;
if (s->x > s2->x + 12)
s->x = s2->x + 12;
s->sflags &= S_SEQST;
s->sflags |= S_BEAM_ST | S_TEMP;
s->u.note.slur_st = 0;
s->u.note.slur_end = 0;
s1 = s;
}
/* search last note in beam */
notes = nflags = 0; /* set x positions, count notes and flags */
two_staves = two_dir = 0;
staff = s1->staff;
voice = s1->voice;
stem_xoff = (s1->flags & ABC_F_GRACE) ? GSTEM_XOFF : s1->u.note.sdx;
for (s2 = s1; ; s2 = s2->next) {
if (s2->abc_type == ABC_T_NOTE) {
if (s2->nflags > nflags)
nflags = s2->nflags;
notes++;
if (s2->staff != staff)
two_staves = 1;
if (s2->stem != s1->stem)
two_dir = 1;
if (s2->sflags & S_BEAM_END)
break;
}
if (!s2->next) { /* beam towards next music line */
for (; ; s2 = s2->prev) {
if (s2->abc_type == ABC_T_NOTE)
break;
}
s = sym_dup(s2);
s->next = s2->next;
if (s->next)
s->next->prev = s;
s2->next = s;
s->prev = s2;
s->ts_next = s2->ts_next;
if (s->ts_next)
s->ts_next->ts_prev = s;
s2->ts_next = s;
s->ts_prev = s2;
s->sflags &= S_SEQST;
s->sflags |= S_BEAM_END | S_TEMP;
s->u.note.slur_st = 0;
s->u.note.slur_end = 0;
s->x += 12;
if (s->x < realwidth - 12)
s->x = realwidth - 12;
s2 = s;
notes++;
break;
}
}
bm->s2 = s2; /* (don't display the flags) */
if (staff_tb[staff].y == 0) { /* staves not defined */
if (two_staves)
return 0;
} else { /* staves defined */
if (!two_staves) {
bm->s1 = s1; /* beam already calculated */
if (s1->xs == s2->xs)
bug("beam with null length", 1);
bm->a = (s1->ys- s2->ys) / (s1->xs - s2->xs);
bm->b = s1->ys - s1->xs * bm->a
+ staff_tb[staff].y;
bm->nflags = nflags;
return 1;
}
}
sx = sy = sxx = sxy = syy = 0; /* linear fit through stem ends */
for (s = s1; ; s = s->next) {
if (s->abc_type != ABC_T_NOTE)
continue;
if ((scale = voice_tb[s->voice].scale) == 1)
scale = staff_tb[s->staff].staffscale;
if (s->stem >= 0)
x = stem_xoff + s->u.note.notes[0].shhd;
else
x = -stem_xoff + s->u.note.notes[s->nhd].shhd;
x *= scale;
x += s->x;
s->xs = x;
y = s->ys + staff_tb[s->staff].y;
sx += x; sy += y;
sxx += x * x; sxy += x * y; syy += y * y;
if (s == s2)
break;
}
/* beam fct: y=ax+b */
a = (sxy * notes - sx * sy) / (sxx * notes - sx * sx);
b = (sy - a * sx) / notes;
/* the next few lines modify the slope of the beam */
if (!(s1->flags & ABC_F_GRACE)) {
if (notes >= 3) {
float hh;
hh = syy - a * sxy - b * sy; /* flatten if notes not in line */
if (hh > 0
&& hh / (notes - 2) > .5)
a *= BEAM_FLATFAC;
}
if (a >= 0)
a = BEAM_SLOPE * a / (BEAM_SLOPE + a); /* max steepness for beam */
else
a = BEAM_SLOPE * a / (BEAM_SLOPE - a);
} else {
if (a > BEAM_SLOPE)
a = BEAM_SLOPE;
else if (a < -BEAM_SLOPE)
a = -BEAM_SLOPE;
}
/* to decide if to draw flat etc. use normalized slope a0 */
a0 = a * (s2->xs - s1->xs) / (20 * (notes - 1));
if (a0 * a0 < BEAM_THRESH * BEAM_THRESH)
a = 0; /* flat below threshhold */
b = (sy - a * sx) / notes; /* recalculate b for new slope */
/* if (nflags>1) b=b+2*stem;*/ /* leave a bit more room if several beams */
/* have flat beams when asked */
if (cfmt.flatbeams) {
if (!(s1->flags & ABC_F_GRACE))
b = -11 + staff_tb[staff].y;
else
b = 35 + staff_tb[staff].y;
a = 0;
}
/*fixme: have a look again*/
/* have room for the symbols in the staff */
max_stem_err = 0; /* check stem lengths */
s = s1;
if (two_dir) { /* 2 directions */
/*fixme: more to do*/
if (!(s1->flags & ABC_F_GRACE))
ys = BEAM_SHIFT;
else
ys = 3;
ys *= (nflags - 1);
ys += BEAM_DEPTH;
ys *= .5;
if (s1->stem != s2->stem && s1->nflags < s2->nflags)
ys *= s2->stem;
else
ys *= s1->stem;
b += ys;
} else if (!(s1->flags & ABC_F_GRACE)) { /* normal notes */
float stem_err, beam_h;
beam_h = BEAM_DEPTH + BEAM_SHIFT * (nflags - 1);
while (s->ts_prev->abc_type == ABC_T_NOTE
&& s->ts_prev->time == s->time
&& s->ts_prev->x > s1->xs)
s = s->ts_prev;
for (; s && s->time <= s2->time; s = s->ts_next) {
if (s->abc_type != ABC_T_NOTE
|| (s->flags & ABC_F_INVIS)
|| (s->staff != staff
&& s->voice != voice)) {
continue;
}
x = s->voice == voice ? s->xs : s->x;
ys = a * x + b - staff_tb[s->staff].y;
if (s->voice == voice) {
if (s->nhd == 0)
stem_err = min_tb[0][(unsigned) s->nflags];
else
stem_err = min_tb[1][(unsigned) s->nflags];
if (s->stem > 0) {
if (s->pits[s->nhd] > 26) {
stem_err -= 2;
if (s->pits[s->nhd] > 28)
stem_err -= 2;
}
stem_err -= ys - (float) (3 *
(s->pits[s->nhd] - 18));
} else {
if (s->pits[0] < 18) {
stem_err -= 2;
if (s->pits[0] < 16)
stem_err -= 2;
}
stem_err -= (float) (3 *
(s->pits[0] - 18)) - ys;
}
stem_err += BEAM_DEPTH + BEAM_SHIFT * (s->nflags - 1);
} else {
/*fixme: KO when two_staves*/
if (s1->stem > 0) {
if (s->stem > 0) {
/*fixme: KO when the voice numbers are inverted*/
if (s->ymn > ys + 4
|| s->ymx < ys - beam_h - 2)
continue;
if (s->voice > voice)
stem_err = s->ymx - ys;
else
stem_err = s->ymn + 8 - ys;
} else {
stem_err = s->ymx - ys;
}
} else {
if (s->stem < 0) {
if (s->ymx < ys - 4
|| s->ymn > ys - beam_h - 2)
continue;
if (s->voice < voice)
stem_err = ys - s->ymn;
else
stem_err = ys - s->ymx + 8;
} else {
stem_err = ys - s->ymn;
}
}
stem_err += 2 + beam_h;
}
if (stem_err > max_stem_err)
max_stem_err = stem_err;
}
} else { /* grace notes */
for ( ; ; s = s->next) {
float stem_err;
ys = a * s->xs + b - staff_tb[s->staff].y;
stem_err = GSTEM - 2;
if (s->stem > 0)
stem_err -= ys - (float) (3 *
(s->pits[s->nhd] - 18));
else
stem_err += ys - (float) (3 *
(s->pits[0] - 18));
stem_err += 3 * (s->nflags - 1);
if (stem_err > max_stem_err)
max_stem_err = stem_err;
if (s == s2)
break;
}
}
if (max_stem_err > 0) /* shift beam if stems too short */
b += s1->stem * max_stem_err;
/* have room for the gracenotes, bars and clefs */
/*fixme: test*/
if (!two_staves && !two_dir)
for (s = s1->next; ; s = s->next) {
struct SYMBOL *g;
switch (s->type) {
case NOTEREST: /* cannot move rests in multi-voices */
if (s->abc_type != ABC_T_REST)
break;
g = s->ts_next;
if (!g || g->staff != staff
|| g->type != NOTEREST)
break;
//fixme:too much vertical shift if some space above the note
//fixme:this does not fix rest under beam in second voice (ts_prev)
/*fall thru*/
case BAR:
#if 1
if (s->flags & ABC_F_INVIS)
#else
//??
if (!(s->flags & ABC_F_INVIS))
#endif
break;
/*fall thru*/
case CLEF:
y = a * s->x + b;
if (s1->stem > 0) {
y = s->ymx - y
+ BEAM_DEPTH + BEAM_SHIFT * (nflags - 1)
+ 2;
if (y > 0)
b += y;
} else {
y = s->ymn - y
- BEAM_DEPTH - BEAM_SHIFT * (nflags - 1)
- 2;
if (y < 0)
b += y;
}
break;
case GRACE:
g = s->extra;
for ( ; g; g = g->next) {
if (g->type != NOTEREST)
continue;
y = a * g->x + b;
if (s1->stem > 0) {
y = g->ymx - y
+ BEAM_DEPTH + BEAM_SHIFT * (nflags - 1)
+ 2;
if (y > 0)
b += y;
} else {
y = g->ymn - y
- BEAM_DEPTH - BEAM_SHIFT * (nflags - 1)
- 2;
if (y < 0)
b += y;
}
}
break;
}
if (s == s2)
break;
}
if (a == 0) /* shift flat beams onto staff lines */
b += b_pos(s1->flags & ABC_F_GRACE, s1->stem, nflags,
b - staff_tb[staff].y);
/* adjust final stems and rests under beam */
for (s = s1; ; s = s->next) {
float dy;
switch (s->abc_type) {
case ABC_T_NOTE:
s->ys = a * s->xs + b - staff_tb[s->staff].y;
if (s->stem > 0) {
s->ymx = s->ys + 2.5;
#if 0
//fixme: hack
if (s->ts_prev
&& s->ts_prev->stem > 0
&& s->ts_prev->staff == s->staff
&& s->ts_prev->ymn < s->ymx
&& s->ts_prev->x == s->x
&& s->u.note.notes[0].shhd == 0) {
s->ts_prev->x -= 5; /* fix stem clash */
s->ts_prev->xs -= 5;
}
#endif
} else {
s->ymn = s->ys - 2.5;
}
break;
case ABC_T_REST:
y = a * s->x + b - staff_tb[s->staff].y;
dy = BEAM_DEPTH + BEAM_SHIFT * (nflags - 1)
+ (s->head != H_FULL ? 4 : 9);
if (s1->stem > 0) {
y -= dy;
if (s1->multi == 0 && y > 12)
y = 12;
if (s->y <= y)
break;
} else {
y += dy;
if (s1->multi == 0 && y < 12)
y = 12;
if (s->y >= y)
break;
}
if (s->head != H_FULL) {
int iy;
iy = ((int) y + 3 + 12) / 6 * 6 - 12;
y = iy;
}
s->y = y;
break;
}
if (s == s2)
break;
}
/* save beam parameters */
if (staff_tb[staff].y == 0) /* if staves not defined */
return 0;
bm->s1 = s1;
bm->a = a;
bm->b = b;
bm->nflags = nflags;
return 1;
}
/* -- draw a single beam -- */
/* (the staves are defined) */
static void draw_beam(float x1,
float x2,
float dy,
float h,
struct BEAM *bm,
int n) /* beam number (1..n) */
{
struct SYMBOL *s;
float y1, dy2;
s = bm->s1;
if ((s->sflags & S_TREM2) && n > s->nflags - s->aux
&& s->head != H_EMPTY) {
if (s->head >= H_OVAL) {
x1 = s->x + 6;
x2 = bm->s2->x - 6;
} else {
x1 += 5;
x2 -= 6;
}
}
y1 = bm->a * x1 + bm->b - dy;
x2 -= x1;
dy2 = bm->a * x2;
putf(h);
putx(x2);
putf(dy2);
putxy(x1, y1);
a2b("bm\n");
}
/* -- draw the beams for one word -- */
/* (the staves are defined) */
static void draw_beams(struct BEAM *bm)
{
struct SYMBOL *s, *s1, *s2;
int i, beam_dir;
float shift, bshift, bstub, bh, da;
s1 = bm->s1;
/*fixme: KO if many staves with different scales*/
//fixme: useless?
// set_scale(s1);
s2 = bm->s2;
if (!(s1->flags & ABC_F_GRACE)) {
bshift = BEAM_SHIFT;
bstub = BEAM_STUB;
shift = .34; /* (half width of the stem) */
bh = BEAM_DEPTH;
} else {
bshift = 3;
bstub = 3.2;
shift = .29;
bh = 1.6;
}
/*fixme: quick hack for stubs at end of beam and different stem directions*/
beam_dir = s1->stem;
if (s1->stem != s2->stem
&& s1->nflags < s2->nflags)
beam_dir = s2->stem;
if (beam_dir < 0)
bh = -bh;
if (cur_trans == 0 && cur_scale != 1) {
bm->a /= cur_scale;
bm->b = s1->ys - s1->xs * bm->a
+ staff_tb[s1->staff].y;
bshift *= cur_scale;
}
/* make first beam over whole word and adjust the stem lengths */
draw_beam(s1->xs - shift, s2->xs + shift, 0., bh, bm, 1);
da = 0;
for (s = s1; ; s = s->next) {
if (s->abc_type == ABC_T_NOTE
&& s->stem != beam_dir)
s->ys = bm->a * s->xs + bm->b
- staff_tb[s->staff].y
+ bshift * (s->nflags - 1) * s->stem
- bh;
if (s == s2)
break;
}
if (s1->sflags & S_FEATHERED_BEAM) {
da = bshift / (s2->xs - s1->xs);
if (s1->dur > s2->dur) {
da = -da;
bshift = da * s1->xs;
} else {
bshift = da * s2->xs;
}
da = da * beam_dir;
}
/* other beams with two or more flags */
shift = 0;
for (i = 2; i <= bm->nflags; i++) {
shift += bshift;
if (da != 0)
bm->a += da;
for (s = s1; ; s = s->next) {
struct SYMBOL *k1, *k2;
float x1;
if (s->abc_type != ABC_T_NOTE
|| s->nflags < i) {
if (s == s2)
break;
continue;
}
if ((s->sflags & S_TREM1)
&& i > s->nflags - s->aux) {
if (s->head >= H_OVAL)
x1 = s->x;
else
x1 = s->xs;
draw_beam(x1 - 5, x1 + 5,
(shift + 2.5) * beam_dir,
bh, bm, i);
if (s == s2)
break;
continue;
}
k1 = s;
for (;;) {
if (s == s2)
break;
if (s->next->type == NOTEREST) {
if (s->next->sflags & S_TREM1) {
if (s->next->nflags - s->next->aux < i)
break;
} else if (s->next->nflags < i) {
break;
}
}
if ((s->next->sflags & S_BEAM_BR1)
|| ((s->next->sflags & S_BEAM_BR2) && i > 2))
break;
s = s->next;
}
k2 = s;
while (k2->abc_type != ABC_T_NOTE)
k2 = k2->prev;
x1 = k1->xs;
if (k1 == k2) {
if (k1 == s1) {
x1 += bstub;
} else if (k1 == s2) {
x1 -= bstub;
} else if ((k1->sflags & S_BEAM_BR1)
|| ((k1->sflags & S_BEAM_BR2)
&& i > 2)) {
x1 += bstub;
} else {
struct SYMBOL *k;
k = k1->next;
while (k->abc_type != ABC_T_NOTE)
k = k->next;
if ((k->sflags & S_BEAM_BR1)
|| ((k->sflags & S_BEAM_BR2)
&& i > 2)) {
x1 -= bstub;
} else {
k1 = k1->prev;
while (k1->abc_type != ABC_T_NOTE)
k1 = k1->prev;
if (k1->nflags < k->nflags
|| (k1->nflags == k->nflags
&& k1->dots < k->dots))
x1 += bstub;
else
x1 -= bstub;
}
}
}
draw_beam(x1, k2->xs,
#if 1
shift * beam_dir,
#else
shift * k1->stem, /*fixme: more complicated */
#endif
bh, bm, i);
if (s == s2)
break;
}
}
if (s1->sflags & S_TEMP)
unlksym(s1);
else if (s2->sflags & S_TEMP)
unlksym(s2);
}
/* -- draw a system brace or bracket -- */
static void draw_sysbra(float x, int staff, int flag)
{
int i, end;
float yt, yb;
while (cursys->staff[staff].empty
|| staff_tb[staff].stafflines == 0) {
if (cursys->staff[staff].flags & flag)
return;
staff++;
}
i = end = staff;
for (;;) {
if (!cursys->staff[i].empty
&& staff_tb[i].stafflines != 0)
end = i;
if (cursys->staff[i].flags & flag)
break;
i++;
}
yt = staff_tb[staff].y + staff_tb[staff].topbar
* staff_tb[staff].staffscale;
yb = staff_tb[end].y + staff_tb[end].botbar
* staff_tb[end].staffscale;
a2b("%.1f %.1f %.1f %s\n",
yt - yb, x, yt,
(flag & (CLOSE_BRACE | CLOSE_BRACE2)) ? "brace" : "bracket");
}
/* -- draw the left side of the staves -- */
static void draw_lstaff(float x)
{
int i, j, l, nst;
float yb;
if (cfmt.alignbars)
return;
nst = cursys->nstaff;
l = 0;
for (i = 0; ; i++) {
if (cursys->staff[i].flags & (OPEN_BRACE | OPEN_BRACKET))
l++;
if (!cursys->staff[i].empty
&& staff_tb[i].stafflines != 0)
break;
if (cursys->staff[i].flags & (CLOSE_BRACE | CLOSE_BRACKET))
l--;
if (i == nst)
break;
}
for (j = nst; j > i; j--) {
if (!cursys->staff[j].empty
&& staff_tb[j].stafflines != 0)
break;
}
if (i == j && l == 0)
return;
set_sscale(-1);
yb = staff_tb[j].y + staff_tb[j].botbar
* staff_tb[j].staffscale;
a2b("%.1f %.1f %.1f bar\n",
staff_tb[i].y
+ staff_tb[i].topbar * staff_tb[i].staffscale
- yb,
x, yb);
for (i = 0; i <= nst; i++) {
if (cursys->staff[i].flags & OPEN_BRACE)
draw_sysbra(x, i, CLOSE_BRACE);
if (cursys->staff[i].flags & OPEN_BRACKET)
draw_sysbra(x, i, CLOSE_BRACKET);
if (cursys->staff[i].flags & OPEN_BRACE2)
draw_sysbra(x - 6, i, CLOSE_BRACE2);
if (cursys->staff[i].flags & OPEN_BRACKET2)
draw_sysbra(x - 6, i, CLOSE_BRACKET2);
}
}
/* -- draw a staff -- */
static void draw_staff(int staff,
float x1, float x2)
{
int nlines;
float y;
/* draw the staff */
set_sscale(staff);
y = staff_tb[staff].y;
nlines = staff_tb[staff].stafflines;
switch (nlines) {
case 0:
return;
case 1:
y += 12;
break;
case 2:
case 3:
y += 6;
break;
}
putx(x2 - x1);
a2b("%d ", nlines);
putxy(x1, y);
a2b("staff\n");
}
/* -- draw the time signature -- */
static void draw_timesig(float x,
struct SYMBOL *s)
{
unsigned i, staff, l, l2;
char *f, meter[64];
float dx;
if (s->u.meter.nmeter == 0)
return;
staff = s->staff;
x -= s->wl;
for (i = 0; i < s->u.meter.nmeter; i++) {
l = strlen(s->u.meter.meter[i].top);
if (l > sizeof s->u.meter.meter[i].top)
l = sizeof s->u.meter.meter[i].top;
if (s->u.meter.meter[i].bot[0] != '\0') {
sprintf(meter, "(%.8s)(%.2s)",
s->u.meter.meter[i].top,
s->u.meter.meter[i].bot);
f = "tsig";
l2 = strlen(s->u.meter.meter[i].bot);
if (l2 > sizeof s->u.meter.meter[i].bot)
l2 = sizeof s->u.meter.meter[i].bot;
if (l2 > l)
l = l2;
} else switch (s->u.meter.meter[i].top[0]) {
case 'C':
if (s->u.meter.meter[i].top[1] != '|') {
f = "csig";
} else {
f = "ctsig";
l--;
}
meter[0] = '\0';
break;
case 'c':
if (s->u.meter.meter[i].top[1] != '.') {
f = "imsig";
} else {
f = "iMsig";
l--;
}
meter[0] = '\0';
break;
case 'o':
if (s->u.meter.meter[i].top[1] != '.') {
f = "pmsig";
} else {
f = "pMsig";
l--;
}
meter[0] = '\0';
break;
case '(':
case ')':
sprintf(meter, "(\\%s)",
s->u.meter.meter[i].top);
f = "stsig";
break;
default:
sprintf(meter, "(%.8s)",
s->u.meter.meter[i].top);
f = "stsig";
break;
}
if (meter[0] != '\0')
a2b("%s ", meter);
dx = (float) (13 * l);
putxy(x + dx * .5, staff_tb[staff].y);
a2b("%s\n", f);
x += dx;
}
}
/* -- draw an accidental -- */
static void draw_acc(int acc, int microscale)
{
int n, d;
n = parse.micro_tb[acc >> 3];
if (acc >> 3 != 0 && microscale) {
if (microscale) {
d = microscale;
n = acc >> 3;
} else {
d = ((n & 0xff) + 1) * 2;
n = (n >> 8) + 1;
}
a2b("%d %s%d ", n, acc_tb[acc & 0x07], d);
} else {
a2b("%s%d ", acc_tb[acc & 0x07], n);
}
}
// draw helper lines
static void draw_hl(float x, int staffb, int up,
int y, int stafflines, char *hltype)
{
int i;
if (!up) {
switch (stafflines) { // lower ledger lines
case 0:
case 1: i = 6; break;
case 2:
case 3: i = 0; break;
default: i = -6; break;
}
for ( ; i >= y; i -= 6) {
putxy(x, staffb + i);
a2b("%s ", hltype);
}
return;
}
switch (stafflines) { // upper ledger lines
case 0:
case 1:
case 2: i = 18; break;
case 3: i = 24; break;
default: i = stafflines * 6; break;
}
for ( ; i <= y; i += 6) {
putxy(x, staffb + i);
a2b("%s ", hltype);
}
}
/* -- draw a key signature -- */
static void draw_keysig(struct VOICE_S *p_voice,