Made 0.4.12 release
[lmms/mlankhorst.git] / include / MidiPort.h
blob50e8db3c60167983f1bba4079614361a235b81e3
1 /*
2 * MidiPort.h - abstraction of MIDI ports which are part of LMMS's MIDI-
3 * sequencing system
5 * Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
7 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this program (see COPYING); if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA.
26 #ifndef _MIDI_PORT_H
27 #define _MIDI_PORT_H
29 #include <QtCore/QString>
30 #include <QtCore/QList>
31 #include <QtCore/QPair>
33 #include "midi.h"
34 #include "AutomatableModel.h"
37 class MidiClient;
38 class MidiEventProcessor;
39 class MidiPortMenu;
40 class midiTime;
43 // class for abstraction of MIDI-port
44 class MidiPort : public Model, public SerializingObject
46 Q_OBJECT
47 mapPropertyFromModel(int,inputChannel,setInputChannel,
48 m_inputChannelModel);
49 mapPropertyFromModel(int,outputChannel,setOutputChannel,
50 m_outputChannelModel);
51 mapPropertyFromModel(int,inputController,setInputController,
52 m_inputControllerModel);
53 mapPropertyFromModel(int,outputController,setOutputController,
54 m_outputControllerModel);
55 mapPropertyFromModel(int,fixedInputVelocity,setFixedInputVelocity,
56 m_fixedInputVelocityModel);
57 mapPropertyFromModel(int,fixedOutputVelocity,setFixedOutputVelocity,
58 m_fixedOutputVelocityModel);
59 mapPropertyFromModel(int,outputProgram,setOutputProgram,
60 m_outputProgramModel);
61 mapPropertyFromModel(bool,isReadable,setReadable,m_readableModel);
62 mapPropertyFromModel(bool,isWritable,setWritable,m_writableModel);
63 public:
64 typedef QMap<QString, bool> Map;
66 enum Modes
68 Disabled, // don't route any MIDI-events (default)
69 Input, // from MIDI-client to MIDI-event-processor
70 Output, // from MIDI-event-processor to MIDI-client
71 Duplex // both directions
72 } ;
74 MidiPort( const QString & _name,
75 MidiClient * _mc,
76 MidiEventProcessor * _mep,
77 Model * _parent = NULL,
78 Modes _mode = Disabled );
79 virtual ~MidiPort();
81 void setName( const QString & _name );
83 inline Modes mode() const
85 return m_mode;
88 void setMode( Modes _mode );
90 inline bool inputEnabled() const
92 return mode() == Input || mode() == Duplex;
95 inline bool outputEnabled() const
97 return mode() == Output || mode() == Duplex;
100 inline int realOutputChannel() const
102 return outputChannel() - 1;
105 void processInEvent( const midiEvent & _me, const midiTime & _time );
106 void processOutEvent( const midiEvent & _me, const midiTime & _time );
109 virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
110 virtual void loadSettings( const QDomElement & _this );
112 virtual QString nodeName() const
114 return "midiport";
117 void subscribeReadablePort( const QString & _port,
118 bool _subscribe = true );
119 void subscribeWritablePort( const QString & _port,
120 bool _subscribe = true );
122 const Map & readablePorts() const
124 return m_readablePorts;
127 const Map & writablePorts() const
129 return m_writablePorts;
132 MidiPortMenu * m_readablePortsMenu;
133 MidiPortMenu * m_writablePortsMenu;
136 public slots:
137 void updateMidiPortMode();
140 private slots:
141 void updateReadablePorts();
142 void updateWritablePorts();
143 void updateOutputProgram();
146 private:
147 MidiClient * m_midiClient;
148 MidiEventProcessor * m_midiEventProcessor;
150 Modes m_mode;
152 IntModel m_inputChannelModel;
153 IntModel m_outputChannelModel;
154 IntModel m_inputControllerModel;
155 IntModel m_outputControllerModel;
156 IntModel m_fixedInputVelocityModel;
157 IntModel m_fixedOutputVelocityModel;
158 IntModel m_outputProgramModel;
159 BoolModel m_readableModel;
160 BoolModel m_writableModel;
162 Map m_readablePorts;
163 Map m_writablePorts;
166 friend class ControllerConnectionDialog;
167 friend class InstrumentMidiIOView;
170 signals:
171 void readablePortsChanged();
172 void writablePortsChanged();
173 void modeChanged();
178 typedef QList<MidiPort *> MidiPortList;
181 #endif