LibMusicXML 3.18
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
20#include "exports.h"
21#include "smartpointer.h"
22
23namespace MusicXML2
24{
25
26class guidovisitor;
27class guidoelement;
28class guidoparam;
29typedef SMARTP<guidoelement> Sguidoelement;
30typedef SMARTP<guidoparam> Sguidoparam;
31
32
33EXP std::ostream& operator<< (std::ostream& os, const Sguidoelement& elt);
34
45class EXP guidoparam : public smartable {
46 public:
47 static SMARTP<guidoparam> create(std::string value, bool quote=true);
48 static SMARTP<guidoparam> create(long value, bool quote=true);
49
51 void set (std::string value, bool quote=true);
52 void set (long value, bool quote=true);
53 std::string get () const { return fValue; }
54 bool quote () const { return fQuote; }
55
56 protected:
57 guidoparam(std::string value, bool quote);
58 guidoparam(long value, bool quote);
59 virtual ~guidoparam ();
60
61 private:
62 std::string fValue;
63 bool fQuote;
64};
65
72class EXP guidoelement : public smartable {
73 public:
74 static SMARTP<guidoelement> create(std::string name, std::string sep=" ");
75
76 long add (Sguidoelement& elt);
77 long add (Sguidoparam& param);
78 long add (Sguidoparam param);
79 virtual void print (std::ostream& os) const;
80
82 void setName (std::string name) { fName = name; }
83 std::string getName () const { return fName; }
84 std::string getStart () const { return fStartList; }
85 std::string getEnd () const { return fEndList; }
86 std::string getSep () const { return fSep; }
87 void setEnd (std::string end) { fEndList=end; }
88 std::vector<Sguidoelement>& elements() { return fElements; }
89 const std::vector<Sguidoelement>& elements() const { return fElements; }
90 const std::vector<Sguidoparam>& parameters() const { return fParams; }
91
92 bool empty () const { return fElements.empty(); }
93 virtual bool isSeq () const { return false; }
94 virtual bool isChord () const { return false; }
95 virtual bool isTag () const { return false; }
96 virtual bool isNote () const { return false; }
97
98 int countNotes () const;
99
100 protected:
101 guidoelement(std::string name, std::string sep=" ");
102 virtual ~guidoelement();
103
104 void printparams (std::ostream& os) const;
105
106 std::string fName;
108 std::string fStartList;
110 std::string fEndList;
112 std::string fSep;
114 std::vector<Sguidoelement> fElements;
116 std::vector<Sguidoparam> fParams;
117};
118
129 public:
130 guidonoteduration(long num, long denom, long dots=0)
131 { set (num, denom, dots); }
132 virtual ~guidonoteduration() {}
133
134 void set (long num, long denom, long dots=0)
135 { fNum=num; fDenom=denom; fDots=dots; }
136 guidonoteduration& operator= (const guidonoteduration& dur)
137 { fNum=dur.fNum; fDenom=dur.fDenom; fDots=dur.fDots; return *this; }
138 bool operator!= (const guidonoteduration& dur) const
139 { return (fNum!=dur.fNum) || (fDenom!=dur.fDenom) || (fDots!=dur.fDots); }
140
141 long fNum;
142 long fDenom;
143 long fDots;
144};
145
152class EXP guidonote : public guidoelement {
153 public:
154 static SMARTP<guidonote> create(unsigned short voice);
155 static SMARTP<guidonote> create(unsigned short voice, std::string name, char octave,
156 guidonoteduration& dur, std::string acc="");
157
158 void set (unsigned short voice, std::string name, char octave, guidonoteduration& dur, std::string acc);
159 void setName (const std::string name) { fNote = name; }
160 void setOctave (char octave) { fOctave = octave; }
161 void setDuration (const guidonoteduration& dur) { fDuration = dur; }
162 void setAccidental (const std::string acc) { fAccidental = acc; }
163
164 const char * name() const { return fNote.c_str(); }
165 const char * accidental() const { return fAccidental.c_str(); }
166 char octave() const { return fOctave; }
167 const guidonoteduration& duration() const { return fDuration; }
168
169 virtual bool isNote () const { return true; }
170
171 protected:
172 guidonote(unsigned short voice);
173 guidonote(unsigned short voice, std::string name, char octave,
174 guidonoteduration& dur, std::string acc="");
175 virtual ~guidonote();
176
177 std::string fNote;
178 std::string fAccidental;
179 char fOctave;
180 guidonoteduration fDuration;
181
182};
184
200 public:
201 enum { kMaxInstances=128 };
202
203 static guidonotestatus* get(unsigned short voice);
204 static void resetall();
205 static void freeall();
206
207 enum { defoctave=1, defnum=1, defdenom=4 };
208
209 void reset() { fOctave=defoctave; fDur.set(defnum, defdenom, 0); }
210 guidonotestatus& operator= (const guidonoteduration& dur) { fDur = dur; return *this; }
211 bool operator!= (const guidonoteduration& dur) const { return fDur!= dur; }
212
213 char fOctave;
215// char fBeat;
216
217 protected:
218 guidonotestatus() : fOctave(defoctave), fDur(defnum, defdenom, 0) {}
219 private:
220 static guidonotestatus * fInstances[kMaxInstances];
221};
222
226class EXP guidoseq : public guidoelement {
227 public:
228 static SMARTP<guidoseq> create();
229 virtual bool isSeq () const { return true; }
230
231 protected:
232 guidoseq();
233 virtual ~guidoseq();
234};
236
240class EXP guidochord : public guidoelement {
241 public:
242 static SMARTP<guidochord> create();
243 virtual bool isChord () const { return true; }
244
245 protected:
246 guidochord ();
247 virtual ~guidochord();
248
249 virtual void print (std::ostream& os) const;
250};
252
259class EXP guidotag : public guidoelement {
260 public:
261 static SMARTP<guidotag> create(std::string name);
262 static SMARTP<guidotag> create(std::string name, std::string sep);
263 virtual bool isTag () const { return true; }
264
265 protected:
266 guidotag(std::string name);
267 guidotag(std::string name, std::string sep);
268 virtual ~guidotag();
269};
273}
274
275#endif
the smart pointer implementation
Definition: smartpointer.h:58
The guido chord element.
Definition: guido.h:240
A generic guido element representation.
Definition: guido.h:72
std::string fSep
the element separator (default to space)
Definition: guido.h:112
std::string fStartList
the contained element start marker (default to empty)
Definition: guido.h:108
std::string fEndList
the contained element end marker (default to empty)
Definition: guido.h:110
std::vector< Sguidoparam > fParams
list of optional parameters
Definition: guido.h:116
std::vector< Sguidoelement > fElements
list of the enclosed elements
Definition: guido.h:114
void setName(std::string name)
the element name
Definition: guido.h:82
A guido note representation.
Definition: guido.h:152
A guido note duration representation.
Definition: guido.h:128
Represents the current status of notes duration and octave.
Definition: guido.h:199
A guidotag parameter representation.
Definition: guido.h:45
void set(std::string value, bool quote=true)
the parameter value
The guido sequence element.
Definition: guido.h:226
A guido tag representation.
Definition: guido.h:259
the base class for smart pointers implementation
Definition: smartpointer.h:29