LibMusicXML 3.22
xml2guidovisitor.h
1/*
2 MusicXML Library
3 Copyright (C) Grame 2006-2013
4
5 This Source Code Form is subject to the terms of the Mozilla Public
6 License, v. 2.0. If a copy of the MPL was not distributed with this
7 file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9 Grame Research Laboratory, 11, cours de Verdun Gensoul 69002 Lyon - France
10 research@grame.fr
11 */
12
13#ifndef __xml2guidovisitor__
14#define __xml2guidovisitor__
15
16#include <ostream>
17#include <stack>
18#include <map>
19#include <string>
20#include <set>
21
22#include "exports.h"
23#include "guido.h"
24#include "typedefs.h"
25#include "visitor.h"
26#include "xml.h"
27#include "rational.h"
28
29
30#include "partlistvisitor.h"
31#include "transposevisitor.h"
32#include "clefvisitor.h"
33
34namespace MusicXML2
35{
36
41
42//______________________________________________________________________________
43typedef struct {
44 S_movement_title fTitle;
45 std::vector<S_creator> fCreators;
47
51//______________________________________________________________________________
52class EXP xml2guidovisitor :
53public partlistvisitor,
54public transposevisitor,
55public visitor<S_score_partwise>,
56public visitor<S_movement_title>,
57public visitor<S_creator>,
58public visitor<S_defaults>,
59public visitor<S_part>,
60public visitor<S_staves>,
61public clefvisitor
62{
63private:
64 // the guido elements stack
65 std::stack<Sguidoelement> fStack;
66 bool fGenerateComments, fGenerateStem, fGenerateBars, fGeneratePositions;
67
68 scoreHeader fHeader; // musicxml header elements (should be flushed at the beginning of the first voice)
69 std::string fCurrentPartID;
70 int fCurrentStaffIndex; // the index of the current guido staff
71
72 void start (Sguidoelement& elt) { fStack.push(elt); }
73 void add (Sguidoelement& elt) { if (fStack.size()) fStack.top()->add(elt); }
74 void push (Sguidoelement& elt) { add(elt); fStack.push(elt); }
75 void pop () {
76 if (fStack.size())
77 fStack.pop();
78 else
79 cerr<<"xml2guido: Pop() called while EMPTY! Please REPORT!"<<endl;
80 }
81
82 void flushHeader ( scoreHeader& header );
83 void flushPartHeader ( partHeader& header );
84 void flushPartGroup (std::string partID);
85
86protected:
87
88 virtual void visitStart( S_score_partwise& elt);
89 virtual void visitStart( S_movement_title& elt);
90 virtual void visitStart( S_creator& elt);
91 //virtual void visitStart( S_score_part& elt);
92 virtual void visitStart( S_defaults& elt);
93 virtual void visitStart( S_part& elt);
94 virtual void visitStart ( S_staves& elt);
95 virtual void visitEnd ( S_clef& elt );
96
97 Sguidoelement& current () { return fStack.top(); }
98
99 bool previousStaffHasLyrics;
100
101 int fCurrentAccoladeIndex;
102
103 int fPartNum; // 0 (default) to parse all score-parts. 1 for "P1" only, etc.
104 int fPartsAvailable; // number of parts available in this XML
105
106 int fBeginMeasure; // Number of measure to begin parsing, used for partial conversion. (default = 0)
107 int fEndMeasure; // Measure Number where parsing ends, used for partial conversion. (default = 0 meaning go to the end)
108 int fEndMeasureOffset; // Ending the score conversion at this offset (but giving fEndMeasure for fEndPosition)
109
114
115 static int defaultStaffDistance; // xml staff-distance value in defaults
116
117 std::map<std::string, int> stavesInPart;
118 std::map<std::string, std::set<std::string> > clefsInPart;
119 std::string currentPart;
120
123
125 std::map<double, int> measurePositionMap;
126
127 double fTotalDuration;
128
129public:
130 xml2guidovisitor(bool generateComments, bool generateStem, bool generateBar=true, int partNum = 0, int beginMeasure = 0, int endMeasure = 0, int endMeasureOffset = 0);
131 virtual ~xml2guidovisitor() {}
132
133 Sguidoelement convert (const Sxmlelement& xml);
134
135 // this is to control exact positionning of elements when information is present
136 // ie converts relative-x/-y into dx/dy attributes
137 void generatePositions (bool state) { fGeneratePositions = state; }
138
140
141 static void addPosition ( Sxmlelement elt, Sguidoelement& tag, float yoffset);
142 static void addPosition ( Sxmlelement elt, Sguidoelement& tag, float yoffset, float xoffset);
143 static void addPosY ( Sxmlelement elt, Sguidoelement& tag, float yoffset, float ymultiplier);
144 static void addPosX ( Sxmlelement elt, Sguidoelement& tag, float xoffset);
145 static void addRelativeX(Sxmlelement elt, Sguidoelement& tag, float xoffset);
146 static void addPlacement ( Sxmlelement elt, Sguidoelement& tag);
147 static float getYposition ( Sxmlelement elt, float yoffset, bool useDefault);
148 static float getXposition ( Sxmlelement elt, float xoffset);
149
150 static void addDirection( Sxmlelement elt, Sguidoelement& tag);
151
153
163 std::string getTransposeInstrumentName ();
164
169
173 std::vector<std::string> getAllClefsOfFirstPart();
174
179
180 std::pair<long, long> getStartPosition() {
181 return std::pair<long, long>(fBeginPosition.getNumerator(), fBeginPosition.getDenominator());
182 }
183
184 std::pair<long, long> getEndPosition() {
185 return std::pair<long, long>(fEndPosition.getNumerator(), fEndPosition.getDenominator());
186 }
187
188 int getTotalMeasures();
189
191 std::map<double, int> getMeasureMap();
192
193 double getTotalDuration();
194
197
198};
199
200
201} // namespace MusicXML2
202
203
204#endif
Definition partlistvisitor.h:45
Definition visitor.h:27
int fTotalMeasures
Number of total measures in score.
Definition xml2guidovisitor.h:122
std::map< double, int > measurePositionMap
Map containing measure number and Position (double output of Rational)
Definition xml2guidovisitor.h:125
std::map< double, int > getMeasureMap()
Returns a map<double,int> where the first are beat positions and second are measure numbers.
rational fEndPosition
Guido Position corresponding to fEndMeasure (without fEndMeasureOffset)
Definition xml2guidovisitor.h:113
int getPartsAvailable()
Returne the number of parts in this XML Score.
std::vector< std::string > getAllClefsOfFirstPart()
static void addPosition(Sxmlelement elt, Sguidoelement &tag, float yoffset)
MARK: Position Helpers.
rational fBeginPosition
Guido Position corresponding to fBeginMeasure.
Definition xml2guidovisitor.h:111
int getTransposeInstrumentChromatic()
MARK: Query methods.
Rational number representation.
Definition rational.h:25
Definition xml2guidovisitor.h:43