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 __conversions__
14 #define __conversions__
15 
16 #include "exports.h"
17 #include "rational.h"
18 #include "bimap.h"
19 #include <string>
20 
21 #ifdef WIN32
22 #pragma warning (disable : 4251)
23 #endif
24 
25 using namespace std;
26 
27 namespace MusicXML2
28 {
29 
30 /*!
31 \brief provides conversions between numeric trill start notes and strings
32 */
33 class EXP TrillStart {
34     public:
35     enum type { undefined, upper, main, below, last=below };
36 
37     //! convert a numeric start note value to a MusicXML string
38     static const string	xml (type d);
39     //! convert a MusicXML string to a numeric start note value
40     static       type	xml (const string str);
41 
42     private:
43 	static bimap<string, type> fSN2String;
44 	static type 		fSNTbl[];
45 	static string 		fSNStrings[];
46 };
47 
48 /*!
49 \brief provides conversions between numeric trill step, turn and strings
50 */
51 class EXP TrillStep {
52     public:
53     enum type { undefined, whole, half, unison, none, last=none };
54 
55     //! convert a numeric trill step or turn value to a MusicXML string
56     static const string	xml (type d);
57     //! convert a MusicXML string to a numeric trill step or turn value
58     static       type	xml (const string str);
59 
60     private:
61 	static bimap<string, type> fTS2String;
62 	static type 		fTSTbl[];
63 	static string 		fTSStrings[];
64 };
65 
66 /*!
67 \brief provides conversions between numeric note size types and strings
68 */
69 class EXP FullCue {
70     public:
71     enum type { undefined, full, cue, last=cue };
72 
73     //! convert a numeric size value to a MusicXML string
74     static const string	xml (type d);
75     //! convert a MusicXML string to a numeric size value
76     static       type	xml (const string str);
77 
78     private:
79 	static bimap<string, type> fFC2String;
80 	static type 		fFCTbl[];
81 	static string 		fFCStrings[];
82 };
83 
84 /*!
85 \brief provides conversions between numeric yes-no types and strings
86 */
87 class EXP YesNo {
88     public:
89     enum type { undefined, yes, no, last=no };
90 
91     //! convert a numeric yes-no value to a MusicXML string
92     static const string	xml (type d);
93     //! convert a MusicXML string to a numeric yes-no value
94     static       type	xml (const string str);
95 
96     private:
97 	static bimap<string, type> fYN2String;
98 	static type 	fYNTbl[];
99 	static string 	fYNStrings[];
100 };
101 
102 /*!
103 \brief provides conversions between numeric start-stop types and strings
104 */
105 class EXP StartStop {
106     public:
107     enum type { undefined, start, stop, cont, last=cont };
108 
109     //! convert a numeric start-stop value to a MusicXML string
110     static const string	xml (type d);
111     //! convert a MusicXML string to a numeric start-stop value
112     static       type	xml (const string str);
113 
114     private:
115 	static bimap<string, type> fStartStop2String;
116 	static type 	fStartStopTbl[];
117 	static string 	fStartStopStrings[];
118 };
119 
120 /*!
121 \brief provides conversions between numeric line types and strings
122 */
123 class EXP LineType {
124     public:
125     enum type { undefined, solid, dashed, dotted, wavy, last=wavy };
126 
127     //! convert a numeric start-stop value to a MusicXML string
128     static const string	xml (type d);
129     //! convert a MusicXML string to a numeric start-stop value
130     static       type	xml (const string str);
131 
132     private:
133 	static bimap<string, type> fLineType2String;
134 	static type 	fLineTypeTbl[];
135 	static string 	fLineTypeStrings[];
136 };
137 
138 /*!
139 \brief provides conversions between numeric note types and strings
140 
141 	Type indicates the graphic note type. Valid values (from
142 	shortest to longest) are 256th, 128th, 64th, 32nd, 16th,
143 	eighth, quarter, half, whole, breve, and long.
144 */
145 class EXP NoteType {
146     public:
147         enum type { undefined,
148                     t256th=1, t128th=1<<1, t64th=1<<2, t32nd=1<<3,
149                     t16th=1<<4, eighth=1<<5, quarter=1<<6,
150                     half=1<<7, whole=1<<8, breve=1<<9, tlong=1<<10,
151                     count=11 };
152 
153 	//! convert an integer note to a rational representation
154     static rational type2rational(type d);
155 	//! convert an integer note type to a MusicXML string
156     static const string	xml (type d);
157     //! convert an MusicXML string to an integer note type
158     static       type	xml (const string str);
159 
160     private:
161 	static bimap<string, type> fType2String;
162 	static type 	fTypeTbl[];
163 	static string 	fTypeStrings[];
164 };
165 
166 } // namespace MusicXML2
167 
168 #endif
169