ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 IMSMidi {
28 class IMuseChannel_Midi;
29 class IMuseChannel_MT32;
30 struct ChannelNode;
31 } // End of namespace IMSMidi
32 
33 namespace Scumm {
34 
35 class IMuseDriver_GMidi : public MidiDriver {
36  friend class IMSMidi::IMuseChannel_Midi;
37 public:
38  IMuseDriver_GMidi(MidiDriver::DeviceHandle dev, bool rolandGSMode, bool newSystem);
39  virtual ~IMuseDriver_GMidi() override;
40 
41  int open() override;
42  void close() override;
43 
44  // Just pass these through...
45  bool isOpen() const override { return _drv ? _drv->isOpen() : false; }
46  uint32 property(int prop, uint32 param) override { return _drv ? _drv->property(prop, param) : 0; }
47  void setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc) override { if (_drv) _drv->setTimerCallback(timerParam, timerProc); }
48  uint32 getBaseTempo() override { return _drv ? _drv->getBaseTempo() : 0; }
49  void send(uint32 b) override { if (_drv && trackMidiState(b)) _drv->send(b); };
50  void sysEx(const byte *msg, uint16 length) override { if (_drv) _drv->sysEx(msg, length); }
51  virtual void setPitchBendRange(byte channel, uint range) override { if (_drv) _drv->setPitchBendRange(channel, range); }
52 
53  // Channel allocation functions
54  MidiChannel *allocateChannel() override;
55  MidiChannel *getPercussionChannel() override;
56 
57 protected:
58  IMSMidi::IMuseChannel_Midi *getPart(int number);
59  virtual void createChannels();
60  virtual void createParts();
61  virtual void releaseChannels();
62 
63  MidiDriver *_drv;
64  const bool _newSystem;
65  byte _numChannels;
66  byte _numVoices;
67  IMSMidi::IMuseChannel_Midi **_imsParts;
68  bool _noProgramTracking;
69 
70 private:
71  virtual void initDevice();
72  void initRolandGSMode();
73  virtual void deinitDevice();
74 
75  void setNoteFlag(byte chan, byte note) { if (_notesPlaying && chan < 16 && note < 128) _notesPlaying[note] |= (1 << chan); }
76  void clearNoteFlag(byte chan, byte note) { if (_notesPlaying && chan < 16 && note < 128) _notesPlaying[note] &= ~(1 << chan); }
77  bool queryNoteFlag(byte chan, byte note) const { return (_notesPlaying && chan < 16 && note < 128) ? _notesPlaying[note] & (1 << chan) : false; }
78  void setSustainFlag(byte chan, byte note) { if (_notesSustained && chan < 16 && note < 128) _notesSustained[note] |= (1 << chan); }
79  void clearSustainFlag(byte chan, byte note) { if (_notesSustained && chan < 16 && note < 128) _notesSustained[note] &= ~(1 << chan); }
80  bool querySustainFlag(byte chan, byte note) const { return (_notesSustained && chan < 16 && note < 128) ? _notesSustained[note] & (1 << chan) : false; }
81 
82  bool trackMidiState(uint32 b);
83 
84  const bool _gsMode;
85 
86  IMSMidi::ChannelNode *_idleChain;
87  IMSMidi::ChannelNode *_activeChain;
88 
89  uint16 *_notesPlaying;
90  uint16 *_notesSustained;
91  byte *_midiRegState;
92 };
93 
94 class IMuseDriver_MT32 final : public IMuseDriver_GMidi {
95  friend class IMSMidi::IMuseChannel_MT32;
96 public:
97  IMuseDriver_MT32(MidiDriver::DeviceHandle dev, bool newSystem);
98  ~IMuseDriver_MT32() override {}
99 
100 private:
101  void initDevice() override;
102  void deinitDevice() override;
103  void createChannels() override;
104  void createParts() override;
105  void releaseChannels() override;
106 
107  // Convenience function that allows to send the sysex message with the exact same arguments as they are used in the original drivers.
108  void sendMT32Sysex(uint32 addr, const byte *data, uint32 dataSize);
109 
110  IMSMidi::ChannelNode *_hwRealChain;
111 
112  const byte *_programsMapping;
113 };
114 
115 } // End of namespace Scumm
116 
117 #endif
void send(uint32 b) override
Definition: midi.h:49
bool isOpen() const override
Definition: midi.h:45
uint32 DeviceHandle
Definition: mididrv.h:318
void(* TimerProc)(void *refCon)
Definition: timer.h:42
Definition: midi.h:94
Definition: mididrv.h:309
uint32 getBaseTempo() override
Definition: midi.h:48
Definition: mididrv.h:537
Definition: midi.h:27
void sysEx(const byte *msg, uint16 length) override
Definition: midi.h:50
Definition: midi.h:35
Definition: actor.h:30
uint32 property(int prop, uint32 param) override
Definition: midi.h:46