Skip to content

Commit

Permalink
clean up scumm midi drv
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Oct 2, 2023
1 parent 58ce13b commit 8df6f9a
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
{
using utils::logW;

void AdLibPart::init(MidiDriver_ADLIB* owner, uint8_t channel)
void AdLibPart::init(MidiDriver_ADLIB* owner)
{
_owner = owner;
_channel = channel;
_priEff = 127;
programChange(0);
}
Expand All @@ -21,7 +20,8 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
_allocated = true;
}

AdLibPart::AdLibPart()
AdLibPart::AdLibPart(const uint8_t channel) :
MidiChannel(channel)
{
memset(&_partInstr, 0, sizeof(_partInstr));
memset(&_partInstrSecondary, 0, sizeof(_partInstrSecondary));
Expand All @@ -33,7 +33,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm

uint8_t AdLibPart::getNumber()
{
return _channel;
return channel;
}

void AdLibPart::release()
Expand All @@ -42,7 +42,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
}

void AdLibPart::send(uint32_t b) {
_owner->send(_channel, b);
_owner->send(channel, b);
}

void AdLibPart::noteOff(uint8_t note) {
Expand All @@ -58,14 +58,14 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
#endif
_owner->partKeyOn(this, &_partInstr, note, velocity,
&_partInstrSecondary,
_pan);
pan);
}

void AdLibPart::programChange(uint8_t program) {
if (program > 127)
return;

_program = program;
program = program;
if (!_owner->m_opl3Mode) {
memcpy(&_partInstr, &g_gmInstruments[program], sizeof(AdLibInstrument));
}
Expand All @@ -79,17 +79,17 @@ namespace HyperSonicDrivers::drivers::midi::scummvm

void AdLibPart::pitchBend(int16_t bend)
{
_pitchBend = bend;
pitch = bend;
for (AdLibVoice* voice = _voice; voice; voice = voice->_next)
{
if (!_owner->m_opl3Mode)
{
_owner->adlibNoteOn(voice->_channel, voice->_note/* + _transposeEff*/,
(_pitchBend * _pitchBendFactor >> 6) + _detuneEff);
(pitch * _pitchBendFactor >> 6) + _detuneEff);
}
else
{
_owner->adlibNoteOn(voice->_channel, voice->_note, _pitchBend >> 1);
_owner->adlibNoteOn(voice->_channel, voice->_note, pitch >> 1);
}
}
}
Expand All @@ -105,7 +105,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
//spdlog::debug("modwheel value {}", value);
break;
case 7:
volume(value);
setVolume(value);
//spdlog::debug("volume value {}", value);
break;
case 10:
Expand Down Expand Up @@ -151,44 +151,44 @@ namespace HyperSonicDrivers::drivers::midi::scummvm

void AdLibPart::modulationWheel(uint8_t value)
{
_modWheel = value;
modulation = value;
for (AdLibVoice* voice = _voice; voice; voice = voice->_next)
{
if (voice->_s10a.active && voice->_s11a.flag0x40)
voice->_s10a.modWheel = _modWheel >> 2;
voice->_s10a.modWheel = modulation >> 2;
if (voice->_s10b.active && voice->_s11b.flag0x40)
voice->_s10b.modWheel = _modWheel >> 2;
voice->_s10b.modWheel = modulation >> 2;
}
}

void AdLibPart::volume(uint8_t value)
void AdLibPart::setVolume(uint8_t value)
{
_volEff = value;
volume = value;
for (AdLibVoice* voice = _voice; voice; voice = voice->_next)
{
if (!_owner->m_opl3Mode)
{
_owner->adlibSetParam(voice->_channel, 0, g_volumeTable[g_volumeLookupTable[voice->_vol2][_volEff >> 2]]);
_owner->adlibSetParam(voice->_channel, 0, g_volumeTable[g_volumeLookupTable[voice->_vol2][volume >> 2]]);
if (voice->_twoChan) {
_owner->adlibSetParam(voice->_channel, 13, g_volumeTable[g_volumeLookupTable[voice->_vol1][_volEff >> 2]]);
_owner->adlibSetParam(voice->_channel, 13, g_volumeTable[g_volumeLookupTable[voice->_vol1][volume >> 2]]);
}
}
else
{
_owner->adlibSetParam(voice->_channel, 0, g_volumeTable[((voice->_vol2 + 1) * _volEff) >> 7], true);
_owner->adlibSetParam(voice->_channel, 0, g_volumeTable[((voice->_secVol2 + 1) * _volEff) >> 7], false);
_owner->adlibSetParam(voice->_channel, 0, g_volumeTable[((voice->_vol2 + 1) * volume) >> 7], true);
_owner->adlibSetParam(voice->_channel, 0, g_volumeTable[((voice->_secVol2 + 1) * volume) >> 7], false);
if (voice->_twoChan) {
_owner->adlibSetParam(voice->_channel, 13, g_volumeTable[((voice->_vol1 + 1) * _volEff) >> 7], true);
_owner->adlibSetParam(voice->_channel, 13, g_volumeTable[((voice->_vol1 + 1) * volume) >> 7], true);
}
if (voice->_secTwoChan) {
_owner->adlibSetParam(voice->_channel, 13, g_volumeTable[((voice->_secVol1 + 1) * _volEff) >> 7], false);
_owner->adlibSetParam(voice->_channel, 13, g_volumeTable[((voice->_secVol1 + 1) * volume) >> 7], false);
}
}
}
}

