Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
/home/iurt/rpm/BUILD/canorus-0.7.R1002/src/import/lilypondimport.h
Go to the documentation of this file.
00001 
00008 #ifndef LILYPONDIMPORT_H_
00009 #define LILYPONDIMPORT_H_
00010 
00011 #include <QString>
00012 #include <QStack>
00013 
00014 #include "core/voice.h"
00015 #include "core/rest.h"
00016 #include "core/keysignature.h"
00017 #include "core/clef.h"
00018 #include "core/timesignature.h"
00019 #include "core/barline.h"
00020 #include "core/lyricscontext.h"
00021 #include "core/syllable.h"
00022 #include "core/playablelength.h"
00023 #include "core/diatonicpitch.h"
00024 
00025 #include "import/import.h"
00026 
00027 class QTextStream;
00028 
00029 class CALilyPondImport : public CAImport {
00030 public:
00031         // Constructors
00032         CALilyPondImport( const QString in );
00033         CALilyPondImport( QTextStream *in=0 );
00034         inline void setTemplateVoice( CAVoice *voice ) { _templateVoice = voice; }
00035         
00036         // Destructor
00037         virtual ~CALilyPondImport();
00038         
00039         const QString readableStatus();
00040         
00041 private:
00042         void initLilyPondImport();
00043         
00044         static const QRegExp WHITESPACE_DELIMITERS;
00045         static const QRegExp SYNTAX_DELIMITERS;
00046         static const QRegExp DELIMITERS;
00047         
00048         // Internal time signature
00049         struct CATime {
00050                 int beats;
00051                 int beat;
00052         };
00053         
00054         enum CALilyPondDepth {
00055                 Score,
00056                 Layout,
00057                 Voice,
00058                 Chord
00059         };
00060         
00061         // Actual import of the input string
00062         CAVoice *importVoiceImpl();
00063         CALyricsContext *importLyricsContextImpl();
00064         
00065         inline CAVoice *curVoice() { return _curVoice; }
00066         inline void setCurVoice(CAVoice *voice) { _curVoice = voice; }
00067         
00068         const QString parseNextElement();
00069         const QString peekNextElement();
00070         void addError(QString description, int lineError = 0, int charError = 0);
00071         
00073         // Helper functions //
00075         CAPlayableLength playableLengthFromLilyPond( QString &playableElt, bool parse=false );
00076         
00077         bool isNote(const QString elt);
00078         CADiatonicPitch relativePitchFromLilyPond(QString &note, CADiatonicPitch prevPitch, bool parse=false);
00079         bool isRest(const QString elt);
00080         CARest::CARestType restTypeFromLilyPond(QString& rest, bool parse=false);
00081         CAClef::CAPredefinedClefType predefinedClefTypeFromLilyPond( const QString clef );
00082         int clefOffsetFromLilyPond( const QString clef );
00083         CABarline::CABarlineType barlineTypeFromLilyPond(const QString bar);
00084         CADiatonicKey::CAGender diatonicKeyGenderFromLilyPond(QString gender);
00085         CATime timeSigFromLilyPond(QString time);
00086                 
00087         CAMusElement* findSharedElement(CAMusElement *elt);
00088         
00090         // Getter/Setter methods //
00092         inline QString& in() { return *stream()->string(); }
00093         inline CALilyPondDepth curDepth() { return _depth.top(); }
00094         inline void pushDepth(CALilyPondDepth depth) { _depth.push(depth); }
00095         inline CALilyPondDepth popDepth() { return _depth.pop(); }
00096         inline int curLine() { return _curLine; }
00097         inline int curChar() { return _curChar; }
00098         
00099         // Attributes
00100         CAVoice *_curVoice;
00101         CASlur *_curSlur;
00102         CASlur *_curPhrasingSlur;
00103         QStack<CALilyPondDepth> _depth; // which block is currently processed
00104         int _curLine, _curChar;
00105         QList<QString> _errors;
00106         QList<QString> _warnings;
00107         
00108         inline CAVoice *templateVoice() { return _templateVoice; }
00109         CAVoice *_templateVoice; // used when importing voice to set the staff etc.
00110 };
00111 
00112 #endif /* LILYPONDIMPORT_H_ */