CLAM-Development  1.4.0
MIDITrack.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * MIDIFileReader C++ classes
20  * This code is part of the CLAM library, but also usable stand-alone.
21  * Maarten de Boer <mdeboer@iua.upf.es>
22  *
23  */
24 #ifndef __MIDITrack__
25 #define __MIDITrack__
26 
27 #include <list>
28 #include "MIDIEvent.hxx"
29 
30 namespace MIDI
31 {
32 
33  class Track
34  {
35  private:
36  /* a midi track consists of a list of midi event */
37  std::list<Event*> mEventList;
38 
39  /* and may have a name */
40  char* mName;
41 
42  public:
43  Track(void)
44  :mName(0)
45  {
46  }
47 
48  ~Track(void)
49  {
50  if (mName) delete mName;
51  }
52 
53  void Add(Event* e)
54  {
55  mEventList.push_back(e);
56  }
57 
58  void Name(const Byte* ptr, int len)
59  {
60  if (mName) delete mName;
61  mName = new char[len+1];
62  for (int i=0;i<len;i++) mName[i] = ptr[i];
63  mName[len] = 0;
64  }
65 
66 
67  /* iterator to traverse the list of events */
68  typedef std::list<Event*>::const_iterator EventIterator;
69 
70  EventIterator Begin(void) { return mEventList.begin(); }
71  EventIterator End(void) { return mEventList.end(); }
72 
73  bool HasTempoEvents(void)
74  {
75  EventIterator it = Begin();
76 
77  while (it!=End())
78  {
79  const Event &ev = **it;
80  if ( ev[0]==0xFF && ev[1]==0x51 ) return true;
81  it++;
82  }
83  return false;
84  }
85 
86  };
87 
88 }
89 
90 #endif
91