ScummVM API documentation
midiadlib.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 #include "audio/fmopl.h"
23 #include "audio/mididrv.h"
24 
25 namespace Queen {
26 
27 class AdLibMidiDriver : public MidiDriver {
28 public:
29 
30  AdLibMidiDriver() {
31  _adlibWaveformSelect = 0;
32  _isOpen = false;
33  }
34 
35  ~AdLibMidiDriver() override {}
36 
37  // MidiDriver
38  int open() override;
39  void close() override;
40  void send(uint32 b) override;
41  void metaEvent(byte type, byte *data, uint16 length) override;
42  MidiChannel *allocateChannel() override { return 0; }
43  MidiChannel *getPercussionChannel() override { return 0; }
44  void setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc) override;
45  bool isOpen() const override { return _isOpen; }
46  uint32 getBaseTempo() override { return 1000000 / OPL::OPL::kDefaultCallbackFrequency; }
47 
48  void setVolume(uint32 volume);
49 
50 private:
51 
52  void handleMidiEvent0x90_NoteOn(int channel, int param1, int param2);
53  void handleSequencerSpecificMetaEvent1(int channel, const uint8 *data);
54  void handleSequencerSpecificMetaEvent2(uint8 value);
55  void handleSequencerSpecificMetaEvent3(uint8 value);
56 
57  void adlibWrite(uint8 port, uint8 value);
58  void adlibSetupCard();
59  void adlibSetupChannels(int fl);
60  void adlibResetAmpVibratoRhythm(int am, int vib, int kso);
61  void adlibResetChannels();
62  void adlibSetAmpVibratoRhythm();
63  void adlibSetCSMKeyboardSplit();
64  void adlibSetNoteMul(int mul);
65  void adlibSetWaveformSelect(int fl);
66  void adlibSetPitchBend(int channel, int range);
67  void adlibPlayNote(int channel);
68  uint8 adlibPlayNoteHelper(int channel, int note1, int note2, int oct);
69  void adlibTurnNoteOff(int channel);
70  void adlibTurnNoteOn(int channel, int note);
71  void adlibSetupChannelFromSequence(int channel, const uint8 *src, int fl);
72  void adlibSetupChannel(int channel, const uint16 *src, int fl);
73  void adlibSetNoteVolume(int channel, int volume);
74  void adlibSetChannelVolume(int channel, uint8 volume);
75  void adlibSetupChannelHelper(int channel);
76  void adlibSetChannel0x40(int channel);
77  void adlibSetChannel0xC0(int channel);
78  void adlibSetChannel0x60(int channel);
79  void adlibSetChannel0x80(int channel);
80  void adlibSetChannel0x20(int channel);
81  void adlibSetChannel0xE0(int channel);
82 
83  void onTimer();
84 
85  OPL::OPL *_opl;
86  int _midiNumberOfChannels;
87  int _adlibNoteMul;
88  int _adlibWaveformSelect;
89  int _adlibAMDepthEq48;
90  int _adlibVibratoDepthEq14;
91  int _adlibRhythmEnabled;
92  int _adlibKeyboardSplitOn;
93  int _adlibVibratoRhythm;
94  uint8 _midiChannelsFreqTable[9];
95  uint8 _adlibChannelsLevelKeyScalingTable[11];
96  uint8 _adlibSetupChannelSequence1[14 * 18];
97  uint16 _adlibSetupChannelSequence2[14];
98  int16 _midiChannelsNote2Table[9];
99  uint8 _midiChannelsNote1Table[9];
100  uint8 _midiChannelsOctTable[9];
101  uint16 _adlibChannelsVolume[11];
102  uint16 _adlibMetaSequenceData[28];
103  uint8 _adlibChannelsVolumeTable[11];
104 
105  bool _isOpen;
106  Common::TimerManager::TimerProc _adlibTimerProc;
107  void *_adlibTimerParam;
108 
109  static const uint8 _adlibChannelsMappingTable1[];
110  static const uint8 _adlibChannelsNoFeedback[];
111  static const uint8 _adlibChannelsMappingTable2[];
112  static const uint8 _adlibChannelsMappingTable3[];
113  static const uint8 _adlibChannelsKeyScalingTable1[];
114  static const uint8 _adlibChannelsKeyScalingTable2[];
115  static const uint8 _adlibInitSequenceData1[];
116  static const uint8 _adlibInitSequenceData2[];
117  static const uint8 _adlibInitSequenceData3[];
118  static const uint8 _adlibInitSequenceData4[];
119  static const uint8 _adlibInitSequenceData5[];
120  static const uint8 _adlibInitSequenceData6[];
121  static const uint8 _adlibInitSequenceData7[];
122  static const uint8 _adlibInitSequenceData8[];
123  static const int16 _midiChannelsNoteTable[];
124  static const int16 _midiNoteFreqTable[];
125 };
126 
127 } // End of namespace Queen
void(* TimerProc)(void *refCon)
Definition: timer.h:42
void send(uint32 b) override
Definition: mididrv.h:309
void close() override
int open() override
Definition: bankman.h:28
Definition: midiadlib.h:27
bool isOpen() const override
Definition: midiadlib.h:45
Definition: mididrv.h:537
uint32 getBaseTempo() override
Definition: midiadlib.h:46
Definition: fmopl.h:115