ScummVM API documentation
cms.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 AGOS_DRIVERS_ACCOLADE_CMS_H
23#define AGOS_DRIVERS_ACCOLADE_CMS_H
24
25#include "audio/mididrv.h"
26
27#include "audio/cms.h"
28
29namespace AGOS {
30
31// MIDI driver for the Creative Music System / Gameblaster.
32// This driver uses only 6 of the available 12 channels and does not support
33// stereo. It only supports note on and off and program change; the selected
34// instrument only affects the note volume.
36protected:
37 static const byte REGISTER_BASE_AMPLITUDE = 0x00;
38 static const byte REGISTER_BASE_FREQUENCY = 0x08;
39 static const byte REGISTER_BASE_OCTAVE = 0x10;
40 static const byte REGISTER_FREQUENCY_ENABLE = 0x14;
41 static const byte REGISTER_RESET_SOUND_ENABLE = 0x1C;
42
43 // Frequency register values for octave notes.
44 static const byte CMS_NOTE_FREQUENCIES[12];
45 // Volume adjustments for all instruments.
46 static const byte CMS_VOLUME_ADJUSTMENTS[128];
47
48public:
50 ~MidiDriver_Accolade_Cms() override;
51
52 int open() override;
53 void close() override;
54 bool isOpen() const override;
55 uint32 getBaseTempo() override;
56 // This driver does not support MidiChannel objects.
57 MidiChannel *allocateChannel() override;
58 // This driver does not support MidiChannel objects.
59 MidiChannel *getPercussionChannel() override;
60
61 using MidiDriver::send;
62 void send(uint32 b) override;
63
64 void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) override;
65 void onTimer();
66
67protected:
68 void cmsInit();
69
70 void noteOff(uint8 channel, uint8 note);
71 void noteOn(uint8 channel, uint8 note, uint8 velocity);
72 void programChange(uint8 channel, uint8 instrument);
73 void controlChange(uint8 channel, uint8 controller, uint8 value);
74
75 // Returns the value for the frequency enable register of the first CMS
76 // chip based on the _activeNotes array (if a note is active, the bit for
77 // the corresponding channel is set).
78 byte determineFrequencyEnableRegisterValue();
79 void writeRegister(uint16 reg, uint8 value);
80
81 CMS::CMS *_cms;
82 bool _isOpen;
83
84 // The selected instrument on each MIDI channel.
85 byte _instruments[16];
86 // The active note on each CMS channel (0xFF if no note is active).
87 byte _activeNotes[12];
88 // The current values of the CMS octave registers (0x10 - 0x12).
89 byte _octaveRegisterValues[6];
90
91 // External timer callback
92 void *_timer_param;
94};
95
96} // End of namespace AGOS
97
98#endif
Definition: cms.h:35
bool isOpen() const override
void send(uint32 b) override
uint32 getBaseTempo() override
Definition: cms.h:39
void(* TimerProc)(void *refCon)
Definition: timer.h:42
Definition: mididrv.h:541
virtual void send(uint32 b)=0
Definition: mididrv.h:313