Source: midimountain/mcSequence.h


Annotated List
Files
Globals
Hierarchy
Index
//============================================================================
//  TMidiSequence class definition
//============================================================================
// Author  : Adrian Meyer
// Version : 0.2.1
// Log     :
//=============================================================================
// 18.02.2000 building class
// 20.02.2000 sequence number, SMPTE offset,
//            lists: marker, tempo, time signature
// 21.02.2000 lisis: cue points, key signature, meta data, track list
// 25.02.2000 compiler switch DEBUG_OUTPUT, reading midi file chunk
// 29.02.2000 reading midi file track
// 01.03.2000 reading midi file meta data
//            TMidiEvents note on/off connected with Ref
//            UseNoteOff, changing events 0x80<->0x90
// 02.03.2000 read offset as measure/beat/ticks
// 05.03.2000 corrected and optimized measure/beat/ticks
// 27.03.2000 removed double track count on LoadFromFile
//            added prefered channel for track on LoadFromFile
// 11.04.2000 change MeasureBeatTick to long, call by reference
//            added max offset
// 28.08.2000 adding base class and message system
// 31.08.2000 added changed flag for edit operations
//            file name included
//            save to file prototype
//            init and removeAll to open file without destroy
// 01.09.2000 corrected RemoveAll (deleting track struct and TMidiTrack!)
//            corrected DeleteTrack
// 03.09.2000 set instrument patch of tracks on LoadFromFile
// 09.09.2000 allocating char* with lenth + 1
// 11.09.2000 added messages for track add / delete
//            return ID with AddMarker
//            position added
// 12.09.2000 sorting marker and time signature lists
// 13.09.2000 key signature functions corrected
// 26.11.2000 save to file :)
//            added size to meta data list
// 03.12.2000 finishing up SaveToFile
// 21.02.2001 adding grid information
// 04.04.2001 adding flag for use of only 7 bit controller
//=============================================================================
// to do:
// change SMPTE long to struct and track
// add reading midi file SMPTE meta data
// read offset as time
// read offset as SMPTE/MTC
// savetofile Sequence number, dynamic length of meta events, SMPTE Offset
//=============================================================================

#include <mcTrack.h>
#include <mcBase.h>
#include <mcList.h>
#include <fstream.h>

#ifndef __MCSEQUENCE__
#define __MCSEQUENCE__
const short cFileTypeSingle = 0;
const short cFileTypeMultiTrack = 1;
const short cFileTypeMultiSequence = 2;
const short cDeltaTimesTypeTicks = 0;
const short cDeltaTimesTypeSync = 1;

