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