Skip to content

Commit

Permalink
code rev
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Oct 3, 2023
1 parent 5f930c5 commit 35a844e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion sdl2-hyper-sonic-drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ target_sources(${LIB_NAME} PRIVATE

${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/scummvm/MidiDriver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/scummvm/AdLibInstrument.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/scummvm/AdLibPart.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/scummvm/AdLibChannel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/scummvm/AdLibPercussionChannel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/scummvm/MidiDriver_ADLIB.cpp

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#include <cstring>
#include <format>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibPart.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibChannel.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/MidiDriver_ADLIB.hpp>
#include <HyperSonicDrivers/utils/ILogger.hpp>

namespace HyperSonicDrivers::drivers::midi::scummvm
{
using utils::logW;

AdLibPart::AdLibPart(const uint8_t channel) :
AdLibChannel::AdLibChannel(const uint8_t channel) :
IMidiChannel(channel)
{
memset(&_partInstr, 0, sizeof(_partInstr));
memset(&_partInstrSecondary, 0, sizeof(_partInstrSecondary));
}

void AdLibPart::setInstr(const bool isOpl3) noexcept
void AdLibChannel::setInstr(const bool isOpl3) noexcept
{
if (isOpl3)
{
Expand All @@ -28,7 +28,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
}
}

void AdLibPart::setCustomInstr(const uint8_t* instr) noexcept
void AdLibChannel::setCustomInstr(const uint8_t* instr) noexcept
{
memcpy(&_partInstr, instr, sizeof(AdLibInstrument));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
{
struct AdLibVoice;

class AdLibPart : public IMidiChannel
class AdLibChannel : public IMidiChannel
{
public:
explicit AdLibPart(const uint8_t channel);
explicit AdLibChannel(const uint8_t channel);

inline const AdLibInstrument* getInstr() const noexcept { return &_partInstr; };
inline const AdLibInstrument* getInstrSecondary() const noexcept { return &_partInstrSecondary; };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
using utils::logW;

AdLibPercussionChannel::AdLibPercussionChannel() :
AdLibPart(audio::midi::MIDI_PERCUSSION_CHANNEL)
AdLibChannel(audio::midi::MIDI_PERCUSSION_CHANNEL)
{
priEff = 0;
volume = 127;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstdint>
#include <array>
#include <memory>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibPart.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibChannel.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibInstrument.h>


Expand All @@ -14,7 +14,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
// will be done through the MidiChannel base class as opposed to the
// AdLibPart base class. If this were NOT the case, all the functions
// listed below would need to be virtual in AdLibPart as well as MidiChannel.
class AdLibPercussionChannel : public AdLibPart
class AdLibPercussionChannel : public AdLibChannel
{
public:
AdLibPercussionChannel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <cstdint>
#include <cstring>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibPart.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibChannel.hpp>
#include <HyperSonicDrivers/drivers/midi/IMidiChannelVoice.hpp>

namespace HyperSonicDrivers::drivers::midi::scummvm
Expand Down Expand Up @@ -62,7 +62,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
AdLibVoice() = default;
inline void setNote(const uint8_t note) { m_note = note; }
inline void setFree(const bool free) { m_free = free; };
inline void setChannel(AdLibPart* chan) { m_channel = chan; };
inline void setChannel(AdLibChannel* chan) { m_channel = chan; };
inline void setWaitForPedal(const bool waitForPedal) { m_sustain = waitForPedal; };
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cassert>
#include <HyperSonicDrivers/audio/midi/types.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/MidiDriver_ADLIB.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibPart.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibChannel.hpp>
#include <HyperSonicDrivers/utils/algorithms.hpp>
#include <HyperSonicDrivers/utils/ILogger.hpp>

Expand Down Expand Up @@ -90,12 +90,12 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
242, 243, 245, 247, 249, 251, 252, 254
};

constexpr AdLibPart* toAdlibPart(IMidiChannel* mc)
constexpr AdLibChannel* toAdlibPart(IMidiChannel* mc)
{
return dynamic_cast<AdLibPart*>(mc);
return dynamic_cast<AdLibChannel*>(mc);
}

static AdLibPart* toAdlibPart(const std::unique_ptr<IMidiChannel>& ap)
static AdLibChannel* toAdlibPart(const std::unique_ptr<IMidiChannel>& ap)
{
return toAdlibPart(ap.get());
}
Expand All @@ -114,11 +114,11 @@ namespace HyperSonicDrivers::drivers::midi::scummvm

std::ranges::fill(_curNotTable, 0);
for (int i = 0; i < MIDI_PERCUSSION_CHANNEL; ++i)
m_channels[i] = std::make_unique<AdLibPart>(static_cast<uint8_t>(i));
m_channels[i] = std::make_unique<AdLibChannel>(static_cast<uint8_t>(i));

m_channels[MIDI_PERCUSSION_CHANNEL] = std::make_unique<AdLibPercussionChannel>();
for (int i = MIDI_PERCUSSION_CHANNEL + 1; i < MIDI_MAX_CHANNELS; i++)
m_channels[i] = std::make_unique<AdLibPart>(static_cast<uint8_t>(i));
m_channels[i] = std::make_unique<AdLibChannel>(static_cast<uint8_t>(i));

std::ranges::fill(_channelTable2, 0);
m_percussion = dynamic_cast<AdLibPercussionChannel*>(m_channels[MIDI_PERCUSSION_CHANNEL].get());
Expand Down Expand Up @@ -221,7 +221,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
if (m_opl3Mode)
return;

AdLibPart* part = toAdlibPart(m_channels[channel]);
AdLibChannel* part = toAdlibPart(m_channels[channel]);
part->pitchBendFactor = range;
for (AdLibVoice* voice = part->voice; voice; voice = voice->next)
{
Expand Down Expand Up @@ -624,7 +624,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm

void MidiDriver_ADLIB::mcIncStuff(AdLibVoice* voice, Struct10* s10, Struct11* s11)
{
const AdLibPart* part = toAdlibPart(voice->getChannel());
const AdLibChannel* part = toAdlibPart(voice->getChannel());
const uint8_t code = struct10OnTimer(s10, s11);

if (code & 1) {
Expand Down Expand Up @@ -882,7 +882,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
return _randSeed * a >> 8;
}

void MidiDriver_ADLIB::partKeyOff(AdLibPart* part, uint8_t note)
void MidiDriver_ADLIB::partKeyOff(AdLibChannel* part, uint8_t note)
{
for (AdLibVoice* voice = part->voice; voice; voice = voice->next)
{
Expand All @@ -896,12 +896,12 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
}
}

AdLibPart* MidiDriver_ADLIB::getChannel(const uint8_t channel) const noexcept
AdLibChannel* MidiDriver_ADLIB::getChannel(const uint8_t channel) const noexcept
{
return toAdlibPart(m_channels[channel]);
}

void MidiDriver_ADLIB::partKeyOn(AdLibPart* part, const AdLibInstrument* instr, uint8_t note, uint8_t velocity, const AdLibInstrument* second, uint8_t pan) {
void MidiDriver_ADLIB::partKeyOn(AdLibChannel* part, const AdLibInstrument* instr, uint8_t note, uint8_t velocity, const AdLibInstrument* second, uint8_t pan) {
AdLibVoice* voice;

voice = allocateVoice(part->priEff);
Expand Down Expand Up @@ -946,7 +946,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
return best;
}

void MidiDriver_ADLIB::linkMc(AdLibPart* part, AdLibVoice* voice)
void MidiDriver_ADLIB::linkMc(AdLibChannel* part, AdLibVoice* voice)
{
voice->setFree(false);
voice->setChannel(part);
Expand All @@ -960,7 +960,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm

void MidiDriver_ADLIB::mcKeyOn(AdLibVoice* voice, const AdLibInstrument* instr, uint8_t note, uint8_t velocity, const AdLibInstrument* second, uint8_t pan)
{
const AdLibPart* part = toAdlibPart(voice->getChannel());
const AdLibChannel* part = toAdlibPart(voice->getChannel());
uint8_t vol1, vol2;
uint8_t secVol1 = 0, secVol2 = 0;

Expand Down Expand Up @@ -1127,7 +1127,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
void MidiDriver_ADLIB::mcInitStuff(AdLibVoice* voice, Struct10* s10,
Struct11* s11, uint8_t flags, const InstrumentExtra* ie)
{
const AdLibPart* part = toAdlibPart(voice->getChannel());
const AdLibChannel* part = toAdlibPart(voice->getChannel());
s11->modifyVal = 0;
s11->flag0x40 = flags & 0x40;
s10->loop = flags & 0x20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <HyperSonicDrivers/drivers/midi/scummvm/MidiDriver.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibInstrument.h>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdlibVoice.h>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibPart.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibChannel.hpp>
#include <HyperSonicDrivers/drivers/midi/scummvm/AdLibPercussionChannel.hpp>


Expand Down Expand Up @@ -88,10 +88,10 @@ namespace HyperSonicDrivers::drivers::midi::scummvm
int _timerIncrease = 0xD69;
int _timerThreshold = 0x411B;

AdLibPart* getChannel(const uint8_t channel) const noexcept;
AdLibChannel* getChannel(const uint8_t channel) const noexcept;

void partKeyOn(AdLibPart* part, const AdLibInstrument* instr, uint8_t note, uint8_t velocity, const AdLibInstrument* second, uint8_t pan);
void partKeyOff(AdLibPart* part, uint8_t note);
void partKeyOn(AdLibChannel* part, const AdLibInstrument* instr, uint8_t note, uint8_t velocity, const AdLibInstrument* second, uint8_t pan);
void partKeyOff(AdLibChannel* part, uint8_t note);

void adlibKeyOff(int chan);
void adlibNoteOn(int chan, uint8_t note, int mod);
Expand All @@ -111,7 +111,7 @@ namespace HyperSonicDrivers::drivers::midi::scummvm

void mcOff(AdLibVoice* voice);

static void linkMc(AdLibPart* part, AdLibVoice* voice);
static void linkMc(AdLibChannel* part, AdLibVoice* voice);
void mcIncStuff(AdLibVoice* voice, Struct10* s10, Struct11* s11);
void mcInitStuff(AdLibVoice* voice, Struct10* s10, Struct11* s11, uint8_t flags,
const InstrumentExtra* ie);
Expand Down

0 comments on commit 35a844e

Please sign in to comment.