LibMusicXML 3.22
guido.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 __guido__
14#define __guido__
15
16#include <vector>
17#include <string>
18#include <iostream>
19#include <algorithm>
20
21#include "exports.h"
22#include "smartpointer.h"
23
24namespace MusicXML2
25{
26
27class guidovisitor;
28class guidoelement;
29class guidoparam;
30typedef SMARTP<guidoelement> Sguidoelement;
31typedef SMARTP<guidoparam> Sguidoparam;
32
33
34EXP std::ostream& operator<< (std::ostream& os, const Sguidoelement& elt);
35
40
46class EXP guidoparam : public smartable {
47 public:
48 static SMARTP<guidoparam> create(std::string value, bool quote=true);
49 static SMARTP<guidoparam> create(long value, bool quote=true);
50
52 void set (std::string value, bool quote=true);
53 void set (long value, bool quote=true);
54 std::string get () const { return fValue; }
55 bool quote () const { return fQuote; }
56
57 protected:
58 guidoparam(std::string value, bool quote);
59 guidoparam(long value, bool quote);
60 virtual ~guidoparam ();
61
62 private:
63 std::string fValue;
64 bool fQuote;
65};
66
73class EXP guidoelement : public smartable {
74 public:
75 static SMARTP<guidoelement> create(std::string name, std::string sep=" ");
76
77 long add (Sguidoelement& elt);
78 long add (Sguidoparam& param);
79 long add (Sguidoparam param);
80 virtual void print (std::ostream& os) const;
81
83 void setName (std::string name) { fName = name; }
84 std::string getName () const { return fName; }
85 std::string getStart () const { return fStartList; }
86 std::string getEnd () const { return fEndList; }
87 std::string getSep () const { return fSep; }
88 void setEnd (std::string end) { fEndList=end; }
89 std::vector<Sguidoelement>& elements() { return fElements; }
90 const std::vector<Sguidoelement>& elements() const { return fElements; }
91 const std::vector<Sguidoparam>& parameters() const { return fParams; }
92
93 bool empty () const { return fElements.empty(); }
94 virtual bool isSeq () const { return false; }
95 virtual bool isChord () const { return false; }
96 virtual bool isTag () const { return false; }
97 virtual bool isNote () const { return false; }
98 virtual bool isRangeTag() const {
99 return fName.find("End") != std::string::npos || fName.find("Begin") != std::string::npos;
100 }
101 virtual bool isBeginTag() const {
102 return fName.find("Begin") != std::string::npos;
103 }
104 virtual bool isEndTag() const {
105 return fName.find("End") != std::string::npos;
106 }
107
108 int countNotes () const;
109
111 const bool getNext(Sguidoelement &i, Sguidoelement &next_e) const {
112 std::vector<Sguidoelement>::const_iterator e = find(fElements.begin(), fElements.end(), i);
113 if (e != fElements.end()) {
114 auto next = std::next(e);
115 if (next != fElements.end()) {
116 next_e = *next;
117 return true;
118 }
119 }
120 return false;
121 }
122
123 const bool getPrev(Sguidoelement &i, Sguidoelement &next_e) const {
124 std::vector<Sguidoelement>::const_reverse_iterator e = find(fElements.rbegin(), fElements.rend(), i);
125 if (e != fElements.rend()) {
126 auto next = std::next(e);
127 if (next != fElements.rend()) {
128 next_e = *next;
129 return true;
130 }
131 }
132 return false;
133 }
134
135
136 protected:
137 guidoelement(std::string name, std::string sep=" ");
138 virtual ~guidoelement();
139
140 void printparams (std::ostream& os) const;
141
142 std::string fName;
144 std::string fStartList;
146 std::string fEndList;
148 std::string fSep;
150 std::vector<Sguidoelement> fElements;
152 std::vector<Sguidoparam> fParams;
153};
154
164class EXP guidonoteduration {
165 public:
166 guidonoteduration(long num, long denom, long dots=0)
167 { set (num, denom, dots); }
168 virtual ~guidonoteduration() {}
169
170 void set (long num, long denom, long dots=0)
171 { fNum=num; fDenom=denom; fDots=dots; }
172 guidonoteduration& operator= (const guidonoteduration& dur)
173 { fNum=dur.fNum; fDenom=dur.fDenom; fDots=dur.fDots; return *this; }
174 bool operator!= (const guidonoteduration& dur) const
175 { return (fNum!=dur.fNum) || (fDenom!=dur.fDenom) || (fDots!=dur.fDots); }
176
177 long fNum;
178 long fDenom;
179 long fDots;
180};
181
188class EXP guidonote : public guidoelement {
189 public:
190 static SMARTP<guidonote> create(unsigned short voice);
191 static SMARTP<guidonote> create(unsigned short voice, std::string name, char octave,
192 guidonoteduration& dur, std::string acc="");
193
194 void set (unsigned short voice, std::string name, char octave, guidonoteduration& dur, std::string acc);
195 void setName (const std::string name) { fNote = name; }
196 void setOctave (char octave) { fOctave = octave; }
197 void setDuration (const guidonoteduration& dur) { fDuration = dur; }
198 void setAccidental (const std::string acc) { fAccidental = acc; }
199
200 const char * name() const { return fNote.c_str(); }
201 const char * accidental() const { return fAccidental.c_str(); }
202 char octave() const { return fOctave; }
203 const guidonoteduration& duration() const { return fDuration; }
204
205 virtual bool isNote () const { return true; }
206
207 protected:
208 guidonote(unsigned short voice);
209 guidonote(unsigned short voice, std::string name, char octave,
210 guidonoteduration& dur, std::string acc="");
211 virtual ~guidonote();
212
213 std::string fNote;
214 std::string fAccidental;
215 char fOctave;
216 guidonoteduration fDuration;
217
218};
219typedef SMARTP<guidonote> Sguidonote;
220
235class EXP guidonotestatus {
236 public:
237 enum { kMaxInstances=128 };
238
239 static guidonotestatus* get(unsigned short voice);
240 static void resetall();
241 static void freeall();
242
243 enum { defoctave=1, defnum=1, defdenom=4 };
244
245 void reset() { fOctave=defoctave; fDur.set(defnum, defdenom, 0); }
246 guidonotestatus& operator= (const guidonoteduration& dur) { fDur = dur; return *this; }
247 bool operator!= (const guidonoteduration& dur) const { return fDur!= dur; }
248
249 char fOctave;
251// char fBeat;
252
253 protected:
254 guidonotestatus() : fOctave(defoctave), fDur(defnum, defdenom, 0) {}
255 private:
256 static guidonotestatus * fInstances[kMaxInstances];
257};
258
262class EXP guidoseq : public guidoelement {
263 public:
264 static SMARTP<guidoseq> create();
265 virtual bool isSeq () const { return true; }
266
267 protected:
268 guidoseq();
269 virtual ~guidoseq();
270};
271typedef SMARTP<guidoseq> Sguidoseq;
272
276class EXP guidochord : public guidoelement {
277 public:
278 static SMARTP<guidochord> create();
279 virtual bool isChord () const { return true; }
280
281 protected:
282 guidochord ();
283 virtual ~guidochord();
284
285 virtual void print (std::ostream& os) const;
286};
287typedef SMARTP<guidochord> Sguidochord;
288
295class EXP guidotag : public guidoelement {
296 public:
297 static SMARTP<guidotag> create(std::string name);
298 static SMARTP<guidotag> create(std::string name, std::string sep);
299 virtual bool isTag () const { return true; }
300
301 protected:
302 guidotag(std::string name);
303 guidotag(std::string name, std::string sep);
304 virtual ~guidotag();
305};
306typedef SMARTP<guidotag> Sguidotag;
308
309}
310
311#endif
the smart pointer implementation
Definition smartpointer.h:58
A generic guido element representation.
Definition guido.h:73
std::string fSep
the element separator (default to space)
Definition guido.h:148
std::string fStartList
the contained element start marker (default to empty)
Definition guido.h:144
std::string fEndList
the contained element end marker (default to empty)
Definition guido.h:146
std::vector< Sguidoparam > fParams
list of optional parameters
Definition guido.h:152
std::vector< Sguidoelement > fElements
list of the enclosed elements
Definition guido.h:150
const bool getNext(Sguidoelement &i, Sguidoelement &next_e) const
Get next subelement.
Definition guido.h:111
void setName(std::string name)
the element name
Definition guido.h:83
A guido note duration representation.
Definition guido.h:164
A guidotag parameter representation.
Definition guido.h:46
void set(std::string value, bool quote=true)
the parameter value