Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
/home/iurt/rpm/BUILD/canorus-0.7.R1002/src/import/midiimport.h
Go to the documentation of this file.
00001 
00008 #ifndef MIDIIMPORT_H_
00009 #define MIDIIMPORT_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 class CAMidiDevice;
00029 class CAMidiImportEvent;
00030 
00031 class CAMidiImport : public CAImport {
00032 public:
00033         // Constructor
00034         CAMidiImport( QTextStream *in=0 );
00035 
00036         // Destructor
00037         virtual ~CAMidiImport();
00038 
00039         // close midi in file after import
00040         void closeFile();
00041 
00042         // where the real work is done
00043         CADocument *importDocumentImpl();
00044         CASheet *importSheetImpl();
00045 
00046         const QString readableStatus();
00047 
00048 private:
00049         void initMidiImport();
00050 
00051         static const QRegExp WHITESPACE_DELIMITERS;
00052         static const QRegExp SYNTAX_DELIMITERS;
00053         static const QRegExp DELIMITERS;
00054 
00055         // Internal time signature
00056         struct CATime {
00057                 int beats;
00058                 int beat;
00059         };
00060 
00061         enum CALilyPondDepth {
00062                 Score,
00063                 Layout,
00064                 Voice,
00065                 Chord
00066         };
00067 
00068         inline CAVoice *curVoice() { return _curVoice; }
00069         inline void setCurVoice(CAVoice *voice) { _curVoice = voice; }
00070 
00071         const QString parseNextElement();
00072         const QString peekNextElement();
00073         void addError(QString description, int lineError = 0, int charError = 0);
00074 
00076         // Helper functions //
00078         CAPlayableLength playableLengthFromLilyPond( QString &playableElt, bool parse=false );
00079 
00080         bool isNote(const QString elt);
00081         CADiatonicPitch relativePitchFromLilyPond(QString &note, CADiatonicPitch prevPitch, bool parse=false);
00082         bool isRest(const QString elt);
00083         CARest::CARestType restTypeFromLilyPond(QString& rest, bool parse=false);
00084         CAClef::CAPredefinedClefType predefinedClefTypeFromLilyPond( const QString clef );
00085         int clefOffsetFromLilyPond( const QString clef );
00086         CABarline::CABarlineType barlineTypeFromLilyPond(const QString bar);
00087         CADiatonicKey::CAGender diatonicKeyGenderFromLilyPond(QString gender);
00088         CATime timeSigFromLilyPond(QString time);
00089 
00090         CAMusElement* findSharedElement(CAMusElement *elt);
00091 
00093         // Getter/Setter methods //
00095         inline QString& in() { return *stream()->string(); }
00096         inline CALilyPondDepth curDepth() { return _depth.top(); }
00097         inline void pushDepth(CALilyPondDepth depth) { _depth.push(depth); }
00098         inline CALilyPondDepth popDepth() { return _depth.pop(); }
00099         inline int curLine() { return _curLine; }
00100         inline int curChar() { return _curChar; }
00101 
00102         // Attributes
00103         CAVoice *_curVoice;
00104         CASlur *_curSlur;
00105         CASlur *_curPhrasingSlur;
00106         QStack<CALilyPondDepth> _depth; // which block is currently processed
00107         int _curLine, _curChar;
00108         QList<QString> _errors;
00109         QList<QString> _warnings;
00110 
00111         //inline CAVoice *templateVoice() { return _templateVoice; }
00112         //CAVoice *_templateVoice; // used when importing voice to set the staff etc.
00113 
00115         // Helper functions //
00117         int getVariableLength(QByteArray *x );
00118         QByteArray getHead(QByteArray *x);
00119         int getByte(QByteArray *x);
00120         int getWord16(QByteArray *x);
00121         int getWord24(QByteArray *x);
00122         int getWord32(QByteArray *x);
00123         QByteArray getString(QByteArray *x, int len);
00124         void printQByteArray( QByteArray x );   // debugging only
00125         int _dataIndex;
00126         int _nextTrackIndex;
00127         bool _parseError;
00128         void noteOn( bool on, int channel, int pitch, int velocity, int time );
00129 
00130         enum smtpOffsComponents {
00131                 hr, min, se, fr, ff, next
00132         };
00133         int _smtpOffset[next];
00134         int _microSecondsPerMidiQuarternote;
00135 
00136         CADocument *_document;
00137         QVector<QList<QList<CAMidiImportEvent*>*>*> _allChannelsEvents;
00138         QList<CAMidiImportEvent*> _eventsX;
00139         void combineMidiFileEvents();
00140         void quantizeMidiFileEvents();
00141         void exportNonChordsToOtherVoices();
00142         void writeMidiFileEventsToScore( CASheet *sheet );
00143         void writeMidiChannelEventsToVoice( int channel, CAStaff *staff, CAVoice *voice );
00144 };
00145 
00146 #endif /* MIDIIMPORT_H_ */