void AdLibPart::panPosition(uint8_t value) {
_pan = value;
pan = value;
}

void AdLibPart::pitchBendFactor(uint8_t value)
Expand All @@ -202,7 +202,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
for (AdLibVoice* voice = _voice; voice; voice = voice->_next)
{
_owner->adlibNoteOn(voice->_channel, voice->_note/* + _transposeEff*/,
(_pitchBend * _pitchBendFactor >> 6) + _detuneEff);
(pitch * _pitchBendFactor >> 6) + _detuneEff);
}
}

Expand All @@ -222,7 +222,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
for (AdLibVoice* voice = _voice; voice; voice = voice->_next)
{
_owner->adlibNoteOn(voice->_channel, voice->_note/* + _transposeEff*/,
(_pitchBend * _pitchBendFactor >> 6) + _detuneEff);
(pitch * _pitchBendFactor >> 6) + _detuneEff);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,23 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
protected:
// AdLibPart *_prev, *_next;
AdLibVoice* _voice = nullptr;
int16_t _pitchBend = 0;
uint8_t _pitchBendFactor = 2;
//int8_t _transposeEff;
uint8_t _volEff = 0;
int8_t _detuneEff = 0;
uint8_t _modWheel = 0;
bool _pedal = false;
uint8_t _program = 0;
uint8_t _priEff = 0;
uint8_t _pan = 64;
//uint8_t pan = 64;
AdLibInstrument _partInstr;
AdLibInstrument _partInstrSecondary;

MidiDriver_ADLIB* _owner = nullptr;
bool _allocated = false;
uint8_t _channel = 0;

void init(MidiDriver_ADLIB* owner, uint8_t channel);
void init(MidiDriver_ADLIB* owner);
void allocate();

public:
AdLibPart();
AdLibPart(const uint8_t channel);

MidiDriver* device() override;
uint8_t getNumber() override;
Expand All @@ -56,7 +51,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
// Control Change messages
void controlChange(uint8_t control, uint8_t value) override;
void modulationWheel(uint8_t value) override;
void volume(uint8_t value) override;
void setVolume(uint8_t value) override;
void panPosition(uint8_t value) override;
void pitchBendFactor(uint8_t value) override;
void detune(uint8_t value) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
using utils::logD;
using utils::logW;

void AdLibPercussionChannel::init(MidiDriver_ADLIB* owner, uint8_t channel)
void AdLibPercussionChannel::init(MidiDriver_ADLIB* owner)
{
AdLibPart::init(owner, channel);
AdLibPart::init(owner);
_priEff = 0;
_volEff = 127;
volume = 127;

// Initialize the custom instruments data
std::ranges::fill(_notes, 0);
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
return;
}

_owner->partKeyOn(this, inst, note, velocity, sec, _pan);
_owner->partKeyOn(this, inst, note, velocity, sec, pan);
}

void AdLibPercussionChannel::sysEx_customInstrument(uint32_t type, const uint8_t* instr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
friend class MidiDriver_ADLIB;

protected:
void init(MidiDriver_ADLIB* owner, uint8_t channel);
void init(MidiDriver_ADLIB* owner);

public:
AdLibPercussionChannel() = default;
AdLibPercussionChannel() : AdLibPart(audio::midi::MIDI_PERCUSSION_CHANNEL) {};
~AdLibPercussionChannel() override = default;

void noteOff(uint8_t note) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>
#include <cstring>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibPart.hpp>
#include <HyperSonicDrivers/drivers/midi/IMidiChannelVoice.hpp>

namespace HyperSonicDrivers::drivers::midi::scummvm
{
Expand Down Expand Up @@ -36,7 +37,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
Struct10* s10;
};

struct AdLibVoice
struct AdLibVoice : public IMidiChannelVoice
{
AdLibPart* _part;
AdLibVoice* _next, * _prev;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

namespace HyperSonicDrivers::drivers::midi::scummvm
{
class MidiChannel //: public IMidiChannel
// TODO: remove this class
class MidiChannel : public IMidiChannel
{
public:
MidiChannel(const uint8_t channel) : IMidiChannel(channel) {};
virtual ~MidiChannel() = default;

virtual MidiDriver* device() = 0;
Expand All @@ -28,7 +30,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
virtual void controlChange(uint8_t control, uint8_t value) = 0;
// TODO: remove the static_cast and pass the original type instead
virtual void modulationWheel(uint8_t value) { controlChange(static_cast<uint8_t>(audio::midi::MIDI_EVENT_CONTROLLER_TYPES::MODULATION_WHEEL), value); }
virtual void volume(uint8_t value) { controlChange(static_cast<uint8_t>(audio::midi::MIDI_EVENT_CONTROLLER_TYPES::CHANNEL_VOLUME), value); }
virtual void setVolume(uint8_t value) { controlChange(static_cast<uint8_t>(audio::midi::MIDI_EVENT_CONTROLLER_TYPES::CHANNEL_VOLUME), value); }
virtual void panPosition(uint8_t value) { controlChange(static_cast<uint8_t>(audio::midi::MIDI_EVENT_CONTROLLER_TYPES::PAN), value); }
virtual void pitchBendFactor(uint8_t value) = 0;
virtual void transpose(int8_t value) {}
Expand Down
Loading

0 comments on commit 8df6f9a

Please sign in to comment.