1 //=============================================================================
2 // MusE Score
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2002-2009 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19
20 #include "ove.h"
21
22 namespace OVE {
23
24 /*template <class T>
25 inline void deleteVector(QList<T*>& vec) {
26 for (int i=0; i<vec.size(); ++i)
27 delete vec[i];
28 }
29 //vec.clear();
30 }*/
31
32 ///////////////////////////////////////////////////////////////////////////////
TickElement()33 TickElement::TickElement() {
34 tick_ = 0;
35 }
36
setTick(int tick)37 void TickElement::setTick(int tick) {
38 tick_ = tick;
39 }
40
getTick(void) const41 int TickElement::getTick(void) const {
42 return tick_;
43 }
44
45 ///////////////////////////////////////////////////////////////////////////////
MeasurePos()46 MeasurePos::MeasurePos() {
47 measure_ = 0;
48 offset_ = 0;
49 }
50
setMeasure(int measure)51 void MeasurePos::setMeasure(int measure) {
52 measure_ = measure;
53 }
54
getMeasure() const55 int MeasurePos::getMeasure() const {
56 return measure_;
57 }
58
setOffset(int offset)59 void MeasurePos::setOffset(int offset) {
60 offset_ = offset;
61 }
62
getOffset() const63 int MeasurePos::getOffset() const {
64 return offset_;
65 }
66
shiftMeasure(int measure) const67 MeasurePos MeasurePos::shiftMeasure(int measure) const {
68 MeasurePos mp;
69 mp.setMeasure(getMeasure() + measure);
70 mp.setOffset(getOffset());
71
72 return mp;
73 }
74
shiftOffset(int offset) const75 MeasurePos MeasurePos::shiftOffset(int offset) const {
76 MeasurePos mp;
77 mp.setMeasure(getMeasure());
78 mp.setOffset(getOffset() + offset);
79
80 return mp;
81 }
82
operator ==(const MeasurePos & mp) const83 bool MeasurePos::operator ==(const MeasurePos& mp) const {
84 return getMeasure() == mp.getMeasure() && getOffset() == mp.getOffset();
85 }
86
operator !=(const MeasurePos & mp) const87 bool MeasurePos::operator !=(const MeasurePos& mp) const {
88 return !(*this == mp);
89 }
90
operator <(const MeasurePos & mp) const91 bool MeasurePos::operator <(const MeasurePos& mp) const {
92 if (getMeasure() != mp.getMeasure()) {
93 return getMeasure() < mp.getMeasure();
94 }
95
96 return getOffset() < mp.getOffset();
97 }
98
operator <=(const MeasurePos & mp) const99 bool MeasurePos::operator <=(const MeasurePos& mp) const {
100 if (getMeasure() != mp.getMeasure()) {
101 return getMeasure() <= mp.getMeasure();
102 }
103
104 return getOffset() <= mp.getOffset();
105 }
106
operator >(const MeasurePos & mp) const107 bool MeasurePos::operator >(const MeasurePos& mp) const {
108 return !(*this <= mp);
109 }
110
operator >=(const MeasurePos & mp) const111 bool MeasurePos::operator >=(const MeasurePos& mp) const {
112 return !(*this < mp);
113 }
114
115 ///////////////////////////////////////////////////////////////////////////////
PairElement()116 PairElement::PairElement() {
117 start_ = new MeasurePos();
118 stop_ = new MeasurePos();
119 }
120
~PairElement()121 PairElement::~PairElement(){
122 delete start_;
123 delete stop_;
124 }
125
start() const126 MeasurePos* PairElement::start() const {
127 return start_;
128 }
129
stop() const130 MeasurePos* PairElement::stop() const {
131 return stop_;
132 }
133
134 ///////////////////////////////////////////////////////////////////////////////
PairEnds()135 PairEnds::PairEnds() {
136 leftLine_ = new LineElement();
137 rightLine_ = new LineElement();
138 leftShoulder_ = new OffsetElement();
139 rightShoulder_ = new OffsetElement();
140 }
141
~PairEnds()142 PairEnds::~PairEnds(){
143 delete leftLine_;
144 delete rightLine_;
145 delete leftShoulder_;
146 delete rightShoulder_;
147 }
148
getLeftLine() const149 LineElement* PairEnds::getLeftLine() const {
150 return leftLine_;
151 }
152
getRightLine() const153 LineElement* PairEnds::getRightLine() const {
154 return rightLine_;
155 }
156
getLeftShoulder() const157 OffsetElement* PairEnds::getLeftShoulder() const {
158 return leftShoulder_;
159 }
160
getRightShoulder() const161 OffsetElement* PairEnds::getRightShoulder() const {
162 return rightShoulder_;
163 }
164
165 ///////////////////////////////////////////////////////////////////////////////
LineElement()166 LineElement::LineElement() {
167 line_ = 0;
168 }
169
setLine(int line)170 void LineElement::setLine(int line) {
171 line_ = line;
172 }
173
getLine(void) const174 int LineElement::getLine(void) const {
175 return line_;
176 }
177
178 ///////////////////////////////////////////////////////////////////////////////
OffsetElement()179 OffsetElement::OffsetElement() {
180 xOffset_ = 0;
181 yOffset_ = 0;
182 }
183
setXOffset(int offset)184 void OffsetElement::setXOffset(int offset) {
185 xOffset_ = offset;
186 }
187
getXOffset() const188 int OffsetElement::getXOffset() const {
189 return xOffset_;
190 }
191
setYOffset(int offset)192 void OffsetElement::setYOffset(int offset) {
193 yOffset_ = offset;
194 }
195
getYOffset() const196 int OffsetElement::getYOffset() const {
197 return yOffset_;
198 }
199
200 ///////////////////////////////////////////////////////////////////////////////
LengthElement()201 LengthElement::LengthElement() {
202 length_ = 0;
203 }
204
setLength(int length)205 void LengthElement::setLength(int length) {
206 length_ = length;
207 }
208
getLength() const209 int LengthElement::getLength() const {
210 return length_;
211 }
212
213 ///////////////////////////////////////////////////////////////////////////////
MusicData()214 MusicData::MusicData() {
215 musicDataType_ = MusicDataType::None;
216 show_ = true;
217 color_ = 0;
218 voice_ = 0;
219 }
220
getMusicDataType() const221 MusicDataType MusicData::getMusicDataType() const {
222 return musicDataType_;
223 }
224
getXmlDataType(MusicDataType type)225 MusicData::XmlDataType MusicData::getXmlDataType(MusicDataType type) {
226 XmlDataType xmlType = XmlDataType::None;
227
228 switch (type) {
229 case MusicDataType::Measure_Repeat: {
230 xmlType = XmlDataType::Attributes;
231 break;
232 }
233 case MusicDataType::Beam: {
234 xmlType = XmlDataType::NoteBeam;
235 break;
236 }
237 case MusicDataType::Slur:
238 case MusicDataType::Glissando:
239 case MusicDataType::Tuplet:
240 case MusicDataType::Tie: {
241 xmlType = XmlDataType::Notations;
242 break;
243 }
244 case MusicDataType::Text:
245 case MusicDataType::Repeat:
246 case MusicDataType::Wedge:
247 case MusicDataType::Dynamics:
248 case MusicDataType::Pedal:
249 case MusicDataType::OctaveShift_EndPoint: {
250 xmlType = XmlDataType::Direction;
251 break;
252 }
253 default: {
254 xmlType = XmlDataType::None;
255 break;
256 }
257 }
258
259 return xmlType;
260 }
261
262 /*bool MusicData::get_is_pair_element(MusicDataType type)
263 {
264 bool pair = false;
265
266 switch ( type )
267 {
268 case MusicDataType::Numeric_Ending :
269 case MusicDataType::Measure_Repeat :
270 case MusicDataType::Wedge :
271 case MusicDataType::OctaveShift :
272 //case MusicDataType::OctaveShift_EndPoint :
273 case MusicDataType::Pedal :
274 case MusicDataType::Beam :
275 case MusicDataType::Glissando :
276 case MusicDataType::Slur :
277 case MusicDataType::Tie :
278 case MusicDataType::Tuplet :
279 {
280 pair = true;
281 break;
282 }
283 default:
284 break;
285 }
286
287 return pair;
288 }*/
289
setShow(bool show)290 void MusicData::setShow(bool show) {
291 show_ = show;
292 }
293
getShow() const294 bool MusicData::getShow() const {
295 return show_;
296 }
297
setColor(unsigned int color)298 void MusicData::setColor(unsigned int color) {
299 color_ = color;
300 }
301
getColor() const302 unsigned int MusicData::getColor() const {
303 return color_;
304 }
305
setVoice(unsigned int voice)306 void MusicData::setVoice(unsigned int voice) {
307 voice_ = voice;
308 }
309
getVoice() const310 unsigned int MusicData::getVoice() const {
311 return voice_;
312 }
313
copyCommonBlock(const MusicData & source)314 void MusicData::copyCommonBlock(const MusicData& source) {
315 setTick(source.getTick());
316 start()->setOffset(source.start()->getOffset());
317 setColor(source.getColor());
318 }
319
320 ///////////////////////////////////////////////////////////////////////////////
MidiData()321 MidiData::MidiData() {
322 midiType_ = MidiType::None;
323 }
324
getMidiType() const325 MidiType MidiData::getMidiType() const {
326 return midiType_;
327 }
328
329 ///////////////////////////////////////////////////////////////////////////////
OveSong()330 OveSong::OveSong() :
331 codec_(0) {
332 clear();
333 }
334
~OveSong()335 OveSong::~OveSong() {
336 clear();
337 }
338
setIsVersion4(bool version4)339 void OveSong::setIsVersion4(bool version4){
340 version4_ = version4;
341 }
342
getIsVersion4() const343 bool OveSong::getIsVersion4() const {
344 return version4_;
345 }
346
setQuarter(int tick)347 void OveSong::setQuarter(int tick) {
348 quarter_ = tick;
349 }
350
getQuarter(void) const351 int OveSong::getQuarter(void) const {
352 return quarter_;
353 }
354
setShowPageMargin(bool show)355 void OveSong::setShowPageMargin(bool show){
356 showPageMargin_ = show;
357 }
358
getShowPageMargin() const359 bool OveSong::getShowPageMargin() const {
360 return showPageMargin_;
361 }
362
setShowTransposeTrack(bool show)363 void OveSong::setShowTransposeTrack(bool show) {
364 showTransposeTrack = show;
365 }
366
getShowTransposeTrack() const367 bool OveSong::getShowTransposeTrack() const {
368 return showTransposeTrack;
369 }
370
setShowLineBreak(bool show)371 void OveSong::setShowLineBreak(bool show) {
372 showLineBreak_ = show;
373 }
374
getShowLineBreak() const375 bool OveSong::getShowLineBreak() const {
376 return showLineBreak_;
377 }
378
setShowRuler(bool show)379 void OveSong::setShowRuler(bool show) {
380 showRuler_ = show;
381 }
382
getShowRuler() const383 bool OveSong::getShowRuler() const {
384 return showRuler_;
385 }
386
setShowColor(bool show)387 void OveSong::setShowColor(bool show) {
388 showColor_ = show;
389 }
390
getShowColor() const391 bool OveSong::getShowColor() const {
392 return showColor_;
393 }
394
setPlayRepeat(bool play)395 void OveSong::setPlayRepeat(bool play) {
396 playRepeat_ = play;
397 }
398
getPlayRepeat() const399 bool OveSong::getPlayRepeat() const {
400 return playRepeat_;
401 }
402
setPlayStyle(PlayStyle style)403 void OveSong::setPlayStyle(PlayStyle style) {
404 playStyle_ = style;
405 }
406
getPlayStyle() const407 OveSong::PlayStyle OveSong::getPlayStyle() const {
408 return playStyle_;
409 }
410
addTitle(const QString & str)411 void OveSong::addTitle(const QString& str) {
412 titles_.push_back(str);
413 }
414
getTitles(void) const415 QList<QString> OveSong::getTitles(void) const {
416 return titles_;
417 }
418
addAnnotate(const QString & str)419 void OveSong::addAnnotate(const QString& str) {
420 annotates_.push_back(str);
421 }
422
getAnnotates(void) const423 QList<QString> OveSong::getAnnotates(void) const {
424 return annotates_;
425 }
426
addWriter(const QString & str)427 void OveSong::addWriter(const QString& str) {
428 writers_.push_back(str);
429 }
430
getWriters(void) const431 QList<QString> OveSong::getWriters(void) const {
432 return writers_;
433 }
434
addCopyright(const QString & str)435 void OveSong::addCopyright(const QString& str) {
436 copyrights_.push_back(str);
437 }
438
getCopyrights(void) const439 QList<QString> OveSong::getCopyrights(void) const {
440 return copyrights_;
441 }
442
addHeader(const QString & str)443 void OveSong::addHeader(const QString& str) {
444 headers_.push_back(str);
445 }
446
getHeaders(void) const447 QList<QString> OveSong::getHeaders(void) const {
448 return headers_;
449 }
450
addFooter(const QString & str)451 void OveSong::addFooter(const QString& str) {
452 footers_.push_back(str);
453 }
454
getFooters(void) const455 QList<QString> OveSong::getFooters(void) const {
456 return footers_;
457 }
458
addTrack(Track * ptr)459 void OveSong::addTrack(Track* ptr) {
460 tracks_.push_back(ptr);
461 }
462
getTrackCount(void) const463 int OveSong::getTrackCount(void) const {
464 return tracks_.size();
465 }
466
getTracks() const467 QList<Track*> OveSong::getTracks() const {
468 return tracks_;
469 }
470
setTrackBarCount(int count)471 void OveSong::setTrackBarCount(int count) {
472 trackBarCount_ = count;
473 }
474
getTrackBarCount() const475 int OveSong::getTrackBarCount() const {
476 return trackBarCount_;
477 }
478
getTrack(int part,int staff) const479 Track* OveSong::getTrack(int part, int staff) const {
480 int trackId = partStaffToTrack(part, staff);
481
482 if( trackId >=0 && trackId < (int)tracks_.size() ) {
483 return tracks_[trackId];
484 }
485
486 return 0;
487 }
488
addPage(Page * page)489 bool OveSong::addPage(Page* page) {
490 pages_.push_back(page);
491 return true;
492 }
493
getPageCount() const494 int OveSong::getPageCount() const {
495 return pages_.size();
496 }
497
getPage(int idx)498 Page* OveSong::getPage(int idx) {
499 if( idx>=0 && idx<(int)pages_.size() ) {
500 return pages_[idx];
501 }
502
503 return 0;
504 }
505
addLine(Line * ptr)506 void OveSong::addLine(Line* ptr) {
507 lines_.push_back(ptr);
508 }
509
getLineCount() const510 int OveSong::getLineCount() const {
511 return lines_.size();
512 }
513
getLine(int idx) const514 Line* OveSong::getLine(int idx) const {
515 if( idx >=0 && idx<(int)lines_.size() ) {
516 return lines_[idx];
517 }
518
519 return 0;
520 }
521
addMeasure(Measure * ptr)522 void OveSong::addMeasure(Measure* ptr) {
523 measures_.push_back(ptr);
524 }
525
getMeasureCount(void) const526 int OveSong::getMeasureCount(void) const {
527 return measures_.size();
528 }
529
getMeasure(int bar) const530 Measure* OveSong::getMeasure(int bar) const {
531 if( bar >= 0 && bar < (int)measures_.size() ) {
532 return measures_[bar];
533 }
534
535 return 0;
536 }
537
addMeasureData(MeasureData * ptr)538 void OveSong::addMeasureData(MeasureData* ptr) {
539 measureDatas_.push_back(ptr);
540 }
541
getMeasureDataCount(void) const542 int OveSong::getMeasureDataCount(void) const {
543 return measureDatas_.size();
544 }
545
getMeasureData(int part,int staff,int bar) const546 MeasureData* OveSong::getMeasureData(int part, int staff/*=0*/, int bar) const {
547 int trackId = partStaffToTrack(part, staff);
548 int trackBarCount = getTrackBarCount();
549
550 if( bar >= 0 && bar < trackBarCount ) {
551 int measureId = trackBarCount * trackId + bar;
552
553 if( measureId >=0 && measureId < (int)measureDatas_.size() ) {
554 return measureDatas_[measureId];
555 }
556 }
557
558 return 0;
559 }
560
getMeasureData(int track,int bar) const561 MeasureData* OveSong::getMeasureData(int track, int bar) const {
562 int id = trackBarCount_*track + bar;
563
564 if( id >=0 && id < (int)measureDatas_.size() ) {
565 return measureDatas_[id];
566 }
567
568 return 0;
569 }
570
setPartStaffCounts(const QList<int> & partStaffCounts)571 void OveSong::setPartStaffCounts(const QList<int>& partStaffCounts) {
572 //partStaffCounts_.assign(partStaffCounts.begin(), partStaffCounts.end());
573 for(int i=0; i<partStaffCounts.size(); ++i) {
574 partStaffCounts_.push_back(partStaffCounts[i]);
575 }
576 }
577
getPartCount() const578 int OveSong::getPartCount() const {
579 return partStaffCounts_.size();
580 }
581
getStaffCount(int part) const582 int OveSong::getStaffCount(int part) const {
583 if( part>=0 && part<(int)partStaffCounts_.size() ) {
584 return partStaffCounts_[part];
585 }
586
587 return 0;
588 }
589
getPartBarCount() const590 int OveSong::getPartBarCount() const {
591 return measureDatas_.size() / tracks_.size();
592 }
593
trackToPartStaff(int track) const594 QPair<int, int> OveSong::trackToPartStaff(int track) const {
595 int i;
596 int staffCount = 0;
597
598 for( i=0; i<partStaffCounts_.size(); ++i ) {
599 if( staffCount + partStaffCounts_[i] > track ) {
600 return qMakePair((int)i, track-staffCount);
601 }
602
603 staffCount += partStaffCounts_[i];
604 }
605
606 return qMakePair((int)partStaffCounts_.size(), 0);
607 }
608
partStaffToTrack(int part,int staff) const609 int OveSong::partStaffToTrack(int part, int staff) const {
610 int i;
611 unsigned int staffCount = 0;
612
613 for( i=0; i<partStaffCounts_.size(); ++i ) {
614 if( part == (int)i && staff>=0 && staff<(int)partStaffCounts_[i] ) {
615 int trackId = staffCount + staff;
616
617 if( trackId >=0 && trackId < (int)tracks_.size() ) {
618 return trackId;
619 }
620 }
621
622 staffCount += partStaffCounts_[i];
623 }
624
625 return tracks_.size();
626 }
627
setTextCodecName(const QString & codecName)628 void OveSong::setTextCodecName(const QString& codecName) {
629 codec_ = QTextCodec::codecForName(codecName.toLatin1());
630 }
631
getCodecString(const QByteArray & text)632 QString OveSong::getCodecString(const QByteArray& text) {
633 QString s;
634 if (codec_ == NULL)
635 s = QString(text);
636 else
637 s = codec_->toUnicode(text);
638
639 s = s.trimmed();
640 return s;
641 }
642
clear(void)643 void OveSong::clear(void)
644 {
645 version4_ = true;
646 quarter_ = 480;
647 showPageMargin_ = false;
648 showTransposeTrack = false;
649 showLineBreak_ = false;
650 showRuler_ = false;
651 showColor_ = true;
652 playRepeat_ = true;
653 playStyle_ = PlayStyle::Record;
654
655 annotates_.clear();
656 copyrights_.clear();
657 footers_.clear();
658 headers_.clear();
659 titles_.clear();
660 writers_.clear();
661
662 // deleteVector(tracks_);
663 for(int i=0; i<tracks_.size(); ++i){
664 delete tracks_[i];
665 }
666 for(int i=0; i<pages_.size(); ++i){
667 delete pages_[i];
668 }
669 for(int i=0; i<lines_.size(); ++i){
670 delete lines_[i];
671 }
672 for(int i=0; i<measures_.size(); ++i){
673 delete measures_[i];
674 }
675 for(int i=0; i<measureDatas_.size(); ++i){
676 delete measureDatas_[i];
677 }
678 tracks_.clear();
679 pages_.clear();
680 lines_.clear();
681 measures_.clear();
682 measureDatas_.clear();
683 trackBarCount_ = 0;
684 partStaffCounts_.clear();
685 }
686
687 ///////////////////////////////////////////////////////////////////////////////
Voice()688 Voice::Voice() {
689 channel_ = 0;
690 volume_ = -1;
691 pitchShift_ = 0;
692 pan_ = 0;
693 patch_ = 0;
694 stemType_ = 0;
695 }
696
setChannel(int channel)697 void Voice::setChannel(int channel) {
698 channel_ = channel;
699 }
700
getChannel() const701 int Voice::getChannel() const {
702 return channel_;
703 }
704
setVolume(int volume)705 void Voice::setVolume(int volume) {
706 volume_ = volume;
707 }
708
getVolume() const709 int Voice::getVolume() const {
710 return volume_;
711 }
712
setPitchShift(int pitchShift)713 void Voice::setPitchShift(int pitchShift) {
714 pitchShift_ = pitchShift;
715 }
716
getPitchShift() const717 int Voice::getPitchShift() const {
718 return pitchShift_;
719 }
720
setPan(int pan)721 void Voice::setPan(int pan) {
722 pan_ = pan;
723 }
724
getPan() const725 int Voice::getPan() const {
726 return pan_;
727 }
728
setPatch(int patch)729 void Voice::setPatch(int patch) {
730 patch_ = patch;
731 }
732
getPatch() const733 int Voice::getPatch() const {
734 return patch_;
735 }
736
setStemType(int stemType)737 void Voice::setStemType(int stemType) {
738 stemType_ = stemType;
739 }
740
getStemType() const741 int Voice::getStemType() const {
742 return stemType_;
743 }
744
getDefaultPatch()745 int Voice::getDefaultPatch() {
746 return -1;
747 }
748
getDefaultVolume()749 int Voice::getDefaultVolume() {
750 return -1;
751 }
752
753 ///////////////////////////////////////////////////////////////////////////////
Track()754 Track::Track() {
755 clear();
756 }
757
~Track()758 Track::~Track() {
759 clear();
760 }
761
setName(const QString & str)762 void Track::setName(const QString& str) {
763 name_ = str;
764 }
765
getName(void) const766 QString Track::getName(void) const {
767 return name_;
768 }
769
setBriefName(const QString & str)770 void Track::setBriefName(const QString& str) {
771 briefName_ = str;
772 }
773
getBriefName(void) const774 QString Track::getBriefName(void) const {
775 return briefName_;
776 }
777
setPatch(unsigned int patch)778 void Track::setPatch(unsigned int patch) {
779 patch_ = patch;
780 }
781
getPatch() const782 unsigned int Track::getPatch() const {
783 return patch_;
784 }
785
setChannel(int channel)786 void Track::setChannel(int channel) {
787 channel_ = channel;
788 }
789
getChannel() const790 int Track::getChannel() const {
791 return channel_;
792 }
793
setShowName(bool show)794 void Track::setShowName(bool show) {
795 showName_ = show;
796 }
797
getShowName() const798 bool Track::getShowName() const {
799 return showName_;
800 }
801
setShowBriefName(bool show)802 void Track::setShowBriefName(bool show) {
803 showBriefName_ = show;
804 }
805
getShowBriefName() const806 bool Track::getShowBriefName() const {
807 return showBriefName_;
808 }
809
setMute(bool mute)810 void Track::setMute(bool mute) {
811 mute_ = mute;
812 }
813
getMute() const814 bool Track::getMute() const {
815 return mute_;
816 }
817
setSolo(bool solo)818 void Track::setSolo(bool solo) {
819 solo_ = solo;
820 }
821
getSolo() const822 bool Track::getSolo() const {
823 return solo_;
824 }
825
setShowKeyEachLine(bool show)826 void Track::setShowKeyEachLine(bool show) {
827 showKeyEachLine_ = show;
828 }
829
getShowKeyEachLine() const830 bool Track::getShowKeyEachLine() const {
831 return showKeyEachLine_;
832 }
833
setVoiceCount(int voices)834 void Track::setVoiceCount(int voices) {
835 voiceCount_ = voices;
836 }
837
getVoiceCount() const838 int Track::getVoiceCount() const {
839 return voiceCount_;
840 }
841
addVoice(Voice * voice)842 void Track::addVoice(Voice* voice) {
843 voices_.push_back(voice);
844 }
845
getVoices() const846 QList<Voice*> Track::getVoices() const {
847 return voices_;
848 }
849
setShowTranspose(bool show)850 void Track::setShowTranspose(bool show) {
851 showTranspose_ = show;
852 }
853
getShowTranspose() const854 bool Track::getShowTranspose() const {
855 return showTranspose_;
856 }
857
setTranspose(int transpose)858 void Track::setTranspose(int transpose) {
859 transpose_ = transpose;
860 }
861
getTranspose() const862 int Track::getTranspose() const {
863 return transpose_;
864 }
865
setNoteShift(int shift)866 void Track::setNoteShift(int shift) {
867 noteShift_ = shift;
868 }
869
getNoteShift() const870 int Track::getNoteShift() const {
871 return noteShift_;
872 }
873
setStartClef(int clef)874 void Track::setStartClef(int clef/*in Clef*/) {
875 startClef_ = ClefType(clef);
876 }
877
getStartClef() const878 ClefType Track::getStartClef() const {
879 return startClef_;
880 }
881
setTransposeClef(int clef)882 void Track::setTransposeClef(int clef) {
883 transposeClef_ = ClefType(clef);
884 }
885
getTansposeClef() const886 ClefType Track::getTansposeClef() const {
887 return transposeClef_;
888 }
889
setStartKey(int key)890 void Track::setStartKey(int key) {
891 startKey_ = key;
892 }
893
getStartKey() const894 int Track::getStartKey() const {
895 return startKey_;
896 }
897
setDisplayPercent(unsigned int percent)898 void Track::setDisplayPercent(unsigned int percent/*25~100?*/) {
899 displayPercent_ = percent;
900 }
901
getDisplayPercent() const902 unsigned int Track::getDisplayPercent() const {
903 return displayPercent_;
904 }
905
setShowLegerLine(bool show)906 void Track::setShowLegerLine(bool show) {
907 showLegerLine_ = show;
908 }
909
getShowLegerLine() const910 bool Track::getShowLegerLine() const {
911 return showLegerLine_;
912 }
913
setShowClef(bool show)914 void Track::setShowClef(bool show) {
915 showClef_ = show;
916 }
917
getShowClef() const918 bool Track::getShowClef() const {
919 return showClef_;
920 }
921
setShowTimeSignature(bool show)922 void Track::setShowTimeSignature(bool show) {
923 showTimeSignature_ = show;
924 }
925
getShowTimeSignature() const926 bool Track::getShowTimeSignature() const {
927 return showTimeSignature_;
928 }
929
setShowKeySignature(bool show)930 void Track::setShowKeySignature(bool show) {
931 showKeySignature_ = show;
932 }
933
getShowKeySignature() const934 bool Track::getShowKeySignature() const {
935 return showKeySignature_;
936 }
937
setShowBarline(bool show)938 void Track::setShowBarline(bool show) {
939 showBarline_ = show;
940 }
941
getShowBarline() const942 bool Track::getShowBarline() const {
943 return showBarline_;
944 }
945
setFillWithRest(bool fill)946 void Track::setFillWithRest(bool fill) {
947 fillWithRest_ = fill;
948 }
949
getFillWithRest() const950 bool Track::getFillWithRest() const {
951 return fillWithRest_;
952 }
953
setFlatTail(bool flat)954 void Track::setFlatTail(bool flat) {
955 flatTail_ = flat;
956 }
957
getFlatTail() const958 bool Track::getFlatTail() const {
959 return flatTail_;
960 }
961
setShowClefEachLine(bool show)962 void Track::setShowClefEachLine(bool show) {
963 showClefEachLine_ = show;
964 }
965
getShowClefEachLine() const966 bool Track::getShowClefEachLine() const {
967 return showClefEachLine_;
968 }
969
addDrum(const DrumNode & node)970 void Track::addDrum(const DrumNode& node) {
971 /*DrumNode node;
972 node.line_ = line;
973 node.headType_ = headType;
974 node.pitch_ = pitch;
975 node.voice_ = voice;*/
976 drumKit_.push_back(node);
977 }
978
getDrumKit() const979 QList<Track::DrumNode> Track::getDrumKit() const {
980 return drumKit_;
981 }
982
setPart(int part)983 void Track::setPart(int part) {
984 part_ = part;
985 }
986
getPart() const987 int Track::getPart() const {
988 return part_;
989 }
990
clear(void)991 void Track::clear(void) {
992 number_ = 0;
993
994 name_ = QString();
995
996 patch_ = 0;
997 channel_ = 0;
998 transpose_ = 0;
999 showTranspose_ = false;
1000 noteShift_ = 0;
1001 startClef_ = ClefType::Treble;
1002 transposeClef_ = ClefType::Treble;
1003 displayPercent_ = 100;
1004 startKey_ = 0;
1005 voiceCount_ = 8;
1006
1007 showName_ = true;
1008 showBriefName_ = false;
1009 showKeyEachLine_ = false;
1010 showLegerLine_ = true;
1011 showClef_ = true;
1012 showTimeSignature_ = true;
1013 showKeySignature_ = true;
1014 showBarline_ = true;
1015 showClefEachLine_ = false;
1016
1017 fillWithRest_ = true;
1018 flatTail_ = false;
1019
1020 mute_ = false;
1021 solo_ = false;
1022
1023 drumKit_.clear();
1024
1025 part_ = 0;
1026
1027 for(int i=0; i<voices_.size(); ++i){
1028 delete voices_[i];
1029 }
1030 voices_.clear();
1031 }
1032
1033 ///////////////////////////////////////////////////////////////////////////////
Page()1034 Page::Page() {
1035 beginLine_ = 0;
1036 lineCount_ = 0;
1037
1038 lineInterval_ = 9;
1039 staffInterval_ = 7;
1040 staffInlineInterval_ = 6;
1041
1042 lineBarCount_ = 4;
1043 pageLineCount_ = 5;
1044
1045 leftMargin_ = 0xA8;
1046 topMargin_ = 0xA8;
1047 rightMargin_ = 0xA8;
1048 bottomMargin_ = 0xA8;
1049
1050 pageWidth_ = 0x0B40;
1051 pageHeight_ = 0x0E90;
1052 }
1053
setBeginLine(int line)1054 void Page::setBeginLine(int line) {
1055 beginLine_ = line;
1056 }
1057
getBeginLine() const1058 int Page::getBeginLine() const {
1059 return beginLine_;
1060 }
1061
setLineCount(int count)1062 void Page::setLineCount(int count) {
1063 lineCount_ = count;
1064 }
1065
getLineCount() const1066 int Page::getLineCount() const {
1067 return lineCount_;
1068 }
1069
setLineInterval(int interval)1070 void Page::setLineInterval(int interval) {
1071 lineInterval_ = interval;
1072 }
1073
getLineInterval() const1074 int Page::getLineInterval() const {
1075 return lineInterval_;
1076 }
1077
setStaffInterval(int interval)1078 void Page::setStaffInterval(int interval) {
1079 staffInterval_ = interval;
1080 }
1081
getStaffInterval() const1082 int Page::getStaffInterval() const {
1083 return staffInterval_;
1084 }
1085
setStaffInlineInterval(int interval)1086 void Page::setStaffInlineInterval(int interval) {
1087 staffInlineInterval_ = interval;
1088 }
1089
getStaffInlineInterval() const1090 int Page::getStaffInlineInterval() const {
1091 return staffInlineInterval_;
1092 }
1093
setLineBarCount(int count)1094 void Page::setLineBarCount(int count) {
1095 lineBarCount_ = count;
1096 }
1097
getLineBarCount() const1098 int Page::getLineBarCount() const {
1099 return lineBarCount_;
1100 }
1101
setPageLineCount(int count)1102 void Page::setPageLineCount(int count) {
1103 pageLineCount_ = count;
1104 }
1105
getPageLineCount() const1106 int Page::getPageLineCount() const {
1107 return pageLineCount_;
1108 }
1109
setLeftMargin(int margin)1110 void Page::setLeftMargin(int margin) {
1111 leftMargin_ = margin;
1112 }
1113
getLeftMargin() const1114 int Page::getLeftMargin() const {
1115 return leftMargin_;
1116 }
1117
setTopMargin(int margin)1118 void Page::setTopMargin(int margin) {
1119 topMargin_ = margin;
1120 }
1121
getTopMargin() const1122 int Page::getTopMargin() const {
1123 return topMargin_;
1124 }
1125
setRightMargin(int margin)1126 void Page::setRightMargin(int margin) {
1127 rightMargin_ = margin;
1128 }
1129
getRightMargin() const1130 int Page::getRightMargin() const {
1131 return rightMargin_;
1132 }
1133
setBottomMargin(int margin)1134 void Page::setBottomMargin(int margin) {
1135 bottomMargin_ = margin;
1136 }
1137
getBottomMargin() const1138 int Page::getBottomMargin() const {
1139 return bottomMargin_;
1140 }
1141
setPageWidth(int width)1142 void Page::setPageWidth(int width) {
1143 pageWidth_ = width;
1144 }
1145
getPageWidth() const1146 int Page::getPageWidth() const {
1147 return pageWidth_;
1148 }
1149
setPageHeight(int height)1150 void Page::setPageHeight(int height) {
1151 pageHeight_ = height;
1152 }
1153
getPageHeight() const1154 int Page::getPageHeight() const {
1155 return pageHeight_;
1156 }
1157
1158 ///////////////////////////////////////////////////////////////////////////////
Line()1159 Line::Line() {
1160 beginBar_ = 0;
1161 barCount_ = 0;
1162 yOffset_ = 0;
1163 leftXOffset_ = 0;
1164 rightXOffset_ = 0;
1165 }
1166
~Line()1167 Line::~Line() {
1168 for(int i=0; i<staves_.size(); ++i) {
1169 delete staves_[i];
1170 }
1171 staves_.clear();
1172 }
1173
addStaff(Staff * staff)1174 void Line::addStaff(Staff* staff) {
1175 staves_.push_back(staff);
1176 }
1177
getStaffCount() const1178 int Line::getStaffCount() const {
1179 return staves_.size();
1180 }
1181
getStaff(int idx) const1182 Staff* Line::getStaff(int idx) const {
1183 if (idx >= 0 && idx < static_cast<int>(staves_.size())) {
1184 return staves_[idx];
1185 }
1186
1187 return 0;
1188 }
1189
setBeginBar(unsigned int bar)1190 void Line::setBeginBar(unsigned int bar) {
1191 beginBar_ = bar;
1192 }
1193
getBeginBar() const1194 unsigned int Line::getBeginBar() const {
1195 return beginBar_;
1196 }
1197
setBarCount(unsigned int count)1198 void Line::setBarCount(unsigned int count) {
1199 barCount_ = count;
1200 }
1201
getBarCount() const1202 unsigned int Line::getBarCount() const {
1203 return barCount_;
1204 }
1205
setYOffset(int offset)1206 void Line::setYOffset(int offset) {
1207 yOffset_ = offset;
1208 }
1209
getYOffset() const1210 int Line::getYOffset() const {
1211 return yOffset_;
1212 }
1213
setLeftXOffset(int offset)1214 void Line::setLeftXOffset(int offset) {
1215 leftXOffset_ = offset;
1216 }
1217
getLeftXOffset() const1218 int Line::getLeftXOffset() const {
1219 return leftXOffset_;
1220 }
1221
setRightXOffset(int offset)1222 void Line::setRightXOffset(int offset) {
1223 rightXOffset_ = offset;
1224 }
1225
getRightXOffset() const1226 int Line::getRightXOffset() const {
1227 return rightXOffset_;
1228 }
1229
1230 ///////////////////////////////////////////////////////////////////////////////
Staff()1231 Staff::Staff() {
1232 clef_ = ClefType::Treble;
1233 key_ = 0;
1234 visible_ = true;
1235 groupType_ = GroupType::None;
1236 groupStaffCount_ = 0;
1237 }
1238
setClefType(int clef)1239 void Staff::setClefType(int clef) {
1240 clef_ = (ClefType) clef;
1241 }
1242
getClefType() const1243 ClefType Staff::getClefType() const {
1244 return clef_;
1245 }
1246
setKeyType(int key)1247 void Staff::setKeyType(int key) {
1248 key_ = key;
1249 }
1250
getKeyType() const1251 int Staff::getKeyType() const {
1252 return key_;
1253 }
1254
setVisible(bool visible)1255 void Staff::setVisible(bool visible) {
1256 visible_ = visible;
1257 }
1258
setVisible() const1259 bool Staff::setVisible() const {
1260 return visible_;
1261 }
1262
setGroupType(GroupType type)1263 void Staff::setGroupType(GroupType type){
1264 groupType_ = type;
1265 }
1266
getGroupType() const1267 GroupType Staff::getGroupType() const {
1268 return groupType_;
1269 }
1270
setGroupStaffCount(int count)1271 void Staff::setGroupStaffCount(int count) {
1272 groupStaffCount_ = count;
1273 }
1274
getGroupStaffCount() const1275 int Staff::getGroupStaffCount() const {
1276 return groupStaffCount_;
1277 }
1278
1279 ///////////////////////////////////////////////////////////////////////////////
Note()1280 Note::Note() {
1281 rest_ = false;
1282 note_ = 60;
1283 accidental_ = AccidentalType::Normal;
1284 showAccidental_ = false;
1285 offVelocity_ = 0x40;
1286 onVelocity_ = 0x50;
1287 headType_ = NoteHeadType::Standard;
1288 tiePos_ = TiePos::None;
1289 offsetStaff_ = 0;
1290 show_ = true;
1291 offsetTick_ = 0;
1292 }
1293
setIsRest(bool rest)1294 void Note::setIsRest(bool rest) {
1295 rest_ = rest;
1296 }
1297
getIsRest() const1298 bool Note::getIsRest() const {
1299 return rest_;
1300 }
1301
setNote(unsigned int note)1302 void Note::setNote(unsigned int note) {
1303 note_ = note;
1304 }
1305
getNote() const1306 unsigned int Note::getNote() const {
1307 return note_;
1308 }
1309
setAccidental(int type)1310 void Note::setAccidental(int type) {
1311 accidental_ = (AccidentalType) type;
1312 }
1313
getAccidental() const1314 AccidentalType Note::getAccidental() const {
1315 return accidental_;
1316 }
1317
setShowAccidental(bool show)1318 void Note::setShowAccidental(bool show) {
1319 showAccidental_ = show;
1320 }
1321
getShowAccidental() const1322 bool Note::getShowAccidental() const {
1323 return showAccidental_;
1324 }
1325
setOnVelocity(unsigned int velocity)1326 void Note::setOnVelocity(unsigned int velocity) {
1327 onVelocity_ = velocity;
1328 }
1329
getOnVelocity() const1330 unsigned int Note::getOnVelocity() const {
1331 return onVelocity_;
1332 }
1333
setOffVelocity(unsigned int velocity)1334 void Note::setOffVelocity(unsigned int velocity) {
1335 offVelocity_ = velocity;
1336 }
1337
getOffVelocity() const1338 unsigned int Note::getOffVelocity() const {
1339 return offVelocity_;
1340 }
1341
setHeadType(int type)1342 void Note::setHeadType(int type) {
1343 headType_ = (NoteHeadType) type;
1344 }
1345
getHeadType() const1346 NoteHeadType Note::getHeadType() const {
1347 return headType_;
1348 }
1349
setTiePos(int tiePos)1350 void Note::setTiePos(int tiePos) {
1351 tiePos_ = (TiePos) tiePos;
1352 }
1353
getTiePos() const1354 TiePos Note::getTiePos() const {
1355 return tiePos_;
1356 }
1357
setOffsetStaff(int offset)1358 void Note::setOffsetStaff(int offset) {
1359 offsetStaff_ = offset;
1360 }
1361
getOffsetStaff() const1362 int Note::getOffsetStaff() const {
1363 return offsetStaff_;
1364 }
1365
setShow(bool show)1366 void Note::setShow(bool show) {
1367 show_ = show;
1368 }
1369
getShow() const1370 bool Note::getShow() const {
1371 return show_;
1372 }
1373
setOffsetTick(int offset)1374 void Note::setOffsetTick(int offset) {
1375 offsetTick_ = offset;
1376 }
1377
getOffsetTick() const1378 int Note::getOffsetTick() const {
1379 return offsetTick_;
1380 }
1381
1382 ///////////////////////////////////////////////////////////////////////////////
Articulation()1383 Articulation::Articulation() {
1384 type_ = ArticulationType::Marcato;
1385 above_ = true;
1386
1387 changeSoundEffect_ = false;
1388 changeLength_ = false;
1389 changeVelocity_ = false;
1390 changeExtraLength_ = false;
1391
1392 soundEffect_ = qMakePair(0, 0);
1393 lengthPercentage_ = 100;
1394 velocityType_ = VelocityType::Offset;
1395 velocityValue_ = 0;
1396 extraLength_ = 0;
1397
1398 trillNoteLength_ = 60;
1399 trillRate_ = NoteType::Note_Sixteen;
1400 accelerateType_ = AccelerateType::None;
1401 auxiliaryFirst_ = false;
1402 trillInterval_ = TrillInterval::Chromatic;
1403 }
1404
setArtType(int type)1405 void Articulation::setArtType(int type) {
1406 type_ = (ArticulationType) type;
1407 }
1408
getArtType() const1409 ArticulationType Articulation::getArtType() const {
1410 return type_;
1411 }
1412
setPlacementAbove(bool above)1413 void Articulation::setPlacementAbove(bool above) {
1414 above_ = above;
1415 }
1416
getPlacementAbove() const1417 bool Articulation::getPlacementAbove() const {
1418 return above_;
1419 }
1420
getChangeSoundEffect() const1421 bool Articulation::getChangeSoundEffect() const {
1422 return changeSoundEffect_;
1423 }
1424
setSoundEffect(int soundFrom,int soundTo)1425 void Articulation::setSoundEffect(int soundFrom, int soundTo) {
1426 soundEffect_ = qMakePair(soundFrom, soundTo);
1427 changeSoundEffect_ = true;
1428 }
1429
getSoundEffect() const1430 QPair<int, int> Articulation::getSoundEffect() const {
1431 return soundEffect_;
1432 }
1433
getChangeLength() const1434 bool Articulation::getChangeLength() const {
1435 return changeLength_;
1436 }
1437
setLengthPercentage(int percentage)1438 void Articulation::setLengthPercentage(int percentage) {
1439 lengthPercentage_ = percentage;
1440 changeLength_ = true;
1441 }
1442
getLengthPercentage() const1443 int Articulation::getLengthPercentage() const {
1444 return lengthPercentage_;
1445 }
1446
getChangeVelocity() const1447 bool Articulation::getChangeVelocity() const {
1448 return changeVelocity_;
1449 }
1450
setVelocityType(VelocityType type)1451 void Articulation::setVelocityType(VelocityType type) {
1452 velocityType_ = type;
1453 changeVelocity_ = true;
1454 }
1455
getVelocityType() const1456 Articulation::VelocityType Articulation::getVelocityType() const {
1457 return velocityType_;
1458 }
1459
setVelocityValue(int value)1460 void Articulation::setVelocityValue(int value) {
1461 velocityValue_ = value;
1462 }
1463
getVelocityValue() const1464 int Articulation::getVelocityValue() const {
1465 return velocityValue_;
1466 }
1467
getChangeExtraLength() const1468 bool Articulation::getChangeExtraLength() const {
1469 return changeExtraLength_;
1470 }
1471
setExtraLength(int length)1472 void Articulation::setExtraLength(int length) {
1473 extraLength_ = length;
1474 changeExtraLength_ = true;
1475 }
1476
getExtraLength() const1477 int Articulation::getExtraLength() const {
1478 return extraLength_;
1479 }
1480
setTrillNoteLength(int length)1481 void Articulation::setTrillNoteLength(int length) {
1482 trillNoteLength_ = length;
1483 }
1484
getTrillNoteLength() const1485 int Articulation::getTrillNoteLength() const {
1486 return trillNoteLength_;
1487 }
1488
setTrillRate(NoteType rate)1489 void Articulation::setTrillRate(NoteType rate) {
1490 trillRate_ = rate;
1491 }
1492
getTrillRate() const1493 NoteType Articulation::getTrillRate() const {
1494 return trillRate_;
1495 }
1496
setAccelerateType(int type)1497 void Articulation::setAccelerateType(int type) {
1498 accelerateType_ = (AccelerateType) type;
1499 }
1500
getAccelerateType() const1501 Articulation::AccelerateType Articulation::getAccelerateType() const {
1502 return accelerateType_;
1503 }
1504
setAuxiliaryFirst(bool first)1505 void Articulation::setAuxiliaryFirst(bool first) {
1506 auxiliaryFirst_ = first;
1507 }
1508
getAuxiliaryFirst() const1509 bool Articulation::getAuxiliaryFirst() const {
1510 return auxiliaryFirst_;
1511 }
1512
setTrillInterval(int interval)1513 void Articulation::setTrillInterval(int interval) {
1514 trillInterval_ = (TrillInterval) interval;
1515 }
1516
getTrillInterval() const1517 Articulation::TrillInterval Articulation::getTrillInterval() const {
1518 return trillInterval_;
1519 }
1520
willAffectNotes() const1521 bool Articulation::willAffectNotes() const {
1522 bool affect = false;
1523
1524 switch (getArtType()) {
1525 case ArticulationType::Major_Trill:
1526 case ArticulationType::Minor_Trill:
1527 case ArticulationType::Trill_Section:
1528 case ArticulationType::Inverted_Short_Mordent:
1529 case ArticulationType::Inverted_Long_Mordent:
1530 case ArticulationType::Short_Mordent:
1531 case ArticulationType::Turn:
1532
1533 case ArticulationType::Arpeggio:
1534 case ArticulationType::Tremolo_Eighth:
1535 case ArticulationType::Tremolo_Sixteenth:
1536 case ArticulationType::Tremolo_Thirty_Second:
1537 case ArticulationType::Tremolo_Sixty_Fourth: {
1538 affect = true;
1539 break;
1540 }
1541 case ArticulationType::Finger_1:
1542 case ArticulationType::Finger_2:
1543 case ArticulationType::Finger_3:
1544 case ArticulationType::Finger_4:
1545 case ArticulationType::Finger_5:
1546 case ArticulationType::Flat_Accidental_For_Trill:
1547 case ArticulationType::Sharp_Accidental_For_Trill:
1548 case ArticulationType::Natural_Accidental_For_Trill:
1549 case ArticulationType::Marcato:
1550 case ArticulationType::Marcato_Dot:
1551 case ArticulationType::Heavy_Attack:
1552 case ArticulationType::SForzando:
1553 case ArticulationType::SForzando_Dot:
1554 case ArticulationType::Heavier_Attack:
1555 case ArticulationType::SForzando_Inverted:
1556 case ArticulationType::SForzando_Dot_Inverted:
1557 case ArticulationType::Staccatissimo:
1558 case ArticulationType::Staccato:
1559 case ArticulationType::Tenuto:
1560 case ArticulationType::Up_Bow:
1561 case ArticulationType::Down_Bow:
1562 case ArticulationType::Up_Bow_Inverted:
1563 case ArticulationType::Down_Bow_Inverted:
1564 case ArticulationType::Natural_Harmonic:
1565 case ArticulationType::Artificial_Harmonic:
1566 case ArticulationType::Plus_Sign:
1567 case ArticulationType::Fermata:
1568 case ArticulationType::Fermata_Inverted:
1569 case ArticulationType::Pedal_Down:
1570 case ArticulationType::Pedal_Up:
1571 case ArticulationType::Pause:
1572 case ArticulationType::Grand_Pause:
1573 case ArticulationType::Toe_Pedal:
1574 case ArticulationType::Heel_Pedal:
1575 case ArticulationType::Toe_To_Heel_Pedal:
1576 case ArticulationType::Heel_To_Toe_Pedal:
1577 case ArticulationType::Open_String:
1578 case ArticulationType::Guitar_Lift:
1579 case ArticulationType::Guitar_Slide_Up:
1580 case ArticulationType::Guitar_Rip:
1581 case ArticulationType::Guitar_Fall_Off:
1582 case ArticulationType::Guitar_Slide_Down:
1583 case ArticulationType::Guitar_Spill:
1584 case ArticulationType::Guitar_Flip:
1585 case ArticulationType::Guitar_Smear:
1586 case ArticulationType::Guitar_Bend:
1587 case ArticulationType::Guitar_Doit:
1588 case ArticulationType::Guitar_Plop:
1589 case ArticulationType::Guitar_Wow_Wow:
1590 case ArticulationType::Guitar_Thumb:
1591 case ArticulationType::Guitar_Index_Finger:
1592 case ArticulationType::Guitar_Middle_Finger:
1593 case ArticulationType::Guitar_Ring_Finger:
1594 case ArticulationType::Guitar_Pinky_Finger:
1595 case ArticulationType::Guitar_Tap:
1596 case ArticulationType::Guitar_Hammer:
1597 case ArticulationType::Guitar_Pluck: {
1598 break;
1599 }
1600 default:
1601 break;
1602 }
1603
1604 return affect;
1605 }
1606
isTrill(ArticulationType type)1607 bool Articulation::isTrill(ArticulationType type) {
1608 bool isTrill = false;
1609
1610 switch (type) {
1611 case ArticulationType::Major_Trill:
1612 case ArticulationType::Minor_Trill:
1613 case ArticulationType::Trill_Section: {
1614 isTrill = true;
1615 break;
1616 }
1617 default:
1618 break;
1619 }
1620
1621 return isTrill;
1622 }
1623
getXmlType() const1624 Articulation::XmlType Articulation::getXmlType() const {
1625 XmlType xmlType = XmlType::Unknown;
1626
1627 switch (type_) {
1628 case ArticulationType::Major_Trill:
1629 case ArticulationType::Minor_Trill:
1630 case ArticulationType::Trill_Section:
1631 case ArticulationType::Inverted_Short_Mordent:
1632 case ArticulationType::Inverted_Long_Mordent:
1633 case ArticulationType::Short_Mordent:
1634 case ArticulationType::Turn:
1635 // case ArticulationType::Flat_Accidental_For_Trill :
1636 // case ArticulationType::Sharp_Accidental_For_Trill :
1637 // case ArticulationType::Natural_Accidental_For_Trill :
1638 case ArticulationType::Tremolo_Eighth:
1639 case ArticulationType::Tremolo_Sixteenth:
1640 case ArticulationType::Tremolo_Thirty_Second:
1641 case ArticulationType::Tremolo_Sixty_Fourth: {
1642 xmlType = XmlType::Ornament;
1643 break;
1644 }
1645 case ArticulationType::Marcato:
1646 case ArticulationType::Marcato_Dot:
1647 case ArticulationType::Heavy_Attack:
1648 case ArticulationType::SForzando:
1649 case ArticulationType::SForzando_Inverted:
1650 case ArticulationType::SForzando_Dot:
1651 case ArticulationType::SForzando_Dot_Inverted:
1652 case ArticulationType::Heavier_Attack:
1653 case ArticulationType::Staccatissimo:
1654 case ArticulationType::Staccato:
1655 case ArticulationType::Tenuto:
1656 case ArticulationType::Pause:
1657 case ArticulationType::Grand_Pause: {
1658 xmlType = XmlType::Articulation;
1659 break;
1660 }
1661 case ArticulationType::Up_Bow:
1662 case ArticulationType::Down_Bow:
1663 case ArticulationType::Up_Bow_Inverted:
1664 case ArticulationType::Down_Bow_Inverted:
1665 case ArticulationType::Natural_Harmonic:
1666 case ArticulationType::Artificial_Harmonic:
1667 case ArticulationType::Finger_1:
1668 case ArticulationType::Finger_2:
1669 case ArticulationType::Finger_3:
1670 case ArticulationType::Finger_4:
1671 case ArticulationType::Finger_5:
1672 case ArticulationType::Plus_Sign: {
1673 xmlType = XmlType::Technical;
1674 break;
1675 }
1676 case ArticulationType::Arpeggio: {
1677 xmlType = XmlType::Arpeggiate;
1678 break;
1679 }
1680 case ArticulationType::Fermata:
1681 case ArticulationType::Fermata_Inverted: {
1682 xmlType = XmlType::Fermata;
1683 break;
1684 }
1685 case ArticulationType::Pedal_Down:
1686 case ArticulationType::Pedal_Up: {
1687 xmlType = XmlType::Direction;
1688 break;
1689 }
1690 // case ArticulationType::Toe_Pedal :
1691 // case ArticulationType::Heel_Pedal :
1692 // case ArticulationType::Toe_To_Heel_Pedal :
1693 // case ArticulationType::Heel_To_Toe_Pedal :
1694 // case ArticulationType::Open_String :
1695 default:
1696 break;
1697 }
1698
1699 return xmlType;
1700 }
1701
1702 ///////////////////////////////////////////////////////////////////////////////
NoteContainer()1703 NoteContainer::NoteContainer() {
1704 musicDataType_ = MusicDataType::Note_Container;
1705
1706 grace_ = false;
1707 cue_ = false;
1708 rest_ = false;
1709 raw_ = false;
1710 noteType_ = NoteType::Note_Quarter;
1711 dot_ = 0;
1712 graceNoteType_ = NoteType::Note_Eight;
1713 stemUp_ = true;
1714 showStem_ = true;
1715 stemLength_ = 7;
1716 inBeam_ = false;
1717 tuplet_ = 0;
1718 space_ = 2;//div by 0
1719 noteShift_ = 0;
1720 }
1721
~NoteContainer()1722 NoteContainer::~NoteContainer(){
1723 for(int i=0; i<notes_.size(); ++i){
1724 delete notes_[i];
1725 }
1726 for(int i=0; i<articulations_.size(); ++i){
1727 delete articulations_[i];
1728 }
1729 notes_.clear();
1730 articulations_.clear();
1731 }
1732
setIsGrace(bool grace)1733 void NoteContainer::setIsGrace(bool grace) {
1734 grace_ = grace;
1735 }
1736
getIsGrace() const1737 bool NoteContainer::getIsGrace() const {
1738 return grace_;
1739 }
1740
setIsCue(bool cue)1741 void NoteContainer::setIsCue(bool cue) {
1742 cue_ = cue;
1743 }
1744
getIsCue() const1745 bool NoteContainer::getIsCue() const {
1746 return cue_;
1747 }
1748
setIsRest(bool rest)1749 void NoteContainer::setIsRest(bool rest) {
1750 rest_ = rest;
1751 }
1752
getIsRest() const1753 bool NoteContainer::getIsRest() const {
1754 return rest_;
1755 }
1756
setIsRaw(bool raw)1757 void NoteContainer::setIsRaw(bool raw) {
1758 raw_ = raw;
1759 }
1760
getIsRaw() const1761 bool NoteContainer::getIsRaw() const {
1762 return raw_;
1763 }
1764
setNoteType(NoteType type)1765 void NoteContainer::setNoteType(NoteType type) {
1766 noteType_ = NoteType::Note_Quarter;
1767
1768 switch (type) {
1769 case NoteType::Note_DoubleWhole:
1770 case NoteType::Note_Whole:
1771 case NoteType::Note_Half:
1772 case NoteType::Note_Quarter:
1773 case NoteType::Note_Eight:
1774 case NoteType::Note_Sixteen:
1775 case NoteType::Note_32:
1776 case NoteType::Note_64:
1777 case NoteType::Note_128:
1778 case NoteType::Note_256: {
1779 // case NoteType::Note_512:
1780 // case NoteType::Note_1024: {
1781 noteType_ = type;
1782 break;
1783 }
1784 default: {
1785 break;
1786 }
1787 }
1788 }
1789
getNoteType() const1790 NoteType NoteContainer::getNoteType() const {
1791 return noteType_;
1792 }
1793
setDot(int dot)1794 void NoteContainer::setDot(int dot) {
1795 dot_ = dot;
1796 }
1797
getDot() const1798 int NoteContainer::getDot() const {
1799 return dot_;
1800 }
1801
setGraceNoteType(NoteType type)1802 void NoteContainer::setGraceNoteType(NoteType type) {
1803 graceNoteType_ = type;
1804 }
1805
getGraceNoteType() const1806 NoteType NoteContainer::getGraceNoteType() const {
1807 return graceNoteType_;
1808 }
1809
setInBeam(bool in)1810 void NoteContainer::setInBeam(bool in) {
1811 inBeam_ = in;
1812 }
1813
getInBeam() const1814 bool NoteContainer::getInBeam() const {
1815 return inBeam_;
1816 }
1817
setStemUp(bool up)1818 void NoteContainer::setStemUp(bool up) {
1819 stemUp_ = up;
1820 }
1821
getStemUp(void) const1822 bool NoteContainer::getStemUp(void) const {
1823 return stemUp_;
1824 }
1825
setShowStem(bool show)1826 void NoteContainer::setShowStem(bool show) {
1827 showStem_ = show;
1828 }
1829
getShowStem() const1830 bool NoteContainer::getShowStem() const {
1831 return showStem_;
1832 }
1833
setStemLength(int line)1834 void NoteContainer::setStemLength(int line) {
1835 stemLength_ = line;
1836 }
1837
getStemLength() const1838 int NoteContainer::getStemLength() const {
1839 return stemLength_;
1840 }
1841
setTuplet(int tuplet)1842 void NoteContainer::setTuplet(int tuplet) {
1843 tuplet_ = tuplet;
1844 }
1845
getTuplet() const1846 int NoteContainer::getTuplet() const {
1847 return tuplet_;
1848 }
1849
setSpace(int space)1850 void NoteContainer::setSpace(int space) {
1851 space_ = space;
1852 }
1853
getSpace() const1854 int NoteContainer::getSpace() const {
1855 return space_;
1856 }
1857
addNoteRest(Note * note)1858 void NoteContainer::addNoteRest(Note* note) {
1859 notes_.push_back(note);
1860 }
1861
getNotesRests() const1862 QList<Note*> NoteContainer::getNotesRests() const {
1863 return notes_;
1864 }
1865
addArticulation(Articulation * art)1866 void NoteContainer::addArticulation(Articulation* art) {
1867 articulations_.push_back(art);
1868 }
1869
getArticulations() const1870 QList<Articulation*> NoteContainer::getArticulations() const {
1871 return articulations_;
1872 }
1873
setNoteShift(int octave)1874 void NoteContainer::setNoteShift(int octave) {
1875 noteShift_ = octave;
1876 }
1877
getNoteShift() const1878 int NoteContainer::getNoteShift() const {
1879 return noteShift_;
1880 }
1881
getOffsetStaff() const1882 int NoteContainer::getOffsetStaff() const {
1883 if(getIsRest())
1884 return 0;
1885
1886 int staffMove = 0;
1887 QList<OVE::Note*> notes = getNotesRests();
1888 for (int i = 0; i < notes.size(); ++i) {
1889 OVE::Note* notePtr = notes[i];
1890 staffMove = notePtr->getOffsetStaff();
1891 }
1892
1893 return staffMove;
1894 }
1895
getDuration() const1896 int NoteContainer::getDuration() const {
1897 int duration = static_cast<int>(NoteDuration::D_4);
1898
1899 switch (noteType_) {
1900 case NoteType::Note_DoubleWhole: {
1901 duration = static_cast<int>(NoteDuration::D_Double_Whole);
1902 break;
1903 }
1904 case NoteType::Note_Whole: {
1905 duration = static_cast<int>(NoteDuration::D_Whole);
1906 break;
1907 }
1908 case NoteType::Note_Half: {
1909 duration = static_cast<int>(NoteDuration::D_2);
1910 break;
1911 }
1912 case NoteType::Note_Quarter: {
1913 duration = static_cast<int>(NoteDuration::D_4);
1914 break;
1915 }
1916 case NoteType::Note_Eight: {
1917 duration = static_cast<int>(NoteDuration::D_8);
1918 break;
1919 }
1920 case NoteType::Note_Sixteen: {
1921 duration = static_cast<int>(NoteDuration::D_16);
1922 break;
1923 }
1924 case NoteType::Note_32: {
1925 duration = static_cast<int>(NoteDuration::D_32);
1926 break;
1927 }
1928 case NoteType::Note_64: {
1929 duration = static_cast<int>(NoteDuration::D_64);
1930 break;
1931 }
1932 case NoteType::Note_128: {
1933 duration = static_cast<int>(NoteDuration::D_128);
1934 break;
1935 }
1936 case NoteType::Note_256: {
1937 duration = static_cast<int>(NoteDuration::D_256);
1938 break;
1939 }
1940 // case NoteType::Note_512: {
1941 // duration = static_cast<int>(NoteDuration::D_512);
1942 // break;
1943 // }
1944 // case NoteType::Note_1024: {
1945 // duration = static_cast<int>(NoteDuration::D_1024);
1946 // break;
1947 // }
1948 default:
1949 break;
1950 }
1951
1952 int dotLength = duration;
1953
1954 for (int i = 0; i < dot_; ++i) {
1955 dotLength /= 2;
1956 }
1957
1958 dotLength = duration - dotLength;
1959
1960 duration += dotLength;
1961
1962 return duration;
1963 }
1964
1965 ///////////////////////////////////////////////////////////////////////////////
Beam()1966 Beam::Beam() {
1967 musicDataType_ = MusicDataType::Beam;
1968 grace_ = false;
1969 }
1970
setIsGrace(bool grace)1971 void Beam::setIsGrace(bool grace) {
1972 grace_ = grace;
1973 }
1974
getIsGrace() const1975 bool Beam::getIsGrace() const {
1976 return grace_;
1977 }
1978
addLine(const MeasurePos & startMp,const MeasurePos & endMp)1979 void Beam::addLine(const MeasurePos& startMp, const MeasurePos& endMp) {
1980 lines_.push_back(qMakePair(startMp, endMp));
1981 }
1982
getLines() const1983 const QList<QPair<MeasurePos, MeasurePos> > Beam::getLines() const {
1984 return lines_;
1985 }
1986
1987 ///////////////////////////////////////////////////////////////////////////////
Tie()1988 Tie::Tie() {
1989 musicDataType_ = MusicDataType::Tie;
1990
1991 showOnTop_ = true;
1992 note_ = 72;
1993 height_ = 24;
1994 }
1995
setShowOnTop(bool top)1996 void Tie::setShowOnTop(bool top) {
1997 showOnTop_ = top;
1998 }
1999
getShowOnTop() const2000 bool Tie::getShowOnTop() const {
2001 return showOnTop_;
2002 }
2003
setNote(int note)2004 void Tie::setNote(int note) {
2005 note_ = note;
2006 }
2007
getNote() const2008 int Tie::getNote() const {
2009 return note_;
2010 }
2011
setHeight(int height)2012 void Tie::setHeight(int height) {
2013 height_ = height;
2014 }
2015
getHeight() const2016 int Tie::getHeight() const {
2017 return height_;
2018 }
2019
2020 ///////////////////////////////////////////////////////////////////////////////
Glissando()2021 Glissando::Glissando() {
2022 musicDataType_ = MusicDataType::Glissando;
2023
2024 straight_ = true;
2025 text_ = "gliss.";
2026 lineThick_ = 8;
2027 }
2028
setStraightWavy(bool straight)2029 void Glissando::setStraightWavy(bool straight) {
2030 straight_ = straight;
2031 }
2032
getStraightWavy() const2033 bool Glissando::getStraightWavy() const {
2034 return straight_;
2035 }
2036
setText(const QString & text)2037 void Glissando::setText(const QString& text) {
2038 text_ = text;
2039 }
2040
getText() const2041 QString Glissando::getText() const {
2042 return text_;
2043 }
2044
setLineThick(int thick)2045 void Glissando::setLineThick(int thick) {
2046 lineThick_ = thick;
2047 }
2048
getLineThick() const2049 int Glissando::getLineThick() const {
2050 return lineThick_;
2051 }
2052
2053 ///////////////////////////////////////////////////////////////////////////////
Decorator()2054 Decorator::Decorator() :
2055 decoratorType_(Type::Articulation),
2056 artType_(ArticulationType::Marcato) {
2057 musicDataType_ = MusicDataType::Decorator;
2058 }
2059
setDecoratorType(Type type)2060 void Decorator::setDecoratorType(Type type) {
2061 decoratorType_ = type;
2062 }
2063
getDecoratorType() const2064 Decorator::Type Decorator::getDecoratorType() const {
2065 return decoratorType_;
2066 }
2067
setArticulationType(ArticulationType type)2068 void Decorator::setArticulationType(ArticulationType type) {
2069 artType_ = type;
2070 }
2071
getArticulationType() const2072 ArticulationType Decorator::getArticulationType() const {
2073 return artType_;
2074 }
2075
2076 ///////////////////////////////////////////////////////////////////////////////
MeasureRepeat()2077 MeasureRepeat::MeasureRepeat() {
2078 musicDataType_ = MusicDataType::Measure_Repeat;
2079 singleRepeat_ = true;
2080 }
2081
setSingleRepeat(bool single)2082 void MeasureRepeat::setSingleRepeat(bool single) {
2083 singleRepeat_ = single;
2084
2085 start()->setMeasure(0);
2086 start()->setOffset(0);
2087 stop()->setMeasure(single ? 1 : 2);
2088 stop()->setOffset(0);
2089 }
2090
getSingleRepeat() const2091 bool MeasureRepeat::getSingleRepeat() const {
2092 return singleRepeat_;
2093 }
2094
2095 ///////////////////////////////////////////////////////////////////////////////
Tuplet()2096 Tuplet::Tuplet() :
2097 tuplet_(3), space_(2), height_(0), noteType_(NoteType::Note_Quarter){
2098 musicDataType_ = MusicDataType::Tuplet;
2099 mark_ = new OffsetElement();
2100 }
2101
~Tuplet()2102 Tuplet::~Tuplet(){
2103 delete mark_;
2104 }
2105
setTuplet(int tuplet)2106 void Tuplet::setTuplet(int tuplet) {
2107 tuplet_ = tuplet;
2108 }
2109
getTuplet() const2110 int Tuplet::getTuplet() const {
2111 return tuplet_;
2112 }
2113
setSpace(int space)2114 void Tuplet::setSpace(int space) {
2115 space_ = space;
2116 }
2117
getSpace() const2118 int Tuplet::getSpace() const {
2119 return space_;
2120 }
2121
getMarkHandle() const2122 OffsetElement* Tuplet::getMarkHandle() const {
2123 return mark_;
2124 }
2125
setHeight(int height)2126 void Tuplet::setHeight(int height) {
2127 height_ = height;
2128 }
2129
getHeight() const2130 int Tuplet::getHeight() const {
2131 return height_;
2132 }
2133
setNoteType(NoteType type)2134 void Tuplet::setNoteType(NoteType type) {
2135 noteType_ = type;
2136 }
2137
getNoteType() const2138 NoteType Tuplet::getNoteType() const {
2139 return noteType_;
2140 }
2141
2142 ///////////////////////////////////////////////////////////////////////////////
Harmony()2143 Harmony::Harmony() {
2144 musicDataType_ = MusicDataType::Harmony;
2145
2146 harmonyType_ = "";
2147 root_ = 0;
2148 bass_ = -1; //0xff
2149 alterRoot_ = 0;
2150 alterBass_ = 0;
2151 bassOnBottom_ = false;
2152 angle_ = 0;
2153 }
2154
setHarmonyType(QString type)2155 void Harmony::setHarmonyType(QString type) {
2156 harmonyType_ = type;
2157 }
2158
getHarmonyType() const2159 QString Harmony::getHarmonyType() const {
2160 return harmonyType_;
2161 }
2162
setRoot(int root)2163 void Harmony::setRoot(int root) {
2164 root_ = root;
2165 }
2166
getRoot() const2167 int Harmony::getRoot() const {
2168 return root_;
2169 }
2170
setAlterRoot(int val)2171 void Harmony::setAlterRoot(int val) {
2172 alterRoot_ = val;
2173 }
2174
getAlterRoot() const2175 int Harmony::getAlterRoot() const {
2176 return alterRoot_;
2177 }
2178
setBass(int bass)2179 void Harmony::setBass(int bass) {
2180 bass_ = bass;
2181 }
2182
getBass() const2183 int Harmony::getBass() const {
2184 return bass_;
2185 }
2186
setAlterBass(int val)2187 void Harmony::setAlterBass(int val) {
2188 alterBass_ = val;
2189 }
2190
getAlterBass() const2191 int Harmony::getAlterBass() const {
2192 return alterBass_;
2193 }
2194
setBassOnBottom(bool on)2195 void Harmony::setBassOnBottom(bool on) {
2196 bassOnBottom_ = on;
2197 }
2198
getBassOnBottom() const2199 bool Harmony::getBassOnBottom() const {
2200 return bassOnBottom_;
2201 }
2202
setAngle(int angle)2203 void Harmony::setAngle(int angle) {
2204 angle_ = angle;
2205 }
2206
getAngle() const2207 int Harmony::getAngle() const {
2208 return angle_;
2209 }
2210
2211 ///////////////////////////////////////////////////////////////////////////////
Clef()2212 Clef::Clef() {
2213 musicDataType_ = MusicDataType::Clef;
2214
2215 clefType_ = ClefType::Treble;
2216 }
2217
setClefType(int type)2218 void Clef::setClefType(int type) {
2219 clefType_ = (ClefType) type;
2220 }
2221
getClefType() const2222 ClefType Clef::getClefType() const {
2223 return clefType_;
2224 }
2225
2226 ///////////////////////////////////////////////////////////////////////////////
Lyric()2227 Lyric::Lyric() {
2228 musicDataType_ = MusicDataType::Lyric;
2229
2230 lyric_ = QString();
2231 verse_ = 0;
2232 }
2233
setLyric(const QString & lyricText)2234 void Lyric::setLyric(const QString& lyricText) {
2235 lyric_ = lyricText;
2236 }
2237
getLyric() const2238 QString Lyric::getLyric() const {
2239 return lyric_;
2240 }
2241
setVerse(int verse)2242 void Lyric::setVerse(int verse) {
2243 verse_ = verse;
2244 }
2245
getVerse() const2246 int Lyric::getVerse() const {
2247 return verse_;
2248 }
2249
2250 ///////////////////////////////////////////////////////////////////////////////
Slur()2251 Slur::Slur() {
2252 musicDataType_ = MusicDataType::Slur;
2253
2254 containerCount_ = 1;
2255 showOnTop_ = true;
2256 noteTimePercent_ = 100;
2257
2258 handle_2_ = new OffsetElement();
2259 handle_3_ = new OffsetElement();
2260 }
2261
~Slur()2262 Slur::~Slur() {
2263 delete handle_2_;
2264 delete handle_3_;
2265 }
2266
setContainerCount(int count)2267 void Slur::setContainerCount(int count) {
2268 containerCount_ = count;
2269 }
2270
getContainerCount() const2271 int Slur::getContainerCount() const {
2272 return containerCount_;
2273 }
2274
setShowOnTop(bool top)2275 void Slur::setShowOnTop(bool top) {
2276 showOnTop_ = top;
2277 }
2278
getShowOnTop() const2279 bool Slur::getShowOnTop() const {
2280 return showOnTop_;
2281 }
2282
getHandle2() const2283 OffsetElement* Slur::getHandle2() const {
2284 return handle_2_;
2285 }
2286
getHandle3() const2287 OffsetElement* Slur::getHandle3() const {
2288 return handle_3_;
2289 }
2290
setNoteTimePercent(int percent)2291 void Slur::setNoteTimePercent(int percent) {
2292 noteTimePercent_ = percent;
2293 }
2294
getNoteTimePercent() const2295 int Slur::getNoteTimePercent() const {
2296 return noteTimePercent_;
2297 }
2298
2299 ///////////////////////////////////////////////////////////////////////////////
Dynamics()2300 Dynamics::Dynamics() {
2301 musicDataType_ = MusicDataType::Dynamics;
2302
2303 dynamicsType_ = DynamicsType::PPPP;
2304 playback_ = true;
2305 velocity_ = 30;
2306 }
2307
setDynamicsType(int type)2308 void Dynamics::setDynamicsType(int type) {
2309 dynamicsType_ = DynamicsType(type);
2310 }
2311
getDynamicsType() const2312 DynamicsType Dynamics::getDynamicsType() const {
2313 return dynamicsType_;
2314 }
2315
setIsPlayback(bool play)2316 void Dynamics::setIsPlayback(bool play) {
2317 playback_ = play;
2318 }
2319
getIsPlayback() const2320 bool Dynamics::getIsPlayback() const {
2321 return playback_;
2322 }
2323
setVelocity(int vel)2324 void Dynamics::setVelocity(int vel) {
2325 velocity_ = vel;
2326 }
2327
getVelocity() const2328 int Dynamics::getVelocity() const {
2329 return velocity_;
2330 }
2331
2332 ///////////////////////////////////////////////////////////////////////////////
WedgeEndPoint()2333 WedgeEndPoint::WedgeEndPoint() {
2334 musicDataType_ = MusicDataType::Wedge_EndPoint;
2335
2336 wedgeType_ = WedgeType::Cres;
2337 height_ = 24;
2338 wedgeStart_ = true;
2339 }
2340
setWedgeType(WedgeType type)2341 void WedgeEndPoint::setWedgeType(WedgeType type) {
2342 wedgeType_ = type;
2343 }
2344
getWedgeType() const2345 WedgeType WedgeEndPoint::getWedgeType() const {
2346 return wedgeType_;
2347 }
2348
setHeight(int height)2349 void WedgeEndPoint::setHeight(int height) {
2350 height_ = height;
2351 }
2352
getHeight() const2353 int WedgeEndPoint::getHeight() const {
2354 return height_;
2355 }
2356
setWedgeStart(bool wedgeStart)2357 void WedgeEndPoint::setWedgeStart(bool wedgeStart) {
2358 wedgeStart_ = wedgeStart;
2359 }
2360
getWedgeStart() const2361 bool WedgeEndPoint::getWedgeStart() const {
2362 return wedgeStart_;
2363 }
2364
2365 ///////////////////////////////////////////////////////////////////////////////
Wedge()2366 Wedge::Wedge() {
2367 musicDataType_ = MusicDataType::Wedge;
2368
2369 wedgeType_ = WedgeType::Cres;
2370 height_ = 24;
2371 }
2372
setWedgeType(WedgeType type)2373 void Wedge::setWedgeType(WedgeType type) {
2374 wedgeType_ = type;
2375 }
2376
getWedgeType() const2377 WedgeType Wedge::getWedgeType() const {
2378 return wedgeType_;
2379 }
2380
setHeight(int height)2381 void Wedge::setHeight(int height) {
2382 height_ = height;
2383 }
2384
getHeight() const2385 int Wedge::getHeight() const {
2386 return height_;
2387 }
2388
2389 ///////////////////////////////////////////////////////////////////////////////
Pedal()2390 Pedal::Pedal() {
2391 musicDataType_ = MusicDataType::Pedal;
2392
2393 half_ = false;
2394 playback_ = false;
2395 playOffset_ = 0;
2396
2397 pedalHandle_ = new OffsetElement();
2398 }
2399
~Pedal()2400 Pedal::~Pedal() {
2401 delete pedalHandle_;
2402 }
2403
setHalf(bool half)2404 void Pedal::setHalf(bool half) {
2405 half_ = half;
2406 }
2407
getHalf() const2408 bool Pedal::getHalf() const {
2409 return half_;
2410 }
2411
getPedalHandle() const2412 OffsetElement* Pedal::getPedalHandle() const {
2413 return pedalHandle_;
2414 }
2415
setIsPlayback(bool playback)2416 void Pedal::setIsPlayback(bool playback) {
2417 playback_ = playback;
2418 }
2419
getIsPlayback() const2420 bool Pedal::getIsPlayback() const {
2421 return playback_;
2422 }
2423
setPlayOffset(int offset)2424 void Pedal::setPlayOffset(int offset) {
2425 playOffset_ = offset;
2426 }
2427
getPlayOffset() const2428 int Pedal::getPlayOffset() const {
2429 return playOffset_;
2430 }
2431
2432 ///////////////////////////////////////////////////////////////////////////////
KuoHao()2433 KuoHao::KuoHao() {
2434 musicDataType_ = MusicDataType::KuoHao;
2435
2436 kuohaoType_ = KuoHaoType::Parentheses;
2437 height_ = 0;
2438 }
2439
setHeight(int height)2440 void KuoHao::setHeight(int height) {
2441 height_ = height;
2442 }
2443
getHeight() const2444 int KuoHao::getHeight() const {
2445 return height_;
2446 }
2447
setKuohaoType(int type)2448 void KuoHao::setKuohaoType(int type) {
2449 kuohaoType_ = (KuoHaoType) type;
2450 }
2451
getKuohaoType() const2452 KuoHaoType KuoHao::getKuohaoType() const {
2453 return kuohaoType_;
2454 }
2455
2456 ///////////////////////////////////////////////////////////////////////////////
Expressions()2457 Expressions::Expressions() {
2458 musicDataType_ = MusicDataType::Expressions;
2459
2460 text_ = QString();
2461 }
2462
setText(const QString & str)2463 void Expressions::setText(const QString& str) {
2464 text_ = str;
2465 }
2466
getText() const2467 QString Expressions::getText() const {
2468 return text_;
2469 }
2470
2471 ///////////////////////////////////////////////////////////////////////////////
HarpPedal()2472 HarpPedal::HarpPedal() :
2473 showType_(0),
2474 showCharFlag_(0) {
2475 musicDataType_ = MusicDataType::Harp_Pedal;
2476 }
2477
setShowType(int type)2478 void HarpPedal::setShowType(int type) {
2479 showType_ = type;
2480 }
2481
getShowType() const2482 int HarpPedal::getShowType() const {
2483 return showType_;
2484 }
2485
setShowCharFlag(int flag)2486 void HarpPedal::setShowCharFlag(int flag) {
2487 showCharFlag_ = flag;
2488 }
2489
getShowCharFlag() const2490 int HarpPedal::getShowCharFlag() const {
2491 return showCharFlag_;
2492 }
2493
2494 ///////////////////////////////////////////////////////////////////////////////
OctaveShift()2495 OctaveShift::OctaveShift() :
2496 octaveShiftType_(OctaveShiftType::OS_8),
2497 octaveShiftPosition_(OctaveShiftPosition::Start),
2498 endTick_(0) {
2499 musicDataType_ = MusicDataType::OctaveShift;
2500 }
2501
setOctaveShiftType(OctaveShiftType type)2502 void OctaveShift::setOctaveShiftType(OctaveShiftType type) {
2503 octaveShiftType_ = type;
2504 }
2505
getOctaveShiftType() const2506 OctaveShiftType OctaveShift::getOctaveShiftType() const {
2507 return octaveShiftType_;
2508 }
2509
getNoteShift() const2510 int OctaveShift::getNoteShift() const {
2511 int shift = 12;
2512
2513 switch (getOctaveShiftType()) {
2514 case OctaveShiftType::OS_8: {
2515 shift = 12;
2516 break;
2517 }
2518 case OctaveShiftType::OS_Minus_8: {
2519 shift = -12;
2520 break;
2521 }
2522 case OctaveShiftType::OS_15: {
2523 shift = 24;
2524 break;
2525 }
2526 case OctaveShiftType::OS_Minus_15: {
2527 shift = -24;
2528 break;
2529 }
2530 default:
2531 break;
2532 }
2533
2534 return shift;
2535 }
2536
setEndTick(int tick)2537 void OctaveShift::setEndTick(int tick) {
2538 endTick_ = tick;
2539 }
2540
getEndTick() const2541 int OctaveShift::getEndTick() const {
2542 return endTick_;
2543 }
2544
setOctaveShiftPosition(OctaveShiftPosition position)2545 void OctaveShift::setOctaveShiftPosition(OctaveShiftPosition position) {
2546 octaveShiftPosition_ = position;
2547 }
2548
getOctaveShiftPosition() const2549 OctaveShiftPosition OctaveShift::getOctaveShiftPosition() const {
2550 return octaveShiftPosition_;
2551 }
2552
2553 ///////////////////////////////////////////////////////////////////////////////
OctaveShiftEndPoint()2554 OctaveShiftEndPoint::OctaveShiftEndPoint() {
2555 musicDataType_ = MusicDataType::OctaveShift_EndPoint;
2556
2557 octaveShiftType_ = OctaveShiftType::OS_8;
2558 octaveShiftPosition_ = OctaveShiftPosition::Start;
2559 endTick_ = 0;
2560 }
2561
setOctaveShiftType(OctaveShiftType type)2562 void OctaveShiftEndPoint::setOctaveShiftType(OctaveShiftType type) {
2563 octaveShiftType_ = type;
2564 }
2565
getOctaveShiftType() const2566 OctaveShiftType OctaveShiftEndPoint::getOctaveShiftType() const {
2567 return octaveShiftType_;
2568 }
2569
setOctaveShiftPosition(OctaveShiftPosition position)2570 void OctaveShiftEndPoint::setOctaveShiftPosition(OctaveShiftPosition position) {
2571 octaveShiftPosition_ = position;
2572 }
2573
getOctaveShiftPosition() const2574 OctaveShiftPosition OctaveShiftEndPoint::getOctaveShiftPosition() const {
2575 return octaveShiftPosition_;
2576 }
2577
setEndTick(int tick)2578 void OctaveShiftEndPoint::setEndTick(int tick) {
2579 endTick_ = tick;
2580 }
2581
getEndTick() const2582 int OctaveShiftEndPoint::getEndTick() const {
2583 return endTick_;
2584 }
2585
2586 ///////////////////////////////////////////////////////////////////////////////
MultiMeasureRest()2587 MultiMeasureRest::MultiMeasureRest() {
2588 musicDataType_ = MusicDataType::Multi_Measure_Rest;
2589 measureCount_ = 0;
2590 }
2591
setMeasureCount(int count)2592 void MultiMeasureRest::setMeasureCount(int count) {
2593 measureCount_ = count;
2594 }
2595
getMeasureCount() const2596 int MultiMeasureRest::getMeasureCount() const {
2597 return measureCount_;
2598 }
2599
2600 ///////////////////////////////////////////////////////////////////////////////
Tempo()2601 Tempo::Tempo() {
2602 musicDataType_ = MusicDataType::Tempo;
2603
2604 leftNoteType_ = 3;
2605 showMark_ = false;
2606 showText_ = false;
2607 showParenthesis_ = false;
2608 typeTempo_ = 96;
2609 leftText_ = QString();
2610 rightText_ = QString();
2611 swingEighth_ = false;
2612 rightNoteType_ = 3;
2613 leftNoteDot_ = false;
2614 rightNoteDot_ = false;
2615 rightSideType_ = 0;
2616 }
2617
setLeftNoteType(int type)2618 void Tempo::setLeftNoteType(int type) {
2619 leftNoteType_ = type;
2620 }
2621
getLeftNoteType() const2622 NoteType Tempo::getLeftNoteType() const {
2623 return (NoteType) leftNoteType_;
2624 }
2625
setShowMark(bool show)2626 void Tempo::setShowMark(bool show) {
2627 showMark_ = show;
2628 }
2629
getShowMark() const2630 bool Tempo::getShowMark() const {
2631 return showMark_;
2632 }
2633
setShowBeforeText(bool show)2634 void Tempo::setShowBeforeText(bool show) {
2635 showText_ = show;
2636 }
2637
getShowBeforeText() const2638 bool Tempo::getShowBeforeText() const {
2639 return showText_;
2640 }
2641
setShowParenthesis(bool show)2642 void Tempo::setShowParenthesis(bool show) {
2643 showParenthesis_ = show;
2644 }
2645
getShowParenthesis() const2646 bool Tempo::getShowParenthesis() const {
2647 return showParenthesis_;
2648 }
2649
setTypeTempo(double tempo)2650 void Tempo::setTypeTempo(double tempo) {
2651 typeTempo_ = tempo;
2652 }
2653
getTypeTempo() const2654 double Tempo::getTypeTempo() const {
2655 return typeTempo_;
2656 }
2657
getQuarterTempo() const2658 double Tempo::getQuarterTempo() const {
2659 double factor = pow(2.0, int(NoteType::Note_Quarter) - int(getLeftNoteType()));
2660 if (getLeftNoteDot())
2661 factor *= 3.0/2.0;
2662 double tempo = getTypeTempo() * factor;
2663
2664 return tempo;
2665 }
2666
setLeftText(const QString & str)2667 void Tempo::setLeftText(const QString& str) {
2668 leftText_ = str;
2669 }
2670
getLeftText() const2671 QString Tempo::getLeftText() const {
2672 return leftText_;
2673 }
2674
setRightText(const QString & str)2675 void Tempo::setRightText(const QString& str) {
2676 rightText_ = str;
2677 }
2678
getRightText() const2679 QString Tempo::getRightText() const {
2680 return rightText_;
2681 }
2682
setSwingEighth(bool swing)2683 void Tempo::setSwingEighth(bool swing) {
2684 swingEighth_ = swing;
2685 }
2686
getSwingEighth() const2687 bool Tempo::getSwingEighth() const {
2688 return swingEighth_;
2689 }
2690
setRightNoteType(int type)2691 void Tempo::setRightNoteType(int type) {
2692 rightNoteType_ = type;
2693 }
2694
getRightNoteType() const2695 NoteType Tempo::getRightNoteType() const {
2696 return (NoteType) rightNoteType_;
2697 }
2698
setLeftNoteDot(bool showDot)2699 void Tempo::setLeftNoteDot(bool showDot) {
2700 leftNoteDot_ = showDot;
2701 }
2702
getLeftNoteDot() const2703 bool Tempo::getLeftNoteDot() const {
2704 return leftNoteDot_;
2705 }
2706
setRightNoteDot(bool showDot)2707 void Tempo::setRightNoteDot(bool showDot) {
2708 rightNoteDot_ = showDot;
2709 }
2710
getRightNoteDot() const2711 bool Tempo::getRightNoteDot() const {
2712 return rightNoteDot_;
2713 }
2714
setRightSideType(int type)2715 void Tempo::setRightSideType(int type) {
2716 rightSideType_ = type;
2717 }
2718
getRightSideType() const2719 int Tempo::getRightSideType() const {
2720 return rightSideType_;
2721 }
2722
2723 ///////////////////////////////////////////////////////////////////////////////
Text()2724 Text::Text() {
2725 musicDataType_ = MusicDataType::Text;
2726
2727 textType_ = Type::Rehearsal;
2728 horiMargin_ = 8;
2729 vertMargin_ = 8;
2730 lineThick_ = 4;
2731 text_ = QString();
2732 width_ = 0;
2733 height_ = 0;
2734 }
2735
setTextType(Type type)2736 void Text::setTextType(Type type) {
2737 textType_ = type;
2738 }
2739
getTextType() const2740 Text::Type Text::getTextType() const {
2741 return textType_;
2742 }
2743
setHorizontalMargin(int margin)2744 void Text::setHorizontalMargin(int margin) {
2745 horiMargin_ = margin;
2746 }
2747
getHorizontalMargin() const2748 int Text::getHorizontalMargin() const {
2749 return horiMargin_;
2750 }
2751
setVerticalMargin(int margin)2752 void Text::setVerticalMargin(int margin) {
2753 vertMargin_ = margin;
2754 }
2755
getVerticalMargin() const2756 int Text::getVerticalMargin() const {
2757 return vertMargin_;
2758 }
2759
setLineThick(int thick)2760 void Text::setLineThick(int thick) {
2761 lineThick_ = thick;
2762 }
2763
getLineThick() const2764 int Text::getLineThick() const {
2765 return lineThick_;
2766 }
2767
setText(const QString & text)2768 void Text::setText(const QString& text) {
2769 text_ = text;
2770 }
2771
getText() const2772 QString Text::getText() const {
2773 return text_;
2774 }
2775
setWidth(int width)2776 void Text::setWidth(int width) {
2777 width_ = width;
2778 }
2779
getWidth() const2780 int Text::getWidth() const {
2781 return width_;
2782 }
2783
setHeight(int height)2784 void Text::setHeight(int height) {
2785 height_ = height;
2786 }
2787
getHeight() const2788 int Text::getHeight() const {
2789 return height_;
2790 }
2791
2792 ///////////////////////////////////////////////////////////////////////////////
TimeSignature()2793 TimeSignature::TimeSignature() {
2794 numerator_ = 4;
2795 denominator_ = 4;
2796 isSymbol_ = false;
2797 beatLength_ = 480;
2798 barLength_ = 1920;
2799 barLengthUnits_ = 0x400;
2800 replaceFont_ = false;
2801 showBeatGroup_ = false;
2802
2803 groupNumerator1_ = 0;
2804 groupNumerator2_ = 0;
2805 groupNumerator3_ = 0;
2806 groupDenominator1_ = 4;
2807 groupDenominator2_ = 4;
2808 groupDenominator3_ = 4;
2809
2810 beamGroup1_ = 4;
2811 beamGroup2_ = 0;
2812 beamGroup3_ = 0;
2813 beamGroup4_ = 0;
2814
2815 beamCount16th_ = 4;
2816 beamCount32th_ = 1;
2817 }
2818
setNumerator(int numerator)2819 void TimeSignature::setNumerator(int numerator) {
2820 numerator_ = numerator;
2821 }
2822
getNumerator() const2823 int TimeSignature::getNumerator() const {
2824 return numerator_;
2825 }
2826
setDenominator(int denominator)2827 void TimeSignature::setDenominator(int denominator) {
2828 denominator_ = denominator;
2829 }
2830
getDenominator() const2831 int TimeSignature::getDenominator() const {
2832 return denominator_;
2833 }
2834
setIsSymbol(bool symbol)2835 void TimeSignature::setIsSymbol(bool symbol) {
2836 isSymbol_ = symbol;
2837 }
2838
getIsSymbol() const2839 bool TimeSignature::getIsSymbol() const {
2840 if (numerator_ == 2 && denominator_ == 2) {
2841 return true;
2842 }
2843
2844 return isSymbol_;
2845 }
2846
setBeatLength(int length)2847 void TimeSignature::setBeatLength(int length) {
2848 beatLength_ = length;
2849 }
2850
getBeatLength() const2851 int TimeSignature::getBeatLength() const {
2852 return beatLength_;
2853 }
2854
setBarLength(int length)2855 void TimeSignature::setBarLength(int length) {
2856 barLength_ = length;
2857 }
2858
getBarLength() const2859 int TimeSignature::getBarLength() const {
2860 return barLength_;
2861 }
2862
addBeat(int startUnit,int lengthUnit,int startTick)2863 void TimeSignature::addBeat(int startUnit, int lengthUnit, int startTick) {
2864 BeatNode node;
2865 node.startUnit_ = startUnit;
2866 node.lengthUnit_ = lengthUnit;
2867 node.startTick_ = startTick;
2868 beats_.push_back(node);
2869 }
2870
endAddBeat()2871 void TimeSignature::endAddBeat() {
2872 int i;
2873 barLengthUnits_ = 0;
2874
2875 for (i = 0; i < beats_.size(); ++i) {
2876 barLengthUnits_ += beats_[i].lengthUnit_;
2877 }
2878 }
2879
getUnits() const2880 int TimeSignature::getUnits() const {
2881 return barLengthUnits_;
2882 }
2883
setReplaceFont(bool replace)2884 void TimeSignature::setReplaceFont(bool replace) {
2885 replaceFont_ = replace;
2886 }
2887
getReplaceFont() const2888 bool TimeSignature::getReplaceFont() const {
2889 return replaceFont_;
2890 }
2891
setShowBeatGroup(bool show)2892 void TimeSignature::setShowBeatGroup(bool show) {
2893 showBeatGroup_ = show;
2894 }
2895
getShowBeatGroup() const2896 bool TimeSignature::getShowBeatGroup() const {
2897 return showBeatGroup_;
2898 }
2899
setGroupNumerator1(int numerator)2900 void TimeSignature::setGroupNumerator1(int numerator) {
2901 groupNumerator1_ = numerator;
2902 }
2903
setGroupNumerator2(int numerator)2904 void TimeSignature::setGroupNumerator2(int numerator) {
2905 groupNumerator2_ = numerator;
2906 }
2907
setGroupNumerator3(int numerator)2908 void TimeSignature::setGroupNumerator3(int numerator) {
2909 groupNumerator3_ = numerator;
2910 }
2911
setGroupDenominator1(int denominator)2912 void TimeSignature::setGroupDenominator1(int denominator) {
2913 groupDenominator1_ = denominator;
2914 }
2915
setGroupDenominator2(int denominator)2916 void TimeSignature::setGroupDenominator2(int denominator) {
2917 groupDenominator2_ = denominator;
2918 }
2919
setGroupDenominator3(int denominator)2920 void TimeSignature::setGroupDenominator3(int denominator) {
2921 groupDenominator3_ = denominator;
2922 }
2923
setBeamGroup1(int count)2924 void TimeSignature::setBeamGroup1(int count) {
2925 beamGroup1_ = count;
2926 }
2927
setBeamGroup2(int count)2928 void TimeSignature::setBeamGroup2(int count) {
2929 beamGroup2_ = count;
2930 }
2931
setBeamGroup3(int count)2932 void TimeSignature::setBeamGroup3(int count) {
2933 beamGroup3_ = count;
2934 }
2935
setBeamGroup4(int count)2936 void TimeSignature::setBeamGroup4(int count) {
2937 beamGroup4_ = count;
2938 }
2939
set16thBeamCount(int count)2940 void TimeSignature::set16thBeamCount(int count) {
2941 beamCount16th_ = count;
2942 }
2943
set32thBeamCount(int count)2944 void TimeSignature::set32thBeamCount(int count) {
2945 beamCount32th_ = count;
2946 }
2947
2948 ///////////////////////////////////////////////////////////////////////////////
Key()2949 Key::Key() {
2950 key_ = 0;
2951 set_ = false;
2952 previousKey_ = 0;
2953 symbolCount_ = 0;
2954 }
2955
setKey(int key)2956 void Key::setKey(int key) {
2957 key_ = key;
2958 set_ = true;
2959 }
2960
getKey() const2961 int Key::getKey() const {
2962 return key_;
2963 }
2964
getSetKey() const2965 bool Key::getSetKey() const {
2966 return set_;
2967 }
2968
setPreviousKey(int key)2969 void Key::setPreviousKey(int key) {
2970 previousKey_ = key;
2971 }
2972
getPreviousKey() const2973 int Key::getPreviousKey() const {
2974 return previousKey_;
2975 }
2976
setSymbolCount(int count)2977 void Key::setSymbolCount(int count) {
2978 symbolCount_ = count;
2979 }
2980
getSymbolCount() const2981 int Key::getSymbolCount() const {
2982 return symbolCount_;
2983 }
2984
2985 ///////////////////////////////////////////////////////////////////////////////
RepeatSymbol()2986 RepeatSymbol::RepeatSymbol() :
2987 text_("#1"), repeatType_(RepeatType::Segno) {
2988 musicDataType_ = MusicDataType::Repeat;
2989 }
2990
setText(const QString & text)2991 void RepeatSymbol::setText(const QString& text) {
2992 text_ = text;
2993 }
2994
getText() const2995 QString RepeatSymbol::getText() const {
2996 return text_;
2997 }
2998
setRepeatType(int repeatType)2999 void RepeatSymbol::setRepeatType(int repeatType) {
3000 repeatType_ = (RepeatType) repeatType;
3001 }
3002
getRepeatType() const3003 RepeatType RepeatSymbol::getRepeatType() const {
3004 return repeatType_;
3005 }
3006
3007 ///////////////////////////////////////////////////////////////////////////////
NumericEnding()3008 NumericEnding::NumericEnding() {
3009 musicDataType_ = MusicDataType::Numeric_Ending;
3010
3011 height_ = 0;
3012 text_ = QString();
3013 numericHandle_ = new OffsetElement();
3014 }
3015
~NumericEnding()3016 NumericEnding::~NumericEnding() {
3017 delete numericHandle_;
3018 }
3019
getNumericHandle() const3020 OffsetElement* NumericEnding::getNumericHandle() const {
3021 return numericHandle_;
3022 }
3023
setHeight(int height)3024 void NumericEnding::setHeight(int height) {
3025 height_ = height;
3026 }
3027
getHeight() const3028 int NumericEnding::getHeight() const {
3029 return height_;
3030 }
3031
setText(const QString & text)3032 void NumericEnding::setText(const QString& text) {
3033 text_ = text;
3034 }
3035
getText() const3036 QString NumericEnding::getText() const {
3037 return text_;
3038 }
3039
getNumbers() const3040 QList<int> NumericEnding::getNumbers() const {
3041 int i;
3042 QStringList strs = text_.split(",", QString::SkipEmptyParts);
3043 QList<int> endings;
3044
3045 for (i = 0; i < strs.size(); ++i) {
3046 bool ok;
3047 int num = strs[i].toInt(&ok);
3048 endings.push_back(num);
3049 }
3050
3051 return endings;
3052 }
3053
getJumpCount() const3054 int NumericEnding::getJumpCount() const {
3055 QList<int> numbers = getNumbers();
3056 int count = 0;
3057
3058 for (int i = 0; i < numbers.size(); ++i) {
3059 if ((int)i + 1 != numbers[i]) {
3060 break;
3061 }
3062
3063 count = i + 1;
3064 }
3065
3066 return count;
3067 }
3068
3069 ///////////////////////////////////////////////////////////////////////////////
BarNumber()3070 BarNumber::BarNumber() {
3071 index_ = 0;
3072 showOnParagraphStart_ = false;
3073 align_ = 0;
3074 showFlag_ = 1; // staff
3075 barRange_ = 1; // can't be 0
3076 prefix_ = QString();
3077 }
3078
setIndex(int index)3079 void BarNumber::setIndex(int index) {
3080 index_ = index;
3081 }
3082
getIndex() const3083 int BarNumber::getIndex() const {
3084 return index_;
3085 }
3086
setShowOnParagraphStart(bool show)3087 void BarNumber::setShowOnParagraphStart(bool show) {
3088 showOnParagraphStart_ = show;
3089 }
3090
getShowOnParagraphStart() const3091 bool BarNumber::getShowOnParagraphStart() const {
3092 return showOnParagraphStart_;
3093 }
3094
setAlign(int align)3095 void BarNumber::setAlign(int align)// 0:left, 1:center, 2:right
3096 {
3097 align_ = align;
3098 }
3099
getAlign() const3100 int BarNumber::getAlign() const {
3101 return align_;
3102 }
3103
setShowFlag(int flag)3104 void BarNumber::setShowFlag(int flag) {
3105 showFlag_ = flag;
3106 }
3107
getShowFlag() const3108 int BarNumber::getShowFlag() const {
3109 return showFlag_;
3110 }
3111
setShowEveryBarCount(int count)3112 void BarNumber::setShowEveryBarCount(int count) {
3113 barRange_ = count;
3114 }
3115
getShowEveryBarCount() const3116 int BarNumber::getShowEveryBarCount() const {
3117 return barRange_;
3118 }
3119
setPrefix(const QString & str)3120 void BarNumber::setPrefix(const QString& str) {
3121 prefix_ = str;
3122 }
3123
getPrefix() const3124 QString BarNumber::getPrefix() const {
3125 return prefix_;
3126 }
3127
3128 ///////////////////////////////////////////////////////////////////////////////
MidiController()3129 MidiController::MidiController() {
3130 midiType_ = MidiType::Controller;
3131 controller_ = 64; // pedal
3132 value_ = 0;
3133 }
3134
setController(int number)3135 void MidiController::setController(int number) {
3136 controller_ = number;
3137 }
3138
getController() const3139 int MidiController::getController() const {
3140 return controller_;
3141 }
3142
setValue(int value)3143 void MidiController::setValue(int value) {
3144 value_ = value;
3145 }
3146
getValue() const3147 int MidiController::getValue() const {
3148 return value_;
3149 }
3150
3151 ///////////////////////////////////////////////////////////////////////////////
MidiProgramChange()3152 MidiProgramChange::MidiProgramChange() {
3153 midiType_ = MidiType::Program_Change;
3154 patch_ = 0; // grand piano
3155 }
3156
setPatch(int patch)3157 void MidiProgramChange::setPatch(int patch) {
3158 patch_ = patch;
3159 }
3160
getPatch() const3161 int MidiProgramChange::getPatch() const {
3162 return patch_;
3163 }
3164
3165 ///////////////////////////////////////////////////////////////////////////////
MidiChannelPressure()3166 MidiChannelPressure::MidiChannelPressure() :
3167 pressure_(0) {
3168 midiType_ = MidiType::Channel_Pressure;
3169 }
3170
setPressure(int pressure)3171 void MidiChannelPressure::setPressure(int pressure) {
3172 pressure_ = pressure;
3173 }
3174
getPressure() const3175 int MidiChannelPressure::getPressure() const {
3176 return pressure_;
3177 }
3178
3179 ///////////////////////////////////////////////////////////////////////////////
MidiPitchWheel()3180 MidiPitchWheel::MidiPitchWheel() {
3181 midiType_ = MidiType::Pitch_Wheel;
3182 value_ = 0;
3183 }
3184
setValue(int value)3185 void MidiPitchWheel::setValue(int value) {
3186 value_ = value;
3187 }
3188
getValue() const3189 int MidiPitchWheel::getValue() const {
3190 return value_;
3191 }
3192
3193 ///////////////////////////////////////////////////////////////////////////////
Measure(int index)3194 Measure::Measure(int index) {
3195 barNumber_ = new BarNumber();
3196 barNumber_->setIndex(index);
3197 time_ = new TimeSignature();
3198
3199 clear();
3200 }
3201
~Measure()3202 Measure::~Measure(){
3203 clear();
3204
3205 delete barNumber_;
3206 delete time_;
3207 }
3208
getBarNumber() const3209 BarNumber* Measure::getBarNumber() const {
3210 return barNumber_;
3211 }
3212
getTime() const3213 TimeSignature* Measure::getTime() const {
3214 return time_;
3215 }
3216
setLeftBarline(int barline)3217 void Measure::setLeftBarline(int barline) {
3218 leftBarline_ = (BarLineType) barline;
3219 }
3220
getLeftBarline() const3221 BarLineType Measure::getLeftBarline() const {
3222 return leftBarline_;
3223 }
3224
setRightBarline(int barline)3225 void Measure::setRightBarline(int barline) {
3226 rightBarline_ = (BarLineType) barline;
3227 }
3228
getRightBarline() const3229 BarLineType Measure::getRightBarline() const {
3230 return rightBarline_;
3231 }
3232
setBackwardRepeatCount(int repeatCount)3233 void Measure::setBackwardRepeatCount(int repeatCount) {
3234 repeatCount_ = repeatCount;
3235 }
3236
getBackwardRepeatCount() const3237 int Measure::getBackwardRepeatCount() const {
3238 return repeatCount_;
3239 }
3240
setTypeTempo(double tempo)3241 void Measure::setTypeTempo(double tempo) {
3242 typeTempo_ = tempo;
3243 }
3244
getTypeTempo() const3245 double Measure::getTypeTempo() const {
3246 return typeTempo_;
3247 }
3248
setIsPickup(bool pickup)3249 void Measure::setIsPickup(bool pickup) {
3250 pickup_ = pickup;
3251 }
3252
getIsPickup() const3253 bool Measure::getIsPickup() const {
3254 return pickup_;
3255 }
3256
setIsMultiMeasureRest(bool rest)3257 void Measure::setIsMultiMeasureRest(bool rest) {
3258 multiMeasureRest_ = rest;
3259 }
3260
getIsMultiMeasureRest() const3261 bool Measure::getIsMultiMeasureRest() const {
3262 return multiMeasureRest_;
3263 }
3264
setMultiMeasureRestCount(int count)3265 void Measure::setMultiMeasureRestCount(int count) {
3266 multiMeasureRestCount_ = count;
3267 }
3268
getMultiMeasureRestCount() const3269 int Measure::getMultiMeasureRestCount() const {
3270 return multiMeasureRestCount_;
3271 }
3272
clear()3273 void Measure::clear() {
3274 leftBarline_ = BarLineType::Default;
3275 rightBarline_ = BarLineType::Default;
3276 repeatCount_ = 1;
3277 typeTempo_ = 96.00;
3278 setLength(0x780); //time = 4/4
3279 pickup_ = false;
3280 multiMeasureRest_ = false;
3281 multiMeasureRestCount_ = 0;
3282 }
3283
3284 ///////////////////////////////////////////////////////////////////////////////
MeasureData()3285 MeasureData::MeasureData() {
3286 key_ = new Key();
3287 clef_ = new Clef();
3288 }
3289
~MeasureData()3290 MeasureData::~MeasureData(){
3291 int i;
3292 for(i=0; i<musicDatas_.size(); ++i){
3293 delete musicDatas_[i];
3294 }
3295 musicDatas_.clear();
3296
3297 // noteContainers_ also in musicDatas_, no need to destroy
3298 noteContainers_.clear();
3299
3300 // only delete at element start
3301 for(i=0; i<crossMeasureElements_.size(); ++i){
3302 if(crossMeasureElements_[i].second){
3303 delete crossMeasureElements_[i].first;
3304 }
3305 }
3306 crossMeasureElements_.clear();
3307
3308 for(i=0; i<midiDatas_.size(); ++i){
3309 delete midiDatas_[i];
3310 }
3311 midiDatas_.clear();
3312
3313 delete key_;
3314 delete clef_;
3315 }
3316
getKey() const3317 Key* MeasureData::getKey() const {
3318 return key_;
3319 }
3320
getClef() const3321 Clef* MeasureData::getClef() const {
3322 return clef_;
3323 }
3324
addNoteContainer(NoteContainer * ptr)3325 void MeasureData::addNoteContainer(NoteContainer* ptr) {
3326 noteContainers_.push_back(ptr);
3327 }
3328
getNoteContainers() const3329 QList<NoteContainer*> MeasureData::getNoteContainers() const {
3330 return noteContainers_;
3331 }
3332
addMusicData(MusicData * ptr)3333 void MeasureData::addMusicData(MusicData* ptr) {
3334 musicDatas_.push_back(ptr);
3335 }
3336
getMusicDatas(MusicDataType type)3337 QList<MusicData*> MeasureData::getMusicDatas(MusicDataType type) {
3338 int i;
3339 QList<MusicData*> notations;
3340
3341 for (i = 0; i < musicDatas_.size(); ++i) {
3342 if (type == MusicDataType::None || musicDatas_[i]->getMusicDataType() == type) {
3343 notations.push_back(musicDatas_[i]);
3344 }
3345 }
3346
3347 return notations;
3348 }
3349
addCrossMeasureElement(MusicData * ptr,bool start)3350 void MeasureData::addCrossMeasureElement(MusicData* ptr, bool start) {
3351 crossMeasureElements_.push_back(qMakePair(ptr, start));
3352 }
3353
getCrossMeasureElements(MusicDataType type,PairType pairType)3354 QList<MusicData*> MeasureData::getCrossMeasureElements(
3355 MusicDataType type, PairType pairType)
3356 {
3357 int i;
3358 QList<MusicData*> pairs;
3359
3360 for (i = 0; i < crossMeasureElements_.size(); ++i) {
3361 if ((type == MusicDataType::None || crossMeasureElements_[i].first->getMusicDataType() == type)
3362 && (pairType == PairType::All || ((crossMeasureElements_[i].second && pairType == PairType::Start)
3363 || (!crossMeasureElements_[i].second && pairType == PairType::Stop)))) {
3364 pairs.push_back(crossMeasureElements_[i].first);
3365 }
3366 }
3367
3368 return pairs;
3369 }
3370
addMidiData(MidiData * ptr)3371 void MeasureData::addMidiData(MidiData* ptr) {
3372 midiDatas_.push_back(ptr);
3373 }
3374
getMidiDatas(MidiType type)3375 QList<MidiData*> MeasureData::getMidiDatas(MidiType type) {
3376 int i;
3377 QList<MidiData*> datas;
3378
3379 for (i = 0; i < midiDatas_.size(); ++i) {
3380 if (type == MidiType::None || midiDatas_[i]->getMidiType() == type) {
3381 datas.push_back(midiDatas_[i]);
3382 }
3383 }
3384
3385 return datas;
3386 }
3387
3388 //////////////////////////////////////////////////////////////////////////////////////
3389 //////////////////////////////////////////////////////////////////////////////////////
StreamHandle()3390 StreamHandle::StreamHandle() :
3391 size_(0), curPos_(0), point_(NULL) {
3392 }
3393
StreamHandle(unsigned char * p,int size)3394 StreamHandle::StreamHandle(unsigned char* p, int size) :
3395 size_(size), curPos_(0), point_(p) {
3396 }
3397
~StreamHandle()3398 StreamHandle::~StreamHandle() {
3399 point_ = NULL;
3400 }
3401
read(char * buff,int size)3402 bool StreamHandle::read(char* buff, int size) {
3403 if (point_ != NULL && curPos_ + size <= size_) {
3404 memcpy(buff, point_ + curPos_, size);
3405 curPos_ += size;
3406
3407 return true;
3408 }
3409
3410 return false;
3411 }
3412
write(char *,int)3413 bool StreamHandle::write(char* /*buff*/, int /*size*/) {
3414 return true;
3415 }
3416
3417 // Block.cpp
3418 ///////////////////////////////////////////////////////////////////////////////////////////////////
Block()3419 Block::Block() {
3420 doResize(0);
3421 }
3422
Block(unsigned int count)3423 Block::Block(unsigned int count) {
3424 doResize(count);
3425 }
3426
resize(unsigned int count)3427 void Block::resize(unsigned int count) {
3428 doResize(count);
3429 }
3430
doResize(unsigned int count)3431 void Block::doResize(unsigned int count) {
3432 data_.clear();
3433 for(unsigned int i=0; i<count; ++i) {
3434 data_.push_back('\0');
3435 }
3436 //data_.resize(count);
3437 }
3438
data() const3439 const unsigned char* Block::data() const {
3440 //return const_cast<unsigned char*>(&data_.front());
3441 return &data_.front();
3442 }
3443
data()3444 unsigned char* Block::data() {
3445 return &data_.front();
3446 }
3447
size() const3448 int Block::size() const {
3449 return data_.size();
3450 }
3451
toBoolean() const3452 bool Block::toBoolean() const {
3453 if (data() == NULL) {
3454 return false;
3455 }
3456
3457 return size() == 1 && data()[0] == 0x01;
3458 }
3459
toUnsignedInt() const3460 unsigned int Block::toUnsignedInt() const {
3461 if (data() == NULL) {
3462 return 0;
3463 }
3464
3465 int num = 0;
3466
3467 for (int i = 0; i < (int)sizeof(int) && i < size(); ++i) {
3468 num = (num << 8) + *(data() + i);
3469 }
3470
3471 return num;
3472 }
3473
toInt() const3474 int Block::toInt() const {
3475 if (data() == NULL) {
3476 return 0;
3477 }
3478
3479 int i;
3480 int num = 0;
3481
3482 for (i = 0; i < (int)sizeof(int) && i < size(); ++i) {
3483 num = (num << 8) + static_cast<int>(*(data() + i));
3484 }
3485
3486 std::size_t minSize = sizeof(int);
3487 if (size() < static_cast<int>(minSize)) {
3488 minSize = size();
3489 }
3490
3491 if ((*(data()) & 0x80) == 0x80) {
3492 // same as int(pow(2, int(minSize) * 8))
3493 int maxNum = 1 << (static_cast<int>(minSize) * 8);
3494 num -= maxNum;
3495 //num *= -1;
3496 }
3497
3498 return num;
3499 }
3500
toStrByteArray() const3501 QByteArray Block::toStrByteArray() const {
3502 if (data() == NULL) {
3503 return QByteArray();
3504 }
3505
3506 QByteArray arr((char*) data(), size());
3507
3508 return arr;
3509 }
3510
fixedSizeBufferToStrByteArray() const3511 QByteArray Block::fixedSizeBufferToStrByteArray() const {
3512 QByteArray str;
3513
3514 for (int i = 0; i < size(); ++i) {
3515 if (*(data() + i) == '\0') {
3516 break;
3517 }
3518
3519 str += (char) *(data() + i);
3520 }
3521
3522 return str;
3523 }
3524
operator ==(const Block & block) const3525 bool Block::operator ==(const Block& block) const {
3526 if (size() != block.size()) {
3527 return false;
3528 }
3529
3530 for (int i = 0; i < size() && i < block.size(); ++i) {
3531 if (*(data() + i) != *(block.data() + i)) {
3532 return false;
3533 }
3534 }
3535
3536 return true;
3537 }
3538
operator !=(const Block & block) const3539 bool Block::operator !=(const Block& block) const {
3540 return !(*this == block);
3541 }
3542
3543 ///////////////////////////////////////////////////////////////////////////////////////////////////
FixedBlock()3544 FixedBlock::FixedBlock() :
3545 Block() {
3546 }
3547
FixedBlock(unsigned int count)3548 FixedBlock::FixedBlock(unsigned int count) :
3549 Block(count) {
3550 }
3551
resize(unsigned int)3552 void FixedBlock::resize(unsigned int /*count*/) {
3553 // Block::resize(size);
3554 }
3555
3556 ///////////////////////////////////////////////////////////////////////////////////////////////////
SizeBlock()3557 SizeBlock::SizeBlock() :
3558 FixedBlock(4) {
3559 }
3560
toSize() const3561 unsigned int SizeBlock::toSize() const {
3562 unsigned int i;
3563 unsigned int num(0);
3564 const unsigned int SIZE = 4;
3565
3566 for (i = 0; i < SIZE; ++i) {
3567 num = (num << 8) + *(data() + i);
3568 }
3569
3570 return num;
3571 }
3572
3573 /*void SizeBlock::fromUnsignedInt(unsigned int count)
3574 {
3575 unsigned_int_to_char_buffer(count, data());
3576 }*/
3577
3578 ///////////////////////////////////////////////////////////////////////////////////////////////////
NameBlock()3579 NameBlock::NameBlock() :
3580 FixedBlock(4) {
3581 }
3582
3583 /*void NameBlock::setValue(const char* const name)
3584 {
3585 unsigned int i;
3586
3587 for( i=0; i<size() && *(name+i)!='\0'; ++i )
3588 {
3589 *(data()+i) = *(name+i);
3590 }
3591 }*/
3592
isEqual(const QString & name) const3593 bool NameBlock::isEqual(const QString& name) const {
3594 int nsize = name.size();
3595
3596 if (nsize != size()) {
3597 return false;
3598 }
3599
3600 for (int i = 0; i < size() && nsize; ++i) {
3601 if (data()[i] != name[i]) {
3602 return false;
3603 }
3604 }
3605
3606 return true;
3607 }
3608
3609 ///////////////////////////////////////////////////////////////////////////////////////////////////
CountBlock()3610 CountBlock::CountBlock() :
3611 FixedBlock(2) {
3612 }
3613
3614 /*void CountBlock::setValue(unsigned short count)
3615 {
3616 unsigned int i;
3617 unsigned int SIZE = sizeof(unsigned short);
3618
3619 for( i=0; i<SIZE; ++i )
3620 {
3621 data()[SIZE-1-i] = count % 256;
3622 count /= 256;
3623 }
3624 }*/
3625
toCount() const3626 unsigned short CountBlock::toCount() const {
3627 unsigned short num = 0;
3628
3629 for (int i = 0; i < size() && i < (int)sizeof(unsigned short); ++i) {
3630 num = (num << 8) + *(data() + i);
3631 }
3632
3633 return num;
3634 }
3635
3636 // Chunk.cpp
3637 const QString Chunk::TrackName = "TRAK";
3638 const QString Chunk::PageName = "PAGE";
3639 const QString Chunk::LineName = "LINE";
3640 const QString Chunk::StaffName = "STAF";
3641 const QString Chunk::MeasureName = "MEAS";
3642 const QString Chunk::ConductName = "COND";
3643 const QString Chunk::BdatName = "BDAT";
3644
Chunk()3645 Chunk::Chunk() {
3646 }
3647
getName() const3648 NameBlock Chunk::getName() const {
3649 return nameBlock_;
3650 }
3651
3652 ////////////////////////////////////////////////////////////////////////////////
3653 const unsigned int SizeChunk::version3TrackSize = 0x13a;
3654
SizeChunk()3655 SizeChunk::SizeChunk() :
3656 Chunk() {
3657 sizeBlock_ = new SizeBlock();
3658 dataBlock_ = new Block();
3659 }
3660
~SizeChunk()3661 SizeChunk::~SizeChunk() {
3662 delete sizeBlock_;
3663 delete dataBlock_;
3664 }
3665
getSizeBlock() const3666 SizeBlock* SizeChunk::getSizeBlock() const {
3667 return sizeBlock_;
3668 }
3669
getDataBlock() const3670 Block* SizeChunk::getDataBlock() const {
3671 return dataBlock_;
3672 }
3673
3674 /////////////////////////////////////////////////////////////////////////////////
GroupChunk()3675 GroupChunk::GroupChunk() : Chunk() {
3676 childCount_ = new CountBlock();
3677 }
3678
~GroupChunk()3679 GroupChunk::~GroupChunk() {
3680 delete childCount_;
3681 }
3682
getCountBlock() const3683 CountBlock* GroupChunk::getCountBlock() const {
3684 return childCount_;
3685 }
3686
3687 // ChunkParse.cpp
getHighNibble(unsigned int byte)3688 unsigned int getHighNibble(unsigned int byte) {
3689 return byte / 16;
3690 }
3691
getLowNibble(unsigned int byte)3692 unsigned int getLowNibble(unsigned int byte) {
3693 return byte % 16;
3694 }
3695
oveKeyToKey(int oveKey)3696 int oveKeyToKey(int oveKey) {
3697 int key = 0;
3698
3699 if( oveKey == 0 ) {
3700 key = 0;
3701 }
3702 else if( oveKey > 7 ) {
3703 key = oveKey - 7;
3704 }
3705 else if( oveKey <= 7 ) {
3706 key = oveKey * (-1);
3707 }
3708
3709 return key;
3710 }
3711
3712 ///////////////////////////////////////////////////////////////////////////////
BasicParse(OveSong * ove)3713 BasicParse::BasicParse(OveSong* ove) :
3714 ove_(ove), handle_(NULL), notify_(NULL) {
3715 }
3716
BasicParse()3717 BasicParse::BasicParse() :
3718 ove_(NULL), handle_(NULL), notify_(NULL) {
3719 }
3720
~BasicParse()3721 BasicParse::~BasicParse() {
3722 ove_ = NULL;
3723 handle_ = NULL;
3724 notify_ = NULL;
3725 }
3726
setNotify(IOveNotify * notify)3727 void BasicParse::setNotify(IOveNotify* notify) {
3728 notify_ = notify;
3729 }
3730
parse()3731 bool BasicParse::parse() {
3732 return false;
3733 }
3734
readBuffer(Block & placeHolder,int size)3735 bool BasicParse::readBuffer(Block& placeHolder, int size) {
3736 if (handle_ == NULL) {
3737 return false;
3738 }
3739 if (placeHolder.size() != size) {
3740 placeHolder.resize(size);
3741 }
3742
3743 if (size > 0) {
3744 return handle_->read((char*) placeHolder.data(), placeHolder.size());
3745 }
3746
3747 return true;
3748 }
3749
jump(int offset)3750 bool BasicParse::jump(int offset) {
3751 if (handle_ == NULL || offset < 0) {
3752 return false;
3753 }
3754
3755 if (offset > 0) {
3756 Block placeHolder(offset);
3757 return handle_->read((char*) placeHolder.data(), placeHolder.size());
3758 }
3759
3760 return true;
3761 }
3762
messageOut(const QString & str)3763 void BasicParse::messageOut(const QString& str) {
3764 if (notify_ != NULL) {
3765 notify_->loadInfo(str);
3766 }
3767 }
3768
3769 ///////////////////////////////////////////////////////////////////////////////
OvscParse(OveSong * ove)3770 OvscParse::OvscParse(OveSong* ove) :
3771 BasicParse(ove), chunk_(NULL) {
3772 }
3773
~OvscParse()3774 OvscParse::~OvscParse() {
3775 chunk_ = NULL;
3776 }
3777
setOvsc(SizeChunk * chunk)3778 void OvscParse::setOvsc(SizeChunk* chunk) {
3779 chunk_ = chunk;
3780 }
3781
parse()3782 bool OvscParse::parse() {
3783 Block* dataBlock = chunk_->getDataBlock();
3784 unsigned int blockSize = chunk_->getSizeBlock()->toSize();
3785 StreamHandle handle(dataBlock->data(), blockSize);
3786 Block placeHolder;
3787
3788 handle_ = &handle;
3789
3790 // version
3791 if (!readBuffer(placeHolder, 1)) { return false; }
3792 bool version4 = placeHolder.toUnsignedInt() == 4;
3793 ove_->setIsVersion4(version4);
3794
3795 QString str = QString("This file is created by Overture ") + (version4 ? "4" : "3") + "\n";
3796 messageOut(str);
3797
3798 if( !jump(6) ) { return false; }
3799
3800 // show page margin
3801 if (!readBuffer(placeHolder, 1)) { return false; }
3802 ove_->setShowPageMargin(placeHolder.toBoolean());
3803
3804 if( !jump(1) ) { return false; }
3805
3806 // transpose track
3807 if (!readBuffer(placeHolder, 1)) { return false; }
3808 ove_->setShowTransposeTrack(placeHolder.toBoolean());
3809
3810 // play repeat
3811 if (!readBuffer(placeHolder, 1)) { return false; }
3812 ove_->setPlayRepeat(placeHolder.toBoolean());
3813
3814 // play style
3815 if (!readBuffer(placeHolder, 1)) { return false; }
3816 OveSong::PlayStyle style = OveSong::PlayStyle::Record;
3817 if(placeHolder.toUnsignedInt() == 1){
3818 style = OveSong::PlayStyle::Swing;
3819 }
3820 else if(placeHolder.toUnsignedInt() == 2){
3821 style = OveSong::PlayStyle::Notation;
3822 }
3823 ove_->setPlayStyle(style);
3824
3825 // show line break
3826 if (!readBuffer(placeHolder, 1)) { return false; }
3827 ove_->setShowLineBreak(placeHolder.toBoolean());
3828
3829 // show ruler
3830 if (!readBuffer(placeHolder, 1)) { return false; }
3831 ove_->setShowRuler(placeHolder.toBoolean());
3832
3833 // show color
3834 if (!readBuffer(placeHolder, 1)) { return false; }
3835 ove_->setShowColor(placeHolder.toBoolean());
3836
3837 return true;
3838 }
3839
3840 ///////////////////////////////////////////////////////////////////////////////
TrackParse(OveSong * ove)3841 TrackParse::TrackParse(OveSong* ove)
3842 :BasicParse(ove) {
3843 }
3844
~TrackParse()3845 TrackParse::~TrackParse() {
3846 }
3847
setTrack(SizeChunk * chunk)3848 void TrackParse::setTrack(SizeChunk* chunk) {
3849 chunk_ = chunk;
3850 }
3851
parse()3852 bool TrackParse::parse() {
3853 Block* dataBlock = chunk_->getDataBlock();
3854 unsigned int blockSize = ove_->getIsVersion4() ? chunk_->getSizeBlock()->toSize() : SizeChunk::version3TrackSize;
3855 StreamHandle handle(dataBlock->data(), blockSize);
3856 Block placeHolder;
3857
3858 handle_ = &handle;
3859
3860 Track* oveTrack = new Track();
3861 ove_->addTrack(oveTrack);
3862
3863 // 2 32bytes long track name buffer
3864 if( !readBuffer(placeHolder, 32) ) { return false; }
3865 oveTrack->setName(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
3866
3867 if( !readBuffer(placeHolder, 32) ) { return false; }
3868 oveTrack->setBriefName(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
3869
3870 if( !jump(8) ) { return false; } //0x fffa0012 fffa0012
3871 if( !jump(1) ) { return false; }
3872
3873 // patch
3874 if( !readBuffer(placeHolder, 1) ) { return false; }
3875 unsigned int thisByte = placeHolder.toInt();
3876 oveTrack->setPatch(thisByte&0x7f);
3877
3878 // show name
3879 if( !readBuffer(placeHolder, 1) ) { return false; }
3880 oveTrack->setShowName(placeHolder.toBoolean());
3881
3882 // show brief name
3883 if( !readBuffer(placeHolder, 1) ) { return false; }
3884 oveTrack->setShowBriefName(placeHolder.toBoolean());
3885
3886 if( !jump(1) ) { return false; }
3887
3888 // show transpose
3889 if( !readBuffer(placeHolder, 1) ) { return false; }
3890 oveTrack->setShowTranspose(placeHolder.toBoolean());
3891
3892 if( !jump(1) ) { return false; }
3893
3894 // mute
3895 if( !readBuffer(placeHolder, 1) ) { return false; }
3896 oveTrack->setMute(placeHolder.toBoolean());
3897
3898 // solo
3899 if( !readBuffer(placeHolder, 1) ) { return false; }
3900 oveTrack->setSolo(placeHolder.toBoolean());
3901
3902 if( !jump(1) ) { return false; }
3903
3904 // show key each line
3905 if( !readBuffer(placeHolder, 1) ) { return false; }
3906 oveTrack->setShowKeyEachLine(placeHolder.toBoolean());
3907
3908 // voice count
3909 if( !readBuffer(placeHolder, 1) ) { return false; }
3910 oveTrack->setVoiceCount(placeHolder.toUnsignedInt());
3911
3912 if( !jump(3) ) { return false; }
3913
3914 // transpose value [-127, 127]
3915 if( !readBuffer(placeHolder, 1) ) { return false; }
3916 oveTrack->setTranspose(placeHolder.toInt());
3917
3918 if( !jump(2) ) { return false; }
3919
3920 // start clef
3921 if( !readBuffer(placeHolder, 1) ) { return false; }
3922 oveTrack->setStartClef(placeHolder.toUnsignedInt());
3923
3924 // transpose celf
3925 if( !readBuffer(placeHolder, 1) ) { return false; }
3926 oveTrack->setTransposeClef(placeHolder.toUnsignedInt());
3927
3928 // start key
3929 if( !readBuffer(placeHolder, 1) ) { return false; }
3930 oveTrack->setStartKey(placeHolder.toUnsignedInt());
3931
3932 // display percent
3933 if( !readBuffer(placeHolder, 1) ) { return false; }
3934 oveTrack->setDisplayPercent(placeHolder.toUnsignedInt());
3935
3936 // show leger line
3937 if( !readBuffer(placeHolder, 1) ) { return false; }
3938 oveTrack->setShowLegerLine(placeHolder.toBoolean());
3939
3940 // show clef
3941 if( !readBuffer(placeHolder, 1) ) { return false; }
3942 oveTrack->setShowClef(placeHolder.toBoolean());
3943
3944 // show time signature
3945 if( !readBuffer(placeHolder, 1) ) { return false; }
3946 oveTrack->setShowTimeSignature(placeHolder.toBoolean());
3947
3948 // show key signature
3949 if( !readBuffer(placeHolder, 1) ) { return false; }
3950 oveTrack->setShowKeySignature(placeHolder.toBoolean());
3951
3952 // show barline
3953 if( !readBuffer(placeHolder, 1) ) { return false; }
3954 oveTrack->setShowBarline(placeHolder.toBoolean());
3955
3956 // fill with rest
3957 if( !readBuffer(placeHolder, 1) ) { return false; }
3958 oveTrack->setFillWithRest(placeHolder.toBoolean());
3959
3960 // flat tail
3961 if( !readBuffer(placeHolder, 1) ) { return false; }
3962 oveTrack->setFlatTail(placeHolder.toBoolean());
3963
3964 // show clef each line
3965 if( !readBuffer(placeHolder, 1) ) { return false; }
3966 oveTrack->setShowClefEachLine(placeHolder.toBoolean());
3967
3968 if( !jump(12) ) { return false; }
3969
3970 // 8 voices
3971 int i;
3972 QList<Voice*> voices;
3973 for( i=0; i<8; ++i ) {
3974 Voice* voicePtr = new Voice();
3975
3976 if( !jump(5) ) { return false; }
3977
3978 // channel
3979 if( !readBuffer(placeHolder, 1) ) { return false; }
3980 voicePtr->setChannel(placeHolder.toUnsignedInt());
3981
3982 // volume
3983 if( !readBuffer(placeHolder, 1) ) { return false; }
3984 voicePtr->setVolume(placeHolder.toInt());
3985
3986 // pitch shift
3987 if( !readBuffer(placeHolder, 1) ) { return false; }
3988 voicePtr->setPitchShift(placeHolder.toInt());
3989
3990 // pan
3991 if( !readBuffer(placeHolder, 1) ) { return false; }
3992 voicePtr->setPan(placeHolder.toInt());
3993
3994 if( !jump(6) ) { return false; }
3995
3996 // patch
3997 if( !readBuffer(placeHolder, 1) ) { return false; }
3998 voicePtr->setPatch(placeHolder.toInt());
3999
4000 voices.push_back(voicePtr);
4001 }
4002
4003 // stem type
4004 for( i=0; i<8; ++i ) {
4005 if( !readBuffer(placeHolder, 1) ) { return false; }
4006 voices[i]->setStemType(placeHolder.toUnsignedInt());
4007
4008 oveTrack->addVoice(voices[i]);
4009 }
4010
4011 // percussion define
4012 QList<Track::DrumNode> nodes;
4013 for(i=0; i<16; ++i) {
4014 nodes.push_back(Track::DrumNode());
4015 }
4016
4017 // line
4018 for( i=0; i<16; ++i ) {
4019 if( !readBuffer(placeHolder, 1) ) { return false; }
4020 nodes[i].line_ = placeHolder.toInt();
4021 }
4022
4023 // head type
4024 for( i=0; i<16; ++i ) {
4025 if( !readBuffer(placeHolder, 1) ) { return false; }
4026 nodes[i].headType_ = placeHolder.toUnsignedInt();
4027 }
4028
4029 // pitch
4030 for( i=0; i<16; ++i ) {
4031 if( !readBuffer(placeHolder, 1) ) { return false; }
4032 nodes[i].pitch_ = placeHolder.toUnsignedInt();
4033 }
4034
4035 // voice
4036 for( i=0; i<16; ++i ) {
4037 if( !readBuffer(placeHolder, 1) ) { return false; }
4038 nodes[i].voice_ = placeHolder.toUnsignedInt();
4039 }
4040
4041 for( i=0; i<nodes.size(); ++i ) {
4042 oveTrack->addDrum(nodes[i]);
4043 }
4044
4045 /* if( !Jump(17) ) { return false; }
4046
4047 // voice 0 channel
4048 if( !ReadBuffer(placeHolder, 1) ) { return false; }
4049 oveTrack->setChannel(placeHolder.toUnsignedInt());
4050
4051 // to be continued. if anything important...*/
4052
4053 return true;
4054 }
4055
4056 ///////////////////////////////////////////////////////////////////////////////
GroupParse(OveSong * ove)4057 GroupParse::GroupParse(OveSong* ove)
4058 :BasicParse(ove) {
4059 }
4060
~GroupParse()4061 GroupParse::~GroupParse(){
4062 sizeChunks_.clear();
4063 }
4064
addSizeChunk(SizeChunk * sizeChunk)4065 void GroupParse::addSizeChunk(SizeChunk* sizeChunk) {
4066 sizeChunks_.push_back(sizeChunk);
4067 }
4068
parse()4069 bool GroupParse::parse() {
4070 return false;
4071 }
4072
4073 ///////////////////////////////////////////////////////////////////////////////
PageGroupParse(OveSong * ove)4074 PageGroupParse::PageGroupParse(OveSong* ove)
4075 :BasicParse(ove) {
4076 }
4077
~PageGroupParse()4078 PageGroupParse::~PageGroupParse(){
4079 pageChunks_.clear();
4080 }
4081
addPage(SizeChunk * chunk)4082 void PageGroupParse::addPage(SizeChunk* chunk) {
4083 pageChunks_.push_back(chunk);
4084 }
4085
parse()4086 bool PageGroupParse::parse() {
4087 if( pageChunks_.isEmpty() ) {
4088 return false;
4089 }
4090
4091 int i;
4092 for( i=0; i<pageChunks_.size(); ++i ) {
4093 Page* page = new Page();
4094 ove_->addPage(page);
4095
4096 if( !parsePage(pageChunks_[i], page) ) { return false; }
4097 }
4098
4099 return true;
4100 }
4101
parsePage(SizeChunk * chunk,Page * page)4102 bool PageGroupParse::parsePage(SizeChunk* chunk, Page* page) {
4103 Block placeHolder(2);
4104 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
4105
4106 handle_ = &handle;
4107
4108 // begin line
4109 if( !readBuffer(placeHolder, 2) ) { return false; }
4110 page->setBeginLine(placeHolder.toUnsignedInt());
4111
4112 // line count
4113 if( !readBuffer(placeHolder, 2) ) { return false; }
4114 page->setLineCount(placeHolder.toUnsignedInt());
4115
4116 if( !jump(4) ) { return false; }
4117
4118 // staff interval
4119 if( !readBuffer(placeHolder, 2) ) { return false; }
4120 page->setStaffInterval(placeHolder.toUnsignedInt());
4121
4122 // line interval
4123 if( !readBuffer(placeHolder, 2) ) { return false; }
4124 page->setLineInterval(placeHolder.toUnsignedInt());
4125
4126 // staff inline interval
4127 if( !readBuffer(placeHolder, 2) ) { return false; }
4128 page->setStaffInlineInterval(placeHolder.toUnsignedInt());
4129
4130 // line bar count
4131 if( !readBuffer(placeHolder, 2) ) { return false; }
4132 page->setLineBarCount(placeHolder.toUnsignedInt());
4133
4134 // page line count
4135 if( !readBuffer(placeHolder, 2) ) { return false; }
4136 page->setPageLineCount(placeHolder.toUnsignedInt());
4137
4138 // left margin
4139 if( !readBuffer(placeHolder, 4) ) { return false; }
4140 page->setLeftMargin(placeHolder.toUnsignedInt());
4141
4142 // top margin
4143 if( !readBuffer(placeHolder, 4) ) { return false; }
4144 page->setTopMargin(placeHolder.toUnsignedInt());
4145
4146 // right margin
4147 if( !readBuffer(placeHolder, 4) ) { return false; }
4148 page->setRightMargin(placeHolder.toUnsignedInt());
4149
4150 // bottom margin
4151 if( !readBuffer(placeHolder, 4) ) { return false; }
4152 page->setBottomMargin(placeHolder.toUnsignedInt());
4153
4154 // page width
4155 if( !readBuffer(placeHolder, 4) ) { return false; }
4156 page->setPageWidth(placeHolder.toUnsignedInt());
4157
4158 // page height
4159 if( !readBuffer(placeHolder, 4) ) { return false; }
4160 page->setPageHeight(placeHolder.toUnsignedInt());
4161
4162 handle_ = NULL;
4163
4164 return true;
4165 }
4166
4167 ///////////////////////////////////////////////////////////////////////////////
StaffCountGetter(OveSong * ove)4168 StaffCountGetter::StaffCountGetter(OveSong* ove)
4169 :BasicParse(ove) {
4170 }
4171
getStaffCount(SizeChunk * chunk)4172 unsigned int StaffCountGetter::getStaffCount(SizeChunk* chunk) {
4173 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
4174 Block placeHolder;
4175
4176 handle_ = &handle;
4177
4178 if( !jump(6) ) { return false; }
4179
4180 // staff count
4181 if( !readBuffer(placeHolder, 2) ) { return false; }
4182 return placeHolder.toUnsignedInt();
4183 }
4184
4185 ///////////////////////////////////////////////////////////////////////////////
LineGroupParse(OveSong * ove)4186 LineGroupParse::LineGroupParse(OveSong* ove) :
4187 BasicParse(ove), chunk_(NULL) {
4188 }
4189
~LineGroupParse()4190 LineGroupParse::~LineGroupParse(){
4191 chunk_ = NULL;
4192 lineChunks_.clear();
4193 staffChunks_.clear();
4194 }
4195
setLineGroup(GroupChunk * chunk)4196 void LineGroupParse::setLineGroup(GroupChunk* chunk) {
4197 chunk_ = chunk;
4198 }
4199
addLine(SizeChunk * chunk)4200 void LineGroupParse::addLine(SizeChunk* chunk) {
4201 lineChunks_.push_back(chunk);
4202 }
4203
addStaff(SizeChunk * chunk)4204 void LineGroupParse::addStaff(SizeChunk* chunk) {
4205 staffChunks_.push_back(chunk);
4206 }
4207
parse()4208 bool LineGroupParse::parse() {
4209 if( lineChunks_.isEmpty() || staffChunks_.size() % lineChunks_.size() != 0 ) { return false; }
4210
4211 int i;
4212 unsigned int j;
4213 unsigned int lineStaffCount = staffChunks_.size() / lineChunks_.size();
4214
4215 for( i=0; i<lineChunks_.size(); ++i ) {
4216 Line* linePtr = new Line();
4217
4218 ove_->addLine(linePtr);
4219
4220 if( !parseLine(lineChunks_[i], linePtr) ) { return false; }
4221
4222 for( j=lineStaffCount*i; j<lineStaffCount*(i+1); ++j ) {
4223 Staff* staffPtr = new Staff();
4224
4225 linePtr->addStaff(staffPtr);
4226
4227 if( !parseStaff(staffChunks_[j], staffPtr) ) { return false; }
4228 }
4229 }
4230
4231 return true;
4232 }
4233
parseLine(SizeChunk * chunk,Line * line)4234 bool LineGroupParse::parseLine(SizeChunk* chunk, Line* line) {
4235 Block placeHolder;
4236
4237 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
4238
4239 handle_ = &handle;
4240
4241 if( !jump(2) ) { return false; }
4242
4243 // begin bar
4244 if( !readBuffer(placeHolder, 2) ) { return false; }
4245 line->setBeginBar(placeHolder.toUnsignedInt());
4246
4247 // bar count
4248 if( !readBuffer(placeHolder, 2) ) { return false; }
4249 line->setBarCount(placeHolder.toUnsignedInt());
4250
4251 if( !jump(6) ) { return false; }
4252
4253 // y offset
4254 if( !readBuffer(placeHolder, 2) ) { return false; }
4255 line->setYOffset(placeHolder.toInt());
4256
4257 // left x offset
4258 if( !readBuffer(placeHolder, 2) ) { return false; }
4259 line->setLeftXOffset(placeHolder.toInt());
4260
4261 // right x offset
4262 if( !readBuffer(placeHolder, 2) ) { return false; }
4263 line->setRightXOffset(placeHolder.toInt());
4264
4265 if( !jump(4) ) { return false; }
4266
4267 handle_ = NULL;
4268
4269 return true;
4270 }
4271
parseStaff(SizeChunk * chunk,Staff * staff)4272 bool LineGroupParse::parseStaff(SizeChunk* chunk, Staff* staff) {
4273 Block placeHolder;
4274
4275 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
4276
4277 handle_ = &handle;
4278
4279 if( !jump(7) ) { return false; }
4280
4281 // clef
4282 if( !readBuffer(placeHolder, 1) ) { return false; }
4283 staff->setClefType(placeHolder.toUnsignedInt());
4284
4285 // key
4286 if( !readBuffer(placeHolder, 1) ) { return false; }
4287 staff->setKeyType(oveKeyToKey(placeHolder.toUnsignedInt()));
4288
4289 if( !jump(2) ) { return false; }
4290
4291 // visible
4292 if( !readBuffer(placeHolder, 1) ) { return false; }
4293 staff->setVisible(placeHolder.toBoolean());
4294
4295 if( !jump(12) ) { return false; }
4296
4297 // y offset
4298 if( !readBuffer(placeHolder, 2) ) { return false; }
4299 staff->setYOffset(placeHolder.toInt());
4300
4301 int jumpAmount = ove_->getIsVersion4() ? 26 : 18;
4302 if( !jump(jumpAmount) ) { return false; }
4303
4304 // group type
4305 if( !readBuffer(placeHolder, 1) ) { return false; }
4306 GroupType groupType = GroupType::None;
4307 if(placeHolder.toUnsignedInt() == 1) {
4308 groupType = GroupType::Brace;
4309 } else if(placeHolder.toUnsignedInt() == 2) {
4310 groupType = GroupType::Bracket;
4311 }
4312 staff->setGroupType(groupType);
4313
4314 // group staff count
4315 if( !readBuffer(placeHolder, 1) ) { return false; }
4316 staff->setGroupStaffCount(placeHolder.toUnsignedInt());
4317
4318 handle_ = NULL;
4319
4320 return true;
4321 }
4322
4323 ///////////////////////////////////////////////////////////////////////////////
BarsParse(OveSong * ove)4324 BarsParse::BarsParse(OveSong* ove) :
4325 BasicParse(ove) {
4326 }
4327
~BarsParse()4328 BarsParse::~BarsParse(){
4329 measureChunks_.clear();
4330 conductChunks_.clear();
4331 bdatChunks_.clear();
4332 }
4333
addMeasure(SizeChunk * chunk)4334 void BarsParse::addMeasure(SizeChunk* chunk) {
4335 measureChunks_.push_back(chunk);
4336 }
4337
addConduct(SizeChunk * chunk)4338 void BarsParse::addConduct(SizeChunk* chunk) {
4339 conductChunks_.push_back(chunk);
4340 }
4341
addBdat(SizeChunk * chunk)4342 void BarsParse::addBdat(SizeChunk* chunk) {
4343 bdatChunks_.push_back(chunk);
4344 }
4345
parse()4346 bool BarsParse::parse() {
4347 int i;
4348 int trackMeasureCount = ove_->getTrackBarCount();
4349 int trackCount = ove_->getTrackCount();
4350 int measureDataCount = trackCount * measureChunks_.size();
4351 QList<Measure*> measures;
4352 QList<MeasureData*> measureDatas;
4353
4354 if (measureChunks_.isEmpty() ||
4355 measureChunks_.size() != conductChunks_.size() ||
4356 bdatChunks_.size() != measureDataCount) {
4357 return false;
4358 }
4359
4360 // add to ove
4361 for ( i = 0; i < measureChunks_.size(); ++i ) {
4362 Measure* measure = new Measure(i);
4363
4364 measures.push_back(measure);
4365 ove_->addMeasure(measure);
4366 }
4367
4368 for ( i = 0; i < measureDataCount; ++i ) {
4369 MeasureData* oveMeasureData = new MeasureData();
4370
4371 measureDatas.push_back(oveMeasureData);
4372 ove_->addMeasureData(oveMeasureData);
4373 }
4374
4375 for ( i = 0; i < measureChunks_.size(); ++i ) {
4376 Measure* measure = measures[i];
4377
4378 // MEAS
4379 if( !parseMeas(measure, measureChunks_[i]) ) {
4380 QString ss = QString("failed in parse MEAS %1\n").arg(i);
4381 messageOut(ss);
4382
4383 return false;
4384 }
4385 }
4386
4387 for ( i = 0; i < conductChunks_.size(); ++i ) {
4388 // COND
4389 if( !parseCond(measures[i], measureDatas[i], conductChunks_[i]) ) {
4390 QString ss = QString("failed in parse COND %1\n").arg(i);
4391 messageOut(ss);
4392
4393 return false;
4394 }
4395 }
4396
4397 for ( i = 0; i < bdatChunks_.size(); ++i ) {
4398 int measId = i % trackMeasureCount;
4399
4400 // BDAT
4401 if( !parseBdat(measures[measId], measureDatas[i], bdatChunks_[i]) ) {
4402 QString ss = QString("failed in parse BDAT %1\n").arg(i);
4403 messageOut(ss);
4404
4405 return false;
4406 }
4407
4408 if( notify_ != NULL ) {
4409 int measureID = i % trackMeasureCount;
4410 int trackID = i / trackMeasureCount;
4411
4412 //msg.msg_ = OVE_IMPORT_POS;
4413 //msg.param1_ = (measureID<<16) + trackMeasureCount;
4414 //msg.param2_ = (trackID<<16) + trackCount;
4415
4416 notify_->loadPosition(measureID, trackMeasureCount, trackID, trackCount);
4417 }
4418 }
4419
4420 return true;
4421 }
4422
parseMeas(Measure * measure,SizeChunk * chunk)4423 bool BarsParse::parseMeas(Measure* measure, SizeChunk* chunk) {
4424 Block placeHolder;
4425
4426 StreamHandle measureHandle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
4427
4428 handle_ = &measureHandle;
4429
4430 if( !jump(2) ) { return false; }
4431
4432 // multi-measure rest
4433 if( !readBuffer(placeHolder, 1) ) { return false; }
4434 measure->setIsMultiMeasureRest(placeHolder.toBoolean());
4435
4436 // pickup
4437 if( !readBuffer(placeHolder, 1) ) { return false; }
4438 measure->setIsPickup(placeHolder.toBoolean());
4439
4440 if( !jump(4) ) { return false; }
4441
4442 // left barline
4443 if( !readBuffer(placeHolder, 1) ) { return false; }
4444 measure->setLeftBarline(placeHolder.toUnsignedInt());
4445
4446 // right barline
4447 if( !readBuffer(placeHolder, 1) ) { return false; }
4448 measure->setRightBarline(placeHolder.toUnsignedInt());
4449
4450 // tempo
4451 if( !readBuffer(placeHolder, 2) ) { return false; }
4452 double tempo = ((double)placeHolder.toUnsignedInt());
4453 if( ove_->getIsVersion4() ) {
4454 tempo /= 100.0;
4455 }
4456 measure->setTypeTempo(tempo);
4457
4458 // bar length(tick)
4459 if( !readBuffer(placeHolder, 2) ) { return false; }
4460 measure->setLength(placeHolder.toUnsignedInt());
4461
4462 if( !jump(6) ) { return false; }
4463
4464 // bar number offset
4465 if( !parseOffsetElement(measure->getBarNumber()) ) { return false; }
4466
4467 if( !jump(2) ) { return false; }
4468
4469 // multi-measure rest count
4470 if( !readBuffer(placeHolder, 2) ) { return false; }
4471 measure->setMultiMeasureRestCount(placeHolder.toUnsignedInt());
4472
4473 handle_ = NULL;
4474
4475 return true;
4476 }
4477
parseCond(Measure * measure,MeasureData * measureData,SizeChunk * chunk)4478 bool BarsParse::parseCond(Measure* measure, MeasureData* measureData, SizeChunk* chunk) {
4479 Block placeHolder;
4480
4481 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
4482
4483 handle_ = &handle;
4484
4485 // item count
4486 if( !readBuffer(placeHolder, 2) ) { return false; }
4487 unsigned int cnt = placeHolder.toUnsignedInt();
4488
4489 if( !parseTimeSignature(measure, 36) ) { return false; }
4490
4491 for( unsigned int i=0; i<cnt; ++i ) {
4492 if( !readBuffer(placeHolder, 2) ) { return false; }
4493 unsigned int twoByte = placeHolder.toUnsignedInt();
4494 unsigned int oldBlockSize = twoByte - 11;
4495 unsigned int newBlockSize = twoByte - 7;
4496
4497 // type id
4498 if( !readBuffer(placeHolder, 1) ) { return false; }
4499 unsigned int thisByte = placeHolder.toUnsignedInt();
4500 CondType type;
4501
4502 if( !getCondElementType(thisByte, type) ) { return false; }
4503
4504 switch (type) {
4505 case CondType::Bar_Number: {
4506 if (!parseBarNumber(measure, twoByte - 1)) {
4507 return false;
4508 }
4509 break;
4510 }
4511 case CondType::Repeat: {
4512 if (!parseRepeatSymbol(measureData, oldBlockSize)) {
4513 return false;
4514 }
4515 break;
4516 }
4517 case CondType::Numeric_Ending: {
4518 if (!parseNumericEndings(measureData, oldBlockSize)) {
4519 return false;
4520 }
4521 break;
4522 }
4523 case CondType::Decorator: {
4524 if (!parseDecorators(measureData, newBlockSize)) {
4525 return false;
4526 }
4527 break;
4528 }
4529 case CondType::Tempo: {
4530 if (!parseTempo(measureData, newBlockSize)) {
4531 return false;
4532 }
4533 break;
4534 }
4535 case CondType::Text: {
4536 if (!parseText(measureData, newBlockSize)) {
4537 return false;
4538 }
4539 break;
4540 }
4541 case CondType::Expression: {
4542 if (!parseExpressions(measureData, newBlockSize)) {
4543 return false;
4544 }
4545 break;
4546 }
4547 case CondType::Time_Parameters: {
4548 if (!parseTimeSignatureParameters(measure, newBlockSize)) {
4549 return false;
4550 }
4551 break;
4552 }
4553 case CondType::Barline_Parameters: {
4554 if (!parseBarlineParameters(measure, newBlockSize)) {
4555 return false;
4556 }
4557 break;
4558 }
4559 default: {
4560 if (!jump(newBlockSize)) {
4561 return false;
4562 }
4563 break;
4564 }
4565 }
4566 }
4567
4568 handle_ = NULL;
4569
4570 return true;
4571 }
4572
parseTimeSignature(Measure * measure,int)4573 bool BarsParse::parseTimeSignature(Measure* measure, int /*length*/) {
4574 Block placeHolder;
4575
4576 TimeSignature* timeSignature = measure->getTime();
4577
4578 // numerator
4579 if( !readBuffer(placeHolder, 1) ) { return false; }
4580 timeSignature->setNumerator(placeHolder.toUnsignedInt());
4581
4582 // denominator
4583 if( !readBuffer(placeHolder, 1) ) { return false; }
4584 timeSignature->setDenominator(placeHolder.toUnsignedInt());
4585
4586 if( !jump(2) ) { return false; }
4587
4588 // beat length
4589 if( !readBuffer(placeHolder, 2) ) { return false; }
4590 timeSignature->setBeatLength(placeHolder.toUnsignedInt());
4591
4592 // bar length
4593 if( !readBuffer(placeHolder, 2) ) { return false; }
4594 timeSignature->setBarLength(placeHolder.toUnsignedInt());
4595
4596 if( !jump(4) ) { return false; }
4597
4598 // is symbol
4599 if( !readBuffer(placeHolder, 1) ) { return false; }
4600 timeSignature->setIsSymbol(placeHolder.toBoolean());
4601
4602 if( !jump(1) ) { return false; }
4603
4604 // replace font
4605 if( !readBuffer(placeHolder, 1) ) { return false; }
4606 timeSignature->setReplaceFont(placeHolder.toBoolean());
4607
4608 // color
4609 if( !readBuffer(placeHolder, 1) ) { return false; }
4610 timeSignature->setColor(placeHolder.toUnsignedInt());
4611
4612 // show
4613 if( !readBuffer(placeHolder, 1) ) { return false; }
4614 timeSignature->setShow(placeHolder.toBoolean());
4615
4616 // show beat group
4617 if( !readBuffer(placeHolder, 1) ) { return false; }
4618 timeSignature->setShowBeatGroup(placeHolder.toBoolean());
4619
4620 if( !jump(6) ) { return false; }
4621
4622 // numerator 1, 2, 3
4623 if( !readBuffer(placeHolder, 1) ) { return false; }
4624 timeSignature->setGroupNumerator1(placeHolder.toUnsignedInt());
4625 if( !readBuffer(placeHolder, 1) ) { return false; }
4626 timeSignature->setGroupNumerator2(placeHolder.toUnsignedInt());
4627 if( !readBuffer(placeHolder, 1) ) { return false; }
4628 timeSignature->setGroupNumerator3(placeHolder.toUnsignedInt());
4629
4630 // denominator
4631 if( !readBuffer(placeHolder, 1) ) { return false; }
4632 timeSignature->setGroupDenominator1(placeHolder.toUnsignedInt());
4633 if( !readBuffer(placeHolder, 1) ) { return false; }
4634 timeSignature->setGroupDenominator2(placeHolder.toUnsignedInt());
4635 if( !readBuffer(placeHolder, 1) ) { return false; }
4636 timeSignature->setGroupDenominator3(placeHolder.toUnsignedInt());
4637
4638 // beam group 1~4
4639 if( !readBuffer(placeHolder, 1) ) { return false; }
4640 timeSignature->setBeamGroup1(placeHolder.toUnsignedInt());
4641 if( !readBuffer(placeHolder, 1) ) { return false; }
4642 timeSignature->setBeamGroup2(placeHolder.toUnsignedInt());
4643 if( !readBuffer(placeHolder, 1) ) { return false; }
4644 timeSignature->setBeamGroup3(placeHolder.toUnsignedInt());
4645 if( !readBuffer(placeHolder, 1) ) { return false; }
4646 timeSignature->setBeamGroup4(placeHolder.toUnsignedInt());
4647
4648 // beam 16th
4649 if( !readBuffer(placeHolder, 1) ) { return false; }
4650 timeSignature->set16thBeamCount(placeHolder.toUnsignedInt());
4651
4652 // beam 32th
4653 if( !readBuffer(placeHolder, 1) ) { return false; }
4654 timeSignature->set32thBeamCount(placeHolder.toUnsignedInt());
4655
4656 return true;
4657 }
4658
parseTimeSignatureParameters(Measure * measure,int length)4659 bool BarsParse::parseTimeSignatureParameters(Measure* measure, int length) {
4660 Block placeHolder;
4661 TimeSignature* ts = measure->getTime();
4662
4663 int cursor = ove_->getIsVersion4() ? 10 : 8;
4664 if( !jump(cursor) ) { return false; }
4665
4666 // numerator
4667 if( !readBuffer(placeHolder, 1) ) { return false; }
4668 unsigned int numerator = placeHolder.toUnsignedInt();
4669
4670 cursor = ove_->getIsVersion4() ? 11 : 9;
4671 if( ( length - cursor ) % 8 != 0 || (length - cursor) / 8 != (int)numerator ) {
4672 return false;
4673 }
4674
4675 for( unsigned int i =0; i<numerator; ++i ) {
4676 // beat start unit
4677 if( !readBuffer(placeHolder, 2) ) { return false; }
4678 int beatStart = placeHolder.toUnsignedInt();
4679
4680 // beat length unit
4681 if( !readBuffer(placeHolder, 2) ) { return false; }
4682 int beatLength = placeHolder.toUnsignedInt();
4683
4684 if( !jump(2) ) { return false; }
4685
4686 // beat start tick
4687 if( !readBuffer(placeHolder, 2) ) { return false; }
4688 int beatStartTick = placeHolder.toUnsignedInt();
4689
4690 ts->addBeat(beatStart, beatLength, beatStartTick);
4691 }
4692
4693 ts->endAddBeat();
4694
4695 return true;
4696 }
4697
parseBarlineParameters(Measure * measure,int)4698 bool BarsParse::parseBarlineParameters(Measure* measure, int /*length*/) {
4699 Block placeHolder;
4700
4701 int cursor = ove_->getIsVersion4() ? 12 : 10;
4702 if( !jump(cursor) ) { return false; }
4703
4704 // repeat count
4705 if( !readBuffer(placeHolder, 1) ) { return false; }
4706 int repeatCount = placeHolder.toUnsignedInt();
4707
4708 measure->setBackwardRepeatCount(repeatCount);
4709
4710 if( !jump(6) ) { return false; }
4711
4712 return true;
4713 }
4714
parseNumericEndings(MeasureData * measureData,int)4715 bool BarsParse::parseNumericEndings(MeasureData* measureData, int /*length*/) {
4716 Block placeHolder;
4717
4718 NumericEnding* numeric = new NumericEnding();
4719 measureData->addCrossMeasureElement(numeric, true);
4720
4721 if( !jump(3) ) { return false; }
4722
4723 // common
4724 if( !parseCommonBlock(numeric) ) { return false; }
4725
4726 if( !jump(6) ) { return false; }
4727
4728 // measure count
4729 if( !readBuffer(placeHolder, 2) ) { return false; }
4730 //int offsetMeasure = placeHolder.toUnsignedInt() - 1;
4731 int offsetMeasure = placeHolder.toUnsignedInt();
4732 numeric->stop()->setMeasure(offsetMeasure);
4733
4734 if( !jump(2) ) { return false; }
4735
4736 // left x offset
4737 if( !readBuffer(placeHolder, 2) ) { return false; }
4738 numeric->getLeftShoulder()->setXOffset(placeHolder.toInt());
4739
4740 // height
4741 if( !readBuffer(placeHolder, 2) ) { return false; }
4742 numeric->setHeight(placeHolder.toUnsignedInt());
4743
4744 // left x offset
4745 if( !readBuffer(placeHolder, 2) ) { return false; }
4746 numeric->getRightShoulder()->setXOffset(placeHolder.toInt());
4747
4748 if( !jump(2) ) { return false; }
4749
4750 // y offset
4751 if( !readBuffer(placeHolder, 2) ) { return false; }
4752 numeric->getLeftShoulder()->setYOffset(placeHolder.toInt());
4753 numeric->getRightShoulder()->setYOffset(placeHolder.toInt());
4754
4755 // number offset
4756 if( !readBuffer(placeHolder, 2) ) { return false; }
4757 numeric->getNumericHandle()->setXOffset(placeHolder.toInt());
4758 if( !readBuffer(placeHolder, 2) ) { return false; }
4759 numeric->getNumericHandle()->setYOffset(placeHolder.toInt());
4760
4761 if( !jump(6) ) { return false; }
4762
4763 // text size
4764 if( !readBuffer(placeHolder, 1) ) { return false; }
4765 unsigned int size = placeHolder.toUnsignedInt();
4766
4767 // text : size maybe a huge value
4768 if( !readBuffer(placeHolder, size) ) { return false; }
4769 numeric->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
4770
4771 // fix for wedding march.ove
4772 if( size % 2 == 0 ) {
4773 if( !jump(1) ) { return false; }
4774 }
4775
4776 return true;
4777 }
4778
parseTempo(MeasureData * measureData,int)4779 bool BarsParse::parseTempo(MeasureData* measureData, int /*length*/) {
4780 Block placeHolder;
4781 unsigned int thisByte;
4782
4783 Tempo* tempo = new Tempo();
4784 measureData->addMusicData(tempo);
4785 if( !jump(3) )
4786 return false;
4787 // common
4788 if( !parseCommonBlock(tempo) )
4789 return false;
4790 if( !readBuffer(placeHolder, 1) )
4791 return false;
4792 thisByte = placeHolder.toUnsignedInt();
4793 // show tempo
4794 tempo->setShowMark( (getHighNibble(thisByte) & 0x4) == 0x4 );
4795 // show before text
4796 tempo->setShowBeforeText( (getHighNibble(thisByte) & 0x8 ) == 0x8 ) ;
4797 // show parenthesis
4798 tempo->setShowParenthesis( (getHighNibble(thisByte) & 0x1 ) == 0x1 );
4799 // left note type
4800 tempo->setLeftNoteType( getLowNibble(thisByte) );
4801 // left note dot
4802 tempo->setLeftNoteDot((getHighNibble(thisByte) & 0x2 ) == 0x2 );
4803 if( !jump(1) ) // dimension of the note symbol
4804 return false;
4805 if( ove_->getIsVersion4() ) {
4806 if( !jump(2) )
4807 return false;
4808 // tempo
4809 if( !readBuffer(placeHolder, 2) )
4810 return false;
4811 tempo->setTypeTempo(((double)placeHolder.toUnsignedInt())/100.0);
4812 }
4813 else {
4814 // tempo
4815 if( !readBuffer(placeHolder, 2) )
4816 return false;
4817 tempo->setTypeTempo((double)placeHolder.toUnsignedInt());
4818 if( !jump(2) )
4819 return false;
4820 }
4821 // offset
4822 if( !parseOffsetElement(tempo) )
4823 return false;
4824 if( !jump(16) )
4825 return false;
4826 // 31 bytes left text
4827 if( !readBuffer(placeHolder, 31) )
4828 return false;
4829 tempo->setLeftText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
4830
4831 if( !readBuffer(placeHolder, 1) )
4832 return false;
4833 thisByte = placeHolder.toUnsignedInt();
4834 // swing eighth
4835 tempo->setSwingEighth((getHighNibble(thisByte) & 0x4 ) == 0x4 );
4836 // right note dot
4837 tempo->setRightNoteDot((getHighNibble(thisByte) & 0x1 ) == 0x1 );
4838 // compatibility with v3 files ?
4839 tempo->setRightSideType(static_cast<int>(getHighNibble(thisByte) & 0x2));
4840 // right note type
4841 tempo->setRightNoteType(getLowNibble(thisByte));
4842 // right text
4843 if( ove_->getIsVersion4() ) {
4844 if( !readBuffer(placeHolder, 31) )
4845 return false;
4846 tempo->setRightText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
4847 if( !readBuffer(placeHolder, 1) )
4848 return false;
4849 // 00 -> float 03 -> integer(floor) 01 -> notetype 02 -> text
4850 tempo->setRightSideType(placeHolder.toInt());
4851 }
4852
4853 return true;
4854 }
4855
parseBarNumber(Measure * measure,int)4856 bool BarsParse::parseBarNumber(Measure* measure, int /*length*/) {
4857 Block placeHolder;
4858
4859 BarNumber* barNumber = measure->getBarNumber();
4860
4861 if( !jump(2) ) { return false; }
4862
4863 // show on paragraph start
4864 if( !readBuffer(placeHolder, 1) ) { return false; }
4865 barNumber->setShowOnParagraphStart(getLowNibble(placeHolder.toUnsignedInt())==8);
4866
4867 unsigned int blankSize = ove_->getIsVersion4() ? 9 : 7;
4868 if( !jump(blankSize) ) { return false; }
4869
4870 // text align
4871 if( !readBuffer(placeHolder, 1) ) { return false; }
4872 barNumber->setAlign(placeHolder.toUnsignedInt());
4873
4874 if( !jump(4) ) { return false; }
4875
4876 // show flag
4877 if( !readBuffer(placeHolder, 1) ) { return false; }
4878 barNumber->setShowFlag(placeHolder.toUnsignedInt());
4879
4880 if( !jump(10) ) { return false; }
4881
4882 // bar range
4883 if( !readBuffer(placeHolder, 1) ) { return false; }
4884 barNumber->setShowEveryBarCount(placeHolder.toUnsignedInt());
4885
4886 // prefix
4887 if( !readBuffer(placeHolder, 2) ) { return false; }
4888 barNumber->setPrefix(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
4889
4890 if( !jump(18) ) { return false; }
4891
4892 return true;
4893 }
4894
parseText(MeasureData * measureData,int length)4895 bool BarsParse::parseText(MeasureData* measureData, int length) {
4896 Block placeHolder;
4897
4898 Text* text = new Text();
4899 measureData->addMusicData(text);
4900
4901 if( !jump(3) ) { return false; }
4902
4903 // common
4904 if( !parseCommonBlock(text) ) { return false; }
4905
4906 // type
4907 if( !readBuffer(placeHolder, 1) ) { return false; }
4908 unsigned int thisByte = placeHolder.toUnsignedInt();
4909 bool includeLineBreak = ( (getHighNibble(thisByte)&0x2) != 0x2 );
4910 unsigned int id = getLowNibble(thisByte);
4911 Text::Type textType = Text::Type::Rehearsal;
4912
4913 if (id == 0) {
4914 textType = Text::Type::MeasureText;
4915 } else if (id == 1) {
4916 textType = Text::Type::SystemText;
4917 } else // id ==2
4918 {
4919 textType = Text::Type::Rehearsal;
4920 }
4921
4922 text->setTextType(textType);
4923
4924 if( !jump(1) ) { return false; }
4925
4926 // x offset
4927 if( !readBuffer(placeHolder, 4) ) { return false; }
4928 text->setXOffset(placeHolder.toInt());
4929
4930 // y offset
4931 if( !readBuffer(placeHolder, 4) ) { return false; }
4932 text->setYOffset(placeHolder.toInt());
4933
4934 // width
4935 if( !readBuffer(placeHolder, 4) ) { return false; }
4936 text->setWidth(placeHolder.toUnsignedInt());
4937
4938 // height
4939 if( !readBuffer(placeHolder, 4) ) { return false; }
4940 text->setHeight(placeHolder.toUnsignedInt());
4941
4942 if( !jump(7) ) { return false; }
4943
4944 // horizontal margin
4945 if( !readBuffer(placeHolder, 1) ) { return false; }
4946 text->setHorizontalMargin(placeHolder.toUnsignedInt());
4947
4948 if( !jump(1) ) { return false; }
4949
4950 // vertical margin
4951 if( !readBuffer(placeHolder, 1) ) { return false; }
4952 text->setVerticalMargin(placeHolder.toUnsignedInt());
4953
4954 if( !jump(1) ) { return false; }
4955
4956 // line thick
4957 if( !readBuffer(placeHolder, 1) ) { return false; }
4958 text->setLineThick(placeHolder.toUnsignedInt());
4959
4960 if( !jump(2) ) { return false; }
4961
4962 // text size
4963 if( !readBuffer(placeHolder, 2) ) { return false; }
4964 unsigned int size = placeHolder.toUnsignedInt();
4965
4966 // text string, maybe huge
4967 if( !readBuffer(placeHolder, size) ) { return false; }
4968 text->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
4969
4970 if( !includeLineBreak ) {
4971 if( !jump(6) ) { return false; }
4972 } else {
4973 unsigned int cursor = ove_->getIsVersion4() ? 43 : 41;
4974 cursor += size;
4975
4976 // multi lines of text
4977 for( unsigned int i=0; i<2; ++i ) {
4978 if( (int)cursor < length ) {
4979 // line parameters count
4980 if( !readBuffer(placeHolder, 2) ) { return false; }
4981 unsigned int lineCount = placeHolder.toUnsignedInt();
4982
4983 if( i==0 && int(cursor + 2 + 8*lineCount) > length ) {
4984 return false;
4985 }
4986
4987 if( i==1 && int(cursor + 2 + 8*lineCount) != length ) {
4988 return false;
4989 }
4990
4991 if( !jump(8*lineCount) ) { return false; }
4992
4993 cursor += 2 + 8*lineCount;
4994 }
4995 }
4996 }
4997
4998 return true;
4999 }
5000
parseRepeatSymbol(MeasureData * measureData,int)5001 bool BarsParse::parseRepeatSymbol(MeasureData* measureData, int /*length*/) {
5002 Block placeHolder;
5003
5004 RepeatSymbol* repeat = new RepeatSymbol();
5005 measureData->addMusicData(repeat);
5006
5007 if( !jump(3) ) { return false; }
5008
5009 // common
5010 if( !parseCommonBlock(repeat) ) { return false; }
5011
5012 // RepeatType
5013 if( !readBuffer(placeHolder, 1) ) { return false; }
5014 repeat->setRepeatType(placeHolder.toUnsignedInt());
5015
5016 if( !jump(13) ) { return false; }
5017
5018 // offset
5019 if( !parseOffsetElement(repeat) ) { return false; }
5020
5021 if( !jump(15) ) { return false; }
5022
5023 // size
5024 if( !readBuffer(placeHolder, 2) ) { return false; }
5025 unsigned int size = placeHolder.toUnsignedInt();
5026
5027 // text, maybe huge
5028 if( !readBuffer(placeHolder, size) ) { return false; }
5029 repeat->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
5030
5031 // last 0
5032 if( size % 2 == 0 ) {
5033 if( !jump(1) ) { return false; }
5034 }
5035
5036 return true;
5037 }
5038
parseBdat(Measure *,MeasureData * measureData,SizeChunk * chunk)5039 bool BarsParse::parseBdat(Measure* /*measure*/, MeasureData* measureData, SizeChunk* chunk) {
5040 Block placeHolder;
5041 StreamHandle handle(chunk->getDataBlock()->data(), chunk->getSizeBlock()->toSize());
5042
5043 handle_ = &handle;
5044
5045 // parse here
5046 if( !readBuffer(placeHolder, 2) ) { return false; }
5047 unsigned int cnt = placeHolder.toUnsignedInt();
5048
5049 for( unsigned int i=0; i<cnt; ++i ) {
5050 // 0x0028 or 0x0016 or 0x002C
5051 if( !readBuffer(placeHolder, 2) ) { return false; }
5052 unsigned int count = placeHolder.toUnsignedInt() - 7;
5053
5054 // type id
5055 if( !readBuffer(placeHolder, 1) ) { return false; }
5056 unsigned int thisByte = placeHolder.toUnsignedInt();
5057 BdatType type;
5058
5059 if( !getBdatElementType(thisByte, type) ) { return false; }
5060
5061 switch( type ) {
5062 case BdatType::Raw_Note :
5063 case BdatType::Rest :
5064 case BdatType::Note : {
5065 if( !parseNoteRest(measureData, count, type) ) { return false; }
5066 break;
5067 }
5068 case BdatType::Beam : {
5069 if( !parseBeam(measureData, count) ) { return false; }
5070 break;
5071 }
5072 case BdatType::Harmony : {
5073 if( !parseHarmony(measureData, count) ) { return false; }
5074 break;
5075 }
5076 case BdatType::Clef : {
5077 if( !parseClef(measureData, count) ) { return false; }
5078 break;
5079 }
5080 case BdatType::Dynamics : {
5081 if( !parseDynamics(measureData, count) ) { return false; }
5082 break;
5083 }
5084 case BdatType::Wedge : {
5085 if( !parseWedge(measureData, count) ) { return false; }
5086 break;
5087 }
5088 case BdatType::Glissando : {
5089 if( !parseGlissando(measureData, count) ) { return false; }
5090 break;
5091 }
5092 case BdatType::Decorator : {
5093 if( !parseDecorators(measureData, count) ) { return false; }
5094 break;
5095 }
5096 case BdatType::Key : {
5097 if( !parseKey(measureData, count) ) { return false; }
5098 break;
5099 }
5100 case BdatType::Lyric : {
5101 if( !parseLyric(measureData, count) ) { return false; }
5102 break;
5103 }
5104 case BdatType::Octave_Shift: {
5105 if( !parseOctaveShift(measureData, count) ) { return false; }
5106 break;
5107 }
5108 case BdatType::Slur : {
5109 if( !parseSlur(measureData, count) ) { return false; }
5110 break;
5111 }
5112 case BdatType::Text : {
5113 if( !parseText(measureData, count) ) { return false; }
5114 break;
5115 }
5116 case BdatType::Tie : {
5117 if( !parseTie(measureData, count) ) { return false; }
5118 break;
5119 }
5120 case BdatType::Tuplet : {
5121 if( !parseTuplet(measureData, count) ) { return false; }
5122 break;
5123 }
5124 case BdatType::Guitar_Bend :
5125 case BdatType::Guitar_Barre : {
5126 if( !parseSizeBlock(count) ) { return false; }
5127 break;
5128 }
5129 case BdatType::Pedal: {
5130 if( !parsePedal(measureData, count) ) { return false; }
5131 break;
5132 }
5133 case BdatType::KuoHao: {
5134 if( !parseKuohao(measureData, count) ) { return false; }
5135 break;
5136 }
5137 case BdatType::Expressions: {
5138 if( !parseExpressions(measureData, count) ) { return false; }
5139 break;
5140 }
5141 case BdatType::Harp_Pedal: {
5142 if( !parseHarpPedal(measureData, count) ) { return false; }
5143 break;
5144 }
5145 case BdatType::Multi_Measure_Rest: {
5146 if( !parseMultiMeasureRest(measureData, count) ) { return false; }
5147 break;
5148 }
5149 case BdatType::Harmony_GuitarFrame: {
5150 if( !parseHarmonyGuitarFrame(measureData, count) ) { return false; }
5151 break;
5152 }
5153 case BdatType::Graphics_40:
5154 case BdatType::Graphics_RoundRect:
5155 case BdatType::Graphics_Rect:
5156 case BdatType::Graphics_Round:
5157 case BdatType::Graphics_Line:
5158 case BdatType::Graphics_Curve:
5159 case BdatType::Graphics_WedgeSymbol: {
5160 if( !parseSizeBlock(count) ) { return false; }
5161 break;
5162 }
5163 case BdatType::Midi_Controller : {
5164 if( !parseMidiController(measureData, count) ) { return false; }
5165 break;
5166 }
5167 case BdatType::Midi_Program_Change : {
5168 if( !parseMidiProgramChange(measureData, count) ) { return false; }
5169 break;
5170 }
5171 case BdatType::Midi_Channel_Pressure : {
5172 if( !parseMidiChannelPressure(measureData, count) ) { return false; }
5173 break;
5174 }
5175 case BdatType::Midi_Pitch_Wheel : {
5176 if( !parseMidiPitchWheel(measureData, count) ) { return false; }
5177 break;
5178 }
5179 default: {
5180 if( !jump(count) ) { return false; }
5181 break;
5182 }
5183 }
5184
5185 // if i==count-1 then is bar end place holder
5186 }
5187
5188 handle_ = NULL;
5189
5190 return true;
5191 }
5192
getInt(int byte,int bits)5193 int getInt(int byte, int bits) {
5194 int num = 0;
5195
5196 if( bits > 0 ) {
5197 // same as int(pow(2, bits - 1))
5198 int factor = 1 << (bits - 1);
5199 num = (byte % (factor*2));
5200
5201 if ( (byte & factor) == factor ) {
5202 num -= factor*2;
5203 }
5204 }
5205
5206 return num;
5207 }
5208
parseNoteRest(MeasureData * measureData,int length,BdatType type)5209 bool BarsParse::parseNoteRest(MeasureData* measureData, int length, BdatType type) {
5210 NoteContainer* container = new NoteContainer();
5211 Block placeHolder;
5212 unsigned int thisByte;
5213
5214 measureData->addNoteContainer(container);
5215 measureData->addMusicData(container);
5216
5217 // note|rest & grace
5218 container->setIsRest(type==BdatType::Rest);
5219 container->setIsRaw(type==BdatType::Raw_Note);
5220
5221 if( !readBuffer(placeHolder, 2) ) { return false; }
5222 thisByte = placeHolder.toUnsignedInt();
5223 container->setIsGrace( thisByte == 0x3C00 );
5224 container->setIsCue( thisByte == 0x4B40 || thisByte == 0x3240 );
5225
5226 // show / hide
5227 if( !readBuffer(placeHolder, 1) ) { return false; }
5228 thisByte = placeHolder.toUnsignedInt();
5229 container->setShow(getLowNibble(thisByte)!=0x8);
5230
5231 // voice
5232 container->setVoice(getLowNibble(thisByte)&0x7);
5233
5234 // common
5235 if( !parseCommonBlock(container) ) { return false; }
5236
5237 // tuplet
5238 if( !readBuffer(placeHolder, 1) ) { return false; }
5239 container->setTuplet(placeHolder.toUnsignedInt());
5240
5241 // space
5242 if( !readBuffer(placeHolder, 1) ) { return false; }
5243 container->setSpace(placeHolder.toUnsignedInt());
5244
5245 // in beam
5246 if( !readBuffer(placeHolder, 1) ) { return false; }
5247 thisByte = placeHolder.toUnsignedInt();
5248 bool inBeam = ( getHighNibble(thisByte) & 0x1 ) == 0x1;
5249 container->setInBeam(inBeam);
5250
5251 // grace NoteType
5252 container->setGraceNoteType((NoteType)getHighNibble(thisByte));
5253
5254 // dot
5255 container->setDot(getLowNibble(thisByte)&0x03);
5256
5257 // NoteType
5258 if( !readBuffer(placeHolder, 1) ) { return false; }
5259 thisByte = placeHolder.toUnsignedInt();
5260 container->setNoteType((NoteType)getLowNibble(thisByte));
5261
5262 int cursor = 0;
5263
5264 if( type == BdatType::Rest ) {
5265 Note* restPtr = new Note();
5266 container->addNoteRest(restPtr);
5267 restPtr->setIsRest(true);
5268
5269 // line
5270 if( !readBuffer(placeHolder, 1) ) { return false; }
5271 restPtr->setLine(placeHolder.toInt());
5272
5273 if( !jump(1) ) { return false; }
5274
5275 cursor = ove_->getIsVersion4() ? 16 : 14;
5276 } else // type == Bdat_Note || type == Bdat_Raw_Note
5277 {
5278 // stem up 0x80, stem down 0x00
5279 if( !readBuffer(placeHolder, 1) ) { return false; }
5280 thisByte = placeHolder.toUnsignedInt();
5281 container->setStemUp((getHighNibble(thisByte)&0x8)==0x8);
5282
5283 // stem length
5284 int stemOffset = thisByte%0x80;
5285 container->setStemLength(getInt(stemOffset, 7)+7/*3.5 line span*/);
5286
5287 // show stem 0x00, hide stem 0x40
5288 if( !readBuffer(placeHolder, 1) ) { return false; }
5289 bool hideStem = getHighNibble(thisByte)==0x4;
5290 container->setShowStem(!hideStem);
5291
5292 if( !jump(1) ) { return false; }
5293
5294 // note count
5295 if( !readBuffer(placeHolder, 1) ) { return false; }
5296 unsigned int noteCount = placeHolder.toUnsignedInt();
5297 unsigned int i;
5298
5299 // each note 16 bytes
5300 for( i=0; i<noteCount; ++i ) {
5301 Note* notePtr = new Note();
5302 notePtr->setIsRest(false);
5303
5304 container->addNoteRest(notePtr);
5305
5306 // note show / hide
5307 if( !readBuffer(placeHolder, 1) ) { return false; }
5308 thisByte = placeHolder.toUnsignedInt();
5309 notePtr->setShow((thisByte&0x80) != 0x80);
5310
5311 // notehead type
5312 notePtr->setHeadType(thisByte&0x7f);
5313
5314 // tie pos
5315 if( !readBuffer(placeHolder, 1) ) { return false; }
5316 thisByte = placeHolder.toUnsignedInt();
5317 notePtr->setTiePos(getHighNibble(thisByte));
5318
5319 // offset staff, in {-1, 0, 1}
5320 if( !readBuffer(placeHolder, 1) ) { return false; }
5321 thisByte = getLowNibble(placeHolder.toUnsignedInt());
5322 int offsetStaff = 0;
5323 if( thisByte == 1 ) { offsetStaff = 1; }
5324 if( thisByte == 7 ) { offsetStaff = -1; }
5325 notePtr->setOffsetStaff(offsetStaff);
5326
5327 // accidental
5328 if( !readBuffer(placeHolder, 1) ) { return false; }
5329 thisByte = placeHolder.toUnsignedInt();
5330 notePtr->setAccidental(getLowNibble(thisByte));
5331 // accidental 0: influenced by key, 4: influenced by previous accidental in measure
5332 //bool notShow = ( getHighNibble(thisByte) == 0 ) || ( getHighNibble(thisByte) == 4 );
5333 bool notShow = !(getHighNibble(thisByte)&0x1);
5334 notePtr->setShowAccidental(!notShow);
5335
5336 if( !jump(1) ) { return false; }
5337
5338 // line
5339 if( !readBuffer(placeHolder, 1) ) { return false; }
5340 notePtr->setLine(placeHolder.toInt());
5341
5342 if( !jump(1) ) { return false; }
5343
5344 // note
5345 if( !readBuffer(placeHolder, 1) ) { return false; }
5346 unsigned int note = placeHolder.toUnsignedInt();
5347 notePtr->setNote(note);
5348
5349 // note on velocity
5350 if( !readBuffer(placeHolder, 1) ) { return false; }
5351 unsigned int onVelocity = placeHolder.toUnsignedInt();
5352 notePtr->setOnVelocity(onVelocity);
5353
5354 // note off velocity
5355 if( !readBuffer(placeHolder, 1) ) { return false; }
5356 unsigned int offVelocity = placeHolder.toUnsignedInt();
5357 notePtr->setOffVelocity(offVelocity);
5358
5359 if( !jump(2) ) { return false; }
5360
5361 // length (tick)
5362 if( !readBuffer(placeHolder, 2) ) { return false; }
5363 container->setLength(placeHolder.toUnsignedInt());
5364
5365 // offset tick
5366 if( !readBuffer(placeHolder, 2) ) { return false; }
5367 notePtr->setOffsetTick(placeHolder.toInt());
5368 }
5369
5370 cursor = ove_->getIsVersion4() ? 18 : 16;
5371 cursor += noteCount * 16/*note size*/;
5372 }
5373
5374 // articulation
5375 while ( cursor < length + 1/* 0x70 || 0x80 || 0x90 */ ) {
5376 Articulation* art = new Articulation();
5377 container->addArticulation(art);
5378
5379 // block size
5380 if( !readBuffer(placeHolder, 2) ) { return false; }
5381 int blockSize = placeHolder.toUnsignedInt();
5382
5383 // articulation type
5384 if( !readBuffer(placeHolder, 1) ) { return false; }
5385 art->setArtType(placeHolder.toUnsignedInt());
5386
5387 // placement
5388 if( !readBuffer(placeHolder, 1) ) { return false; }
5389 art->setPlacementAbove(placeHolder.toUnsignedInt()!=0x00); //0x00:below, 0x30:above
5390
5391 // offset
5392 if( !parseOffsetElement(art) ) { return false; }
5393
5394 if( !ove_->getIsVersion4() ) {
5395 if( blockSize - 8 > 0 ) {
5396 if( !jump(blockSize-8) ) { return false; }
5397 }
5398 } else {
5399 // setting
5400 if( !readBuffer(placeHolder, 1) ) { return false; }
5401 thisByte = placeHolder.toUnsignedInt();
5402 const bool changeSoundEffect = ( ( thisByte & 0x1 ) == 0x1 );
5403 const bool changeLength = ( ( thisByte & 0x2 ) == 0x2 );
5404 const bool changeVelocity = ( ( thisByte & 0x4 ) == 0x4 );
5405 //const bool changeExtraLength = ( ( thisByte & 0x20 ) == 0x20 );
5406
5407 if( !jump(8) ) { return false; }
5408
5409 // velocity type
5410 if( !readBuffer(placeHolder, 1) ) { return false; }
5411 thisByte = placeHolder.toUnsignedInt();
5412 if( changeVelocity ) {
5413 art->setVelocityType((Articulation::VelocityType)thisByte);
5414 }
5415
5416 if( !jump(14) ) { return false; }
5417
5418 // sound effect
5419 if( !readBuffer(placeHolder, 2) ) { return false; }
5420 int from = placeHolder.toInt();
5421 if( !readBuffer(placeHolder, 2) ) { return false; }
5422 int to = placeHolder.toInt();
5423 if( changeSoundEffect ) {
5424 art->setSoundEffect(from, to);
5425 }
5426
5427 if( !jump(1) ) { return false; }
5428
5429 // length percentage
5430 if( !readBuffer(placeHolder, 1) ) { return false; }
5431 if( changeLength ) {
5432 art->setLengthPercentage(placeHolder.toUnsignedInt());
5433 }
5434
5435 // velocity
5436 if( !readBuffer(placeHolder, 2) ) { return false; }
5437 if( changeVelocity ) {
5438 art->setVelocityValue(placeHolder.toInt());
5439 }
5440
5441 if( Articulation::isTrill(art->getArtType()) ) {
5442 if( !jump(8) ) { return false; }
5443
5444 // trill note length
5445 if( !readBuffer(placeHolder, 1) ) { return false; }
5446 art->setTrillNoteLength(placeHolder.toUnsignedInt());
5447
5448 // trill rate
5449 if( !readBuffer(placeHolder, 1) ) { return false; }
5450 thisByte = placeHolder.toUnsignedInt();
5451 NoteType trillNoteType = NoteType::Note_Sixteen;
5452 switch ( getHighNibble(thisByte) ) {
5453 case 0:
5454 trillNoteType = NoteType::Note_None;
5455 break;
5456 case 1:
5457 trillNoteType = NoteType::Note_Sixteen;
5458 break;
5459 case 2:
5460 trillNoteType = NoteType::Note_32;
5461 break;
5462 case 3:
5463 trillNoteType = NoteType::Note_64;
5464 break;
5465 case 4:
5466 trillNoteType = NoteType::Note_128;
5467 break;
5468 default:
5469 break;
5470 }
5471 art->setTrillRate(trillNoteType);
5472
5473 // accelerate type
5474 art->setAccelerateType(thisByte&0xf);
5475
5476 if( !jump(1) ) { return false; }
5477
5478 // auxiliary first
5479 if( !readBuffer(placeHolder, 1) ) { return false; }
5480 art->setAuxiliaryFirst(placeHolder.toBoolean());
5481
5482 if( !jump(1) ) { return false; }
5483
5484 // trill interval
5485 if( !readBuffer(placeHolder, 1) ) { return false; }
5486 art->setTrillInterval(placeHolder.toUnsignedInt());
5487 } else {
5488 if( blockSize > 40 ) {
5489 if( !jump( blockSize - 40 ) ) { return false; }
5490 }
5491 }
5492 }
5493
5494 cursor += blockSize;
5495 }
5496
5497 return true;
5498 }
5499
tupletToSpace(int tuplet)5500 int tupletToSpace(int tuplet) {
5501 int a(1);
5502
5503 while( a*2 < tuplet ) {
5504 a *= 2;
5505 }
5506
5507 return a;
5508 }
5509
parseBeam(MeasureData * measureData,int length)5510 bool BarsParse::parseBeam(MeasureData* measureData, int length) {
5511 int i;
5512 Block placeHolder;
5513
5514 Beam* beam = new Beam();
5515 measureData->addCrossMeasureElement(beam, true);
5516
5517 // maybe create tuplet, for < quarter & tool 3(
5518 bool createTuplet = false;
5519 int maxEndUnit = 0;
5520 Tuplet* tuplet = new Tuplet();
5521
5522 // is grace
5523 if( !readBuffer(placeHolder, 1) ) { return false; }
5524 beam->setIsGrace(placeHolder.toBoolean());
5525
5526 if( !jump(1) ) { return false; }
5527
5528 // voice
5529 if( !readBuffer(placeHolder, 1) ) { return false; }
5530 beam->setVoice(getLowNibble(placeHolder.toUnsignedInt())&0x7);
5531
5532 // common
5533 if( !parseCommonBlock(beam) ) { return false; }
5534
5535 if( !jump(2) ) { return false; }
5536
5537 // beam count
5538 if( !readBuffer(placeHolder, 1) ) { return false; }
5539 int beamCount = placeHolder.toUnsignedInt();
5540
5541 if( !jump(1) ) { return false; }
5542
5543 // left line
5544 if( !readBuffer(placeHolder, 1) ) { return false; }
5545 beam->getLeftLine()->setLine(placeHolder.toInt());
5546
5547 // right line
5548 if( !readBuffer(placeHolder, 1) ) { return false; }
5549 beam->getRightLine()->setLine(placeHolder.toInt());
5550
5551 if( ove_->getIsVersion4() ) {
5552 if( !jump(8) ) { return false; }
5553 }
5554
5555 int currentCursor = ove_->getIsVersion4() ? 23 : 13;
5556 int count = (length - currentCursor)/16;
5557
5558 if( count != beamCount ) { return false; }
5559
5560 for( i=0; i<count; ++i ) {
5561 if( !jump(1) ) { return false; }
5562
5563 // tuplet
5564 if( !readBuffer(placeHolder, 1) ) { return false; }
5565 int tupletCount = placeHolder.toUnsignedInt();
5566 if( tupletCount > 0 ) {
5567 createTuplet = true;
5568 tuplet->setTuplet(tupletCount);
5569 tuplet->setSpace(tupletToSpace(tupletCount));
5570 }
5571
5572 // start / stop measure
5573 // line i start end position
5574 MeasurePos startMp;
5575 MeasurePos stopMp;
5576
5577 if( !readBuffer(placeHolder, 1) ) { return false; }
5578 startMp.setMeasure(placeHolder.toUnsignedInt());
5579 if( !readBuffer(placeHolder, 1) ) { return false; }
5580 stopMp.setMeasure(placeHolder.toUnsignedInt());
5581
5582 if( !readBuffer(placeHolder, 2) ) { return false; }
5583 startMp.setOffset(placeHolder.toInt());
5584 if( !readBuffer(placeHolder, 2) ) { return false; }
5585 stopMp.setOffset(placeHolder.toInt());
5586
5587 beam->addLine(startMp, stopMp);
5588
5589 if( stopMp.getOffset() > maxEndUnit ) {
5590 maxEndUnit = stopMp.getOffset();
5591 }
5592
5593 if( i == 0 ) {
5594 if( !jump(4) ) { return false; }
5595
5596 // left offset up+4, down-4
5597 if( !readBuffer(placeHolder, 2) ) { return false; }
5598 beam->getLeftShoulder()->setYOffset(placeHolder.toInt());
5599
5600 // right offset up+4, down-4
5601 if( !readBuffer(placeHolder, 2) ) { return false; }
5602 beam->getRightShoulder()->setYOffset(placeHolder.toInt());
5603 } else {
5604 if( !jump(8) ) { return false; }
5605 }
5606 }
5607
5608 const QList<QPair<MeasurePos, MeasurePos> > lines = beam->getLines();
5609 MeasurePos offsetMp;
5610
5611 for( i=0; i<lines.size(); ++i ) {
5612 if( lines[i].second > offsetMp ) {
5613 offsetMp = lines[i].second;
5614 }
5615 }
5616
5617 beam->stop()->setMeasure(offsetMp.getMeasure());
5618 beam->stop()->setOffset(offsetMp.getOffset());
5619
5620 // a case that Tuplet block don't exist, and hide inside beam
5621 if( createTuplet ) {
5622 tuplet->copyCommonBlock(*beam);
5623 tuplet->getLeftLine()->setLine(beam->getLeftLine()->getLine());
5624 tuplet->getRightLine()->setLine(beam->getRightLine()->getLine());
5625 tuplet->stop()->setMeasure(beam->stop()->getMeasure());
5626 tuplet->stop()->setOffset(maxEndUnit);
5627
5628 measureData->addCrossMeasureElement(tuplet, true);
5629 } else {
5630 delete tuplet;
5631 }
5632
5633 return true;
5634 }
5635
parseTie(MeasureData * measureData,int)5636 bool BarsParse::parseTie(MeasureData* measureData, int /*length*/) {
5637 Block placeHolder;
5638
5639 Tie* tie = new Tie();
5640 measureData->addCrossMeasureElement(tie, true);
5641
5642 if( !jump(3) ) { return false; }
5643
5644 // start common
5645 if( !parseCommonBlock(tie) ) { return false; }
5646
5647 if( !jump(1) ) { return false; }
5648
5649 // note
5650 if( !readBuffer(placeHolder, 1) ) { return false; }
5651 tie->setNote(placeHolder.toUnsignedInt());
5652
5653 // pair lines
5654 if( !parsePairLinesBlock(tie) ) { return false; }
5655
5656 // offset common
5657 if( !parseOffsetCommonBlock(tie) ) { return false; }
5658
5659 // left shoulder offset
5660 if( !parseOffsetElement(tie->getLeftShoulder()) ) { return false; }
5661
5662 // right shoulder offset
5663 if( !parseOffsetElement(tie->getRightShoulder()) ) { return false; }
5664
5665 // height
5666 if( !readBuffer(placeHolder, 2) ) { return false; }
5667 tie->setHeight(placeHolder.toUnsignedInt());
5668
5669 return true;
5670 }
5671
parseTuplet(MeasureData * measureData,int)5672 bool BarsParse::parseTuplet(MeasureData* measureData, int /*length*/) {
5673 Block placeHolder;
5674
5675 Tuplet* tuplet = new Tuplet();
5676 measureData->addCrossMeasureElement(tuplet, true);
5677
5678 if( !jump(3) ) { return false; }
5679
5680 // common
5681 if( !parseCommonBlock(tuplet) ) { return false; }
5682
5683 if( !jump(2) ) { return false; }
5684
5685 // pair lines
5686 if( !parsePairLinesBlock(tuplet) ) { return false; }
5687
5688 // offset common
5689 if( !parseOffsetCommonBlock(tuplet) ) { return false; }
5690
5691 // left shoulder offset
5692 if( !parseOffsetElement(tuplet->getLeftShoulder()) ) { return false; }
5693
5694 // right shoulder offset
5695 if( !parseOffsetElement(tuplet->getRightShoulder()) ) { return false; }
5696
5697 if( !jump(2) ) { return false; }
5698
5699 // height
5700 if( !readBuffer(placeHolder, 2) ) { return false; }
5701 tuplet->setHeight(placeHolder.toUnsignedInt());
5702
5703 // tuplet
5704 if( !readBuffer(placeHolder, 1) ) { return false; }
5705 tuplet->setTuplet(placeHolder.toUnsignedInt());
5706
5707 // space
5708 if( !readBuffer(placeHolder, 1) ) { return false; }
5709 tuplet->setSpace(placeHolder.toUnsignedInt());
5710
5711 // mark offset
5712 if( !parseOffsetElement(tuplet->getMarkHandle()) ) { return false; }
5713
5714 return true;
5715 }
5716
binaryToHarmonyType(int bin)5717 QString binaryToHarmonyType(int bin) {
5718 QString type = "";
5719 switch (bin) {
5720 case 0x0005: { type = "add9(no3)"; break; }
5721 case 0x0009: { type = "min(no5)"; break; }
5722 case 0x0011: { type = "(no5)"; break; }
5723 case 0x0021: { type = "sus(no5)"; break; }
5724 case 0x0025: { type = "24"; break; }
5725 case 0x0029: { type = "min4(no5)"; break; }
5726 case 0x0049: { type = "dim"; break; }
5727 case 0x0051: { type = "(b5)"; break; }
5728 case 0x0055: { type = "2#4(no5)"; break; }
5729 case 0x0081: { type = "(no3)"; break; }
5730 case 0x0085: { type = "2"; break; }
5731 case 0x0089: { type = "min"; break; }
5732 case 0x008D: { type = "min(add9)"; break; }
5733 case 0x0091: { type = ""; break; }
5734 case 0x0093: { type = "addb9"; break; }
5735 case 0x0095: { type = "add9"; break; }
5736 case 0x00A1: { type = "sus4"; break; }
5737 case 0x00A5: { type = "sus(add9)"; break; }
5738 case 0x00A9: { type = "min4"; break; }
5739 case 0x00D5: { type = "2#4"; break; }
5740 case 0x0111: { type = "aug"; break; }
5741 case 0x0115: { type = "aug(add9)"; break; }
5742 case 0x0151: { type = "(b5b6)"; break; }
5743 case 0x0155: { type = "+add9#11"; break; }
5744 case 0x0189: { type = "minb6"; break; }
5745 case 0x018D: { type = "min2b6"; break; }
5746 case 0x0191: { type = "(b6)"; break; }
5747 case 0x0199: { type = "(add9)b6"; break; }
5748 case 0x0205: { type = "26"; break; }
5749 case 0x020D: { type = "min69"; break; }
5750 case 0x0211: { type = "6"; break; }
5751 case 0x0215: { type = "69"; break; }
5752 case 0x022D: { type = "min69 11"; break; }
5753 case 0x0249: { type = "dim7"; break; }
5754 case 0x0251: { type = "6#11"; break; }
5755 case 0x0255: { type = "13#11"; break; }
5756 case 0x0281: { type = "6(no3)"; break; }
5757 case 0x0285: { type = "69(no3)"; break; }
5758 case 0x0289: { type = "min6"; break; }
5759 case 0x028D: { type = "min69"; break; }
5760 case 0x0291: { type = "6"; break; }
5761 case 0x0293: { type = "6b9"; break; }
5762 case 0x0295: { type = "69"; break; }
5763 case 0x02AD: { type = "min69 11"; break; }
5764 case 0x02C5: { type = "69#11(no3)"; break; }
5765 case 0x02D5: { type = "69#11"; break; }
5766 case 0x040D: { type = "min9(no5)"; break; }
5767 case 0x0411: { type = "7(no5)"; break; }
5768 case 0x0413: { type = "7b9"; break; }
5769 case 0x0415: { type = "9"; break; }
5770 case 0x0419: { type = "7#9"; break; }
5771 case 0x041B: { type = "7b9#9"; break; }
5772 case 0x0421: { type = "sus7"; break; }
5773 case 0x0429: { type = "min11"; break; }
5774 case 0x042D: { type = "min11"; break; }
5775 case 0x0445: { type = "9b5(no3)"; break; }
5776 case 0x0449: { type = "min7b5"; break; }
5777 case 0x044D: { type = "min9b5"; break; }
5778 case 0x0451: { type = "7b5"; break; }
5779 case 0x0453: { type = "7b9b5"; break; }
5780 case 0x0455: { type = "9b5"; break; }
5781 case 0x045B: { type = "7b5b9#9"; break; }
5782 case 0x0461: { type = "sus7b5"; break; }
5783 case 0x0465: { type = "sus9b5"; break; }
5784 case 0x0469: { type = "min11b5"; break; }
5785 case 0x046D: { type = "min11b5"; break; }
5786 case 0x0481: { type = "7(no3)"; break; }
5787 case 0x0489: { type = "min7"; break; }
5788 case 0x048D: { type = "min9"; break; }
5789 case 0x0491: { type = "7"; break; }
5790 case 0x0493: { type = "7b9"; break; }
5791 case 0x0495: { type = "9"; break; }
5792 case 0x0499: { type = "7#9"; break; }
5793 case 0x049B: { type = "7b9#9"; break; }
5794 case 0x04A1: { type = "sus7"; break; }
5795 case 0x04A5: { type = "sus9"; break; }
5796 case 0x04A9: { type = "min11"; break; }
5797 case 0x04AD: { type = "min11"; break; }
5798 case 0x04B5: { type = "11"; break; }
5799 case 0x04D5: { type = "9#11"; break; }
5800 case 0x0509: { type = "min7#5"; break; }
5801 case 0x0511: { type = "aug7"; break; }
5802 case 0x0513: { type = "7#5b9"; break; }
5803 case 0x0515: { type = "aug9"; break; }
5804 case 0x0519: { type = "7#5#9"; break; }
5805 case 0x0529: { type = "min11b13"; break; }
5806 case 0x0533: { type = "11b9#5"; break; }
5807 case 0x0551: { type = "aug7#11"; break; }
5808 case 0x0553: { type = "7b5b9b13"; break; }
5809 case 0x0555: { type = "aug9#11"; break; }
5810 case 0x0559: { type = "aug7#9#11"; break; }
5811 case 0x0609: { type = "min13"; break; }
5812 case 0x0611: { type = "13"; break; }
5813 case 0x0613: { type = "13b9"; break; }
5814 case 0x0615: { type = "13"; break; }
5815 case 0x0619: { type = "13#9"; break; }
5816 case 0x061B: { type = "13b9#9"; break; }
5817 case 0x0621: { type = "sus13"; break; }
5818 case 0x062D: { type = "min13(11)"; break; }
5819 case 0x0633: { type = "13b9add4"; break; }
5820 case 0x0635: { type = "13"; break; }
5821 case 0x0645: { type = "13#11(no3)"; break; }
5822 case 0x0651: { type = "13b5"; break; }
5823 case 0x0653: { type = "13b9#11"; break; }
5824 case 0x0655: { type = "13#11"; break; }
5825 case 0x0659: { type = "13#9b5"; break; }
5826 case 0x065B: { type = "13b5b9#9"; break; }
5827 case 0x0685: { type = "13(no3)"; break; }
5828 case 0x068D: { type = "min13"; break; }
5829 case 0x0691: { type = "13"; break; }
5830 case 0x0693: { type = "13b9"; break; }
5831 case 0x0695: { type = "13"; break; }
5832 case 0x0699: { type = "13#9"; break; }
5833 case 0x06A5: { type = "sus13"; break; }
5834 case 0x06AD: { type = "min13(11)"; break; }
5835 case 0x06B5: { type = "13"; break; }
5836 case 0x06D5: { type = "13#11"; break; }
5837 case 0x0813: { type = "maj7b9"; break; }
5838 case 0x0851: { type = "maj7#11"; break; }
5839 case 0x0855: { type = "maj9#11"; break; }
5840 case 0x0881: { type = "maj7(no3)"; break; }
5841 case 0x0889: { type = "min(\u266e7)"; break; } // "min(<sym>accidentalNatural</sym>7)"
5842 case 0x088D: { type = "min9(\u266e7)"; break; } // "min9(<sym>accidentalNatural</sym>7)"
5843 case 0x0891: { type = "maj7"; break; }
5844 case 0x0895: { type = "maj9"; break; }
5845 case 0x08C9: { type = "dim7(add maj 7)"; break; }
5846 case 0x08D1: { type = "maj7#11"; break; }
5847 case 0x08D5: { type = "maj9#11"; break; }
5848 case 0x0911: { type = "maj7#5"; break; }
5849 case 0x0991: { type = "maj7#5"; break; }
5850 case 0x0995: { type = "maj9#5"; break; }
5851 case 0x0A0D: { type = "min69(\u266e7)"; break; } // "min69(<sym>accidentalNatural</sym>7)"
5852 case 0x0A11: { type = "maj13"; break; }
5853 case 0x0A15: { type = "maj13"; break; }
5854 case 0x0A51: { type = "maj13#11"; break; }
5855 case 0x0A55: { type = "maj13#11"; break; }
5856 case 0x0A85: { type = "maj13(no3)"; break; }
5857 case 0x0A89: { type = "min13(\u266e7)"; break; } // "min13(<sym>accidentalNatural</sym>7)"
5858 case 0x0A8D: { type = "min69(\u266e7)"; break; } // "min69(<sym>accidentalNatural</sym>7)"
5859 case 0x0A91: { type = "maj13"; break; }
5860 case 0x0A95: { type = "maj13"; break; }
5861 case 0x0AAD: { type = "min13(\u266e7)"; break; } // "min13(<sym>accidentalNatural</sym>7)"
5862 case 0x0AD5: { type = "maj13#11"; break; }
5863 case 0x0B45: { type = "maj13#5#11(no4)"; break; }
5864 default: {
5865 qDebug("Unrecognized harmony type: %04X",bin);
5866 type = "";
5867 break;
5868 }
5869 }
5870 return type;
5871 }
5872
parseHarmony(MeasureData * measureData,int)5873 bool BarsParse::parseHarmony(MeasureData* measureData, int /*length*/) {
5874 Block placeHolder;
5875
5876 Harmony* harmony = new Harmony();
5877 measureData->addMusicData(harmony);
5878
5879 if( !jump(3) ) { return false; }
5880
5881 // common
5882 if( !parseCommonBlock(harmony) ) { return false; }
5883
5884 // bass on bottom
5885 if( !readBuffer(placeHolder, 1) ) { return false; }
5886 harmony->setBassOnBottom((getHighNibble(placeHolder.toUnsignedInt()) & 0x4));
5887
5888 // root alteration
5889 switch (placeHolder.toUnsignedInt() & 0x18) {
5890 case 0: {
5891 harmony->setAlterRoot(0); // natural
5892 break;
5893 }
5894 case 16: {
5895 harmony->setAlterRoot(-1); // flat
5896 break;
5897 }
5898 case 8: {
5899 harmony->setAlterRoot(1); // sharp
5900 break;
5901 }
5902 default: {
5903 harmony->setAlterRoot(0);
5904 break;
5905 }
5906 }
5907
5908 // bass alteration
5909 switch (placeHolder.toUnsignedInt() & 0x3) {
5910 case 0: {
5911 harmony->setAlterBass(0); // natural
5912 break;
5913 }
5914 case 2: {
5915 harmony->setAlterBass(-1); // flat
5916 break;
5917 }
5918 case 1: {
5919 harmony->setAlterBass(1); // sharp
5920 break;
5921 }
5922 default: {
5923 harmony->setAlterBass(0);
5924 break;
5925 }
5926 }
5927
5928 // show bass
5929 bool useBass = placeHolder.toUnsignedInt() & 0x80;
5930
5931 if( !jump(1) ) { return false; }
5932
5933 // y offset
5934 if( !readBuffer(placeHolder, 2) ) { return false; }
5935 harmony->setYOffset(placeHolder.toInt());
5936
5937 // harmony type
5938 if( !readBuffer(placeHolder, 2) ) { return false; }
5939 harmony->setHarmonyType(binaryToHarmonyType(placeHolder.toUnsignedInt()));
5940
5941 // root
5942 if( !readBuffer(placeHolder, 1) ) { return false; }
5943 harmony->setRoot(placeHolder.toInt());
5944
5945 // bass
5946 if( !readBuffer(placeHolder, 1) ) { return false; }
5947 if (useBass)
5948 harmony->setBass(placeHolder.toInt());
5949
5950 // angle
5951 if( !readBuffer(placeHolder, 2) ) { return false; }
5952 harmony->setAngle(placeHolder.toInt());
5953
5954 if( ove_->getIsVersion4() ) {
5955 // length (tick)
5956 if( !readBuffer(placeHolder, 2) ) { return false; }
5957 harmony->setLength(placeHolder.toUnsignedInt());
5958
5959 if( !jump(4) ) { return false; }
5960 }
5961
5962 return true;
5963 }
5964
parseClef(MeasureData * measureData,int)5965 bool BarsParse::parseClef(MeasureData* measureData, int /*length*/) {
5966 Block placeHolder;
5967
5968 Clef* clef = new Clef();
5969 measureData->addMusicData(clef);
5970
5971 if( !jump(3) ) { return false; }
5972
5973 // common
5974 if( !parseCommonBlock(clef) ) { return false; }
5975
5976 // clef type
5977 if( !readBuffer(placeHolder, 1) ) { return false; }
5978 clef->setClefType(placeHolder.toUnsignedInt());
5979
5980 // line
5981 if( !readBuffer(placeHolder, 1) ) { return false; }
5982 clef->setLine(placeHolder.toInt());
5983
5984 if( !jump(2) ) { return false; }
5985
5986 return true;
5987 }
5988
parseLyric(MeasureData * measureData,int length)5989 bool BarsParse::parseLyric(MeasureData* measureData, int length) {
5990 Block placeHolder;
5991
5992 Lyric* lyric = new Lyric();
5993 measureData->addMusicData(lyric);
5994
5995 if( !jump(3) ) { return false; }
5996
5997 // common
5998 if( !parseCommonBlock(lyric) ) { return false; }
5999
6000 if( !jump(2) ) { return false; }
6001
6002 // offset
6003 if( !parseOffsetElement(lyric) ) { return false; }
6004
6005 if( !jump(7) ) { return false; }
6006
6007 // verse
6008 if( !readBuffer(placeHolder, 1) ) { return false; }
6009 lyric->setVerse(placeHolder.toUnsignedInt());
6010
6011 if( ove_->getIsVersion4() ) {
6012 if( !jump(6) ) { return false; }
6013
6014 // lyric
6015 if( length > 29 ) {
6016 if( !readBuffer(placeHolder, length-29) ) { return false; }
6017 lyric->setLyric(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
6018 }
6019 }
6020
6021 return true;
6022 }
6023
parseSlur(MeasureData * measureData,int)6024 bool BarsParse::parseSlur(MeasureData* measureData, int /*length*/) {
6025 Block placeHolder;
6026
6027 Slur* slur = new Slur();
6028 measureData->addCrossMeasureElement(slur, true);
6029
6030 if( !jump(2) ) { return false; }
6031
6032 // voice
6033 if( !readBuffer(placeHolder, 1) ) { return false; }
6034 slur->setVoice(getLowNibble(placeHolder.toUnsignedInt())&0x7);
6035
6036 // common
6037 if( !parseCommonBlock(slur) ) { return false; }
6038
6039 // show on top
6040 if( !readBuffer(placeHolder, 1) ) { return false; }
6041 slur->setShowOnTop(getHighNibble(placeHolder.toUnsignedInt())==0x8);
6042
6043 if( !jump(1) ) { return false; }
6044
6045 // pair lines
6046 if( !parsePairLinesBlock(slur) ) { return false; }
6047
6048 // offset common
6049 if( !parseOffsetCommonBlock(slur) ) { return false; }
6050
6051 // handle 1
6052 if( !parseOffsetElement(slur->getLeftShoulder()) ) { return false; }
6053
6054 // handle 4
6055 if( !parseOffsetElement(slur->getRightShoulder()) ) { return false; }
6056
6057 // handle 2
6058 if( !parseOffsetElement(slur->getHandle2()) ) { return false; }
6059
6060 // handle 3
6061 if( !parseOffsetElement(slur->getHandle3()) ) { return false; }
6062
6063 if( ove_->getIsVersion4() ) {
6064 if( !jump(3) ) { return false; }
6065
6066 // note time percent
6067 if( !readBuffer(placeHolder, 1) ) { return false; }
6068 slur->setNoteTimePercent(placeHolder.toUnsignedInt());
6069
6070 if( !jump(36) ) { return false; }
6071 }
6072
6073 return true;
6074 }
6075
parseGlissando(MeasureData * measureData,int)6076 bool BarsParse::parseGlissando(MeasureData* measureData, int /*length*/) {
6077 Block placeHolder;
6078
6079 Glissando* glissando = new Glissando();
6080 measureData->addCrossMeasureElement(glissando, true);
6081
6082 if( !jump(3) ) { return false; }
6083
6084 // common
6085 if( !parseCommonBlock(glissando) ) { return false; }
6086
6087 // straight or wavy
6088 if( !readBuffer(placeHolder, 1) ) { return false; }
6089 unsigned int thisByte = placeHolder.toUnsignedInt();
6090 glissando->setStraightWavy(getHighNibble(thisByte)==4);
6091
6092 if( !jump(1) ) { return false; }
6093
6094 // pair lines
6095 if( !parsePairLinesBlock(glissando) ) { return false; }
6096
6097 // offset common
6098 if( !parseOffsetCommonBlock(glissando) ) { return false; }
6099
6100 // left shoulder
6101 if( !parseOffsetElement(glissando->getLeftShoulder()) ) { return false; }
6102
6103 // right shoulder
6104 if( !parseOffsetElement(glissando->getRightShoulder()) ) { return false; }
6105
6106 if( ove_->getIsVersion4() ) {
6107 if( !jump(1) ) { return false; }
6108
6109 // line thick
6110 if( !readBuffer(placeHolder, 1) ) { return false; }
6111 glissando->setLineThick(placeHolder.toUnsignedInt());
6112
6113 if( !jump(12) ) { return false; }
6114
6115 // text 32 bytes
6116 if( !readBuffer(placeHolder, 32) ) { return false; }
6117 glissando->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
6118
6119 if( !jump(6) ) { return false; }
6120 }
6121
6122 return true;
6123 }
6124
getDecoratorType(unsigned int thisByte,bool & measureRepeat,Decorator::Type & decoratorType,bool & singleRepeat,ArticulationType & artType)6125 bool getDecoratorType(
6126 unsigned int thisByte,
6127 bool& measureRepeat,
6128 Decorator::Type& decoratorType,
6129 bool& singleRepeat,
6130 ArticulationType& artType) {
6131 measureRepeat = false;
6132 decoratorType = Decorator::Type::Articulation;
6133 singleRepeat = true;
6134 artType = ArticulationType::None;
6135
6136 switch (thisByte) {
6137 case 0x00: {
6138 decoratorType = Decorator::Type::Dotted_Barline;
6139 break;
6140 }
6141 case 0x30: {
6142 artType = ArticulationType::Open_String;
6143 break;
6144 }
6145 case 0x31: {
6146 artType = ArticulationType::Finger_1;
6147 break;
6148 }
6149 case 0x32: {
6150 artType = ArticulationType::Finger_2;
6151 break;
6152 }
6153 case 0x33: {
6154 artType = ArticulationType::Finger_3;
6155 break;
6156 }
6157 case 0x34: {
6158 artType = ArticulationType::Finger_4;
6159 break;
6160 }
6161 case 0x35: {
6162 artType = ArticulationType::Finger_5;
6163 break;
6164 }
6165 case 0x6B: {
6166 artType = ArticulationType::Flat_Accidental_For_Trill;
6167 break;
6168 }
6169 case 0x6C: {
6170 artType = ArticulationType::Sharp_Accidental_For_Trill;
6171 break;
6172 }
6173 case 0x6D: {
6174 artType = ArticulationType::Natural_Accidental_For_Trill;
6175 break;
6176 }
6177 case 0x8d: {
6178 measureRepeat = true;
6179 singleRepeat = true;
6180 break;
6181 }
6182 case 0x8e: {
6183 measureRepeat = true;
6184 singleRepeat = false;
6185 break;
6186 }
6187 case 0xA0: {
6188 artType = ArticulationType::Minor_Trill;
6189 break;
6190 }
6191 case 0xA1: {
6192 artType = ArticulationType::Major_Trill;
6193 break;
6194 }
6195 case 0xA2: {
6196 artType = ArticulationType::Trill_Section;
6197 break;
6198 }
6199 case 0xA6: {
6200 artType = ArticulationType::Turn;
6201 break;
6202 }
6203 case 0xA8: {
6204 artType = ArticulationType::Tremolo_Eighth;
6205 break;
6206 }
6207 case 0xA9: {
6208 artType = ArticulationType::Tremolo_Sixteenth;
6209 break;
6210 }
6211 case 0xAA: {
6212 artType = ArticulationType::Tremolo_Thirty_Second;
6213 break;
6214 }
6215 case 0xAB: {
6216 artType = ArticulationType::Tremolo_Sixty_Fourth;
6217 break;
6218 }
6219 case 0xB2: {
6220 artType = ArticulationType::Fermata;
6221 break;
6222 }
6223 case 0xB3: {
6224 artType = ArticulationType::Fermata_Inverted;
6225 break;
6226 }
6227 case 0xB9: {
6228 artType = ArticulationType::Pause;
6229 break;
6230 }
6231 case 0xBA: {
6232 artType = ArticulationType::Grand_Pause;
6233 break;
6234 }
6235 case 0xC0: {
6236 artType = ArticulationType::Marcato;
6237 break;
6238 }
6239 case 0xC1: {
6240 artType = ArticulationType::Marcato_Dot;
6241 break;
6242 }
6243 case 0xC2: {
6244 artType = ArticulationType::SForzando;
6245 break;
6246 }
6247 case 0xC3: {
6248 artType = ArticulationType::SForzando_Dot;
6249 break;
6250 }
6251 case 0xC4: {
6252 artType = ArticulationType::SForzando_Inverted;
6253 break;
6254 }
6255 case 0xC5: {
6256 artType = ArticulationType::SForzando_Dot_Inverted;
6257 break;
6258 }
6259 case 0xC6: {
6260 artType = ArticulationType::Staccatissimo;
6261 break;
6262 }
6263 case 0xC7: {
6264 artType = ArticulationType::Staccato;
6265 break;
6266 }
6267 case 0xC8: {
6268 artType = ArticulationType::Tenuto;
6269 break;
6270 }
6271 case 0xC9: {
6272 artType = ArticulationType::Natural_Harmonic;
6273 break;
6274 }
6275 case 0xCA: {
6276 artType = ArticulationType::Artificial_Harmonic;
6277 break;
6278 }
6279 case 0xCB: {
6280 artType = ArticulationType::Plus_Sign;
6281 break;
6282 }
6283 case 0xCC: {
6284 artType = ArticulationType::Up_Bow;
6285 break;
6286 }
6287 case 0xCD: {
6288 artType = ArticulationType::Down_Bow;
6289 break;
6290 }
6291 case 0xCE: {
6292 artType = ArticulationType::Up_Bow_Inverted;
6293 break;
6294 }
6295 case 0xCF: {
6296 artType = ArticulationType::Down_Bow_Inverted;
6297 break;
6298 }
6299 case 0xD0: {
6300 artType = ArticulationType::Pedal_Down;
6301 break;
6302 }
6303 case 0xD1: {
6304 artType = ArticulationType::Pedal_Up;
6305 break;
6306 }
6307 case 0xD6: {
6308 artType = ArticulationType::Heavy_Attack;
6309 break;
6310 }
6311 case 0xD7: {
6312 artType = ArticulationType::Heavier_Attack;
6313 break;
6314 }
6315 default:
6316 return false;
6317 break;
6318 }
6319
6320 return true;
6321 }
6322
parseDecorators(MeasureData * measureData,int length)6323 bool BarsParse::parseDecorators(MeasureData* measureData, int length) {
6324 Block placeHolder;
6325 MusicData* musicData = new MusicData();
6326
6327 if( !jump(3) ) { return false; }
6328
6329 // common
6330 if( !parseCommonBlock(musicData) ) { return false; }
6331
6332 if( !jump(2) ) { return false; }
6333
6334 // y offset
6335 if( !readBuffer(placeHolder, 2) ) { return false; }
6336 musicData->setYOffset(placeHolder.toInt());
6337
6338 if( !jump(2) ) { return false; }
6339
6340 // measure repeat | piano pedal | dotted barline | articulation
6341 if( !readBuffer(placeHolder, 1) ) { return false; }
6342 unsigned int thisByte = placeHolder.toUnsignedInt();
6343
6344 Decorator::Type decoratorType;
6345 bool isMeasureRepeat;
6346 bool isSingleRepeat = true;
6347 ArticulationType artType = ArticulationType::None;
6348
6349 getDecoratorType(thisByte, isMeasureRepeat, decoratorType, isSingleRepeat, artType);
6350
6351 if( isMeasureRepeat ) {
6352 MeasureRepeat* measureRepeat = new MeasureRepeat();
6353 measureData->addCrossMeasureElement(measureRepeat, true);
6354
6355 measureRepeat->copyCommonBlock(*musicData);
6356 measureRepeat->setYOffset(musicData->getYOffset());
6357
6358 measureRepeat->setSingleRepeat(isSingleRepeat);
6359 } else {
6360 Decorator* decorator = new Decorator();
6361 measureData->addMusicData(decorator);
6362
6363 decorator->copyCommonBlock(*musicData);
6364 decorator->setYOffset(musicData->getYOffset());
6365
6366 decorator->setDecoratorType(decoratorType);
6367 decorator->setArticulationType(artType);
6368 }
6369
6370 int cursor = ove_->getIsVersion4() ? 16 : 14;
6371 if( !jump(length-cursor) ) { return false; }
6372
6373 return true;
6374 }
6375
parseWedge(MeasureData * measureData,int length)6376 bool BarsParse::parseWedge(MeasureData* measureData, int length) {
6377 Block placeHolder;
6378 Wedge* wedge = new Wedge();
6379
6380 if( !jump(3) ) { return false; }
6381
6382 // common
6383 if( !parseCommonBlock(wedge) ) { return false; }
6384
6385 // wedge type
6386 if( !readBuffer(placeHolder, 1) ) { return false; }
6387 WedgeType wedgeType = WedgeType::Cres_Line;
6388 bool wedgeOrExpression = true;
6389 unsigned int highHalfByte = getHighNibble(placeHolder.toUnsignedInt());
6390 unsigned int lowHalfByte = getLowNibble(placeHolder.toUnsignedInt());
6391
6392 switch (highHalfByte) {
6393 case 0x0: {
6394 wedgeType = WedgeType::Cres_Line;
6395 wedgeOrExpression = true;
6396 break;
6397 }
6398 case 0x4: {
6399 wedgeType = WedgeType::Decresc_Line;
6400 wedgeOrExpression = true;
6401 break;
6402 }
6403 case 0x6: {
6404 wedgeType = WedgeType::Decresc;
6405 wedgeOrExpression = false;
6406 break;
6407 }
6408 case 0x2: {
6409 wedgeType = WedgeType::Cres;
6410 wedgeOrExpression = false;
6411 break;
6412 }
6413 default:
6414 break;
6415 }
6416
6417 // 0xb | 0x8(ove3) , else 3, 0(ove3)
6418 if( (lowHalfByte & 0x8) == 0x8 ) {
6419 wedgeType = WedgeType::Double_Line;
6420 wedgeOrExpression = true;
6421 }
6422
6423 if( !jump(1) ) { return false; }
6424
6425 // y offset
6426 if( !readBuffer(placeHolder, 2) ) { return false; }
6427 wedge->setYOffset(placeHolder.toInt());
6428
6429 // wedge
6430 if( wedgeOrExpression ) {
6431 measureData->addCrossMeasureElement(wedge, true);
6432 wedge->setWedgeType(wedgeType);
6433
6434 if( !jump(2) ) { return false; }
6435
6436 // height
6437 if( !readBuffer(placeHolder, 2) ) { return false; }
6438 wedge->setHeight(placeHolder.toUnsignedInt());
6439
6440 // offset common
6441 if( !parseOffsetCommonBlock(wedge) ) { return false; }
6442
6443 int cursor = ove_->getIsVersion4() ? 21 : 19;
6444 if( !jump(length-cursor) ) { return false; }
6445 }
6446 // expression : cresc, decresc
6447 else {
6448 Expressions* express = new Expressions();
6449 measureData->addMusicData(express);
6450
6451 express->copyCommonBlock(*wedge);
6452 express->setYOffset(wedge->getYOffset());
6453
6454 if( !jump(4) ) { return false; }
6455
6456 // offset common
6457 if( !parseOffsetCommonBlock(express) ) { return false; }
6458
6459 if( ove_->getIsVersion4() ) {
6460 if( !jump(18) ) { return false; }
6461
6462 // words
6463 if( length > 39 ) {
6464 if( !readBuffer(placeHolder, length-39) ) { return false; }
6465 express->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
6466 }
6467 } else {
6468 QString str = wedgeType==WedgeType::Cres ? "cresc" : "decresc";
6469 express->setText(str);
6470
6471 if( !jump(8) ) { return false; }
6472 }
6473 }
6474
6475 return true;
6476 }
6477
parseDynamics(MeasureData * measureData,int)6478 bool BarsParse::parseDynamics(MeasureData* measureData, int /*length*/) {
6479 Block placeHolder;
6480
6481 Dynamics* dynamics = new Dynamics();
6482 measureData->addMusicData(dynamics);
6483
6484 if( !jump(1) ) { return false; }
6485
6486 // is playback
6487 if( !readBuffer(placeHolder, 1) ) { return false; }
6488 dynamics->setIsPlayback(getHighNibble(placeHolder.toUnsignedInt())!=0x4);
6489
6490 if( !jump(1) ) { return false; }
6491
6492 // common
6493 if( !parseCommonBlock(dynamics) ) { return false; }
6494
6495 // y offset
6496 if( !readBuffer(placeHolder, 2) ) { return false; }
6497 dynamics->setYOffset(placeHolder.toInt());
6498
6499 // dynamics type
6500 if( !readBuffer(placeHolder, 1) ) { return false; }
6501 dynamics->setDynamicsType(getLowNibble(placeHolder.toUnsignedInt()));
6502
6503 // velocity
6504 if( !readBuffer(placeHolder, 1) ) { return false; }
6505 dynamics->setVelocity(placeHolder.toUnsignedInt());
6506
6507 int cursor = ove_->getIsVersion4() ? 4 : 2;
6508
6509 if( !jump(cursor) ) { return false; }
6510
6511 return true;
6512 }
6513
parseKey(MeasureData * measureData,int)6514 bool BarsParse::parseKey(MeasureData* measureData, int /*length*/) {
6515 Block placeHolder;
6516 Key* key = measureData->getKey();
6517 int cursor = ove_->getIsVersion4() ? 9 : 7;
6518
6519 if( !jump(cursor) ) { return false; }
6520
6521 // key
6522 if( !readBuffer(placeHolder, 1) ) { return false; }
6523 key->setKey(oveKeyToKey(placeHolder.toUnsignedInt()));
6524
6525 // previous key
6526 if( !readBuffer(placeHolder, 1) ) { return false; }
6527 key->setPreviousKey(oveKeyToKey(placeHolder.toUnsignedInt()));
6528
6529 if( !jump(3) ) { return false; }
6530
6531 // symbol count
6532 if( !readBuffer(placeHolder, 1) ) { return false; }
6533 key->setSymbolCount(placeHolder.toUnsignedInt());
6534
6535 if( !jump(4) ) { return false; }
6536
6537 return true;
6538 }
6539
parsePedal(MeasureData * measureData,int length)6540 bool BarsParse::parsePedal(MeasureData* measureData, int length) {
6541 Block placeHolder;
6542
6543 Pedal* pedal = new Pedal();
6544 //measureData->addMusicData(pedal); //can't remember why
6545 measureData->addCrossMeasureElement(pedal, true);
6546
6547 if( !jump(1) ) { return false; }
6548
6549 // is playback
6550 if( !readBuffer(placeHolder, 1) ) { return false; }
6551 pedal->setIsPlayback(getHighNibble(placeHolder.toUnsignedInt())!=4);
6552
6553 if( !jump(1) ) { return false; }
6554
6555 // common
6556 if( !parseCommonBlock(pedal) ) { return false; }
6557
6558 if( !jump(2) ) { return false; }
6559
6560 // pair lines
6561 if( !parsePairLinesBlock(pedal) ) { return false; }
6562
6563 // offset common
6564 if( !parseOffsetCommonBlock(pedal) ) { return false; }
6565
6566 // left shoulder
6567 if( !parseOffsetElement(pedal->getLeftShoulder()) ) { return false; }
6568
6569 // right shoulder
6570 if( !parseOffsetElement(pedal->getRightShoulder()) ) { return false; }
6571
6572 int cursor = ove_->getIsVersion4() ? 0x45 : 0x23;
6573 int blankCount = ove_->getIsVersion4() ? 42 : 10;
6574
6575 pedal->setHalf( length > cursor );
6576
6577 if( !jump(blankCount) ) { return false; }
6578
6579 if( length > cursor ) {
6580 if( !jump(2) ) { return false; }
6581
6582 // handle x offset
6583 if( !readBuffer(placeHolder, 2) ) { return false; }
6584 pedal->getPedalHandle()->setXOffset(placeHolder.toInt());
6585
6586 if( !jump(6) ) { return false; }
6587 }
6588
6589 return true;
6590 }
6591
parseKuohao(MeasureData * measureData,int)6592 bool BarsParse::parseKuohao(MeasureData* measureData, int /*length*/) {
6593 Block placeHolder;
6594
6595 KuoHao* kuoHao = new KuoHao();
6596 measureData->addMusicData(kuoHao);
6597
6598 if( !jump(3) ) { return false; }
6599
6600 // common
6601 if( !parseCommonBlock(kuoHao) ) { return false; }
6602
6603 if( !jump(2) ) { return false; }
6604
6605 // pair lines
6606 if( !parsePairLinesBlock(kuoHao) ) { return false; }
6607
6608 if( !jump(4) ) { return false; }
6609
6610 // left shoulder
6611 if( !parseOffsetElement(kuoHao->getLeftShoulder()) ) { return false; }
6612
6613 // right shoulder
6614 if( !parseOffsetElement(kuoHao->getRightShoulder()) ) { return false; }
6615
6616 // kuohao type
6617 if( !readBuffer(placeHolder, 1) ) { return false; }
6618 kuoHao->setKuohaoType(placeHolder.toUnsignedInt());
6619
6620 // height
6621 if( !readBuffer(placeHolder, 1) ) { return false; }
6622 kuoHao->setHeight(placeHolder.toUnsignedInt());
6623
6624 int jumpAmount = ove_->getIsVersion4() ? 40 : 8;
6625 if( !jump(jumpAmount) ) { return false; }
6626
6627 return true;
6628 }
6629
parseExpressions(MeasureData * measureData,int length)6630 bool BarsParse::parseExpressions(MeasureData* measureData, int length) {
6631 Block placeHolder;
6632
6633 Expressions* expressions = new Expressions();
6634 measureData->addMusicData(expressions);
6635
6636 if( !jump(3) ) { return false; }
6637
6638 // common00
6639 if( !parseCommonBlock(expressions) ) { return false; }
6640
6641 if( !jump(2) ) { return false; }
6642
6643 // y offset
6644 if( !readBuffer(placeHolder, 2) ) { return false; }
6645 expressions->setYOffset(placeHolder.toInt());
6646
6647 // range bar offset
6648 if( !readBuffer(placeHolder, 2) ) { return false; }
6649 //int barOffset = placeHolder.toUnsignedInt();
6650
6651 if( !jump(10) ) { return false; }
6652
6653 // tempo 1
6654 if( !readBuffer(placeHolder, 2) ) { return false; }
6655 //double tempo1 = ((double)placeHolder.toUnsignedInt()) / 100.0;
6656
6657 // tempo 2
6658 if( !readBuffer(placeHolder, 2) ) { return false; }
6659 //double tempo2 = ((double)placeHolder.toUnsignedInt()) / 100.0;
6660
6661 if( !jump(6) ) { return false; }
6662
6663 // text
6664 int cursor = ove_->getIsVersion4() ? 35 : 33;
6665 if( length > cursor ) {
6666 if( !readBuffer(placeHolder, length-cursor) ) { return false; }
6667 expressions->setText(ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray()));
6668 }
6669
6670 return true;
6671 }
6672
parseHarpPedal(MeasureData * measureData,int)6673 bool BarsParse::parseHarpPedal(MeasureData* measureData, int /*length*/) {
6674 Block placeHolder;
6675
6676 HarpPedal* harpPedal = new HarpPedal();
6677 measureData->addMusicData(harpPedal);
6678
6679 if( !jump(3) ) { return false; }
6680
6681 // common
6682 if( !parseCommonBlock(harpPedal) ) { return false; }
6683
6684 if( !jump(2) ) { return false; }
6685
6686 // y offset
6687 if( !readBuffer(placeHolder, 2) ) { return false; }
6688 harpPedal->setYOffset(placeHolder.toInt());
6689
6690 // show type
6691 if( !readBuffer(placeHolder, 1) ) { return false; }
6692 harpPedal->setShowType(placeHolder.toUnsignedInt());
6693
6694 // show char flag
6695 if( !readBuffer(placeHolder, 1) ) { return false; }
6696 harpPedal->setShowCharFlag(placeHolder.toUnsignedInt());
6697
6698 if( !jump(8) ) { return false; }
6699
6700 return true;
6701 }
6702
parseMultiMeasureRest(MeasureData * measureData,int)6703 bool BarsParse::parseMultiMeasureRest(MeasureData* measureData, int /*length*/) {
6704 Block placeHolder(2);
6705 MultiMeasureRest* measureRest = new MultiMeasureRest();
6706 measureData->addMusicData(measureRest);
6707
6708 if( !jump(3) ) { return false; }
6709
6710 // common
6711 if( !parseCommonBlock(measureRest) ) { return false; }
6712
6713 if( !jump(6) ) { return false; }
6714
6715 return true;
6716 }
6717
parseHarmonyGuitarFrame(MeasureData * measureData,int length)6718 bool BarsParse::parseHarmonyGuitarFrame(MeasureData* measureData, int length) {
6719 Block placeHolder;
6720
6721 Harmony* harmony = new Harmony();
6722 measureData->addMusicData(harmony);
6723
6724 if( !jump(3) ) { return false; }
6725
6726 // common
6727 if( !parseCommonBlock(harmony) ) { return false; }
6728
6729 // root
6730 if( !readBuffer(placeHolder, 1) ) { return false; }
6731 harmony->setRoot(placeHolder.toUnsignedInt());
6732
6733 // type
6734 if( !readBuffer(placeHolder, 1) ) { return false; }
6735 //harmony->setHarmonyType((HarmonyType)placeHolder.toUnsignedInt()); // TODO
6736
6737 // bass
6738 if( !readBuffer(placeHolder, 1) ) { return false; }
6739 harmony->setBass(placeHolder.toUnsignedInt());
6740
6741 int jumpAmount = ove_->getIsVersion4() ? length - 12 : length - 10;
6742 if( !jump(jumpAmount) ) { return false; }
6743
6744 return true;
6745 }
6746
extractOctave(unsigned int Bits,OctaveShiftType & octaveShiftType,QList<OctaveShiftPosition> & positions)6747 void extractOctave(unsigned int Bits, OctaveShiftType& octaveShiftType, QList<OctaveShiftPosition>& positions) {
6748 octaveShiftType = OctaveShiftType::OS_8;
6749 positions.clear();
6750
6751 switch (Bits) {
6752 case 0x0: {
6753 octaveShiftType = OctaveShiftType::OS_8;
6754 positions.push_back(OctaveShiftPosition::Continue);
6755 break;
6756 }
6757 case 0x1: {
6758 octaveShiftType = OctaveShiftType::OS_Minus_8;
6759 positions.push_back(OctaveShiftPosition::Continue);
6760 break;
6761 }
6762 case 0x2: {
6763 octaveShiftType = OctaveShiftType::OS_15;
6764 positions.push_back(OctaveShiftPosition::Continue);
6765 break;
6766 }
6767 case 0x3: {
6768 octaveShiftType = OctaveShiftType::OS_Minus_15;
6769 positions.push_back(OctaveShiftPosition::Continue);
6770 break;
6771 }
6772 case 0x4: {
6773 octaveShiftType = OctaveShiftType::OS_8;
6774 positions.push_back(OctaveShiftPosition::Stop);
6775 break;
6776 }
6777 case 0x5: {
6778 octaveShiftType = OctaveShiftType::OS_Minus_8;
6779 positions.push_back(OctaveShiftPosition::Stop);
6780 break;
6781 }
6782 case 0x6: {
6783 octaveShiftType = OctaveShiftType::OS_15;
6784 positions.push_back(OctaveShiftPosition::Stop);
6785 break;
6786 }
6787 case 0x7: {
6788 octaveShiftType = OctaveShiftType::OS_Minus_15;
6789 positions.push_back(OctaveShiftPosition::Stop);
6790 break;
6791 }
6792 case 0x8: {
6793 octaveShiftType = OctaveShiftType::OS_8;
6794 positions.push_back(OctaveShiftPosition::Start);
6795 break;
6796 }
6797 case 0x9: {
6798 octaveShiftType = OctaveShiftType::OS_Minus_8;
6799 positions.push_back(OctaveShiftPosition::Start);
6800 break;
6801 }
6802 case 0xA: {
6803 octaveShiftType = OctaveShiftType::OS_15;
6804 positions.push_back(OctaveShiftPosition::Start);
6805 break;
6806 }
6807 case 0xB: {
6808 octaveShiftType = OctaveShiftType::OS_Minus_15;
6809 positions.push_back(OctaveShiftPosition::Start);
6810 ;
6811 break;
6812 }
6813 case 0xC: {
6814 octaveShiftType = OctaveShiftType::OS_8;
6815 positions.push_back(OctaveShiftPosition::Start);
6816 positions.push_back(OctaveShiftPosition::Stop);
6817 break;
6818 }
6819 case 0xD: {
6820 octaveShiftType = OctaveShiftType::OS_Minus_8;
6821 positions.push_back(OctaveShiftPosition::Start);
6822 positions.push_back(OctaveShiftPosition::Stop);
6823 break;
6824 }
6825 case 0xE: {
6826 octaveShiftType = OctaveShiftType::OS_15;
6827 positions.push_back(OctaveShiftPosition::Start);
6828 positions.push_back(OctaveShiftPosition::Stop);
6829 break;
6830 }
6831 case 0xF: {
6832 octaveShiftType = OctaveShiftType::OS_Minus_15;
6833 positions.push_back(OctaveShiftPosition::Start);
6834 positions.push_back(OctaveShiftPosition::Stop);
6835 break;
6836 }
6837 default:
6838 break;
6839 }
6840 }
6841
parseOctaveShift(MeasureData * measureData,int)6842 bool BarsParse::parseOctaveShift(MeasureData* measureData, int /*length*/) {
6843 Block placeHolder;
6844
6845 OctaveShift* octave = new OctaveShift();
6846 measureData->addCrossMeasureElement(octave, true);
6847
6848 if( !jump(3) ) { return false; }
6849
6850 // common
6851 if( !parseCommonBlock(octave) ) { return false; }
6852
6853 // octave
6854 if( !readBuffer(placeHolder, 1) ) { return false; }
6855 unsigned int type = getLowNibble(placeHolder.toUnsignedInt());
6856 OctaveShiftType octaveShiftType = OctaveShiftType::OS_8;
6857 QList<OctaveShiftPosition> positions;
6858 extractOctave(type, octaveShiftType, positions);
6859
6860 octave->setOctaveShiftType(octaveShiftType);
6861
6862 if( !jump(1) ) { return false; }
6863
6864 // y offset
6865 if( !readBuffer(placeHolder, 2) ) { return false; }
6866 octave->setYOffset(placeHolder.toInt());
6867
6868 if( !jump(4) ) { return false; }
6869
6870 // length
6871 if( !readBuffer(placeHolder, 2) ) { return false; }
6872 octave->setLength(placeHolder.toUnsignedInt());
6873
6874 // end tick
6875 if( !readBuffer(placeHolder, 2) ) { return false; }
6876 octave->setEndTick(placeHolder.toUnsignedInt());
6877
6878 // start & stop maybe appear in same measure
6879 for (int i=0; i<positions.size(); ++i) {
6880 OctaveShiftPosition position = positions[i];
6881 OctaveShiftEndPoint* octavePoint = new OctaveShiftEndPoint();
6882 measureData->addMusicData(octavePoint);
6883
6884 octavePoint->copyCommonBlock(*octave);
6885 octavePoint->setOctaveShiftType(octaveShiftType);
6886 octavePoint->setOctaveShiftPosition(position);
6887 octavePoint->setEndTick(octave->getEndTick());
6888
6889 // stop
6890 if( i==0 && position == OctaveShiftPosition::Stop ) {
6891 octavePoint->start()->setOffset(octave->start()->getOffset()+octave->getLength());
6892 }
6893
6894 // end point
6895 if( i>0 ) {
6896 octavePoint->start()->setOffset(octave->start()->getOffset()+octave->getLength());
6897 octavePoint->setTick(octave->getEndTick());
6898 }
6899 }
6900
6901 return true;
6902 }
6903
parseMidiController(MeasureData * measureData,int)6904 bool BarsParse::parseMidiController(MeasureData* measureData, int /*length*/) {
6905 Block placeHolder;
6906 MidiController* controller = new MidiController();
6907 measureData->addMidiData(controller);
6908
6909 parseMidiCommon(controller);
6910
6911 // value [0, 128)
6912 if( !readBuffer(placeHolder, 1) ) { return false; }
6913 controller->setValue(placeHolder.toUnsignedInt());
6914
6915 // controller number
6916 if( !readBuffer(placeHolder, 1) ) { return false; }
6917 controller->setController(placeHolder.toUnsignedInt());
6918
6919 if( ove_->getIsVersion4() ) {
6920 if( !jump(2) ) { return false; }
6921 }
6922
6923 return true;
6924 }
6925
parseMidiProgramChange(MeasureData * measureData,int)6926 bool BarsParse::parseMidiProgramChange(MeasureData* measureData, int /*length*/) {
6927 Block placeHolder;
6928 MidiProgramChange* program = new MidiProgramChange();
6929 measureData->addMidiData(program);
6930
6931 parseMidiCommon(program);
6932
6933 if( !jump(1) ) { return false; }
6934
6935 // patch
6936 if( !readBuffer(placeHolder, 1) ) { return false; }
6937 program->setPatch(placeHolder.toUnsignedInt());
6938
6939 if( ove_->getIsVersion4() ) {
6940 if( !jump(2) ) { return false; }
6941 }
6942
6943 return true;
6944 }
6945
parseMidiChannelPressure(MeasureData * measureData,int)6946 bool BarsParse::parseMidiChannelPressure(MeasureData* measureData, int /*length*/) {
6947 Block placeHolder;
6948 MidiChannelPressure* pressure = new MidiChannelPressure();
6949 measureData->addMidiData(pressure);
6950
6951 parseMidiCommon(pressure);
6952
6953 if( !jump(1) ) { return false; }
6954
6955 // pressure
6956 if( !readBuffer(placeHolder, 1) ) { return false; }
6957 pressure->setPressure(placeHolder.toUnsignedInt());
6958
6959 if( ove_->getIsVersion4() )
6960 {
6961 if( !jump(2) ) { return false; }
6962 }
6963
6964 return true;
6965 }
6966
parseMidiPitchWheel(MeasureData * measureData,int)6967 bool BarsParse::parseMidiPitchWheel(MeasureData* measureData, int /*length*/) {
6968 Block placeHolder;
6969 MidiPitchWheel* wheel = new MidiPitchWheel();
6970 measureData->addMidiData(wheel);
6971
6972 parseMidiCommon(wheel);
6973
6974 // pitch wheel
6975 if( !readBuffer(placeHolder, 2) ) { return false; }
6976 int value = placeHolder.toUnsignedInt();
6977 wheel->setValue(value);
6978
6979 if( ove_->getIsVersion4() ) {
6980 if( !jump(2) ) { return false; }
6981 }
6982
6983 return true;
6984 }
6985
parseSizeBlock(int length)6986 bool BarsParse::parseSizeBlock(int length) {
6987 if( !jump(length) ) { return false; }
6988
6989 return true;
6990 }
6991
parseMidiCommon(MidiData * ptr)6992 bool BarsParse::parseMidiCommon(MidiData* ptr) {
6993 Block placeHolder;
6994
6995 if( !jump(3) ) { return false; }
6996
6997 // start position
6998 if( !readBuffer(placeHolder, 2) ) { return false; }
6999 ptr->setTick(placeHolder.toUnsignedInt());
7000
7001 return true;
7002 }
7003
parseCommonBlock(MusicData * ptr)7004 bool BarsParse::parseCommonBlock(MusicData* ptr) {
7005 Block placeHolder;
7006
7007 // start tick
7008 if( !readBuffer(placeHolder, 2) ) { return false; }
7009 ptr->setTick(placeHolder.toInt());
7010
7011 // start unit
7012 if( !readBuffer(placeHolder, 2) ) { return false; }
7013 ptr->start()->setOffset(placeHolder.toInt());
7014
7015 if( ove_->getIsVersion4() ) {
7016 // color
7017 if( !readBuffer(placeHolder, 1) ) { return false; }
7018 ptr->setColor(placeHolder.toUnsignedInt());
7019
7020 if( !jump(1) ) { return false; }
7021 }
7022
7023 return true;
7024 }
7025
parseOffsetCommonBlock(MusicData * ptr)7026 bool BarsParse::parseOffsetCommonBlock(MusicData* ptr) {
7027 Block placeHolder;
7028
7029 // offset measure
7030 if( !readBuffer(placeHolder, 2) ) { return false; }
7031 ptr->stop()->setMeasure(placeHolder.toUnsignedInt());
7032
7033 // end unit
7034 if( !readBuffer(placeHolder, 2) ) { return false; }
7035 ptr->stop()->setOffset(placeHolder.toInt());
7036
7037 return true;
7038 }
7039
parsePairLinesBlock(PairEnds * ptr)7040 bool BarsParse::parsePairLinesBlock(PairEnds* ptr) {
7041 Block placeHolder;
7042
7043 // left line
7044 if( !readBuffer(placeHolder, 2) ) { return false; }
7045 ptr->getLeftLine()->setLine(placeHolder.toInt());
7046
7047 // right line
7048 if( !readBuffer(placeHolder, 2) ) { return false; }
7049 ptr->getRightLine()->setLine(placeHolder.toInt());
7050
7051 return true;
7052 }
7053
parseOffsetElement(OffsetElement * ptr)7054 bool BarsParse::parseOffsetElement(OffsetElement* ptr) {
7055 Block placeHolder;
7056
7057 // x offset
7058 if( !readBuffer(placeHolder, 2) ) { return false; }
7059 ptr->setXOffset(placeHolder.toInt());
7060
7061 // y offset
7062 if( !readBuffer(placeHolder, 2) ) { return false; }
7063 ptr->setYOffset(placeHolder.toInt());
7064
7065 return true;
7066 }
7067
getCondElementType(unsigned int byteData,CondType & type)7068 bool BarsParse::getCondElementType(unsigned int byteData, CondType& type) {
7069 if( byteData == 0x09 ) {
7070 type = CondType::Time_Parameters;
7071 } else if (byteData == 0x0A) {
7072 type = CondType::Bar_Number;
7073 } else if (byteData == 0x16) {
7074 type = CondType::Decorator;
7075 } else if (byteData == 0x1C) {
7076 type = CondType::Tempo;
7077 } else if (byteData == 0x1D) {
7078 type = CondType::Text;
7079 } else if (byteData == 0x25) {
7080 type = CondType::Expression;
7081 } else if (byteData == 0x30) {
7082 type = CondType::Barline_Parameters;
7083 } else if (byteData == 0x31) {
7084 type = CondType::Repeat;
7085 } else if (byteData == 0x32) {
7086 type = CondType::Numeric_Ending;
7087 } else {
7088 return false;
7089 }
7090
7091 return true;
7092 }
7093
getBdatElementType(unsigned int byteData,BdatType & type)7094 bool BarsParse::getBdatElementType(unsigned int byteData, BdatType& type) {
7095 if (byteData == 0x70) {
7096 type = BdatType::Raw_Note;
7097 } else if (byteData == 0x80) {
7098 type = BdatType::Rest;
7099 } else if (byteData == 0x90) {
7100 type = BdatType::Note;
7101 } else if (byteData == 0x10) {
7102 type = BdatType::Beam;
7103 } else if (byteData == 0x11) {
7104 type = BdatType::Harmony;
7105 } else if (byteData == 0x12) {
7106 type = BdatType::Clef;
7107 } else if (byteData == 0x13) {
7108 type = BdatType::Wedge;
7109 } else if (byteData == 0x14) {
7110 type = BdatType::Dynamics;
7111 } else if (byteData == 0x15) {
7112 type = BdatType::Glissando;
7113 } else if (byteData == 0x16) {
7114 type = BdatType::Decorator;
7115 } else if (byteData == 0x17) {
7116 type = BdatType::Key;
7117 } else if (byteData == 0x18) {
7118 type = BdatType::Lyric;
7119 } else if (byteData == 0x19) {
7120 type = BdatType::Octave_Shift;
7121 } else if (byteData == 0x1B) {
7122 type = BdatType::Slur;
7123 } else if (byteData == 0x1D) {
7124 type = BdatType::Text;
7125 } else if (byteData == 0x1E) {
7126 type = BdatType::Tie;
7127 } else if (byteData == 0x1F) {
7128 type = BdatType::Tuplet;
7129 } else if (byteData == 0x21) {
7130 type = BdatType::Guitar_Bend;
7131 } else if (byteData == 0x22) {
7132 type = BdatType::Guitar_Barre;
7133 } else if (byteData == 0x23) {
7134 type = BdatType::Pedal;
7135 } else if (byteData == 0x24) {
7136 type = BdatType::KuoHao;
7137 } else if (byteData == 0x25) {
7138 type = BdatType::Expressions;
7139 } else if (byteData == 0x26) {
7140 type = BdatType::Harp_Pedal;
7141 } else if (byteData == 0x27) {
7142 type = BdatType::Multi_Measure_Rest;
7143 } else if (byteData == 0x28) {
7144 type = BdatType::Harmony_GuitarFrame;
7145 } else if (byteData == 0x40) {
7146 type = BdatType::Graphics_40;
7147 } else if (byteData == 0x41) {
7148 type = BdatType::Graphics_RoundRect;
7149 } else if (byteData == 0x42) {
7150 type = BdatType::Graphics_Rect;
7151 } else if (byteData == 0x43) {
7152 type = BdatType::Graphics_Round;
7153 } else if (byteData == 0x44) {
7154 type = BdatType::Graphics_Line;
7155 } else if (byteData == 0x45) {
7156 type = BdatType::Graphics_Curve;
7157 } else if (byteData == 0x46) {
7158 type = BdatType::Graphics_WedgeSymbol;
7159 } else if (byteData == 0xAB) {
7160 type = BdatType::Midi_Controller;
7161 } else if (byteData == 0xAC) {
7162 type = BdatType::Midi_Program_Change;
7163 } else if (byteData == 0xAD) {
7164 type = BdatType::Midi_Channel_Pressure;
7165 } else if (byteData == 0xAE) {
7166 type = BdatType::Midi_Pitch_Wheel;
7167 } else if (byteData == 0xFF) {
7168 type = BdatType::Bar_End;
7169 } else {
7170 return false;
7171 }
7172
7173 return true;
7174 }
7175
7176 ///////////////////////////////////////////////////////////////////////////////
LyricChunkParse(OveSong * ove)7177 LyricChunkParse::LyricChunkParse(OveSong* ove) :
7178 BasicParse(ove) {
7179 }
7180
setLyricChunk(SizeChunk * chunk)7181 void LyricChunkParse::setLyricChunk(SizeChunk* chunk) {
7182 chunk_ = chunk;
7183 }
7184
7185 // only ove3 has this chunk
parse()7186 bool LyricChunkParse::parse() {
7187 unsigned int i;
7188 Block* dataBlock = chunk_->getDataBlock();
7189 unsigned int blockSize = chunk_->getSizeBlock()->toSize();
7190 StreamHandle handle(dataBlock->data(), blockSize);
7191 Block placeHolder;
7192
7193 handle_ = &handle;
7194
7195 if( !jump(4) ) { return false; }
7196
7197 // Lyric count
7198 if( !readBuffer(placeHolder, 2) ) { return false; }
7199 unsigned int count = placeHolder.toUnsignedInt();
7200
7201 for( i=0; i<count; ++i ) {
7202 LyricInfo info;
7203
7204 if( !readBuffer(placeHolder, 2) ) { return false; }
7205 //unsigned int size = placeHolder.toUnsignedInt();
7206
7207 // 0x0D00
7208 if( !jump(2) ) { return false; }
7209
7210 // voice
7211 if( !readBuffer(placeHolder, 1) ) { return false; }
7212 info.voice_ = placeHolder.toUnsignedInt();
7213
7214 // verse
7215 if( !readBuffer(placeHolder, 1) ) { return false; }
7216 info.verse_ = placeHolder.toUnsignedInt();
7217
7218 // track
7219 if( !readBuffer(placeHolder, 1) ) { return false; }
7220 info.track_ = placeHolder.toUnsignedInt();
7221
7222 if( !jump(1) ) { return false; }
7223
7224 // measure
7225 if( !readBuffer(placeHolder, 2) ) { return false; }
7226 info.measure_ = placeHolder.toUnsignedInt();
7227
7228 // word count
7229 if( !readBuffer(placeHolder, 2) ) { return false; }
7230 info.wordCount_ = placeHolder.toUnsignedInt();
7231
7232 // lyric size
7233 if( !readBuffer(placeHolder, 2) ) { return false; }
7234 info.lyricSize_ = placeHolder.toUnsignedInt();
7235
7236 if( !jump(6) ) { return false; }
7237
7238 // name
7239 if( !readBuffer(placeHolder, 32) ) { return false; }
7240 info.name_ = ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray());
7241
7242 if( info.lyricSize_ > 0 ) {
7243 // lyric
7244 if( !readBuffer(placeHolder, info.lyricSize_) ) { return false; }
7245 info.lyric_ = ove_->getCodecString(placeHolder.fixedSizeBufferToStrByteArray());
7246
7247 if( !jump(4) ) { return false; }
7248
7249 // font
7250 if( !readBuffer(placeHolder, 2) ) { return false; }
7251 info.font_ = placeHolder.toUnsignedInt();
7252
7253 if( !jump(1) ) { return false; }
7254
7255 // font size
7256 if( !readBuffer(placeHolder, 1) ) { return false; }
7257 info.fontSize_ = placeHolder.toUnsignedInt();
7258
7259 // font style
7260 if( !readBuffer(placeHolder, 1) ) { return false; }
7261 info.fontStyle_ = placeHolder.toUnsignedInt();
7262
7263 if( !jump(1) ) { return false; }
7264
7265 for( int j=0; j<info.wordCount_; ++j ) {
7266 if( !jump(8) ) { return false; }
7267 }
7268 }
7269
7270 processLyricInfo(info);
7271 }
7272
7273 return true;
7274 }
7275
isSpace(char c)7276 bool isSpace(char c) {
7277 return c == ' ' || c == '\n';
7278 }
7279
processLyricInfo(const LyricInfo & info)7280 void LyricChunkParse::processLyricInfo(const LyricInfo& info) {
7281 int i;
7282 int j;
7283 int index = 0; //words
7284
7285 int measureId = info.measure_-1;
7286 bool changeMeasure = true;
7287 MeasureData* measureData = 0;
7288 int trackMeasureCount = ove_->getTrackBarCount();
7289 QStringList words = info.lyric_.split(" ", QString::SkipEmptyParts);
7290
7291 while ( index < words.size() && measureId+1 < trackMeasureCount ) {
7292 if( changeMeasure ) {
7293 ++measureId;
7294 measureData = ove_->getMeasureData(info.track_, measureId);
7295 changeMeasure = false;
7296 }
7297
7298 if( measureData == 0 ) { return; }
7299 QList<NoteContainer*> containers = measureData->getNoteContainers();
7300 QList<MusicData*> lyrics = measureData->getMusicDatas(MusicDataType::Lyric);
7301
7302 for( i=0; i<containers.size() && index<words.size(); ++i ) {
7303 if( containers[i]->getIsRest() ) {
7304 continue;
7305 }
7306
7307 for( j=0; j<lyrics.size(); ++j ) {
7308 Lyric* lyric = static_cast<Lyric*>(lyrics[j]);
7309
7310 if( containers[i]->start()->getOffset() == lyric->start()->getOffset() &&
7311 (int)containers[i]->getVoice() == info.voice_ &&
7312 lyric->getVerse() == info.verse_ ) {
7313 if(index<words.size()) {
7314 QString l = words[index].trimmed();
7315 if(!l.isEmpty()) {
7316 lyric->setLyric(l);
7317 lyric->setVoice(info.voice_);
7318 }
7319 }
7320
7321 ++index;
7322 }
7323 }
7324 }
7325
7326 changeMeasure = true;
7327 }
7328 }
7329
7330 ///////////////////////////////////////////////////////////////////////////////
TitleChunkParse(OveSong * ove)7331 TitleChunkParse::TitleChunkParse(OveSong* ove) :
7332 BasicParse(ove) {
7333 titleType_ = 0x00000001;
7334 annotateType_ = 0x00010000;
7335 writerType_ = 0x00020002;
7336 copyrightType_ = 0x00030001;
7337 headerType_ = 0x00040000;
7338 footerType_ = 0x00050002;
7339 }
7340
setTitleChunk(SizeChunk * chunk)7341 void TitleChunkParse::setTitleChunk(SizeChunk* chunk) {
7342 chunk_ = chunk;
7343 }
7344
getByteArray(const Block & block)7345 QByteArray getByteArray(const Block& block) {
7346 QByteArray array((char*)block.data(), block.size());
7347 int index0 = array.indexOf('\0');
7348 array = array.left(index0);
7349
7350 return array;
7351 }
7352
parse()7353 bool TitleChunkParse::parse() {
7354 Block* dataBlockP = chunk_->getDataBlock();
7355 unsigned int blockSize = chunk_->getSizeBlock()->toSize();
7356 StreamHandle handle(dataBlockP->data(), blockSize);
7357 Block typeBlock;
7358 unsigned int titleType;
7359
7360 handle_ = &handle;
7361
7362 if( !readBuffer(typeBlock, 4) ) { return false; }
7363
7364 titleType = typeBlock.toUnsignedInt();
7365
7366 if( titleType == titleType_ || titleType == annotateType_ || titleType == writerType_ || titleType == copyrightType_ ) {
7367 Block offsetBlock;
7368
7369 if( !readBuffer(offsetBlock, 4) ) { return false; }
7370
7371 const unsigned int itemCount = 4;
7372 unsigned int i;
7373
7374 for( i=0; i<itemCount; ++i ) {
7375 if( i>0 ) {
7376 //0x 00 AB 00 0C 00 00
7377 if( !jump(6) ) { return false; }
7378 }
7379
7380 Block countBlock;
7381 if( !readBuffer(countBlock, 2) ) { return false; }
7382 unsigned int titleSize = countBlock.toUnsignedInt();
7383
7384 Block dataBlock;
7385 if( !readBuffer(dataBlock, titleSize) ) { return false; }
7386
7387 QByteArray array = getByteArray(dataBlock);
7388 if(!array.isEmpty()) {
7389 addToOve(ove_->getCodecString(array), titleType);
7390 }
7391 }
7392
7393 return true;
7394 }
7395
7396 if( titleType == headerType_ || titleType == footerType_ ) {
7397 if( !jump(10) ) { return false; }
7398
7399 Block countBlock;
7400 if( !readBuffer(countBlock, 2) ) { return false; }
7401 unsigned int titleSize = countBlock.toUnsignedInt();
7402
7403 Block dataBlock;
7404 if( !readBuffer(dataBlock, titleSize) ) { return false; }
7405
7406 QByteArray array = getByteArray(dataBlock);
7407 addToOve(ove_->getCodecString(array), titleType);
7408
7409 //0x 00 AB 00 0C 00 00
7410 if( !jump(6) ) { return false; }
7411
7412 return true;
7413 }
7414
7415 return false;
7416 }
7417
addToOve(const QString & str,unsigned int titleType)7418 void TitleChunkParse::addToOve(const QString& str, unsigned int titleType) {
7419 if( str.isEmpty() ) { return; }
7420
7421 if (titleType == titleType_) {
7422 ove_->addTitle(str);
7423 }
7424
7425 if (titleType == annotateType_) {
7426 ove_->addAnnotate(str);
7427 }
7428
7429 if (titleType == writerType_) {
7430 ove_->addWriter(str);
7431 }
7432
7433 if (titleType == copyrightType_) {
7434 ove_->addCopyright(str);
7435 }
7436
7437 if (titleType == headerType_) {
7438 ove_->addHeader(str);
7439 }
7440
7441 if (titleType == footerType_) {
7442 ove_->addFooter(str);
7443 }
7444 }
7445
7446 // OveOrganize.cpp
OveOrganizer(OveSong * ove)7447 OveOrganizer::OveOrganizer(OveSong* ove) {
7448 ove_ = ove;
7449 }
7450
organize()7451 void OveOrganizer::organize() {
7452 if(ove_ == NULL) {
7453 return;
7454 }
7455
7456 organizeTracks();
7457 organizeAttributes();
7458 organizeMeasures();
7459 }
7460
organizeAttributes()7461 void OveOrganizer::organizeAttributes() {
7462 int i;
7463 int j;
7464 int k;
7465
7466 // key
7467 if(ove_->getLineCount() > 0) {
7468 Line* line = ove_->getLine(0);
7469 int partBarCount = ove_->getPartBarCount();
7470 int lastKey = 0;
7471
7472 if(line != 0){
7473 for(i=0; i<line->getStaffCount(); ++i) {
7474 QPair<int, int> partStaff = ove_->trackToPartStaff(i);
7475 Staff* staff = line->getStaff(i);
7476 lastKey = staff->getKeyType();
7477
7478 for(j=0; j<partBarCount; ++j) {
7479 MeasureData* measureData = ove_->getMeasureData(partStaff.first, partStaff.second, j);
7480
7481 if(measureData != 0) {
7482 Key* key = measureData->getKey();
7483
7484 if( j==0 ) {
7485 key->setKey(lastKey);
7486 key->setPreviousKey(lastKey);
7487 }
7488
7489 if( !key->getSetKey() ) {
7490 key->setKey(lastKey);
7491 key->setPreviousKey(lastKey);
7492 }
7493 else {
7494 if( key->getKey() != lastKey ) {
7495 lastKey = key->getKey();
7496 }
7497 }
7498 }
7499 }
7500 }
7501 }
7502 }
7503
7504 // clef
7505 if( ove_->getLineCount() > 0 ) {
7506 Line* line = ove_->getLine(0);
7507 int partBarCount = ove_->getPartBarCount();
7508 ClefType lastClefType = ClefType::Treble;
7509
7510 if(line != 0){
7511 for( i=0; i<line->getStaffCount(); ++i ) {
7512 QPair<int, int> partStaff = ove_->trackToPartStaff(i);
7513 Staff* staff = line->getStaff(i);
7514 lastClefType = staff->getClefType();
7515
7516 for( j=0; j<partBarCount; ++j ) {
7517 MeasureData* measureData = ove_->getMeasureData(partStaff.first, partStaff.second, j);
7518
7519 if(measureData != 0) {
7520 Clef* clefPtr = measureData->getClef();
7521 clefPtr->setClefType((int)lastClefType);
7522
7523 const QList<MusicData*>& clefs = measureData->getMusicDatas(MusicDataType::Clef);
7524
7525 for( k=0; k<clefs.size(); ++k ) {
7526 Clef* clef = static_cast<Clef*>(clefs[k]);
7527 lastClefType = clef->getClefType();
7528 }
7529 }
7530 }
7531 }
7532 }
7533 }
7534 }
7535
getStaff(OveSong * ove,int track)7536 Staff* getStaff(OveSong* ove, int track) {
7537 if (ove->getLineCount() > 0) {
7538 Line* line = ove->getLine(0);
7539 if(line != 0 && line->getStaffCount() > 0) {
7540 Staff* staff = line->getStaff(track);
7541 return staff;
7542 }
7543 }
7544
7545 return 0;
7546 }
7547
organizeTracks()7548 void OveOrganizer::organizeTracks() {
7549 int i;
7550 //QList<QPair<ClefType, int> > trackChannels;
7551 QList<Track*> tracks = ove_->getTracks();
7552 QList<bool> comboStaveStarts;
7553
7554 for( i=0; i<tracks.size(); ++i ) {
7555 comboStaveStarts.push_back(false);
7556 }
7557
7558 for( i=0; i<tracks.size(); ++i ) {
7559 Staff* staff = getStaff(ove_, i);
7560 if(staff != 0) {
7561 if(staff->getGroupType() == GroupType::Brace && staff->getGroupStaffCount() == 1 ) {
7562 comboStaveStarts[i] = true;
7563 }
7564 }
7565
7566 /*if( i < tracks.size() - 1 ) {
7567 if( tracks[i]->getStartClef() == ClefType::Treble &&
7568 tracks[i+1]->getStartClef() == ClefType::Bass &&
7569 tracks[i]->getChannel() == tracks[i+1]->get_channel() ) {
7570 }
7571 }*/
7572 }
7573
7574 int trackId = 0;
7575 QList<int> partStaffCounts;
7576
7577 while( trackId < (int)tracks.size() ) {
7578 int partTrackCount = 1;
7579
7580 if( comboStaveStarts[trackId] ) {
7581 partTrackCount = 2;
7582 }
7583
7584 partStaffCounts.push_back(partTrackCount);
7585 trackId += partTrackCount;
7586 }
7587
7588 ove_->setPartStaffCounts(partStaffCounts);
7589 }
7590
organizeMeasures()7591 void OveOrganizer::organizeMeasures() {
7592 int trackBarCount = ove_->getTrackBarCount();
7593
7594 for( int i=0; i<ove_->getPartCount(); ++i ) {
7595 int partStaffCount = ove_->getStaffCount(i);
7596
7597 for( int j=0; j<partStaffCount; ++j ) {
7598 for( int k=0; k<trackBarCount; ++k ) {
7599 Measure* measure = ove_->getMeasure(k);
7600 MeasureData* measureData = ove_->getMeasureData(i, j, k);
7601
7602 organizeMeasure(i, j, measure, measureData);
7603 }
7604 }
7605 }
7606 }
7607
organizeMeasure(int part,int track,Measure * measure,MeasureData * measureData)7608 void OveOrganizer::organizeMeasure(int part, int track, Measure* measure, MeasureData* measureData) {
7609 // note containers
7610 organizeContainers(part, track, measure, measureData);
7611
7612 // single end data
7613 organizeMusicDatas(part, track, measure, measureData);
7614
7615 // cross measure elements
7616 organizeCrossMeasureElements(part, track, measure, measureData);
7617 }
7618
addToList(QList<int> & list,int number)7619 void addToList(QList<int>& list, int number) {
7620 for(int i=0; i<list.size(); ++i){
7621 if(list[i] == number){
7622 return;
7623 }
7624 }
7625
7626 list.push_back(number);
7627 }
7628
organizeContainers(int,int,Measure * measure,MeasureData * measureData)7629 void OveOrganizer::organizeContainers(int /*part*/, int /*track*/,
7630 Measure* measure, MeasureData* measureData) {
7631 int i;
7632 QList<NoteContainer*> containers = measureData->getNoteContainers();
7633 int barUnits = measure->getTime()->getUnits();
7634 QList<int> voices;
7635
7636 for(i=0; i<containers.size(); ++i){
7637 int endUnit = barUnits;
7638 if( i < containers.size() - 1 ) {
7639 endUnit = containers[i+1]->start()->getOffset();
7640 }
7641
7642 containers[i]->stop()->setOffset(endUnit);
7643 addToList(voices, containers[i]->getVoice());
7644 }
7645
7646 // shift voices
7647 std::sort(voices.begin(), voices.end());
7648
7649 for (i = 0; i < voices.size(); ++i) {
7650 int voice = voices[i];
7651 // voice -> i
7652 for(int j=0; j<(int)containers.size(); ++j) {
7653 int avoice = containers[j]->getVoice();
7654 if ( avoice == voice && avoice != i ) {
7655 containers[j]->setVoice(i);
7656 }
7657 }
7658 }
7659 }
7660
organizeMusicDatas(int,int,Measure * measure,MeasureData * measureData)7661 void OveOrganizer::organizeMusicDatas(int /*part*/, int /*track*/, Measure* measure, MeasureData* measureData) {
7662 int i;
7663 int barIndex = measure->getBarNumber()->getIndex();
7664 QList<MusicData*> datas = measureData->getMusicDatas(MusicDataType::None);
7665
7666 for(i=0; i<datas.size(); ++i) {
7667 datas[i]->start()->setMeasure(barIndex);
7668 }
7669 }
7670
organizeCrossMeasureElements(int part,int track,Measure * measure,MeasureData * measureData)7671 void OveOrganizer::organizeCrossMeasureElements(int part, int track, Measure* measure, MeasureData* measureData) {
7672 int i;
7673 QList<MusicData*> pairs = measureData->getCrossMeasureElements(MusicDataType::None, MeasureData::PairType::Start);
7674
7675 for(i=0; i<pairs.size(); ++i) {
7676 MusicData* pair = pairs[i];
7677
7678 switch ( pair->getMusicDataType() ) {
7679 case MusicDataType::Beam :
7680 case MusicDataType::Glissando :
7681 case MusicDataType::Slur :
7682 case MusicDataType::Tie :
7683 case MusicDataType::Tuplet :
7684 case MusicDataType::Pedal :
7685 case MusicDataType::Numeric_Ending :
7686 //case MusicDataType::OctaveShift_EndPoint :
7687 case MusicDataType::Measure_Repeat : {
7688 organizePairElement(pair, part, track, measure, measureData);
7689 break;
7690 }
7691 case MusicDataType::OctaveShift : {
7692 OctaveShift* octave = static_cast<OctaveShift*>(pair);
7693 organizeOctaveShift(octave, measure, measureData);
7694 break;
7695 }
7696 case MusicDataType::Wedge : {
7697 Wedge* wedge = static_cast<Wedge*>(pair);
7698 organizeWedge(wedge, part, track, measure, measureData);
7699 break;
7700 }
7701 default:
7702 break;
7703 }
7704 }
7705 }
7706
organizePairElement(MusicData * data,int part,int track,Measure * measure,MeasureData * measureData)7707 void OveOrganizer::organizePairElement(
7708 MusicData* data,
7709 int part,
7710 int track,
7711 Measure* measure,
7712 MeasureData* measureData) {
7713 int bar1Index = measure->getBarNumber()->getIndex();
7714 int bar2Index = bar1Index + data->stop()->getMeasure();
7715 MeasureData* measureData2 = ove_->getMeasureData(part, track, bar2Index);
7716
7717 data->start()->setMeasure(bar1Index);
7718
7719 if(measureData2 != 0 && measureData != measureData2) {
7720 measureData2->addCrossMeasureElement(data, false);
7721 }
7722
7723 if( data->getMusicDataType() == MusicDataType::Tuplet ){
7724 Tuplet* tuplet = static_cast<Tuplet*>(data);
7725 const QList<NoteContainer*> containers = measureData->getNoteContainers();
7726
7727 for(int i=0; i<containers.size(); ++i){
7728 if(containers[i]->getTick() > tuplet->getTick()){
7729 break;
7730 }
7731
7732 if(containers[i]->getTick() == tuplet->getTick()){
7733 tuplet->setNoteType(containers[i]->getNoteType());
7734 }
7735 }
7736
7737 int tupletTick = NoteTypeToTick(tuplet->getNoteType(), ove_->getQuarter())*tuplet->getSpace();
7738 if( tuplet->getTick() % tupletTick != 0 ) {
7739 int newStartTick = (tuplet->getTick() / tupletTick) * tupletTick;
7740
7741 for(int i=0; i<containers.size(); ++i){
7742 if( containers[i]->getTick() == newStartTick &&
7743 containers[i]->getTuplet() == tuplet->getTuplet()) {
7744 tuplet->setTick(containers[i]->getTick());
7745 tuplet->start()->setOffset(containers[i]->start()->getOffset());
7746 }
7747 }
7748 }
7749 }
7750 }
7751
organizeOctaveShift(OctaveShift * octave,Measure * measure,MeasureData * measureData)7752 void OveOrganizer::organizeOctaveShift(
7753 OctaveShift* octave,
7754 Measure* measure,
7755 MeasureData* measureData) {
7756 // octave shift
7757 int i;
7758 const QList<NoteContainer*> containers = measureData->getNoteContainers();
7759 int barIndex = measure->getBarNumber()->getIndex();
7760
7761 octave->start()->setMeasure(barIndex);
7762
7763 for(i=0; i<containers.size(); ++i) {
7764 int noteShift = octave->getNoteShift();
7765 int containerTick = containers[i]->getTick();
7766
7767 if( octave->getTick() <= containerTick && octave->getEndTick() > containerTick ) {
7768 containers[i]->setNoteShift(noteShift);
7769 }
7770 }
7771 }
7772
getMiddleUnit(OveSong * ove,int,int,Measure * measure1,Measure * measure2,int unit1,int,Measure * middleMeasure,int & middleUnit)7773 bool getMiddleUnit(
7774 OveSong* ove, int /*part*/, int /*track*/,
7775 Measure* measure1, Measure* measure2, int unit1, int /*unit2*/,
7776 Measure* middleMeasure, int& middleUnit) {
7777 Q_UNUSED(middleMeasure); // avoid (bogus?) warning to show up
7778 QList<int> barUnits;
7779 int i;
7780 int bar1Index = measure1->getBarNumber()->getIndex();
7781 int bar2Index = measure2->getBarNumber()->getIndex();
7782 int sumUnit = 0;
7783
7784 for( int j=bar1Index; j<=bar2Index; ++j ) {
7785 Measure* measure = ove->getMeasure(j);
7786 barUnits.push_back(measure->getTime()->getUnits());
7787 sumUnit += measure->getTime()->getUnits();
7788 }
7789
7790 int currentSumUnit = 0;
7791 for( i=0; i<barUnits.size(); ++i ) {
7792 int barUnit = barUnits[i];
7793
7794 if( i==0 ) {
7795 barUnit = barUnits[i] - unit1;
7796 }
7797
7798 if( currentSumUnit + barUnit < sumUnit/2 ) {
7799 currentSumUnit += barUnit;
7800 }
7801 else {
7802 break;
7803 }
7804 }
7805
7806 if( i < barUnits.size() ) {
7807 int barMiddleIndex = bar1Index + i;
7808 middleMeasure = ove->getMeasure(barMiddleIndex);
7809 middleUnit = sumUnit/2 - currentSumUnit;
7810
7811 return true;
7812 }
7813
7814 return false;
7815 }
7816
organizeWedge(Wedge * wedge,int part,int track,Measure * measure,MeasureData * measureData)7817 void OveOrganizer::organizeWedge(Wedge* wedge, int part, int track, Measure* measure, MeasureData* measureData) {
7818 int bar1Index = measure->getBarNumber()->getIndex();
7819 int bar2Index = bar1Index + wedge->stop()->getMeasure();
7820 MeasureData* measureData2 = ove_->getMeasureData(part, track, bar2Index);
7821 WedgeType wedgeType = wedge->getWedgeType();
7822
7823 if( wedge->getWedgeType() == WedgeType::Double_Line ) {
7824 wedgeType = WedgeType::Cres_Line;
7825 }
7826
7827 wedge->start()->setMeasure(bar1Index);
7828
7829 WedgeEndPoint* startPoint = new WedgeEndPoint();
7830 measureData->addMusicData(startPoint);
7831
7832 startPoint->setTick(wedge->getTick());
7833 startPoint->start()->setOffset(wedge->start()->getOffset());
7834 startPoint->setWedgeStart(true);
7835 startPoint->setWedgeType(wedgeType);
7836 startPoint->setHeight(wedge->getHeight());
7837
7838 WedgeEndPoint* stopPoint = new WedgeEndPoint();
7839
7840 stopPoint->setTick(wedge->getTick());
7841 stopPoint->start()->setOffset(wedge->stop()->getOffset());
7842 stopPoint->setWedgeStart(false);
7843 stopPoint->setWedgeType(wedgeType);
7844 stopPoint->setHeight(wedge->getHeight());
7845
7846 if(measureData2 != 0) {
7847 measureData2->addMusicData(stopPoint);
7848 }
7849
7850 if( wedge->getWedgeType() == WedgeType::Double_Line ) {
7851 Measure* middleMeasure = NULL;
7852 int middleUnit = 0;
7853
7854 getMiddleUnit(
7855 ove_, part, track,
7856 measure, ove_->getMeasure(bar2Index),
7857 wedge->start()->getOffset(), wedge->stop()->getOffset(),
7858 middleMeasure, middleUnit);
7859
7860 if( middleUnit != 0 ) {
7861 WedgeEndPoint* midStopPoint = new WedgeEndPoint();
7862 measureData->addMusicData(midStopPoint);
7863
7864 midStopPoint->setTick(wedge->getTick());
7865 midStopPoint->start()->setOffset(middleUnit);
7866 midStopPoint->setWedgeStart(false);
7867 midStopPoint->setWedgeType(WedgeType::Cres_Line);
7868 midStopPoint->setHeight(wedge->getHeight());
7869
7870 WedgeEndPoint* midStartPoint = new WedgeEndPoint();
7871 measureData->addMusicData(midStartPoint);
7872
7873 midStartPoint->setTick(wedge->getTick());
7874 midStartPoint->start()->setOffset(middleUnit);
7875 midStartPoint->setWedgeStart(true);
7876 midStartPoint->setWedgeType(WedgeType::Decresc_Line);
7877 midStartPoint->setHeight(wedge->getHeight());
7878 }
7879 }
7880 }
7881
7882
7883 // OveSerialize.cpp
7884 enum class ChunkType : char {
7885 OVSC = 00 ,
7886 TRKL,
7887 TRAK,
7888 PAGL,
7889 PAGE,
7890 LINL,
7891 LINE,
7892 STAF,
7893 BARL,
7894 MEAS,
7895 COND,
7896 BDAT,
7897 PACH,
7898 FNTS,
7899 ODEV,
7900 TITL,
7901 ALOT,
7902 ENGR,
7903 FMAP,
7904 PCPR,
7905
7906 // Overture 3.6
7907 LYRC,
7908
7909 NONE
7910 };
7911
nameToChunkType(const NameBlock & name)7912 ChunkType nameToChunkType(const NameBlock& name) {
7913 ChunkType type = ChunkType::NONE;
7914
7915 if (name.isEqual("OVSC")) {
7916 type = ChunkType::OVSC;
7917 } else if (name.isEqual("TRKL")) {
7918 type = ChunkType::TRKL;
7919 } else if (name.isEqual("TRAK")) {
7920 type = ChunkType::TRAK;
7921 } else if (name.isEqual("PAGL")) {
7922 type = ChunkType::PAGL;
7923 } else if (name.isEqual("PAGE")) {
7924 type = ChunkType::PAGE;
7925 } else if (name.isEqual("LINL")) {
7926 type = ChunkType::LINL;
7927 } else if (name.isEqual("LINE")) {
7928 type = ChunkType::LINE;
7929 } else if (name.isEqual("STAF")) {
7930 type = ChunkType::STAF;
7931 } else if (name.isEqual("BARL")) {
7932 type = ChunkType::BARL;
7933 } else if (name.isEqual("MEAS")) {
7934 type = ChunkType::MEAS;
7935 } else if (name.isEqual("COND")) {
7936 type = ChunkType::COND;
7937 } else if (name.isEqual("BDAT")) {
7938 type = ChunkType::BDAT;
7939 } else if (name.isEqual("PACH")) {
7940 type = ChunkType::PACH;
7941 } else if (name.isEqual("FNTS")) {
7942 type = ChunkType::FNTS;
7943 } else if (name.isEqual("ODEV")) {
7944 type = ChunkType::ODEV;
7945 } else if (name.isEqual("TITL")) {
7946 type = ChunkType::TITL;
7947 } else if (name.isEqual("ALOT")) {
7948 type = ChunkType::ALOT;
7949 } else if (name.isEqual("ENGR")) {
7950 type = ChunkType::ENGR;
7951 } else if (name.isEqual("FMAP")) {
7952 type = ChunkType::FMAP;
7953 } else if (name.isEqual("PCPR")) {
7954 type = ChunkType::PCPR;
7955 } else if (name.isEqual("LYRC")) {
7956 type = ChunkType::LYRC;
7957 }
7958
7959 return type;
7960 }
7961
chunkTypeToMaxTimes(ChunkType type)7962 int chunkTypeToMaxTimes(ChunkType type) {
7963 int maxTimes = -1; // no limit
7964
7965 switch (type) {
7966 case ChunkType::OVSC: {
7967 maxTimes = 1;
7968 break;
7969 }
7970 case ChunkType::TRKL: {// case ChunkType::TRAK :
7971 maxTimes = 1;
7972 break;
7973 }
7974 case ChunkType::PAGL: {// case ChunkType::PAGE :
7975 maxTimes = 1;
7976 break;
7977 }
7978 // case ChunkType::LINE :
7979 // case ChunkType::STAF :
7980 case ChunkType::LINL: {
7981 maxTimes = 1;
7982 break;
7983 }
7984 // case ChunkType::MEAS :
7985 // case ChunkType::COND :
7986 // case ChunkType::BDAT :
7987 case ChunkType::BARL: {
7988 maxTimes = 1;
7989 break;
7990 }
7991 case ChunkType::PACH:
7992 case ChunkType::FNTS:
7993 case ChunkType::ODEV:
7994 case ChunkType::ALOT:
7995 case ChunkType::ENGR:
7996 case ChunkType::FMAP:
7997 case ChunkType::PCPR: {
7998 maxTimes = 1;
7999 break;
8000 }
8001 case ChunkType::TITL: {
8002 maxTimes = 8;
8003 break;
8004 }
8005 case ChunkType::LYRC: {
8006 maxTimes = 1;
8007 break;
8008 }
8009 // case ChunkType::NONE :
8010 default:
8011 break;
8012 }
8013
8014 return maxTimes;
8015 }
8016
8017 ///////////////////////////////////////////////////////////////////////////////////////////
8018
OveSerialize()8019 OveSerialize::OveSerialize() :
8020 ove_(0),
8021 streamHandle_(0),
8022 notify_(0) {
8023 }
8024
~OveSerialize()8025 OveSerialize::~OveSerialize() {
8026 if(streamHandle_ != 0) {
8027 delete streamHandle_;
8028 streamHandle_ = 0;
8029 }
8030 }
8031
setOve(OveSong * ove)8032 void OveSerialize::setOve(OveSong* ove) {
8033 ove_ = ove;
8034 }
8035
setFileStream(unsigned char * buffer,unsigned int size)8036 void OveSerialize::setFileStream(unsigned char* buffer, unsigned int size) {
8037 streamHandle_ = new StreamHandle(buffer, size);
8038 }
8039
setNotify(IOveNotify * notify)8040 void OveSerialize::setNotify(IOveNotify* notify) {
8041 notify_ = notify;
8042 }
8043
messageOutError()8044 void OveSerialize::messageOutError() {
8045 if (notify_ != NULL) {
8046 notify_->loadError();
8047 }
8048 }
8049
messageOut(const QString & str)8050 void OveSerialize::messageOut(const QString& str) {
8051 if (notify_ != NULL) {
8052 notify_->loadInfo(str);
8053 }
8054 }
8055
load(void)8056 bool OveSerialize::load(void) {
8057 if(streamHandle_ == 0)
8058 return false;
8059
8060 if( !readHeader() ) {
8061 messageOutError();
8062 return false;
8063 }
8064
8065 unsigned int i;
8066 QMap<ChunkType, int> chunkTimes;
8067 //bool firstEnter = true;
8068
8069 for( i=(int)ChunkType::OVSC; i<(int)ChunkType::NONE; ++i ) {
8070 chunkTimes[(ChunkType)i] = 0;
8071 }
8072
8073 ChunkType chunkType = ChunkType::NONE;
8074
8075 do {
8076 NameBlock nameBlock;
8077 SizeChunk sizeChunk;
8078
8079 if( !readNameBlock(nameBlock) ) { return false; }
8080
8081 chunkType = nameToChunkType(nameBlock);
8082 ++chunkTimes[chunkType];
8083 int maxTime = chunkTypeToMaxTimes(chunkType);
8084
8085 if( maxTime > 0 && chunkTimes[chunkType] > maxTime ) {
8086 messageOut("format not support, chunk appear more than accept.\n");
8087 return false;
8088 }
8089
8090 switch (chunkType) {
8091 /*case ChunkType::OVSC :
8092 {
8093 if( !readHeadData(&sizeChunk) )
8094 {
8095 messageOut_error();
8096 return false;
8097 }
8098
8099 break;
8100 }*/
8101 case ChunkType::TRKL: {
8102 if (!readTracksData()) {
8103 messageOutError();
8104 return false;
8105 }
8106
8107 break;
8108 }
8109 case ChunkType::PAGL: {
8110 if (!readPagesData()) {
8111 messageOutError();
8112 return false;
8113 }
8114
8115 break;
8116 }
8117 case ChunkType::LINL: {
8118 if (!readLinesData()) {
8119 messageOutError();
8120 return false;
8121 }
8122
8123 break;
8124 }
8125 case ChunkType::BARL: {
8126 if (!readBarsData()) {
8127 messageOutError();
8128 return false;
8129 }
8130
8131 break;
8132 }
8133 case ChunkType::TRAK:
8134 case ChunkType::PAGE:
8135 case ChunkType::LINE:
8136 case ChunkType::STAF:
8137 case ChunkType::MEAS:
8138 case ChunkType::COND:
8139 case ChunkType::BDAT: {
8140 return false;
8141 break;
8142 }
8143 case ChunkType::LYRC: {
8144 SizeChunk lyricChunk;
8145 if (!readSizeChunk(&lyricChunk)) {
8146 messageOutError();
8147 return false;
8148 }
8149
8150 LyricChunkParse parse(ove_);
8151
8152 parse.setLyricChunk(&lyricChunk);
8153 parse.parse();
8154
8155 break;
8156 }
8157 case ChunkType::TITL: {
8158 SizeChunk titleChunk;
8159 if (!readSizeChunk(&titleChunk)) {
8160 messageOutError();
8161 return false;
8162 }
8163
8164 TitleChunkParse titleChunkParse(ove_);
8165
8166 titleChunkParse.setTitleChunk(&titleChunk);
8167 titleChunkParse.parse();
8168
8169 break;
8170 }
8171 case ChunkType::PACH:
8172 case ChunkType::FNTS:
8173 case ChunkType::ODEV:
8174 case ChunkType::ALOT:
8175 case ChunkType::ENGR:
8176 case ChunkType::FMAP:
8177 case ChunkType::PCPR: {
8178 if (!readSizeChunk(&sizeChunk)) {
8179 messageOutError();
8180 return false;
8181 }
8182
8183 break;
8184 }
8185 default:
8186 /*if( firstEnter )
8187 {
8188 QString info = "Not compatible file, try to load and save with newer version, Overture 4 is recommended.\n";
8189 messageOut(info);
8190 messageOutError();
8191
8192 return false;
8193 }*/
8194
8195 break;
8196 }
8197
8198 //firstEnter = false;
8199 }
8200 while ( chunkType != ChunkType::NONE );
8201
8202 // if( !readOveEnd() ) { return false; }
8203
8204 // organize OveData
8205 OVE::OveOrganizer organizer(ove_);
8206 organizer.organize();
8207
8208 return true;
8209 }
8210
release()8211 void OveSerialize::release() {
8212 delete this;
8213 }
8214
readHeader()8215 bool OveSerialize::readHeader() {
8216 ChunkType chunkType = ChunkType::NONE;
8217 NameBlock nameBlock;
8218 SizeChunk sizeChunk;
8219
8220 if (!readNameBlock(nameBlock)) {
8221 return false;
8222 }
8223
8224 chunkType = nameToChunkType(nameBlock);
8225 //int maxTime = chunkTypeToMaxTimes(chunkType);
8226
8227 if (chunkType == ChunkType::OVSC) {
8228 if (readHeadData(&sizeChunk)) {
8229 return true;
8230 }
8231 }
8232
8233 QString info = "Not compatible file, try to load and save with newer version, Overture 4 is recommended.\n";
8234 messageOut(info);
8235
8236 return false;
8237 }
8238
readHeadData(SizeChunk * ovscChunk)8239 bool OveSerialize::readHeadData(SizeChunk* ovscChunk) {
8240 if (!readSizeChunk(ovscChunk))
8241 return false;
8242
8243 OvscParse ovscParse(ove_);
8244
8245 ovscParse.setNotify(notify_);
8246 ovscParse.setOvsc(ovscChunk);
8247
8248 return ovscParse.parse();
8249 }
8250
readTracksData()8251 bool OveSerialize::readTracksData() {
8252 GroupChunk trackGroupChunk;
8253
8254 if (!readGroupChunk(&trackGroupChunk))
8255 return false;
8256
8257 unsigned int i;
8258 unsigned short trackCount = trackGroupChunk.getCountBlock()->toCount();
8259
8260 for (i = 0; i < trackCount; ++i) {
8261 SizeChunk* trackChunk = new SizeChunk();
8262
8263 if (ove_->getIsVersion4()) {
8264 if (!readChunkName(trackChunk, Chunk::TrackName)) {
8265 return false;
8266 }
8267 if (!readSizeChunk(trackChunk)) {
8268 return false;
8269 }
8270 } else {
8271 if (!readDataChunk(trackChunk->getDataBlock(),
8272 SizeChunk::version3TrackSize)) {
8273 return false;
8274 }
8275 }
8276
8277 TrackParse trackParse(ove_);
8278
8279 trackParse.setTrack(trackChunk);
8280 trackParse.parse();
8281 }
8282
8283 return true;
8284 }
8285
readPagesData()8286 bool OveSerialize::readPagesData() {
8287 GroupChunk pageGroupChunk;
8288
8289 if (!readGroupChunk(&pageGroupChunk))
8290 return false;
8291
8292 unsigned short pageCount = pageGroupChunk.getCountBlock()->toCount();
8293 unsigned int i;
8294 PageGroupParse parse(ove_);
8295
8296 for (i = 0; i < pageCount; ++i) {
8297 SizeChunk* pageChunk = new SizeChunk();
8298
8299 if (!readChunkName(pageChunk, Chunk::PageName)) {
8300 return false;
8301 }
8302 if (!readSizeChunk(pageChunk)) {
8303 return false;
8304 }
8305
8306 parse.addPage(pageChunk);
8307 }
8308
8309 if (!parse.parse()) {
8310 return false;
8311 }
8312
8313 return true;
8314 }
8315
readLinesData()8316 bool OveSerialize::readLinesData() {
8317 GroupChunk lineGroupChunk;
8318 if (!readGroupChunk(&lineGroupChunk))
8319 return false;
8320
8321 unsigned short lineCount = lineGroupChunk.getCountBlock()->toCount();
8322 int i;
8323 unsigned int j;
8324 QList<SizeChunk*> lineChunks;
8325 QList<SizeChunk*> staffChunks;
8326
8327 for (i = 0; i < lineCount; ++i) {
8328 SizeChunk* lineChunk = new SizeChunk();
8329
8330 if (!readChunkName(lineChunk, Chunk::LineName)) {
8331 return false;
8332 }
8333 if (!readSizeChunk(lineChunk)) {
8334 return false;
8335 }
8336
8337 lineChunks.push_back(lineChunk);
8338
8339 StaffCountGetter getter(ove_);
8340 unsigned int staffCount = getter.getStaffCount(lineChunk);
8341
8342 for (j = 0; j < staffCount; ++j) {
8343 SizeChunk* staffChunk = new SizeChunk();
8344
8345 if (!readChunkName(staffChunk, Chunk::StaffName)) {
8346 return false;
8347 }
8348 if (!readSizeChunk(staffChunk)) {
8349 return false;
8350 }
8351
8352 staffChunks.push_back(staffChunk);
8353 }
8354 }
8355
8356 LineGroupParse parse(ove_);
8357
8358 parse.setLineGroup(&lineGroupChunk);
8359
8360 for (i = 0; i < lineChunks.size(); ++i) {
8361 parse.addLine(lineChunks[i]);
8362 }
8363
8364 for (i = 0; i < staffChunks.size(); ++i) {
8365 parse.addStaff(staffChunks[i]);
8366 }
8367
8368 if (!parse.parse()) {
8369 return false;
8370 }
8371
8372 return true;
8373 }
8374
readBarsData()8375 bool OveSerialize::readBarsData() {
8376 GroupChunk barGroupChunk;
8377 if (!readGroupChunk(&barGroupChunk))
8378 return false;
8379
8380 unsigned short measCount = barGroupChunk.getCountBlock()->toCount();
8381 int i;
8382
8383 QList<SizeChunk*> measureChunks;
8384 QList<SizeChunk*> conductChunks;
8385 QList<SizeChunk*> bdatChunks;
8386
8387 ove_->setTrackBarCount(measCount);
8388
8389 // read chunks
8390 for (i = 0; i < measCount; ++i) {
8391 SizeChunk* measureChunkPtr = new SizeChunk();
8392
8393 if (!readChunkName(measureChunkPtr, Chunk::MeasureName)) {
8394 return false;
8395 }
8396 if (!readSizeChunk(measureChunkPtr)) {
8397 return false;
8398 }
8399
8400 measureChunks.push_back(measureChunkPtr);
8401 }
8402
8403 for (i = 0; i < measCount; ++i) {
8404 SizeChunk* conductChunkPtr = new SizeChunk();
8405
8406 if (!readChunkName(conductChunkPtr, Chunk::ConductName))
8407 return false;
8408
8409 if (!readSizeChunk(conductChunkPtr))
8410 return false;
8411
8412 conductChunks.push_back(conductChunkPtr);
8413 }
8414
8415 int bdatCount = ove_->getTrackCount() * measCount;
8416 for (i = 0; i < bdatCount; ++i) {
8417 SizeChunk* batChunkPtr = new SizeChunk();
8418
8419 if (!readChunkName(batChunkPtr, Chunk::BdatName)) {
8420 return false;
8421 }
8422 if (!readSizeChunk(batChunkPtr)) {
8423 return false;
8424 }
8425
8426 bdatChunks.push_back(batChunkPtr);
8427 }
8428
8429 // parse bars
8430 BarsParse barsParse(ove_);
8431
8432 for (i = 0; i < measureChunks.size(); ++i) {
8433 barsParse.addMeasure(measureChunks[i]);
8434 }
8435
8436 for (i = 0; i < conductChunks.size(); ++i) {
8437 barsParse.addConduct(conductChunks[i]);
8438 }
8439
8440 for (i = 0; i < bdatChunks.size(); ++i) {
8441 barsParse.addBdat(bdatChunks[i]);
8442 }
8443
8444 barsParse.setNotify(notify_);
8445 if (!barsParse.parse()) {
8446 return false;
8447 }
8448
8449 return true;
8450 }
8451
readOveEnd()8452 bool OveSerialize::readOveEnd() {
8453 if (streamHandle_ == 0)
8454 return false;
8455
8456 const unsigned int END_OVE1 = 0xffffffff;
8457 const unsigned int END_OVE2 = 0x00000000;
8458 unsigned int buffer;
8459
8460 if (!streamHandle_->read((char*) &buffer, sizeof(unsigned int)))
8461 return false;
8462
8463 if (buffer != END_OVE1)
8464 return false;
8465
8466 if (!streamHandle_->read((char*) &buffer, sizeof(unsigned int)))
8467 return false;
8468
8469 if (buffer != END_OVE2)
8470 return false;
8471
8472 return true;
8473 }
8474
8475 /////////////////////////////////////////////////////////////////////////////////////////
readNameBlock(NameBlock & nameBlock)8476 bool OveSerialize::readNameBlock(NameBlock& nameBlock) {
8477 if (streamHandle_ == 0)
8478 return false;
8479
8480 if (!streamHandle_->read((char*) nameBlock.data(), nameBlock.size()))
8481 return false;
8482
8483 return true;
8484 }
8485
readChunkName(Chunk *,const QString & name)8486 bool OveSerialize::readChunkName(Chunk* /*chunk*/, const QString& name) {
8487 if (streamHandle_ == 0)
8488 return false;
8489
8490 NameBlock nameBlock;
8491
8492 if (!streamHandle_->read((char*) nameBlock.data(), nameBlock.size()))
8493 return false;
8494
8495 if (!(nameBlock.toStrByteArray() == name))
8496 return false;
8497
8498 return true;
8499 }
8500
readSizeChunk(SizeChunk * sizeChunk)8501 bool OveSerialize::readSizeChunk(SizeChunk* sizeChunk) {
8502 if (streamHandle_ == 0)
8503 return false;
8504
8505 SizeBlock* sizeBlock = sizeChunk->getSizeBlock();
8506
8507 if (!streamHandle_->read((char*) sizeBlock->data(), sizeBlock->size()))
8508 return false;
8509
8510 unsigned int blockSize = sizeBlock->toSize();
8511
8512 sizeChunk->getDataBlock()->resize(blockSize);
8513
8514 Block* dataBlock = sizeChunk->getDataBlock();
8515
8516 if (!streamHandle_->read((char*) dataBlock->data(), blockSize))
8517 return false;
8518
8519 return true;
8520 }
8521
readDataChunk(Block * block,unsigned int size)8522 bool OveSerialize::readDataChunk(Block* block, unsigned int size) {
8523 if (streamHandle_ == 0)
8524 return false;
8525
8526 block->resize(size);
8527
8528 if (!streamHandle_->read((char*) block->data(), size))
8529 return false;
8530
8531 return true;
8532 }
8533
readGroupChunk(GroupChunk * groupChunk)8534 bool OveSerialize::readGroupChunk(GroupChunk* groupChunk) {
8535 if (streamHandle_ == 0)
8536 return false;
8537
8538 CountBlock* countBlock = groupChunk->getCountBlock();
8539
8540 if (!streamHandle_->read((char*) countBlock->data(), countBlock->size()))
8541 return false;
8542
8543 return true;
8544 }
8545
createOveStreamLoader()8546 IOVEStreamLoader* createOveStreamLoader() {
8547 return new OveSerialize;
8548 }
8549
8550 }
8551