LibMusicXML 3.18
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
21#include "exports.h"
22#include "guido.h"
23#include "typedefs.h"
24#include "visitor.h"
25#include "xml.h"
26#include "rational.h"
27
28
29#include "partlistvisitor.h"
30
31
32namespace MusicXML2
33{
34
40//______________________________________________________________________________
41typedef struct {
42 S_movement_title fTitle;
43 std::vector<S_creator> fCreators;
45
46 /*
47typedef struct {
48 S_part_name fPartName;
49} partHeader;
50typedef std::map<std::string, partHeader> partHeaderMap;
51*/
52
56//______________________________________________________________________________
58 public partlistvisitor,
59 public visitor<S_score_partwise>,
60 public visitor<S_movement_title>,
61 public visitor<S_creator>,
62 public visitor<S_defaults>,
63 public visitor<S_part>
64{
65 // the guido elements stack
66 std::stack<Sguidoelement> fStack;
67 bool fGenerateComments, fGenerateStem, fGenerateBars, fGeneratePositions;
68
69 scoreHeader fHeader; // musicxml header elements (should be flushed at the beginning of the first voice)
70 //partHeaderMap fPartHeaders; // musicxml score-part elements (should be flushed at the beginning of each part)
71 std::string fCurrentPartID;
72 int fCurrentStaffIndex; // the index of the current guido staff
73
74 void start (Sguidoelement& elt) { fStack.push(elt); }
75 void add (Sguidoelement& elt) { if (fStack.size()) fStack.top()->add(elt); }
76 void push (Sguidoelement& elt) { add(elt); fStack.push(elt); }
77 void pop () {
78 if (fStack.size())
79 fStack.pop();
80 else
81 cerr<<"xml2guido: Pop() called while EMPTY! Please REPORT!"<<endl;
82 }
83
84 void flushHeader ( scoreHeader& header );
85 void flushPartHeader ( partHeader& header );
86 void flushPartGroup (std::string partID);
87
88 protected:
89
90 virtual void visitStart( S_score_partwise& elt);
91 virtual void visitStart( S_movement_title& elt);
92 virtual void visitStart( S_creator& elt);
93 //virtual void visitStart( S_score_part& elt);
94 virtual void visitStart( S_defaults& elt);
95 virtual void visitStart( S_part& 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
105 int defaultStaffDistance; // xml staff-distance value in defaults
106 int defaultGuidoStaffDistance; // the above converted to Guido value
107
109 //std::multimap<int, std::pair< rational, string > > staffClefMap;
110 std::multimap<int, std::pair< int, std::pair< rational, string > > > staffClefMap;
111
113 std::map< int, std::map< rational, std::vector<int> > > timePositions;
114
115
116 public:
117 xml2guidovisitor(bool generateComments, bool generateStem, bool generateBar=true, int partNum = 0);
118 virtual ~xml2guidovisitor() {}
119
120 Sguidoelement convert (const Sxmlelement& xml);
121
122 // this is to control exact positionning of elements when information is present
123 // ie converts relative-x/-y into dx/dy attributes
124 void generatePositions (bool state) { fGeneratePositions = state; }
125
126 static void addPosition ( Sxmlelement elt, Sguidoelement& tag, float yoffset);
127 static void addPosition ( Sxmlelement elt, Sguidoelement& tag, float yoffset, float xoffset);
128 static void addPosY ( Sxmlelement elt, Sguidoelement& tag, float yoffset, float ymultiplier);
129 static void addPosX ( Sxmlelement elt, Sguidoelement& tag, float xoffset);
130 static void addPlacement ( Sxmlelement elt, Sguidoelement& tag);
131 static float getYposition ( Sxmlelement elt, float yoffset, bool useDefault);
132 static float getXposition ( Sxmlelement elt, float xoffset);
133
134 static void addDirection( Sxmlelement elt, Sguidoelement& tag);
135
136};
137
138
139} // namespace MusicXML2
140
141
142#endif
Definition: partlistvisitor.h:45
Produces a summary of a MusicXML parts for groupings.
Definition: partlistvisitor.h:72
Definition: visitor.h:27
A score visitor to produce a Guido representation.
Definition: xml2guidovisitor.h:64
std::multimap< int, std::pair< int, std::pair< rational, string > > > staffClefMap
multimap containing <staff-num, measureNum, position, clef type>
Definition: xml2guidovisitor.h:110
std::map< int, std::map< rational, std::vector< int > > > timePositions
Containing default-x positions on a fCurrentVoicePosition (rational) of measure(int)
Definition: xml2guidovisitor.h:113
Definition: xml2guidovisitor.h:41