LCOV - code coverage report
Current view: top level - src/importexport/ove/internal - ove.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 41.5 % 5953 2469
Test Date: 2026-11-05 04:07:02

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

Generated by: LCOV version 2.0-1