aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/adlmidi.h2
-rw-r--r--src/adlmidi.cpp11
-rw-r--r--src/adlmidi_bankmap.h2
-rw-r--r--src/adlmidi_load.cpp25
-rw-r--r--src/adlmidi_midiplay.cpp73
-rw-r--r--src/adlmidi_opl3.cpp59
-rw-r--r--src/adlmidi_private.cpp18
-rw-r--r--src/adlmidi_private.hpp50
-rw-r--r--src/cvt_mus2mid.hpp8
-rw-r--r--src/midi_sequencer_impl.hpp32
-rw-r--r--utils/midiplay/adlmidiplay.cpp4
11 files changed, 160 insertions, 124 deletions
diff --git a/include/adlmidi.h b/include/adlmidi.h
index 9b7a6d9..a1289a0 100644
--- a/include/adlmidi.h
+++ b/include/adlmidi.h
@@ -238,7 +238,7 @@ extern const char *adl_errorInfo(struct ADL_MIDIPlayer *device);
extern struct ADL_MIDIPlayer *adl_init(long sample_rate);
/*Set 4-bit device identifier*/
-extern int adl_setDeviceIdentifier(struct ADL_MIDIPlayer *device, ADL_UInt8 id);
+extern int adl_setDeviceIdentifier(struct ADL_MIDIPlayer *device, unsigned id);
/*Load MIDI file from File System*/
extern int adl_openFile(struct ADL_MIDIPlayer *device, const char *filePath);
diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp
index 1027aef..6ad554a 100644
--- a/src/adlmidi.cpp
+++ b/src/adlmidi.cpp
@@ -72,14 +72,14 @@ ADLMIDI_EXPORT struct ADL_MIDIPlayer *adl_init(long sample_rate)
return midi_device;
}
-ADLMIDI_EXPORT int adl_setDeviceIdentifier(ADL_MIDIPlayer *device, ADL_UInt8 id)
+ADLMIDI_EXPORT int adl_setDeviceIdentifier(ADL_MIDIPlayer *device, unsigned id)
{
if(!device || id > 0x0f)
return -1;
MidiPlayer *play = GET_MIDI_PLAYER(device);
if(!play)
return -1;
- play->setDeviceId(id);
+ play->setDeviceId(static_cast<uint8_t>(id));
return 0;
}
@@ -186,7 +186,7 @@ ADLMIDI_EXPORT int adl_getBank(ADL_MIDIPlayer *device, const ADL_BankId *idp, in
ADL_BankId id = *idp;
if(id.lsb > 127 || id.msb > 127 || id.percussive > 1)
return -1;
- uint16_t idnumber = uint16_t((id.msb << 8) | id.lsb | (id.percussive ? OPL3::PercussionTag : 0));
+ size_t idnumber = ((id.msb << 8) | id.lsb | (id.percussive ? size_t(OPL3::PercussionTag) : 0));
MidiPlayer *play = GET_MIDI_PLAYER(device);
OPL3::BankMap &map = play->m_synth.m_insBanks;
@@ -200,7 +200,7 @@ ADLMIDI_EXPORT int adl_getBank(ADL_MIDIPlayer *device, const ADL_BankId *idp, in
}
else
{
- std::pair<uint16_t, OPL3::Bank> value;
+ std::pair<size_t, OPL3::Bank> value;
value.first = idnumber;
memset(&value.second, 0, sizeof(value.second));
for (unsigned i = 0; i < 128; ++i)
@@ -228,7 +228,7 @@ ADLMIDI_EXPORT int adl_getBankId(ADL_MIDIPlayer *device, const ADL_Bank *bank, A
return -1;
OPL3::BankMap::iterator it = OPL3::BankMap::iterator::from_ptrs(bank->pointer);
- unsigned idnumber = it->first;
+ OPL3::BankMap::key_type idnumber = it->first;
id->msb = (idnumber >> 8) & 127;
id->lsb = idnumber & 127;
id->percussive = (idnumber & OPL3::PercussionTag) ? 1 : 0;
@@ -643,6 +643,7 @@ ADLMIDI_EXPORT void adl_reset(struct ADL_MIDIPlayer *device)
play->m_synth.reset(play->m_setup.emulator, play->m_setup.PCM_RATE, play);
play->m_chipChannels.clear();
play->m_chipChannels.resize((size_t)play->m_synth.m_numChannels);
+ play->resetMIDI();
}
ADLMIDI_EXPORT double adl_totalTimeLength(struct ADL_MIDIPlayer *device)
diff --git a/src/adlmidi_bankmap.h b/src/adlmidi_bankmap.h
index e4534cd..29643f1 100644
--- a/src/adlmidi_bankmap.h
+++ b/src/adlmidi_bankmap.h
@@ -40,7 +40,7 @@ template <class T>
class BasicBankMap
{
public:
- typedef uint16_t key_type; /* the bank identifier */
+ typedef size_t key_type; /* the bank identifier */
typedef T mapped_type;
typedef std::pair<key_type, T> value_type;
diff --git a/src/adlmidi_load.cpp b/src/adlmidi_load.cpp
index 43b74f2..f2a24a2 100644
--- a/src/adlmidi_load.cpp
+++ b/src/adlmidi_load.cpp
@@ -233,11 +233,9 @@ bool MIDIplay::LoadBank(FileAndMemReader &fr)
{
for(size_t i = 0; i < slots_counts[ss]; i++)
{
- uint16_t bankno = uint16_t(
- (slots_src_ins[ss][i].bank_midi_msb * 256) +
- slots_src_ins[ss][i].bank_midi_lsb +
- (ss ? OPL3::PercussionTag : 0)
- );
+ size_t bankno = (slots_src_ins[ss][i].bank_midi_msb * 256) +
+ (slots_src_ins[ss][i].bank_midi_lsb) +
+ (ss ? size_t(OPL3::PercussionTag) : 0);
OPL3::Bank &bank = m_synth.m_insBanks[bankno];
for(int j = 0; j < 128; j++)
{
@@ -249,7 +247,7 @@ bool MIDIplay::LoadBank(FileAndMemReader &fr)
}
}
- m_synth.m_embeddedBank = ~0u; // Use dynamic banks!
+ m_synth.m_embeddedBank = OPL3::CustomBankTag; // Use dynamic banks!
//Percussion offset is count of instruments multipled to count of melodic banks
applySetup();
@@ -263,19 +261,16 @@ bool MIDIplay::LoadBank(FileAndMemReader &fr)
bool MIDIplay::LoadMIDI_pre()
{
#ifdef DISABLE_EMBEDDED_BANKS
- if((m_synth.m_embeddedBank != ~0u) || m_synth.m_insBanks.empty())
+ if((m_synth.m_embeddedBank != CustomBankTag) || m_synth.m_insBanks.empty())
{
errorStringOut = "Bank is not set! Please load any instruments bank by using of adl_openBankFile() or adl_openBankData() functions!";
return false;
}
#endif
/**** Set all properties BEFORE starting of actial file reading! ****/
+ resetMIDI();
applySetup();
- caugh_missing_instruments.clear();
- caugh_missing_banks_melodic.clear();
- caugh_missing_banks_percussion.clear();
-
return true;
}
@@ -291,11 +286,11 @@ bool MIDIplay::LoadMIDI_post()
for(uint16_t i = 0; i < ins_count; ++i)
{
const uint8_t *InsData = instruments[i].data;
- uint16_t bank = i / 256;
- bank = uint16_t((bank & 127) + ((bank >> 7) << 8));
+ size_t bank = i / 256;
+ bank = ((bank & 127) + ((bank >> 7) << 8));
if(bank > 127 + (127 << 8))
break;
- bank += (i % 256 < 128) ? 0 : OPL3::PercussionTag;
+ bank += (i % 256 < 128) ? 0 : size_t(OPL3::PercussionTag);
/*std::printf("Ins %3u: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
i, InsData[0],InsData[1],InsData[2],InsData[3], InsData[4],InsData[5],InsData[6],InsData[7],
@@ -325,7 +320,7 @@ bool MIDIplay::LoadMIDI_post()
adlins.voice2_fine_tune = 0.0;
}
- m_synth.m_embeddedBank = ~0u; // Ignore AdlBank number, use dynamic banks instead
+ m_synth.m_embeddedBank = OPL3::CustomBankTag; // Ignore AdlBank number, use dynamic banks instead
//std::printf("CMF deltas %u ticks %u, basictempo = %u\n", deltas, ticks, basictempo);
m_synth.m_rhythmMode = true;
m_synth.m_musicMode = OPL3::MODE_CMF;
diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp
index 1969190..c4cac5d 100644
--- a/src/adlmidi_midiplay.cpp
+++ b/src/adlmidi_midiplay.cpp
@@ -25,7 +25,7 @@
// Mapping from MIDI volume level to OPL level value.
-static const uint8_t DMX_volume_mapping_table[128] =
+static const uint_fast32_t DMX_volume_mapping_table[128] =
{
0, 1, 3, 5, 6, 8, 10, 11,
13, 14, 16, 17, 19, 20, 22, 23,
@@ -45,7 +45,7 @@ static const uint8_t DMX_volume_mapping_table[128] =
124, 124, 125, 125, 126, 126, 127, 127,
};
-static const uint8_t W9X_volume_mapping_table[32] =
+static const uint_fast32_t W9X_volume_mapping_table[32] =
{
63, 63, 40, 36, 32, 28, 23, 21,
19, 17, 15, 14, 13, 12, 11, 10,
@@ -154,8 +154,8 @@ MIDIplay::MIDIplay(unsigned long sampleRate):
#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER
initSequencerInterface();
#endif
+ resetMIDI();
applySetup();
- chooseDevice("none");
realTime_ResetState();
}
@@ -168,7 +168,7 @@ void MIDIplay::applySetup()
m_synth.m_runAtPcmRate = m_setup.runAtPcmRate;
#ifndef DISABLE_EMBEDDED_BANKS
- if(m_synth.m_embeddedBank != ~0u)
+ if(m_synth.m_embeddedBank != OPL3::CustomBankTag)
m_synth.m_insBankSetup = adlbanksetup[m_setup.bankId];
#endif
@@ -205,6 +205,21 @@ void MIDIplay::applySetup()
m_arpeggioCounter = 0;
}
+void MIDIplay::resetMIDI()
+{
+ m_masterVolume = MasterVolumeDefault;
+ m_sysExDeviceId = 0;
+ m_synthMode = Mode_XG;
+ m_arpeggioCounter = 0;
+
+ m_midiChannels.clear();
+ m_midiChannels.resize(16, MIDIchannel());
+
+ caugh_missing_instruments.clear();
+ caugh_missing_banks_melodic.clear();
+ caugh_missing_banks_percussion.clear();
+}
+
void MIDIplay::TickIterators(double s)
{
for(uint16_t c = 0; c < m_synth.m_numChannels; ++c)
@@ -268,13 +283,13 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity)
size_t midiins = midiChan.patch;
bool isPercussion = (channel % 16 == 9) || midiChan.is_xg_percussion;
- uint16_t bank = 0;
+ size_t bank = 0;
if(midiChan.bank_msb || midiChan.bank_lsb)
{
if((m_synthMode & Mode_GS) != 0) //in GS mode ignore LSB
- bank = (uint16_t(midiChan.bank_msb) * 256);
+ bank = (midiChan.bank_msb * 256);
else
- bank = (uint16_t(midiChan.bank_msb) * 256) + uint16_t(midiChan.bank_lsb);
+ bank = (midiChan.bank_msb * 256) + midiChan.bank_lsb;
}
if(isPercussion)
@@ -290,11 +305,11 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity)
// Let XG Percussion bank will use (0...127 LSB range in WOPN file)
// Choose: SFX or Drum Kits
- bank = (uint16_t)midiins + ((bank == 0x7E00) ? 128 : 0);
+ bank = midiins + ((bank == 0x7E00) ? 128 : 0);
}
else
{
- bank = (uint16_t)midiins;
+ bank = midiins;
}
midiins = note; // Percussion instrument
}
@@ -316,8 +331,8 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity)
ains = &bnk->ins[midiins];
else if(hooks.onDebugMessage)
{
- std::set<uint16_t> &missing = (isPercussion) ?
- caugh_missing_banks_percussion : caugh_missing_banks_melodic;
+ std::set<size_t> &missing = (isPercussion) ?
+ caugh_missing_banks_percussion : caugh_missing_banks_melodic;
const char *text = (isPercussion) ?
"percussion" : "melodic";
if(missing.insert(bank).second)
@@ -335,7 +350,7 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity)
ains = &bnk->ins[midiins];
}
- int16_t tone = note;
+ int32_t tone = note;
if(!isPercussion && (bank > 0)) // For non-zero banks
{
if(ains->flags & adlinsdata::Flag_NoSound)
@@ -413,9 +428,9 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity)
if(voices[0].ains == voices[1].ains || pseudo_4op/*i[0] == i[1] || pseudo_4op*/)
{
// Only use regular channels
- uint8_t expected_mode = 0;
+ uint32_t expected_mode = 0;
- if(m_synth.m_rhythmMode == 1)
+ if(m_synth.m_rhythmMode)
{
if(m_cmfPercussionMode)
expected_mode = channel < 11 ? 0 : (3 + channel - 11); // CMF
@@ -431,7 +446,7 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity)
if(ccount == 0)
{
// Only use four-op master channels
- if(m_synth.m_channelCategory[a] != 1)
+ if(m_synth.m_channelCategory[a] != OPL3::ChanCat_4op_Master)
continue;
}
else
@@ -480,7 +495,7 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity)
ir = midiChan.activenotes_insert(note);
ir.first->vol = velocity;
ir.first->vibrato = midiChan.noteAftertouch[note];
- ir.first->noteTone = tone;
+ ir.first->noteTone = static_cast<int16_t>(tone);
ir.first->currentTone = tone;
ir.first->glideRate = HUGE_VAL;
ir.first->midiins = midiins;
@@ -576,12 +591,12 @@ void MIDIplay::realTime_Controller(uint8_t channel, uint8_t type, uint8_t value)
break;
case 5: // Set portamento msb
- m_midiChannels[channel].portamento = static_cast<uint16_t>((m_midiChannels[channel].portamento & 0x7F) | (value << 7));
+ m_midiChannels[channel].portamento = static_cast<uint16_t>((m_midiChannels[channel].portamento & 0x007F) | (value << 7));
updatePortamento(channel);
break;
case 37: // Set portamento lsb
- m_midiChannels[channel].portamento = (m_midiChannels[channel].portamento & 0x3F80) | (value);
+ m_midiChannels[channel].portamento = static_cast<uint16_t>((m_midiChannels[channel].portamento & 0x3F80) | (value));
updatePortamento(channel);
break;
@@ -811,7 +826,7 @@ bool MIDIplay::doUniversalSysEx(unsigned dev, bool realtime, const uint8_t *data
unsigned volume =
(((unsigned)data[0] & 0x7F)) |
(((unsigned)data[1] & 0x7F) << 7);
- m_masterVolume = volume >> 7;
+ m_masterVolume = static_cast<uint8_t>(volume >> 7);
for(size_t ch = 0; ch < m_midiChannels.size(); ch++)
noteUpdateAll(uint16_t(ch), Upd_Volume);
return true;
@@ -981,6 +996,8 @@ void MIDIplay::realTime_deviceSwitch(size_t track, const char *data, size_t leng
uint64_t MIDIplay::realTime_currentDevice(size_t track)
{
+ if(m_currentMidiDevice.empty())
+ return 0;
return m_currentMidiDevice[track];
}
@@ -1104,9 +1121,9 @@ void MIDIplay::noteUpdate(size_t midCh,
if(props_mask & Upd_Volume)
{
- uint32_t volume;
+ uint_fast32_t volume;
bool is_percussion = (midCh == 9) || m_midiChannels[midCh].is_xg_percussion;
- uint8_t brightness = is_percussion ? 127 : m_midiChannels[midCh].brightness;
+ uint_fast32_t brightness = is_percussion ? 127 : m_midiChannels[midCh].brightness;
if(!m_setup.fullRangeBrightnessCC74)
{
@@ -1134,7 +1151,7 @@ void MIDIplay::noteUpdate(size_t midCh,
//volume = (int)(volume * std::sqrt( (double) ch[c].users.size() ));
// The formula below: SOLVE(V=127^4 * 2^( (A-63.49999) / 8), A)
- volume = volume > (8725 * 127) ? static_cast<uint32_t>(std::log(static_cast<double>(volume)) * 11.541560327111707 - 1.601379199767093e+02) : 0;
+ volume = volume > (8725 * 127) ? static_cast<uint_fast32_t>(std::log(static_cast<double>(volume)) * 11.541560327111707 - 1.601379199767093e+02) : 0;
// The incorrect formula below: SOLVE(V=127^4 * (2^(A/63)-1), A)
//opl.Touch_Real(c, volume>(11210*127) ? 91.61112 * std::log((4.8819E-7/127)*volume + 1.0)+0.5 : 0);
}
@@ -1173,7 +1190,7 @@ void MIDIplay::noteUpdate(size_t midCh,
break;
}
- m_synth.touchNote(c, volume, brightness);
+ m_synth.touchNote(c, static_cast<uint8_t>(volume), static_cast<uint8_t>(brightness));
/* DEBUG ONLY!!!
static uint32_t max = 0;
@@ -1435,7 +1452,7 @@ void MIDIplay::panic()
}
}
-void MIDIplay::killSustainingNotes(int32_t midCh, int32_t this_adlchn, uint8_t sustain_type)
+void MIDIplay::killSustainingNotes(int32_t midCh, int32_t this_adlchn, uint32_t sustain_type)
{
uint32_t first = 0, last = m_synth.m_numChannels;
@@ -1734,11 +1751,11 @@ ADLMIDI_EXPORT void AdlInstrumentTester::Touch(unsigned c, unsigned volume) // V
#ifndef DISABLE_EMBEDDED_BANKS
OPL3 *opl = P->opl;
if(opl->m_volumeScale == OPL3::VOLUME_NATIVE)
- opl->touchNote(c, volume * 127 / (127 * 127 * 127) / 2);
+ opl->touchNote(c, static_cast<uint8_t>(volume * 127 / (127 * 127 * 127) / 2));
else
{
// The formula below: SOLVE(V=127^3 * 2^( (A-63.49999) / 8), A)
- opl->touchNote(c, volume > 8725 ? static_cast<unsigned int>(std::log((double)volume) * 11.541561 + (0.5 - 104.22845)) : 0);
+ opl->touchNote(c, static_cast<uint8_t>(volume > 8725 ? static_cast<unsigned int>(std::log((double)volume) * 11.541561 + (0.5 - 104.22845)) : 0));
// The incorrect formula below: SOLVE(V=127^3 * (2^(A/63)-1), A)
//Touch_Real(c, volume>11210 ? 91.61112 * std::log(4.8819E-7*volume + 1.0)+0.5 : 0);
}
@@ -1821,7 +1838,7 @@ ADLMIDI_EXPORT void AdlInstrumentTester::NextAdl(int offset)
//OPL3 *opl = P->opl;
if(P->adl_ins_list.empty()) FindAdlList();
const unsigned NumBanks = (unsigned)adl_getBanksCount();
- P->ins_idx = (uint32_t)((int32_t)P->ins_idx + (int32_t)P->adl_ins_list.size() + offset) % P->adl_ins_list.size();
+ P->ins_idx = (uint32_t)((int32_t)P->ins_idx + (int32_t)P->adl_ins_list.size() + offset) % (int32_t)P->adl_ins_list.size();
#if 0
UI.Color(15);
@@ -1834,7 +1851,7 @@ ADLMIDI_EXPORT void AdlInstrumentTester::NextAdl(int offset)
std::fflush(stderr);
#endif
- for(unsigned a = 0, n = P->adl_ins_list.size(); a < n; ++a)
+ for(size_t a = 0, n = P->adl_ins_list.size(); a < n; ++a)
{
const unsigned i = P->adl_ins_list[a];
const adlinsdata2 ains(adlins[i]);
diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp
index 2a8aaa9..3e33e86 100644
--- a/src/adlmidi_opl3.cpp
+++ b/src/adlmidi_opl3.cpp
@@ -126,7 +126,7 @@ OPL3::OPL3() :
m_volumeScale(VOLUME_Generic)
{
#ifdef DISABLE_EMBEDDED_BANKS
- m_embeddedBank = ~0u;
+ m_embeddedBank = CustomBankTag;
#else
setEmbeddedBank(0);
#endif
@@ -161,7 +161,7 @@ void OPL3::setEmbeddedBank(uint32_t bank)
void OPL3::writeReg(size_t chip, uint16_t address, uint8_t value)
{
- #ifdef ADLMIDI_HW_OPL
+#ifdef ADLMIDI_HW_OPL
ADL_UNUSED(chip);
unsigned o = address >> 8;
unsigned port = OPLBase + o * 2;
@@ -180,9 +180,18 @@ void OPL3::writeReg(size_t chip, uint16_t address, uint8_t value)
for(uint16_t c = 0; c < 35; ++c) inp(port);
#endif//__WATCOMC__
- #else//ADLMIDI_HW_OPL
+#else//ADLMIDI_HW_OPL
m_chips[chip]->writeReg(address, value);
- #endif
+#endif
+}
+
+void OPL3::writeRegI(size_t chip, uint32_t address, uint32_t value)
+{
+#ifdef ADLMIDI_HW_OPL
+ writeReg(chip, static_cast<uint16_t>(address), static_cast<uint8_t>(value));
+#else//ADLMIDI_HW_OPL
+ m_chips[chip]->writeReg(static_cast<uint16_t>(address), static_cast<uint8_t>(value));
+#endif
}
@@ -193,11 +202,11 @@ void OPL3::noteOff(size_t c)
if(cc >= 18)
{
m_regBD[chip] &= ~(0x10 >> (cc - 18));
- writeReg(chip, 0xBD, m_regBD[chip]);
+ writeRegI(chip, 0xBD, m_regBD[chip]);
return;
}
- writeReg(chip, 0xB0 + g_channelsMap[cc], m_keyBlockFNumCache[c] & 0xDF);
+ writeRegI(chip, 0xB0 + g_channelsMap[cc], m_keyBlockFNumCache[c] & 0xDF);
}
void OPL3::noteOn(size_t c, double hertz) // Hertz range: 0..131071
@@ -220,16 +229,16 @@ void OPL3::noteOn(size_t c, double hertz) // Hertz range: 0..131071
if(cc >= 18)
{
m_regBD[chip ] |= (0x10 >> (cc - 18));
- writeReg(chip , 0x0BD, m_regBD[chip ]);
+ writeRegI(chip , 0x0BD, m_regBD[chip ]);
x &= ~0x2000u;
//x |= 0x800; // for test
}
if(chn != 0xFFF)
{
- writeReg(chip , 0xA0 + chn, static_cast<uint8_t>(x & 0xFF));
- writeReg(chip , 0xB0 + chn, static_cast<uint8_t>(x >> 8));
- m_keyBlockFNumCache[c] = static_cast<uint8_t>(x >> 8);
+ writeRegI(chip , 0xA0 + chn, (x & 0xFF));
+ writeRegI(chip , 0xB0 + chn, (x >> 8));
+ m_keyBlockFNumCache[c] = (x >> 8);
}
}
@@ -243,7 +252,7 @@ void OPL3::touchNote(size_t c, uint8_t volume, uint8_t brightness)
uint16_t o1 = g_operatorsMap[cc * 2 + 0];
uint16_t o2 = g_operatorsMap[cc * 2 + 1];
uint8_t x = adli.modulator_40, y = adli.carrier_40;
- uint16_t mode = 1; // 2-op AM
+ uint32_t mode = 1; // 2-op AM
if(m_channelCategory[c] == 0 || m_channelCategory[c] == 3)
{
@@ -285,9 +294,9 @@ void OPL3::touchNote(size_t c, uint8_t volume, uint8_t brightness)
if(m_musicMode == MODE_RSXX)
{
- writeReg(chip, 0x40 + o1, x);
+ writeRegI(chip, 0x40 + o1, x);
if(o2 != 0xFFF)
- writeReg(chip, 0x40 + o2, y - volume / 2);
+ writeRegI(chip, 0x40 + o2, y - volume / 2);
}
else
{
@@ -306,9 +315,9 @@ void OPL3::touchNote(size_t c, uint8_t volume, uint8_t brightness)
carrier = (carrier | 63) - brightness + brightness * (carrier & 63) / 63;
}
- writeReg(chip, 0x40 + o1, modulator);
+ writeRegI(chip, 0x40 + o1, modulator);
if(o2 != 0xFFF)
- writeReg(chip, 0x40 + o2, carrier);
+ writeRegI(chip, 0x40 + o2, carrier);
}
// Correct formula (ST3, AdPlug):
@@ -342,11 +351,11 @@ void OPL3::setPatch(size_t c, const adldata &instrument)
uint16_t o2 = g_operatorsMap[cc * 2 + 1];
unsigned x = instrument.modulator_E862, y = instrument.carrier_E862;
- for(unsigned a = 0; a < 4; ++a, x >>= 8, y >>= 8)
+ for(size_t a = 0; a < 4; ++a, x >>= 8, y >>= 8)
{
- writeReg(chip, data[a] + o1, x & 0xFF);
+ writeRegI(chip, data[a] + o1, x & 0xFF);
if(o2 != 0xFFF)
- writeReg(chip, data[a] + o2, y & 0xFF);
+ writeRegI(chip, data[a] + o2, y & 0xFF);
}
}
@@ -354,7 +363,7 @@ void OPL3::setPan(size_t c, uint8_t value)
{
size_t chip = c / 23, cc = c % 23;
if(g_channelsMap[cc] != 0xFFF)
- writeReg(chip, 0xC0 + g_channelsMap[cc], m_insCache[c].feedconn | value);
+ writeRegI(chip, 0xC0 + g_channelsMap[cc], m_insCache[c].feedconn | value);
}
void OPL3::silenceAll() // Silence all OPL channels.
@@ -373,9 +382,9 @@ void OPL3::updateChannelCategories()
for(size_t chip = 0; chip < m_numChips; ++chip)
{
m_regBD[chip] = (m_deepTremoloMode * 0x80 + m_deepVibratoMode * 0x40 + m_rhythmMode * 0x20);
- writeReg(chip, 0x0BD, m_regBD[chip]);
- uint8_t fours_this_chip = std::min(fours, static_cast<uint32_t>(6u));
- writeReg(chip, 0x104, (1 << fours_this_chip) - 1);
+ writeRegI(chip, 0x0BD, m_regBD[chip]);
+ uint32_t fours_this_chip = std::min(fours, static_cast<uint32_t>(6u));
+ writeRegI(chip, 0x104, (1 << fours_this_chip) - 1);
fours -= fours_this_chip;
}
@@ -449,7 +458,7 @@ void OPL3::commitDeepFlags()
for(size_t chip = 0; chip < m_numChips; ++chip)
{
m_regBD[chip] = (m_deepTremoloMode * 0x80 + m_deepVibratoMode * 0x40 + m_rhythmMode * 0x20);
- writeReg(chip, 0x0BD, m_regBD[chip]);
+ writeRegI(chip, 0x0BD, m_regBD[chip]);
}
}
@@ -566,9 +575,9 @@ void OPL3::reset(int emulator, unsigned long PCM_RATE, void *audioTickHandler)
/* Clean-up channels from any playing junk sounds */
for(size_t a = 0; a < 18; ++a)
- writeReg(i, 0xB0 + g_channelsMap[a], 0x00);
+ writeRegI(i, 0xB0 + g_channelsMap[a], 0x00);
for(size_t a = 0; a < sizeof(data) / sizeof(*data); a += 2)
- writeReg(i, data[a], static_cast<uint8_t>(data[a + 1]));
+ writeRegI(i, data[a], (data[a + 1]));
}
updateChannelCategories();
diff --git a/src/adlmidi_private.cpp b/src/adlmidi_private.cpp
index 8d7b9a7..8e7d260 100644
--- a/src/adlmidi_private.cpp
+++ b/src/adlmidi_private.cpp
@@ -36,12 +36,12 @@ void adl_audioTickHandler(void *instance, uint32_t chipId, uint32_t rate)
int adlRefreshNumCards(ADL_MIDIPlayer *device)
{
- unsigned n_fourop[2] = {0, 0}, n_total[2] = {0, 0};
+ size_t n_fourop[2] = {0, 0}, n_total[2] = {0, 0};
MIDIplay *play = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer);
//Automatically calculate how much 4-operator channels is necessary
#ifndef DISABLE_EMBEDDED_BANKS
- if(play->m_synth.m_embeddedBank == ~0u)
+ if(play->m_synth.m_embeddedBank == OPL3::CustomBankTag)
#endif
{
//For custom bank
@@ -49,9 +49,9 @@ int adlRefreshNumCards(ADL_MIDIPlayer *device)
OPL3::BankMap::iterator end = play->m_synth.m_insBanks.end();
for(; it != end; ++it)
{
- uint16_t bank = it->first;
- unsigned div = (bank & OPL3::PercussionTag) ? 1 : 0;
- for(unsigned i = 0; i < 128; ++i)
+ size_t bank = it->first;
+ size_t div = (bank & OPL3::PercussionTag) ? 1 : 0;
+ for(size_t i = 0; i < 128; ++i)
{
adlinsdata2 &ins = it->second.ins[i];
if(ins.flags & adlinsdata::Flag_NoSound)
@@ -66,9 +66,9 @@ int adlRefreshNumCards(ADL_MIDIPlayer *device)
else
{
//For embedded bank
- for(unsigned a = 0; a < 256; ++a)
+ for(size_t a = 0; a < 256; ++a)
{
- unsigned insno = banks[play->m_setup.bankId][a];
+ size_t insno = banks[play->m_setup.bankId][a];
if(insno == 198)
continue;
++n_total[a / 128];
@@ -79,7 +79,7 @@ int adlRefreshNumCards(ADL_MIDIPlayer *device)
}
#endif
- unsigned numFourOps = 0;
+ size_t numFourOps = 0;
// All 2ops (no 4ops)
if((n_fourop[0] == 0) && (n_fourop[1] == 0))
@@ -100,7 +100,7 @@ int adlRefreshNumCards(ADL_MIDIPlayer *device)
: (play->m_setup.NumCards == 1 ? 1 : play->m_setup.NumCards * 4);
*/
- play->m_synth.m_numFourOps = play->m_setup.numFourOps = (numFourOps * play->m_setup.numChips);
+ play->m_synth.m_numFourOps = play->m_setup.numFourOps = static_cast<unsigned>(numFourOps * play->m_setup.numChips);
return 0;
}
diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp
index 83eb151..a7374f7 100644
--- a/src/adlmidi_private.hpp
+++ b/src/adlmidi_private.hpp
@@ -169,7 +169,7 @@ extern std::string ADLMIDI_ErrorString;
template <class Real>
inline Real adl_cvtReal(int32_t x)
{
- return x * ((Real)1 / INT16_MAX);
+ return static_cast<Real>(x) * (static_cast<Real>(1) / static_cast<Real>(INT16_MAX));
}
inline int32_t adl_cvtS16(int32_t x)
@@ -220,12 +220,16 @@ class OPL3
friend class AdlInstrumentTester;
friend int adlRefreshNumCards(ADL_MIDIPlayer *device);
public:
- enum { PercussionTag = 1 << 15 };
+ enum
+ {
+ PercussionTag = 1 << 15,
+ CustomBankTag = 0xFFFFFFFF
+ };
//! Total number of chip channels between all running emulators
uint32_t m_numChannels;
//! Just a padding. Reserved.
- char ____padding[4];
+ char _padding[4];
#ifndef ADLMIDI_HW_OPL
//! Running chip emulators
std::vector<AdlMIDI_SPtr<OPLChipBase > > m_chips;
@@ -237,9 +241,9 @@ private:
//! Value written to B0, cached, needed by NoteOff.
/*! Contains Key on/off state, octave block and frequency number values
*/
- std::vector<uint8_t> m_keyBlockFNumCache;
+ std::vector<uint32_t> m_keyBlockFNumCache;
//! Cached BD registry value (flags register: DeepTremolo, DeepVibrato, and RhythmMode)
- std::vector<uint8_t> m_regBD;
+ std::vector<uint32_t> m_regBD;
public:
/**
@@ -261,7 +265,7 @@ public:
static const adlinsdata2 m_emptyInstrument;
//! Total number of running concurrent emulated chips
uint32_t m_numChips;
- //! Currently running embedded bank number. "~0" means usign of the custom bank.
+ //! Currently running embedded bank number. "CustomBankTag" means usign of the custom bank.
uint32_t m_embeddedBank;
//! Total number of needed four-operator channels in all running chips
uint32_t m_numFourOps;
@@ -277,7 +281,7 @@ public:
bool m_runAtPcmRate;
//! Just a padding. Reserved.
- char ___padding2[3];
+ char _padding2[3];
/**
* @brief Music playing mode
@@ -312,7 +316,7 @@ public:
} m_volumeScale;
//! Reserved
- char ____padding3[8];
+ char _padding3[8];
/**
* @brief Channel categiry enumeration
@@ -348,7 +352,7 @@ public:
7 = percussion Hihat
8 = percussion slave
*/
- std::vector<char> m_channelCategory;
+ std::vector<uint32_t> m_channelCategory;
/**
@@ -371,6 +375,14 @@ public:
void writeReg(size_t chip, uint16_t address, uint8_t value);
/**
+ * @brief Write data to OPL3 chip register
+ * @param chip Index of emulated chip. In hardware OPL3 builds, this parameter is ignored
+ * @param index Register address to write
+ * @param value Value to write
+ */
+ void writeRegI(size_t chip, uint32_t address, uint32_t value);
+
+ /**
* @brief Off the note in specified chip channel
* @param c Channel of chip (Emulated chip choosing by next formula: [c = ch + (chipId * 23)])
*/
@@ -478,6 +490,8 @@ public:
void applySetup();
+ void resetMIDI();
+
/**********************Internal structures and classes**********************/
/**
@@ -518,7 +532,7 @@ public:
//! Is note aftertouch has any non-zero value
bool noteAfterTouchInUse;
//! Reserved
- char ____padding[6];
+ char _padding[6];
//! Pitch bend value
int bend;
//! Pitch bend sensitivity
@@ -650,7 +664,7 @@ public:
};
//! Reserved
- char ____padding2[5];
+ char _padding2[5];
//! Count of gliding notes in this channel
unsigned gliding_note_count;
@@ -832,8 +846,8 @@ public:
Sustain_Sostenuto = 0x02,
Sustain_ANY = Sustain_Pedal | Sustain_Sostenuto,
};
- uint8_t sustained;
- char ____padding[6];
+ uint32_t sustained;
+ char _padding[6];
MIDIchannel::NoteInfo::Phys ins; // a copy of that in phys[]
//! Has fixed sustain, don't iterate "on" timeout
bool fixed_sustain;
@@ -986,7 +1000,7 @@ private:
std::map<uint64_t /*track*/, uint64_t /*channel begin index*/> m_currentMidiDevice;
//! Padding to fix CLanc code model's warning
- char ____padding[7];
+ char _padding[7];
//! Chip channels map
std::vector<AdlChannel> m_chipChannels;
@@ -1002,11 +1016,11 @@ private:
std::string errorStringOut;
//! Missing instruments catches
- std::set<uint8_t> caugh_missing_instruments;
+ std::set<size_t> caugh_missing_instruments;
//! Missing melodic banks catches
- std::set<uint16_t> caugh_missing_banks_melodic;
+ std::set<size_t> caugh_missing_banks_melodic;
//! Missing percussion banks catches
- std::set<uint16_t> caugh_missing_banks_percussion;
+ std::set<size_t> caugh_missing_banks_percussion;
public:
@@ -1357,7 +1371,7 @@ private:
*/
void killSustainingNotes(int32_t midCh = -1,
int32_t this_adlchn = -1,
- uint8_t sustain_type = AdlChannel::LocationData::Sustain_ANY);
+ uint32_t sustain_type = AdlChannel::LocationData::Sustain_ANY);
/**
* @brief Find active notes and mark them as sostenuto-sustained
* @param MidCh MIDI channel, -1 - all MIDI channels
diff --git a/src/cvt_mus2mid.hpp b/src/cvt_mus2mid.hpp
index 5a465c2..b5096c6 100644
--- a/src/cvt_mus2mid.hpp
+++ b/src/cvt_mus2mid.hpp
@@ -167,10 +167,10 @@ static void mus2mid_write4(struct mus_ctx *ctx, uint32_t val)
{
if (ctx->dstrem < 4)
mus2mid_resize_dst(ctx);
- *ctx->dst_ptr++ = (val>>24)&0xff;
- *ctx->dst_ptr++ = (val>>16)&0xff;
- *ctx->dst_ptr++ = (val>>8) & 0xff;
- *ctx->dst_ptr++ = val & 0xff;
+ *ctx->dst_ptr++ = (uint8_t)((val>>24)&0xff);
+ *ctx->dst_ptr++ = (uint8_t)((val>>16)&0xff);
+ *ctx->dst_ptr++ = (uint8_t)((val>>8) & 0xff);
+ *ctx->dst_ptr++ = (uint8_t)((val & 0xff));
ctx->dstrem -= 4;
}
diff --git a/src/midi_sequencer_impl.hpp b/src/midi_sequencer_impl.hpp
index a253852..273e63f 100644
--- a/src/midi_sequencer_impl.hpp
+++ b/src/midi_sequencer_impl.hpp
@@ -687,7 +687,7 @@ bool BW_MidiSequencer::buildTrackData(const std::vector<std::vector<uint8_t> > &
bool isOn;
char ___pad[7];
} drNotes[255];
- uint16_t banks[16];
+ size_t banks[16];
for(size_t tk = 0; tk < trackCount; ++tk)
{
@@ -713,10 +713,10 @@ bool BW_MidiSequencer::buildTrackData(const std::vector<std::vector<uint8_t> > &
switch(ctrlno)
{
case 0: // Set bank msb (GM bank)
- banks[et->channel] = uint16_t(uint16_t(value) << 8) | uint16_t(banks[et->channel] & 0x00FF);
+ banks[et->channel] = (value << 8) | (banks[et->channel] & 0x00FF);
break;
case 32: // Set bank lsb (XG bank)
- banks[et->channel] = (banks[et->channel] & 0xFF00) | (uint16_t(value) & 0x00FF);
+ banks[et->channel] = (banks[et->channel] & 0xFF00) | (value & 0x00FF);
break;
}
continue;
@@ -1007,7 +1007,7 @@ BW_MidiSequencer::MidiEvent BW_MidiSequencer::parseEvent(const uint8_t **pptr, c
for(size_t i = 0; i < data.size(); i++)
{
if(data[i] <= 'Z' && data[i] >= 'A')
- data[i] = data[i] - ('Z' - 'z');
+ data[i] = static_cast<char>(data[i] - ('Z' - 'z'));
}
if(data == "loopstart")
@@ -1219,9 +1219,9 @@ void BW_MidiSequencer::handleEvent(size_t track, const BW_MidiSequencer::MidiEve
/*UI.PrintLn("@%X Track %u: %02X %02X",
CurrentPosition.track[track].ptr-1, (unsigned)track, byte,
TrackData[track][CurrentPosition.track[track].ptr]);*/
- uint8_t midCh = evt.channel;//byte & 0x0F, EvType = byte >> 4;
+ size_t midCh = evt.channel;//byte & 0x0F, EvType = byte >> 4;
if(m_interface->rt_currentDevice)
- midCh += (uint8_t)m_interface->rt_currentDevice(m_interface->rtUserData, track);
+ midCh += m_interface->rt_currentDevice(m_interface->rtUserData, track);
status = evt.type;
switch(evt.type)
@@ -1229,7 +1229,7 @@ void BW_MidiSequencer::handleEvent(size_t track, const BW_MidiSequencer::MidiEve
case MidiEvent::T_NOTEOFF: // Note off
{
uint8_t note = evt.data[0];
- m_interface->rt_noteOff(m_interface->rtUserData, midCh, note);
+ m_interface->rt_noteOff(m_interface->rtUserData, static_cast<uint8_t>(midCh), note);
break;
}
@@ -1237,7 +1237,7 @@ void BW_MidiSequencer::handleEvent(size_t track, const BW_MidiSequencer::MidiEve
{
uint8_t note = evt.data[0];
uint8_t vol = evt.data[1];
- m_interface->rt_noteOn(m_interface->rtUserData, midCh, note, vol);
+ m_interface->rt_noteOn(m_interface->rtUserData, static_cast<uint8_t>(midCh), note, vol);
break;
}
@@ -1245,7 +1245,7 @@ void BW_MidiSequencer::handleEvent(size_t track, const BW_MidiSequencer::MidiEve
{
uint8_t note = evt.data[0];
uint8_t vol = evt.data[1];
- m_interface->rt_noteAfterTouch(m_interface->rtUserData, midCh, note, vol);
+ m_interface->rt_noteAfterTouch(m_interface->rtUserData, static_cast<uint8_t>(midCh), note, vol);
break;
}
@@ -1253,20 +1253,20 @@ void BW_MidiSequencer::handleEvent(size_t track, const BW_MidiSequencer::MidiEve
{
uint8_t ctrlno = evt.data[0];
uint8_t value = evt.data[1];
- m_interface->rt_controllerChange(m_interface->rtUserData, midCh, ctrlno, value);
+ m_interface->rt_controllerChange(m_interface->rtUserData, static_cast<uint8_t>(midCh), ctrlno, value);
break;
}
case MidiEvent::T_PATCHCHANGE: // Patch change
{
- m_interface->rt_patchChange(m_interface->rtUserData, midCh, evt.data[0]);
+ m_interface->rt_patchChange(m_interface->rtUserData, static_cast<uint8_t>(midCh), evt.data[0]);
break;
}
case MidiEvent::T_CHANAFTTOUCH: // Channel after-touch
{
uint8_t chanat = evt.data[0];
- m_interface->rt_channelAfterTouch(m_interface->rtUserData, midCh, chanat);
+ m_interface->rt_channelAfterTouch(m_interface->rtUserData, static_cast<uint8_t>(midCh), chanat);
break;
}
@@ -1274,7 +1274,7 @@ void BW_MidiSequencer::handleEvent(size_t track, const BW_MidiSequencer::MidiEve
{
uint8_t a = evt.data[0];
uint8_t b = evt.data[1];
- m_interface->rt_pitchBend(m_interface->rtUserData, midCh, b, a);
+ m_interface->rt_pitchBend(m_interface->rtUserData, static_cast<uint8_t>(midCh), b, a);
break;
}
}//switch
@@ -1768,10 +1768,10 @@ riffskip:
rawTrackData[tk].insert(rawTrackData[tk].end(), special_event_buf, special_event_buf + 5);
//if(delay>>21) TrackData[tk].push_back( 0x80 | ((delay>>21) & 0x7F ) );
if(delay >> 14)
- rawTrackData[tk].push_back(0x80 | ((delay >> 14) & 0x7F));
+ rawTrackData[tk].push_back(static_cast<uint8_t>(0x80 | ((delay >> 14) & 0x7F)));
if(delay >> 7)
- rawTrackData[tk].push_back(0x80 | ((delay >> 7) & 0x7F));
- rawTrackData[tk].push_back(((delay >> 0) & 0x7F));
+ rawTrackData[tk].push_back(static_cast<uint8_t>(0x80 | ((delay >> 7) & 0x7F)));
+ rawTrackData[tk].push_back(static_cast<uint8_t>(((delay >> 0) & 0x7F)));
}
rawTrackData[tk].insert(rawTrackData[tk].end(), EndTag + 0, EndTag + 4);
diff --git a/utils/midiplay/adlmidiplay.cpp b/utils/midiplay/adlmidiplay.cpp
index 2bcdd1d..78b1235 100644
--- a/utils/midiplay/adlmidiplay.cpp
+++ b/utils/midiplay/adlmidiplay.cpp
@@ -210,7 +210,7 @@ static inline void secondsToHMSM(double seconds_full, char *hmsm_buffer, size_t
double seconds_integral;
double seconds_fractional = std::modf(seconds_full, &seconds_integral);
unsigned int milliseconds = static_cast<unsigned int>(std::floor(seconds_fractional * 1000.0));
- unsigned int seconds = std::fmod(seconds_full, 60.0);
+ unsigned int seconds = static_cast<unsigned int>(std::fmod(seconds_full, 60.0));
unsigned int minutes = static_cast<unsigned int>(std::floor(seconds_full / 60));
unsigned int hours = static_cast<unsigned int>(std::floor(seconds_full / 3600));
std::memset(hmsm_buffer, 0, hmsm_buffer_size);
@@ -657,7 +657,7 @@ int main(int argc, char **argv)
g_audioBuffer_lock.Unlock();
const SDL_AudioSpec &spec = obtained;
- while(g_audioBuffer.size() > spec.samples + (spec.freq * g_audioFormat.sampleOffset) * OurHeadRoomLength)
+ while(g_audioBuffer.size() > static_cast<size_t>(spec.samples + (spec.freq * g_audioFormat.sampleOffset) * OurHeadRoomLength))
{
SDL_Delay(1);
}