ScummVM API documentation
cpp_interface.h
1 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
2  * Copyright (C) 2011-2022 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MT32EMU_CPP_INTERFACE_H
19 #define MT32EMU_CPP_INTERFACE_H
20 
21 #include <cstdarg>
22 
23 #include "../globals.h"
24 #include "c_types.h"
25 
26 #include "../Types.h"
27 #include "../Enumerations.h"
28 
29 #if MT32EMU_API_TYPE == 2
30 
31 extern "C" {
32 
34 mt32emu_service_i mt32emu_get_service_i();
35 
36 }
37 
38 #define mt32emu_get_supported_report_handler_version i.v0->getSupportedReportHandlerVersionID
39 #define mt32emu_get_supported_midi_receiver_version i.v0->getSupportedMIDIReceiverVersionID
40 #define mt32emu_get_library_version_int i.v0->getLibraryVersionInt
41 #define mt32emu_get_library_version_string i.v0->getLibraryVersionString
42 #define mt32emu_get_stereo_output_samplerate i.v0->getStereoOutputSamplerate
43 #define mt32emu_get_best_analog_output_mode iV1()->getBestAnalogOutputMode
44 #define mt32emu_get_machine_ids iV4()->getMachineIDs
45 #define mt32emu_get_rom_ids iV4()->getROMIDs
46 #define mt32emu_identify_rom_data iV4()->identifyROMData
47 #define mt32emu_identify_rom_file iV4()->identifyROMFile
48 #define mt32emu_create_context i.v0->createContext
49 #define mt32emu_free_context i.v0->freeContext
50 #define mt32emu_add_rom_data i.v0->addROMData
51 #define mt32emu_add_rom_file i.v0->addROMFile
52 #define mt32emu_merge_and_add_rom_data iV4()->mergeAndAddROMData
53 #define mt32emu_merge_and_add_rom_files iV4()->mergeAndAddROMFiles
54 #define mt32emu_add_machine_rom_file iV4()->addMachineROMFile
55 #define mt32emu_get_rom_info i.v0->getROMInfo
56 #define mt32emu_set_partial_count i.v0->setPartialCount
57 #define mt32emu_set_analog_output_mode i.v0->setAnalogOutputMode
58 #define mt32emu_set_stereo_output_samplerate iV1()->setStereoOutputSampleRate
59 #define mt32emu_set_samplerate_conversion_quality iV1()->setSamplerateConversionQuality
60 #define mt32emu_select_renderer_type iV1()->selectRendererType
61 #define mt32emu_get_selected_renderer_type iV1()->getSelectedRendererType
62 #define mt32emu_open_synth i.v0->openSynth
63 #define mt32emu_close_synth i.v0->closeSynth
64 #define mt32emu_is_open i.v0->isOpen
65 #define mt32emu_get_actual_stereo_output_samplerate i.v0->getActualStereoOutputSamplerate
66 #define mt32emu_convert_output_to_synth_timestamp iV1()->convertOutputToSynthTimestamp
67 #define mt32emu_convert_synth_to_output_timestamp iV1()->convertSynthToOutputTimestamp
68 #define mt32emu_flush_midi_queue i.v0->flushMIDIQueue
69 #define mt32emu_set_midi_event_queue_size i.v0->setMIDIEventQueueSize
70 #define mt32emu_configure_midi_event_queue_sysex_storage iV3()->configureMIDIEventQueueSysexStorage
71 #define mt32emu_set_midi_receiver i.v0->setMIDIReceiver
72 #define mt32emu_get_internal_rendered_sample_count iV2()->getInternalRenderedSampleCount
73 #define mt32emu_parse_stream i.v0->parseStream
74 #define mt32emu_parse_stream_at i.v0->parseStream_At
75 #define mt32emu_play_short_message i.v0->playShortMessage
76 #define mt32emu_play_short_message_at i.v0->playShortMessageAt
77 #define mt32emu_play_msg i.v0->playMsg
78 #define mt32emu_play_sysex i.v0->playSysex
79 #define mt32emu_play_msg_at i.v0->playMsgAt
80 #define mt32emu_play_sysex_at i.v0->playSysexAt
81 #define mt32emu_play_msg_now i.v0->playMsgNow
82 #define mt32emu_play_msg_on_part i.v0->playMsgOnPart
83 #define mt32emu_play_sysex_now i.v0->playSysexNow
84 #define mt32emu_write_sysex i.v0->writeSysex
85 #define mt32emu_set_reverb_enabled i.v0->setReverbEnabled
86 #define mt32emu_is_reverb_enabled i.v0->isReverbEnabled
87 #define mt32emu_set_reverb_overridden i.v0->setReverbOverridden
88 #define mt32emu_is_reverb_overridden i.v0->isReverbOverridden
89 #define mt32emu_set_reverb_compatibility_mode i.v0->setReverbCompatibilityMode
90 #define mt32emu_is_mt32_reverb_compatibility_mode i.v0->isMT32ReverbCompatibilityMode
91 #define mt32emu_is_default_reverb_mt32_compatible i.v0->isDefaultReverbMT32Compatible
92 #define mt32emu_preallocate_reverb_memory iV3()->preallocateReverbMemory
93 #define mt32emu_set_dac_input_mode i.v0->setDACInputMode
94 #define mt32emu_get_dac_input_mode i.v0->getDACInputMode
95 #define mt32emu_set_midi_delay_mode i.v0->setMIDIDelayMode
96 #define mt32emu_get_midi_delay_mode i.v0->getMIDIDelayMode
97 #define mt32emu_set_output_gain i.v0->setOutputGain
98 #define mt32emu_get_output_gain i.v0->getOutputGain
99 #define mt32emu_set_reverb_output_gain i.v0->setReverbOutputGain
100 #define mt32emu_get_reverb_output_gain i.v0->getReverbOutputGain
101 #define mt32emu_set_part_volume_override iV5()->setPartVolumeOverride
102 #define mt32emu_get_part_volume_override iV5()->getPartVolumeOverride
103 #define mt32emu_set_reversed_stereo_enabled i.v0->setReversedStereoEnabled
104 #define mt32emu_is_reversed_stereo_enabled i.v0->isReversedStereoEnabled
105 #define mt32emu_set_nice_amp_ramp_enabled iV2()->setNiceAmpRampEnabled
106 #define mt32emu_is_nice_amp_ramp_enabled iV2()->isNiceAmpRampEnabled
107 #define mt32emu_set_nice_panning_enabled iV3()->setNicePanningEnabled
108 #define mt32emu_is_nice_panning_enabled iV3()->isNicePanningEnabled
109 #define mt32emu_set_nice_partial_mixing_enabled iV3()->setNicePartialMixingEnabled
110 #define mt32emu_is_nice_partial_mixing_enabled iV3()->isNicePartialMixingEnabled
111 #define mt32emu_render_bit16s i.v0->renderBit16s
112 #define mt32emu_render_float i.v0->renderFloat
113 #define mt32emu_render_bit16s_streams i.v0->renderBit16sStreams
114 #define mt32emu_render_float_streams i.v0->renderFloatStreams
115 #define mt32emu_has_active_partials i.v0->hasActivePartials
116 #define mt32emu_is_active i.v0->isActive
117 #define mt32emu_get_partial_count i.v0->getPartialCount
118 #define mt32emu_get_part_states i.v0->getPartStates
119 #define mt32emu_get_partial_states i.v0->getPartialStates
120 #define mt32emu_get_playing_notes i.v0->getPlayingNotes
121 #define mt32emu_get_patch_name i.v0->getPatchName
122 #define mt32emu_get_sound_group_name iV6()->getSoundGroupName
123 #define mt32emu_get_sound_name iV6()->getSoundName
124 #define mt32emu_read_memory i.v0->readMemory
125 #define mt32emu_get_display_state iV5()->getDisplayState
126 #define mt32emu_set_main_display_mode iV5()->setMainDisplayMode
127 #define mt32emu_set_display_compatibility iV5()->setDisplayCompatibility
128 #define mt32emu_is_display_old_mt32_compatible iV5()->isDisplayOldMT32Compatible
129 #define mt32emu_is_default_display_old_mt32_compatible iV5()->isDefaultDisplayOldMT32Compatible
130 
131 #else // #if MT32EMU_API_TYPE == 2
132 
133 #include "c_interface.h"
134 
135 #endif // #if MT32EMU_API_TYPE == 2
136 
137 namespace MT32Emu {
138 
139 namespace CppInterfaceImpl {
140 
141 static const mt32emu_report_handler_i NULL_REPORT_HANDLER = { NULL };
142 static mt32emu_report_handler_i getReportHandlerThunk(mt32emu_report_handler_version);
143 static mt32emu_midi_receiver_i getMidiReceiverThunk();
144 
145 }
146 
147 /*
148  * The classes below correspond to the interfaces defined in c_types.h and provided for convenience when using C++.
149  * The approach used makes no assumption of any internal class data memory layout, since the C++ standard does not
150  * provide any detail in this area and leaves it up to the implementation. Therefore, this way portability is guaranteed,
151  * despite the implementation may be a little inefficient.
152  * See c_types.h and c_interface.h for description of the corresponding interface methods.
153  */
154 
155 // Defines the interface for handling reported events (initial version).
156 // Corresponds to the mt32emu_report_handler_i_v0 interface.
158 public:
159  virtual void printDebug(const char *fmt, va_list list) = 0;
160  virtual void onErrorControlROM() = 0;
161  virtual void onErrorPCMROM() = 0;
162  virtual void showLCDMessage(const char *message) = 0;
163  virtual void onMIDIMessagePlayed() = 0;
164  virtual bool onMIDIQueueOverflow() = 0;
165  virtual void onMIDISystemRealtime(Bit8u system_realtime) = 0;
166  virtual void onDeviceReset() = 0;
167  virtual void onDeviceReconfig() = 0;
168  virtual void onNewReverbMode(Bit8u mode) = 0;
169  virtual void onNewReverbTime(Bit8u time) = 0;
170  virtual void onNewReverbLevel(Bit8u level) = 0;
171  virtual void onPolyStateChanged(Bit8u part_num) = 0;
172  virtual void onProgramChanged(Bit8u part_num, const char *sound_group_name, const char *patch_name) = 0;
173 
174 protected:
175  ~IReportHandler() {}
176 };
177 
178 // Extends IReportHandler, so that the client may supply callbacks for reporting signals about updated display state.
179 // Corresponds to the mt32emu_report_handler_i_v1 interface.
181 public:
182  virtual void onLCDStateUpdated() = 0;
183  virtual void onMidiMessageLEDStateUpdated(bool ledState) = 0;
184 
185 protected:
186  ~IReportHandlerV1() {}
187 };
188 
189 // Defines the interface for receiving MIDI messages generated by MIDI stream parser.
190 // Corresponds to the current version of mt32emu_midi_receiver_i interface.
192 public:
193  virtual void handleShortMessage(const Bit32u message) = 0;
194  virtual void handleSysex(const Bit8u stream[], const Bit32u length) = 0;
195  virtual void handleSystemRealtimeMessage(const Bit8u realtime) = 0;
196 
197 protected:
198  ~IMidiReceiver() {}
199 };
200 
201 // Defines all the library services.
202 // Corresponds to the current version of mt32emu_service_i interface.
203 class Service {
204 public:
205 #if MT32EMU_API_TYPE == 2
206  explicit Service(mt32emu_service_i interface, mt32emu_context context = NULL) : i(interface), c(context) {}
207 #else
208  explicit Service(mt32emu_context context = NULL) : c(context) {}
209 #endif
210  ~Service() { if (c != NULL) mt32emu_free_context(c); }
211 
212  // Context-independent methods
213 
214 #if MT32EMU_API_TYPE == 2
215  mt32emu_service_version getVersionID() { return i.v0->getVersionID(i); }
216 #endif
217  mt32emu_report_handler_version getSupportedReportHandlerVersionID() { return mt32emu_get_supported_report_handler_version(); }
218  mt32emu_midi_receiver_version getSupportedMIDIReceiverVersionID() { return mt32emu_get_supported_midi_receiver_version(); }
219 
220  Bit32u getLibraryVersionInt() { return mt32emu_get_library_version_int(); }
221  const char *getLibraryVersionString() { return mt32emu_get_library_version_string(); }
222 
223  Bit32u getStereoOutputSamplerate(const AnalogOutputMode analog_output_mode) { return mt32emu_get_stereo_output_samplerate(static_cast<mt32emu_analog_output_mode>(analog_output_mode)); }
224  AnalogOutputMode getBestAnalogOutputMode(const double target_samplerate) { return static_cast<AnalogOutputMode>(mt32emu_get_best_analog_output_mode(target_samplerate)); }
225 
226  size_t getMachineIDs(const char **machine_ids, size_t machine_ids_size) { return mt32emu_get_machine_ids(machine_ids, machine_ids_size); }
227  size_t getROMIDs(const char **rom_ids, size_t rom_ids_size, const char *machine_id) { return mt32emu_get_rom_ids(rom_ids, rom_ids_size, machine_id); }
228  mt32emu_return_code identifyROMData(mt32emu_rom_info *rom_info, const Bit8u *data, size_t data_size, const char *machine_id) { return mt32emu_identify_rom_data(rom_info, data, data_size, machine_id); }
229  mt32emu_return_code identifyROMFile(mt32emu_rom_info *rom_info, const char *filename, const char *machine_id) { return mt32emu_identify_rom_file(rom_info, filename, machine_id); }
230 
231  // Context-dependent methods
232 
233  mt32emu_context getContext() { return c; }
234  void createContext(mt32emu_report_handler_i report_handler = CppInterfaceImpl::NULL_REPORT_HANDLER, void *instance_data = NULL) { freeContext(); c = mt32emu_create_context(report_handler, instance_data); }
235  void createContext(IReportHandler &report_handler) { createContext(CppInterfaceImpl::getReportHandlerThunk(MT32EMU_REPORT_HANDLER_VERSION_0), &report_handler); }
236  void createContext(IReportHandlerV1 &report_handler) { createContext(CppInterfaceImpl::getReportHandlerThunk(MT32EMU_REPORT_HANDLER_VERSION_1), &report_handler); }
237  void freeContext() { if (c != NULL) { mt32emu_free_context(c); c = NULL; } }
238  mt32emu_return_code addROMData(const Bit8u *data, size_t data_size, const mt32emu_sha1_digest *sha1_digest = NULL) { return mt32emu_add_rom_data(c, data, data_size, sha1_digest); }
239  mt32emu_return_code addROMFile(const char *filename) { return mt32emu_add_rom_file(c, filename); }
240  mt32emu_return_code mergeAndAddROMData(const Bit8u *part1_data, size_t part1_data_size, const Bit8u *part2_data, size_t part2_data_size) { return mt32emu_merge_and_add_rom_data(c, part1_data, part1_data_size, NULL, part2_data, part2_data_size, NULL); }
241  mt32emu_return_code mergeAndAddROMData(const Bit8u *part1_data, size_t part1_data_size, const mt32emu_sha1_digest *part1_sha1_digest, const Bit8u *part2_data, size_t part2_data_size, const mt32emu_sha1_digest *part2_sha1_digest) { return mt32emu_merge_and_add_rom_data(c, part1_data, part1_data_size, part1_sha1_digest, part2_data, part2_data_size, part2_sha1_digest); }
242  mt32emu_return_code mergeAndAddROMFiles(const char *part1_filename, const char *part2_filename) { return mt32emu_merge_and_add_rom_files(c, part1_filename, part2_filename); }
243  mt32emu_return_code addMachineROMFile(const char *machine_id, const char *filename) { return mt32emu_add_machine_rom_file(c, machine_id, filename); }
244  void getROMInfo(mt32emu_rom_info *rom_info) { mt32emu_get_rom_info(c, rom_info); }
245  void setPartialCount(const Bit32u partial_count) { mt32emu_set_partial_count(c, partial_count); }
246  void setAnalogOutputMode(const AnalogOutputMode analog_output_mode) { mt32emu_set_analog_output_mode(c, static_cast<mt32emu_analog_output_mode>(analog_output_mode)); }
247  void setStereoOutputSampleRate(const double samplerate) { mt32emu_set_stereo_output_samplerate(c, samplerate); }
248  void setSamplerateConversionQuality(const SamplerateConversionQuality quality) { mt32emu_set_samplerate_conversion_quality(c, static_cast<mt32emu_samplerate_conversion_quality>(quality)); }
249  void selectRendererType(const RendererType newRendererType) { mt32emu_select_renderer_type(c, static_cast<mt32emu_renderer_type>(newRendererType)); }
250  RendererType getSelectedRendererType() { return static_cast<RendererType>(mt32emu_get_selected_renderer_type(c)); }
251  mt32emu_return_code openSynth() { return mt32emu_open_synth(c); }
252  void closeSynth() { mt32emu_close_synth(c); }
253  bool isOpen() { return mt32emu_is_open(c) != MT32EMU_BOOL_FALSE; }
254  Bit32u getActualStereoOutputSamplerate() { return mt32emu_get_actual_stereo_output_samplerate(c); }
255  Bit32u convertOutputToSynthTimestamp(Bit32u output_timestamp) { return mt32emu_convert_output_to_synth_timestamp(c, output_timestamp); }
256  Bit32u convertSynthToOutputTimestamp(Bit32u synth_timestamp) { return mt32emu_convert_synth_to_output_timestamp(c, synth_timestamp); }
257  void flushMIDIQueue() { mt32emu_flush_midi_queue(c); }
258  Bit32u setMIDIEventQueueSize(const Bit32u queue_size) { return mt32emu_set_midi_event_queue_size(c, queue_size); }
259  void configureMIDIEventQueueSysexStorage(const Bit32u storage_buffer_size) { mt32emu_configure_midi_event_queue_sysex_storage(c, storage_buffer_size); }
260  void setMIDIReceiver(mt32emu_midi_receiver_i midi_receiver, void *instance_data) { mt32emu_set_midi_receiver(c, midi_receiver, instance_data); }
261  void setMIDIReceiver(IMidiReceiver &midi_receiver) { setMIDIReceiver(CppInterfaceImpl::getMidiReceiverThunk(), &midi_receiver); }
262 
263  Bit32u getInternalRenderedSampleCount() { return mt32emu_get_internal_rendered_sample_count(c); }
264  void parseStream(const Bit8u *stream, Bit32u length) { mt32emu_parse_stream(c, stream, length); }
265  void parseStream_At(const Bit8u *stream, Bit32u length, Bit32u timestamp) { mt32emu_parse_stream_at(c, stream, length, timestamp); }
266  void playShortMessage(Bit32u message) { mt32emu_play_short_message(c, message); }
267  void playShortMessageAt(Bit32u message, Bit32u timestamp) { mt32emu_play_short_message_at(c, message, timestamp); }
268  mt32emu_return_code playMsg(Bit32u msg) { return mt32emu_play_msg(c, msg); }
269  mt32emu_return_code playSysex(const Bit8u *sysex, Bit32u len) { return mt32emu_play_sysex(c, sysex, len); }
270  mt32emu_return_code playMsgAt(Bit32u msg, Bit32u timestamp) { return mt32emu_play_msg_at(c, msg, timestamp); }
271  mt32emu_return_code playSysexAt(const Bit8u *sysex, Bit32u len, Bit32u timestamp) { return mt32emu_play_sysex_at(c, sysex, len, timestamp); }
272 
273  void playMsgNow(Bit32u msg) { mt32emu_play_msg_now(c, msg); }
274  void playMsgOnPart(Bit8u part, Bit8u code, Bit8u note, Bit8u velocity) { mt32emu_play_msg_on_part(c, part, code, note, velocity); }
275  void playSysexNow(const Bit8u *sysex, Bit32u len) { mt32emu_play_sysex_now(c, sysex, len); }
276  void writeSysex(Bit8u channel, const Bit8u *sysex, Bit32u len) { mt32emu_write_sysex(c, channel, sysex, len); }
277 
278  void setReverbEnabled(const bool reverb_enabled) { mt32emu_set_reverb_enabled(c, reverb_enabled ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE); }
279  bool isReverbEnabled() { return mt32emu_is_reverb_enabled(c) != MT32EMU_BOOL_FALSE; }
280  void setReverbOverridden(const bool reverb_overridden) { mt32emu_set_reverb_overridden(c, reverb_overridden ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE); }
281  bool isReverbOverridden() { return mt32emu_is_reverb_overridden(c) != MT32EMU_BOOL_FALSE; }
282  void setReverbCompatibilityMode(const bool mt32_compatible_mode) { mt32emu_set_reverb_compatibility_mode(c, mt32_compatible_mode ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE); }
283  bool isMT32ReverbCompatibilityMode() { return mt32emu_is_mt32_reverb_compatibility_mode(c) != MT32EMU_BOOL_FALSE; }
284  bool isDefaultReverbMT32Compatible() { return mt32emu_is_default_reverb_mt32_compatible(c) != MT32EMU_BOOL_FALSE; }
285  void preallocateReverbMemory(const bool enabled) { mt32emu_preallocate_reverb_memory(c, enabled ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE); }
286 
287  void setDACInputMode(const DACInputMode mode) { mt32emu_set_dac_input_mode(c, static_cast<mt32emu_dac_input_mode>(mode)); }
288  DACInputMode getDACInputMode() { return static_cast<DACInputMode>(mt32emu_get_dac_input_mode(c)); }
289 
290  void setMIDIDelayMode(const MIDIDelayMode mode) { mt32emu_set_midi_delay_mode(c, static_cast<mt32emu_midi_delay_mode>(mode)); }
291  MIDIDelayMode getMIDIDelayMode() { return static_cast<MIDIDelayMode>(mt32emu_get_midi_delay_mode(c)); }
292 
293  void setOutputGain(float gain) { mt32emu_set_output_gain(c, gain); }
294  float getOutputGain() { return mt32emu_get_output_gain(c); }
295  void setReverbOutputGain(float gain) { mt32emu_set_reverb_output_gain(c, gain); }
296  float getReverbOutputGain() { return mt32emu_get_reverb_output_gain(c); }
297 
298  void setPartVolumeOverride(Bit8u part_number, Bit8u volume_override) { mt32emu_set_part_volume_override(c, part_number, volume_override); }
299  Bit8u getPartVolumeOverride(Bit8u part_number) { return mt32emu_get_part_volume_override(c, part_number); }
300 
301  void setReversedStereoEnabled(const bool enabled) { mt32emu_set_reversed_stereo_enabled(c, enabled ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE); }
302  bool isReversedStereoEnabled() { return mt32emu_is_reversed_stereo_enabled(c) != MT32EMU_BOOL_FALSE; }
303 
304  void setNiceAmpRampEnabled(const bool enabled) { mt32emu_set_nice_amp_ramp_enabled(c, enabled ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE); }
305  bool isNiceAmpRampEnabled() { return mt32emu_is_nice_amp_ramp_enabled(c) != MT32EMU_BOOL_FALSE; }
306 
307  void setNicePanningEnabled(const bool enabled) { mt32emu_set_nice_panning_enabled(c, enabled ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE); }
308  bool isNicePanningEnabled() { return mt32emu_is_nice_panning_enabled(c) != MT32EMU_BOOL_FALSE; }
309 
310  void setNicePartialMixingEnabled(const bool enabled) { mt32emu_set_nice_partial_mixing_enabled(c, enabled ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE); }
311  bool isNicePartialMixingEnabled() { return mt32emu_is_nice_partial_mixing_enabled(c) != MT32EMU_BOOL_FALSE; }
312 
313  void renderBit16s(Bit16s *stream, Bit32u len) { mt32emu_render_bit16s(c, stream, len); }
314  void renderFloat(float *stream, Bit32u len) { mt32emu_render_float(c, stream, len); }
315  void renderBit16sStreams(const mt32emu_dac_output_bit16s_streams *streams, Bit32u len) { mt32emu_render_bit16s_streams(c, streams, len); }
316  void renderFloatStreams(const mt32emu_dac_output_float_streams *streams, Bit32u len) { mt32emu_render_float_streams(c, streams, len); }
317 
318  bool hasActivePartials() { return mt32emu_has_active_partials(c) != MT32EMU_BOOL_FALSE; }
319  bool isActive() { return mt32emu_is_active(c) != MT32EMU_BOOL_FALSE; }
320  Bit32u getPartialCount() { return mt32emu_get_partial_count(c); }
321  Bit32u getPartStates() { return mt32emu_get_part_states(c); }
322  void getPartialStates(Bit8u *partial_states) { mt32emu_get_partial_states(c, partial_states); }
323  Bit32u getPlayingNotes(Bit8u part_number, Bit8u *keys, Bit8u *velocities) { return mt32emu_get_playing_notes(c, part_number, keys, velocities); }
324  const char *getPatchName(Bit8u part_number) { return mt32emu_get_patch_name(c, part_number); }
325  bool getSoundGroupName(char *soundGroupName, Bit8u timbreGroup, Bit8u timbreNumber) { return mt32emu_get_sound_group_name(c, soundGroupName, timbreGroup, timbreNumber) != MT32EMU_BOOL_FALSE; }
326  bool getSoundName(char *soundName, Bit8u timbreGroup, Bit8u timbreNumber) { return mt32emu_get_sound_name(c, soundName, timbreGroup, timbreNumber) != MT32EMU_BOOL_FALSE; }
327  void readMemory(Bit32u addr, Bit32u len, Bit8u *data) { mt32emu_read_memory(c, addr, len, data); }
328 
329  bool getDisplayState(char *target_buffer, const bool narrow_lcd) { return mt32emu_get_display_state(c, target_buffer, narrow_lcd ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE) != MT32EMU_BOOL_FALSE; }
330  void setMainDisplayMode() { mt32emu_set_main_display_mode(c); }
331 
332  void setDisplayCompatibility(const bool oldMT32CompatibilityEnabled) { mt32emu_set_display_compatibility(c, oldMT32CompatibilityEnabled ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE); }
333  bool isDisplayOldMT32Compatible() { return mt32emu_is_display_old_mt32_compatible(c) != MT32EMU_BOOL_FALSE; }
334  bool isDefaultDisplayOldMT32Compatible() { return mt32emu_is_default_display_old_mt32_compatible(c) != MT32EMU_BOOL_FALSE; }
335 
336 private:
337 #if MT32EMU_API_TYPE == 2
338  const mt32emu_service_i i;
339 #endif
340  mt32emu_context c;
341 
342 #if MT32EMU_API_TYPE == 2
343  const mt32emu_service_i_v1 *iV1() { return (getVersionID() < MT32EMU_SERVICE_VERSION_1) ? NULL : i.v1; }
344  const mt32emu_service_i_v2 *iV2() { return (getVersionID() < MT32EMU_SERVICE_VERSION_2) ? NULL : i.v2; }
345  const mt32emu_service_i_v3 *iV3() { return (getVersionID() < MT32EMU_SERVICE_VERSION_3) ? NULL : i.v3; }
346  const mt32emu_service_i_v4 *iV4() { return (getVersionID() < MT32EMU_SERVICE_VERSION_4) ? NULL : i.v4; }
347  const mt32emu_service_i_v5 *iV5() { return (getVersionID() < MT32EMU_SERVICE_VERSION_5) ? NULL : i.v5; }
348  const mt32emu_service_i_v6 *iV6() { return (getVersionID() < MT32EMU_SERVICE_VERSION_6) ? NULL : i.v6; }
349 #endif
350 
351  Service(const Service &); // prevent copy-construction
352  Service& operator=(const Service &); // prevent assignment
353 };
354 
355 namespace CppInterfaceImpl {
356 
357 static mt32emu_report_handler_version MT32EMU_C_CALL getReportHandlerVersionID(mt32emu_report_handler_i);
358 
359 static void MT32EMU_C_CALL printDebug(void *instance_data, const char *fmt, va_list list) {
360  static_cast<IReportHandler *>(instance_data)->printDebug(fmt, list);
361 }
362 
363 static void MT32EMU_C_CALL onErrorControlROM(void *instance_data) {
364  static_cast<IReportHandler *>(instance_data)->onErrorControlROM();
365 }
366 
367 static void MT32EMU_C_CALL onErrorPCMROM(void *instance_data) {
368  static_cast<IReportHandler *>(instance_data)->onErrorPCMROM();
369 }
370 
371 static void MT32EMU_C_CALL showLCDMessage(void *instance_data, const char *message) {
372  static_cast<IReportHandler *>(instance_data)->showLCDMessage(message);
373 }
374 
375 static void MT32EMU_C_CALL onMIDIMessagePlayed(void *instance_data) {
376  static_cast<IReportHandler *>(instance_data)->onMIDIMessagePlayed();
377 }
378 
379 static mt32emu_boolean MT32EMU_C_CALL onMIDIQueueOverflow(void *instance_data) {
380  return static_cast<IReportHandler *>(instance_data)->onMIDIQueueOverflow() ? MT32EMU_BOOL_TRUE : MT32EMU_BOOL_FALSE;
381 }
382 
383 static void MT32EMU_C_CALL onMIDISystemRealtime(void *instance_data, mt32emu_bit8u system_realtime) {
384  static_cast<IReportHandler *>(instance_data)->onMIDISystemRealtime(system_realtime);
385 }
386 
387 static void MT32EMU_C_CALL onDeviceReset(void *instance_data) {
388  static_cast<IReportHandler *>(instance_data)->onDeviceReset();
389 }
390 
391 static void MT32EMU_C_CALL onDeviceReconfig(void *instance_data) {
392  static_cast<IReportHandler *>(instance_data)->onDeviceReconfig();
393 }
394 
395 static void MT32EMU_C_CALL onNewReverbMode(void *instance_data, mt32emu_bit8u mode) {
396  static_cast<IReportHandler *>(instance_data)->onNewReverbMode(mode);
397 }
398 
399 static void MT32EMU_C_CALL onNewReverbTime(void *instance_data, mt32emu_bit8u time) {
400  static_cast<IReportHandler *>(instance_data)->onNewReverbTime(time);
401 }
402 
403 static void MT32EMU_C_CALL onNewReverbLevel(void *instance_data, mt32emu_bit8u level) {
404  static_cast<IReportHandler *>(instance_data)->onNewReverbLevel(level);
405 }
406 
407 static void MT32EMU_C_CALL onPolyStateChanged(void *instance_data, mt32emu_bit8u part_num) {
408  static_cast<IReportHandler *>(instance_data)->onPolyStateChanged(part_num);
409 }
410 
411 static void MT32EMU_C_CALL onProgramChanged(void *instance_data, mt32emu_bit8u part_num, const char *sound_group_name, const char *patch_name) {
412  static_cast<IReportHandler *>(instance_data)->onProgramChanged(part_num, sound_group_name, patch_name);
413 }
414 
415 static void MT32EMU_C_CALL onLCDStateUpdated(void *instance_data) {
416  static_cast<IReportHandlerV1 *>(instance_data)->onLCDStateUpdated();
417 }
418 
419 static void MT32EMU_C_CALL onMidiMessageLEDStateUpdated(void *instance_data, mt32emu_boolean led_state) {
420  static_cast<IReportHandlerV1 *>(instance_data)->onMidiMessageLEDStateUpdated(led_state != MT32EMU_BOOL_FALSE);
421 }
422 
423 #define MT32EMU_REPORT_HANDLER_V0_THUNK \
424  getReportHandlerVersionID, \
425  printDebug, \
426  onErrorControlROM, \
427  onErrorPCMROM, \
428  showLCDMessage, \
429  onMIDIMessagePlayed, \
430  onMIDIQueueOverflow, \
431  onMIDISystemRealtime, \
432  onDeviceReset, \
433  onDeviceReconfig, \
434  onNewReverbMode, \
435  onNewReverbTime, \
436  onNewReverbLevel, \
437  onPolyStateChanged, \
438  onProgramChanged
439 
440 static const mt32emu_report_handler_i_v0 REPORT_HANDLER_V0_THUNK = {
441  MT32EMU_REPORT_HANDLER_V0_THUNK
442 };
443 
444 static const mt32emu_report_handler_i_v1 REPORT_HANDLER_V1_THUNK = {
445  MT32EMU_REPORT_HANDLER_V0_THUNK,
446  onLCDStateUpdated,
447  onMidiMessageLEDStateUpdated
448 };
449 
450 #undef MT32EMU_REPORT_HANDLER_THUNK_V0
451 
452 static mt32emu_report_handler_version MT32EMU_C_CALL getReportHandlerVersionID(mt32emu_report_handler_i thunk) {
453  if (thunk.v0 == &REPORT_HANDLER_V0_THUNK) return MT32EMU_REPORT_HANDLER_VERSION_0;
454  return MT32EMU_REPORT_HANDLER_VERSION_CURRENT;
455 }
456 
457 static mt32emu_report_handler_i getReportHandlerThunk(mt32emu_report_handler_version versionID) {
459  if (versionID == MT32EMU_REPORT_HANDLER_VERSION_0) thunk.v0 = &REPORT_HANDLER_V0_THUNK;
460  else thunk.v1 = &REPORT_HANDLER_V1_THUNK;
461  return thunk;
462 }
463 
464 static mt32emu_midi_receiver_version MT32EMU_C_CALL getMidiReceiverVersionID(mt32emu_midi_receiver_i) {
465  return MT32EMU_MIDI_RECEIVER_VERSION_CURRENT;
466 }
467 
468 static void MT32EMU_C_CALL handleShortMessage(void *instance_data, const mt32emu_bit32u message) {
469  static_cast<IMidiReceiver *>(instance_data)->handleShortMessage(message);
470 }
471 
472 static void MT32EMU_C_CALL handleSysex(void *instance_data, const mt32emu_bit8u stream[], const mt32emu_bit32u length) {
473  static_cast<IMidiReceiver *>(instance_data)->handleSysex(stream, length);
474 }
475 
476 static void MT32EMU_C_CALL handleSystemRealtimeMessage(void *instance_data, const mt32emu_bit8u realtime) {
477  static_cast<IMidiReceiver *>(instance_data)->handleSystemRealtimeMessage(realtime);
478 }
479 
480 static mt32emu_midi_receiver_i getMidiReceiverThunk() {
481  static const mt32emu_midi_receiver_i_v0 MIDI_RECEIVER_V0_THUNK = {
482  getMidiReceiverVersionID,
483  handleShortMessage,
484  handleSysex,
485  handleSystemRealtimeMessage
486  };
487 
488  static const mt32emu_midi_receiver_i MIDI_RECEIVER_THUNK = { &MIDI_RECEIVER_V0_THUNK };
489 
490  return MIDI_RECEIVER_THUNK;
491 }
492 
493 } // namespace CppInterfaceImpl
494 
495 } // namespace MT32Emu
496 
497 #if MT32EMU_API_TYPE == 2
498 
499 #undef mt32emu_get_supported_report_handler_version
500 #undef mt32emu_get_supported_midi_receiver_version
501 #undef mt32emu_get_library_version_int
502 #undef mt32emu_get_library_version_string
503 #undef mt32emu_get_stereo_output_samplerate
504 #undef mt32emu_get_best_analog_output_mode
505 #undef mt32emu_get_machine_ids
506 #undef mt32emu_get_rom_ids
507 #undef mt32emu_identify_rom_data
508 #undef mt32emu_identify_rom_file
509 #undef mt32emu_create_context
510 #undef mt32emu_free_context
511 #undef mt32emu_add_rom_data
512 #undef mt32emu_add_rom_file
513 #undef mt32emu_merge_and_add_rom_data
514 #undef mt32emu_merge_and_add_rom_files
515 #undef mt32emu_add_machine_rom_file
516 #undef mt32emu_get_rom_info
517 #undef mt32emu_set_partial_count
518 #undef mt32emu_set_analog_output_mode
519 #undef mt32emu_set_stereo_output_samplerate
520 #undef mt32emu_set_samplerate_conversion_quality
521 #undef mt32emu_select_renderer_type
522 #undef mt32emu_get_selected_renderer_type
523 #undef mt32emu_open_synth
524 #undef mt32emu_close_synth
525 #undef mt32emu_is_open
526 #undef mt32emu_get_actual_stereo_output_samplerate
527 #undef mt32emu_convert_output_to_synth_timestamp
528 #undef mt32emu_convert_synth_to_output_timestamp
529 #undef mt32emu_flush_midi_queue
530 #undef mt32emu_set_midi_event_queue_size
531 #undef mt32emu_configure_midi_event_queue_sysex_storage
532 #undef mt32emu_set_midi_receiver
533 #undef mt32emu_get_internal_rendered_sample_count
534 #undef mt32emu_parse_stream
535 #undef mt32emu_parse_stream_at
536 #undef mt32emu_play_short_message
537 #undef mt32emu_play_short_message_at
538 #undef mt32emu_play_msg
539 #undef mt32emu_play_sysex
540 #undef mt32emu_play_msg_at
541 #undef mt32emu_play_sysex_at
542 #undef mt32emu_play_msg_now
543 #undef mt32emu_play_msg_on_part
544 #undef mt32emu_play_sysex_now
545 #undef mt32emu_write_sysex
546 #undef mt32emu_set_reverb_enabled
547 #undef mt32emu_is_reverb_enabled
548 #undef mt32emu_set_reverb_overridden
549 #undef mt32emu_is_reverb_overridden
550 #undef mt32emu_set_reverb_compatibility_mode
551 #undef mt32emu_is_mt32_reverb_compatibility_mode
552 #undef mt32emu_is_default_reverb_mt32_compatible
553 #undef mt32emu_preallocate_reverb_memory
554 #undef mt32emu_set_dac_input_mode
555 #undef mt32emu_get_dac_input_mode
556 #undef mt32emu_set_midi_delay_mode
557 #undef mt32emu_get_midi_delay_mode
558 #undef mt32emu_set_output_gain
559 #undef mt32emu_get_output_gain
560 #undef mt32emu_set_reverb_output_gain
561 #undef mt32emu_get_reverb_output_gain
562 #undef mt32emu_set_reversed_stereo_enabled
563 #undef mt32emu_is_reversed_stereo_enabled
564 #undef mt32emu_set_nice_amp_ramp_enabled
565 #undef mt32emu_is_nice_amp_ramp_enabled
566 #undef mt32emu_set_nice_panning_enabled
567 #undef mt32emu_is_nice_panning_enabled
568 #undef mt32emu_set_nice_partial_mixing_enabled
569 #undef mt32emu_is_nice_partial_mixing_enabled
570 #undef mt32emu_render_bit16s
571 #undef mt32emu_render_float
572 #undef mt32emu_render_bit16s_streams
573 #undef mt32emu_render_float_streams
574 #undef mt32emu_has_active_partials
575 #undef mt32emu_is_active
576 #undef mt32emu_get_partial_count
577 #undef mt32emu_get_part_states
578 #undef mt32emu_get_partial_states
579 #undef mt32emu_get_playing_notes
580 #undef mt32emu_get_patch_name
581 #undef mt32emu_get_sound_group_name
582 #undef mt32emu_get_sound_name
583 #undef mt32emu_read_memory
584 #undef mt32emu_get_display_state
585 #undef mt32emu_set_main_display_mode
586 #undef mt32emu_set_display_compatibility
587 #undef mt32emu_is_display_old_mt32_compatible
588 #undef mt32emu_is_default_display_old_mt32_compatible
589 
590 #endif // #if MT32EMU_API_TYPE == 2
591 
592 #endif /* #ifndef MT32EMU_CPP_INTERFACE_H */
Definition: Analog.h:26
Definition: c_types.h:106
Definition: cpp_interface.h:191
Definition: c_types.h:377
Definition: c_types.h:86
Definition: c_types.h:191
Definition: c_types.h:388
Definition: c_types.h:382
Definition: cpp_interface.h:180
Definition: c_types.h:96
Definition: c_types.h:395
Definition: c_types.h:403
Definition: cpp_interface.h:203
Definition: c_types.h:205
Definition: c_types.h:427
Definition: c_types.h:218
Definition: c_types.h:195
Definition: c_types.h:412
Definition: cpp_interface.h:157
Definition: c_types.h:237