drumstick  0.5.0
qove.cpp
Go to the documentation of this file.
00001 /*
00002     Overture OVE File component
00003     Copyright (C) 2006-2010, Rui Fan <vanferry@gmail.com>
00004 
00005     This library is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License along
00016     with this program; if not, write to the Free Software Foundation, Inc.,
00017     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 */
00019 
00020 #include "qove.h"
00021 #include <QFile>
00022 #include <QIODevice>
00023 #include <QMap>
00024 #include <QPair>
00025 #include <QTextCodec>
00026 #include <QString>
00027 #include <QStringList>
00028 #include <cmath>
00029 #include <cstdlib>
00030 
00036 namespace OVE {
00037 
00038 class OveSong;
00039 class Track;
00040 class Page;
00041 class Voice;
00042 class Line;
00043 class Staff;
00044 class Measure;
00045 class MeasureData;
00046 class MusicData;
00047 class OffsetElement;
00048 class LineElement;
00049 class PairEnds;
00050 class Note;
00051 class NoteContainer;
00052 class Beam;
00053 class Tie;
00054 class Tuplet;
00055 class Harmony;
00056 class Clef;
00057 class Lyric;
00058 class Slur;
00059 class MeasureText;
00060 class Articulation;
00061 class Glissando;
00062 class Decorator;
00063 class MeasureRepeat;
00064 class Dynamics;
00065 class Wedge;
00066 class WedgeEndPoint;
00067 class Pedal;
00068 class KuoHao;
00069 class Expressions;
00070 class HarpPedal;
00071 class MultiMeasureRest;
00072 class OctaveShift;
00073 class OctaveShiftEndPoint;
00074 class BarNumber;
00075 class Tempo;
00076 class Text;
00077 class TimeSignature;
00078 class Key;
00079 class RepeatSymbol;
00080 class NumericEnding;
00081 class MidiData;
00082 class MidiController;
00083 class MidiProgramChange;
00084 class MidiChannelPressure;
00085 class MidiPitchWheel;
00086 
00087 const int TWELVE_TONE = 12 ;
00088 const int INVALID_NOTE = -1 ;
00089 const int OCTAVE = 7 ;
00090 
00091 enum CondType {
00092     Cond_Time_Parameters    = 0x09, // size - 7, TimeSignature
00093     Cond_Bar_Number         = 0x0A, // size, compatible with previous version
00094     Cond_Decorator          = 0x16,
00095     Cond_Tempo              = 0x1C, // size - 7
00096     Cond_Text               = 0x1D, // size - 7, Rehearsal | SystemText
00097     Cond_Expression         = 0x25, // size - 7, if set playback parameters in Expression, will store in COND
00098     Cond_Barline_Parameters = 0x30, // size - 7, include :|| repeat count
00099     Cond_Repeat             = 0x31, //
00100     Cond_Numeric_Ending     = 0x32, //
00101 
00102     Cond_None
00103 };
00104 
00105 enum BdatType {
00106     Bdat_Raw_Note               = 0x70,
00107     Bdat_Rest                   = 0x80,
00108     Bdat_Note                   = 0x90,
00109     Bdat_Beam                   = 0x10,
00110     Bdat_Harmony                = 0x11,
00111     Bdat_Clef                   = 0x12,
00112     Bdat_Dynamics               = 0x13,
00113     Bdat_Wedge                  = 0x14, // cresendo, decresendo
00114     Bdat_Glissando              = 0x15,
00115     Bdat_Decorator              = 0x16, // measure repeat | piano pedal | dotted barline
00116     Bdat_Key                    = 0x17,
00117     Bdat_Lyric                  = 0x18,
00118     Bdat_Octave_Shift           = 0x19,
00119     Bdat_Slur                   = 0x1B,
00120     Bdat_Text                   = 0x1D,
00121     Bdat_Tie                    = 0x1E,
00122     Bdat_Tuplet                 = 0x1F,
00123     Bdat_Guitar_Bend            = 0x21, //
00124     Bdat_Guitar_Barre           = 0x22, //
00125     Bdat_Pedal                  = 0x23,
00126     Bdat_KuoHao                 = 0x24, // () [] {}
00127     Bdat_Expressions            = 0x25,
00128     Bdat_Harp_Pedal             = 0x26,
00129     Bdat_Multi_Measure_Rest     = 0x27,
00130     Bdat_Harmony_GuitarFrame    = 0x28,
00131     Bdat_Graphics_40            = 0x40, // unknown
00132     Bdat_Graphics_RoundRect     = 0x41,
00133     Bdat_Graphics_Rect          = 0x42,
00134     Bdat_Graphics_Round         = 0x43,
00135     Bdat_Graphics_Line          = 0x44,
00136     Bdat_Graphics_Curve         = 0x45,
00137     Bdat_Graphics_WedgeSymbol   = 0x46,
00138     Bdat_Midi_Controller        = 0xAB,
00139     Bdat_Midi_Program_Change    = 0xAC,
00140     Bdat_Midi_Channel_Pressure  = 0xAD,
00141     Bdat_Midi_Pitch_Wheel       = 0xAE,
00142     Bdat_Bar_End                = 0xFF,
00143 
00144     Bdat_None
00145 };
00146 
00148 
00149 enum MusicDataType {
00150     // attributes
00151     MusicData_Clef,
00152     MusicData_Key,
00153     MusicData_Measure_Repeat,
00154 
00155     // sound
00156     MusicData_Tempo,
00157 
00158     // direction
00159     MusicData_Dynamics,
00160     MusicData_Wedge,
00161     MusicData_Wedge_EndPoint,
00162     MusicData_OctaveShift,
00163     MusicData_OctaveShift_EndPoint,
00164     MusicData_Expressions,
00165     MusicData_Repeat,
00166     MusicData_Text,
00167     MusicData_Harp_Pedal,
00168     MusicData_Pedal,
00169 
00170     // note & harmony
00171     MusicData_Note_Container,
00172     MusicData_Harmony,
00173 
00174     // note's children
00175     MusicData_Beam,
00176     MusicData_Glissando,
00177     MusicData_Lyric,
00178     MusicData_Slur,
00179     MusicData_Tie,
00180     MusicData_Tuplet,
00181 
00182     // barline
00183     MusicData_Numeric_Ending,
00184 
00185     MusicData_KuoHao,
00186     MusicData_Bar_End,
00187     MusicData_Decorator,
00188     MusicData_Multi_Measure_Rest,
00189 
00190     MusicData_None
00191 };
00192 
00193 enum MidiType {
00194     Midi_Controller = 0,
00195     Midi_Program_Change,
00196     Midi_Channel_Pressure,
00197     Midi_Pitch_Wheel,
00198 
00199     Midi_None
00200 };
00201 
00202 enum ClefType {
00203     Clef_Treble = 0x00, //0x00
00204     Clef_Bass,          //0x01
00205     Clef_Alto,          //0x02
00206     Clef_UpAlto,        //0x03
00207     Clef_DownDownAlto,  //0x04
00208     Clef_DownAlto,      //0x05
00209     Clef_UpUpAlto,      //0x06
00210     Clef_Treble8va,     //0x07
00211     Clef_Bass8va,       //0x08
00212     Clef_Treble8vb,     //0x09
00213     Clef_Bass8vb,       //0x0A
00214     Clef_Percussion1,   //0x0B
00215     Clef_Percussion2,   //0x0C
00216     Clef_TAB            //0x0D
00217 };
00218 
00219 enum GroupType {
00220     Group_None = 0,
00221     Group_Brace,
00222     Group_Bracket
00223 };
00224 
00225 enum AccidentalType {
00226     Accidental_Normal               = 0x0,
00227     Accidental_Sharp                = 0x1,
00228     Accidental_Flat                 = 0x2,
00229     Accidental_Natural              = 0x3,
00230     Accidental_DoubleSharp          = 0x4,
00231     Accidental_DoubleFlat           = 0x5,
00232     Accidental_Sharp_Caution        = 0x9,
00233     Accidental_Flat_Caution         = 0xA,
00234     Accidental_Natural_Caution      = 0xB,
00235     Accidental_DoubleSharp_Caution  = 0xC,
00236     Accidental_DoubleFlat_Caution   = 0xD
00237 };
00238 
00239 enum NoteHeadType {
00240     NoteHead_Standard   = 0x00,
00241     NoteHead_Invisible,
00242     NoteHead_Rhythmic_Slash,
00243     NoteHead_Percussion,
00244     NoteHead_Closed_Rhythm,
00245     NoteHead_Open_Rhythm,
00246     NoteHead_Closed_Slash,
00247     NoteHead_Open_Slash,
00248     NoteHead_Closed_Do,
00249     NoteHead_Open_Do,
00250     NoteHead_Closed_Re,
00251     NoteHead_Open_Re,
00252     NoteHead_Closed_Mi,
00253     NoteHead_Open_Mi,
00254     NoteHead_Closed_Fa,
00255     NoteHead_Open_Fa,
00256     NoteHead_Closed_Sol,
00257     NoteHead_Open_Sol,
00258     NoteHead_Closed_La,
00259     NoteHead_Open_La,
00260     NoteHead_Closed_Ti,
00261     NoteHead_Open_Ti
00262 };
00263 
00264 enum TiePos {
00265     Tie_None        = 0x0,
00266     Tie_LeftEnd     = 0x1,
00267     Tie_RightEnd    = 0x2
00268 };
00269 
00270 enum ArticulationType {
00271     Articulation_Major_Trill            = 0x00,
00272     Articulation_Minor_Trill            = 0x01,
00273     Articulation_Trill_Section          = 0x02,
00274     Articulation_Inverted_Short_Mordent = 0x03,
00275     Articulation_Inverted_Long_Mordent  = 0x04,
00276     Articulation_Short_Mordent          = 0x05,
00277     Articulation_Turn                   = 0x06,
00278     Articulation_Finger_1               = 0x07,
00279     Articulation_Finger_2               = 0x08,
00280     Articulation_Finger_3               = 0x09,
00281     Articulation_Finger_4               = 0x0A,
00282     Articulation_Finger_5               = 0x0B,
00283     Articulation_Flat_Accidental_For_Trill = 0x0C,
00284     Articulation_Sharp_Accidental_For_Trill = 0x0D,
00285     Articulation_Natural_Accidental_For_Trill = 0x0E,
00286     Articulation_Marcato                = 0x0F,
00287     Articulation_Marcato_Dot            = 0x10,
00288     Articulation_Heavy_Attack           = 0x11,
00289     Articulation_SForzando              = 0x12,
00290     Articulation_SForzando_Dot          = 0x13,
00291     Articulation_Heavier_Attack         = 0x14,
00292     Articulation_SForzando_Inverted     = 0x15,
00293     Articulation_SForzando_Dot_Inverted = 0x16,
00294     Articulation_Staccatissimo          = 0x17,
00295     Articulation_Staccato               = 0x18,
00296     Articulation_Tenuto                 = 0x19,
00297     Articulation_Up_Bow                 = 0x1A,
00298     Articulation_Down_Bow               = 0x1B,
00299     Articulation_Up_Bow_Inverted        = 0x1C,
00300     Articulation_Down_Bow_Inverted      = 0x1D,
00301     Articulation_Arpeggio               = 0x1E,
00302     Articulation_Tremolo_Eighth         = 0x1F,
00303     Articulation_Tremolo_Sixteenth      = 0x20,
00304     Articulation_Tremolo_Thirty_Second  = 0x21,
00305     Articulation_Tremolo_Sixty_Fourth   = 0x22,
00306     Articulation_Natural_Harmonic       = 0x23,
00307     Articulation_Artificial_Harmonic    = 0x24,
00308     Articulation_Plus_Sign              = 0x25,
00309     Articulation_Fermata                = 0x26,
00310     Articulation_Fermata_Inverted       = 0x27,
00311     Articulation_Pedal_Down             = 0x28,
00312     Articulation_Pedal_Up               = 0x29,
00313     Articulation_Pause                  = 0x2A,
00314     Articulation_Grand_Pause            = 0x2B,
00315     Articulation_Toe_Pedal              = 0x2C,
00316     Articulation_Heel_Pedal             = 0x2D,
00317     Articulation_Toe_To_Heel_Pedal      = 0x2E,
00318     Articulation_Heel_To_Toe_Pedal      = 0x2F,
00319     Articulation_Open_String            = 0x30, // finger 0 in guitar
00320     Articulation_Guitar_Lift            = 0x46,
00321     Articulation_Guitar_Slide_Up        = 0x47,
00322     Articulation_Guitar_Rip             = 0x48,
00323     Articulation_Guitar_Fall_Off        = 0x49,
00324     Articulation_Guitar_Slide_Down      = 0x4A,
00325     Articulation_Guitar_Spill           = 0x4B,
00326     Articulation_Guitar_Flip            = 0x4C,
00327     Articulation_Guitar_Smear           = 0x4D,
00328     Articulation_Guitar_Bend            = 0x4E,
00329     Articulation_Guitar_Doit            = 0x4F,
00330     Articulation_Guitar_Plop            = 0x50,
00331     Articulation_Guitar_Wow_Wow         = 0x51,
00332     Articulation_Guitar_Thumb           = 0x64,
00333     Articulation_Guitar_Index_Finger    = 0x65,
00334     Articulation_Guitar_Middle_Finger   = 0x66,
00335     Articulation_Guitar_Ring_Finger     = 0x67,
00336     Articulation_Guitar_Pinky_Finger    = 0x68,
00337     Articulation_Guitar_Tap             = 0x69,
00338     Articulation_Guitar_Hammer          = 0x6A,
00339     Articulation_Guitar_Pluck           = 0x6B,
00340 
00341     Articulation_None
00342 
00343 /*  Articulation_Detached_Legato,
00344     Articulation_Spiccato,
00345     Articulation_Scoop,
00346     Articulation_Plop,
00347     Articulation_Doit,
00348     Articulation_Falloff,
00349     Articulation_Breath_Mark,
00350     Articulation_Caesura,*/
00351 };
00352 
00353 enum NoteType {
00354     Note_DoubleWhole= 0x0,
00355     Note_Whole      = 0x1,
00356     Note_Half       = 0x2,
00357     Note_Quarter    = 0x3,
00358     Note_Eight      = 0x4,
00359     Note_Sixteen    = 0x5,
00360     Note_32         = 0x6,
00361     Note_64         = 0x7,
00362     Note_128        = 0x8,
00363     Note_256        = 0x9,
00364 
00365     Note_None
00366 };
00367 
00368 inline int NoteTypeToTick(NoteType type, int quarter) {
00369     int c = int(pow(2.0, (int)type)) ;
00370     return quarter * 4 * 2 / c ;
00371 }
00372 
00373 enum HarmonyType {
00374     Harmony_maj = 0,
00375     Harmony_min,
00376     Harmony_aug,
00377     Harmony_dim,
00378     Harmony_dim7,
00379     Harmony_sus2,
00380     Harmony_sus4,
00381     Harmony_sus24,
00382     Harmony_add2,
00383     Harmony_add9,
00384     Harmony_omit3,
00385     Harmony_omit5,
00386     Harmony_2,
00387     Harmony_5,
00388     Harmony_6,
00389     Harmony_69,
00390     Harmony_7,
00391     Harmony_7b5,
00392     Harmony_7b9,
00393     Harmony_7s9,
00394     Harmony_7s11,
00395     Harmony_7b5s9,
00396     Harmony_7b5b9,
00397     Harmony_7b9s9,
00398     Harmony_7b9s11,
00399     Harmony_7sus4,
00400     Harmony_9,
00401     Harmony_9b5,
00402     Harmony_9s11,
00403     Harmony_9sus4,
00404     Harmony_11,
00405     Harmony_13,
00406     Harmony_13b5,
00407     Harmony_13b9,
00408     Harmony_13s9,
00409     Harmony_13s11,
00410     Harmony_13sus4,
00411     Harmony_min_add2,
00412     Harmony_min_add9,
00413     Harmony_min_maj7,
00414     Harmony_min6,
00415     Harmony_min6_add9,
00416     Harmony_min7,
00417     Harmony_min7b5,
00418     Harmony_min7_add4,
00419     Harmony_min7_add11,
00420     Harmony_min9,
00421     Harmony_min9_b5,
00422     Harmony_min9_maj7,
00423     Harmony_min11,
00424     Harmony_min13,
00425     Harmony_maj7,
00426     Harmony_maj7_b5,
00427     Harmony_maj7_s5,
00428     Harmony_maj7_69,
00429     Harmony_maj7_add9,
00430     Harmony_maj7_s11,
00431     Harmony_maj9,
00432     Harmony_maj9_sus4,
00433     Harmony_maj9_b5,
00434     Harmony_maj9_s5,
00435     Harmony_maj9_s11,
00436     Harmony_maj13,
00437     Harmony_maj13_b5,
00438     Harmony_maj13_b9,
00439     Harmony_maj13_b9b5,
00440     Harmony_maj13_s11,
00441     Harmony_aug7,
00442     Harmony_aug7_b9,
00443     Harmony_aug7_s9,
00444 
00445     Harmony_None
00446 };
00447 
00448 enum DynamicsType {
00449     Dynamics_pppp = 0,
00450     Dynamics_ppp,
00451     Dynamics_pp,
00452     Dynamics_p,
00453     Dynamics_mp,
00454     Dynamics_mf,
00455     Dynamics_f,
00456     Dynamics_ff,
00457     Dynamics_fff,
00458     Dynamics_ffff,
00459     Dynamics_sf,
00460     Dynamics_fz,
00461     Dynamics_sfz,
00462     Dynamics_sffz,
00463     Dynamics_fp,
00464     Dynamics_sfp
00465 };
00466 
00467 enum WedgeType {
00468     Wedge_Cres_Line = 0,    // <
00469     Wedge_Double_Line,      // <>, not appear in xml
00470     Wedge_Decresc_Line,     // >
00471     Wedge_Cres,             // cresc., not appear in xml, will create Expression
00472     Wedge_Decresc           // decresc., not appear in xml, will create Expression
00473 };
00474 
00475 enum KuoHaoType {
00476     KuoHao_Parentheses = 0,
00477     KuoHao_Brace,
00478     KuoHao_Bracket
00479 };
00480 
00481 enum OctaveShiftType {
00482     OctaveShift_8 = 0,
00483     OctaveShift_Minus_8,
00484     OctaveShift_15,
00485     OctaveShift_Minus_15
00486 };
00487 
00488 enum OctaveShiftPosition {
00489     OctavePosition_Start = 0 ,
00490     OctavePosition_Continue,
00491     OctavePosition_Stop
00492 };
00493 
00494 enum RepeatType {
00495     Repeat_Segno = 0,
00496     Repeat_Coda,
00497     Repeat_ToCoda,
00498     Repeat_DSAlCoda,
00499     Repeat_DSAlFine,
00500     Repeat_DCAlCoda,
00501     Repeat_DCAlFine,
00502     Repeat_Fine,
00503 
00504     Repeat_Null
00505 };
00506 
00507 enum BarlineType {
00508     Barline_Default = 0,    //0x00 will be | or final (at last measure)
00509     Barline_Double,         //0x01 ||
00510     Barline_RepeatLeft,     //0x02 ||:
00511     Barline_RepeatRight,    //0x03 :||
00512     Barline_Final,          //0x04
00513     Barline_Dashed,         //0x05
00514     Barline_Null            //0x06
00515 } ;
00516 
00517 enum NoteDuration {
00518     NoteDuration_256 = 15,
00519     NoteDuration_128 = NoteDuration_256 * 2,            // 30
00520     NoteDuration_64 = NoteDuration_128 * 2,             // 60
00521     NoteDuration_32 = NoteDuration_64 * 2,              // 120
00522     NoteDuration_16 = NoteDuration_32 * 2,              // 240
00523     NoteDuration_8 = NoteDuration_16 * 2,               // 480
00524     NoteDuration_4 = NoteDuration_8 * 2,                // 960
00525     NoteDuration_2 = NoteDuration_4 * 2,                // 1920
00526     NoteDuration_Whole = NoteDuration_2 * 2,            // 3840
00527     NoteDuration_Double_Whole = NoteDuration_Whole * 2  // 7680
00528 };
00529 
00530 enum ToneType {
00531     Tone_C = 0 ,
00532     Tone_D,
00533     Tone_E,
00534     Tone_F,
00535     Tone_G,
00536     Tone_A,
00537     Tone_B
00538 };
00539 
00540 enum KeyType {
00541     Key_C = 0,      // C
00542     Key_Bass_1,     // F
00543     Key_Bass_2,     // Bb
00544     Key_Bass_3,     // Eb
00545     Key_Bass_4,     // Ab
00546     Key_Bass_5,     // Db
00547     Key_Bass_6,     // Gb
00548     Key_Bass_7,     // Cb
00549     Key_Sharp_1,    // G
00550     Key_Sharp_2,    // D
00551     Key_Sharp_3,    // A
00552     Key_Sharp_4,    // E
00553     Key_Sharp_5,    // B
00554     Key_Sharp_6,    // F#
00555     Key_Sharp_7     // C#
00556 };
00557 
00558 // IOveNotify.h
00559 class IOveNotify {
00560 public:
00561     IOveNotify() {}
00562     virtual ~IOveNotify() {}
00563 
00564 public:
00565     virtual void loadInfo(const QString& info) = 0;
00566     virtual void loadError() = 0;
00567     virtual void loadPosition(int currentMeasure, int totalMeasure, int currentTrack, int totalTrack) = 0;
00568 };
00569 
00570 class IOVEStreamLoader {
00571 public:
00572     IOVEStreamLoader() {}
00573     virtual ~IOVEStreamLoader() {}
00574 
00575 public:
00576     virtual void setNotify(IOveNotify* notify) = 0;
00577     virtual void setFileStream(unsigned char* buffer, unsigned int size) = 0;
00578     virtual void setOve(OveSong* ove) = 0;
00579 
00580     // read stream, set readed data to setOve(ove)
00581     virtual bool load() = 0;
00582 
00583     virtual void release() = 0;
00584 };
00585 
00586 IOVEStreamLoader* createOveStreamLoader();
00587 
00589 // basic element
00590 class TickElement {
00591 public:
00592     TickElement();
00593     virtual ~TickElement() {}
00594 
00595 public:
00596     void setTick(int tick);
00597     int getTick(void) const;
00598 
00599 private:
00600     int tick_;
00601 };
00602 
00603 class MeasurePos {
00604 public:
00605     MeasurePos();
00606     virtual ~MeasurePos() {}
00607 
00608 public:
00609     void setMeasure(int measure);
00610     int getMeasure() const;
00611 
00612     void setOffset(int offset);
00613     int getOffset() const;
00614 
00615     MeasurePos shiftMeasure(int measure) const;
00616     MeasurePos shiftOffset(int offset) const; // ignore cross measure
00617 
00618     bool operator ==(const MeasurePos& mp) const;
00619     bool operator !=(const MeasurePos& mp) const;
00620     bool operator <(const MeasurePos& mp) const;
00621     bool operator <=(const MeasurePos& mp) const;
00622     bool operator >(const MeasurePos& mp) const;
00623     bool operator >=(const MeasurePos& mp) const;
00624 
00625 private:
00626     int measure_;
00627     int offset_;
00628 };
00629 
00630 class PairElement {
00631 public:
00632     PairElement();
00633     virtual ~PairElement();
00634 
00635 public:
00636     MeasurePos* start() const;
00637     MeasurePos* stop() const;
00638 
00639 private:
00640     MeasurePos* start_;
00641     MeasurePos* stop_;
00642 };
00643 
00644 class PairEnds {
00645 public:
00646     PairEnds();
00647     virtual ~PairEnds();
00648 
00649 public:
00650     LineElement* getLeftLine() const;
00651     LineElement* getRightLine() const;
00652 
00653     OffsetElement* getLeftShoulder() const;
00654     OffsetElement* getRightShoulder() const;
00655 
00656 private:
00657     LineElement* leftLine_;
00658     LineElement* rightLine_;
00659     OffsetElement* leftShoulder_;
00660     OffsetElement* rightShoulder_;
00661 };
00662 
00663 class LineElement {
00664 public:
00665     LineElement();
00666     virtual ~LineElement() {}
00667 
00668 public:
00669     virtual void setLine(int line); // middle line (3rd line of each clef) is set 0
00670     virtual int getLine(void) const;
00671 
00672 private:
00673     int line_;
00674 };
00675 
00676 class OffsetElement {
00677 public:
00678     OffsetElement();
00679     virtual ~OffsetElement() {}
00680 
00681 public:
00682     virtual void setXOffset(int offset);
00683     virtual int getXOffset() const;
00684 
00685     virtual void setYOffset(int offset);
00686     virtual int getYOffset() const;
00687 
00688 private:
00689     int xOffset_;
00690     int yOffset_;
00691 };
00692 
00693 class LengthElement {
00694 public:
00695     LengthElement();
00696     virtual ~LengthElement() {}
00697 
00698 public:
00699     void setLength(int length);
00700     int getLength() const;
00701 
00702 private:
00703     int length_; // tick
00704 };
00705 
00706 // base class of many ove music element
00707 class MusicData: public TickElement, public PairElement, public OffsetElement {
00708 public:
00709     MusicData();
00710     virtual ~MusicData() {}
00711 
00712 public:
00713     MusicDataType getMusicDataType() const;
00714 
00715     enum XmlDataType {
00716         Attributes = 0, NoteBeam, Notations, Direction, None
00717     };
00718     static XmlDataType getXmlDataType(MusicDataType type);
00719     //  static bool get_is_pair_element(MusicDataType type) ;
00720 
00721     // show / hide
00722     void setShow(bool show);
00723     bool getShow() const;
00724 
00725     // color
00726     void setColor(unsigned int color); // not exists in ove 3
00727     unsigned int getColor() const;
00728 
00729     void setVoice(unsigned int voice);
00730     unsigned int getVoice() const;
00731 
00732     void copyCommonBlock(const MusicData& source);
00733 
00734 protected:
00735     MusicDataType musicDataType_;
00736 
00737 private:
00738     bool show_;
00739     unsigned int color_;
00740     unsigned int voice_;
00741 };
00742 
00743 class MidiData: public TickElement {
00744 public:
00745     MidiData();
00746     virtual ~MidiData() {}
00747 
00748 public:
00749     MidiType getMidiType() const;
00750 
00751 protected:
00752     MidiType midiType_;
00753 };
00754 
00755 
00757 class OveSong {
00758 public:
00759     OveSong();
00760     ~OveSong();
00761 
00762 public:
00763     void setIsVersion4(bool version4 = true);
00764     bool getIsVersion4() const;
00765 
00766     void setQuarter(int tick);
00767     int getQuarter(void) const;
00768 
00769     void setShowPageMargin(bool show);
00770     bool getShowPageMargin() const;
00771 
00772     void setShowTransposeTrack(bool show);
00773     bool getShowTransposeTrack() const;
00774 
00775     void setShowLineBreak(bool show);
00776     bool getShowLineBreak() const;
00777 
00778     void setShowRuler(bool show);
00779     bool getShowRuler() const;
00780 
00781     void setShowColor(bool show);
00782     bool getShowColor() const;
00783 
00784     void setPlayRepeat(bool play);
00785     bool getPlayRepeat() const;
00786 
00787     enum PlayStyle{
00788         Record, Swing, Notation
00789     };
00790     void setPlayStyle(PlayStyle style);
00791     PlayStyle getPlayStyle() const;
00792 
00793     void addTitle(const QString& str);
00794     QList<QString> getTitles(void) const;
00795 
00796     void addAnnotate(const QString& str);
00797     QList<QString> getAnnotates(void) const;
00798 
00799     void addWriter(const QString& str);
00800     QList<QString> getWriters(void) const;
00801 
00802     void addCopyright(const QString& str);
00803     QList<QString> getCopyrights(void) const;
00804 
00805     void addHeader(const QString& str);
00806     QList<QString> getHeaders(void) const;
00807 
00808     void addFooter(const QString& str);
00809     QList<QString> getFooters(void) const;
00810 
00811     void addTrack(Track* ptr);
00812     int getTrackCount(void) const;
00813     QList<Track*> getTracks() const;
00814     Track* getTrack(int part, int staff) const;
00815 
00816     void setTrackBarCount(int count);
00817     int getTrackBarCount() const;
00818 
00819     bool addPage(Page* page);
00820     int getPageCount() const;
00821     Page* getPage(int idx);
00822 
00823     void addLine(Line* ptr);
00824     int getLineCount() const;
00825     Line* getLine(int idx) const;
00826 
00827     void addMeasure(Measure* ptr);
00828     int getMeasureCount(void) const;
00829     Measure* getMeasure(int bar) const;
00830 
00831     void addMeasureData(MeasureData* ptr);
00832     int getMeasureDataCount(void) const;
00833     MeasureData* getMeasureData(int part, int staff/*=0*/, int bar) const;
00834     MeasureData* getMeasureData(int track, int bar) const;
00835 
00836     // tool
00837     void setPartStaffCounts(const QList<int>& partStaffCounts);
00838     int getPartCount() const;
00839     int getStaffCount(int part) const;
00840     int getPartBarCount() const;
00841 
00842     void clear(void);
00843 
00844     QPair<int, int> trackToPartStaff(int track) const;
00845 
00846     void setTextCodecName(const QString& codecName);
00847     QString getCodecString(const QByteArray& text);
00848 
00849 private:
00850     int partStaffToTrack(int part, int staff) const;
00851 
00852 private:
00853     bool version4_;
00854     int quarter_;
00855 
00856     bool showPageMargin_;
00857     bool showTransposeTrack;
00858     bool showLineBreak_;
00859     bool showRuler_;
00860     bool showColor_;
00861     bool playRepeat_;
00862     PlayStyle playStyle_;
00863 
00864     QList<QString> titles_;
00865     QList<QString> annotates_;
00866     QList<QString> writers_;
00867     QList<QString> copyrights_;
00868     QList<QString> headers_;
00869     QList<QString> footers_;
00870 
00871     QList<Track*> tracks_;
00872     QList<Page*> pages_;
00873     QList<Line*> lines_;
00874     QList<Measure*> measures_;
00875     QList<MeasureData*> measureDatas_;
00876     int trackBarCount_; //equal to measures_.size()
00877 
00878     QList<int> partStaffCounts_;
00879     QTextCodec* codec_;
00880 };
00881 
00882 class Voice {
00883 public:
00884     Voice();
00885     ~Voice(){}
00886 
00887 public:
00888     void setChannel(int channel);
00889     int getChannel() const;
00890 
00891     void setVolume(int volume);
00892     int getVolume() const;
00893 
00894     void setPitchShift(int pitchShift);
00895     int getPitchShift() const;
00896 
00897     void setPan(int pan);
00898     int getPan() const;
00899 
00900     void setPatch(int patch);
00901     int getPatch() const;
00902 
00903     void setStemType(int stemType);
00904     int getStemType() const;
00905 
00906     static int getDefaultPatch();
00907     static int getDefaultVolume();
00908 
00909 private:
00910     int channel_;       // [0, 15]
00911     int volume_;        // [-1, 127], -1 default
00912     int pitchShift_;    // [-36, 36]
00913     int pan_;           // [-64, 63]
00914     int patch_;         // [0, 127]
00915     int stemType_;      // 0, 1, 2
00916 };
00917 
00918 class Track {
00919 public:
00920     Track();
00921     ~Track();
00922 
00923 public:
00924     void setName(const QString& str);
00925     QString getName(void) const;
00926 
00927     void setBriefName(const QString& str);
00928     QString getBriefName(void) const;
00929 
00930     void setPatch(unsigned int patch); // -1: percussion
00931     unsigned int getPatch() const;
00932 
00933     void setChannel(int channel);
00934     int getChannel() const;
00935 
00936     void setShowName(bool show);
00937     bool getShowName() const;
00938 
00939     void setShowBriefName(bool show);
00940     bool getShowBriefName() const;
00941 
00942     void setMute(bool mute);
00943     bool getMute() const;
00944 
00945     void setSolo(bool solo);
00946     bool getSolo() const;
00947 
00948     void setShowKeyEachLine(bool show);
00949     bool getShowKeyEachLine() const;
00950 
00951     void setVoiceCount(int voices);
00952     int getVoiceCount() const;
00953 
00954     void addVoice(Voice* voice);
00955     QList<Voice*> getVoices() const;
00956 
00957     void setShowTranspose(bool show);
00958     bool getShowTranspose() const;
00959 
00960     void setTranspose(int transpose);
00961     int getTranspose() const;
00962 
00963     void setNoteShift(int shift);
00964     int getNoteShift() const;
00965 
00966     void setStartClef(int clef/*in ClefType*/);
00967     ClefType getStartClef() const;
00968 
00969     void setTransposeClef(int clef);
00970     int getTansposeClef() const;
00971 
00972     void setStartKey(int key/*in KeyType*/);
00973     int getStartKey() const;
00974 
00975     void setDisplayPercent(unsigned int percent/*25~100*/);
00976     unsigned int getDisplayPercent() const;
00977 
00978     void setShowLegerLine(bool show);
00979     bool getShowLegerLine() const;
00980 
00981     void setShowClef(bool show);
00982     bool getShowClef() const;
00983 
00984     void setShowTimeSignature(bool show);
00985     bool getShowTimeSignature() const;
00986 
00987     void setShowKeySignature(bool show);
00988     bool getShowKeySignature() const;
00989 
00990     void setShowBarline(bool show);
00991     bool getShowBarline() const;
00992 
00993     void setFillWithRest(bool fill);
00994     bool getFillWithRest() const;
00995 
00996     void setFlatTail(bool flat);
00997     bool getFlatTail() const;
00998 
00999     void setShowClefEachLine(bool show);
01000     bool getShowClefEachLine() const;
01001 
01002     struct DrumNode {
01003         int line_;
01004         int headType_;
01005         int pitch_;
01006         int voice_;
01007 
01008     public:
01009         DrumNode():line_(0), headType_(0), pitch_(0), voice_(0){}
01010     };
01011     void addDrum(const DrumNode& node);
01012     QList<DrumNode> getDrumKit() const;
01013 
01014     void clear(void);
01015 
01017     void setPart(int part);
01018     int getPart() const;
01019 
01020 private:
01021     int number_;
01022     QString name_;
01023     QString briefName_;
01024     unsigned int patch_;
01025     int channel_;
01026     int transpose_;
01027     bool showTranspose_;
01028     int noteShift_;
01029     int startClef_;
01030     int transposeClef_;
01031     unsigned int displayPercent_;
01032     int startKey_;
01033     int voiceCount_;
01034     QList<Voice*> voices_;
01035 
01036     bool showName_;
01037     bool showBriefName_;
01038     bool showKeyEachLine_;
01039     bool showLegerLine_;
01040     bool showClef_;
01041     bool showTimeSignature_;
01042     bool showKeySignature_;
01043     bool showBarline_;
01044     bool showClefEachLine_;
01045 
01046     bool fillWithRest_;
01047     bool flatTail_;
01048 
01049     bool mute_;
01050     bool solo_;
01051 
01052     QList<DrumNode> drumKit_;
01053 
01055     int part_;
01056 };
01057 
01058 class Page {
01059 public:
01060     Page();
01061     ~Page(){}
01062 
01063 public:
01064     void setBeginLine(int line);
01065     int getBeginLine() const;
01066 
01067     void setLineCount(int count);
01068     int getLineCount() const;
01069 
01070     void setLineInterval(int interval); // between system
01071     int getLineInterval() const;
01072 
01073     void setStaffInterval(int interval);
01074     int getStaffInterval() const;
01075 
01076     void setStaffInlineInterval(int interval); // between treble-bass staff
01077     int getStaffInlineInterval() const;
01078 
01079     void setLineBarCount(int count);
01080     int getLineBarCount() const;
01081 
01082     void setPageLineCount(int count);
01083     int getPageLineCount() const;
01084 
01085     void setLeftMargin(int margin);
01086     int getLeftMargin() const;
01087 
01088     void setTopMargin(int margin);
01089     int getTopMargin() const;
01090 
01091     void setRightMargin(int margin);
01092     int getRightMargin() const;
01093 
01094     void setBottomMargin(int margin);
01095     int getBottomMargin() const;
01096 
01097     void setPageWidth(int width);
01098     int getPageWidth() const;
01099 
01100     void setPageHeight(int height);
01101     int getPageHeight() const;
01102 
01103 private:
01104     int beginLine_;
01105     int lineCount_;
01106 
01107     int lineInterval_;
01108     int staffInterval_;
01109     int staffInlineInterval_;
01110 
01111     int lineBarCount_;
01112     int pageLineCount_;
01113 
01114     int leftMargin_;
01115     int topMargin_;
01116     int rightMargin_;
01117     int bottomMargin_;
01118 
01119     int pageWidth_;
01120     int pageHeight_;
01121 };
01122 
01123 class Line {
01124 public:
01125     Line();
01126     ~Line();
01127 
01128 public:
01129     void addStaff(Staff* staff);
01130     int getStaffCount() const;
01131     Staff* getStaff(int idx) const;
01132 
01133     void setBeginBar(unsigned int bar);
01134     unsigned int getBeginBar() const;
01135 
01136     void setBarCount(unsigned int count);
01137     unsigned int getBarCount() const;
01138 
01139     void setYOffset(int offset);
01140     int getYOffset() const;
01141 
01142     void setLeftXOffset(int offset);
01143     int getLeftXOffset() const;
01144 
01145     void setRightXOffset(int offset);
01146     int getRightXOffset() const;
01147 
01148 private:
01149     QList<Staff*> staffs_;
01150     unsigned int beginBar_;
01151     unsigned int barCount_;
01152     int yOffset_;
01153     int leftXOffset_;
01154     int rightXOffset_;
01155 };
01156 
01157 class Staff : public OffsetElement {
01158 public:
01159     Staff();
01160     virtual ~Staff(){}
01161 
01162 public:
01163     void setClefType(int clef);
01164     ClefType getClefType() const;
01165 
01166     void setKeyType(int key);
01167     int getKeyType() const;
01168 
01169     void setVisible(bool visible);
01170     bool setVisible() const;
01171 
01172     void setGroupType(GroupType type);
01173     GroupType getGroupType() const;
01174 
01175     void setGroupStaffCount(int count);
01176     int getGroupStaffCount() const;
01177 
01178 private:
01179     ClefType clef_;
01180     int key_;
01181     bool visible_;
01182     GroupType groupType_;
01183     int groupStaffCount_;
01184 };
01185 
01187 
01188 class Note : public LineElement {
01189 public:
01190     Note();
01191     virtual ~Note(){}
01192 
01193 public:
01194     void setIsRest(bool rest);
01195     bool getIsRest() const;
01196 
01197     void setNote(unsigned int note);
01198     unsigned int getNote() const;
01199 
01200     void setAccidental(int type);       //AccidentalType
01201     AccidentalType getAccidental() const;
01202 
01203     void setShowAccidental(bool show);
01204     bool getShowAccidental() const;
01205 
01206     void setOnVelocity(unsigned int velocity);
01207     unsigned int getOnVelocity() const;
01208 
01209     void setOffVelocity(unsigned int velocity);
01210     unsigned int getOffVelocity() const;
01211 
01212     void setHeadType(int type);     //NoteHeadType
01213     NoteHeadType getHeadType() const;
01214 
01215     void setTiePos(int tiePos);
01216     TiePos getTiePos() const;
01217 
01218     void setOffsetStaff(int offset);    // cross staff notes
01219     int getOffsetStaff() const;
01220 
01221     void setShow(bool show);
01222     bool getShow() const;
01223 
01224     void setOffsetTick(int offset);
01225     int getOffsetTick() const;
01226 
01227 private:
01228     bool rest_;
01229     unsigned int note_;
01230     AccidentalType accidental_;
01231     bool showAccidental_;
01232     unsigned int onVelocity_;
01233     unsigned int offVelocity_;
01234     NoteHeadType headType_;
01235     TiePos tiePos_;
01236     int offsetStaff_;
01237     bool show_;
01238     int offsetTick_;//for playback
01239 };
01240 
01241 class Articulation : public OffsetElement {
01242 public:
01243     Articulation();
01244     virtual ~Articulation(){}
01245 
01246 public:
01247     void setArtType(int type);//ArticulationType
01248     ArticulationType getArtType() const;
01249 
01250     void setPlacementAbove(bool above);
01251     bool getPlacementAbove() const;
01252 
01253     // for midi
01254     bool willAffectNotes() const;
01255 
01256     static bool isTrill(ArticulationType type);
01257 
01258     // for xml
01259     enum XmlType {
01260         Xml_Articulation,
01261         Xml_Technical,
01262         Xml_Arpeggiate,
01263         Xml_Ornament,
01264         Xml_Fermata,
01265         Xml_Direction,
01266 
01267         Xml_Unknown
01268     };
01269     XmlType getXmlType() const;
01270 
01271     // sound setting
01272     bool getChangeSoundEffect() const;
01273     void setSoundEffect(int soundFrom, int soundTo);
01274     QPair<int, int> getSoundEffect() const;
01275 
01276     bool getChangeLength() const;
01277     void setLengthPercentage(int percentage);
01278     int getLengthPercentage() const;
01279 
01280     bool getChangeVelocity() const;
01281     enum VelocityType
01282     {
01283         Velocity_Offset,
01284         Velocity_SetValue,
01285         Velocity_Percentage
01286     };
01287     void setVelocityType(VelocityType type);
01288     VelocityType getVelocityType() const;
01289 
01290     void setVelocityValue(int value);
01291     int getVelocityValue() const;
01292 
01293     bool getChangeExtraLength() const;
01294     void setExtraLength(int length);
01295     int getExtraLength() const;
01296 
01297     // trill
01298     enum TrillInterval {
01299         TrillInterval_Diatonic = 0,
01300         TrillInterval_Chromatic,
01301         TrillInterval_Whole
01302     };
01303     void setTrillInterval(int interval);
01304     TrillInterval getTrillInterval() const;
01305 
01306     void setAuxiliaryFirst(bool first);
01307     bool getAuxiliaryFirst() const;
01308 
01309     void setTrillRate(NoteType rate);
01310     NoteType getTrillRate() const;
01311 
01312     void setTrillNoteLength(int length);
01313     int getTrillNoteLength() const;
01314 
01315     enum AccelerateType {
01316         Accelerate_None = 0 ,
01317         Accelerate_Slow,
01318         Accelerate_Normal,
01319         Accelerate_Fast
01320     };
01321     void setAccelerateType(int type);
01322     AccelerateType getAccelerateType() const;
01323 
01324 private:
01325     ArticulationType type_;
01326     bool above_;
01327 
01328     bool changeSoundEffect_;
01329     QPair<int, int> soundEffect_;
01330     bool changeLength_;
01331     int lengthPercentage_;
01332     bool changeVelocity_;
01333     VelocityType velocityType_;
01334     int velocityValue_;
01335     bool changeExtraLength_;
01336     int extraLength_;
01337 
01338     // trill
01339     TrillInterval trillInterval_;
01340     bool auxiliaryFirst_;
01341     NoteType trillRate_;
01342     int trillNoteLength_;
01343     AccelerateType accelerateType_;
01344 };
01345 
01346 class NoteContainer : public MusicData, public LengthElement {
01347 public:
01348     NoteContainer();
01349     virtual ~NoteContainer();
01350 
01351 public:
01352     void setIsGrace(bool grace);
01353     bool getIsGrace() const;
01354 
01355     void setIsCue(bool cue);
01356     bool getIsCue() const;
01357 
01358     void setIsRest(bool rest/*or note*/);
01359     bool getIsRest() const;
01360 
01361     void setIsRaw(bool raw);
01362     bool getIsRaw() const;
01363 
01364     void setNoteType(NoteType type);
01365     NoteType getNoteType() const;
01366 
01367     void setDot(int dot);
01368     int getDot() const;
01369 
01370     void setGraceNoteType(NoteType type);
01371     NoteType getGraceNoteType() const;
01372 
01373     void setInBeam(bool in);
01374     bool getInBeam() const;
01375 
01376     void setStemUp(bool up);
01377     bool getStemUp(void) const;
01378 
01379     void setShowStem(bool show);
01380     bool getShowStem() const;
01381 
01382     void setStemLength(int line);
01383     int getStemLength() const;
01384 
01385     void setTuplet(int tuplet);
01386     int getTuplet() const;
01387 
01388     void setSpace(int space);
01389     int getSpace() const;
01390 
01391     void addNoteRest(Note* note);
01392     QList<Note*> getNotesRests() const;
01393 
01394     void addArticulation(Articulation* art);
01395     QList<Articulation*> getArticulations() const;
01396 
01397     void setNoteShift(int octave);
01398     int getNoteShift() const;
01399 
01400     int getOffsetStaff() const;
01401 
01402     int getDuration() const;
01403 
01404 private:
01405     bool grace_;
01406     bool cue_;
01407     bool rest_;
01408     bool raw_;
01409     NoteType noteType_;
01410     int dot_;
01411     NoteType graceNoteType_;
01412     int tuplet_;
01413     int space_;
01414     bool inBeam_;
01415     bool stemUp_;
01416     bool showStem_;
01417     int stemLength_;    // line count span
01418     int noteShift_;
01419 
01420     QList<Note*> notes_;
01421     QList<Articulation*> articulations_;
01422 };
01423 
01424 class Beam : public MusicData, public PairEnds {
01425 public:
01426     Beam();
01427     virtual ~Beam(){}
01428 
01429 public:
01430     void setIsGrace(bool grace);
01431     bool getIsGrace() const;
01432 
01433     void addLine(const MeasurePos& startMp, const MeasurePos& endMp);
01434     const QList<QPair<MeasurePos, MeasurePos> > getLines() const;
01435 
01436 private:
01437     bool grace_;
01438     QList<QPair<MeasurePos, MeasurePos> > lines_;
01439 };
01440 
01441 class Tie : public MusicData, public PairEnds {
01442 public:
01443     Tie();
01444     virtual ~Tie(){}
01445 
01446 public:
01447     void setShowOnTop(bool top);
01448     bool getShowOnTop() const;
01449 
01450     void setNote(int note);// note value tie point to
01451     int getNote() const;
01452 
01453     void setHeight(int height);
01454     int getHeight() const;
01455 
01456 private:
01457     bool showOnTop_;
01458     int note_;
01459     int height_;
01460 };
01461 
01462 class Glissando : public MusicData, public PairEnds {
01463 public:
01464     Glissando();
01465     virtual ~Glissando(){}
01466 
01467 public:
01468     void setStraightWavy(bool straight);
01469     bool getStraightWavy() const;
01470 
01471     void setText(const QString& text);
01472     QString getText() const;
01473 
01474     void setLineThick(int thick);
01475     int getLineThick() const;
01476 
01477 private:
01478     bool straight_;
01479     QString text_;
01480     int lineThick_;
01481 };
01482 
01483 class Decorator : public MusicData {
01484 public:
01485     Decorator();
01486     virtual ~Decorator(){}
01487 
01488 public:
01489     enum DecoratorType {
01490         Decorator_Dotted_Barline = 0,
01491         Decorator_Articulation
01492     };
01493     void setDecoratorType(DecoratorType type);
01494     DecoratorType getDecoratorType() const;
01495 
01496     void setArticulationType(ArticulationType type);
01497     ArticulationType getArticulationType() const;
01498 
01499 private:
01500     DecoratorType decoratorType_;
01501     ArticulationType artType_;
01502 };
01503 
01504 class MeasureRepeat : public MusicData {
01505 public:
01506     MeasureRepeat();
01507     virtual ~MeasureRepeat(){}
01508 
01509 public:
01510     void setSingleRepeat(bool single); // false : double
01511     bool getSingleRepeat() const;
01512 
01513 private:
01514     bool singleRepeat_;
01515 };
01516 
01517 class Tuplet : public MusicData, public PairEnds {
01518 public:
01519     Tuplet();
01520     virtual ~Tuplet();
01521 
01522 public:
01523     void setTuplet(int tuplet=3);
01524     int getTuplet() const;
01525 
01526     void setSpace(int space=2);
01527     int getSpace() const;
01528 
01529     void setHeight(int height);
01530     int getHeight() const;
01531 
01532     void setNoteType(NoteType type);
01533     NoteType getNoteType() const;
01534 
01535     OffsetElement* getMarkHandle() const;
01536 
01537 private:
01538     int tuplet_;
01539     int space_;
01540     int height_;
01541     NoteType noteType_;
01542     OffsetElement* mark_;
01543 };
01544 
01545 class Harmony : public MusicData, public LengthElement {
01546 public:
01547     Harmony();
01548     virtual ~Harmony(){}
01549 
01550 public:
01551     void setHarmonyType(HarmonyType type);
01552     HarmonyType getHarmonyType() const;
01553 
01554     void setRoot(int root=0);//C
01555     int getRoot() const;
01556 
01557     void setBass(int bass);
01558     int getBass() const;
01559 
01560     void setBassOnBottom(bool on);
01561     bool getBassOnBottom() const;
01562 
01563     void setAngle(int angle);
01564     int getAngle() const;
01565 
01566 private:
01567     HarmonyType harmonyType_;
01568     int root_;
01569     int bass_;
01570     bool bassOnBottom_;
01571     int angle_;
01572 };
01573 
01574 class Clef : public MusicData, public LineElement {
01575 public:
01576     Clef();
01577     virtual ~Clef(){}
01578 
01579 public:
01580     void setClefType(int type); // ClefType
01581     ClefType getClefType() const;
01582 
01583 private:
01584     ClefType clefType_;
01585 };
01586 
01587 class Lyric : public MusicData {
01588 public:
01589     Lyric();
01590     virtual ~Lyric(){}
01591 
01592 public:
01593     void setLyric(const QString& lyricText);
01594     QString getLyric() const;
01595 
01596     void setVerse(int verse);
01597     int getVerse() const;
01598 
01599 private:
01600     QString lyric_;
01601     int verse_;
01602 };
01603 
01604 class Slur: public MusicData, public PairEnds {
01605 public:
01606     Slur();
01607     virtual ~Slur();
01608 
01609 public:
01610     void setContainerCount(int count); // span
01611     int getContainerCount() const;
01612 
01613     void setShowOnTop(bool top);
01614     bool getShowOnTop() const;
01615 
01616     OffsetElement* getHandle2() const;
01617     OffsetElement* getHandle3() const;
01618 
01619     void setNoteTimePercent(int percent); // 50% ~ 200%
01620     int getNoteTimePercent() const;
01621 
01622 private:
01623     int containerCount_;
01624     bool showOnTop_;
01625     int noteTimePercent_;
01626     OffsetElement* handle_2_;
01627     OffsetElement* handle_3_;
01628 };
01629 
01630 class Dynamics: public MusicData {
01631 public:
01632     Dynamics();
01633     virtual ~Dynamics() {}
01634 
01635 public:
01636     void setDynamicsType(int type);//DynamicsType
01637     DynamicsType getDynamicsType() const;
01638 
01639     void setIsPlayback(bool play);
01640     bool getIsPlayback() const;
01641 
01642     void setVelocity(int vel);
01643     int getVelocity() const;
01644 
01645 private:
01646     DynamicsType dynamicsType_;
01647     bool playback_;
01648     int velocity_;
01649 };
01650 
01651 class WedgeEndPoint: public MusicData {
01652 public:
01653     WedgeEndPoint();
01654     virtual ~WedgeEndPoint() {}
01655 
01656 public:
01657     void setWedgeType(WedgeType type);
01658     WedgeType getWedgeType() const;
01659 
01660     void setHeight(int height);
01661     int getHeight() const;
01662 
01663     void setWedgeStart(bool wedgeStart);
01664     bool getWedgeStart() const;
01665 
01666 private:
01667     int height_;
01668     WedgeType wedgeType_;
01669     bool wedgeStart_;
01670 };
01671 
01672 class Wedge: public MusicData {
01673 public:
01674     Wedge();
01675     virtual ~Wedge() {}
01676 
01677 public:
01678     void setWedgeType(WedgeType type);
01679     WedgeType getWedgeType() const;
01680 
01681     void setHeight(int height);
01682     int getHeight() const;
01683 
01684 private:
01685     int height_;
01686     WedgeType wedgeType_;
01687 };
01688 
01689 class Pedal: public MusicData, public PairEnds {
01690 public:
01691     Pedal();
01692     virtual ~Pedal();
01693 
01694 public:
01695     void setHalf(bool half);
01696     bool getHalf() const;
01697 
01698     void setIsPlayback(bool playback);
01699     bool getIsPlayback() const;
01700 
01701     void setPlayOffset(int offset); // -127~127
01702     int getPlayOffset() const;
01703 
01704     OffsetElement* getPedalHandle() const; //only on half pedal
01705 
01706 private:
01707     bool half_;
01708     bool playback_;
01709     int playOffset_;
01710     OffsetElement* pedalHandle_;
01711 };
01712 
01713 class KuoHao: public MusicData, public PairEnds {
01714 public:
01715     KuoHao();
01716     virtual ~KuoHao() {}
01717 
01718 public:
01719     void setHeight(int height);
01720     int getHeight() const;
01721 
01722     void setKuohaoType(int type);// KuoHaoType
01723     KuoHaoType getKuohaoType() const;
01724 
01725 private:
01726     int height_;
01727     KuoHaoType kuohaoType_;
01728 };
01729 
01730 class Expressions: public MusicData {
01731 public:
01732     Expressions();
01733     virtual ~Expressions() {}
01734 
01735 public:
01736     void setText(const QString& str);
01737     QString getText() const;
01738 
01739 private:
01740     QString text_;
01741 };
01742 
01743 class HarpPedal: public MusicData {
01744 public:
01745     HarpPedal();
01746     virtual ~HarpPedal() {}
01747 
01748 public:
01749     void setShowType(int type);//0:graph, 1:char, 2:char cut, 3:change
01750     int getShowType() const;
01751 
01752     void setShowCharFlag(int flag);//each bit is a bool, total 7 bools
01753     int getShowCharFlag() const;
01754 
01755 private:
01756     int showType_;
01757     int showCharFlag_;
01758 };
01759 
01760 class OctaveShift: public MusicData, public LengthElement {
01761 public:
01762     OctaveShift();
01763     virtual ~OctaveShift() {}
01764 
01765 public:
01766     void setOctaveShiftType(int type);
01767     OctaveShiftType getOctaveShiftType() const;
01768 
01769     int getNoteShift() const;
01770 
01771     void setEndTick(int tick);
01772     int getEndTick() const;
01773 
01774 private:
01775     OctaveShiftType octaveShiftType_;
01776     OctaveShiftPosition octaveShiftPosition_;
01777     int endTick_;
01778 };
01779 
01780 class OctaveShiftEndPoint: public MusicData, public LengthElement {
01781 public:
01782     OctaveShiftEndPoint();
01783     virtual ~OctaveShiftEndPoint() {}
01784 
01785 public:
01786     void setOctaveShiftType(int type);
01787     OctaveShiftType getOctaveShiftType() const;
01788 
01789     void setOctaveShiftPosition(int position);
01790     OctaveShiftPosition getOctaveShiftPosition() const;
01791 
01792     void setEndTick(int tick);
01793     int getEndTick() const;
01794 
01795 private:
01796     OctaveShiftType octaveShiftType_;
01797     OctaveShiftPosition octaveShiftPosition_;
01798     int endTick_;
01799 };
01800 
01801 class MultiMeasureRest: public MusicData {
01802 public:
01803     MultiMeasureRest();
01804     virtual ~MultiMeasureRest() {}
01805 
01806 public:
01807     void setMeasureCount(int count);
01808     int getMeasureCount() const;
01809 
01810 private:
01811     int measureCount_;
01812 };
01813 
01814 class Tempo: public MusicData {
01815 public:
01816     Tempo();
01817     virtual ~Tempo() {}
01818 
01819 public:
01820     void setLeftNoteType(int type);//NoteType
01821     NoteType getLeftNoteType() const;
01822 
01823     void setShowMark(bool show);
01824     bool getShowMark() const;
01825 
01826     void setShowBeforeText(bool show);
01827     bool getShowBeforeText() const;
01828 
01829     void setShowParenthesis(bool show);
01830     bool getShowParenthesis() const;
01831 
01832     void setTypeTempo(int tempo); //0x2580 = 96.00
01833     int getTypeTempo() const;
01834     int getQuarterTempo() const;
01835 
01836     void setLeftText(const QString& str);// string at left of the mark
01837     QString getLeftText() const;
01838 
01839     void setRightText(const QString& str);
01840     QString getRightText() const;
01841 
01842     void setSwingEighth(bool swing);
01843     bool getSwingEighth() const;
01844 
01845     void setRightNoteType(int type);
01846     int getRightNoteType() const;
01847 
01848 private:
01849     int leftNoteType_;
01850     bool showMark_;
01851     bool showText_;
01852     bool showParenthesis_;
01853     int typeTempo_;
01854     QString leftText_;
01855     QString rightText_;
01856     bool swingEighth_;
01857     int rightNoteType_;
01858 };
01859 
01860 class Text: public MusicData, public LengthElement {
01861 public:
01862     Text();
01863     virtual ~Text() {}
01864 
01865 public:
01866     enum TextType {
01867         Text_Rehearsal,
01868         Text_SystemText,
01869         Text_MeasureText
01870     };
01871 
01872     void setTextType(TextType type);
01873     TextType getTextType() const;
01874 
01875     void setHorizontalMargin(int margin);
01876     int getHorizontalMargin() const;
01877 
01878     void setVerticalMargin(int margin);
01879     int getVerticalMargin() const;
01880 
01881     void setLineThick(int thick);
01882     int getLineThick() const;
01883 
01884     void setText(const QString& text);
01885     QString getText() const;
01886 
01887     void setWidth(int width);
01888     int getWidth() const;
01889 
01890     void setHeight(int height);
01891     int getHeight() const;
01892 
01893 private:
01894     TextType textType_;
01895     int horiMargin_;
01896     int vertMargin_;
01897     int lineThick_;
01898     QString text_;
01899     int width_;
01900     int height_;
01901 };
01902 
01904 
01905 class TimeSignature: public MusicData {
01906 public:
01907     TimeSignature();
01908     virtual ~TimeSignature() {}
01909 
01910 public:
01911     void setNumerator(int numerator);
01912     int getNumerator() const;
01913 
01914     void setDenominator(int denominator);
01915     int getDenominator() const;
01916 
01917     void setIsSymbol(bool symbol); //4/4:common, 2/2:cut
01918     bool getIsSymbol() const;
01919 
01920     void setBeatLength(int length); // tick
01921     int getBeatLength() const;
01922 
01923     void setBarLength(int length); // tick
01924     int getBarLength() const;
01925 
01926     void addBeat(int startUnit, int lengthUnit, int startTick);
01927     void endAddBeat();
01928     int getUnits() const;
01929 
01930     void setReplaceFont(bool replace);
01931     bool getReplaceFont() const;
01932 
01933     void setShowBeatGroup(bool show);
01934     bool getShowBeatGroup() const;
01935 
01936     void setGroupNumerator1(int numerator);
01937     void setGroupNumerator2(int numerator);
01938     void setGroupNumerator3(int numerator);
01939     void setGroupDenominator1(int denominator);
01940     void setGroupDenominator2(int denominator);
01941     void setGroupDenominator3(int denominator);
01942 
01943     void setBeamGroup1(int count);
01944     void setBeamGroup2(int count);
01945     void setBeamGroup3(int count);
01946     void setBeamGroup4(int count);
01947 
01948     void set16thBeamCount(int count);
01949     void set32thBeamCount(int count);
01950 
01951 private:
01952     int numerator_;
01953     int denominator_;
01954     bool isSymbol_;
01955     int beatLength_;
01956     int barLength_;
01957 
01958     struct BeatNode {
01959         int startUnit_;
01960         int lengthUnit_;
01961         int startTick_;
01962 
01963         BeatNode() :
01964             startUnit_(0),
01965             lengthUnit_(0),
01966             startTick_(0) {
01967         }
01968     };
01969     QList<BeatNode> beats_;
01970     int barLengthUnits_;
01971 
01972     bool replaceFont_;
01973     bool showBeatGroup_;
01974 
01975     int groupNumerator1_;
01976     int groupNumerator2_;
01977     int groupNumerator3_;
01978     int groupDenominator1_;
01979     int groupDenominator2_;
01980     int groupDenominator3_;
01981 
01982     int beamGroup1_;
01983     int beamGroup2_;
01984     int beamGroup3_;
01985     int beamGroup4_;
01986 
01987     int beamCount16th_;
01988     int beamCount32th_;
01989 };
01990 
01991 class Key: public MusicData {
01992 public:
01993     Key();
01994     virtual ~Key() {}
01995 
01996 public:
01997     void setKey(int key); //C=0x0, G=0x8, C#=0xE, F=0x1, Db=0x7
01998     int getKey() const;
01999     bool getSetKey() const;
02000 
02001     void setPreviousKey(int key);
02002     int getPreviousKey() const;
02003 
02004     void setSymbolCount(int count);
02005     int getSymbolCount() const;
02006 
02007 private:
02008     int key_;
02009     bool set_;
02010     int previousKey_;
02011     int symbolCount_;
02012 };
02013 
02014 class RepeatSymbol: public MusicData {
02015 public:
02016     RepeatSymbol();
02017     virtual ~RepeatSymbol() {}
02018 
02019 public:
02020     void setText(const QString& text);
02021     QString getText() const;
02022 
02023     void setRepeatType(int repeatType);
02024     RepeatType getRepeatType() const;
02025 
02026 private:
02027     QString text_;
02028     RepeatType repeatType_;
02029 };
02030 
02031 class NumericEnding: public MusicData, public PairEnds {
02032 public:
02033     NumericEnding();
02034     virtual ~NumericEnding();
02035 
02036 public:
02037     OffsetElement* getNumericHandle() const;
02038 
02039     void setHeight(int height);
02040     int getHeight() const;
02041 
02042     void setText(const QString& text);
02043     QString getText() const;
02044     QList<int> getNumbers() const;
02045     int getJumpCount() const;
02046 
02047 private:
02048     int height_;
02049     QString text_;
02050     OffsetElement* numericHandle_;
02051 };
02052 
02053 class BarNumber: public MusicData {
02054 public:
02055     BarNumber();
02056     virtual ~BarNumber() {}
02057 
02058 public:
02059     void setIndex(int index);
02060     int getIndex() const;
02061 
02062     void setShowOnParagraphStart(bool show);
02063     bool getShowOnParagraphStart() const;
02064 
02065     void setAlign(int align);// 0:left, 1:center, 2:right
02066     int getAlign() const;
02067 
02068     void setShowFlag(int flag); // 0:page, 1:staff, 2:bar, 3:none
02069     int getShowFlag() const;
02070 
02071     void setShowEveryBarCount(int count);
02072     int getShowEveryBarCount() const;
02073 
02074     void setPrefix(const QString& str);
02075     QString getPrefix() const;
02076 
02077 private:
02078     int index_;
02079     bool showOnParagraphStart_;
02080     int align_;
02081     int showFlag_;
02082     int barRange_;
02083     QString prefix_;
02084 };
02085 
02087 // MIDI
02088 class MidiController: public MidiData {
02089 public:
02090     MidiController();
02091     virtual ~MidiController() {}
02092 
02093 public:
02094     void setController(int number);
02095     int getController() const;
02096 
02097     void setValue(int value);
02098     int getValue() const;
02099 
02100 private:
02101     int controller_;
02102     int value_;
02103 };
02104 
02105 class MidiProgramChange: public MidiData {
02106 public:
02107     MidiProgramChange();
02108     virtual ~MidiProgramChange() {}
02109 
02110 public:
02111     void setPatch(int patch);
02112     int getPatch() const;
02113 
02114 private:
02115     int patch_;
02116 };
02117 
02118 class MidiChannelPressure: public MidiData {
02119 public:
02120     MidiChannelPressure();
02121     virtual ~MidiChannelPressure() {}
02122 
02123 public:
02124     void setPressure(int pressure);
02125     int getPressure() const;
02126 
02127 private:
02128     int pressure_;
02129 };
02130 
02131 class MidiPitchWheel: public MidiData {
02132 public:
02133     MidiPitchWheel();
02134     virtual ~MidiPitchWheel() {}
02135 
02136 public:
02137     void setValue(int value);
02138     int getValue() const;
02139 
02140 private:
02141     int value_;
02142 };
02143 
02145 class Measure: public LengthElement {
02146 public:
02147     Measure(int index = 0);
02148     virtual ~Measure();
02149 
02150 private:
02151     Measure();
02152 
02153 public:
02154     BarNumber* getBarNumber() const;
02155     TimeSignature* getTime() const;
02156 
02157     void setLeftBarline(int barline/*in BarlineType*/);
02158     BarlineType getLeftBarline() const;
02159 
02160     void setRightBarline(int barline/*in BarlineType*/);
02161     BarlineType getRightBarline() const;
02162 
02163     // set when rightBarline == Baline_Backward
02164     void setBackwardRepeatCount(int repeatCount);
02165     int getBackwardRepeatCount() const;
02166 
02167     void setTypeTempo(double tempo);
02168     double getTypeTempo() const;
02169 
02170     void setIsPickup(bool pickup);
02171     bool getIsPickup() const;
02172 
02173     void setIsMultiMeasureRest(bool rest);
02174     bool getIsMultiMeasureRest() const;
02175 
02176     void setMultiMeasureRestCount(int count);
02177     int getMultiMeasureRestCount() const;
02178 
02179 private:
02180     void clear();
02181 
02182     BarNumber* barNumber_;
02183     TimeSignature* time_;
02184 
02185     BarlineType leftBarline_;
02186     BarlineType rightBarline_;
02187     int repeatCount_;
02188     double typeTempo_; // based on some type
02189     bool pickup_;
02190     bool multiMeasureRest_;
02191     int multiMeasureRestCount_;
02192 };
02193 
02194 class MeasureData {
02195 public:
02196     MeasureData();
02197     ~MeasureData();
02198 
02199 public:
02200     Clef* getClef() const;
02201     Key* getKey() const;
02202 
02203     void addNoteContainer(NoteContainer* ptr);
02204     QList<NoteContainer*> getNoteContainers() const;
02205 
02206     // put Tempo, Text, RepeatSymbol to MeasureData at part=0 && staff=0
02207     void addMusicData(MusicData* ptr);
02208     // if type==MusicData_None, return all
02209     QList<MusicData*> getMusicDatas(MusicDataType type);//MusicXml: note|direction|harmony
02210 
02211     // put NumericEnding to MeasureData at part=0 && staff=0
02212     void addCrossMeasureElement(MusicData* ptr, bool start);
02213     enum PairType {
02214         PairType_Start,
02215         PairType_Stop,
02216         PairType_All
02217     };
02218     QList<MusicData*> getCrossMeasureElements(MusicDataType type, PairType pairType);
02219 
02220     // for midi
02221     void addMidiData(MidiData* ptr);
02222     QList<MidiData*> getMidiDatas(MidiType type);
02223 
02224 private:
02225     Key* key_;
02226     Clef* clef_;
02227     QList<MusicData*> musicDatas_;
02228     QList<NoteContainer*> noteContainers_;
02229     QList<QPair<MusicData*, bool> > crossMeasureElements_;
02230     QList<MidiData*> midiDatas_;
02231 };
02232 
02233 // StreamHandle
02234 class StreamHandle {
02235 public:
02236     StreamHandle(unsigned char* p, int size);
02237     virtual ~StreamHandle();
02238 
02239 private:
02240     StreamHandle();
02241 
02242 public:
02243     virtual bool read(char* buff, int size);
02244     virtual bool write(char* buff, int size);
02245 
02246 private:
02247     int size_;
02248     int curPos_;
02249     unsigned char* point_;
02250 };
02251 
02252 // Block.h
02253 // base block, or resizable block in ove to store data
02254 class Block {
02255 public:
02256     Block();
02257     explicit Block(unsigned int size);
02258     virtual ~Block() {
02259     }
02260 
02261 public:
02262     // size > 0, check this in use code
02263     virtual void resize(unsigned int count);
02264 
02265     const unsigned char* data() const;
02266     unsigned char* data();
02267     unsigned int size() const;
02268 
02269     bool operator ==(const Block& block) const;
02270     bool operator !=(const Block& block) const;
02271 
02272     bool toBoolean() const;
02273     unsigned int toUnsignedInt() const;
02274     int toInt() const;
02275     QByteArray toStrByteArray() const;                  // string
02276     QByteArray fixedSizeBufferToStrByteArray() const;   // string
02277 
02278 private:
02279     void doResize(unsigned int count);
02280 
02281 private:
02282     // char [-128, 127], unsigned char [0, 255]
02283     QList<unsigned char> data_;
02284 };
02285 
02286 class FixedBlock: public Block {
02287 public:
02288     explicit FixedBlock(unsigned int count);
02289     virtual ~FixedBlock() {
02290     }
02291 
02292 private:
02293     FixedBlock();
02294 
02295 private:
02296     // can't resize
02297     virtual void resize(unsigned int count);
02298 };
02299 
02301 // 4 byte block in ove to store size
02302 class SizeBlock: public FixedBlock {
02303 public:
02304     SizeBlock();
02305     virtual ~SizeBlock() {
02306     }
02307 
02308 public:
02309     //  void fromUnsignedInt(unsigned int count) ;
02310 
02311     unsigned int toSize() const;
02312 };
02313 
02314 // 4 bytes block in ove to store name
02315 class NameBlock: public FixedBlock {
02316 public:
02317     NameBlock();
02318     virtual ~NameBlock() {
02319     }
02320 
02321 public:
02322     // ingore data more than 4 bytes
02323     bool isEqual(const QString& name) const;
02324 };
02325 
02326 // 2 bytes block in ove to store count
02327 class CountBlock: public FixedBlock {
02328 public:
02329     CountBlock();
02330     virtual ~CountBlock() {
02331     }
02332 
02333 public:
02334     //  void setValue(unsigned short count) ;
02335 
02336     unsigned short toCount() const;
02337 };
02338 
02339 // Chunk.h
02340 // content : name
02341 class Chunk {
02342 public:
02343     Chunk();
02344     virtual ~Chunk() {
02345     }
02346 
02347 public:
02348     const static QString TrackName;
02349     const static QString PageName;
02350     const static QString LineName;
02351     const static QString StaffName;
02352     const static QString MeasureName;
02353     const static QString ConductName;
02354     const static QString BdatName;
02355 
02356     NameBlock getName() const;
02357 
02358 protected:
02359     NameBlock nameBlock_;
02360 };
02361 
02362 // content : name / size / data
02363 class SizeChunk: public Chunk {
02364 public:
02365     SizeChunk();
02366     virtual ~SizeChunk();
02367 
02368 public:
02369     SizeBlock* getSizeBlock() const;
02370     Block* getDataBlock() const;
02371 
02372     const static unsigned int version3TrackSize;
02373 
02374 protected:
02375     SizeBlock* sizeBlock_;
02376     Block* dataBlock_;
02377 };
02378 
02379 // content : name / count
02380 class GroupChunk: public Chunk {
02381 public:
02382     GroupChunk();
02383     virtual ~GroupChunk();
02384 
02385 public:
02386     CountBlock* getCountBlock() const;
02387 
02388 protected:
02389     CountBlock* childCount_;
02390 };
02391 
02392 // ChunkParse.h
02393 class BasicParse {
02394 public:
02395     BasicParse(OveSong* ove);
02396     virtual ~BasicParse();
02397 
02398 private:
02399     BasicParse();
02400 
02401 public:
02402     void setNotify(IOveNotify* notify);
02403     virtual bool parse();
02404 
02405 protected:
02406     bool readBuffer(Block& placeHolder, unsigned int size);
02407     bool jump(int offset);
02408 
02409     void messageOut(const QString& str);
02410 
02411 protected:
02412     OveSong* ove_;
02413     StreamHandle* handle_;
02414     IOveNotify* notify_;
02415 };
02416 
02418 
02419 class OvscParse: public BasicParse {
02420 public:
02421     OvscParse(OveSong* ove);
02422     virtual ~OvscParse();
02423 
02424 public:
02425     void setOvsc(SizeChunk* chunk);
02426 
02427     virtual bool parse();
02428 
02429 private:
02430     SizeChunk* chunk_;
02431 };
02432 
02433 class TrackParse: public BasicParse {
02434 public:
02435     TrackParse(OveSong* ove);
02436     virtual ~TrackParse();
02437 
02438 public:
02439     void setTrack(SizeChunk* chunk);
02440 
02441     virtual bool parse();
02442 
02443 private:
02444     SizeChunk* chunk_;
02445 };
02446 
02447 class GroupParse: BasicParse {
02448 public:
02449     GroupParse(OveSong* ove);
02450     virtual ~GroupParse();
02451 
02452 public:
02453     void addSizeChunk(SizeChunk* sizeChunk);
02454 
02455     virtual bool parse();
02456 
02457 private:
02458     QList<SizeChunk*> sizeChunks_;
02459 };
02460 
02461 class PageGroupParse: public BasicParse {
02462 public:
02463     PageGroupParse(OveSong* ove);
02464     virtual ~PageGroupParse();
02465 
02466 public:
02467     void addPage(SizeChunk* chunk);
02468 
02469     virtual bool parse();
02470 
02471 private:
02472     bool parsePage(SizeChunk* chunk, Page* page);
02473 
02474 private:
02475     QList<SizeChunk*> pageChunks_;
02476 };
02477 
02478 class StaffCountGetter: public BasicParse {
02479 public:
02480     StaffCountGetter(OveSong* ove);
02481     virtual ~StaffCountGetter() {}
02482 
02483 public:
02484     unsigned int getStaffCount(SizeChunk* chunk);
02485 };
02486 
02487 class LineGroupParse: public BasicParse {
02488 public:
02489     LineGroupParse(OveSong* ove);
02490     virtual ~LineGroupParse();
02491 
02492 public:
02493     void setLineGroup(GroupChunk* chunk);
02494     void addLine(SizeChunk* chunk);
02495     void addStaff(SizeChunk* chunk);
02496 
02497     virtual bool parse();
02498 
02499 private:
02500     bool parseLine(SizeChunk* chunk, Line* line);
02501     bool parseStaff(SizeChunk* chunk, Staff* staff);
02502 
02503 private:
02504     GroupChunk* chunk_;
02505     QList<SizeChunk*> lineChunks_;
02506     QList<SizeChunk*> staffChunks_;
02507 };
02508 
02509 class BarsParse: public BasicParse {
02510 public:
02511     BarsParse(OveSong* ove);
02512     virtual ~BarsParse();
02513 
02514 public:
02515     void addMeasure(SizeChunk* chunk);
02516     void addConduct(SizeChunk* chunk);
02517     void addBdat(SizeChunk* chunk);
02518 
02519     virtual bool parse();
02520 
02521 private:
02522     bool parseMeas(Measure* measure, SizeChunk* chunk);
02523     bool parseCond(Measure* measure, MeasureData* measureData, SizeChunk* chunk);
02524     bool parseBdat(Measure* measure, MeasureData* measureData, SizeChunk* chunk);
02525 
02526     bool getCondElementType(unsigned int byteData, CondType& type);
02527     bool getBdatElementType(unsigned int byteData, BdatType& type);
02528 
02529     // COND
02530     bool parseTimeSignature(Measure* measure, int length);
02531     bool parseTimeSignatureParameters(Measure* measure, int length);
02532     bool parseRepeatSymbol(MeasureData* measureData, int length);
02533     bool parseNumericEndings(MeasureData* measureData, int length);
02534     bool parseTempo(MeasureData* measureData, int length);
02535     bool parseBarNumber(Measure* measure, int length);
02536     bool parseText(MeasureData* measureData, int length);
02537     bool parseBarlineParameters(Measure* measure, int length);
02538 
02539     // BDAT
02540     bool parseNoteRest(MeasureData* measureData, int length, BdatType type);
02541     bool parseBeam(MeasureData* measureData, int length);
02542     bool parseTie(MeasureData* measureData, int length);
02543     bool parseTuplet(MeasureData* measureData, int length);
02544     bool parseHarmony(MeasureData* measureData, int length);
02545     bool parseClef(MeasureData* measureData, int length);
02546     bool parseLyric(MeasureData* measureData, int length);
02547     bool parseSlur(MeasureData* measureData, int length);
02548     bool parseGlissando(MeasureData* measureData, int length);
02549     bool parseDecorators(MeasureData* measureData, int length);
02550     bool parseDynamics(MeasureData* measureData, int length);
02551     bool parseWedge(MeasureData* measureData, int length);
02552     bool parseKey(MeasureData* measureData, int length);
02553     bool parsePedal(MeasureData* measureData, int length);
02554     bool parseKuohao(MeasureData* measureData, int length);
02555     bool parseExpressions(MeasureData* measureData, int length);
02556     bool parseHarpPedal(MeasureData* measureData, int length);
02557     bool parseMultiMeasureRest(MeasureData* measureData, int length);
02558     bool parseHarmonyGuitarFrame(MeasureData* measureData, int length);
02559     bool parseOctaveShift(MeasureData* measureData, int length);
02560     bool parseMidiController(MeasureData* measureData, int length);
02561     bool parseMidiProgramChange(MeasureData* measureData, int length);
02562     bool parseMidiChannelPressure(MeasureData* measureData, int length);
02563     bool parseMidiPitchWheel(MeasureData* measureData, int length);
02564 
02565     bool parseSizeBlock(int length);
02566     bool parseMidiCommon(MidiData* ptr);
02567     bool parseCommonBlock(MusicData* ptr);
02568     bool parseOffsetCommonBlock(MusicData* ptr);
02569     bool parsePairLinesBlock(PairEnds* ptr); //size==2
02570     bool parseOffsetElement(OffsetElement* ptr);//size==2
02571 
02572 private:
02573     QList<SizeChunk*> measureChunks_;
02574     QList<SizeChunk*> conductChunks_;
02575     QList<SizeChunk*> bdatChunks_;
02576 };
02577 
02578 class LyricChunkParse: public BasicParse {
02579 public:
02580     LyricChunkParse(OveSong* ove);
02581     virtual ~LyricChunkParse() {}
02582 
02583 public:
02584     void setLyricChunk(SizeChunk* chunk);
02585 
02586     virtual bool parse();
02587 
02588 private:
02589     struct LyricInfo {
02590         int track_;
02591         int measure_;
02592         int verse_;
02593         int voice_;
02594         int wordCount_;
02595         int lyricSize_;
02596         QString name_;
02597         QString lyric_;
02598         int font_;
02599         int fontSize_;
02600         int fontStyle_;
02601 
02602         LyricInfo() :
02603             track_(0), measure_(0), verse_(0), voice_(0), wordCount_(0),
02604                     lyricSize_(0), name_(QString()), lyric_(QString()),
02605                     font_(0), fontSize_(12), fontStyle_(0) {}
02606     };
02607 
02608     void processLyricInfo(const LyricInfo& info);
02609 
02610 private:
02611     SizeChunk* chunk_;
02612 };
02613 
02614 class TitleChunkParse: public BasicParse {
02615 public:
02616     TitleChunkParse(OveSong* ove);
02617     virtual ~TitleChunkParse() {}
02618 
02619 public:
02620     void setTitleChunk(SizeChunk* chunk);
02621 
02622     virtual bool parse();
02623 
02624 private:
02625     void addToOve(const QString& str, unsigned int titleType);
02626 
02627 private:
02628     unsigned int titleType_;
02629     unsigned int annotateType_;
02630     unsigned int writerType_;
02631     unsigned int copyrightType_;
02632     unsigned int headerType_;
02633     unsigned int footerType_;
02634 
02635     SizeChunk* chunk_;
02636 };
02637 
02638 // OveOrganizer.h
02639 class OveOrganizer {
02640 public:
02641     OveOrganizer(OveSong* ove) ;
02642     virtual ~OveOrganizer(){}
02643 
02644 public:
02645     void organize() ;
02646 
02647 private:
02648     void organizeAttributes() ;
02649     void organizeTracks() ;
02650     void organizeMeasures() ;
02651     void organizeMeasure(int part, int track, Measure* measure, MeasureData* measureData) ;
02652 
02653     void organizeContainers(int part, int track, Measure* measure, MeasureData* measureData) ;
02654     void organizeMusicDatas(int part, int track, Measure* measure, MeasureData* measureData) ;
02655     void organizeCrossMeasureElements(int part, int track, Measure* measure, MeasureData* measureData) ;
02656 
02657     void organizePairElement(MusicData* data, int part, int track, Measure* measure, MeasureData* measureData) ;
02658     void organizeOctaveShift(OctaveShift* octave, Measure* measure, MeasureData* measureData) ;
02659     void organizeWedge(Wedge* wedge, int part, int track, Measure* measure, MeasureData* measureData) ;
02660 
02661 private:
02662     OveSong* ove_ ;
02663 };
02664 
02665 // OveSerialize.h
02666 class StreamHandle;
02667 class Block;
02668 class NameBlock;
02669 class Chunk;
02670 class SizeChunk;
02671 class GroupChunk;
02672 
02673 class OveSerialize: public IOVEStreamLoader {
02674 public:
02675     OveSerialize();
02676     virtual ~OveSerialize();
02677 
02678 public:
02679     virtual void setOve(OveSong* ove);
02680     virtual void setFileStream(unsigned char* buffer, unsigned int size);
02681     virtual void setNotify(IOveNotify* notify);
02682     virtual bool load(void);
02683 
02684     virtual void release();
02685 
02686 private:
02687     bool readNameBlock(NameBlock& nameBlock);
02688     bool readChunkName(Chunk* chunk, const QString& name);
02689     bool readSizeChunk(SizeChunk* sizeChunk); // contains a SizeChunk and data buffer
02690     bool readDataChunk(Block* block, unsigned int size);
02691     bool readGroupChunk(GroupChunk* groupChunk);
02692 
02693     bool readHeader();
02694     bool readHeadData(SizeChunk* ovscChunk);
02695     bool readTracksData();
02696     bool readPagesData();
02697     bool readLinesData();
02698     bool readBarsData();
02699     bool readOveEnd();
02700 
02701     void messageOutError();
02702     void messageOut(const QString& str);
02703 
02704 private:
02705     OveSong* ove_;
02706     StreamHandle* streamHandle_;
02707     IOveNotify* notify_;
02708 };
02709 
02710 /*template <class T>
02711 inline void deleteVector(QList<T*>& vec) {
02712     for (int i=0; i<vec.size(); ++i)
02713         delete vec[i];
02714     }
02715     //vec.clear();
02716 }*/
02717 
02719 TickElement::TickElement() {
02720     tick_ = 0;
02721 }
02722 
02723 void TickElement::setTick(int tick) {
02724     tick_ = tick;
02725 }
02726 
02727 int TickElement::getTick(void) const {
02728     return tick_;
02729 }
02730 
02732 MeasurePos::MeasurePos() {
02733     measure_ = 0;
02734     offset_ = 0;
02735 }
02736 
02737 void MeasurePos::setMeasure(int measure) {
02738     measure_ = measure;
02739 }
02740 
02741 int MeasurePos::getMeasure() const {
02742     return measure_;
02743 }
02744 
02745 void MeasurePos::setOffset(int offset) {
02746     offset_ = offset;
02747 }
02748 
02749 int MeasurePos::getOffset() const {
02750     return offset_;
02751 }
02752 
02753 MeasurePos MeasurePos::shiftMeasure(int measure) const {
02754     MeasurePos mp;
02755     mp.setMeasure(getMeasure() + measure);
02756     mp.setOffset(getOffset());
02757 
02758     return mp;
02759 }
02760 
02761 MeasurePos MeasurePos::shiftOffset(int offset) const {
02762     MeasurePos mp;
02763     mp.setMeasure(getMeasure());
02764     mp.setOffset(getOffset() + offset);
02765 
02766     return mp;
02767 }
02768 
02769 bool MeasurePos::operator ==(const MeasurePos& mp) const {
02770     return getMeasure() == mp.getMeasure() && getOffset() == mp.getOffset();
02771 }
02772 
02773 bool MeasurePos::operator !=(const MeasurePos& mp) const {
02774     return !(*this == mp);
02775 }
02776 
02777 bool MeasurePos::operator <(const MeasurePos& mp) const {
02778     if (getMeasure() != mp.getMeasure()) {
02779         return getMeasure() < mp.getMeasure();
02780     }
02781 
02782     return getOffset() < mp.getOffset();
02783 }
02784 
02785 bool MeasurePos::operator <=(const MeasurePos& mp) const {
02786     if (getMeasure() != mp.getMeasure()) {
02787         return getMeasure() <= mp.getMeasure();
02788     }
02789 
02790     return getOffset() <= mp.getOffset();
02791 }
02792 
02793 bool MeasurePos::operator >(const MeasurePos& mp) const {
02794     return !(*this <= mp);
02795 }
02796 
02797 bool MeasurePos::operator >=(const MeasurePos& mp) const {
02798     return !(*this < mp);
02799 }
02800 
02802 PairElement::PairElement() {
02803     start_ = new MeasurePos();
02804     stop_ = new MeasurePos();
02805 }
02806 
02807 PairElement::~PairElement(){
02808     delete start_;
02809     delete stop_;
02810 }
02811 
02812 MeasurePos* PairElement::start() const {
02813     return start_;
02814 }
02815 
02816 MeasurePos* PairElement::stop() const {
02817     return stop_;
02818 }
02819 
02821 PairEnds::PairEnds() {
02822     leftLine_ = new LineElement();
02823     rightLine_ = new LineElement();
02824     leftShoulder_ = new OffsetElement();
02825     rightShoulder_ = new OffsetElement();
02826 }
02827 
02828 PairEnds::~PairEnds(){
02829     delete leftLine_;
02830     delete rightLine_;
02831     delete leftShoulder_;
02832     delete rightShoulder_;
02833 }
02834 
02835 LineElement* PairEnds::getLeftLine() const {
02836     return leftLine_;
02837 }
02838 
02839 LineElement* PairEnds::getRightLine() const {
02840     return rightLine_;
02841 }
02842 
02843 OffsetElement* PairEnds::getLeftShoulder() const {
02844     return leftShoulder_;
02845 }
02846 
02847 OffsetElement* PairEnds::getRightShoulder() const {
02848     return rightShoulder_;
02849 }
02850 
02852 LineElement::LineElement() {
02853     line_ = 0;
02854 }
02855 
02856 void LineElement::setLine(int line) {
02857     line_ = line;
02858 }
02859 
02860 int LineElement::getLine(void) const {
02861     return line_;
02862 }
02863 
02865 OffsetElement::OffsetElement() {
02866     xOffset_ = 0;
02867     yOffset_ = 0;
02868 }
02869 
02870 void OffsetElement::setXOffset(int offset) {
02871     xOffset_ = offset;
02872 }
02873 
02874 int OffsetElement::getXOffset() const {
02875     return xOffset_;
02876 }
02877 
02878 void OffsetElement::setYOffset(int offset) {
02879     yOffset_ = offset;
02880 }
02881 
02882 int OffsetElement::getYOffset() const {
02883     return yOffset_;
02884 }
02885 
02887 LengthElement::LengthElement() {
02888     length_ = 0;
02889 }
02890 
02891 void LengthElement::setLength(int length) {
02892     length_ = length;
02893 }
02894 
02895 int LengthElement::getLength() const {
02896     return length_;
02897 }
02898 
02900 MusicData::MusicData() {
02901     musicDataType_ = MusicData_None;
02902     show_ = true;
02903     color_ = 0;
02904     voice_ = 0;
02905 }
02906 
02907 MusicDataType MusicData::getMusicDataType() const {
02908     return musicDataType_;
02909 }
02910 
02911 MusicData::XmlDataType MusicData::getXmlDataType(MusicDataType type) {
02912     XmlDataType xmlType = None;
02913 
02914     switch (type) {
02915     case MusicData_Measure_Repeat: {
02916         xmlType = Attributes;
02917         break;
02918     }
02919     case MusicData_Beam: {
02920         xmlType = NoteBeam;
02921         break;
02922     }
02923     case MusicData_Slur:
02924     case MusicData_Glissando:
02925     case MusicData_Tuplet:
02926     case MusicData_Tie: {
02927         xmlType = Notations;
02928         break;
02929     }
02930     case MusicData_Text:
02931     case MusicData_Repeat:
02932     case MusicData_Wedge:
02933     case MusicData_Dynamics:
02934     case MusicData_Pedal:
02935     case MusicData_OctaveShift_EndPoint: {
02936         xmlType = Direction;
02937         break;
02938     }
02939     default: {
02940         xmlType = None;
02941         break;
02942     }
02943     }
02944 
02945     return xmlType;
02946 }
02947 
02948 /*bool MusicData::get_is_pair_element(MusicDataType type)
02949  {
02950  bool pair = false;
02951 
02952  switch ( type )
02953  {
02954  case MusicData_Numeric_Ending :
02955  case MusicData_Measure_Repeat :
02956  case MusicData_Wedge :
02957  case MusicData_OctaveShift :
02958  //case MusicData_OctaveShift_EndPoint :
02959  case MusicData_Pedal :
02960  case MusicData_Beam :
02961  case MusicData_Glissando :
02962  case MusicData_Slur :
02963  case MusicData_Tie :
02964  case MusicData_Tuplet :
02965  {
02966  pair = true;
02967  break;
02968  }
02969  default:
02970  break;
02971  }
02972 
02973  return pair;
02974  }*/
02975 
02976 void MusicData::setShow(bool show) {
02977     show_ = show;
02978 }
02979 
02980 bool MusicData::getShow() const {
02981     return show_;
02982 }
02983 
02984 void MusicData::setColor(unsigned int color) {
02985     color_ = color;
02986 }
02987 
02988 unsigned int MusicData::getColor() const {
02989     return color_;
02990 }
02991 
02992 void MusicData::setVoice(unsigned int voice) {
02993     voice_ = voice;
02994 }
02995 
02996 unsigned int MusicData::getVoice() const {
02997     return voice_;
02998 }
02999 
03000 void MusicData::copyCommonBlock(const MusicData& source) {
03001     setTick(source.getTick());
03002     start()->setOffset(source.start()->getOffset());
03003     setColor(source.getColor());
03004 }
03005 
03007 MidiData::MidiData() {
03008     midiType_ = Midi_None;
03009 }
03010 
03011 MidiType MidiData::getMidiType() const {
03012     return midiType_;
03013 }
03014 
03016 OveSong::OveSong() :
03017     codec_(0) {
03018     clear();
03019 }
03020 
03021 OveSong::~OveSong() {
03022     clear();
03023 }
03024 
03025 void OveSong::setIsVersion4(bool version4){
03026     version4_ = version4;
03027 }
03028 
03029 bool OveSong::getIsVersion4() const {
03030     return version4_;
03031 }
03032 
03033 void OveSong::setQuarter(int tick) {
03034     quarter_ = tick;
03035 }
03036 
03037 int OveSong::getQuarter(void) const {
03038     return quarter_;
03039 }
03040 
03041 void OveSong::setShowPageMargin(bool show){
03042     showPageMargin_ = show;
03043 }
03044 
03045 bool OveSong::getShowPageMargin() const {
03046     return showPageMargin_;
03047 }
03048 
03049 void OveSong::setShowTransposeTrack(bool show) {
03050     showTransposeTrack = show;
03051 }
03052 
03053 bool OveSong::getShowTransposeTrack() const {
03054     return showTransposeTrack;
03055 }
03056 
03057 void OveSong::setShowLineBreak(bool show) {
03058     showLineBreak_ = show;
03059 }
03060 
03061 bool OveSong::getShowLineBreak() const {
03062     return showLineBreak_;
03063 }
03064 
03065 void OveSong::setShowRuler(bool show) {
03066     showRuler_ = show;
03067 }
03068 
03069 bool OveSong::getShowRuler() const {
03070     return showRuler_;
03071 }
03072 
03073 void OveSong::setShowColor(bool show) {
03074     showColor_ = show;
03075 }
03076 
03077 bool OveSong::getShowColor() const {
03078     return showColor_;
03079 }
03080 
03081 void OveSong::setPlayRepeat(bool play) {
03082     playRepeat_ = play;
03083 }
03084 
03085 bool OveSong::getPlayRepeat() const {
03086     return playRepeat_;
03087 }
03088 
03089 void OveSong::setPlayStyle(PlayStyle style) {
03090     playStyle_ = style;
03091 }
03092 
03093 OveSong::PlayStyle OveSong::getPlayStyle() const {
03094     return playStyle_;
03095 }
03096 
03097 void OveSong::addTitle(const QString& str) {
03098     titles_.push_back(str);
03099 }
03100 
03101 QList<QString> OveSong::getTitles(void) const {
03102     return titles_;
03103 }
03104 
03105 void OveSong::addAnnotate(const QString& str) {
03106     annotates_.push_back(str);
03107 }
03108 
03109 QList<QString> OveSong::getAnnotates(void) const {
03110     return annotates_;
03111 }
03112 
03113 void OveSong::addWriter(const QString& str) {
03114     writers_.push_back(str);
03115 }
03116 
03117 QList<QString> OveSong::getWriters(void) const {
03118     return writers_;
03119 }
03120 
03121 void OveSong::addCopyright(const QString& str) {
03122     copyrights_.push_back(str);
03123 }
03124 
03125 QList<QString> OveSong::getCopyrights(void) const {
03126     return copyrights_;
03127 }
03128 
03129 void OveSong::addHeader(const QString& str) {
03130     headers_.push_back(str);
03131 }
03132 
03133 QList<QString> OveSong::getHeaders(void) const {
03134     return headers_;
03135 }
03136 
03137 void OveSong::addFooter(const QString& str) {
03138     footers_.push_back(str);
03139 }
03140 
03141 QList<QString> OveSong::getFooters(void) const {
03142     return footers_;
03143 }
03144 
03145 void OveSong::addTrack(Track* ptr) {
03146     tracks_.push_back(ptr);
03147 }
03148 
03149 int OveSong::getTrackCount(void) const {
03150     return tracks_.size();
03151 }
03152 
03153 QList<Track*> OveSong::getTracks() const {
03154     return tracks_;
03155 }
03156 
03157 void OveSong::setTrackBarCount(int count) {
03158     trackBarCount_ = count;
03159 }
03160 
03161 int OveSong::getTrackBarCount() const {
03162     return trackBarCount_;
03163 }
03164 
03165 Track* OveSong::getTrack(int part, int staff) const {
03166     int trackId = partStaffToTrack(part, staff);
03167 
03168     if( trackId >=0 && trackId < (int)tracks_.size() ) {
03169         return tracks_[trackId];
03170     }
03171 
03172     return 0;
03173 }
03174 
03175 bool OveSong::addPage(Page* page) {
03176     pages_.push_back(page);
03177     return true;
03178 }
03179 
03180 int OveSong::getPageCount() const {
03181     return pages_.size();
03182 }
03183 
03184 Page* OveSong::getPage(int idx) {
03185     if( idx>=0 && idx<(int)pages_.size() ) {
03186         return pages_[idx];
03187     }
03188 
03189     return 0;
03190 }
03191 
03192 void OveSong::addLine(Line* ptr) {
03193     lines_.push_back(ptr);
03194 }
03195 
03196 int OveSong::getLineCount() const {
03197     return lines_.size();
03198 }
03199 
03200 Line* OveSong::getLine(int idx) const {
03201     if( idx >=0 && idx<(int)lines_.size() ) {
03202         return lines_[idx];
03203     }
03204 
03205     return 0;
03206 }
03207 
03208 void OveSong::addMeasure(Measure* ptr) {
03209     measures_.push_back(ptr);
03210 }
03211 
03212 int OveSong::getMeasureCount(void) const {
03213     return measures_.size();
03214 }
03215 
03216 Measure* OveSong::getMeasure(int bar) const {
03217     if( bar >= 0 && bar < (int)measures_.size() ) {
03218         return measures_[bar];
03219     }
03220 
03221     return 0;
03222 }
03223 
03224 void OveSong::addMeasureData(MeasureData* ptr) {
03225     measureDatas_.push_back(ptr);
03226 }
03227 
03228 int OveSong::getMeasureDataCount(void) const {
03229     return measureDatas_.size();
03230 }
03231 
03232 MeasureData* OveSong::getMeasureData(int part, int staff/*=0*/, int bar) const {
03233     int trackId = partStaffToTrack(part, staff);
03234     int trackBarCount = getTrackBarCount();
03235 
03236     if( bar >= 0 && bar < trackBarCount ) {
03237         int measureId = trackBarCount * trackId + bar;
03238 
03239         if( measureId >=0 && measureId < (int)measureDatas_.size() ) {
03240             return measureDatas_[measureId];
03241         }
03242     }
03243 
03244     return 0;
03245 }
03246 
03247 MeasureData* OveSong::getMeasureData(int track, int bar) const {
03248     int id = trackBarCount_*track + bar;
03249 
03250     if( id >=0 && id < (int)measureDatas_.size() ) {
03251         return measureDatas_[id];
03252     }
03253 
03254     return 0;
03255 }
03256 
03257 void OveSong::setPartStaffCounts(const QList<int>& partStaffCounts) {
03258     //partStaffCounts_.assign(partStaffCounts.begin(), partStaffCounts.end());
03259     for(int i=0; i<partStaffCounts.size(); ++i) {
03260         partStaffCounts_.push_back(partStaffCounts[i]);
03261     }
03262 }
03263 
03264 int OveSong::getPartCount() const {
03265     return partStaffCounts_.size();
03266 }
03267 
03268 int OveSong::getStaffCount(int part) const {
03269     if( part>=0 && part<(int)partStaffCounts_.size() ) {
03270         return partStaffCounts_[part];
03271     }
03272 
03273     return 0;
03274 }
03275 
03276 int OveSong::getPartBarCount() const {
03277     return measureDatas_.size() / tracks_.size();
03278 }
03279 
03280 QPair<int, int> OveSong::trackToPartStaff(int track) const {
03281     QPair<int, int> partStaff;
03282     int i;
03283     int staffCount = 0;
03284 
03285     for( i=0; i<partStaffCounts_.size(); ++i ) {
03286         if( staffCount + partStaffCounts_[i] > track ) {
03287             return qMakePair((int)i, track-staffCount);
03288         }
03289 
03290         staffCount += partStaffCounts_[i];
03291     }
03292 
03293     return qMakePair((int)partStaffCounts_.size(), 0);
03294 }
03295 
03296 int OveSong::partStaffToTrack(int part, int staff) const {
03297     int i;
03298     unsigned int staffCount = 0;
03299 
03300     for( i=0; i<partStaffCounts_.size(); ++i ) {
03301         if( part == (int)i && staff>=0 && staff<(int)partStaffCounts_[i] ) {
03302             int trackId = staffCount + staff;
03303 
03304             if( trackId >=0 && trackId < (int)tracks_.size() ) {
03305                 return trackId;
03306             }
03307         }
03308 
03309         staffCount += partStaffCounts_[i];
03310     }
03311 
03312     return tracks_.size();
03313 }
03314 
03315 void OveSong::setTextCodecName(const QString& codecName) {
03316     codec_ = QTextCodec::codecForName(codecName.toLatin1());
03317 }
03318 
03319 QString OveSong::getCodecString(const QByteArray& text) {
03320     QString s;
03321     if (codec_ == NULL)
03322         s = QString(text);
03323     else
03324         s = codec_->toUnicode(text);
03325 
03326     return s;
03327 }
03328 
03329 void OveSong::clear(void)
03330 {
03331     version4_ = true;
03332     quarter_ = 480;
03333     showPageMargin_ = false;
03334     showTransposeTrack = false;
03335     showLineBreak_ = false;
03336     showRuler_ = false;
03337     showColor_ = true;
03338     playRepeat_ = true;
03339     playStyle_ = Record;
03340 
03341     annotates_.clear();
03342     copyrights_.clear();
03343     footers_.clear();
03344     headers_.clear();
03345     titles_.clear();
03346     writers_.clear();
03347 
03348 //  deleteVector(tracks_);
03349     for(int i=0; i<tracks_.size(); ++i){
03350         delete tracks_[i];
03351     }
03352     for(int i=0; i<pages_.size(); ++i){
03353         delete pages_[i];
03354     }
03355     for(int i=0; i<lines_.size(); ++i){
03356         delete lines_[i];
03357     }
03358     for(int i=0; i<measures_.size(); ++i){
03359         delete measures_[i];
03360     }
03361     for(int i=0; i<measureDatas_.size(); ++i){
03362         delete measureDatas_[i];
03363     }
03364     tracks_.clear();
03365     pages_.clear();
03366     lines_.clear();
03367     measures_.clear();
03368     measureDatas_.clear();
03369     trackBarCount_ = 0;
03370     partStaffCounts_.clear();
03371 }
03372 
03374 Voice::Voice() {
03375     channel_ = 0;
03376     volume_ = -1;
03377     pitchShift_ = 0;
03378     pan_ = 0;
03379     patch_ = 0;
03380     stemType_ = 0;
03381 }
03382 
03383 void Voice::setChannel(int channel) {
03384     channel_ = channel;
03385 }
03386 
03387 int Voice::getChannel() const {
03388     return channel_;
03389 }
03390 
03391 void Voice::setVolume(int volume) {
03392     volume_ = volume;
03393 }
03394 
03395 int Voice::getVolume() const {
03396     return volume_;
03397 }
03398 
03399 void Voice::setPitchShift(int pitchShift) {
03400     pitchShift_ = pitchShift;
03401 }
03402 
03403 int Voice::getPitchShift() const {
03404     return pitchShift_;
03405 }
03406 
03407 void Voice::setPan(int pan) {
03408     pan_ = pan;
03409 }
03410 
03411 int Voice::getPan() const {
03412     return pan_;
03413 }
03414 
03415 void Voice::setPatch(int patch) {
03416     patch_ = patch;
03417 }
03418 
03419 int Voice::getPatch() const {
03420     return patch_;
03421 }
03422 
03423 void Voice::setStemType(int stemType) {
03424     stemType_ = stemType;
03425 }
03426 
03427 int Voice::getStemType() const {
03428     return stemType_;
03429 }
03430 
03431 int Voice::getDefaultPatch() {
03432     return -1;
03433 }
03434 
03435 int Voice::getDefaultVolume() {
03436     return -1;
03437 }
03438 
03440 Track::Track() {
03441     clear();
03442 }
03443 
03444 Track::~Track() {
03445     clear();
03446 }
03447 
03448 void Track::setName(const QString& str) {
03449     name_ = str;
03450 }
03451 
03452 QString Track::getName(void) const {
03453     return name_;
03454 }
03455 
03456 void Track::setBriefName(const QString& str) {
03457     briefName_ = str;
03458 }
03459 
03460 QString Track::getBriefName(void) const {
03461     return briefName_;
03462 }
03463 
03464 void Track::setPatch(unsigned int patch) {
03465     patch_ = patch;
03466 }
03467 
03468 unsigned int Track::getPatch() const {
03469     return patch_;
03470 }
03471 
03472 void Track::setChannel(int channel) {
03473     channel_ = channel;
03474 }
03475 
03476 int Track::getChannel() const {
03477     return channel_;
03478 }
03479 
03480 void Track::setShowName(bool show) {
03481     showName_ = show;
03482 }
03483 
03484 bool Track::getShowName() const {
03485     return showName_;
03486 }
03487 
03488 void Track::setShowBriefName(bool show) {
03489     showBriefName_ = show;
03490 }
03491 
03492 bool Track::getShowBriefName() const {
03493     return showBriefName_;
03494 }
03495 
03496 void Track::setMute(bool mute) {
03497     mute_ = mute;
03498 }
03499 
03500 bool Track::getMute() const {
03501     return mute_;
03502 }
03503 
03504 void Track::setSolo(bool solo) {
03505     solo_ = solo;
03506 }
03507 
03508 bool Track::getSolo() const {
03509     return solo_;
03510 }
03511 
03512 void Track::setShowKeyEachLine(bool show) {
03513     showKeyEachLine_ = show;
03514 }
03515 
03516 bool Track::getShowKeyEachLine() const {
03517     return showKeyEachLine_;
03518 }
03519 
03520 void Track::setVoiceCount(int voices) {
03521     voiceCount_ = voices;
03522 }
03523 
03524 int Track::getVoiceCount() const {
03525     return voiceCount_;
03526 }
03527 
03528 void Track::addVoice(Voice* voice) {
03529     voices_.push_back(voice);
03530 }
03531 
03532 QList<Voice*> Track::getVoices() const {
03533     return voices_;
03534 }
03535 
03536 void Track::setShowTranspose(bool show) {
03537     showTranspose_ = show;
03538 }
03539 
03540 bool Track::getShowTranspose() const {
03541     return showTranspose_;
03542 }
03543 
03544 void Track::setTranspose(int transpose) {
03545     transpose_ = transpose;
03546 }
03547 
03548 int Track::getTranspose() const {
03549     return transpose_;
03550 }
03551 
03552 void Track::setNoteShift(int shift) {
03553     noteShift_ = shift;
03554 }
03555 
03556 int Track::getNoteShift() const {
03557     return noteShift_;
03558 }
03559 
03560 void Track::setStartClef(int clef/*in Clef*/) {
03561     startClef_ = clef;
03562 }
03563 
03564 ClefType Track::getStartClef() const {
03565     return (ClefType)startClef_;
03566 }
03567 
03568 void Track::setTransposeClef(int clef) {
03569     transposeClef_ = clef;
03570 }
03571 
03572 int Track::getTansposeClef() const {
03573     return transposeClef_;
03574 }
03575 
03576 void Track::setStartKey(int key) {
03577     startKey_ = key;
03578 }
03579 
03580 int Track::getStartKey() const {
03581     return startKey_;
03582 }
03583 
03584 void Track::setDisplayPercent(unsigned int percent/*25~100?*/) {
03585     displayPercent_ = percent;
03586 }
03587 
03588 unsigned int Track::getDisplayPercent() const {
03589     return displayPercent_;
03590 }
03591 
03592 void Track::setShowLegerLine(bool show) {
03593     showLegerLine_ = show;
03594 }
03595 
03596 bool Track::getShowLegerLine() const {
03597     return showLegerLine_;
03598 }
03599 
03600 void Track::setShowClef(bool show) {
03601     showClef_ = show;
03602 }
03603 
03604 bool Track::getShowClef() const {
03605     return showClef_;
03606 }
03607 
03608 void Track::setShowTimeSignature(bool show) {
03609     showTimeSignature_ = show;
03610 }
03611 
03612 bool Track::getShowTimeSignature() const {
03613     return showTimeSignature_;
03614 }
03615 
03616 void Track::setShowKeySignature(bool show) {
03617     showKeySignature_ = show;
03618 }
03619 
03620 bool Track::getShowKeySignature() const {
03621     return showKeySignature_;
03622 }
03623 
03624 void Track::setShowBarline(bool show) {
03625     showBarline_ = show;
03626 }
03627 
03628 bool Track::getShowBarline() const {
03629     return showBarline_;
03630 }
03631 
03632 void Track::setFillWithRest(bool fill) {
03633     fillWithRest_ = fill;
03634 }
03635 
03636 bool Track::getFillWithRest() const {
03637     return fillWithRest_;
03638 }
03639 
03640 void Track::setFlatTail(bool flat) {
03641     flatTail_ = flat;
03642 }
03643 
03644 bool Track::getFlatTail() const {
03645     return flatTail_;
03646 }
03647 
03648 void Track::setShowClefEachLine(bool show) {
03649     showClefEachLine_ = show;
03650 }
03651 
03652 bool Track::getShowClefEachLine() const {
03653     return showClefEachLine_;
03654 }
03655 
03656 void Track::addDrum(const DrumNode& node) {
03657     /*DrumNode node;
03658     node.line_ = line;
03659     node.headType_ = headType;
03660     node.pitch_ = pitch;
03661     node.voice_ = voice;*/
03662     drumKit_.push_back(node);
03663 }
03664 
03665 QList<Track::DrumNode> Track::getDrumKit() const {
03666     return drumKit_;
03667 }
03668 
03669 void Track::setPart(int part) {
03670     part_ = part;
03671 }
03672 
03673 int Track::getPart() const {
03674     return part_;
03675 }
03676 
03677 void Track::clear(void) {
03678     number_ = 0;
03679 
03680     name_ = QString();
03681 
03682     patch_ = 0;
03683     channel_ = 0;
03684     transpose_ = 0;
03685     showTranspose_ = false;
03686     noteShift_ = 0;
03687     startClef_ = Clef_Treble;
03688     transposeClef_ = Clef_Treble;
03689     displayPercent_ = 100;
03690     startKey_ = 0;
03691     voiceCount_ = 8;
03692 
03693     showName_ = true;
03694     showBriefName_ = false;
03695     showKeyEachLine_ = false;
03696     showLegerLine_ = true;
03697     showClef_ = true;
03698     showTimeSignature_ = true;
03699     showKeySignature_ = true;
03700     showBarline_ = true;
03701     showClefEachLine_ = false;
03702 
03703     fillWithRest_ = true;
03704     flatTail_ = false;
03705 
03706     mute_ = false;
03707     solo_ = false;
03708 
03709     drumKit_.clear();
03710 
03711     part_ = 0;
03712 
03713     for(int i=0; i<voices_.size(); ++i){
03714         delete voices_[i];
03715     }
03716     voices_.clear();
03717 }
03718 
03720 Page::Page() {
03721     beginLine_ = 0;
03722     lineCount_ = 0;
03723 
03724     lineInterval_ = 9;
03725     staffInterval_ = 7;
03726     staffInlineInterval_ = 6;
03727 
03728     lineBarCount_ = 4;
03729     pageLineCount_ = 5;
03730 
03731     leftMargin_ = 0xA8;
03732     topMargin_ = 0xA8;
03733     rightMargin_ = 0xA8;
03734     bottomMargin_ = 0xA8;
03735 
03736     pageWidth_ = 0x0B40;
03737     pageHeight_ = 0x0E90;
03738 }
03739 
03740 void Page::setBeginLine(int line) {
03741     beginLine_ = line;
03742 }
03743 
03744 int Page::getBeginLine() const {
03745     return beginLine_;
03746 }
03747 
03748 void Page::setLineCount(int count) {
03749     lineCount_ = count;
03750 }
03751 
03752 int Page::getLineCount() const {
03753     return lineCount_;
03754 }
03755 
03756 void Page::setLineInterval(int interval) {
03757     lineInterval_ = interval;
03758 }
03759 
03760 int Page::getLineInterval() const {
03761     return lineInterval_;
03762 }
03763 
03764 void Page::setStaffInterval(int interval) {
03765     staffInterval_ = interval;
03766 }
03767 
03768 int Page::getStaffInterval() const {
03769     return staffInterval_;
03770 }
03771 
03772 void Page::setStaffInlineInterval(int interval) {
03773     staffInlineInterval_ = interval;
03774 }
03775 
03776 int Page::getStaffInlineInterval() const {
03777     return staffInlineInterval_;
03778 }
03779 
03780 void Page::setLineBarCount(int count) {
03781     lineBarCount_ = count;
03782 }
03783 
03784 int Page::getLineBarCount() const {
03785     return lineBarCount_;
03786 }
03787 
03788 void Page::setPageLineCount(int count) {
03789     pageLineCount_ = count;
03790 }
03791 
03792 int Page::getPageLineCount() const {
03793     return pageLineCount_;
03794 }
03795 
03796 void Page::setLeftMargin(int margin) {
03797     leftMargin_ = margin;
03798 }
03799 
03800 int Page::getLeftMargin() const {
03801     return leftMargin_;
03802 }
03803 
03804 void Page::setTopMargin(int margin) {
03805     topMargin_ = margin;
03806 }
03807 
03808 int Page::getTopMargin() const {
03809     return topMargin_;
03810 }
03811 
03812 void Page::setRightMargin(int margin) {
03813     rightMargin_ = margin;
03814 }
03815 
03816 int Page::getRightMargin() const {
03817     return rightMargin_;
03818 }
03819 
03820 void Page::setBottomMargin(int margin) {
03821     bottomMargin_ = margin;
03822 }
03823 
03824 int Page::getBottomMargin() const {
03825     return bottomMargin_;
03826 }
03827 
03828 void Page::setPageWidth(int width) {
03829     pageWidth_ = width;
03830 }
03831 
03832 int Page::getPageWidth() const {
03833     return pageWidth_;
03834 }
03835 
03836 void Page::setPageHeight(int height) {
03837     pageHeight_ = height;
03838 }
03839 
03840 int Page::getPageHeight() const {
03841     return pageHeight_;
03842 }
03843 
03845 Line::Line() {
03846     beginBar_ = 0;
03847     barCount_ = 0;
03848     yOffset_ = 0;
03849     leftXOffset_ = 0;
03850     rightXOffset_ = 0;
03851 }
03852 
03853 Line::~Line() {
03854     for(int i=0; i<staffs_.size(); ++i){
03855         delete staffs_[i];
03856     }
03857     staffs_.clear();
03858 }
03859 
03860 void Line::addStaff(Staff* staff) {
03861     staffs_.push_back(staff);
03862 }
03863 
03864 int Line::getStaffCount() const {
03865     return staffs_.size();
03866 }
03867 
03868 Staff* Line::getStaff(int idx) const {
03869     if (idx >= 0 && idx < (int) staffs_.size()) {
03870         return staffs_[idx];
03871     }
03872 
03873     return 0;
03874 }
03875 
03876 void Line::setBeginBar(unsigned int bar) {
03877     beginBar_ = bar;
03878 }
03879 
03880 unsigned int Line::getBeginBar() const {
03881     return beginBar_;
03882 }
03883 
03884 void Line::setBarCount(unsigned int count) {
03885     barCount_ = count;
03886 }
03887 
03888 unsigned int Line::getBarCount() const {
03889     return barCount_;
03890 }
03891 
03892 void Line::setYOffset(int offset) {
03893     yOffset_ = offset;
03894 }
03895 
03896 int Line::getYOffset() const {
03897     return yOffset_;
03898 }
03899 
03900 void Line::setLeftXOffset(int offset) {
03901     leftXOffset_ = offset;
03902 }
03903 
03904 int Line::getLeftXOffset() const {
03905     return leftXOffset_;
03906 }
03907 
03908 void Line::setRightXOffset(int offset) {
03909     rightXOffset_ = offset;
03910 }
03911 
03912 int Line::getRightXOffset() const {
03913     return rightXOffset_;
03914 }
03915 
03917 Staff::Staff() {
03918     clef_ = Clef_Treble;
03919     key_ = 0;
03920     visible_ = true;
03921     groupType_ = Group_None;
03922     groupStaffCount_ = 0;
03923 }
03924 
03925 void Staff::setClefType(int clef) {
03926     clef_ = (ClefType) clef;
03927 }
03928 
03929 ClefType Staff::getClefType() const {
03930     return clef_;
03931 }
03932 
03933 void Staff::setKeyType(int key) {
03934     key_ = key;
03935 }
03936 
03937 int Staff::getKeyType() const {
03938     return key_;
03939 }
03940 
03941 void Staff::setVisible(bool visible) {
03942     visible_ = visible;
03943 }
03944 
03945 bool Staff::setVisible() const {
03946     return visible_;
03947 }
03948 
03949 void Staff::setGroupType(GroupType type){
03950     groupType_ = type;
03951 }
03952 
03953 GroupType Staff::getGroupType() const {
03954     return groupType_;
03955 }
03956 
03957 void Staff::setGroupStaffCount(int count) {
03958     groupStaffCount_ = count;
03959 }
03960 
03961 int Staff::getGroupStaffCount() const {
03962     return groupStaffCount_;
03963 }
03964 
03966 Note::Note() {
03967     rest_ = false;
03968     note_ = 60;
03969     accidental_ = Accidental_Normal;
03970     showAccidental_ = false;
03971     offVelocity_ = 0x40;
03972     onVelocity_ = 0x50;
03973     headType_ = NoteHead_Standard;
03974     tiePos_ = Tie_None;
03975     offsetStaff_ = 0;
03976     show_ = true;
03977     offsetTick_ = 0;
03978 }
03979 
03980 void Note::setIsRest(bool rest) {
03981     rest_ = rest;
03982 }
03983 
03984 bool Note::getIsRest() const {
03985     return rest_;
03986 }
03987 
03988 void Note::setNote(unsigned int note) {
03989     note_ = note;
03990 }
03991 
03992 unsigned int Note::getNote() const {
03993     return note_;
03994 }
03995 
03996 void Note::setAccidental(int type) {
03997     accidental_ = (AccidentalType) type;
03998 }
03999 
04000 AccidentalType Note::getAccidental() const {
04001     return accidental_;
04002 }
04003 
04004 void Note::setShowAccidental(bool show) {
04005     showAccidental_ = show;
04006 }
04007 
04008 bool Note::getShowAccidental() const {
04009     return showAccidental_;
04010 }
04011 
04012 void Note::setOnVelocity(unsigned int velocity) {
04013     onVelocity_ = velocity;
04014 }
04015 
04016 unsigned int Note::getOnVelocity() const {
04017     return onVelocity_;
04018 }
04019 
04020 void Note::setOffVelocity(unsigned int velocity) {
04021     offVelocity_ = velocity;
04022 }
04023 
04024 unsigned int Note::getOffVelocity() const {
04025     return offVelocity_;
04026 }
04027 
04028 void Note::setHeadType(int type) {
04029     headType_ = (NoteHeadType) type;
04030 }
04031 
04032 NoteHeadType Note::getHeadType() const {
04033     return headType_;
04034 }
04035 
04036 void Note::setTiePos(int tiePos) {
04037     tiePos_ = (TiePos) tiePos;
04038 }
04039 
04040 TiePos Note::getTiePos() const {
04041     return tiePos_;
04042 }
04043 
04044 void Note::setOffsetStaff(int offset) {
04045     offsetStaff_ = offset;
04046 }
04047 
04048 int Note::getOffsetStaff() const {
04049     return offsetStaff_;
04050 }
04051 
04052 void Note::setShow(bool show) {
04053     show_ = show;
04054 }
04055 
04056 bool Note::getShow() const {
04057     return show_;
04058 }
04059 
04060 void Note::setOffsetTick(int offset) {
04061     offsetTick_ = offset;
04062 }
04063 
04064 int Note::getOffsetTick() const {
04065     return offsetTick_;
04066 }
04067 
04069 Articulation::Articulation() {
04070     type_ = Articulation_Marcato;
04071     above_ = true;
04072 
04073     changeSoundEffect_ = false;
04074     changeLength_ = false;
04075     changeVelocity_ = false;
04076     changeExtraLength_ = false;
04077 
04078     soundEffect_ = qMakePair(0, 0);
04079     lengthPercentage_ = 100;
04080     velocityType_ = Velocity_Offset;
04081     velocityValue_ = 0;
04082     extraLength_ = 0;
04083 
04084     trillNoteLength_ = 60;
04085     trillRate_ = Note_Sixteen;
04086     accelerateType_ = Accelerate_None;
04087     auxiliaryFirst_ = false;
04088     trillInterval_ = TrillInterval_Chromatic;
04089 }
04090 
04091 void Articulation::setArtType(int type) {
04092     type_ = (ArticulationType) type;
04093 }
04094 
04095 ArticulationType Articulation::getArtType() const {
04096     return type_;
04097 }
04098 
04099 void Articulation::setPlacementAbove(bool above) {
04100     above_ = above;
04101 }
04102 
04103 bool Articulation::getPlacementAbove() const {
04104     return above_;
04105 }
04106 
04107 bool Articulation::getChangeSoundEffect() const {
04108     return changeSoundEffect_;
04109 }
04110 
04111 void Articulation::setSoundEffect(int soundFrom, int soundTo) {
04112     soundEffect_ = qMakePair(soundFrom, soundTo);
04113     changeSoundEffect_ = true;
04114 }
04115 
04116 QPair<int, int> Articulation::getSoundEffect() const {
04117     return soundEffect_;
04118 }
04119 
04120 bool Articulation::getChangeLength() const {
04121     return changeLength_;
04122 }
04123 
04124 void Articulation::setLengthPercentage(int percentage) {
04125     lengthPercentage_ = percentage;
04126     changeLength_ = true;
04127 }
04128 
04129 int Articulation::getLengthPercentage() const {
04130     return lengthPercentage_;
04131 }
04132 
04133 bool Articulation::getChangeVelocity() const {
04134     return changeVelocity_;
04135 }
04136 
04137 void Articulation::setVelocityType(VelocityType type) {
04138     velocityType_ = type;
04139     changeVelocity_ = true;
04140 }
04141 
04142 Articulation::VelocityType Articulation::getVelocityType() const {
04143     return velocityType_;
04144 }
04145 
04146 void Articulation::setVelocityValue(int value) {
04147     velocityValue_ = value;
04148 }
04149 
04150 int Articulation::getVelocityValue() const {
04151     return velocityValue_;
04152 }
04153 
04154 bool Articulation::getChangeExtraLength() const {
04155     return changeExtraLength_;
04156 }
04157 
04158 void Articulation::setExtraLength(int length) {
04159     extraLength_ = length;
04160     changeExtraLength_ = true;
04161 }
04162 
04163 int Articulation::getExtraLength() const {
04164     return extraLength_;
04165 }
04166 
04167 void Articulation::setTrillNoteLength(int length) {
04168     trillNoteLength_ = length;
04169 }
04170 
04171 int Articulation::getTrillNoteLength() const {
04172     return trillNoteLength_;
04173 }
04174 
04175 void Articulation::setTrillRate(NoteType rate) {
04176     trillRate_ = rate;
04177 }
04178 
04179 NoteType Articulation::getTrillRate() const {
04180     return trillRate_;
04181 }
04182 
04183 void Articulation::setAccelerateType(int type) {
04184     accelerateType_ = (AccelerateType) type;
04185 }
04186 
04187 Articulation::AccelerateType Articulation::getAccelerateType() const {
04188     return accelerateType_;
04189 }
04190 
04191 void Articulation::setAuxiliaryFirst(bool first) {
04192     auxiliaryFirst_ = first;
04193 }
04194 
04195 bool Articulation::getAuxiliaryFirst() const {
04196     return auxiliaryFirst_;
04197 }
04198 
04199 void Articulation::setTrillInterval(int interval) {
04200     trillInterval_ = (TrillInterval) interval;
04201 }
04202 
04203 Articulation::TrillInterval Articulation::getTrillInterval() const {
04204     return trillInterval_;
04205 }
04206 
04207 bool Articulation::willAffectNotes() const {
04208     bool affect = false;
04209 
04210     switch (getArtType()) {
04211     case Articulation_Major_Trill:
04212     case Articulation_Minor_Trill:
04213     case Articulation_Trill_Section:
04214     case Articulation_Inverted_Short_Mordent:
04215     case Articulation_Inverted_Long_Mordent:
04216     case Articulation_Short_Mordent:
04217     case Articulation_Turn:
04218 
04219     case Articulation_Arpeggio:
04220     case Articulation_Tremolo_Eighth:
04221     case Articulation_Tremolo_Sixteenth:
04222     case Articulation_Tremolo_Thirty_Second:
04223     case Articulation_Tremolo_Sixty_Fourth: {
04224         affect = true;
04225         break;
04226     }
04227     case Articulation_Finger_1:
04228     case Articulation_Finger_2:
04229     case Articulation_Finger_3:
04230     case Articulation_Finger_4:
04231     case Articulation_Finger_5:
04232     case Articulation_Flat_Accidental_For_Trill:
04233     case Articulation_Sharp_Accidental_For_Trill:
04234     case Articulation_Natural_Accidental_For_Trill:
04235     case Articulation_Marcato:
04236     case Articulation_Marcato_Dot:
04237     case Articulation_Heavy_Attack:
04238     case Articulation_SForzando:
04239     case Articulation_SForzando_Dot:
04240     case Articulation_Heavier_Attack:
04241     case Articulation_SForzando_Inverted:
04242     case Articulation_SForzando_Dot_Inverted:
04243     case Articulation_Staccatissimo:
04244     case Articulation_Staccato:
04245     case Articulation_Tenuto:
04246     case Articulation_Up_Bow:
04247     case Articulation_Down_Bow:
04248     case Articulation_Up_Bow_Inverted:
04249     case Articulation_Down_Bow_Inverted:
04250     case Articulation_Natural_Harmonic:
04251     case Articulation_Artificial_Harmonic:
04252     case Articulation_Plus_Sign:
04253     case Articulation_Fermata:
04254     case Articulation_Fermata_Inverted:
04255     case Articulation_Pedal_Down:
04256     case Articulation_Pedal_Up:
04257     case Articulation_Pause:
04258     case Articulation_Grand_Pause:
04259     case Articulation_Toe_Pedal:
04260     case Articulation_Heel_Pedal:
04261     case Articulation_Toe_To_Heel_Pedal:
04262     case Articulation_Heel_To_Toe_Pedal:
04263     case Articulation_Open_String:
04264     case Articulation_Guitar_Lift:
04265     case Articulation_Guitar_Slide_Up:
04266     case Articulation_Guitar_Rip:
04267     case Articulation_Guitar_Fall_Off:
04268     case Articulation_Guitar_Slide_Down:
04269     case Articulation_Guitar_Spill:
04270     case Articulation_Guitar_Flip:
04271     case Articulation_Guitar_Smear:
04272     case Articulation_Guitar_Bend:
04273     case Articulation_Guitar_Doit:
04274     case Articulation_Guitar_Plop:
04275     case Articulation_Guitar_Wow_Wow:
04276     case Articulation_Guitar_Thumb:
04277     case Articulation_Guitar_Index_Finger:
04278     case Articulation_Guitar_Middle_Finger:
04279     case Articulation_Guitar_Ring_Finger:
04280     case Articulation_Guitar_Pinky_Finger:
04281     case Articulation_Guitar_Tap:
04282     case Articulation_Guitar_Hammer:
04283     case Articulation_Guitar_Pluck: {
04284         break;
04285     }
04286     default:
04287         break;
04288     }
04289 
04290     return affect;
04291 }
04292 
04293 bool Articulation::isTrill(ArticulationType type) {
04294     bool isTrill = false;
04295 
04296     switch (type) {
04297     case Articulation_Major_Trill:
04298     case Articulation_Minor_Trill:
04299     case Articulation_Trill_Section: {
04300         isTrill = true;
04301         break;
04302     }
04303     default:
04304         break;
04305     }
04306 
04307     return isTrill;
04308 }
04309 
04310 Articulation::XmlType Articulation::getXmlType() const {
04311     XmlType xmlType = Xml_Unknown;
04312 
04313     switch (type_) {
04314     case Articulation_Major_Trill:
04315     case Articulation_Minor_Trill:
04316     case Articulation_Trill_Section:
04317     case Articulation_Inverted_Short_Mordent:
04318     case Articulation_Inverted_Long_Mordent:
04319     case Articulation_Short_Mordent:
04320     case Articulation_Turn:
04321         //  case Articulation_Flat_Accidental_For_Trill :
04322         //  case Articulation_Sharp_Accidental_For_Trill :
04323         //  case Articulation_Natural_Accidental_For_Trill :
04324     case Articulation_Tremolo_Eighth:
04325     case Articulation_Tremolo_Sixteenth:
04326     case Articulation_Tremolo_Thirty_Second:
04327     case Articulation_Tremolo_Sixty_Fourth: {
04328         xmlType = Xml_Ornament;
04329         break;
04330     }
04331     case Articulation_Marcato:
04332     case Articulation_Marcato_Dot:
04333     case Articulation_Heavy_Attack:
04334     case Articulation_SForzando:
04335     case Articulation_SForzando_Inverted:
04336     case Articulation_SForzando_Dot:
04337     case Articulation_SForzando_Dot_Inverted:
04338     case Articulation_Heavier_Attack:
04339     case Articulation_Staccatissimo:
04340     case Articulation_Staccato:
04341     case Articulation_Tenuto:
04342     case Articulation_Pause:
04343     case Articulation_Grand_Pause: {
04344         xmlType = Xml_Articulation;
04345         break;
04346     }
04347     case Articulation_Up_Bow:
04348     case Articulation_Down_Bow:
04349     case Articulation_Up_Bow_Inverted:
04350     case Articulation_Down_Bow_Inverted:
04351     case Articulation_Natural_Harmonic:
04352     case Articulation_Artificial_Harmonic:
04353     case Articulation_Finger_1:
04354     case Articulation_Finger_2:
04355     case Articulation_Finger_3:
04356     case Articulation_Finger_4:
04357     case Articulation_Finger_5:
04358     case Articulation_Plus_Sign: {
04359         xmlType = Xml_Technical;
04360         break;
04361     }
04362     case Articulation_Arpeggio: {
04363         xmlType = Xml_Arpeggiate;
04364         break;
04365     }
04366     case Articulation_Fermata:
04367     case Articulation_Fermata_Inverted: {
04368         xmlType = Xml_Fermata;
04369         break;
04370     }
04371     case Articulation_Pedal_Down:
04372     case Articulation_Pedal_Up: {
04373         xmlType = Xml_Direction;
04374         break;
04375     }
04376         //  case Articulation_Toe_Pedal :
04377         //  case Articulation_Heel_Pedal :
04378         //  case Articulation_Toe_To_Heel_Pedal :
04379         //  case Articulation_Heel_To_Toe_Pedal :
04380         //  case Articulation_Open_String :
04381     default:
04382         break;
04383     }
04384 
04385     return xmlType;
04386 }
04387 
04389 NoteContainer::NoteContainer() {
04390     musicDataType_ = MusicData_Note_Container;
04391 
04392     grace_ = false;
04393     cue_ = false;
04394     rest_ = false;
04395     raw_ = false;
04396     noteType_ = Note_Quarter;
04397     dot_ = 0;
04398     graceNoteType_ = Note_Eight;
04399     stemUp_ = true;
04400     showStem_ = true;
04401     stemLength_ = 7;
04402     inBeam_ = false;
04403     tuplet_ = 0;
04404     space_ = 2;//div by 0
04405     noteShift_ = 0;
04406 }
04407 
04408 NoteContainer::~NoteContainer(){
04409     for(int i=0; i<notes_.size(); ++i){
04410         delete notes_[i];
04411     }
04412     for(int i=0; i<articulations_.size(); ++i){
04413         delete articulations_[i];
04414     }
04415     notes_.clear();
04416     articulations_.clear();
04417 }
04418 
04419 void NoteContainer::setIsGrace(bool grace) {
04420     grace_ = grace;
04421 }
04422 
04423 bool NoteContainer::getIsGrace() const {
04424     return grace_;
04425 }
04426 
04427 void NoteContainer::setIsCue(bool cue) {
04428     cue_ = cue;
04429 }
04430 
04431 bool NoteContainer::getIsCue() const {
04432     return cue_;
04433 }
04434 
04435 void NoteContainer::setIsRest(bool rest) {
04436     rest_ = rest;
04437 }
04438 
04439 bool NoteContainer::getIsRest() const {
04440     return rest_;
04441 }
04442 
04443 void NoteContainer::setIsRaw(bool raw) {
04444     raw_ = raw;
04445 }
04446 
04447 bool NoteContainer::getIsRaw() const {
04448     return raw_;
04449 }
04450 
04451 void NoteContainer::setNoteType(NoteType type) {
04452     noteType_ = Note_Quarter;
04453 
04454     switch (type) {
04455     case Note_DoubleWhole:
04456     case Note_Whole:
04457     case Note_Half:
04458     case Note_Quarter:
04459     case Note_Eight:
04460     case Note_Sixteen:
04461     case Note_32:
04462     case Note_64:
04463     case Note_128:
04464     case Note_256: {
04465         noteType_ = type;
04466         break;
04467     }
04468     default: {
04469         break;
04470     }
04471     }
04472 }
04473 
04474 NoteType NoteContainer::getNoteType() const {
04475     return noteType_;
04476 }
04477 
04478 void NoteContainer::setDot(int dot) {
04479     dot_ = dot;
04480 }
04481 
04482 int NoteContainer::getDot() const {
04483     return dot_;
04484 }
04485 
04486 void NoteContainer::setGraceNoteType(NoteType type) {
04487     graceNoteType_ = type;
04488 }
04489 
04490 NoteType NoteContainer::getGraceNoteType() const {
04491     return graceNoteType_;
04492 }
04493 
04494 void NoteContainer::setInBeam(bool in) {
04495     inBeam_ = in;
04496 }
04497 
04498 bool NoteContainer::getInBeam() const {
04499     return inBeam_;
04500 }
04501 
04502 void NoteContainer::setStemUp(bool up) {
04503     stemUp_ = up;
04504 }
04505 
04506 bool NoteContainer::getStemUp(void) const {
04507     return stemUp_;
04508 }
04509 
04510 void NoteContainer::setShowStem(bool show) {
04511     showStem_ = show;
04512 }
04513 
04514 bool NoteContainer::getShowStem() const {
04515     return showStem_;
04516 }
04517 
04518 void NoteContainer::setStemLength(int line) {
04519     stemLength_ = line;
04520 }
04521 
04522 int NoteContainer::getStemLength() const {
04523     return stemLength_;
04524 }
04525 
04526 void NoteContainer::setTuplet(int tuplet) {
04527     tuplet_ = tuplet;
04528 }
04529 
04530 int NoteContainer::getTuplet() const {
04531     return tuplet_;
04532 }
04533 
04534 void NoteContainer::setSpace(int space) {
04535     space_ = space;
04536 }
04537 
04538 int NoteContainer::getSpace() const {
04539     return space_;
04540 }
04541 
04542 void NoteContainer::addNoteRest(Note* note) {
04543     notes_.push_back(note);
04544 }
04545 
04546 QList<Note*> NoteContainer::getNotesRests() const {
04547     return notes_;
04548 }
04549 
04550 void NoteContainer::addArticulation(Articulation* art) {
04551     articulations_.push_back(art);
04552 }
04553 
04554 QList<Articulation*> NoteContainer::getArticulations() const {
04555     return articulations_;
04556 }
04557 
04558 void NoteContainer::setNoteShift(int octave) {
04559     noteShift_ = octave;
04560 }
04561 
04562 int NoteContainer::getNoteShift() const {
04563     return noteShift_;
04564 }
04565 
04566 int NoteContainer::getOffsetStaff() const {
04567     if(getIsRest())
04568         return 0;
04569 
04570     int staffMove = 0;
04571     QList<OVE::Note*> notes = getNotesRests();
04572     for (int i = 0; i < notes.size(); ++i) {
04573         OVE::Note* notePtr = notes[i];
04574         staffMove = notePtr->getOffsetStaff();
04575     }
04576 
04577     return staffMove;
04578 }
04579 
04580 int NoteContainer::getDuration() const {
04581     int duration = (int) NoteDuration_4;
04582 
04583     switch (noteType_) {
04584     case Note_DoubleWhole: {
04585         duration = (int) NoteDuration_Double_Whole;
04586         break;
04587     }
04588     case Note_Whole: {
04589         duration = (int) NoteDuration_Whole;
04590         break;
04591     }
04592     case Note_Half: {
04593         duration = (int) NoteDuration_2;
04594         break;
04595     }
04596     case Note_Quarter: {
04597         duration = (int) NoteDuration_4;
04598         break;
04599     }
04600     case Note_Eight: {
04601         duration = (int) NoteDuration_8;
04602         break;
04603     }
04604     case Note_Sixteen: {
04605         duration = (int) NoteDuration_16;
04606         break;
04607     }
04608     case Note_32: {
04609         duration = (int) NoteDuration_32;
04610         break;
04611     }
04612     case Note_64: {
04613         duration = (int) NoteDuration_64;
04614         break;
04615     }
04616     case Note_128: {
04617         duration = (int) NoteDuration_128;
04618         break;
04619     }
04620     case Note_256: {
04621         duration = (int) NoteDuration_256;
04622         break;
04623     }
04624     default:
04625         break;
04626     }
04627 
04628     int dotLength = duration;
04629 
04630     for (int i = 0; i < dot_; ++i) {
04631         dotLength /= 2;
04632     }
04633 
04634     dotLength = duration - dotLength;
04635 
04636     duration += dotLength;
04637 
04638     return duration;
04639 }
04640 
04642 Beam::Beam() {
04643     musicDataType_ = MusicData_Beam;
04644     grace_ = false;
04645 }
04646 
04647 void Beam::setIsGrace(bool grace) {
04648     grace_ = grace;
04649 }
04650 
04651 bool Beam::getIsGrace() const {
04652     return grace_;
04653 }
04654 
04655 void Beam::addLine(const MeasurePos& startMp, const MeasurePos& endMp) {
04656     lines_.push_back(qMakePair(startMp, endMp));
04657 }
04658 
04659 const QList<QPair<MeasurePos, MeasurePos> > Beam::getLines() const {
04660     return lines_;
04661 }
04662 
04664 Tie::Tie() {
04665     musicDataType_ = MusicData_Tie;
04666 
04667     showOnTop_ = true;
04668     note_ = 72;
04669     height_ = 24;
04670 }
04671 
04672 void Tie::setShowOnTop(bool top) {
04673     showOnTop_ = top;
04674 }
04675 
04676 bool Tie::getShowOnTop() const {
04677     return showOnTop_;
04678 }
04679 
04680 void Tie::setNote(int note) {
04681     note_ = note;
04682 }
04683 
04684 int Tie::getNote() const {
04685     return note_;
04686 }
04687 
04688 void Tie::setHeight(int height) {
04689     height_ = height;
04690 }
04691 
04692 int Tie::getHeight() const {
04693     return height_;
04694 }
04695 
04697 Glissando::Glissando() {
04698     musicDataType_ = MusicData_Glissando;
04699 
04700     straight_ = true;
04701     text_ = "gliss.";
04702     lineThick_ = 8;
04703 }
04704 
04705 void Glissando::setStraightWavy(bool straight) {
04706     straight_ = straight;
04707 }
04708 
04709 bool Glissando::getStraightWavy() const {
04710     return straight_;
04711 }
04712 
04713 void Glissando::setText(const QString& text) {
04714     text_ = text;
04715 }
04716 
04717 QString Glissando::getText() const {
04718     return text_;
04719 }
04720 
04721 void Glissando::setLineThick(int thick) {
04722     lineThick_ = thick;
04723 }
04724 
04725 int Glissando::getLineThick() const {
04726     return lineThick_;
04727 }
04728 
04730 Decorator::Decorator() :
04731     decoratorType_(Decorator_Articulation),
04732     artType_(Articulation_Marcato) {
04733     musicDataType_ = MusicData_Decorator;
04734 }
04735 
04736 void Decorator::setDecoratorType(DecoratorType type) {
04737     decoratorType_ = type;
04738 }
04739 
04740 Decorator::DecoratorType Decorator::getDecoratorType() const {
04741     return decoratorType_;
04742 }
04743 
04744 void Decorator::setArticulationType(ArticulationType type) {
04745     artType_ = type;
04746 }
04747 
04748 ArticulationType Decorator::getArticulationType() const {
04749     return artType_;
04750 }
04751 
04753 MeasureRepeat::MeasureRepeat() {
04754     musicDataType_ = MusicData_Measure_Repeat;
04755     singleRepeat_ = true;
04756 }
04757 
04758 void MeasureRepeat::setSingleRepeat(bool single) {
04759     singleRepeat_ = single;
04760 
04761     start()->setMeasure(0);
04762     start()->setOffset(0);
04763     stop()->setMeasure(single ? 1 : 2);
04764     stop()->setOffset(0);
04765 }
04766 
04767 bool MeasureRepeat::getSingleRepeat() const {
04768     return singleRepeat_;
04769 }
04770 
04772 Tuplet::Tuplet() :
04773     tuplet_(3), space_(2), height_(0), noteType_(Note_Quarter){
04774     musicDataType_ = MusicData_Tuplet;
04775     mark_ = new OffsetElement();
04776 }
04777 
04778 Tuplet::~Tuplet(){
04779     delete mark_;
04780 }
04781 
04782 void Tuplet::setTuplet(int tuplet) {
04783     tuplet_ = tuplet;
04784 }
04785 
04786 int Tuplet::getTuplet() const {
04787     return tuplet_;
04788 }
04789 
04790 void Tuplet::setSpace(int space) {
04791     space_ = space;
04792 }
04793 
04794 int Tuplet::getSpace() const {
04795     return space_;
04796 }
04797 
04798 OffsetElement* Tuplet::getMarkHandle() const {
04799     return mark_;
04800 }
04801 
04802 void Tuplet::setHeight(int height) {
04803     height_ = height;
04804 }
04805 
04806 int Tuplet::getHeight() const {
04807     return height_;
04808 }
04809 
04810 void Tuplet::setNoteType(NoteType type) {
04811     noteType_ = type;
04812 }
04813 
04814 NoteType Tuplet::getNoteType() const {
04815     return noteType_;
04816 }
04817 
04819 Harmony::Harmony() {
04820     musicDataType_ = MusicData_Harmony;
04821 
04822     harmonyType_ = Harmony_maj;
04823     root_ = 0;
04824     bass_ = -1;//0xff
04825     bassOnBottom_ = false;
04826     angle_ = 0;
04827 }
04828 
04829 void Harmony::setHarmonyType(HarmonyType type) {
04830     harmonyType_ = type;
04831 }
04832 
04833 HarmonyType Harmony::getHarmonyType() const {
04834     return harmonyType_;
04835 }
04836 
04837 void Harmony::setRoot(int root) {
04838     root_ = root;
04839 }
04840 
04841 int Harmony::getRoot() const {
04842     return root_;
04843 }
04844 
04845 void Harmony::setBass(int bass) {
04846     bass_ = bass;
04847 }
04848 
04849 int Harmony::getBass() const {
04850     return bass_;
04851 }
04852 
04853 void Harmony::setBassOnBottom(bool on) {
04854     bassOnBottom_ = on;
04855 }
04856 
04857 bool Harmony::getBassOnBottom() const {
04858     return bassOnBottom_;
04859 }
04860 
04861 void Harmony::setAngle(int angle) {
04862     angle_ = angle;
04863 }
04864 
04865 int Harmony::getAngle() const {
04866     return angle_;
04867 }
04868 
04870 Clef::Clef() {
04871     musicDataType_ = MusicData_Clef;
04872 
04873     clefType_ = Clef_Treble;
04874 }
04875 
04876 void Clef::setClefType(int type) {
04877     clefType_ = (ClefType) type;
04878 }
04879 
04880 ClefType Clef::getClefType() const {
04881     return clefType_;
04882 }
04883 
04885 Lyric::Lyric() {
04886     musicDataType_ = MusicData_Lyric;
04887 
04888     lyric_ = QString();
04889     verse_ = 0;
04890 }
04891 
04892 void Lyric::setLyric(const QString& lyricText) {
04893     lyric_ = lyricText;
04894 }
04895 
04896 QString Lyric::getLyric() const {
04897     return lyric_;
04898 }
04899 
04900 void Lyric::setVerse(int verse) {
04901     verse_ = verse;
04902 }
04903 
04904 int Lyric::getVerse() const {
04905     return verse_;
04906 }
04907 
04909 Slur::Slur() {
04910     musicDataType_ = MusicData_Slur;
04911 
04912     containerCount_ = 1;
04913     showOnTop_ = true;
04914     noteTimePercent_ = 100;
04915 
04916     handle_2_ = new OffsetElement();
04917     handle_3_ = new OffsetElement();
04918 }
04919 
04920 Slur::~Slur() {
04921     delete handle_2_;
04922     delete handle_3_;
04923 }
04924 
04925 void Slur::setContainerCount(int count) {
04926     containerCount_ = count;
04927 }
04928 
04929 int Slur::getContainerCount() const {
04930     return containerCount_;
04931 }
04932 
04933 void Slur::setShowOnTop(bool top) {
04934     showOnTop_ = top;
04935 }
04936 
04937 bool Slur::getShowOnTop() const {
04938     return showOnTop_;
04939 }
04940 
04941 OffsetElement* Slur::getHandle2() const {
04942     return handle_2_;
04943 }
04944 
04945 OffsetElement* Slur::getHandle3() const {
04946     return handle_3_;
04947 }
04948 
04949 void Slur::setNoteTimePercent(int percent) {
04950     noteTimePercent_ = percent;
04951 }
04952 
04953 int Slur::getNoteTimePercent() const {
04954     return noteTimePercent_;
04955 }
04956 
04958 Dynamics::Dynamics() {
04959     musicDataType_ = MusicData_Dynamics;
04960 
04961     dynamicsType_ = Dynamics_pppp;
04962     playback_ = true;
04963     velocity_ = 30;
04964 }
04965 
04966 void Dynamics::setDynamicsType(int type) {
04967     dynamicsType_ = (DynamicsType) type;
04968 }
04969 
04970 DynamicsType Dynamics::getDynamicsType() const {
04971     return dynamicsType_;
04972 }
04973 
04974 void Dynamics::setIsPlayback(bool play) {
04975     playback_ = play;
04976 }
04977 
04978 bool Dynamics::getIsPlayback() const {
04979     return playback_;
04980 }
04981 
04982 void Dynamics::setVelocity(int vel) {
04983     velocity_ = vel;
04984 }
04985 
04986 int Dynamics::getVelocity() const {
04987     return velocity_;
04988 }
04989 
04991 WedgeEndPoint::WedgeEndPoint() {
04992     musicDataType_ = MusicData_Wedge_EndPoint;
04993 
04994     wedgeType_ = Wedge_Cres;
04995     height_ = 24;
04996     wedgeStart_ = true;
04997 }
04998 
04999 void WedgeEndPoint::setWedgeType(WedgeType type) {
05000     wedgeType_ = type;
05001 }
05002 
05003 WedgeType WedgeEndPoint::getWedgeType() const {
05004     return wedgeType_;
05005 }
05006 
05007 void WedgeEndPoint::setHeight(int height) {
05008     height_ = height;
05009 }
05010 
05011 int WedgeEndPoint::getHeight() const {
05012     return height_;
05013 }
05014 
05015 void WedgeEndPoint::setWedgeStart(bool wedgeStart) {
05016     wedgeStart_ = wedgeStart;
05017 }
05018 
05019 bool WedgeEndPoint::getWedgeStart() const {
05020     return wedgeStart_;
05021 }
05022 
05024 Wedge::Wedge() {
05025     musicDataType_ = MusicData_Wedge;
05026 
05027     wedgeType_ = Wedge_Cres;
05028     height_ = 24;
05029 }
05030 
05031 void Wedge::setWedgeType(WedgeType type) {
05032     wedgeType_ = type;
05033 }
05034 
05035 WedgeType Wedge::getWedgeType() const {
05036     return wedgeType_;
05037 }
05038 
05039 void Wedge::setHeight(int height) {
05040     height_ = height;
05041 }
05042 
05043 int Wedge::getHeight() const {
05044     return height_;
05045 }
05046 
05048 Pedal::Pedal() {
05049     musicDataType_ = MusicData_Pedal;
05050 
05051     half_ = false;
05052     playback_ = false;
05053     playOffset_ = 0;
05054 
05055     pedalHandle_ = new OffsetElement();
05056 }
05057 
05058 Pedal::~Pedal() {
05059     delete pedalHandle_;
05060 }
05061 
05062 void Pedal::setHalf(bool half) {
05063     half_ = half;
05064 }
05065 
05066 bool Pedal::getHalf() const {
05067     return half_;
05068 }
05069 
05070 OffsetElement* Pedal::getPedalHandle() const {
05071     return pedalHandle_;
05072 }
05073 
05074 void Pedal::setIsPlayback(bool playback) {
05075     playback_ = playback;
05076 }
05077 
05078 bool Pedal::getIsPlayback() const {
05079     return playback_;
05080 }
05081 
05082 void Pedal::setPlayOffset(int offset) {
05083     playOffset_ = offset;
05084 }
05085 
05086 int Pedal::getPlayOffset() const {
05087     return playOffset_;
05088 }
05089 
05091 KuoHao::KuoHao() {
05092     musicDataType_ = MusicData_KuoHao;
05093 
05094     kuohaoType_ = KuoHao_Parentheses;
05095     height_ = 0;
05096 }
05097 
05098 void KuoHao::setHeight(int height) {
05099     height_ = height;
05100 }
05101 
05102 int KuoHao::getHeight() const {
05103     return height_;
05104 }
05105 
05106 void KuoHao::setKuohaoType(int type) {
05107     kuohaoType_ = (KuoHaoType) type;
05108 }
05109 
05110 KuoHaoType KuoHao::getKuohaoType() const {
05111     return kuohaoType_;
05112 }
05113 
05115 Expressions::Expressions() {
05116     musicDataType_ = MusicData_Expressions;
05117 
05118     text_ = QString();
05119 }
05120 
05121 void Expressions::setText(const QString& str) {
05122     text_ = str;
05123 }
05124 
05125 QString Expressions::getText() const {
05126     return text_;
05127 }
05128 
05130 HarpPedal::HarpPedal() :
05131     showType_(0),
05132     showCharFlag_(0) {
05133     musicDataType_ = MusicData_Harp_Pedal;
05134 }
05135 
05136 void HarpPedal::setShowType(int type) {
05137     showType_ = type;
05138 }
05139 
05140 int HarpPedal::getShowType() const {
05141     return showType_;
05142 }
05143 
05144 void HarpPedal::setShowCharFlag(int flag) {
05145     showCharFlag_ = flag;
05146 }
05147 
05148 int HarpPedal::getShowCharFlag() const {
05149     return showCharFlag_;
05150 }
05151 
05153 OctaveShift::OctaveShift() :
05154     octaveShiftType_(OctaveShift_8),
05155     octaveShiftPosition_(OctavePosition_Start),
05156     endTick_(0) {
05157     musicDataType_ = MusicData_OctaveShift;
05158 }
05159 
05160 void OctaveShift::setOctaveShiftType(int type) {
05161     octaveShiftType_ = (OctaveShiftType) type;
05162 }
05163 
05164 OctaveShiftType OctaveShift::getOctaveShiftType() const {
05165     return octaveShiftType_;
05166 }
05167 
05168 int OctaveShift::getNoteShift() const {
05169     int shift = 12;
05170 
05171     switch (getOctaveShiftType()) {
05172     case OctaveShift_8: {
05173         shift = 12;
05174         break;
05175     }
05176     case OctaveShift_Minus_8: {
05177         shift = -12;
05178         break;
05179     }
05180     case OctaveShift_15: {
05181         shift = 24;
05182         break;
05183     }
05184     case OctaveShift_Minus_15: {
05185         shift = -24;
05186         break;
05187     }
05188     default:
05189         break;
05190     }
05191 
05192     return shift;
05193 }
05194 
05195 void OctaveShift::setEndTick(int tick) {
05196     endTick_ = tick;
05197 }
05198 
05199 int OctaveShift::getEndTick() const {
05200     return endTick_;
05201 }
05202 
05204 OctaveShiftEndPoint::OctaveShiftEndPoint() {
05205     musicDataType_ = MusicData_OctaveShift_EndPoint;
05206 
05207     octaveShiftType_ = OctaveShift_8;
05208     octaveShiftPosition_ = OctavePosition_Start;
05209     endTick_ = 0;
05210 }
05211 
05212 void OctaveShiftEndPoint::setOctaveShiftType(int type) {
05213     octaveShiftType_ = (OctaveShiftType) type;
05214 }
05215 
05216 OctaveShiftType OctaveShiftEndPoint::getOctaveShiftType() const {
05217     return octaveShiftType_;
05218 }
05219 
05220 void OctaveShiftEndPoint::setOctaveShiftPosition(int position) {
05221     octaveShiftPosition_ = (OctaveShiftPosition) position;
05222 }
05223 
05224 OctaveShiftPosition OctaveShiftEndPoint::getOctaveShiftPosition() const {
05225     return octaveShiftPosition_;
05226 }
05227 
05228 void OctaveShiftEndPoint::setEndTick(int tick) {
05229     endTick_ = tick;
05230 }
05231 
05232 int OctaveShiftEndPoint::getEndTick() const {
05233     return endTick_;
05234 }
05235 
05237 MultiMeasureRest::MultiMeasureRest() {
05238     musicDataType_ = MusicData_Multi_Measure_Rest;
05239     measureCount_ = 0;
05240 }
05241 
05242 void MultiMeasureRest::setMeasureCount(int count) {
05243     measureCount_ = count;
05244 }
05245 
05246 int MultiMeasureRest::getMeasureCount() const {
05247     return measureCount_;
05248 }
05249 
05251 Tempo::Tempo() {
05252     musicDataType_ = MusicData_Tempo;
05253 
05254     leftNoteType_ = 3;
05255     showMark_ = false;
05256     showText_ = false;
05257     showParenthesis_ = false;
05258     typeTempo_ = 96;
05259     leftText_ = QString();
05260     rightText_ = QString();
05261     swingEighth_ = false;
05262     rightNoteType_ = 3;
05263 }
05264 
05265 void Tempo::setLeftNoteType(int type) {
05266     leftNoteType_ = type;
05267 }
05268 
05269 NoteType Tempo::getLeftNoteType() const {
05270     return (NoteType) leftNoteType_;
05271 }
05272 
05273 void Tempo::setShowMark(bool show) {
05274     showMark_ = show;
05275 }
05276 
05277 bool Tempo::getShowMark() const {
05278     return showMark_;
05279 }
05280 
05281 void Tempo::setShowBeforeText(bool show) {
05282     showText_ = show;
05283 }
05284 
05285 bool Tempo::getShowBeforeText() const {
05286     return showText_;
05287 }
05288 
05289 void Tempo::setShowParenthesis(bool show) {
05290     showParenthesis_ = show;
05291 }
05292 
05293 bool Tempo::getShowParenthesis() const {
05294     return showParenthesis_;
05295 }
05296 
05297 void Tempo::setTypeTempo(int tempo) {
05298     typeTempo_ = tempo;
05299 }
05300 
05301 int Tempo::getTypeTempo() const {
05302     return typeTempo_;
05303 }
05304 
05305 int Tempo::getQuarterTempo() const {
05306     double factor = pow(2.0, (int) Note_Quarter - (int) getLeftNoteType());
05307     int tempo = int((double) getTypeTempo() * factor);
05308 
05309     return tempo;
05310 }
05311 
05312 void Tempo::setLeftText(const QString& str) {
05313     leftText_ = str;
05314 }
05315 
05316 QString Tempo::getLeftText() const {
05317     return leftText_;
05318 }
05319 
05320 void Tempo::setRightText(const QString& str) {
05321     rightText_ = str;
05322 }
05323 
05324 QString Tempo::getRightText() const {
05325     return rightText_;
05326 }
05327 
05328 void Tempo::setSwingEighth(bool swing) {
05329     swingEighth_ = swing;
05330 }
05331 
05332 bool Tempo::getSwingEighth() const {
05333     return swingEighth_;
05334 }
05335 
05336 void Tempo::setRightNoteType(int type) {
05337     rightNoteType_ = type;
05338 }
05339 
05340 int Tempo::getRightNoteType() const {
05341     return rightNoteType_;
05342 }
05343 
05345 Text::Text() {
05346     musicDataType_ = MusicData_Text;
05347 
05348     textType_ = Text_Rehearsal;
05349     horiMargin_ = 8;
05350     vertMargin_ = 8;
05351     lineThick_ = 4;
05352     text_ = QString();
05353     width_ = 0;
05354     height_ = 0;
05355 }
05356 
05357 void Text::setTextType(TextType type) {
05358     textType_ = type;
05359 }
05360 
05361 Text::TextType Text::getTextType() const {
05362     return textType_;
05363 }
05364 
05365 void Text::setHorizontalMargin(int margin) {
05366     horiMargin_ = margin;
05367 }
05368 
05369 int Text::getHorizontalMargin() const {
05370     return horiMargin_;
05371 }
05372 
05373 void Text::setVerticalMargin(int margin) {
05374     vertMargin_ = margin;
05375 }
05376 
05377 int Text::getVerticalMargin() const {
05378     return vertMargin_;
05379 }
05380 
05381 void Text::setLineThick(int thick) {
05382     lineThick_ = thick;
05383 }
05384 
05385 int Text::getLineThick() const {
05386     return lineThick_;
05387 }
05388 
05389 void Text::setText(const QString& text) {
05390     text_ = text;
05391 }
05392 
05393 QString Text::getText() const {
05394     return text_;
05395 }
05396 
05397 void Text::setWidth(int width) {
05398     width_ = width;
05399 }
05400 
05401 int Text::getWidth() const {
05402     return width_;
05403 }
05404 
05405 void Text::setHeight(int height) {
05406     height_ = height;
05407 }
05408 
05409 int Text::getHeight() const {
05410     return height_;
05411 }
05412 
05414 TimeSignature::TimeSignature() {
05415     numerator_ = 4;
05416     denominator_ = 4;
05417     isSymbol_ = false;
05418     beatLength_ = 480;
05419     barLength_ = 1920;
05420     barLengthUnits_ = 0x400;
05421     replaceFont_ = false;
05422     showBeatGroup_ = false;
05423 
05424     groupNumerator1_ = 0;
05425     groupNumerator2_ = 0;
05426     groupNumerator3_ = 0;
05427     groupDenominator1_ = 4;
05428     groupDenominator2_ = 4;
05429     groupDenominator3_ = 4;
05430 
05431     beamGroup1_ = 4;
05432     beamGroup2_ = 0;
05433     beamGroup3_ = 0;
05434     beamGroup4_ = 0;
05435 
05436     beamCount16th_ = 4;
05437     beamCount32th_ = 1;
05438 }
05439 
05440 void TimeSignature::setNumerator(int numerator) {
05441     numerator_ = numerator;
05442 }
05443 
05444 int TimeSignature::getNumerator() const {
05445     return numerator_;
05446 }
05447 
05448 void TimeSignature::setDenominator(int denominator) {
05449     denominator_ = denominator;
05450 }
05451 
05452 int TimeSignature::getDenominator() const {
05453     return denominator_;
05454 }
05455 
05456 void TimeSignature::setIsSymbol(bool symbol) {
05457     isSymbol_ = symbol;
05458 }
05459 
05460 bool TimeSignature::getIsSymbol() const {
05461     if (numerator_ == 2 && denominator_ == 2) {
05462         return true;
05463     }
05464 
05465     return isSymbol_;
05466 }
05467 
05468 void TimeSignature::setBeatLength(int length) {
05469     beatLength_ = length;
05470 }
05471 
05472 int TimeSignature::getBeatLength() const {
05473     return beatLength_;
05474 }
05475 
05476 void TimeSignature::setBarLength(int length) {
05477     barLength_ = length;
05478 }
05479 
05480 int TimeSignature::getBarLength() const {
05481     return barLength_;
05482 }
05483 
05484 void TimeSignature::addBeat(int startUnit, int lengthUnit, int startTick) {
05485     BeatNode node;
05486     node.startUnit_ = startUnit;
05487     node.lengthUnit_ = lengthUnit;
05488     node.startTick_ = startTick;
05489     beats_.push_back(node);
05490 }
05491 
05492 void TimeSignature::endAddBeat()
05493 {
05494     int i;
05495     barLengthUnits_ = 0;
05496 
05497     for (i = 0; i < beats_.size(); ++i) {
05498         barLengthUnits_ += beats_[i].lengthUnit_;
05499     }
05500 }
05501 
05502 int TimeSignature::getUnits() const {
05503     return barLengthUnits_;
05504 }
05505 
05506 void TimeSignature::setReplaceFont(bool replace) {
05507     replaceFont_ = replace;
05508 }
05509 
05510 bool TimeSignature::getReplaceFont() const {
05511     return replaceFont_;
05512 }
05513 
05514 void TimeSignature::setShowBeatGroup(bool show) {
05515     showBeatGroup_ = show;
05516 }
05517 
05518 bool TimeSignature::getShowBeatGroup() const {
05519     return showBeatGroup_;
05520 }
05521 
05522 void TimeSignature::setGroupNumerator1(int numerator) {
05523     groupNumerator1_ = numerator;
05524 }
05525 
05526 void TimeSignature::setGroupNumerator2(int numerator) {
05527     groupNumerator2_ = numerator;
05528 }
05529 
05530 void TimeSignature::setGroupNumerator3(int numerator) {
05531     groupNumerator3_ = numerator;
05532 }
05533 
05534 void TimeSignature::setGroupDenominator1(int denominator) {
05535     groupDenominator1_ = denominator;
05536 }
05537 
05538 void TimeSignature::setGroupDenominator2(int denominator) {
05539     groupDenominator2_ = denominator;
05540 }
05541 
05542 void TimeSignature::setGroupDenominator3(int denominator) {
05543     groupDenominator3_ = denominator;
05544 }
05545 
05546 void TimeSignature::setBeamGroup1(int count) {
05547     beamGroup1_ = count;
05548 }
05549 
05550 void TimeSignature::setBeamGroup2(int count) {
05551     beamGroup2_ = count;
05552 }
05553 
05554 void TimeSignature::setBeamGroup3(int count) {
05555     beamGroup3_ = count;
05556 }
05557 
05558 void TimeSignature::setBeamGroup4(int count) {
05559     beamGroup4_ = count;
05560 }
05561 
05562 void TimeSignature::set16thBeamCount(int count) {
05563     beamCount16th_ = count;
05564 }
05565 
05566 void TimeSignature::set32thBeamCount(int count) {
05567     beamCount32th_ = count;
05568 }
05569 
05571 Key::Key() {
05572     key_ = 0;
05573     set_ = false;
05574     previousKey_ = 0;
05575     symbolCount_ = 0;
05576 }
05577 
05578 void Key::setKey(int key) {
05579     key_ = key;
05580     set_ = true;
05581 }
05582 
05583 int Key::getKey() const {
05584     return key_;
05585 }
05586 
05587 bool Key::getSetKey() const {
05588     return set_;
05589 }
05590 
05591 void Key::setPreviousKey(int key) {
05592     previousKey_ = key;
05593 }
05594 
05595 int Key::getPreviousKey() const {
05596     return previousKey_;
05597 }
05598 
05599 void Key::setSymbolCount(int count) {
05600     symbolCount_ = count;
05601 }
05602 
05603 int Key::getSymbolCount() const {
05604     return symbolCount_;
05605 }
05606 
05608 RepeatSymbol::RepeatSymbol() :
05609     text_("#1"), repeatType_(Repeat_Segno) {
05610     musicDataType_ = MusicData_Repeat;
05611 }
05612 
05613 void RepeatSymbol::setText(const QString& text) {
05614     text_ = text;
05615 }
05616 
05617 QString RepeatSymbol::getText() const {
05618     return text_;
05619 }
05620 
05621 void RepeatSymbol::setRepeatType(int repeatType) {
05622     repeatType_ = (RepeatType) repeatType;
05623 }
05624 
05625 RepeatType RepeatSymbol::getRepeatType() const {
05626     return repeatType_;
05627 }
05628 
05630 NumericEnding::NumericEnding() {
05631     musicDataType_ = MusicData_Numeric_Ending;
05632 
05633     height_ = 0;
05634     text_ = QString();
05635     numericHandle_ = new OffsetElement();
05636 }
05637 
05638 NumericEnding::~NumericEnding() {
05639     delete numericHandle_;
05640 }
05641 
05642 OffsetElement* NumericEnding::getNumericHandle() const {
05643     return numericHandle_;
05644 }
05645 
05646 void NumericEnding::setHeight(int height) {
05647     height_ = height;
05648 }
05649 
05650 int NumericEnding::getHeight() const {
05651     return height_;
05652 }
05653 
05654 void NumericEnding::setText(const QString& text) {
05655     text_ = text;
05656 }
05657 
05658 QString NumericEnding::getText() const {
05659     return text_;
05660 }
05661 
05662 QList<int> NumericEnding::getNumbers() const {
05663     int i;
05664     QStringList strs = text_.split(",", QString::SkipEmptyParts);
05665     QList<int> endings;
05666 
05667     for (i = 0; i < strs.size(); ++i) {
05668         bool ok;
05669         int num = strs[i].toInt(&ok);
05670         endings.push_back(num);
05671     }
05672 
05673     return endings;
05674 }
05675 
05676 int NumericEnding::getJumpCount() const {
05677     QList<int> numbers = getNumbers();
05678     int count = 0;
05679 
05680     for (int i = 0; i < numbers.size(); ++i) {
05681         if ((int)i + 1 != numbers[i]) {
05682             break;
05683         }
05684 
05685         count = i + 1;
05686     }
05687 
05688     return count;
05689 }
05690 
05692 BarNumber::BarNumber() {
05693     index_ = 0;
05694     showOnParagraphStart_ = false;
05695     align_ = 0;
05696     showFlag_ = 1; // staff
05697     barRange_ = 1; // can't be 0
05698     prefix_ = QString();
05699 }
05700 
05701 void BarNumber::setIndex(int index) {
05702     index_ = index;
05703 }
05704 
05705 int BarNumber::getIndex() const {
05706     return index_;
05707 }
05708 
05709 void BarNumber::setShowOnParagraphStart(bool show) {
05710     showOnParagraphStart_ = show;
05711 }
05712 
05713 bool BarNumber::getShowOnParagraphStart() const {
05714     return showOnParagraphStart_;
05715 }
05716 
05717 void BarNumber::setAlign(int align)// 0:left, 1:center, 2:right
05718 {
05719     align_ = align;
05720 }
05721 
05722 int BarNumber::getAlign() const {
05723     return align_;
05724 }
05725 
05726 void BarNumber::setShowFlag(int flag) {
05727     showFlag_ = flag;
05728 }
05729 
05730 int BarNumber::getShowFlag() const {
05731     return showFlag_;
05732 }
05733 
05734 void BarNumber::setShowEveryBarCount(int count) {
05735     barRange_ = count;
05736 }
05737 
05738 int BarNumber::getShowEveryBarCount() const {
05739     return barRange_;
05740 }
05741 
05742 void BarNumber::setPrefix(const QString& str) {
05743     prefix_ = str;
05744 }
05745 
05746 QString BarNumber::getPrefix() const {
05747     return prefix_;
05748 }
05749 
05751 MidiController::MidiController() {
05752     midiType_ = Midi_Controller;
05753     controller_ = 64; // pedal
05754     value_ = 0;
05755 }
05756 
05757 void MidiController::setController(int number) {
05758     controller_ = number;
05759 }
05760 
05761 int MidiController::getController() const {
05762     return controller_;
05763 }
05764 
05765 void MidiController::setValue(int value) {
05766     value_ = value;
05767 }
05768 
05769 int MidiController::getValue() const {
05770     return value_;
05771 }
05772 
05774 MidiProgramChange::MidiProgramChange() {
05775     midiType_ = Midi_Program_Change;
05776     patch_ = 0; // grand piano
05777 }
05778 
05779 void MidiProgramChange::setPatch(int patch) {
05780     patch_ = patch;
05781 }
05782 
05783 int MidiProgramChange::getPatch() const {
05784     return patch_;
05785 }
05786 
05788 MidiChannelPressure::MidiChannelPressure() :
05789     pressure_(0) {
05790     midiType_ = Midi_Channel_Pressure;
05791 }
05792 
05793 void MidiChannelPressure::setPressure(int pressure) {
05794     pressure_ = pressure;
05795 }
05796 
05797 int MidiChannelPressure::getPressure() const {
05798     return pressure_;
05799 }
05800 
05802 MidiPitchWheel::MidiPitchWheel() {
05803     midiType_ = Midi_Pitch_Wheel;
05804     value_ = 0;
05805 }
05806 
05807 void MidiPitchWheel::setValue(int value) {
05808     value_ = value;
05809 }
05810 
05811 int MidiPitchWheel::getValue() const {
05812     return value_;
05813 }
05814 
05816 Measure::Measure(int index) {
05817     barNumber_ = new BarNumber();
05818     barNumber_->setIndex(index);
05819     time_ = new TimeSignature();
05820 
05821     clear();
05822 }
05823 
05824 Measure::~Measure(){
05825     clear();
05826 
05827     delete barNumber_;
05828     delete time_;
05829 }
05830 
05831 BarNumber* Measure::getBarNumber() const {
05832     return barNumber_;
05833 }
05834 
05835 TimeSignature* Measure::getTime() const {
05836     return time_;
05837 }
05838 
05839 void Measure::setLeftBarline(int barline) {
05840     leftBarline_ = (BarlineType) barline;
05841 }
05842 
05843 BarlineType Measure::getLeftBarline() const {
05844     return leftBarline_;
05845 }
05846 
05847 void Measure::setRightBarline(int barline) {
05848     rightBarline_ = (BarlineType) barline;
05849 }
05850 
05851 BarlineType Measure::getRightBarline() const {
05852     return rightBarline_;
05853 }
05854 
05855 void Measure::setBackwardRepeatCount(int repeatCount) {
05856     repeatCount_ = repeatCount;
05857 }
05858 
05859 int Measure::getBackwardRepeatCount() const {
05860     return repeatCount_;
05861 }
05862 
05863 void Measure::setTypeTempo(double tempo) {
05864     typeTempo_ = tempo;
05865 }
05866 
05867 double Measure::getTypeTempo() const {
05868     return typeTempo_;
05869 }
05870 
05871 void Measure::setIsPickup(bool pickup) {
05872     pickup_ = pickup;
05873 }
05874 
05875 bool Measure::getIsPickup() const {
05876     return pickup_;
05877 }
05878 
05879 void Measure::setIsMultiMeasureRest(bool rest) {
05880     multiMeasureRest_ = rest;
05881 }
05882 
05883 bool Measure::getIsMultiMeasureRest() const {
05884     return multiMeasureRest_;
05885 }
05886 
05887 void Measure::setMultiMeasureRestCount(int count) {
05888     multiMeasureRestCount_ = count;
05889 }
05890 
05891 int Measure::getMultiMeasureRestCount() const {
05892     return multiMeasureRestCount_;
05893 }
05894 
05895 void Measure::clear() {
05896     leftBarline_ = Barline_Default;
05897     rightBarline_ = Barline_Default;
05898     repeatCount_ = 1;
05899     typeTempo_ = 96.00;
05900     setLength(0x780); //time = 4/4
05901     pickup_ = false;
05902     multiMeasureRest_ = false;
05903     multiMeasureRestCount_ = 0;
05904 }
05905 
05907 MeasureData::MeasureData() {
05908     key_ = new Key();
05909     clef_ = new Clef();
05910 }
05911 
05912 MeasureData::~MeasureData(){
05913     int i;
05914     for(i=0; i<musicDatas_.size(); ++i){
05915         delete musicDatas_[i];
05916     }
05917     musicDatas_.clear();
05918 
05919     // noteContainers_ also in musicDatas_, no need to destory
05920     noteContainers_.clear();
05921 
05922     // only delete at element start
05923     for(i=0; i<crossMeasureElements_.size(); ++i){
05924         if(crossMeasureElements_[i].second){
05925             delete crossMeasureElements_[i].first;
05926         }
05927     }
05928     crossMeasureElements_.clear();
05929 
05930     for(i=0; i<midiDatas_.size(); ++i){
05931         delete midiDatas_[i];
05932     }
05933     midiDatas_.clear();
05934 
05935     delete key_;
05936     delete clef_;
05937 }
05938 
05939 Key* MeasureData::getKey() const {
05940     return key_;
05941 }
05942 
05943 Clef* MeasureData::getClef() const {
05944     return clef_;
05945 }
05946 
05947 void MeasureData::addNoteContainer(NoteContainer* ptr) {
05948     noteContainers_.push_back(ptr);
05949 }
05950 
05951 QList<NoteContainer*> MeasureData::getNoteContainers() const {
05952     return noteContainers_;
05953 }
05954 
05955 void MeasureData::addMusicData(MusicData* ptr) {
05956     musicDatas_.push_back(ptr);
05957 }
05958 
05959 QList<MusicData*> MeasureData::getMusicDatas(MusicDataType type) {
05960     int i;
05961     QList<MusicData*> notations;
05962 
05963     for (i = 0; i < musicDatas_.size(); ++i) {
05964         if (type == MusicData_None || musicDatas_[i]->getMusicDataType() == type) {
05965             notations.push_back(musicDatas_[i]);
05966         }
05967     }
05968 
05969     return notations;
05970 }
05971 
05972 void MeasureData::addCrossMeasureElement(MusicData* ptr, bool start) {
05973     crossMeasureElements_.push_back(qMakePair(ptr, start));
05974 }
05975 
05976 QList<MusicData*> MeasureData::getCrossMeasureElements(
05977         MusicDataType type, PairType pairType)
05978 {
05979     int i;
05980     QList<MusicData*> pairs;
05981 
05982     for (i = 0; i < crossMeasureElements_.size(); ++i) {
05983         if ((type == MusicData_None || crossMeasureElements_[i].first->getMusicDataType() == type)
05984                 && (pairType == PairType_All || ((crossMeasureElements_[i].second && pairType == PairType_Start)
05985                         || (!crossMeasureElements_[i].second && pairType == PairType_Stop)))) {
05986             pairs.push_back(crossMeasureElements_[i].first);
05987         }
05988     }
05989 
05990     return pairs;
05991 }
05992 
05993 void MeasureData::addMidiData(MidiData* ptr) {
05994     midiDatas_.push_back(ptr);
05995 }
05996 
05997 QList<MidiData*> MeasureData::getMidiDatas(MidiType type) {
05998     int i;
05999     QList<MidiData*> datas;
06000 
06001     for (i = 0; i < midiDatas_.size(); ++i) {
06002         if (type == Midi_None || midiDatas_[i]->getMidiType() == type) {
06003             datas.push_back(midiDatas_[i]);
06004         }
06005     }
06006 
06007     return datas;
06008 }
06009 
06012 StreamHandle::StreamHandle() :
06013     size_(0), curPos_(0), point_(NULL) {
06014 }
06015 
06016 StreamHandle::StreamHandle(unsigned char* p, int size) :
06017     size_(size), curPos_(0), point_(p) {
06018 }
06019 
06020 StreamHandle::~StreamHandle() {
06021     point_ = NULL;
06022 }
06023 
06024 bool StreamHandle::read(char* buff, int size) {
06025     if (point_ != NULL && curPos_ + size <= size_) {
06026         memcpy(buff, point_ + curPos_, size);
06027         curPos_ += size;
06028 
06029         return true;
06030     }
06031 
06032     return false;
06033 }
06034 
06035 bool StreamHandle::write(char* /*buff*/, int /*size*/) {
06036     return true;
06037 }
06038 
06039 // Block.cpp
06041 Block::Block() {
06042     doResize(0);
06043 }
06044 
06045 Block::Block(unsigned int count) {
06046     doResize(count);
06047 }
06048 
06049 void Block::resize(unsigned int count) {
06050     doResize(count);
06051 }
06052 
06053 void Block::doResize(unsigned int count) {
06054     data_.clear();
06055     for(unsigned int i=0; i<count; ++i) {
06056         data_.push_back('\0');
06057     }
06058     //data_.resize(count);
06059 }
06060 
06061 const unsigned char* Block::data() const {
06062     //return const_cast<unsigned char*>(&data_.front());
06063     return &data_.front();
06064 }
06065 
06066 unsigned char* Block::data() {
06067     return &data_.front();
06068 }
06069 
06070 unsigned int Block::size() const {
06071     return data_.size();
06072 }
06073 
06074 bool Block::toBoolean() const {
06075     if (data() == NULL) {
06076         return false;
06077     }
06078 
06079     return size() == 1 && data()[0] == 0x01;
06080 }
06081 
06082 unsigned int Block::toUnsignedInt() const {
06083     if (data() == NULL) {
06084         return 0;
06085     }
06086 
06087     unsigned int i;
06088     unsigned int num(0);
06089 
06090     for (i = 0; i < sizeof(unsigned int) && i < size(); ++i) {
06091         num = (num << 8) + *(data() + i);
06092     }
06093 
06094     return num;
06095 }
06096 
06097 int Block::toInt() const {
06098     if (data() == NULL) {
06099         return 0;
06100     }
06101 
06102     unsigned int i;
06103     int num = 0;
06104 
06105     for (i = 0; i < sizeof(unsigned int) && i < size(); ++i) {
06106         num = (num << 8) + (int) *(data() + i);
06107     }
06108 
06109     std::size_t minSize = sizeof(unsigned int);
06110     if (size() < minSize) {
06111         minSize = size();
06112     }
06113 
06114     if ((*(data()) & 0x80) == 0x80) {
06115         int maxNum = int(pow(2.0, (int) minSize * 8));
06116         num -= maxNum;
06117         //num *= -1;
06118     }
06119 
06120     return num;
06121 }
06122 
06123 QByteArray Block::toStrByteArray() const {
06124     if (data() == NULL) {
06125         return QByteArray();
06126     }
06127 
06128     QByteArray arr((char*) data(), size());
06129 
06130     return arr;
06131 }
06132 
06133 QByteArray Block::fixedSizeBufferToStrByteArray() const {
06134     unsigned int i;
06135     QByteArray str;
06136 
06137     for (i = 0; i < size(); ++i) {
06138         if (*(data() + i) == '\0') {
06139             break;
06140         }
06141 
06142         str += (char) *(data() + i);
06143     }
06144 
06145     return str;
06146 }
06147 
06148 bool Block::operator ==(const Block& block) const {
06149     unsigned int i;
06150 
06151     if (size() != block.size()) {
06152         return false;
06153     }
06154 
06155     for (i = 0; i < size() && i < block.size(); ++i) {
06156         if (*(data() + i) != *(block.data() + i)) {
06157             return false;
06158         }
06159     }
06160 
06161     return true;
06162 }
06163 
06164 bool Block::operator !=(const Block& block) const {
06165     return !(*this == block);
06166 }
06167 
06169 FixedBlock::FixedBlock() :
06170     Block() {
06171 }
06172 
06173 FixedBlock::FixedBlock(unsigned int count) :
06174     Block(count) {
06175 }
06176 
06177 void FixedBlock::resize(unsigned int /*count*/) {
06178     //  Block::resize(size);
06179 }
06180 
06182 SizeBlock::SizeBlock() :
06183     FixedBlock(4) {
06184 }
06185 
06186 unsigned int SizeBlock::toSize() const {
06187     unsigned int i;
06188     unsigned int num(0);
06189     const unsigned int SIZE = 4;
06190 
06191     for (i = 0; i < SIZE; ++i) {
06192         num = (num << 8) + *(data() + i);
06193     }
06194 
06195     return num;
06196 }
06197 
06198 /*void SizeBlock::fromUnsignedInt(unsigned int count)
06199  {
06200  unsigned_int_to_char_buffer(count, data());
06201  }*/
06202 
06204 NameBlock::NameBlock() :
06205     FixedBlock(4) {
06206 }
06207 
06208 /*void NameBlock::setValue(const char* const name)
06209  {
06210  unsigned int i;
06211 
06212  for( i=0; i<size() && *(name+i)!='\0'; ++i )
06213  {
06214  *(data()+i) = *(name+i);
06215  }
06216  }*/
06217 
06218 bool NameBlock::isEqual(const QString& name) const
06219 {
06220     unsigned int i, nsize = static_cast<unsigned>(name.size());
06221 
06222     if (nsize != size()) {
06223         return false;
06224     }
06225 
06226     for (i = 0; i < size() && nsize; ++i) {
06227         if (data()[i] != name[i]) {
06228             return false;
06229         }
06230     }
06231 
06232     return true;
06233 }
06234 
06236 CountBlock::CountBlock() :
06237     FixedBlock(2) {
06238 }
06239 
06240 /*void CountBlock::setValue(unsigned short count)
06241  {
06242  unsigned int i;
06243  unsigned int SIZE = sizeof(unsigned short);
06244 
06245  for( i=0; i<SIZE; ++i )
06246  {
06247  data()[SIZE-1-i] = count % 256;
06248  count /= 256;
06249  }
06250  }*/
06251 
06252 unsigned short CountBlock::toCount() const {
06253     unsigned int i;
06254     unsigned short num = 0;
06255 
06256     for (i = 0; i < size() && i < sizeof(unsigned short); ++i) {
06257         num = (num << 8) + *(data() + i);
06258     }
06259 
06260     return num;
06261 }
06262 
06263 // Chunk.cpp
06264 const QString Chunk::TrackName  = "TRAK";
06265 const QString Chunk::PageName   = "PAGE";
06266 const QString Chunk::LineName   = "LINE";
06267 const QString Chunk::StaffName  = "STAF";
06268 const QString Chunk::MeasureName = "MEAS";
06269 const QString Chunk::ConductName = "COND";
06270 const QString Chunk::BdatName   = "BDAT";
06271 
06272 Chunk::Chunk() {
06273 }
06274 
06275 NameBlock Chunk::getName() const {
06276     return nameBlock_;
06277 }
06278 
06280 const unsigned int SizeChunk::version3TrackSize = 0x13a;
06281 
06282 SizeChunk::SizeChunk() :
06283     Chunk() {
06284     sizeBlock_ = new SizeBlock();
06285     dataBlock_ = new Block();
06286 }
06287 
06288 SizeChunk::~SizeChunk() {
06289     delete sizeBlock_;
06290     delete dataBlock_;
06291 }
06292 
06293 SizeBlock* SizeChunk::getSizeBlock() const {
06294     return sizeBlock_;
06295 }
06296 
06297 Block* SizeChunk::getDataBlock() const {
06298     return dataBlock_;
06299 }
06300 
06302 GroupChunk::GroupChunk() : Chunk() {
06303     childCount_ = new CountBlock();
06304 }
06305 
06306 GroupChunk::~GroupChunk() {
06307     delete childCount_;
06308 }
06309 
06310 CountBlock* GroupChunk::getCountBlock() const {
06311     return childCount_;
06312 }
06313 
06314 // ChunkParse.cpp
06315 unsigned int getHighNibble(unsigned int byte) {
06316     return byte / 16;
06317 }
06318 
06319 unsigned int getLowNibble(unsigned int byte) {
06320     return byte % 16;
06321 }
06322 
06323 int oveKeyToKey(int oveKey) {
06324     int key = 0;
06325 
06326     if( oveKey == 0 ) {
06327         key = 0;
06328     }
06329     else if( oveKey > 7 ) {
06330         key = oveKey - 7;
06331     }
06332     else if( oveKey <= 7 ) {
06333         key = oveKey * (-1);
06334     }
06335 
06336     return key;
06337 }
06338 
06340 BasicParse::BasicParse(OveSong* ove) :
06341     ove_(ove), handle_(NULL), notify_(NULL) {
06342 }
06343 
06344 BasicParse::BasicParse() :
06345     ove_(NULL), handle_(NULL), notify_(NULL) {
06346 }
06347 
06348 BasicParse::~BasicParse() {
06349     ove_ = NULL;
06350     handle_ = NULL;
06351     notify_ = NULL;
06352 }
06353 
06354 void BasicParse::setNotify(IOveNotify* notify) {
06355     notify_ = notify;
06356 }
06357 
06358 bool BasicParse::parse() {
06359     return false;
06360 }
06361 
06362 bool BasicParse::readBuffer(Block& placeHolder, unsigned int size) {
06363     if (handle_ == NULL) {
06364         return false;
06365     }
06366     if (placeHolder.size() != size) {
06367         placeHolder.resize(size);
06368     }
06369 
06370     if (size > 0) {
06371         return handle_->read((char*) placeHolder.data(), placeHolder.size());
06372     }
06373 
06374     return true;
06375 }
06376 
06377 bool BasicParse::jump(int offset) {
06378     if (handle_ == NULL || offset < 0) {
06379         return false;
06380     }
06381 
06382     if (offset > 0) {
06383         Block placeHolder(offset);
06384         return handle_->read((char*) placeHolder.data(), placeHolder.size());
06385     }
06386 
06387     return true;
06388 }
06389 
06390 void BasicParse::messageOut(const QString& str) {
06391     if (notify_ != NULL) {
06392         notify_->loadInfo(str);
06393     }
06394 }
06395 
06397 OvscParse::OvscParse(OveSong* ove) :
06398     BasicParse(ove), chunk_(NULL) {
06399 }
06400 
06401 OvscParse::~OvscParse() {
06402     chunk_ = NULL;
06403 }
06404 
06405 void OvscParse::setOvsc(SizeChunk* chunk) {
06406     chunk_ = chunk;
06407 }
06408 
06409 bool OvscParse::parse() {
06410     Block* dataBlock = chunk_->getDataBlock();
06411     unsigned int blockSize = chunk_->getSizeBlock()->toSize();
06412     StreamHandle handle(dataBlock->data(), blockSize);
06413     Block placeHolder;
06414 
06415     handle_ = &handle;
06416 
06417     // version
06418     if (!readBuffer(placeHolder, 1)) { return false; }
06419     bool version4 = placeHolder.toUnsignedInt() == 4;
06420     ove_->setIsVersion4(version4);
06421 
06422     QString str = QString("This file is created by Overture ") + (version4 ? "4" : "3");
06423     messageOut(str);
06424 
06425     if( !jump(6) ) { return false; }
06426 
06427     // show page margin
06428     if (!readBuffer(placeHolder, 1)) { return false; }
06429     ove_->setShowPageMargin(placeHolder.toBoolean());
06430 
06431     if( !jump(1) ) { return false; }
06432 
06433     // transpose track
06434     if (!readBuffer(placeHolder, 1)) { return false; }
06435     ove_->setShowTransposeTrack(placeHolder.toBoolean());
06436 
06437     // play repeat
06438     if (!readBuffer(placeHolder, 1)) { return false; }
06439     ove_->setPlayRepeat(placeHolder.toBoolean());
06440 
06441     // play style
06442     if (!readBuffer(placeHolder, 1)) { return false; }
06443     OveSong::PlayStyle style = OveSong::Record;
06444     if(placeHolder.toUnsignedInt() == 1){
06445         style = OveSong::Swing;
06446     }
06447     else if(placeHolder.toUnsignedInt() == 2){
06448         style = OveSong::Notation;
06449     }
06450     ove_->setPlayStyle(style);
06451 
06452     // show line break
06453     if (!readBuffer(placeHolder, 1)) { return false; }
06454     ove_->setShowLineBreak(placeHolder.toBoolean());
06455 
06456     // show ruler
06457     if (!readBuffer(placeHolder, 1)) { return false; }
06458     ove_->setShowRuler(placeHolder.toBoolean());
06459 
06460     // show color
06461     if (!readBuffer(placeHolder, 1)) { return false; }
06462     ove_->setShowColor(placeHolder.toBoolean());
06463 
06464     return true;
06465 }
06466 
06468 TrackParse::TrackParse(OveSong* ove)
06469 :BasicParse(ove) {
06470 }
06471 
06472 TrackParse::~TrackParse() {
06473 }
06474 
06475 void TrackParse::setTrack(SizeChunk* chunk) {
06476     chunk_ = chunk;
06477 }
06478 
06479 bool TrackParse::parse()
06480 {
06481     Block* dataBlock = chunk_->getDataBlock();
06482     unsigned int blockSize = ove_->getIsVersion4() ? chunk_->getSizeBlock()->toSize() : SizeChunk::version3TrackSize;
06483     StreamHandle handle(dataBlock->data(), blockSize);
06484     Block placeHolder;
06485 
06486     handle_ = &handle;
06487 
06488     Track* oveTrack = new Track();
06489     ove_->addTrack(oveTrack);
06490 
06491     // 2 32bytes long track name buffer
06492     if( !readBuffer(placeHolder, 32) ) { return false; }
06493     oveTrack->setName(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
06494 
06495     if( !readBuffer(placeHolder, 32) ) { return false; }
06496     oveTrack->setBriefName(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
06497 
06498     if( !jump(8) ) { return false; } //0x fffa0012 fffa0012
06499     if( !jump(1) ) { return false; }
06500 
06501     // patch
06502     if( !readBuffer(placeHolder, 1) ) { return false; }
06503     unsigned int thisByte = placeHolder.toInt();
06504     oveTrack->setPatch(thisByte&0x7f);
06505 
06506     // show name
06507     if( !readBuffer(placeHolder, 1) ) { return false; }
06508     oveTrack->setShowName(placeHolder.toBoolean());
06509 
06510     // show brief name
06511     if( !readBuffer(placeHolder, 1) ) { return false; }
06512     oveTrack->setShowBriefName(placeHolder.toBoolean());
06513 
06514     if( !jump(1) ) { return false; }
06515 
06516     // show transpose
06517     if( !readBuffer(placeHolder, 1) ) { return false; }
06518     oveTrack->setShowTranspose(placeHolder.toBoolean());
06519 
06520     if( !jump(1) ) { return false; }
06521 
06522     // mute
06523     if( !readBuffer(placeHolder, 1) ) { return false; }
06524     oveTrack->setMute(placeHolder.toBoolean());
06525 
06526     // solo
06527     if( !readBuffer(placeHolder, 1) ) { return false; }
06528     oveTrack->setSolo(placeHolder.toBoolean());
06529 
06530     if( !jump(1) ) { return false; }
06531 
06532     // show key each line
06533     if( !readBuffer(placeHolder, 1) ) { return false; }
06534     oveTrack->setShowKeyEachLine(placeHolder.toBoolean());
06535 
06536     // voice count
06537     if( !readBuffer(placeHolder, 1) ) { return false; }
06538     oveTrack->setVoiceCount(placeHolder.toUnsignedInt());
06539 
06540     if( !jump(3) ) { return false; }
06541 
06542     // transpose value [-127, 127]
06543     if( !readBuffer(placeHolder, 1) ) { return false; }
06544     oveTrack->setTranspose(placeHolder.toInt());
06545 
06546     if( !jump(2) ) { return false; }
06547 
06548     // start clef
06549     if( !readBuffer(placeHolder, 1) ) { return false; }
06550     oveTrack->setStartClef(placeHolder.toUnsignedInt());
06551 
06552     // transpose celf
06553     if( !readBuffer(placeHolder, 1) ) { return false; }
06554     oveTrack->setTransposeClef(placeHolder.toUnsignedInt());
06555 
06556     // start key
06557     if( !readBuffer(placeHolder, 1) ) { return false; }
06558     oveTrack->setStartKey(placeHolder.toUnsignedInt());
06559 
06560     // display percent
06561     if( !readBuffer(placeHolder, 1) ) { return false; }
06562     oveTrack->setDisplayPercent(placeHolder.toUnsignedInt());
06563 
06564     // show leger line
06565     if( !readBuffer(placeHolder, 1) ) { return false; }
06566     oveTrack->setShowLegerLine(placeHolder.toBoolean());
06567 
06568     // show clef
06569     if( !readBuffer(placeHolder, 1) ) { return false; }
06570     oveTrack->setShowClef(placeHolder.toBoolean());
06571 
06572     // show time signature
06573     if( !readBuffer(placeHolder, 1) ) { return false; }
06574     oveTrack->setShowTimeSignature(placeHolder.toBoolean());
06575 
06576     // show key signature
06577     if( !readBuffer(placeHolder, 1) ) { return false; }
06578     oveTrack->setShowKeySignature(placeHolder.toBoolean());
06579 
06580     // show barline
06581     if( !readBuffer(placeHolder, 1) ) { return false; }
06582     oveTrack->setShowBarline(placeHolder.toBoolean());
06583 
06584     // fill with rest
06585     if( !readBuffer(placeHolder, 1) ) { return false; }
06586     oveTrack->setFillWithRest(placeHolder.toBoolean());
06587 
06588     // flat tail
06589     if( !readBuffer(placeHolder, 1) ) { return false; }
06590     oveTrack->setFlatTail(placeHolder.toBoolean());
06591 
06592     // show clef each line
06593     if( !readBuffer(placeHolder, 1) ) { return false; }
06594     oveTrack->setShowClefEachLine(placeHolder.toBoolean());
06595 
06596     if( !jump(12) ) { return false; }
06597 
06598     // 8 voices
06599     int i;
06600     QList<Voice*> voices;
06601     for( i=0; i<8; ++i ) {
06602         Voice* voicePtr = new Voice();
06603 
06604         if( !jump(5) ) { return false; }
06605 
06606         // channel
06607         if( !readBuffer(placeHolder, 1) ) { return false; }
06608         voicePtr->setChannel(placeHolder.toUnsignedInt());
06609 
06610         // volume
06611         if( !readBuffer(placeHolder, 1) ) { return false; }
06612         voicePtr->setVolume(placeHolder.toInt());
06613 
06614         // pitch shift
06615         if( !readBuffer(placeHolder, 1) ) { return false; }
06616         voicePtr->setPitchShift(placeHolder.toInt());
06617 
06618         // pan
06619         if( !readBuffer(placeHolder, 1) ) { return false; }
06620         voicePtr->setPan(placeHolder.toInt());
06621 
06622         if( !jump(6) ) { return false; }
06623 
06624         // patch
06625         if( !readBuffer(placeHolder, 1) ) { return false; }
06626         voicePtr->setPatch(placeHolder.toInt());
06627 
06628         voices.push_back(voicePtr);
06629     }
06630 
06631     // stem type
06632     for( i=0; i<8; ++i ) {
06633         if( !readBuffer(placeHolder, 1) ) { return false; }
06634         voices[i]->setStemType(placeHolder.toUnsignedInt());
06635 
06636         oveTrack->addVoice(voices[i]);
06637     }
06638 
06639     // percussion define
06640     QList<Track::DrumNode> nodes;
06641     for(i=0; i<16; ++i) {
06642         nodes.push_back(Track::DrumNode());
06643     }
06644 
06645     // line
06646     for( i=0; i<16; ++i ) {
06647         if( !readBuffer(placeHolder, 1) ) { return false; }
06648         nodes[i].line_ = placeHolder.toInt();
06649     }
06650 
06651     // head type
06652     for( i=0; i<16; ++i ) {
06653         if( !readBuffer(placeHolder, 1) ) { return false; }
06654         nodes[i].headType_ = placeHolder.toUnsignedInt();
06655     }
06656 
06657     // pitch
06658     for( i=0; i<16; ++i ) {
06659         if( !readBuffer(placeHolder, 1) ) { return false; }
06660         nodes[i].pitch_ = placeHolder.toUnsignedInt();
06661     }
06662 
06663     // voice
06664     for( i=0; i<16; ++i ) {
06665         if( !readBuffer(placeHolder, 1) ) { return false; }
06666         nodes[i].voice_ = placeHolder.toUnsignedInt();
06667     }
06668 
06669     for( i=0; i<nodes.size(); ++i ) {
06670         oveTrack->addDrum(nodes[i]);
06671     }
06672 
06673 /*  if( !Jump(17) ) { return false; }
06674 
06675     // voice 0 channel
06676     if( !ReadBuffer(placeHolder, 1) ) { return false; }
06677     oveTrack->setChannel(placeHolder.toUnsignedInt());
06678 
06679     // to be continued. if anything important...*/
06680 
06681     return true;
06682 }
06683 
06685 GroupParse::GroupParse(OveSong* ove)
06686 :BasicParse(ove) {
06687 }
06688 
06689 GroupParse::~GroupParse(){
06690     sizeChunks_.clear();
06691 }
06692 
06693 void GroupParse::addSizeChunk(SizeChunk* sizeChunk) {
06694     sizeChunks_.push_back(sizeChunk);
06695 }
06696 
06697 bool GroupParse::parse() {
06698     return false;
06699 }
06700 
06702 PageGroupParse::PageGroupParse(OveSong* ove)
06703 :BasicParse(ove) {
06704 }
06705 
06706 PageGroupParse::~PageGroupParse(){
06707     pageChunks_.clear();
06708 }
06709 
06710 void PageGroupParse::addPage(SizeChunk* chunk) {
06711     pageChunks_.push_back(chunk);
06712 }
06713 
06714 bool PageGroupParse::parse()
06715 {
06716     if( pageChunks_.empty() ) {
06717         return false;
06718     }
06719 
06720     int i;
06721     for( i=0; i<pageChunks_.size(); ++i ) {
06722         Page* page = new Page();
06723         ove_->addPage(page);
06724 
06725         if( !parsePage(pageChunks_[i], page) ) { return false; }
06726     }
06727 
06728     return true;
06729 }
06730 
06731 bool PageGroupParse::parsePage(SizeChunk* chunk, Page* page) {
06732     Block placeHolder(2);
06733     StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
06734 
06735     handle_ = &handle;
06736 
06737     // begin line
06738     if( !readBuffer(placeHolder, 2) ) { return false; }
06739     page->setBeginLine(placeHolder.toUnsignedInt());
06740 
06741     // line count
06742     if( !readBuffer(placeHolder, 2) ) { return false; }
06743     page->setLineCount(placeHolder.toUnsignedInt());
06744 
06745     if( !jump(4) ) { return false; }
06746 
06747     // staff interval
06748     if( !readBuffer(placeHolder, 2) ) { return false; }
06749     page->setStaffInterval(placeHolder.toUnsignedInt());
06750 
06751     // line interval
06752     if( !readBuffer(placeHolder, 2) ) { return false; }
06753     page->setLineInterval(placeHolder.toUnsignedInt());
06754 
06755     // staff inline interval
06756     if( !readBuffer(placeHolder, 2) ) { return false; }
06757     page->setStaffInlineInterval(placeHolder.toUnsignedInt());
06758 
06759     // line bar count
06760     if( !readBuffer(placeHolder, 2) ) { return false; }
06761     page->setLineBarCount(placeHolder.toUnsignedInt());
06762 
06763     // page line count
06764     if( !readBuffer(placeHolder, 2) ) { return false; }
06765     page->setPageLineCount(placeHolder.toUnsignedInt());
06766 
06767     // left margin
06768     if( !readBuffer(placeHolder, 4) ) { return false; }
06769     page->setLeftMargin(placeHolder.toUnsignedInt());
06770 
06771     // top margin
06772     if( !readBuffer(placeHolder, 4) ) { return false; }
06773     page->setTopMargin(placeHolder.toUnsignedInt());
06774 
06775     // right margin
06776     if( !readBuffer(placeHolder, 4) ) { return false; }
06777     page->setRightMargin(placeHolder.toUnsignedInt());
06778 
06779     // bottom margin
06780     if( !readBuffer(placeHolder, 4) ) { return false; }
06781     page->setBottomMargin(placeHolder.toUnsignedInt());
06782 
06783     // page width
06784     if( !readBuffer(placeHolder, 4) ) { return false; }
06785     page->setPageWidth(placeHolder.toUnsignedInt());
06786 
06787     // page height
06788     if( !readBuffer(placeHolder, 4) ) { return false; }
06789     page->setPageHeight(placeHolder.toUnsignedInt());
06790 
06791     handle_ = NULL;
06792 
06793     return true;
06794 }
06795 
06797 StaffCountGetter::StaffCountGetter(OveSong* ove)
06798 :BasicParse(ove) {
06799 }
06800 
06801 unsigned int StaffCountGetter::getStaffCount(SizeChunk* chunk) {
06802     StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
06803     Block placeHolder;
06804 
06805     handle_ = &handle;
06806 
06807     if( !jump(6) ) { return false; }
06808 
06809     // staff count
06810     if( !readBuffer(placeHolder, 2) ) { return false; }
06811     return placeHolder.toUnsignedInt();
06812 }
06813 
06815 LineGroupParse::LineGroupParse(OveSong* ove) :
06816     BasicParse(ove), chunk_(NULL) {
06817 }
06818 
06819 LineGroupParse::~LineGroupParse(){
06820     chunk_ = NULL;
06821     lineChunks_.clear();
06822     staffChunks_.clear();
06823 }
06824 
06825 void LineGroupParse::setLineGroup(GroupChunk* chunk) {
06826     chunk_ = chunk;
06827 }
06828 
06829 void LineGroupParse::addLine(SizeChunk* chunk) {
06830     lineChunks_.push_back(chunk);
06831 }
06832 
06833 void LineGroupParse::addStaff(SizeChunk* chunk) {
06834     staffChunks_.push_back(chunk);
06835 }
06836 
06837 bool LineGroupParse::parse()
06838 {
06839     if( lineChunks_.empty() || staffChunks_.size() % lineChunks_.size() != 0 ) { return false; }
06840 
06841     int i;
06842     unsigned int j;
06843     unsigned int lineStaffCount = staffChunks_.size() / lineChunks_.size();
06844 
06845     for( i=0; i<lineChunks_.size(); ++i ) {
06846         Line* linePtr = new Line();
06847 
06848         ove_->addLine(linePtr);
06849 
06850         if( !parseLine(lineChunks_[i], linePtr) ) { return false; }
06851 
06852         for( j=lineStaffCount*i; j<lineStaffCount*(i+1); ++j ) {
06853             Staff* staffPtr = new Staff();
06854 
06855             linePtr->addStaff(staffPtr);
06856 
06857             if( !parseStaff(staffChunks_[j], staffPtr) ) { return false; }
06858         }
06859     }
06860 
06861     return true;
06862 }
06863 
06864 bool LineGroupParse::parseLine(SizeChunk* chunk, Line* line) {
06865     Block placeHolder;
06866 
06867     StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
06868 
06869     handle_ = &handle;
06870 
06871     if( !jump(2) ) { return false; }
06872 
06873     // begin bar
06874     if( !readBuffer(placeHolder, 2) ) { return false; }
06875     line->setBeginBar(placeHolder.toUnsignedInt());
06876 
06877     // bar count
06878     if( !readBuffer(placeHolder, 2) ) { return false; }
06879     line->setBarCount(placeHolder.toUnsignedInt());
06880 
06881     if( !jump(6) ) { return false; }
06882 
06883     // y offset
06884     if( !readBuffer(placeHolder, 2) ) { return false; }
06885     line->setYOffset(placeHolder.toInt());
06886 
06887     // left x offset
06888     if( !readBuffer(placeHolder, 2) ) { return false; }
06889     line->setLeftXOffset(placeHolder.toInt());
06890 
06891     // right x offset
06892     if( !readBuffer(placeHolder, 2) ) { return false; }
06893     line->setRightXOffset(placeHolder.toInt());
06894 
06895     if( !jump(4) ) { return false; }
06896 
06897     handle_ = NULL;
06898 
06899     return true;
06900 }
06901 
06902 bool LineGroupParse::parseStaff(SizeChunk* chunk, Staff* staff) {
06903     Block placeHolder;
06904 
06905     StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
06906 
06907     handle_ = &handle;
06908 
06909     if( !jump(7) ) { return false; }
06910 
06911     // clef
06912     if( !readBuffer(placeHolder, 1) ) { return false; }
06913     staff->setClefType(placeHolder.toUnsignedInt());
06914 
06915     // key
06916     if( !readBuffer(placeHolder, 1) ) { return false; }
06917     staff->setKeyType(oveKeyToKey(placeHolder.toUnsignedInt()));
06918 
06919     if( !jump(2) ) { return false; }
06920 
06921     // visible
06922     if( !readBuffer(placeHolder, 1) ) { return false; }
06923     staff->setVisible(placeHolder.toBoolean());
06924 
06925     if( !jump(12) ) { return false; }
06926 
06927     // y offset
06928     if( !readBuffer(placeHolder, 2) ) { return false; }
06929     staff->setYOffset(placeHolder.toInt());
06930 
06931     int jumpAmount = ove_->getIsVersion4() ? 26 : 18;
06932     if( !jump(jumpAmount) ) { return false; }
06933 
06934     // group type
06935     if( !readBuffer(placeHolder, 1) ) { return false; }
06936     GroupType groupType = Group_None;
06937     if(placeHolder.toUnsignedInt() == 1) {
06938         groupType = Group_Brace;
06939     } else if(placeHolder.toUnsignedInt() == 2) {
06940         groupType = Group_Bracket;
06941     }
06942     staff->setGroupType(groupType);
06943 
06944     // group staff count
06945     if( !readBuffer(placeHolder, 1) ) { return false; }
06946     staff->setGroupStaffCount(placeHolder.toUnsignedInt());
06947 
06948     handle_ = NULL;
06949 
06950     return true;
06951 }
06952 
06954 BarsParse::BarsParse(OveSong* ove) :
06955     BasicParse(ove) {
06956 }
06957 
06958 BarsParse::~BarsParse(){
06959     measureChunks_.clear();
06960     conductChunks_.clear();
06961     bdatChunks_.clear();
06962 }
06963 
06964 void BarsParse::addMeasure(SizeChunk* chunk) {
06965     measureChunks_.push_back(chunk);
06966 }
06967 
06968 void BarsParse::addConduct(SizeChunk* chunk) {
06969     conductChunks_.push_back(chunk);
06970 }
06971 
06972 void BarsParse::addBdat(SizeChunk* chunk) {
06973     bdatChunks_.push_back(chunk);
06974 }
06975 
06976 bool BarsParse::parse() {
06977     int i;
06978     int trackMeasureCount = ove_->getTrackBarCount();
06979     int trackCount = ove_->getTrackCount();
06980     int measureDataCount = trackCount * measureChunks_.size();
06981     QList<Measure*> measures;
06982     QList<MeasureData*> measureDatas;
06983 
06984     if( measureChunks_.empty() ||
06985         measureChunks_.size() != conductChunks_.size() ||
06986         (int)bdatChunks_.size() != measureDataCount ) {
06987         return false;
06988     }
06989 
06990     // add to ove
06991     for ( i=0; i<(int)measureChunks_.size(); ++i ) {
06992         Measure* measure = new Measure(i);
06993 
06994         measures.push_back(measure);
06995         ove_->addMeasure(measure);
06996     }
06997 
06998     for ( i=0; i<measureDataCount; ++i ) {
06999         MeasureData* oveMeasureData = new MeasureData();
07000 
07001         measureDatas.push_back(oveMeasureData);
07002         ove_->addMeasureData(oveMeasureData);
07003     }
07004 
07005     for( i=0; i<(int)measureChunks_.size(); ++i ) {
07006         Measure* measure = measures[i];
07007 
07008         // MEAS
07009         if( !parseMeas(measure, measureChunks_[i]) ) {
07010             QString ss = "failed in parse MEAS " + i;
07011             messageOut(ss);
07012 
07013             return false;
07014         }
07015     }
07016 
07017     for( i=0; i<(int)conductChunks_.size(); ++i ) {
07018         // COND
07019         if( !parseCond(measures[i], measureDatas[i], conductChunks_[i]) ) {
07020             QString ss = "failed in parse COND " + i;
07021             messageOut(ss);
07022 
07023             return false;
07024         }
07025     }
07026 
07027     for( i=0; i<(int)bdatChunks_.size(); ++i ) {
07028         int measId = i % trackMeasureCount;
07029 
07030         // BDAT
07031         if( !parseBdat(measures[measId], measureDatas[i], bdatChunks_[i]) ) {
07032             QString ss = "failed in parse BDAT " + i;
07033             messageOut(ss);
07034 
07035             return false;
07036         }
07037 
07038         if( notify_ != NULL ) {
07039             int measureID = i % trackMeasureCount;
07040             int trackID = i / trackMeasureCount;
07041 
07042             //msg.msg_ = OVE_IMPORT_POS;
07043             //msg.param1_ = (measureID<<16) + trackMeasureCount;
07044             //msg.param2_ = (trackID<<16) + trackCount;
07045 
07046             notify_->loadPosition(measureID, trackMeasureCount, trackID, trackCount);
07047         }
07048     }
07049 
07050     return true;
07051 }
07052 
07053 bool BarsParse::parseMeas(Measure* measure, SizeChunk* chunk) {
07054     Block placeHolder;
07055 
07056     StreamHandle measureHandle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
07057 
07058     handle_ = &measureHandle;
07059 
07060     if( !jump(2) ) { return false; }
07061 
07062     // multi-measure rest
07063     if( !readBuffer(placeHolder, 1) ) { return false; }
07064     measure->setIsMultiMeasureRest(placeHolder.toBoolean());
07065 
07066     // pickup
07067     if( !readBuffer(placeHolder, 1) ) { return false; }
07068     measure->setIsPickup(placeHolder.toBoolean());
07069 
07070     if( !jump(4) ) { return false; }
07071 
07072     // left barline
07073     if( !readBuffer(placeHolder, 1) ) { return false; }
07074     measure->setLeftBarline(placeHolder.toUnsignedInt());
07075 
07076     // right barline
07077     if( !readBuffer(placeHolder, 1) ) { return false; }
07078     measure->setRightBarline(placeHolder.toUnsignedInt());
07079 
07080     // tempo
07081     if( !readBuffer(placeHolder, 2) ) { return false; }
07082     double tempo = ((double)placeHolder.toUnsignedInt());
07083     if( ove_->getIsVersion4() ) {
07084         tempo /= 100.0;
07085     }
07086     measure->setTypeTempo(tempo);
07087 
07088     // bar length(tick)
07089     if( !readBuffer(placeHolder, 2) ) { return false; }
07090     measure->setLength(placeHolder.toUnsignedInt());
07091 
07092     if( !jump(6) ) { return false; }
07093 
07094     // bar number offset
07095     if( !parseOffsetElement(measure->getBarNumber()) ) { return false; }
07096 
07097     if( !jump(2) ) { return false; }
07098 
07099     // multi-measure rest count
07100     if( !readBuffer(placeHolder, 2) ) { return false; }
07101     measure->setMultiMeasureRestCount(placeHolder.toUnsignedInt());
07102 
07103     handle_ = NULL;
07104 
07105     return true;
07106 }
07107 
07108 bool BarsParse::parseCond(Measure* measure, MeasureData* measureData, SizeChunk* chunk) {
07109     Block placeHolder;
07110 
07111     StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
07112 
07113     handle_ = &handle;
07114 
07115     // item count
07116     if( !readBuffer(placeHolder, 2) ) { return false; }
07117     unsigned int cnt = placeHolder.toUnsignedInt();
07118 
07119     if( !parseTimeSignature(measure, 36) ) { return false; }
07120 
07121     for( unsigned int i=0; i<cnt; ++i ) {
07122         if( !readBuffer(placeHolder, 2) ) { return false; }
07123         unsigned int twoByte = placeHolder.toUnsignedInt();
07124         unsigned int oldBlockSize = twoByte - 11;
07125         unsigned int newBlockSize = twoByte - 7;
07126 
07127         // type id
07128         if( !readBuffer(placeHolder, 1) ) { return false; }
07129         unsigned int thisByte = placeHolder.toUnsignedInt();
07130         CondType type;
07131 
07132         if( !getCondElementType(thisByte, type) ) { return false; }
07133 
07134         switch (type) {
07135         case Cond_Bar_Number: {
07136             if (!parseBarNumber(measure, twoByte - 1)) {
07137                 return false;
07138             }
07139             break;
07140         }
07141         case Cond_Repeat: {
07142             if (!parseRepeatSymbol(measureData, oldBlockSize)) {
07143                 return false;
07144             }
07145             break;
07146         }
07147         case Cond_Numeric_Ending: {
07148             if (!parseNumericEndings(measureData, oldBlockSize)) {
07149                 return false;
07150             }
07151             break;
07152         }
07153         case Cond_Decorator: {
07154             if (!parseDecorators(measureData, newBlockSize)) {
07155                 return false;
07156             }
07157             break;
07158         }
07159         case Cond_Tempo: {
07160             if (!parseTempo(measureData, newBlockSize)) {
07161                 return false;
07162             }
07163             break;
07164         }
07165         case Cond_Text: {
07166             if (!parseText(measureData, newBlockSize)) {
07167                 return false;
07168             }
07169             break;
07170         }
07171         case Cond_Expression: {
07172             if (!parseExpressions(measureData, newBlockSize)) {
07173                 return false;
07174             }
07175             break;
07176         }
07177         case Cond_Time_Parameters: {
07178             if (!parseTimeSignatureParameters(measure, newBlockSize)) {
07179                 return false;
07180             }
07181             break;
07182         }
07183         case Cond_Barline_Parameters: {
07184             if (!parseBarlineParameters(measure, newBlockSize)) {
07185                 return false;
07186             }
07187             break;
07188         }
07189         default: {
07190             if (!jump(newBlockSize)) {
07191                 return false;
07192             }
07193             break;
07194         }
07195         }
07196     }
07197 
07198     handle_ = NULL;
07199 
07200     return true;
07201 }
07202 
07203 bool BarsParse::parseTimeSignature(Measure* measure, int /*length*/) {
07204     Block placeHolder;
07205 
07206     TimeSignature* timeSignature = measure->getTime();
07207 
07208     // numerator
07209     if( !readBuffer(placeHolder, 1) ) { return false; }
07210     timeSignature->setNumerator(placeHolder.toUnsignedInt());
07211 
07212     // denominator
07213     if( !readBuffer(placeHolder, 1) ) { return false; }
07214     timeSignature->setDenominator(placeHolder.toUnsignedInt());
07215 
07216     if( !jump(2) ) { return false; }
07217 
07218     // beat length
07219     if( !readBuffer(placeHolder, 2) ) { return false; }
07220     timeSignature->setBeatLength(placeHolder.toUnsignedInt());
07221 
07222     // bar length
07223     if( !readBuffer(placeHolder, 2) ) { return false; }
07224     timeSignature->setBarLength(placeHolder.toUnsignedInt());
07225 
07226     if( !jump(4) ) { return false; }
07227 
07228     // is symbol
07229     if( !readBuffer(placeHolder, 1) ) { return false; }
07230     timeSignature->setIsSymbol(placeHolder.toBoolean());
07231 
07232     if( !jump(1) ) { return false; }
07233 
07234     // replace font
07235     if( !readBuffer(placeHolder, 1) ) { return false; }
07236     timeSignature->setReplaceFont(placeHolder.toBoolean());
07237 
07238     // color
07239     if( !readBuffer(placeHolder, 1) ) { return false; }
07240     timeSignature->setColor(placeHolder.toUnsignedInt());
07241 
07242     // show
07243     if( !readBuffer(placeHolder, 1) ) { return false; }
07244     timeSignature->setShow(placeHolder.toBoolean());
07245 
07246     // show beat group
07247     if( !readBuffer(placeHolder, 1) ) { return false; }
07248     timeSignature->setShowBeatGroup(placeHolder.toBoolean());
07249 
07250     if( !jump(6) ) { return false; }
07251 
07252     // numerator 1, 2, 3
07253     if( !readBuffer(placeHolder, 1) ) { return false; }
07254     timeSignature->setGroupNumerator1(placeHolder.toUnsignedInt());
07255     if( !readBuffer(placeHolder, 1) ) { return false; }
07256     timeSignature->setGroupNumerator2(placeHolder.toUnsignedInt());
07257     if( !readBuffer(placeHolder, 1) ) { return false; }
07258     timeSignature->setGroupNumerator3(placeHolder.toUnsignedInt());
07259 
07260     // denominator
07261     if( !readBuffer(placeHolder, 1) ) { return false; }
07262     timeSignature->setGroupDenominator1(placeHolder.toUnsignedInt());
07263     if( !readBuffer(placeHolder, 1) ) { return false; }
07264     timeSignature->setGroupDenominator2(placeHolder.toUnsignedInt());
07265     if( !readBuffer(placeHolder, 1) ) { return false; }
07266     timeSignature->setGroupDenominator3(placeHolder.toUnsignedInt());
07267 
07268     // beam group 1~4
07269     if( !readBuffer(placeHolder, 1) ) { return false; }
07270     timeSignature->setBeamGroup1(placeHolder.toUnsignedInt());
07271     if( !readBuffer(placeHolder, 1) ) { return false; }
07272     timeSignature->setBeamGroup2(placeHolder.toUnsignedInt());
07273     if( !readBuffer(placeHolder, 1) ) { return false; }
07274     timeSignature->setBeamGroup3(placeHolder.toUnsignedInt());
07275     if( !readBuffer(placeHolder, 1) ) { return false; }
07276     timeSignature->setBeamGroup4(placeHolder.toUnsignedInt());
07277 
07278     // beam 16th
07279     if( !readBuffer(placeHolder, 1) ) { return false; }
07280     timeSignature->set16thBeamCount(placeHolder.toUnsignedInt());
07281 
07282     // beam 32th
07283     if( !readBuffer(placeHolder, 1) ) { return false; }
07284     timeSignature->set32thBeamCount(placeHolder.toUnsignedInt());
07285 
07286     return true;
07287 }
07288 
07289 bool BarsParse::parseTimeSignatureParameters(Measure* measure, int length) {
07290     Block placeHolder;
07291     TimeSignature* ts = measure->getTime();
07292 
07293     int cursor = ove_->getIsVersion4() ? 10 : 8;
07294     if( !jump(cursor) ) { return false; }
07295 
07296     // numerator
07297     if( !readBuffer(placeHolder, 1) ) { return false; }
07298     unsigned int numerator = placeHolder.toUnsignedInt();
07299 
07300     cursor = ove_->getIsVersion4() ? 11 : 9;
07301     if( ( length - cursor ) % 8 != 0 || (length - cursor) / 8 != (int)numerator ) {
07302         return false;
07303     }
07304 
07305     for( unsigned int i =0; i<numerator; ++i ) {
07306         // beat start unit
07307         if( !readBuffer(placeHolder, 2) ) { return false; }
07308         int beatStart = placeHolder.toUnsignedInt();
07309 
07310         // beat length unit
07311         if( !readBuffer(placeHolder, 2) ) { return false; }
07312         int beatLength = placeHolder.toUnsignedInt();
07313 
07314         if( !jump(2) ) { return false; }
07315 
07316         // beat start tick
07317         if( !readBuffer(placeHolder, 2) ) { return false; }
07318         int beatStartTick = placeHolder.toUnsignedInt();
07319 
07320         ts->addBeat(beatStart, beatLength, beatStartTick);
07321     }
07322 
07323     ts->endAddBeat();
07324 
07325     return true;
07326 }
07327 
07328 bool BarsParse::parseBarlineParameters(Measure* measure, int /*length*/) {
07329     Block placeHolder;
07330 
07331     int cursor = ove_->getIsVersion4() ? 12 : 10;
07332     if( !jump(cursor) ) { return false; }
07333 
07334     // repeat count
07335     if( !readBuffer(placeHolder, 1) ) { return false; }
07336     int repeatCount = placeHolder.toUnsignedInt();
07337 
07338     measure->setBackwardRepeatCount(repeatCount);
07339 
07340     if( !jump(6) ) { return false; }
07341 
07342     return true;
07343 }
07344 
07345 bool BarsParse::parseNumericEndings(MeasureData* measureData, int /*length*/) {
07346     Block placeHolder;
07347 
07348     NumericEnding* numeric = new NumericEnding();
07349     measureData->addCrossMeasureElement(numeric, true);
07350 
07351     if( !jump(3) ) { return false; }
07352 
07353     // common
07354     if( !parseCommonBlock(numeric) ) { return false; }
07355 
07356     if( !jump(6) ) { return false; }
07357 
07358     // measure count
07359     if( !readBuffer(placeHolder, 2) ) { return false; }
07360     //int offsetMeasure = placeHolder.toUnsignedInt() - 1;
07361     int offsetMeasure = placeHolder.toUnsignedInt();
07362     numeric->stop()->setMeasure(offsetMeasure);
07363 
07364     if( !jump(2) ) { return false; }
07365 
07366     // left x offset
07367     if( !readBuffer(placeHolder, 2) ) { return false; }
07368     numeric->getLeftShoulder()->setXOffset(placeHolder.toInt());
07369 
07370     // height
07371     if( !readBuffer(placeHolder, 2) ) { return false; }
07372     numeric->setHeight(placeHolder.toUnsignedInt());
07373 
07374     // left x offset
07375     if( !readBuffer(placeHolder, 2) ) { return false; }
07376     numeric->getRightShoulder()->setXOffset(placeHolder.toInt());
07377 
07378     if( !jump(2) ) { return false; }
07379 
07380     // y offset
07381     if( !readBuffer(placeHolder, 2) ) { return false; }
07382     numeric->getLeftShoulder()->setYOffset(placeHolder.toInt());
07383     numeric->getRightShoulder()->setYOffset(placeHolder.toInt());
07384 
07385     // number offset
07386     if( !readBuffer(placeHolder, 2) ) { return false; }
07387     numeric->getNumericHandle()->setXOffset(placeHolder.toInt());
07388     if( !readBuffer(placeHolder, 2) ) { return false; }
07389     numeric->getNumericHandle()->setYOffset(placeHolder.toInt());
07390 
07391     if( !jump(6) ) { return false; }
07392 
07393     // text size
07394     if( !readBuffer(placeHolder, 1) ) { return false; }
07395     unsigned int size = placeHolder.toUnsignedInt();
07396 
07397     // text : size maybe a huge value
07398     if( !readBuffer(placeHolder, size) ) { return false; }
07399     numeric->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
07400 
07401     // fix for wedding march.ove
07402     if( size % 2 == 0 ) {
07403         if( !jump(1) ) { return false; }
07404     }
07405 
07406     return true;
07407 }
07408 
07409 bool BarsParse::parseTempo(MeasureData* measureData, int /*length*/) {
07410     Block placeHolder;
07411     unsigned int thisByte;
07412 
07413     Tempo* tempo = new Tempo();
07414     measureData->addMusicData(tempo);
07415 
07416     if( !jump(3) ) { return false; }
07417 
07418     // common
07419     if( !parseCommonBlock(tempo) ) { return false; }
07420 
07421     if( !readBuffer(placeHolder, 1) ) { return false; }
07422     thisByte = placeHolder.toUnsignedInt();
07423 
07424     // show tempo
07425     tempo->setShowMark( (getHighNibble(thisByte) & 0x4) == 0x4 );
07426     // show before text
07427     tempo->setShowBeforeText( (getHighNibble(thisByte) & 0x8 ) == 0x8 ) ;
07428     // show parenthesis
07429     tempo->setShowParenthesis( (getHighNibble(thisByte) & 0x1 ) == 0x1 );
07430     // left note type
07431     tempo->setLeftNoteType( getLowNibble(thisByte) );
07432 
07433     if( !jump(1) ) { return false; }
07434 
07435     if( ove_->getIsVersion4() ) {
07436         if( !jump(2) ) { return false; }
07437 
07438         // tempo
07439         if( !readBuffer(placeHolder, 2) ) { return false; }
07440         tempo->setTypeTempo(placeHolder.toUnsignedInt()/100);
07441     } else {
07442         // tempo
07443         if( !readBuffer(placeHolder, 2) ) { return false; }
07444         tempo->setTypeTempo(placeHolder.toUnsignedInt());
07445 
07446         if( !jump(2) ) { return false; }
07447     }
07448 
07449     // offset
07450     if( !parseOffsetElement(tempo) ) { return false; }
07451 
07452     if( !jump(16) ) { return false; }
07453 
07454     // 31 bytes left text
07455     if( !readBuffer(placeHolder, 31) ) { return false; }
07456     tempo->setLeftText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
07457 
07458     if( !readBuffer(placeHolder, 1) ) { return false; }
07459     thisByte = placeHolder.toUnsignedInt();
07460 
07461     // swing eighth
07462     tempo->setSwingEighth(getHighNibble(thisByte)!=8);
07463 
07464     // right note type
07465     tempo->setRightNoteType(getLowNibble(thisByte));
07466 
07467     // right text
07468     if( ove_->getIsVersion4() ) {
07469         if( !readBuffer(placeHolder, 31) ) { return false; }
07470         tempo->setRightText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
07471 
07472         if( !jump(1) ) { return false; }
07473     }
07474 
07475     return true;
07476 }
07477 
07478 bool BarsParse::parseBarNumber(Measure* measure, int /*length*/) {
07479     Block placeHolder;
07480 
07481     BarNumber* barNumber = measure->getBarNumber();
07482 
07483     if( !jump(2) ) { return false; }
07484 
07485     // show on paragraph start
07486     if( !readBuffer(placeHolder, 1) ) { return false; }
07487     barNumber->setShowOnParagraphStart(getLowNibble(placeHolder.toUnsignedInt())==8);
07488 
07489     unsigned int blankSize = ove_->getIsVersion4() ? 9 : 7;
07490     if( !jump(blankSize) ) { return false; }
07491 
07492     // text align
07493     if( !readBuffer(placeHolder, 1) ) { return false; }
07494     barNumber->setAlign(placeHolder.toUnsignedInt());
07495 
07496     if( !jump(4) ) { return false; }
07497 
07498     // show flag
07499     if( !readBuffer(placeHolder, 1) ) { return false; }
07500     barNumber->setShowFlag(placeHolder.toUnsignedInt());
07501 
07502     if( !jump(10) ) { return false; }
07503 
07504     // bar range
07505     if( !readBuffer(placeHolder, 1) ) { return false; }
07506     barNumber->setShowEveryBarCount(placeHolder.toUnsignedInt());
07507 
07508     // prefix
07509     if( !readBuffer(placeHolder, 2) ) { return false; }
07510     barNumber->setPrefix(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
07511 
07512     if( !jump(18) ) { return false; }
07513 
07514     return true;
07515 }
07516 
07517 bool BarsParse::parseText(MeasureData* measureData, int length) {
07518     Block placeHolder;
07519 
07520     Text* text = new Text();
07521     measureData->addMusicData(text);
07522 
07523     if( !jump(3) ) { return false; }
07524 
07525     // common
07526     if( !parseCommonBlock(text) ) { return false; }
07527 
07528     // type
07529     if( !readBuffer(placeHolder, 1) ) { return false; }
07530     unsigned int thisByte = placeHolder.toUnsignedInt();
07531     bool includeLineBreak = ( (getHighNibble(thisByte)&0x2) != 0x2 );
07532     unsigned int id = getLowNibble(thisByte);
07533     Text::TextType textType = Text::Text_Rehearsal;
07534 
07535     if (id == 0) {
07536         textType = Text::Text_MeasureText;
07537     } else if (id == 1) {
07538         textType = Text::Text_SystemText;
07539     } else // id ==2
07540     {
07541         textType = Text::Text_Rehearsal;
07542     }
07543 
07544     text->setTextType(textType);
07545 
07546     if( !jump(1) ) { return false; }
07547 
07548     // x offset
07549     if( !readBuffer(placeHolder, 4) ) { return false; }
07550     text->setXOffset(placeHolder.toInt());
07551 
07552     // y offset
07553     if( !readBuffer(placeHolder, 4) ) { return false; }
07554     text->setYOffset(placeHolder.toInt());
07555 
07556     // width
07557     if( !readBuffer(placeHolder, 4) ) { return false; }
07558     text->setWidth(placeHolder.toUnsignedInt());
07559 
07560     // height
07561     if( !readBuffer(placeHolder, 4) ) { return false; }
07562     text->setHeight(placeHolder.toUnsignedInt());
07563 
07564     if( !jump(7) ) { return false; }
07565 
07566     // horizontal margin
07567     if( !readBuffer(placeHolder, 1) ) { return false; }
07568     text->setHorizontalMargin(placeHolder.toUnsignedInt());
07569 
07570     if( !jump(1) ) { return false; }
07571 
07572     // vertical margin
07573     if( !readBuffer(placeHolder, 1) ) { return false; }
07574     text->setVerticalMargin(placeHolder.toUnsignedInt());
07575 
07576     if( !jump(1) ) { return false; }
07577 
07578     // line thick
07579     if( !readBuffer(placeHolder, 1) ) { return false; }
07580     text->setLineThick(placeHolder.toUnsignedInt());
07581 
07582     if( !jump(2) ) { return false; }
07583 
07584     // text size
07585     if( !readBuffer(placeHolder, 2) ) { return false; }
07586     unsigned int size = placeHolder.toUnsignedInt();
07587 
07588     // text string, maybe huge
07589     if( !readBuffer(placeHolder, size) ) { return false; }
07590     text->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
07591 
07592     if( !includeLineBreak ) {
07593         if( !jump(6) ) { return false; }
07594     } else {
07595         unsigned int cursor = ove_->getIsVersion4() ? 43 : 41;
07596         cursor += size;
07597 
07598         // multi lines of text
07599         for( unsigned int i=0; i<2; ++i ) {
07600             if( (int)cursor < length ) {
07601                 // line parameters count
07602                 if( !readBuffer(placeHolder, 2) ) { return false; }
07603                 unsigned int lineCount = placeHolder.toUnsignedInt();
07604 
07605                 if( i==0 && int(cursor + 2 + 8*lineCount) > length ) {
07606                     return false;
07607                 }
07608 
07609                 if( i==1 && int(cursor + 2 + 8*lineCount) != length ) {
07610                     return false;
07611                 }
07612 
07613                 if( !jump(8*lineCount) ) { return false; }
07614 
07615                 cursor += 2 + 8*lineCount;
07616             }
07617         }
07618     }
07619 
07620     return true;
07621 }
07622 
07623 bool BarsParse::parseRepeatSymbol(MeasureData* measureData, int /*length*/) {
07624     Block placeHolder;
07625 
07626     RepeatSymbol* repeat = new RepeatSymbol();
07627     measureData->addMusicData(repeat);
07628 
07629     if( !jump(3) ) { return false; }
07630 
07631     // common
07632     if( !parseCommonBlock(repeat) ) { return false; }
07633 
07634     // RepeatType
07635     if( !readBuffer(placeHolder, 1) ) { return false; }
07636     repeat->setRepeatType(placeHolder.toUnsignedInt());
07637 
07638     if( !jump(13) ) { return false; }
07639 
07640     // offset
07641     if( !parseOffsetElement(repeat) ) { return false; }
07642 
07643     if( !jump(15) ) { return false; }
07644 
07645     // size
07646     if( !readBuffer(placeHolder, 2) ) { return false; }
07647     unsigned int size = placeHolder.toUnsignedInt();
07648 
07649     // text, maybe huge
07650     if( !readBuffer(placeHolder, size) ) { return false; }
07651     repeat->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
07652 
07653     // last 0
07654     if( size % 2 == 0 ) {
07655         if( !jump(1) ) { return false; }
07656     }
07657 
07658     return true;
07659 }
07660 
07661 bool BarsParse::parseBdat(Measure* /*measure*/, MeasureData* measureData, SizeChunk* chunk) {
07662     Block placeHolder;
07663     StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
07664 
07665     handle_ = &handle;
07666 
07667     // parse here
07668     if( !readBuffer(placeHolder, 2) ) { return false; }
07669     unsigned int cnt = placeHolder.toUnsignedInt();
07670 
07671     for( unsigned int i=0; i<cnt; ++i ) {
07672         // 0x0028 or 0x0016 or 0x002C
07673         if( !readBuffer(placeHolder, 2) ) { return false; }
07674         unsigned int count = placeHolder.toUnsignedInt() - 7;
07675 
07676         // type id
07677         if( !readBuffer(placeHolder, 1) ) { return false; }
07678         unsigned int thisByte = placeHolder.toUnsignedInt();
07679         BdatType type;
07680 
07681         if( !getBdatElementType(thisByte, type) ) { return false; }
07682 
07683         switch( type ) {
07684         case Bdat_Raw_Note :
07685         case Bdat_Rest :
07686         case Bdat_Note : {
07687                 if( !parseNoteRest(measureData, count, type) ) { return false; }
07688                 break;
07689             }
07690         case Bdat_Beam : {
07691                 if( !parseBeam(measureData, count) ) { return false; }
07692                 break;
07693             }
07694         case Bdat_Harmony : {
07695                 if( !parseHarmony(measureData, count) ) { return false; }
07696                 break;
07697             }
07698         case Bdat_Clef : {
07699                 if( !parseClef(measureData, count) ) { return false; }
07700                 break;
07701             }
07702         case Bdat_Dynamics : {
07703                 if( !parseDynamics(measureData, count) ) { return false; }
07704                 break;
07705             }
07706         case Bdat_Wedge : {
07707                 if( !parseWedge(measureData, count) ) { return false; }
07708                 break;
07709             }
07710         case Bdat_Glissando : {
07711                 if( !parseGlissando(measureData, count) ) { return false; }
07712                 break;
07713             }
07714         case Bdat_Decorator : {
07715                 if( !parseDecorators(measureData, count) ) { return false; }
07716                 break;
07717             }
07718         case Bdat_Key : {
07719                 if( !parseKey(measureData, count) ) { return false; }
07720                 break;
07721             }
07722         case Bdat_Lyric : {
07723                 if( !parseLyric(measureData, count) ) { return false; }
07724                 break;
07725             }
07726         case Bdat_Octave_Shift: {
07727                 if( !parseOctaveShift(measureData, count) ) { return false; }
07728                 break;
07729             }
07730         case Bdat_Slur : {
07731                 if( !parseSlur(measureData, count) ) { return false; }
07732                 break;
07733             }
07734         case Bdat_Text : {
07735                 if( !parseText(measureData, count) ) { return false; }
07736                 break;
07737             }
07738         case Bdat_Tie : {
07739                 if( !parseTie(measureData, count) ) { return false; }
07740                 break;
07741             }
07742         case Bdat_Tuplet : {
07743                 if( !parseTuplet(measureData, count) ) { return false; }
07744                 break;
07745             }
07746         case Bdat_Guitar_Bend :
07747         case Bdat_Guitar_Barre : {
07748                 if( !parseSizeBlock(count) ) { return false; }
07749                 break;
07750             }
07751         case Bdat_Pedal: {
07752                 if( !parsePedal(measureData, count) ) { return false; }
07753                 break;
07754             }
07755         case Bdat_KuoHao: {
07756                 if( !parseKuohao(measureData, count) ) { return false; }
07757                 break;
07758             }
07759         case Bdat_Expressions: {
07760                 if( !parseExpressions(measureData, count) ) { return false; }
07761                 break;
07762             }
07763         case Bdat_Harp_Pedal: {
07764                 if( !parseHarpPedal(measureData, count) ) { return false; }
07765                 break;
07766             }
07767         case Bdat_Multi_Measure_Rest: {
07768                 if( !parseMultiMeasureRest(measureData, count) ) { return false; }
07769                 break;
07770             }
07771         case Bdat_Harmony_GuitarFrame: {
07772                 if( !parseHarmonyGuitarFrame(measureData, count) ) { return false; }
07773                 break;
07774             }
07775         case Bdat_Graphics_40:
07776         case Bdat_Graphics_RoundRect:
07777         case Bdat_Graphics_Rect:
07778         case Bdat_Graphics_Round:
07779         case Bdat_Graphics_Line:
07780         case Bdat_Graphics_Curve:
07781         case Bdat_Graphics_WedgeSymbol: {
07782                 if( !parseSizeBlock(count) ) { return false; }
07783                 break;
07784             }
07785         case Bdat_Midi_Controller : {
07786                 if( !parseMidiController(measureData, count) ) { return false; }
07787                 break;
07788             }
07789         case Bdat_Midi_Program_Change : {
07790                 if( !parseMidiProgramChange(measureData, count) ) { return false; }
07791                 break;
07792             }
07793         case Bdat_Midi_Channel_Pressure : {
07794                 if( !parseMidiChannelPressure(measureData, count) ) { return false; }
07795                 break;
07796             }
07797         case Bdat_Midi_Pitch_Wheel : {
07798                 if( !parseMidiPitchWheel(measureData, count) ) { return false; }
07799                 break;
07800             }
07801         default: {
07802                 if( !jump(count) ) { return false; }
07803                 break;
07804             }
07805         }
07806 
07807         // if i==count-1 then is bar end place holder
07808     }
07809 
07810     handle_ = NULL;
07811 
07812     return true;
07813 }
07814 
07815 int getInt(int byte, int bits) {
07816     int num = 0;
07817 
07818     if( bits > 0 ) {
07819         int factor = int(pow(2.0, bits-1));
07820         num = (byte % (factor*2));
07821 
07822         if ( (byte & factor) == factor ) {
07823             num -= factor*2;
07824         }
07825     }
07826 
07827     return num;
07828 }
07829 
07830 bool BarsParse::parseNoteRest(MeasureData* measureData, int length, BdatType type) {
07831     NoteContainer* container = new NoteContainer();
07832     Block placeHolder;
07833     unsigned int thisByte;
07834 
07835     measureData->addNoteContainer(container);
07836     measureData->addMusicData(container);
07837 
07838     // note|rest & grace
07839     container->setIsRest(type==Bdat_Rest);
07840     container->setIsRaw(type==Bdat_Raw_Note);
07841 
07842     if( !readBuffer(placeHolder, 2) ) { return false; }
07843     thisByte = placeHolder.toUnsignedInt();
07844     container->setIsGrace( thisByte == 0x3C00 );
07845     container->setIsCue( thisByte == 0x4B40 || thisByte == 0x3240 );
07846 
07847     // show / hide
07848     if( !readBuffer(placeHolder, 1) ) { return false; }
07849     thisByte = placeHolder.toUnsignedInt();
07850     container->setShow(getLowNibble(thisByte)!=0x8);
07851 
07852     // voice
07853     container->setVoice(getLowNibble(thisByte)&0x7);
07854 
07855     // common
07856     if( !parseCommonBlock(container) ) { return false; }
07857 
07858     // tuplet
07859     if( !readBuffer(placeHolder, 1) ) { return false; }
07860     container->setTuplet(placeHolder.toUnsignedInt());
07861 
07862     // space
07863     if( !readBuffer(placeHolder, 1) ) { return false; }
07864     container->setSpace(placeHolder.toUnsignedInt());
07865 
07866     // in beam
07867     if( !readBuffer(placeHolder, 1) ) { return false; }
07868     thisByte = placeHolder.toUnsignedInt();
07869     bool inBeam = ( getHighNibble(thisByte) & 0x1 ) == 0x1;
07870     container->setInBeam(inBeam);
07871 
07872     // grace NoteType
07873     container->setGraceNoteType((NoteType)getHighNibble(thisByte));
07874 
07875     // dot
07876     container->setDot(getLowNibble(thisByte)&0x03);
07877 
07878     // NoteType
07879     if( !readBuffer(placeHolder, 1) ) { return false; }
07880     thisByte = placeHolder.toUnsignedInt();
07881     container->setNoteType((NoteType)getLowNibble(thisByte));
07882 
07883     int cursor = 0;
07884 
07885     if( type == Bdat_Rest ) {
07886         Note* restPtr = new Note();
07887         container->addNoteRest(restPtr);
07888         restPtr->setIsRest(true);
07889 
07890         // line
07891         if( !readBuffer(placeHolder, 1) ) { return false; }
07892         restPtr->setLine(placeHolder.toInt());
07893 
07894         if( !jump(1) ) { return false; }
07895 
07896         cursor = ove_->getIsVersion4() ? 16 : 14;
07897     } else // type == Bdat_Note || type == Bdat_Raw_Note
07898     {
07899         // stem up 0x80, stem down 0x00
07900         if( !readBuffer(placeHolder, 1) ) { return false; }
07901         thisByte = placeHolder.toUnsignedInt();
07902         container->setStemUp((getHighNibble(thisByte)&0x8)==0x8);
07903 
07904         // stem length
07905         int stemOffset = thisByte%0x80;
07906         container->setStemLength(getInt(stemOffset, 7)+7/*3.5 line span*/);
07907 
07908         // show stem 0x00, hide stem 0x40
07909         if( !readBuffer(placeHolder, 1) ) { return false; }
07910         bool hideStem = getHighNibble(thisByte)==0x4;
07911         container->setShowStem(!hideStem);
07912 
07913         if( !jump(1) ) { return false; }
07914 
07915         // note count
07916         if( !readBuffer(placeHolder, 1) ) { return false; }
07917         unsigned int noteCount = placeHolder.toUnsignedInt();
07918         unsigned int i;
07919 
07920         // each note 16 bytes
07921         for( i=0; i<noteCount; ++i ) {
07922             Note* notePtr = new Note();
07923             notePtr->setIsRest(false);
07924 
07925             container->addNoteRest(notePtr);
07926 
07927             // note show / hide
07928             if( !readBuffer(placeHolder, 1) ) { return false; }
07929             thisByte = placeHolder.toUnsignedInt();
07930             notePtr->setShow((thisByte&0x80) != 0x80);
07931 
07932             // note head type
07933             notePtr->setHeadType(thisByte&0x7f);
07934 
07935             // tie pos
07936             if( !readBuffer(placeHolder, 1) ) { return false; }
07937             thisByte = placeHolder.toUnsignedInt();
07938             notePtr->setTiePos(getHighNibble(thisByte));
07939 
07940             // offset staff, in {-1, 0, 1}
07941             if( !readBuffer(placeHolder, 1) ) { return false; }
07942             thisByte = getLowNibble(placeHolder.toUnsignedInt());
07943             int offsetStaff = 0;
07944             if( thisByte == 1 ) { offsetStaff = 1; }
07945             if( thisByte == 7 ) { offsetStaff = -1; }
07946             notePtr->setOffsetStaff(offsetStaff);
07947 
07948             // accidental
07949             if( !readBuffer(placeHolder, 1) ) { return false; }
07950             thisByte = placeHolder.toUnsignedInt();
07951             notePtr->setAccidental(getLowNibble(thisByte));
07952             // accidental 0: influenced by key, 4: influenced by previous accidental in measure
07953             bool notShow = ( getHighNibble(thisByte) == 0 ) || ( getHighNibble(thisByte) == 4 );
07954             notePtr->setShowAccidental(!notShow);
07955 
07956             if( !jump(1) ) { return false; }
07957 
07958             // line
07959             if( !readBuffer(placeHolder, 1) ) { return false; }
07960             notePtr->setLine(placeHolder.toInt());
07961 
07962             if( !jump(1) ) { return false; }
07963 
07964             // note
07965             if( !readBuffer(placeHolder, 1) ) { return false; }
07966             unsigned int note = placeHolder.toUnsignedInt();
07967             notePtr->setNote(note);
07968 
07969             // note on velocity
07970             if( !readBuffer(placeHolder, 1) ) { return false; }
07971             unsigned int onVelocity = placeHolder.toUnsignedInt();
07972             notePtr->setOnVelocity(onVelocity);
07973 
07974             // note off velocity
07975             if( !readBuffer(placeHolder, 1) ) { return false; }
07976             unsigned int offVelocity = placeHolder.toUnsignedInt();
07977             notePtr->setOffVelocity(offVelocity);
07978 
07979             if( !jump(2) ) { return false; }
07980 
07981             // length (tick)
07982             if( !readBuffer(placeHolder, 2) ) { return false; }
07983             container->setLength(placeHolder.toUnsignedInt());
07984 
07985             // offset tick
07986             if( !readBuffer(placeHolder, 2) ) { return false; }
07987             notePtr->setOffsetTick(placeHolder.toInt());
07988         }
07989 
07990         cursor = ove_->getIsVersion4() ? 18 : 16;
07991         cursor += noteCount * 16/*note size*/;
07992     }
07993 
07994     // articulation
07995     while ( cursor < length + 1/* 0x70 || 0x80 || 0x90 */ ) {
07996         Articulation* art = new Articulation();
07997         container->addArticulation(art);
07998 
07999         // block size
08000         if( !readBuffer(placeHolder, 2) ) { return false; }
08001         int blockSize = placeHolder.toUnsignedInt();
08002 
08003         // articulation type
08004         if( !readBuffer(placeHolder, 1) ) { return false; }
08005         art->setArtType(placeHolder.toUnsignedInt());
08006 
08007         // placement
08008         if( !readBuffer(placeHolder, 1) ) { return false; }
08009         art->setPlacementAbove(placeHolder.toUnsignedInt()!=0x00);  //0x00:below, 0x30:above
08010 
08011         // offset
08012         if( !parseOffsetElement(art) ) { return false; }
08013 
08014         if( !ove_->getIsVersion4() ) {
08015             if( blockSize - 8 > 0 ) {
08016                 if( !jump(blockSize-8) ) { return false; }
08017             }
08018         } else {
08019             // setting
08020             if( !readBuffer(placeHolder, 1) ) { return false; }
08021             thisByte = placeHolder.toUnsignedInt();
08022             const bool changeSoundEffect = ( ( thisByte & 0x1 ) == 0x1 );
08023             const bool changeLength = ( ( thisByte & 0x2 ) == 0x2 );
08024             const bool changeVelocity = ( ( thisByte & 0x4 ) == 0x4 );
08025             //const bool changeExtraLength = ( ( thisByte & 0x20 ) == 0x20 );
08026 
08027             if( !jump(8) ) { return false; }
08028 
08029             // velocity type
08030             if( !readBuffer(placeHolder, 1) ) { return false; }
08031             thisByte = placeHolder.toUnsignedInt();
08032             if( changeVelocity ) {
08033                 art->setVelocityType((Articulation::VelocityType)thisByte);
08034             }
08035 
08036             if( !jump(14) ) { return false; }
08037 
08038             // sound effect
08039             if( !readBuffer(placeHolder, 2) ) { return false; }
08040             int from = placeHolder.toInt();
08041             if( !readBuffer(placeHolder, 2) ) { return false; }
08042             int to = placeHolder.toInt();
08043             if( changeSoundEffect ) {
08044                 art->setSoundEffect(from, to);
08045             }
08046 
08047             if( !jump(1) ) { return false; }
08048 
08049             // length percentage
08050             if( !readBuffer(placeHolder, 1) ) { return false; }
08051             if( changeLength ) {
08052                 art->setLengthPercentage(placeHolder.toUnsignedInt());
08053             }
08054 
08055             // velocity
08056             if( !readBuffer(placeHolder, 2) ) { return false; }
08057             if( changeVelocity ) {
08058                 art->setVelocityValue(placeHolder.toInt());
08059             }
08060 
08061             if( Articulation::isTrill(art->getArtType()) ) {
08062                 if( !jump(8) ) { return false; }
08063 
08064                 // trill note length
08065                 if( !readBuffer(placeHolder, 1) ) { return false; }
08066                 art->setTrillNoteLength(placeHolder.toUnsignedInt());
08067 
08068                 // trill rate
08069                 if( !readBuffer(placeHolder, 1) ) { return false; }
08070                 thisByte = placeHolder.toUnsignedInt();
08071                 NoteType trillNoteType = Note_Sixteen;
08072                 switch ( getHighNibble(thisByte) ) {
08073                 case 0:
08074                     trillNoteType = Note_None;
08075                     break;
08076                 case 1:
08077                     trillNoteType = Note_Sixteen;
08078                     break;
08079                 case 2:
08080                     trillNoteType = Note_32;
08081                     break;
08082                 case 3:
08083                     trillNoteType = Note_64;
08084                     break;
08085                 case 4:
08086                     trillNoteType = Note_128;
08087                     break;
08088                 default:
08089                     break;
08090                 }
08091                 art->setTrillRate(trillNoteType);
08092 
08093                 // accelerate type
08094                 art->setAccelerateType(thisByte&0xf);
08095 
08096                 if( !jump(1) ) { return false; }
08097 
08098                 // auxiliary first
08099                 if( !readBuffer(placeHolder, 1) ) { return false; }
08100                 art->setAuxiliaryFirst(placeHolder.toBoolean());
08101 
08102                 if( !jump(1) ) { return false; }
08103 
08104                 // trill interval
08105                 if( !readBuffer(placeHolder, 1) ) { return false; }
08106                 art->setTrillInterval(placeHolder.toUnsignedInt());
08107             } else {
08108                 if( blockSize > 40 ) {
08109                     if( !jump( blockSize - 40 ) ) { return false; }
08110                 }
08111             }
08112         }
08113 
08114         cursor += blockSize;
08115     }
08116 
08117     return true;
08118 }
08119 
08120 int tupletToSpace(int tuplet) {
08121     int a(1);
08122 
08123     while( a*2 < tuplet ) {
08124         a *= 2;
08125     }
08126 
08127     return a;
08128 }
08129 
08130 bool BarsParse::parseBeam(MeasureData* measureData, int length)
08131 {
08132     int i;
08133     Block placeHolder;
08134 
08135     Beam* beam = new Beam();
08136     measureData->addCrossMeasureElement(beam, true);
08137 
08138     // maybe create tuplet, for < quarter & tool 3(
08139     bool createTuplet = false;
08140     int maxEndUnit = 0;
08141     Tuplet* tuplet = new Tuplet();
08142 
08143     // is grace
08144     if( !readBuffer(placeHolder, 1) ) { return false; }
08145     beam->setIsGrace(placeHolder.toBoolean());
08146 
08147     if( !jump(1) ) { return false; }
08148 
08149     // voice
08150     if( !readBuffer(placeHolder, 1) ) { return false; }
08151     beam->setVoice(getLowNibble(placeHolder.toUnsignedInt())&0x7);
08152 
08153     // common
08154     if( !parseCommonBlock(beam) ) { return false; }
08155 
08156     if( !jump(2) ) { return false; }
08157 
08158     // beam count
08159     if( !readBuffer(placeHolder, 1) ) { return false; }
08160     int beamCount = placeHolder.toUnsignedInt();
08161 
08162     if( !jump(1) ) { return false; }
08163 
08164     // left line
08165     if( !readBuffer(placeHolder, 1) ) { return false; }
08166     beam->getLeftLine()->setLine(placeHolder.toInt());
08167 
08168     // right line
08169     if( !readBuffer(placeHolder, 1) ) { return false; }
08170     beam->getRightLine()->setLine(placeHolder.toInt());
08171 
08172     if( ove_->getIsVersion4() ) {
08173         if( !jump(8) ) { return false; }
08174     }
08175 
08176     int currentCursor = ove_->getIsVersion4() ? 23 : 13;
08177     int count = (length - currentCursor)/16;
08178 
08179     if( count != beamCount ) { return false; }
08180 
08181     for( i=0; i<count; ++i ) {
08182         if( !jump(1) ) { return false; }
08183 
08184         // tuplet
08185         if( !readBuffer(placeHolder, 1) ) { return false; }
08186         int tupletCount = placeHolder.toUnsignedInt();
08187         if( tupletCount > 0 ) {
08188             createTuplet = true;
08189             tuplet->setTuplet(tupletCount);
08190             tuplet->setSpace(tupletToSpace(tupletCount));
08191         }
08192 
08193         // start / stop measure
08194         // line i start end position
08195         MeasurePos startMp;
08196         MeasurePos stopMp;
08197 
08198         if( !readBuffer(placeHolder, 1) ) { return false; }
08199         startMp.setMeasure(placeHolder.toUnsignedInt());
08200         if( !readBuffer(placeHolder, 1) ) { return false; }
08201         stopMp.setMeasure(placeHolder.toUnsignedInt());
08202 
08203         if( !readBuffer(placeHolder, 2) ) { return false; }
08204         startMp.setOffset(placeHolder.toInt());
08205         if( !readBuffer(placeHolder, 2) ) { return false; }
08206         stopMp.setOffset(placeHolder.toInt());
08207 
08208         beam->addLine(startMp, stopMp);
08209 
08210         if( stopMp.getOffset() > maxEndUnit ) {
08211             maxEndUnit = stopMp.getOffset();
08212         }
08213 
08214         if( i == 0 ) {
08215             if( !jump(4) ) { return false; }
08216 
08217             // left offset up+4, down-4
08218             if( !readBuffer(placeHolder, 2) ) { return false; }
08219             beam->getLeftShoulder()->setYOffset(placeHolder.toInt());
08220 
08221             // right offset up+4, down-4
08222             if( !readBuffer(placeHolder, 2) ) { return false; }
08223             beam->getRightShoulder()->setYOffset(placeHolder.toInt());
08224         } else {
08225             if( !jump(8) ) { return false; }
08226         }
08227     }
08228 
08229     const QList<QPair<MeasurePos, MeasurePos> > lines = beam->getLines();
08230     MeasurePos offsetMp;
08231 
08232     for( i=0; i<lines.size(); ++i ) {
08233         if( lines[i].second > offsetMp ) {
08234             offsetMp = lines[i].second;
08235         }
08236     }
08237 
08238     beam->stop()->setMeasure(offsetMp.getMeasure());
08239     beam->stop()->setOffset(offsetMp.getOffset());
08240 
08241     // a case that Tuplet block don't exist, and hide inside beam
08242     if( createTuplet ) {
08243         tuplet->copyCommonBlock(*beam);
08244         tuplet->getLeftLine()->setLine(beam->getLeftLine()->getLine());
08245         tuplet->getRightLine()->setLine(beam->getRightLine()->getLine());
08246         tuplet->stop()->setMeasure(beam->stop()->getMeasure());
08247         tuplet->stop()->setOffset(maxEndUnit);
08248 
08249         measureData->addCrossMeasureElement(tuplet, true);
08250     } else {
08251         delete tuplet;
08252     }
08253 
08254     return true;
08255 }
08256 
08257 bool BarsParse::parseTie(MeasureData* measureData, int /*length*/) {
08258     Block placeHolder;
08259 
08260     Tie* tie = new Tie();
08261     measureData->addCrossMeasureElement(tie, true);
08262 
08263     if( !jump(3) ) { return false; }
08264 
08265     // start common
08266     if( !parseCommonBlock(tie) ) { return false; }
08267 
08268     if( !jump(1) ) { return false; }
08269 
08270     // note
08271     if( !readBuffer(placeHolder, 1) ) { return false; }
08272     tie->setNote(placeHolder.toUnsignedInt());
08273 
08274     // pair lines
08275     if( !parsePairLinesBlock(tie) ) { return false; }
08276 
08277     // offset common
08278     if( !parseOffsetCommonBlock(tie) ) { return false; }
08279 
08280     // left shoulder offset
08281     if( !parseOffsetElement(tie->getLeftShoulder()) ) { return false; }
08282 
08283     // right shoulder offset
08284     if( !parseOffsetElement(tie->getRightShoulder()) ) { return false; }
08285 
08286     // height
08287     if( !readBuffer(placeHolder, 2) ) { return false; }
08288     tie->setHeight(placeHolder.toUnsignedInt());
08289 
08290     return true;
08291 }
08292 
08293 bool BarsParse::parseTuplet(MeasureData* measureData, int /*length*/) {
08294     Block placeHolder;
08295 
08296     Tuplet* tuplet = new Tuplet();
08297     measureData->addCrossMeasureElement(tuplet, true);
08298 
08299     if( !jump(3) ) { return false; }
08300 
08301     // common
08302     if( !parseCommonBlock(tuplet) ) { return false; }
08303 
08304     if( !jump(2) ) { return false; }
08305 
08306     // pair lines
08307     if( !parsePairLinesBlock(tuplet) ) { return false; }
08308 
08309     // offset common
08310     if( !parseOffsetCommonBlock(tuplet) ) { return false; }
08311 
08312     // left shoulder offset
08313     if( !parseOffsetElement(tuplet->getLeftShoulder()) ) { return false; }
08314 
08315     // right shoulder offset
08316     if( !parseOffsetElement(tuplet->getRightShoulder()) ) { return false; }
08317 
08318     if( !jump(2) ) { return false; }
08319 
08320     // height
08321     if( !readBuffer(placeHolder, 2) ) { return false; }
08322     tuplet->setHeight(placeHolder.toUnsignedInt());
08323 
08324     // tuplet
08325     if( !readBuffer(placeHolder, 1) ) { return false; }
08326     tuplet->setTuplet(placeHolder.toUnsignedInt());
08327 
08328     // space
08329     if( !readBuffer(placeHolder, 1) ) { return false; }
08330     tuplet->setSpace(placeHolder.toUnsignedInt());
08331 
08332     // mark offset
08333     if( !parseOffsetElement(tuplet->getMarkHandle()) ) { return false; }
08334 
08335     return true;
08336 }
08337 
08338 HarmonyType binaryToHarmonyType(int bin) {
08339     HarmonyType type = Harmony_maj;
08340     if( bin == 0x0091 ) {
08341         type = Harmony_maj;
08342     } else if( bin == 0x0089 ) {
08343         type = Harmony_min;
08344     } else if( bin == 0x0489 ) {
08345         type = Harmony_min7;
08346     } else if( bin == 0x0491 ) {
08347         type = Harmony_7;
08348     } else if( bin == 0x0495 ) {
08349         type = Harmony_9;
08350     } else if( bin == 0x0449 ) {
08351         type = Harmony_min7b5;
08352     } else if( bin == 0x04A1 ) {
08353         type = Harmony_7sus4;
08354     } else if( bin == 0x00A1 ) {
08355         type = Harmony_sus4;
08356     } else if( bin == 0x0049 ) {
08357         type = Harmony_dim;
08358     } else if( bin == 0x0249 ) {
08359         type = Harmony_dim7;
08360     } else if( bin == 0x0111 ) {
08361         type = Harmony_aug;
08362     } else if( bin == 0x0511 ) {
08363         type = Harmony_aug7;
08364     } else if( bin == 0x044D ) {
08365         type = Harmony_min9_b5;
08366     } else if( bin == 0x0499 ) {
08367         type = Harmony_7s9;
08368     } else if( bin == 0x0615 ) {
08369         type = Harmony_13;
08370     } else if( bin == 0x0289 ) {
08371         type = Harmony_min6;
08372     } else if( bin == 0x0291 ) {
08373         type = Harmony_6;
08374     } else if( bin == 0x0295 ) {
08375         type = Harmony_6;   //6add9
08376     } else if( bin == 0x0095 ) {
08377         type = Harmony_min; //minor add9
08378     } else if( bin == 0x008D ) {
08379         type = Harmony_maj7;
08380     } else if( bin == 0x0891 ) {
08381         type = Harmony_maj7;
08382     } else if( bin == 0x0881 ) {
08383         type = Harmony_maj7_s5; //maj7#5
08384     } else if( bin == 0x0911 ) {
08385         type = Harmony_maj7_s5; //maj7#5
08386     } else if( bin == 0x0991 ) {
08387         type = Harmony_maj7_s11;//maj7#11
08388     } else if( bin == 0x0851 ) {
08389         type = Harmony_maj7_s11;//maj7#11
08390     } else if( bin == 0x08D1 ) {
08391         type = Harmony_maj9;
08392     } else if( bin == 0x0895 ) {
08393         type = Harmony_maj9_s5; //maj9#5
08394     } else if( bin == 0x0995 ) {
08395         type = Harmony_maj13_s11;//maj9#11
08396     } else if( bin == 0x0855 ) {
08397         type = Harmony_maj9_s11;//maj9#11
08398     } else if( bin == 0x08D5 ) {
08399         type = Harmony_maj13;
08400     } else if( bin == 0x0A95 ) {
08401         type = Harmony_maj13_s11;//maj13#11
08402     } else if( bin == 0x0A55 ) {
08403         type = Harmony_maj13;   //maj13(no3)
08404     } else if( bin == 0x0A85 ) {
08405         type = Harmony_maj9_s5; //maj13#5#11(no4)
08406     } else if( bin == 0x0B45 ) {
08407         type = Harmony_7b9;
08408     } else if( bin == 0x0493 ) {
08409         type = Harmony_7b5;
08410     } else if( bin == 0x0451 ) {
08411         type = Harmony_9b5;
08412     } else if( bin == 0x0455 ) {
08413         type = Harmony_7s9;     //7#5#9
08414     } else if( bin == 0x0519 ) {
08415         type = Harmony_7b9;     //7#5b9
08416     } else if( bin == 0x0513 ) {
08417         type = Harmony_aug7;    //aug9
08418     } else if( bin == 0x0515 ) {
08419         type = Harmony_sus4;    //sus9
08420     } else if( bin == 0x04A5 ) {
08421         type = Harmony_13b9;
08422     } else if( bin == 0x0613 ) {
08423         type = Harmony_13b9;    //13b9#11
08424     } else if( bin == 0x0611 ) {
08425         type = Harmony_13;
08426     } else if( bin == 0x0653 ) {
08427         type = Harmony_min;     //m(natural7)
08428     } else if( bin == 0x0889 ) {
08429         type = Harmony_min9;    //m9(natural7)
08430     } else if( bin == 0x088D ) {
08431         type = Harmony_min11;
08432     } else if( bin == 0x04AD ) {
08433         type = Harmony_9s11;
08434     } else if( bin == 0x04D5 ) {
08435         type = Harmony_7sus4;   //sus7
08436     } else if( bin == 0x0421 ) {
08437         type = Harmony_min11;
08438     } else if( bin == 0x04A9 ) {
08439         type = Harmony_min9;
08440     } else if( bin == 0x048D ) {
08441         type = Harmony_7b5b9;
08442     } else if( bin == 0x0453 ) {
08443         type = Harmony_maj;     //(no5)
08444     } else if( bin == 0x0011 ) {
08445         type = Harmony_maj7;    //(no3)
08446     } else if( bin == 0x0081 ) {
08447         type = Harmony_7;       //7(no3)
08448     } else if( bin == 0x0481 ) {
08449         type = Harmony_7;       //7(no5)
08450     } else if( bin == 0x0411 ) {
08451         type = Harmony_6;
08452     } else if( bin == 0x0291 ) {
08453         type = Harmony_sus4;    //sus(add9)
08454     } else if( bin == 0x00A5 ) {
08455         type = Harmony_13s9;    //13#9b5
08456     } else if( bin == 0x0659 ) {
08457         type = Harmony_sus4;    //sus(no5)
08458     } else if( bin == 0x0021 ) {
08459         type = Harmony_7b5b9;   //7b5b9#9
08460     } else if( bin == 0x045B ) {
08461         type = Harmony_13b5;    //13b5b9#9
08462     } else if( bin == 0x065B ) {
08463         type = Harmony_13b9;    //13b9#9
08464     } else if( bin == 0x061B ) {
08465         type = Harmony_7b9s9;   //7b9#9
08466     } else if( bin == 0x04B5 ) {
08467         type = Harmony_7;
08468     }
08469 
08470     return type;
08471 }
08472 
08473 bool BarsParse::parseHarmony(MeasureData* measureData, int /*length*/) {
08474     Block placeHolder;
08475 
08476     Harmony* harmony = new Harmony();
08477     measureData->addMusicData(harmony);
08478 
08479     if( !jump(3) ) { return false; }
08480 
08481     // common
08482     if( !parseCommonBlock(harmony) ) { return false; }
08483 
08484     // bass on bottom
08485     if( !readBuffer(placeHolder, 1) ) { return false; }
08486     harmony->setBassOnBottom((getHighNibble(placeHolder.toUnsignedInt())==0x4));
08487 
08488     if( !jump(1) ) { return false; }
08489 
08490     // y offset
08491     if( !readBuffer(placeHolder, 2) ) { return false; }
08492     harmony->setYOffset(placeHolder.toInt());
08493 
08494     // harmony type
08495     if( !readBuffer(placeHolder, 2) ) { return false; }
08496     harmony->setHarmonyType(binaryToHarmonyType(placeHolder.toUnsignedInt()));
08497 
08498     // root
08499     if( !readBuffer(placeHolder, 1) ) { return false; }
08500     harmony->setRoot(placeHolder.toInt());
08501 
08502     // bass
08503     if( !readBuffer(placeHolder, 1) ) { return false; }
08504     harmony->setBass(placeHolder.toInt());
08505 
08506     // angle
08507     if( !readBuffer(placeHolder, 2) ) { return false; }
08508     harmony->setAngle(placeHolder.toInt());
08509 
08510     if( ove_->getIsVersion4() ) {
08511         // length (tick)
08512         if( !readBuffer(placeHolder, 2) ) { return false; }
08513         harmony->setLength(placeHolder.toUnsignedInt());
08514 
08515         if( !jump(4) ) { return false; }
08516     }
08517 
08518     return true;
08519 }
08520 
08521 bool BarsParse::parseClef(MeasureData* measureData, int /*length*/) {
08522     Block placeHolder;
08523 
08524     Clef* clef = new Clef();
08525     measureData->addMusicData(clef);
08526 
08527     if( !jump(3) ) { return false; }
08528 
08529     // common
08530     if( !parseCommonBlock(clef) ) { return false; }
08531 
08532     // clef type
08533     if( !readBuffer(placeHolder, 1) ) { return false; }
08534     clef->setClefType(placeHolder.toUnsignedInt());
08535 
08536     // line
08537     if( !readBuffer(placeHolder, 1) ) { return false; }
08538     clef->setLine(placeHolder.toInt());
08539 
08540     if( !jump(2) ) { return false; }
08541 
08542     return true;
08543 }
08544 
08545 bool BarsParse::parseLyric(MeasureData* measureData, int length) {
08546     Block placeHolder;
08547 
08548     Lyric* lyric = new Lyric();
08549     measureData->addMusicData(lyric);
08550 
08551     if( !jump(3) ) { return false; }
08552 
08553     // common
08554     if( !parseCommonBlock(lyric) ) { return false; }
08555 
08556     if( !jump(2) ) { return false; }
08557 
08558     // offset
08559     if( !parseOffsetElement(lyric) ) { return false; }
08560 
08561     if( !jump(7) ) { return false; }
08562 
08563     // verse
08564     if( !readBuffer(placeHolder, 1) ) { return false; }
08565     lyric->setVerse(placeHolder.toUnsignedInt());
08566 
08567     if( ove_->getIsVersion4() ) {
08568         if( !jump(6) ) { return false; }
08569 
08570         // lyric
08571         if( length > 29 ) {
08572             if( !readBuffer(placeHolder, length-29) ) { return false; }
08573             lyric->setLyric(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
08574         }
08575     }
08576 
08577     return true;
08578 }
08579 
08580 bool BarsParse::parseSlur(MeasureData* measureData, int /*length*/) {
08581     Block placeHolder;
08582 
08583     Slur* slur = new Slur();
08584     measureData->addCrossMeasureElement(slur, true);
08585 
08586     if( !jump(2) ) { return false; }
08587 
08588     // voice
08589     if( !readBuffer(placeHolder, 1) ) { return false; }
08590     slur->setVoice(getLowNibble(placeHolder.toUnsignedInt())&0x7);
08591 
08592     // common
08593     if( !parseCommonBlock(slur) ) { return false; }
08594 
08595     // show on top
08596     if( !readBuffer(placeHolder, 1) ) { return false; }
08597     slur->setShowOnTop(getHighNibble(placeHolder.toUnsignedInt())==0x8);
08598 
08599     if( !jump(1) ) { return false; }
08600 
08601     // pair lines
08602     if( !parsePairLinesBlock(slur) ) { return false; }
08603 
08604     // offset common
08605     if( !parseOffsetCommonBlock(slur) ) { return false; }
08606 
08607     // handle 1
08608     if( !parseOffsetElement(slur->getLeftShoulder()) ) { return false; }
08609 
08610     // handle 4
08611     if( !parseOffsetElement(slur->getRightShoulder()) ) { return false; }
08612 
08613     // handle 2
08614     if( !parseOffsetElement(slur->getHandle2()) ) { return false; }
08615 
08616     // handle 3
08617     if( !parseOffsetElement(slur->getHandle3()) ) { return false; }
08618 
08619     if( ove_->getIsVersion4() ) {
08620         if( !jump(3) ) { return false; }
08621 
08622         // note time percent
08623         if( !readBuffer(placeHolder, 1) ) { return false; }
08624         slur->setNoteTimePercent(placeHolder.toUnsignedInt());
08625 
08626         if( !jump(36) ) { return false; }
08627     }
08628 
08629     return true;
08630 }
08631 
08632 bool BarsParse::parseGlissando(MeasureData* measureData, int /*length*/) {
08633     Block placeHolder;
08634 
08635     Glissando* glissando = new Glissando();
08636     measureData->addCrossMeasureElement(glissando, true);
08637 
08638     if( !jump(3) ) { return false; }
08639 
08640     // common
08641     if( !parseCommonBlock(glissando) ) { return false; }
08642 
08643     // straight or wavy
08644     if( !readBuffer(placeHolder, 1) ) { return false; }
08645     unsigned int thisByte = placeHolder.toUnsignedInt();
08646     glissando->setStraightWavy(getHighNibble(thisByte)==4);
08647 
08648     if( !jump(1) ) { return false; }
08649 
08650     // pair lines
08651     if( !parsePairLinesBlock(glissando) ) { return false; }
08652 
08653     // offset common
08654     if( !parseOffsetCommonBlock(glissando) ) { return false; }
08655 
08656     // left shoulder
08657     if( !parseOffsetElement(glissando->getLeftShoulder()) ) { return false; }
08658 
08659     // right shoulder
08660     if( !parseOffsetElement(glissando->getRightShoulder()) ) { return false; }
08661 
08662     if( ove_->getIsVersion4() ) {
08663         if( !jump(1) ) { return false; }
08664 
08665         // line thick
08666         if( !readBuffer(placeHolder, 1) ) { return false; }
08667         glissando->setLineThick(placeHolder.toUnsignedInt());
08668 
08669         if( !jump(12) ) { return false; }
08670 
08671         // text 32 bytes
08672         if( !readBuffer(placeHolder, 32) ) { return false; }
08673         glissando->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
08674 
08675         if( !jump(6) ) { return false; }
08676     }
08677 
08678     return true;
08679 }
08680 
08681 bool getDecoratorType(
08682             unsigned int thisByte,
08683             bool& measureRepeat,
08684             Decorator::DecoratorType& decoratorType,
08685             bool& singleRepeat,
08686             ArticulationType& artType) {
08687     measureRepeat = false;
08688     decoratorType = Decorator::Decorator_Articulation;
08689     singleRepeat = true;
08690     artType = Articulation_None;
08691 
08692     switch (thisByte) {
08693     case 0x00: {
08694         decoratorType = Decorator::Decorator_Dotted_Barline;
08695         break;
08696     }
08697     case 0x30: {
08698         artType = Articulation_Open_String;
08699         break;
08700     }
08701     case 0x31: {
08702         artType = Articulation_Finger_1;
08703         break;
08704     }
08705     case 0x32: {
08706         artType = Articulation_Finger_2;
08707         break;
08708     }
08709     case 0x33: {
08710         artType = Articulation_Finger_3;
08711         break;
08712     }
08713     case 0x34: {
08714         artType = Articulation_Finger_4;
08715         break;
08716     }
08717     case 0x35: {
08718         artType = Articulation_Finger_5;
08719         break;
08720     }
08721     case 0x6B: {
08722         artType = Articulation_Flat_Accidental_For_Trill;
08723         break;
08724     }
08725     case 0x6C: {
08726         artType = Articulation_Sharp_Accidental_For_Trill;
08727         break;
08728     }
08729     case 0x6D: {
08730         artType = Articulation_Natural_Accidental_For_Trill;
08731         break;
08732     }
08733     case 0x8d: {
08734         measureRepeat = true;
08735         singleRepeat = true;
08736         break;
08737     }
08738     case 0x8e: {
08739         measureRepeat = true;
08740         singleRepeat = false;
08741         break;
08742     }
08743     case 0xA0: {
08744         artType = Articulation_Minor_Trill;
08745         break;
08746     }
08747     case 0xA1: {
08748         artType = Articulation_Major_Trill;
08749         break;
08750     }
08751     case 0xA2: {
08752         artType = Articulation_Trill_Section;
08753         break;
08754     }
08755     case 0xA6: {
08756         artType = Articulation_Turn;
08757         break;
08758     }
08759     case 0xA8: {
08760         artType = Articulation_Tremolo_Eighth;
08761         break;
08762     }
08763     case 0xA9: {
08764         artType = Articulation_Tremolo_Sixteenth;
08765         break;
08766     }
08767     case 0xAA: {
08768         artType = Articulation_Tremolo_Thirty_Second;
08769         break;
08770     }
08771     case 0xAB: {
08772         artType = Articulation_Tremolo_Sixty_Fourth;
08773         break;
08774     }
08775     case 0xB2: {
08776         artType = Articulation_Fermata;
08777         break;
08778     }
08779     case 0xB3: {
08780         artType = Articulation_Fermata_Inverted;
08781         break;
08782     }
08783     case 0xB9: {
08784         artType = Articulation_Pause;
08785         break;
08786     }
08787     case 0xBA: {
08788         artType = Articulation_Grand_Pause;
08789         break;
08790     }
08791     case 0xC0: {
08792         artType = Articulation_Marcato;
08793         break;
08794     }
08795     case 0xC1: {
08796         artType = Articulation_Marcato_Dot;
08797         break;
08798     }
08799     case 0xC2: {
08800         artType = Articulation_SForzando;
08801         break;
08802     }
08803     case 0xC3: {
08804         artType = Articulation_SForzando_Dot;
08805         break;
08806     }
08807     case 0xC4: {
08808         artType = Articulation_SForzando_Inverted;
08809         break;
08810     }
08811     case 0xC5: {
08812         artType = Articulation_SForzando_Dot_Inverted;
08813         break;
08814     }
08815     case 0xC6: {
08816         artType = Articulation_Staccatissimo;
08817         break;
08818     }
08819     case 0xC7: {
08820         artType = Articulation_Staccato;
08821         break;
08822     }
08823     case 0xC8: {
08824         artType = Articulation_Tenuto;
08825         break;
08826     }
08827     case 0xC9: {
08828         artType = Articulation_Natural_Harmonic;
08829         break;
08830     }
08831     case 0xCA: {
08832         artType = Articulation_Artificial_Harmonic;
08833         break;
08834     }
08835     case 0xCB: {
08836         artType = Articulation_Plus_Sign;
08837         break;
08838     }
08839     case 0xCC: {
08840         artType = Articulation_Up_Bow;
08841         break;
08842     }
08843     case 0xCD: {
08844         artType = Articulation_Down_Bow;
08845         break;
08846     }
08847     case 0xCE: {
08848         artType = Articulation_Up_Bow_Inverted;
08849         break;
08850     }
08851     case 0xCF: {
08852         artType = Articulation_Down_Bow_Inverted;
08853         break;
08854     }
08855     case 0xD0: {
08856         artType = Articulation_Pedal_Down;
08857         break;
08858     }
08859     case 0xD1: {
08860         artType = Articulation_Pedal_Up;
08861         break;
08862     }
08863     case 0xD6: {
08864         artType = Articulation_Heavy_Attack;
08865         break;
08866     }
08867     case 0xD7: {
08868         artType = Articulation_Heavier_Attack;
08869         break;
08870     }
08871     default:
08872         return false;
08873         break;
08874     }
08875 
08876     return true;
08877 }
08878 
08879 bool BarsParse::parseDecorators(MeasureData* measureData, int length) {
08880     Block placeHolder;
08881     MusicData* musicData = new MusicData();
08882 
08883     if( !jump(3) ) { return false; }
08884 
08885     // common
08886     if( !parseCommonBlock(musicData) ) { return false; }
08887 
08888     if( !jump(2) ) { return false; }
08889 
08890     // y offset
08891     if( !readBuffer(placeHolder, 2) ) { return false; }
08892     musicData->setYOffset(placeHolder.toInt());
08893 
08894     if( !jump(2) ) { return false; }
08895 
08896     // measure repeat | piano pedal | dotted barline | articulation
08897     if( !readBuffer(placeHolder, 1) ) { return false; }
08898     unsigned int thisByte = placeHolder.toUnsignedInt();
08899 
08900     Decorator::DecoratorType decoratorType;
08901     bool isMeasureRepeat;
08902     bool isSingleRepeat = true;
08903     ArticulationType artType = Articulation_None;
08904 
08905     getDecoratorType(thisByte, isMeasureRepeat, decoratorType, isSingleRepeat, artType);
08906 
08907     if( isMeasureRepeat ) {
08908         MeasureRepeat* measureRepeat = new MeasureRepeat();
08909         measureData->addCrossMeasureElement(measureRepeat, true);
08910 
08911         measureRepeat->copyCommonBlock(*musicData);
08912         measureRepeat->setYOffset(musicData->getYOffset());
08913 
08914         measureRepeat->setSingleRepeat(isSingleRepeat);
08915     } else {
08916         Decorator* decorator = new Decorator();
08917         measureData->addMusicData(decorator);
08918 
08919         decorator->copyCommonBlock(*musicData);
08920         decorator->setYOffset(musicData->getYOffset());
08921 
08922         decorator->setDecoratorType(decoratorType);
08923         decorator->setArticulationType(artType);
08924     }
08925 
08926     int cursor = ove_->getIsVersion4() ? 16 : 14;
08927     if( !jump(length-cursor) ) { return false; }
08928 
08929     return true;
08930 }
08931 
08932 bool BarsParse::parseWedge(MeasureData* measureData, int length) {
08933     Block placeHolder;
08934     Wedge* wedge = new Wedge();
08935 
08936     if( !jump(3) ) { return false; }
08937 
08938     // common
08939     if( !parseCommonBlock(wedge) ) { return false; }
08940 
08941     // wedge type
08942     if( !readBuffer(placeHolder, 1) ) { return false; }
08943     WedgeType wedgeType = Wedge_Cres_Line;
08944     bool wedgeOrExpression = true;
08945     unsigned int highHalfByte = getHighNibble(placeHolder.toUnsignedInt());
08946     unsigned int lowHalfByte = getLowNibble(placeHolder.toUnsignedInt());
08947 
08948     switch (highHalfByte) {
08949     case 0x0: {
08950         wedgeType = Wedge_Cres_Line;
08951         wedgeOrExpression = true;
08952         break;
08953     }
08954     case 0x4: {
08955         wedgeType = Wedge_Decresc_Line;
08956         wedgeOrExpression = true;
08957         break;
08958     }
08959     case 0x6: {
08960         wedgeType = Wedge_Decresc;
08961         wedgeOrExpression = false;
08962         break;
08963     }
08964     case 0x2: {
08965         wedgeType = Wedge_Cres;
08966         wedgeOrExpression = false;
08967         break;
08968     }
08969     default:
08970         break;
08971     }
08972 
08973     // 0xb | 0x8(ove3) , else 3, 0(ove3)
08974     if( (lowHalfByte & 0x8) == 0x8 ) {
08975         wedgeType = Wedge_Double_Line;
08976         wedgeOrExpression = true;
08977     }
08978 
08979     if( !jump(1) ) { return false; }
08980 
08981     // y offset
08982     if( !readBuffer(placeHolder, 2) ) { return false; }
08983     wedge->setYOffset(placeHolder.toInt());
08984 
08985     // wedge
08986     if( wedgeOrExpression ) {
08987         measureData->addCrossMeasureElement(wedge, true);
08988         wedge->setWedgeType(wedgeType);
08989 
08990         if( !jump(2) ) { return false; }
08991 
08992         // height
08993         if( !readBuffer(placeHolder, 2) ) { return false; }
08994         wedge->setHeight(placeHolder.toUnsignedInt());
08995 
08996         // offset common
08997         if( !parseOffsetCommonBlock(wedge) ) { return false; }
08998 
08999         int cursor = ove_->getIsVersion4() ? 21 : 19;
09000         if( !jump(length-cursor) ) { return false; }
09001     }
09002     // expression : cresc, decresc
09003     else {
09004         Expressions* express = new Expressions();
09005         measureData->addMusicData(express);
09006 
09007         express->copyCommonBlock(*wedge);
09008         express->setYOffset(wedge->getYOffset());
09009 
09010         if( !jump(4) ) { return false; }
09011 
09012         // offset common
09013         if( !parseOffsetCommonBlock(express) ) { return false; }
09014 
09015         if( ove_->getIsVersion4() ) {
09016             if( !jump(18) ) { return false; }
09017 
09018             // words
09019             if( length > 39 ) {
09020                 if( !readBuffer(placeHolder, length-39) ) { return false; }
09021                 express->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
09022             }
09023         } else {
09024             QString str = wedgeType==Wedge_Cres ? "cresc" : "decresc";
09025             express->setText(str);
09026 
09027             if( !jump(8) ) { return false; }
09028         }
09029     }
09030 
09031     return true;
09032 }
09033 
09034 bool BarsParse::parseDynamics(MeasureData* measureData, int /*length*/) {
09035     Block placeHolder;
09036 
09037     Dynamics* dynamics = new Dynamics();
09038     measureData->addMusicData(dynamics);
09039 
09040     if( !jump(1) ) { return false; }
09041 
09042     // is playback
09043     if( !readBuffer(placeHolder, 1) ) { return false; }
09044     dynamics->setIsPlayback(getHighNibble(placeHolder.toUnsignedInt())!=0x4);
09045 
09046     if( !jump(1) ) { return false; }
09047 
09048     // common
09049     if( !parseCommonBlock(dynamics) ) { return false; }
09050 
09051     // y offset
09052     if( !readBuffer(placeHolder, 2) ) { return false; }
09053     dynamics->setYOffset(placeHolder.toInt());
09054 
09055     // dynamics type
09056     if( !readBuffer(placeHolder, 1) ) { return false; }
09057     dynamics->setDynamicsType(getLowNibble(placeHolder.toUnsignedInt()));
09058 
09059     // velocity
09060     if( !readBuffer(placeHolder, 1) ) { return false; }
09061     dynamics->setVelocity(placeHolder.toUnsignedInt());
09062 
09063     int cursor = ove_->getIsVersion4() ? 4 : 2;
09064 
09065     if( !jump(cursor) ) { return false; }
09066 
09067     return true;
09068 }
09069 
09070 bool BarsParse::parseKey(MeasureData* measureData, int /*length*/) {
09071     Block placeHolder;
09072     Key* key = measureData->getKey();
09073     int cursor = ove_->getIsVersion4() ? 9 : 7;
09074 
09075     if( !jump(cursor) ) { return false; }
09076 
09077     // key
09078     if( !readBuffer(placeHolder, 1) ) { return false; }
09079     key->setKey(oveKeyToKey(placeHolder.toUnsignedInt()));
09080 
09081     // previous key
09082     if( !readBuffer(placeHolder, 1) ) { return false; }
09083     key->setPreviousKey(oveKeyToKey(placeHolder.toUnsignedInt()));
09084 
09085     if( !jump(3) ) { return false; }
09086 
09087     // symbol count
09088     if( !readBuffer(placeHolder, 1) ) { return false; }
09089     key->setSymbolCount(placeHolder.toUnsignedInt());
09090 
09091     if( !jump(4) ) { return false; }
09092 
09093     return true;
09094 }
09095 
09096 bool BarsParse::parsePedal(MeasureData* measureData, int length) {
09097     Block placeHolder;
09098 
09099     Pedal* pedal = new Pedal();
09100     //measureData->addMusicData(pedal); //can't remember why
09101     measureData->addCrossMeasureElement(pedal, true);
09102 
09103     if( !jump(1) ) { return false; }
09104 
09105     // is playback
09106     if( !readBuffer(placeHolder, 1) ) { return false; }
09107     pedal->setIsPlayback(getHighNibble(placeHolder.toUnsignedInt())!=4);
09108 
09109     if( !jump(1) ) { return false; }
09110 
09111     // common
09112     if( !parseCommonBlock(pedal) ) { return false; }
09113 
09114     if( !jump(2) ) { return false; }
09115 
09116     // pair lines
09117     if( !parsePairLinesBlock(pedal) ) { return false; }
09118 
09119     // offset common
09120     if( !parseOffsetCommonBlock(pedal) ) { return false; }
09121 
09122     // left shoulder
09123     if( !parseOffsetElement(pedal->getLeftShoulder()) ) { return false; }
09124 
09125     // right shoulder
09126     if( !parseOffsetElement(pedal->getRightShoulder()) ) { return false; }
09127 
09128     int cursor = ove_->getIsVersion4() ? 0x45 : 0x23;
09129     int blankCount = ove_->getIsVersion4() ? 42 : 10;
09130 
09131     pedal->setHalf( length > cursor );
09132 
09133     if( !jump(blankCount) ) { return false; }
09134 
09135     if( length > cursor ) {
09136         if( !jump(2) ) { return false; }
09137 
09138         // handle x offset
09139         if( !readBuffer(placeHolder, 2) ) { return false; }
09140         pedal->getPedalHandle()->setXOffset(placeHolder.toInt());
09141 
09142         if( !jump(6) ) { return false; }
09143     }
09144 
09145     return true;
09146 }
09147 
09148 bool BarsParse::parseKuohao(MeasureData* measureData, int /*length*/) {
09149     Block placeHolder;
09150 
09151     KuoHao* kuoHao = new KuoHao();
09152     measureData->addMusicData(kuoHao);
09153 
09154     if( !jump(3) ) { return false; }
09155 
09156     // common
09157     if( !parseCommonBlock(kuoHao) ) { return false; }
09158 
09159     if( !jump(2) ) { return false; }
09160 
09161     // pair lines
09162     if( !parsePairLinesBlock(kuoHao) ) { return false; }
09163 
09164     if( !jump(4) ) { return false; }
09165 
09166     // left shoulder
09167     if( !parseOffsetElement(kuoHao->getLeftShoulder()) ) { return false; }
09168 
09169     // right shoulder
09170     if( !parseOffsetElement(kuoHao->getRightShoulder()) ) { return false; }
09171 
09172     // kuohao type
09173     if( !readBuffer(placeHolder, 1) ) { return false; }
09174     kuoHao->setKuohaoType(placeHolder.toUnsignedInt());
09175 
09176     // height
09177     if( !readBuffer(placeHolder, 1) ) { return false; }
09178     kuoHao->setHeight(placeHolder.toUnsignedInt());
09179 
09180     int jumpAmount = ove_->getIsVersion4() ? 40 : 8;
09181     if( !jump(jumpAmount) ) { return false; }
09182 
09183     return true;
09184 }
09185 
09186 bool BarsParse::parseExpressions(MeasureData* measureData, int length) {
09187     Block placeHolder;
09188 
09189     Expressions* expressions = new Expressions();
09190     measureData->addMusicData(expressions);
09191 
09192     if( !jump(3) ) { return false; }
09193 
09194     // common00
09195     if( !parseCommonBlock(expressions) ) { return false; }
09196 
09197     if( !jump(2) ) { return false; }
09198 
09199     // y offset
09200     if( !readBuffer(placeHolder, 2) ) { return false; }
09201     expressions->setYOffset(placeHolder.toInt());
09202 
09203     // range bar offset
09204     if( !readBuffer(placeHolder, 2) ) { return false; }
09205     //int barOffset = placeHolder.toUnsignedInt();
09206 
09207     if( !jump(10) ) { return false; }
09208 
09209     // tempo 1
09210     if( !readBuffer(placeHolder, 2) ) { return false; }
09211     //double tempo1 = ((double)placeHolder.toUnsignedInt()) / 100.0;
09212 
09213     // tempo 2
09214     if( !readBuffer(placeHolder, 2) ) { return false; }
09215     //double tempo2 = ((double)placeHolder.toUnsignedInt()) / 100.0;
09216 
09217     if( !jump(6) ) { return false; }
09218 
09219     // text
09220     int cursor = ove_->getIsVersion4() ? 35 : 33;
09221     if( length > cursor ) {
09222         if( !readBuffer(placeHolder, length-cursor) ) { return false; }
09223         expressions->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
09224     }
09225 
09226     return true;
09227 }
09228 
09229 bool BarsParse::parseHarpPedal(MeasureData* measureData, int /*length*/) {
09230     Block placeHolder;
09231 
09232     HarpPedal* harpPedal = new HarpPedal();
09233     measureData->addMusicData(harpPedal);
09234 
09235     if( !jump(3) ) { return false; }
09236 
09237     // common
09238     if( !parseCommonBlock(harpPedal) ) { return false; }
09239 
09240     if( !jump(2) ) { return false; }
09241 
09242     // y offset
09243     if( !readBuffer(placeHolder, 2) ) { return false; }
09244     harpPedal->setYOffset(placeHolder.toInt());
09245 
09246     // show type
09247     if( !readBuffer(placeHolder, 1) ) { return false; }
09248     harpPedal->setShowType(placeHolder.toUnsignedInt());
09249 
09250     // show char flag
09251     if( !readBuffer(placeHolder, 1) ) { return false; }
09252     harpPedal->setShowCharFlag(placeHolder.toUnsignedInt());
09253 
09254     if( !jump(8) ) { return false; }
09255 
09256     return true;
09257 }
09258 
09259 bool BarsParse::parseMultiMeasureRest(MeasureData* measureData, int /*length*/) {
09260     Block placeHolder(2);
09261     MultiMeasureRest* measureRest = new MultiMeasureRest();
09262     measureData->addMusicData(measureRest);
09263 
09264     if( !jump(3) ) { return false; }
09265 
09266     // common
09267     if( !parseCommonBlock(measureRest) ) { return false; }
09268 
09269     if( !jump(6) ) { return false; }
09270 
09271     return true;
09272 }
09273 
09274 bool BarsParse::parseHarmonyGuitarFrame(MeasureData* measureData, int length) {
09275     Block placeHolder;
09276 
09277     Harmony* harmony = new Harmony();
09278     measureData->addMusicData(harmony);
09279 
09280     if( !jump(3) ) { return false; }
09281 
09282     // common
09283     if( !parseCommonBlock(harmony) ) { return false; }
09284 
09285     // root
09286     if( !readBuffer(placeHolder, 1) ) { return false; }
09287     harmony->setRoot(placeHolder.toUnsignedInt());
09288 
09289     // type
09290     if( !readBuffer(placeHolder, 1) ) { return false; }
09291     harmony->setHarmonyType((HarmonyType)placeHolder.toUnsignedInt());
09292 
09293     // bass
09294     if( !readBuffer(placeHolder, 1) ) { return false; }
09295     harmony->setBass(placeHolder.toUnsignedInt());
09296 
09297     int jumpAmount = ove_->getIsVersion4() ? length - 12 : length - 10;
09298     if( !jump(jumpAmount) ) { return false; }
09299 
09300     return true;
09301 }
09302 
09303 void extractOctave(unsigned int Bits, OctaveShiftType& octaveShiftType, QList<OctaveShiftPosition>& positions) {
09304     octaveShiftType = OctaveShift_8;
09305     positions.clear();
09306 
09307     switch (Bits) {
09308     case 0x0: {
09309         octaveShiftType = OctaveShift_8;
09310         positions.push_back(OctavePosition_Continue);
09311         break;
09312     }
09313     case 0x1: {
09314         octaveShiftType = OctaveShift_Minus_8;
09315         positions.push_back(OctavePosition_Continue);
09316         break;
09317     }
09318     case 0x2: {
09319         octaveShiftType = OctaveShift_15;
09320         positions.push_back(OctavePosition_Continue);
09321         break;
09322     }
09323     case 0x3: {
09324         octaveShiftType = OctaveShift_Minus_15;
09325         positions.push_back(OctavePosition_Continue);
09326         break;
09327     }
09328     case 0x4: {
09329         octaveShiftType = OctaveShift_8;
09330         positions.push_back(OctavePosition_Stop);
09331         break;
09332     }
09333     case 0x5: {
09334         octaveShiftType = OctaveShift_Minus_8;
09335         positions.push_back(OctavePosition_Stop);
09336         break;
09337     }
09338     case 0x6: {
09339         octaveShiftType = OctaveShift_15;
09340         positions.push_back(OctavePosition_Stop);
09341         break;
09342     }
09343     case 0x7: {
09344         octaveShiftType = OctaveShift_Minus_15;
09345         positions.push_back(OctavePosition_Stop);
09346         break;
09347     }
09348     case 0x8: {
09349         octaveShiftType = OctaveShift_8;
09350         positions.push_back(OctavePosition_Start);
09351         break;
09352     }
09353     case 0x9: {
09354         octaveShiftType = OctaveShift_Minus_8;
09355         positions.push_back(OctavePosition_Start);
09356         break;
09357     }
09358     case 0xA: {
09359         octaveShiftType = OctaveShift_15;
09360         positions.push_back(OctavePosition_Start);
09361         break;
09362     }
09363     case 0xB: {
09364         octaveShiftType = OctaveShift_Minus_15;
09365         positions.push_back(OctavePosition_Start);
09366         ;
09367         break;
09368     }
09369     case 0xC: {
09370         octaveShiftType = OctaveShift_8;
09371         positions.push_back(OctavePosition_Start);
09372         positions.push_back(OctavePosition_Stop);
09373         break;
09374     }
09375     case 0xD: {
09376         octaveShiftType = OctaveShift_Minus_8;
09377         positions.push_back(OctavePosition_Start);
09378         positions.push_back(OctavePosition_Stop);
09379         break;
09380     }
09381     case 0xE: {
09382         octaveShiftType = OctaveShift_15;
09383         positions.push_back(OctavePosition_Start);
09384         positions.push_back(OctavePosition_Stop);
09385         break;
09386     }
09387     case 0xF: {
09388         octaveShiftType = OctaveShift_Minus_15;
09389         positions.push_back(OctavePosition_Start);
09390         positions.push_back(OctavePosition_Stop);
09391         break;
09392     }
09393     default:
09394         break;
09395     }
09396 }
09397 
09398 bool BarsParse::parseOctaveShift(MeasureData* measureData, int /*length*/)
09399 {
09400     Block placeHolder;
09401 
09402     OctaveShift* octave = new OctaveShift();
09403     measureData->addCrossMeasureElement(octave, true);
09404 
09405     if( !jump(3) ) { return false; }
09406 
09407     // common
09408     if( !parseCommonBlock(octave) ) { return false; }
09409 
09410     // octave
09411     if( !readBuffer(placeHolder, 1) ) { return false; }
09412     unsigned int type = getLowNibble(placeHolder.toUnsignedInt());
09413     OctaveShiftType octaveShiftType = OctaveShift_8;
09414     QList<OctaveShiftPosition> positions;
09415     extractOctave(type, octaveShiftType, positions);
09416 
09417     octave->setOctaveShiftType(octaveShiftType);
09418 
09419     if( !jump(1) ) { return false; }
09420 
09421     // y offset
09422     if( !readBuffer(placeHolder, 2) ) { return false; }
09423     octave->setYOffset(placeHolder.toInt());
09424 
09425     if( !jump(4) ) { return false; }
09426 
09427     // length
09428     if( !readBuffer(placeHolder, 2) ) { return false; }
09429     octave->setLength(placeHolder.toUnsignedInt());
09430 
09431     // end tick
09432     if( !readBuffer(placeHolder, 2) ) { return false; }
09433     octave->setEndTick(placeHolder.toUnsignedInt());
09434 
09435     // start & stop maybe appear in same measure
09436     for (int i=0; i<positions.size(); ++i) {
09437         OctaveShiftPosition position = positions[i];
09438         OctaveShiftEndPoint* octavePoint = new OctaveShiftEndPoint();
09439         measureData->addMusicData(octavePoint);
09440 
09441         octavePoint->copyCommonBlock(*octave);
09442         octavePoint->setOctaveShiftType(octaveShiftType);
09443         octavePoint->setOctaveShiftPosition(position);
09444         octavePoint->setEndTick(octave->getEndTick());
09445 
09446         // stop
09447         if( i==0 && position == OctavePosition_Stop ) {
09448             octavePoint->start()->setOffset(octave->start()->getOffset()+octave->getLength());
09449         }
09450 
09451         // end point
09452         if( i>0 ) {
09453             octavePoint->start()->setOffset(octave->start()->getOffset()+octave->getLength());
09454             octavePoint->setTick(octave->getEndTick());
09455         }
09456     }
09457 
09458     return true;
09459 }
09460 
09461 bool BarsParse::parseMidiController(MeasureData* measureData, int /*length*/) {
09462     Block placeHolder;
09463     MidiController* controller = new MidiController();
09464     measureData->addMidiData(controller);
09465 
09466     parseMidiCommon(controller);
09467 
09468     // value [0, 128)
09469     if( !readBuffer(placeHolder, 1) ) { return false; }
09470     controller->setValue(placeHolder.toUnsignedInt());
09471 
09472     // controller number
09473     if( !readBuffer(placeHolder, 1) ) { return false; }
09474     controller->setController(placeHolder.toUnsignedInt());
09475 
09476     if( ove_->getIsVersion4() ) {
09477         if( !jump(2) ) { return false; }
09478     }
09479 
09480     return true;
09481 }
09482 
09483 bool BarsParse::parseMidiProgramChange(MeasureData* measureData, int /*length*/) {
09484     Block placeHolder;
09485     MidiProgramChange* program = new MidiProgramChange();
09486     measureData->addMidiData(program);
09487 
09488     parseMidiCommon(program);
09489 
09490     if( !jump(1) ) { return false; }
09491 
09492     // patch
09493     if( !readBuffer(placeHolder, 1) ) { return false; }
09494     program->setPatch(placeHolder.toUnsignedInt());
09495 
09496     if( ove_->getIsVersion4() ) {
09497         if( !jump(2) ) { return false; }
09498     }
09499 
09500     return true;
09501 }
09502 
09503 bool BarsParse::parseMidiChannelPressure(MeasureData* measureData, int /*length*/) {
09504     Block placeHolder;
09505     MidiChannelPressure* pressure = new MidiChannelPressure();
09506     measureData->addMidiData(pressure);
09507 
09508     parseMidiCommon(pressure);
09509 
09510     if( !jump(1) ) { return false; }
09511 
09512     // pressure
09513     if( !readBuffer(placeHolder, 1) ) { return false; }
09514     pressure->setPressure(placeHolder.toUnsignedInt());
09515 
09516     if( ove_->getIsVersion4() )
09517     {
09518         if( !jump(2) ) { return false; }
09519     }
09520 
09521     return true;
09522 }
09523 
09524 bool BarsParse::parseMidiPitchWheel(MeasureData* measureData, int /*length*/) {
09525     Block placeHolder;
09526     MidiPitchWheel* wheel = new MidiPitchWheel();
09527     measureData->addMidiData(wheel);
09528 
09529     parseMidiCommon(wheel);
09530 
09531     // pitch wheel
09532     if( !readBuffer(placeHolder, 2) ) { return false; }
09533     int value = placeHolder.toUnsignedInt();
09534     wheel->setValue(value);
09535 
09536     if( ove_->getIsVersion4() ) {
09537         if( !jump(2) ) { return false; }
09538     }
09539 
09540     return true;
09541 }
09542 
09543 bool BarsParse::parseSizeBlock(int length) {
09544     if( !jump(length) ) { return false; }
09545 
09546     return true;
09547 }
09548 
09549 bool BarsParse::parseMidiCommon(MidiData* ptr) {
09550     Block placeHolder;
09551 
09552     if( !jump(3) ) { return false; }
09553 
09554     // start position
09555     if( !readBuffer(placeHolder, 2) ) { return false; }
09556     ptr->setTick(placeHolder.toUnsignedInt());
09557 
09558     return true;
09559 }
09560 
09561 bool BarsParse::parseCommonBlock(MusicData* ptr) {
09562     Block placeHolder;
09563 
09564     // start tick
09565     if( !readBuffer(placeHolder, 2) ) { return false; }
09566     ptr->setTick(placeHolder.toInt());
09567 
09568     // start unit
09569     if( !readBuffer(placeHolder, 2) ) { return false; }
09570     ptr->start()->setOffset(placeHolder.toInt());
09571 
09572     if( ove_->getIsVersion4() )     {
09573         // color
09574         if( !readBuffer(placeHolder, 1) ) { return false; }
09575         ptr->setColor(placeHolder.toUnsignedInt());
09576 
09577         if( !jump(1) ) { return false; }
09578     }
09579 
09580     return true;
09581 }
09582 
09583 bool BarsParse::parseOffsetCommonBlock(MusicData* ptr) {
09584     Block placeHolder;
09585 
09586     // offset measure
09587     if( !readBuffer(placeHolder, 2) ) { return false; }
09588     ptr->stop()->setMeasure(placeHolder.toUnsignedInt());
09589 
09590     // end unit
09591     if( !readBuffer(placeHolder, 2) ) { return false; }
09592     ptr->stop()->setOffset(placeHolder.toInt());
09593 
09594     return true;
09595 }
09596 
09597 bool BarsParse::parsePairLinesBlock(PairEnds* ptr) {
09598     Block placeHolder;
09599 
09600     // left line
09601     if( !readBuffer(placeHolder, 2) ) { return false; }
09602     ptr->getLeftLine()->setLine(placeHolder.toInt());
09603 
09604     // right line
09605     if( !readBuffer(placeHolder, 2) ) { return false; }
09606     ptr->getRightLine()->setLine(placeHolder.toInt());
09607 
09608     return true;
09609 }
09610 
09611 bool BarsParse::parseOffsetElement(OffsetElement* ptr) {
09612     Block placeHolder;
09613 
09614     // x offset
09615     if( !readBuffer(placeHolder, 2) ) { return false; }
09616     ptr->setXOffset(placeHolder.toInt());
09617 
09618     // y offset
09619     if( !readBuffer(placeHolder, 2) ) { return false; }
09620     ptr->setYOffset(placeHolder.toInt());
09621 
09622     return true;
09623 }
09624 
09625 bool BarsParse::getCondElementType(unsigned int byteData, CondType& type) {
09626     if( byteData == 0x09 ) {
09627         type = Cond_Time_Parameters;
09628     } else if (byteData == 0x0A) {
09629         type = Cond_Bar_Number;
09630     } else if (byteData == 0x16) {
09631         type = Cond_Decorator;
09632     } else if (byteData == 0x1C) {
09633         type = Cond_Tempo;
09634     } else if (byteData == 0x1D) {
09635         type = Cond_Text;
09636     } else if (byteData == 0x25) {
09637         type = Cond_Expression;
09638     } else if (byteData == 0x30) {
09639         type = Cond_Barline_Parameters;
09640     } else if (byteData == 0x31) {
09641         type = Cond_Repeat;
09642     } else if (byteData == 0x32) {
09643         type = Cond_Numeric_Ending;
09644     } else {
09645         return false;
09646     }
09647 
09648     return true;
09649 }
09650 
09651 bool BarsParse::getBdatElementType(unsigned int byteData, BdatType& type) {
09652     if (byteData == 0x70) {
09653         type = Bdat_Raw_Note;
09654     } else if (byteData == 0x80) {
09655         type = Bdat_Rest;
09656     } else if (byteData == 0x90) {
09657         type = Bdat_Note;
09658     } else if (byteData == 0x10) {
09659         type = Bdat_Beam;
09660     } else if (byteData == 0x11) {
09661         type = Bdat_Harmony;
09662     } else if (byteData == 0x12) {
09663         type = Bdat_Clef;
09664     } else if (byteData == 0x13) {
09665         type = Bdat_Wedge;
09666     } else if (byteData == 0x14) {
09667         type = Bdat_Dynamics;
09668     } else if (byteData == 0x15) {
09669         type = Bdat_Glissando;
09670     } else if (byteData == 0x16) {
09671         type = Bdat_Decorator;
09672     } else if (byteData == 0x17) {
09673         type = Bdat_Key;
09674     } else if (byteData == 0x18) {
09675         type = Bdat_Lyric;
09676     } else if (byteData == 0x19) {
09677         type = Bdat_Octave_Shift;
09678     } else if (byteData == 0x1B) {
09679         type = Bdat_Slur;
09680     } else if (byteData == 0x1D) {
09681         type = Bdat_Text;
09682     } else if (byteData == 0x1E) {
09683         type = Bdat_Tie;
09684     } else if (byteData == 0x1F) {
09685         type = Bdat_Tuplet;
09686     } else if (byteData == 0x21) {
09687         type = Bdat_Guitar_Bend;
09688     } else if (byteData == 0x22) {
09689         type = Bdat_Guitar_Barre;
09690     } else if (byteData == 0x23) {
09691         type = Bdat_Pedal;
09692     } else if (byteData == 0x24) {
09693         type = Bdat_KuoHao;
09694     } else if (byteData == 0x25) {
09695         type = Bdat_Expressions;
09696     } else if (byteData == 0x26) {
09697         type = Bdat_Harp_Pedal;
09698     } else if (byteData == 0x27) {
09699         type = Bdat_Multi_Measure_Rest;
09700     } else if (byteData == 0x28) {
09701         type = Bdat_Harmony_GuitarFrame;
09702     } else if (byteData == 0x40) {
09703         type = Bdat_Graphics_40;
09704     } else if (byteData == 0x41) {
09705         type = Bdat_Graphics_RoundRect;
09706     } else if (byteData == 0x42) {
09707         type = Bdat_Graphics_Rect;
09708     } else if (byteData == 0x43) {
09709         type = Bdat_Graphics_Round;
09710     } else if (byteData == 0x44) {
09711         type = Bdat_Graphics_Line;
09712     } else if (byteData == 0x45) {
09713         type = Bdat_Graphics_Curve;
09714     } else if (byteData == 0x46) {
09715         type = Bdat_Graphics_WedgeSymbol;
09716     } else if (byteData == 0xAB) {
09717         type = Bdat_Midi_Controller;
09718     } else if (byteData == 0xAC) {
09719         type = Bdat_Midi_Program_Change;
09720     } else if (byteData == 0xAD) {
09721         type = Bdat_Midi_Channel_Pressure;
09722     } else if (byteData == 0xAE) {
09723         type = Bdat_Midi_Pitch_Wheel;
09724     } else if (byteData == 0xFF) {
09725         type = Bdat_Bar_End;
09726     } else {
09727         return false;
09728     }
09729 
09730     return true;
09731 }
09732 
09734 LyricChunkParse::LyricChunkParse(OveSong* ove) :
09735     BasicParse(ove) {
09736 }
09737 
09738 void LyricChunkParse::setLyricChunk(SizeChunk* chunk) {
09739     chunk_ = chunk;
09740 }
09741 
09742 // only ove3 has this chunk
09743 bool LyricChunkParse::parse() {
09744     unsigned int i;
09745     Block* dataBlock = chunk_->getDataBlock();
09746     unsigned int blockSize = chunk_->getSizeBlock()->toSize();
09747     StreamHandle handle(dataBlock->data(), blockSize);
09748     Block placeHolder;
09749 
09750     handle_ = &handle;
09751 
09752     if( !jump(4) ) { return false; }
09753 
09754     // Lyric count
09755     if( !readBuffer(placeHolder, 2) ) { return false; }
09756     unsigned int count = placeHolder.toUnsignedInt();
09757 
09758     for( i=0; i<count; ++i ) {
09759         LyricInfo info;
09760 
09761         if( !readBuffer(placeHolder, 2) ) { return false; }
09762         //unsigned int size = placeHolder.toUnsignedInt();
09763 
09764         // 0x0D00
09765         if( !jump(2) ) { return false; }
09766 
09767         // voice
09768         if( !readBuffer(placeHolder, 1) ) { return false; }
09769         info.voice_ = placeHolder.toUnsignedInt();
09770 
09771         // verse
09772         if( !readBuffer(placeHolder, 1) ) { return false; }
09773         info.verse_ = placeHolder.toUnsignedInt();
09774 
09775         // track
09776         if( !readBuffer(placeHolder, 1) ) { return false; }
09777         info.track_ = placeHolder.toUnsignedInt();
09778 
09779         if( !jump(1) ) { return false; }
09780 
09781         // measure
09782         if( !readBuffer(placeHolder, 2) ) { return false; }
09783         info.measure_ = placeHolder.toUnsignedInt();
09784 
09785         // word count
09786         if( !readBuffer(placeHolder, 2) ) { return false; }
09787         info.wordCount_ = placeHolder.toUnsignedInt();
09788 
09789         // lyric size
09790         if( !readBuffer(placeHolder, 2) ) { return false; }
09791         info.lyricSize_ = placeHolder.toUnsignedInt();
09792 
09793         if( !jump(6) ) { return false; }
09794 
09795         // name
09796         if( !readBuffer(placeHolder, 32) ) { return false; }
09797         info.name_ = ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray());
09798 
09799         if( info.lyricSize_ > 0 ) {
09800             // lyric
09801             if( info.lyricSize_ > 0 ) {
09802                 if( !readBuffer(placeHolder, info.lyricSize_) ) { return false; }
09803                 info.lyric_ = ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray());
09804             }
09805 
09806             if( !jump(4) ) { return false; }
09807 
09808             // font
09809             if( !readBuffer(placeHolder, 2) ) { return false; }
09810             info.font_ = placeHolder.toUnsignedInt();
09811 
09812             if( !jump(1) ) { return false; }
09813 
09814             // font size
09815             if( !readBuffer(placeHolder, 1) ) { return false; }
09816             info.fontSize_ = placeHolder.toUnsignedInt();
09817 
09818             // font style
09819             if( !readBuffer(placeHolder, 1) ) { return false; }
09820             info.fontStyle_ = placeHolder.toUnsignedInt();
09821 
09822             if( !jump(1) ) { return false; }
09823 
09824             for( int j=0; j<info.wordCount_; ++j ) {
09825                 if( !jump(8) ) { return false; }
09826             }
09827         }
09828 
09829         processLyricInfo(info);
09830     }
09831 
09832     return true;
09833 }
09834 
09835 bool isSpace(char c) {
09836     return c == ' ' || c == '\n';
09837 }
09838 
09839 void LyricChunkParse::processLyricInfo(const LyricInfo& info)
09840 {
09841     int i;
09842     int j;
09843     int index = 0; //words
09844 
09845     int measureId = info.measure_-1;
09846     bool changeMeasure = true;
09847     MeasureData* measureData = 0;
09848     int trackMeasureCount = ove_->getTrackBarCount();
09849     QStringList words = info.lyric_.split(" ", QString::SkipEmptyParts);
09850 
09851     while ( index < words.size() && measureId+1 < trackMeasureCount ) {
09852         if( changeMeasure ) {
09853             ++measureId;
09854             measureData = ove_->getMeasureData(info.track_, measureId);
09855             changeMeasure = false;
09856         }
09857 
09858         if( measureData == 0 ) { return; }
09859         QList<NoteContainer*> containers = measureData->getNoteContainers();
09860         QList<MusicData*> lyrics = measureData->getMusicDatas(MusicData_Lyric);
09861 
09862         for( i=0; i<containers.size() && index<words.size(); ++i ) {
09863             if( containers[i]->getIsRest() ) {
09864                 continue;
09865             }
09866 
09867             for( j=0; j<lyrics.size(); ++j ) {
09868                 Lyric* lyric = static_cast<Lyric*>(lyrics[j]);
09869 
09870                 if( containers[i]->start()->getOffset() == lyric->start()->getOffset() &&
09871                     (int)containers[i]->getVoice() == info.voice_ &&
09872                     lyric->getVerse() == info.verse_ ) {
09873                         if(index<words.size()) {
09874                             QString l = words[index].trimmed();
09875                             if(!l.isEmpty()) {
09876                                 lyric->setLyric(l);
09877                                 lyric->setVoice(info.voice_);
09878                             }
09879                         }
09880 
09881                         ++index;
09882                 }
09883             }
09884         }
09885 
09886         changeMeasure = true;
09887     }
09888 }
09889 
09891 TitleChunkParse::TitleChunkParse(OveSong* ove) :
09892     BasicParse(ove) {
09893     titleType_ = 0x00000001;
09894     annotateType_ = 0x00010000;
09895     writerType_ = 0x00020002;
09896     copyrightType_ = 0x00030001;
09897     headerType_ = 0x00040000;
09898     footerType_ = 0x00050002;
09899 }
09900 
09901 void TitleChunkParse::setTitleChunk(SizeChunk* chunk) {
09902     chunk_ = chunk;
09903 }
09904 
09905 bool TitleChunkParse::parse() {
09906     Block* dataBlock = chunk_->getDataBlock();
09907     unsigned int blockSize = chunk_->getSizeBlock()->toSize();
09908     StreamHandle handle(dataBlock->data(), blockSize);
09909     Block typeBlock;
09910     unsigned int titleType;
09911 
09912     handle_ = &handle;
09913 
09914     if( !readBuffer(typeBlock, 4) ) { return false; }
09915 
09916     titleType = typeBlock.toUnsignedInt();
09917 
09918     if( titleType == titleType_ || titleType == annotateType_ || titleType == writerType_ || titleType == copyrightType_ ) {
09919         Block offsetBlock;
09920 
09921         if( !readBuffer(offsetBlock, 4) ) { return false; }
09922 
09923         const unsigned int itemCount = 4;
09924         unsigned int i;
09925 
09926         for( i=0; i<itemCount; ++i ) {
09927             if( i>0 ) {
09928                 //0x 00 AB 00 0C 00 00
09929                 if( !jump(6) ) { return false; }
09930             }
09931 
09932             Block countBlock;
09933             if( !readBuffer(countBlock, 2) ) { return false; }
09934             unsigned int titleSize = countBlock.toUnsignedInt();
09935 
09936             Block dataBlock;
09937             if( !readBuffer(dataBlock, titleSize) ) { return false; }
09938 
09939             QByteArray array((char*)dataBlock.data(), dataBlock.size());
09940             addToOve(ove_->getCodecString(array), titleType);
09941         }
09942 
09943         return true;
09944     }
09945 
09946     if( titleType == headerType_ || titleType == footerType_ ) {
09947         if( !jump(10) ) { return false; }
09948 
09949         Block countBlock;
09950         if( !readBuffer(countBlock, 2) ) { return false; }
09951         unsigned int titleSize = countBlock.toUnsignedInt();
09952 
09953         Block dataBlock;
09954         if( !readBuffer(dataBlock, titleSize) ) { return false; }
09955 
09956         QByteArray array((char*)dataBlock.data(), dataBlock.size());
09957         addToOve(ove_->getCodecString(array), titleType);
09958 
09959         //0x 00 AB 00 0C 00 00
09960         if( !jump(6) ) { return false; }
09961 
09962         return true;
09963     }
09964 
09965     return false;
09966 }
09967 
09968 void TitleChunkParse::addToOve(const QString& str, unsigned int titleType) {
09969     if( str.isEmpty() ) { return; }
09970 
09971     if (titleType == titleType_) {
09972         ove_->addTitle(str);
09973     }
09974 
09975     if (titleType == annotateType_) {
09976         ove_->addAnnotate(str);
09977     }
09978 
09979     if (titleType == writerType_) {
09980         ove_->addWriter(str);
09981     }
09982 
09983     if (titleType == copyrightType_) {
09984         ove_->addCopyright(str);
09985     }
09986 
09987     if (titleType == headerType_) {
09988         ove_->addHeader(str);
09989     }
09990 
09991     if (titleType == footerType_) {
09992         ove_->addFooter(str);
09993     }
09994 }
09995 
09996 // OveOrganize.cpp
09997 OveOrganizer::OveOrganizer(OveSong* ove) {
09998     ove_ = ove;
09999 }
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 
11241 QOve::~QOve() {
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 && 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 = abs(art->getSoundEffect().first) + 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