-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
tlayout.cpp
6666 lines (5781 loc) · 246 KB
/
tlayout.cpp
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
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-Studio-CLA-applies
*
* MuseScore Studio
* Music Composition & Notation
*
* Copyright (C) 2023 MuseScore Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 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, see <https://www.gnu.org/licenses/>.
*/
#include <cfloat>
#include "tlayout.h"
#include "global/realfn.h"
#include "global/types/number.h"
#include "draw/fontmetrics.h"
#include "iengravingconfiguration.h"
#include "infrastructure/rtti.h"
#include "infrastructure/ld_access.h"
#include "iengravingfont.h"
#include "types/typesconv.h"
#include "types/symnames.h"
#include "dom/score.h"
#include "dom/utils.h"
#include "dom/accidental.h"
#include "dom/ambitus.h"
#include "dom/arpeggio.h"
#include "dom/articulation.h"
#include "dom/barline.h"
#include "dom/beam.h"
#include "dom/bend.h"
#include "dom/box.h"
#include "dom/bracket.h"
#include "dom/breath.h"
#include "dom/chord.h"
#include "dom/chordline.h"
#include "dom/clef.h"
#include "dom/capo.h"
#include "dom/deadslapped.h"
#include "dom/dynamic.h"
#include "dom/expression.h"
#include "dom/fermata.h"
#include "dom/figuredbass.h"
#include "dom/fingering.h"
#include "dom/fret.h"
#include "dom/glissando.h"
#include "dom/gradualtempochange.h"
#include "dom/guitarbend.h"
#include "dom/hairpin.h"
#include "dom/harppedaldiagram.h"
#include "dom/harmonicmark.h"
#include "dom/harmony.h"
#include "dom/hook.h"
#include "dom/image.h"
#include "dom/instrchange.h"
#include "dom/instrumentname.h"
#include "dom/jump.h"
#include "dom/keysig.h"
#include "dom/layoutbreak.h"
#include "dom/ledgerline.h"
#include "dom/letring.h"
#include "dom/line.h"
#include "dom/lyrics.h"
#include "dom/marker.h"
#include "dom/measurebase.h"
#include "dom/measurenumber.h"
#include "dom/measurenumberbase.h"
#include "dom/measurerepeat.h"
#include "dom/mmrest.h"
#include "dom/mmrestrange.h"
#include "dom/note.h"
#include "dom/notedot.h"
#include "dom/ornament.h"
#include "dom/ottava.h"
#include "dom/page.h"
#include "dom/palmmute.h"
#include "dom/part.h"
#include "dom/pedal.h"
#include "dom/pickscrape.h"
#include "dom/playtechannotation.h"
#include "dom/rasgueado.h"
#include "dom/rehearsalmark.h"
#include "dom/rest.h"
#include "dom/shadownote.h"
#include "dom/slur.h"
#include "dom/spacer.h"
#include "dom/staff.h"
#include "dom/stafflines.h"
#include "dom/staffstate.h"
#include "dom/stafftext.h"
#include "dom/stafftype.h"
#include "dom/stafftypechange.h"
#include "dom/stem.h"
#include "dom/stemslash.h"
#include "dom/sticking.h"
#include "dom/stringtunings.h"
#include "dom/stretchedbend.h"
#include "dom/bsymbol.h"
#include "dom/symbol.h"
#include "dom/system.h"
#include "dom/systemdivider.h"
#include "dom/systemtext.h"
#include "dom/soundflag.h"
#include "dom/tempotext.h"
#include "dom/text.h"
#include "dom/textline.h"
#include "dom/tie.h"
#include "dom/timesig.h"
#include "dom/tremolosinglechord.h"
#include "dom/tremolotwochord.h"
#include "dom/tremolobar.h"
#include "dom/trill.h"
#include "dom/tripletfeel.h"
#include "dom/tuplet.h"
#include "dom/vibrato.h"
#include "dom/volta.h"
#include "dom/whammybar.h"
#include "accidentalslayout.h"
#include "arpeggiolayout.h"
#include "autoplace.h"
#include "beamlayout.h"
#include "chordlayout.h"
#include "guitarbendlayout.h"
#include "lyricslayout.h"
#include "slurtielayout.h"
#include "tremololayout.h"
#include "tupletlayout.h"
#include "horizontalspacing.h"
using namespace muse;
using namespace muse::draw;
using namespace mu::engraving;
using namespace mu::engraving::rtti;
using namespace mu::engraving::rendering::dev;
#define LAYOUT_CALL_ITEM(item) LAYOUT_CALL() << LAYOUT_ITEM_INFO(item);
void TLayout::layoutItem(EngravingItem* item, LayoutContext& ctx)
{
//DO_ASSERT(!ctx.conf().isPaletteMode());
EngravingItem::LayoutData* ldata = item->mutldata();
switch (item->type()) {
case ElementType::ACCIDENTAL:
layoutAccidental(item_cast<const Accidental*>(item), static_cast<Accidental::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::ACTION_ICON:
layoutActionIcon(item_cast<const ActionIcon*>(item), static_cast<ActionIcon::LayoutData*>(ldata));
break;
case ElementType::AMBITUS:
layoutAmbitus(item_cast<const Ambitus*>(item), static_cast<Ambitus::LayoutData*>(ldata), ctx);
break;
case ElementType::ARPEGGIO:
layoutArpeggio(item_cast<const Arpeggio*>(item), static_cast<Arpeggio::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::ARTICULATION:
layoutArticulation(item_cast<const Articulation*>(item), static_cast<Articulation::LayoutData*>(ldata));
break;
case ElementType::BAR_LINE:
layoutBarLine(item_cast<const BarLine*>(item), static_cast<BarLine::LayoutData*>(ldata), ctx);
break;
case ElementType::BEAM: layoutBeam(item_cast<Beam*>(item), ctx);
break;
case ElementType::BEND:
layoutBend(item_cast<const Bend*>(item), static_cast<Bend::LayoutData*>(ldata));
break;
case ElementType::STRETCHED_BEND: layoutStretchedBend(item_cast<StretchedBend*>(item), ctx);
break;
case ElementType::HBOX:
layoutHBox(item_cast<const HBox*>(item), static_cast<HBox::LayoutData*>(ldata), ctx);
break;
case ElementType::VBOX:
layoutVBox(item_cast<const VBox*>(item), static_cast<VBox::LayoutData*>(ldata), ctx);
break;
case ElementType::FBOX:
layoutFBox(item_cast<const FBox*>(item), static_cast<FBox::LayoutData*>(ldata), ctx);
break;
case ElementType::TBOX:
layoutTBox(item_cast<const TBox*>(item), static_cast<TBox::LayoutData*>(ldata), ctx);
break;
case ElementType::BRACKET:
layoutBracket(item_cast<const Bracket*>(item), static_cast<Bracket::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::BREATH:
layoutBreath(item_cast<const Breath*>(item), static_cast<Breath::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::CHORD: layoutChord(item_cast<Chord*>(item), ctx);
break;
case ElementType::CHORDLINE:
layoutChordLine(item_cast<const ChordLine*>(item), static_cast<ChordLine::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::CLEF:
layoutClef(item_cast<const Clef*>(item), static_cast<Clef::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::CAPO:
layoutCapo(item_cast<const Capo*>(item), static_cast<Capo::LayoutData*>(ldata), ctx);
break;
case ElementType::DEAD_SLAPPED:
layoutDeadSlapped(item_cast<const DeadSlapped*>(item), static_cast<DeadSlapped::LayoutData*>(ldata));
break;
case ElementType::DYNAMIC:
layoutDynamic(item_cast<Dynamic*>(item), static_cast<Dynamic::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::EXPRESSION:
layoutExpression(item_cast<const Expression*>(item), static_cast<Expression::LayoutData*>(ldata));
break;
case ElementType::FERMATA:
layoutFermata(item_cast<const Fermata*>(item), static_cast<Fermata::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::FIGURED_BASS:
layoutFiguredBass(item_cast<const FiguredBass*>(item), static_cast<FiguredBass::LayoutData*>(ldata), ctx);
break;
case ElementType::FINGERING:
layoutFingering(item_cast<const Fingering*>(item), static_cast<Fingering::LayoutData*>(ldata));
break;
case ElementType::FRET_DIAGRAM:
layoutFretDiagram(item_cast<const FretDiagram*>(item), static_cast<FretDiagram::LayoutData*>(ldata), ctx);
break;
case ElementType::GLISSANDO: layoutGlissando(item_cast<Glissando*>(item), ctx);
break;
case ElementType::GLISSANDO_SEGMENT: layoutGlissandoSegment(item_cast<GlissandoSegment*>(item), ctx);
break;
case ElementType::GRADUAL_TEMPO_CHANGE: layoutGradualTempoChange(item_cast<GradualTempoChange*>(item), ctx);
break;
case ElementType::GRADUAL_TEMPO_CHANGE_SEGMENT: layoutGradualTempoChangeSegment(item_cast<GradualTempoChangeSegment*>(item), ctx);
break;
case ElementType::GUITAR_BEND: layoutGuitarBend(item_cast<GuitarBend*>(item), ctx);
break;
case ElementType::GUITAR_BEND_SEGMENT: layoutGuitarBendSegment(item_cast<GuitarBendSegment*>(item), ctx);
break;
case ElementType::GUITAR_BEND_HOLD_SEGMENT: GuitarBendLayout::layoutHoldLine(item_cast<GuitarBendHoldSegment*>(item));
break;
case ElementType::HAIRPIN: layoutHairpin(item_cast<Hairpin*>(item), ctx);
break;
case ElementType::HAIRPIN_SEGMENT: layoutHairpinSegment(item_cast<HairpinSegment*>(item), ctx);
break;
case ElementType::HARP_DIAGRAM:
layoutHarpPedalDiagram(item_cast<const HarpPedalDiagram*>(item), static_cast<HarpPedalDiagram::LayoutData*>(ldata));
break;
case ElementType::HARMONY:
layoutHarmony(item_cast<const Harmony*>(item), static_cast<Harmony::LayoutData*>(ldata), ctx);
break;
case ElementType::HARMONIC_MARK_SEGMENT: layoutHarmonicMarkSegment(item_cast<HarmonicMarkSegment*>(item), ctx);
break;
case ElementType::HOOK:
layoutHook(item_cast<const Hook*>(item), static_cast<Hook::LayoutData*>(ldata));
break;
case ElementType::IMAGE:
layoutImage(item_cast<const Image*>(item), static_cast<Image::LayoutData*>(ldata));
break;
case ElementType::INSTRUMENT_CHANGE:
layoutInstrumentChange(item_cast<const InstrumentChange*>(item), static_cast<InstrumentChange::LayoutData*>(ldata));
break;
case ElementType::INSTRUMENT_NAME:
layoutInstrumentName(item_cast<const InstrumentName*>(item), static_cast<InstrumentName::LayoutData*>(ldata));
break;
case ElementType::JUMP:
layoutJump(item_cast<const Jump*>(item), static_cast<Jump::LayoutData*>(ldata));
break;
case ElementType::KEYSIG:
layoutKeySig(item_cast<const KeySig*>(item), static_cast<KeySig::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::LAYOUT_BREAK:
layoutLayoutBreak(item_cast<const LayoutBreak*>(item), static_cast<LayoutBreak::LayoutData*>(ldata));
break;
case ElementType::LET_RING: layoutLetRing(item_cast<LetRing*>(item), ctx);
break;
case ElementType::LET_RING_SEGMENT: layoutLetRingSegment(item_cast<LetRingSegment*>(item), ctx);
break;
case ElementType::LEDGER_LINE: layoutLedgerLine(item_cast<LedgerLine*>(item), ctx);
break;
case ElementType::LYRICS: layoutLyrics(item_cast<Lyrics*>(item), ctx);
break;
case ElementType::LYRICSLINE_SEGMENT: layoutLyricsLineSegment(item_cast<LyricsLineSegment*>(item), ctx);
break;
case ElementType::MARKER:
layoutMarker(item_cast<const Marker*>(item), static_cast<Marker::LayoutData*>(ldata));
break;
case ElementType::MEASURE_NUMBER:
layoutMeasureNumber(item_cast<const MeasureNumber*>(item), static_cast<MeasureNumber::LayoutData*>(ldata));
break;
case ElementType::MEASURE_REPEAT:
layoutMeasureRepeat(item_cast<const MeasureRepeat*>(item), static_cast<MeasureRepeat::LayoutData*>(ldata), ctx);
break;
case ElementType::MMREST:
layoutMMRest(item_cast<const MMRest*>(item), static_cast<MMRest::LayoutData*>(ldata), ctx);
break;
case ElementType::MMREST_RANGE:
layoutMMRestRange(item_cast<const MMRestRange*>(item), static_cast<MMRestRange::LayoutData*>(ldata));
break;
case ElementType::NOTE:
layoutNote(item_cast<const Note*>(item), static_cast<Note::LayoutData*>(ldata));
break;
case ElementType::NOTEDOT:
layoutNoteDot(item_cast<const NoteDot*>(item), static_cast<NoteDot::LayoutData*>(ldata));
break;
case ElementType::NOTEHEAD:
layoutSymbol(item_cast<const NoteHead*>(item), static_cast<NoteHead::LayoutData*>(ldata), ctx);
break;
case ElementType::ORNAMENT:
layoutOrnament(item_cast<const Ornament*>(item), static_cast<Ornament::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::OTTAVA: layoutOttava(item_cast<Ottava*>(item), ctx);
break;
case ElementType::OTTAVA_SEGMENT: layoutOttavaSegment(item_cast<OttavaSegment*>(item), ctx);
break;
case ElementType::PALM_MUTE: layoutPalmMute(item_cast<PalmMute*>(item), ctx);
break;
case ElementType::PALM_MUTE_SEGMENT: layoutPalmMuteSegment(item_cast<PalmMuteSegment*>(item), ctx);
break;
case ElementType::PEDAL: layoutPedal(item_cast<Pedal*>(item), ctx);
break;
case ElementType::PEDAL_SEGMENT: layoutPedalSegment(item_cast<PedalSegment*>(item), ctx);
break;
case ElementType::PICK_SCRAPE_SEGMENT: layoutPickScrapeSegment(item_cast<PickScrapeSegment*>(item), ctx);
break;
case ElementType::PLAYTECH_ANNOTATION:
layoutPlayTechAnnotation(item_cast<const PlayTechAnnotation*>(item), static_cast<PlayTechAnnotation::LayoutData*>(ldata));
break;
case ElementType::RASGUEADO_SEGMENT: layoutRasgueadoSegment(item_cast<RasgueadoSegment*>(item), ctx);
break;
case ElementType::REHEARSAL_MARK:
layoutRehearsalMark(item_cast<const RehearsalMark*>(item), static_cast<RehearsalMark::LayoutData*>(ldata));
break;
case ElementType::REST:
layoutRest(item_cast<const Rest*>(item), static_cast<Rest::LayoutData*>(ldata), ctx);
break;
case ElementType::SHADOW_NOTE: layoutShadowNote(item_cast<ShadowNote*>(item), ctx);
break;
case ElementType::SLUR: layoutSlur(item_cast<Slur*>(item), ctx);
break;
case ElementType::SPACER: layoutSpacer(item_cast<Spacer*>(item), ctx);
break;
case ElementType::STAFF_STATE:
layoutStaffState(item_cast<const StaffState*>(item), static_cast<StaffState::LayoutData*>(ldata));
break;
case ElementType::STAFF_TEXT:
layoutStaffText(item_cast<const StaffText*>(item), static_cast<StaffText::LayoutData*>(ldata));
break;
case ElementType::STAFFTYPE_CHANGE:
layoutStaffTypeChange(item_cast<const StaffTypeChange*>(item), static_cast<StaffTypeChange::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::SOUND_FLAG:
layoutSoundFlag(item_cast<const SoundFlag*>(item), static_cast<SoundFlag::LayoutData*>(ldata));
break;
case ElementType::STEM:
layoutStem(item_cast<const Stem*>(item), static_cast<Stem::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::STEM_SLASH:
layoutStemSlash(item_cast<const StemSlash*>(item), static_cast<StemSlash::LayoutData*>(ldata), ctx.conf());
break;
case ElementType::STICKING:
layoutSticking(item_cast<const Sticking*>(item), static_cast<Sticking::LayoutData*>(ldata));
break;
case ElementType::STRING_TUNINGS:
layoutStringTunings(item_cast<StringTunings*>(item), ctx);
break;
case ElementType::SYMBOL:
layoutSymbol(item_cast<const Symbol*>(item), static_cast<Symbol::LayoutData*>(ldata), ctx);
break;
case ElementType::FSYMBOL:
layoutFSymbol(item_cast<const FSymbol*>(item), static_cast<FSymbol::LayoutData*>(ldata));
break;
case ElementType::SYSTEM_DIVIDER:
layoutSystemDivider(item_cast<const SystemDivider*>(item), static_cast<SystemDivider::LayoutData*>(ldata), ctx);
break;
case ElementType::SYSTEM_TEXT:
layoutSystemText(item_cast<const SystemText*>(item), static_cast<SystemText::LayoutData*>(ldata));
break;
case ElementType::TEMPO_TEXT:
layoutTempoText(item_cast<const TempoText*>(item), static_cast<TempoText::LayoutData*>(ldata));
break;
case ElementType::TEXT:
layoutText(item_cast<const Text*>(item), static_cast<Text::LayoutData*>(ldata));
break;
case ElementType::TEXTLINE: layoutTextLine(item_cast<TextLine*>(item), ctx);
break;
case ElementType::TEXTLINE_SEGMENT: layoutTextLineSegment(item_cast<TextLineSegment*>(item), ctx);
break;
case ElementType::TIE: layoutTie(item_cast<Tie*>(item), ctx);
break;
case ElementType::TIMESIG:
layoutTimeSig(item_cast<const TimeSig*>(item), static_cast<TimeSig::LayoutData*>(ldata), ctx);
break;
case ElementType::TIME_TICK_ANCHOR: layoutTimeTickAnchor(static_cast<TimeTickAnchor*>(item), ctx);
break;
case ElementType::TREMOLO_SINGLECHORD: layoutTremoloSingle(item_cast<TremoloSingleChord*>(item), ctx);
break;
case ElementType::TREMOLO_TWOCHORD: layoutTremoloTwo(item_cast<TremoloTwoChord*>(item), ctx);
break;
case ElementType::TREMOLOBAR:
layoutTremoloBar(item_cast<const TremoloBar*>(item), static_cast<TremoloBar::LayoutData*>(ldata));
break;
case ElementType::TRILL: layoutTrill(item_cast<Trill*>(item), ctx);
break;
case ElementType::TRILL_SEGMENT: layoutTrillSegment(item_cast<TrillSegment*>(item), ctx);
break;
case ElementType::TRIPLET_FEEL:
layoutTripletFeel(item_cast<const TripletFeel*>(item), static_cast<TripletFeel::LayoutData*>(ldata));
break;
case ElementType::TUPLET: layoutTuplet(item_cast<Tuplet*>(item), ctx);
break;
case ElementType::VIBRATO: layoutVibrato(item_cast<Vibrato*>(item), ctx);
break;
case ElementType::VIBRATO_SEGMENT: layoutVibratoSegment(item_cast<VibratoSegment*>(item), ctx);
break;
case ElementType::VOLTA: layoutVolta(item_cast<Volta*>(item), ctx);
break;
case ElementType::VOLTA_SEGMENT: layoutVoltaSegment(item_cast<VoltaSegment*>(item), ctx);
break;
case ElementType::WHAMMY_BAR_SEGMENT: layoutWhammyBarSegment(item_cast<WhammyBarSegment*>(item), ctx);
break;
default:
LOGE() << "not found in layout types item: " << item->typeName();
DO_ASSERT(false);
}
}
void TLayout::layoutAccidental(const Accidental* item, Accidental::LayoutData* ldata, const LayoutConfiguration& conf)
{
LAYOUT_CALL_ITEM(item);
LD_INDEPENDENT;
if (ldata->isValid()) {
return;
}
ldata->syms.clear();
// TODO: remove Accidental in layout
// don't show accidentals for tab or slash notation
if (item->onTabStaff() || (item->note() && item->note()->fixed())) {
ldata->setIsSkipDraw(true);
return;
}
ldata->setIsSkipDraw(false);
ldata->setPos(PointF());
if (item->accidentalType() == AccidentalType::NONE) {
return;
}
ldata->column = 0;
auto accidentalSingleSym = [](const Accidental* item) -> SymId
{
// if the accidental is standard (doubleflat, flat, natural, sharp or double sharp)
// and it has either no bracket or parentheses, then we have glyphs straight from smufl.
if (item->bracket() == AccidentalBracket::PARENTHESIS && !item->parentNoteHasParentheses()) {
switch (item->accidentalType()) {
case AccidentalType::FLAT: return SymId::accidentalFlatParens;
case AccidentalType::FLAT2: return SymId::accidentalDoubleFlatParens;
case AccidentalType::NATURAL: return SymId::accidentalNaturalParens;
case AccidentalType::SHARP: return SymId::accidentalSharpParens;
case AccidentalType::SHARP2: return SymId::accidentalDoubleSharpParens;
default:
break;
}
}
return SymId::noSym;
};
auto accidentalBracketSyms = [](AccidentalBracket type) -> std::pair<SymId, SymId>
{
switch (type) {
case AccidentalBracket::PARENTHESIS: return { SymId::accidentalParensLeft, SymId::accidentalParensRight };
case AccidentalBracket::BRACKET: return { SymId::accidentalBracketLeft, SymId::accidentalBracketRight };
case AccidentalBracket::BRACE: return { SymId::accidentalCombiningOpenCurlyBrace, SymId::accidentalCombiningCloseCurlyBrace };
case AccidentalBracket::NONE: return { SymId::noSym, SymId::noSym };
}
return { SymId::noSym, SymId::noSym };
};
Shape shape;
// Single?
SymId singleSym = accidentalSingleSym(item);
if (singleSym != SymId::noSym && conf.engravingFont()->isValid(singleSym)) {
Accidental::LayoutData::Sym s(singleSym, 0.0, 0.0);
ldata->syms.push_back(s);
shape.add(item->symShapeWithCutouts(singleSym));
}
// Multi
else {
double margin = conf.styleMM(Sid::bracketedAccidentalPadding);
double x = 0.0;
std::pair<SymId, SymId> bracketSyms;
bool isNeedBracket = item->bracket() != AccidentalBracket::NONE && !item->parentNoteHasParentheses();
if (isNeedBracket) {
bracketSyms = accidentalBracketSyms(item->bracket());
}
// Left
if (bracketSyms.first != SymId::noSym) {
Accidental::LayoutData::Sym ls(bracketSyms.first, 0.0,
item->bracket() == AccidentalBracket::BRACE ? item->spatium() * 0.4 : 0.0);
ldata->syms.push_back(ls);
shape.add(item->symBbox(bracketSyms.first), item);
x += item->symAdvance(bracketSyms.first) + margin;
}
// Main
SymId mainSym = item->symId();
Accidental::LayoutData::Sym ms(mainSym, x, 0.0);
ldata->syms.push_back(ms);
shape.add(item->symShapeWithCutouts(mainSym).translated(PointF(x, 0.0)));
// Right
if (bracketSyms.second != SymId::noSym) {
x += item->symAdvance(mainSym) + margin;
Accidental::LayoutData::Sym rs(bracketSyms.second, x,
item->bracket() == AccidentalBracket::BRACE ? item->spatium() * 0.4 : 0.0);
ldata->syms.push_back(rs);
shape.add(item->symBbox(bracketSyms.second).translated(x, 0.0), item);
}
}
ldata->setShape(shape);
}
void TLayout::layoutActionIcon(const ActionIcon* item, ActionIcon::LayoutData* ldata)
{
LAYOUT_CALL_ITEM(item);
LD_INDEPENDENT;
if (ldata->isValid()) {
return;
}
FontMetrics fontMetrics(item->iconFont());
ldata->setBbox(fontMetrics.boundingRect(Char(item->icon())));
ldata->setPos(PointF());
}
void TLayout::layoutAmbitus(const Ambitus* item, Ambitus::LayoutData* ldata, const LayoutContext& ctx)
{
LAYOUT_CALL_ITEM(item);
LD_INDEPENDENT;
if (ldata->isValid()) {
return;
}
const double spatium = item->spatium();
const double headWdt = item->headWidth();
Accidental::LayoutData* topAccData = item->topAccidental()->mutldata();
Accidental::LayoutData* bottomAccData = item->bottomAccidental()->mutldata();
ldata->setPos(PointF());
//
// NOTEHEADS Y POS
//
{
const Fraction tick = item->segment()->tick();
const Staff* stf = ctx.dom().staff(item->staffIdx());
const ClefType clf = stf->clef(tick);
const Key key = stf->key(tick);
const double lineDist = stf->lineDistance(tick) * spatium;
// top notehead
if (item->topPitch() == INVALID_PITCH || item->topTpc() == Tpc::TPC_INVALID) {
ldata->topPos.setY(0.0); // if uninitialized, set to top staff line
} else {
int topLine = Ambitus::staffLine(item->topTpc(), item->topPitch(), clf);
ldata->topPos.setY(topLine * lineDist * 0.5);
// compute accidental
AccidentalType accidType = Ambitus::accidentalType(item->topTpc(), key);
item->topAccidental()->setAccidentalType(accidType);
TLayout::layoutAccidental(item->topAccidental(), topAccData, ctx.conf());
topAccData->setPosY(ldata->topPos.y());
}
// bottom notehead
if (item->bottomPitch() == INVALID_PITCH || item->bottomTpc() == Tpc::TPC_INVALID) {
const int numOfLines = stf->lines(tick);
ldata->bottomPos.setY((numOfLines - 1) * lineDist); // if uninitialized, set to last staff line
} else {
int bottomLine = Ambitus::staffLine(item->bottomTpc(), item->bottomPitch(), clf);
ldata->bottomPos.setY(bottomLine * lineDist * 0.5);
// compute accidental
AccidentalType accidType = Ambitus::accidentalType(item->bottomTpc(), key);
item->bottomAccidental()->setAccidentalType(accidType);
TLayout::layoutAccidental(item->bottomAccidental(), bottomAccData, ctx.conf());
bottomAccData->setPosY(ldata->bottomPos.y());
}
}
//
// NOTEHEAD X POS
//
// Note: manages colliding accidentals
//
{
double accNoteDist = item->point(ctx.conf().styleS(Sid::accidentalNoteDistance));
double xAccidOffTop = topAccData->bbox().width() + accNoteDist;
double xAccidOffBottom = bottomAccData->bbox().width() + accNoteDist;
// if top accidental extends down more than bottom accidental extends up,
// AND ambitus is not leaning right, bottom accidental needs to be displaced
bool collision = (item->direction() != DirectionH::RIGHT)
&& (topAccData->pos().y() + topAccData->bbox().y() + topAccData->bbox().height()
> bottomAccData->pos().y() + bottomAccData->bbox().y());
if (collision) {
// displace bottom accidental (also attempting to 'undercut' flats)
AccidentalType bottomAccType = item->bottomAccidental()->accidentalType();
xAccidOffBottom = xAccidOffTop + ((bottomAccType == AccidentalType::FLAT
|| bottomAccType == AccidentalType::FLAT2
|| bottomAccType == AccidentalType::NATURAL)
? bottomAccData->bbox().width() * 0.5 : bottomAccData->bbox().width());
}
switch (item->direction()) {
case DirectionH::AUTO: // noteheads one above the other
// left align noteheads and right align accidentals 'hanging' on the left
ldata->topPos.setX(0.0);
ldata->bottomPos.setX(0.0);
topAccData->setPosX(-xAccidOffTop);
bottomAccData->setPosX(-xAccidOffBottom);
break;
case DirectionH::LEFT: // top notehead at the left of bottom notehead
// place top notehead at left margin; bottom notehead at right of top head;
// top accid. 'hanging' on left of top head and bottom accid. 'hanging' at left of bottom head
ldata->topPos.setX(0.0);
ldata->bottomPos.setX(headWdt);
topAccData->setPosX(-xAccidOffTop);
bottomAccData->setPosX(collision ? -xAccidOffBottom : headWdt - xAccidOffBottom);
break;
case DirectionH::RIGHT: // top notehead at the right of bottom notehead
// bottom notehead at left margin; top notehead at right of bottomnotehead
// top accid. 'hanging' on left of top head and bottom accid. 'hanging' at left of bottom head
ldata->topPos.setX(headWdt);
ldata->bottomPos.setX(0.0);
topAccData->setPosX(headWdt - xAccidOffTop);
bottomAccData->setPosX(-xAccidOffBottom);
break;
}
}
// LINE
// compute line from top note centre to bottom note centre
{
LineF fullLine(ldata->topPos.x() + headWdt * 0.5,
ldata->topPos.y(),
ldata->bottomPos.x() + headWdt * 0.5,
ldata->bottomPos.y());
// shorten line on each side by offsets
double yDelta = ldata->bottomPos.y() - ldata->topPos.y();
if (!muse::RealIsNull(yDelta)) {
double off = spatium * Ambitus::LINEOFFSET_DEFAULT;
PointF p1 = fullLine.pointAt(off / yDelta);
PointF p2 = fullLine.pointAt(1 - (off / yDelta));
ldata->line = LineF(p1, p2);
} else {
ldata->line = fullLine;
}
}
// BBOX
{
RectF headRect(0, -0.5 * spatium, headWdt, 1 * spatium);
ldata->setBbox(headRect.translated(ldata->topPos).united(headRect.translated(ldata->bottomPos))
.united(topAccData->bbox().translated(topAccData->pos()))
.united(bottomAccData->bbox().translated(bottomAccData->pos())));
}
}
void TLayout::layoutArpeggio(const Arpeggio* item, Arpeggio::LayoutData* ldata, const LayoutConfiguration& conf,
bool includeCrossStaffHeight)
{
LAYOUT_CALL_ITEM(item);
UNUSED(includeCrossStaffHeight);
//! NOTE Can be edited and relayout,
//! in this case the reset layout data has not yet been done
// if (ldata->isValid()) {
// return;
// }
if (conf.styleB(Sid::ArpeggioHiddenInStdIfTab)) {
if (item->staff() && item->staff()->isPitchedStaff(item->tick())) {
for (Staff* s : item->staff()->staffList()) {
if (s->onSameScore(item) && s->isTabStaff(item->tick()) && s->visible()) {
ldata->setIsSkipDraw(true);
}
}
}
}
ldata->setIsSkipDraw(false);
if (!ldata->isSetPos()) {
ldata->setPos(PointF());
}
IF_ASSERT_FAILED(item->explicitParent()) {
return;
}
//! NOTE Must already be set previously
Chord* parentChord = item->chord();
LD_CONDITION(parentChord->upNote()->ldata()->isSetPos());
LD_CONDITION(parentChord->downNote()->ldata()->isSetPos());
auto computeHeight = [](const Arpeggio* item) -> double
{
Chord* chord = item->chord();
double y = chord->upNote()->pagePos().y() - chord->upNote()->headHeight() * .5;
Note* downNote = chord->downNote();
EngravingItem* e = chord->segment()->element(item->track() + item->span() - 1);
if (e && e->isChord()) {
downNote = toChord(e)->downNote();
}
double h = downNote->pagePos().y() + downNote->headHeight() * .5 - y;
return h;
};
auto calcTop = [](const Arpeggio* item, const LayoutConfiguration& conf) -> double
{
double top = -item->userLen1();
switch (item->arpeggioType()) {
case ArpeggioType::BRACKET: {
double lineWidth = conf.styleMM(Sid::ArpeggioLineWidth);
return top - lineWidth / 2.0;
}
case ArpeggioType::NORMAL:
case ArpeggioType::UP:
case ArpeggioType::DOWN: {
// if the top is in the staff on a space, move it up
// if the bottom note is on a line, the distance is 0.25 spaces
// if the bottom note is on a space, the distance is 0.5 spaces
int topNoteLine = item->chord()->upNote()->line();
int lines = item->staff()->lines(item->tick());
int bottomLine = (lines - 1) * 2;
if (topNoteLine <= 0 || topNoteLine % 2 == 0 || topNoteLine >= bottomLine) {
return top;
}
int downNoteLine = item->chord()->downNote()->line();
if (downNoteLine % 2 == 1 && downNoteLine < bottomLine) {
return top - 0.4 * item->spatium();
}
return top - 0.25 * item->spatium();
}
default: {
return top - item->spatium() / 4;
}
}
};
auto calcBottom = [](const Arpeggio* item, double arpeggioHeight, const LayoutConfiguration& conf) -> double
{
double top = -item->userLen1();
double bottom = arpeggioHeight + item->userLen2();
switch (item->arpeggioType()) {
case ArpeggioType::BRACKET: {
double lineWidth = conf.styleMM(Sid::ArpeggioLineWidth);
return bottom - top + lineWidth;
}
case ArpeggioType::NORMAL:
case ArpeggioType::UP:
case ArpeggioType::DOWN: {
return bottom;
}
default: {
return bottom - top + item->spatium() / 2;
}
}
};
auto symbolLine = [](const std::shared_ptr<const IEngravingFont>& f, Arpeggio::LayoutData* data, SymId end, SymId fill)
{
data->symbols.clear();
double w = data->bottom - data->top;
double w1 = f->advance(end, data->magS);
double w2 = f->advance(fill, data->magS);
int n = lrint((w - w1) / w2);
for (int i = 0; i < n; ++i) {
data->symbols.push_back(fill);
}
data->symbols.push_back(end);
};
ldata->arpeggioHeight = computeHeight(item);
ldata->top = calcTop(item, conf);
ldata->bottom = calcBottom(item, ldata->arpeggioHeight, conf);
ldata->setMag(item->staff() ? item->staff()->staffMag(item->tick()) : item->mag());
ldata->magS = conf.magS(ldata->mag());
std::shared_ptr<const IEngravingFont> font = conf.engravingFont();
switch (item->arpeggioType()) {
case ArpeggioType::NORMAL: {
symbolLine(font, ldata, SymId::wiggleArpeggiatoUp, SymId::wiggleArpeggiatoUp);
// string is rotated -90 degrees
ldata->symsBBox = font->bbox(ldata->symbols, ldata->magS);
ldata->setBbox(RectF(0.0, -ldata->symsBBox.x() + ldata->top, ldata->symsBBox.height(), ldata->symsBBox.width()));
} break;
case ArpeggioType::UP: {
symbolLine(font, ldata, SymId::wiggleArpeggiatoUpArrow, SymId::wiggleArpeggiatoUp);
// string is rotated -90 degrees
ldata->symsBBox = font->bbox(ldata->symbols, ldata->magS);
ldata->setBbox(RectF(0.0, -ldata->symsBBox.x() + ldata->top, ldata->symsBBox.height(), ldata->symsBBox.width()));
} break;
case ArpeggioType::DOWN: {
symbolLine(font, ldata, SymId::wiggleArpeggiatoUpArrow, SymId::wiggleArpeggiatoUp);
// string is rotated +90 degrees (so that UpArrow turns into a DownArrow)
ldata->symsBBox = font->bbox(ldata->symbols, ldata->magS);
ldata->setBbox(RectF(0.0, ldata->symsBBox.x() + ldata->top, ldata->symsBBox.height(), ldata->symsBBox.width()));
} break;
case ArpeggioType::UP_STRAIGHT: {
double x1 = item->spatium() * 0.5;
ldata->symsBBox = font->bbox(SymId::arrowheadBlackUp, ldata->magS);
double w = ldata->symsBBox.width();
ldata->setBbox(RectF(x1 - w * 0.5, ldata->top, w, ldata->bottom));
} break;
case ArpeggioType::DOWN_STRAIGHT: {
double x1 = item->spatium() * 0.5;
ldata->symsBBox = font->bbox(SymId::arrowheadBlackDown, ldata->magS);
double w = ldata->symsBBox.width();
ldata->setBbox(RectF(x1 - w * 0.5, ldata->top, w, ldata->bottom));
} break;
case ArpeggioType::BRACKET: {
double w = conf.styleS(Sid::ArpeggioHookLen).val() * item->spatium();
ldata->setBbox(RectF(0.0, ldata->top, w, ldata->bottom));
} break;
}
// Loop through staves spanned & regenerate chord shape
// This makes sure the arpeggio's shape is added to the shape of each chord it spans
Chord* chord = item->chord();
Segment* seg = chord->segment();
staff_idx_t staveSpan = (item->track() + item->span() - 1) / VOICES;
for (staff_idx_t staffIdx = item->staffIdx(); staffIdx <= staveSpan; staffIdx++) {
seg->createShape(staffIdx);
}
}
void TLayout::layoutArticulation(const Articulation* item, Articulation::LayoutData* ldata)
{
LAYOUT_CALL_ITEM(item);
if (item->isHiddenOnTabStaff()) {
ldata->setIsSkipDraw(true);
return;
}
ldata->setIsSkipDraw(false);
ldata->setPos(PointF());
//! NOTE Must already be set previously
LD_CONDITION(ldata->symId.has_value());
RectF bbox;
if (item->textType() == ArticulationTextType::NO_TEXT) {
bbox = item->symBbox(ldata->symId);
} else {
Font scaledFont(item->font());
scaledFont.setPointSizeF(item->font().pointSizeF() * item->magS());
FontMetrics fm(scaledFont);
bbox = fm.boundingRect(scaledFont, TConv::text(item->textType()));
}
ldata->setBbox(bbox.translated(-0.5 * bbox.width(), 0.0));
fillArticulationShape(item, ldata);
}
void TLayout::fillArticulationShape(const Articulation* item, Articulation::LayoutData* ldata)
{
LAYOUT_CALL_ITEM(item);
SymId sym = item->symId();
if (sym == SymId::articAccentAbove || sym == SymId::articAccentBelow) {
RectF symBbox = item->symBbox(sym);
double width = symBbox.width();
double height = symBbox.height();
double thirdWidth = width / 3;
double thirdHeight = height / 3;
RectF base = RectF(0.0, 0.0, thirdWidth, height);
RectF center = RectF(thirdWidth, thirdHeight, thirdWidth, thirdHeight);
RectF tip = RectF(2 * thirdWidth, 1.25 * thirdHeight, thirdWidth, 0.5 * thirdHeight);
Shape shape;
shape.add(base, item);
shape.add(center, item);
shape.add(tip, item);
PointF translate(-0.5 * width, sym == SymId::articAccentAbove ? -height : 0.0);
ldata->setShape(shape.translate(translate));
} else {
ldata->setShape(Shape(ldata->bbox(), item));
}
}
static double barLineWidth(const BarLine* item, const MStyle& style, double dotWidth)
{
double w = 0.0;
switch (item->barLineType()) {
case BarLineType::DOUBLE:
w = style.styleMM(Sid::doubleBarWidth) * 2.0
+ style.styleMM(Sid::doubleBarDistance);
break;
case BarLineType::DOUBLE_HEAVY:
w = style.styleMM(Sid::endBarWidth) * 2.0
+ style.styleMM(Sid::endBarDistance);
break;
case BarLineType::END_START_REPEAT:
w = style.styleMM(Sid::endBarWidth)
+ style.styleMM(Sid::barWidth) * 2.0
+ style.styleMM(Sid::endBarDistance) * 2.0
+ style.styleMM(Sid::repeatBarlineDotSeparation) * 2.0
+ dotWidth * 2;
break;
case BarLineType::START_REPEAT:
case BarLineType::END_REPEAT:
w = style.styleMM(Sid::endBarWidth)
+ style.styleMM(Sid::barWidth)
+ style.styleMM(Sid::endBarDistance)
+ style.styleMM(Sid::repeatBarlineDotSeparation)
+ dotWidth;
break;
case BarLineType::END:
case BarLineType::REVERSE_END:
w = style.styleMM(Sid::endBarWidth)
+ style.styleMM(Sid::barWidth)
+ style.styleMM(Sid::endBarDistance);
break;
case BarLineType::BROKEN:
case BarLineType::NORMAL:
case BarLineType::DOTTED:
w = style.styleMM(Sid::barWidth);
break;
case BarLineType::HEAVY:
w = style.styleMM(Sid::endBarWidth);
break;
}
return w;
}
void TLayout::layoutBarLine(const BarLine* item, BarLine::LayoutData* ldata, const LayoutContext& ctx)
{
LAYOUT_CALL_ITEM(item);
// barlines hidden on this staff
if (item->staff() && item->segment()) {
if ((!item->staff()->staffTypeForElement(item)->showBarlines() && item->segment()->segmentType() == SegmentType::EndBarLine)
|| (item->staff()->hideSystemBarLine() && item->segment()->segmentType() == SegmentType::BeginBarLine)) {
ldata->setPos(PointF());
ldata->setBbox(RectF());
ldata->setIsSkipDraw(true);
return;
}
}