1 // 2 // musicxmlquery.cpp 3 // GuidoKit 4 // 5 // Created by Arshia Cont on 23/12/16. 6 // Copyright © 2016 Antescofo SAS. All rights reserved. 7 // 8 9 #include "musicxmlquery.h" 10 11 #include "libmusicxml.h" 12 #include "xml.h" 13 #include "xmlfile.h" 14 #include "xmlreader.h" 15 16 #include <sstream> 17 18 // Transposition operations on MusicXML 19 #include "xml.h" 20 #include "xmlreader.h" 21 #include "xml_tree_browser.h" 22 23 namespace MusicXML2 24 { 25 /// Constructors and Deconstructors musicxmlQuery()26 musicxmlQuery::musicxmlQuery() { 27 init(); 28 } 29 ~musicxmlQuery()30 musicxmlQuery::~musicxmlQuery() { 31 } 32 init()33 void musicxmlQuery::init() { 34 beatCum = 0.0; 35 } 36 37 getStavesForFirstPart()38 int musicxmlQuery::getStavesForFirstPart() { 39 return stavesInPart.begin()->second; 40 } 41 getAllClefsOfFirstPart()42 std::vector<std::string> musicxmlQuery::getAllClefsOfFirstPart() { 43 std::set<string> clefsSet = clefsInPart.begin()->second; 44 std::vector<string> clefsVector(clefsSet.begin(), clefsSet.end()); 45 return clefsVector; 46 } 47 48 getTotalStaves()49 int musicxmlQuery::getTotalStaves() { 50 int totalStaves = 0; 51 for (auto&& e : stavesInPart) { 52 totalStaves += e.second; 53 } 54 return totalStaves; 55 } 56 57 /// Instance methods: getTransposeInstrumentChromatic()58 int musicxmlQuery::getTransposeInstrumentChromatic () { 59 // The chromatic element, representing the number of chromatic steps to add to the written pitch, is the one required element. The diatonic, octave-change, and double elements are optional elements. 60 return fChromatic + (transposevisitor::fOctaveChange * 12); 61 } 62 getTransposeInstrumentName()63 std::string musicxmlQuery::getTransposeInstrumentName() { 64 switch (fChromatic) { 65 case -2: 66 return "Bb"; 67 break; 68 69 case -3: 70 return "A"; 71 break; 72 73 case -5: 74 return "G"; 75 break; 76 77 case 3: 78 return "Eb"; 79 break; 80 81 case 2: 82 return "D"; 83 break; 84 85 default: 86 return "C"; 87 break; 88 } 89 } 90 91 92 //________________________________________________________________________ 93 // The visit methods 94 //________________________________________________________________________ visitEnd(S_note & elt)95 void musicxmlQuery::visitEnd ( S_note& elt ) 96 { 97 notevisitor::visitEnd (elt); 98 99 ctree<xmlelement>::iterator next; 100 for (ctree<xmlelement>::iterator i = elt->begin(); i != elt->end(); ) { 101 next = i; 102 next++; 103 switch (i->getType()) { 104 case k_step: 105 break; 106 case k_octave: 107 break; 108 case k_alter: 109 110 break; 111 case k_accidental: 112 break; 113 case k_time_modification: 114 case k_stem: 115 case k_notehead: 116 case k_staff: 117 case k_beam: 118 case k_notations: 119 case k_lyric: 120 121 break; 122 } 123 i = next; 124 } 125 } 126 127 visitEnd(S_rehearsal & elt)128 void musicxmlQuery::visitEnd ( S_rehearsal& elt ) 129 { 130 //cout<< " Rehearsal Mark \""<< elt->getValue() <<"\" at beat-pos "<<beatCum<<endl; 131 } 132 133 //________________________________________________________________________ visitStart(S_part & elt)134 void musicxmlQuery::visitStart ( S_part& elt) 135 { 136 currentPart = elt->getAttributeValue("id"); 137 stavesInPart[currentPart] = 1; 138 } 139 140 //________________________________________________________________________ visitStart(S_staves & elt)141 void musicxmlQuery::visitStart ( S_staves& elt) 142 { 143 stavesInPart[currentPart] = int(*elt); 144 } 145 visitEnd(S_clef & elt)146 void musicxmlQuery::visitEnd ( S_clef& elt ) 147 { 148 std::string key; 149 if(clefvisitor::fSign == "G" && clefvisitor::fLine == 2 && clefvisitor::fOctaveChange == 0) { 150 key = "g2"; 151 }else if(clefvisitor::fSign == "G" && clefvisitor::fLine == 2 && clefvisitor::fOctaveChange == -1) { 152 key = "g-8"; 153 }else if(clefvisitor::fSign == "G" && clefvisitor::fLine == 2 && clefvisitor::fOctaveChange == 1) { 154 key = "g+8"; 155 }else if(clefvisitor::fSign == "F" && clefvisitor::fLine == 4 && clefvisitor::fOctaveChange == 0) { 156 key = "f4"; 157 }else if(clefvisitor::fSign == "F" && clefvisitor::fLine == 4 && clefvisitor::fOctaveChange == -1) { 158 key = "f-8"; 159 }else if(clefvisitor::fSign == "F" && clefvisitor::fLine == 4 && clefvisitor::fOctaveChange == 1) { 160 key = "f+8"; 161 }else if(clefvisitor::fSign == "C" && clefvisitor::fLine == 3 && clefvisitor::fOctaveChange == 0) { 162 key = "alto"; 163 }else if(clefvisitor::fSign == "C" && clefvisitor::fLine == 4 && clefvisitor::fOctaveChange == 0) { 164 key = "tenor"; 165 }else{ 166 key = "unknown"; 167 } 168 clefsInPart[currentPart].insert(key); 169 } 170 171 } 172