rewrote management of MIDI-ports and MIDI-port subscriptions - now it's central and easy to use

git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1087 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Tobias Doerffel
2008-06-07 21:20:35 +00:00
parent 4c4596f9f4
commit 231bef1349
25 changed files with 677 additions and 1053 deletions

View File

@@ -38,11 +38,12 @@
class QLineEdit;
class QListView;
class QScrollArea;
class autoDetectMidiController;
class comboBox;
class groupBox;
class lcdSpinBox;
class ledCheckBox;
class comboBox;
class autoDetectMidiController;
class midiPortMenu;
@@ -69,16 +70,13 @@ public slots:
protected slots:
void midiValueChanged( void );
void activatedReadablePort( QAction * _item );
void updateReadablePortsMenu( void );
private:
groupBox * m_midiGroupBox;
lcdSpinBox * m_midiChannelSpinBox;
lcdSpinBox * m_midiControllerSpinBox;
ledCheckBox * m_midiAutoDetectCheckBox;
QMenu * m_readablePorts;
midiPortMenu * m_readablePorts;
boolModel m_midiAutoDetect;
groupBox * m_userGroupBox;

View File

@@ -32,30 +32,21 @@
#include "mv_base.h"
class QMenu;
class QAction;
class tabWidget;
class ledCheckBox;
class lcdSpinBox;
class midiPortMenu;
class instrumentMidiIOView : public QWidget, public modelView
{
Q_OBJECT
public:
instrumentMidiIOView( QWidget * _parent );
instrumentMidiIOView( midiPortMenu * _readable_ports_menu,
midiPortMenu * _writable_ports_menu,
QWidget * _parent );
virtual ~instrumentMidiIOView();
protected slots:
void activatedReadablePort( QAction * _item );
void activatedWriteablePort( QAction * _item );
void updateReadablePortsMenu( void );
void updateWriteablePortsMenu( void );
private:
virtual void modelChanged( void );
@@ -67,12 +58,6 @@ private:
ledCheckBox * m_defaultVelocityInCheckBox;
ledCheckBox * m_defaultVelocityOutCheckBox;
QMenu * m_readablePorts;
QMenu * m_writeablePorts;
friend class instrumentTrackWindow;
} ;

View File

@@ -32,10 +32,10 @@
#include "audio_port.h"
#include "automatable_model.h"
#include "instrument_functions.h"
#include "instrument_midi_io.h"
#include "instrument_sound_shaping.h"
#include "lcd_spinbox.h"
#include "midi_event_processor.h"
#include "midi_port.h"
#include "mixer.h"
#include "piano.h"
#include "effect_chain.h"
@@ -51,10 +51,10 @@ class effectRackView;
class instrumentSoundShapingView;
class fadeButton;
class instrument;
class instrumentMidiIOView;
class instrumentTrackButton;
class instrumentTrackWindow;
class midiPort;
class instrumentMidiIOView;
class midiPortMenu;
class notePlayHandle;
class pluginView;
class presetPreviewPlayHandle;
@@ -167,8 +167,8 @@ protected slots:
private:
midiPort * m_midiPort;
audioPort m_audioPort;
midiPort m_midiPort;
notePlayHandle * m_notes[NumKeys];
@@ -186,7 +186,6 @@ private:
instrumentSoundShaping m_soundShaping;
arpeggiator m_arpeggiator;
chordCreator m_chordCreator;
instrumentMidiIO m_midiIO;
piano m_piano;
@@ -234,6 +233,10 @@ private slots:
void updateName( void );
void midiInSelected( void );
void midiOutSelected( void );
void midiConfigChanged( void );
private:
instrumentTrackWindow * m_window;
@@ -246,6 +249,11 @@ private:
instrumentTrackButton * m_tswInstrumentTrackButton;
QMenu * m_tswMidiMenu;
midiPortMenu * m_readablePortsMenu;
midiPortMenu * m_writablePortsMenu;
QAction * m_midiInputAction;
QAction * m_midiOutputAction;
friend class instrumentTrackButton;
@@ -292,10 +300,6 @@ public slots:
void updateName( void );
void updateInstrumentView( void );
void midiInSelected( void );
void midiOutSelected( void );
void midiConfigChanged( bool );
protected:
// capture close-events for toggling instrument-track-button
@@ -339,9 +343,6 @@ private:
// test-piano at the bottom of every instrument-settings-window
pianoView * m_pianoView;
QAction * m_midiInputAction;
QAction * m_midiOutputAction;
friend class instrumentTrackButton;
friend class instrumentView;

