Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/MidiPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ class MidiPort : public Model, public SerializingObject

int realOutputChannel() const
{
return outputChannel() - 1;
// There's a possibility of outputChannel being 0 ("--"), which is used to keep all
// midi channels when forwarding. In that case, realOutputChannel will return the
// default channel 1 (whose value is 0).
return outputChannel() ? outputChannel() - 1 : 0;
}

void processInEvent( const MidiEvent& event, const MidiTime& time = MidiTime() );
Expand Down
36 changes: 27 additions & 9 deletions src/core/midi/MidiPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ MidiPort::MidiPort( const QString& name,
m_midiEventProcessor( eventProcessor ),
m_mode( mode ),
m_inputChannelModel( 0, 0, MidiChannelCount, this, tr( "Input channel" ) ),
m_outputChannelModel( 1, 1, MidiChannelCount, this, tr( "Output channel" ) ),
m_outputChannelModel( 1, 0, MidiChannelCount, this, tr( "Output channel" ) ),
m_inputControllerModel( 0, 0, MidiControllerCount, this, tr( "Input controller" ) ),
m_outputControllerModel( 0, 0, MidiControllerCount, this, tr( "Output controller" ) ),
m_fixedInputVelocityModel( -1, -1, MidiMaxVelocity, this, tr( "Fixed input velocity" ) ),
Expand Down Expand Up @@ -151,18 +151,36 @@ void MidiPort::processInEvent( const MidiEvent& event, const MidiTime& time )

void MidiPort::processOutEvent( const MidiEvent& event, const MidiTime& time )
{
// mask event
if( isOutputEnabled() && realOutputChannel() == event.channel() )
// If we selected a channel from 1-16, we will only route the selected channel.
// But if we selected channel 0 ("--") we will route all channels out.
if( isOutputEnabled() )
{
MidiEvent outEvent = event;

if( fixedOutputVelocity() >= 0 && event.velocity() > 0 &&
( event.type() == MidiNoteOn || event.type() == MidiKeyPressure ) )
// Selected channel 0 ("--"). Route all channels
if( outputChannel() == 0 )
{
outEvent.setVelocity( fixedOutputVelocity() );
MidiEvent outEvent = event;

if( fixedOutputVelocity() >= 0 && event.velocity() > 0 &&
( event.type() == MidiNoteOn || event.type() == MidiKeyPressure ) )
{
outEvent.setVelocity( fixedOutputVelocity() );
}

m_midiClient->processOutEvent( outEvent, time, this );
}
// Selected channel between 1-16. Mask event.
else if( realOutputChannel() == event.channel() )
{
MidiEvent outEvent = event;

if( fixedOutputVelocity() >= 0 && event.velocity() > 0 &&
( event.type() == MidiNoteOn || event.type() == MidiKeyPressure ) )
{
outEvent.setVelocity( fixedOutputVelocity() );
}

m_midiClient->processOutEvent( outEvent, time, this );
m_midiClient->processOutEvent( outEvent, time, this );
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/gui/widgets/InstrumentMidiIOView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ InstrumentMidiIOView::InstrumentMidiIOView( QWidget* parent ) :
midiOutputLayout->setSpacing( 6 );

m_outputChannelSpinBox = new LcdSpinBox( 2, m_midiOutputGroupBox );
m_outputChannelSpinBox->addTextForValue( 0, "--" );
m_outputChannelSpinBox->setLabel( tr( "CHANNEL" ) );
m_outputChannelSpinBox->setEnabled( false );
m_outputChannelSpinBox->setEnabled( true );
midiOutputLayout->addWidget( m_outputChannelSpinBox );

m_fixedOutputVelocitySpinBox = new LcdSpinBox( 3, m_midiOutputGroupBox );
Expand All @@ -108,8 +109,6 @@ InstrumentMidiIOView::InstrumentMidiIOView( QWidget* parent ) :
midiOutputLayout->addWidget( m_fixedOutputNoteSpinBox );
midiOutputLayout->addStretch();

connect( m_midiOutputGroupBox->ledButton(), SIGNAL( toggled( bool ) ),
m_outputChannelSpinBox, SLOT( setEnabled( bool ) ) );
connect( m_midiOutputGroupBox->ledButton(), SIGNAL( toggled( bool ) ),
m_fixedOutputVelocitySpinBox, SLOT( setEnabled( bool ) ) );
connect( m_midiOutputGroupBox->ledButton(), SIGNAL( toggled( bool ) ),
Expand Down
14 changes: 11 additions & 3 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ void InstrumentTrack::processOutEvent( const MidiEvent& event, const MidiTime& t
const MidiEvent transposedEvent = applyMasterKey( event );
const int key = transposedEvent.key();

// If we have a selected output midi channel between 1-16, we will use that channel to handle the midi event.
// But if our selected midi output channel is 0 ("--"), we will use the event channel instead.
auto handleEventOutputChannel = midiPort()->realOutputChannel();
if( midiPort()->outputChannel() == 0 )
{
handleEventOutputChannel = event.channel();
}

switch( event.type() )
{
case MidiNoteOn:
Expand All @@ -403,10 +411,10 @@ void InstrumentTrack::processOutEvent( const MidiEvent& event, const MidiTime& t
{
if( m_runningMidiNotes[key] > 0 )
{
m_instrument->handleMidiEvent( MidiEvent( MidiNoteOff, midiPort()->realOutputChannel(), key, 0 ), time, offset );
m_instrument->handleMidiEvent( MidiEvent( MidiNoteOff, handleEventOutputChannel, key, 0 ), time, offset );
}
++m_runningMidiNotes[key];
m_instrument->handleMidiEvent( MidiEvent( MidiNoteOn, midiPort()->realOutputChannel(), key, event.velocity() ), time, offset );
m_instrument->handleMidiEvent( MidiEvent( MidiNoteOn, handleEventOutputChannel, key, event.velocity() ), time, offset );

}
m_midiNotesMutex.unlock();
Expand All @@ -419,7 +427,7 @@ void InstrumentTrack::processOutEvent( const MidiEvent& event, const MidiTime& t

if( key >= 0 && key < NumKeys && --m_runningMidiNotes[key] <= 0 )
{
m_instrument->handleMidiEvent( MidiEvent( MidiNoteOff, midiPort()->realOutputChannel(), key, 0 ), time, offset );
m_instrument->handleMidiEvent( MidiEvent( MidiNoteOff, handleEventOutputChannel, key, 0 ), time, offset );
}
m_midiNotesMutex.unlock();
emit endNote();
Expand Down