// messages for sequence
const long cMMSequenceCreate                = cMCSequence << 16 | 0x0001;
const long cMMSequenceDestroy               = cMCSequence << 16 | 0x0002;
const long cMMSequenceOpenFile              = cMCSequence << 16 | 0x0003;
const long cMMSequenceSetFileType           = cMCSequence << 16 | 0x0004;
const long cMMSequenceSetTrackCount         = cMCSequence << 16 | 0x0005;
const long cMMSequenceSetDeltaTimesType     = cMCSequence << 16 | 0x0006;
const long cMMSequenceSetRunningStatus      = cMCSequence << 16 | 0x0007;
const long cMMSequenceSetUseNoteOff         = cMCSequence << 16 | 0x0008;
const long cMMSequenceSetCopyrightNotice    = cMCSequence << 16 | 0x0009;
const long cMMSequenceSetSequenceName       = cMCSequence << 16 | 0x000A;
const long cMMSequenceSetSequenceNumber     = cMCSequence << 16 | 0x000B;
const long cMMSequenceSetSMPTEOffset        = cMCSequence << 16 | 0x000C;
const long cMMSequenceAddMarker             = cMCSequence << 16 | 0x000D;
const long cMMSequenceRenameMarker          = cMCSequence << 16 | 0x000E;
const long cMMSequenceDeleteMarker          = cMCSequence << 16 | 0x000F;
const long cMMSequenceAddTempo              = cMCSequence << 16 | 0x0010;
const long cMMSequenceDeleteTempo           = cMCSequence << 16 | 0x0011;
const long cMMSequenceAddTimeSignature      = cMCSequence << 16 | 0x0012;
const long cMMSequenceAddCuePoint           = cMCSequence << 16 | 0x0013;
const long cMMSequenceRenameCuePoint        = cMCSequence << 16 | 0x0014;
const long cMMSequenceDeleteCuePoint        = cMCSequence << 16 | 0x0015;
const long cMMSequenceAddKeySignature       = cMCSequence << 16 | 0x0016;
const long cMMSequenceDeleteKeySignature    = cMCSequence << 16 | 0x0017;
const long cMMSequenceAddMetaData           = cMCSequence << 16 | 0x0018;
const long cMMSequenceDeleteMetaData        = cMCSequence << 16 | 0x0019;
const long cMMSequenceDeleteTimeSignature   = cMCSequence << 16 | 0x001A;
const long cMMSequenceChanged               = cMCSequence << 16 | 0x001B;
const long cMMSequenceSaveFile              = cMCSequence << 16 | 0x001C;
const long cMMSequenceNew                   = cMCSequence << 16 | 0x001D;
const long cMMSequenceSetSelectionStart     = cMCSequence << 16 | 0x001E;
const long cMMSequenceSetSelectionEnd       = cMCSequence << 16 | 0x001F;
const long cMMSequenceAddTrack              = cMCSequence << 16 | 0x0020;
const long cMMSequenceDeleteTrack           = cMCSequence << 16 | 0x0021;
const long cMMSequenceSetPosition           = cMCSequence << 16 | 0x0022;
const long cMMSequenceSortMarker            = cMCSequence << 16 | 0x0023;
const long cMMSequenceSortTimeSignature     = cMCSequence << 16 | 0x0024;
const long cMMSequenceChangeTimeSignature   = cMCSequence << 16 | 0x0025;
const long cMMSequenceSortKeySignature      = cMCSequence << 16 | 0x0026;
const long cMMSequenceChangeKeySignature    = cMCSequence << 16 | 0x0027;
const long cMMSequenceSetGrid               = cMCSequence << 16 | 0x0028;
const long cMMSequenceSetUse14BitController = cMCSequence << 16 | 0x0029;

class TMidiTrack;

struct sDataTocken                                    // data tocken to save file
{
  long Offset;                                        // offset
  char* Data;                                         // data buffer
  char* DynOffset;                                    // dyn size buffer
  long DataSize;                                      // size of data
  long DynOffsetSize;                                 // size of dyn size
};

// structures for lists
struct sTrackList
{
  TMidiTrack* Track;                                  // pointer to track
  long ID;                                            // id of track
  sTrackList* Next;                                   // next track
  sTrackList* Prev;                                   // previous track
};

class TMidiMarker: public TMidiItem                   // marker
{
	private:
    char* fName;                                      // name of marker
  public:
    TMidiMarker( long aOffset, char* aName );
    char* GetName( void );                             // read marker name
    void SetName( char* aName );                      // set marker name
};

struct sCuePointList                                  // cue point list
{
  char* CuePointName;                                 // name of cue point
  long Offset;                                        // offset of cue point
  long ID;                                            // id of cue point
  sCuePointList* Next;                                // next cue point
};

struct sTempoList                                     // tempo list
{
  long Tempo;                                         // tempo
  long Offset;                                        // offset of tempo
  long ID;                                            // id of tempo
  sTempoList* Next;                                   // next tempo
};

struct sTimeSignatureList
{
  int Numerator;                                      // numerator of signature
  int Denominator;                                    // denominator of signature
  int MidiClocksPerQuarter;                           // clocks per quarter
  int NotesPerQuarter;                                // 32nd-notes per quarter
  long Offset;                                        // offset of time signature
  long ID;                                            // id of time signature
  sTimeSignatureList* Next;                           // next time signature
  sTimeSignatureList* Prev;                           // previous time signature
};

struct sKeySignatureList
{
  int SharpFlatCount;                                 // count of flats or sharps
  int IsMinor;                                        // minot or major
  long Offset;                                        // offset of time signature
  long ID;                                            // id of key signature
  sKeySignatureList* Next;                            // next key signature
};

struct sMetaDataList                                  // meta data list
{
  char* MetaData;                                     // meta data
  long Size;
  long Offset;                                        // offset of meta data
  long ID;                                            // id of meta data
  sMetaDataList* Next;                                // next meta data
};

  // in midi file "MThd nnnnnnnn" n for chunk length
