root/trunk/libjdkmidi/trunk/include/jdkmidi/track.h

Revision 555, 5.8 kB (checked in by jeffk@…, 4 months ago)

latex documentation started. autobuild dir switched to magicmakefile v6

Line 
1/*
2 *  libjdkmidi-2004 C++ Class Library for MIDI
3 *
4 *  Copyright (C) 2004  J.D. Koftinoff Software, Ltd.
5 *  www.jdkoftinoff.com
6 *  jeffk@jdkoftinoff.com
7 *
8 *  *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 ***
9 *
10 *  This program is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License as published by
12 *  the Free Software Foundation; either version 2 of the License, or
13 *  (at your option) any later version.
14 *
15 *  This program is distributed in the hope that it will be useful,
16 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 *  GNU General Public License for more details.
19 *
20 *  You should have received a copy of the GNU General Public License
21 *  along with this program; if not, write to the Free Software
22 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23*/
24/*
25** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd.
26**
27** All rights reserved.
28**
29** No one may duplicate this source code in any form for any reason
30** without the written permission given by J.D. Koftinoff Software, Ltd.
31**
32*/
33
34#ifndef JDKMIDI_TRACK_H
35#define JDKMIDI_TRACK_H
36
37#include "jdkmidi/midi.h"
38#include "jdkmidi/msg.h"
39#include "jdkmidi/sysex.h"
40
41namespace jdkmidi
42{
43
44  ///
45  /// MIDITrackChunkSize is a constant which specifies how many events are in one MIDITrackChunk.
46  ///
47 
48  const int MIDITrackChunkSize=512;
49 
50 
51  ///
52  /// A MIDITrack's events are allocated in these chunks in order to avoid memory fragmentation
53  /// in embedded systems or other systems lacking an MMU. Every item within a MIDITrackChunk
54  /// object is a MIDITimedBigMessage. To avoid unnecessary copied of big events, access
55  /// to these events is only done via the GetEventAddress() method.
56  ///
57 
58  class  MIDITrackChunk
59  {
60    public:
61      ///
62      /// GetEventAddress() const returns the address of the MIDITimedBigMessage referred to by event_num
63      /// @param event_num an integer specifying an event number in the range 0 to MIDITrackChunkSize
64      /// @returns The const pointer to the requested event.
65      ///
66      const MIDITimedBigMessage * GetEventAddress ( int event_num ) const;
67     
68      ///
69      /// GetEventAddress()  returns the address of the MIDITimedBigMessage referred to by event_num
70      /// @param event_num an integer specifying an event number in the range 0 to MIDITrackChunkSize
71      /// @returns The non-const pointer to the requested event.
72      ///
73     
74      MIDITimedBigMessage * GetEventAddress ( int event_num );
75     
76    protected:
77   
78    private:
79      MIDITimedBigMessage buf[MIDITrackChunkSize];
80  };
81 
82  ///
83  /// The MIDIChunksPerTrack constant specifies the maximum number of MIDITrackChunks that can be in one track.
84  /// The value MIDIChunksPerTrack * MIDITrackChunkSize is the total number of events.
85  /// This is a constant in order to avoid memory fragmentation in embedded systems or systems without an MMU
86  ///
87 
88  const int MIDIChunksPerTrack=512;
89 
90 
91  ///
92  /// The MIDITrack class is a container that manages an array of MIDIChunk objects and provides an
93  /// interface to the user that is useful for managing a list of MIDITimedBigMessages. It internally
94  /// stores MIDITimedBigMessage objects. There is a fixed maximum number of events that it can store,
95  /// which is defined by MIDIChunksPerTrack * MIDITrackChunkSize.
96  ///
97 
98  class  MIDITrack
99  {
100    public:
101   
102      ///
103      /// Construct a MIDITrack object with the specified number of events
104      /// @param size The number of events, defaults to 0
105      ///
106      MIDITrack ( int size=0 );
107     
108      ///
109      /// Copy Constructor for a MIDITrack object
110      /// @param t The reference to the MIDITrack object to copy
111      ///
112      MIDITrack ( const MIDITrack &t );
113     
114      ///
115      /// The MIDITrack Destructor, frees all chunks and referenced MIDITimedBigMessage's
116      ///
117      ~MIDITrack();
118     
119      ///
120      /// Clear() sets the number of active events in the track to 0. It does NOT
121      /// free any events. See the Shrink() method.
122      ///
123      void Clear();
124     
125      ///
126      /// Shrink() frees any unused MIDITrackChunk objects and associated MIDITimedBigMessage events.
127      ///
128      void Shrink();
129     
130      ///
131      /// ClearAndMerge() allows you to merge the events in two separate tracks into a third track.
132      /// @param src1 Pointer to first track
133      /// @param src2 Pointer to second track
134      /// ClearAndMerge() assumes all events in both tracks are already ordered by time.
135      ///
136      void ClearAndMerge ( const MIDITrack *src1, const MIDITrack *src2 );
137     
138// bool Insert( int start_event, int num_events );
139//    bool  Delete( int start_event, int num_events);
140//    void  Sort();
141
142      bool Expand ( int increase_amount= ( MIDITrackChunkSize ) );
143     
144      MIDITimedBigMessage * GetEventAddress ( int event_num );
145     
146      const MIDITimedBigMessage * GetEventAddress ( int event_num ) const;
147     
148      const  MIDITimedBigMessage *GetEvent ( int event_num ) const;
149      MIDITimedBigMessage *GetEvent ( int event_num );
150      bool GetEvent ( int event_num, MIDITimedBigMessage *msg ) const;
151     
152      bool PutEvent ( const MIDITimedBigMessage &msg );
153      bool PutEvent ( const MIDITimedMessage &msg, MIDISystemExclusive *sysex );
154      bool SetEvent ( int event_num, const MIDITimedBigMessage &msg );
155     
156      bool MakeEventNoOp ( int event_num );
157     
158      bool FindEventNumber ( MIDIClockTime time, int *event_num ) const;
159     
160      int GetBufferSize() const;
161      int GetNumEvents() const;
162     
163    private:
164
165      const MIDITrack & operator = ( const MIDITrack &o );
166
167// void  QSort( int left, int right );
168
169      MIDITrackChunk * chunk[MIDIChunksPerTrack];
170     
171      int buf_size;
172      int num_events;
173  };
174 
175}
176
177#endif
Note: See TracBrowser for help on using the browser.