From 3aa03da5af6090ac58769c97d9ddee3340dec5ca Mon Sep 17 00:00:00 2001 From: "Raine M. Ekman" Date: Sat, 10 Nov 2012 12:49:37 +0100 Subject: [PATCH] InstrumentMidiIOView: added support for fixed output notes It came to me that having LMMS output one fixed note from a track could be useful for controlling drum machines or something like that, so here's a new spinbox for the MIDI tab. Signed-off-by: Tobias Doerffel --- include/InstrumentMidiIOView.h | 1 + include/MidiPort.h | 3 +++ include/midi.h | 1 + src/core/midi/MidiPort.cpp | 13 ++++++++++++- src/gui/widgets/InstrumentMidiIOView.cpp | 16 +++++++++++++--- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/include/InstrumentMidiIOView.h b/include/InstrumentMidiIOView.h index 4747cd13d..047613062 100644 --- a/include/InstrumentMidiIOView.h +++ b/include/InstrumentMidiIOView.h @@ -55,6 +55,7 @@ private: lcdSpinBox * m_outputChannelSpinBox; lcdSpinBox * m_fixedOutputVelocitySpinBox; lcdSpinBox * m_outputProgramSpinBox; + lcdSpinBox * m_fixedOutputNoteSpinBox; QToolButton * m_wpBtn; } ; diff --git a/include/MidiPort.h b/include/MidiPort.h index 50e8db3c6..a5b1aee0e 100644 --- a/include/MidiPort.h +++ b/include/MidiPort.h @@ -56,6 +56,8 @@ class MidiPort : public Model, public SerializingObject m_fixedInputVelocityModel); mapPropertyFromModel(int,fixedOutputVelocity,setFixedOutputVelocity, m_fixedOutputVelocityModel); + mapPropertyFromModel(int,fixedOutputNote,setFixedOutputNote, + m_fixedOutputNoteModel); mapPropertyFromModel(int,outputProgram,setOutputProgram, m_outputProgramModel); mapPropertyFromModel(bool,isReadable,setReadable,m_readableModel); @@ -155,6 +157,7 @@ private: IntModel m_outputControllerModel; IntModel m_fixedInputVelocityModel; IntModel m_fixedOutputVelocityModel; + IntModel m_fixedOutputNoteModel; IntModel m_outputProgramModel; BoolModel m_readableModel; BoolModel m_writableModel; diff --git a/include/midi.h b/include/midi.h index c7f048838..5d8b91da6 100644 --- a/include/midi.h +++ b/include/midi.h @@ -85,6 +85,7 @@ const int MidiChannelCount = 16; const int MidiControllerCount = 128; const int MidiProgramCount = 128; const int MidiMaxVelocity = 127; +const int MidiMaxNote = 127; const int MidiMaxPanning = 127; const int MidiMinPanning = -128; diff --git a/src/core/midi/MidiPort.cpp b/src/core/midi/MidiPort.cpp index 4cbc78ef9..49c61e674 100644 --- a/src/core/midi/MidiPort.cpp +++ b/src/core/midi/MidiPort.cpp @@ -52,6 +52,8 @@ MidiPort::MidiPort( const QString & _name, MidiClient * _mc, tr( "Fixed input velocity" ) ), m_fixedOutputVelocityModel( -1, -1, MidiMaxVelocity, this, tr( "Fixed output velocity" ) ), + m_fixedOutputNoteModel( -1, -1, MidiMaxNote, this, + tr( "Fixed output note" ) ), m_outputProgramModel( 1, 1, MidiProgramCount, this, tr( "Output MIDI program" ) ), m_readableModel( false, this, tr( "Receive MIDI-events" ) ), @@ -156,9 +158,16 @@ void MidiPort::processOutEvent( const midiEvent & _me, const midiTime & _time ) midiEvent ev = _me; // we use/display MIDI channels 1...16 but we need 0...15 for // the outside world - if( ev.m_channel > 0 ) + // We are already in "real" MIDI channel space here + /* if( ev.m_channel > 0 ) { --ev.m_channel; + } */ + if( ( _me.m_type == MidiNoteOn || _me.m_type == MidiNoteOff ) && + fixedOutputNote() >=0 ) { + // Convert MIDI note number (from spinbox) -> LMMS note number + // that will be converted back when outputted. + ev.key() = fixedOutputNote() - KeysPerOctave; } if( fixedOutputVelocity() >= 0 && _me.velocity() > 0 && ( _me.m_type == MidiNoteOn || @@ -183,6 +192,8 @@ void MidiPort::saveSettings( QDomDocument & _doc, QDomElement & _this ) "fixedinputvelocity" ); m_fixedOutputVelocityModel.saveSettings( _doc, _this, "fixedoutputvelocity" ); + m_fixedOutputNoteModel.saveSettings( _doc, _this, + "fixedoutputnote" ); m_outputProgramModel.saveSettings( _doc, _this, "outputprogram" ); m_readableModel.saveSettings( _doc, _this, "readable" ); m_writableModel.saveSettings( _doc, _this, "writable" ); diff --git a/src/gui/widgets/InstrumentMidiIOView.cpp b/src/gui/widgets/InstrumentMidiIOView.cpp index 8969db162..bfa08e95c 100644 --- a/src/gui/widgets/InstrumentMidiIOView.cpp +++ b/src/gui/widgets/InstrumentMidiIOView.cpp @@ -85,26 +85,34 @@ InstrumentMidiIOView::InstrumentMidiIOView( QWidget * _parent ) : m_outputProgramSpinBox->move( 112, 32 ); m_outputProgramSpinBox->setEnabled( false ); + m_fixedOutputNoteSpinBox = new lcdSpinBox( 3, m_midiOutputGroupBox ); + m_fixedOutputNoteSpinBox->addTextForValue( -1, "---" ); + m_fixedOutputNoteSpinBox->setLabel( tr( "NOTE" ) ); + m_fixedOutputNoteSpinBox->move( 160, 32 ); + m_fixedOutputNoteSpinBox->setEnabled( false ); + + 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 ) ), m_outputProgramSpinBox, SLOT( setEnabled( bool ) ) ); - + connect( m_midiOutputGroupBox->ledButton(), SIGNAL( toggled( bool ) ), + m_fixedOutputNoteSpinBox, SLOT( setEnabled( bool ) ) ); if( !engine::getMixer()->midiClient()->isRaw() ) { m_rpBtn = new QToolButton( m_midiInputGroupBox ); m_rpBtn->setText( tr( "MIDI devices to receive MIDI events from" ) ); m_rpBtn->setIcon( embed::getIconPixmap( "piano" ) ); - m_rpBtn->setGeometry( 186, 24, 32, 32 ); + m_rpBtn->setGeometry( 208, 24, 32, 32 ); m_rpBtn->setPopupMode( QToolButton::InstantPopup ); m_wpBtn = new QToolButton( m_midiOutputGroupBox ); m_wpBtn->setText( tr( "MIDI devices to send MIDI events to" ) ); m_wpBtn->setIcon( embed::getIconPixmap( "piano" ) ); - m_wpBtn->setGeometry( 186, 24, 32, 32 ); + m_wpBtn->setGeometry( 208, 24, 32, 32 ); m_wpBtn->setPopupMode( QToolButton::InstantPopup ); } } @@ -131,6 +139,8 @@ void InstrumentMidiIOView::modelChanged() m_outputChannelSpinBox->setModel( &mp->m_outputChannelModel ); m_fixedOutputVelocitySpinBox->setModel( &mp->m_fixedOutputVelocityModel ); + m_fixedOutputNoteSpinBox->setModel( + &mp->m_fixedOutputNoteModel ); m_outputProgramSpinBox->setModel( &mp->m_outputProgramModel ); if( m_rpBtn )