18 #ifndef MT32EMU_SYNTH_H 19 #define MT32EMU_SYNTH_H 27 #include "Enumerations.h" 43 class PatchTempMemoryRegion;
44 class RhythmTempMemoryRegion;
45 class TimbreTempMemoryRegion;
46 class PatchesMemoryRegion;
47 class TimbresMemoryRegion;
48 class SystemMemoryRegion;
49 class DisplayMemoryRegion;
50 class ResetMemoryRegion;
52 struct ControlROMFeatureSet;
57 const Bit8u SYSEX_MANUFACTURER_ROLAND = 0x41;
59 const Bit8u SYSEX_MDL_MT32 = 0x16;
60 const Bit8u SYSEX_MDL_D50 = 0x14;
62 const Bit8u SYSEX_CMD_RQ1 = 0x11;
63 const Bit8u SYSEX_CMD_DT1 = 0x12;
64 const Bit8u SYSEX_CMD_WSD = 0x40;
65 const Bit8u SYSEX_CMD_RQD = 0x41;
66 const Bit8u SYSEX_CMD_DAT = 0x42;
67 const Bit8u SYSEX_CMD_ACK = 0x43;
68 const Bit8u SYSEX_CMD_EOD = 0x45;
69 const Bit8u SYSEX_CMD_ERR = 0x4E;
70 const Bit8u SYSEX_CMD_RJC = 0x4F;
75 const Bit32u CONTROL_ROM_SIZE = 64 * 1024;
94 virtual void printDebug(
const char *fmt, va_list list);
96 virtual void onErrorControlROM() {}
97 virtual void onErrorPCMROM() {}
99 virtual void showLCDMessage(
const char *message);
101 virtual void onMIDIMessagePlayed() {}
104 virtual bool onMIDIQueueOverflow() {
return false; }
106 virtual void onMIDISystemRealtime(Bit8u ) {}
108 virtual void onDeviceReset() {}
109 virtual void onDeviceReconfig() {}
111 virtual void onNewReverbMode(Bit8u ) {}
112 virtual void onNewReverbTime(Bit8u ) {}
113 virtual void onNewReverbLevel(Bit8u ) {}
115 virtual void onPolyStateChanged(Bit8u ) {}
116 virtual void onProgramChanged(Bit8u ,
const char * ,
const char * ) {}
126 virtual void onLCDStateUpdated() {}
128 virtual void onMidiMessageLEDStateUpdated(
bool ) {}
139 friend class Renderer;
159 Bit8u *paddedTimbreMaxTable;
165 Bit8u controlROMData[CONTROL_ROM_SIZE];
169 Bit8u soundGroupIx[128];
170 const char (*soundGroupNames)[9];
176 volatile Bit32u lastReceivedMIDIEventTimestamp;
177 volatile Bit32u renderedSampleCount;
183 bool reverbOverridden;
185 MIDIDelayMode midiDelayMode;
186 DACInputMode dacInputMode;
189 float reverbOutputGain;
191 bool reversedStereoEnabled;
196 bool isDefaultReportHandler;
211 Extensions &extensions;
215 Bit32u addMIDIInterfaceDelay(Bit32u len, Bit32u timestamp);
216 bool isAbortingPoly()
const {
return abortingPoly != NULL; }
218 void writeSysexGlobal(Bit32u addr,
const Bit8u *sysex, Bit32u len);
219 void readSysex(Bit8u channel,
const Bit8u *sysex, Bit32u len)
const;
220 void initMemoryRegions();
221 void deleteMemoryRegions();
223 void writeMemoryRegion(
const MemoryRegion *region, Bit32u addr, Bit32u len,
const Bit8u *data);
224 void readMemoryRegion(
const MemoryRegion *region, Bit32u addr, Bit32u len, Bit8u *data);
226 bool loadControlROM(
const ROMImage &controlROMImage);
227 bool loadPCMROM(
const ROMImage &pcmROMImage);
229 bool initPCMList(Bit16u mapAddress, Bit16u count);
230 bool initTimbres(Bit16u mapAddress, Bit16u offset, Bit16u timbreCount, Bit16u startTimbre,
bool compressed);
231 bool initCompressedTimbre(Bit16u drumNum,
const Bit8u *mem, Bit32u memLen);
232 void initReverbModels(
bool mt32CompatibleMode);
233 void initSoundGroups(
char newSoundGroupNames[][9]);
235 void refreshSystemMasterTune();
236 void refreshSystemReverbParameters();
237 void refreshSystemReserveSettings();
238 void refreshSystemChanAssign(Bit8u firstPart, Bit8u lastPart);
239 void refreshSystemMasterVol();
240 void refreshSystem();
244 void printPartialUsage(Bit32u sampleOffset = 0);
246 void rhythmNotePlayed()
const;
247 void voicePartStateChanged(Bit8u partNum,
bool activated)
const;
248 void newTimbreSet(Bit8u partNum)
const;
249 const char *getSoundGroupName(
const Part *part)
const;
250 const char *getSoundGroupName(Bit8u timbreGroup, Bit8u timbreNumber)
const;
251 void printDebug(
const char *fmt, ...);
254 const Part *getPart(Bit8u partNum)
const;
256 void resetMasterTunePitchDelta();
257 Bit32s getMasterTunePitchDelta()
const;
260 static inline Bit16s clipSampleEx(Bit32s sampleEx) {
265 return ((-0x8000 <= sampleEx) && (sampleEx <= 0x7FFF)) ? Bit16s(sampleEx) : Bit16s((sampleEx >> 31) ^ 0x7FFF);
268 static inline float clipSampleEx(
float sampleEx) {
273 static inline void muteSampleBuffer(S *buffer, Bit32u len) {
274 if (buffer == NULL)
return;
275 memset(buffer, 0, len *
sizeof(S));
278 static inline void muteSampleBuffer(
float *buffer, Bit32u len) {
279 if (buffer == NULL)
return;
286 static inline Bit16s convertSample(
float sample) {
287 return Synth::clipSampleEx(Bit32s(sample * 32768.0f));
290 static inline float convertSample(Bit16s sample) {
291 return float(sample) / 32768.0f;
298 MT32EMU_EXPORT
static Bit32u getLibraryVersionInt();
300 MT32EMU_EXPORT
static const char *getLibraryVersionString();
302 MT32EMU_EXPORT
static Bit32u getShortMessageLength(Bit32u msg);
303 MT32EMU_EXPORT
static Bit8u calcSysexChecksum(
const Bit8u *data,
const Bit32u len,
const Bit8u initChecksum = 0);
307 MT32EMU_EXPORT
static Bit32u getStereoOutputSampleRate(AnalogOutputMode analogOutputMode);
311 MT32EMU_EXPORT ~Synth();
315 MT32EMU_EXPORT_V(2.6)
void setReportHandler2(
ReportHandler2 *reportHandler2);
322 MT32EMU_EXPORT
bool open(
const ROMImage &controlROMImage,
const ROMImage &pcmROMImage, Bit32u usePartialCount = DEFAULT_MAX_PARTIALS, AnalogOutputMode analogOutputMode = AnalogOutputMode_COARSE);
325 MT32EMU_EXPORT
bool open(
const ROMImage &controlROMImage,
const ROMImage &pcmROMImage, AnalogOutputMode analogOutputMode);
328 MT32EMU_EXPORT
void close();
331 MT32EMU_EXPORT
bool isOpen()
const;
334 MT32EMU_EXPORT
void flushMIDIQueue();
339 MT32EMU_EXPORT Bit32u setMIDIEventQueueSize(Bit32u requestedSize);
350 MT32EMU_EXPORT
void configureMIDIEventQueueSysexStorage(Bit32u storageBufferSize);
354 MT32EMU_EXPORT Bit32u getInternalRenderedSampleCount()
const;
365 MT32EMU_EXPORT
bool playMsg(Bit32u msg, Bit32u timestamp);
367 MT32EMU_EXPORT
bool playSysex(
const Bit8u *sysex, Bit32u len, Bit32u timestamp);
370 MT32EMU_EXPORT
bool playMsg(Bit32u msg);
372 MT32EMU_EXPORT
bool playSysex(
const Bit8u *sysex, Bit32u len);
381 MT32EMU_EXPORT
void playMsgNow(Bit32u msg);
384 MT32EMU_EXPORT
void playMsgOnPart(Bit8u part, Bit8u code, Bit8u note, Bit8u velocity);
388 MT32EMU_EXPORT
void playSysexNow(
const Bit8u *sysex, Bit32u len);
391 MT32EMU_EXPORT
void playSysexWithoutFraming(
const Bit8u *sysex, Bit32u len);
394 MT32EMU_EXPORT
void playSysexWithoutHeader(Bit8u device, Bit8u command,
const Bit8u *sysex, Bit32u len);
397 MT32EMU_EXPORT
void writeSysex(Bit8u channel,
const Bit8u *sysex, Bit32u len);
400 MT32EMU_EXPORT
void setReverbEnabled(
bool reverbEnabled);
402 MT32EMU_EXPORT
bool isReverbEnabled()
const;
406 MT32EMU_EXPORT
void setReverbOverridden(
bool reverbOverridden);
408 MT32EMU_EXPORT
bool isReverbOverridden()
const;
413 MT32EMU_EXPORT
void setReverbCompatibilityMode(
bool mt32CompatibleMode);
415 MT32EMU_EXPORT
bool isMT32ReverbCompatibilityMode()
const;
417 MT32EMU_EXPORT
bool isDefaultReverbMT32Compatible()
const;
421 MT32EMU_EXPORT
void preallocateReverbMemory(
bool enabled);
423 MT32EMU_EXPORT
void setDACInputMode(DACInputMode mode);
425 MT32EMU_EXPORT DACInputMode getDACInputMode()
const;
427 MT32EMU_EXPORT
void setMIDIDelayMode(MIDIDelayMode mode);
429 MT32EMU_EXPORT MIDIDelayMode getMIDIDelayMode()
const;
434 MT32EMU_EXPORT
void setOutputGain(
float gain);
436 MT32EMU_EXPORT
float getOutputGain()
const;
446 MT32EMU_EXPORT
void setReverbOutputGain(
float gain);
448 MT32EMU_EXPORT
float getReverbOutputGain()
const;
460 MT32EMU_EXPORT_V(2.6)
void setPartVolumeOverride(Bit8u partNumber, Bit8u volumeOverride);
464 MT32EMU_EXPORT_V(2.6) Bit8u getPartVolumeOverride(Bit8u partNumber)
const;
467 MT32EMU_EXPORT
void setReversedStereoEnabled(
bool enabled);
469 MT32EMU_EXPORT
bool isReversedStereoEnabled()
const;
477 MT32EMU_EXPORT
void setNiceAmpRampEnabled(
bool enabled);
479 MT32EMU_EXPORT
bool isNiceAmpRampEnabled()
const;
488 MT32EMU_EXPORT
void setNicePanningEnabled(
bool enabled);
490 MT32EMU_EXPORT
bool isNicePanningEnabled()
const;
500 MT32EMU_EXPORT
void setNicePartialMixingEnabled(
bool enabled);
502 MT32EMU_EXPORT
bool isNicePartialMixingEnabled()
const;
507 MT32EMU_EXPORT
void selectRendererType(RendererType);
510 MT32EMU_EXPORT RendererType getSelectedRendererType()
const;
514 MT32EMU_EXPORT Bit32u getStereoOutputSampleRate()
const;
521 MT32EMU_EXPORT
void render(Bit16s *stream, Bit32u len);
523 MT32EMU_EXPORT
void render(
float *stream, Bit32u len);
529 MT32EMU_EXPORT
void renderStreams(Bit16s *nonReverbLeft, Bit16s *nonReverbRight, Bit16s *reverbDryLeft, Bit16s *reverbDryRight, Bit16s *reverbWetLeft, Bit16s *reverbWetRight, Bit32u len);
532 MT32EMU_EXPORT
void renderStreams(
float *nonReverbLeft,
float *nonReverbRight,
float *reverbDryLeft,
float *reverbDryRight,
float *reverbWetLeft,
float *reverbWetRight, Bit32u len);
536 MT32EMU_EXPORT
bool hasActivePartials()
const;
541 MT32EMU_EXPORT
bool isActive();
544 MT32EMU_EXPORT Bit32u getPartialCount()
const;
549 MT32EMU_EXPORT
void getPartStates(
bool *partStates)
const;
554 MT32EMU_EXPORT Bit32u getPartStates()
const;
557 MT32EMU_EXPORT
void getPartialStates(PartialState *partialStates)
const;
562 MT32EMU_EXPORT
void getPartialStates(Bit8u *partialStates)
const;
568 MT32EMU_EXPORT Bit32u getPlayingNotes(Bit8u partNumber, Bit8u *keys, Bit8u *velocities)
const;
573 MT32EMU_EXPORT
const char *getPatchName(Bit8u partNumber)
const;
581 MT32EMU_EXPORT_V(2.7)
bool getSoundGroupName(
char *soundGroupName, Bit8u timbreGroup, Bit8u timbreNumber)
const;
588 MT32EMU_EXPORT_V(2.7)
bool getSoundName(
char *soundName, Bit8u timbreGroup, Bit8u timbreNumber)
const;
591 MT32EMU_EXPORT
void readMemory(Bit32u addr, Bit32u len, Bit8u *data);
602 MT32EMU_EXPORT_V(2.6)
bool getDisplayState(
char *targetBuffer,
bool narrowLCD =
false)
const;
607 MT32EMU_EXPORT_V(2.6)
void setMainDisplayMode();
613 MT32EMU_EXPORT_V(2.6)
void setDisplayCompatibility(
bool oldMT32CompatibilityEnabled);
615 MT32EMU_EXPORT_V(2.6)
bool isDisplayOldMT32Compatible()
const;
618 MT32EMU_EXPORT_V(2.6)
bool isDefaultDisplayOldMT32Compatible()
const;
623 #endif // #ifndef MT32EMU_SYNTH_H
Definition: Structures.h:132
Definition: MemoryRegion.h:127
Definition: Structures.h:186
Definition: SoxrAdapter.h:28
Definition: MemoryRegion.h:121
Definition: BReverbModel.h:28
Definition: Structures.h:238
Definition: MemoryRegion.h:105
Definition: PartialManager.h:32
Definition: SamplerateAdapter.h:28
Definition: MemoryRegion.h:109
Definition: MemoryRegion.h:97
Definition: MidiEventQueue.h:36
Definition: Structures.h:203
Definition: MemoryRegion.h:35
Definition: MemoryRegion.h:101
Definition: MidiStreamParser.h:104
Definition: MemoryRegion.h:113
Definition: MemoryRegion.h:117