Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
midiimport.h
Go to the documentation of this file.
1 
8 #ifndef MIDIIMPORT_H_
9 #define MIDIIMPORT_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 class CAMidiDevice;
29 class CAMidiImportEvent;
30 
31 class CAMidiImport : public CAImport {
32 public:
33  // Constructor
34  CAMidiImport( QTextStream *in=0 );
35 
36  // Destructor
37  virtual ~CAMidiImport();
38 
39  // close midi in file after import
40  void closeFile();
41 
42  // where the real work is done
45 
46  const QString readableStatus();
47 
48 private:
49  void initMidiImport();
50 
51  static const QRegExp WHITESPACE_DELIMITERS;
52  static const QRegExp SYNTAX_DELIMITERS;
53  static const QRegExp DELIMITERS;
54 
55  // Internal time signature
56  struct CATime {
57  int beats;
58  int beat;
59  };
60 
66  };
67 
68  inline CAVoice *curVoice() { return _curVoice; }
69  inline void setCurVoice(CAVoice *voice) { _curVoice = voice; }
70 
71  const QString parseNextElement();
72  const QString peekNextElement();
73  void addError(QString description, int lineError = 0, int charError = 0);
74 
76  // Helper functions //
78  CAPlayableLength playableLengthFromLilyPond( QString &playableElt, bool parse=false );
79 
80  bool isNote(const QString elt);
81  CADiatonicPitch relativePitchFromLilyPond(QString &note, CADiatonicPitch prevPitch, bool parse=false);
82  bool isRest(const QString elt);
83  CARest::CARestType restTypeFromLilyPond(QString& rest, bool parse=false);
85  int clefOffsetFromLilyPond( const QString clef );
88  CATime timeSigFromLilyPond(QString time);
89 
91 
93  // Getter/Setter methods //
95  inline QString& in() { return *stream()->string(); }
96  inline CALilyPondDepth curDepth() { return _depth.top(); }
97  inline void pushDepth(CALilyPondDepth depth) { _depth.push(depth); }
98  inline CALilyPondDepth popDepth() { return _depth.pop(); }
99  inline int curLine() { return _curLine; }
100  inline int curChar() { return _curChar; }
101 
102  // Attributes
106  QStack<CALilyPondDepth> _depth; // which block is currently processed
108  QList<QString> _errors;
109  QList<QString> _warnings;
110 
111  //inline CAVoice *templateVoice() { return _templateVoice; }
112  //CAVoice *_templateVoice; // used when importing voice to set the staff etc.
113 
115  // Helper functions //
117  int getVariableLength(QByteArray *x );
118  QByteArray getHead(QByteArray *x);
119  int getByte(QByteArray *x);
120  int getWord16(QByteArray *x);
121  int getWord24(QByteArray *x);
122  int getWord32(QByteArray *x);
123  QByteArray getString(QByteArray *x, int len);
124  void printQByteArray( QByteArray x ); // debugging only
128  void noteOn( bool on, int channel, int pitch, int velocity, int time );
129 
131  hr, min, se, fr, ff, next
132  };
135 
137  QVector<QList<QList<CAMidiImportEvent*>*>*> _allChannelsEvents;
138  QList<CAMidiImportEvent*> _eventsX;
139  void combineMidiFileEvents();
140  void quantizeMidiFileEvents();
142  void writeMidiFileEventsToScore( CASheet *sheet );
143  void writeMidiChannelEventsToVoice( int channel, CAStaff *staff, CAVoice *voice );
144 };
145 
146 #endif /* MIDIIMPORT_H_ */