Skip to content

Commit

Permalink
Seeking support for pitch bends and piano override
Browse files Browse the repository at this point in the history
  • Loading branch information
khang06 committed Oct 6, 2023
1 parent 961cfc6 commit 4f68030
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions PianoFromAbove/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,10 +1113,8 @@ GameState::GameError MainScreen::Logic( void )
if (pEvent->GetChannelEventType() != MIDIChannelEvent::NoteOn) {
if (pEvent->GetChannelEventType() == MIDIChannelEvent::ProgramChange && pEvent->GetChannel() != MIDI::Drums && config.m_bPianoOverride)
pEvent->SetParam1(0);
if (pEvent->GetChannelEventType() == MIDIChannelEvent::PitchBend) {
//m_pBends[pEvent->GetChannel()] = (short)(((pEvent->GetParam2() << 7) | pEvent->GetParam1()) - 8192);
if (pEvent->GetChannelEventType() == MIDIChannelEvent::PitchBend)
m_pBends[pEvent->GetChannel()] = (notex_table[1] - notex_table[0]) * (((short)(((pEvent->GetParam2() << 7) | pEvent->GetParam1()) - 8192)) / (8192.0f / 12.0f));
}
m_OutDevice.PlayEvent(pEvent->GetEventCode(), pEvent->GetParam1(), pEvent->GetParam2());
}
else if (!m_bMute && (!m_bAnyChannelMuted || !m_vTrackSettings[pEvent->GetTrack()].aChannels[pEvent->GetChannel()].bMuted)) {
Expand Down Expand Up @@ -1327,9 +1325,11 @@ void MainScreen::PlaySkippedEvents(eventvec_t::const_iterator itOldProgramChange
return;

// Lookup tables to see if we've got an event for a given control or program. faster than map or hash_map.
bool aControl[16][128], aProgram[16];
bool aControl[16][128], aProgram[16], aPitchBend[16];
bool bPianoOverride = Config::GetConfig().m_bPianoOverride;
memset(aControl, 0, sizeof(aControl));
memset(aProgram, 0, sizeof(aProgram));
memset(aPitchBend, 0, sizeof(aPitchBend));

// Go from one before the next to the beginning backwards. iterators are so verbose :/
vector< MIDIChannelEvent* > vControl;
Expand All @@ -1352,6 +1352,15 @@ void MainScreen::PlaySkippedEvents(eventvec_t::const_iterator itOldProgramChange
!aProgram[pEvent->GetChannel()])
{
aProgram[pEvent->GetChannel()] = true;
if (pEvent->GetChannel() != MIDI::Drums && bPianoOverride)
pEvent->SetParam1(0);
m_OutDevice.PlayEvent(pEvent->GetEventCode(), pEvent->GetParam1(), pEvent->GetParam2());
}
else if (pEvent->GetChannelEventType() == MIDIChannelEvent::PitchBend &&
!aPitchBend[pEvent->GetChannel()])
{
aPitchBend[pEvent->GetChannel()] = true;
m_pBends[pEvent->GetChannel()] = (notex_table[1] - notex_table[0]) * (((short)(((pEvent->GetParam2() << 7) | pEvent->GetParam1()) - 8192)) / (8192.0f / 12.0f));
m_OutDevice.PlayEvent(pEvent->GetEventCode(), pEvent->GetParam1(), pEvent->GetParam2());
}
}
Expand Down
2 changes: 1 addition & 1 deletion PianoFromAbove/MIDI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ void MIDI::PostProcess(vector<MIDIChannelEvent*>& vChannelEvents, eventvec_t* vP
vChannelEvents.push_back(pChannelEvent);

MIDIChannelEvent::ChannelEventType eEventType = pChannelEvent->GetChannelEventType();
if (vProgramChanges && (eEventType == MIDIChannelEvent::ProgramChange || eEventType == MIDIChannelEvent::Controller))
if (vProgramChanges && (eEventType == MIDIChannelEvent::ProgramChange || eEventType == MIDIChannelEvent::Controller || eEventType == MIDIChannelEvent::PitchBend))
vProgramChanges->push_back(pair< long long, int >(pEvent->GetAbsMicroSec(), vChannelEvents.size() - 1));
}
else if ( pEvent->GetEventType() == MIDIEvent::MetaEvent )
Expand Down

0 comments on commit 4f68030

Please sign in to comment.