aboutsummaryrefslogtreecommitdiff
path: root/src/adlmidi_midiplay.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/adlmidi_midiplay.cpp')
-rw-r--r--src/adlmidi_midiplay.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp
index ea46f16..69db6b0 100644
--- a/src/adlmidi_midiplay.cpp
+++ b/src/adlmidi_midiplay.cpp
@@ -110,6 +110,11 @@ static const uint8_t PercussionMap[256] =
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+inline bool isXgPercChannel(uint8_t msb, uint8_t lsb)
+{
+ return (msb == 0x7E || msb == 0x7F) && (lsb == 0);
+}
+
void MIDIplay::AdlChannel::AddAge(int64_t ms)
{
if(users.empty())
@@ -908,6 +913,7 @@ void MIDIplay::realTime_ResetState()
chan.lastlrpn = 0;
chan.lastmrpn = 0;
chan.nrpn = false;
+ chan.brightness = 127;
NoteUpdate_All(uint16_t(ch), Upd_All);
NoteUpdate_All(uint16_t(ch), Upd_Off);
}
@@ -1194,10 +1200,12 @@ void MIDIplay::realTime_Controller(uint8_t channel, uint8_t type, uint8_t value)
case 0: // Set bank msb (GM bank)
Ch[channel].bank_msb = value;
+ Ch[channel].is_xg_percussion = isXgPercChannel(Ch[channel].bank_msb, Ch[channel].bank_lsb);
break;
case 32: // Set bank lsb (XG bank)
Ch[channel].bank_lsb = value;
+ Ch[channel].is_xg_percussion = isXgPercChannel(Ch[channel].bank_msb, Ch[channel].bank_lsb);
break;
case 5: // Set portamento msb
@@ -1220,11 +1228,14 @@ void MIDIplay::realTime_Controller(uint8_t channel, uint8_t type, uint8_t value)
NoteUpdate_All(channel, Upd_Volume);
break;
+ case 74: // Change brightness
+ Ch[channel].brightness = value;
+ NoteUpdate_All(channel, Upd_Volume);
+ break;
+
case 64: // Enable/disable sustain
Ch[channel].sustain = value;
-
if(!value) KillSustainingNotes(channel);
-
break;
case 11: // Change expression (another volume factor)
@@ -1251,6 +1262,7 @@ void MIDIplay::realTime_Controller(uint8_t channel, uint8_t type, uint8_t value)
Ch[channel].vibdelay = 0;
Ch[channel].panning = 0x30;
Ch[channel].portamento = 0;
+ Ch[channel].brightness = 127;
//UpdatePortamento(MidCh);
NoteUpdate_All(channel, Upd_Pan + Upd_Volume + Upd_Pitch);
// Kill all sustained notes
@@ -1449,6 +1461,8 @@ void MIDIplay::NoteUpdate(uint16_t MidCh,
if(props_mask & Upd_Volume)
{
uint32_t volume;
+ bool is_percussion = (MidCh == 9) || Ch[MidCh].is_xg_percussion;
+ uint8_t brightness = is_percussion ? 127 : Ch[MidCh].brightness;
switch(opl.m_volumeScale)
{
@@ -1471,12 +1485,11 @@ void MIDIplay::NoteUpdate(uint16_t MidCh,
else
{
// The formula below: SOLVE(V=127^3 * 2^( (A-63.49999) / 8), A)
- volume = volume > 8725 ? static_cast<unsigned int>(std::log((double)volume) * 11.541561 + (0.5 - 104.22845)) : 0;
+ volume = volume > 8725 ? static_cast<uint32_t>(std::log(static_cast<double>(volume)) * 11.541561 + (0.5 - 104.22845)) : 0;
// The incorrect formula below: SOLVE(V=127^3 * (2^(A/63)-1), A)
//opl.Touch_Real(c, volume>11210 ? 91.61112 * std::log(4.8819E-7*volume + 1.0)+0.5 : 0);
}
-
- opl.Touch_Real(c, volume);
+ opl.Touch_Real(c, volume, brightness);
//opl.Touch(c, volume);
}
break;
@@ -1486,7 +1499,7 @@ void MIDIplay::NoteUpdate(uint16_t MidCh,
volume = 2 * ((Ch[MidCh].volume * Ch[MidCh].expression) * 127 / 16129) + 1;
//volume = 2 * (Ch[MidCh].volume) + 1;
volume = (DMX_volume_mapping_table[vol] * volume) >> 9;
- opl.Touch_Real(c, volume);
+ opl.Touch_Real(c, volume, brightness);
}
break;
@@ -1495,7 +1508,7 @@ void MIDIplay::NoteUpdate(uint16_t MidCh,
volume = ((Ch[MidCh].volume * Ch[MidCh].expression) * 127 / 16129);
volume = ((64 * (vol + 0x80)) * volume) >> 15;
//volume = ((63 * (vol + 0x80)) * Ch[MidCh].volume) >> 15;
- opl.Touch_Real(c, volume);
+ opl.Touch_Real(c, volume, brightness);
}
break;
@@ -1504,7 +1517,7 @@ void MIDIplay::NoteUpdate(uint16_t MidCh,
//volume = 63 - W9X_volume_mapping_table[(((vol * Ch[MidCh].volume /** Ch[MidCh].expression*/) * 127 / 16129 /*2048383*/) >> 2)];
volume = 63 - W9X_volume_mapping_table[(((vol * Ch[MidCh].volume * Ch[MidCh].expression) * 127 / 2048383) >> 2)];
//volume = W9X_volume_mapping_table[vol >> 2] + volume;
- opl.Touch_Real(c, volume);
+ opl.Touch_Real(c, volume, brightness);
}
break;
}