midicomp.h 2.27 KB

#define MIDI_TYPE 0
#define META_TYPE 1
#define SYSEX_TYPE 2

#define META_PLACEHOLDER  0xFF
#define NO_LOOPEND        0xFFFFFFFF
#define BIG_LOOPCOUNT_ADD    0x80

#define MIN_MATCH_SIZE  6
#define MAX_MATCH_LEN   255
#define MAX_WIND_ADV    0xFDFF

class MIDIList : public List
{
   public:
       
    void MIDIList::endNote(long time, char chan, char key);

};

class MIDIComp : public MIDIFile
{
  protected:
    char    *curOutPtr;
    char    *compData;
    char    *compTrackBufs[16];
    long    compTrackSizes[16];
    char    *trackBufs[16];
    long    trackSizes[16];
    long    hashMask;
    char    **hashTable;
    char    *nextHashPtr;

    
    virtual void midiHeader(TrackHdr *hdr);

    /* Meta Message handlers */
    virtual void midiTempo(long tempo);
    virtual void midiEndOfTrack();

    /* Channel Message handlers */
    virtual void midiNoteOn(char chan, char note, char velocity);
    virtual void midiNoteOff(char chan, char note, char velocity);
    virtual void midiKeyPressure(char chan, char key, char velocity);
    virtual void midiControlChange(char chan, char control, char value);
    virtual void midiPitchBend(char chan, char msb, char lsb);
    virtual void midiProgramChange(char chan, char program);
    virtual void midiChannelPressure(char chan, char pressure);

    /* write operations */
    virtual void writeHeader(void);
    virtual void buildTrack(int track);
    virtual void compressTracks(void);
    virtual void compress1Track(long track);
    
    long MIDIComp::deltaSize(long delta);

    /* write sub routines */
    void noteOn2Buf(char *trackBuf,long *bufOffset,Node *item);
    void delta2Buf(char *trackBuf,long *bufOffset,long delta);
    void TwoByteMidi2Buf(char *trackBuf,long *bufOffset,Node *item);
    void ThreeByteMidi2Buf(char *trackBuf,long *bufOffset,Node *item);
    void meta2Buf(char *trackBuf,long *bufOffset,Node *item);
    void loopStart2Buf(char *trackBuf,long *bufOffset,Node *item);
    void loopEnd2Buf(char *trackBuf,long *bufOffset,Node *item,long loopCount);
    
    char *CopyData(char *src, char *dst, long len);
    long matchPattern(char *test,char *tryPtr);
    long HashString(char *str, long hashMask);
    long HashSize(long numObjs);

public:
    void    Write(void);
    long    sequenceEnd;
    long    division;
};