Panda3D
 All Classes Functions Variables Enumerations
globalMilesManager.h
1 // Filename: globalMilesManager.h
2 // Created by: drose (26Jul07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef GLOBALMILESMANAGER_H
16 #define GLOBALMILESMANAGER_H
17 
18 #include "pandabase.h"
19 #ifdef HAVE_RAD_MSS //[
20 
21 #include "mss.h"
22 #include "pset.h"
23 #include "lightMutex.h"
24 #include "lightMutexHolder.h"
25 
26 #ifndef UINTa
27 #define UINTa U32
28 #endif
29 
30 #ifndef SINTa
31 #define SINTa S32
32 #endif
33 
34 class MilesAudioSample;
35 class MilesAudioSequence;
36 
37 ////////////////////////////////////////////////////////////////////
38 // Class : GlobalMilesManager
39 // Description : This is a wrapper around the parts of the Miles API
40 // that should only be created once. This represents
41 // the global data common to all MilesAudioManagers.
42 ////////////////////////////////////////////////////////////////////
43 class EXPCL_MILES_AUDIO GlobalMilesManager {
44 private:
45  GlobalMilesManager();
46 
47 public:
48  void add_manager(MilesAudioManager *manager);
49  void remove_manager(MilesAudioManager *manager);
50  void cleanup();
51  INLINE bool is_open() const;
52 
53  bool get_sample(HSAMPLE &sample, size_t &index, MilesAudioSample *sound);
54  void release_sample(size_t index, MilesAudioSample *sound);
55  INLINE int get_num_samples() const;
56 
57  bool get_sequence(HSEQUENCE &sequence, size_t &index, MilesAudioSequence *sound);
58  void release_sequence(size_t index, MilesAudioSequence *sound);
59  INLINE int get_num_sequences() const;
60 
61  void force_midi_reset();
62 
63  static GlobalMilesManager *get_global_ptr();
64 
65 public:
66  HDIGDRIVER _digital_driver;
67  HMDIDRIVER _midi_driver;
68 
69  // For software MIDI:
70  HDLSDEVICE _dls_device;
71  HDLSFILEID _dls_file;
72  pvector<unsigned char> _dls_data;
73 
74 private:
75  void open_api();
76  void close_api();
77 
78  static U32 AILCALLBACK open_callback(char const *filename, UINTa *file_handle);
79  static void AILCALLBACK close_callback(UINTa file_handle);
80  static S32 AILCALLBACK seek_callback(UINTa file_handle, S32 offset, U32 type);
81  static U32 AILCALLBACK read_callback(UINTa file_handle, void *buffer, U32 bytes);
82 
83 
84 private:
85  bool _is_open;
86 
87  typedef pset<MilesAudioManager *> Managers;
88  Managers _managers;
89  LightMutex _managers_lock;
90 
91  class SampleData {
92  public:
93  HSAMPLE _sample;
94  MilesAudioSample *_sound;
95  };
96 
97  typedef pvector<SampleData> Samples;
98  Samples _samples;
99  LightMutex _samples_lock;
100 
101  class SequenceData {
102  public:
103  HSEQUENCE _sequence;
104  MilesAudioSequence *_sound;
105  };
106 
107  typedef pvector<SequenceData> Sequences;
108  Sequences _sequences;
109  LightMutex _sequences_lock;
110 
111  static GlobalMilesManager *_global_ptr;
112 };
113 
114 #include "globalMilesManager.I"
115 
116 #endif //]
117 
118 #endif
119 
120 
121 
This is our own Panda specialization on the default STL set.
Definition: pset.h:52
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45