View File

@@ -78,7 +78,7 @@ public:
protected:
virtual void FASTCALL sendByte( const Uint8 _c );
virtual void sendByte( const Uint8 _c );
virtual void run( void );

View File

@@ -70,14 +70,14 @@ public:
virtual void FASTCALL processOutEvent( const midiEvent & _me,
virtual void processOutEvent( const midiEvent & _me,
const midiTime & _time,
const midiPort * _port );
virtual void FASTCALL applyPortMode( midiPort * _port );
virtual void FASTCALL applyPortName( midiPort * _port );
virtual void applyPortMode( midiPort * _port );
virtual void applyPortName( midiPort * _port );
virtual void FASTCALL removePort( midiPort * _port );
virtual void removePort( midiPort * _port );
// list seq-ports from ALSA
@@ -94,10 +94,10 @@ public:
// (un)subscribe given midiPort to/from destination-port
virtual void subscribeReadablePort( midiPort * _port,
const QString & _dest,
bool _unsubscribe = FALSE );
bool _subscribe = TRUE );
virtual void subscribeWriteablePort( midiPort * _port,
const QString & _dest,
bool _unsubscribe = FALSE );
bool _subscribe = TRUE );
virtual void connectRPChanged( QObject * _receiver,
const char * _member )
{

View File

@@ -1,7 +1,7 @@
/*
* midi_client.h - base-class for MIDI-clients like ALSA-sequencer-client
*
* Copyright (c) 2005-2007 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -46,24 +46,19 @@ public:
virtual ~midiClient();
// to be implemented by sub-classes
virtual void FASTCALL processOutEvent( const midiEvent & _me,
virtual void processOutEvent( const midiEvent & _me,
const midiTime & _time,
const midiPort * _port ) = 0;
// inheriting classes can re-implement this for being able to update
// their internal port-structures etc.
virtual void FASTCALL applyPortMode( midiPort * _port );
virtual void FASTCALL applyPortName( midiPort * _port );
virtual void applyPortMode( midiPort * _port );
virtual void applyPortName( midiPort * _port );
// inheriting classes can re-implement this although it's actually not
// neccessary, because they can catch port-mode-changes and do their
// stuff as soon as port-mode changes from DUMMY to something else
// re-implemented methods HAVE to call addPort() of base-class!!
virtual midiPort * FASTCALL addPort( midiEventProcessor * _mep,
const QString & _name );
virtual void addPort( midiPort * _port );
// re-implemented methods HAVE to call removePort() of base-class!!
virtual void FASTCALL removePort( midiPort * _port );
virtual void removePort( midiPort * _port );
// returns whether client works with raw-MIDI, only needs to be
@@ -80,10 +75,10 @@ public:
// (un)subscribe given midiPort to/from destination-port
virtual void subscribeReadablePort( midiPort * _port,
const QString & _dest,
bool _unsubscribe = FALSE );
bool _subscribe = TRUE );
virtual void subscribeWriteablePort( midiPort * _port,
const QString & _dest,
bool _unsubscribe = FALSE );
bool _subscribe = TRUE );
// qobject-derived classes can use this for make a slot being
// connected to signal of non-raw-MIDI-client if port-lists change
@@ -152,22 +147,22 @@ public:
protected:
// generic raw-MIDI-parser which generates appropriate MIDI-events
void FASTCALL parseData( const Uint8 _c );
void parseData( const Uint8 _c );
// to be implemented by actual client-implementation
virtual void FASTCALL sendByte( const Uint8 _c ) = 0;
virtual void sendByte( const Uint8 _c ) = 0;
private:
// this does MIDI-event-process
void processParsedEvent();
virtual void FASTCALL processOutEvent( const midiEvent & _me,
virtual void processOutEvent( const midiEvent & _me,
const midiTime & _time,
const midiPort * _port );
// small helper function returning length of a certain event - this
// is neccessary for parsing raw-MIDI-data
static Uint8 FASTCALL eventLength( const Uint8 _event );
static Uint8 eventLength( const Uint8 _event );
// data being used for parsing

View File

@@ -26,13 +26,11 @@
#define _MIDI_CONTROLLER_H
#include <QtGui/QWidget>
#include <QtCore/QMap>
#include "mv_base.h"
#include "automatable_model.h"
#include "controller.h"
#include "controller_dialog.h"
#include "midi_event_processor.h"
#include "midi_port.h"
class midiPort;
@@ -42,18 +40,16 @@ class midiController : public controller, public midiEventProcessor
{
Q_OBJECT
public:
typedef QMap<QString, bool> midiPortMap;
midiController( model * _parent );
virtual ~midiController();
#warning TODO: use displayName-property!
virtual QString publicName() const
{
return "MIDI Controller";
}
virtual void processInEvent( const midiEvent & _me,
const midiTime & _time,
bool _lock = TRUE );
@@ -68,45 +64,29 @@ public:
virtual void loadSettings( const QDomElement & _this );
virtual QString nodeName( void ) const;
virtual intModel * midiChannelModel( void )
{
return &m_midiChannel;
}
virtual intModel * midiControllerModel( void )
{
return &m_midiController;
}
virtual midiPort * getMidiPort( void )
{
return m_midiPort;
}
// Used by controllerConnectionDialog to copy
virtual void setReadablePorts( const midiPortMap & _map );
void subscribeReadablePorts( const midiPort::map & _map );
public slots:
virtual controllerDialog * createDialog( QWidget * _parent );
void updateMidiPort( void );
void updateReadablePorts( void );
void updateName( void );
protected:
// The internal per-controller get-value function
virtual float value( int _offset );
intModel m_midiChannel;
intModel m_midiController;
midiPort * m_midiPort;
midiPortMap m_readablePorts;
midiPort m_midiPort;
float m_lastValue;
friend class controllerConnectionDialog;
};
friend class autoDetectMidiController;
} ;
#endif

View File

@@ -1,100 +0,0 @@
/*
* instrument_midi_io.h - class instrumentMidiIO
*
* Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef _INSTRUMENT_MIDI_IO_H
#define _INSTRUMENT_MIDI_IO_H
#include <QtCore/QList>
#include <QtCore/QPair>
#include "automatable_model.h"
class instrumentTrack;
class midiPort;
class instrumentMidiIO : public model, public journallingObject
{
Q_OBJECT
public:
typedef QPair<QString, bool> descriptiveMidiPort;
typedef QList<descriptiveMidiPort> midiPortMap;
instrumentMidiIO( instrumentTrack * _instrument_track,
midiPort * _port );
virtual ~instrumentMidiIO();
virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
virtual void loadSettings( const QDomElement & _this );
virtual QString nodeName( void ) const
{
return( "midi" );
}
signals:
void readablePortsChanged( void );
void writeablePortsChanged( void );
public slots:
void updateMidiPortMode( void );
protected slots:
void updateInputChannel( void );
void updateOutputChannel( void );
void updateDefaultVelIn( void );
void updateDefaultVelOut( void );
void updateReadablePorts( void );
void updateWriteablePorts( void );
void activatedReadablePort( const descriptiveMidiPort & _port );
void activatedWriteablePort( const descriptiveMidiPort & _port );
private:
instrumentTrack * m_instrumentTrack;
midiPort * m_midiPort;
intModel m_inputChannelModel;
intModel m_outputChannelModel;
boolModel m_receiveEnabledModel;
boolModel m_sendEnabledModel;
boolModel m_defaultVelocityInEnabledModel;
boolModel m_defaultVelocityOutEnabledModel;
midiPortMap m_readablePorts;
midiPortMap m_writeablePorts;
friend class instrumentMidiIOView;
} ;
#endif

View File

@@ -71,7 +71,7 @@ public:
protected:
virtual void FASTCALL sendByte( const Uint8 _c );
virtual void sendByte( const Uint8 _c );
virtual void run( void );

View File

@@ -2,7 +2,7 @@
* midi_port.h - abstraction of MIDI-ports which are part of LMMS's MIDI-
* sequencing system
*
* Copyright (c) 2005-2007 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -28,14 +28,11 @@
#define _MIDI_PORT_H
#include <QtCore/QString>
#include <QtCore/QList>
#include <QtCore/QPair>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "types.h"
#include "midi.h"
#include "automatable_model.h"
class midiClient;
@@ -44,9 +41,22 @@ class midiTime;
// class for abstraction of MIDI-port
class midiPort
class midiPort : public model, public serializingObject
{
Q_OBJECT
mapPropertyFromModel(int,inputChannel,setInputChannel,
m_inputChannelModel);
mapPropertyFromModel(int,outputChannel,setOutputChannel,
m_outputChannelModel);
mapPropertyFromModel(int,inputController,setInputController,
m_inputControllerModel);
mapPropertyFromModel(int,outputController,setOutputController,
m_outputControllerModel);
mapPropertyFromModel(bool,isReadable,setReadable,m_readableModel);
mapPropertyFromModel(bool,isWritable,setWritable,m_writableModel);
public:
typedef QMap<QString, bool> map;
enum Modes
{
Disabled, // don't route any MIDI-events (default)
@@ -55,71 +65,105 @@ public:
Duplex // both directions
} ;
midiPort( midiClient * _mc, midiEventProcessor * _mep,
const QString & _name, Modes _mode = Disabled );
~midiPort();
midiPort( const QString & _name,
midiClient * _mc,
midiEventProcessor * _mep,
model * _parent = NULL,
track * _track = NULL,
Modes _mode = Disabled );
virtual ~midiPort();
inline const QString & name( void ) const
{
return( m_name );
}
void FASTCALL setName( const QString & _name );
void setName( const QString & _name );
inline Modes mode( void ) const
{
return( m_mode );
}
void FASTCALL setMode( Modes _mode );
inline Sint8 inputChannel( void ) const
{
return( m_inputChannel );
}
inline void setInputChannel( Sint8 _chnl )
{
m_inputChannel = _chnl;
}
void setMode( Modes _mode );
inline void enableDefaultVelocityForInEvents( const bool _on )
{
m_defaultVelocityForInEventsEnabled = _on;
}
inline Sint8 outputChannel( void ) const
{
return( m_outputChannel );
}
inline void setOutputChannel( Sint8 _chnl )
{
m_outputChannel = _chnl;
m_defaultVelocityInEnabledModel.setValue( _on );
}
inline void enableDefaultVelocityForOutEvents( const bool _on )
{
m_defaultVelocityForOutEventsEnabled = _on;
m_defaultVelocityOutEnabledModel.setValue( _on );
}
void processInEvent( const midiEvent & _me, const midiTime & _time );
void processOutEvent( const midiEvent & _me, const midiTime & _time );
void FASTCALL processInEvent( const midiEvent & _me,
const midiTime & _time );
void FASTCALL processOutEvent( const midiEvent & _me,
const midiTime & _time );
virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
virtual void loadSettings( const QDomElement & _this );
virtual QString nodeName( void ) const
{
return( "midiport" );
}
void subscribeReadablePort( const QString & _port,
bool _subscribe = TRUE );
void subscribeWriteablePort( const QString & _port,
bool _subscribe = TRUE );
const map & readablePorts( void ) const
{
return( m_readablePorts );
}
const map & writablePorts( void ) const
{
return( m_writablePorts );
}
signals:
void readablePortsChanged( void );
void writeablePortsChanged( void );
void modeChanged( void );
public slots:
void updateMidiPortMode( void );
private slots:
void updateReadablePorts( void );
void updateWriteablePorts( void );
private:
midiClient * m_midiClient;
midiEventProcessor * m_midiEventProcessor;
QString m_name;
QString m_name; // TODO: replace with model-name-property!
Modes m_mode;
Sint8 m_inputChannel;
Sint8 m_outputChannel;
bool m_defaultVelocityForInEventsEnabled;
bool m_defaultVelocityForOutEventsEnabled;
intModel m_inputChannelModel;
intModel m_outputChannelModel;
intModel m_inputControllerModel;
intModel m_outputControllerModel;
boolModel m_readableModel;
boolModel m_writableModel;
boolModel m_defaultVelocityInEnabledModel;
boolModel m_defaultVelocityOutEnabledModel;
map m_readablePorts;
map m_writablePorts;
friend class controllerConnectionDialog;
friend class instrumentMidiIOView;
} ;

60
include/midi_port_menu.h Normal file
View File

@@ -0,0 +1,60 @@
/*
* midi_port_menu.h - a menu for subscribing a midiPort to several external
* MIDI ports
*
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef _MIDI_PORT_MENU_H
#define _MIDI_PORT_MENU_H
#include <QtGui/QMenu>
#include "mv_base.h"
#include "midi_port.h"
class QAction;
class midiPortMenu : public QMenu, public modelView
{
Q_OBJECT
public:
midiPortMenu( midiPort::Modes _mode );
virtual ~midiPortMenu();
protected slots:
void activatedPort( QAction * _item );
void updatePorts( void );
private:
virtual void modelChanged( void );
midiPort::Modes m_mode;
} ;
#endif