drumstick 0.5.0

qwrk.h

Go to the documentation of this file.
00001 /*
00002     WRK File component
00003     Copyright (C) 2010, Pedro Lopez-Cabanillas <plcl@users.sf.net>
00004 
00005     This library is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License along
00016     with this program; if not, write to the Free Software Foundation, Inc.,
00017     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 */
00019 
00020 #ifndef DRUMSTICK_QWRK_H
00021 #define DRUMSTICK_QWRK_H
00022 
00023 #include "macros.h"
00024 #include <QObject>
00025 
00026 class QDataStream;
00027 
00035 namespace drumstick {
00036 
00040 enum WrkChunkType {
00041     TRACK_CHUNK = 1,     
00042     STREAM_CHUNK = 2,    
00043     VARS_CHUNK = 3,      
00044     TEMPO_CHUNK = 4,     
00045     METER_CHUNK = 5,     
00046     SYSEX_CHUNK = 6,     
00047     MEMRGN_CHUNK = 7,    
00048     COMMENTS_CHUNK = 8,  
00049     TRKOFFS_CHUNK = 9,   
00050     TIMEBASE_CHUNK = 10, 
00051     TIMEFMT_CHUNK = 11,  
00052     TRKREPS_CHUNK = 12,  
00053     TRKPATCH_CHUNK = 14, 
00054     NTEMPO_CHUNK = 15,   
00055     THRU_CHUNK = 16,     
00056     LYRICS_CHUNK = 18,   
00057     TRKVOL_CHUNK = 19,   
00058     SYSEX2_CHUNK = 20,   
00059     STRTAB_CHUNK = 22,   
00060     METERKEY_CHUNK = 23, 
00061     TRKNAME_CHUNK = 24,  
00062     VARIABLE_CHUNK = 26, 
00063     NTRKOFS_CHUNK = 27,  
00064     TRKBANK_CHUNK = 30,  
00065     NTRACK_CHUNK = 36,   
00066     NSYSEX_CHUNK = 44,   
00067     NSTREAM_CHUNK = 45,  
00068     SGMNT_CHUNK = 49,    
00069     SOFTVER_CHUNK = 74,  
00070     END_CHUNK = 255      
00071 };
00072 
00073 const QByteArray HEADER("CAKEWALK"); 
00074 
00081 class DRUMSTICK_EXPORT QWrk : public QObject
00082 {
00083     Q_OBJECT
00084 
00085 public:
00086     QWrk(QObject * parent = 0);
00087     virtual ~QWrk();
00088 
00089     void readFromStream(QDataStream *stream);
00090     void readFromFile(const QString& fileName);
00091     QTextCodec* getTextCodec();
00092     void setTextCodec(QTextCodec *codec);
00093     long getFilePos();
00094 
00095     int getNow() const;
00096     int getFrom() const;
00097     int getThru() const;
00098     int getKeySig() const;
00099     int getClock() const;
00100     int getAutoSave() const;
00101     int getPlayDelay() const;
00102     bool getZeroCtrls() const;
00103     bool getSendSPP() const;
00104     bool getSendCont() const;
00105     bool getPatchSearch() const;
00106     bool getAutoStop() const;
00107     unsigned int getStopTime() const;
00108     bool getAutoRewind() const;
00109     int getRewindTime() const;
00110     bool getMetroPlay() const;
00111     bool getMetroRecord() const;
00112     bool getMetroAccent() const;
00113     int getCountIn() const;
00114     bool getThruOn() const;
00115     bool getAutoRestart() const;
00116     int getCurTempoOfs() const;
00117     int getTempoOfs1() const;
00118     int getTempoOfs2() const;
00119     int getTempoOfs3() const;
00120     bool getPunchEnabled() const;
00121     int getPunchInTime() const;
00122     int getPunchOutTime() const;
00123     int getEndAllTime() const;
00124 
00125     QByteArray getLastChunkRawData() const;
00126     double getRealTime(long ticks) const;
00127 
00128 Q_SIGNALS:
00129 
00135     void signalWRKError(const QString& errorStr);
00136 
00143     void signalWRKUnknownChunk(int type, const QByteArray& data);
00144 
00151     void signalWRKHeader(int verh, int verl);
00152 
00156     void signalWRKEnd();
00157 
00161     void signalWRKStreamEnd(long time);
00162 
00173     void signalWRKNote(int track, long time, int chan, int pitch, int vol, int dur);
00174 
00184     void signalWRKKeyPress(int track, long time, int chan, int pitch, int press);
00185 
00195     void signalWRKCtlChange(int track, long time, int chan, int ctl, int value);
00196 
00205     void signalWRKPitchBend(int track, long time, int chan, int value);
00206 
00215     void signalWRKProgram(int track, long time, int chan, int patch);
00216 
00225     void signalWRKChanPress(int track, long time, int chan, int press);
00226 
00234     void signalWRKSysexEvent(int track, long time, int bank);
00235 
00245     void signalWRKSysex(int bank, const QString& name, bool autosend, int port, const QByteArray& data);
00246 
00255     void signalWRKText(int track, long time, int type, const QString& data);
00256 
00264     void signalWRKTimeSig(int bar, int num, int den);
00265 
00272     void signalWRKKeySig(int bar, int alt);
00273 
00283     void signalWRKTempo(long time, int tempo);
00284 
00299     void signalWRKTrack(const QString& name1,
00300                         const QString& name2,
00301                         int trackno, int channel, int pitch,
00302                         int velocity, int port,
00303                         bool selected, bool muted, bool loop );
00304 
00310     void signalWRKTimeBase(int timebase);
00311 
00320     void signalWRKGlobalVars();
00321 
00336     void signalWRKThru(int mode, int port, int channel, int keyPlus, int velPlus, int localPort);
00337 
00344     void signalWRKTrackOffset(int track, int offset);
00345 
00352     void signalWRKTrackReps(int track, int reps);
00353 
00360     void signalWRKTrackPatch(int track, int patch);
00361 
00368     void signalWRKTrackBank(int track, int bank);
00369 
00376     void signalWRKTimeFormat(int frames, int offset);
00377 
00383     void signalWRKComments(const QString& data);
00384 
00392     void signalWRKVariableRecord(const QString& name, const QByteArray& data);
00393 
00400     void signalWRKTrackVol(int track, int vol);
00401 
00415     void signalWRKNewTrack( const QString& name,
00416                             int trackno, int channel, int pitch,
00417                             int velocity, int port,
00418                             bool selected, bool muted, bool loop );
00419 
00425     void signalWRKSoftVer(const QString& version);
00426 
00433     void signalWRKTrackName(int track, const QString& name);
00434 
00440     void signalWRKStringTable(const QStringList& strs);
00441 
00449     void signalWRKSegment(int track, long time, const QString& name);
00450 
00459     void signalWRKChord(int track, long time, const QString& name, const QByteArray& data);
00460 
00469     void signalWRKExpression(int track, long time, int code, const QString& text);
00470 
00479     void signalWRKHairpin(int track, long time, int code, int dur);
00480 
00481 private:
00482     quint8 readByte();
00483     quint16 to16bit(quint8 c1, quint8 c2);
00484     quint32 to32bit(quint8 c1, quint8 c2, quint8 c3, quint8 c4);
00485     quint16 read16bit();
00486     quint32 read24bit();
00487     quint32 read32bit();
00488     QString readString(int len);
00489     QString readVarString();
00490     void readRawData(int size);
00491     void readGap(int size);
00492     bool atEnd();
00493     void seek(qint64 pos);
00494 
00495     int readChunk();
00496     void processTrackChunk();
00497     void processVarsChunk();
00498     void processTimebaseChunk();
00499     void processNoteArray(int track, int events);
00500     void processStreamChunk();
00501     void processMeterChunk();
00502     void processTempoChunk(int factor = 1);
00503     void processSysexChunk();
00504     void processSysex2Chunk();
00505     void processNewSysexChunk();
00506     void processThruChunk();
00507     void processTrackOffset();
00508     void processTrackReps();
00509     void processTrackPatch();
00510     void processTrackBank();
00511     void processTimeFormat();
00512     void processComments();
00513     void processVariableRecord(int max);
00514     void processNewTrack();
00515     void processSoftVer();
00516     void processTrackName();
00517     void processStringTable();
00518     void processLyricsStream();
00519     void processTrackVol();
00520     void processNewTrackOffset();
00521     void processMeterKeyChunk();
00522     void processSegmentChunk();
00523     void processNewStream();
00524     void processUnknown(int id);
00525     void processEndChunk();
00526     void wrkRead();
00527 
00528     struct RecTempo {
00529         long time;
00530         double tempo;
00531         double seconds;
00532     };
00533 
00534     class QWrkPrivate;
00535     QWrkPrivate *d;
00536 };
00537 
00538 } // namespace drumstick;
00539 
00542 #endif // DRUMSTICK_QWRK_H