Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lilypondimport.h
Go to the documentation of this file.
1 
8 #ifndef LILYPONDIMPORT_H_
9 #define LILYPONDIMPORT_H_
10 
11 #include <QString>
12 #include <QStack>
13 
14 #include "core/voice.h"
15 #include "core/rest.h"
16 #include "core/keysignature.h"
17 #include "core/clef.h"
18 #include "core/timesignature.h"
19 #include "core/barline.h"
20 #include "core/lyricscontext.h"
21 #include "core/syllable.h"
22 #include "core/playablelength.h"
23 #include "core/diatonicpitch.h"
24 
25 #include "import/import.h"
26 
27 class QTextStream;
28 
29 class CALilyPondImport : public CAImport {
30 public:
31  // Constructors
32  CALilyPondImport( const QString in );
33  CALilyPondImport( QTextStream *in=0 );
34  inline void setTemplateVoice( CAVoice *voice ) { _templateVoice = voice; }
35 
36  // Destructor
37  virtual ~CALilyPondImport();
38 
39  const QString readableStatus();
40 
41 private:
42  void initLilyPondImport();
43 
44  static const QRegExp WHITESPACE_DELIMITERS;
45  static const QRegExp SYNTAX_DELIMITERS;
46  static const QRegExp DELIMITERS;
47 
48  // Internal time signature
49  struct CATime {
50  int beats;
51  int beat;
52  };
53 
59  };
60 
61  // Actual import of the input string
64 
65  inline CAVoice *curVoice() { return _curVoice; }
66  inline void setCurVoice(CAVoice *voice) { _curVoice = voice; }
67 
68  const QString parseNextElement();
69  const QString peekNextElement();
70  void addError(QString description, int lineError = 0, int charError = 0);
71 
73  // Helper functions //
75  CAPlayableLength playableLengthFromLilyPond( QString &playableElt, bool parse=false );
76 
77  bool isNote(const QString elt);
78  CADiatonicPitch relativePitchFromLilyPond(QString &note, CADiatonicPitch prevPitch, bool parse=false);
79  bool isRest(const QString elt);
80  CARest::CARestType restTypeFromLilyPond(QString& rest, bool parse=false);
82  int clefOffsetFromLilyPond( const QString clef );
85  CATime timeSigFromLilyPond(QString time);
86 
88 
90  // Getter/Setter methods //
92  inline QString& in() { return *stream()->string(); }
93  inline CALilyPondDepth curDepth() { return _depth.top(); }
94  inline void pushDepth(CALilyPondDepth depth) { _depth.push(depth); }
95  inline CALilyPondDepth popDepth() { return _depth.pop(); }
96  inline int curLine() { return _curLine; }
97  inline int curChar() { return _curChar; }
98 
99  // Attributes
103  QStack<CALilyPondDepth> _depth; // which block is currently processed
105  QList<QString> _errors;
106  QList<QString> _warnings;
107 
108  inline CAVoice *templateVoice() { return _templateVoice; }
109  CAVoice *_templateVoice; // used when importing voice to set the staff etc.
110 };
111 
112 #endif /* LILYPONDIMPORT_H_ */