class TMidiSequence: public TMidiBase
  {
    private:
      
      TMidiTrack*  trackList;                         // pointer list of track
      ifstream fFile;                                 // file stream to open
      ofstream fSaveFile;                             // file stream to save
      char fMeasureBeatTick[256];                     // storrage for GetMeasureB..

      long fSelectionStart;                           // selection start
      long fSelectionEnd;                             // selection end
      long fPosition;                                 // position in playback
      long fGrid;                                     // grid used in sequencer

      char* fFileBuffer;
      char* fFileName;
      long fBufferSize;
      bool fChanged;                                  // sequence changed?
      void ReadBuffer( long aSize );                  // read buffer from file
      short ReadShort( long aSize );
      long ReadLong( long aSize );  
      long ReadDynamic( long aPosition, long* aCount );
      void ShowBuffer( void );                        // display buffer
      void RemoveAll( void );                         // reset all objects
      void InitAll( void );                           // initialize settings

      void WriteFixNumber( long aNumber, long aWidth );// write number with fixed width

        // check for MSB and LSB with same offset->connect MidiEvent->Ref
      bool fUse14BitController;                       // use only 14 bit contollers
        // in midi file 1st 2 bytes [0..2]
      short fFileType;                                // type of file
        // in midi file 2nd 2 bytes [1..65536]
      int   fTrackCount;                              // count of tracks
        // in midi file 3rd 2 bytes
        // bit 15=0 -> ticks per quarter note
        // bit 15=1 -> bit 8-14 negative SMPTE format, bits 0..7 ticks per frame
      short fDeltaTimesType;                          // type of delta times
        // in midi file no doubled status bytes
      bool fUseRunningStatus;                         // use the running status
        // play 0x8c for note off instead of 0x9c and velocity 0
      bool fUseNoteOff;                               // use note off
        // in midi file "FF 01 len text"
      char* fCopyrightNotice;                         // copyright notice
        // in midi file track 1 offset 0 "FF 03 len text"
      char* fSequenceName;                            // name of the sequence
        // in midi file track 1 offset 0 "FF 00 nn"
      short fSequenceNumber;                          // sequence number
        // in midi file "FF 05 hr mn se fr ff"
      long  fSMPTEOffset;                             // SMPTE offset
        // in midi file "FF 06 len text"
      TMidiList* fMarkerList;                         // list with markers
        // in midi file "FF 51 03 tttttt"
      sTempoList* fTempoList;                         // list with tempos
        // in midi file "FF 58 04 nn dd cc bb"
      sTimeSignatureList* fTimeSignatureList;         // list with time signatures
        // in midi file "FF 07 len text"
      sCuePointList* fCuePointList;                   // list with cue points
        // in midi file "FF 59 02 sf mi"
      sKeySignatureList* fKeySignatureList;           // list with key signatures
        // in midi file "FF 7F len data" (fist byte or 3 bytes manufacturer ID)
      sMetaDataList* fMetaDataList;                   // list with meta data

        // in midi file "MTrk"
      sTrackList* fTrackList;                         // list with midi tracks
  public:
                                                      // constructor with message hook
    TMidiSequence( tMCMessage * aMCMessage, void* aUserData );
    ~TMidiSequence( void );

    short LoadFromFile( char* aFileName );            // load objects from file
    short SaveToFile( char* aFileName );              // save objects to file
    void New( void );                                 // new sequence

    void GetMeasureBeatTick( long aOffset, long* aMeasure, long* aBeat, long* Tick );
    char* GetMeasureBeatTick( long aOffset );         // read measure/beat/tick
    long GetMaxOffset( void );                        // read max event offset
    void GetTimeInformation( long aMeasure, long* aBeatCount, long* aTicksPerBeat );
    long GetOffset( long aMeasure, long aBeat, long Tick );

    void SetUse14BitController(bool aUse14BitController);// set 14bit controller use
    bool GetUse14BitController( void );               // read 14 bit controller use
    void SetFileType( short aFileType );              // write file type
    short GetFileType( void );                        // read file type
    void SetTrackCount( int aTrackCount );            // write track count
    int GetTrackCount( void );                        // read track count
    void SetDeltaTimesType( short aDeltaTimesType );  // write delta time type
    short GetDeltaTimesType( void );                  // read delta times type
    void SetUseRunningStatus( bool aRunningUseStatus );// write running status
    bool GetUseRunningStatus( void );                 // read running status
    void SetUseNoteOff( bool aUseNoteOff );           // write use note off
    bool GetUseNoteOff( void );                       // read use note off
    void SetCopyrightNotice( char* aCopyrightNotice );// write copyright
    char* GetCopyrightNotice( void );                 // read copyright
    void SetSequenceName( char* aSequenceName );      // write sequence name
    char* GetSequenceName( void );                    // read sequence name
    void SetSequenceNumber( short aSequenceNumber );  // write sequence number
    short GetSequenceNumber( void );                  // read sequence number
    void SetSMPTEOffset( long aSMPTEOffset );         // write SMPTE offset
    long GetSMPTEOffset( void );                      // read SMPTE offset
    void SetFileName( char* aFileName );              // write file name
    char* GetFileName( void );                        // read file name

    TMidiMarker* AddMarker( long aOffset, char* aMarkerName );// add marker
    void RenameMarker( TMidiMarker* aMarker, char* aMarkerName ); // rename marker
    void SetMarkerOffset( TMidiMarker* aMarker, long aOffset ); // set marker offset
    void DeleteMarker( TMidiMarker* aMarker );        // delete a marker
    TMidiMarker* GetMarker( long aID );               // read marker
    long GetMarkerCount( void );                      // read marker count

    void AddTempo( long aTempo, long aOffset );       // add tempo
    void DeleteTempo( long aID );                     // delete a tempo
    sTempoList* GetTempo( long aID );                 // read tempo
    long GetTempoCount( void );                       // read marker count
    long GetTempoAt( long aOffset );                  // get tempo at offset

    long AddTimeSignature( int aNumerator, int aDenominator,// add time signature  
      int aMidiClocksPerQuarter, int aNotesPerQuarter, long aOffset );                                      
    void DeleteTimeSignature( long aID );             // delete a time signature
    sTimeSignatureList* GetTimeSignature( long aID ); // read time signature
    long GetTimeSignatureCount( void );               // read time signature count
    void ChangeTimeSignature( long aID, int aNumerator, int aDenominator,
      int aMidiClocksPerQuarter, int aNotesPerQuarter );
    void SortTimeSignature( void );                   // sort time signature list

    void AddCuePoint( char* aCuePointName, long aOffset );// add cue point
    void RenameCuePoint( char* aCuePointName, long aID );  // rename cue point
    void DeleteCuePoint( long aID );                  // delete a cue point
    sCuePointList* GetCuePoint( long aID );           // list cue point list
    long GetCuePointCount( void );                    // read cue point count

    long AddKeySignature( int aSharpFlatCount, short aIsMinor,
                           long aOffset );            // add key signature  
    void DeleteKeySignature( long aID );              // delete a key signature
    sKeySignatureList* GetKeySignature( long aID );   // read key signature
    long GetKeySignatureCount( void );                // read key signature count
    void SortKeySignature( void );                    // sort key signature list
    void ChangeKeySignature( long aID,                // change key signature  
        int aSharpFlatCount, short aIsMinor );

                                                      // add meta data
    void AddMetaData( char* aMetaData, long aSize, long aOffset );
    void DeleteMetaData( long aID );                  // delete a meta data
    sMetaDataList* GetMetaData( long aID );           // list meta data list
    long GetMetaDataCount( void );                    // read meta data count

    TMidiTrack* AddTrack( void );                     // add track
    void DeleteTrack( long aID );                     // delete a track
    sTrackList* GetTrackList( long aID );             // get midi track list item
    TMidiTrack* GetTrack( long aID );                 // get midi track

    void SetChanged( bool aChanged );                 // set thchanged flag
    bool GetChanged( void );                          // read the changed flag

    void SetSelectionStart( long aSelectionStart );   // write selection start
    long GetSelectionStart( void );                   // read selection start
    void SetSelectionEnd( long aSelectionEnd );       // write selection end
    long GetSelectionEnd( void );                     // read selection end

    void SetPosition( long aPosition );               // write position
    long GetPosition( void );                         // read position

    void SetGrid( long aGrid );                       // write grid
    long GetGrid( void );                             // read grid
  };

#endif

Generated by: root@castle on Fri Jul 20 00:33:17 2001, using kdoc 2.0a36.