ScummVM API documentation
midi.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SCUMM_IMUSE_DRV_MIDI_H
23 #define SCUMM_IMUSE_DRV_MIDI_H
24 
25 #include "audio/mididrv.h"
26 
27 namespace Scumm {
28 
29 class IMuseChannel_Midi;
30 class IMuseChannel_MT32;
31 struct ChannelNode;
32 
33 class IMuseDriver_GMidi : public MidiDriver {
34  friend class IMuseChannel_Midi;
35 public:
36  IMuseDriver_GMidi(MidiDriver::DeviceHandle dev, bool rolandGSMode, bool newSystem);
37  virtual ~IMuseDriver_GMidi() override;
38 
39  int open() override;
40  void close() override;
41 
42  // Just pass these through...
43  bool isOpen() const override { return _drv ? _drv->isOpen() : false; }
44  uint32 property(int prop, uint32 param) override { return _drv ? _drv->property(prop, param) : 0; }
45  void setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc) override { if (_drv) _drv->setTimerCallback(timerParam, timerProc); }
46  uint32 getBaseTempo() override { return _drv ? _drv->getBaseTempo() : 0; }
47  void send(uint32 b) override { if (_drv) _drv->send(b); };
48  void sysEx(const byte *msg, uint16 length) override { if (_drv) _drv->sysEx(msg, length); }
49  virtual void setPitchBendRange(byte channel, uint range) override { if (_drv) _drv->setPitchBendRange(channel, range); }
50 
51  // Channel allocation functions
52  MidiChannel *allocateChannel() override;
53  MidiChannel *getPercussionChannel() override;
54 
55 protected:
56  IMuseChannel_Midi *getPart(int number);
57  virtual void createChannels();
58  virtual void createParts();
59  virtual void releaseChannels();
60 
61  MidiDriver *_drv;
62  const bool _newSystem;
63  byte _numChannels;
64  byte _numVoices;
65  IMuseChannel_Midi **_imsParts;
66 
67 private:
68  virtual void initDevice();
69  void initRolandGSMode();
70  virtual void deinitDevice();
71 
72  void setNoteFlag(byte chan, byte note) { if (_notesPlaying && chan < 16 && note < 128) _notesPlaying[note] |= (1 << chan); }
73  void clearNoteFlag(byte chan, byte note) { if (_notesPlaying && chan < 16 && note < 128) _notesPlaying[note] &= ~(1 << chan); }
74  bool queryNoteFlag(byte chan, byte note) const { return (_notesPlaying && chan < 16 && note < 128) ? _notesPlaying[note] & (1 << chan) : false; }
75  void setSustainFlag(byte chan, byte note) { if (_notesSustained && chan < 16 && note < 128) _notesSustained[note] |= (1 << chan); }
76  void clearSustainFlag(byte chan, byte note) { if (_notesSustained && chan < 16 && note < 128) _notesSustained[note] &= ~(1 << chan); }
77  bool querySustainFlag(byte chan, byte note) const { return (_notesSustained && chan < 16 && note < 128) ? _notesSustained[note] & (1 << chan) : false; }
78 
79  const bool _gsMode;
80 
81  ChannelNode *_idleChain;
82  ChannelNode *_activeChain;
83 
84  uint16 *_notesPlaying;
85  uint16 *_notesSustained;
86 };
87 
88 class IMuseDriver_MT32 final : public IMuseDriver_GMidi {
89  friend class IMuseChannel_MT32;
90 public:
91  IMuseDriver_MT32(MidiDriver::DeviceHandle dev, bool newSystem);
92  ~IMuseDriver_MT32() override {}
93 
94 private:
95  void initDevice() override;
96  void deinitDevice() override;
97  void createChannels() override;
98  void createParts() override;
99  void releaseChannels() override;
100 
101  // Convenience function that allows to send the sysex message with the exact same arguments as they are used in the original drivers.
102  void sendMT32Sysex(uint32 addr, const byte *data, uint32 dataSize);
103 
104  ChannelNode *_hwRealChain;
105 
106  const byte *_programsMapping;
107 };
108 
109 } // End of namespace Scumm
110 
111 #endif
void send(uint32 b) override
Definition: midi.h:47
virtual uint32 property(int prop, uint32 param)
Definition: mididrv.h:495
virtual uint32 getBaseTempo()=0
bool isOpen() const override
Definition: midi.h:43
uint32 DeviceHandle
Definition: mididrv.h:318
virtual bool isOpen() const =0
void(* TimerProc)(void *refCon)
Definition: timer.h:42
Definition: midi.h:88
Definition: mididrv.h:309
uint32 getBaseTempo() override
Definition: midi.h:46
Definition: mididrv.h:537
void close() override
void sysEx(const byte *msg, uint16 length) override
Definition: midi.h:48
virtual void sysEx(const byte *msg, uint16 length)
Definition: mididrv.h:216
Definition: midi.h:33
virtual void send(uint32 b)=0
Definition: actor.h:30
uint32 property(int prop, uint32 param) override
Definition: midi.h:44