From 369d4f3e758a66d0525dab66eb32b2fcffd1dc3c Mon Sep 17 00:00:00 2001 From: Ian Caio Date: Fri, 4 Dec 2020 22:25:40 -0300 Subject: [PATCH] First commit This attempts to fix a bug uncovered by #5581, where the wrong MidiEvent constructor is selected due to ambiguity in the arguments that are used in the call. Part of the solution is to use a enum class on the last parameter instead of a boolean to avoid implicit conversions and a more strict method selection through the ADL. One of the parameters type on a constructor was also changed from int to std::size_t which more accurately represents it. "ignoreOnExport" was replaced with "source", which for now can be Source::Internal or Source::External, and its value is still used on the processInEvent to define whether a MidiEvent should be ignored during the song export. --- include/MidiEvent.h | 27 ++++++++++++++------------- src/tracks/InstrumentTrack.cpp | 6 +++--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/MidiEvent.h b/include/MidiEvent.h index 177ef75ea94..a82c5d4645c 100644 --- a/include/MidiEvent.h +++ b/include/MidiEvent.h @@ -33,30 +33,32 @@ class MidiEvent { public: + enum class Source { Internal, External }; + MidiEvent(MidiEventTypes type = MidiActiveSensing, int8_t channel = 0, int16_t param1 = 0, int16_t param2 = 0, const void* sourcePort = nullptr, - bool ignoreOnExport = true) : + Source source = Source::External) : m_type( type ), m_metaEvent( MidiMetaInvalid ), m_channel( channel ), m_sysExData( NULL ), m_sourcePort(sourcePort), - m_ignoreOnExport(ignoreOnExport) + m_source(source) { m_data.m_param[0] = param1; m_data.m_param[1] = param2; } - MidiEvent(MidiEventTypes type, const char* sysExData, int dataLen, bool ignoreOnExport = true) : + MidiEvent(MidiEventTypes type, const char* sysExData, std::size_t dataLen, Source source = Source::External) : m_type( type ), m_metaEvent( MidiMetaInvalid ), m_channel( 0 ), m_sysExData( sysExData ), m_sourcePort(nullptr), - m_ignoreOnExport(ignoreOnExport) + m_source(source) { m_data.m_sysExDataLen = dataLen; } @@ -68,7 +70,7 @@ class MidiEvent m_data( other.m_data ), m_sysExData( other.m_sysExData ), m_sourcePort(other.m_sourcePort), - m_ignoreOnExport(other.m_ignoreOnExport) + m_source(other.m_source) { } @@ -194,14 +196,14 @@ class MidiEvent setParam( 0, pitchBend ); } - bool ignoreOnExport() const + Source source() const { - return m_ignoreOnExport; + return m_source; } - void setIgnoreOnExport(bool value) + void setSource(Source value) { - m_ignoreOnExport = value; + m_source = value; } @@ -212,16 +214,15 @@ class MidiEvent union { int16_t m_param[2]; // first/second parameter (key/velocity) - uint8_t m_bytes[4]; // raw bytes + uint8_t m_bytes[4]; // raw bytes int32_t m_sysExDataLen; // len of m_sysExData } m_data; const char* m_sysExData; const void* m_sourcePort; - // This helps us ignore MIDI events that shouldn't be processed - // during a project export, like physical controller events. - bool m_ignoreOnExport; + // Stores the source of the MidiEvent: Internal or External (hardware controllers). + Source m_source; } ; #endif diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 702257f2959..80ce57cb29a 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -267,10 +267,10 @@ void InstrumentTrack::processCCEvent(int controller) uint16_t cc = static_cast(controller); uint16_t value = static_cast(m_midiCCModel[controller]->value()); - // Process the MIDI CC event as an input event but with ignoreOnExport set to false + // Process the MIDI CC event as an input event but with source set to Internal // so we can know LMMS generated the event, not a controller, and can process it during // the project export - processInEvent(MidiEvent(MidiControlChange, channel, cc, value, NULL, false)); + processInEvent(MidiEvent(MidiControlChange, channel, cc, value, nullptr, MidiEvent::Source::Internal)); } @@ -278,7 +278,7 @@ void InstrumentTrack::processCCEvent(int controller) void InstrumentTrack::processInEvent( const MidiEvent& event, const TimePos& time, f_cnt_t offset ) { - if (Engine::getSong()->isExporting() && event.ignoreOnExport()) + if (Engine::getSong()->isExporting() && event.source() == MidiEvent::Source::External) { return; }