Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
	This attempts to fix a bug uncovered by LMMS#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.
  • Loading branch information
IanCaio committed Dec 5, 2020
1 parent ddf69fe commit 369d4f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
27 changes: 14 additions & 13 deletions include/MidiEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)
{
}

Expand Down Expand Up @@ -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;
}


Expand All @@ -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
6 changes: 3 additions & 3 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,18 @@ void InstrumentTrack::processCCEvent(int controller)
uint16_t cc = static_cast<uint16_t>(controller);
uint16_t value = static_cast<uint16_t>(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));
}




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;
}
Expand Down

0 comments on commit 369d4f3

Please sign in to comment.