drumstick 1.1.3
qove.cpp
Go to the documentation of this file.
1/*
2 Overture OVE File component
3 Copyright (C) 2006-2019, Rui Fan <vanferry@gmail.com>
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This library 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, see <http://www.gnu.org/licenses/>.
17*/
18
19#include <QFile>
20#include <QIODevice>
21#include <QMap>
22#include <QPair>
23#include <QTextCodec>
24#include <QString>
25#include <QStringList>
26#include <cmath>
27#include <cstdlib>
28#include <drumstick/qove.h>
29
35namespace OVE {
36
37class OveSong;
38class Track;
39class Page;
40class Voice;
41class Line;
42class Staff;
43class Measure;
44class MeasureData;
45class MusicData;
46class OffsetElement;
47class LineElement;
48class PairEnds;
49class Note;
50class NoteContainer;
51class Beam;
52class Tie;
53class Tuplet;
54class Harmony;
55class Clef;
56class Lyric;
57class Slur;
58class MeasureText;
59class Articulation;
60class Glissando;
61class Decorator;
62class MeasureRepeat;
63class Dynamics;
64class Wedge;
65class WedgeEndPoint;
66class Pedal;
67class KuoHao;
68class Expressions;
69class HarpPedal;
70class MultiMeasureRest;
71class OctaveShift;
72class OctaveShiftEndPoint;
73class BarNumber;
74class Tempo;
75class Text;
76class TimeSignature;
77class Key;
78class RepeatSymbol;
79class NumericEnding;
80class MidiData;
81class MidiController;
82class MidiProgramChange;
83class MidiChannelPressure;
84class MidiPitchWheel;
85
86const int TWELVE_TONE = 12 ;
87const int INVALID_NOTE = -1 ;
88const int OCTAVE = 7 ;
89
90enum CondType {
91 Cond_Time_Parameters = 0x09, // size - 7, TimeSignature
92 Cond_Bar_Number = 0x0A, // size, compatible with previous version
93 Cond_Decorator = 0x16,
94 Cond_Tempo = 0x1C, // size - 7
95 Cond_Text = 0x1D, // size - 7, Rehearsal | SystemText
96 Cond_Expression = 0x25, // size - 7, if set playback parameters in Expression, will store in COND
97 Cond_Barline_Parameters = 0x30, // size - 7, include :|| repeat count
98 Cond_Repeat = 0x31, //
99 Cond_Numeric_Ending = 0x32, //
100
101 Cond_None
102};
103
104enum BdatType {
105 Bdat_Raw_Note = 0x70,
106 Bdat_Rest = 0x80,
107 Bdat_Note = 0x90,
108 Bdat_Beam = 0x10,
109 Bdat_Harmony = 0x11,
110 Bdat_Clef = 0x12,
111 Bdat_Dynamics = 0x13,
112 Bdat_Wedge = 0x14, // cresendo, decresendo
113 Bdat_Glissando = 0x15,
114 Bdat_Decorator = 0x16, // measure repeat | piano pedal | dotted barline
115 Bdat_Key = 0x17,
116 Bdat_Lyric = 0x18,
117 Bdat_Octave_Shift = 0x19,
118 Bdat_Slur = 0x1B,
119 Bdat_Text = 0x1D,
120 Bdat_Tie = 0x1E,
121 Bdat_Tuplet = 0x1F,
122 Bdat_Guitar_Bend = 0x21, //
123 Bdat_Guitar_Barre = 0x22, //
124 Bdat_Pedal = 0x23,
125 Bdat_KuoHao = 0x24, // () [] {}
126 Bdat_Expressions = 0x25,
127 Bdat_Harp_Pedal = 0x26,
128 Bdat_Multi_Measure_Rest = 0x27,
129 Bdat_Harmony_GuitarFrame = 0x28,
130 Bdat_Graphics_40 = 0x40, // unknown
131 Bdat_Graphics_RoundRect = 0x41,
132 Bdat_Graphics_Rect = 0x42,
133 Bdat_Graphics_Round = 0x43,
134 Bdat_Graphics_Line = 0x44,
135 Bdat_Graphics_Curve = 0x45,
136 Bdat_Graphics_WedgeSymbol = 0x46,
137 Bdat_Midi_Controller = 0xAB,
138 Bdat_Midi_Program_Change = 0xAC,
139 Bdat_Midi_Channel_Pressure = 0xAD,
140 Bdat_Midi_Pitch_Wheel = 0xAE,
141 Bdat_Bar_End = 0xFF,
142
143 Bdat_None
144};
145
147
148enum MusicDataType {
149 // attributes
150 MusicData_Clef,
151 MusicData_Key,
152 MusicData_Measure_Repeat,
153
154 // sound
155 MusicData_Tempo,
156
157 // direction
158 MusicData_Dynamics,
159 MusicData_Wedge,
160 MusicData_Wedge_EndPoint,
161 MusicData_OctaveShift,
162 MusicData_OctaveShift_EndPoint,
163 MusicData_Expressions,
164 MusicData_Repeat,
165 MusicData_Text,
166 MusicData_Harp_Pedal,
167 MusicData_Pedal,
168
169 // note & harmony
170 MusicData_Note_Container,
171 MusicData_Harmony,
172
173 // note's children
174 MusicData_Beam,
175 MusicData_Glissando,
176 MusicData_Lyric,
177 MusicData_Slur,
178 MusicData_Tie,
179 MusicData_Tuplet,
180
181 // barline
182 MusicData_Numeric_Ending,
183
184 MusicData_KuoHao,
185 MusicData_Bar_End,
186 MusicData_Decorator,
187 MusicData_Multi_Measure_Rest,
188
189 MusicData_None
190};
191
192enum MidiType {
193 Midi_Controller = 0,
194 Midi_Program_Change,
195 Midi_Channel_Pressure,
196 Midi_Pitch_Wheel,
197
198 Midi_None
199};
200
201enum ClefType {
202 Clef_Treble = 0x00, //0x00
203 Clef_Bass, //0x01
204 Clef_Alto, //0x02
205 Clef_UpAlto, //0x03
206 Clef_DownDownAlto, //0x04
207 Clef_DownAlto, //0x05
208 Clef_UpUpAlto, //0x06
209 Clef_Treble8va, //0x07
210 Clef_Bass8va, //0x08
211 Clef_Treble8vb, //0x09
212 Clef_Bass8vb, //0x0A
213 Clef_Percussion1, //0x0B
214 Clef_Percussion2, //0x0C
215 Clef_TAB //0x0D
216};
217
218enum GroupType {
219 Group_None = 0,
220 Group_Brace,
221 Group_Bracket
222};
223
224enum AccidentalType {
225 Accidental_Normal = 0x0,
226 Accidental_Sharp = 0x1,
227 Accidental_Flat = 0x2,
228 Accidental_Natural = 0x3,
229 Accidental_DoubleSharp = 0x4,
230 Accidental_DoubleFlat = 0x5,
231 Accidental_Sharp_Caution = 0x9,
232 Accidental_Flat_Caution = 0xA,
233 Accidental_Natural_Caution = 0xB,
234 Accidental_DoubleSharp_Caution = 0xC,
235 Accidental_DoubleFlat_Caution = 0xD
236};
237
238enum NoteHeadType {
239 NoteHead_Standard = 0x00,
240 NoteHead_Invisible,
241 NoteHead_Rhythmic_Slash,
242 NoteHead_Percussion,
243 NoteHead_Closed_Rhythm,
244 NoteHead_Open_Rhythm,
245 NoteHead_Closed_Slash,
246 NoteHead_Open_Slash,
247 NoteHead_Closed_Do,
248 NoteHead_Open_Do,
249 NoteHead_Closed_Re,
250 NoteHead_Open_Re,
251 NoteHead_Closed_Mi,
252 NoteHead_Open_Mi,
253 NoteHead_Closed_Fa,
254 NoteHead_Open_Fa,
255 NoteHead_Closed_Sol,
256 NoteHead_Open_Sol,
257 NoteHead_Closed_La,
258 NoteHead_Open_La,
259 NoteHead_Closed_Ti,
260 NoteHead_Open_Ti
261};
262
263enum TiePos {
264 Tie_None = 0x0,
265 Tie_LeftEnd = 0x1,
266 Tie_RightEnd = 0x2
267};
268
269enum ArticulationType {
270 Articulation_Major_Trill = 0x00,
271 Articulation_Minor_Trill = 0x01,
272 Articulation_Trill_Section = 0x02,
273 Articulation_Inverted_Short_Mordent = 0x03,
274 Articulation_Inverted_Long_Mordent = 0x04,
275 Articulation_Short_Mordent = 0x05,
276 Articulation_Turn = 0x06,
277 Articulation_Finger_1 = 0x07,
278 Articulation_Finger_2 = 0x08,
279 Articulation_Finger_3 = 0x09,
280 Articulation_Finger_4 = 0x0A,
281 Articulation_Finger_5 = 0x0B,
282 Articulation_Flat_Accidental_For_Trill = 0x0C,
283 Articulation_Sharp_Accidental_For_Trill = 0x0D,
284 Articulation_Natural_Accidental_For_Trill = 0x0E,
285 Articulation_Marcato = 0x0F,
286 Articulation_Marcato_Dot = 0x10,
287 Articulation_Heavy_Attack = 0x11,
288 Articulation_SForzando = 0x12,
289 Articulation_SForzando_Dot = 0x13,
290 Articulation_Heavier_Attack = 0x14,
291 Articulation_SForzando_Inverted = 0x15,
292 Articulation_SForzando_Dot_Inverted = 0x16,
293 Articulation_Staccatissimo = 0x17,
294 Articulation_Staccato = 0x18,
295 Articulation_Tenuto = 0x19,
296 Articulation_Up_Bow = 0x1A,
297 Articulation_Down_Bow = 0x1B,
298 Articulation_Up_Bow_Inverted = 0x1C,
299 Articulation_Down_Bow_Inverted = 0x1D,
300 Articulation_Arpeggio = 0x1E,
301 Articulation_Tremolo_Eighth = 0x1F,
302 Articulation_Tremolo_Sixteenth = 0x20,
303 Articulation_Tremolo_Thirty_Second = 0x21,
304 Articulation_Tremolo_Sixty_Fourth = 0x22,
305 Articulation_Natural_Harmonic = 0x23,
306 Articulation_Artificial_Harmonic = 0x24,
307 Articulation_Plus_Sign = 0x25,
308 Articulation_Fermata = 0x26,
309 Articulation_Fermata_Inverted = 0x27,
310 Articulation_Pedal_Down = 0x28,
311 Articulation_Pedal_Up = 0x29,
312 Articulation_Pause = 0x2A,
313 Articulation_Grand_Pause = 0x2B,
314 Articulation_Toe_Pedal = 0x2C,
315 Articulation_Heel_Pedal = 0x2D,
316 Articulation_Toe_To_Heel_Pedal = 0x2E,
317 Articulation_Heel_To_Toe_Pedal = 0x2F,
318 Articulation_Open_String = 0x30, // finger 0 in guitar
319 Articulation_Guitar_Lift = 0x46,
320 Articulation_Guitar_Slide_Up = 0x47,
321 Articulation_Guitar_Rip = 0x48,
322 Articulation_Guitar_Fall_Off = 0x49,
323 Articulation_Guitar_Slide_Down = 0x4A,
324 Articulation_Guitar_Spill = 0x4B,
325 Articulation_Guitar_Flip = 0x4C,
326 Articulation_Guitar_Smear = 0x4D,
327 Articulation_Guitar_Bend = 0x4E,
328 Articulation_Guitar_Doit = 0x4F,
329 Articulation_Guitar_Plop = 0x50,
330 Articulation_Guitar_Wow_Wow = 0x51,
331 Articulation_Guitar_Thumb = 0x64,
332 Articulation_Guitar_Index_Finger = 0x65,
333 Articulation_Guitar_Middle_Finger = 0x66,
334 Articulation_Guitar_Ring_Finger = 0x67,
335 Articulation_Guitar_Pinky_Finger = 0x68,
336 Articulation_Guitar_Tap = 0x69,
337 Articulation_Guitar_Hammer = 0x6A,
338 Articulation_Guitar_Pluck = 0x6B,
339
340 Articulation_None
341
342/* Articulation_Detached_Legato,
343 Articulation_Spiccato,
344 Articulation_Scoop,
345 Articulation_Plop,
346 Articulation_Doit,
347 Articulation_Falloff,
348 Articulation_Breath_Mark,
349 Articulation_Caesura,*/
350};
351
352enum NoteType {
353 Note_DoubleWhole= 0x0,
354 Note_Whole = 0x1,
355 Note_Half = 0x2,
356 Note_Quarter = 0x3,
357 Note_Eight = 0x4,
358 Note_Sixteen = 0x5,
359 Note_32 = 0x6,
360 Note_64 = 0x7,
361 Note_128 = 0x8,
362 Note_256 = 0x9,
363
364 Note_None
365};
366
367inline int NoteTypeToTick(NoteType type, int quarter) {
368 int c = int(pow(2.0, (int)type)) ;
369 return quarter * 4 * 2 / c ;
370}
371
372enum HarmonyType {
373 Harmony_maj = 0,
374 Harmony_min,
375 Harmony_aug,
376 Harmony_dim,
377 Harmony_dim7,
378 Harmony_sus2,
379 Harmony_sus4,
380 Harmony_sus24,
381 Harmony_add2,
382 Harmony_add9,
383 Harmony_omit3,
384 Harmony_omit5,
385 Harmony_2,
386 Harmony_5,
387 Harmony_6,
388 Harmony_69,
389 Harmony_7,
390 Harmony_7b5,
391 Harmony_7b9,
392 Harmony_7s9,
393 Harmony_7s11,
394 Harmony_7b5s9,
395 Harmony_7b5b9,
396 Harmony_7b9s9,
397 Harmony_7b9s11,
398 Harmony_7sus4,
399 Harmony_9,
400 Harmony_9b5,
401 Harmony_9s11,
402 Harmony_9sus4,
403 Harmony_11,
404 Harmony_13,
405 Harmony_13b5,
406 Harmony_13b9,
407 Harmony_13s9,
408 Harmony_13s11,
409 Harmony_13sus4,
410 Harmony_min_add2,
411 Harmony_min_add9,
412 Harmony_min_maj7,
413 Harmony_min6,
414 Harmony_min6_add9,
415 Harmony_min7,
416 Harmony_min7b5,
417 Harmony_min7_add4,
418 Harmony_min7_add11,
419 Harmony_min9,
420 Harmony_min9_b5,
421 Harmony_min9_maj7,
422 Harmony_min11,
423 Harmony_min13,
424 Harmony_maj7,
425 Harmony_maj7_b5,
426 Harmony_maj7_s5,
427 Harmony_maj7_69,
428 Harmony_maj7_add9,
429 Harmony_maj7_s11,
430 Harmony_maj9,
431 Harmony_maj9_sus4,
432 Harmony_maj9_b5,
433 Harmony_maj9_s5,
434 Harmony_maj9_s11,
435 Harmony_maj13,
436 Harmony_maj13_b5,
437 Harmony_maj13_b9,
438 Harmony_maj13_b9b5,
439 Harmony_maj13_s11,
440 Harmony_aug7,
441 Harmony_aug7_b9,
442 Harmony_aug7_s9,
443
444 Harmony_None
445};
446
447enum DynamicsType {
448 Dynamics_pppp = 0,
449 Dynamics_ppp,
450 Dynamics_pp,
451 Dynamics_p,
452 Dynamics_mp,
453 Dynamics_mf,
454 Dynamics_f,
455 Dynamics_ff,
456 Dynamics_fff,
457 Dynamics_ffff,
458 Dynamics_sf,
459 Dynamics_fz,
460 Dynamics_sfz,
461 Dynamics_sffz,
462 Dynamics_fp,
463 Dynamics_sfp
464};
465
466enum WedgeType {
467 Wedge_Cres_Line = 0, // <
468 Wedge_Double_Line, // <>, not appear in xml
469 Wedge_Decresc_Line, // >
470 Wedge_Cres, // cresc., not appear in xml, will create Expression
471 Wedge_Decresc // decresc., not appear in xml, will create Expression
472};
473
474enum KuoHaoType {
475 KuoHao_Parentheses = 0,
476 KuoHao_Brace,
477 KuoHao_Bracket
478};
479
480enum OctaveShiftType {
481 OctaveShift_8 = 0,
482 OctaveShift_Minus_8,
483 OctaveShift_15,
484 OctaveShift_Minus_15
485};
486
487enum OctaveShiftPosition {
488 OctavePosition_Start = 0 ,
489 OctavePosition_Continue,
490 OctavePosition_Stop
491};
492
493enum RepeatType {
494 Repeat_Segno = 0,
495 Repeat_Coda,
496 Repeat_ToCoda,
497 Repeat_DSAlCoda,
498 Repeat_DSAlFine,
499 Repeat_DCAlCoda,
500 Repeat_DCAlFine,
501 Repeat_Fine,
502
503 Repeat_Null
504};
505
506enum BarlineType {
507 Barline_Default = 0, //0x00 will be | or final (at last measure)
508 Barline_Double, //0x01 ||
509 Barline_RepeatLeft, //0x02 ||:
510 Barline_RepeatRight, //0x03 :||
511 Barline_Final, //0x04
512 Barline_Dashed, //0x05
513 Barline_Null //0x06
514} ;
515
516enum NoteDuration {
517 NoteDuration_256 = 15,
518 NoteDuration_128 = NoteDuration_256 * 2, // 30
519 NoteDuration_64 = NoteDuration_128 * 2, // 60
520 NoteDuration_32 = NoteDuration_64 * 2, // 120
521 NoteDuration_16 = NoteDuration_32 * 2, // 240
522 NoteDuration_8 = NoteDuration_16 * 2, // 480
523 NoteDuration_4 = NoteDuration_8 * 2, // 960
524 NoteDuration_2 = NoteDuration_4 * 2, // 1920
525 NoteDuration_Whole = NoteDuration_2 * 2, // 3840
526 NoteDuration_Double_Whole = NoteDuration_Whole * 2 // 7680
527};
528
529enum ToneType {
530 Tone_C = 0 ,
531 Tone_D,
532 Tone_E,
533 Tone_F,
534 Tone_G,
535 Tone_A,
536 Tone_B
537};
538
539enum KeyType {
540 Key_C = 0, // C
541 Key_Bass_1, // F
542 Key_Bass_2, // Bb
543 Key_Bass_3, // Eb
544 Key_Bass_4, // Ab
545 Key_Bass_5, // Db
546 Key_Bass_6, // Gb
547 Key_Bass_7, // Cb
548 Key_Sharp_1, // G
549 Key_Sharp_2, // D
550 Key_Sharp_3, // A
551 Key_Sharp_4, // E
552 Key_Sharp_5, // B
553 Key_Sharp_6, // F#
554 Key_Sharp_7 // C#
555};
556
557// IOveNotify.h
558class IOveNotify {
559public:
560 IOveNotify() {}
561 virtual ~IOveNotify() {}
562
563public:
564 virtual void loadInfo(const QString& info) = 0;
565 virtual void loadError() = 0;
566 virtual void loadPosition(int currentMeasure, int totalMeasure, int currentTrack, int totalTrack) = 0;
567};
568
569class IOVEStreamLoader {
570public:
571 IOVEStreamLoader() {}
572 virtual ~IOVEStreamLoader() {}
573
574public:
575 virtual void setNotify(IOveNotify* notify) = 0;
576 virtual void setFileStream(unsigned char* buffer, unsigned int size) = 0;
577 virtual void setOve(OveSong* ove) = 0;
578
579 // read stream, set readed data to setOve(ove)
580 virtual bool load() = 0;
581
582 virtual void release() = 0;
583};
584
585IOVEStreamLoader* createOveStreamLoader();
586
588// basic element
589class TickElement {
590public:
591 TickElement();
592 virtual ~TickElement() {}
593
594public:
595 void setTick(int tick);
596 int getTick(void) const;
597
598private:
599 int tick_;
600};
601
602class MeasurePos {
603public:
604 MeasurePos();
605 virtual ~MeasurePos() {}
606
607public:
608 void setMeasure(int measure);
609 int getMeasure() const;
610
611 void setOffset(int offset);
612 int getOffset() const;
613
614 MeasurePos shiftMeasure(int measure) const;
615 MeasurePos shiftOffset(int offset) const; // ignore cross measure
616
617 bool operator ==(const MeasurePos& mp) const;
618 bool operator !=(const MeasurePos& mp) const;
619 bool operator <(const MeasurePos& mp) const;
620 bool operator <=(const MeasurePos& mp) const;
621 bool operator >(const MeasurePos& mp) const;
622 bool operator >=(const MeasurePos& mp) const;
623
624private:
625 int measure_;
626 int offset_;
627};
628
629class PairElement {
630public:
631 PairElement();
632 virtual ~PairElement();
633
634public:
635 MeasurePos* start() const;
636 MeasurePos* stop() const;
637
638private:
639 MeasurePos* start_;
640 MeasurePos* stop_;
641};
642
643class PairEnds {
644public:
645 PairEnds();
646 virtual ~PairEnds();
647
648public:
649 LineElement* getLeftLine() const;
650 LineElement* getRightLine() const;
651
652 OffsetElement* getLeftShoulder() const;
653 OffsetElement* getRightShoulder() const;
654
655private:
656 LineElement* leftLine_;
657 LineElement* rightLine_;
658 OffsetElement* leftShoulder_;
659 OffsetElement* rightShoulder_;
660};
661
662class LineElement {
663public:
664 LineElement();
665 virtual ~LineElement() {}
666
667public:
668 virtual void setLine(int line); // middle line (3rd line of each clef) is set 0
669 virtual int getLine(void) const;
670
671private:
672 int line_;
673};
674
675class OffsetElement {
676public:
677 OffsetElement();
678 virtual ~OffsetElement() {}
679
680public:
681 virtual void setXOffset(int offset);
682 virtual int getXOffset() const;
683
684 virtual void setYOffset(int offset);
685 virtual int getYOffset() const;
686
687private:
688 int xOffset_;
689 int yOffset_;
690};
691
692class LengthElement {
693public:
694 LengthElement();
695 virtual ~LengthElement() {}
696
697public:
698 void setLength(int length);
699 int getLength() const;
700
701private:
702 int length_; // tick
703};
704
705// base class of many ove music element
706class MusicData: public TickElement, public PairElement, public OffsetElement {
707public:
708 MusicData();
709 virtual ~MusicData() {}
710
711public:
712 MusicDataType getMusicDataType() const;
713
714 enum XmlDataType {
715 Attributes = 0, NoteBeam, Notations, Direction, None
716 };
717 static XmlDataType getXmlDataType(MusicDataType type);
718 // static bool get_is_pair_element(MusicDataType type) ;
719
720 // show / hide
721 void setShow(bool show);
722 bool getShow() const;
723
724 // color
725 void setColor(unsigned int color); // not exists in ove 3
726 unsigned int getColor() const;
727
728 void setVoice(unsigned int voice);
729 unsigned int getVoice() const;
730
731 void copyCommonBlock(const MusicData& source);
732
733protected:
734 MusicDataType musicDataType_;
735
736private:
737 bool show_;
738 unsigned int color_;
739 unsigned int voice_;
740};
741
742class MidiData: public TickElement {
743public:
744 MidiData();
745 virtual ~MidiData() {}
746
747public:
748 MidiType getMidiType() const;
749
750protected:
751 MidiType midiType_;
752};
753
754
756class OveSong {
757public:
758 OveSong();
759 ~OveSong();
760
761public:
762 void setIsVersion4(bool version4 = true);
763 bool getIsVersion4() const;
764
765 void setQuarter(int tick);
766 int getQuarter(void) const;
767
768 void setShowPageMargin(bool show);
769 bool getShowPageMargin() const;
770
771 void setShowTransposeTrack(bool show);
772 bool getShowTransposeTrack() const;
773
774 void setShowLineBreak(bool show);
775 bool getShowLineBreak() const;
776
777 void setShowRuler(bool show);
778 bool getShowRuler() const;
779
780 void setShowColor(bool show);
781 bool getShowColor() const;
782
783 void setPlayRepeat(bool play);
784 bool getPlayRepeat() const;
785
786 enum PlayStyle{
787 Record, Swing, Notation
788 };
789 void setPlayStyle(PlayStyle style);
790 PlayStyle getPlayStyle() const;
791
792 void addTitle(const QString& str);
793 QList<QString> getTitles(void) const;
794
795 void addAnnotate(const QString& str);
796 QList<QString> getAnnotates(void) const;
797
798 void addWriter(const QString& str);
799 QList<QString> getWriters(void) const;
800
801 void addCopyright(const QString& str);
802 QList<QString> getCopyrights(void) const;
803
804 void addHeader(const QString& str);
805 QList<QString> getHeaders(void) const;
806
807 void addFooter(const QString& str);
808 QList<QString> getFooters(void) const;
809
810 void addTrack(Track* ptr);
811 int getTrackCount(void) const;
812 QList<Track*> getTracks() const;
813 Track* getTrack(int part, int staff) const;
814
815 void setTrackBarCount(int count);
816 int getTrackBarCount() const;
817
818 bool addPage(Page* page);
819 int getPageCount() const;
820 Page* getPage(int idx);
821
822 void addLine(Line* ptr);
823 int getLineCount() const;
824 Line* getLine(int idx) const;
825
826 void addMeasure(Measure* ptr);
827 int getMeasureCount(void) const;
828 Measure* getMeasure(int bar) const;
829
830 void addMeasureData(MeasureData* ptr);
831 int getMeasureDataCount(void) const;
832 MeasureData* getMeasureData(int part, int staff/*=0*/, int bar) const;
833 MeasureData* getMeasureData(int track, int bar) const;
834
835 // tool
836 void setPartStaffCounts(const QList<int>& partStaffCounts);
837 int getPartCount() const;
838 int getStaffCount(int part) const;
839 int getPartBarCount() const;
840
841 void clear(void);
842
843 QPair<int, int> trackToPartStaff(int track) const;
844
845 void setTextCodecName(const QString& codecName);
846 QString getCodecString(const QByteArray& text);
847
848private:
849 int partStaffToTrack(int part, int staff) const;
850
851private:
852 bool version4_;
853 int quarter_;
854
855 bool showPageMargin_;
856 bool showTransposeTrack;
857 bool showLineBreak_;
858 bool showRuler_;
859 bool showColor_;
860 bool playRepeat_;
861 PlayStyle playStyle_;
862
863 QList<QString> titles_;
864 QList<QString> annotates_;
865 QList<QString> writers_;
866 QList<QString> copyrights_;
867 QList<QString> headers_;
868 QList<QString> footers_;
869
870 QList<Track*> tracks_;
871 QList<Page*> pages_;
872 QList<Line*> lines_;
873 QList<Measure*> measures_;
874 QList<MeasureData*> measureDatas_;
875 int trackBarCount_; //equal to measures_.size()
876
877 QList<int> partStaffCounts_;
878 QTextCodec* codec_;
879};
880
881class Voice {
882public:
883 Voice();
884 ~Voice(){}
885
886public:
887 void setChannel(int channel);
888 int getChannel() const;
889
890 void setVolume(int volume);
891 int getVolume() const;
892
893 void setPitchShift(int pitchShift);
894 int getPitchShift() const;
895
896 void setPan(int pan);
897 int getPan() const;
898
899 void setPatch(int patch);
900 int getPatch() const;
901
902 void setStemType(int stemType);
903 int getStemType() const;
904
905 static int getDefaultPatch();
906 static int getDefaultVolume();
907
908private:
909 int channel_; // [0, 15]
910 int volume_; // [-1, 127], -1 default
911 int pitchShift_; // [-36, 36]
912 int pan_; // [-64, 63]
913 int patch_; // [0, 127]
914 int stemType_; // 0, 1, 2
915};
916
917class Track {
918public:
919 Track();
920 ~Track();
921
922public:
923 void setName(const QString& str);
924 QString getName(void) const;
925
926 void setBriefName(const QString& str);
927 QString getBriefName(void) const;
928
929 void setPatch(unsigned int patch); // -1: percussion
930 unsigned int getPatch() const;
931
932 void setChannel(int channel);
933 int getChannel() const;
934
935 void setShowName(bool show);
936 bool getShowName() const;
937
938 void setShowBriefName(bool show);
939 bool getShowBriefName() const;
940
941 void setMute(bool mute);
942 bool getMute() const;
943
944 void setSolo(bool solo);
945 bool getSolo() const;
946
947 void setShowKeyEachLine(bool show);
948 bool getShowKeyEachLine() const;
949
950 void setVoiceCount(int voices);
951 int getVoiceCount() const;
952
953 void addVoice(Voice* voice);
954 QList<Voice*> getVoices() const;
955
956 void setShowTranspose(bool show);
957 bool getShowTranspose() const;
958
959 void setTranspose(int transpose);
960 int getTranspose() const;
961
962 void setNoteShift(int shift);
963 int getNoteShift() const;
964
965 void setStartClef(int clef/*in ClefType*/);
966 ClefType getStartClef() const;
967
968 void setTransposeClef(int clef);
969 int getTansposeClef() const;
970
971 void setStartKey(int key/*in KeyType*/);
972 int getStartKey() const;
973
974 void setDisplayPercent(unsigned int percent/*25~100*/);
975 unsigned int getDisplayPercent() const;
976
977 void setShowLegerLine(bool show);
978 bool getShowLegerLine() const;
979
980 void setShowClef(bool show);
981 bool getShowClef() const;
982
983 void setShowTimeSignature(bool show);
984 bool getShowTimeSignature() const;
985
986 void setShowKeySignature(bool show);
987 bool getShowKeySignature() const;
988
989 void setShowBarline(bool show);
990 bool getShowBarline() const;
991
992 void setFillWithRest(bool fill);
993 bool getFillWithRest() const;
994
995 void setFlatTail(bool flat);
996 bool getFlatTail() const;
997
998 void setShowClefEachLine(bool show);
999 bool getShowClefEachLine() const;
1000
1001 struct DrumNode {
1002 int line_;
1003 int headType_;
1004 int pitch_;
1005 int voice_;
1006
1007 public:
1008 DrumNode():line_(0), headType_(0), pitch_(0), voice_(0){}
1009 };
1010 void addDrum(const DrumNode& node);
1011 QList<DrumNode> getDrumKit() const;
1012
1013 void clear(void);
1014
1016 void setPart(int part);
1017 int getPart() const;
1018
1019private:
1020 int number_;
1021 QString name_;
1022 QString briefName_;
1023 unsigned int patch_;
1024 int channel_;
1025 int transpose_;
1026 bool showTranspose_;
1027 int noteShift_;
1028 int startClef_;
1029 int transposeClef_;
1030 unsigned int displayPercent_;
1031 int startKey_;
1032 int voiceCount_;
1033 QList<Voice*> voices_;
1034
1035 bool showName_;
1036 bool showBriefName_;
1037 bool showKeyEachLine_;
1038 bool showLegerLine_;
1039 bool showClef_;
1040 bool showTimeSignature_;
1041 bool showKeySignature_;
1042 bool showBarline_;
1043 bool showClefEachLine_;
1044
1045 bool fillWithRest_;
1046 bool flatTail_;
1047
1048 bool mute_;
1049 bool solo_;
1050
1051 QList<DrumNode> drumKit_;
1052
1054 int part_;
1055};
1056
1057class Page {
1058public:
1059 Page();
1060 ~Page(){}
1061
1062public:
1063 void setBeginLine(int line);
1064 int getBeginLine() const;
1065
1066 void setLineCount(int count);
1067 int getLineCount() const;
1068
1069 void setLineInterval(int interval); // between system
1070 int getLineInterval() const;
1071
1072 void setStaffInterval(int interval);
1073 int getStaffInterval() const;
1074
1075 void setStaffInlineInterval(int interval); // between treble-bass staff
1076 int getStaffInlineInterval() const;
1077
1078 void setLineBarCount(int count);
1079 int getLineBarCount() const;
1080
1081 void setPageLineCount(int count);
1082 int getPageLineCount() const;
1083
1084 void setLeftMargin(int margin);
1085 int getLeftMargin() const;
1086
1087 void setTopMargin(int margin);
1088 int getTopMargin() const;
1089
1090 void setRightMargin(int margin);
1091 int getRightMargin() const;
1092
1093 void setBottomMargin(int margin);
1094 int getBottomMargin() const;
1095
1096 void setPageWidth(int width);
1097 int getPageWidth() const;
1098
1099 void setPageHeight(int height);
1100 int getPageHeight() const;
1101
1102private:
1103 int beginLine_;
1104 int lineCount_;
1105
1106 int lineInterval_;
1107 int staffInterval_;
1108 int staffInlineInterval_;
1109
1110 int lineBarCount_;
1111 int pageLineCount_;
1112
1113 int leftMargin_;
1114 int topMargin_;
1115 int rightMargin_;
1116 int bottomMargin_;
1117
1118 int pageWidth_;
1119 int pageHeight_;
1120};
1121
1122class Line {
1123public:
1124 Line();
1125 ~Line();
1126
1127public:
1128 void addStaff(Staff* staff);
1129 int getStaffCount() const;
1130 Staff* getStaff(int idx) const;
1131
1132 void setBeginBar(unsigned int bar);
1133 unsigned int getBeginBar() const;
1134
1135 void setBarCount(unsigned int count);
1136 unsigned int getBarCount() const;
1137
1138 void setYOffset(int offset);
1139 int getYOffset() const;
1140
1141 void setLeftXOffset(int offset);
1142 int getLeftXOffset() const;
1143
1144 void setRightXOffset(int offset);
1145 int getRightXOffset() const;
1146
1147private:
1148 QList<Staff*> staffs_;
1149 unsigned int beginBar_;
1150 unsigned int barCount_;
1151 int yOffset_;
1152 int leftXOffset_;
1153 int rightXOffset_;
1154};
1155
1156class Staff : public OffsetElement {
1157public:
1158 Staff();
1159 virtual ~Staff(){}
1160
1161public:
1162 void setClefType(int clef);
1163 ClefType getClefType() const;
1164
1165 void setKeyType(int key);
1166 int getKeyType() const;
1167
1168 void setVisible(bool visible);
1169 bool setVisible() const;
1170
1171 void setGroupType(GroupType type);
1172 GroupType getGroupType() const;
1173
1174 void setGroupStaffCount(int count);
1175 int getGroupStaffCount() const;
1176
1177private:
1178 ClefType clef_;
1179 int key_;
1180 bool visible_;
1181 GroupType groupType_;
1182 int groupStaffCount_;
1183};
1184
1186
1187class Note : public LineElement {
1188public:
1189 Note();
1190 virtual ~Note(){}
1191
1192public:
1193 void setIsRest(bool rest);
1194 bool getIsRest() const;
1195
1196 void setNote(unsigned int note);
1197 unsigned int getNote() const;
1198
1199 void setAccidental(int type); //AccidentalType
1200 AccidentalType getAccidental() const;
1201
1202 void setShowAccidental(bool show);
1203 bool getShowAccidental() const;
1204
1205 void setOnVelocity(unsigned int velocity);
1206 unsigned int getOnVelocity() const;
1207
1208 void setOffVelocity(unsigned int velocity);
1209 unsigned int getOffVelocity() const;
1210
1211 void setHeadType(int type); //NoteHeadType
1212 NoteHeadType getHeadType() const;
1213
1214 void setTiePos(int tiePos);
1215 TiePos getTiePos() const;
1216
1217 void setOffsetStaff(int offset); // cross staff notes
1218 int getOffsetStaff() const;
1219
1220 void setShow(bool show);
1221 bool getShow() const;
1222
1223 void setOffsetTick(int offset);
1224 int getOffsetTick() const;
1225
1226private:
1227 bool rest_;
1228 unsigned int note_;
1229 AccidentalType accidental_;
1230 bool showAccidental_;
1231 unsigned int onVelocity_;
1232 unsigned int offVelocity_;
1233 NoteHeadType headType_;
1234 TiePos tiePos_;
1235 int offsetStaff_;
1236 bool show_;
1237 int offsetTick_;//for playback
1238};
1239
1240class Articulation : public OffsetElement {
1241public:
1242 Articulation();
1243 virtual ~Articulation(){}
1244
1245public:
1246 void setArtType(int type);//ArticulationType
1247 ArticulationType getArtType() const;
1248
1249 void setPlacementAbove(bool above);
1250 bool getPlacementAbove() const;
1251
1252 // for midi
1253 bool willAffectNotes() const;
1254
1255 static bool isTrill(ArticulationType type);
1256
1257 // for xml
1258 enum XmlType {
1259 Xml_Articulation,
1260 Xml_Technical,
1261 Xml_Arpeggiate,
1262 Xml_Ornament,
1263 Xml_Fermata,
1264 Xml_Direction,
1265
1266 Xml_Unknown
1267 };
1268 XmlType getXmlType() const;
1269
1270 // sound setting
1271 bool getChangeSoundEffect() const;
1272 void setSoundEffect(int soundFrom, int soundTo);
1273 QPair<int, int> getSoundEffect() const;
1274
1275 bool getChangeLength() const;
1276 void setLengthPercentage(int percentage);
1277 int getLengthPercentage() const;
1278
1279 bool getChangeVelocity() const;
1280 enum VelocityType
1281 {
1282 Velocity_Offset,
1283 Velocity_SetValue,
1284 Velocity_Percentage
1285 };
1286 void setVelocityType(VelocityType type);
1287 VelocityType getVelocityType() const;
1288
1289 void setVelocityValue(int value);
1290 int getVelocityValue() const;
1291
1292 bool getChangeExtraLength() const;
1293 void setExtraLength(int length);
1294 int getExtraLength() const;
1295
1296 // trill
1297 enum TrillInterval {
1298 TrillInterval_Diatonic = 0,
1299 TrillInterval_Chromatic,
1300 TrillInterval_Whole
1301 };
1302 void setTrillInterval(int interval);
1303 TrillInterval getTrillInterval() const;
1304
1305 void setAuxiliaryFirst(bool first);
1306 bool getAuxiliaryFirst() const;
1307
1308 void setTrillRate(NoteType rate);
1309 NoteType getTrillRate() const;
1310
1311 void setTrillNoteLength(int length);
1312 int getTrillNoteLength() const;
1313
1314 enum AccelerateType {
1315 Accelerate_None = 0 ,
1316 Accelerate_Slow,
1317 Accelerate_Normal,
1318 Accelerate_Fast
1319 };
1320 void setAccelerateType(int type);
1321 AccelerateType getAccelerateType() const;
1322
1323private:
1324 ArticulationType type_;
1325 bool above_;
1326
1327 bool changeSoundEffect_;
1328 QPair<int, int> soundEffect_;
1329 bool changeLength_;
1330 int lengthPercentage_;
1331 bool changeVelocity_;
1332 VelocityType velocityType_;
1333 int velocityValue_;
1334 bool changeExtraLength_;
1335 int extraLength_;
1336
1337 // trill
1338 TrillInterval trillInterval_;
1339 bool auxiliaryFirst_;
1340 NoteType trillRate_;
1341 int trillNoteLength_;
1342 AccelerateType accelerateType_;
1343};
1344
1345class NoteContainer : public MusicData, public LengthElement {
1346public:
1347 NoteContainer();
1348 virtual ~NoteContainer();
1349
1350public:
1351 void setIsGrace(bool grace);
1352 bool getIsGrace() const;
1353
1354 void setIsCue(bool cue);
1355 bool getIsCue() const;
1356
1357 void setIsRest(bool rest/*or note*/);
1358 bool getIsRest() const;
1359
1360 void setIsRaw(bool raw);
1361 bool getIsRaw() const;
1362
1363 void setNoteType(NoteType type);
1364 NoteType getNoteType() const;
1365
1366 void setDot(int dot);
1367 int getDot() const;
1368
1369 void setGraceNoteType(NoteType type);
1370 NoteType getGraceNoteType() const;
1371
1372 void setInBeam(bool in);
1373 bool getInBeam() const;
1374
1375 void setStemUp(bool up);
1376 bool getStemUp(void) const;
1377
1378 void setShowStem(bool show);
1379 bool getShowStem() const;
1380
1381 void setStemLength(int line);
1382 int getStemLength() const;
1383
1384 void setTuplet(int tuplet);
1385 int getTuplet() const;
1386
1387 void setSpace(int space);
1388 int getSpace() const;
1389
1390 void addNoteRest(Note* note);
1391 QList<Note*> getNotesRests() const;
1392
1393 void addArticulation(Articulation* art);
1394 QList<Articulation*> getArticulations() const;
1395
1396 void setNoteShift(int octave);
1397 int getNoteShift() const;
1398
1399 int getOffsetStaff() const;
1400
1401 int getDuration() const;
1402
1403private:
1404 bool grace_;
1405 bool cue_;
1406 bool rest_;
1407 bool raw_;
1408 NoteType noteType_;
1409 int dot_;
1410 NoteType graceNoteType_;
1411 int tuplet_;
1412 int space_;
1413 bool inBeam_;
1414 bool stemUp_;
1415 bool showStem_;
1416 int stemLength_; // line count span
1417 int noteShift_;
1418
1419 QList<Note*> notes_;
1420 QList<Articulation*> articulations_;
1421};
1422
1423class Beam : public MusicData, public PairEnds {
1424public:
1425 Beam();
1426 virtual ~Beam(){}
1427
1428public:
1429 void setIsGrace(bool grace);
1430 bool getIsGrace() const;
1431
1432 void addLine(const MeasurePos& startMp, const MeasurePos& endMp);
1433 const QList<QPair<MeasurePos, MeasurePos> > getLines() const;
1434
1435private:
1436 bool grace_;
1437 QList<QPair<MeasurePos, MeasurePos> > lines_;
1438};
1439
1440class Tie : public MusicData, public PairEnds {
1441public:
1442 Tie();
1443 virtual ~Tie(){}
1444
1445public:
1446 void setShowOnTop(bool top);
1447 bool getShowOnTop() const;
1448
1449 void setNote(int note);// note value tie point to
1450 int getNote() const;
1451
1452 void setHeight(int height);
1453 int getHeight() const;
1454
1455private:
1456 bool showOnTop_;
1457 int note_;
1458 int height_;
1459};
1460
1461class Glissando : public MusicData, public PairEnds {
1462public:
1463 Glissando();
1464 virtual ~Glissando(){}
1465
1466public:
1467 void setStraightWavy(bool straight);
1468 bool getStraightWavy() const;
1469
1470 void setText(const QString& text);
1471 QString getText() const;
1472
1473 void setLineThick(int thick);
1474 int getLineThick() const;
1475
1476private:
1477 bool straight_;
1478 QString text_;
1479 int lineThick_;
1480};
1481
1482class Decorator : public MusicData {
1483public:
1484 Decorator();
1485 virtual ~Decorator(){}
1486
1487public:
1488 enum DecoratorType {
1489 Decorator_Dotted_Barline = 0,
1490 Decorator_Articulation
1491 };
1492 void setDecoratorType(DecoratorType type);
1493 DecoratorType getDecoratorType() const;
1494
1495 void setArticulationType(ArticulationType type);
1496 ArticulationType getArticulationType() const;
1497
1498private:
1499 DecoratorType decoratorType_;
1500 ArticulationType artType_;
1501};
1502
1503class MeasureRepeat : public MusicData {
1504public:
1505 MeasureRepeat();
1506 virtual ~MeasureRepeat(){}
1507
1508public:
1509 void setSingleRepeat(bool single); // false : double
1510 bool getSingleRepeat() const;
1511
1512private:
1513 bool singleRepeat_;
1514};
1515
1516class Tuplet : public MusicData, public PairEnds {
1517public:
1518 Tuplet();
1519 virtual ~Tuplet();
1520
1521public:
1522 void setTuplet(int tuplet=3);
1523 int getTuplet() const;
1524
1525 void setSpace(int space=2);
1526 int getSpace() const;
1527
1528 void setHeight(int height);
1529 int getHeight() const;
1530
1531 void setNoteType(NoteType type);
1532 NoteType getNoteType() const;
1533
1534 OffsetElement* getMarkHandle() const;
1535
1536private:
1537 int tuplet_;
1538 int space_;
1539 int height_;
1540 NoteType noteType_;
1541 OffsetElement* mark_;
1542};
1543
1544class Harmony : public MusicData, public LengthElement {
1545public:
1546 Harmony();
1547 virtual ~Harmony(){}
1548
1549public:
1550 void setHarmonyType(HarmonyType type);
1551 HarmonyType getHarmonyType() const;
1552
1553 void setRoot(int root=0);//C
1554 int getRoot() const;
1555
1556 void setBass(int bass);
1557 int getBass() const;
1558
1559 void setBassOnBottom(bool on);
1560 bool getBassOnBottom() const;
1561
1562 void setAngle(int angle);
1563 int getAngle() const;
1564
1565private:
1566 HarmonyType harmonyType_;
1567 int root_;
1568 int bass_;
1569 bool bassOnBottom_;
1570 int angle_;
1571};
1572
1573class Clef : public MusicData, public LineElement {
1574public:
1575 Clef();
1576 virtual ~Clef(){}
1577
1578public:
1579 void setClefType(int type); // ClefType
1580 ClefType getClefType() const;
1581
1582private:
1583 ClefType clefType_;
1584};
1585
1586class Lyric : public MusicData {
1587public:
1588 Lyric();
1589 virtual ~Lyric(){}
1590
1591public:
1592 void setLyric(const QString& lyricText);
1593 QString getLyric() const;
1594
1595 void setVerse(int verse);
1596 int getVerse() const;
1597
1598private:
1599 QString lyric_;
1600 int verse_;
1601};
1602
1603class Slur: public MusicData, public PairEnds {
1604public:
1605 Slur();
1606 virtual ~Slur();
1607
1608public:
1609 void setContainerCount(int count); // span
1610 int getContainerCount() const;
1611
1612 void setShowOnTop(bool top);
1613 bool getShowOnTop() const;
1614
1615 OffsetElement* getHandle2() const;
1616 OffsetElement* getHandle3() const;
1617
1618 void setNoteTimePercent(int percent); // 50% ~ 200%
1619 int getNoteTimePercent() const;
1620
1621private:
1622 int containerCount_;
1623 bool showOnTop_;
1624 int noteTimePercent_;
1625 OffsetElement* handle_2_;
1626 OffsetElement* handle_3_;
1627};
1628
1629class Dynamics: public MusicData {
1630public:
1631 Dynamics();
1632 virtual ~Dynamics() {}
1633
1634public:
1635 void setDynamicsType(int type);//DynamicsType
1636 DynamicsType getDynamicsType() const;
1637
1638 void setIsPlayback(bool play);
1639 bool getIsPlayback() const;
1640
1641 void setVelocity(int vel);
1642 int getVelocity() const;
1643
1644private:
1645 DynamicsType dynamicsType_;
1646 bool playback_;
1647 int velocity_;
1648};
1649
1650class WedgeEndPoint: public MusicData {
1651public:
1652 WedgeEndPoint();
1653 virtual ~WedgeEndPoint() {}
1654
1655public:
1656 void setWedgeType(WedgeType type);
1657 WedgeType getWedgeType() const;
1658
1659 void setHeight(int height);
1660 int getHeight() const;
1661
1662 void setWedgeStart(bool wedgeStart);
1663 bool getWedgeStart() const;
1664
1665private:
1666 int height_;
1667 WedgeType wedgeType_;
1668 bool wedgeStart_;
1669};
1670
1671class Wedge: public MusicData {
1672public:
1673 Wedge();
1674 virtual ~Wedge() {}
1675
1676public:
1677 void setWedgeType(WedgeType type);
1678 WedgeType getWedgeType() const;
1679
1680 void setHeight(int height);
1681 int getHeight() const;
1682
1683private:
1684 int height_;
1685 WedgeType wedgeType_;
1686};
1687
1688class Pedal: public MusicData, public PairEnds {
1689public:
1690 Pedal();
1691 virtual ~Pedal();
1692
1693public:
1694 void setHalf(bool half);
1695 bool getHalf() const;
1696
1697 void setIsPlayback(bool playback);
1698 bool getIsPlayback() const;
1699
1700 void setPlayOffset(int offset); // -127~127
1701 int getPlayOffset() const;
1702
1703 OffsetElement* getPedalHandle() const; //only on half pedal
1704
1705private:
1706 bool half_;
1707 bool playback_;
1708 int playOffset_;
1709 OffsetElement* pedalHandle_;
1710};
1711
1712class KuoHao: public MusicData, public PairEnds {
1713public:
1714 KuoHao();
1715 virtual ~KuoHao() {}
1716
1717public:
1718 void setHeight(int height);
1719 int getHeight() const;
1720
1721 void setKuohaoType(int type);// KuoHaoType
1722 KuoHaoType getKuohaoType() const;
1723
1724private:
1725 int height_;
1726 KuoHaoType kuohaoType_;
1727};
1728
1729class Expressions: public MusicData {
1730public:
1731 Expressions();
1732 virtual ~Expressions() {}
1733
1734public:
1735 void setText(const QString& str);
1736 QString getText() const;
1737
1738private:
1739 QString text_;
1740};
1741
1742class HarpPedal: public MusicData {
1743public:
1744 HarpPedal();
1745 virtual ~HarpPedal() {}
1746
1747public:
1748 void setShowType(int type);//0:graph, 1:char, 2:char cut, 3:change
1749 int getShowType() const;
1750
1751 void setShowCharFlag(int flag);//each bit is a bool, total 7 bools
1752 int getShowCharFlag() const;
1753
1754private:
1755 int showType_;
1756 int showCharFlag_;
1757};
1758
1759class OctaveShift: public MusicData, public LengthElement {
1760public:
1761 OctaveShift();
1762 virtual ~OctaveShift() {}
1763
1764public:
1765 void setOctaveShiftType(int type);
1766 OctaveShiftType getOctaveShiftType() const;
1767
1768 int getNoteShift() const;
1769
1770 void setEndTick(int tick);
1771 int getEndTick() const;
1772
1773private:
1774 OctaveShiftType octaveShiftType_;
1775 OctaveShiftPosition octaveShiftPosition_;
1776 int endTick_;
1777};
1778
1779class OctaveShiftEndPoint: public MusicData, public LengthElement {
1780public:
1781 OctaveShiftEndPoint();
1782 virtual ~OctaveShiftEndPoint() {}
1783
1784public:
1785 void setOctaveShiftType(int type);
1786 OctaveShiftType getOctaveShiftType() const;
1787
1788 void setOctaveShiftPosition(int position);
1789 OctaveShiftPosition getOctaveShiftPosition() const;
1790
1791 void setEndTick(int tick);
1792 int getEndTick() const;
1793
1794private:
1795 OctaveShiftType octaveShiftType_;
1796 OctaveShiftPosition octaveShiftPosition_;
1797 int endTick_;
1798};
1799
1800class MultiMeasureRest: public MusicData {
1801public:
1802 MultiMeasureRest();
1803 virtual ~MultiMeasureRest() {}
1804
1805public:
1806 void setMeasureCount(int count);
1807 int getMeasureCount() const;
1808
1809private:
1810 int measureCount_;
1811};
1812
1813class Tempo: public MusicData {
1814public:
1815 Tempo();
1816 virtual ~Tempo() {}
1817
1818public:
1819 void setLeftNoteType(int type);//NoteType
1820 NoteType getLeftNoteType() const;
1821
1822 void setShowMark(bool show);
1823 bool getShowMark() const;
1824
1825 void setShowBeforeText(bool show);
1826 bool getShowBeforeText() const;
1827
1828 void setShowParenthesis(bool show);
1829 bool getShowParenthesis() const;
1830
1831 void setTypeTempo(int tempo); //0x2580 = 96.00
1832 int getTypeTempo() const;
1833 int getQuarterTempo() const;
1834
1835 void setLeftText(const QString& str);// string at left of the mark
1836 QString getLeftText() const;
1837
1838 void setRightText(const QString& str);
1839 QString getRightText() const;
1840
1841 void setSwingEighth(bool swing);
1842 bool getSwingEighth() const;
1843
1844 void setRightNoteType(int type);
1845 int getRightNoteType() const;
1846
1847private:
1848 int leftNoteType_;
1849 bool showMark_;
1850 bool showText_;
1851 bool showParenthesis_;
1852 int typeTempo_;
1853 QString leftText_;
1854 QString rightText_;
1855 bool swingEighth_;
1856 int rightNoteType_;
1857};
1858
1859class Text: public MusicData, public LengthElement {
1860public:
1861 Text();
1862 virtual ~Text() {}
1863
1864public:
1865 enum TextType {
1866 Text_Rehearsal,
1867 Text_SystemText,
1868 Text_MeasureText
1869 };
1870
1871 void setTextType(TextType type);
1872 TextType getTextType() const;
1873
1874 void setHorizontalMargin(int margin);
1875 int getHorizontalMargin() const;
1876
1877 void setVerticalMargin(int margin);
1878 int getVerticalMargin() const;
1879
1880 void setLineThick(int thick);
1881 int getLineThick() const;
1882
1883 void setText(const QString& text);
1884 QString getText() const;
1885
1886 void setWidth(int width);
1887 int getWidth() const;
1888
1889 void setHeight(int height);
1890 int getHeight() const;
1891
1892private:
1893 TextType textType_;
1894 int horiMargin_;
1895 int vertMargin_;
1896 int lineThick_;
1897 QString text_;
1898 int width_;
1899 int height_;
1900};
1901
1903
1904class TimeSignature: public MusicData {
1905public:
1906 TimeSignature();
1907 virtual ~TimeSignature() {}
1908
1909public:
1910 void setNumerator(int numerator);
1911 int getNumerator() const;
1912
1913 void setDenominator(int denominator);
1914 int getDenominator() const;
1915
1916 void setIsSymbol(bool symbol); //4/4:common, 2/2:cut
1917 bool getIsSymbol() const;
1918
1919 void setBeatLength(int length); // tick
1920 int getBeatLength() const;
1921
1922 void setBarLength(int length); // tick
1923 int getBarLength() const;
1924
1925 void addBeat(int startUnit, int lengthUnit, int startTick);
1926 void endAddBeat();
1927 int getUnits() const;
1928
1929 void setReplaceFont(bool replace);
1930 bool getReplaceFont() const;
1931
1932 void setShowBeatGroup(bool show);
1933 bool getShowBeatGroup() const;
1934
1935 void setGroupNumerator1(int numerator);
1936 void setGroupNumerator2(int numerator);
1937 void setGroupNumerator3(int numerator);
1938 void setGroupDenominator1(int denominator);
1939 void setGroupDenominator2(int denominator);
1940 void setGroupDenominator3(int denominator);
1941
1942 void setBeamGroup1(int count);
1943 void setBeamGroup2(int count);
1944 void setBeamGroup3(int count);
1945 void setBeamGroup4(int count);
1946
1947 void set16thBeamCount(int count);
1948 void set32thBeamCount(int count);
1949
1950private:
1951 int numerator_;
1952 int denominator_;
1953 bool isSymbol_;
1954 int beatLength_;
1955 int barLength_;
1956
1957 struct BeatNode {
1958 int startUnit_;
1959 int lengthUnit_;
1960 int startTick_;
1961
1962 BeatNode() :
1963 startUnit_(0),
1964 lengthUnit_(0),
1965 startTick_(0) {
1966 }
1967 };
1968 QList<BeatNode> beats_;
1969 int barLengthUnits_;
1970
1971 bool replaceFont_;
1972 bool showBeatGroup_;
1973
1974 int groupNumerator1_;
1975 int groupNumerator2_;
1976 int groupNumerator3_;
1977 int groupDenominator1_;
1978 int groupDenominator2_;
1979 int groupDenominator3_;
1980
1981 int beamGroup1_;
1982 int beamGroup2_;
1983 int beamGroup3_;
1984 int beamGroup4_;
1985
1986 int beamCount16th_;
1987 int beamCount32th_;
1988};
1989
1990class Key: public MusicData {
1991public:
1992 Key();
1993 virtual ~Key() {}
1994
1995public:
1996 void setKey(int key); //C=0x0, G=0x8, C#=0xE, F=0x1, Db=0x7
1997 int getKey() const;
1998 bool getSetKey() const;
1999
2000 void setPreviousKey(int key);
2001 int getPreviousKey() const;
2002
2003 void setSymbolCount(int count);
2004 int getSymbolCount() const;
2005
2006private:
2007 int key_;
2008 bool set_;
2009 int previousKey_;
2010 int symbolCount_;
2011};
2012
2013class RepeatSymbol: public MusicData {
2014public:
2015 RepeatSymbol();
2016 virtual ~RepeatSymbol() {}
2017
2018public:
2019 void setText(const QString& text);
2020 QString getText() const;
2021
2022 void setRepeatType(int repeatType);
2023 RepeatType getRepeatType() const;
2024
2025private:
2026 QString text_;
2027 RepeatType repeatType_;
2028};
2029
2030class NumericEnding: public MusicData, public PairEnds {
2031public:
2032 NumericEnding();
2033 virtual ~NumericEnding();
2034
2035public:
2036 OffsetElement* getNumericHandle() const;
2037
2038 void setHeight(int height);
2039 int getHeight() const;
2040
2041 void setText(const QString& text);
2042 QString getText() const;
2043 QList<int> getNumbers() const;
2044 int getJumpCount() const;
2045
2046private:
2047 int height_;
2048 QString text_;
2049 OffsetElement* numericHandle_;
2050};
2051
2052class BarNumber: public MusicData {
2053public:
2054 BarNumber();
2055 virtual ~BarNumber() {}
2056
2057public:
2058 void setIndex(int index);
2059 int getIndex() const;
2060
2061 void setShowOnParagraphStart(bool show);
2062 bool getShowOnParagraphStart() const;
2063
2064 void setAlign(int align);// 0:left, 1:center, 2:right
2065 int getAlign() const;
2066
2067 void setShowFlag(int flag); // 0:page, 1:staff, 2:bar, 3:none
2068 int getShowFlag() const;
2069
2070 void setShowEveryBarCount(int count);
2071 int getShowEveryBarCount() const;
2072
2073 void setPrefix(const QString& str);
2074 QString getPrefix() const;
2075
2076private:
2077 int index_;
2078 bool showOnParagraphStart_;
2079 int align_;
2080 int showFlag_;
2081 int barRange_;
2082 QString prefix_;
2083};
2084
2086// MIDI
2087class MidiController: public MidiData {
2088public:
2089 MidiController();
2090 virtual ~MidiController() {}
2091
2092public:
2093 void setController(int number);
2094 int getController() const;
2095
2096 void setValue(int value);
2097 int getValue() const;
2098
2099private:
2100 int controller_;
2101 int value_;
2102};
2103
2104class MidiProgramChange: public MidiData {
2105public:
2106 MidiProgramChange();
2107 virtual ~MidiProgramChange() {}
2108
2109public:
2110 void setPatch(int patch);
2111 int getPatch() const;
2112
2113private:
2114 int patch_;
2115};
2116
2117class MidiChannelPressure: public MidiData {
2118public:
2119 MidiChannelPressure();
2120 virtual ~MidiChannelPressure() {}
2121
2122public:
2123 void setPressure(int pressure);
2124 int getPressure() const;
2125
2126private:
2127 int pressure_;
2128};
2129
2130class MidiPitchWheel: public MidiData {
2131public:
2132 MidiPitchWheel();
2133 virtual ~MidiPitchWheel() {}
2134
2135public:
2136 void setValue(int value);
2137 int getValue() const;
2138
2139private:
2140 int value_;
2141};
2142
2144class Measure: public LengthElement {
2145public:
2146 Measure(int index = 0);
2147 virtual ~Measure();
2148
2149private:
2150 Measure();
2151
2152public:
2153 BarNumber* getBarNumber() const;
2154 TimeSignature* getTime() const;
2155
2156 void setLeftBarline(int barline/*in BarlineType*/);
2157 BarlineType getLeftBarline() const;
2158
2159 void setRightBarline(int barline/*in BarlineType*/);
2160 BarlineType getRightBarline() const;
2161
2162 // set when rightBarline == Baline_Backward
2163 void setBackwardRepeatCount(int repeatCount);
2164 int getBackwardRepeatCount() const;
2165
2166 void setTypeTempo(double tempo);
2167 double getTypeTempo() const;
2168
2169 void setIsPickup(bool pickup);
2170 bool getIsPickup() const;
2171
2172 void setIsMultiMeasureRest(bool rest);
2173 bool getIsMultiMeasureRest() const;
2174
2175 void setMultiMeasureRestCount(int count);
2176 int getMultiMeasureRestCount() const;
2177
2178private:
2179 void clear();
2180
2181 BarNumber* barNumber_;
2182 TimeSignature* time_;
2183
2184 BarlineType leftBarline_;
2185 BarlineType rightBarline_;
2186 int repeatCount_;
2187 double typeTempo_; // based on some type
2188 bool pickup_;
2189 bool multiMeasureRest_;
2190 int multiMeasureRestCount_;
2191};
2192
2193class MeasureData {
2194public:
2195 MeasureData();
2196 ~MeasureData();
2197
2198public:
2199 Clef* getClef() const;
2200 Key* getKey() const;
2201
2202 void addNoteContainer(NoteContainer* ptr);
2203 QList<NoteContainer*> getNoteContainers() const;
2204
2205 // put Tempo, Text, RepeatSymbol to MeasureData at part=0 && staff=0
2206 void addMusicData(MusicData* ptr);
2207 // if type==MusicData_None, return all
2208 QList<MusicData*> getMusicDatas(MusicDataType type);//MusicXml: note|direction|harmony
2209
2210 // put NumericEnding to MeasureData at part=0 && staff=0
2211 void addCrossMeasureElement(MusicData* ptr, bool start);
2212 enum PairType {
2213 PairType_Start,
2214 PairType_Stop,
2215 PairType_All
2216 };
2217 QList<MusicData*> getCrossMeasureElements(MusicDataType type, PairType pairType);
2218
2219 // for midi
2220 void addMidiData(MidiData* ptr);
2221 QList<MidiData*> getMidiDatas(MidiType type);
2222
2223private:
2224 Key* key_;
2225 Clef* clef_;
2226 QList<MusicData*> musicDatas_;
2227 QList<NoteContainer*> noteContainers_;
2228 QList<QPair<MusicData*, bool> > crossMeasureElements_;
2229 QList<MidiData*> midiDatas_;
2230};
2231
2232// StreamHandle
2233class StreamHandle {
2234public:
2235 StreamHandle(unsigned char* p, int size);
2236 virtual ~StreamHandle();
2237
2238private:
2239 StreamHandle();
2240
2241public:
2242 virtual bool read(char* buff, int size);
2243 virtual bool write(char* buff, int size);
2244
2245private:
2246 int size_;
2247 int curPos_;
2248 unsigned char* point_;
2249};
2250
2251// Block.h
2252// base block, or resizable block in ove to store data
2253class Block {
2254public:
2255 Block();
2256 explicit Block(unsigned int size);
2257 virtual ~Block() {
2258 }
2259
2260public:
2261 // size > 0, check this in use code
2262 virtual void resize(unsigned int count);
2263
2264 const unsigned char* data() const;
2265 unsigned char* data();
2266 unsigned int size() const;
2267
2268 bool operator ==(const Block& block) const;
2269 bool operator !=(const Block& block) const;
2270
2271 bool toBoolean() const;
2272 unsigned int toUnsignedInt() const;
2273 int toInt() const;
2274 QByteArray toStrByteArray() const; // string
2275 QByteArray fixedSizeBufferToStrByteArray() const; // string
2276
2277private:
2278 void doResize(unsigned int count);
2279
2280private:
2281 // char [-128, 127], unsigned char [0, 255]
2282 QList<unsigned char> data_;
2283};
2284
2285class FixedBlock: public Block {
2286public:
2287 explicit FixedBlock(unsigned int count);
2288 virtual ~FixedBlock() {
2289 }
2290
2291private:
2292 FixedBlock();
2293
2294private:
2295 // can't resize
2296 virtual void resize(unsigned int count);
2297};
2298
2300// 4 byte block in ove to store size
2301class SizeBlock: public FixedBlock {
2302public:
2303 SizeBlock();
2304 virtual ~SizeBlock() {
2305 }
2306
2307public:
2308 // void fromUnsignedInt(unsigned int count) ;
2309
2310 unsigned int toSize() const;
2311};
2312
2313// 4 bytes block in ove to store name
2314class NameBlock: public FixedBlock {
2315public:
2316 NameBlock();
2317 virtual ~NameBlock() {
2318 }
2319
2320public:
2321 // ingore data more than 4 bytes
2322 bool isEqual(const QString& name) const;
2323};
2324
2325// 2 bytes block in ove to store count
2326class CountBlock: public FixedBlock {
2327public:
2328 CountBlock();
2329 virtual ~CountBlock() {
2330 }
2331
2332public:
2333 // void setValue(unsigned short count) ;
2334
2335 unsigned short toCount() const;
2336};
2337
2338// Chunk.h
2339// content : name
2340class Chunk {
2341public:
2342 Chunk();
2343 virtual ~Chunk() {
2344 }
2345
2346public:
2347 const static QString TrackName;
2348 const static QString PageName;
2349 const static QString LineName;
2350 const static QString StaffName;
2351 const static QString MeasureName;
2352 const static QString ConductName;
2353 const static QString BdatName;
2354
2355 NameBlock getName() const;
2356
2357protected:
2358 NameBlock nameBlock_;
2359};
2360
2361// content : name / size / data
2362class SizeChunk: public Chunk {
2363public:
2364 SizeChunk();
2365 virtual ~SizeChunk();
2366
2367public:
2368 SizeBlock* getSizeBlock() const;
2369 Block* getDataBlock() const;
2370
2371 const static unsigned int version3TrackSize;
2372
2373protected:
2374 SizeBlock* sizeBlock_;
2375 Block* dataBlock_;
2376};
2377
2378// content : name / count
2379class GroupChunk: public Chunk {
2380public:
2381 GroupChunk();
2382 virtual ~GroupChunk();
2383
2384public:
2385 CountBlock* getCountBlock() const;
2386
2387protected:
2388 CountBlock* childCount_;
2389};
2390
2391// ChunkParse.h
2392class BasicParse {
2393public:
2394 BasicParse(OveSong* ove);
2395 virtual ~BasicParse();
2396
2397private:
2398 BasicParse();
2399
2400public:
2401 void setNotify(IOveNotify* notify);
2402 virtual bool parse();
2403
2404protected:
2405 bool readBuffer(Block& placeHolder, unsigned int size);
2406 bool jump(int offset);
2407
2408 void messageOut(const QString& str);
2409
2410protected:
2411 OveSong* ove_;
2412 StreamHandle* handle_;
2413 IOveNotify* notify_;
2414};
2415
2417
2418class OvscParse: public BasicParse {
2419public:
2420 OvscParse(OveSong* ove);
2421 virtual ~OvscParse();
2422
2423public:
2424 void setOvsc(SizeChunk* chunk);
2425
2426 virtual bool parse();
2427
2428private:
2429 SizeChunk* chunk_;
2430};
2431
2432class TrackParse: public BasicParse {
2433public:
2434 TrackParse(OveSong* ove);
2435 virtual ~TrackParse();
2436
2437public:
2438 void setTrack(SizeChunk* chunk);
2439
2440 virtual bool parse();
2441
2442private:
2443 SizeChunk* chunk_;
2444};
2445
2446class GroupParse: BasicParse {
2447public:
2448 GroupParse(OveSong* ove);
2449 virtual ~GroupParse();
2450
2451public:
2452 void addSizeChunk(SizeChunk* sizeChunk);
2453
2454 virtual bool parse();
2455
2456private:
2457 QList<SizeChunk*> sizeChunks_;
2458};
2459
2460class PageGroupParse: public BasicParse {
2461public:
2462 PageGroupParse(OveSong* ove);
2463 virtual ~PageGroupParse();
2464
2465public:
2466 void addPage(SizeChunk* chunk);
2467
2468 virtual bool parse();
2469
2470private:
2471 bool parsePage(SizeChunk* chunk, Page* page);
2472
2473private:
2474 QList<SizeChunk*> pageChunks_;
2475};
2476
2477class StaffCountGetter: public BasicParse {
2478public:
2479 StaffCountGetter(OveSong* ove);
2480 virtual ~StaffCountGetter() {}
2481
2482public:
2483 unsigned int getStaffCount(SizeChunk* chunk);
2484};
2485
2486class LineGroupParse: public BasicParse {
2487public:
2488 LineGroupParse(OveSong* ove);
2489 virtual ~LineGroupParse();
2490
2491public:
2492 void setLineGroup(GroupChunk* chunk);
2493 void addLine(SizeChunk* chunk);
2494 void addStaff(SizeChunk* chunk);
2495
2496 virtual bool parse();
2497
2498private:
2499 bool parseLine(SizeChunk* chunk, Line* line);
2500 bool parseStaff(SizeChunk* chunk, Staff* staff);
2501
2502private:
2503 GroupChunk* chunk_;
2504 QList<SizeChunk*> lineChunks_;
2505 QList<SizeChunk*> staffChunks_;
2506};
2507
2508class BarsParse: public BasicParse {
2509public:
2510 BarsParse(OveSong* ove);
2511 virtual ~BarsParse();
2512
2513public:
2514 void addMeasure(SizeChunk* chunk);
2515 void addConduct(SizeChunk* chunk);
2516 void addBdat(SizeChunk* chunk);
2517
2518 virtual bool parse();
2519
2520private:
2521 bool parseMeas(Measure* measure, SizeChunk* chunk);
2522 bool parseCond(Measure* measure, MeasureData* measureData, SizeChunk* chunk);
2523 bool parseBdat(Measure* measure, MeasureData* measureData, SizeChunk* chunk);
2524
2525 bool getCondElementType(unsigned int byteData, CondType& type);
2526 bool getBdatElementType(unsigned int byteData, BdatType& type);
2527
2528 // COND
2529 bool parseTimeSignature(Measure* measure, int length);
2530 bool parseTimeSignatureParameters(Measure* measure, int length);
2531 bool parseRepeatSymbol(MeasureData* measureData, int length);
2532 bool parseNumericEndings(MeasureData* measureData, int length);
2533 bool parseTempo(MeasureData* measureData, int length);
2534 bool parseBarNumber(Measure* measure, int length);
2535 bool parseText(MeasureData* measureData, int length);
2536 bool parseBarlineParameters(Measure* measure, int length);
2537
2538 // BDAT
2539 bool parseNoteRest(MeasureData* measureData, int length, BdatType type);
2540 bool parseBeam(MeasureData* measureData, int length);
2541 bool parseTie(MeasureData* measureData, int length);
2542 bool parseTuplet(MeasureData* measureData, int length);
2543 bool parseHarmony(MeasureData* measureData, int length);
2544 bool parseClef(MeasureData* measureData, int length);
2545 bool parseLyric(MeasureData* measureData, int length);
2546 bool parseSlur(MeasureData* measureData, int length);
2547 bool parseGlissando(MeasureData* measureData, int length);
2548 bool parseDecorators(MeasureData* measureData, int length);
2549 bool parseDynamics(MeasureData* measureData, int length);
2550 bool parseWedge(MeasureData* measureData, int length);
2551 bool parseKey(MeasureData* measureData, int length);
2552 bool parsePedal(MeasureData* measureData, int length);
2553 bool parseKuohao(MeasureData* measureData, int length);
2554 bool parseExpressions(MeasureData* measureData, int length);
2555 bool parseHarpPedal(MeasureData* measureData, int length);
2556 bool parseMultiMeasureRest(MeasureData* measureData, int length);
2557 bool parseHarmonyGuitarFrame(MeasureData* measureData, int length);
2558 bool parseOctaveShift(MeasureData* measureData, int length);
2559 bool parseMidiController(MeasureData* measureData, int length);
2560 bool parseMidiProgramChange(MeasureData* measureData, int length);
2561 bool parseMidiChannelPressure(MeasureData* measureData, int length);
2562 bool parseMidiPitchWheel(MeasureData* measureData, int length);
2563
2564 bool parseSizeBlock(int length);
2565 bool parseMidiCommon(MidiData* ptr);
2566 bool parseCommonBlock(MusicData* ptr);
2567 bool parseOffsetCommonBlock(MusicData* ptr);
2568 bool parsePairLinesBlock(PairEnds* ptr); //size==2
2569 bool parseOffsetElement(OffsetElement* ptr);//size==2
2570
2571private:
2572 QList<SizeChunk*> measureChunks_;
2573 QList<SizeChunk*> conductChunks_;
2574 QList<SizeChunk*> bdatChunks_;
2575};
2576
2577class LyricChunkParse: public BasicParse {
2578public:
2579 LyricChunkParse(OveSong* ove);
2580 virtual ~LyricChunkParse() {}
2581
2582public:
2583 void setLyricChunk(SizeChunk* chunk);
2584
2585 virtual bool parse();
2586
2587private:
2588 struct LyricInfo {
2589 int track_;
2590 int measure_;
2591 int verse_;
2592 int voice_;
2593 int wordCount_;
2594 int lyricSize_;
2595 QString name_;
2596 QString lyric_;
2597 int font_;
2598 int fontSize_;
2599 int fontStyle_;
2600
2601 LyricInfo() :
2602 track_(0), measure_(0), verse_(0), voice_(0), wordCount_(0),
2603 lyricSize_(0), name_(QString()), lyric_(QString()),
2604 font_(0), fontSize_(12), fontStyle_(0) {}
2605 };
2606
2607 void processLyricInfo(const LyricInfo& info);
2608
2609private:
2610 SizeChunk* chunk_;
2611};
2612
2613class TitleChunkParse: public BasicParse {
2614public:
2615 TitleChunkParse(OveSong* ove);
2616 virtual ~TitleChunkParse() {}
2617
2618public:
2619 void setTitleChunk(SizeChunk* chunk);
2620
2621 virtual bool parse();
2622
2623private:
2624 void addToOve(const QString& str, unsigned int titleType);
2625
2626private:
2627 unsigned int titleType_;
2628 unsigned int annotateType_;
2629 unsigned int writerType_;
2630 unsigned int copyrightType_;
2631 unsigned int headerType_;
2632 unsigned int footerType_;
2633
2634 SizeChunk* chunk_;
2635};
2636
2637// OveOrganizer.h
2638class OveOrganizer {
2639public:
2640 OveOrganizer(OveSong* ove) ;
2641 virtual ~OveOrganizer(){}
2642
2643public:
2644 void organize() ;
2645
2646private:
2647 void organizeAttributes() ;
2648 void organizeTracks() ;
2649 void organizeMeasures() ;
2650 void organizeMeasure(int part, int track, Measure* measure, MeasureData* measureData) ;
2651
2652 void organizeContainers(int part, int track, Measure* measure, MeasureData* measureData) ;
2653 void organizeMusicDatas(int part, int track, Measure* measure, MeasureData* measureData) ;
2654 void organizeCrossMeasureElements(int part, int track, Measure* measure, MeasureData* measureData) ;
2655
2656 void organizePairElement(MusicData* data, int part, int track, Measure* measure, MeasureData* measureData) ;
2657 void organizeOctaveShift(OctaveShift* octave, Measure* measure, MeasureData* measureData) ;
2658 void organizeWedge(Wedge* wedge, int part, int track, Measure* measure, MeasureData* measureData) ;
2659
2660private:
2661 OveSong* ove_ ;
2662};
2663
2664// OveSerialize.h
2665class StreamHandle;
2666class Block;
2667class NameBlock;
2668class Chunk;
2669class SizeChunk;
2670class GroupChunk;
2671
2672class OveSerialize: public IOVEStreamLoader {
2673public:
2674 OveSerialize();
2675 virtual ~OveSerialize();
2676
2677public:
2678 virtual void setOve(OveSong* ove);
2679 virtual void setFileStream(unsigned char* buffer, unsigned int size);
2680 virtual void setNotify(IOveNotify* notify);
2681 virtual bool load(void);
2682
2683 virtual void release();
2684
2685private:
2686 bool readNameBlock(NameBlock& nameBlock);
2687 bool readChunkName(Chunk* chunk, const QString& name);
2688 bool readSizeChunk(SizeChunk* sizeChunk); // contains a SizeChunk and data buffer
2689 bool readDataChunk(Block* block, unsigned int size);
2690 bool readGroupChunk(GroupChunk* groupChunk);
2691
2692 bool readHeader();
2693 bool readHeadData(SizeChunk* ovscChunk);
2694 bool readTracksData();
2695 bool readPagesData();
2696 bool readLinesData();
2697 bool readBarsData();
2698 bool readOveEnd();
2699
2700 void messageOutError();
2701 void messageOut(const QString& str);
2702
2703private:
2704 OveSong* ove_;
2705 StreamHandle* streamHandle_;
2706 IOveNotify* notify_;
2707};
2708
2709/*template <class T>
2710inline void deleteVector(QList<T*>& vec) {
2711 for (int i=0; i<vec.size(); ++i)
2712 delete vec[i];
2713 }
2714 //vec.clear();
2715}*/
2716
2718TickElement::TickElement() {
2719 tick_ = 0;
2720}
2721
2722void TickElement::setTick(int tick) {
2723 tick_ = tick;
2724}
2725
2726int TickElement::getTick(void) const {
2727 return tick_;
2728}
2729
2731MeasurePos::MeasurePos() {
2732 measure_ = 0;
2733 offset_ = 0;
2734}
2735
2736void MeasurePos::setMeasure(int measure) {
2737 measure_ = measure;
2738}
2739
2740int MeasurePos::getMeasure() const {
2741 return measure_;
2742}
2743
2744void MeasurePos::setOffset(int offset) {
2745 offset_ = offset;
2746}
2747
2748int MeasurePos::getOffset() const {
2749 return offset_;
2750}
2751
2752MeasurePos MeasurePos::shiftMeasure(int measure) const {
2753 MeasurePos mp;
2754 mp.setMeasure(getMeasure() + measure);
2755 mp.setOffset(getOffset());
2756
2757 return mp;
2758}
2759
2760MeasurePos MeasurePos::shiftOffset(int offset) const {
2761 MeasurePos mp;
2762 mp.setMeasure(getMeasure());
2763 mp.setOffset(getOffset() + offset);
2764
2765 return mp;
2766}
2767
2768bool MeasurePos::operator ==(const MeasurePos& mp) const {
2769 return getMeasure() == mp.getMeasure() && getOffset() == mp.getOffset();
2770}
2771
2772bool MeasurePos::operator !=(const MeasurePos& mp) const {
2773 return !(*this == mp);
2774}
2775
2776bool MeasurePos::operator <(const MeasurePos& mp) const {
2777 if (getMeasure() != mp.getMeasure()) {
2778 return getMeasure() < mp.getMeasure();
2779 }
2780
2781 return getOffset() < mp.getOffset();
2782}
2783
2784bool MeasurePos::operator <=(const MeasurePos& mp) const {
2785 if (getMeasure() != mp.getMeasure()) {
2786 return getMeasure() <= mp.getMeasure();
2787 }
2788
2789 return getOffset() <= mp.getOffset();
2790}
2791
2792bool MeasurePos::operator >(const MeasurePos& mp) const {
2793 return !(*this <= mp);
2794}
2795
2796bool MeasurePos::operator >=(const MeasurePos& mp) const {
2797 return !(*this < mp);
2798}
2799
2801PairElement::PairElement() {
2802 start_ = new MeasurePos();
2803 stop_ = new MeasurePos();
2804}
2805
2806PairElement::~PairElement(){
2807 delete start_;
2808 delete stop_;
2809}
2810
2811MeasurePos* PairElement::start() const {
2812 return start_;
2813}
2814
2815MeasurePos* PairElement::stop() const {
2816 return stop_;
2817}
2818
2820PairEnds::PairEnds() {
2821 leftLine_ = new LineElement();
2822 rightLine_ = new LineElement();
2823 leftShoulder_ = new OffsetElement();
2824 rightShoulder_ = new OffsetElement();
2825}
2826
2827PairEnds::~PairEnds(){
2828 delete leftLine_;
2829 delete rightLine_;
2830 delete leftShoulder_;
2831 delete rightShoulder_;
2832}
2833
2834LineElement* PairEnds::getLeftLine() const {
2835 return leftLine_;
2836}
2837
2838LineElement* PairEnds::getRightLine() const {
2839 return rightLine_;
2840}
2841
2842OffsetElement* PairEnds::getLeftShoulder() const {
2843 return leftShoulder_;
2844}
2845
2846OffsetElement* PairEnds::getRightShoulder() const {
2847 return rightShoulder_;
2848}
2849
2851LineElement::LineElement() {
2852 line_ = 0;
2853}
2854
2855void LineElement::setLine(int line) {
2856 line_ = line;
2857}
2858
2859int LineElement::getLine(void) const {
2860 return line_;
2861}
2862
2864OffsetElement::OffsetElement() {
2865 xOffset_ = 0;
2866 yOffset_ = 0;
2867}
2868
2869void OffsetElement::setXOffset(int offset) {
2870 xOffset_ = offset;
2871}
2872
2873int OffsetElement::getXOffset() const {
2874 return xOffset_;
2875}
2876
2877void OffsetElement::setYOffset(int offset) {
2878 yOffset_ = offset;
2879}
2880
2881int OffsetElement::getYOffset() const {
2882 return yOffset_;
2883}
2884
2886LengthElement::LengthElement() {
2887 length_ = 0;
2888}
2889
2890void LengthElement::setLength(int length) {
2891 length_ = length;
2892}
2893
2894int LengthElement::getLength() const {
2895 return length_;
2896}
2897
2899MusicData::MusicData() {
2900 musicDataType_ = MusicData_None;
2901 show_ = true;
2902 color_ = 0;
2903 voice_ = 0;
2904}
2905
2906MusicDataType MusicData::getMusicDataType() const {
2907 return musicDataType_;
2908}
2909
2910MusicData::XmlDataType MusicData::getXmlDataType(MusicDataType type) {
2911 XmlDataType xmlType = None;
2912
2913 switch (type) {
2914 case MusicData_Measure_Repeat: {
2915 xmlType = Attributes;
2916 break;
2917 }
2918 case MusicData_Beam: {
2919 xmlType = NoteBeam;
2920 break;
2921 }
2922 case MusicData_Slur:
2923 case MusicData_Glissando:
2924 case MusicData_Tuplet:
2925 case MusicData_Tie: {
2926 xmlType = Notations;
2927 break;
2928 }
2929 case MusicData_Text:
2930 case MusicData_Repeat:
2931 case MusicData_Wedge:
2932 case MusicData_Dynamics:
2933 case MusicData_Pedal:
2934 case MusicData_OctaveShift_EndPoint: {
2935 xmlType = Direction;
2936 break;
2937 }
2938 default: {
2939 xmlType = None;
2940 break;
2941 }
2942 }
2943
2944 return xmlType;
2945}
2946
2947/*bool MusicData::get_is_pair_element(MusicDataType type)
2948 {
2949 bool pair = false;
2950
2951 switch ( type )
2952 {
2953 case MusicData_Numeric_Ending :
2954 case MusicData_Measure_Repeat :
2955 case MusicData_Wedge :
2956 case MusicData_OctaveShift :
2957 //case MusicData_OctaveShift_EndPoint :
2958 case MusicData_Pedal :
2959 case MusicData_Beam :
2960 case MusicData_Glissando :
2961 case MusicData_Slur :
2962 case MusicData_Tie :
2963 case MusicData_Tuplet :
2964 {
2965 pair = true;
2966 break;
2967 }
2968 default:
2969 break;
2970 }
2971
2972 return pair;
2973 }*/
2974
2975void MusicData::setShow(bool show) {
2976 show_ = show;
2977}
2978
2979bool MusicData::getShow() const {
2980 return show_;
2981}
2982
2983void MusicData::setColor(unsigned int color) {
2984 color_ = color;
2985}
2986
2987unsigned int MusicData::getColor() const {
2988 return color_;
2989}
2990
2991void MusicData::setVoice(unsigned int voice) {
2992 voice_ = voice;
2993}
2994
2995unsigned int MusicData::getVoice() const {
2996 return voice_;
2997}
2998
2999void MusicData::copyCommonBlock(const MusicData& source) {
3000 setTick(source.getTick());
3001 start()->setOffset(source.start()->getOffset());
3002 setColor(source.getColor());
3003}
3004
3006MidiData::MidiData() {
3007 midiType_ = Midi_None;
3008}
3009
3010MidiType MidiData::getMidiType() const {
3011 return midiType_;
3012}
3013
3015OveSong::OveSong() :
3016 codec_(0) {
3017 clear();
3018}
3019
3020OveSong::~OveSong() {
3021 clear();
3022}
3023
3024void OveSong::setIsVersion4(bool version4){
3025 version4_ = version4;
3026}
3027
3028bool OveSong::getIsVersion4() const {
3029 return version4_;
3030}
3031
3032void OveSong::setQuarter(int tick) {
3033 quarter_ = tick;
3034}
3035
3036int OveSong::getQuarter(void) const {
3037 return quarter_;
3038}
3039
3040void OveSong::setShowPageMargin(bool show){
3041 showPageMargin_ = show;
3042}
3043
3044bool OveSong::getShowPageMargin() const {
3045 return showPageMargin_;
3046}
3047
3048void OveSong::setShowTransposeTrack(bool show) {
3049 showTransposeTrack = show;
3050}
3051
3052bool OveSong::getShowTransposeTrack() const {
3053 return showTransposeTrack;
3054}
3055
3056void OveSong::setShowLineBreak(bool show) {
3057 showLineBreak_ = show;
3058}
3059
3060bool OveSong::getShowLineBreak() const {
3061 return showLineBreak_;
3062}
3063
3064void OveSong::setShowRuler(bool show) {
3065 showRuler_ = show;
3066}
3067
3068bool OveSong::getShowRuler() const {
3069 return showRuler_;
3070}
3071
3072void OveSong::setShowColor(bool show) {
3073 showColor_ = show;
3074}
3075
3076bool OveSong::getShowColor() const {
3077 return showColor_;
3078}
3079
3080void OveSong::setPlayRepeat(bool play) {
3081 playRepeat_ = play;
3082}
3083
3084bool OveSong::getPlayRepeat() const {
3085 return playRepeat_;
3086}
3087
3088void OveSong::setPlayStyle(PlayStyle style) {
3089 playStyle_ = style;
3090}
3091
3092OveSong::PlayStyle OveSong::getPlayStyle() const {
3093 return playStyle_;
3094}
3095
3096void OveSong::addTitle(const QString& str) {
3097 titles_.push_back(str);
3098}
3099
3100QList<QString> OveSong::getTitles(void) const {
3101 return titles_;
3102}
3103
3104void OveSong::addAnnotate(const QString& str) {
3105 annotates_.push_back(str);
3106}
3107
3108QList<QString> OveSong::getAnnotates(void) const {
3109 return annotates_;
3110}
3111
3112void OveSong::addWriter(const QString& str) {
3113 writers_.push_back(str);
3114}
3115
3116QList<QString> OveSong::getWriters(void) const {
3117 return writers_;
3118}
3119
3120void OveSong::addCopyright(const QString& str) {
3121 copyrights_.push_back(str);
3122}
3123
3124QList<QString> OveSong::getCopyrights(void) const {
3125 return copyrights_;
3126}
3127
3128void OveSong::addHeader(const QString& str) {
3129 headers_.push_back(str);
3130}
3131
3132QList<QString> OveSong::getHeaders(void) const {
3133 return headers_;
3134}
3135
3136void OveSong::addFooter(const QString& str) {
3137 footers_.push_back(str);
3138}
3139
3140QList<QString> OveSong::getFooters(void) const {
3141 return footers_;
3142}
3143
3144void OveSong::addTrack(Track* ptr) {
3145 tracks_.push_back(ptr);
3146}
3147
3148int OveSong::getTrackCount(void) const {
3149 return tracks_.size();
3150}
3151
3152QList<Track*> OveSong::getTracks() const {
3153 return tracks_;
3154}
3155
3156void OveSong::setTrackBarCount(int count) {
3157 trackBarCount_ = count;
3158}
3159
3160int OveSong::getTrackBarCount() const {
3161 return trackBarCount_;
3162}
3163
3164Track* OveSong::getTrack(int part, int staff) const {
3165 int trackId = partStaffToTrack(part, staff);
3166
3167 if( trackId >=0 && trackId < (int)tracks_.size() ) {
3168 return tracks_[trackId];
3169 }
3170
3171 return 0;
3172}
3173
3174bool OveSong::addPage(Page* page) {
3175 pages_.push_back(page);
3176 return true;
3177}
3178
3179int OveSong::getPageCount() const {
3180 return pages_.size();
3181}
3182
3183Page* OveSong::getPage(int idx) {
3184 if( idx>=0 && idx<(int)pages_.size() ) {
3185 return pages_[idx];
3186 }
3187
3188 return 0;
3189}
3190
3191void OveSong::addLine(Line* ptr) {
3192 lines_.push_back(ptr);
3193}
3194
3195int OveSong::getLineCount() const {
3196 return lines_.size();
3197}
3198
3199Line* OveSong::getLine(int idx) const {
3200 if( idx >=0 && idx<(int)lines_.size() ) {
3201 return lines_[idx];
3202 }
3203
3204 return 0;
3205}
3206
3207void OveSong::addMeasure(Measure* ptr) {
3208 measures_.push_back(ptr);
3209}
3210
3211int OveSong::getMeasureCount(void) const {
3212 return measures_.size();
3213}
3214
3215Measure* OveSong::getMeasure(int bar) const {
3216 if( bar >= 0 && bar < (int)measures_.size() ) {
3217 return measures_[bar];
3218 }
3219
3220 return 0;
3221}
3222
3223void OveSong::addMeasureData(MeasureData* ptr) {
3224 measureDatas_.push_back(ptr);
3225}
3226
3227int OveSong::getMeasureDataCount(void) const {
3228 return measureDatas_.size();
3229}
3230
3231MeasureData* OveSong::getMeasureData(int part, int staff/*=0*/, int bar) const {
3232 int trackId = partStaffToTrack(part, staff);
3233 int trackBarCount = getTrackBarCount();
3234
3235 if( bar >= 0 && bar < trackBarCount ) {
3236 int measureId = trackBarCount * trackId + bar;
3237
3238 if( measureId >=0 && measureId < (int)measureDatas_.size() ) {
3239 return measureDatas_[measureId];
3240 }
3241 }
3242
3243 return 0;
3244}
3245
3246MeasureData* OveSong::getMeasureData(int track, int bar) const {
3247 int id = trackBarCount_*track + bar;
3248
3249 if( id >=0 && id < (int)measureDatas_.size() ) {
3250 return measureDatas_[id];
3251 }
3252
3253 return 0;
3254}
3255
3256void OveSong::setPartStaffCounts(const QList<int>& partStaffCounts) {
3257 //partStaffCounts_.assign(partStaffCounts.begin(), partStaffCounts.end());
3258 for(int i=0; i<partStaffCounts.size(); ++i) {
3259 partStaffCounts_.push_back(partStaffCounts[i]);
3260 }
3261}
3262
3263int OveSong::getPartCount() const {
3264 return partStaffCounts_.size();
3265}
3266
3267int OveSong::getStaffCount(int part) const {
3268 if( part>=0 && part<(int)partStaffCounts_.size() ) {
3269 return partStaffCounts_[part];
3270 }
3271
3272 return 0;
3273}
3274
3275int OveSong::getPartBarCount() const {
3276 return measureDatas_.size() / tracks_.size();
3277}
3278
3279QPair<int, int> OveSong::trackToPartStaff(int track) const {
3280 QPair<int, int> partStaff;
3281 int i;
3282 int staffCount = 0;
3283
3284 for( i=0; i<partStaffCounts_.size(); ++i ) {
3285 if( staffCount + partStaffCounts_[i] > track ) {
3286 return qMakePair((int)i, track-staffCount);
3287 }
3288
3289 staffCount += partStaffCounts_[i];
3290 }
3291
3292 return qMakePair((int)partStaffCounts_.size(), 0);
3293}
3294
3295int OveSong::partStaffToTrack(int part, int staff) const {
3296 int i;
3297 unsigned int staffCount = 0;
3298
3299 for( i=0; i<partStaffCounts_.size(); ++i ) {
3300 if( part == (int)i && staff>=0 && staff<(int)partStaffCounts_[i] ) {
3301 int trackId = staffCount + staff;
3302
3303 if( trackId >=0 && trackId < (int)tracks_.size() ) {
3304 return trackId;
3305 }
3306 }
3307
3308 staffCount += partStaffCounts_[i];
3309 }
3310
3311 return tracks_.size();
3312}
3313
3314void OveSong::setTextCodecName(const QString& codecName) {
3315 codec_ = QTextCodec::codecForName(codecName.toLatin1());
3316}
3317
3318QString OveSong::getCodecString(const QByteArray& text) {
3319 QString s;
3320 if (codec_ == NULL)
3321 s = QString(text);
3322 else
3323 s = codec_->toUnicode(text);
3324
3325 return s;
3326}
3327
3328void OveSong::clear(void)
3329{
3330 version4_ = true;
3331 quarter_ = 480;
3332 showPageMargin_ = false;
3333 showTransposeTrack = false;
3334 showLineBreak_ = false;
3335 showRuler_ = false;
3336 showColor_ = true;
3337 playRepeat_ = true;
3338 playStyle_ = Record;
3339
3340 annotates_.clear();
3341 copyrights_.clear();
3342 footers_.clear();
3343 headers_.clear();
3344 titles_.clear();
3345 writers_.clear();
3346
3347// deleteVector(tracks_);
3348 for(int i=0; i<tracks_.size(); ++i){
3349 delete tracks_[i];
3350 }
3351 for(int i=0; i<pages_.size(); ++i){
3352 delete pages_[i];
3353 }
3354 for(int i=0; i<lines_.size(); ++i){
3355 delete lines_[i];
3356 }
3357 for(int i=0; i<measures_.size(); ++i){
3358 delete measures_[i];
3359 }
3360 for(int i=0; i<measureDatas_.size(); ++i){
3361 delete measureDatas_[i];
3362 }
3363 tracks_.clear();
3364 pages_.clear();
3365 lines_.clear();
3366 measures_.clear();
3367 measureDatas_.clear();
3368 trackBarCount_ = 0;
3369 partStaffCounts_.clear();
3370}
3371
3373Voice::Voice() {
3374 channel_ = 0;
3375 volume_ = -1;
3376 pitchShift_ = 0;
3377 pan_ = 0;
3378 patch_ = 0;
3379 stemType_ = 0;
3380}
3381
3382void Voice::setChannel(int channel) {
3383 channel_ = channel;
3384}
3385
3386int Voice::getChannel() const {
3387 return channel_;
3388}
3389
3390void Voice::setVolume(int volume) {
3391 volume_ = volume;
3392}
3393
3394int Voice::getVolume() const {
3395 return volume_;
3396}
3397
3398void Voice::setPitchShift(int pitchShift) {
3399 pitchShift_ = pitchShift;
3400}
3401
3402int Voice::getPitchShift() const {
3403 return pitchShift_;
3404}
3405
3406void Voice::setPan(int pan) {
3407 pan_ = pan;
3408}
3409
3410int Voice::getPan() const {
3411 return pan_;
3412}
3413
3414void Voice::setPatch(int patch) {
3415 patch_ = patch;
3416}
3417
3418int Voice::getPatch() const {
3419 return patch_;
3420}
3421
3422void Voice::setStemType(int stemType) {
3423 stemType_ = stemType;
3424}
3425
3426int Voice::getStemType() const {
3427 return stemType_;
3428}
3429
3430int Voice::getDefaultPatch() {
3431 return -1;
3432}
3433
3434int Voice::getDefaultVolume() {
3435 return -1;
3436}
3437
3439Track::Track() {
3440 clear();
3441}
3442
3443Track::~Track() {
3444 clear();
3445}
3446
3447void Track::setName(const QString& str) {
3448 name_ = str;
3449}
3450
3451QString Track::getName(void) const {
3452 return name_;
3453}
3454
3455void Track::setBriefName(const QString& str) {
3456 briefName_ = str;
3457}
3458
3459QString Track::getBriefName(void) const {
3460 return briefName_;
3461}
3462
3463void Track::setPatch(unsigned int patch) {
3464 patch_ = patch;
3465}
3466
3467unsigned int Track::getPatch() const {
3468 return patch_;
3469}
3470
3471void Track::setChannel(int channel) {
3472 channel_ = channel;
3473}
3474
3475int Track::getChannel() const {
3476 return channel_;
3477}
3478
3479void Track::setShowName(bool show) {
3480 showName_ = show;
3481}
3482
3483bool Track::getShowName() const {
3484 return showName_;
3485}
3486
3487void Track::setShowBriefName(bool show) {
3488 showBriefName_ = show;
3489}
3490
3491bool Track::getShowBriefName() const {
3492 return showBriefName_;
3493}
3494
3495void Track::setMute(bool mute) {
3496 mute_ = mute;
3497}
3498
3499bool Track::getMute() const {
3500 return mute_;
3501}
3502
3503void Track::setSolo(bool solo) {
3504 solo_ = solo;
3505}
3506
3507bool Track::getSolo() const {
3508 return solo_;
3509}
3510
3511void Track::setShowKeyEachLine(bool show) {
3512 showKeyEachLine_ = show;
3513}
3514
3515bool Track::getShowKeyEachLine() const {
3516 return showKeyEachLine_;
3517}
3518
3519void Track::setVoiceCount(int voices) {
3520 voiceCount_ = voices;
3521}
3522
3523int Track::getVoiceCount() const {
3524 return voiceCount_;
3525}
3526
3527void Track::addVoice(Voice* voice) {
3528 voices_.push_back(voice);
3529}
3530
3531QList<Voice*> Track::getVoices() const {
3532 return voices_;
3533}
3534
3535void Track::setShowTranspose(bool show) {
3536 showTranspose_ = show;
3537}
3538
3539bool Track::getShowTranspose() const {
3540 return showTranspose_;
3541}
3542
3543void Track::setTranspose(int transpose) {
3544 transpose_ = transpose;
3545}
3546
3547int Track::getTranspose() const {
3548 return transpose_;
3549}
3550
3551void Track::setNoteShift(int shift) {
3552 noteShift_ = shift;
3553}
3554
3555int Track::getNoteShift() const {
3556 return noteShift_;
3557}
3558
3559void Track::setStartClef(int clef/*in Clef*/) {
3560 startClef_ = clef;
3561}
3562
3563ClefType Track::getStartClef() const {
3564 return (ClefType)startClef_;
3565}
3566
3567void Track::setTransposeClef(int clef) {
3568 transposeClef_ = clef;
3569}
3570
3571int Track::getTansposeClef() const {
3572 return transposeClef_;
3573}
3574
3575void Track::setStartKey(int key) {
3576 startKey_ = key;
3577}
3578
3579int Track::getStartKey() const {
3580 return startKey_;
3581}
3582
3583void Track::setDisplayPercent(unsigned int percent/*25~100?*/) {
3584 displayPercent_ = percent;
3585}
3586
3587unsigned int Track::getDisplayPercent() const {
3588 return displayPercent_;
3589}
3590
3591void Track::setShowLegerLine(bool show) {
3592 showLegerLine_ = show;
3593}
3594
3595bool Track::getShowLegerLine() const {
3596 return showLegerLine_;
3597}
3598
3599void Track::setShowClef(bool show) {
3600 showClef_ = show;
3601}
3602
3603bool Track::getShowClef() const {
3604 return showClef_;
3605}
3606
3607void Track::setShowTimeSignature(bool show) {
3608 showTimeSignature_ = show;
3609}
3610
3611bool Track::getShowTimeSignature() const {
3612 return showTimeSignature_;
3613}
3614
3615void Track::setShowKeySignature(bool show) {
3616 showKeySignature_ = show;
3617}
3618
3619bool Track::getShowKeySignature() const {
3620 return showKeySignature_;
3621}
3622
3623void Track::setShowBarline(bool show) {
3624 showBarline_ = show;
3625}
3626
3627bool Track::getShowBarline() const {
3628 return showBarline_;
3629}
3630
3631void Track::setFillWithRest(bool fill) {
3632 fillWithRest_ = fill;
3633}
3634
3635bool Track::getFillWithRest() const {
3636 return fillWithRest_;
3637}
3638
3639void Track::setFlatTail(bool flat) {
3640 flatTail_ = flat;
3641}
3642
3643bool Track::getFlatTail() const {
3644 return flatTail_;
3645}
3646
3647void Track::setShowClefEachLine(bool show) {
3648 showClefEachLine_ = show;
3649}
3650
3651bool Track::getShowClefEachLine() const {
3652 return showClefEachLine_;
3653}
3654
3655void Track::addDrum(const DrumNode& node) {
3656 /*DrumNode node;
3657 node.line_ = line;
3658 node.headType_ = headType;
3659 node.pitch_ = pitch;
3660 node.voice_ = voice;*/
3661 drumKit_.push_back(node);
3662}
3663
3664QList<Track::DrumNode> Track::getDrumKit() const {
3665 return drumKit_;
3666}
3667
3668void Track::setPart(int part) {
3669 part_ = part;
3670}
3671
3672int Track::getPart() const {
3673 return part_;
3674}
3675
3676void Track::clear(void) {
3677 number_ = 0;
3678
3679 name_ = QString();
3680
3681 patch_ = 0;
3682 channel_ = 0;
3683 transpose_ = 0;
3684 showTranspose_ = false;
3685 noteShift_ = 0;
3686 startClef_ = Clef_Treble;
3687 transposeClef_ = Clef_Treble;
3688 displayPercent_ = 100;
3689 startKey_ = 0;
3690 voiceCount_ = 8;
3691
3692 showName_ = true;
3693 showBriefName_ = false;
3694 showKeyEachLine_ = false;
3695 showLegerLine_ = true;
3696 showClef_ = true;
3697 showTimeSignature_ = true;
3698 showKeySignature_ = true;
3699 showBarline_ = true;
3700 showClefEachLine_ = false;
3701
3702 fillWithRest_ = true;
3703 flatTail_ = false;
3704
3705 mute_ = false;
3706 solo_ = false;
3707
3708 drumKit_.clear();
3709
3710 part_ = 0;
3711
3712 for(int i=0; i<voices_.size(); ++i){
3713 delete voices_[i];
3714 }
3715 voices_.clear();
3716}
3717
3719Page::Page() {
3720 beginLine_ = 0;
3721 lineCount_ = 0;
3722
3723 lineInterval_ = 9;
3724 staffInterval_ = 7;
3725 staffInlineInterval_ = 6;
3726
3727 lineBarCount_ = 4;
3728 pageLineCount_ = 5;
3729
3730 leftMargin_ = 0xA8;
3731 topMargin_ = 0xA8;
3732 rightMargin_ = 0xA8;
3733 bottomMargin_ = 0xA8;
3734
3735 pageWidth_ = 0x0B40;
3736 pageHeight_ = 0x0E90;
3737}
3738
3739void Page::setBeginLine(int line) {
3740 beginLine_ = line;
3741}
3742
3743int Page::getBeginLine() const {
3744 return beginLine_;
3745}
3746
3747void Page::setLineCount(int count) {
3748 lineCount_ = count;
3749}
3750
3751int Page::getLineCount() const {
3752 return lineCount_;
3753}
3754
3755void Page::setLineInterval(int interval) {
3756 lineInterval_ = interval;
3757}
3758
3759int Page::getLineInterval() const {
3760 return lineInterval_;
3761}
3762
3763void Page::setStaffInterval(int interval) {
3764 staffInterval_ = interval;
3765}
3766
3767int Page::getStaffInterval() const {
3768 return staffInterval_;
3769}
3770
3771void Page::setStaffInlineInterval(int interval) {
3772 staffInlineInterval_ = interval;
3773}
3774
3775int Page::getStaffInlineInterval() const {
3776 return staffInlineInterval_;
3777}
3778
3779void Page::setLineBarCount(int count) {
3780 lineBarCount_ = count;
3781}
3782
3783int Page::getLineBarCount() const {
3784 return lineBarCount_;
3785}
3786
3787void Page::setPageLineCount(int count) {
3788 pageLineCount_ = count;
3789}
3790
3791int Page::getPageLineCount() const {
3792 return pageLineCount_;
3793}
3794
3795void Page::setLeftMargin(int margin) {
3796 leftMargin_ = margin;
3797}
3798
3799int Page::getLeftMargin() const {
3800 return leftMargin_;
3801}
3802
3803void Page::setTopMargin(int margin) {
3804 topMargin_ = margin;
3805}
3806
3807int Page::getTopMargin() const {
3808 return topMargin_;
3809}
3810
3811void Page::setRightMargin(int margin) {
3812 rightMargin_ = margin;
3813}
3814
3815int Page::getRightMargin() const {
3816 return rightMargin_;
3817}
3818
3819void Page::setBottomMargin(int margin) {
3820 bottomMargin_ = margin;
3821}
3822
3823int Page::getBottomMargin() const {
3824 return bottomMargin_;
3825}
3826
3827void Page::setPageWidth(int width) {
3828 pageWidth_ = width;
3829}
3830
3831int Page::getPageWidth() const {
3832 return pageWidth_;
3833}
3834
3835void Page::setPageHeight(int height) {
3836 pageHeight_ = height;
3837}
3838
3839int Page::getPageHeight() const {
3840 return pageHeight_;
3841}
3842
3844Line::Line() {
3845 beginBar_ = 0;
3846 barCount_ = 0;
3847 yOffset_ = 0;
3848 leftXOffset_ = 0;
3849 rightXOffset_ = 0;
3850}
3851
3852Line::~Line() {
3853 for(int i=0; i<staffs_.size(); ++i){
3854 delete staffs_[i];
3855 }
3856 staffs_.clear();
3857}
3858
3859void Line::addStaff(Staff* staff) {
3860 staffs_.push_back(staff);
3861}
3862
3863int Line::getStaffCount() const {
3864 return staffs_.size();
3865}
3866
3867Staff* Line::getStaff(int idx) const {
3868 if (idx >= 0 && idx < (int) staffs_.size()) {
3869 return staffs_[idx];
3870 }
3871
3872 return 0;
3873}
3874
3875void Line::setBeginBar(unsigned int bar) {
3876 beginBar_ = bar;
3877}
3878
3879unsigned int Line::getBeginBar() const {
3880 return beginBar_;
3881}
3882
3883void Line::setBarCount(unsigned int count) {
3884 barCount_ = count;
3885}
3886
3887unsigned int Line::getBarCount() const {
3888 return barCount_;
3889}
3890
3891void Line::setYOffset(int offset) {
3892 yOffset_ = offset;
3893}
3894
3895int Line::getYOffset() const {
3896 return yOffset_;
3897}
3898
3899void Line::setLeftXOffset(int offset) {
3900 leftXOffset_ = offset;
3901}
3902
3903int Line::getLeftXOffset() const {
3904 return leftXOffset_;
3905}
3906
3907void Line::setRightXOffset(int offset) {
3908 rightXOffset_ = offset;
3909}
3910
3911int Line::getRightXOffset() const {
3912 return rightXOffset_;
3913}
3914
3916Staff::Staff() {
3917 clef_ = Clef_Treble;
3918 key_ = 0;
3919 visible_ = true;
3920 groupType_ = Group_None;
3921 groupStaffCount_ = 0;
3922}
3923
3924void Staff::setClefType(int clef) {
3925 clef_ = (ClefType) clef;
3926}
3927
3928ClefType Staff::getClefType() const {
3929 return clef_;
3930}
3931
3932void Staff::setKeyType(int key) {
3933 key_ = key;
3934}
3935
3936int Staff::getKeyType() const {
3937 return key_;
3938}
3939
3940void Staff::setVisible(bool visible) {
3941 visible_ = visible;
3942}
3943
3944bool Staff::setVisible() const {
3945 return visible_;
3946}
3947
3948void Staff::setGroupType(GroupType type){
3949 groupType_ = type;
3950}
3951
3952GroupType Staff::getGroupType() const {
3953 return groupType_;
3954}
3955
3956void Staff::setGroupStaffCount(int count) {
3957 groupStaffCount_ = count;
3958}
3959
3960int Staff::getGroupStaffCount() const {
3961 return groupStaffCount_;
3962}
3963
3965Note::Note() {
3966 rest_ = false;
3967 note_ = 60;
3968 accidental_ = Accidental_Normal;
3969 showAccidental_ = false;
3970 offVelocity_ = 0x40;
3971 onVelocity_ = 0x50;
3972 headType_ = NoteHead_Standard;
3973 tiePos_ = Tie_None;
3974 offsetStaff_ = 0;
3975 show_ = true;
3976 offsetTick_ = 0;
3977}
3978
3979void Note::setIsRest(bool rest) {
3980 rest_ = rest;
3981}
3982
3983bool Note::getIsRest() const {
3984 return rest_;
3985}
3986
3987void Note::setNote(unsigned int note) {
3988 note_ = note;
3989}
3990
3991unsigned int Note::getNote() const {
3992 return note_;
3993}
3994
3995void Note::setAccidental(int type) {
3996 accidental_ = (AccidentalType) type;
3997}
3998
3999AccidentalType Note::getAccidental() const {
4000 return accidental_;
4001}
4002
4003void Note::setShowAccidental(bool show) {
4004 showAccidental_ = show;
4005}
4006
4007bool Note::getShowAccidental() const {
4008 return showAccidental_;
4009}
4010
4011void Note::setOnVelocity(unsigned int velocity) {
4012 onVelocity_ = velocity;
4013}
4014
4015unsigned int Note::getOnVelocity() const {
4016 return onVelocity_;
4017}
4018
4019void Note::setOffVelocity(unsigned int velocity) {
4020 offVelocity_ = velocity;
4021}
4022
4023unsigned int Note::getOffVelocity() const {
4024 return offVelocity_;
4025}
4026
4027void Note::setHeadType(int type) {
4028 headType_ = (NoteHeadType) type;
4029}
4030
4031NoteHeadType Note::getHeadType() const {
4032 return headType_;
4033}
4034
4035void Note::setTiePos(int tiePos) {
4036 tiePos_ = (TiePos) tiePos;
4037}
4038
4039TiePos Note::getTiePos() const {
4040 return tiePos_;
4041}
4042
4043void Note::setOffsetStaff(int offset) {
4044 offsetStaff_ = offset;
4045}
4046
4047int Note::getOffsetStaff() const {
4048 return offsetStaff_;
4049}
4050
4051void Note::setShow(bool show) {
4052 show_ = show;
4053}
4054
4055bool Note::getShow() const {
4056 return show_;
4057}
4058
4059void Note::setOffsetTick(int offset) {
4060 offsetTick_ = offset;
4061}
4062
4063int Note::getOffsetTick() const {
4064 return offsetTick_;
4065}
4066
4068Articulation::Articulation() {
4069 type_ = Articulation_Marcato;
4070 above_ = true;
4071
4072 changeSoundEffect_ = false;
4073 changeLength_ = false;
4074 changeVelocity_ = false;
4075 changeExtraLength_ = false;
4076
4077 soundEffect_ = qMakePair(0, 0);
4078 lengthPercentage_ = 100;
4079 velocityType_ = Velocity_Offset;
4080 velocityValue_ = 0;
4081 extraLength_ = 0;
4082
4083 trillNoteLength_ = 60;
4084 trillRate_ = Note_Sixteen;
4085 accelerateType_ = Accelerate_None;
4086 auxiliaryFirst_ = false;
4087 trillInterval_ = TrillInterval_Chromatic;
4088}
4089
4090void Articulation::setArtType(int type) {
4091 type_ = (ArticulationType) type;
4092}
4093
4094ArticulationType Articulation::getArtType() const {
4095 return type_;
4096}
4097
4098void Articulation::setPlacementAbove(bool above) {
4099 above_ = above;
4100}
4101
4102bool Articulation::getPlacementAbove() const {
4103 return above_;
4104}
4105
4106bool Articulation::getChangeSoundEffect() const {
4107 return changeSoundEffect_;
4108}
4109
4110void Articulation::setSoundEffect(int soundFrom, int soundTo) {
4111 soundEffect_ = qMakePair(soundFrom, soundTo);
4112 changeSoundEffect_ = true;
4113}
4114
4115QPair<int, int> Articulation::getSoundEffect() const {
4116 return soundEffect_;
4117}
4118
4119bool Articulation::getChangeLength() const {
4120 return changeLength_;
4121}
4122
4123void Articulation::setLengthPercentage(int percentage) {
4124 lengthPercentage_ = percentage;
4125 changeLength_ = true;
4126}
4127
4128int Articulation::getLengthPercentage() const {
4129 return lengthPercentage_;
4130}
4131
4132bool Articulation::getChangeVelocity() const {
4133 return changeVelocity_;
4134}
4135
4136void Articulation::setVelocityType(VelocityType type) {
4137 velocityType_ = type;
4138 changeVelocity_ = true;
4139}
4140
4141Articulation::VelocityType Articulation::getVelocityType() const {
4142 return velocityType_;
4143}
4144
4145void Articulation::setVelocityValue(int value) {
4146 velocityValue_ = value;
4147}
4148
4149int Articulation::getVelocityValue() const {
4150 return velocityValue_;
4151}
4152
4153bool Articulation::getChangeExtraLength() const {
4154 return changeExtraLength_;
4155}
4156
4157void Articulation::setExtraLength(int length) {
4158 extraLength_ = length;
4159 changeExtraLength_ = true;
4160}
4161
4162int Articulation::getExtraLength() const {
4163 return extraLength_;
4164}
4165
4166void Articulation::setTrillNoteLength(int length) {
4167 trillNoteLength_ = length;
4168}
4169
4170int Articulation::getTrillNoteLength() const {
4171 return trillNoteLength_;
4172}
4173
4174void Articulation::setTrillRate(NoteType rate) {
4175 trillRate_ = rate;
4176}
4177
4178NoteType Articulation::getTrillRate() const {
4179 return trillRate_;
4180}
4181
4182void Articulation::setAccelerateType(int type) {
4183 accelerateType_ = (AccelerateType) type;
4184}
4185
4186Articulation::AccelerateType Articulation::getAccelerateType() const {
4187 return accelerateType_;
4188}
4189
4190void Articulation::setAuxiliaryFirst(bool first) {
4191 auxiliaryFirst_ = first;
4192}
4193
4194bool Articulation::getAuxiliaryFirst() const {
4195 return auxiliaryFirst_;
4196}
4197
4198void Articulation::setTrillInterval(int interval) {
4199 trillInterval_ = (TrillInterval) interval;
4200}
4201
4202Articulation::TrillInterval Articulation::getTrillInterval() const {
4203 return trillInterval_;
4204}
4205
4206bool Articulation::willAffectNotes() const {
4207 bool affect = false;
4208
4209 switch (getArtType()) {
4210 case Articulation_Major_Trill:
4211 case Articulation_Minor_Trill:
4212 case Articulation_Trill_Section:
4213 case Articulation_Inverted_Short_Mordent:
4214 case Articulation_Inverted_Long_Mordent:
4215 case Articulation_Short_Mordent:
4216 case Articulation_Turn:
4217
4218 case Articulation_Arpeggio:
4219 case Articulation_Tremolo_Eighth:
4220 case Articulation_Tremolo_Sixteenth:
4221 case Articulation_Tremolo_Thirty_Second:
4222 case Articulation_Tremolo_Sixty_Fourth: {
4223 affect = true;
4224 break;
4225 }
4226 case Articulation_Finger_1:
4227 case Articulation_Finger_2:
4228 case Articulation_Finger_3:
4229 case Articulation_Finger_4:
4230 case Articulation_Finger_5:
4231 case Articulation_Flat_Accidental_For_Trill:
4232 case Articulation_Sharp_Accidental_For_Trill:
4233 case Articulation_Natural_Accidental_For_Trill:
4234 case Articulation_Marcato:
4235 case Articulation_Marcato_Dot:
4236 case Articulation_Heavy_Attack:
4237 case Articulation_SForzando:
4238 case Articulation_SForzando_Dot:
4239 case Articulation_Heavier_Attack:
4240 case Articulation_SForzando_Inverted:
4241 case Articulation_SForzando_Dot_Inverted:
4242 case Articulation_Staccatissimo:
4243 case Articulation_Staccato:
4244 case Articulation_Tenuto:
4245 case Articulation_Up_Bow:
4246 case Articulation_Down_Bow:
4247 case Articulation_Up_Bow_Inverted:
4248 case Articulation_Down_Bow_Inverted:
4249 case Articulation_Natural_Harmonic:
4250 case Articulation_Artificial_Harmonic:
4251 case Articulation_Plus_Sign:
4252 case Articulation_Fermata:
4253 case Articulation_Fermata_Inverted:
4254 case Articulation_Pedal_Down:
4255 case Articulation_Pedal_Up:
4256 case Articulation_Pause:
4257 case Articulation_Grand_Pause:
4258 case Articulation_Toe_Pedal:
4259 case Articulation_Heel_Pedal:
4260 case Articulation_Toe_To_Heel_Pedal:
4261 case Articulation_Heel_To_Toe_Pedal:
4262 case Articulation_Open_String:
4263 case Articulation_Guitar_Lift:
4264 case Articulation_Guitar_Slide_Up:
4265 case Articulation_Guitar_Rip:
4266 case Articulation_Guitar_Fall_Off:
4267 case Articulation_Guitar_Slide_Down:
4268 case Articulation_Guitar_Spill:
4269 case Articulation_Guitar_Flip:
4270 case Articulation_Guitar_Smear:
4271 case Articulation_Guitar_Bend:
4272 case Articulation_Guitar_Doit:
4273 case Articulation_Guitar_Plop:
4274 case Articulation_Guitar_Wow_Wow:
4275 case Articulation_Guitar_Thumb:
4276 case Articulation_Guitar_Index_Finger:
4277 case Articulation_Guitar_Middle_Finger:
4278 case Articulation_Guitar_Ring_Finger:
4279 case Articulation_Guitar_Pinky_Finger:
4280 case Articulation_Guitar_Tap:
4281 case Articulation_Guitar_Hammer:
4282 case Articulation_Guitar_Pluck: {
4283 break;
4284 }
4285 default:
4286 break;
4287 }
4288
4289 return affect;
4290}
4291
4292bool Articulation::isTrill(ArticulationType type) {
4293 bool isTrill = false;
4294
4295 switch (type) {
4296 case Articulation_Major_Trill:
4297 case Articulation_Minor_Trill:
4298 case Articulation_Trill_Section: {
4299 isTrill = true;
4300 break;
4301 }
4302 default:
4303 break;
4304 }
4305
4306 return isTrill;
4307}
4308
4309Articulation::XmlType Articulation::getXmlType() const {
4310 XmlType xmlType = Xml_Unknown;
4311
4312 switch (type_) {
4313 case Articulation_Major_Trill:
4314 case Articulation_Minor_Trill:
4315 case Articulation_Trill_Section:
4316 case Articulation_Inverted_Short_Mordent:
4317 case Articulation_Inverted_Long_Mordent:
4318 case Articulation_Short_Mordent:
4319 case Articulation_Turn:
4320 // case Articulation_Flat_Accidental_For_Trill :
4321 // case Articulation_Sharp_Accidental_For_Trill :
4322 // case Articulation_Natural_Accidental_For_Trill :
4323 case Articulation_Tremolo_Eighth:
4324 case Articulation_Tremolo_Sixteenth:
4325 case Articulation_Tremolo_Thirty_Second:
4326 case Articulation_Tremolo_Sixty_Fourth: {
4327 xmlType = Xml_Ornament;
4328 break;
4329 }
4330 case Articulation_Marcato:
4331 case Articulation_Marcato_Dot:
4332 case Articulation_Heavy_Attack:
4333 case Articulation_SForzando:
4334 case Articulation_SForzando_Inverted:
4335 case Articulation_SForzando_Dot:
4336 case Articulation_SForzando_Dot_Inverted:
4337 case Articulation_Heavier_Attack:
4338 case Articulation_Staccatissimo:
4339 case Articulation_Staccato:
4340 case Articulation_Tenuto:
4341 case Articulation_Pause:
4342 case Articulation_Grand_Pause: {
4343 xmlType = Xml_Articulation;
4344 break;
4345 }
4346 case Articulation_Up_Bow:
4347 case Articulation_Down_Bow:
4348 case Articulation_Up_Bow_Inverted:
4349 case Articulation_Down_Bow_Inverted:
4350 case Articulation_Natural_Harmonic:
4351 case Articulation_Artificial_Harmonic:
4352 case Articulation_Finger_1:
4353 case Articulation_Finger_2:
4354 case Articulation_Finger_3:
4355 case Articulation_Finger_4:
4356 case Articulation_Finger_5:
4357 case Articulation_Plus_Sign: {
4358 xmlType = Xml_Technical;
4359 break;
4360 }
4361 case Articulation_Arpeggio: {
4362 xmlType = Xml_Arpeggiate;
4363 break;
4364 }
4365 case Articulation_Fermata:
4366 case Articulation_Fermata_Inverted: {
4367 xmlType = Xml_Fermata;
4368 break;
4369 }
4370 case Articulation_Pedal_Down:
4371 case Articulation_Pedal_Up: {
4372 xmlType = Xml_Direction;
4373 break;
4374 }
4375 // case Articulation_Toe_Pedal :
4376 // case Articulation_Heel_Pedal :
4377 // case Articulation_Toe_To_Heel_Pedal :
4378 // case Articulation_Heel_To_Toe_Pedal :
4379 // case Articulation_Open_String :
4380 default:
4381 break;
4382 }
4383
4384 return xmlType;
4385}
4386
4388NoteContainer::NoteContainer() {
4389 musicDataType_ = MusicData_Note_Container;
4390
4391 grace_ = false;
4392 cue_ = false;
4393 rest_ = false;
4394 raw_ = false;
4395 noteType_ = Note_Quarter;
4396 dot_ = 0;
4397 graceNoteType_ = Note_Eight;
4398 stemUp_ = true;
4399 showStem_ = true;
4400 stemLength_ = 7;
4401 inBeam_ = false;
4402 tuplet_ = 0;
4403 space_ = 2;//div by 0
4404 noteShift_ = 0;
4405}
4406
4407NoteContainer::~NoteContainer(){
4408 for(int i=0; i<notes_.size(); ++i){
4409 delete notes_[i];
4410 }
4411 for(int i=0; i<articulations_.size(); ++i){
4412 delete articulations_[i];
4413 }
4414 notes_.clear();
4415 articulations_.clear();
4416}
4417
4418void NoteContainer::setIsGrace(bool grace) {
4419 grace_ = grace;
4420}
4421
4422bool NoteContainer::getIsGrace() const {
4423 return grace_;
4424}
4425
4426void NoteContainer::setIsCue(bool cue) {
4427 cue_ = cue;
4428}
4429
4430bool NoteContainer::getIsCue() const {
4431 return cue_;
4432}
4433
4434void NoteContainer::setIsRest(bool rest) {
4435 rest_ = rest;
4436}
4437
4438bool NoteContainer::getIsRest() const {
4439 return rest_;
4440}
4441
4442void NoteContainer::setIsRaw(bool raw) {
4443 raw_ = raw;
4444}
4445
4446bool NoteContainer::getIsRaw() const {
4447 return raw_;
4448}
4449
4450void NoteContainer::setNoteType(NoteType type) {
4451 noteType_ = Note_Quarter;
4452
4453 switch (type) {
4454 case Note_DoubleWhole:
4455 case Note_Whole:
4456 case Note_Half:
4457 case Note_Quarter:
4458 case Note_Eight:
4459 case Note_Sixteen:
4460 case Note_32:
4461 case Note_64:
4462 case Note_128:
4463 case Note_256: {
4464 noteType_ = type;
4465 break;
4466 }
4467 default: {
4468 break;
4469 }
4470 }
4471}
4472
4473NoteType NoteContainer::getNoteType() const {
4474 return noteType_;
4475}
4476
4477void NoteContainer::setDot(int dot) {
4478 dot_ = dot;
4479}
4480
4481int NoteContainer::getDot() const {
4482 return dot_;
4483}
4484
4485void NoteContainer::setGraceNoteType(NoteType type) {
4486 graceNoteType_ = type;
4487}
4488
4489NoteType NoteContainer::getGraceNoteType() const {
4490 return graceNoteType_;
4491}
4492
4493void NoteContainer::setInBeam(bool in) {
4494 inBeam_ = in;
4495}
4496
4497bool NoteContainer::getInBeam() const {
4498 return inBeam_;
4499}
4500
4501void NoteContainer::setStemUp(bool up) {
4502 stemUp_ = up;
4503}
4504
4505bool NoteContainer::getStemUp(void) const {
4506 return stemUp_;
4507}
4508
4509void NoteContainer::setShowStem(bool show) {
4510 showStem_ = show;
4511}
4512
4513bool NoteContainer::getShowStem() const {
4514 return showStem_;
4515}
4516
4517void NoteContainer::setStemLength(int line) {
4518 stemLength_ = line;
4519}
4520
4521int NoteContainer::getStemLength() const {
4522 return stemLength_;
4523}
4524
4525void NoteContainer::setTuplet(int tuplet) {
4526 tuplet_ = tuplet;
4527}
4528
4529int NoteContainer::getTuplet() const {
4530 return tuplet_;
4531}
4532
4533void NoteContainer::setSpace(int space) {
4534 space_ = space;
4535}
4536
4537int NoteContainer::getSpace() const {
4538 return space_;
4539}
4540
4541void NoteContainer::addNoteRest(Note* note) {
4542 notes_.push_back(note);
4543}
4544
4545QList<Note*> NoteContainer::getNotesRests() const {
4546 return notes_;
4547}
4548
4549void NoteContainer::addArticulation(Articulation* art) {
4550 articulations_.push_back(art);
4551}
4552
4553QList<Articulation*> NoteContainer::getArticulations() const {
4554 return articulations_;
4555}
4556
4557void NoteContainer::setNoteShift(int octave) {
4558 noteShift_ = octave;
4559}
4560
4561int NoteContainer::getNoteShift() const {
4562 return noteShift_;
4563}
4564
4565int NoteContainer::getOffsetStaff() const {
4566 if(getIsRest())
4567 return 0;
4568
4569 int staffMove = 0;
4570 QList<OVE::Note*> notes = getNotesRests();
4571 for (int i = 0; i < notes.size(); ++i) {
4572 OVE::Note* notePtr = notes[i];
4573 staffMove = notePtr->getOffsetStaff();
4574 }
4575
4576 return staffMove;
4577}
4578
4579int NoteContainer::getDuration() const {
4580 int duration = (int) NoteDuration_4;
4581
4582 switch (noteType_) {
4583 case Note_DoubleWhole: {
4584 duration = (int) NoteDuration_Double_Whole;
4585 break;
4586 }
4587 case Note_Whole: {
4588 duration = (int) NoteDuration_Whole;
4589 break;
4590 }
4591 case Note_Half: {
4592 duration = (int) NoteDuration_2;
4593 break;
4594 }
4595 case Note_Quarter: {
4596 duration = (int) NoteDuration_4;
4597 break;
4598 }
4599 case Note_Eight: {
4600 duration = (int) NoteDuration_8;
4601 break;
4602 }
4603 case Note_Sixteen: {
4604 duration = (int) NoteDuration_16;
4605 break;
4606 }
4607 case Note_32: {
4608 duration = (int) NoteDuration_32;
4609 break;
4610 }
4611 case Note_64: {
4612 duration = (int) NoteDuration_64;
4613 break;
4614 }
4615 case Note_128: {
4616 duration = (int) NoteDuration_128;
4617 break;
4618 }
4619 case Note_256: {
4620 duration = (int) NoteDuration_256;
4621 break;
4622 }
4623 default:
4624 break;
4625 }
4626
4627 int dotLength = duration;
4628
4629 for (int i = 0; i < dot_; ++i) {
4630 dotLength /= 2;
4631 }
4632
4633 dotLength = duration - dotLength;
4634
4635 duration += dotLength;
4636
4637 return duration;
4638}
4639
4641Beam::Beam() {
4642 musicDataType_ = MusicData_Beam;
4643 grace_ = false;
4644}
4645
4646void Beam::setIsGrace(bool grace) {
4647 grace_ = grace;
4648}
4649
4650bool Beam::getIsGrace() const {
4651 return grace_;
4652}
4653
4654void Beam::addLine(const MeasurePos& startMp, const MeasurePos& endMp) {
4655 lines_.push_back(qMakePair(startMp, endMp));
4656}
4657
4658const QList<QPair<MeasurePos, MeasurePos> > Beam::getLines() const {
4659 return lines_;
4660}
4661
4663Tie::Tie() {
4664 musicDataType_ = MusicData_Tie;
4665
4666 showOnTop_ = true;
4667 note_ = 72;
4668 height_ = 24;
4669}
4670
4671void Tie::setShowOnTop(bool top) {
4672 showOnTop_ = top;
4673}
4674
4675bool Tie::getShowOnTop() const {
4676 return showOnTop_;
4677}
4678
4679void Tie::setNote(int note) {
4680 note_ = note;
4681}
4682
4683int Tie::getNote() const {
4684 return note_;
4685}
4686
4687void Tie::setHeight(int height) {
4688 height_ = height;
4689}
4690
4691int Tie::getHeight() const {
4692 return height_;
4693}
4694
4696Glissando::Glissando() {
4697 musicDataType_ = MusicData_Glissando;
4698
4699 straight_ = true;
4700 text_ = "gliss.";
4701 lineThick_ = 8;
4702}
4703
4704void Glissando::setStraightWavy(bool straight) {
4705 straight_ = straight;
4706}
4707
4708bool Glissando::getStraightWavy() const {
4709 return straight_;
4710}
4711
4712void Glissando::setText(const QString& text) {
4713 text_ = text;
4714}
4715
4716QString Glissando::getText() const {
4717 return text_;
4718}
4719
4720void Glissando::setLineThick(int thick) {
4721 lineThick_ = thick;
4722}
4723
4724int Glissando::getLineThick() const {
4725 return lineThick_;
4726}
4727
4729Decorator::Decorator() :
4730 decoratorType_(Decorator_Articulation),
4731 artType_(Articulation_Marcato) {
4732 musicDataType_ = MusicData_Decorator;
4733}
4734
4735void Decorator::setDecoratorType(DecoratorType type) {
4736 decoratorType_ = type;
4737}
4738
4739Decorator::DecoratorType Decorator::getDecoratorType() const {
4740 return decoratorType_;
4741}
4742
4743void Decorator::setArticulationType(ArticulationType type) {
4744 artType_ = type;
4745}
4746
4747ArticulationType Decorator::getArticulationType() const {
4748 return artType_;
4749}
4750
4752MeasureRepeat::MeasureRepeat() {
4753 musicDataType_ = MusicData_Measure_Repeat;
4754 singleRepeat_ = true;
4755}
4756
4757void MeasureRepeat::setSingleRepeat(bool single) {
4758 singleRepeat_ = single;
4759
4760 start()->setMeasure(0);
4761 start()->setOffset(0);
4762 stop()->setMeasure(single ? 1 : 2);
4763 stop()->setOffset(0);
4764}
4765
4766bool MeasureRepeat::getSingleRepeat() const {
4767 return singleRepeat_;
4768}
4769
4771Tuplet::Tuplet() :
4772 tuplet_(3), space_(2), height_(0), noteType_(Note_Quarter){
4773 musicDataType_ = MusicData_Tuplet;
4774 mark_ = new OffsetElement();
4775}
4776
4777Tuplet::~Tuplet(){
4778 delete mark_;
4779}
4780
4781void Tuplet::setTuplet(int tuplet) {
4782 tuplet_ = tuplet;
4783}
4784
4785int Tuplet::getTuplet() const {
4786 return tuplet_;
4787}
4788
4789void Tuplet::setSpace(int space) {
4790 space_ = space;
4791}
4792
4793int Tuplet::getSpace() const {
4794 return space_;
4795}
4796
4797OffsetElement* Tuplet::getMarkHandle() const {
4798 return mark_;
4799}
4800
4801void Tuplet::setHeight(int height) {
4802 height_ = height;
4803}
4804
4805int Tuplet::getHeight() const {
4806 return height_;
4807}
4808
4809void Tuplet::setNoteType(NoteType type) {
4810 noteType_ = type;
4811}
4812
4813NoteType Tuplet::getNoteType() const {
4814 return noteType_;
4815}
4816
4818Harmony::Harmony() {
4819 musicDataType_ = MusicData_Harmony;
4820
4821 harmonyType_ = Harmony_maj;
4822 root_ = 0;
4823 bass_ = -1;//0xff
4824 bassOnBottom_ = false;
4825 angle_ = 0;
4826}
4827
4828void Harmony::setHarmonyType(HarmonyType type) {
4829 harmonyType_ = type;
4830}
4831
4832HarmonyType Harmony::getHarmonyType() const {
4833 return harmonyType_;
4834}
4835
4836void Harmony::setRoot(int root) {
4837 root_ = root;
4838}
4839
4840int Harmony::getRoot() const {
4841 return root_;
4842}
4843
4844void Harmony::setBass(int bass) {
4845 bass_ = bass;
4846}
4847
4848int Harmony::getBass() const {
4849 return bass_;
4850}
4851
4852void Harmony::setBassOnBottom(bool on) {
4853 bassOnBottom_ = on;
4854}
4855
4856bool Harmony::getBassOnBottom() const {
4857 return bassOnBottom_;
4858}
4859
4860void Harmony::setAngle(int angle) {
4861 angle_ = angle;
4862}
4863
4864int Harmony::getAngle() const {
4865 return angle_;
4866}
4867
4869Clef::Clef() {
4870 musicDataType_ = MusicData_Clef;
4871
4872 clefType_ = Clef_Treble;
4873}
4874
4875void Clef::setClefType(int type) {
4876 clefType_ = (ClefType) type;
4877}
4878
4879ClefType Clef::getClefType() const {
4880 return clefType_;
4881}
4882
4884Lyric::Lyric() {
4885 musicDataType_ = MusicData_Lyric;
4886
4887 lyric_ = QString();
4888 verse_ = 0;
4889}
4890
4891void Lyric::setLyric(const QString& lyricText) {
4892 lyric_ = lyricText;
4893}
4894
4895QString Lyric::getLyric() const {
4896 return lyric_;
4897}
4898
4899void Lyric::setVerse(int verse) {
4900 verse_ = verse;
4901}
4902
4903int Lyric::getVerse() const {
4904 return verse_;
4905}
4906
4908Slur::Slur() {
4909 musicDataType_ = MusicData_Slur;
4910
4911 containerCount_ = 1;
4912 showOnTop_ = true;
4913 noteTimePercent_ = 100;
4914
4915 handle_2_ = new OffsetElement();
4916 handle_3_ = new OffsetElement();
4917}
4918
4919Slur::~Slur() {
4920 delete handle_2_;
4921 delete handle_3_;
4922}
4923
4924void Slur::setContainerCount(int count) {
4925 containerCount_ = count;
4926}
4927
4928int Slur::getContainerCount() const {
4929 return containerCount_;
4930}
4931
4932void Slur::setShowOnTop(bool top) {
4933 showOnTop_ = top;
4934}
4935
4936bool Slur::getShowOnTop() const {
4937 return showOnTop_;
4938}
4939
4940OffsetElement* Slur::getHandle2() const {
4941 return handle_2_;
4942}
4943
4944OffsetElement* Slur::getHandle3() const {
4945 return handle_3_;
4946}
4947
4948void Slur::setNoteTimePercent(int percent) {
4949 noteTimePercent_ = percent;
4950}
4951
4952int Slur::getNoteTimePercent() const {
4953 return noteTimePercent_;
4954}
4955
4957Dynamics::Dynamics() {
4958 musicDataType_ = MusicData_Dynamics;
4959
4960 dynamicsType_ = Dynamics_pppp;
4961 playback_ = true;
4962 velocity_ = 30;
4963}
4964
4965void Dynamics::setDynamicsType(int type) {
4966 dynamicsType_ = (DynamicsType) type;
4967}
4968
4969DynamicsType Dynamics::getDynamicsType() const {
4970 return dynamicsType_;
4971}
4972
4973void Dynamics::setIsPlayback(bool play) {
4974 playback_ = play;
4975}
4976
4977bool Dynamics::getIsPlayback() const {
4978 return playback_;
4979}
4980
4981void Dynamics::setVelocity(int vel) {
4982 velocity_ = vel;
4983}
4984
4985int Dynamics::getVelocity() const {
4986 return velocity_;
4987}
4988
4990WedgeEndPoint::WedgeEndPoint() {
4991 musicDataType_ = MusicData_Wedge_EndPoint;
4992
4993 wedgeType_ = Wedge_Cres;
4994 height_ = 24;
4995 wedgeStart_ = true;
4996}
4997
4998void WedgeEndPoint::setWedgeType(WedgeType type) {
4999 wedgeType_ = type;
5000}
5001
5002WedgeType WedgeEndPoint::getWedgeType() const {
5003 return wedgeType_;
5004}
5005
5006void WedgeEndPoint::setHeight(int height) {
5007 height_ = height;
5008}
5009
5010int WedgeEndPoint::getHeight() const {
5011 return height_;
5012}
5013
5014void WedgeEndPoint::setWedgeStart(bool wedgeStart) {
5015 wedgeStart_ = wedgeStart;
5016}
5017
5018bool WedgeEndPoint::getWedgeStart() const {
5019 return wedgeStart_;
5020}
5021
5023Wedge::Wedge() {
5024 musicDataType_ = MusicData_Wedge;
5025
5026 wedgeType_ = Wedge_Cres;
5027 height_ = 24;
5028}
5029
5030void Wedge::setWedgeType(WedgeType type) {
5031 wedgeType_ = type;
5032}
5033
5034WedgeType Wedge::getWedgeType() const {
5035 return wedgeType_;
5036}
5037
5038void Wedge::setHeight(int height) {
5039 height_ = height;
5040}
5041
5042int Wedge::getHeight() const {
5043 return height_;
5044}
5045
5047Pedal::Pedal() {
5048 musicDataType_ = MusicData_Pedal;
5049
5050 half_ = false;
5051 playback_ = false;
5052 playOffset_ = 0;
5053
5054 pedalHandle_ = new OffsetElement();
5055}
5056
5057Pedal::~Pedal() {
5058 delete pedalHandle_;
5059}
5060
5061void Pedal::setHalf(bool half) {
5062 half_ = half;
5063}
5064
5065bool Pedal::getHalf() const {
5066 return half_;
5067}
5068
5069OffsetElement* Pedal::getPedalHandle() const {
5070 return pedalHandle_;
5071}
5072
5073void Pedal::setIsPlayback(bool playback) {
5074 playback_ = playback;
5075}
5076
5077bool Pedal::getIsPlayback() const {
5078 return playback_;
5079}
5080
5081void Pedal::setPlayOffset(int offset) {
5082 playOffset_ = offset;
5083}
5084
5085int Pedal::getPlayOffset() const {
5086 return playOffset_;
5087}
5088
5090KuoHao::KuoHao() {
5091 musicDataType_ = MusicData_KuoHao;
5092
5093 kuohaoType_ = KuoHao_Parentheses;
5094 height_ = 0;
5095}
5096
5097void KuoHao::setHeight(int height) {
5098 height_ = height;
5099}
5100
5101int KuoHao::getHeight() const {
5102 return height_;
5103}
5104
5105void KuoHao::setKuohaoType(int type) {
5106 kuohaoType_ = (KuoHaoType) type;
5107}
5108
5109KuoHaoType KuoHao::getKuohaoType() const {
5110 return kuohaoType_;
5111}
5112
5114Expressions::Expressions() {
5115 musicDataType_ = MusicData_Expressions;
5116
5117 text_ = QString();
5118}
5119
5120void Expressions::setText(const QString& str) {
5121 text_ = str;
5122}
5123
5124QString Expressions::getText() const {
5125 return text_;
5126}
5127
5129HarpPedal::HarpPedal() :
5130 showType_(0),
5131 showCharFlag_(0) {
5132 musicDataType_ = MusicData_Harp_Pedal;
5133}
5134
5135void HarpPedal::setShowType(int type) {
5136 showType_ = type;
5137}
5138
5139int HarpPedal::getShowType() const {
5140 return showType_;
5141}
5142
5143void HarpPedal::setShowCharFlag(int flag) {
5144 showCharFlag_ = flag;
5145}
5146
5147int HarpPedal::getShowCharFlag() const {
5148 return showCharFlag_;
5149}
5150
5152OctaveShift::OctaveShift() :
5153 octaveShiftType_(OctaveShift_8),
5154 octaveShiftPosition_(OctavePosition_Start),
5155 endTick_(0) {
5156 musicDataType_ = MusicData_OctaveShift;
5157}
5158
5159void OctaveShift::setOctaveShiftType(int type) {
5160 octaveShiftType_ = (OctaveShiftType) type;
5161}
5162
5163OctaveShiftType OctaveShift::getOctaveShiftType() const {
5164 return octaveShiftType_;
5165}
5166
5167int OctaveShift::getNoteShift() const {
5168 int shift = 12;
5169
5170 switch (getOctaveShiftType()) {
5171 case OctaveShift_8: {
5172 shift = 12;
5173 break;
5174 }
5175 case OctaveShift_Minus_8: {
5176 shift = -12;
5177 break;
5178 }
5179 case OctaveShift_15: {
5180 shift = 24;
5181 break;
5182 }
5183 case OctaveShift_Minus_15: {
5184 shift = -24;
5185 break;
5186 }
5187 default:
5188 break;
5189 }
5190
5191 return shift;
5192}
5193
5194void OctaveShift::setEndTick(int tick) {
5195 endTick_ = tick;
5196}
5197
5198int OctaveShift::getEndTick() const {
5199 return endTick_;
5200}
5201
5203OctaveShiftEndPoint::OctaveShiftEndPoint() {
5204 musicDataType_ = MusicData_OctaveShift_EndPoint;
5205
5206 octaveShiftType_ = OctaveShift_8;
5207 octaveShiftPosition_ = OctavePosition_Start;
5208 endTick_ = 0;
5209}
5210
5211void OctaveShiftEndPoint::setOctaveShiftType(int type) {
5212 octaveShiftType_ = (OctaveShiftType) type;
5213}
5214
5215OctaveShiftType OctaveShiftEndPoint::getOctaveShiftType() const {
5216 return octaveShiftType_;
5217}
5218
5219void OctaveShiftEndPoint::setOctaveShiftPosition(int position) {
5220 octaveShiftPosition_ = (OctaveShiftPosition) position;
5221}
5222
5223OctaveShiftPosition OctaveShiftEndPoint::getOctaveShiftPosition() const {
5224 return octaveShiftPosition_;
5225}
5226
5227void OctaveShiftEndPoint::setEndTick(int tick) {
5228 endTick_ = tick;
5229}
5230
5231int OctaveShiftEndPoint::getEndTick() const {
5232 return endTick_;
5233}
5234
5236MultiMeasureRest::MultiMeasureRest() {
5237 musicDataType_ = MusicData_Multi_Measure_Rest;
5238 measureCount_ = 0;
5239}
5240
5241void MultiMeasureRest::setMeasureCount(int count) {
5242 measureCount_ = count;
5243}
5244
5245int MultiMeasureRest::getMeasureCount() const {
5246 return measureCount_;
5247}
5248
5250Tempo::Tempo() {
5251 musicDataType_ = MusicData_Tempo;
5252
5253 leftNoteType_ = 3;
5254 showMark_ = false;
5255 showText_ = false;
5256 showParenthesis_ = false;
5257 typeTempo_ = 96;
5258 leftText_ = QString();
5259 rightText_ = QString();
5260 swingEighth_ = false;
5261 rightNoteType_ = 3;
5262}
5263
5264void Tempo::setLeftNoteType(int type) {
5265 leftNoteType_ = type;
5266}
5267
5268NoteType Tempo::getLeftNoteType() const {
5269 return (NoteType) leftNoteType_;
5270}
5271
5272void Tempo::setShowMark(bool show) {
5273 showMark_ = show;
5274}
5275
5276bool Tempo::getShowMark() const {
5277 return showMark_;
5278}
5279
5280void Tempo::setShowBeforeText(bool show) {
5281 showText_ = show;
5282}
5283
5284bool Tempo::getShowBeforeText() const {
5285 return showText_;
5286}
5287
5288void Tempo::setShowParenthesis(bool show) {
5289 showParenthesis_ = show;
5290}
5291
5292bool Tempo::getShowParenthesis() const {
5293 return showParenthesis_;
5294}
5295
5296void Tempo::setTypeTempo(int tempo) {
5297 typeTempo_ = tempo;
5298}
5299
5300int Tempo::getTypeTempo() const {
5301 return typeTempo_;
5302}
5303
5304int Tempo::getQuarterTempo() const {
5305 double factor = pow(2.0, (int) Note_Quarter - (int) getLeftNoteType());
5306 int tempo = int((double) getTypeTempo() * factor);
5307
5308 return tempo;
5309}
5310
5311void Tempo::setLeftText(const QString& str) {
5312 leftText_ = str;
5313}
5314
5315QString Tempo::getLeftText() const {
5316 return leftText_;
5317}
5318
5319void Tempo::setRightText(const QString& str) {
5320 rightText_ = str;
5321}
5322
5323QString Tempo::getRightText() const {
5324 return rightText_;
5325}
5326
5327void Tempo::setSwingEighth(bool swing) {
5328 swingEighth_ = swing;
5329}
5330
5331bool Tempo::getSwingEighth() const {
5332 return swingEighth_;
5333}
5334
5335void Tempo::setRightNoteType(int type) {
5336 rightNoteType_ = type;
5337}
5338
5339int Tempo::getRightNoteType() const {
5340 return rightNoteType_;
5341}
5342
5344Text::Text() {
5345 musicDataType_ = MusicData_Text;
5346
5347 textType_ = Text_Rehearsal;
5348 horiMargin_ = 8;
5349 vertMargin_ = 8;
5350 lineThick_ = 4;
5351 text_ = QString();
5352 width_ = 0;
5353 height_ = 0;
5354}
5355
5356void Text::setTextType(TextType type) {
5357 textType_ = type;
5358}
5359
5360Text::TextType Text::getTextType() const {
5361 return textType_;
5362}
5363
5364void Text::setHorizontalMargin(int margin) {
5365 horiMargin_ = margin;
5366}
5367
5368int Text::getHorizontalMargin() const {
5369 return horiMargin_;
5370}
5371
5372void Text::setVerticalMargin(int margin) {
5373 vertMargin_ = margin;
5374}
5375
5376int Text::getVerticalMargin() const {
5377 return vertMargin_;
5378}
5379
5380void Text::setLineThick(int thick) {
5381 lineThick_ = thick;
5382}
5383
5384int Text::getLineThick() const {
5385 return lineThick_;
5386}
5387
5388void Text::setText(const QString& text) {
5389 text_ = text;
5390}
5391
5392QString Text::getText() const {
5393 return text_;
5394}
5395
5396void Text::setWidth(int width) {
5397 width_ = width;
5398}
5399
5400int Text::getWidth() const {
5401 return width_;
5402}
5403
5404void Text::setHeight(int height) {
5405 height_ = height;
5406}
5407
5408int Text::getHeight() const {
5409 return height_;
5410}
5411
5413TimeSignature::TimeSignature() {
5414 numerator_ = 4;
5415 denominator_ = 4;
5416 isSymbol_ = false;
5417 beatLength_ = 480;
5418 barLength_ = 1920;
5419 barLengthUnits_ = 0x400;
5420 replaceFont_ = false;
5421 showBeatGroup_ = false;
5422
5423 groupNumerator1_ = 0;
5424 groupNumerator2_ = 0;
5425 groupNumerator3_ = 0;
5426 groupDenominator1_ = 4;
5427 groupDenominator2_ = 4;
5428 groupDenominator3_ = 4;
5429
5430 beamGroup1_ = 4;
5431 beamGroup2_ = 0;
5432 beamGroup3_ = 0;
5433 beamGroup4_ = 0;
5434
5435 beamCount16th_ = 4;
5436 beamCount32th_ = 1;
5437}
5438
5439void TimeSignature::setNumerator(int numerator) {
5440 numerator_ = numerator;
5441}
5442
5443int TimeSignature::getNumerator() const {
5444 return numerator_;
5445}
5446
5447void TimeSignature::setDenominator(int denominator) {
5448 denominator_ = denominator;
5449}
5450
5451int TimeSignature::getDenominator() const {
5452 return denominator_;
5453}
5454
5455void TimeSignature::setIsSymbol(bool symbol) {
5456 isSymbol_ = symbol;
5457}
5458
5459bool TimeSignature::getIsSymbol() const {
5460 if (numerator_ == 2 && denominator_ == 2) {
5461 return true;
5462 }
5463
5464 return isSymbol_;
5465}
5466
5467void TimeSignature::setBeatLength(int length) {
5468 beatLength_ = length;
5469}
5470
5471int TimeSignature::getBeatLength() const {
5472 return beatLength_;
5473}
5474
5475void TimeSignature::setBarLength(int length) {
5476 barLength_ = length;
5477}
5478
5479int TimeSignature::getBarLength() const {
5480 return barLength_;
5481}
5482
5483void TimeSignature::addBeat(int startUnit, int lengthUnit, int startTick) {
5484 BeatNode node;
5485 node.startUnit_ = startUnit;
5486 node.lengthUnit_ = lengthUnit;
5487 node.startTick_ = startTick;
5488 beats_.push_back(node);
5489}
5490
5491void TimeSignature::endAddBeat()
5492{
5493 int i;
5494 barLengthUnits_ = 0;
5495
5496 for (i = 0; i < beats_.size(); ++i) {
5497 barLengthUnits_ += beats_[i].lengthUnit_;
5498 }
5499}
5500
5501int TimeSignature::getUnits() const {
5502 return barLengthUnits_;
5503}
5504
5505void TimeSignature::setReplaceFont(bool replace) {
5506 replaceFont_ = replace;
5507}
5508
5509bool TimeSignature::getReplaceFont() const {
5510 return replaceFont_;
5511}
5512
5513void TimeSignature::setShowBeatGroup(bool show) {
5514 showBeatGroup_ = show;
5515}
5516
5517bool TimeSignature::getShowBeatGroup() const {
5518 return showBeatGroup_;
5519}
5520
5521void TimeSignature::setGroupNumerator1(int numerator) {
5522 groupNumerator1_ = numerator;
5523}
5524
5525void TimeSignature::setGroupNumerator2(int numerator) {
5526 groupNumerator2_ = numerator;
5527}
5528
5529void TimeSignature::setGroupNumerator3(int numerator) {
5530 groupNumerator3_ = numerator;
5531}
5532
5533void TimeSignature::setGroupDenominator1(int denominator) {
5534 groupDenominator1_ = denominator;
5535}
5536
5537void TimeSignature::setGroupDenominator2(int denominator) {
5538 groupDenominator2_ = denominator;
5539}
5540
5541void TimeSignature::setGroupDenominator3(int denominator) {
5542 groupDenominator3_ = denominator;
5543}
5544
5545void TimeSignature::setBeamGroup1(int count) {
5546 beamGroup1_ = count;
5547}
5548
5549void TimeSignature::setBeamGroup2(int count) {
5550 beamGroup2_ = count;
5551}
5552
5553void TimeSignature::setBeamGroup3(int count) {
5554 beamGroup3_ = count;
5555}
5556
5557void TimeSignature::setBeamGroup4(int count) {
5558 beamGroup4_ = count;
5559}
5560
5561void TimeSignature::set16thBeamCount(int count) {
5562 beamCount16th_ = count;
5563}
5564
5565void TimeSignature::set32thBeamCount(int count) {
5566 beamCount32th_ = count;
5567}
5568
5570Key::Key() {
5571 key_ = 0;
5572 set_ = false;
5573 previousKey_ = 0;
5574 symbolCount_ = 0;
5575}
5576
5577void Key::setKey(int key) {
5578 key_ = key;
5579 set_ = true;
5580}
5581
5582int Key::getKey() const {
5583 return key_;
5584}
5585
5586bool Key::getSetKey() const {
5587 return set_;
5588}
5589
5590void Key::setPreviousKey(int key) {
5591 previousKey_ = key;
5592}
5593
5594int Key::getPreviousKey() const {
5595 return previousKey_;
5596}
5597
5598void Key::setSymbolCount(int count) {
5599 symbolCount_ = count;
5600}
5601
5602int Key::getSymbolCount() const {
5603 return symbolCount_;
5604}
5605
5607RepeatSymbol::RepeatSymbol() :
5608 text_("#1"), repeatType_(Repeat_Segno) {
5609 musicDataType_ = MusicData_Repeat;
5610}
5611
5612void RepeatSymbol::setText(const QString& text) {
5613 text_ = text;
5614}
5615
5616QString RepeatSymbol::getText() const {
5617 return text_;
5618}
5619
5620void RepeatSymbol::setRepeatType(int repeatType) {
5621 repeatType_ = (RepeatType) repeatType;
5622}
5623
5624RepeatType RepeatSymbol::getRepeatType() const {
5625 return repeatType_;
5626}
5627
5629NumericEnding::NumericEnding() {
5630 musicDataType_ = MusicData_Numeric_Ending;
5631
5632 height_ = 0;
5633 text_ = QString();
5634 numericHandle_ = new OffsetElement();
5635}
5636
5637NumericEnding::~NumericEnding() {
5638 delete numericHandle_;
5639}
5640
5641OffsetElement* NumericEnding::getNumericHandle() const {
5642 return numericHandle_;
5643}
5644
5645void NumericEnding::setHeight(int height) {
5646 height_ = height;
5647}
5648
5649int NumericEnding::getHeight() const {
5650 return height_;
5651}
5652
5653void NumericEnding::setText(const QString& text) {
5654 text_ = text;
5655}
5656
5657QString NumericEnding::getText() const {
5658 return text_;
5659}
5660
5661QList<int> NumericEnding::getNumbers() const {
5662 int i;
5663 QStringList strs = text_.split(",", QString::SkipEmptyParts);
5664 QList<int> endings;
5665
5666 for (i = 0; i < strs.size(); ++i) {
5667 bool ok;
5668 int num = strs[i].toInt(&ok);
5669 endings.push_back(num);
5670 }
5671
5672 return endings;
5673}
5674
5675int NumericEnding::getJumpCount() const {
5676 QList<int> numbers = getNumbers();
5677 int count = 0;
5678
5679 for (int i = 0; i < numbers.size(); ++i) {
5680 if ((int)i + 1 != numbers[i]) {
5681 break;
5682 }
5683
5684 count = i + 1;
5685 }
5686
5687 return count;
5688}
5689
5691BarNumber::BarNumber() {
5692 index_ = 0;
5693 showOnParagraphStart_ = false;
5694 align_ = 0;
5695 showFlag_ = 1; // staff
5696 barRange_ = 1; // can't be 0
5697 prefix_ = QString();
5698}
5699
5700void BarNumber::setIndex(int index) {
5701 index_ = index;
5702}
5703
5704int BarNumber::getIndex() const {
5705 return index_;
5706}
5707
5708void BarNumber::setShowOnParagraphStart(bool show) {
5709 showOnParagraphStart_ = show;
5710}
5711
5712bool BarNumber::getShowOnParagraphStart() const {
5713 return showOnParagraphStart_;
5714}
5715
5716void BarNumber::setAlign(int align)// 0:left, 1:center, 2:right
5717{
5718 align_ = align;
5719}
5720
5721int BarNumber::getAlign() const {
5722 return align_;
5723}
5724
5725void BarNumber::setShowFlag(int flag) {
5726 showFlag_ = flag;
5727}
5728
5729int BarNumber::getShowFlag() const {
5730 return showFlag_;
5731}
5732
5733void BarNumber::setShowEveryBarCount(int count) {
5734 barRange_ = count;
5735}
5736
5737int BarNumber::getShowEveryBarCount() const {
5738 return barRange_;
5739}
5740
5741void BarNumber::setPrefix(const QString& str) {
5742 prefix_ = str;
5743}
5744
5745QString BarNumber::getPrefix() const {
5746 return prefix_;
5747}
5748
5750MidiController::MidiController() {
5751 midiType_ = Midi_Controller;
5752 controller_ = 64; // pedal
5753 value_ = 0;
5754}
5755
5756void MidiController::setController(int number) {
5757 controller_ = number;
5758}
5759
5760int MidiController::getController() const {
5761 return controller_;
5762}
5763
5764void MidiController::setValue(int value) {
5765 value_ = value;
5766}
5767
5768int MidiController::getValue() const {
5769 return value_;
5770}
5771
5773MidiProgramChange::MidiProgramChange() {
5774 midiType_ = Midi_Program_Change;
5775 patch_ = 0; // grand piano
5776}
5777
5778void MidiProgramChange::setPatch(int patch) {
5779 patch_ = patch;
5780}
5781
5782int MidiProgramChange::getPatch() const {
5783 return patch_;
5784}
5785
5787MidiChannelPressure::MidiChannelPressure() :
5788 pressure_(0) {
5789 midiType_ = Midi_Channel_Pressure;
5790}
5791
5792void MidiChannelPressure::setPressure(int pressure) {
5793 pressure_ = pressure;
5794}
5795
5796int MidiChannelPressure::getPressure() const {
5797 return pressure_;
5798}
5799
5801MidiPitchWheel::MidiPitchWheel() {
5802 midiType_ = Midi_Pitch_Wheel;
5803 value_ = 0;
5804}
5805
5806void MidiPitchWheel::setValue(int value) {
5807 value_ = value;
5808}
5809
5810int MidiPitchWheel::getValue() const {
5811 return value_;
5812}
5813
5815Measure::Measure(int index) {
5816 barNumber_ = new BarNumber();
5817 barNumber_->setIndex(index);
5818 time_ = new TimeSignature();
5819
5820 clear();
5821}
5822
5823Measure::~Measure(){
5824 clear();
5825
5826 delete barNumber_;
5827 delete time_;
5828}
5829
5830BarNumber* Measure::getBarNumber() const {
5831 return barNumber_;
5832}
5833
5834TimeSignature* Measure::getTime() const {
5835 return time_;
5836}
5837
5838void Measure::setLeftBarline(int barline) {
5839 leftBarline_ = (BarlineType) barline;
5840}
5841
5842BarlineType Measure::getLeftBarline() const {
5843 return leftBarline_;
5844}
5845
5846void Measure::setRightBarline(int barline) {
5847 rightBarline_ = (BarlineType) barline;
5848}
5849
5850BarlineType Measure::getRightBarline() const {
5851 return rightBarline_;
5852}
5853
5854void Measure::setBackwardRepeatCount(int repeatCount) {
5855 repeatCount_ = repeatCount;
5856}
5857
5858int Measure::getBackwardRepeatCount() const {
5859 return repeatCount_;
5860}
5861
5862void Measure::setTypeTempo(double tempo) {
5863 typeTempo_ = tempo;
5864}
5865
5866double Measure::getTypeTempo() const {
5867 return typeTempo_;
5868}
5869
5870void Measure::setIsPickup(bool pickup) {
5871 pickup_ = pickup;
5872}
5873
5874bool Measure::getIsPickup() const {
5875 return pickup_;
5876}
5877
5878void Measure::setIsMultiMeasureRest(bool rest) {
5879 multiMeasureRest_ = rest;
5880}
5881
5882bool Measure::getIsMultiMeasureRest() const {
5883 return multiMeasureRest_;
5884}
5885
5886void Measure::setMultiMeasureRestCount(int count) {
5887 multiMeasureRestCount_ = count;
5888}
5889
5890int Measure::getMultiMeasureRestCount() const {
5891 return multiMeasureRestCount_;
5892}
5893
5894void Measure::clear() {
5895 leftBarline_ = Barline_Default;
5896 rightBarline_ = Barline_Default;
5897 repeatCount_ = 1;
5898 typeTempo_ = 96.00;
5899 setLength(0x780); //time = 4/4
5900 pickup_ = false;
5901 multiMeasureRest_ = false;
5902 multiMeasureRestCount_ = 0;
5903}
5904
5906MeasureData::MeasureData() {
5907 key_ = new Key();
5908 clef_ = new Clef();
5909}
5910
5911MeasureData::~MeasureData(){
5912 int i;
5913 for(i=0; i<musicDatas_.size(); ++i){
5914 delete musicDatas_[i];
5915 }
5916 musicDatas_.clear();
5917
5918 // noteContainers_ also in musicDatas_, no need to destory
5919 noteContainers_.clear();
5920
5921 // only delete at element start
5922 for(i=0; i<crossMeasureElements_.size(); ++i){
5923 if(crossMeasureElements_[i].second){
5924 delete crossMeasureElements_[i].first;
5925 }
5926 }
5927 crossMeasureElements_.clear();
5928
5929 for(i=0; i<midiDatas_.size(); ++i){
5930 delete midiDatas_[i];
5931 }
5932 midiDatas_.clear();
5933
5934 delete key_;
5935 delete clef_;
5936}
5937
5938Key* MeasureData::getKey() const {
5939 return key_;
5940}
5941
5942Clef* MeasureData::getClef() const {
5943 return clef_;
5944}
5945
5946void MeasureData::addNoteContainer(NoteContainer* ptr) {
5947 noteContainers_.push_back(ptr);
5948}
5949
5950QList<NoteContainer*> MeasureData::getNoteContainers() const {
5951 return noteContainers_;
5952}
5953
5954void MeasureData::addMusicData(MusicData* ptr) {
5955 musicDatas_.push_back(ptr);
5956}
5957
5958QList<MusicData*> MeasureData::getMusicDatas(MusicDataType type) {
5959 int i;
5960 QList<MusicData*> notations;
5961
5962 for (i = 0; i < musicDatas_.size(); ++i) {
5963 if (type == MusicData_None || musicDatas_[i]->getMusicDataType() == type) {
5964 notations.push_back(musicDatas_[i]);
5965 }
5966 }
5967
5968 return notations;
5969}
5970
5971void MeasureData::addCrossMeasureElement(MusicData* ptr, bool start) {
5972 crossMeasureElements_.push_back(qMakePair(ptr, start));
5973}
5974
5975QList<MusicData*> MeasureData::getCrossMeasureElements(
5976 MusicDataType type, PairType pairType)
5977{
5978 int i;
5979 QList<MusicData*> pairs;
5980
5981 for (i = 0; i < crossMeasureElements_.size(); ++i) {
5982 if ((type == MusicData_None || crossMeasureElements_[i].first->getMusicDataType() == type)
5983 && (pairType == PairType_All || ((crossMeasureElements_[i].second && pairType == PairType_Start)
5984 || (!crossMeasureElements_[i].second && pairType == PairType_Stop)))) {
5985 pairs.push_back(crossMeasureElements_[i].first);
5986 }
5987 }
5988
5989 return pairs;
5990}
5991
5992void MeasureData::addMidiData(MidiData* ptr) {
5993 midiDatas_.push_back(ptr);
5994}
5995
5996QList<MidiData*> MeasureData::getMidiDatas(MidiType type) {
5997 int i;
5998 QList<MidiData*> datas;
5999
6000 for (i = 0; i < midiDatas_.size(); ++i) {
6001 if (type == Midi_None || midiDatas_[i]->getMidiType() == type) {
6002 datas.push_back(midiDatas_[i]);
6003 }
6004 }
6005
6006 return datas;
6007}
6008
6011StreamHandle::StreamHandle() :
6012 size_(0), curPos_(0), point_(NULL) {
6013}
6014
6015StreamHandle::StreamHandle(unsigned char* p, int size) :
6016 size_(size), curPos_(0), point_(p) {
6017}
6018
6019StreamHandle::~StreamHandle() {
6020 point_ = NULL;
6021}
6022
6023bool StreamHandle::read(char* buff, int size) {
6024 if (point_ != NULL && curPos_ + size <= size_) {
6025 memcpy(buff, point_ + curPos_, size);
6026 curPos_ += size;
6027
6028 return true;
6029 }
6030
6031 return false;
6032}
6033
6034bool StreamHandle::write(char* /*buff*/, int /*size*/) {
6035 return true;
6036}
6037
6038// Block.cpp
6040Block::Block() {
6041 doResize(0);
6042}
6043
6044Block::Block(unsigned int count) {
6045 doResize(count);
6046}
6047
6048void Block::resize(unsigned int count) {
6049 doResize(count);
6050}
6051
6052void Block::doResize(unsigned int count) {
6053 data_.clear();
6054 for(unsigned int i=0; i<count; ++i) {
6055 data_.push_back('\0');
6056 }
6057 //data_.resize(count);
6058}
6059
6060const unsigned char* Block::data() const {
6061 //return const_cast<unsigned char*>(&data_.front());
6062 return &data_.front();
6063}
6064
6065unsigned char* Block::data() {
6066 return &data_.front();
6067}
6068
6069unsigned int Block::size() const {
6070 return data_.size();
6071}
6072
6073bool Block::toBoolean() const {
6074 if (data() == NULL) {
6075 return false;
6076 }
6077
6078 return size() == 1 && data()[0] == 0x01;
6079}
6080
6081unsigned int Block::toUnsignedInt() const {
6082 if (data() == NULL) {
6083 return 0;
6084 }
6085
6086 unsigned int i;
6087 unsigned int num(0);
6088
6089 for (i = 0; i < sizeof(unsigned int) && i < size(); ++i) {
6090 num = (num << 8) + *(data() + i);
6091 }
6092
6093 return num;
6094}
6095
6096int Block::toInt() const {
6097 if (data() == NULL) {
6098 return 0;
6099 }
6100
6101 unsigned int i;
6102 int num = 0;
6103
6104 for (i = 0; i < sizeof(unsigned int) && i < size(); ++i) {
6105 num = (num << 8) + (int) *(data() + i);
6106 }
6107
6108 std::size_t minSize = sizeof(unsigned int);
6109 if (size() < minSize) {
6110 minSize = size();
6111 }
6112
6113 if ((*(data()) & 0x80) == 0x80) {
6114 int maxNum = int(pow(2.0, (int) minSize * 8));
6115 num -= maxNum;
6116 //num *= -1;
6117 }
6118
6119 return num;
6120}
6121
6122QByteArray Block::toStrByteArray() const {
6123 if (data() == NULL) {
6124 return QByteArray();
6125 }
6126
6127 QByteArray arr((char*) data(), size());
6128
6129 return arr;
6130}
6131
6132QByteArray Block::fixedSizeBufferToStrByteArray() const {
6133 unsigned int i;
6134 QByteArray str;
6135
6136 for (i = 0; i < size(); ++i) {
6137 if (*(data() + i) == '\0') {
6138 break;
6139 }
6140
6141 str += (char) *(data() + i);
6142 }
6143
6144 return str;
6145}
6146
6147bool Block::operator ==(const Block& block) const {
6148 unsigned int i;
6149
6150 if (size() != block.size()) {
6151 return false;
6152 }
6153
6154 for (i = 0; i < size() && i < block.size(); ++i) {
6155 if (*(data() + i) != *(block.data() + i)) {
6156 return false;
6157 }
6158 }
6159
6160 return true;
6161}
6162
6163bool Block::operator !=(const Block& block) const {
6164 return !(*this == block);
6165}
6166
6168FixedBlock::FixedBlock() :
6169 Block() {
6170}
6171
6172FixedBlock::FixedBlock(unsigned int count) :
6173 Block(count) {
6174}
6175
6176void FixedBlock::resize(unsigned int /*count*/) {
6177 // Block::resize(size);
6178}
6179
6181SizeBlock::SizeBlock() :
6182 FixedBlock(4) {
6183}
6184
6185unsigned int SizeBlock::toSize() const {
6186 unsigned int i;
6187 unsigned int num(0);
6188 const unsigned int SIZE = 4;
6189
6190 for (i = 0; i < SIZE; ++i) {
6191 num = (num << 8) + *(data() + i);
6192 }
6193
6194 return num;
6195}
6196
6197/*void SizeBlock::fromUnsignedInt(unsigned int count)
6198 {
6199 unsigned_int_to_char_buffer(count, data());
6200 }*/
6201
6203NameBlock::NameBlock() :
6204 FixedBlock(4) {
6205}
6206
6207/*void NameBlock::setValue(const char* const name)
6208 {
6209 unsigned int i;
6210
6211 for( i=0; i<size() && *(name+i)!='\0'; ++i )
6212 {
6213 *(data()+i) = *(name+i);
6214 }
6215 }*/
6216
6217bool NameBlock::isEqual(const QString& name) const
6218{
6219 unsigned int i, nsize = static_cast<unsigned>(name.size());
6220
6221 if (nsize != size()) {
6222 return false;
6223 }
6224
6225 for (i = 0; i < size() && nsize; ++i) {
6226 if (data()[i] != name[i]) {
6227 return false;
6228 }
6229 }
6230
6231 return true;
6232}
6233
6235CountBlock::CountBlock() :
6236 FixedBlock(2) {
6237}
6238
6239/*void CountBlock::setValue(unsigned short count)
6240 {
6241 unsigned int i;
6242 unsigned int SIZE = sizeof(unsigned short);
6243
6244 for( i=0; i<SIZE; ++i )
6245 {
6246 data()[SIZE-1-i] = count % 256;
6247 count /= 256;
6248 }
6249 }*/
6250
6251unsigned short CountBlock::toCount() const {
6252 unsigned int i;
6253 unsigned short num = 0;
6254
6255 for (i = 0; i < size() && i < sizeof(unsigned short); ++i) {
6256 num = (num << 8) + *(data() + i);
6257 }
6258
6259 return num;
6260}
6261
6262// Chunk.cpp
6263const QString Chunk::TrackName = "TRAK";
6264const QString Chunk::PageName = "PAGE";
6265const QString Chunk::LineName = "LINE";
6266const QString Chunk::StaffName = "STAF";
6267const QString Chunk::MeasureName = "MEAS";
6268const QString Chunk::ConductName = "COND";
6269const QString Chunk::BdatName = "BDAT";
6270
6271Chunk::Chunk() {
6272}
6273
6274NameBlock Chunk::getName() const {
6275 return nameBlock_;
6276}
6277
6279const unsigned int SizeChunk::version3TrackSize = 0x13a;
6280
6281SizeChunk::SizeChunk() :
6282 Chunk() {
6283 sizeBlock_ = new SizeBlock();
6284 dataBlock_ = new Block();
6285}
6286
6287SizeChunk::~SizeChunk() {
6288 delete sizeBlock_;
6289 delete dataBlock_;
6290}
6291
6292SizeBlock* SizeChunk::getSizeBlock() const {
6293 return sizeBlock_;
6294}
6295
6296Block* SizeChunk::getDataBlock() const {
6297 return dataBlock_;
6298}
6299
6301GroupChunk::GroupChunk() : Chunk() {
6302 childCount_ = new CountBlock();
6303}
6304
6305GroupChunk::~GroupChunk() {
6306 delete childCount_;
6307}
6308
6309CountBlock* GroupChunk::getCountBlock() const {
6310 return childCount_;
6311}
6312
6313// ChunkParse.cpp
6314unsigned int getHighNibble(unsigned int byte) {
6315 return byte / 16;
6316}
6317
6318unsigned int getLowNibble(unsigned int byte) {
6319 return byte % 16;
6320}
6321
6322int oveKeyToKey(int oveKey) {
6323 int key = 0;
6324
6325 if( oveKey == 0 ) {
6326 key = 0;
6327 }
6328 else if( oveKey > 7 ) {
6329 key = oveKey - 7;
6330 }
6331 else if( oveKey <= 7 ) {
6332 key = oveKey * (-1);
6333 }
6334
6335 return key;
6336}
6337
6339BasicParse::BasicParse(OveSong* ove) :
6340 ove_(ove), handle_(NULL), notify_(NULL) {
6341}
6342
6343BasicParse::BasicParse() :
6344 ove_(NULL), handle_(NULL), notify_(NULL) {
6345}
6346
6347BasicParse::~BasicParse() {
6348 ove_ = NULL;
6349 handle_ = NULL;
6350 notify_ = NULL;
6351}
6352
6353void BasicParse::setNotify(IOveNotify* notify) {
6354 notify_ = notify;
6355}
6356
6357bool BasicParse::parse() {
6358 return false;
6359}
6360
6361bool BasicParse::readBuffer(Block& placeHolder, unsigned int size) {
6362 if (handle_ == NULL) {
6363 return false;
6364 }
6365 if (placeHolder.size() != size) {
6366 placeHolder.resize(size);
6367 }
6368
6369 if (size > 0) {
6370 return handle_->read((char*) placeHolder.data(), placeHolder.size());
6371 }
6372
6373 return true;
6374}
6375
6376bool BasicParse::jump(int offset) {
6377 if (handle_ == NULL || offset < 0) {
6378 return false;
6379 }
6380
6381 if (offset > 0) {
6382 Block placeHolder(offset);
6383 return handle_->read((char*) placeHolder.data(), placeHolder.size());
6384 }
6385
6386 return true;
6387}
6388
6389void BasicParse::messageOut(const QString& str) {
6390 if (notify_ != NULL) {
6391 notify_->loadInfo(str);
6392 }
6393}
6394
6396OvscParse::OvscParse(OveSong* ove) :
6397 BasicParse(ove), chunk_(NULL) {
6398}
6399
6400OvscParse::~OvscParse() {
6401 chunk_ = NULL;
6402}
6403
6404void OvscParse::setOvsc(SizeChunk* chunk) {
6405 chunk_ = chunk;
6406}
6407
6408bool OvscParse::parse() {
6409 Block* dataBlock = chunk_->getDataBlock();
6410 unsigned int blockSize = chunk_->getSizeBlock()->toSize();
6411 StreamHandle handle(dataBlock->data(), blockSize);
6412 Block placeHolder;
6413
6414 handle_ = &handle;
6415
6416 // version
6417 if (!readBuffer(placeHolder, 1)) { return false; }
6418 bool version4 = placeHolder.toUnsignedInt() == 4;
6419 ove_->setIsVersion4(version4);
6420
6421 QString str = QString("This file is created by Overture ") + (version4 ? "4" : "3");
6422 messageOut(str);
6423
6424 if( !jump(6) ) { return false; }
6425
6426 // show page margin
6427 if (!readBuffer(placeHolder, 1)) { return false; }
6428 ove_->setShowPageMargin(placeHolder.toBoolean());
6429
6430 if( !jump(1) ) { return false; }
6431
6432 // transpose track
6433 if (!readBuffer(placeHolder, 1)) { return false; }
6434 ove_->setShowTransposeTrack(placeHolder.toBoolean());
6435
6436 // play repeat
6437 if (!readBuffer(placeHolder, 1)) { return false; }
6438 ove_->setPlayRepeat(placeHolder.toBoolean());
6439
6440 // play style
6441 if (!readBuffer(placeHolder, 1)) { return false; }
6442 OveSong::PlayStyle style = OveSong::Record;
6443 if(placeHolder.toUnsignedInt() == 1){
6444 style = OveSong::Swing;
6445 }
6446 else if(placeHolder.toUnsignedInt() == 2){
6447 style = OveSong::Notation;
6448 }
6449 ove_->setPlayStyle(style);
6450
6451 // show line break
6452 if (!readBuffer(placeHolder, 1)) { return false; }
6453 ove_->setShowLineBreak(placeHolder.toBoolean());
6454
6455 // show ruler
6456 if (!readBuffer(placeHolder, 1)) { return false; }
6457 ove_->setShowRuler(placeHolder.toBoolean());
6458
6459 // show color
6460 if (!readBuffer(placeHolder, 1)) { return false; }
6461 ove_->setShowColor(placeHolder.toBoolean());
6462
6463 return true;
6464}
6465
6467TrackParse::TrackParse(OveSong* ove)
6468:BasicParse(ove) {
6469}
6470
6471TrackParse::~TrackParse() {
6472}
6473
6474void TrackParse::setTrack(SizeChunk* chunk) {
6475 chunk_ = chunk;
6476}
6477
6478bool TrackParse::parse()
6479{
6480 Block* dataBlock = chunk_->getDataBlock();
6481 unsigned int blockSize = ove_->getIsVersion4() ? chunk_->getSizeBlock()->toSize() : SizeChunk::version3TrackSize;
6482 StreamHandle handle(dataBlock->data(), blockSize);
6483 Block placeHolder;
6484
6485 handle_ = &handle;
6486
6487 Track* oveTrack = new Track();
6488 ove_->addTrack(oveTrack);
6489
6490 // 2 32bytes long track name buffer
6491 if( !readBuffer(placeHolder, 32) ) { return false; }
6492 oveTrack->setName(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
6493
6494 if( !readBuffer(placeHolder, 32) ) { return false; }
6495 oveTrack->setBriefName(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
6496
6497 if( !jump(8) ) { return false; } //0x fffa0012 fffa0012
6498 if( !jump(1) ) { return false; }
6499
6500 // patch
6501 if( !readBuffer(placeHolder, 1) ) { return false; }
6502 unsigned int thisByte = placeHolder.toInt();
6503 oveTrack->setPatch(thisByte&0x7f);
6504
6505 // show name
6506 if( !readBuffer(placeHolder, 1) ) { return false; }
6507 oveTrack->setShowName(placeHolder.toBoolean());
6508
6509 // show brief name
6510 if( !readBuffer(placeHolder, 1) ) { return false; }
6511 oveTrack->setShowBriefName(placeHolder.toBoolean());
6512
6513 if( !jump(1) ) { return false; }
6514
6515 // show transpose
6516 if( !readBuffer(placeHolder, 1) ) { return false; }
6517 oveTrack->setShowTranspose(placeHolder.toBoolean());
6518
6519 if( !jump(1) ) { return false; }
6520
6521 // mute
6522 if( !readBuffer(placeHolder, 1) ) { return false; }
6523 oveTrack->setMute(placeHolder.toBoolean());
6524
6525 // solo
6526 if( !readBuffer(placeHolder, 1) ) { return false; }
6527 oveTrack->setSolo(placeHolder.toBoolean());
6528
6529 if( !jump(1) ) { return false; }
6530
6531 // show key each line
6532 if( !readBuffer(placeHolder, 1) ) { return false; }
6533 oveTrack->setShowKeyEachLine(placeHolder.toBoolean());
6534
6535 // voice count
6536 if( !readBuffer(placeHolder, 1) ) { return false; }
6537 oveTrack->setVoiceCount(placeHolder.toUnsignedInt());
6538
6539 if( !jump(3) ) { return false; }
6540
6541 // transpose value [-127, 127]
6542 if( !readBuffer(placeHolder, 1) ) { return false; }
6543 oveTrack->setTranspose(placeHolder.toInt());
6544
6545 if( !jump(2) ) { return false; }
6546
6547 // start clef
6548 if( !readBuffer(placeHolder, 1) ) { return false; }
6549 oveTrack->setStartClef(placeHolder.toUnsignedInt());
6550
6551 // transpose celf
6552 if( !readBuffer(placeHolder, 1) ) { return false; }
6553 oveTrack->setTransposeClef(placeHolder.toUnsignedInt());
6554
6555 // start key
6556 if( !readBuffer(placeHolder, 1) ) { return false; }
6557 oveTrack->setStartKey(placeHolder.toUnsignedInt());
6558
6559 // display percent
6560 if( !readBuffer(placeHolder, 1) ) { return false; }
6561 oveTrack->setDisplayPercent(placeHolder.toUnsignedInt());
6562
6563 // show leger line
6564 if( !readBuffer(placeHolder, 1) ) { return false; }
6565 oveTrack->setShowLegerLine(placeHolder.toBoolean());
6566
6567 // show clef
6568 if( !readBuffer(placeHolder, 1) ) { return false; }
6569 oveTrack->setShowClef(placeHolder.toBoolean());
6570
6571 // show time signature
6572 if( !readBuffer(placeHolder, 1) ) { return false; }
6573 oveTrack->setShowTimeSignature(placeHolder.toBoolean());
6574
6575 // show key signature
6576 if( !readBuffer(placeHolder, 1) ) { return false; }
6577 oveTrack->setShowKeySignature(placeHolder.toBoolean());
6578
6579 // show barline
6580 if( !readBuffer(placeHolder, 1) ) { return false; }
6581 oveTrack->setShowBarline(placeHolder.toBoolean());
6582
6583 // fill with rest
6584 if( !readBuffer(placeHolder, 1) ) { return false; }
6585 oveTrack->setFillWithRest(placeHolder.toBoolean());
6586
6587 // flat tail
6588 if( !readBuffer(placeHolder, 1) ) { return false; }
6589 oveTrack->setFlatTail(placeHolder.toBoolean());
6590
6591 // show clef each line
6592 if( !readBuffer(placeHolder, 1) ) { return false; }
6593 oveTrack->setShowClefEachLine(placeHolder.toBoolean());
6594
6595 if( !jump(12) ) { return false; }
6596
6597 // 8 voices
6598 int i;
6599 QList<Voice*> voices;
6600 for( i=0; i<8; ++i ) {
6601 Voice* voicePtr = new Voice();
6602
6603 if( !jump(5) ) { return false; }
6604
6605 // channel
6606 if( !readBuffer(placeHolder, 1) ) { return false; }
6607 voicePtr->setChannel(placeHolder.toUnsignedInt());
6608
6609 // volume
6610 if( !readBuffer(placeHolder, 1) ) { return false; }
6611 voicePtr->setVolume(placeHolder.toInt());
6612
6613 // pitch shift
6614 if( !readBuffer(placeHolder, 1) ) { return false; }
6615 voicePtr->setPitchShift(placeHolder.toInt());
6616
6617 // pan
6618 if( !readBuffer(placeHolder, 1) ) { return false; }
6619 voicePtr->setPan(placeHolder.toInt());
6620
6621 if( !jump(6) ) { return false; }
6622
6623 // patch
6624 if( !readBuffer(placeHolder, 1) ) { return false; }
6625 voicePtr->setPatch(placeHolder.toInt());
6626
6627 voices.push_back(voicePtr);
6628 }
6629
6630 // stem type
6631 for( i=0; i<8; ++i ) {
6632 if( !readBuffer(placeHolder, 1) ) { return false; }
6633 voices[i]->setStemType(placeHolder.toUnsignedInt());
6634
6635 oveTrack->addVoice(voices[i]);
6636 }
6637
6638 // percussion define
6639 QList<Track::DrumNode> nodes;
6640 for(i=0; i<16; ++i) {
6641 nodes.push_back(Track::DrumNode());
6642 }
6643
6644 // line
6645 for( i=0; i<16; ++i ) {
6646 if( !readBuffer(placeHolder, 1) ) { return false; }
6647 nodes[i].line_ = placeHolder.toInt();
6648 }
6649
6650 // head type
6651 for( i=0; i<16; ++i ) {
6652 if( !readBuffer(placeHolder, 1) ) { return false; }
6653 nodes[i].headType_ = placeHolder.toUnsignedInt();
6654 }
6655
6656 // pitch
6657 for( i=0; i<16; ++i ) {
6658 if( !readBuffer(placeHolder, 1) ) { return false; }
6659 nodes[i].pitch_ = placeHolder.toUnsignedInt();
6660 }
6661
6662 // voice
6663 for( i=0; i<16; ++i ) {
6664 if( !readBuffer(placeHolder, 1) ) { return false; }
6665 nodes[i].voice_ = placeHolder.toUnsignedInt();
6666 }
6667
6668 for( i=0; i<nodes.size(); ++i ) {
6669 oveTrack->addDrum(nodes[i]);
6670 }
6671
6672/* if( !Jump(17) ) { return false; }
6673
6674 // voice 0 channel
6675 if( !ReadBuffer(placeHolder, 1) ) { return false; }
6676 oveTrack->setChannel(placeHolder.toUnsignedInt());
6677
6678 // to be continued. if anything important...*/
6679
6680 return true;
6681}
6682
6684GroupParse::GroupParse(OveSong* ove)
6685:BasicParse(ove) {
6686}
6687
6688GroupParse::~GroupParse(){
6689 sizeChunks_.clear();
6690}
6691
6692void GroupParse::addSizeChunk(SizeChunk* sizeChunk) {
6693 sizeChunks_.push_back(sizeChunk);
6694}
6695
6696bool GroupParse::parse() {
6697 return false;
6698}
6699
6701PageGroupParse::PageGroupParse(OveSong* ove)
6702:BasicParse(ove) {
6703}
6704
6705PageGroupParse::~PageGroupParse(){
6706 pageChunks_.clear();
6707}
6708
6709void PageGroupParse::addPage(SizeChunk* chunk) {
6710 pageChunks_.push_back(chunk);
6711}
6712
6713bool PageGroupParse::parse()
6714{
6715 if( pageChunks_.empty() ) {
6716 return false;
6717 }
6718
6719 int i;
6720 for( i=0; i<pageChunks_.size(); ++i ) {
6721 Page* page = new Page();
6722 ove_->addPage(page);
6723
6724 if( !parsePage(pageChunks_[i], page) ) { return false; }
6725 }
6726
6727 return true;
6728}
6729
6730bool PageGroupParse::parsePage(SizeChunk* chunk, Page* page) {
6731 Block placeHolder(2);
6732 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
6733
6734 handle_ = &handle;
6735
6736 // begin line
6737 if( !readBuffer(placeHolder, 2) ) { return false; }
6738 page->setBeginLine(placeHolder.toUnsignedInt());
6739
6740 // line count
6741 if( !readBuffer(placeHolder, 2) ) { return false; }
6742 page->setLineCount(placeHolder.toUnsignedInt());
6743
6744 if( !jump(4) ) { return false; }
6745
6746 // staff interval
6747 if( !readBuffer(placeHolder, 2) ) { return false; }
6748 page->setStaffInterval(placeHolder.toUnsignedInt());
6749
6750 // line interval
6751 if( !readBuffer(placeHolder, 2) ) { return false; }
6752 page->setLineInterval(placeHolder.toUnsignedInt());
6753
6754 // staff inline interval
6755 if( !readBuffer(placeHolder, 2) ) { return false; }
6756 page->setStaffInlineInterval(placeHolder.toUnsignedInt());
6757
6758 // line bar count
6759 if( !readBuffer(placeHolder, 2) ) { return false; }
6760 page->setLineBarCount(placeHolder.toUnsignedInt());
6761
6762 // page line count
6763 if( !readBuffer(placeHolder, 2) ) { return false; }
6764 page->setPageLineCount(placeHolder.toUnsignedInt());
6765
6766 // left margin
6767 if( !readBuffer(placeHolder, 4) ) { return false; }
6768 page->setLeftMargin(placeHolder.toUnsignedInt());
6769
6770 // top margin
6771 if( !readBuffer(placeHolder, 4) ) { return false; }
6772 page->setTopMargin(placeHolder.toUnsignedInt());
6773
6774 // right margin
6775 if( !readBuffer(placeHolder, 4) ) { return false; }
6776 page->setRightMargin(placeHolder.toUnsignedInt());
6777
6778 // bottom margin
6779 if( !readBuffer(placeHolder, 4) ) { return false; }
6780 page->setBottomMargin(placeHolder.toUnsignedInt());
6781
6782 // page width
6783 if( !readBuffer(placeHolder, 4) ) { return false; }
6784 page->setPageWidth(placeHolder.toUnsignedInt());
6785
6786 // page height
6787 if( !readBuffer(placeHolder, 4) ) { return false; }
6788 page->setPageHeight(placeHolder.toUnsignedInt());
6789
6790 handle_ = NULL;
6791
6792 return true;
6793}
6794
6796StaffCountGetter::StaffCountGetter(OveSong* ove)
6797:BasicParse(ove) {
6798}
6799
6800unsigned int StaffCountGetter::getStaffCount(SizeChunk* chunk) {
6801 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
6802 Block placeHolder;
6803
6804 handle_ = &handle;
6805
6806 if( !jump(6) ) { return false; }
6807
6808 // staff count
6809 if( !readBuffer(placeHolder, 2) ) { return false; }
6810 return placeHolder.toUnsignedInt();
6811}
6812
6814LineGroupParse::LineGroupParse(OveSong* ove) :
6815 BasicParse(ove), chunk_(NULL) {
6816}
6817
6818LineGroupParse::~LineGroupParse(){
6819 chunk_ = NULL;
6820 lineChunks_.clear();
6821 staffChunks_.clear();
6822}
6823
6824void LineGroupParse::setLineGroup(GroupChunk* chunk) {
6825 chunk_ = chunk;
6826}
6827
6828void LineGroupParse::addLine(SizeChunk* chunk) {
6829 lineChunks_.push_back(chunk);
6830}
6831
6832void LineGroupParse::addStaff(SizeChunk* chunk) {
6833 staffChunks_.push_back(chunk);
6834}
6835
6836bool LineGroupParse::parse()
6837{
6838 if( lineChunks_.empty() || staffChunks_.size() % lineChunks_.size() != 0 ) { return false; }
6839
6840 int i;
6841 unsigned int j;
6842 unsigned int lineStaffCount = staffChunks_.size() / lineChunks_.size();
6843
6844 for( i=0; i<lineChunks_.size(); ++i ) {
6845 Line* linePtr = new Line();
6846
6847 ove_->addLine(linePtr);
6848
6849 if( !parseLine(lineChunks_[i], linePtr) ) { return false; }
6850
6851 for( j=lineStaffCount*i; j<lineStaffCount*(i+1); ++j ) {
6852 Staff* staffPtr = new Staff();
6853
6854 linePtr->addStaff(staffPtr);
6855
6856 if( !parseStaff(staffChunks_[j], staffPtr) ) { return false; }
6857 }
6858 }
6859
6860 return true;
6861}
6862
6863bool LineGroupParse::parseLine(SizeChunk* chunk, Line* line) {
6864 Block placeHolder;
6865
6866 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
6867
6868 handle_ = &handle;
6869
6870 if( !jump(2) ) { return false; }
6871
6872 // begin bar
6873 if( !readBuffer(placeHolder, 2) ) { return false; }
6874 line->setBeginBar(placeHolder.toUnsignedInt());
6875
6876 // bar count
6877 if( !readBuffer(placeHolder, 2) ) { return false; }
6878 line->setBarCount(placeHolder.toUnsignedInt());
6879
6880 if( !jump(6) ) { return false; }
6881
6882 // y offset
6883 if( !readBuffer(placeHolder, 2) ) { return false; }
6884 line->setYOffset(placeHolder.toInt());
6885
6886 // left x offset
6887 if( !readBuffer(placeHolder, 2) ) { return false; }
6888 line->setLeftXOffset(placeHolder.toInt());
6889
6890 // right x offset
6891 if( !readBuffer(placeHolder, 2) ) { return false; }
6892 line->setRightXOffset(placeHolder.toInt());
6893
6894 if( !jump(4) ) { return false; }
6895
6896 handle_ = NULL;
6897
6898 return true;
6899}
6900
6901bool LineGroupParse::parseStaff(SizeChunk* chunk, Staff* staff) {
6902 Block placeHolder;
6903
6904 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
6905
6906 handle_ = &handle;
6907
6908 if( !jump(7) ) { return false; }
6909
6910 // clef
6911 if( !readBuffer(placeHolder, 1) ) { return false; }
6912 staff->setClefType(placeHolder.toUnsignedInt());
6913
6914 // key
6915 if( !readBuffer(placeHolder, 1) ) { return false; }
6916 staff->setKeyType(oveKeyToKey(placeHolder.toUnsignedInt()));
6917
6918 if( !jump(2) ) { return false; }
6919
6920 // visible
6921 if( !readBuffer(placeHolder, 1) ) { return false; }
6922 staff->setVisible(placeHolder.toBoolean());
6923
6924 if( !jump(12) ) { return false; }
6925
6926 // y offset
6927 if( !readBuffer(placeHolder, 2) ) { return false; }
6928 staff->setYOffset(placeHolder.toInt());
6929
6930 int jumpAmount = ove_->getIsVersion4() ? 26 : 18;
6931 if( !jump(jumpAmount) ) { return false; }
6932
6933 // group type
6934 if( !readBuffer(placeHolder, 1) ) { return false; }
6935 GroupType groupType = Group_None;
6936 if(placeHolder.toUnsignedInt() == 1) {
6937 groupType = Group_Brace;
6938 } else if(placeHolder.toUnsignedInt() == 2) {
6939 groupType = Group_Bracket;
6940 }
6941 staff->setGroupType(groupType);
6942
6943 // group staff count
6944 if( !readBuffer(placeHolder, 1) ) { return false; }
6945 staff->setGroupStaffCount(placeHolder.toUnsignedInt());
6946
6947 handle_ = NULL;
6948
6949 return true;
6950}
6951
6953BarsParse::BarsParse(OveSong* ove) :
6954 BasicParse(ove) {
6955}
6956
6957BarsParse::~BarsParse(){
6958 measureChunks_.clear();
6959 conductChunks_.clear();
6960 bdatChunks_.clear();
6961}
6962
6963void BarsParse::addMeasure(SizeChunk* chunk) {
6964 measureChunks_.push_back(chunk);
6965}
6966
6967void BarsParse::addConduct(SizeChunk* chunk) {
6968 conductChunks_.push_back(chunk);
6969}
6970
6971void BarsParse::addBdat(SizeChunk* chunk) {
6972 bdatChunks_.push_back(chunk);
6973}
6974
6975bool BarsParse::parse() {
6976 int i;
6977 int trackMeasureCount = ove_->getTrackBarCount();
6978 int trackCount = ove_->getTrackCount();
6979 int measureDataCount = trackCount * measureChunks_.size();
6980 QList<Measure*> measures;
6981 QList<MeasureData*> measureDatas;
6982
6983 if( measureChunks_.empty() ||
6984 measureChunks_.size() != conductChunks_.size() ||
6985 (int)bdatChunks_.size() != measureDataCount ) {
6986 return false;
6987 }
6988
6989 // add to ove
6990 for ( i=0; i<(int)measureChunks_.size(); ++i ) {
6991 Measure* measure = new Measure(i);
6992
6993 measures.push_back(measure);
6994 ove_->addMeasure(measure);
6995 }
6996
6997 for ( i=0; i<measureDataCount; ++i ) {
6998 MeasureData* oveMeasureData = new MeasureData();
6999
7000 measureDatas.push_back(oveMeasureData);
7001 ove_->addMeasureData(oveMeasureData);
7002 }
7003
7004 for( i=0; i<(int)measureChunks_.size(); ++i ) {
7005 Measure* measure = measures[i];
7006
7007 // MEAS
7008 if( !parseMeas(measure, measureChunks_[i]) ) {
7009 QString ss = "failed in parse MEAS " + i;
7010 messageOut(ss);
7011
7012 return false;
7013 }
7014 }
7015
7016 for( i=0; i<(int)conductChunks_.size(); ++i ) {
7017 // COND
7018 if( !parseCond(measures[i], measureDatas[i], conductChunks_[i]) ) {
7019 QString ss = "failed in parse COND " + i;
7020 messageOut(ss);
7021
7022 return false;
7023 }
7024 }
7025
7026 for( i=0; i<(int)bdatChunks_.size(); ++i ) {
7027 int measId = i % trackMeasureCount;
7028
7029 // BDAT
7030 if( !parseBdat(measures[measId], measureDatas[i], bdatChunks_[i]) ) {
7031 QString ss = "failed in parse BDAT " + i;
7032 messageOut(ss);
7033
7034 return false;
7035 }
7036
7037 if( notify_ != NULL ) {
7038 int measureID = i % trackMeasureCount;
7039 int trackID = i / trackMeasureCount;
7040
7041 //msg.msg_ = OVE_IMPORT_POS;
7042 //msg.param1_ = (measureID<<16) + trackMeasureCount;
7043 //msg.param2_ = (trackID<<16) + trackCount;
7044
7045 notify_->loadPosition(measureID, trackMeasureCount, trackID, trackCount);
7046 }
7047 }
7048
7049 return true;
7050}
7051
7052bool BarsParse::parseMeas(Measure* measure, SizeChunk* chunk) {
7053 Block placeHolder;
7054
7055 StreamHandle measureHandle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
7056
7057 handle_ = &measureHandle;
7058
7059 if( !jump(2) ) { return false; }
7060
7061 // multi-measure rest
7062 if( !readBuffer(placeHolder, 1) ) { return false; }
7063 measure->setIsMultiMeasureRest(placeHolder.toBoolean());
7064
7065 // pickup
7066 if( !readBuffer(placeHolder, 1) ) { return false; }
7067 measure->setIsPickup(placeHolder.toBoolean());
7068
7069 if( !jump(4) ) { return false; }
7070
7071 // left barline
7072 if( !readBuffer(placeHolder, 1) ) { return false; }
7073 measure->setLeftBarline(placeHolder.toUnsignedInt());
7074
7075 // right barline
7076 if( !readBuffer(placeHolder, 1) ) { return false; }
7077 measure->setRightBarline(placeHolder.toUnsignedInt());
7078
7079 // tempo
7080 if( !readBuffer(placeHolder, 2) ) { return false; }
7081 double tempo = ((double)placeHolder.toUnsignedInt());
7082 if( ove_->getIsVersion4() ) {
7083 tempo /= 100.0;
7084 }
7085 measure->setTypeTempo(tempo);
7086
7087 // bar length(tick)
7088 if( !readBuffer(placeHolder, 2) ) { return false; }
7089 measure->setLength(placeHolder.toUnsignedInt());
7090
7091 if( !jump(6) ) { return false; }
7092
7093 // bar number offset
7094 if( !parseOffsetElement(measure->getBarNumber()) ) { return false; }
7095
7096 if( !jump(2) ) { return false; }
7097
7098 // multi-measure rest count
7099 if( !readBuffer(placeHolder, 2) ) { return false; }
7100 measure->setMultiMeasureRestCount(placeHolder.toUnsignedInt());
7101
7102 handle_ = NULL;
7103
7104 return true;
7105}
7106
7107bool BarsParse::parseCond(Measure* measure, MeasureData* measureData, SizeChunk* chunk) {
7108 Block placeHolder;
7109
7110 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
7111
7112 handle_ = &handle;
7113
7114 // item count
7115 if( !readBuffer(placeHolder, 2) ) { return false; }
7116 unsigned int cnt = placeHolder.toUnsignedInt();
7117
7118 if( !parseTimeSignature(measure, 36) ) { return false; }
7119
7120 for( unsigned int i=0; i<cnt; ++i ) {
7121 if( !readBuffer(placeHolder, 2) ) { return false; }
7122 unsigned int twoByte = placeHolder.toUnsignedInt();
7123 unsigned int oldBlockSize = twoByte - 11;
7124 unsigned int newBlockSize = twoByte - 7;
7125
7126 // type id
7127 if( !readBuffer(placeHolder, 1) ) { return false; }
7128 unsigned int thisByte = placeHolder.toUnsignedInt();
7129 CondType type;
7130
7131 if( !getCondElementType(thisByte, type) ) { return false; }
7132
7133 switch (type) {
7134 case Cond_Bar_Number: {
7135 if (!parseBarNumber(measure, twoByte - 1)) {
7136 return false;
7137 }
7138 break;
7139 }
7140 case Cond_Repeat: {
7141 if (!parseRepeatSymbol(measureData, oldBlockSize)) {
7142 return false;
7143 }
7144 break;
7145 }
7146 case Cond_Numeric_Ending: {
7147 if (!parseNumericEndings(measureData, oldBlockSize)) {
7148 return false;
7149 }
7150 break;
7151 }
7152 case Cond_Decorator: {
7153 if (!parseDecorators(measureData, newBlockSize)) {
7154 return false;
7155 }
7156 break;
7157 }
7158 case Cond_Tempo: {
7159 if (!parseTempo(measureData, newBlockSize)) {
7160 return false;
7161 }
7162 break;
7163 }
7164 case Cond_Text: {
7165 if (!parseText(measureData, newBlockSize)) {
7166 return false;
7167 }
7168 break;
7169 }
7170 case Cond_Expression: {
7171 if (!parseExpressions(measureData, newBlockSize)) {
7172 return false;
7173 }
7174 break;
7175 }
7176 case Cond_Time_Parameters: {
7177 if (!parseTimeSignatureParameters(measure, newBlockSize)) {
7178 return false;
7179 }
7180 break;
7181 }
7182 case Cond_Barline_Parameters: {
7183 if (!parseBarlineParameters(measure, newBlockSize)) {
7184 return false;
7185 }
7186 break;
7187 }
7188 default: {
7189 if (!jump(newBlockSize)) {
7190 return false;
7191 }
7192 break;
7193 }
7194 }
7195 }
7196
7197 handle_ = NULL;
7198
7199 return true;
7200}
7201
7202bool BarsParse::parseTimeSignature(Measure* measure, int /*length*/) {
7203 Block placeHolder;
7204
7205 TimeSignature* timeSignature = measure->getTime();
7206
7207 // numerator
7208 if( !readBuffer(placeHolder, 1) ) { return false; }
7209 timeSignature->setNumerator(placeHolder.toUnsignedInt());
7210
7211 // denominator
7212 if( !readBuffer(placeHolder, 1) ) { return false; }
7213 timeSignature->setDenominator(placeHolder.toUnsignedInt());
7214
7215 if( !jump(2) ) { return false; }
7216
7217 // beat length
7218 if( !readBuffer(placeHolder, 2) ) { return false; }
7219 timeSignature->setBeatLength(placeHolder.toUnsignedInt());
7220
7221 // bar length
7222 if( !readBuffer(placeHolder, 2) ) { return false; }
7223 timeSignature->setBarLength(placeHolder.toUnsignedInt());
7224
7225 if( !jump(4) ) { return false; }
7226
7227 // is symbol
7228 if( !readBuffer(placeHolder, 1) ) { return false; }
7229 timeSignature->setIsSymbol(placeHolder.toBoolean());
7230
7231 if( !jump(1) ) { return false; }
7232
7233 // replace font
7234 if( !readBuffer(placeHolder, 1) ) { return false; }
7235 timeSignature->setReplaceFont(placeHolder.toBoolean());
7236
7237 // color
7238 if( !readBuffer(placeHolder, 1) ) { return false; }
7239 timeSignature->setColor(placeHolder.toUnsignedInt());
7240
7241 // show
7242 if( !readBuffer(placeHolder, 1) ) { return false; }
7243 timeSignature->setShow(placeHolder.toBoolean());
7244
7245 // show beat group
7246 if( !readBuffer(placeHolder, 1) ) { return false; }
7247 timeSignature->setShowBeatGroup(placeHolder.toBoolean());
7248
7249 if( !jump(6) ) { return false; }
7250
7251 // numerator 1, 2, 3
7252 if( !readBuffer(placeHolder, 1) ) { return false; }
7253 timeSignature->setGroupNumerator1(placeHolder.toUnsignedInt());
7254 if( !readBuffer(placeHolder, 1) ) { return false; }
7255 timeSignature->setGroupNumerator2(placeHolder.toUnsignedInt());
7256 if( !readBuffer(placeHolder, 1) ) { return false; }
7257 timeSignature->setGroupNumerator3(placeHolder.toUnsignedInt());
7258
7259 // denominator
7260 if( !readBuffer(placeHolder, 1) ) { return false; }
7261 timeSignature->setGroupDenominator1(placeHolder.toUnsignedInt());
7262 if( !readBuffer(placeHolder, 1) ) { return false; }
7263 timeSignature->setGroupDenominator2(placeHolder.toUnsignedInt());
7264 if( !readBuffer(placeHolder, 1) ) { return false; }
7265 timeSignature->setGroupDenominator3(placeHolder.toUnsignedInt());
7266
7267 // beam group 1~4
7268 if( !readBuffer(placeHolder, 1) ) { return false; }
7269 timeSignature->setBeamGroup1(placeHolder.toUnsignedInt());
7270 if( !readBuffer(placeHolder, 1) ) { return false; }
7271 timeSignature->setBeamGroup2(placeHolder.toUnsignedInt());
7272 if( !readBuffer(placeHolder, 1) ) { return false; }
7273 timeSignature->setBeamGroup3(placeHolder.toUnsignedInt());
7274 if( !readBuffer(placeHolder, 1) ) { return false; }
7275 timeSignature->setBeamGroup4(placeHolder.toUnsignedInt());
7276
7277 // beam 16th
7278 if( !readBuffer(placeHolder, 1) ) { return false; }
7279 timeSignature->set16thBeamCount(placeHolder.toUnsignedInt());
7280
7281 // beam 32th
7282 if( !readBuffer(placeHolder, 1) ) { return false; }
7283 timeSignature->set32thBeamCount(placeHolder.toUnsignedInt());
7284
7285 return true;
7286}
7287
7288bool BarsParse::parseTimeSignatureParameters(Measure* measure, int length) {
7289 Block placeHolder;
7290 TimeSignature* ts = measure->getTime();
7291
7292 int cursor = ove_->getIsVersion4() ? 10 : 8;
7293 if( !jump(cursor) ) { return false; }
7294
7295 // numerator
7296 if( !readBuffer(placeHolder, 1) ) { return false; }
7297 unsigned int numerator = placeHolder.toUnsignedInt();
7298
7299 cursor = ove_->getIsVersion4() ? 11 : 9;
7300 if( ( length - cursor ) % 8 != 0 || (length - cursor) / 8 != (int)numerator ) {
7301 return false;
7302 }
7303
7304 for( unsigned int i =0; i<numerator; ++i ) {
7305 // beat start unit
7306 if( !readBuffer(placeHolder, 2) ) { return false; }
7307 int beatStart = placeHolder.toUnsignedInt();
7308
7309 // beat length unit
7310 if( !readBuffer(placeHolder, 2) ) { return false; }
7311 int beatLength = placeHolder.toUnsignedInt();
7312
7313 if( !jump(2) ) { return false; }
7314
7315 // beat start tick
7316 if( !readBuffer(placeHolder, 2) ) { return false; }
7317 int beatStartTick = placeHolder.toUnsignedInt();
7318
7319 ts->addBeat(beatStart, beatLength, beatStartTick);
7320 }
7321
7322 ts->endAddBeat();
7323
7324 return true;
7325}
7326
7327bool BarsParse::parseBarlineParameters(Measure* measure, int /*length*/) {
7328 Block placeHolder;
7329
7330 int cursor = ove_->getIsVersion4() ? 12 : 10;
7331 if( !jump(cursor) ) { return false; }
7332
7333 // repeat count
7334 if( !readBuffer(placeHolder, 1) ) { return false; }
7335 int repeatCount = placeHolder.toUnsignedInt();
7336
7337 measure->setBackwardRepeatCount(repeatCount);
7338
7339 if( !jump(6) ) { return false; }
7340
7341 return true;
7342}
7343
7344bool BarsParse::parseNumericEndings(MeasureData* measureData, int /*length*/) {
7345 Block placeHolder;
7346
7347 NumericEnding* numeric = new NumericEnding();
7348 measureData->addCrossMeasureElement(numeric, true);
7349
7350 if( !jump(3) ) { return false; }
7351
7352 // common
7353 if( !parseCommonBlock(numeric) ) { return false; }
7354
7355 if( !jump(6) ) { return false; }
7356
7357 // measure count
7358 if( !readBuffer(placeHolder, 2) ) { return false; }
7359 //int offsetMeasure = placeHolder.toUnsignedInt() - 1;
7360 int offsetMeasure = placeHolder.toUnsignedInt();
7361 numeric->stop()->setMeasure(offsetMeasure);
7362
7363 if( !jump(2) ) { return false; }
7364
7365 // left x offset
7366 if( !readBuffer(placeHolder, 2) ) { return false; }
7367 numeric->getLeftShoulder()->setXOffset(placeHolder.toInt());
7368
7369 // height
7370 if( !readBuffer(placeHolder, 2) ) { return false; }
7371 numeric->setHeight(placeHolder.toUnsignedInt());
7372
7373 // left x offset
7374 if( !readBuffer(placeHolder, 2) ) { return false; }
7375 numeric->getRightShoulder()->setXOffset(placeHolder.toInt());
7376
7377 if( !jump(2) ) { return false; }
7378
7379 // y offset
7380 if( !readBuffer(placeHolder, 2) ) { return false; }
7381 numeric->getLeftShoulder()->setYOffset(placeHolder.toInt());
7382 numeric->getRightShoulder()->setYOffset(placeHolder.toInt());
7383
7384 // number offset
7385 if( !readBuffer(placeHolder, 2) ) { return false; }
7386 numeric->getNumericHandle()->setXOffset(placeHolder.toInt());
7387 if( !readBuffer(placeHolder, 2) ) { return false; }
7388 numeric->getNumericHandle()->setYOffset(placeHolder.toInt());
7389
7390 if( !jump(6) ) { return false; }
7391
7392 // text size
7393 if( !readBuffer(placeHolder, 1) ) { return false; }
7394 unsigned int size = placeHolder.toUnsignedInt();
7395
7396 // text : size maybe a huge value
7397 if( !readBuffer(placeHolder, size) ) { return false; }
7398 numeric->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
7399
7400 // fix for wedding march.ove
7401 if( size % 2 == 0 ) {
7402 if( !jump(1) ) { return false; }
7403 }
7404
7405 return true;
7406}
7407
7408bool BarsParse::parseTempo(MeasureData* measureData, int /*length*/) {
7409 Block placeHolder;
7410 unsigned int thisByte;
7411
7412 Tempo* tempo = new Tempo();
7413 measureData->addMusicData(tempo);
7414
7415 if( !jump(3) ) { return false; }
7416
7417 // common
7418 if( !parseCommonBlock(tempo) ) { return false; }
7419
7420 if( !readBuffer(placeHolder, 1) ) { return false; }
7421 thisByte = placeHolder.toUnsignedInt();
7422
7423 // show tempo
7424 tempo->setShowMark( (getHighNibble(thisByte) & 0x4) == 0x4 );
7425 // show before text
7426 tempo->setShowBeforeText( (getHighNibble(thisByte) & 0x8 ) == 0x8 ) ;
7427 // show parenthesis
7428 tempo->setShowParenthesis( (getHighNibble(thisByte) & 0x1 ) == 0x1 );
7429 // left note type
7430 tempo->setLeftNoteType( getLowNibble(thisByte) );
7431
7432 if( !jump(1) ) { return false; }
7433
7434 if( ove_->getIsVersion4() ) {
7435 if( !jump(2) ) { return false; }
7436
7437 // tempo
7438 if( !readBuffer(placeHolder, 2) ) { return false; }
7439 tempo->setTypeTempo(placeHolder.toUnsignedInt()/100);
7440 } else {
7441 // tempo
7442 if( !readBuffer(placeHolder, 2) ) { return false; }
7443 tempo->setTypeTempo(placeHolder.toUnsignedInt());
7444
7445 if( !jump(2) ) { return false; }
7446 }
7447
7448 // offset
7449 if( !parseOffsetElement(tempo) ) { return false; }
7450
7451 if( !jump(16) ) { return false; }
7452
7453 // 31 bytes left text
7454 if( !readBuffer(placeHolder, 31) ) { return false; }
7455 tempo->setLeftText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
7456
7457 if( !readBuffer(placeHolder, 1) ) { return false; }
7458 thisByte = placeHolder.toUnsignedInt();
7459
7460 // swing eighth
7461 tempo->setSwingEighth(getHighNibble(thisByte)!=8);
7462
7463 // right note type
7464 tempo->setRightNoteType(getLowNibble(thisByte));
7465
7466 // right text
7467 if( ove_->getIsVersion4() ) {
7468 if( !readBuffer(placeHolder, 31) ) { return false; }
7469 tempo->setRightText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
7470
7471 if( !jump(1) ) { return false; }
7472 }
7473
7474 return true;
7475}
7476
7477bool BarsParse::parseBarNumber(Measure* measure, int /*length*/) {
7478 Block placeHolder;
7479
7480 BarNumber* barNumber = measure->getBarNumber();
7481
7482 if( !jump(2) ) { return false; }
7483
7484 // show on paragraph start
7485 if( !readBuffer(placeHolder, 1) ) { return false; }
7486 barNumber->setShowOnParagraphStart(getLowNibble(placeHolder.toUnsignedInt())==8);
7487
7488 unsigned int blankSize = ove_->getIsVersion4() ? 9 : 7;
7489 if( !jump(blankSize) ) { return false; }
7490
7491 // text align
7492 if( !readBuffer(placeHolder, 1) ) { return false; }
7493 barNumber->setAlign(placeHolder.toUnsignedInt());
7494
7495 if( !jump(4) ) { return false; }
7496
7497 // show flag
7498 if( !readBuffer(placeHolder, 1) ) { return false; }
7499 barNumber->setShowFlag(placeHolder.toUnsignedInt());
7500
7501 if( !jump(10) ) { return false; }
7502
7503 // bar range
7504 if( !readBuffer(placeHolder, 1) ) { return false; }
7505 barNumber->setShowEveryBarCount(placeHolder.toUnsignedInt());
7506
7507 // prefix
7508 if( !readBuffer(placeHolder, 2) ) { return false; }
7509 barNumber->setPrefix(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
7510
7511 if( !jump(18) ) { return false; }
7512
7513 return true;
7514}
7515
7516bool BarsParse::parseText(MeasureData* measureData, int length) {
7517 Block placeHolder;
7518
7519 Text* text = new Text();
7520 measureData->addMusicData(text);
7521
7522 if( !jump(3) ) { return false; }
7523
7524 // common
7525 if( !parseCommonBlock(text) ) { return false; }
7526
7527 // type
7528 if( !readBuffer(placeHolder, 1) ) { return false; }
7529 unsigned int thisByte = placeHolder.toUnsignedInt();
7530 bool includeLineBreak = ( (getHighNibble(thisByte)&0x2) != 0x2 );
7531 unsigned int id = getLowNibble(thisByte);
7532 Text::TextType textType = Text::Text_Rehearsal;
7533
7534 if (id == 0) {
7535 textType = Text::Text_MeasureText;
7536 } else if (id == 1) {
7537 textType = Text::Text_SystemText;
7538 } else // id ==2
7539 {
7540 textType = Text::Text_Rehearsal;
7541 }
7542
7543 text->setTextType(textType);
7544
7545 if( !jump(1) ) { return false; }
7546
7547 // x offset
7548 if( !readBuffer(placeHolder, 4) ) { return false; }
7549 text->setXOffset(placeHolder.toInt());
7550
7551 // y offset
7552 if( !readBuffer(placeHolder, 4) ) { return false; }
7553 text->setYOffset(placeHolder.toInt());
7554
7555 // width
7556 if( !readBuffer(placeHolder, 4) ) { return false; }
7557 text->setWidth(placeHolder.toUnsignedInt());
7558
7559 // height
7560 if( !readBuffer(placeHolder, 4) ) { return false; }
7561 text->setHeight(placeHolder.toUnsignedInt());
7562
7563 if( !jump(7) ) { return false; }
7564
7565 // horizontal margin
7566 if( !readBuffer(placeHolder, 1) ) { return false; }
7567 text->setHorizontalMargin(placeHolder.toUnsignedInt());
7568
7569 if( !jump(1) ) { return false; }
7570
7571 // vertical margin
7572 if( !readBuffer(placeHolder, 1) ) { return false; }
7573 text->setVerticalMargin(placeHolder.toUnsignedInt());
7574
7575 if( !jump(1) ) { return false; }
7576
7577 // line thick
7578 if( !readBuffer(placeHolder, 1) ) { return false; }
7579 text->setLineThick(placeHolder.toUnsignedInt());
7580
7581 if( !jump(2) ) { return false; }
7582
7583 // text size
7584 if( !readBuffer(placeHolder, 2) ) { return false; }
7585 unsigned int size = placeHolder.toUnsignedInt();
7586
7587 // text string, maybe huge
7588 if( !readBuffer(placeHolder, size) ) { return false; }
7589 text->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
7590
7591 if( !includeLineBreak ) {
7592 if( !jump(6) ) { return false; }
7593 } else {
7594 unsigned int cursor = ove_->getIsVersion4() ? 43 : 41;
7595 cursor += size;
7596
7597 // multi lines of text
7598 for( unsigned int i=0; i<2; ++i ) {
7599 if( (int)cursor < length ) {
7600 // line parameters count
7601 if( !readBuffer(placeHolder, 2) ) { return false; }
7602 unsigned int lineCount = placeHolder.toUnsignedInt();
7603
7604 if( i==0 && int(cursor + 2 + 8*lineCount) > length ) {
7605 return false;
7606 }
7607
7608 if( i==1 && int(cursor + 2 + 8*lineCount) != length ) {
7609 return false;
7610 }
7611
7612 if( !jump(8*lineCount) ) { return false; }
7613
7614 cursor += 2 + 8*lineCount;
7615 }
7616 }
7617 }
7618
7619 return true;
7620}
7621
7622bool BarsParse::parseRepeatSymbol(MeasureData* measureData, int /*length*/) {
7623 Block placeHolder;
7624
7625 RepeatSymbol* repeat = new RepeatSymbol();
7626 measureData->addMusicData(repeat);
7627
7628 if( !jump(3) ) { return false; }
7629
7630 // common
7631 if( !parseCommonBlock(repeat) ) { return false; }
7632
7633 // RepeatType
7634 if( !readBuffer(placeHolder, 1) ) { return false; }
7635 repeat->setRepeatType(placeHolder.toUnsignedInt());
7636
7637 if( !jump(13) ) { return false; }
7638
7639 // offset
7640 if( !parseOffsetElement(repeat) ) { return false; }
7641
7642 if( !jump(15) ) { return false; }
7643
7644 // size
7645 if( !readBuffer(placeHolder, 2) ) { return false; }
7646 unsigned int size = placeHolder.toUnsignedInt();
7647
7648 // text, maybe huge
7649 if( !readBuffer(placeHolder, size) ) { return false; }
7650 repeat->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
7651
7652 // last 0
7653 if( size % 2 == 0 ) {
7654 if( !jump(1) ) { return false; }
7655 }
7656
7657 return true;
7658}
7659
7660bool BarsParse::parseBdat(Measure* /*measure*/, MeasureData* measureData, SizeChunk* chunk) {
7661 Block placeHolder;
7662 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
7663
7664 handle_ = &handle;
7665
7666 // parse here
7667 if( !readBuffer(placeHolder, 2) ) { return false; }
7668 unsigned int cnt = placeHolder.toUnsignedInt();
7669
7670 for( unsigned int i=0; i<cnt; ++i ) {
7671 // 0x0028 or 0x0016 or 0x002C
7672 if( !readBuffer(placeHolder, 2) ) { return false; }
7673 unsigned int count = placeHolder.toUnsignedInt() - 7;
7674
7675 // type id
7676 if( !readBuffer(placeHolder, 1) ) { return false; }
7677 unsigned int thisByte = placeHolder.toUnsignedInt();
7678 BdatType type;
7679
7680 if( !getBdatElementType(thisByte, type) ) { return false; }
7681
7682 switch( type ) {
7683 case Bdat_Raw_Note :
7684 case Bdat_Rest :
7685 case Bdat_Note : {
7686 if( !parseNoteRest(measureData, count, type) ) { return false; }
7687 break;
7688 }
7689 case Bdat_Beam : {
7690 if( !parseBeam(measureData, count) ) { return false; }
7691 break;
7692 }
7693 case Bdat_Harmony : {
7694 if( !parseHarmony(measureData, count) ) { return false; }
7695 break;
7696 }
7697 case Bdat_Clef : {
7698 if( !parseClef(measureData, count) ) { return false; }
7699 break;
7700 }
7701 case Bdat_Dynamics : {
7702 if( !parseDynamics(measureData, count) ) { return false; }
7703 break;
7704 }
7705 case Bdat_Wedge : {
7706 if( !parseWedge(measureData, count) ) { return false; }
7707 break;
7708 }
7709 case Bdat_Glissando : {
7710 if( !parseGlissando(measureData, count) ) { return false; }
7711 break;
7712 }
7713 case Bdat_Decorator : {
7714 if( !parseDecorators(measureData, count) ) { return false; }
7715 break;
7716 }
7717 case Bdat_Key : {
7718 if( !parseKey(measureData, count) ) { return false; }
7719 break;
7720 }
7721 case Bdat_Lyric : {
7722 if( !parseLyric(measureData, count) ) { return false; }
7723 break;
7724 }
7725 case Bdat_Octave_Shift: {
7726 if( !parseOctaveShift(measureData, count) ) { return false; }
7727 break;
7728 }
7729 case Bdat_Slur : {
7730 if( !parseSlur(measureData, count) ) { return false; }
7731 break;
7732 }
7733 case Bdat_Text : {
7734 if( !parseText(measureData, count) ) { return false; }
7735 break;
7736 }
7737 case Bdat_Tie : {
7738 if( !parseTie(measureData, count) ) { return false; }
7739 break;
7740 }
7741 case Bdat_Tuplet : {
7742 if( !parseTuplet(measureData, count) ) { return false; }
7743 break;
7744 }
7745 case Bdat_Guitar_Bend :
7746 case Bdat_Guitar_Barre : {
7747 if( !parseSizeBlock(count) ) { return false; }
7748 break;
7749 }
7750 case Bdat_Pedal: {
7751 if( !parsePedal(measureData, count) ) { return false; }
7752 break;
7753 }
7754 case Bdat_KuoHao: {
7755 if( !parseKuohao(measureData, count) ) { return false; }
7756 break;
7757 }
7758 case Bdat_Expressions: {
7759 if( !parseExpressions(measureData, count) ) { return false; }
7760 break;
7761 }
7762 case Bdat_Harp_Pedal: {
7763 if( !parseHarpPedal(measureData, count) ) { return false; }
7764 break;
7765 }
7766 case Bdat_Multi_Measure_Rest: {
7767 if( !parseMultiMeasureRest(measureData, count) ) { return false; }
7768 break;
7769 }
7770 case Bdat_Harmony_GuitarFrame: {
7771 if( !parseHarmonyGuitarFrame(measureData, count) ) { return false; }
7772 break;
7773 }
7774 case Bdat_Graphics_40:
7775 case Bdat_Graphics_RoundRect:
7776 case Bdat_Graphics_Rect:
7777 case Bdat_Graphics_Round:
7778 case Bdat_Graphics_Line:
7779 case Bdat_Graphics_Curve:
7780 case Bdat_Graphics_WedgeSymbol: {
7781 if( !parseSizeBlock(count) ) { return false; }
7782 break;
7783 }
7784 case Bdat_Midi_Controller : {
7785 if( !parseMidiController(measureData, count) ) { return false; }
7786 break;
7787 }
7788 case Bdat_Midi_Program_Change : {
7789 if( !parseMidiProgramChange(measureData, count) ) { return false; }
7790 break;
7791 }
7792 case Bdat_Midi_Channel_Pressure : {
7793 if( !parseMidiChannelPressure(measureData, count) ) { return false; }
7794 break;
7795 }
7796 case Bdat_Midi_Pitch_Wheel : {
7797 if( !parseMidiPitchWheel(measureData, count) ) { return false; }
7798 break;
7799 }
7800 default: {
7801 if( !jump(count) ) { return false; }
7802 break;
7803 }
7804 }
7805
7806 // if i==count-1 then is bar end place holder
7807 }
7808
7809 handle_ = NULL;
7810
7811 return true;
7812}
7813
7814int getInt(int byte, int bits) {
7815 int num = 0;
7816
7817 if( bits > 0 ) {
7818 int factor = int(pow(2.0, bits-1));
7819 num = (byte % (factor*2));
7820
7821 if ( (byte & factor) == factor ) {
7822 num -= factor*2;
7823 }
7824 }
7825
7826 return num;
7827}
7828
7829bool BarsParse::parseNoteRest(MeasureData* measureData, int length, BdatType type) {
7830 NoteContainer* container = new NoteContainer();
7831 Block placeHolder;
7832 unsigned int thisByte;
7833
7834 measureData->addNoteContainer(container);
7835 measureData->addMusicData(container);
7836
7837 // note|rest & grace
7838 container->setIsRest(type==Bdat_Rest);
7839 container->setIsRaw(type==Bdat_Raw_Note);
7840
7841 if( !readBuffer(placeHolder, 2) ) { return false; }
7842 thisByte = placeHolder.toUnsignedInt();
7843 container->setIsGrace( thisByte == 0x3C00 );
7844 container->setIsCue( thisByte == 0x4B40 || thisByte == 0x3240 );
7845
7846 // show / hide
7847 if( !readBuffer(placeHolder, 1) ) { return false; }
7848 thisByte = placeHolder.toUnsignedInt();
7849 container->setShow(getLowNibble(thisByte)!=0x8);
7850
7851 // voice
7852 container->setVoice(getLowNibble(thisByte)&0x7);
7853
7854 // common
7855 if( !parseCommonBlock(container) ) { return false; }
7856
7857 // tuplet
7858 if( !readBuffer(placeHolder, 1) ) { return false; }
7859 container->setTuplet(placeHolder.toUnsignedInt());
7860
7861 // space
7862 if( !readBuffer(placeHolder, 1) ) { return false; }
7863 container->setSpace(placeHolder.toUnsignedInt());
7864
7865 // in beam
7866 if( !readBuffer(placeHolder, 1) ) { return false; }
7867 thisByte = placeHolder.toUnsignedInt();
7868 bool inBeam = ( getHighNibble(thisByte) & 0x1 ) == 0x1;
7869 container->setInBeam(inBeam);
7870
7871 // grace NoteType
7872 container->setGraceNoteType((NoteType)getHighNibble(thisByte));
7873
7874 // dot
7875 container->setDot(getLowNibble(thisByte)&0x03);
7876
7877 // NoteType
7878 if( !readBuffer(placeHolder, 1) ) { return false; }
7879 thisByte = placeHolder.toUnsignedInt();
7880 container->setNoteType((NoteType)getLowNibble(thisByte));
7881
7882 int cursor = 0;
7883
7884 if( type == Bdat_Rest ) {
7885 Note* restPtr = new Note();
7886 container->addNoteRest(restPtr);
7887 restPtr->setIsRest(true);
7888
7889 // line
7890 if( !readBuffer(placeHolder, 1) ) { return false; }
7891 restPtr->setLine(placeHolder.toInt());
7892
7893 if( !jump(1) ) { return false; }
7894
7895 cursor = ove_->getIsVersion4() ? 16 : 14;
7896 } else // type == Bdat_Note || type == Bdat_Raw_Note
7897 {
7898 // stem up 0x80, stem down 0x00
7899 if( !readBuffer(placeHolder, 1) ) { return false; }
7900 thisByte = placeHolder.toUnsignedInt();
7901 container->setStemUp((getHighNibble(thisByte)&0x8)==0x8);
7902
7903 // stem length
7904 int stemOffset = thisByte%0x80;
7905 container->setStemLength(getInt(stemOffset, 7)+7/*3.5 line span*/);
7906
7907 // show stem 0x00, hide stem 0x40
7908 if( !readBuffer(placeHolder, 1) ) { return false; }
7909 bool hideStem = getHighNibble(thisByte)==0x4;
7910 container->setShowStem(!hideStem);
7911
7912 if( !jump(1) ) { return false; }
7913
7914 // note count
7915 if( !readBuffer(placeHolder, 1) ) { return false; }
7916 unsigned int noteCount = placeHolder.toUnsignedInt();
7917 unsigned int i;
7918
7919 // each note 16 bytes
7920 for( i=0; i<noteCount; ++i ) {
7921 Note* notePtr = new Note();
7922 notePtr->setIsRest(false);
7923
7924 container->addNoteRest(notePtr);
7925
7926 // note show / hide
7927 if( !readBuffer(placeHolder, 1) ) { return false; }
7928 thisByte = placeHolder.toUnsignedInt();
7929 notePtr->setShow((thisByte&0x80) != 0x80);
7930
7931 // note head type
7932 notePtr->setHeadType(thisByte&0x7f);
7933
7934 // tie pos
7935 if( !readBuffer(placeHolder, 1) ) { return false; }
7936 thisByte = placeHolder.toUnsignedInt();
7937 notePtr->setTiePos(getHighNibble(thisByte));
7938
7939 // offset staff, in {-1, 0, 1}
7940 if( !readBuffer(placeHolder, 1) ) { return false; }
7941 thisByte = getLowNibble(placeHolder.toUnsignedInt());
7942 int offsetStaff = 0;
7943 if( thisByte == 1 ) { offsetStaff = 1; }
7944 if( thisByte == 7 ) { offsetStaff = -1; }
7945 notePtr->setOffsetStaff(offsetStaff);
7946
7947 // accidental
7948 if( !readBuffer(placeHolder, 1) ) { return false; }
7949 thisByte = placeHolder.toUnsignedInt();
7950 notePtr->setAccidental(getLowNibble(thisByte));
7951 // accidental 0: influenced by key, 4: influenced by previous accidental in measure
7952 bool notShow = ( getHighNibble(thisByte) == 0 ) || ( getHighNibble(thisByte) == 4 );
7953 notePtr->setShowAccidental(!notShow);
7954
7955 if( !jump(1) ) { return false; }
7956
7957 // line
7958 if( !readBuffer(placeHolder, 1) ) { return false; }
7959 notePtr->setLine(placeHolder.toInt());
7960
7961 if( !jump(1) ) { return false; }
7962
7963 // note
7964 if( !readBuffer(placeHolder, 1) ) { return false; }
7965 unsigned int note = placeHolder.toUnsignedInt();
7966 notePtr->setNote(note);
7967
7968 // note on velocity
7969 if( !readBuffer(placeHolder, 1) ) { return false; }
7970 unsigned int onVelocity = placeHolder.toUnsignedInt();
7971 notePtr->setOnVelocity(onVelocity);
7972
7973 // note off velocity
7974 if( !readBuffer(placeHolder, 1) ) { return false; }
7975 unsigned int offVelocity = placeHolder.toUnsignedInt();
7976 notePtr->setOffVelocity(offVelocity);
7977
7978 if( !jump(2) ) { return false; }
7979
7980 // length (tick)
7981 if( !readBuffer(placeHolder, 2) ) { return false; }
7982 container->setLength(placeHolder.toUnsignedInt());
7983
7984 // offset tick
7985 if( !readBuffer(placeHolder, 2) ) { return false; }
7986 notePtr->setOffsetTick(placeHolder.toInt());
7987 }
7988
7989 cursor = ove_->getIsVersion4() ? 18 : 16;
7990 cursor += noteCount * 16/*note size*/;
7991 }
7992
7993 // articulation
7994 while ( cursor < length + 1/* 0x70 || 0x80 || 0x90 */ ) {
7995 Articulation* art = new Articulation();
7996 container->addArticulation(art);
7997
7998 // block size
7999 if( !readBuffer(placeHolder, 2) ) { return false; }
8000 int blockSize = placeHolder.toUnsignedInt();
8001
8002 // articulation type
8003 if( !readBuffer(placeHolder, 1) ) { return false; }
8004 art->setArtType(placeHolder.toUnsignedInt());
8005
8006 // placement
8007 if( !readBuffer(placeHolder, 1) ) { return false; }
8008 art->setPlacementAbove(placeHolder.toUnsignedInt()!=0x00); //0x00:below, 0x30:above
8009
8010 // offset
8011 if( !parseOffsetElement(art) ) { return false; }
8012
8013 if( !ove_->getIsVersion4() ) {
8014 if( blockSize - 8 > 0 ) {
8015 if( !jump(blockSize-8) ) { return false; }
8016 }
8017 } else {
8018 // setting
8019 if( !readBuffer(placeHolder, 1) ) { return false; }
8020 thisByte = placeHolder.toUnsignedInt();
8021 const bool changeSoundEffect = ( ( thisByte & 0x1 ) == 0x1 );
8022 const bool changeLength = ( ( thisByte & 0x2 ) == 0x2 );
8023 const bool changeVelocity = ( ( thisByte & 0x4 ) == 0x4 );
8024 //const bool changeExtraLength = ( ( thisByte & 0x20 ) == 0x20 );
8025
8026 if( !jump(8) ) { return false; }
8027
8028 // velocity type
8029 if( !readBuffer(placeHolder, 1) ) { return false; }
8030 thisByte = placeHolder.toUnsignedInt();
8031 if( changeVelocity ) {
8032 art->setVelocityType((Articulation::VelocityType)thisByte);
8033 }
8034
8035 if( !jump(14) ) { return false; }
8036
8037 // sound effect
8038 if( !readBuffer(placeHolder, 2) ) { return false; }
8039 int from = placeHolder.toInt();
8040 if( !readBuffer(placeHolder, 2) ) { return false; }
8041 int to = placeHolder.toInt();
8042 if( changeSoundEffect ) {
8043 art->setSoundEffect(from, to);
8044 }
8045
8046 if( !jump(1) ) { return false; }
8047
8048 // length percentage
8049 if( !readBuffer(placeHolder, 1) ) { return false; }
8050 if( changeLength ) {
8051 art->setLengthPercentage(placeHolder.toUnsignedInt());
8052 }
8053
8054 // velocity
8055 if( !readBuffer(placeHolder, 2) ) { return false; }
8056 if( changeVelocity ) {
8057 art->setVelocityValue(placeHolder.toInt());
8058 }
8059
8060 if( Articulation::isTrill(art->getArtType()) ) {
8061 if( !jump(8) ) { return false; }
8062
8063 // trill note length
8064 if( !readBuffer(placeHolder, 1) ) { return false; }
8065 art->setTrillNoteLength(placeHolder.toUnsignedInt());
8066
8067 // trill rate
8068 if( !readBuffer(placeHolder, 1) ) { return false; }
8069 thisByte = placeHolder.toUnsignedInt();
8070 NoteType trillNoteType = Note_Sixteen;
8071 switch ( getHighNibble(thisByte) ) {
8072 case 0:
8073 trillNoteType = Note_None;
8074 break;
8075 case 1:
8076 trillNoteType = Note_Sixteen;
8077 break;
8078 case 2:
8079 trillNoteType = Note_32;
8080 break;
8081 case 3:
8082 trillNoteType = Note_64;
8083 break;
8084 case 4:
8085 trillNoteType = Note_128;
8086 break;
8087 default:
8088 break;
8089 }
8090 art->setTrillRate(trillNoteType);
8091
8092 // accelerate type
8093 art->setAccelerateType(thisByte&0xf);
8094
8095 if( !jump(1) ) { return false; }
8096
8097 // auxiliary first
8098 if( !readBuffer(placeHolder, 1) ) { return false; }
8099 art->setAuxiliaryFirst(placeHolder.toBoolean());
8100
8101 if( !jump(1) ) { return false; }
8102
8103 // trill interval
8104 if( !readBuffer(placeHolder, 1) ) { return false; }
8105 art->setTrillInterval(placeHolder.toUnsignedInt());
8106 } else {
8107 if( blockSize > 40 ) {
8108 if( !jump( blockSize - 40 ) ) { return false; }
8109 }
8110 }
8111 }
8112
8113 cursor += blockSize;
8114 }
8115
8116 return true;
8117}
8118
8119int tupletToSpace(int tuplet) {
8120 int a(1);
8121
8122 while( a*2 < tuplet ) {
8123 a *= 2;
8124 }
8125
8126 return a;
8127}
8128
8129bool BarsParse::parseBeam(MeasureData* measureData, int length)
8130{
8131 int i;
8132 Block placeHolder;
8133
8134 Beam* beam = new Beam();
8135 measureData->addCrossMeasureElement(beam, true);
8136
8137 // maybe create tuplet, for < quarter & tool 3(
8138 bool createTuplet = false;
8139 int maxEndUnit = 0;
8140 Tuplet* tuplet = new Tuplet();
8141
8142 // is grace
8143 if( !readBuffer(placeHolder, 1) ) { return false; }
8144 beam->setIsGrace(placeHolder.toBoolean());
8145
8146 if( !jump(1) ) { return false; }
8147
8148 // voice
8149 if( !readBuffer(placeHolder, 1) ) { return false; }
8150 beam->setVoice(getLowNibble(placeHolder.toUnsignedInt())&0x7);
8151
8152 // common
8153 if( !parseCommonBlock(beam) ) { return false; }
8154
8155 if( !jump(2) ) { return false; }
8156
8157 // beam count
8158 if( !readBuffer(placeHolder, 1) ) { return false; }
8159 int beamCount = placeHolder.toUnsignedInt();
8160
8161 if( !jump(1) ) { return false; }
8162
8163 // left line
8164 if( !readBuffer(placeHolder, 1) ) { return false; }
8165 beam->getLeftLine()->setLine(placeHolder.toInt());
8166
8167 // right line
8168 if( !readBuffer(placeHolder, 1) ) { return false; }
8169 beam->getRightLine()->setLine(placeHolder.toInt());
8170
8171 if( ove_->getIsVersion4() ) {
8172 if( !jump(8) ) { return false; }
8173 }
8174
8175 int currentCursor = ove_->getIsVersion4() ? 23 : 13;
8176 int count = (length - currentCursor)/16;
8177
8178 if( count != beamCount ) { return false; }
8179
8180 for( i=0; i<count; ++i ) {
8181 if( !jump(1) ) { return false; }
8182
8183 // tuplet
8184 if( !readBuffer(placeHolder, 1) ) { return false; }
8185 int tupletCount = placeHolder.toUnsignedInt();
8186 if( tupletCount > 0 ) {
8187 createTuplet = true;
8188 tuplet->setTuplet(tupletCount);
8189 tuplet->setSpace(tupletToSpace(tupletCount));
8190 }
8191
8192 // start / stop measure
8193 // line i start end position
8194 MeasurePos startMp;
8195 MeasurePos stopMp;
8196
8197 if( !readBuffer(placeHolder, 1) ) { return false; }
8198 startMp.setMeasure(placeHolder.toUnsignedInt());
8199 if( !readBuffer(placeHolder, 1) ) { return false; }
8200 stopMp.setMeasure(placeHolder.toUnsignedInt());
8201
8202 if( !readBuffer(placeHolder, 2) ) { return false; }
8203 startMp.setOffset(placeHolder.toInt());
8204 if( !readBuffer(placeHolder, 2) ) { return false; }
8205 stopMp.setOffset(placeHolder.toInt());
8206
8207 beam->addLine(startMp, stopMp);
8208
8209 if( stopMp.getOffset() > maxEndUnit ) {
8210 maxEndUnit = stopMp.getOffset();
8211 }
8212
8213 if( i == 0 ) {
8214 if( !jump(4) ) { return false; }
8215
8216 // left offset up+4, down-4
8217 if( !readBuffer(placeHolder, 2) ) { return false; }
8218 beam->getLeftShoulder()->setYOffset(placeHolder.toInt());
8219
8220 // right offset up+4, down-4
8221 if( !readBuffer(placeHolder, 2) ) { return false; }
8222 beam->getRightShoulder()->setYOffset(placeHolder.toInt());
8223 } else {
8224 if( !jump(8) ) { return false; }
8225 }
8226 }
8227
8228 const QList<QPair<MeasurePos, MeasurePos> > lines = beam->getLines();
8229 MeasurePos offsetMp;
8230
8231 for( i=0; i<lines.size(); ++i ) {
8232 if( lines[i].second > offsetMp ) {
8233 offsetMp = lines[i].second;
8234 }
8235 }
8236
8237 beam->stop()->setMeasure(offsetMp.getMeasure());
8238 beam->stop()->setOffset(offsetMp.getOffset());
8239
8240 // a case that Tuplet block don't exist, and hide inside beam
8241 if( createTuplet ) {
8242 tuplet->copyCommonBlock(*beam);
8243 tuplet->getLeftLine()->setLine(beam->getLeftLine()->getLine());
8244 tuplet->getRightLine()->setLine(beam->getRightLine()->getLine());
8245 tuplet->stop()->setMeasure(beam->stop()->getMeasure());
8246 tuplet->stop()->setOffset(maxEndUnit);
8247
8248 measureData->addCrossMeasureElement(tuplet, true);
8249 } else {
8250 delete tuplet;
8251 }
8252
8253 return true;
8254}
8255
8256bool BarsParse::parseTie(MeasureData* measureData, int /*length*/) {
8257 Block placeHolder;
8258
8259 Tie* tie = new Tie();
8260 measureData->addCrossMeasureElement(tie, true);
8261
8262 if( !jump(3) ) { return false; }
8263
8264 // start common
8265 if( !parseCommonBlock(tie) ) { return false; }
8266
8267 if( !jump(1) ) { return false; }
8268
8269 // note
8270 if( !readBuffer(placeHolder, 1) ) { return false; }
8271 tie->setNote(placeHolder.toUnsignedInt());
8272
8273 // pair lines
8274 if( !parsePairLinesBlock(tie) ) { return false; }
8275
8276 // offset common
8277 if( !parseOffsetCommonBlock(tie) ) { return false; }
8278
8279 // left shoulder offset
8280 if( !parseOffsetElement(tie->getLeftShoulder()) ) { return false; }
8281
8282 // right shoulder offset
8283 if( !parseOffsetElement(tie->getRightShoulder()) ) { return false; }
8284
8285 // height
8286 if( !readBuffer(placeHolder, 2) ) { return false; }
8287 tie->setHeight(placeHolder.toUnsignedInt());
8288
8289 return true;
8290}
8291
8292bool BarsParse::parseTuplet(MeasureData* measureData, int /*length*/) {
8293 Block placeHolder;
8294
8295 Tuplet* tuplet = new Tuplet();
8296 measureData->addCrossMeasureElement(tuplet, true);
8297
8298 if( !jump(3) ) { return false; }
8299
8300 // common
8301 if( !parseCommonBlock(tuplet) ) { return false; }
8302
8303 if( !jump(2) ) { return false; }
8304
8305 // pair lines
8306 if( !parsePairLinesBlock(tuplet) ) { return false; }
8307
8308 // offset common
8309 if( !parseOffsetCommonBlock(tuplet) ) { return false; }
8310
8311 // left shoulder offset
8312 if( !parseOffsetElement(tuplet->getLeftShoulder()) ) { return false; }
8313
8314 // right shoulder offset
8315 if( !parseOffsetElement(tuplet->getRightShoulder()) ) { return false; }
8316
8317 if( !jump(2) ) { return false; }
8318
8319 // height
8320 if( !readBuffer(placeHolder, 2) ) { return false; }
8321 tuplet->setHeight(placeHolder.toUnsignedInt());
8322
8323 // tuplet
8324 if( !readBuffer(placeHolder, 1) ) { return false; }
8325 tuplet->setTuplet(placeHolder.toUnsignedInt());
8326
8327 // space
8328 if( !readBuffer(placeHolder, 1) ) { return false; }
8329 tuplet->setSpace(placeHolder.toUnsignedInt());
8330
8331 // mark offset
8332 if( !parseOffsetElement(tuplet->getMarkHandle()) ) { return false; }
8333
8334 return true;
8335}
8336
8337HarmonyType binaryToHarmonyType(int bin) {
8338 HarmonyType type = Harmony_maj;
8339 if( bin == 0x0091 ) {
8340 type = Harmony_maj;
8341 } else if( bin == 0x0089 ) {
8342 type = Harmony_min;
8343 } else if( bin == 0x0489 ) {
8344 type = Harmony_min7;
8345 } else if( bin == 0x0491 ) {
8346 type = Harmony_7;
8347 } else if( bin == 0x0495 ) {
8348 type = Harmony_9;
8349 } else if( bin == 0x0449 ) {
8350 type = Harmony_min7b5;
8351 } else if( bin == 0x04A1 ) {
8352 type = Harmony_7sus4;
8353 } else if( bin == 0x00A1 ) {
8354 type = Harmony_sus4;
8355 } else if( bin == 0x0049 ) {
8356 type = Harmony_dim;
8357 } else if( bin == 0x0249 ) {
8358 type = Harmony_dim7;
8359 } else if( bin == 0x0111 ) {
8360 type = Harmony_aug;
8361 } else if( bin == 0x0511 ) {
8362 type = Harmony_aug7;
8363 } else if( bin == 0x044D ) {
8364 type = Harmony_min9_b5;
8365 } else if( bin == 0x0499 ) {
8366 type = Harmony_7s9;
8367 } else if( bin == 0x0615 ) {
8368 type = Harmony_13;
8369 } else if( bin == 0x0289 ) {
8370 type = Harmony_min6;
8371 } else if( bin == 0x0291 ) {
8372 type = Harmony_6;
8373 } else if( bin == 0x0295 ) {
8374 type = Harmony_6; //6add9
8375 } else if( bin == 0x0095 ) {
8376 type = Harmony_min; //minor add9
8377 } else if( bin == 0x008D ) {
8378 type = Harmony_maj7;
8379 } else if( bin == 0x0891 ) {
8380 type = Harmony_maj7;
8381 } else if( bin == 0x0881 ) {
8382 type = Harmony_maj7_s5; //maj7#5
8383 } else if( bin == 0x0911 ) {
8384 type = Harmony_maj7_s5; //maj7#5
8385 } else if( bin == 0x0991 ) {
8386 type = Harmony_maj7_s11;//maj7#11
8387 } else if( bin == 0x0851 ) {
8388 type = Harmony_maj7_s11;//maj7#11
8389 } else if( bin == 0x08D1 ) {
8390 type = Harmony_maj9;
8391 } else if( bin == 0x0895 ) {
8392 type = Harmony_maj9_s5; //maj9#5
8393 } else if( bin == 0x0995 ) {
8394 type = Harmony_maj13_s11;//maj9#11
8395 } else if( bin == 0x0855 ) {
8396 type = Harmony_maj9_s11;//maj9#11
8397 } else if( bin == 0x08D5 ) {
8398 type = Harmony_maj13;
8399 } else if( bin == 0x0A95 ) {
8400 type = Harmony_maj13_s11;//maj13#11
8401 } else if( bin == 0x0A55 ) {
8402 type = Harmony_maj13; //maj13(no3)
8403 } else if( bin == 0x0A85 ) {
8404 type = Harmony_maj9_s5; //maj13#5#11(no4)
8405 } else if( bin == 0x0B45 ) {
8406 type = Harmony_7b9;
8407 } else if( bin == 0x0493 ) {
8408 type = Harmony_7b5;
8409 } else if( bin == 0x0451 ) {
8410 type = Harmony_9b5;
8411 } else if( bin == 0x0455 ) {
8412 type = Harmony_7s9; //7#5#9
8413 } else if( bin == 0x0519 ) {
8414 type = Harmony_7b9; //7#5b9
8415 } else if( bin == 0x0513 ) {
8416 type = Harmony_aug7; //aug9
8417 } else if( bin == 0x0515 ) {
8418 type = Harmony_sus4; //sus9
8419 } else if( bin == 0x04A5 ) {
8420 type = Harmony_13b9;
8421 } else if( bin == 0x0613 ) {
8422 type = Harmony_13b9; //13b9#11
8423 } else if( bin == 0x0611 ) {
8424 type = Harmony_13;
8425 } else if( bin == 0x0653 ) {
8426 type = Harmony_min; //m(natural7)
8427 } else if( bin == 0x0889 ) {
8428 type = Harmony_min9; //m9(natural7)
8429 } else if( bin == 0x088D ) {
8430 type = Harmony_min11;
8431 } else if( bin == 0x04AD ) {
8432 type = Harmony_9s11;
8433 } else if( bin == 0x04D5 ) {
8434 type = Harmony_7sus4; //sus7
8435 } else if( bin == 0x0421 ) {
8436 type = Harmony_min11;
8437 } else if( bin == 0x04A9 ) {
8438 type = Harmony_min9;
8439 } else if( bin == 0x048D ) {
8440 type = Harmony_7b5b9;
8441 } else if( bin == 0x0453 ) {
8442 type = Harmony_maj; //(no5)
8443 } else if( bin == 0x0011 ) {
8444 type = Harmony_maj7; //(no3)
8445 } else if( bin == 0x0081 ) {
8446 type = Harmony_7; //7(no3)
8447 } else if( bin == 0x0481 ) {
8448 type = Harmony_7; //7(no5)
8449 } else if( bin == 0x0411 ) {
8450 type = Harmony_6;
8451 } else if( bin == 0x0291 ) {
8452 type = Harmony_sus4; //sus(add9)
8453 } else if( bin == 0x00A5 ) {
8454 type = Harmony_13s9; //13#9b5
8455 } else if( bin == 0x0659 ) {
8456 type = Harmony_sus4; //sus(no5)
8457 } else if( bin == 0x0021 ) {
8458 type = Harmony_7b5b9; //7b5b9#9
8459 } else if( bin == 0x045B ) {
8460 type = Harmony_13b5; //13b5b9#9
8461 } else if( bin == 0x065B ) {
8462 type = Harmony_13b9; //13b9#9
8463 } else if( bin == 0x061B ) {
8464 type = Harmony_7b9s9; //7b9#9
8465 } else if( bin == 0x04B5 ) {
8466 type = Harmony_7;
8467 }
8468
8469 return type;
8470}
8471
8472bool BarsParse::parseHarmony(MeasureData* measureData, int /*length*/) {
8473 Block placeHolder;
8474
8475 Harmony* harmony = new Harmony();
8476 measureData->addMusicData(harmony);
8477
8478 if( !jump(3) ) { return false; }
8479
8480 // common
8481 if( !parseCommonBlock(harmony) ) { return false; }
8482
8483 // bass on bottom
8484 if( !readBuffer(placeHolder, 1) ) { return false; }
8485 harmony->setBassOnBottom((getHighNibble(placeHolder.toUnsignedInt())==0x4));
8486
8487 if( !jump(1) ) { return false; }
8488
8489 // y offset
8490 if( !readBuffer(placeHolder, 2) ) { return false; }
8491 harmony->setYOffset(placeHolder.toInt());
8492
8493 // harmony type
8494 if( !readBuffer(placeHolder, 2) ) { return false; }
8495 harmony->setHarmonyType(binaryToHarmonyType(placeHolder.toUnsignedInt()));
8496
8497 // root
8498 if( !readBuffer(placeHolder, 1) ) { return false; }
8499 harmony->setRoot(placeHolder.toInt());
8500
8501 // bass
8502 if( !readBuffer(placeHolder, 1) ) { return false; }
8503 harmony->setBass(placeHolder.toInt());
8504
8505 // angle
8506 if( !readBuffer(placeHolder, 2) ) { return false; }
8507 harmony->setAngle(placeHolder.toInt());
8508
8509 if( ove_->getIsVersion4() ) {
8510 // length (tick)
8511 if( !readBuffer(placeHolder, 2) ) { return false; }
8512 harmony->setLength(placeHolder.toUnsignedInt());
8513
8514 if( !jump(4) ) { return false; }
8515 }
8516
8517 return true;
8518}
8519
8520bool BarsParse::parseClef(MeasureData* measureData, int /*length*/) {
8521 Block placeHolder;
8522
8523 Clef* clef = new Clef();
8524 measureData->addMusicData(clef);
8525
8526 if( !jump(3) ) { return false; }
8527
8528 // common
8529 if( !parseCommonBlock(clef) ) { return false; }
8530
8531 // clef type
8532 if( !readBuffer(placeHolder, 1) ) { return false; }
8533 clef->setClefType(placeHolder.toUnsignedInt());
8534
8535 // line
8536 if( !readBuffer(placeHolder, 1) ) { return false; }
8537 clef->setLine(placeHolder.toInt());
8538
8539 if( !jump(2) ) { return false; }
8540
8541 return true;
8542}
8543
8544bool BarsParse::parseLyric(MeasureData* measureData, int length) {
8545 Block placeHolder;
8546
8547 Lyric* lyric = new Lyric();
8548 measureData->addMusicData(lyric);
8549
8550 if( !jump(3) ) { return false; }
8551
8552 // common
8553 if( !parseCommonBlock(lyric) ) { return false; }
8554
8555 if( !jump(2) ) { return false; }
8556
8557 // offset
8558 if( !parseOffsetElement(lyric) ) { return false; }
8559
8560 if( !jump(7) ) { return false; }
8561
8562 // verse
8563 if( !readBuffer(placeHolder, 1) ) { return false; }
8564 lyric->setVerse(placeHolder.toUnsignedInt());
8565
8566 if( ove_->getIsVersion4() ) {
8567 if( !jump(6) ) { return false; }
8568
8569 // lyric
8570 if( length > 29 ) {
8571 if( !readBuffer(placeHolder, length-29) ) { return false; }
8572 lyric->setLyric(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
8573 }
8574 }
8575
8576 return true;
8577}
8578
8579bool BarsParse::parseSlur(MeasureData* measureData, int /*length*/) {
8580 Block placeHolder;
8581
8582 Slur* slur = new Slur();
8583 measureData->addCrossMeasureElement(slur, true);
8584
8585 if( !jump(2) ) { return false; }
8586
8587 // voice
8588 if( !readBuffer(placeHolder, 1) ) { return false; }
8589 slur->setVoice(getLowNibble(placeHolder.toUnsignedInt())&0x7);
8590
8591 // common
8592 if( !parseCommonBlock(slur) ) { return false; }
8593
8594 // show on top
8595 if( !readBuffer(placeHolder, 1) ) { return false; }
8596 slur->setShowOnTop(getHighNibble(placeHolder.toUnsignedInt())==0x8);
8597
8598 if( !jump(1) ) { return false; }
8599
8600 // pair lines
8601 if( !parsePairLinesBlock(slur) ) { return false; }
8602
8603 // offset common
8604 if( !parseOffsetCommonBlock(slur) ) { return false; }
8605
8606 // handle 1
8607 if( !parseOffsetElement(slur->getLeftShoulder()) ) { return false; }
8608
8609 // handle 4
8610 if( !parseOffsetElement(slur->getRightShoulder()) ) { return false; }
8611
8612 // handle 2
8613 if( !parseOffsetElement(slur->getHandle2()) ) { return false; }
8614
8615 // handle 3
8616 if( !parseOffsetElement(slur->getHandle3()) ) { return false; }
8617
8618 if( ove_->getIsVersion4() ) {
8619 if( !jump(3) ) { return false; }
8620
8621 // note time percent
8622 if( !readBuffer(placeHolder, 1) ) { return false; }
8623 slur->setNoteTimePercent(placeHolder.toUnsignedInt());
8624
8625 if( !jump(36) ) { return false; }
8626 }
8627
8628 return true;
8629}
8630
8631bool BarsParse::parseGlissando(MeasureData* measureData, int /*length*/) {
8632 Block placeHolder;
8633
8634 Glissando* glissando = new Glissando();
8635 measureData->addCrossMeasureElement(glissando, true);
8636
8637 if( !jump(3) ) { return false; }
8638
8639 // common
8640 if( !parseCommonBlock(glissando) ) { return false; }
8641
8642 // straight or wavy
8643 if( !readBuffer(placeHolder, 1) ) { return false; }
8644 unsigned int thisByte = placeHolder.toUnsignedInt();
8645 glissando->setStraightWavy(getHighNibble(thisByte)==4);
8646
8647 if( !jump(1) ) { return false; }
8648
8649 // pair lines
8650 if( !parsePairLinesBlock(glissando) ) { return false; }
8651
8652 // offset common
8653 if( !parseOffsetCommonBlock(glissando) ) { return false; }
8654
8655 // left shoulder
8656 if( !parseOffsetElement(glissando->getLeftShoulder()) ) { return false; }
8657
8658 // right shoulder
8659 if( !parseOffsetElement(glissando->getRightShoulder()) ) { return false; }
8660
8661 if( ove_->getIsVersion4() ) {
8662 if( !jump(1) ) { return false; }
8663
8664 // line thick
8665 if( !readBuffer(placeHolder, 1) ) { return false; }
8666 glissando->setLineThick(placeHolder.toUnsignedInt());
8667
8668 if( !jump(12) ) { return false; }
8669
8670 // text 32 bytes
8671 if( !readBuffer(placeHolder, 32) ) { return false; }
8672 glissando->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
8673
8674 if( !jump(6) ) { return false; }
8675 }
8676
8677 return true;
8678}
8679
8680bool getDecoratorType(
8681 unsigned int thisByte,
8682 bool& measureRepeat,
8683 Decorator::DecoratorType& decoratorType,
8684 bool& singleRepeat,
8685 ArticulationType& artType) {
8686 measureRepeat = false;
8687 decoratorType = Decorator::Decorator_Articulation;
8688 singleRepeat = true;
8689 artType = Articulation_None;
8690
8691 switch (thisByte) {
8692 case 0x00: {
8693 decoratorType = Decorator::Decorator_Dotted_Barline;
8694 break;
8695 }
8696 case 0x30: {
8697 artType = Articulation_Open_String;
8698 break;
8699 }
8700 case 0x31: {
8701 artType = Articulation_Finger_1;
8702 break;
8703 }
8704 case 0x32: {
8705 artType = Articulation_Finger_2;
8706 break;
8707 }
8708 case 0x33: {
8709 artType = Articulation_Finger_3;
8710 break;
8711 }
8712 case 0x34: {
8713 artType = Articulation_Finger_4;
8714 break;
8715 }
8716 case 0x35: {
8717 artType = Articulation_Finger_5;
8718 break;
8719 }
8720 case 0x6B: {
8721 artType = Articulation_Flat_Accidental_For_Trill;
8722 break;
8723 }
8724 case 0x6C: {
8725 artType = Articulation_Sharp_Accidental_For_Trill;
8726 break;
8727 }
8728 case 0x6D: {
8729 artType = Articulation_Natural_Accidental_For_Trill;
8730 break;
8731 }
8732 case 0x8d: {
8733 measureRepeat = true;
8734 singleRepeat = true;
8735 break;
8736 }
8737 case 0x8e: {
8738 measureRepeat = true;
8739 singleRepeat = false;
8740 break;
8741 }
8742 case 0xA0: {
8743 artType = Articulation_Minor_Trill;
8744 break;
8745 }
8746 case 0xA1: {
8747 artType = Articulation_Major_Trill;
8748 break;
8749 }
8750 case 0xA2: {
8751 artType = Articulation_Trill_Section;
8752 break;
8753 }
8754 case 0xA6: {
8755 artType = Articulation_Turn;
8756 break;
8757 }
8758 case 0xA8: {
8759 artType = Articulation_Tremolo_Eighth;
8760 break;
8761 }
8762 case 0xA9: {
8763 artType = Articulation_Tremolo_Sixteenth;
8764 break;
8765 }
8766 case 0xAA: {
8767 artType = Articulation_Tremolo_Thirty_Second;
8768 break;
8769 }
8770 case 0xAB: {
8771 artType = Articulation_Tremolo_Sixty_Fourth;
8772 break;
8773 }
8774 case 0xB2: {
8775 artType = Articulation_Fermata;
8776 break;
8777 }
8778 case 0xB3: {
8779 artType = Articulation_Fermata_Inverted;
8780 break;
8781 }
8782 case 0xB9: {
8783 artType = Articulation_Pause;
8784 break;
8785 }
8786 case 0xBA: {
8787 artType = Articulation_Grand_Pause;
8788 break;
8789 }
8790 case 0xC0: {
8791 artType = Articulation_Marcato;
8792 break;
8793 }
8794 case 0xC1: {
8795 artType = Articulation_Marcato_Dot;
8796 break;
8797 }
8798 case 0xC2: {
8799 artType = Articulation_SForzando;
8800 break;
8801 }
8802 case 0xC3: {
8803 artType = Articulation_SForzando_Dot;
8804 break;
8805 }
8806 case 0xC4: {
8807 artType = Articulation_SForzando_Inverted;
8808 break;
8809 }
8810 case 0xC5: {
8811 artType = Articulation_SForzando_Dot_Inverted;
8812 break;
8813 }
8814 case 0xC6: {
8815 artType = Articulation_Staccatissimo;
8816 break;
8817 }
8818 case 0xC7: {
8819 artType = Articulation_Staccato;
8820 break;
8821 }
8822 case 0xC8: {
8823 artType = Articulation_Tenuto;
8824 break;
8825 }
8826 case 0xC9: {
8827 artType = Articulation_Natural_Harmonic;
8828 break;
8829 }
8830 case 0xCA: {
8831 artType = Articulation_Artificial_Harmonic;
8832 break;
8833 }
8834 case 0xCB: {
8835 artType = Articulation_Plus_Sign;
8836 break;
8837 }
8838 case 0xCC: {
8839 artType = Articulation_Up_Bow;
8840 break;
8841 }
8842 case 0xCD: {
8843 artType = Articulation_Down_Bow;
8844 break;
8845 }
8846 case 0xCE: {
8847 artType = Articulation_Up_Bow_Inverted;
8848 break;
8849 }
8850 case 0xCF: {
8851 artType = Articulation_Down_Bow_Inverted;
8852 break;
8853 }
8854 case 0xD0: {
8855 artType = Articulation_Pedal_Down;
8856 break;
8857 }
8858 case 0xD1: {
8859 artType = Articulation_Pedal_Up;
8860 break;
8861 }
8862 case 0xD6: {
8863 artType = Articulation_Heavy_Attack;
8864 break;
8865 }
8866 case 0xD7: {
8867 artType = Articulation_Heavier_Attack;
8868 break;
8869 }
8870 default:
8871 return false;
8872 break;
8873 }
8874
8875 return true;
8876}
8877
8878bool BarsParse::parseDecorators(MeasureData* measureData, int length) {
8879 Block placeHolder;
8880 MusicData* musicData = new MusicData();
8881
8882 if( !jump(3) ) { return false; }
8883
8884 // common
8885 if( !parseCommonBlock(musicData) ) { return false; }
8886
8887 if( !jump(2) ) { return false; }
8888
8889 // y offset
8890 if( !readBuffer(placeHolder, 2) ) { return false; }
8891 musicData->setYOffset(placeHolder.toInt());
8892
8893 if( !jump(2) ) { return false; }
8894
8895 // measure repeat | piano pedal | dotted barline | articulation
8896 if( !readBuffer(placeHolder, 1) ) { return false; }
8897 unsigned int thisByte = placeHolder.toUnsignedInt();
8898
8899 Decorator::DecoratorType decoratorType;
8900 bool isMeasureRepeat;
8901 bool isSingleRepeat = true;
8902 ArticulationType artType = Articulation_None;
8903
8904 getDecoratorType(thisByte, isMeasureRepeat, decoratorType, isSingleRepeat, artType);
8905
8906 if( isMeasureRepeat ) {
8907 MeasureRepeat* measureRepeat = new MeasureRepeat();
8908 measureData->addCrossMeasureElement(measureRepeat, true);
8909
8910 measureRepeat->copyCommonBlock(*musicData);
8911 measureRepeat->setYOffset(musicData->getYOffset());
8912
8913 measureRepeat->setSingleRepeat(isSingleRepeat);
8914 } else {
8915 Decorator* decorator = new Decorator();
8916 measureData->addMusicData(decorator);
8917
8918 decorator->copyCommonBlock(*musicData);
8919 decorator->setYOffset(musicData->getYOffset());
8920
8921 decorator->setDecoratorType(decoratorType);
8922 decorator->setArticulationType(artType);
8923 }
8924
8925 int cursor = ove_->getIsVersion4() ? 16 : 14;
8926 if( !jump(length-cursor) ) { return false; }
8927
8928 return true;
8929}
8930
8931bool BarsParse::parseWedge(MeasureData* measureData, int length) {
8932 Block placeHolder;
8933 Wedge* wedge = new Wedge();
8934
8935 if( !jump(3) ) { return false; }
8936
8937 // common
8938 if( !parseCommonBlock(wedge) ) { return false; }
8939
8940 // wedge type
8941 if( !readBuffer(placeHolder, 1) ) { return false; }
8942 WedgeType wedgeType = Wedge_Cres_Line;
8943 bool wedgeOrExpression = true;
8944 unsigned int highHalfByte = getHighNibble(placeHolder.toUnsignedInt());
8945 unsigned int lowHalfByte = getLowNibble(placeHolder.toUnsignedInt());
8946
8947 switch (highHalfByte) {
8948 case 0x0: {
8949 wedgeType = Wedge_Cres_Line;
8950 wedgeOrExpression = true;
8951 break;
8952 }
8953 case 0x4: {
8954 wedgeType = Wedge_Decresc_Line;
8955 wedgeOrExpression = true;
8956 break;
8957 }
8958 case 0x6: {
8959 wedgeType = Wedge_Decresc;
8960 wedgeOrExpression = false;
8961 break;
8962 }
8963 case 0x2: {
8964 wedgeType = Wedge_Cres;
8965 wedgeOrExpression = false;
8966 break;
8967 }
8968 default:
8969 break;
8970 }
8971
8972 // 0xb | 0x8(ove3) , else 3, 0(ove3)
8973 if( (lowHalfByte & 0x8) == 0x8 ) {
8974 wedgeType = Wedge_Double_Line;
8975 wedgeOrExpression = true;
8976 }
8977
8978 if( !jump(1) ) { return false; }
8979
8980 // y offset
8981 if( !readBuffer(placeHolder, 2) ) { return false; }
8982 wedge->setYOffset(placeHolder.toInt());
8983
8984 // wedge
8985 if( wedgeOrExpression ) {
8986 measureData->addCrossMeasureElement(wedge, true);
8987 wedge->setWedgeType(wedgeType);
8988
8989 if( !jump(2) ) { return false; }
8990
8991 // height
8992 if( !readBuffer(placeHolder, 2) ) { return false; }
8993 wedge->setHeight(placeHolder.toUnsignedInt());
8994
8995 // offset common
8996 if( !parseOffsetCommonBlock(wedge) ) { return false; }
8997
8998 int cursor = ove_->getIsVersion4() ? 21 : 19;
8999 if( !jump(length-cursor) ) { return false; }
9000 }
9001 // expression : cresc, decresc
9002 else {
9003 Expressions* express = new Expressions();
9004 measureData->addMusicData(express);
9005
9006 express->copyCommonBlock(*wedge);
9007 express->setYOffset(wedge->getYOffset());
9008
9009 if( !jump(4) ) { return false; }
9010
9011 // offset common
9012 if( !parseOffsetCommonBlock(express) ) { return false; }
9013
9014 if( ove_->getIsVersion4() ) {
9015 if( !jump(18) ) { return false; }
9016
9017 // words
9018 if( length > 39 ) {
9019 if( !readBuffer(placeHolder, length-39) ) { return false; }
9020 express->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
9021 }
9022 } else {
9023 QString str = wedgeType==Wedge_Cres ? "cresc" : "decresc";
9024 express->setText(str);
9025
9026 if( !jump(8) ) { return false; }
9027 }
9028 }
9029
9030 return true;
9031}
9032
9033bool BarsParse::parseDynamics(MeasureData* measureData, int /*length*/) {
9034 Block placeHolder;
9035
9036 Dynamics* dynamics = new Dynamics();
9037 measureData->addMusicData(dynamics);
9038
9039 if( !jump(1) ) { return false; }
9040
9041 // is playback
9042 if( !readBuffer(placeHolder, 1) ) { return false; }
9043 dynamics->setIsPlayback(getHighNibble(placeHolder.toUnsignedInt())!=0x4);
9044
9045 if( !jump(1) ) { return false; }
9046
9047 // common
9048 if( !parseCommonBlock(dynamics) ) { return false; }
9049
9050 // y offset
9051 if( !readBuffer(placeHolder, 2) ) { return false; }
9052 dynamics->setYOffset(placeHolder.toInt());
9053
9054 // dynamics type
9055 if( !readBuffer(placeHolder, 1) ) { return false; }
9056 dynamics->setDynamicsType(getLowNibble(placeHolder.toUnsignedInt()));
9057
9058 // velocity
9059 if( !readBuffer(placeHolder, 1) ) { return false; }
9060 dynamics->setVelocity(placeHolder.toUnsignedInt());
9061
9062 int cursor = ove_->getIsVersion4() ? 4 : 2;
9063
9064 if( !jump(cursor) ) { return false; }
9065
9066 return true;
9067}
9068
9069bool BarsParse::parseKey(MeasureData* measureData, int /*length*/) {
9070 Block placeHolder;
9071 Key* key = measureData->getKey();
9072 int cursor = ove_->getIsVersion4() ? 9 : 7;
9073
9074 if( !jump(cursor) ) { return false; }
9075
9076 // key
9077 if( !readBuffer(placeHolder, 1) ) { return false; }
9078 key->setKey(oveKeyToKey(placeHolder.toUnsignedInt()));
9079
9080 // previous key
9081 if( !readBuffer(placeHolder, 1) ) { return false; }
9082 key->setPreviousKey(oveKeyToKey(placeHolder.toUnsignedInt()));
9083
9084 if( !jump(3) ) { return false; }
9085
9086 // symbol count
9087 if( !readBuffer(placeHolder, 1) ) { return false; }
9088 key->setSymbolCount(placeHolder.toUnsignedInt());
9089
9090 if( !jump(4) ) { return false; }
9091
9092 return true;
9093}
9094
9095bool BarsParse::parsePedal(MeasureData* measureData, int length) {
9096 Block placeHolder;
9097
9098 Pedal* pedal = new Pedal();
9099 //measureData->addMusicData(pedal); //can't remember why
9100 measureData->addCrossMeasureElement(pedal, true);
9101
9102 if( !jump(1) ) { return false; }
9103
9104 // is playback
9105 if( !readBuffer(placeHolder, 1) ) { return false; }
9106 pedal->setIsPlayback(getHighNibble(placeHolder.toUnsignedInt())!=4);
9107
9108 if( !jump(1) ) { return false; }
9109
9110 // common
9111 if( !parseCommonBlock(pedal) ) { return false; }
9112
9113 if( !jump(2) ) { return false; }
9114
9115 // pair lines
9116 if( !parsePairLinesBlock(pedal) ) { return false; }
9117
9118 // offset common
9119 if( !parseOffsetCommonBlock(pedal) ) { return false; }
9120
9121 // left shoulder
9122 if( !parseOffsetElement(pedal->getLeftShoulder()) ) { return false; }
9123
9124 // right shoulder
9125 if( !parseOffsetElement(pedal->getRightShoulder()) ) { return false; }
9126
9127 int cursor = ove_->getIsVersion4() ? 0x45 : 0x23;
9128 int blankCount = ove_->getIsVersion4() ? 42 : 10;
9129
9130 pedal->setHalf( length > cursor );
9131
9132 if( !jump(blankCount) ) { return false; }
9133
9134 if( length > cursor ) {
9135 if( !jump(2) ) { return false; }
9136
9137 // handle x offset
9138 if( !readBuffer(placeHolder, 2) ) { return false; }
9139 pedal->getPedalHandle()->setXOffset(placeHolder.toInt());
9140
9141 if( !jump(6) ) { return false; }
9142 }
9143
9144 return true;
9145}
9146
9147bool BarsParse::parseKuohao(MeasureData* measureData, int /*length*/) {
9148 Block placeHolder;
9149
9150 KuoHao* kuoHao = new KuoHao();
9151 measureData->addMusicData(kuoHao);
9152
9153 if( !jump(3) ) { return false; }
9154
9155 // common
9156 if( !parseCommonBlock(kuoHao) ) { return false; }
9157
9158 if( !jump(2) ) { return false; }
9159
9160 // pair lines
9161 if( !parsePairLinesBlock(kuoHao) ) { return false; }
9162
9163 if( !jump(4) ) { return false; }
9164
9165 // left shoulder
9166 if( !parseOffsetElement(kuoHao->getLeftShoulder()) ) { return false; }
9167
9168 // right shoulder
9169 if( !parseOffsetElement(kuoHao->getRightShoulder()) ) { return false; }
9170
9171 // kuohao type
9172 if( !readBuffer(placeHolder, 1) ) { return false; }
9173 kuoHao->setKuohaoType(placeHolder.toUnsignedInt());
9174
9175 // height
9176 if( !readBuffer(placeHolder, 1) ) { return false; }
9177 kuoHao->setHeight(placeHolder.toUnsignedInt());
9178
9179 int jumpAmount = ove_->getIsVersion4() ? 40 : 8;
9180 if( !jump(jumpAmount) ) { return false; }
9181
9182 return true;
9183}
9184
9185bool BarsParse::parseExpressions(MeasureData* measureData, int length) {
9186 Block placeHolder;
9187
9188 Expressions* expressions = new Expressions();
9189 measureData->addMusicData(expressions);
9190
9191 if( !jump(3) ) { return false; }
9192
9193 // common00
9194 if( !parseCommonBlock(expressions) ) { return false; }
9195
9196 if( !jump(2) ) { return false; }
9197
9198 // y offset
9199 if( !readBuffer(placeHolder, 2) ) { return false; }
9200 expressions->setYOffset(placeHolder.toInt());
9201
9202 // range bar offset
9203 if( !readBuffer(placeHolder, 2) ) { return false; }
9204 //int barOffset = placeHolder.toUnsignedInt();
9205
9206 if( !jump(10) ) { return false; }
9207
9208 // tempo 1
9209 if( !readBuffer(placeHolder, 2) ) { return false; }
9210 //double tempo1 = ((double)placeHolder.toUnsignedInt()) / 100.0;
9211
9212 // tempo 2
9213 if( !readBuffer(placeHolder, 2) ) { return false; }
9214 //double tempo2 = ((double)placeHolder.toUnsignedInt()) / 100.0;
9215
9216 if( !jump(6) ) { return false; }
9217
9218 // text
9219 int cursor = ove_->getIsVersion4() ? 35 : 33;
9220 if( length > cursor ) {
9221 if( !readBuffer(placeHolder, length-cursor) ) { return false; }
9222 expressions->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
9223 }
9224
9225 return true;
9226}
9227
9228bool BarsParse::parseHarpPedal(MeasureData* measureData, int /*length*/) {
9229 Block placeHolder;
9230
9231 HarpPedal* harpPedal = new HarpPedal();
9232 measureData->addMusicData(harpPedal);
9233
9234 if( !jump(3) ) { return false; }
9235
9236 // common
9237 if( !parseCommonBlock(harpPedal) ) { return false; }
9238
9239 if( !jump(2) ) { return false; }
9240
9241 // y offset
9242 if( !readBuffer(placeHolder, 2) ) { return false; }
9243 harpPedal->setYOffset(placeHolder.toInt());
9244
9245 // show type
9246 if( !readBuffer(placeHolder, 1) ) { return false; }
9247 harpPedal->setShowType(placeHolder.toUnsignedInt());
9248
9249 // show char flag
9250 if( !readBuffer(placeHolder, 1) ) { return false; }
9251 harpPedal->setShowCharFlag(placeHolder.toUnsignedInt());
9252
9253 if( !jump(8) ) { return false; }
9254
9255 return true;
9256}
9257
9258bool BarsParse::parseMultiMeasureRest(MeasureData* measureData, int /*length*/) {
9259 Block placeHolder(2);
9260 MultiMeasureRest* measureRest = new MultiMeasureRest();
9261 measureData->addMusicData(measureRest);
9262
9263 if( !jump(3) ) { return false; }
9264
9265 // common
9266 if( !parseCommonBlock(measureRest) ) { return false; }
9267
9268 if( !jump(6) ) { return false; }
9269
9270 return true;
9271}
9272
9273bool BarsParse::parseHarmonyGuitarFrame(MeasureData* measureData, int length) {
9274 Block placeHolder;
9275
9276 Harmony* harmony = new Harmony();
9277 measureData->addMusicData(harmony);
9278
9279 if( !jump(3) ) { return false; }
9280
9281 // common
9282 if( !parseCommonBlock(harmony) ) { return false; }
9283
9284 // root
9285 if( !readBuffer(placeHolder, 1) ) { return false; }
9286 harmony->setRoot(placeHolder.toUnsignedInt());
9287
9288 // type
9289 if( !readBuffer(placeHolder, 1) ) { return false; }
9290 harmony->setHarmonyType((HarmonyType)placeHolder.toUnsignedInt());
9291
9292 // bass
9293 if( !readBuffer(placeHolder, 1) ) { return false; }
9294 harmony->setBass(placeHolder.toUnsignedInt());
9295
9296 int jumpAmount = ove_->getIsVersion4() ? length - 12 : length - 10;
9297 if( !jump(jumpAmount) ) { return false; }
9298
9299 return true;
9300}
9301
9302void extractOctave(unsigned int Bits, OctaveShiftType& octaveShiftType, QList<OctaveShiftPosition>& positions) {
9303 octaveShiftType = OctaveShift_8;
9304 positions.clear();
9305
9306 switch (Bits) {
9307 case 0x0: {
9308 octaveShiftType = OctaveShift_8;
9309 positions.push_back(OctavePosition_Continue);
9310 break;
9311 }
9312 case 0x1: {
9313 octaveShiftType = OctaveShift_Minus_8;
9314 positions.push_back(OctavePosition_Continue);
9315 break;
9316 }
9317 case 0x2: {
9318 octaveShiftType = OctaveShift_15;
9319 positions.push_back(OctavePosition_Continue);
9320 break;
9321 }
9322 case 0x3: {
9323 octaveShiftType = OctaveShift_Minus_15;
9324 positions.push_back(OctavePosition_Continue);
9325 break;
9326 }
9327 case 0x4: {
9328 octaveShiftType = OctaveShift_8;
9329 positions.push_back(OctavePosition_Stop);
9330 break;
9331 }
9332 case 0x5: {
9333 octaveShiftType = OctaveShift_Minus_8;
9334 positions.push_back(OctavePosition_Stop);
9335 break;
9336 }
9337 case 0x6: {
9338 octaveShiftType = OctaveShift_15;
9339 positions.push_back(OctavePosition_Stop);
9340 break;
9341 }
9342 case 0x7: {
9343 octaveShiftType = OctaveShift_Minus_15;
9344 positions.push_back(OctavePosition_Stop);
9345 break;
9346 }
9347 case 0x8: {
9348 octaveShiftType = OctaveShift_8;
9349 positions.push_back(OctavePosition_Start);
9350 break;
9351 }
9352 case 0x9: {
9353 octaveShiftType = OctaveShift_Minus_8;
9354 positions.push_back(OctavePosition_Start);
9355 break;
9356 }
9357 case 0xA: {
9358 octaveShiftType = OctaveShift_15;
9359 positions.push_back(OctavePosition_Start);
9360 break;
9361 }
9362 case 0xB: {
9363 octaveShiftType = OctaveShift_Minus_15;
9364 positions.push_back(OctavePosition_Start);
9365 ;
9366 break;
9367 }
9368 case 0xC: {
9369 octaveShiftType = OctaveShift_8;
9370 positions.push_back(OctavePosition_Start);
9371 positions.push_back(OctavePosition_Stop);
9372 break;
9373 }
9374 case 0xD: {
9375 octaveShiftType = OctaveShift_Minus_8;
9376 positions.push_back(OctavePosition_Start);
9377 positions.push_back(OctavePosition_Stop);
9378 break;
9379 }
9380 case 0xE: {
9381 octaveShiftType = OctaveShift_15;
9382 positions.push_back(OctavePosition_Start);
9383 positions.push_back(OctavePosition_Stop);
9384 break;
9385 }
9386 case 0xF: {
9387 octaveShiftType = OctaveShift_Minus_15;
9388 positions.push_back(OctavePosition_Start);
9389 positions.push_back(OctavePosition_Stop);
9390 break;
9391 }
9392 default:
9393 break;
9394 }
9395}
9396
9397bool BarsParse::parseOctaveShift(MeasureData* measureData, int /*length*/)
9398{
9399 Block placeHolder;
9400
9401 OctaveShift* octave = new OctaveShift();
9402 measureData->addCrossMeasureElement(octave, true);
9403
9404 if( !jump(3) ) { return false; }
9405
9406 // common
9407 if( !parseCommonBlock(octave) ) { return false; }
9408
9409 // octave
9410 if( !readBuffer(placeHolder, 1) ) { return false; }
9411 unsigned int type = getLowNibble(placeHolder.toUnsignedInt());
9412 OctaveShiftType octaveShiftType = OctaveShift_8;
9413 QList<OctaveShiftPosition> positions;
9414 extractOctave(type, octaveShiftType, positions);
9415
9416 octave->setOctaveShiftType(octaveShiftType);
9417
9418 if( !jump(1) ) { return false; }
9419
9420 // y offset
9421 if( !readBuffer(placeHolder, 2) ) { return false; }
9422 octave->setYOffset(placeHolder.toInt());
9423
9424 if( !jump(4) ) { return false; }
9425
9426 // length
9427 if( !readBuffer(placeHolder, 2) ) { return false; }
9428 octave->setLength(placeHolder.toUnsignedInt());
9429
9430 // end tick
9431 if( !readBuffer(placeHolder, 2) ) { return false; }
9432 octave->setEndTick(placeHolder.toUnsignedInt());
9433
9434 // start & stop maybe appear in same measure
9435 for (int i=0; i<positions.size(); ++i) {
9436 OctaveShiftPosition position = positions[i];
9437 OctaveShiftEndPoint* octavePoint = new OctaveShiftEndPoint();
9438 measureData->addMusicData(octavePoint);
9439
9440 octavePoint->copyCommonBlock(*octave);
9441 octavePoint->setOctaveShiftType(octaveShiftType);
9442 octavePoint->setOctaveShiftPosition(position);
9443 octavePoint->setEndTick(octave->getEndTick());
9444
9445 // stop
9446 if( i==0 && position == OctavePosition_Stop ) {
9447 octavePoint->start()->setOffset(octave->start()->getOffset()+octave->getLength());
9448 }
9449
9450 // end point
9451 if( i>0 ) {
9452 octavePoint->start()->setOffset(octave->start()->getOffset()+octave->getLength());
9453 octavePoint->setTick(octave->getEndTick());
9454 }
9455 }
9456
9457 return true;
9458}
9459
9460bool BarsParse::parseMidiController(MeasureData* measureData, int /*length*/) {
9461 Block placeHolder;
9462 MidiController* controller = new MidiController();
9463 measureData->addMidiData(controller);
9464
9465 parseMidiCommon(controller);
9466
9467 // value [0, 128)
9468 if( !readBuffer(placeHolder, 1) ) { return false; }
9469 controller->setValue(placeHolder.toUnsignedInt());
9470
9471 // controller number
9472 if( !readBuffer(placeHolder, 1) ) { return false; }
9473 controller->setController(placeHolder.toUnsignedInt());
9474
9475 if( ove_->getIsVersion4() ) {
9476 if( !jump(2) ) { return false; }
9477 }
9478
9479 return true;
9480}
9481
9482bool BarsParse::parseMidiProgramChange(MeasureData* measureData, int /*length*/) {
9483 Block placeHolder;
9484 MidiProgramChange* program = new MidiProgramChange();
9485 measureData->addMidiData(program);
9486
9487 parseMidiCommon(program);
9488
9489 if( !jump(1) ) { return false; }
9490
9491 // patch
9492 if( !readBuffer(placeHolder, 1) ) { return false; }
9493 program->setPatch(placeHolder.toUnsignedInt());
9494
9495 if( ove_->getIsVersion4() ) {
9496 if( !jump(2) ) { return false; }
9497 }
9498
9499 return true;
9500}
9501
9502bool BarsParse::parseMidiChannelPressure(MeasureData* measureData, int /*length*/) {
9503 Block placeHolder;
9504 MidiChannelPressure* pressure = new MidiChannelPressure();
9505 measureData->addMidiData(pressure);
9506
9507 parseMidiCommon(pressure);
9508
9509 if( !jump(1) ) { return false; }
9510
9511 // pressure
9512 if( !readBuffer(placeHolder, 1) ) { return false; }
9513 pressure->setPressure(placeHolder.toUnsignedInt());
9514
9515 if( ove_->getIsVersion4() )
9516 {
9517 if( !jump(2) ) { return false; }
9518 }
9519
9520 return true;
9521}
9522
9523bool BarsParse::parseMidiPitchWheel(MeasureData* measureData, int /*length*/) {
9524 Block placeHolder;
9525 MidiPitchWheel* wheel = new MidiPitchWheel();
9526 measureData->addMidiData(wheel);
9527
9528 parseMidiCommon(wheel);
9529
9530 // pitch wheel
9531 if( !readBuffer(placeHolder, 2) ) { return false; }
9532 int value = placeHolder.toUnsignedInt();
9533 wheel->setValue(value);
9534
9535 if( ove_->getIsVersion4() ) {
9536 if( !jump(2) ) { return false; }
9537 }
9538
9539 return true;
9540}
9541
9542bool BarsParse::parseSizeBlock(int length) {
9543 if( !jump(length) ) { return false; }
9544
9545 return true;
9546}
9547
9548bool BarsParse::parseMidiCommon(MidiData* ptr) {
9549 Block placeHolder;
9550
9551 if( !jump(3) ) { return false; }
9552
9553 // start position
9554 if( !readBuffer(placeHolder, 2) ) { return false; }
9555 ptr->setTick(placeHolder.toUnsignedInt());
9556
9557 return true;
9558}
9559
9560bool BarsParse::parseCommonBlock(MusicData* ptr) {
9561 Block placeHolder;
9562
9563 // start tick
9564 if( !readBuffer(placeHolder, 2) ) { return false; }
9565 ptr->setTick(placeHolder.toInt());
9566
9567 // start unit
9568 if( !readBuffer(placeHolder, 2) ) { return false; }
9569 ptr->start()->setOffset(placeHolder.toInt());
9570
9571 if( ove_->getIsVersion4() ) {
9572 // color
9573 if( !readBuffer(placeHolder, 1) ) { return false; }
9574 ptr->setColor(placeHolder.toUnsignedInt());
9575
9576 if( !jump(1) ) { return false; }
9577 }
9578
9579 return true;
9580}
9581
9582bool BarsParse::parseOffsetCommonBlock(MusicData* ptr) {
9583 Block placeHolder;
9584
9585 // offset measure
9586 if( !readBuffer(placeHolder, 2) ) { return false; }
9587 ptr->stop()->setMeasure(placeHolder.toUnsignedInt());
9588
9589 // end unit
9590 if( !readBuffer(placeHolder, 2) ) { return false; }
9591 ptr->stop()->setOffset(placeHolder.toInt());
9592
9593 return true;
9594}
9595
9596bool BarsParse::parsePairLinesBlock(PairEnds* ptr) {
9597 Block placeHolder;
9598
9599 // left line
9600 if( !readBuffer(placeHolder, 2) ) { return false; }
9601 ptr->getLeftLine()->setLine(placeHolder.toInt());
9602
9603 // right line
9604 if( !readBuffer(placeHolder, 2) ) { return false; }
9605 ptr->getRightLine()->setLine(placeHolder.toInt());
9606
9607 return true;
9608}
9609
9610bool BarsParse::parseOffsetElement(OffsetElement* ptr) {
9611 Block placeHolder;
9612
9613 // x offset
9614 if( !readBuffer(placeHolder, 2) ) { return false; }
9615 ptr->setXOffset(placeHolder.toInt());
9616
9617 // y offset
9618 if( !readBuffer(placeHolder, 2) ) { return false; }
9619 ptr->setYOffset(placeHolder.toInt());
9620
9621 return true;
9622}
9623
9624bool BarsParse::getCondElementType(unsigned int byteData, CondType& type) {
9625 if( byteData == 0x09 ) {
9626 type = Cond_Time_Parameters;
9627 } else if (byteData == 0x0A) {
9628 type = Cond_Bar_Number;
9629 } else if (byteData == 0x16) {
9630 type = Cond_Decorator;
9631 } else if (byteData == 0x1C) {
9632 type = Cond_Tempo;
9633 } else if (byteData == 0x1D) {
9634 type = Cond_Text;
9635 } else if (byteData == 0x25) {
9636 type = Cond_Expression;
9637 } else if (byteData == 0x30) {
9638 type = Cond_Barline_Parameters;
9639 } else if (byteData == 0x31) {
9640 type = Cond_Repeat;
9641 } else if (byteData == 0x32) {
9642 type = Cond_Numeric_Ending;
9643 } else {
9644 return false;
9645 }
9646
9647 return true;
9648}
9649
9650bool BarsParse::getBdatElementType(unsigned int byteData, BdatType& type) {
9651 if (byteData == 0x70) {
9652 type = Bdat_Raw_Note;
9653 } else if (byteData == 0x80) {
9654 type = Bdat_Rest;
9655 } else if (byteData == 0x90) {
9656 type = Bdat_Note;
9657 } else if (byteData == 0x10) {
9658 type = Bdat_Beam;
9659 } else if (byteData == 0x11) {
9660 type = Bdat_Harmony;
9661 } else if (byteData == 0x12) {
9662 type = Bdat_Clef;
9663 } else if (byteData == 0x13) {
9664 type = Bdat_Wedge;
9665 } else if (byteData == 0x14) {
9666 type = Bdat_Dynamics;
9667 } else if (byteData == 0x15) {
9668 type = Bdat_Glissando;
9669 } else if (byteData == 0x16) {
9670 type = Bdat_Decorator;
9671 } else if (byteData == 0x17) {
9672 type = Bdat_Key;
9673 } else if (byteData == 0x18) {
9674 type = Bdat_Lyric;
9675 } else if (byteData == 0x19) {
9676 type = Bdat_Octave_Shift;
9677 } else if (byteData == 0x1B) {
9678 type = Bdat_Slur;
9679 } else if (byteData == 0x1D) {
9680 type = Bdat_Text;
9681 } else if (byteData == 0x1E) {
9682 type = Bdat_Tie;
9683 } else if (byteData == 0x1F) {
9684 type = Bdat_Tuplet;
9685 } else if (byteData == 0x21) {
9686 type = Bdat_Guitar_Bend;
9687 } else if (byteData == 0x22) {
9688 type = Bdat_Guitar_Barre;
9689 } else if (byteData == 0x23) {
9690 type = Bdat_Pedal;
9691 } else if (byteData == 0x24) {
9692 type = Bdat_KuoHao;
9693 } else if (byteData == 0x25) {
9694 type = Bdat_Expressions;
9695 } else if (byteData == 0x26) {
9696 type = Bdat_Harp_Pedal;
9697 } else if (byteData == 0x27) {
9698 type = Bdat_Multi_Measure_Rest;
9699 } else if (byteData == 0x28) {
9700 type = Bdat_Harmony_GuitarFrame;
9701 } else if (byteData == 0x40) {
9702 type = Bdat_Graphics_40;
9703 } else if (byteData == 0x41) {
9704 type = Bdat_Graphics_RoundRect;
9705 } else if (byteData == 0x42) {
9706 type = Bdat_Graphics_Rect;
9707 } else if (byteData == 0x43) {
9708 type = Bdat_Graphics_Round;
9709 } else if (byteData == 0x44) {
9710 type = Bdat_Graphics_Line;
9711 } else if (byteData == 0x45) {
9712 type = Bdat_Graphics_Curve;
9713 } else if (byteData == 0x46) {
9714 type = Bdat_Graphics_WedgeSymbol;
9715 } else if (byteData == 0xAB) {
9716 type = Bdat_Midi_Controller;
9717 } else if (byteData == 0xAC) {
9718 type = Bdat_Midi_Program_Change;
9719 } else if (byteData == 0xAD) {
9720 type = Bdat_Midi_Channel_Pressure;
9721 } else if (byteData == 0xAE) {
9722 type = Bdat_Midi_Pitch_Wheel;
9723 } else if (byteData == 0xFF) {
9724 type = Bdat_Bar_End;
9725 } else {
9726 return false;
9727 }
9728
9729 return true;
9730}
9731
9733LyricChunkParse::LyricChunkParse(OveSong* ove) :
9734 BasicParse(ove) {
9735}
9736
9737void LyricChunkParse::setLyricChunk(SizeChunk* chunk) {
9738 chunk_ = chunk;
9739}
9740
9741// only ove3 has this chunk
9742bool LyricChunkParse::parse() {
9743 unsigned int i;
9744 Block* dataBlock = chunk_->getDataBlock();
9745 unsigned int blockSize = chunk_->getSizeBlock()->toSize();
9746 StreamHandle handle(dataBlock->data(), blockSize);
9747 Block placeHolder;
9748
9749 handle_ = &handle;
9750
9751 if( !jump(4) ) { return false; }
9752
9753 // Lyric count
9754 if( !readBuffer(placeHolder, 2) ) { return false; }
9755 unsigned int count = placeHolder.toUnsignedInt();
9756
9757 for( i=0; i<count; ++i ) {
9758 LyricInfo info;
9759
9760 if( !readBuffer(placeHolder, 2) ) { return false; }
9761 //unsigned int size = placeHolder.toUnsignedInt();
9762
9763 // 0x0D00
9764 if( !jump(2) ) { return false; }
9765
9766 // voice
9767 if( !readBuffer(placeHolder, 1) ) { return false; }
9768 info.voice_ = placeHolder.toUnsignedInt();
9769
9770 // verse
9771 if( !readBuffer(placeHolder, 1) ) { return false; }
9772 info.verse_ = placeHolder.toUnsignedInt();
9773
9774 // track
9775 if( !readBuffer(placeHolder, 1) ) { return false; }
9776 info.track_ = placeHolder.toUnsignedInt();
9777
9778 if( !jump(1) ) { return false; }
9779
9780 // measure
9781 if( !readBuffer(placeHolder, 2) ) { return false; }
9782 info.measure_ = placeHolder.toUnsignedInt();
9783
9784 // word count
9785 if( !readBuffer(placeHolder, 2) ) { return false; }
9786 info.wordCount_ = placeHolder.toUnsignedInt();
9787
9788 // lyric size
9789 if( !readBuffer(placeHolder, 2) ) { return false; }
9790 info.lyricSize_ = placeHolder.toUnsignedInt();
9791
9792 if( !jump(6) ) { return false; }
9793
9794 // name
9795 if( !readBuffer(placeHolder, 32) ) { return false; }
9796 info.name_ = ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray());
9797
9798 if( info.lyricSize_ > 0 ) {
9799 // lyric
9800 if( info.lyricSize_ > 0 ) {
9801 if( !readBuffer(placeHolder, info.lyricSize_) ) { return false; }
9802 info.lyric_ = ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray());
9803 }
9804
9805 if( !jump(4) ) { return false; }
9806
9807 // font
9808 if( !readBuffer(placeHolder, 2) ) { return false; }
9809 info.font_ = placeHolder.toUnsignedInt();
9810
9811 if( !jump(1) ) { return false; }
9812
9813 // font size
9814 if( !readBuffer(placeHolder, 1) ) { return false; }
9815 info.fontSize_ = placeHolder.toUnsignedInt();
9816
9817 // font style
9818 if( !readBuffer(placeHolder, 1) ) { return false; }
9819 info.fontStyle_ = placeHolder.toUnsignedInt();
9820
9821 if( !jump(1) ) { return false; }
9822
9823 for( int j=0; j<info.wordCount_; ++j ) {
9824 if( !jump(8) ) { return false; }
9825 }
9826 }
9827
9828 processLyricInfo(info);
9829 }
9830
9831 return true;
9832}
9833
9834bool isSpace(char c) {
9835 return c == ' ' || c == '\n';
9836}
9837
9838void LyricChunkParse::processLyricInfo(const LyricInfo& info)
9839{
9840 int i;
9841 int j;
9842 int index = 0; //words
9843
9844 int measureId = info.measure_-1;
9845 bool changeMeasure = true;
9846 MeasureData* measureData = 0;
9847 int trackMeasureCount = ove_->getTrackBarCount();
9848 QStringList words = info.lyric_.split(" ", QString::SkipEmptyParts);
9849
9850 while ( index < words.size() && measureId+1 < trackMeasureCount ) {
9851 if( changeMeasure ) {
9852 ++measureId;
9853 measureData = ove_->getMeasureData(info.track_, measureId);
9854 changeMeasure = false;
9855 }
9856
9857 if( measureData == 0 ) { return; }
9858 QList<NoteContainer*> containers = measureData->getNoteContainers();
9859 QList<MusicData*> lyrics = measureData->getMusicDatas(MusicData_Lyric);
9860
9861 for( i=0; i<containers.size() && index<words.size(); ++i ) {
9862 if( containers[i]->getIsRest() ) {
9863 continue;
9864 }
9865
9866 for( j=0; j<lyrics.size(); ++j ) {
9867 Lyric* lyric = static_cast<Lyric*>(lyrics[j]);
9868
9869 if( containers[i]->start()->getOffset() == lyric->start()->getOffset() &&
9870 (int)containers[i]->getVoice() == info.voice_ &&
9871 lyric->getVerse() == info.verse_ ) {
9872 if(index<words.size()) {
9873 QString l = words[index].trimmed();
9874 if(!l.isEmpty()) {
9875 lyric->setLyric(l);
9876 lyric->setVoice(info.voice_);
9877 }
9878 }
9879
9880 ++index;
9881 }
9882 }
9883 }
9884
9885 changeMeasure = true;
9886 }
9887}
9888
9890TitleChunkParse::TitleChunkParse(OveSong* ove) :
9891 BasicParse(ove) {
9892 titleType_ = 0x00000001;
9893 annotateType_ = 0x00010000;
9894 writerType_ = 0x00020002;
9895 copyrightType_ = 0x00030001;
9896 headerType_ = 0x00040000;
9897 footerType_ = 0x00050002;
9898}
9899
9900void TitleChunkParse::setTitleChunk(SizeChunk* chunk) {
9901 chunk_ = chunk;
9902}
9903
9904bool TitleChunkParse::parse() {
9905 Block* dataBlock = chunk_->getDataBlock();
9906 unsigned int blockSize = chunk_->getSizeBlock()->toSize();
9907 StreamHandle handle(dataBlock->data(), blockSize);
9908 Block typeBlock;
9909 unsigned int titleType;
9910
9911 handle_ = &handle;
9912
9913 if( !readBuffer(typeBlock, 4) ) { return false; }
9914
9915 titleType = typeBlock.toUnsignedInt();
9916
9917 if( titleType == titleType_ || titleType == annotateType_ || titleType == writerType_ || titleType == copyrightType_ ) {
9918 Block offsetBlock;
9919
9920 if( !readBuffer(offsetBlock, 4) ) { return false; }
9921
9922 const unsigned int itemCount = 4;
9923 unsigned int i;
9924
9925 for( i=0; i<itemCount; ++i ) {
9926 if( i>0 ) {
9927 //0x 00 AB 00 0C 00 00
9928 if( !jump(6) ) { return false; }
9929 }
9930
9931 Block countBlock;
9932 if( !readBuffer(countBlock, 2) ) { return false; }
9933 unsigned int titleSize = countBlock.toUnsignedInt();
9934
9935 Block dataBlock;
9936 if( !readBuffer(dataBlock, titleSize) ) { return false; }
9937
9938 QByteArray array((char*)dataBlock.data(), dataBlock.size());
9939 addToOve(ove_->getCodecString(array), titleType);
9940 }
9941
9942 return true;
9943 }
9944
9945 if( titleType == headerType_ || titleType == footerType_ ) {
9946 if( !jump(10) ) { return false; }
9947
9948 Block countBlock;
9949 if( !readBuffer(countBlock, 2) ) { return false; }
9950 unsigned int titleSize = countBlock.toUnsignedInt();
9951
9952 Block dataBlock;
9953 if( !readBuffer(dataBlock, titleSize) ) { return false; }
9954
9955 QByteArray array((char*)dataBlock.data(), dataBlock.size());
9956 addToOve(ove_->getCodecString(array), titleType);
9957
9958 //0x 00 AB 00 0C 00 00
9959 if( !jump(6) ) { return false; }
9960
9961 return true;
9962 }
9963
9964 return false;
9965}
9966
9967void TitleChunkParse::addToOve(const QString& str, unsigned int titleType) {
9968 if( str.isEmpty() ) { return; }
9969
9970 if (titleType == titleType_) {
9971 ove_->addTitle(str);
9972 }
9973
9974 if (titleType == annotateType_) {
9975 ove_->addAnnotate(str);
9976 }
9977
9978 if (titleType == writerType_) {
9979 ove_->addWriter(str);
9980 }
9981
9982 if (titleType == copyrightType_) {
9983 ove_->addCopyright(str);
9984 }
9985
9986 if (titleType == headerType_) {
9987 ove_->addHeader(str);
9988 }
9989
9990 if (titleType == footerType_) {
9991 ove_->addFooter(str);
9992 }
9993}
9994
9995// OveOrganize.cpp
9996OveOrganizer::OveOrganizer(OveSong* ove) {
9997 ove_ = ove;
9998}
9999
10000void OveOrganizer::organize() {
10001 if(ove_ == NULL) {
10002 return;
10003 }
10004
10005 organizeTracks();
10006 organizeAttributes();
10007 organizeMeasures();
10008}
10009
10010void OveOrganizer::organizeAttributes() {
10011 int i;
10012 int j;
10013 int k;
10014
10015 // key
10016 if(ove_->getLineCount() > 0) {
10017 Line* line = ove_->getLine(0);
10018 int partBarCount = ove_->getPartBarCount();
10019 int lastKey = 0;
10020
10021 if(line != 0){
10022 for(i=0; i<line->getStaffCount(); ++i) {
10023 QPair<int, int> partStaff = ove_->trackToPartStaff(i);
10024 Staff* staff = line->getStaff(i);
10025 lastKey = staff->getKeyType();
10026
10027 for(j=0; j<partBarCount; ++j) {
10028 MeasureData* measureData = ove_->getMeasureData(partStaff.first, partStaff.second, j);
10029
10030 if(measureData != 0) {
10031 Key* key = measureData->getKey();
10032
10033 if( j==0 ) {
10034 key->setKey(lastKey);
10035 key->setPreviousKey(lastKey);
10036 }
10037
10038 if( !key->getSetKey() ) {
10039 key->setKey(lastKey);
10040 key->setPreviousKey(lastKey);
10041 }
10042 else {
10043 if( key->getKey() != lastKey ) {
10044 lastKey = key->getKey();
10045 }
10046 }
10047 }
10048 }
10049 }
10050 }
10051 }
10052
10053 // clef
10054 if( ove_->getLineCount() > 0 ) {
10055 Line* line = ove_->getLine(0);
10056 int partBarCount = ove_->getPartBarCount();
10057 ClefType lastClefType = Clef_Treble;
10058
10059 if(line != 0){
10060 for( i=0; i<line->getStaffCount(); ++i ) {
10061 QPair<int, int> partStaff = ove_->trackToPartStaff(i);
10062 Staff* staff = line->getStaff(i);
10063 lastClefType = staff->getClefType();
10064
10065 for( j=0; j<partBarCount; ++j ) {
10066 MeasureData* measureData = ove_->getMeasureData(partStaff.first, partStaff.second, j);
10067
10068 if(measureData != 0) {
10069 Clef* clefPtr = measureData->getClef();
10070 clefPtr->setClefType((int)lastClefType);
10071
10072 const QList<MusicData*>& clefs = measureData->getMusicDatas(MusicData_Clef);
10073
10074 for( k=0; k<clefs.size(); ++k ) {
10075 Clef* clef = static_cast<Clef*>(clefs[k]);
10076 lastClefType = clef->getClefType();
10077 }
10078 }
10079 }
10080 }
10081 }
10082 }
10083}
10084
10085Staff* getStaff(OveSong* ove, int track) {
10086 if (ove->getLineCount() > 0) {
10087 Line* line = ove->getLine(0);
10088 if(line != 0 && line->getStaffCount() > 0) {
10089 Staff* staff = line->getStaff(track);
10090 return staff;
10091 }
10092 }
10093
10094 return 0;
10095}
10096
10097void OveOrganizer::organizeTracks() {
10098 int i;
10099 //QList<QPair<ClefType, int> > trackChannels;
10100 QList<Track*> tracks = ove_->getTracks();
10101 QList<bool> comboStaveStarts;
10102
10103 for( i=0; i<tracks.size(); ++i ) {
10104 comboStaveStarts.push_back(false);
10105 }
10106
10107 for( i=0; i<tracks.size(); ++i ) {
10108 Staff* staff = getStaff(ove_, i);
10109 if(staff != 0) {
10110 if(staff->getGroupType() == Group_Brace && staff->getGroupStaffCount() == 1 ) {
10111 comboStaveStarts[i] = true;
10112 }
10113 }
10114
10115 /*if( i < tracks.size() - 1 ) {
10116 if( tracks[i]->getStartClef() == Clef_Treble &&
10117 tracks[i+1]->getStartClef() == Clef_Bass &&
10118 tracks[i]->getChannel() == tracks[i+1]->get_channel() ) {
10119 }
10120 }*/
10121 }
10122
10123 int trackId = 0;
10124 QList<int> partStaffCounts;
10125
10126 while( trackId < (int)tracks.size() ) {
10127 int partTrackCount = 1;
10128
10129 if( comboStaveStarts[trackId] ) {
10130 partTrackCount = 2;
10131 }
10132
10133 partStaffCounts.push_back(partTrackCount);
10134 trackId += partTrackCount;
10135 }
10136
10137 ove_->setPartStaffCounts(partStaffCounts);
10138}
10139
10140void OveOrganizer::organizeMeasures() {
10141 int trackBarCount = ove_->getTrackBarCount();
10142
10143 for( int i=0; i<ove_->getPartCount(); ++i ) {
10144 int partStaffCount = ove_->getStaffCount(i);
10145
10146 for( int j=0; j<partStaffCount; ++j ) {
10147 for( int k=0; k<trackBarCount; ++k ) {
10148 Measure* measure = ove_->getMeasure(k);
10149 MeasureData* measureData = ove_->getMeasureData(i, j, k);
10150
10151 organizeMeasure(i, j, measure, measureData);
10152 }
10153 }
10154 }
10155}
10156
10157void OveOrganizer::organizeMeasure(int part, int track, Measure* measure, MeasureData* measureData) {
10158 // note containers
10159 organizeContainers(part, track, measure, measureData);
10160
10161 // single end data
10162 organizeMusicDatas(part, track, measure, measureData);
10163
10164 // cross measure elements
10165 organizeCrossMeasureElements(part, track, measure, measureData);
10166}
10167
10168void addToList(QList<int>& list, int number) {
10169 for(int i=0; i<list.size(); ++i){
10170 if(list[i] == number){
10171 return;
10172 }
10173 }
10174
10175 list.push_back(number);
10176}
10177
10178void OveOrganizer::organizeContainers(int /*part*/, int /*track*/,
10179 Measure* measure, MeasureData* measureData)
10180{
10181 int i;
10182 QList<NoteContainer*> containers = measureData->getNoteContainers();
10183 int barUnits = measure->getTime()->getUnits();
10184 QList<int> voices;
10185
10186 for(i=0; i<containers.size(); ++i){
10187 int endUnit = barUnits;
10188 if( i < containers.size() - 1 ) {
10189 endUnit = containers[i+1]->start()->getOffset();
10190 }
10191
10192 containers[i]->stop()->setOffset(endUnit);
10193 addToList(voices, containers[i]->getVoice());
10194 }
10195
10196 // shift voices
10197 qSort(voices.begin(), voices.end());
10198
10199 for (i = 0; i < voices.size(); ++i) {
10200 int voice = voices[i];
10201 // voice -> i
10202 for(int j=0; j<(int)containers.size(); ++j) {
10203 int avoice = containers[j]->getVoice();
10204 if ( avoice == voice && avoice != i ) {
10205 containers[j]->setVoice(i);
10206 }
10207 }
10208 }
10209}
10210
10211void OveOrganizer::organizeMusicDatas(int /*part*/, int /*track*/, Measure* measure, MeasureData* measureData) {
10212 int i;
10213 int barIndex = measure->getBarNumber()->getIndex();
10214 QList<MusicData*> datas = measureData->getMusicDatas(MusicData_None);
10215
10216 for(i=0; i<datas.size(); ++i) {
10217 datas[i]->start()->setMeasure(barIndex);
10218 }
10219}
10220
10221void OveOrganizer::organizeCrossMeasureElements(int part, int track, Measure* measure, MeasureData* measureData)
10222{
10223 int i;
10224 QList<MusicData*> pairs = measureData->getCrossMeasureElements(MusicData_None, MeasureData::PairType_Start);
10225
10226 for(i=0; i<pairs.size(); ++i) {
10227 MusicData* pair = pairs[i];
10228
10229 switch ( pair->getMusicDataType() ) {
10230 case MusicData_Beam :
10231 case MusicData_Glissando :
10232 case MusicData_Slur :
10233 case MusicData_Tie :
10234 case MusicData_Tuplet :
10235 case MusicData_Pedal :
10236 case MusicData_Numeric_Ending :
10237 //case MusicData_OctaveShift_EndPoint :
10238 case MusicData_Measure_Repeat : {
10239 organizePairElement(pair, part, track, measure, measureData);
10240 break;
10241 }
10242 case MusicData_OctaveShift : {
10243 OctaveShift* octave = static_cast<OctaveShift*>(pair);
10244 organizeOctaveShift(octave, measure, measureData);
10245 break;
10246 }
10247 case MusicData_Wedge : {
10248 Wedge* wedge = static_cast<Wedge*>(pair);
10249 organizeWedge(wedge, part, track, measure, measureData);
10250 break;
10251 }
10252 default:
10253 break;
10254 }
10255 }
10256}
10257
10258void OveOrganizer::organizePairElement(
10259 MusicData* data,
10260 int part,
10261 int track,
10262 Measure* measure,
10263 MeasureData* measureData) {
10264 int bar1Index = measure->getBarNumber()->getIndex();
10265 int bar2Index = bar1Index + data->stop()->getMeasure();
10266 MeasureData* measureData2 = ove_->getMeasureData(part, track, bar2Index);
10267
10268 data->start()->setMeasure(bar1Index);
10269
10270 if(measureData2 != 0 && measureData != measureData2) {
10271 measureData2->addCrossMeasureElement(data, false);
10272 }
10273
10274 if( data->getMusicDataType() == MusicData_Tuplet ){
10275 Tuplet* tuplet = static_cast<Tuplet*>(data);
10276 const QList<NoteContainer*> containers = measureData->getNoteContainers();
10277
10278 for(int i=0; i<containers.size(); ++i){
10279 if(containers[i]->getTick() > tuplet->getTick()){
10280 break;
10281 }
10282
10283 if(containers[i]->getTick() == tuplet->getTick()){
10284 tuplet->setNoteType(containers[i]->getNoteType());
10285 }
10286 }
10287
10288 int tupletTick = NoteTypeToTick(tuplet->getNoteType(), ove_->getQuarter())*tuplet->getSpace();
10289 if( tuplet->getTick() % tupletTick != 0 ) {
10290 int newStartTick = (tuplet->getTick() / tupletTick) * tupletTick;
10291
10292 for(int i=0; i<containers.size(); ++i){
10293 if( containers[i]->getTick() == newStartTick &&
10294 containers[i]->getTuplet() == tuplet->getTuplet()) {
10295 tuplet->setTick(containers[i]->getTick());
10296 tuplet->start()->setOffset(containers[i]->start()->getOffset());
10297 }
10298 }
10299 }
10300 }
10301}
10302
10303void OveOrganizer::organizeOctaveShift(
10304 OctaveShift* octave,
10305 Measure* measure,
10306 MeasureData* measureData)
10307{
10308 // octave shift
10309 int i;
10310 const QList<NoteContainer*> containers = measureData->getNoteContainers();
10311 int barIndex = measure->getBarNumber()->getIndex();
10312
10313 octave->start()->setMeasure(barIndex);
10314
10315 for(i=0; i<containers.size(); ++i) {
10316 int noteShift = octave->getNoteShift();
10317 int containerTick = containers[i]->getTick();
10318
10319 if( octave->getTick() <= containerTick && octave->getEndTick() > containerTick ) {
10320 containers[i]->setNoteShift(noteShift);
10321 }
10322 }
10323}
10324
10325bool getMiddleUnit(
10326 OveSong* ove, int /*part*/, int /*track*/,
10327 Measure* measure1, Measure* measure2, int unit1, int /*unit2*/,
10328 Measure* middleMeasure, int& middleUnit) {
10329 QList<int> barUnits;
10330 int i;
10331 int bar1Index = measure1->getBarNumber()->getIndex();
10332 int bar2Index = measure2->getBarNumber()->getIndex();
10333 int sumUnit = 0;
10334
10335 for( int j=bar1Index; j<=bar2Index; ++j ) {
10336 Measure* measure = ove->getMeasure(j);
10337 barUnits.push_back(measure->getTime()->getUnits());
10338 sumUnit += measure->getTime()->getUnits();
10339 }
10340
10341 int currentSumUnit = 0;
10342 for( i=0; i<barUnits.size(); ++i ) {
10343 int barUnit = barUnits[i];
10344
10345 if( i==0 ) {
10346 barUnit = barUnits[i] - unit1;
10347 }
10348
10349 if( currentSumUnit + barUnit < sumUnit/2 ) {
10350 currentSumUnit += barUnit;
10351 }
10352 else {
10353 break;
10354 }
10355 }
10356
10357 if( i < barUnits.size() ) {
10358 int barMiddleIndex = bar1Index + i;
10359 middleMeasure = ove->getMeasure(barMiddleIndex);
10360 middleUnit = sumUnit/2 - currentSumUnit;
10361
10362 return true;
10363 }
10364
10365 return false;
10366}
10367
10368void OveOrganizer::organizeWedge(Wedge* wedge, int part, int track, Measure* measure, MeasureData* measureData) {
10369 int bar1Index = measure->getBarNumber()->getIndex();
10370 int bar2Index = bar1Index + wedge->stop()->getMeasure();
10371 MeasureData* measureData2 = ove_->getMeasureData(part, track, bar2Index);
10372 WedgeType wedgeType = wedge->getWedgeType();
10373
10374 if( wedge->getWedgeType() == Wedge_Double_Line ) {
10375 wedgeType = Wedge_Cres_Line;
10376 }
10377
10378 wedge->start()->setMeasure(bar1Index);
10379
10380 WedgeEndPoint* startPoint = new WedgeEndPoint();
10381 measureData->addMusicData(startPoint);
10382
10383 startPoint->setTick(wedge->getTick());
10384 startPoint->start()->setOffset(wedge->start()->getOffset());
10385 startPoint->setWedgeStart(true);
10386 startPoint->setWedgeType(wedgeType);
10387 startPoint->setHeight(wedge->getHeight());
10388
10389 WedgeEndPoint* stopPoint = new WedgeEndPoint();
10390
10391 stopPoint->setTick(wedge->getTick());
10392 stopPoint->start()->setOffset(wedge->stop()->getOffset());
10393 stopPoint->setWedgeStart(false);
10394 stopPoint->setWedgeType(wedgeType);
10395 stopPoint->setHeight(wedge->getHeight());
10396
10397 if(measureData2 != 0) {
10398 measureData2->addMusicData(stopPoint);
10399 }
10400
10401 if( wedge->getWedgeType() == Wedge_Double_Line ) {
10402 Measure* middleMeasure = NULL;
10403 int middleUnit = 0;
10404
10405 getMiddleUnit(
10406 ove_, part, track,
10407 measure, ove_->getMeasure(bar2Index),
10408 wedge->start()->getOffset(), wedge->stop()->getOffset(),
10409 middleMeasure, middleUnit);
10410
10411 if( middleMeasure != 0 ) {
10412 WedgeEndPoint* midStopPoint = new WedgeEndPoint();
10413 measureData->addMusicData(midStopPoint);
10414
10415 midStopPoint->setTick(wedge->getTick());
10416 midStopPoint->start()->setOffset(middleUnit);
10417 midStopPoint->setWedgeStart(false);
10418 midStopPoint->setWedgeType(Wedge_Cres_Line);
10419 midStopPoint->setHeight(wedge->getHeight());
10420
10421 WedgeEndPoint* midStartPoint = new WedgeEndPoint();
10422 measureData->addMusicData(midStartPoint);
10423
10424 midStartPoint->setTick(wedge->getTick());
10425 midStartPoint->start()->setOffset(middleUnit);
10426 midStartPoint->setWedgeStart(true);
10427 midStartPoint->setWedgeType(Wedge_Decresc_Line);
10428 midStartPoint->setHeight(wedge->getHeight());
10429 }
10430 }
10431}
10432
10433
10434// OveSerialize.cpp
10435enum ChunkType {
10436 Chunk_OVSC = 00 ,
10437 Chunk_TRKL,
10438 Chunk_TRAK,
10439 Chunk_PAGL,
10440 Chunk_PAGE,
10441 Chunk_LINL,
10442 Chunk_LINE,
10443 Chunk_STAF,
10444 Chunk_BARL,
10445 Chunk_MEAS,
10446 Chunk_COND,
10447 Chunk_BDAT,
10448 Chunk_PACH,
10449 Chunk_FNTS,
10450 Chunk_ODEV,
10451 Chunk_TITL,
10452 Chunk_ALOT,
10453 Chunk_ENGR,
10454 Chunk_FMAP,
10455 Chunk_PCPR,
10456
10457 // Overture 3.6
10458 Chunk_LYRC,
10459
10460 Chunk_NONE
10461};
10462
10463ChunkType nameToChunkType(const NameBlock& name) {
10464 ChunkType type = Chunk_NONE;
10465
10466 if (name.isEqual("OVSC")) {
10467 type = Chunk_OVSC;
10468 } else if (name.isEqual("TRKL")) {
10469 type = Chunk_TRKL;
10470 } else if (name.isEqual("TRAK")) {
10471 type = Chunk_TRAK;
10472 } else if (name.isEqual("PAGL")) {
10473 type = Chunk_PAGL;
10474 } else if (name.isEqual("PAGE")) {
10475 type = Chunk_PAGE;
10476 } else if (name.isEqual("LINL")) {
10477 type = Chunk_LINL;
10478 } else if (name.isEqual("LINE")) {
10479 type = Chunk_LINE;
10480 } else if (name.isEqual("STAF")) {
10481 type = Chunk_STAF;
10482 } else if (name.isEqual("BARL")) {
10483 type = Chunk_BARL;
10484 } else if (name.isEqual("MEAS")) {
10485 type = Chunk_MEAS;
10486 } else if (name.isEqual("COND")) {
10487 type = Chunk_COND;
10488 } else if (name.isEqual("BDAT")) {
10489 type = Chunk_BDAT;
10490 } else if (name.isEqual("PACH")) {
10491 type = Chunk_PACH;
10492 } else if (name.isEqual("FNTS")) {
10493 type = Chunk_FNTS;
10494 } else if (name.isEqual("ODEV")) {
10495 type = Chunk_ODEV;
10496 } else if (name.isEqual("TITL")) {
10497 type = Chunk_TITL;
10498 } else if (name.isEqual("ALOT")) {
10499 type = Chunk_ALOT;
10500 } else if (name.isEqual("ENGR")) {
10501 type = Chunk_ENGR;
10502 } else if (name.isEqual("FMAP")) {
10503 type = Chunk_FMAP;
10504 } else if (name.isEqual("PCPR")) {
10505 type = Chunk_PCPR;
10506 } else if (name.isEqual("LYRC")) {
10507 type = Chunk_LYRC;
10508 }
10509
10510 return type;
10511}
10512
10513int chunkTypeToMaxTimes(ChunkType type) {
10514 int maxTimes = -1; // no limit
10515
10516 switch (type) {
10517 case Chunk_OVSC: {
10518 maxTimes = 1;
10519 break;
10520 }
10521 case Chunk_TRKL: {// case Chunk_TRAK :
10522 maxTimes = 1;
10523 break;
10524 }
10525 case Chunk_PAGL: {// case Chunk_PAGE :
10526 maxTimes = 1;
10527 break;
10528 }
10529// case Chunk_LINE :
10530// case Chunk_STAF :
10531 case Chunk_LINL: {
10532 maxTimes = 1;
10533 break;
10534 }
10535// case Chunk_MEAS :
10536// case Chunk_COND :
10537// case Chunk_BDAT :
10538 case Chunk_BARL: {
10539 maxTimes = 1;
10540 break;
10541 }
10542 case Chunk_PACH:
10543 case Chunk_FNTS:
10544 case Chunk_ODEV:
10545 case Chunk_ALOT:
10546 case Chunk_ENGR:
10547 case Chunk_FMAP:
10548 case Chunk_PCPR: {
10549 maxTimes = 1;
10550 break;
10551 }
10552 case Chunk_TITL: {
10553 maxTimes = 8;
10554 break;
10555 }
10556 case Chunk_LYRC: {
10557 maxTimes = 1;
10558 break;
10559 }
10560// case Chunk_NONE :
10561 default:
10562 break;
10563 }
10564
10565 return maxTimes;
10566}
10567
10569
10570OveSerialize::OveSerialize() :
10571 ove_(0),
10572 streamHandle_(0),
10573 notify_(0) {
10574}
10575
10576OveSerialize::~OveSerialize() {
10577 if(streamHandle_ != 0) {
10578 delete streamHandle_;
10579 streamHandle_ = 0;
10580 }
10581}
10582
10583void OveSerialize::setOve(OveSong* ove) {
10584 ove_ = ove;
10585}
10586
10587void OveSerialize::setFileStream(unsigned char* buffer, unsigned int size) {
10588 streamHandle_ = new StreamHandle(buffer, size);
10589}
10590
10591void OveSerialize::setNotify(IOveNotify* notify) {
10592 notify_ = notify;
10593}
10594
10595void OveSerialize::messageOutError() {
10596 if (notify_ != NULL) {
10597 notify_->loadError();
10598 }
10599}
10600
10601void OveSerialize::messageOut(const QString& str) {
10602 if (notify_ != NULL) {
10603 notify_->loadInfo(str);
10604 }
10605}
10606
10607bool OveSerialize::load(void) {
10608 if(streamHandle_ == 0)
10609 return false;
10610
10611 if( !readHeader() ) {
10612 messageOutError();
10613 return false;
10614 }
10615
10616 unsigned int i;
10617 QMap<ChunkType, int> chunkTimes;
10618 //bool firstEnter = true;
10619
10620 for( i=(int)Chunk_OVSC; i<(int)Chunk_NONE; ++i ) {
10621 chunkTimes[(ChunkType)i] = 0;
10622 }
10623
10624 ChunkType chunkType = Chunk_NONE;
10625
10626 do {
10627 NameBlock nameBlock;
10628 SizeChunk sizeChunk;
10629
10630 if( !readNameBlock(nameBlock) ) { return false; }
10631
10632 chunkType = nameToChunkType(nameBlock);
10633 ++chunkTimes[chunkType];
10634 int maxTime = chunkTypeToMaxTimes(chunkType);
10635
10636 if( maxTime > 0 && chunkTimes[chunkType] > maxTime ) {
10637 messageOut("format not support, chunk appear more than accept.");
10638 return false;
10639 }
10640
10641 switch (chunkType) {
10642 /*case Chunk_OVSC :
10643 {
10644 if( !readHeadData(&sizeChunk) )
10645 {
10646 messageOut_error();
10647 return false;
10648 }
10649
10650 break;
10651 }*/
10652 case Chunk_TRKL: {
10653 if (!readTracksData()) {
10654 messageOutError();
10655 return false;
10656 }
10657
10658 break;
10659 }
10660 case Chunk_PAGL: {
10661 if (!readPagesData()) {
10662 messageOutError();
10663 return false;
10664 }
10665
10666 break;
10667 }
10668 case Chunk_LINL: {
10669 if (!readLinesData()) {
10670 messageOutError();
10671 return false;
10672 }
10673
10674 break;
10675 }
10676 case Chunk_BARL: {
10677 if (!readBarsData()) {
10678 messageOutError();
10679 return false;
10680 }
10681
10682 break;
10683 }
10684 case Chunk_TRAK:
10685 case Chunk_PAGE:
10686 case Chunk_LINE:
10687 case Chunk_STAF:
10688 case Chunk_MEAS:
10689 case Chunk_COND:
10690 case Chunk_BDAT: {
10691 return false;
10692 break;
10693 }
10694 case Chunk_LYRC: {
10695 SizeChunk lyricChunk;
10696 if (!readSizeChunk(&lyricChunk)) {
10697 messageOutError();
10698 return false;
10699 }
10700
10701 LyricChunkParse parse(ove_);
10702
10703 parse.setLyricChunk(&lyricChunk);
10704 parse.parse();
10705
10706 break;
10707 }
10708 case Chunk_TITL: {
10709 SizeChunk titleChunk;
10710 if (!readSizeChunk(&titleChunk)) {
10711 messageOutError();
10712 return false;
10713 }
10714
10715 TitleChunkParse titleChunkParse(ove_);
10716
10717 titleChunkParse.setTitleChunk(&titleChunk);
10718 titleChunkParse.parse();
10719
10720 break;
10721 }
10722 case Chunk_PACH:
10723 case Chunk_FNTS:
10724 case Chunk_ODEV:
10725 case Chunk_ALOT:
10726 case Chunk_ENGR:
10727 case Chunk_FMAP:
10728 case Chunk_PCPR: {
10729 if (!readSizeChunk(&sizeChunk)) {
10730 messageOutError();
10731 return false;
10732 }
10733
10734 break;
10735 }
10736 default:
10737 /*if( firstEnter )
10738 {
10739 QString info = "Not compatible file, try to load and save with newer version, Overture 4 is recommended.";
10740 messageOut(info);
10741 messageOutError();
10742
10743 return false;
10744 }*/
10745
10746 break;
10747 }
10748
10749 //firstEnter = false;
10750 }
10751 while ( chunkType != Chunk_NONE );
10752
10753// if( !readOveEnd() ) { return false; }
10754
10755 // organize OveData
10756 OVE::OveOrganizer organizer(ove_);
10757 organizer.organize();
10758
10759 return true;
10760}
10761
10762void OveSerialize::release() {
10763 delete this;
10764}
10765
10766bool OveSerialize::readHeader() {
10767 ChunkType chunkType = Chunk_NONE;
10768 NameBlock nameBlock;
10769 SizeChunk sizeChunk;
10770
10771 if (!readNameBlock(nameBlock)) {
10772 return false;
10773 }
10774
10775 chunkType = nameToChunkType(nameBlock);
10776 //int maxTime = chunkTypeToMaxTimes(chunkType);
10777
10778 if (chunkType == Chunk_OVSC) {
10779 if (readHeadData(&sizeChunk)) {
10780 return true;
10781 }
10782 }
10783
10784 QString info = "Not compatible file, try to load and save with newer version, Overture 4 is recommended.";
10785 messageOut(info);
10786
10787 return false;
10788}
10789
10790bool OveSerialize::readHeadData(SizeChunk* ovscChunk) {
10791 if (!readSizeChunk(ovscChunk))
10792 return false;
10793
10794 OvscParse ovscParse(ove_);
10795
10796 ovscParse.setNotify(notify_);
10797 ovscParse.setOvsc(ovscChunk);
10798
10799 return ovscParse.parse();
10800}
10801
10802bool OveSerialize::readTracksData() {
10803 GroupChunk trackGroupChunk;
10804
10805 if (!readGroupChunk(&trackGroupChunk))
10806 return false;
10807
10808 unsigned int i;
10809 unsigned short trackCount = trackGroupChunk.getCountBlock()->toCount();
10810
10811 for (i = 0; i < trackCount; ++i) {
10812 SizeChunk* trackChunk = new SizeChunk();
10813
10814 if (ove_->getIsVersion4()) {
10815 if (!readChunkName(trackChunk, Chunk::TrackName)) {
10816 return false;
10817 }
10818 if (!readSizeChunk(trackChunk)) {
10819 return false;
10820 }
10821 } else {
10822 if (!readDataChunk(trackChunk->getDataBlock(),
10823 SizeChunk::version3TrackSize)) {
10824 return false;
10825 }
10826 }
10827
10828 TrackParse trackParse(ove_);
10829
10830 trackParse.setTrack(trackChunk);
10831 trackParse.parse();
10832 }
10833
10834 return true;
10835}
10836
10837bool OveSerialize::readPagesData() {
10838 GroupChunk pageGroupChunk;
10839
10840 if (!readGroupChunk(&pageGroupChunk))
10841 return false;
10842
10843 unsigned short pageCount = pageGroupChunk.getCountBlock()->toCount();
10844 unsigned int i;
10845 PageGroupParse parse(ove_);
10846
10847 for (i = 0; i < pageCount; ++i) {
10848 SizeChunk* pageChunk = new SizeChunk();
10849
10850 if (!readChunkName(pageChunk, Chunk::PageName)) {
10851 return false;
10852 }
10853 if (!readSizeChunk(pageChunk)) {
10854 return false;
10855 }
10856
10857 parse.addPage(pageChunk);
10858 }
10859
10860 if (!parse.parse()) {
10861 return false;
10862 }
10863
10864 return true;
10865}
10866
10867bool OveSerialize::readLinesData() {
10868 GroupChunk lineGroupChunk;
10869 if (!readGroupChunk(&lineGroupChunk))
10870 return false;
10871
10872 unsigned short lineCount = lineGroupChunk.getCountBlock()->toCount();
10873 int i;
10874 unsigned int j;
10875 QList<SizeChunk*> lineChunks;
10876 QList<SizeChunk*> staffChunks;
10877
10878 for (i = 0; i < lineCount; ++i) {
10879 SizeChunk* lineChunk = new SizeChunk();
10880
10881 if (!readChunkName(lineChunk, Chunk::LineName)) {
10882 return false;
10883 }
10884 if (!readSizeChunk(lineChunk)) {
10885 return false;
10886 }
10887
10888 lineChunks.push_back(lineChunk);
10889
10890 StaffCountGetter getter(ove_);
10891 unsigned int staffCount = getter.getStaffCount(lineChunk);
10892
10893 for (j = 0; j < staffCount; ++j) {
10894 SizeChunk* staffChunk = new SizeChunk();
10895
10896 if (!readChunkName(staffChunk, Chunk::StaffName)) {
10897 return false;
10898 }
10899 if (!readSizeChunk(staffChunk)) {
10900 return false;
10901 }
10902
10903 staffChunks.push_back(staffChunk);
10904 }
10905 }
10906
10907 LineGroupParse parse(ove_);
10908
10909 parse.setLineGroup(&lineGroupChunk);
10910
10911 for (i = 0; i < lineChunks.size(); ++i) {
10912 parse.addLine(lineChunks[i]);
10913 }
10914
10915 for (i = 0; i < staffChunks.size(); ++i) {
10916 parse.addStaff(staffChunks[i]);
10917 }
10918
10919 if (!parse.parse()) {
10920 return false;
10921 }
10922
10923 return true;
10924}
10925
10926bool OveSerialize::readBarsData() {
10927 GroupChunk barGroupChunk;
10928 if (!readGroupChunk(&barGroupChunk))
10929 return false;
10930
10931 unsigned short measCount = barGroupChunk.getCountBlock()->toCount();
10932 int i;
10933
10934 QList<SizeChunk*> measureChunks;
10935 QList<SizeChunk*> conductChunks;
10936 QList<SizeChunk*> bdatChunks;
10937
10938 ove_->setTrackBarCount(measCount);
10939
10940 // read chunks
10941 for (i = 0; i < measCount; ++i) {
10942 SizeChunk* measureChunkPtr = new SizeChunk();
10943
10944 if (!readChunkName(measureChunkPtr, Chunk::MeasureName)) {
10945 return false;
10946 }
10947 if (!readSizeChunk(measureChunkPtr)) {
10948 return false;
10949 }
10950
10951 measureChunks.push_back(measureChunkPtr);
10952 }
10953
10954 for (i = 0; i < measCount; ++i) {
10955 SizeChunk* conductChunkPtr = new SizeChunk();
10956
10957 if (!readChunkName(conductChunkPtr, Chunk::ConductName))
10958 return false;
10959
10960 if (!readSizeChunk(conductChunkPtr))
10961 return false;
10962
10963 conductChunks.push_back(conductChunkPtr);
10964 }
10965
10966 int bdatCount = ove_->getTrackCount() * measCount;
10967 for (i = 0; i < bdatCount; ++i) {
10968 SizeChunk* batChunkPtr = new SizeChunk();
10969
10970 if (!readChunkName(batChunkPtr, Chunk::BdatName)) {
10971 return false;
10972 }
10973 if (!readSizeChunk(batChunkPtr)) {
10974 return false;
10975 }
10976
10977 bdatChunks.push_back(batChunkPtr);
10978 }
10979
10980 // parse bars
10981 BarsParse barsParse(ove_);
10982
10983 for (i = 0; i < (int) measureChunks.size(); ++i) {
10984 barsParse.addMeasure(measureChunks[i]);
10985 }
10986
10987 for (i = 0; i < (int) conductChunks.size(); ++i) {
10988 barsParse.addConduct(conductChunks[i]);
10989 }
10990
10991 for (i = 0; i < (int) bdatChunks.size(); ++i) {
10992 barsParse.addBdat(bdatChunks[i]);
10993 }
10994
10995 barsParse.setNotify(notify_);
10996 if (!barsParse.parse()) {
10997 return false;
10998 }
10999
11000 return true;
11001}
11002
11003bool OveSerialize::readOveEnd() {
11004 if (streamHandle_ == 0)
11005 return false;
11006
11007 const unsigned int END_OVE1 = 0xffffffff;
11008 const unsigned int END_OVE2 = 0x00000000;
11009 unsigned int buffer;
11010
11011 if (!streamHandle_->read((char*) &buffer, sizeof(unsigned int)))
11012 return false;
11013
11014 if (buffer != END_OVE1)
11015 return false;
11016
11017 if (!streamHandle_->read((char*) &buffer, sizeof(unsigned int)))
11018 return false;
11019
11020 if (buffer != END_OVE2)
11021 return false;
11022
11023 return true;
11024}
11025
11027bool OveSerialize::readNameBlock(NameBlock& nameBlock) {
11028 if (streamHandle_ == 0)
11029 return false;
11030
11031 if (!streamHandle_->read((char*) nameBlock.data(), nameBlock.size()))
11032 return false;
11033
11034 return true;
11035}
11036
11037bool OveSerialize::readChunkName(Chunk* /*chunk*/, const QString& name) {
11038 if (streamHandle_ == 0)
11039 return false;
11040
11041 NameBlock nameBlock;
11042
11043 if (!streamHandle_->read((char*) nameBlock.data(), nameBlock.size()))
11044 return false;
11045
11046 if (!(nameBlock.toStrByteArray() == name))
11047 return false;
11048
11049 return true;
11050}
11051
11052bool OveSerialize::readSizeChunk(SizeChunk* sizeChunk) {
11053 if (streamHandle_ == 0)
11054 return false;
11055
11056 SizeBlock* sizeBlock = sizeChunk->getSizeBlock();
11057
11058 if (!streamHandle_->read((char*) sizeBlock->data(), sizeBlock->size()))
11059 return false;
11060
11061 unsigned int blockSize = sizeBlock->toSize();
11062
11063 sizeChunk->getDataBlock()->resize(blockSize);
11064
11065 Block* dataBlock = sizeChunk->getDataBlock();
11066
11067 if (!streamHandle_->read((char*) dataBlock->data(), blockSize))
11068 return false;
11069
11070 return true;
11071}
11072
11073bool OveSerialize::readDataChunk(Block* block, unsigned int size) {
11074 if (streamHandle_ == 0)
11075 return false;
11076
11077 block->resize(size);
11078
11079 if (!streamHandle_->read((char*) block->data(), size))
11080 return false;
11081
11082 return true;
11083}
11084
11085bool OveSerialize::readGroupChunk(GroupChunk* groupChunk) {
11086 if (streamHandle_ == 0)
11087 return false;
11088
11089 CountBlock* countBlock = groupChunk->getCountBlock();
11090
11091 if (!streamHandle_->read((char*) countBlock->data(), countBlock->size()))
11092 return false;
11093
11094 return true;
11095}
11096
11097IOVEStreamLoader* createOveStreamLoader() {
11098 return new OveSerialize;
11099}
11100
11101} // end of OVE namespace
11102
11104namespace drumstick {
11105
11120class MeasureToTick {
11121public:
11122 MeasureToTick();
11123 virtual ~MeasureToTick() {
11124 }
11125
11126public:
11127 void build(OVE::OveSong* ove, int quarter);
11128
11129 struct TimeTick {
11130 int numerator_;
11131 int denominator_;
11132 int measure_;
11133 int tick_;
11134
11135 TimeTick() :
11136 numerator_(4), denominator_(4), measure_(0), tick_(0) {
11137 }
11138 };
11139 int getTick(int measure, int tickOffset);
11140 QList<TimeTick> getTimeTicks() const;
11141
11142private:
11143 int quarter_;
11144 OVE::OveSong* ove_;
11145
11146 QList<TimeTick> tts_;
11147};
11148
11149int getMeasureTick(int quarter, int num, int den) {
11150 return quarter * 4 * num / den;
11151}
11152
11153MeasureToTick::MeasureToTick() {
11154 quarter_ = 480;
11155 ove_ = NULL;
11156}
11157
11158void MeasureToTick::build(OVE::OveSong* ove, int quarter) {
11159 unsigned int i;
11160 int currentTick = 0;
11161 unsigned int measureCount = ove->getMeasureCount();
11162
11163 quarter_ = quarter;
11164 ove_ = ove;
11165 tts_.clear();
11166
11167 for (i = 0; i < measureCount; ++i) {
11168 OVE::Measure* measure = ove_->getMeasure(i);
11169 OVE::TimeSignature* time = measure->getTime();
11170 TimeTick tt;
11171 bool change = false;
11172
11173 tt.tick_ = currentTick;
11174 tt.numerator_ = time->getNumerator();
11175 tt.denominator_ = time->getDenominator();
11176 tt.measure_ = i;
11177
11178 if (i == 0) {
11179 change = true;
11180 } else {
11181 OVE::TimeSignature* previousTime = ove_->getMeasure(i - 1)->getTime();
11182
11183 if (time->getNumerator() != previousTime->getNumerator()
11184 || time->getDenominator() != previousTime->getDenominator()) {
11185 change = true;
11186 }
11187 }
11188
11189 if (change) {
11190 tts_.push_back(tt);
11191 }
11192
11193 currentTick += getMeasureTick(quarter_, tt.numerator_, tt.denominator_);
11194 }
11195}
11196
11197int MeasureToTick::getTick(int measure, int tickOffset) {
11198 int i;
11199 TimeTick tt;
11200
11201 for (i = 0; i < tts_.size(); ++i) {
11202 if (measure >= tts_[i].measure_ && (i == tts_.size() - 1 || measure < tts_[i + 1].measure_)) {
11203 int measuresTick = (measure - tts_[i].measure_) *
11204 getMeasureTick(quarter_, tts_[i].numerator_, tts_[i].denominator_);
11205
11206 return tts_[i].tick_ + measuresTick + tickOffset;
11207 }
11208 }
11209
11210 return 0;
11211}
11212
11213QList<MeasureToTick::TimeTick> MeasureToTick::getTimeTicks() const {
11214 return tts_;
11215}
11216
11218class QOve::QOvePrivate {
11219public:
11220 QOvePrivate() {}
11221
11222 ~QOvePrivate() {}
11223
11224 OVE::OveSong ove;
11225 MeasureToTick mtt;
11226};
11227
11232 QObject(parent),
11233 d(new QOvePrivate)
11234{
11235}
11236
11241 delete d;
11242}
11243
11249void QOve::setTextCodecName(const QString& codec) {
11250 d->ove.setTextCodecName(codec);
11251}
11252
11258void QOve::readFromFile(const QString& fileName) {
11259 QFile oveFile(fileName);
11260 bool success = true;
11261
11262 if (oveFile.open(QFile::ReadOnly)) {
11263 QByteArray buffer = oveFile.readAll();
11264
11265 oveFile.close();
11266 d->ove.clear();
11267
11268 // ove -> OveSong
11269 OVE::IOVEStreamLoader* oveLoader = OVE::createOveStreamLoader();
11270
11271 oveLoader->setOve(&d->ove);
11272 oveLoader->setFileStream((unsigned char*) buffer.data(), buffer.size());
11273 oveLoader->setNotify(0);
11274 bool result = oveLoader->load();
11275 oveLoader->release();
11276
11277 if(!result)
11278 success = false;
11279
11280 if (result) {
11281 convertSong();
11282 }
11283 }
11284
11285 if (!success) {
11286 Q_EMIT signalOVEError(
11287 "Cannot read this OVE file, "
11288 "probably because it has an incompatible format.\n"
11289 "Please, convert it using Overture 4 or a newer version.");
11290 }
11291}
11292
11293void QOve::convertSong() {
11294 unsigned int i;
11295 int trackNo = 0;
11296
11297 d->mtt.build(&d->ove, d->ove.getQuarter());
11298
11299 Q_EMIT signalOVEHeader(d->ove.getQuarter(), d->ove.getTrackCount());
11300
11301 convertSignatures();
11302
11303 for (i = 0; i < (unsigned int) d->ove.getPartCount(); ++i) {
11304 int partStaffCount = d->ove.getStaffCount(i);
11305
11306 for (int j = 0; j < partStaffCount; ++j) {
11307 OVE::Track* trackPtr = d->ove.getTrack(i, j);
11308 int transpose = trackPtr->getShowTranspose() ? trackPtr->getTranspose() : 0;
11309
11310 convertTrackHeader(trackPtr, trackNo);
11311
11312 //int beginMeasure = 0;
11313 int endMeasure = d->ove.getMeasureCount();
11314 int offsetTick = 0;
11315
11316 for (int l = 0; l < endMeasure; ++l) {
11317 OVE::Measure* measure = d->ove.getMeasure(l);
11318 OVE::MeasureData* measureData = d->ove.getMeasureData(i, j, l);
11319
11320/* if (notify_ != NULL) {
11321 notify_->notify_convert_pos(l, endMeasure, trackID, d->ove_.getPartCount());
11322 }*/
11323
11324 convertMeasure(trackPtr, trackNo, trackPtr->getVoices(), measure, measureData, transpose, offsetTick);
11325 }
11326
11327 ++trackNo;
11328 }
11329 }
11330
11331 Q_EMIT signalOVEEnd();
11332}
11333
11334void QOve::convertSignatures() {
11335 int i;
11336 int beginMeasure = 0;
11337 int endMeasure = d->ove.getMeasureCount();
11338
11339 // tempo
11340 QMap<int, int> tempos;
11341 for (i = 0; i < d->ove.getPartCount(); ++i) {
11342 if(i>0) {
11343 break;
11344 }
11345
11346 int partStaffCount = d->ove.getStaffCount(i);
11347
11348 for (int j = 0; j < partStaffCount; ++j) {
11349 if(j>0) {
11350 break;
11351 }
11352
11353 for (int k = beginMeasure; k < endMeasure; ++k) {
11354 OVE::Measure* measure = d->ove.getMeasure(k);
11355 OVE::MeasureData* measureData = d->ove.getMeasureData(i, j, k);
11356 QList<OVE::MusicData*> tempoPtrs = measureData->getMusicDatas(OVE::MusicData_Tempo);
11357
11358 if (k == 0 || (k > 0 && std::abs(measure->getTypeTempo() - d->ove.getMeasure(k - 1)->getTypeTempo()) > 0.01)) {
11359 int tick = d->mtt.getTick(k, 0);
11360 int tempo = (int) measure->getTypeTempo();
11361 tempos[tick] = tempo;
11362 }
11363
11364 for (int l = 0; l < tempoPtrs.size(); ++l) {
11365 OVE::Tempo* ptr = static_cast<OVE::Tempo*> (tempoPtrs[l]);
11366 int tick = d->mtt.getTick(measure->getBarNumber()->getIndex(), ptr->getTick());
11367 int tempo = ptr->getQuarterTempo() > 0 ? ptr->getQuarterTempo() : 1;
11368
11369 tempos[tick] = tempo;
11370 }
11371 }
11372 }
11373 }
11374
11375 QMap<int, int>::iterator it;
11376 int lastTempo = 0;
11377 for (it = tempos.begin(); it != tempos.end(); ++it) {
11378 if (it == tempos.begin() || it.value() != lastTempo) {
11379 Q_EMIT signalOVETempo(it.key(), it.value()*100);
11380 }
11381
11382 lastTempo = it.value();
11383 }
11384
11385 // time signature
11386 const QList<MeasureToTick::TimeTick> tts = d->mtt.getTimeTicks();
11387 for (i = 0; i < (int) tts.size(); ++i) {
11388 if (beginMeasure <= tts[i].measure_ && endMeasure > tts[i].measure_) {
11389 Q_EMIT signalOVETimeSig(tts[i].measure_, tts[i].tick_, tts[i].numerator_, tts[i].denominator_);
11390 }
11391 }
11392
11393 // key signature
11394 bool createKey = false;
11395 for (i = beginMeasure; i < endMeasure; ++i) {
11396 OVE::MeasureData* measureData = d->ove.getMeasureData(0, 0, i);
11397
11398 if (measureData != NULL) {
11399 OVE::Key* keyPtr = measureData->getKey();
11400
11401 if (i == 0 || keyPtr->getKey() != keyPtr->getPreviousKey()) {
11402 Q_EMIT signalOVEKeySig(i, d->mtt.getTick(i, 0), keyPtr->getKey());
11403
11404 createKey = true;
11405 }
11406 }
11407 }
11408
11409 if (!createKey) {
11410 Q_EMIT signalOVEKeySig(0, 0, 0);
11411 }
11412}
11413
11414void QOve::convertTrackHeader(OVE::Track* track, int trackNo) {
11415 int i;
11416 const QList<OVE::Voice*> voices = track->getVoices();
11417 QMap<int, int> patches; // channel, patch
11418 QMap<int, int> pans; // channel, pan
11419 QMap<int, int> volumes; // channel, volume
11420 QMap<int, int>::iterator it;
11421 int ch = 0;
11422 int vol = 100;
11423 int patch = 0;
11424
11425 // name
11426 QString trackName = track->getName();
11427
11428 // patch, pan(control 10), volume(control 7)
11429 for (i = 0; i < voices.size() && i < (unsigned int)track->getVoiceCount(); ++i) {
11430 int patch = voices[i]->getPatch();
11431 int channel = voices[i]->getChannel();
11432 int volume = voices[i]->getVolume();
11433
11434 if (patch != OVE::Voice::getDefaultPatch()) {
11435 patches[channel] = patch;
11436 }
11437
11438 pans[channel] = voices[i]->getPan();
11439
11440 if (volume != OVE::Voice::getDefaultVolume()) {
11441 volumes[channel] = volume;
11442 }
11443
11444 ch = channel;
11445 vol = volume;
11446 }
11447
11448 // patch
11449 for (it = patches.begin(); it != patches.end(); ++it) {
11450 patch = it.value();
11451 break;
11452 }
11453
11454 // pan
11455 int lastPan = 64;//center
11456 for (it = pans.begin(); it != pans.end(); ++it) {
11457 if (it.value() != 0 && it.value() != lastPan) {
11458 Q_EMIT signalOVECtlChange(trackNo, 0, ch, 10, it.value());
11459 }
11460
11461 lastPan = it.value();
11462 }
11463
11464 // volume
11465 for (it = volumes.begin(); it != volumes.end(); ++it) {
11466 int volume = it.value();
11467 if (volume != -1) {
11468 Q_EMIT signalOVECtlChange(trackNo, 0, ch, 7, it.value());
11469 }
11470 }
11471
11472 Q_EMIT signalOVENewTrack(track->getName(), trackNo, ch, 0, vol, 0, false, false, false);
11473 Q_EMIT signalOVETrackBank(trackNo, ch, 0);
11474 Q_EMIT signalOVETrackPatch(trackNo, ch, patch);
11475}
11476
11477int getPitchShift(const QList<OVE::Voice*>& voices, int voice) {
11478 if (voice >= 0 && voice < (int) voices.size())
11479 return voices[voice]->getPitchShift();
11480 return 0;
11481}
11482
11483int getChannel(const QList<OVE::Voice*>& voices, int voice) {
11484 if (voice >= 0 && voice < (int) voices.size())
11485 return voices[voice]->getChannel();
11486 return 0;
11487}
11488
11489int getTick(int tick) {
11490 if(tick > 0)
11491 return tick;
11492 return 0;
11493}
11494
11495void QOve::convertMeasure(
11496 OVE::Track* track, int trackNo, const QList<OVE::Voice*>& voices,
11497 OVE::Measure* measure, OVE::MeasureData* measureData, int transpose, int offsetTick)
11498{
11499 Q_UNUSED(track)
11500 int i;
11501 int measureId = measure->getBarNumber()->getIndex();
11502 QList<OVE::NoteContainer*> containers = measureData->getNoteContainers();
11503
11504 // midi notes
11505 for (i = 0; i < containers.size(); ++i) {
11506 OVE::NoteContainer* container = containers[i];
11507 int measureTick = d->mtt.getTick(measureId, 0);
11508 convertNotes(
11509 trackNo,
11510 measureTick,
11511 container,
11512 getChannel(voices, container->getVoice()),
11513 getPitchShift(voices, container->getVoice()) - transpose);
11514 }
11515
11516 // midi events in graph window
11517 QList<OVE::MidiData*> midiDatas = measureData->getMidiDatas(OVE::Midi_None);
11518 int channel = getChannel(voices, 0);
11519
11520 for (i = 0; i < midiDatas.size(); ++i) {
11521 OVE::MidiType midiType = midiDatas[i]->getMidiType();
11522 int midiTick = getTick(d->mtt.getTick(measureId, midiDatas[i]->getTick()) + offsetTick);
11523
11524 switch (midiType) {
11525 case OVE::Midi_Controller: {
11526 OVE::MidiController* controller = static_cast<OVE::MidiController*> (midiDatas[i]);
11527
11528 Q_EMIT signalOVECtlChange(trackNo, midiTick, channel, controller->getController(), controller->getValue());
11529
11530 break;
11531 }
11532 case OVE::Midi_Program_Change: {
11533 OVE::MidiProgramChange* program = static_cast<OVE::MidiProgramChange*> (midiDatas[i]);
11534
11535 Q_EMIT signalOVEProgram(trackNo, midiTick, channel, program->getPatch());
11536
11537 break;
11538 }
11539 case OVE::Midi_Channel_Pressure: {
11540 OVE::MidiChannelPressure* pressure = static_cast<OVE::MidiChannelPressure*> (midiDatas[i]);
11541
11542 Q_EMIT signalOVEChanPress(trackNo, midiTick, channel, pressure->getPressure());
11543
11544 break;
11545 }
11546 case OVE::Midi_Pitch_Wheel: {
11547 OVE::MidiPitchWheel* pitchWheel = static_cast<OVE::MidiPitchWheel*> (midiDatas[i]);
11548
11549 Q_EMIT signalOVEPitchBend(trackNo, midiTick, channel, pitchWheel->getValue());
11550
11551 break;
11552 }
11553 default:
11554 break;
11555 }
11556 }
11557
11558 // MusicData
11559 QList<OVE::MusicData*> musicDatas = measureData->getMusicDatas(OVE::MusicData_None);
11560
11561 for (i = 0; i < musicDatas.size(); ++i) {
11562 OVE::MusicDataType type = musicDatas[i]->getMusicDataType();
11563 int musicDataTick = getTick(d->mtt.getTick(measureId, musicDatas[i]->getTick()) + offsetTick);
11564
11565 switch (type) {
11566 case OVE::MusicData_Lyric: {
11567 OVE::Lyric* lyricPtr = static_cast<OVE::Lyric*> (musicDatas[i]);
11568
11569 Q_EMIT signalOVEText(trackNo, musicDataTick, lyricPtr->getLyric());
11570
11571 break;
11572 }
11573 case OVE::MusicData_Dynamics: {
11574 OVE::Dynamics* dynamicPtr = static_cast<OVE::Dynamics*> (musicDatas[i]);
11575
11576 Q_EMIT signalOVECtlChange(trackNo, musicDataTick, channel, 7, dynamicPtr->getVelocity());
11577
11578 break;
11579 }
11580 case OVE::MusicData_Decorator: {
11581 OVE::Decorator* decorator = static_cast<OVE::Decorator*> (musicDatas[i]);
11582
11583 if (decorator->getDecoratorType() == OVE::Decorator::Decorator_Articulation) {
11584 OVE::ArticulationType artType = decorator->getArticulationType();
11585
11586 switch (artType) {
11587 case OVE::Articulation_Pedal_Down: {
11588 Q_EMIT signalOVECtlChange(trackNo, musicDataTick, channel, 64, 64);
11589
11590 break;
11591 }
11592 case OVE::Articulation_Pedal_Up: {
11593 Q_EMIT signalOVECtlChange(trackNo, musicDataTick, channel, 64, 0);
11594
11595 break;
11596 }
11597 default:
11598 break;
11599 }
11600 }
11601
11602 break;
11603 }
11604 default:
11605 break;
11606 }
11607 }
11608}
11609
11610bool hasNoteOn(int pos) {
11611 return (pos & OVE::Tie_RightEnd) != OVE::Tie_RightEnd;
11612}
11613
11614bool hasNoteOff(int pos) {
11615 return (pos & OVE::Tie_LeftEnd) != OVE::Tie_LeftEnd;
11616}
11617
11618int noteTypeToTick(OVE::NoteType type, int quarter = 480) {
11619 int c = int(pow(2.0, (int) type));
11620 return quarter * 4 * 2 / c;
11621}
11622
11623void QOve::convertNotes(int trackNo, int measureTick, OVE::NoteContainer* container, int channel, int pitchShift)
11624{
11625 if (container->getIsRest()) {
11626 return;
11627 }
11628
11629 int i;
11630 int j;
11631 int k;
11632 QList<OVE::Note*> notes = container->getNotesRests();
11633 QList<OVE::Articulation*> articulations = container->getArticulations();
11634 bool changeNoteCount = false;
11635
11636 // for those who can change note numbers
11637 for (i = 0; i < articulations.size(); ++i) {
11638 OVE::Articulation* art = articulations[i];
11639 OVE::ArticulationType type = art->getArtType();
11640
11641 for (j = 0; j < notes.size(); ++j) {
11642 OVE::Note* notePtr = notes[j];
11643 unsigned int velocityValue = notePtr->getOnVelocity();
11644 int noteValue = notePtr->getNote() + container->getNoteShift() + pitchShift;
11645 int startTick = measureTick + container->getTick() + notePtr->getOffsetTick();
11646
11647 // note on
11648 if (hasNoteOn(notePtr->getTiePos())) {
11649 switch (type) {
11650 // tremolo
11651 case OVE::Articulation_Tremolo_Eighth:
11652 case OVE::Articulation_Tremolo_Sixteenth:
11653 case OVE::Articulation_Tremolo_Thirty_Second:
11654 case OVE::Articulation_Tremolo_Sixty_Fourth: {
11655 int noteCount = (int) pow(2.0, ((int) type - (int) OVE::Articulation_Tremolo_Eighth) + 1);
11656 int noteTick = noteTypeToTick(container->getNoteType(), d->ove.getQuarter()) / noteCount;
11657
11658 for (k = 0; k < noteCount; ++k) {
11659 // on
11660 int onTick = getTick(startTick + k * noteTick);
11661
11662 Q_EMIT signalOVENoteOn(trackNo, onTick, channel, noteValue, velocityValue);
11663
11664 if (k < noteCount - 1 || hasNoteOff((int) notePtr->getTiePos())) {
11665 // off
11666 int offTick = getTick(startTick + (k + 1) * noteTick);
11667
11668 Q_EMIT signalOVENoteOff(trackNo, offTick, channel, noteValue, velocityValue);
11669 }
11670 }
11671
11672 changeNoteCount = true;
11673
11674 break;
11675 }
11676 default:
11677 break;
11678 }
11679 }
11680 }
11681 }
11682
11683 if (changeNoteCount) {
11684 return;
11685 }
11686
11687 // others who can change note properties
11688 for (i = 0; i < notes.size(); ++i) {
11689 OVE::Note* notePtr = notes[i];
11690 unsigned int velocityValue = notePtr->getOnVelocity();
11691 int noteValue = notePtr->getNote() + container->getNoteShift() + pitchShift;
11692
11693 int startTick = getTick(measureTick + container->getTick() + notePtr->getOffsetTick());
11694 int lengthTick = container->getLength();
11695
11696 // note on
11697 if (hasNoteOn((int) notePtr->getTiePos())) {
11698 for (j = 0; j < articulations.size(); ++j) {
11699 OVE::Articulation* art = articulations[j];
11700 OVE::ArticulationType type = art->getArtType();
11701
11702 if (art->getChangeLength()) {
11703 lengthTick = noteTypeToTick(container->getNoteType(), d->ove.getQuarter()) * art->getLengthPercentage() / 100;
11704 }
11705
11706 if (art->getChangeVelocity()) {
11707 switch (art->getVelocityType()) {
11708 case OVE::Articulation::Velocity_Offset: {
11709 velocityValue += art->getVelocityValue();
11710 break;
11711 }
11712 case OVE::Articulation::Velocity_Percentage: {
11713 velocityValue *= (unsigned int) ((double) art->getVelocityValue() / (double) 100);
11714 break;
11715 }
11716 case OVE::Articulation::Velocity_SetValue: {
11717 velocityValue = art->getVelocityValue();
11718 break;
11719 }
11720 default:
11721 break;
11722 }
11723 }
11724
11725 if (art->getChangeExtraLength()) {
11726 }
11727
11728 switch (type) {
11729 case OVE::Articulation_Pedal_Down: {
11730 Q_EMIT signalOVECtlChange(trackNo, startTick, channel, 64, 64);
11731
11732 break;
11733 }
11734 case OVE::Articulation_Pedal_Up: {
11735 Q_EMIT signalOVECtlChange(trackNo, startTick, channel, 64, 0);
11736
11737 break;
11738 }
11739 case OVE::Articulation_Arpeggio: {
11740 //if( art->getChangeSoundEffect() ) {
11741 unsigned int soundEffect = std::abs(art->getSoundEffect().first) + std::abs(art->getSoundEffect().second);
11742 int tickAmount = (soundEffect / notes.size()) * ((notes.size() - i) - 1);
11743 startTick -= tickAmount;
11744 //}
11745
11746 break;
11747 }
11748 default:
11749 break;
11750 }
11751 }
11752
11753 Q_EMIT signalOVENoteOn(trackNo, getTick(startTick), channel, noteValue, velocityValue);
11754 }
11755
11756 // note off
11757 if (hasNoteOff(notePtr->getTiePos())) {
11758 Q_EMIT signalOVENoteOff(trackNo, getTick(startTick + lengthTick), channel, noteValue, velocityValue);
11759 }
11760 }
11761
11762 return;
11763}
11764
11765} // namespace drumstick
The QObject class is the base class of all Qt objects.
void signalOVENoteOn(int track, long tick, int channel, int pitch, int vol)
Emitted after reading a Note message.
void signalOVEHeader(int quarter, int trackCount)
Emitted after reading a WRK header.
void signalOVEText(int track, long tick, const QString &data)
Emitted after reading a text message.
void signalOVETrackPatch(int track, int channel, int patch)
Emitted after reading a track patch chunk.
void signalOVETimeSig(int bar, long tick, int num, int den)
Emitted after reading a Time signature.
void signalOVENewTrack(const QString &name, int track, int channel, int pitch, int velocity, int port, bool selected, bool muted, bool loop)
Emitted after reading a new track prefix.
QOve(QObject *parent=0)
Constructor.
Definition qove.cpp:11231
void signalOVEKeySig(int bar, long tick, int alt)
Emitted after reading a Key Signature.
void signalOVETrackBank(int track, int channel, int bank)
Emitted after reading a track bank chunk.
void signalOVETempo(long tick, int tempo)
Emitted after reading a Tempo Change message.
void signalOVEEnd()
Emitted after reading the last chunk of a OVE file.
void setTextCodecName(const QString &codec)
Sets the text codec for text meta-events.
Definition qove.cpp:11249
void readFromFile(const QString &fileName)
Reads an Overture file.
Definition qove.cpp:11258
virtual ~QOve()
Destructor.
Definition qove.cpp:11240
void signalOVEError(const QString &errorStr)
Emitted for a OVE file read error.
void signalOVEProgram(int track, long tick, int channel, int patch)
Emitted after reading a Program change message.
void signalOVECtlChange(int track, long tick, int channel, int ctl, int value)
Emitted after reading a Control Change message.
void signalOVEChanPress(int track, long tick, int channel, int press)
Emitted after reading a Channel Aftertouch message.
void signalOVEPitchBend(int track, long tick, int channel, int value)
Emitted after reading a Bender message.
Overture OVE Files Input.
#define lyric
SMF Lyric.
Definition qsmf.h:48