1 //============================================================================= 2 // MuseScore 3 // Linux Music Score Editor 4 // 5 // Copyright (C) 2009-2013 Werner Schweer and others 6 // 7 // This program is free software; you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License version 2. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 //============================================================================= 19 20 #ifndef __CAPELLA_H__ 21 #define __CAPELLA_H__ 22 23 #include "libmscore/xml.h" 24 25 namespace Ms { 26 27 enum class TIMESTEP : char { D1, D2, D4, D8, D16, D32, D64, D128, D256, D_BREVE }; 28 29 #if 0 30 static const char* timeNames[] = { "1/1", "1/2", "1/4", "1/8", "1/16", "1/32", "1/64", 31 "1/128", "1/256", "breve" }; 32 #endif 33 34 class Capella; 35 enum class ClefType : signed char; 36 37 enum class CapellaNoteObjectType : char { 38 REST, CHORD, CLEF, KEY, METER, EXPL_BARLINE, IMPL_BARLINE, 39 PAGE_BKGR 40 }; 41 42 enum class BeamMode : unsigned char { AUTO, FORCE, SPLIT }; 43 44 //--------------------------------------------------------- 45 // CapellaObj 46 //--------------------------------------------------------- 47 48 class CapellaObj { 49 protected: 50 Capella* cap; 51 52 public: CapellaObj(Capella * c)53 CapellaObj(Capella* c) { cap = c; } 54 }; 55 56 //--------------------------------------------------------- 57 // NoteObj 58 //--------------------------------------------------------- 59 60 class NoteObj { 61 CapellaNoteObjectType _type; 62 63 public: NoteObj(CapellaNoteObjectType t)64 NoteObj(CapellaNoteObjectType t) { _type = t; } type()65 CapellaNoteObjectType type() const { return _type; } 66 }; 67 68 enum class Form : char { 69 G, C, F, PERCUSSION, 70 FORM_NULL, CLEF_UNCHANGED 71 }; 72 73 enum class ClefLine : char { 74 L5, L4, L3, L2, L1 75 }; 76 77 enum class Oct : char { 78 OCT_ALTA, OCT_NULL, OCT_BASSA 79 }; 80 81 //--------------------------------------------------------- 82 // CapClef 83 //--------------------------------------------------------- 84 85 class CapClef : public NoteObj, public CapellaObj { 86 Form form; 87 88 public: CapClef(Capella * c)89 CapClef(Capella* c) : NoteObj(CapellaNoteObjectType::CLEF), CapellaObj(c) {} 90 void read(); 91 void readCapx(XmlReader& e); name()92 const char* name() { 93 static const char* formName[] = { "G", "C", "F", "=", " ", "*" }; 94 return formName[int(form)]; 95 } 96 ClefType clef() const; 97 98 ClefLine line; 99 Oct oct; 100 static ClefType clefType(Form, ClefLine, Oct); 101 }; 102 103 //--------------------------------------------------------- 104 // CapKey 105 //--------------------------------------------------------- 106 107 class CapKey : public NoteObj, public CapellaObj { 108 109 public: CapKey(Capella * c)110 CapKey(Capella* c) : NoteObj(CapellaNoteObjectType::KEY), CapellaObj(c) {} 111 void read(); 112 void readCapx(XmlReader& e); 113 int signature { 0 }; // -7 - +7 114 }; 115 116 //--------------------------------------------------------- 117 // CapMeter 118 //--------------------------------------------------------- 119 120 class CapMeter : public NoteObj, public CapellaObj { 121 public: 122 unsigned char numerator; 123 int log2Denom; 124 bool allaBreve; 125 CapMeter(Capella * c)126 CapMeter(Capella* c) : NoteObj(CapellaNoteObjectType::METER), CapellaObj(c) {} 127 void read(); 128 void readCapx(XmlReader& e); 129 }; 130 131 //--------------------------------------------------------- 132 // CapExplicitBarline 133 //--------------------------------------------------------- 134 135 class CapExplicitBarline : public NoteObj, public CapellaObj { 136 BarLineType _type { BarLineType::NORMAL }; 137 int _barMode { 0 }; // 0 = auto, 1 = nur Zeilen, 2 = durchgezogen 138 139 public: CapExplicitBarline(Capella * c)140 CapExplicitBarline(Capella* c) : NoteObj(CapellaNoteObjectType::EXPL_BARLINE), CapellaObj(c) {} 141 void read(); 142 void readCapx(XmlReader& e); type()143 BarLineType type() const { return _type; } barMode()144 int barMode() const { return _barMode; } 145 146 }; 147 148 //--------------------------------------------------------- 149 // CapVoice 150 //--------------------------------------------------------- 151 152 struct CapVoice { 153 uchar y0Lyrics; 154 uchar dyLyrics; 155 QFont lyricsFont; 156 unsigned char stemDir; 157 QList<NoteObj*> objects; 158 int voiceNo; 159 }; 160 161 //--------------------------------------------------------- 162 // CapStaff 163 //--------------------------------------------------------- 164 165 struct CapStaff { 166 uchar numerator; // default time signature 167 int log2Denom; 168 bool allaBreve; 169 170 uchar iLayout; 171 int topDistX; 172 int btmDistX; 173 QColor color; 174 QList<CapVoice*> voices; 175 }; 176 177 //--------------------------------------------------------- 178 // struct CapStaffLayout 179 //--------------------------------------------------------- 180 181 struct CapStaffLayout { 182 uchar barlineMode; 183 uchar noteLines; 184 bool bSmall; 185 int topDist; 186 int btmDist; 187 int groupDist; 188 uchar barlineFrom; 189 uchar barlineTo; 190 191 Form form; 192 ClefLine line; 193 Oct oct; // clef 194 195 // Schlagzeuginformation 196 bool bPercussion; // use drum channel 197 bool bSoundMapIn; 198 bool bSoundMapOut; 199 char soundMapIn[128]; // Tabelle für MIDI-Töne iMin...iMin+n-1 200 char soundMapOut[128]; // Tabelle für MIDI-Töne iMin...iMin+n-1 201 202 int sound, volume, transp; 203 204 QString descr; 205 QString name; 206 QString abbrev; 207 QString intermediateName; 208 QString intermediateAbbrev; 209 }; 210 211 //--------------------------------------------------------- 212 // CapSystem 213 //--------------------------------------------------------- 214 215 struct CapSystem { 216 int nAddBarCount; 217 bool bBarCountReset; 218 unsigned char explLeftIndent; // < 0 --> Einrückung gemäß Stimmenbezeichnungen 219 // >= --> explizite Einrückung 220 BeamMode beamMode; 221 unsigned tempo; 222 QColor color; // fuer Systemklammern 223 bool bJustified; // Randausgleich (Blocksatz) 224 bool bPageBreak; // nach dem System neue Seite anfangen 225 int instrNotation; // 0 = keine Instrumentenbezeichnung 226 // 1 = abgekürzt, 2 = vollständig 227 QList<CapStaff*> staves; 228 }; 229 230 //--------------------------------------------------------- 231 // BasicDrawObj 232 //--------------------------------------------------------- 233 234 enum class CapellaType : unsigned char { GROUP, TRANSPOSABLE, METAFILE, SIMPLE_TEXT, TEXT, RECT_ELLIPSE, 235 LINE, POLYGON, WAVY_LINE, SLUR, NOTE_LINES, WEDGE, VOLTA, 236 BRACKET, GUITAR, TRILL 237 }; 238 239 class BasicDrawObj : public CapellaObj { 240 public: 241 unsigned char modeX, modeY, distY, flags; 242 int nRefNote; 243 int nNotes; 244 bool background; 245 int pageRange; 246 CapellaType type; 247 BasicDrawObj(CapellaType t,Capella * c)248 BasicDrawObj(CapellaType t, Capella* c) 249 : CapellaObj(c), modeX(0), modeY(0), distY(0), flags(0), 250 nRefNote(0), nNotes(0), background(0), pageRange(0), type(t) {} 251 void read(); 252 void readCapx(XmlReader& e); 253 }; 254 255 //--------------------------------------------------------- 256 // BasicRectObj 257 //--------------------------------------------------------- 258 259 class BasicRectObj : public BasicDrawObj { 260 public: BasicRectObj(CapellaType t,Capella * c)261 BasicRectObj(CapellaType t, Capella* c) : BasicDrawObj(t, c) {} 262 void read(); 263 264 QPointF relPos; 265 int width; 266 int yxRatio; 267 int height; 268 }; 269 270 //--------------------------------------------------------- 271 // GroupObj 272 //--------------------------------------------------------- 273 274 class GroupObj : public BasicDrawObj { 275 public: GroupObj(Capella * c)276 GroupObj(Capella* c) : BasicDrawObj(CapellaType::GROUP, c) {} 277 void read(); 278 279 QPointF relPos; 280 QList<BasicDrawObj*> objects; 281 }; 282 283 //--------------------------------------------------------- 284 // TransposableObj 285 //--------------------------------------------------------- 286 287 class TransposableObj : public BasicDrawObj { 288 public: TransposableObj(Capella * c)289 TransposableObj(Capella* c) : BasicDrawObj(CapellaType::TRANSPOSABLE, c) {} 290 void read(); 291 void readCapx(XmlReader& e); 292 293 QPointF relPos; 294 char b { 0 }; 295 QList<BasicDrawObj*> variants; 296 }; 297 298 //--------------------------------------------------------- 299 // MetafileObj 300 //--------------------------------------------------------- 301 302 class MetafileObj : public BasicRectObj { 303 public: MetafileObj(Capella * c)304 MetafileObj(Capella* c) : BasicRectObj(CapellaType::METAFILE, c) {} 305 void read(); 306 }; 307 308 //--------------------------------------------------------- 309 // LineObj 310 //--------------------------------------------------------- 311 312 class LineObj : public BasicDrawObj { 313 314 public: LineObj(Capella * c)315 LineObj(Capella* c) : BasicDrawObj(CapellaType::LINE, c) {} LineObj(CapellaType t,Capella * c)316 LineObj(CapellaType t, Capella* c) : BasicDrawObj(t, c) {} 317 void read(); 318 319 QPointF pt1, pt2; 320 QColor color; 321 char lineWidth { 0 }; 322 }; 323 324 //--------------------------------------------------------- 325 // RectEllipseObj 326 //--------------------------------------------------------- 327 328 class RectEllipseObj : public LineObj { // special 329 public: RectEllipseObj(Capella * c)330 RectEllipseObj(Capella* c) : LineObj(CapellaType::RECT_ELLIPSE, c) {} 331 void read(); 332 333 int radius; 334 bool bFilled; 335 QColor clrFill; 336 }; 337 338 //--------------------------------------------------------- 339 // PolygonObj 340 //--------------------------------------------------------- 341 342 class PolygonObj : public BasicDrawObj { 343 public: PolygonObj(Capella * c)344 PolygonObj(Capella* c) : BasicDrawObj(CapellaType::POLYGON, c) {} 345 void read(); 346 347 bool bFilled; 348 unsigned lineWidth; 349 QColor clrFill; 350 QColor clrLine; 351 }; 352 353 //--------------------------------------------------------- 354 // WavyLineObj 355 //--------------------------------------------------------- 356 357 class WavyLineObj : public LineObj { 358 public: WavyLineObj(Capella * c)359 WavyLineObj(Capella* c) : LineObj(CapellaType::WAVY_LINE, c) {} 360 void read(); 361 362 unsigned waveLen; 363 bool adapt; 364 }; 365 366 //--------------------------------------------------------- 367 // NotelinesObj 368 //--------------------------------------------------------- 369 370 class NotelinesObj : public BasicDrawObj { 371 public: NotelinesObj(Capella * c)372 NotelinesObj(Capella* c) : BasicDrawObj(CapellaType::NOTE_LINES, c) {} 373 void read(); 374 375 int x0, x1, y; 376 QColor color; 377 }; 378 379 //--------------------------------------------------------- 380 // VoltaObj 381 //--------------------------------------------------------- 382 383 class VoltaObj : public BasicDrawObj { 384 public: VoltaObj(Capella * c)385 VoltaObj(Capella* c) 386 : BasicDrawObj(CapellaType::VOLTA, c), x0(0), x1(0), y(0), 387 bLeft(false), bRight(false), bDotted(false), 388 allNumbers(false), from(0), to(0) {} 389 void read(); 390 void readCapx(XmlReader& e); 391 392 int x0, x1, y; 393 QColor color; 394 395 bool bLeft; 396 bool bRight; 397 bool bDotted; 398 bool allNumbers; 399 400 int from, to; 401 }; 402 403 //--------------------------------------------------------- 404 // GuitarObj 405 //--------------------------------------------------------- 406 407 class GuitarObj : public BasicDrawObj { 408 public: GuitarObj(Capella * c)409 GuitarObj(Capella* c) : BasicDrawObj(CapellaType::GUITAR, c) {} 410 void read(); 411 412 QPointF relPos; 413 QColor color; 414 short flags; 415 int strings; // 8 Saiten in 8 Halbbytes 416 }; 417 418 //--------------------------------------------------------- 419 // TrillObj 420 //--------------------------------------------------------- 421 422 class TrillObj : public BasicDrawObj { 423 public: TrillObj(Capella * c)424 TrillObj(Capella* c) : BasicDrawObj(CapellaType::TRILL, c), x0(0), 425 x1(0), y(0), trillSign(true) {} 426 void read(); 427 void readCapx(XmlReader& e); 428 429 int x0, x1, y; 430 QColor color; 431 bool trillSign; 432 }; 433 434 //--------------------------------------------------------- 435 // SlurObj 436 //--------------------------------------------------------- 437 438 class SlurObj : public BasicDrawObj { 439 QPointF bezierPoint[4]; // note default constructor inits to (0, 0) 440 QColor color; // note default constructor inits to invalid 441 442 public: SlurObj(Capella * c)443 SlurObj(Capella* c) 444 : BasicDrawObj(CapellaType::SLUR, c), color(Qt::black), nEnd(0), nMid(0), nDotDist(0), nDotWidth(0) {} 445 void read(); 446 void readCapx(XmlReader& e); 447 unsigned char nEnd, nMid, nDotDist, nDotWidth; 448 }; 449 450 //--------------------------------------------------------- 451 // TextObj 452 //--------------------------------------------------------- 453 454 class TextObj : public BasicRectObj { 455 456 public: TextObj(Capella * c)457 TextObj(Capella* c) : BasicRectObj(CapellaType::TEXT, c) {} ~TextObj()458 ~TextObj() {} 459 void read(); 460 461 QString text; 462 }; 463 464 //--------------------------------------------------------- 465 // SimpleTextObj 466 //--------------------------------------------------------- 467 468 class SimpleTextObj : public BasicDrawObj { 469 QString _text; 470 QPointF relPos; 471 unsigned char align; 472 QFont _font; 473 474 public: SimpleTextObj(Capella * c)475 SimpleTextObj(Capella* c) 476 : BasicDrawObj(CapellaType::SIMPLE_TEXT, c), relPos(0, 0), align(0) {} 477 void read(); 478 void readCapx(XmlReader& e); text()479 QString text() const { return _text; } font()480 QFont font() const { return _font; } pos()481 QPointF pos() const { return relPos; } textalign()482 unsigned char textalign() const { return align; } 483 }; 484 485 //--------------------------------------------------------- 486 // BracketObj 487 //--------------------------------------------------------- 488 489 class BracketObj : public LineObj { 490 491 public: BracketObj(Capella * c)492 BracketObj(Capella* c) : LineObj(CapellaType::BRACKET, c) {} 493 void read(); 494 495 char orientation, number; 496 }; 497 498 //--------------------------------------------------------- 499 // WedgeObj 500 //--------------------------------------------------------- 501 502 class WedgeObj : public LineObj { 503 504 public: WedgeObj(Capella * c)505 WedgeObj(Capella* c) : LineObj(CapellaType::WEDGE, c), height(32), 506 decresc(false) {} 507 void read(); 508 void readCapx(XmlReader& e); 509 510 int height; 511 bool decresc; 512 }; 513 514 //--------------------------------------------------------- 515 // BasicDurationalObj 516 //--------------------------------------------------------- 517 518 class BasicDurationalObj : public CapellaObj { 519 public: 520 int nDots; 521 bool noDuration; 522 bool postGrace; 523 bool bSmall; 524 bool notBlack; 525 QColor color; 526 TIMESTEP t; 527 int horizontalShift; 528 int count; // tuplet 529 bool tripartite; 530 bool isProlonging; 531 532 public: BasicDurationalObj(Capella * c)533 BasicDurationalObj(Capella* c) : CapellaObj(c) {} 534 void read(); 535 void readCapx(XmlReader& e, unsigned int& fullm); 536 void readCapxDisplay(XmlReader& e); 537 void readCapxObjectArray(XmlReader& e); 538 Fraction ticks() const; 539 bool invisible; 540 QList<BasicDrawObj*> objects; 541 }; 542 543 //--------------------------------------------------------- 544 // Verse 545 //--------------------------------------------------------- 546 547 struct Verse { 548 bool leftAlign; 549 bool extender; 550 bool hyphen; 551 int num; 552 QString verseNumber; 553 QString text; 554 }; 555 556 struct CNote { 557 signed char pitch; 558 int explAlteration; // 1 force, 2 suppress 559 int headType; 560 int alteration; 561 int silent; 562 }; 563 564 //--------------------------------------------------------- 565 // ChordObj 566 //--------------------------------------------------------- 567 568 class ChordObj : public BasicDurationalObj, public NoteObj { 569 public: 570 enum class StemDir : signed char { DOWN = -1, AUTO = 0, UP = 1, NONE = 3 }; 571 BeamMode beamMode; 572 signed char notationStave; 573 char dStemLength; 574 unsigned char nTremoloBars; 575 unsigned articulation; 576 bool leftTie; 577 bool rightTie; 578 char beamShift; 579 char beamSlope; 580 581 public: 582 ChordObj(Capella*); 583 void read(); 584 void readCapx(XmlReader& e); 585 void readCapxLyrics(XmlReader& e); 586 void readCapxNotes(XmlReader& e); 587 void readCapxStem(XmlReader& e); 588 void readCapxArticulation(XmlReader& e); 589 QList<Verse> verse; 590 QList<CNote> notes; 591 StemDir stemDir; 592 }; 593 594 //--------------------------------------------------------- 595 // RestObj 596 //--------------------------------------------------------- 597 598 class RestObj : public BasicDurationalObj, public NoteObj { 599 bool bVerticalCentered { false }; 600 int vertShift { 0 }; 601 602 public: 603 RestObj(Capella*); 604 void read(); 605 void readCapx(XmlReader& e); 606 unsigned fullMeasures; // >0, multi measure rest (counting measures) 607 }; 608 609 //--------------------------------------------------------- 610 // CapFont 611 //--------------------------------------------------------- 612 613 struct CapFont { 614 QString face; 615 }; 616 617 //--------------------------------------------------------- 618 // CapBracket 619 //--------------------------------------------------------- 620 621 struct CapBracket { 622 int from, to; 623 bool curly; 624 }; 625 626 //--------------------------------------------------------- 627 // Capella 628 //--------------------------------------------------------- 629 630 class Capella { 631 static const char* errmsg[]; 632 int curPos; 633 634 QFile* f; 635 char* author; 636 char* keywords; 637 char* comment; 638 639 unsigned char beamRelMin0; 640 unsigned char beamRelMin1; 641 unsigned char beamRelMax0; 642 unsigned char beamRelMax1; 643 unsigned nRel; // presentation parameter 644 unsigned nAbs; 645 bool bUseRealSize; 646 bool bAllowCompression; 647 bool bPrintLandscape; 648 649 bool bShowBarCount; // Taktnumerierung zeigen 650 unsigned char barNumberFrame; // 0=kein, 1=Rechteck, 2=Ellipse 651 unsigned char nBarDistX; 652 unsigned char nBarDistY; 653 // LogFont barNumFont; 654 655 unsigned nFirstPage; // Versatz fuer Seitenzaehlung 656 657 unsigned leftPageMargins; // Seitenraender 658 unsigned topPageMargins; 659 unsigned rightPageMargins; 660 unsigned btmPageMargins; 661 662 QList<QFont> fonts; 663 QList<CapStaffLayout*> _staffLayouts; // staff layout 664 665 int interDist; 666 unsigned char txtAlign; // Stimmenbezeichnungen 0=links, 1=zentriert, 2=rechts 667 unsigned char adjustVert; // 0=nein, 1=außer letzte Seite, 3=alle Seiten 668 bool redundantKeys; 669 bool modernDoubleNote; 670 bool bSystemSeparators; 671 int nUnnamed; 672 QFont namesFont; 673 674 void readVoice(CapStaff*, int); 675 void readStaff(CapSystem*); 676 void readSystem(); 677 678 protected: 679 void readStaveLayout(CapStaffLayout*, int); 680 void readLayout(); 681 682 public: 683 enum class Error : char { CAP_NO_ERROR, BAD_SIG, CAP_EOF, BAD_VOICE_SIG, 684 BAD_STAFF_SIG, BAD_SYSTEM_SIG 685 }; 686 687 Capella(); 688 ~Capella(); 689 void read(QFile*); error(Error n)690 QString error(Error n) const { return QString(errmsg[int(n)]); } 691 692 unsigned char readByte(); 693 char readChar(); 694 QColor readColor(); 695 int readInt(); 696 int readLong(); 697 short readWord(); 698 int readDWord(); 699 unsigned readUnsigned(); 700 char* readString(); 701 QString readQString(); 702 void readExtra(); 703 QList<BasicDrawObj*> readDrawObjectArray(); 704 bool read(void* p, qint64 len); 705 QFont readFont(); 706 QPointF readPoint(); 707 708 QList<CapSystem*> systems; 709 QList<CapBracket> brackets; 710 ChordObj* backgroundChord; staffLayout(int idx)711 CapStaffLayout* staffLayout(int idx) { return _staffLayouts[idx]; } staffLayouts()712 const QList<CapStaffLayout*>& staffLayouts() const { return _staffLayouts; } 713 714 double smallLineDist; // spatium unit in metric mm 715 double normalLineDist; 716 int topDist; 717 // capx support 718 private: 719 void readCapxVoice(XmlReader& e, CapStaff*, int); 720 void readCapxStaff(XmlReader& e, CapSystem*); 721 void readCapxSystem(XmlReader& e); 722 void capxSystems(XmlReader& e); 723 void readCapxStaveLayout(XmlReader& e, CapStaffLayout*, int); 724 void capxLayoutStaves(XmlReader& e); 725 void capxLayout(XmlReader& e); 726 void initCapxLayout(); 727 public: 728 void readCapx(XmlReader& e); 729 QList<BasicDrawObj*> readCapxDrawObjectArray(XmlReader& e); 730 }; 731 732 733 } // namespace Ms 734 #endif 735 736