00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __guido__
00025 #define __guido__
00026
00027 #include "exports.h"
00028 #include "smartpointer.h"
00029 #include "guidovisitor.h"
00030
00031 #include <vector>
00032 #include <iostream>
00033 #include <sstream>
00034 #include <string>
00035
00036 using namespace std;
00037
00038 class guidovisitor;
00039 class guidoelement;
00040 class guidoparam;
00041 typedef SMARTP<guidoelement> Sguidoelement;
00042 typedef SMARTP<guidoparam> Sguidoparam;
00043
00044 VEXP ostream& operator<< (ostream& os, const Sguidoelement& elt);
00045
00056 class VEXP guidoparam : public smartable, public guidovisitable {
00057 public:
00058 VEXP friend SMARTP<guidoparam> new_guidoparam(string value, bool quote=true);
00059 VEXP friend SMARTP<guidoparam> new_guidoparam(long value, bool quote=true);
00060
00062 void set (string value, bool quote=true);
00063 void set (long value, bool quote=true);
00064 string get () const { return fValue; }
00065 bool quote () const { return fQuote; }
00066
00067 void accept(guidovisitor& visitor);
00068
00069 protected:
00070 guidoparam(string value, bool quote) : fValue(value), fQuote(quote) {}
00071 guidoparam(long value, bool quote) { set(value, quote); }
00072 virtual ~guidoparam () {}
00073
00074 private:
00075 string fValue;
00076 bool fQuote;
00077 };
00078
00086 class VEXP guidoelement : public smartable, public guidovisitable {
00087 public:
00088 VEXP friend SMARTP<guidoelement> new_guidoelement(string name, string sep=" ");
00089
00090 long add (Sguidoelement& elt);
00091 long add (Sguidoparam& param);
00092 #ifndef WIN32
00093 long add (Sguidoparam param);
00094 #endif
00095 void print (ostream& os);
00096
00098 void setName (string name) { fName = name; }
00099 string getName () const { return fName; }
00100 string getStart () const { return fStartList; }
00101 string getEnd () const { return fEndList; }
00102 string getSep () const { return fSep; }
00103 const vector<Sguidoelement>& elements() const { return fElements; }
00104 const vector<Sguidoparam>& parameters() const { return fParams; }
00105
00106 bool empty () const { return fElements.empty(); }
00107
00108 virtual void accept(guidovisitor& visitor);
00109
00110 protected:
00111 guidoelement(string name, string sep=" ") : fName(name), fSep(sep) {}
00112 virtual ~guidoelement() {}
00113
00114 string fName;
00116 string fStartList;
00118 string fEndList;
00120 string fSep;
00122 vector<Sguidoelement> fElements;
00124 vector<Sguidoparam> fParams;
00125 };
00126
00136 class VEXP guidonoteduration {
00137 public:
00138 guidonoteduration(long num, long denom, long dots=0)
00139 { set (num, denom, dots); }
00140 virtual ~guidonoteduration() {}
00141
00142 void set (long num, long denom, long dots=0)
00143 { fNum=num; fDenom=denom; fDots=dots; }
00144 guidonoteduration& operator= (const guidonoteduration& dur)
00145 { fNum=dur.fNum; fDenom=dur.fDenom; fDots=dur.fDots; return *this; }
00146 bool operator!= (const guidonoteduration& dur) const
00147 { return (fNum!=dur.fNum) || (fDenom!=dur.fDenom) || (fDots!=dur.fDots); }
00148
00149 long fNum;
00150 long fDenom;
00151 long fDots;
00152 };
00153
00160 class VEXP guidonote : public guidoelement {
00161 public:
00162 VEXP friend SMARTP<guidonote> new_guidonote(unsigned short voice, string name, char octave,
00163 guidonoteduration& dur, string acc="");
00164
00165 void set (unsigned short voice, string name, char octave,
00166 guidonoteduration& dur, string acc);
00167
00168 void accept(guidovisitor& visitor);
00169
00170 const char * name() const { return fNote.c_str(); }
00171 const char * accidental() const { return fAccidental.c_str(); }
00172 char octave() const { return fOctave; }
00173 const guidonoteduration& duration() const { return fDuration; }
00174
00175 protected:
00176 guidonote(unsigned short voice, string name, char octave,
00177 guidonoteduration& dur, string acc="")
00178 : guidoelement(""), fDuration(1,4) { set(voice, name, octave, dur, acc); }
00179 virtual ~guidonote() {}
00180
00181 string fNote;
00182 string fAccidental;
00183 char fOctave;
00184 guidonoteduration fDuration;
00185
00186 };
00187 typedef SMARTP<guidonote> Sguidonote;
00188
00203 class VEXP guidonotestatus {
00204 public:
00205 enum { kMaxInstances=128 };
00206
00207 static guidonotestatus* get(unsigned short voice);
00208 static void resetall();
00209
00210 enum { defoctave=1, defnum=1, defdenom=4 };
00211
00212 void reset() { fOctave=defoctave; fDur.set(defnum, defdenom, 0); }
00213 guidonotestatus& operator= (const guidonoteduration& dur) { fDur = dur; return *this; }
00214 bool operator!= (const guidonoteduration& dur) const { return fDur!= dur; }
00215
00216 char fOctave;
00217 guidonoteduration fDur;
00218
00219
00220 protected:
00221 guidonotestatus() : fOctave(defoctave), fDur(defnum, defdenom, 0) {}
00222 private:
00223 static guidonotestatus * fInstances[kMaxInstances];
00224 };
00225
00229 class VEXP guidoseq : public guidoelement {
00230 public:
00231 VEXP friend SMARTP<guidoseq> new_guidoseq();
00232 void accept(guidovisitor& visitor);
00233 protected:
00234 guidoseq() : guidoelement("") { fStartList="["; fEndList=" ]"; }
00235 virtual ~guidoseq() {}
00236 };
00237 typedef SMARTP<guidoseq> Sguidoseq;
00238
00242 class VEXP guidochord : public guidoelement {
00243 public:
00244 VEXP friend SMARTP<guidochord> new_guidochord();
00245 void accept(guidovisitor& visitor);
00246 protected:
00247 guidochord () : guidoelement("", ", ") { fStartList="{"; fEndList=" }"; }
00248 virtual ~guidochord() {}
00249 };
00250 typedef SMARTP<guidochord> Sguidochord;
00251
00258 class VEXP guidotag : public guidoelement {
00259 public:
00260 VEXP friend SMARTP<guidotag> new_guidotag(string name);
00261 void accept(guidovisitor& visitor);
00262 protected:
00263 guidotag(string name) : guidoelement("\\"+name) { fStartList="("; fEndList=")"; }
00264 virtual ~guidotag() {}
00265 };
00266 typedef SMARTP<guidotag> Sguidotag;
00270 #endif